annotate src/main/java/de/mpiwg/itgroup/annotations/neo4j/AnnotationStore.java @ 43:d1bef7952bec

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