Changeset 59:e2f86ef9b871 in AnnotationManagerN4J for src/main/java
- Timestamp:
- Nov 20, 2012, 6:16:43 PM (12 years ago)
- Branch:
- default
- Location:
- src/main/java/de/mpiwg/itgroup/annotations
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/main/java/de/mpiwg/itgroup/annotations/neo4j/AnnotationStore.java
r48 r59 56 56 } 57 57 58 public static String ANNOTATION_URI_ BASE = "http://entities.mpiwg-berlin.mpg.de/annotations/";58 public static String ANNOTATION_URI_PREFIX = ""; 59 59 60 60 public AnnotationStore(GraphDatabaseService graphDb) { … … 80 80 */ 81 81 public Node getPersonNodeByUri(String userUri) { 82 if (userUri == null) return null; 83 Node person = getNodeIndex(NodeTypes.PERSON).get("uri", userUri).getSingle(); 84 return person; 82 return getNodeFromIndex("uri", userUri, NodeTypes.PERSON); 85 83 } 86 84 … … 90 88 */ 91 89 public Node getTagNodeByUri(String tagUri) { 92 if (tagUri == null) return null; 93 Node person = getNodeIndex(NodeTypes.TAG).get("uri", tagUri).getSingle(); 94 return person; 90 return getNodeFromIndex("uri", tagUri, NodeTypes.TAG); 95 91 } 96 92 … … 112 108 113 109 /** 114 * Returns the Node with the given key and value. 115 * Key has to be indexed. 110 * Returns the Node with the given key and value. Key has to be indexed. 116 111 * 117 112 * @param key … … 122 117 public Node getNodeFromIndex(String key, String value, NodeTypes type) { 123 118 if (key == null || value == null) return null; 124 Node person= getNodeIndex(type).get(key, value).getSingle();125 return person;126 } 127 128 /** 129 * Returns list of Actors of given type (Group or Person). 130 * Key has to beindexed.119 Node node = getNodeIndex(type).get(key, value).getSingle(); 120 return node; 121 } 122 123 /** 124 * Returns list of Actors of given type (Group or Person). Key has to be 125 * indexed. 131 126 * 132 127 * @param key … … 150 145 return actors; 151 146 } 152 147 153 148 /** 154 149 * Returns list of groups. Key has to be indexed. 150 * 155 151 * @param key 156 152 * @param query … … 161 157 return groups; 162 158 } 163 159 164 160 /** 165 161 * Returns list of Persons. Key has to be indexed. 162 * 166 163 * @param key 167 164 * @param query … … 172 169 return persons; 173 170 } 174 175 /** 176 * Returns list of uri-like objects of given type (Target or Resource). 177 * Keyhas to be indexed.171 172 /** 173 * Returns list of uri-like objects of given type (Target or Resource). Key 174 * has to be indexed. 178 175 * 179 176 * @param key … … 198 195 } 199 196 200 201 197 /** 202 198 * Returns list of Targets. Key has to be indexed. 199 * 203 200 * @param key 204 201 * @param query … … 209 206 return targets; 210 207 } 211 208 212 209 /** 213 210 * Returns list of Resources. Key has to be indexed. 211 * 214 212 * @param key 215 213 * @param query … … 220 218 return targets; 221 219 } 222 223 /** 224 * Returns List of Annotations. 225 * Key has to be indexed. 220 221 /** 222 * Returns List of Annotations. Key has to be indexed. 226 223 * 227 224 * @param key … … 244 241 } 245 242 246 247 248 /** 249 * Returns List of Tags. 250 * Key has to be indexed. 243 /** 244 * Returns List of Tags. Key has to be indexed. 251 245 * 252 246 * @param key … … 596 590 return (Resource) createUriFromNode(resourceNode); 597 591 } 598 592 599 593 /** 600 594 * @param targetNode … … 604 598 return (Target) createUriFromNode(targetNode); 605 599 } 606 607 600 608 601 protected Uri createUriFromNode(Node uriNode) { 609 602 if (uriNode == null) return null; … … 1083 1076 */ 1084 1077 private String createRessourceURI(String prefix) { 1085 1086 1078 Calendar cal = Calendar.getInstance(); 1087 1088 1079 long time = cal.getTimeInMillis(); 1089 1090 return String.format("%s%s%s", ANNOTATION_URI_BASE, prefix, time); 1091 1080 return String.format("%s%s%s", ANNOTATION_URI_PREFIX, prefix, time); 1092 1081 } 1093 1082 1094 1083 public List<Annotation> getAnnotationsByTag(String tagUri) { 1095 1096 1084 ArrayList<Annotation> ret = new ArrayList<Annotation>(); 1097 1085 Node tag = getTagNodeByUri(tagUri); 1098 1099 Iterable<Relationship> rels = tag.getRelationships(Direction.INCOMING, RelationTypes.HAS_TAG); 1100 1101 for (Relationship rel : rels) { 1102 Node node = rel.getStartNode(); 1103 ret.add(createAnnotationFromNode(node)); 1104 1086 if (tag != null) { 1087 Iterable<Relationship> rels = tag.getRelationships(Direction.INCOMING, RelationTypes.HAS_TAG); 1088 for (Relationship rel : rels) { 1089 Node node = rel.getStartNode(); 1090 ret.add(createAnnotationFromNode(node)); 1091 } 1105 1092 } 1106 1093 return ret; … … 1109 1096 public List<Annotation> getAnnotationsByResource(String resourceUri) { 1110 1097 ArrayList<Annotation> ret = new ArrayList<Annotation>(); 1111 Node tag = getNodeFromIndex("uri", resourceUri, NodeTypes.RESOURCE); 1112 Iterable<Relationship> rels = tag.getRelationships(Direction.INCOMING, RelationTypes.ANNOTATES); 1113 for (Relationship rel : rels) { 1114 Node an = rel.getStartNode(); 1115 Node rn = rel.getEndNode(); 1116 if (rn.getProperty("TYPE", "").equals("RESOURCE")) { 1117 logger.error("getAnnotationsByResource got ANNOTATES != RESOURCE"); 1118 } 1119 ret.add(createAnnotationFromNode(an)); 1098 Node res = getNodeFromIndex("uri", resourceUri, NodeTypes.RESOURCE); 1099 if (res != null) { 1100 Iterable<Relationship> rels = res.getRelationships(Direction.INCOMING, RelationTypes.ANNOTATES); 1101 for (Relationship rel : rels) { 1102 Node an = rel.getStartNode(); 1103 Node rn = rel.getEndNode(); 1104 if (rn.getProperty("TYPE", "").equals("RESOURCE")) { 1105 logger.error("getAnnotationsByResource got ANNOTATES != RESOURCE"); 1106 } 1107 ret.add(createAnnotationFromNode(an)); 1108 } 1120 1109 } 1121 1110 return ret; -
src/main/java/de/mpiwg/itgroup/annotations/restlet/BaseRestlet.java
r58 r59 99 99 public static String GROUPS_URI_PREFIX = ""; 100 100 public static final String GROUPS_URI_KEY = "annotationmanager.uris.groups"; 101 102 public static final String ANNOTATIONS_URI_KEY = "annotationmanager.uris.annotations"; 101 103 102 104 /** … … 218 220 BaseRestlet.TAGS_URI_PREFIX = tup; 219 221 } 222 String aup = (String) sc.getAttribute(ANNOTATIONS_URI_KEY); 223 if (aup != null) { 224 AnnotationStore.ANNOTATION_URI_PREFIX = aup; 225 } 220 226 } else { 221 227 logger.error("Unable to get ServletContext!");
Note: See TracChangeset
for help on using the changeset viewer.