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