Mercurial > hg > AnnotationManagerN4J
annotate src/main/java/de/mpiwg/itgroup/annotations/neo4j/AnnotationStore.java @ 63:9f8c9611848a
fixed bug with new rectangle shapes. added limit, offset and sortBy parameters to annotator/ and annotator/search.
| author | casties |
|---|---|
| date | Fri, 23 Nov 2012 17:55:04 +0100 |
| parents | e2f86ef9b871 |
| children | 5b568de5ee0d |
| rev | line source |
|---|---|
| 4 | 1 /** |
| 2 * | |
| 3 */ | |
| 4 package de.mpiwg.itgroup.annotations.neo4j; | |
| 5 | |
| 6 import java.util.ArrayList; | |
|
32
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
7 import java.util.Arrays; |
| 4 | 8 import java.util.Calendar; |
| 16 | 9 import java.util.HashSet; |
| 4 | 10 import java.util.List; |
| 16 | 11 import java.util.Set; |
| 4 | 12 |
| 13 import org.apache.log4j.Logger; | |
| 5 | 14 import org.neo4j.graphdb.Direction; |
| 4 | 15 import org.neo4j.graphdb.GraphDatabaseService; |
| 16 import org.neo4j.graphdb.Node; | |
| 17 import org.neo4j.graphdb.Relationship; | |
| 18 import org.neo4j.graphdb.RelationshipType; | |
| 19 import org.neo4j.graphdb.Transaction; | |
| 20 import org.neo4j.graphdb.index.Index; | |
| 21 import org.neo4j.graphdb.index.IndexHits; | |
| 22 | |
| 9 | 23 import de.mpiwg.itgroup.annotations.Actor; |
| 4 | 24 import de.mpiwg.itgroup.annotations.Annotation; |
| 25 import de.mpiwg.itgroup.annotations.Annotation.FragmentTypes; | |
| 12 | 26 import de.mpiwg.itgroup.annotations.Group; |
| 10 | 27 import de.mpiwg.itgroup.annotations.Person; |
| 42 | 28 import de.mpiwg.itgroup.annotations.Resource; |
| 28 | 29 import de.mpiwg.itgroup.annotations.Tag; |
| 42 | 30 import de.mpiwg.itgroup.annotations.Target; |
| 31 import de.mpiwg.itgroup.annotations.Uri; | |
| 4 | 32 |
| 33 /** | |
|
32
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
34 * Neo4J based Annotation store. |
|
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
35 * |
| 4 | 36 * @author casties |
| 37 * | |
| 38 */ | |
| 39 public class AnnotationStore { | |
| 40 | |
|
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
41 protected static Logger logger = Logger.getLogger(AnnotationStore.class); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
42 |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
43 protected GraphDatabaseService graphDb; |
| 4 | 44 |
|
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
45 public static enum NodeTypes { |
|
36
0fdb05f35139
new node type "resource" for base documents (sans page number).
casties
parents:
34
diff
changeset
|
46 ANNOTATION, PERSON, TARGET, GROUP, TAG, RESOURCE |
|
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
47 } |
| 4 | 48 |
|
32
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
49 // types of nodes that should not be automatically deleted. |
|
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
50 public Set<String> permanentNodeTypes = new HashSet<String>(Arrays.asList("PERSON", "GROUP", "TAG")); |
|
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
51 |
|
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
52 protected List<Index<Node>> nodeIndexes; |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
53 |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
54 public static enum RelationTypes implements RelationshipType { |
|
36
0fdb05f35139
new node type "resource" for base documents (sans page number).
casties
parents:
34
diff
changeset
|
55 ANNOTATES, CREATED, PERMITS_ADMIN, PERMITS_DELETE, PERMITS_UPDATE, PERMITS_READ, MEMBER_OF, HAS_TAG, PART_OF |
|
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
56 } |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
57 |
|
59
e2f86ef9b871
make annotation uri in store configurable. fix npe with no tags.
casties
parents:
48
diff
changeset
|
58 public static String ANNOTATION_URI_PREFIX = ""; |
| 4 | 59 |
|
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
60 public AnnotationStore(GraphDatabaseService graphDb) { |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
61 super(); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
62 this.graphDb = graphDb; |
| 16 | 63 nodeIndexes = new ArrayList<Index<Node>>(5); |
|
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
64 // List.set(enum.ordinal(), val) seems not to work. |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
65 nodeIndexes.add(NodeTypes.ANNOTATION.ordinal(), graphDb.index().forNodes("annotations")); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
66 nodeIndexes.add(NodeTypes.PERSON.ordinal(), graphDb.index().forNodes("persons")); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
67 nodeIndexes.add(NodeTypes.TARGET.ordinal(), graphDb.index().forNodes("targets")); |
| 15 | 68 nodeIndexes.add(NodeTypes.GROUP.ordinal(), graphDb.index().forNodes("groups")); |
| 16 | 69 nodeIndexes.add(NodeTypes.TAG.ordinal(), graphDb.index().forNodes("tags")); |
|
36
0fdb05f35139
new node type "resource" for base documents (sans page number).
casties
parents:
34
diff
changeset
|
70 nodeIndexes.add(NodeTypes.RESOURCE.ordinal(), graphDb.index().forNodes("resources")); |
|
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
71 } |
| 4 | 72 |
|
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
73 protected Index<Node> getNodeIndex(NodeTypes type) { |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
74 return nodeIndexes.get(type.ordinal()); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
75 } |
| 12 | 76 |
|
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
77 /** |
| 15 | 78 * @param userUri |
| 79 * @return | |
| 80 */ | |
| 81 public Node getPersonNodeByUri(String userUri) { | |
|
59
e2f86ef9b871
make annotation uri in store configurable. fix npe with no tags.
casties
parents:
48
diff
changeset
|
82 return getNodeFromIndex("uri", userUri, NodeTypes.PERSON); |
| 15 | 83 } |
| 84 | |
| 28 | 85 /** |
| 86 * @param tagUri | |
| 87 * @return | |
| 88 */ | |
| 89 public Node getTagNodeByUri(String tagUri) { | |
|
59
e2f86ef9b871
make annotation uri in store configurable. fix npe with no tags.
casties
parents:
48
diff
changeset
|
90 return getNodeFromIndex("uri", tagUri, NodeTypes.TAG); |
| 28 | 91 } |
| 92 | |
| 42 | 93 /** |
| 43 | 94 * @param resourceUri |
| 95 * @return | |
| 96 */ | |
| 97 public Node getResourceNodeByUri(String resourceUri) { | |
| 98 return getNodeFromIndex("uri", resourceUri, NodeTypes.RESOURCE); | |
| 99 } | |
| 100 | |
| 101 /** | |
| 102 * @param targetUri | |
| 103 * @return | |
| 104 */ | |
| 105 public Node getTargetNodeByUri(String targetUri) { | |
| 106 return getNodeFromIndex("uri", targetUri, NodeTypes.RESOURCE); | |
| 107 } | |
| 108 | |
| 109 /** | |
|
59
e2f86ef9b871
make annotation uri in store configurable. fix npe with no tags.
casties
parents:
48
diff
changeset
|
110 * Returns the Node with the given key and value. Key has to be indexed. |
| 42 | 111 * |
| 112 * @param key | |
| 113 * @param value | |
| 114 * @param type | |
| 115 * @return | |
| 116 */ | |
| 117 public Node getNodeFromIndex(String key, String value, NodeTypes type) { | |
| 118 if (key == null || value == null) return null; | |
|
59
e2f86ef9b871
make annotation uri in store configurable. fix npe with no tags.
casties
parents:
48
diff
changeset
|
119 Node node = getNodeIndex(type).get(key, value).getSingle(); |
|
e2f86ef9b871
make annotation uri in store configurable. fix npe with no tags.
casties
parents:
48
diff
changeset
|
120 return node; |
| 42 | 121 } |
| 122 | |
| 123 /** | |
|
59
e2f86ef9b871
make annotation uri in store configurable. fix npe with no tags.
casties
parents:
48
diff
changeset
|
124 * Returns list of Actors of given type (Group or Person). Key has to be |
|
e2f86ef9b871
make annotation uri in store configurable. fix npe with no tags.
casties
parents:
48
diff
changeset
|
125 * indexed. |
| 42 | 126 * |
| 127 * @param key | |
| 128 * @param query | |
| 129 * @param type | |
| 130 * @return | |
| 131 */ | |
| 132 @SuppressWarnings("unchecked") | |
| 45 | 133 protected <T extends Actor> List<T> getActors(String key, String query, NodeTypes type) { |
| 42 | 134 ArrayList<T> actors = new ArrayList<T>(); |
| 24 | 135 Index<Node> idx = getNodeIndex(type); |
| 136 if (key == null) { | |
| 137 key = "uri"; | |
| 138 query = "*"; | |
| 139 } | |
| 140 IndexHits<Node> actorNodes = idx.query(key, query); | |
| 141 for (Node actorNode : actorNodes) { | |
| 142 Actor actor = createActorFromNode(actorNode); | |
| 42 | 143 actors.add((T) actor); |
| 24 | 144 } |
| 145 return actors; | |
| 146 } | |
|
59
e2f86ef9b871
make annotation uri in store configurable. fix npe with no tags.
casties
parents:
48
diff
changeset
|
147 |
| 15 | 148 /** |
| 42 | 149 * Returns list of groups. Key has to be indexed. |
|
59
e2f86ef9b871
make annotation uri in store configurable. fix npe with no tags.
casties
parents:
48
diff
changeset
|
150 * |
| 19 | 151 * @param key |
| 152 * @param query | |
| 18 | 153 * @return |
| 154 */ | |
| 19 | 155 public List<Group> getGroups(String key, String query) { |
| 42 | 156 List<Group> groups = getActors(key, query, NodeTypes.GROUP); |
| 157 return groups; | |
| 158 } | |
|
59
e2f86ef9b871
make annotation uri in store configurable. fix npe with no tags.
casties
parents:
48
diff
changeset
|
159 |
| 42 | 160 /** |
| 161 * Returns list of Persons. Key has to be indexed. | |
|
59
e2f86ef9b871
make annotation uri in store configurable. fix npe with no tags.
casties
parents:
48
diff
changeset
|
162 * |
| 42 | 163 * @param key |
| 164 * @param query | |
| 165 * @return | |
| 166 */ | |
| 167 public List<Person> getPersons(String key, String query) { | |
| 168 List<Person> persons = getActors(key, query, NodeTypes.PERSON); | |
| 169 return persons; | |
| 170 } | |
|
59
e2f86ef9b871
make annotation uri in store configurable. fix npe with no tags.
casties
parents:
48
diff
changeset
|
171 |
| 42 | 172 /** |
|
59
e2f86ef9b871
make annotation uri in store configurable. fix npe with no tags.
casties
parents:
48
diff
changeset
|
173 * Returns list of uri-like objects of given type (Target or Resource). Key |
|
e2f86ef9b871
make annotation uri in store configurable. fix npe with no tags.
casties
parents:
48
diff
changeset
|
174 * has to be indexed. |
| 42 | 175 * |
| 176 * @param key | |
| 177 * @param query | |
| 178 * @param type | |
| 179 * @return | |
| 180 */ | |
| 181 @SuppressWarnings("unchecked") | |
| 45 | 182 protected <T extends Uri> List<T> getUris(String key, String query, NodeTypes type) { |
| 42 | 183 ArrayList<T> uris = new ArrayList<T>(); |
| 184 Index<Node> idx = getNodeIndex(type); | |
| 19 | 185 if (key == null) { |
| 186 key = "uri"; | |
| 187 query = "*"; | |
| 188 } | |
| 42 | 189 IndexHits<Node> actorNodes = idx.query(key, query); |
| 190 for (Node actorNode : actorNodes) { | |
| 191 Uri uri = createUriFromNode(actorNode); | |
| 192 uris.add((T) uri); | |
| 18 | 193 } |
| 42 | 194 return uris; |
| 18 | 195 } |
|
32
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
196 |
| 42 | 197 /** |
| 198 * Returns list of Targets. Key has to be indexed. | |
|
59
e2f86ef9b871
make annotation uri in store configurable. fix npe with no tags.
casties
parents:
48
diff
changeset
|
199 * |
| 42 | 200 * @param key |
| 201 * @param query | |
| 202 * @return | |
| 203 */ | |
| 204 public List<Target> getTargets(String key, String query) { | |
| 205 List<Target> targets = getUris(key, query, NodeTypes.TARGET); | |
| 206 return targets; | |
| 207 } | |
|
59
e2f86ef9b871
make annotation uri in store configurable. fix npe with no tags.
casties
parents:
48
diff
changeset
|
208 |
| 42 | 209 /** |
| 210 * Returns list of Resources. Key has to be indexed. | |
|
59
e2f86ef9b871
make annotation uri in store configurable. fix npe with no tags.
casties
parents:
48
diff
changeset
|
211 * |
| 42 | 212 * @param key |
| 213 * @param query | |
| 214 * @return | |
| 215 */ | |
| 216 public List<Resource> getResources(String key, String query) { | |
| 217 List<Resource> targets = getUris(key, query, NodeTypes.RESOURCE); | |
| 218 return targets; | |
| 219 } | |
|
59
e2f86ef9b871
make annotation uri in store configurable. fix npe with no tags.
casties
parents:
48
diff
changeset
|
220 |
| 28 | 221 /** |
|
59
e2f86ef9b871
make annotation uri in store configurable. fix npe with no tags.
casties
parents:
48
diff
changeset
|
222 * Returns List of Annotations. Key has to be indexed. |
| 31 | 223 * |
| 224 * @param key | |
| 225 * @param query | |
| 226 * @return | |
| 227 */ | |
| 228 public List<Annotation> getAnnotations(String key, String query) { | |
| 229 ArrayList<Annotation> annotations = new ArrayList<Annotation>(); | |
| 230 Index<Node> idx = getNodeIndex(NodeTypes.ANNOTATION); | |
| 231 if (key == null) { | |
| 232 key = "id"; | |
| 233 query = "*"; | |
| 234 } | |
| 235 IndexHits<Node> annotNodes = idx.query(key, query); | |
| 236 for (Node annotNode : annotNodes) { | |
| 237 Annotation annotation = createAnnotationFromNode(annotNode); | |
| 238 annotations.add(annotation); | |
| 239 } | |
| 240 return annotations; | |
| 241 } | |
| 242 | |
| 243 /** | |
|
59
e2f86ef9b871
make annotation uri in store configurable. fix npe with no tags.
casties
parents:
48
diff
changeset
|
244 * Returns List of Tags. Key has to be indexed. |
| 28 | 245 * |
| 246 * @param key | |
| 247 * @param query | |
| 248 * @return | |
| 249 */ | |
| 250 public List<Tag> getTags(String key, String query) { | |
| 251 ArrayList<Tag> tags = new ArrayList<Tag>(); | |
| 252 Index<Node> idx = getNodeIndex(NodeTypes.TAG); | |
| 253 if (key == null) { | |
| 254 key = "uri"; | |
| 255 query = "*"; | |
| 256 } | |
| 257 IndexHits<Node> groupNodes = idx.query(key, query); | |
| 258 for (Node groupNode : groupNodes) { | |
| 259 Tag tag = createTagFromNode(groupNode); | |
| 260 tags.add(tag); | |
| 261 } | |
| 262 return tags; | |
| 263 } | |
| 18 | 264 |
|
32
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
265 /** |
| 15 | 266 * Returns List of Groups the person is member of. |
| 267 * | |
| 268 * @param person | |
| 269 * @return | |
| 270 */ | |
| 271 public List<Group> getGroupsForPersonNode(Node person) { | |
| 272 ArrayList<Group> groups = new ArrayList<Group>(); | |
| 273 Iterable<Relationship> rels = person.getRelationships(RelationTypes.MEMBER_OF); | |
| 274 for (Relationship rel : rels) { | |
| 275 Node groupNode = rel.getEndNode(); | |
| 276 Actor group = createActorFromNode(groupNode); | |
| 277 // make sure we're getting a group | |
| 278 if (!(group instanceof Group)) { | |
| 16 | 279 logger.error("target of MEMBER_OF is not GROUP! rel=" + rel); |
| 15 | 280 continue; |
| 281 } | |
| 282 groups.add((Group) group); | |
| 283 } | |
| 284 return groups; | |
| 285 } | |
| 16 | 286 |
| 15 | 287 /** |
| 288 * Returns if person with uri is in Group group. | |
| 289 * | |
| 290 * @param person | |
| 291 * @param group | |
| 292 * @return | |
| 293 */ | |
| 294 public boolean isPersonInGroup(Person person, Group group) { | |
| 295 Node pn = getPersonNodeByUri(person.getUriString()); | |
| 296 if (pn == null) return false; | |
| 16 | 297 // optimized version of getGroupsForPersonNode |
| 15 | 298 Iterable<Relationship> rels = pn.getRelationships(RelationTypes.MEMBER_OF); |
| 299 for (Relationship rel : rels) { | |
| 300 Node gn = rel.getEndNode(); | |
| 301 if (gn.getProperty("uri", "").equals(group.getUriString()) || gn.getProperty("id", "").equals(group.getId())) { | |
| 302 return true; | |
| 303 } | |
| 304 } | |
| 305 return false; | |
| 306 } | |
| 16 | 307 |
| 15 | 308 /** |
| 22 | 309 * Returns the members of the group. |
| 310 * | |
| 311 * @param group | |
| 312 * @return | |
| 313 */ | |
| 314 public List<Person> getMembersOfGroup(Group group) { | |
| 315 ArrayList<Person> members = new ArrayList<Person>(); | |
| 316 Node gn = getActorNode(group); | |
| 317 Iterable<Relationship> rels = gn.getRelationships(RelationTypes.MEMBER_OF); | |
| 318 for (Relationship rel : rels) { | |
| 319 Node memberNode = rel.getStartNode(); | |
| 320 Actor member = createActorFromNode(memberNode); | |
| 321 // make sure we're getting a group | |
| 322 if (!(member instanceof Person)) { | |
| 323 logger.error("source of MEMBER_OF is not PERSON! rel=" + rel); | |
| 324 continue; | |
| 325 } | |
| 326 members.add((Person) member); | |
| 327 } | |
| 328 return members; | |
| 329 } | |
|
32
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
330 |
| 22 | 331 /** |
| 25 | 332 * Add Person newMember to Group group. |
| 333 * | |
| 334 * @param group | |
| 335 * @param member | |
| 336 */ | |
| 337 public Person addGroupMember(Group group, Person member) { | |
| 338 Node gn = getActorNode(group); | |
| 339 Node pn = getActorNode(member); | |
| 340 Person addedMember = null; | |
| 341 if (gn != null && pn != null) { | |
| 342 getOrCreateRelation(pn, RelationTypes.MEMBER_OF, gn); | |
| 343 addedMember = member; | |
| 344 } | |
| 345 return addedMember; | |
| 346 } | |
|
32
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
347 |
| 25 | 348 /** |
| 349 * Delete Person oldMember from Group group. | |
| 350 * | |
| 351 * @param group | |
| 352 * @param member | |
| 353 */ | |
| 354 public void deleteGroupMember(Group group, Person member) { | |
| 355 Node gn = getActorNode(group); | |
|
32
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
356 Node pn = getActorNode(member); |
| 25 | 357 Iterable<Relationship> rels = gn.getRelationships(RelationTypes.MEMBER_OF); |
| 358 for (Relationship rel : rels) { | |
| 359 Node mn = rel.getStartNode(); | |
|
32
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
360 if (mn.equals(pn)) { |
|
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
361 Transaction tx = graphDb.beginTx(); |
|
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
362 try { |
|
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
363 rel.delete(); |
|
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
364 tx.success(); |
|
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
365 } finally { |
|
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
366 tx.finish(); |
|
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
367 } |
| 25 | 368 // there should be only one |
| 369 break; | |
| 370 } | |
|
32
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
371 } |
| 25 | 372 } |
|
32
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
373 |
| 25 | 374 /** |
| 22 | 375 * Returns the stored Actor matching the given one. |
| 376 * | |
| 377 * @param actor | |
| 378 * @return | |
| 379 */ | |
| 380 public Actor getActor(Actor actor) { | |
|
32
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
381 Node actorNode = getActorNode(actor); |
|
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
382 Actor storedActor = createActorFromNode(actorNode); |
|
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
383 return storedActor; |
| 22 | 384 } |
|
32
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
385 |
| 22 | 386 /** |
|
32
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
387 * Stores an Actor (Person or Group). Creates a new actor Node or update an |
|
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
388 * existing one. |
| 22 | 389 * |
| 390 * @param actor | |
| 391 * @return | |
| 392 */ | |
| 393 public Actor storeActor(Actor actor) { | |
|
32
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
394 Node actorNode = getOrCreateActorNode(actor); |
|
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
395 Transaction tx = graphDb.beginTx(); |
|
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
396 try { |
|
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
397 // id |
|
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
398 String id = actor.getId(); |
|
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
399 if (id != null) { |
|
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
400 actorNode.setProperty("id", id); |
|
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
401 } |
|
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
402 // name |
|
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
403 String name = actor.getName(); |
|
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
404 if (name != null) { |
|
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
405 actorNode.setProperty("name", name); |
|
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
406 } |
|
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
407 // uri |
|
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
408 String uri = actor.getUri(); |
|
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
409 if (uri != null) { |
|
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
410 actorNode.setProperty("uri", uri); |
|
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
411 } |
|
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
412 tx.success(); |
|
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
413 } finally { |
|
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
414 tx.finish(); |
|
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
415 } |
|
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
416 Actor storedActor = createActorFromNode(actorNode); |
|
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
417 return storedActor; |
| 22 | 418 } |
|
32
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
419 |
|
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
420 /** |
|
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
421 * Deletes the given Actor. |
|
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
422 * |
|
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
423 * @param actor |
|
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
424 */ |
|
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
425 public void deleteActor(Actor actor) { |
|
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
426 String uri = actor.getUriString(); |
|
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
427 Index<Node> idx; |
|
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
428 if (actor.isGroup()) { |
|
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
429 idx = getNodeIndex(NodeTypes.GROUP); |
|
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
430 } else { |
|
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
431 idx = getNodeIndex(NodeTypes.PERSON); |
|
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
432 } |
|
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
433 Node actorNode = idx.get("uri", uri).getSingle(); |
|
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
434 if (actorNode != null) { |
|
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
435 // delete relations |
|
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
436 Transaction tx = graphDb.beginTx(); |
|
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
437 try { |
|
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
438 for (Relationship rel : actorNode.getRelationships()) { |
|
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
439 rel.delete(); |
|
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
440 } |
|
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
441 if (!actorNode.hasRelationship()) { |
|
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
442 // this shouldn't happen |
|
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
443 deleteNode(actorNode); |
|
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
444 } else { |
|
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
445 logger.error("deleteActor: unable to delete: Node still has relations."); |
|
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
446 } |
|
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
447 tx.success(); |
|
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
448 } finally { |
|
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
449 tx.finish(); |
|
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
450 } |
|
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
451 } |
|
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
452 } |
|
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
453 |
| 22 | 454 /** |
|
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
455 * Returns the Annotation with the given id. |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
456 * |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
457 * @param id |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
458 * @return |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
459 */ |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
460 public Annotation getAnnotationById(String id) { |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
461 Node annotNode = getNodeIndex(NodeTypes.ANNOTATION).get("id", id).getSingle(); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
462 Annotation annot = createAnnotationFromNode(annotNode); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
463 return annot; |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
464 } |
| 6 | 465 |
|
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
466 /** |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
467 * Returns an Annotation object from an annotation-Node. |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
468 * |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
469 * @param annotNode |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
470 * @return |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
471 */ |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
472 public Annotation createAnnotationFromNode(Node annotNode) { |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
473 Annotation annot = new Annotation(); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
474 annot.setUri((String) annotNode.getProperty("id", null)); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
475 annot.setBodyText((String) annotNode.getProperty("bodyText", null)); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
476 annot.setBodyUri((String) annotNode.getProperty("bodyUri", null)); |
| 16 | 477 /* |
| 45 | 478 * get annotation target and resource from relation |
| 16 | 479 */ |
| 45 | 480 for (Relationship rel : annotNode.getRelationships(RelationTypes.ANNOTATES)) { |
| 481 Node target = rel.getEndNode(); | |
| 482 String type = (String) target.getProperty("TYPE"); | |
| 483 if (type.equals("TARGET")) { | |
|
48
0e00bf8e27fb
targets and resources of Annotation object are objects now.
casties
parents:
45
diff
changeset
|
484 annot.setTarget(new Target((String) target.getProperty("uri", null))); |
| 45 | 485 } else if (type.equals("RESOURCE")) { |
|
48
0e00bf8e27fb
targets and resources of Annotation object are objects now.
casties
parents:
45
diff
changeset
|
486 annot.setResource(new Resource((String) target.getProperty("uri", null))); |
| 45 | 487 } |
| 488 } | |
|
48
0e00bf8e27fb
targets and resources of Annotation object are objects now.
casties
parents:
45
diff
changeset
|
489 if (annot.getTarget() == null) { |
|
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
490 logger.error("annotation " + annotNode + " has no target node!"); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
491 } |
| 45 | 492 // get fragment from attribute |
|
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
493 annot.setTargetFragment((String) annotNode.getProperty("targetFragment", null)); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
494 String ft = (String) annotNode.getProperty("fragmentType", null); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
495 if (ft != null) { |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
496 annot.setFragmentType(FragmentTypes.valueOf(ft)); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
497 } |
| 16 | 498 /* |
| 499 * get creator from relation | |
| 500 */ | |
|
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
501 Relationship creatorRel = getRelation(annotNode, RelationTypes.CREATED, null); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
502 if (creatorRel != null) { |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
503 Node creatorNode = creatorRel.getStartNode(); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
504 Actor creator = createActorFromNode(creatorNode); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
505 annot.setCreator(creator); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
506 } else { |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
507 logger.error("annotation " + annotNode + " has no creator node!"); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
508 } |
| 16 | 509 /* |
| 510 * get creation date | |
| 511 */ | |
|
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
512 annot.setCreated((String) annotNode.getProperty("created", null)); |
| 16 | 513 /* |
| 514 * get permissions | |
| 515 */ | |
|
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
516 Relationship adminRel = getRelation(annotNode, RelationTypes.PERMITS_ADMIN, null); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
517 if (adminRel != null) { |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
518 Node adminNode = adminRel.getEndNode(); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
519 Actor admin = createActorFromNode(adminNode); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
520 annot.setAdminPermission(admin); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
521 } |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
522 Relationship deleteRel = getRelation(annotNode, RelationTypes.PERMITS_DELETE, null); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
523 if (deleteRel != null) { |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
524 Node deleteNode = deleteRel.getEndNode(); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
525 Actor delete = createActorFromNode(deleteNode); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
526 annot.setDeletePermission(delete); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
527 } |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
528 Relationship updateRel = getRelation(annotNode, RelationTypes.PERMITS_UPDATE, null); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
529 if (updateRel != null) { |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
530 Node updateNode = updateRel.getEndNode(); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
531 Actor update = createActorFromNode(updateNode); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
532 annot.setUpdatePermission(update); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
533 } |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
534 Relationship readRel = getRelation(annotNode, RelationTypes.PERMITS_READ, null); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
535 if (readRel != null) { |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
536 Node readNode = readRel.getEndNode(); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
537 Actor read = createActorFromNode(readNode); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
538 annot.setReadPermission(read); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
539 } |
| 16 | 540 /* |
| 541 * get tags | |
| 542 */ | |
| 543 Set<String> tags = new HashSet<String>(); | |
| 544 for (Relationship rel : annotNode.getRelationships(RelationTypes.HAS_TAG)) { | |
| 545 String tag = (String) rel.getEndNode().getProperty("name", null); | |
| 546 if (tag != null) { | |
| 547 tags.add(tag); | |
| 548 } | |
| 549 } | |
| 550 annot.setTags(tags); | |
| 4 | 551 |
|
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
552 return annot; |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
553 } |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
554 |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
555 /** |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
556 * Returns an Actor object from a node. |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
557 * |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
558 * @param actorNode |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
559 * @return |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
560 */ |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
561 protected Actor createActorFromNode(Node actorNode) { |
|
32
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
562 if (actorNode == null) return null; |
| 15 | 563 String id = (String) actorNode.getProperty("id", null); |
|
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
564 String uri = (String) actorNode.getProperty("uri", null); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
565 String name = (String) actorNode.getProperty("name", null); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
566 String type = (String) actorNode.getProperty("TYPE", null); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
567 if (type != null && type.equals("PERSON")) { |
| 15 | 568 return new Person(id, uri, name); |
|
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
569 } else if (type != null && type.equals("GROUP")) { |
| 15 | 570 return new Group(id, uri, name); |
|
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
571 } |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
572 return null; |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
573 } |
|
32
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
574 |
| 28 | 575 public Tag createTagFromNode(Node tagNode) { |
|
32
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
576 if (tagNode == null) return null; |
|
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
577 String name = (String) tagNode.getProperty("name", null); |
|
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
578 String uri = (String) tagNode.getProperty("uri", null); |
|
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
579 String id = (String) tagNode.getProperty("id", null); |
| 28 | 580 |
|
32
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
581 return new Tag(id, uri, name); |
|
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
582 |
|
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
583 } |
| 4 | 584 |
| 43 | 585 /** |
| 586 * @param resourceNode | |
| 587 * @return | |
| 588 */ | |
| 589 public Resource createResourceFromNode(Node resourceNode) { | |
| 590 return (Resource) createUriFromNode(resourceNode); | |
| 591 } | |
|
59
e2f86ef9b871
make annotation uri in store configurable. fix npe with no tags.
casties
parents:
48
diff
changeset
|
592 |
| 43 | 593 /** |
| 594 * @param targetNode | |
| 595 * @return | |
| 596 */ | |
| 597 public Target createTargetFromNode(Node targetNode) { | |
| 598 return (Target) createUriFromNode(targetNode); | |
| 599 } | |
|
59
e2f86ef9b871
make annotation uri in store configurable. fix npe with no tags.
casties
parents:
48
diff
changeset
|
600 |
| 42 | 601 protected Uri createUriFromNode(Node uriNode) { |
| 602 if (uriNode == null) return null; | |
| 603 String uri = (String) uriNode.getProperty("uri", null); | |
| 604 String type = (String) uriNode.getProperty("TYPE", null); | |
| 605 if (type != null && type.equals("TARGET")) { | |
| 606 return new Target(uri); | |
| 607 } else if (type != null && type.equals("RESOURCE")) { | |
| 608 return new Resource(uri); | |
| 609 } | |
| 610 return null; | |
| 611 } | |
| 612 | |
|
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
613 /** |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
614 * Store a new annotation in the store or update an existing one. Returns |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
615 * the stored annotation. |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
616 * |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
617 * @param annot |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
618 * @return |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
619 */ |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
620 public Annotation storeAnnotation(Annotation annot) { |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
621 Node annotNode = null; |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
622 Transaction tx = graphDb.beginTx(); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
623 try { |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
624 /* |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
625 * create or get the annotation |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
626 */ |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
627 String id = annot.getUri(); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
628 if (id == null) { |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
629 id = createRessourceURI("annot:"); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
630 } |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
631 annotNode = getOrCreateAnnotationNode(id); |
| 4 | 632 |
|
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
633 /* |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
634 * the annotation body |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
635 */ |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
636 String bodyText = annot.getBodyText(); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
637 if (bodyText != null) { |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
638 annotNode.setProperty("bodyText", bodyText); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
639 } |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
640 String bodyUri = annot.getBodyUri(); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
641 if (bodyUri != null) { |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
642 annotNode.setProperty("bodyUri", bodyUri); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
643 } |
| 4 | 644 |
|
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
645 /* |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
646 * the annotation target |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
647 */ |
|
48
0e00bf8e27fb
targets and resources of Annotation object are objects now.
casties
parents:
45
diff
changeset
|
648 Target target = annot.getTarget(); |
|
40
03e0f7574224
saving and loading resource targets should work now (no searching yet)
casties
parents:
36
diff
changeset
|
649 Node targetNode = null; |
|
48
0e00bf8e27fb
targets and resources of Annotation object are objects now.
casties
parents:
45
diff
changeset
|
650 if (target != null) { |
|
0e00bf8e27fb
targets and resources of Annotation object are objects now.
casties
parents:
45
diff
changeset
|
651 targetNode = getOrCreateUriNode(target.getUri(), NodeTypes.TARGET); |
|
40
03e0f7574224
saving and loading resource targets should work now (no searching yet)
casties
parents:
36
diff
changeset
|
652 getOrCreateRelation(annotNode, RelationTypes.ANNOTATES, targetNode); |
|
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
653 } |
| 4 | 654 |
|
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
655 /* |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
656 * The fragment part of the annotation target. |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
657 */ |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
658 String targetFragment = annot.getTargetFragment(); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
659 FragmentTypes fragmentType = annot.getFragmentType(); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
660 if (targetFragment != null) { |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
661 annotNode.setProperty("targetFragment", targetFragment); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
662 annotNode.setProperty("fragmentType", fragmentType.name()); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
663 } |
| 4 | 664 |
|
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
665 /* |
|
40
03e0f7574224
saving and loading resource targets should work now (no searching yet)
casties
parents:
36
diff
changeset
|
666 * the annotation resource |
|
03e0f7574224
saving and loading resource targets should work now (no searching yet)
casties
parents:
36
diff
changeset
|
667 */ |
|
48
0e00bf8e27fb
targets and resources of Annotation object are objects now.
casties
parents:
45
diff
changeset
|
668 Resource resource = annot.getResource(); |
|
0e00bf8e27fb
targets and resources of Annotation object are objects now.
casties
parents:
45
diff
changeset
|
669 if (resource != null) { |
|
0e00bf8e27fb
targets and resources of Annotation object are objects now.
casties
parents:
45
diff
changeset
|
670 Node resourceNode = getOrCreateUriNode(resource.getUri(), NodeTypes.RESOURCE); |
|
0e00bf8e27fb
targets and resources of Annotation object are objects now.
casties
parents:
45
diff
changeset
|
671 getOrCreateRelation(annotNode, RelationTypes.ANNOTATES, resourceNode); |
|
0e00bf8e27fb
targets and resources of Annotation object are objects now.
casties
parents:
45
diff
changeset
|
672 getOrCreateRelation(targetNode, RelationTypes.PART_OF, resourceNode); |
|
40
03e0f7574224
saving and loading resource targets should work now (no searching yet)
casties
parents:
36
diff
changeset
|
673 } |
|
03e0f7574224
saving and loading resource targets should work now (no searching yet)
casties
parents:
36
diff
changeset
|
674 |
|
03e0f7574224
saving and loading resource targets should work now (no searching yet)
casties
parents:
36
diff
changeset
|
675 /* |
|
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
676 * The creator of this annotation. |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
677 */ |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
678 Actor creator = annot.getCreator(); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
679 if (creator != null) { |
| 15 | 680 Node creatorNode = getOrCreateActorNode(creator); |
|
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
681 getOrCreateRelation(creatorNode, RelationTypes.CREATED, annotNode); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
682 } |
| 12 | 683 |
|
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
684 /* |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
685 * The creation date of this annotation. |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
686 */ |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
687 String created = annot.getCreated(); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
688 if (created != null) { |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
689 annotNode.setProperty("created", created); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
690 } |
| 4 | 691 |
|
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
692 /* |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
693 * Permissions for this annotation. |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
694 */ |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
695 setPermissionRelation(annotNode, RelationTypes.PERMITS_ADMIN, annot.getAdminPermission()); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
696 setPermissionRelation(annotNode, RelationTypes.PERMITS_DELETE, annot.getDeletePermission()); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
697 setPermissionRelation(annotNode, RelationTypes.PERMITS_UPDATE, annot.getUpdatePermission()); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
698 setPermissionRelation(annotNode, RelationTypes.PERMITS_READ, annot.getReadPermission()); |
| 6 | 699 |
| 16 | 700 /* |
| 701 * Tags on this annotation. | |
| 702 */ | |
| 703 Set<String> newTags = annot.getTags(); | |
| 704 // we ignore existing tags if tags == null | |
| 705 if (newTags != null) { | |
| 706 List<Relationship> oldHasTags = new ArrayList<Relationship>(); | |
| 707 for (Relationship rel : annotNode.getRelationships(RelationTypes.HAS_TAG)) { | |
| 708 oldHasTags.add(rel); | |
| 709 } | |
| 710 // adjust to new tags | |
| 711 if (newTags.isEmpty()) { | |
| 712 // remove old tags | |
| 713 if (!oldHasTags.isEmpty()) { | |
| 714 for (Relationship rel : oldHasTags) { | |
| 715 rel.delete(); | |
| 716 // TODO: should we delete orphan nodes too? | |
| 717 } | |
| 718 } | |
| 719 } else { | |
| 720 if (!oldHasTags.isEmpty()) { | |
| 721 // adjust old tags | |
| 722 for (Relationship rel : oldHasTags) { | |
| 723 String oldTag = (String) rel.getEndNode().getProperty("name", null); | |
| 724 if (newTags.contains(oldTag)) { | |
| 725 // tag exists | |
| 726 newTags.remove(oldTag); | |
| 727 } else { | |
| 728 // tag exists no longer | |
| 729 rel.delete(); | |
| 730 // TODO: should we delete orphan nodes too? | |
| 731 } | |
| 732 } | |
| 733 } | |
| 734 if (!newTags.isEmpty()) { | |
| 735 // still tags to add | |
| 736 for (String tag : newTags) { | |
| 737 // create new tag | |
|
32
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
738 Node tagNode = getOrCreateTagNode(new Tag(null, null, tag)); |
| 16 | 739 getOrCreateRelation(annotNode, RelationTypes.HAS_TAG, tagNode); |
| 740 } | |
| 741 } | |
| 742 | |
| 743 } | |
| 744 } | |
|
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
745 tx.success(); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
746 } finally { |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
747 tx.finish(); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
748 } |
| 12 | 749 |
|
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
750 // re-read and return annotation |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
751 Annotation storedAnnot = createAnnotationFromNode(annotNode); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
752 return storedAnnot; |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
753 } |
| 4 | 754 |
|
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
755 /** |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
756 * Deletes the annotation with the given id. |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
757 * |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
758 * @param id |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
759 */ |
|
32
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
760 public void deleteAnnotationById(String id) { |
|
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
761 Node annotNode = getNodeIndex(NodeTypes.ANNOTATION).get("id", id).getSingle(); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
762 if (annotNode != null) { |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
763 // delete related objects |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
764 Transaction tx = graphDb.beginTx(); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
765 try { |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
766 for (Relationship rel : annotNode.getRelationships()) { |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
767 // delete relation and the related node if it has no other |
|
32
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
768 // relations and is not permanent |
|
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
769 Node other = rel.getOtherNode(annotNode); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
770 rel.delete(); |
|
32
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
771 if (!(other.hasRelationship() || permanentNodeTypes.contains(other.getProperty("TYPE", null)))) { |
|
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
772 deleteNode(other); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
773 } |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
774 } |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
775 if (!annotNode.hasRelationship()) { |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
776 deleteNode(annotNode); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
777 } else { |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
778 logger.error("deleteById: unable to delete: Node still has relations."); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
779 } |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
780 tx.success(); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
781 } finally { |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
782 tx.finish(); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
783 } |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
784 } |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
785 } |
| 4 | 786 |
|
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
787 /** |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
788 * Returns all annotations with the given uri and/or user. |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
789 * |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
790 * @param uri |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
791 * @param userUri |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
792 * @return |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
793 */ |
|
63
9f8c9611848a
fixed bug with new rectangle shapes. added limit, offset and sortBy parameters to annotator/ and annotator/search.
casties
parents:
59
diff
changeset
|
794 public List<Annotation> searchAnnotationByUriUser(String targetUri, String userUri) { |
|
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
795 List<Annotation> annotations = new ArrayList<Annotation>(); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
796 if (targetUri != null) { |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
797 // there should be only one |
|
63
9f8c9611848a
fixed bug with new rectangle shapes. added limit, offset and sortBy parameters to annotator/ and annotator/search.
casties
parents:
59
diff
changeset
|
798 Node target = getNodeFromIndex("uri", targetUri, NodeTypes.TARGET); |
|
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
799 if (target != null) { |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
800 Iterable<Relationship> relations = target.getRelationships(RelationTypes.ANNOTATES); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
801 for (Relationship relation : relations) { |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
802 Node ann = relation.getStartNode(); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
803 if (ann.getProperty("TYPE", "").equals("ANNOTATION")) { |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
804 Annotation annot = createAnnotationFromNode(ann); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
805 annotations.add(annot); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
806 } else { |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
807 logger.error("ANNOTATES relation does not start with ANNOTATION: " + ann); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
808 } |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
809 } |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
810 } |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
811 } |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
812 if (userUri != null) { |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
813 // there should be only one |
| 15 | 814 Node person = getPersonNodeByUri(userUri); |
|
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
815 if (person != null) { |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
816 Iterable<Relationship> relations = person.getRelationships(RelationTypes.CREATED); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
817 for (Relationship relation : relations) { |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
818 Node ann = relation.getEndNode(); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
819 if (ann.getProperty("TYPE", "").equals("ANNOTATION")) { |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
820 Annotation annot = createAnnotationFromNode(ann); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
821 annotations.add(annot); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
822 } else { |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
823 logger.error("CREATED relation does not end with ANNOTATION: " + ann); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
824 } |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
825 } |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
826 } |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
827 } |
| 16 | 828 // TODO: if both uri and user are given we should intersect |
|
63
9f8c9611848a
fixed bug with new rectangle shapes. added limit, offset and sortBy parameters to annotator/ and annotator/search.
casties
parents:
59
diff
changeset
|
829 |
|
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
830 return annotations; |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
831 } |
| 5 | 832 |
| 16 | 833 /** |
| 834 * Returns Relationship of type from Node start to Node end. Creates one if | |
| 835 * it doesn't exist. | |
| 836 * | |
| 837 * @param start | |
| 838 * @param type | |
| 839 * @param end | |
| 840 * @return | |
| 841 */ | |
|
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
842 protected Relationship getOrCreateRelation(Node start, RelationshipType type, Node end) { |
|
40
03e0f7574224
saving and loading resource targets should work now (no searching yet)
casties
parents:
36
diff
changeset
|
843 if (start == null || end == null) return null; |
|
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
844 if (start.hasRelationship()) { |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
845 // there are relations |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
846 Iterable<Relationship> rels = start.getRelationships(type, Direction.OUTGOING); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
847 for (Relationship rel : rels) { |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
848 if (rel.getEndNode().equals(end)) { |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
849 // relation exists |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
850 return rel; |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
851 } |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
852 } |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
853 } |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
854 // create new one |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
855 Relationship rel; |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
856 Transaction tx = graphDb.beginTx(); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
857 try { |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
858 rel = start.createRelationshipTo(end, type); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
859 tx.success(); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
860 } finally { |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
861 tx.finish(); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
862 } |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
863 return rel; |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
864 } |
| 12 | 865 |
|
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
866 protected Node getOrCreateAnnotationNode(String id) { |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
867 Index<Node> idx = getNodeIndex(NodeTypes.ANNOTATION); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
868 IndexHits<Node> annotations = idx.get("id", id); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
869 Node annotation = annotations.getSingle(); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
870 if (annotation == null) { |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
871 // does not exist yet |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
872 Transaction tx = graphDb.beginTx(); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
873 try { |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
874 annotation = graphDb.createNode(); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
875 annotation.setProperty("TYPE", NodeTypes.ANNOTATION.name()); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
876 annotation.setProperty("id", id); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
877 idx.add(annotation, "id", id); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
878 tx.success(); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
879 } finally { |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
880 tx.finish(); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
881 } |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
882 } |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
883 return annotation; |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
884 } |
| 6 | 885 |
|
48
0e00bf8e27fb
targets and resources of Annotation object are objects now.
casties
parents:
45
diff
changeset
|
886 protected Node getOrCreateUriNode(String uri, NodeTypes type) { |
|
40
03e0f7574224
saving and loading resource targets should work now (no searching yet)
casties
parents:
36
diff
changeset
|
887 Index<Node> idx = getNodeIndex(type); |
|
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
888 IndexHits<Node> targets = idx.get("uri", uri); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
889 Node target = targets.getSingle(); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
890 if (target == null) { |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
891 // does not exist yet |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
892 Transaction tx = graphDb.beginTx(); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
893 try { |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
894 target = graphDb.createNode(); |
|
40
03e0f7574224
saving and loading resource targets should work now (no searching yet)
casties
parents:
36
diff
changeset
|
895 target.setProperty("TYPE", type.name()); |
|
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
896 target.setProperty("uri", uri); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
897 idx.add(target, "uri", uri); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
898 tx.success(); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
899 } finally { |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
900 tx.finish(); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
901 } |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
902 } |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
903 return target; |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
904 } |
| 4 | 905 |
| 22 | 906 protected Node getActorNode(Actor actor) { |
| 907 // Person/Group is identified by URI or id | |
| 908 String uri = actor.getUriString(); | |
| 909 Index<Node> idx; | |
| 910 if (actor.isGroup()) { | |
| 911 idx = getNodeIndex(NodeTypes.GROUP); | |
| 912 } else { | |
| 913 idx = getNodeIndex(NodeTypes.PERSON); | |
| 914 } | |
| 915 IndexHits<Node> persons = idx.get("uri", uri); | |
| 916 Node person = persons.getSingle(); | |
| 917 return person; | |
| 918 } | |
|
32
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
919 |
| 15 | 920 protected Node getOrCreateActorNode(Actor actor) { |
| 921 // Person/Group is identified by URI or id | |
|
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
922 String uri = actor.getUriString(); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
923 String name = actor.getName(); |
| 15 | 924 String id = actor.getId(); |
| 925 Index<Node> idx; | |
| 926 if (actor.isGroup()) { | |
| 927 idx = getNodeIndex(NodeTypes.GROUP); | |
| 928 } else { | |
| 929 idx = getNodeIndex(NodeTypes.PERSON); | |
| 930 } | |
|
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
931 IndexHits<Node> persons = idx.get("uri", uri); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
932 Node person = persons.getSingle(); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
933 if (person == null) { |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
934 // does not exist yet |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
935 Transaction tx = graphDb.beginTx(); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
936 try { |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
937 person = graphDb.createNode(); |
| 15 | 938 if (actor.isGroup()) { |
| 939 person.setProperty("TYPE", NodeTypes.GROUP.name()); | |
| 940 } else { | |
| 16 | 941 person.setProperty("TYPE", NodeTypes.PERSON.name()); |
| 15 | 942 } |
|
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
943 person.setProperty("uri", uri); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
944 idx.add(person, "uri", uri); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
945 if (name != null) { |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
946 person.setProperty("name", name); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
947 } |
| 15 | 948 if (id != null) { |
| 949 person.setProperty("id", id); | |
| 950 } | |
|
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
951 tx.success(); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
952 } finally { |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
953 tx.finish(); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
954 } |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
955 } |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
956 return person; |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
957 } |
| 4 | 958 |
| 28 | 959 protected Node getOrCreateTagNode(Tag inTag) { |
| 16 | 960 Index<Node> idx = getNodeIndex(NodeTypes.TAG); |
| 28 | 961 String tagname = inTag.getName(); |
| 16 | 962 IndexHits<Node> tags = idx.get("name", tagname); |
| 963 Node tag = tags.getSingle(); | |
| 964 if (tag == null) { | |
| 965 // does not exist yet | |
| 966 Transaction tx = graphDb.beginTx(); | |
| 967 try { | |
| 968 tag = graphDb.createNode(); | |
| 969 tag.setProperty("TYPE", NodeTypes.TAG.name()); | |
| 970 tag.setProperty("name", tagname); | |
| 971 idx.add(tag, "name", tagname); | |
|
32
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
972 |
| 28 | 973 tag.setProperty("id", inTag.getId()); |
| 974 tag.setProperty("uri", inTag.getUri()); | |
| 975 idx.add(tag, "uri", inTag.getUri()); | |
|
32
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
976 |
| 16 | 977 tx.success(); |
| 978 } finally { | |
| 979 tx.finish(); | |
| 980 } | |
| 981 } | |
| 982 return tag; | |
| 983 } | |
| 984 | |
|
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
985 /** |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
986 * Create or update permissions relations for an annotation. |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
987 * |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
988 * @param annotNode |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
989 * @param type |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
990 * @param annot |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
991 */ |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
992 protected void setPermissionRelation(Node annotNode, RelationTypes type, Actor actor) { |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
993 Node newActorNode = null; |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
994 if (actor != null) { |
| 15 | 995 newActorNode = getOrCreateActorNode(actor); |
|
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
996 } |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
997 Relationship rel = getRelation(annotNode, type, null); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
998 if (rel != null) { |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
999 // relation exists |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1000 Node oldActorNode = rel.getEndNode(); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1001 if (!oldActorNode.equals(newActorNode)) { |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1002 // new admin is different |
| 33 | 1003 Transaction tx = graphDb.beginTx(); |
| 1004 try { | |
| 1005 rel.delete(); | |
| 1006 tx.success(); | |
| 1007 } finally { | |
| 1008 tx.finish(); | |
| 1009 } | |
|
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1010 if (newActorNode != null) { |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1011 rel = getOrCreateRelation(annotNode, type, newActorNode); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1012 } |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1013 } |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1014 } else { |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1015 // no relation yet |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1016 if (newActorNode != null) { |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1017 rel = getOrCreateRelation(annotNode, type, newActorNode); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1018 } |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1019 } |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1020 } |
| 4 | 1021 |
|
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1022 /** |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1023 * Unindexes and deletes given Node if it has no relations. |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1024 * |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1025 * @param node |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1026 */ |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1027 protected void deleteNode(Node node) { |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1028 Transaction tx = graphDb.beginTx(); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1029 try { |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1030 if (node.hasRelationship()) { |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1031 logger.error("deleteNode: unable to delete: Node still has relations."); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1032 } else { |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1033 String ts = (String) node.getProperty("TYPE", null); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1034 try { |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1035 NodeTypes type = NodeTypes.valueOf(ts); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1036 getNodeIndex(type).remove(node); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1037 } catch (Exception e) { |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1038 logger.error("deleteNode: unable to get TYPE of node: " + node); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1039 } |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1040 node.delete(); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1041 } |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1042 tx.success(); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1043 } finally { |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1044 tx.finish(); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1045 } |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1046 } |
| 4 | 1047 |
| 16 | 1048 /** |
| 1049 * returns the (first) Relationship of RelationTypes type from Node start. | |
| 1050 * | |
| 15 | 1051 * @param start |
| 1052 * @param type | |
| 1053 * @param direction | |
| 1054 * @return | |
| 1055 */ | |
|
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1056 protected Relationship getRelation(Node start, RelationTypes type, Direction direction) { |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1057 Iterable<Relationship> rels; |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1058 if (direction == null) { |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1059 // ignore direction |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1060 rels = start.getRelationships(type); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1061 } else { |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1062 rels = start.getRelationships(type, direction); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1063 } |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1064 for (Relationship rel : rels) { |
| 16 | 1065 // just the first one |
|
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1066 return rel; |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1067 } |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1068 return null; |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1069 } |
| 4 | 1070 |
|
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1071 /** |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1072 * Erzeuge eine urn aus der aktuellen Zeit in millis |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1073 * |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1074 * @return |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1075 */ |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1076 private String createRessourceURI(String prefix) { |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1077 Calendar cal = Calendar.getInstance(); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1078 long time = cal.getTimeInMillis(); |
|
59
e2f86ef9b871
make annotation uri in store configurable. fix npe with no tags.
casties
parents:
48
diff
changeset
|
1079 return String.format("%s%s%s", ANNOTATION_URI_PREFIX, prefix, time); |
|
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1080 } |
| 4 | 1081 |
|
32
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
1082 public List<Annotation> getAnnotationsByTag(String tagUri) { |
|
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
1083 ArrayList<Annotation> ret = new ArrayList<Annotation>(); |
|
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
1084 Node tag = getTagNodeByUri(tagUri); |
|
59
e2f86ef9b871
make annotation uri in store configurable. fix npe with no tags.
casties
parents:
48
diff
changeset
|
1085 if (tag != null) { |
|
e2f86ef9b871
make annotation uri in store configurable. fix npe with no tags.
casties
parents:
48
diff
changeset
|
1086 Iterable<Relationship> rels = tag.getRelationships(Direction.INCOMING, RelationTypes.HAS_TAG); |
|
e2f86ef9b871
make annotation uri in store configurable. fix npe with no tags.
casties
parents:
48
diff
changeset
|
1087 for (Relationship rel : rels) { |
|
e2f86ef9b871
make annotation uri in store configurable. fix npe with no tags.
casties
parents:
48
diff
changeset
|
1088 Node node = rel.getStartNode(); |
|
e2f86ef9b871
make annotation uri in store configurable. fix npe with no tags.
casties
parents:
48
diff
changeset
|
1089 ret.add(createAnnotationFromNode(node)); |
|
e2f86ef9b871
make annotation uri in store configurable. fix npe with no tags.
casties
parents:
48
diff
changeset
|
1090 } |
|
32
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
1091 } |
|
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
1092 return ret; |
|
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
1093 } |
| 28 | 1094 |
| 42 | 1095 public List<Annotation> getAnnotationsByResource(String resourceUri) { |
| 1096 ArrayList<Annotation> ret = new ArrayList<Annotation>(); | |
|
59
e2f86ef9b871
make annotation uri in store configurable. fix npe with no tags.
casties
parents:
48
diff
changeset
|
1097 Node res = getNodeFromIndex("uri", resourceUri, NodeTypes.RESOURCE); |
|
e2f86ef9b871
make annotation uri in store configurable. fix npe with no tags.
casties
parents:
48
diff
changeset
|
1098 if (res != null) { |
|
e2f86ef9b871
make annotation uri in store configurable. fix npe with no tags.
casties
parents:
48
diff
changeset
|
1099 Iterable<Relationship> rels = res.getRelationships(Direction.INCOMING, RelationTypes.ANNOTATES); |
|
e2f86ef9b871
make annotation uri in store configurable. fix npe with no tags.
casties
parents:
48
diff
changeset
|
1100 for (Relationship rel : rels) { |
|
e2f86ef9b871
make annotation uri in store configurable. fix npe with no tags.
casties
parents:
48
diff
changeset
|
1101 Node an = rel.getStartNode(); |
|
e2f86ef9b871
make annotation uri in store configurable. fix npe with no tags.
casties
parents:
48
diff
changeset
|
1102 Node rn = rel.getEndNode(); |
|
e2f86ef9b871
make annotation uri in store configurable. fix npe with no tags.
casties
parents:
48
diff
changeset
|
1103 if (rn.getProperty("TYPE", "").equals("RESOURCE")) { |
|
e2f86ef9b871
make annotation uri in store configurable. fix npe with no tags.
casties
parents:
48
diff
changeset
|
1104 logger.error("getAnnotationsByResource got ANNOTATES != RESOURCE"); |
|
e2f86ef9b871
make annotation uri in store configurable. fix npe with no tags.
casties
parents:
48
diff
changeset
|
1105 } |
|
e2f86ef9b871
make annotation uri in store configurable. fix npe with no tags.
casties
parents:
48
diff
changeset
|
1106 ret.add(createAnnotationFromNode(an)); |
| 43 | 1107 } |
| 42 | 1108 } |
| 1109 return ret; | |
| 1110 } | |
| 1111 | |
| 4 | 1112 } |
