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