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