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