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