Mercurial > hg > AnnotationManagerN4J
annotate src/main/java/de/mpiwg/itgroup/annotations/neo4j/AnnotationStore.java @ 101:7268c3ca025b
make admin ui view of all annotations scale better.
author | casties |
---|---|
date | Fri, 13 Feb 2015 18:10:11 +0100 |
parents | 5a764c625290 |
children |
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; |
75 | 35 import java.util.logging.Logger; |
4 | 36 |
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 | |
101 | 64 protected static Logger logger = Logger.getLogger(AnnotationStore.class.getCanonicalName()); |
14
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 /** |
101 | 259 * Returns the total number of Annotations. |
260 * | |
261 * @return number of annotations | |
262 */ | |
263 public int getAnnotationCount() { | |
264 int num = -1; | |
265 Index<Node> idx = getNodeIndex(NodeTypes.ANNOTATION); | |
266 try (Transaction tx = graphDb.beginTx()) { | |
267 IndexHits<Node> annotNodes = idx.query("id", "*"); | |
268 num = annotNodes.size(); | |
269 tx.success(); | |
270 } | |
271 return num; | |
272 } | |
273 | |
274 /** | |
59
e2f86ef9b871
make annotation uri in store configurable. fix npe with no tags.
casties
parents:
48
diff
changeset
|
275 * Returns List of Annotations. Key has to be indexed. |
31 | 276 * |
277 * @param key | |
278 * @param query | |
101 | 279 * @param limit |
280 * @param offset | |
31 | 281 * @return |
282 */ | |
101 | 283 public List<Annotation> getAnnotations(String key, String query, int limit, int offset) { |
284 long ts = System.currentTimeMillis(); | |
31 | 285 ArrayList<Annotation> annotations = new ArrayList<Annotation>(); |
286 Index<Node> idx = getNodeIndex(NodeTypes.ANNOTATION); | |
287 if (key == null) { | |
288 key = "id"; | |
289 query = "*"; | |
290 } | |
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
|
291 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
|
292 IndexHits<Node> annotNodes = idx.query(key, query); |
101 | 293 int cnt = 0; |
294 int max = offset + limit; | |
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
|
295 for (Node annotNode : annotNodes) { |
101 | 296 cnt += 1; |
297 if (cnt < offset) continue; | |
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
|
298 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
|
299 annotations.add(annotation); |
101 | 300 if (limit > 0 && cnt >= max) { |
301 annotNodes.close(); | |
302 break; | |
303 } | |
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
|
304 } |
5b568de5ee0d
updated to new Neo4J version 2.0. doesn't use new features. problems with neo4j admin web ui.
casties
parents:
63
diff
changeset
|
305 tx.success(); |
31 | 306 } |
101 | 307 logger.finer("got "+annotations.size()+" annotations in "+(System.currentTimeMillis()-ts)+"ms"); |
31 | 308 return annotations; |
309 } | |
310 | |
311 /** | |
59
e2f86ef9b871
make annotation uri in store configurable. fix npe with no tags.
casties
parents:
48
diff
changeset
|
312 * Returns List of Tags. Key has to be indexed. |
28 | 313 * |
314 * @param key | |
315 * @param query | |
316 * @return | |
317 */ | |
318 public List<Tag> getTags(String key, String query) { | |
319 ArrayList<Tag> tags = new ArrayList<Tag>(); | |
320 Index<Node> idx = getNodeIndex(NodeTypes.TAG); | |
321 if (key == null) { | |
322 key = "uri"; | |
323 query = "*"; | |
324 } | |
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
|
325 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
|
326 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
|
327 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
|
328 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
|
329 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
|
330 } |
5b568de5ee0d
updated to new Neo4J version 2.0. doesn't use new features. problems with neo4j admin web ui.
casties
parents:
63
diff
changeset
|
331 tx.success(); |
28 | 332 } |
333 return tags; | |
334 } | |
18 | 335 |
32
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
336 /** |
15 | 337 * Returns List of Groups the person is member of. |
338 * | |
339 * @param person | |
340 * @return | |
341 */ | |
342 public List<Group> getGroupsForPersonNode(Node person) { | |
343 ArrayList<Group> groups = new ArrayList<Group>(); | |
81
3be57c18c693
more fixing bugs with transactions thanks to neo4j 2 :-(
casties
parents:
76
diff
changeset
|
344 try (Transaction tx = graphDb.beginTx()) { |
3be57c18c693
more fixing bugs with transactions thanks to neo4j 2 :-(
casties
parents:
76
diff
changeset
|
345 Iterable<Relationship> rels = person.getRelationships(RelationTypes.MEMBER_OF); |
3be57c18c693
more fixing bugs with transactions thanks to neo4j 2 :-(
casties
parents:
76
diff
changeset
|
346 for (Relationship rel : rels) { |
3be57c18c693
more fixing bugs with transactions thanks to neo4j 2 :-(
casties
parents:
76
diff
changeset
|
347 Node groupNode = rel.getEndNode(); |
3be57c18c693
more fixing bugs with transactions thanks to neo4j 2 :-(
casties
parents:
76
diff
changeset
|
348 Actor group = createActorFromNode(groupNode); |
3be57c18c693
more fixing bugs with transactions thanks to neo4j 2 :-(
casties
parents:
76
diff
changeset
|
349 // make sure we're getting a group |
3be57c18c693
more fixing bugs with transactions thanks to neo4j 2 :-(
casties
parents:
76
diff
changeset
|
350 if (!(group instanceof Group)) { |
3be57c18c693
more fixing bugs with transactions thanks to neo4j 2 :-(
casties
parents:
76
diff
changeset
|
351 logger.severe("target of MEMBER_OF is not GROUP! rel=" + rel); |
3be57c18c693
more fixing bugs with transactions thanks to neo4j 2 :-(
casties
parents:
76
diff
changeset
|
352 continue; |
3be57c18c693
more fixing bugs with transactions thanks to neo4j 2 :-(
casties
parents:
76
diff
changeset
|
353 } |
3be57c18c693
more fixing bugs with transactions thanks to neo4j 2 :-(
casties
parents:
76
diff
changeset
|
354 groups.add((Group) group); |
3be57c18c693
more fixing bugs with transactions thanks to neo4j 2 :-(
casties
parents:
76
diff
changeset
|
355 } |
3be57c18c693
more fixing bugs with transactions thanks to neo4j 2 :-(
casties
parents:
76
diff
changeset
|
356 tx.success(); |
15 | 357 } |
358 return groups; | |
359 } | |
16 | 360 |
15 | 361 /** |
362 * Returns if person with uri is in Group group. | |
363 * | |
364 * @param person | |
365 * @param group | |
366 * @return | |
367 */ | |
368 public boolean isPersonInGroup(Person person, Group group) { | |
369 Node pn = getPersonNodeByUri(person.getUriString()); | |
68
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
370 if (pn == null) |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
371 return false; |
16 | 372 // optimized version of getGroupsForPersonNode |
67 | 373 try (Transaction tx = graphDb.beginTx()) { |
68
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
374 Iterable<Relationship> rels = pn.getRelationships(RelationTypes.MEMBER_OF); |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
375 for (Relationship rel : rels) { |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
376 Node gn = rel.getEndNode(); |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
377 if (gn.getProperty("uri", "").equals(group.getUriString()) |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
378 || gn.getProperty("id", "").equals(group.getId())) { |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
379 tx.success(); |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
380 return true; |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
381 } |
15 | 382 } |
68
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
383 tx.success(); |
67 | 384 } |
15 | 385 return false; |
386 } | |
16 | 387 |
15 | 388 /** |
22 | 389 * Returns the members of the group. |
390 * | |
391 * @param group | |
392 * @return | |
393 */ | |
394 public List<Person> getMembersOfGroup(Group group) { | |
395 ArrayList<Person> members = new ArrayList<Person>(); | |
396 Node gn = getActorNode(group); | |
81
3be57c18c693
more fixing bugs with transactions thanks to neo4j 2 :-(
casties
parents:
76
diff
changeset
|
397 try (Transaction tx = graphDb.beginTx()) { |
3be57c18c693
more fixing bugs with transactions thanks to neo4j 2 :-(
casties
parents:
76
diff
changeset
|
398 Iterable<Relationship> rels = gn.getRelationships(RelationTypes.MEMBER_OF); |
3be57c18c693
more fixing bugs with transactions thanks to neo4j 2 :-(
casties
parents:
76
diff
changeset
|
399 for (Relationship rel : rels) { |
3be57c18c693
more fixing bugs with transactions thanks to neo4j 2 :-(
casties
parents:
76
diff
changeset
|
400 Node memberNode = rel.getStartNode(); |
3be57c18c693
more fixing bugs with transactions thanks to neo4j 2 :-(
casties
parents:
76
diff
changeset
|
401 Actor member = createActorFromNode(memberNode); |
3be57c18c693
more fixing bugs with transactions thanks to neo4j 2 :-(
casties
parents:
76
diff
changeset
|
402 // make sure we're getting a group |
3be57c18c693
more fixing bugs with transactions thanks to neo4j 2 :-(
casties
parents:
76
diff
changeset
|
403 if (!(member instanceof Person)) { |
3be57c18c693
more fixing bugs with transactions thanks to neo4j 2 :-(
casties
parents:
76
diff
changeset
|
404 logger.severe("source of MEMBER_OF is not PERSON! rel=" + rel); |
3be57c18c693
more fixing bugs with transactions thanks to neo4j 2 :-(
casties
parents:
76
diff
changeset
|
405 continue; |
3be57c18c693
more fixing bugs with transactions thanks to neo4j 2 :-(
casties
parents:
76
diff
changeset
|
406 } |
3be57c18c693
more fixing bugs with transactions thanks to neo4j 2 :-(
casties
parents:
76
diff
changeset
|
407 members.add((Person) member); |
3be57c18c693
more fixing bugs with transactions thanks to neo4j 2 :-(
casties
parents:
76
diff
changeset
|
408 } |
3be57c18c693
more fixing bugs with transactions thanks to neo4j 2 :-(
casties
parents:
76
diff
changeset
|
409 tx.success(); |
22 | 410 } |
411 return members; | |
412 } | |
32
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
413 |
22 | 414 /** |
25 | 415 * Add Person newMember to Group group. |
416 * | |
417 * @param group | |
418 * @param member | |
419 */ | |
420 public Person addGroupMember(Group group, Person member) { | |
421 Node gn = getActorNode(group); | |
422 Node pn = getActorNode(member); | |
423 Person addedMember = null; | |
424 if (gn != null && pn != null) { | |
425 getOrCreateRelation(pn, RelationTypes.MEMBER_OF, gn); | |
426 addedMember = member; | |
427 } | |
428 return addedMember; | |
429 } | |
32
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
430 |
25 | 431 /** |
432 * Delete Person oldMember from Group group. | |
433 * | |
434 * @param group | |
435 * @param member | |
436 */ | |
437 public void deleteGroupMember(Group group, Person member) { | |
438 Node gn = getActorNode(group); | |
32
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
439 Node pn = getActorNode(member); |
81
3be57c18c693
more fixing bugs with transactions thanks to neo4j 2 :-(
casties
parents:
76
diff
changeset
|
440 try (Transaction tx = graphDb.beginTx()) { |
3be57c18c693
more fixing bugs with transactions thanks to neo4j 2 :-(
casties
parents:
76
diff
changeset
|
441 Iterable<Relationship> rels = gn.getRelationships(RelationTypes.MEMBER_OF); |
3be57c18c693
more fixing bugs with transactions thanks to neo4j 2 :-(
casties
parents:
76
diff
changeset
|
442 for (Relationship rel : rels) { |
3be57c18c693
more fixing bugs with transactions thanks to neo4j 2 :-(
casties
parents:
76
diff
changeset
|
443 Node mn = rel.getStartNode(); |
3be57c18c693
more fixing bugs with transactions thanks to neo4j 2 :-(
casties
parents:
76
diff
changeset
|
444 if (mn.equals(pn)) { |
32
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
445 rel.delete(); |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
446 } |
25 | 447 // there should be only one |
448 break; | |
449 } | |
81
3be57c18c693
more fixing bugs with transactions thanks to neo4j 2 :-(
casties
parents:
76
diff
changeset
|
450 tx.success(); |
32
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
451 } |
25 | 452 } |
32
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
453 |
25 | 454 /** |
22 | 455 * Returns the stored Actor matching the given one. |
456 * | |
457 * @param actor | |
458 * @return | |
459 */ | |
460 public Actor getActor(Actor actor) { | |
32
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
461 Node actorNode = getActorNode(actor); |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
462 Actor storedActor = createActorFromNode(actorNode); |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
463 return storedActor; |
22 | 464 } |
32
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
465 |
22 | 466 /** |
32
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
467 * 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
|
468 * existing one. |
22 | 469 * |
470 * @param actor | |
471 * @return | |
472 */ | |
473 public Actor storeActor(Actor actor) { | |
32
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
474 Node actorNode = getOrCreateActorNode(actor); |
68
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
475 try (Transaction tx = graphDb.beginTx()) { |
32
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
476 // id |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
477 String id = actor.getId(); |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
478 if (id != null) { |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
479 actorNode.setProperty("id", id); |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
480 } |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
481 // name |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
482 String name = actor.getName(); |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
483 if (name != null) { |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
484 actorNode.setProperty("name", name); |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
485 } |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
486 // uri |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
487 String uri = actor.getUri(); |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
488 if (uri != null) { |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
489 actorNode.setProperty("uri", uri); |
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 tx.success(); |
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 Actor storedActor = createActorFromNode(actorNode); |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
494 return storedActor; |
22 | 495 } |
32
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
496 |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
497 /** |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
498 * Deletes the given Actor. |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
499 * |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
500 * @param actor |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
501 */ |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
502 public void deleteActor(Actor actor) { |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
503 String uri = actor.getUriString(); |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
504 Index<Node> idx; |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
505 if (actor.isGroup()) { |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
506 idx = getNodeIndex(NodeTypes.GROUP); |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
507 } else { |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
508 idx = getNodeIndex(NodeTypes.PERSON); |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
509 } |
81
3be57c18c693
more fixing bugs with transactions thanks to neo4j 2 :-(
casties
parents:
76
diff
changeset
|
510 try (Transaction tx = graphDb.beginTx()) { |
3be57c18c693
more fixing bugs with transactions thanks to neo4j 2 :-(
casties
parents:
76
diff
changeset
|
511 Node actorNode = idx.get("uri", uri).getSingle(); |
3be57c18c693
more fixing bugs with transactions thanks to neo4j 2 :-(
casties
parents:
76
diff
changeset
|
512 if (actorNode != null) { |
3be57c18c693
more fixing bugs with transactions thanks to neo4j 2 :-(
casties
parents:
76
diff
changeset
|
513 // delete relations |
3be57c18c693
more fixing bugs with transactions thanks to neo4j 2 :-(
casties
parents:
76
diff
changeset
|
514 for (Relationship rel : actorNode.getRelationships()) { |
3be57c18c693
more fixing bugs with transactions thanks to neo4j 2 :-(
casties
parents:
76
diff
changeset
|
515 rel.delete(); |
3be57c18c693
more fixing bugs with transactions thanks to neo4j 2 :-(
casties
parents:
76
diff
changeset
|
516 } |
3be57c18c693
more fixing bugs with transactions thanks to neo4j 2 :-(
casties
parents:
76
diff
changeset
|
517 if (!actorNode.hasRelationship()) { |
32
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
518 // this shouldn't happen |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
519 deleteNode(actorNode); |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
520 } else { |
75 | 521 logger.severe("deleteActor: unable to delete: Node still has relations."); |
32
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
522 } |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
523 } |
81
3be57c18c693
more fixing bugs with transactions thanks to neo4j 2 :-(
casties
parents:
76
diff
changeset
|
524 tx.success(); |
32
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
525 } |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
526 } |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
527 |
22 | 528 /** |
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
529 * Returns the Annotation with the given id. |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
530 * |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
531 * @param id |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
532 * @return |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
533 */ |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
534 public Annotation getAnnotationById(String id) { |
67 | 535 Annotation annot = null; |
68
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
536 try (Transaction tx = graphDb.beginTx()) { |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
537 Node annotNode = getNodeIndex(NodeTypes.ANNOTATION).get("id", id).getSingle(); |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
538 annot = createAnnotationFromNode(annotNode); |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
539 tx.success(); |
67 | 540 } |
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
541 return annot; |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
542 } |
6 | 543 |
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
544 /** |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
545 * Returns an Annotation object from an annotation-Node. |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
546 * |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
547 * @param annotNode |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
548 * @return |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
549 */ |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
550 public Annotation createAnnotationFromNode(Node annotNode) { |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
551 Annotation annot = new Annotation(); |
68
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
552 try (Transaction tx = graphDb.beginTx()) { |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
553 annot.setUri((String) annotNode.getProperty("id", null)); |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
554 annot.setBodyText((String) annotNode.getProperty("bodyText", null)); |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
555 annot.setBodyUri((String) annotNode.getProperty("bodyUri", null)); |
76 | 556 annot.setQuote((String) annotNode.getProperty("quote", null)); |
68
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
557 /* |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
558 * get annotation target and resource from relation |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
559 */ |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
560 for (Relationship rel : annotNode.getRelationships(RelationTypes.ANNOTATES)) { |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
561 Node target = rel.getEndNode(); |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
562 String type = (String) target.getProperty("TYPE"); |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
563 if (type.equals("TARGET")) { |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
564 annot.setTarget(new Target((String) target.getProperty("uri", null))); |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
565 } else if (type.equals("RESOURCE")) { |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
566 annot.setResource(new Resource((String) target.getProperty("uri", null))); |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
567 } |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
568 } |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
569 if (annot.getTarget() == null) { |
75 | 570 logger.warning("annotation " + annotNode + " has no target node!"); |
68
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
571 } |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
572 // get fragment from attribute |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
573 annot.setTargetFragment((String) annotNode.getProperty("targetFragment", null)); |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
574 String ft = (String) annotNode.getProperty("fragmentType", null); |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
575 if (ft != null) { |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
576 annot.setFragmentType(FragmentTypes.valueOf(ft)); |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
577 } |
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 * get creator from relation |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
580 */ |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
581 Relationship creatorRel = getRelation(annotNode, RelationTypes.CREATED, null); |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
582 if (creatorRel != null) { |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
583 Node creatorNode = creatorRel.getStartNode(); |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
584 Actor creator = createActorFromNode(creatorNode); |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
585 annot.setCreator(creator); |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
586 } else { |
75 | 587 logger.warning("annotation " + annotNode + " has no creator node!"); |
45 | 588 } |
68
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
589 /* |
98 | 590 * get creation and update date |
68
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
591 */ |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
592 annot.setCreated((String) annotNode.getProperty("created", null)); |
98 | 593 annot.setUpdated((String) annotNode.getProperty("updated", null)); |
68
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 * get permissions |
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 Relationship adminRel = getRelation(annotNode, RelationTypes.PERMITS_ADMIN, null); |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
598 if (adminRel != null) { |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
599 Node adminNode = adminRel.getEndNode(); |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
600 Actor admin = createActorFromNode(adminNode); |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
601 annot.setAdminPermission(admin); |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
602 } |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
603 Relationship deleteRel = getRelation(annotNode, RelationTypes.PERMITS_DELETE, null); |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
604 if (deleteRel != null) { |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
605 Node deleteNode = deleteRel.getEndNode(); |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
606 Actor delete = createActorFromNode(deleteNode); |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
607 annot.setDeletePermission(delete); |
16 | 608 } |
68
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
609 Relationship updateRel = getRelation(annotNode, RelationTypes.PERMITS_UPDATE, null); |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
610 if (updateRel != null) { |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
611 Node updateNode = updateRel.getEndNode(); |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
612 Actor update = createActorFromNode(updateNode); |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
613 annot.setUpdatePermission(update); |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
614 } |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
615 Relationship readRel = getRelation(annotNode, RelationTypes.PERMITS_READ, null); |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
616 if (readRel != null) { |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
617 Node readNode = readRel.getEndNode(); |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
618 Actor read = createActorFromNode(readNode); |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
619 annot.setReadPermission(read); |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
620 } |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
621 /* |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
622 * get tags |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
623 */ |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
624 Set<String> tags = new HashSet<String>(); |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
625 for (Relationship rel : annotNode.getRelationships(RelationTypes.HAS_TAG)) { |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
626 String tag = (String) rel.getEndNode().getProperty("name", null); |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
627 if (tag != null) { |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
628 tags.add(tag); |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
629 } |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
630 } |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
631 annot.setTags(tags); |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
632 |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
633 tx.success(); |
67 | 634 } |
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
635 return annot; |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
636 } |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
637 |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
638 /** |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
639 * Returns an Actor object from a node. |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
640 * |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
641 * @param actorNode |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
642 * @return |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
643 */ |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
644 protected Actor createActorFromNode(Node actorNode) { |
68
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
645 if (actorNode == null) |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
646 return null; |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
647 try (Transaction tx = graphDb.beginTx()) { |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
648 String id = (String) actorNode.getProperty("id", null); |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
649 String uri = (String) actorNode.getProperty("uri", null); |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
650 String name = (String) actorNode.getProperty("name", null); |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
651 String type = (String) actorNode.getProperty("TYPE", null); |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
652 tx.success(); |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
653 if (type != null && type.equals("PERSON")) { |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
654 return new Person(id, uri, name); |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
655 } else if (type != null && type.equals("GROUP")) { |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
656 return new Group(id, uri, name); |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
657 } |
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
658 } |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
659 return null; |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
660 } |
32
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
661 |
28 | 662 public Tag createTagFromNode(Node tagNode) { |
68
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
663 if (tagNode == null) |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
664 return null; |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
665 String id; |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
666 String uri; |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
667 String name; |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
668 try (Transaction tx = graphDb.beginTx()) { |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
669 name = (String) tagNode.getProperty("name", null); |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
670 uri = (String) tagNode.getProperty("uri", null); |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
671 id = (String) tagNode.getProperty("id", null); |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
672 tx.success(); |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
673 } |
32
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
674 return new Tag(id, uri, name); |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
675 |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
676 } |
4 | 677 |
43 | 678 /** |
679 * @param resourceNode | |
680 * @return | |
681 */ | |
682 public Resource createResourceFromNode(Node resourceNode) { | |
683 return (Resource) createUriFromNode(resourceNode); | |
684 } | |
59
e2f86ef9b871
make annotation uri in store configurable. fix npe with no tags.
casties
parents:
48
diff
changeset
|
685 |
43 | 686 /** |
687 * @param targetNode | |
688 * @return | |
689 */ | |
690 public Target createTargetFromNode(Node targetNode) { | |
691 return (Target) createUriFromNode(targetNode); | |
692 } | |
59
e2f86ef9b871
make annotation uri in store configurable. fix npe with no tags.
casties
parents:
48
diff
changeset
|
693 |
42 | 694 protected Uri createUriFromNode(Node uriNode) { |
68
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
695 if (uriNode == null) |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
696 return null; |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
697 try (Transaction tx = graphDb.beginTx()) { |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
698 String uri = (String) uriNode.getProperty("uri", null); |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
699 String type = (String) uriNode.getProperty("TYPE", null); |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
700 tx.success(); |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
701 if (type != null && type.equals("TARGET")) { |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
702 return new Target(uri); |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
703 } else if (type != null && type.equals("RESOURCE")) { |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
704 return new Resource(uri); |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
705 } |
42 | 706 } |
707 return null; | |
708 } | |
709 | |
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
710 /** |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
711 * 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
|
712 * the stored annotation. |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
713 * |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
714 * @param annot |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
715 * @return |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
716 */ |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
717 public Annotation storeAnnotation(Annotation annot) { |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
718 Node annotNode = null; |
68
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
719 try (Transaction tx = graphDb.beginTx()) { |
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
720 /* |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
721 * create or get the annotation |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
722 */ |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
723 String id = annot.getUri(); |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
724 if (id == null) { |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
725 id = createRessourceURI("annot:"); |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
726 } |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
727 annotNode = getOrCreateAnnotationNode(id); |
4 | 728 |
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
729 /* |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
730 * the annotation body |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
731 */ |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
732 String bodyText = annot.getBodyText(); |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
733 if (bodyText != null) { |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
734 annotNode.setProperty("bodyText", bodyText); |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
735 } |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
736 String bodyUri = annot.getBodyUri(); |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
737 if (bodyUri != null) { |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
738 annotNode.setProperty("bodyUri", bodyUri); |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
739 } |
76 | 740 |
741 /* | |
742 * the annotation quote | |
743 */ | |
744 String quote = annot.getQuote(); | |
745 if (quote != null) { | |
746 annotNode.setProperty("quote", quote); | |
747 } | |
68
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
748 |
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
749 /* |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
750 * the annotation target |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
751 */ |
48
0e00bf8e27fb
targets and resources of Annotation object are objects now.
casties
parents:
45
diff
changeset
|
752 Target target = annot.getTarget(); |
40
03e0f7574224
saving and loading resource targets should work now (no searching yet)
casties
parents:
36
diff
changeset
|
753 Node targetNode = null; |
48
0e00bf8e27fb
targets and resources of Annotation object are objects now.
casties
parents:
45
diff
changeset
|
754 if (target != null) { |
0e00bf8e27fb
targets and resources of Annotation object are objects now.
casties
parents:
45
diff
changeset
|
755 targetNode = getOrCreateUriNode(target.getUri(), NodeTypes.TARGET); |
40
03e0f7574224
saving and loading resource targets should work now (no searching yet)
casties
parents:
36
diff
changeset
|
756 getOrCreateRelation(annotNode, RelationTypes.ANNOTATES, targetNode); |
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
757 } |
4 | 758 |
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
759 /* |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
760 * The fragment part of the annotation target. |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
761 */ |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
762 String targetFragment = annot.getTargetFragment(); |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
763 FragmentTypes fragmentType = annot.getFragmentType(); |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
764 if (targetFragment != null) { |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
765 annotNode.setProperty("targetFragment", targetFragment); |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
766 annotNode.setProperty("fragmentType", fragmentType.name()); |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
767 } |
4 | 768 |
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
769 /* |
40
03e0f7574224
saving and loading resource targets should work now (no searching yet)
casties
parents:
36
diff
changeset
|
770 * the annotation resource |
03e0f7574224
saving and loading resource targets should work now (no searching yet)
casties
parents:
36
diff
changeset
|
771 */ |
48
0e00bf8e27fb
targets and resources of Annotation object are objects now.
casties
parents:
45
diff
changeset
|
772 Resource resource = annot.getResource(); |
0e00bf8e27fb
targets and resources of Annotation object are objects now.
casties
parents:
45
diff
changeset
|
773 if (resource != null) { |
0e00bf8e27fb
targets and resources of Annotation object are objects now.
casties
parents:
45
diff
changeset
|
774 Node resourceNode = getOrCreateUriNode(resource.getUri(), NodeTypes.RESOURCE); |
0e00bf8e27fb
targets and resources of Annotation object are objects now.
casties
parents:
45
diff
changeset
|
775 getOrCreateRelation(annotNode, RelationTypes.ANNOTATES, resourceNode); |
0e00bf8e27fb
targets and resources of Annotation object are objects now.
casties
parents:
45
diff
changeset
|
776 getOrCreateRelation(targetNode, RelationTypes.PART_OF, resourceNode); |
40
03e0f7574224
saving and loading resource targets should work now (no searching yet)
casties
parents:
36
diff
changeset
|
777 } |
03e0f7574224
saving and loading resource targets should work now (no searching yet)
casties
parents:
36
diff
changeset
|
778 |
03e0f7574224
saving and loading resource targets should work now (no searching yet)
casties
parents:
36
diff
changeset
|
779 /* |
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
780 * The creator of this annotation. |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
781 */ |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
782 Actor creator = annot.getCreator(); |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
783 if (creator != null) { |
15 | 784 Node creatorNode = getOrCreateActorNode(creator); |
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
785 getOrCreateRelation(creatorNode, RelationTypes.CREATED, annotNode); |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
786 } |
12 | 787 |
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
788 /* |
98 | 789 * The creation and update date of this annotation. |
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
790 */ |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
791 String created = annot.getCreated(); |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
792 if (created != null) { |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
793 annotNode.setProperty("created", created); |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
794 } |
98 | 795 String updated = annot.getUpdated(); |
796 if (updated != null) { | |
797 annotNode.setProperty("updated", updated); | |
798 } | |
4 | 799 |
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
800 /* |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
801 * Permissions for this annotation. |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
802 */ |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
803 setPermissionRelation(annotNode, RelationTypes.PERMITS_ADMIN, annot.getAdminPermission()); |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
804 setPermissionRelation(annotNode, RelationTypes.PERMITS_DELETE, annot.getDeletePermission()); |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
805 setPermissionRelation(annotNode, RelationTypes.PERMITS_UPDATE, annot.getUpdatePermission()); |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
806 setPermissionRelation(annotNode, RelationTypes.PERMITS_READ, annot.getReadPermission()); |
6 | 807 |
16 | 808 /* |
809 * Tags on this annotation. | |
810 */ | |
811 Set<String> newTags = annot.getTags(); | |
812 // we ignore existing tags if tags == null | |
813 if (newTags != null) { | |
814 List<Relationship> oldHasTags = new ArrayList<Relationship>(); | |
815 for (Relationship rel : annotNode.getRelationships(RelationTypes.HAS_TAG)) { | |
816 oldHasTags.add(rel); | |
817 } | |
818 // adjust to new tags | |
819 if (newTags.isEmpty()) { | |
820 // remove old tags | |
821 if (!oldHasTags.isEmpty()) { | |
822 for (Relationship rel : oldHasTags) { | |
823 rel.delete(); | |
824 // TODO: should we delete orphan nodes too? | |
825 } | |
826 } | |
827 } else { | |
828 if (!oldHasTags.isEmpty()) { | |
829 // adjust old tags | |
830 for (Relationship rel : oldHasTags) { | |
831 String oldTag = (String) rel.getEndNode().getProperty("name", null); | |
832 if (newTags.contains(oldTag)) { | |
833 // tag exists | |
834 newTags.remove(oldTag); | |
835 } else { | |
836 // tag exists no longer | |
837 rel.delete(); | |
838 // TODO: should we delete orphan nodes too? | |
839 } | |
840 } | |
841 } | |
842 if (!newTags.isEmpty()) { | |
843 // still tags to add | |
844 for (String tag : newTags) { | |
845 // create new tag | |
32
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
846 Node tagNode = getOrCreateTagNode(new Tag(null, null, tag)); |
16 | 847 getOrCreateRelation(annotNode, RelationTypes.HAS_TAG, tagNode); |
848 } | |
849 } | |
850 | |
851 } | |
852 } | |
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
853 tx.success(); |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
854 } |
12 | 855 |
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
856 // re-read and return annotation |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
857 Annotation storedAnnot = createAnnotationFromNode(annotNode); |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
858 return storedAnnot; |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
859 } |
4 | 860 |
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
861 /** |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
862 * Deletes the annotation with the given id. |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
863 * |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
864 * @param id |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
865 */ |
32
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
866 public void deleteAnnotationById(String id) { |
68
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
867 try (Transaction tx = graphDb.beginTx()) { |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
868 Node annotNode = getNodeIndex(NodeTypes.ANNOTATION).get("id", id).getSingle(); |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
869 if (annotNode != null) { |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
870 // delete related objects |
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
871 for (Relationship rel : annotNode.getRelationships()) { |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
872 // 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
|
873 // relations and is not permanent |
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
874 Node other = rel.getOtherNode(annotNode); |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
875 rel.delete(); |
32
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
876 if (!(other.hasRelationship() || permanentNodeTypes.contains(other.getProperty("TYPE", null)))) { |
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
877 deleteNode(other); |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
878 } |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
879 } |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
880 if (!annotNode.hasRelationship()) { |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
881 deleteNode(annotNode); |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
882 } else { |
75 | 883 logger.severe("deleteById: unable to delete: Node still has relations."); |
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
884 } |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
885 } |
68
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
886 tx.success(); |
14
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 } |
4 | 889 |
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
890 /** |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
891 * Returns all annotations with the given uri and/or user. |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
892 * |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
893 * @param uri |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
894 * @param userUri |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
895 * @return |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
896 */ |
63
9f8c9611848a
fixed bug with new rectangle shapes. added limit, offset and sortBy parameters to annotator/ and annotator/search.
casties
parents:
59
diff
changeset
|
897 public List<Annotation> searchAnnotationByUriUser(String targetUri, String userUri) { |
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
898 List<Annotation> annotations = new ArrayList<Annotation>(); |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
899 if (targetUri != null) { |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
900 // there should be only one |
68
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
901 Node target = getNodeFromIndex("uri", targetUri, NodeTypes.TARGET); |
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
902 if (target != null) { |
68
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
903 try (Transaction tx = graphDb.beginTx()) { |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
904 Iterable<Relationship> relations = target.getRelationships(RelationTypes.ANNOTATES); |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
905 for (Relationship relation : relations) { |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
906 Node ann = relation.getStartNode(); |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
907 if (ann.getProperty("TYPE", "").equals("ANNOTATION")) { |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
908 Annotation annot = createAnnotationFromNode(ann); |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
909 annotations.add(annot); |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
910 } else { |
75 | 911 logger.severe("ANNOTATES relation does not start with ANNOTATION: " + ann); |
68
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
912 } |
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
913 } |
68
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
914 tx.success(); |
67 | 915 } |
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
916 } |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
917 } |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
918 if (userUri != null) { |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
919 // there should be only one |
15 | 920 Node person = getPersonNodeByUri(userUri); |
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
921 if (person != null) { |
68
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
922 try (Transaction tx = graphDb.beginTx()) { |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
923 Iterable<Relationship> relations = person.getRelationships(RelationTypes.CREATED); |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
924 for (Relationship relation : relations) { |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
925 Node ann = relation.getEndNode(); |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
926 if (ann.getProperty("TYPE", "").equals("ANNOTATION")) { |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
927 Annotation annot = createAnnotationFromNode(ann); |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
928 annotations.add(annot); |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
929 } else { |
75 | 930 logger.severe("CREATED relation does not end with ANNOTATION: " + ann); |
68
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
931 } |
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
932 } |
68
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
933 tx.success(); |
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
934 } |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
935 } |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
936 } |
16 | 937 // 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
|
938 |
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
939 return annotations; |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
940 } |
5 | 941 |
16 | 942 /** |
943 * Returns Relationship of type from Node start to Node end. Creates one if | |
944 * it doesn't exist. | |
945 * | |
946 * @param start | |
947 * @param type | |
948 * @param end | |
949 * @return | |
950 */ | |
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
951 protected Relationship getOrCreateRelation(Node start, RelationshipType type, Node end) { |
68
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
952 if (start == null || end == null) |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
953 return null; |
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
954 if (start.hasRelationship()) { |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
955 // there are relations |
68
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
956 try (Transaction tx = graphDb.beginTx()) { |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
957 Iterable<Relationship> rels = start.getRelationships(type, Direction.OUTGOING); |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
958 for (Relationship rel : rels) { |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
959 if (rel.getEndNode().equals(end)) { |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
960 // relation exists |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
961 tx.success(); |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
962 return rel; |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
963 } |
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
964 } |
68
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
965 tx.success(); |
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
966 } |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
967 } |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
968 // create new one |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
969 Relationship rel; |
68
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
970 try (Transaction tx = graphDb.beginTx()) { |
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
971 rel = start.createRelationshipTo(end, type); |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
972 tx.success(); |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
973 } |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
974 return rel; |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
975 } |
12 | 976 |
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
977 protected Node getOrCreateAnnotationNode(String id) { |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
978 Index<Node> idx = getNodeIndex(NodeTypes.ANNOTATION); |
68
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
979 Node annotation; |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
980 try (Transaction tx = graphDb.beginTx()) { |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
981 IndexHits<Node> annotations = idx.get("id", id); |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
982 annotation = annotations.getSingle(); |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
983 if (annotation == null) { |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
984 // does not exist yet |
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
985 annotation = graphDb.createNode(); |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
986 annotation.setProperty("TYPE", NodeTypes.ANNOTATION.name()); |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
987 annotation.setProperty("id", id); |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
988 idx.add(annotation, "id", id); |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
989 } |
68
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
990 tx.success(); |
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
991 } |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
992 return annotation; |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
993 } |
6 | 994 |
48
0e00bf8e27fb
targets and resources of Annotation object are objects now.
casties
parents:
45
diff
changeset
|
995 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
|
996 Index<Node> idx = getNodeIndex(type); |
68
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
997 Node target; |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
998 try (Transaction tx = graphDb.beginTx()) { |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
999 IndexHits<Node> targets = idx.get("uri", uri); |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
1000 target = targets.getSingle(); |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
1001 if (target == null) { |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
1002 // does not exist yet |
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1003 target = graphDb.createNode(); |
40
03e0f7574224
saving and loading resource targets should work now (no searching yet)
casties
parents:
36
diff
changeset
|
1004 target.setProperty("TYPE", type.name()); |
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1005 target.setProperty("uri", uri); |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1006 idx.add(target, "uri", uri); |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1007 } |
68
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
1008 tx.success(); |
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1009 } |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1010 return target; |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1011 } |
4 | 1012 |
22 | 1013 protected Node getActorNode(Actor actor) { |
1014 // Person/Group is identified by URI or id | |
1015 String uri = actor.getUriString(); | |
1016 Index<Node> idx; | |
68
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
1017 Node person; |
22 | 1018 if (actor.isGroup()) { |
1019 idx = getNodeIndex(NodeTypes.GROUP); | |
1020 } else { | |
1021 idx = getNodeIndex(NodeTypes.PERSON); | |
1022 } | |
68
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
1023 try (Transaction tx = graphDb.beginTx()) { |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
1024 IndexHits<Node> persons = idx.get("uri", uri); |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
1025 person = persons.getSingle(); |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
1026 tx.success(); |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
1027 } |
22 | 1028 return person; |
1029 } | |
32
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
1030 |
15 | 1031 protected Node getOrCreateActorNode(Actor actor) { |
1032 // Person/Group is identified by URI or id | |
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1033 String uri = actor.getUriString(); |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1034 String name = actor.getName(); |
15 | 1035 String id = actor.getId(); |
68
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
1036 Node person; |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
1037 try (Transaction tx = graphDb.beginTx()) { |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
1038 Index<Node> idx; |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
1039 if (actor.isGroup()) { |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
1040 idx = getNodeIndex(NodeTypes.GROUP); |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
1041 } else { |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
1042 idx = getNodeIndex(NodeTypes.PERSON); |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
1043 } |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
1044 IndexHits<Node> persons = idx.get("uri", uri); |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
1045 person = persons.getSingle(); |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
1046 if (person == null) { |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
1047 // does not exist yet |
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1048 person = graphDb.createNode(); |
15 | 1049 if (actor.isGroup()) { |
1050 person.setProperty("TYPE", NodeTypes.GROUP.name()); | |
1051 } else { | |
16 | 1052 person.setProperty("TYPE", NodeTypes.PERSON.name()); |
15 | 1053 } |
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1054 person.setProperty("uri", uri); |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1055 idx.add(person, "uri", uri); |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1056 if (name != null) { |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1057 person.setProperty("name", name); |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1058 } |
15 | 1059 if (id != null) { |
1060 person.setProperty("id", id); | |
1061 } | |
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1062 } |
68
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
1063 tx.success(); |
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1064 } |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1065 return person; |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1066 } |
4 | 1067 |
28 | 1068 protected Node getOrCreateTagNode(Tag inTag) { |
16 | 1069 Index<Node> idx = getNodeIndex(NodeTypes.TAG); |
28 | 1070 String tagname = inTag.getName(); |
68
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
1071 Node tag; |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
1072 try (Transaction tx = graphDb.beginTx()) { |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
1073 IndexHits<Node> tags = idx.get("name", tagname); |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
1074 tag = tags.getSingle(); |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
1075 if (tag == null) { |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
1076 // does not exist yet |
16 | 1077 tag = graphDb.createNode(); |
1078 tag.setProperty("TYPE", NodeTypes.TAG.name()); | |
1079 tag.setProperty("name", tagname); | |
1080 idx.add(tag, "name", tagname); | |
32
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
1081 |
28 | 1082 tag.setProperty("id", inTag.getId()); |
1083 tag.setProperty("uri", inTag.getUri()); | |
1084 idx.add(tag, "uri", inTag.getUri()); | |
16 | 1085 } |
68
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
1086 tx.success(); |
16 | 1087 } |
1088 return tag; | |
1089 } | |
1090 | |
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1091 /** |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1092 * Create or update permissions relations for an annotation. |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1093 * |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1094 * @param annotNode |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1095 * @param type |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1096 * @param annot |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1097 */ |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1098 protected void setPermissionRelation(Node annotNode, RelationTypes type, Actor actor) { |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1099 Node newActorNode = null; |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1100 if (actor != null) { |
15 | 1101 newActorNode = getOrCreateActorNode(actor); |
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1102 } |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1103 Relationship rel = getRelation(annotNode, type, null); |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1104 if (rel != null) { |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1105 // relation exists |
68
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
1106 try (Transaction tx = graphDb.beginTx()) { |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
1107 Node oldActorNode = rel.getEndNode(); |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
1108 if (!oldActorNode.equals(newActorNode)) { |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
1109 // new admin is different |
33 | 1110 rel.delete(); |
1111 tx.success(); | |
1112 } | |
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1113 if (newActorNode != null) { |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1114 rel = getOrCreateRelation(annotNode, type, newActorNode); |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1115 } |
68
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
1116 tx.success(); |
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1117 } |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1118 } else { |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1119 // no relation yet |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1120 if (newActorNode != null) { |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1121 rel = getOrCreateRelation(annotNode, type, newActorNode); |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1122 } |
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 } |
4 | 1125 |
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1126 /** |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1127 * Unindexes and deletes given Node if it has no relations. |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1128 * |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1129 * @param node |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1130 */ |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1131 protected void deleteNode(Node node) { |
68
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
1132 try (Transaction tx = graphDb.beginTx()) { |
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1133 if (node.hasRelationship()) { |
75 | 1134 logger.severe("deleteNode: unable to delete: Node still has relations."); |
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1135 } else { |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1136 String ts = (String) node.getProperty("TYPE", null); |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1137 try { |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1138 NodeTypes type = NodeTypes.valueOf(ts); |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1139 getNodeIndex(type).remove(node); |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1140 } catch (Exception e) { |
75 | 1141 logger.severe("deleteNode: unable to get TYPE of node: " + node); |
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1142 } |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1143 node.delete(); |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1144 } |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1145 tx.success(); |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1146 } |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1147 } |
4 | 1148 |
16 | 1149 /** |
1150 * returns the (first) Relationship of RelationTypes type from Node start. | |
1151 * | |
15 | 1152 * @param start |
1153 * @param type | |
1154 * @param direction | |
1155 * @return | |
1156 */ | |
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1157 protected Relationship getRelation(Node start, RelationTypes type, Direction direction) { |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1158 Iterable<Relationship> rels; |
68
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
1159 try (Transaction tx = graphDb.beginTx()) { |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
1160 if (direction == null) { |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
1161 // ignore direction |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
1162 rels = start.getRelationships(type); |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
1163 } else { |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
1164 rels = start.getRelationships(type, direction); |
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 tx.success(); |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
1167 for (Relationship rel : rels) { |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
1168 // just the first one |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
1169 return rel; |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
1170 } |
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1171 } |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1172 return null; |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1173 } |
4 | 1174 |
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1175 /** |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1176 * Erzeuge eine urn aus der aktuellen Zeit in millis |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1177 * |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1178 * @return |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1179 */ |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1180 private String createRessourceURI(String prefix) { |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1181 Calendar cal = Calendar.getInstance(); |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
1182 long time = cal.getTimeInMillis(); |
59
e2f86ef9b871
make annotation uri in store configurable. fix npe with no tags.
casties
parents:
48
diff
changeset
|
1183 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
|
1184 } |
4 | 1185 |
32
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
1186 public List<Annotation> getAnnotationsByTag(String tagUri) { |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
1187 ArrayList<Annotation> ret = new ArrayList<Annotation>(); |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
1188 Node tag = getTagNodeByUri(tagUri); |
59
e2f86ef9b871
make annotation uri in store configurable. fix npe with no tags.
casties
parents:
48
diff
changeset
|
1189 if (tag != null) { |
68
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
1190 try (Transaction tx = graphDb.beginTx()) { |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
1191 Iterable<Relationship> rels = tag.getRelationships(Direction.INCOMING, RelationTypes.HAS_TAG); |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
1192 for (Relationship rel : rels) { |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
1193 Node node = rel.getStartNode(); |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
1194 ret.add(createAnnotationFromNode(node)); |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
1195 } |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
1196 tx.success(); |
59
e2f86ef9b871
make annotation uri in store configurable. fix npe with no tags.
casties
parents:
48
diff
changeset
|
1197 } |
32
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
1198 } |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
1199 return ret; |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
29
diff
changeset
|
1200 } |
28 | 1201 |
42 | 1202 public List<Annotation> getAnnotationsByResource(String resourceUri) { |
1203 ArrayList<Annotation> ret = new ArrayList<Annotation>(); | |
59
e2f86ef9b871
make annotation uri in store configurable. fix npe with no tags.
casties
parents:
48
diff
changeset
|
1204 Node res = getNodeFromIndex("uri", resourceUri, NodeTypes.RESOURCE); |
e2f86ef9b871
make annotation uri in store configurable. fix npe with no tags.
casties
parents:
48
diff
changeset
|
1205 if (res != null) { |
68
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
1206 try (Transaction tx = graphDb.beginTx()) { |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
1207 Iterable<Relationship> rels = res.getRelationships(Direction.INCOMING, RelationTypes.ANNOTATES); |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
1208 for (Relationship rel : rels) { |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
1209 Node an = rel.getStartNode(); |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
1210 Node rn = rel.getEndNode(); |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
1211 if (rn.getProperty("TYPE", "").equals("RESOURCE")) { |
75 | 1212 logger.severe("getAnnotationsByResource got ANNOTATES != RESOURCE"); |
68
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
1213 } |
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
1214 ret.add(createAnnotationFromNode(an)); |
59
e2f86ef9b871
make annotation uri in store configurable. fix npe with no tags.
casties
parents:
48
diff
changeset
|
1215 } |
68
39bc52f9b102
(hopefully) fixed issues with neo4j 2.0 transactions.
casties
parents:
67
diff
changeset
|
1216 tx.success(); |
43 | 1217 } |
42 | 1218 } |
1219 return ret; | |
1220 } | |
1221 | |
4 | 1222 } |