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