annotate src/main/java/de/mpiwg/itgroup/annotations/Actor.java @ 88:b406507a953d

upped version to 0.5. can use display name and groups from auth token.
author casties
date Tue, 03 Feb 2015 19:01:27 +0100
parents 2b1e6df5e21a
children f83eb8b335b1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9
b2bfc3bc9ba8 new internal actor class for creator.
casties
parents:
diff changeset
1 /**
b2bfc3bc9ba8 new internal actor class for creator.
casties
parents:
diff changeset
2 *
b2bfc3bc9ba8 new internal actor class for creator.
casties
parents:
diff changeset
3 */
b2bfc3bc9ba8 new internal actor class for creator.
casties
parents:
diff changeset
4 package de.mpiwg.itgroup.annotations;
b2bfc3bc9ba8 new internal actor class for creator.
casties
parents:
diff changeset
5
70
2b1e6df5e21a added lgpl_v3 license information.
casties
parents: 58
diff changeset
6 /*
2b1e6df5e21a added lgpl_v3 license information.
casties
parents: 58
diff changeset
7 * #%L
2b1e6df5e21a added lgpl_v3 license information.
casties
parents: 58
diff changeset
8 * AnnotationManager
2b1e6df5e21a added lgpl_v3 license information.
casties
parents: 58
diff changeset
9 * %%
2b1e6df5e21a added lgpl_v3 license information.
casties
parents: 58
diff changeset
10 * Copyright (C) 2012 - 2014 MPIWG Berlin
2b1e6df5e21a added lgpl_v3 license information.
casties
parents: 58
diff changeset
11 * %%
2b1e6df5e21a added lgpl_v3 license information.
casties
parents: 58
diff changeset
12 * This program is free software: you can redistribute it and/or modify
2b1e6df5e21a added lgpl_v3 license information.
casties
parents: 58
diff changeset
13 * it under the terms of the GNU Lesser General Public License as
2b1e6df5e21a added lgpl_v3 license information.
casties
parents: 58
diff changeset
14 * published by the Free Software Foundation, either version 3 of the
2b1e6df5e21a added lgpl_v3 license information.
casties
parents: 58
diff changeset
15 * License, or (at your option) any later version.
2b1e6df5e21a added lgpl_v3 license information.
casties
parents: 58
diff changeset
16 *
2b1e6df5e21a added lgpl_v3 license information.
casties
parents: 58
diff changeset
17 * This program is distributed in the hope that it will be useful,
2b1e6df5e21a added lgpl_v3 license information.
casties
parents: 58
diff changeset
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
2b1e6df5e21a added lgpl_v3 license information.
casties
parents: 58
diff changeset
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2b1e6df5e21a added lgpl_v3 license information.
casties
parents: 58
diff changeset
20 * GNU General Lesser Public License for more details.
2b1e6df5e21a added lgpl_v3 license information.
casties
parents: 58
diff changeset
21 *
2b1e6df5e21a added lgpl_v3 license information.
casties
parents: 58
diff changeset
22 * You should have received a copy of the GNU General Lesser Public
2b1e6df5e21a added lgpl_v3 license information.
casties
parents: 58
diff changeset
23 * License along with this program. If not, see
2b1e6df5e21a added lgpl_v3 license information.
casties
parents: 58
diff changeset
24 * <http://www.gnu.org/licenses/lgpl-3.0.html>.
2b1e6df5e21a added lgpl_v3 license information.
casties
parents: 58
diff changeset
25 * #L%
2b1e6df5e21a added lgpl_v3 license information.
casties
parents: 58
diff changeset
26 */
2b1e6df5e21a added lgpl_v3 license information.
casties
parents: 58
diff changeset
27
15
58357a4b86de ASSIGNED - # 249: Annotations shared in groups
casties
parents: 14
diff changeset
28 import de.mpiwg.itgroup.annotations.neo4j.AnnotationStore;
58
f5c0e6df7e88 made uri prefixes in store configurable.
casties
parents: 18
diff changeset
29 import de.mpiwg.itgroup.annotations.restlet.BaseRestlet;
10
90911b2da322 more work on permissions...
casties
parents: 9
diff changeset
30
9
b2bfc3bc9ba8 new internal actor class for creator.
casties
parents:
diff changeset
31 /**
b2bfc3bc9ba8 new internal actor class for creator.
casties
parents:
diff changeset
32 * @author casties
14
629e15b345aa permissions mostly work. need more server-side checking.
casties
parents: 13
diff changeset
33 *
9
b2bfc3bc9ba8 new internal actor class for creator.
casties
parents:
diff changeset
34 */
10
90911b2da322 more work on permissions...
casties
parents: 9
diff changeset
35 public abstract class Actor {
9
b2bfc3bc9ba8 new internal actor class for creator.
casties
parents:
diff changeset
36
b2bfc3bc9ba8 new internal actor class for creator.
casties
parents:
diff changeset
37 public String uri;
b2bfc3bc9ba8 new internal actor class for creator.
casties
parents:
diff changeset
38 public String name;
10
90911b2da322 more work on permissions...
casties
parents: 9
diff changeset
39 public String id;
14
629e15b345aa permissions mostly work. need more server-side checking.
casties
parents: 13
diff changeset
40
9
b2bfc3bc9ba8 new internal actor class for creator.
casties
parents:
diff changeset
41 /**
10
90911b2da322 more work on permissions...
casties
parents: 9
diff changeset
42 * @return if this Actor is a Group
9
b2bfc3bc9ba8 new internal actor class for creator.
casties
parents:
diff changeset
43 */
10
90911b2da322 more work on permissions...
casties
parents: 9
diff changeset
44 public abstract boolean isGroup();
14
629e15b345aa permissions mostly work. need more server-side checking.
casties
parents: 13
diff changeset
45
629e15b345aa permissions mostly work. need more server-side checking.
casties
parents: 13
diff changeset
46 /**
15
58357a4b86de ASSIGNED - # 249: Annotations shared in groups
casties
parents: 14
diff changeset
47 * Returns if this Actor is equivalent to Person person. If this is
14
629e15b345aa permissions mostly work. need more server-side checking.
casties
parents: 13
diff changeset
48 * a Group returns true when the Person is in the Group.
629e15b345aa permissions mostly work. need more server-side checking.
casties
parents: 13
diff changeset
49 *
15
58357a4b86de ASSIGNED - # 249: Annotations shared in groups
casties
parents: 14
diff changeset
50 * @param person
58357a4b86de ASSIGNED - # 249: Annotations shared in groups
casties
parents: 14
diff changeset
51 * @param store AnnotationStore to check group membership
14
629e15b345aa permissions mostly work. need more server-side checking.
casties
parents: 13
diff changeset
52 * @return
629e15b345aa permissions mostly work. need more server-side checking.
casties
parents: 13
diff changeset
53 */
15
58357a4b86de ASSIGNED - # 249: Annotations shared in groups
casties
parents: 14
diff changeset
54 public boolean isEquivalentWith(Person person, AnnotationStore store) {
58357a4b86de ASSIGNED - # 249: Annotations shared in groups
casties
parents: 14
diff changeset
55 if (person == null) return false;
16
794077e6288c CLOSED - # 252: Tags for Annotations
casties
parents: 15
diff changeset
56 if (person.equals(this)) return true;
794077e6288c CLOSED - # 252: Tags for Annotations
casties
parents: 15
diff changeset
57 if (person.getIdString().equals(this.getIdString())) return true;
15
58357a4b86de ASSIGNED - # 249: Annotations shared in groups
casties
parents: 14
diff changeset
58 if (isGroup() && store != null) {
58357a4b86de ASSIGNED - # 249: Annotations shared in groups
casties
parents: 14
diff changeset
59 // check if person in group
88
b406507a953d upped version to 0.5.
casties
parents: 70
diff changeset
60 if (person.groups != null) {
b406507a953d upped version to 0.5.
casties
parents: 70
diff changeset
61 // check person's groups
b406507a953d upped version to 0.5.
casties
parents: 70
diff changeset
62 if (person.groups.contains(this.id)) {
b406507a953d upped version to 0.5.
casties
parents: 70
diff changeset
63 return true;
b406507a953d upped version to 0.5.
casties
parents: 70
diff changeset
64 }
b406507a953d upped version to 0.5.
casties
parents: 70
diff changeset
65 }
b406507a953d upped version to 0.5.
casties
parents: 70
diff changeset
66 // check in store
15
58357a4b86de ASSIGNED - # 249: Annotations shared in groups
casties
parents: 14
diff changeset
67 return store.isPersonInGroup(person, (Group) this);
14
629e15b345aa permissions mostly work. need more server-side checking.
casties
parents: 13
diff changeset
68 }
629e15b345aa permissions mostly work. need more server-side checking.
casties
parents: 13
diff changeset
69 return false;
629e15b345aa permissions mostly work. need more server-side checking.
casties
parents: 13
diff changeset
70 }
629e15b345aa permissions mostly work. need more server-side checking.
casties
parents: 13
diff changeset
71
9
b2bfc3bc9ba8 new internal actor class for creator.
casties
parents:
diff changeset
72 /**
b2bfc3bc9ba8 new internal actor class for creator.
casties
parents:
diff changeset
73 * @return the uri
b2bfc3bc9ba8 new internal actor class for creator.
casties
parents:
diff changeset
74 */
b2bfc3bc9ba8 new internal actor class for creator.
casties
parents:
diff changeset
75 public String getUri() {
b2bfc3bc9ba8 new internal actor class for creator.
casties
parents:
diff changeset
76 return uri;
b2bfc3bc9ba8 new internal actor class for creator.
casties
parents:
diff changeset
77 }
13
abe25edf2178 storing and retrieving permissions works now.
casties
parents: 10
diff changeset
78
abe25edf2178 storing and retrieving permissions works now.
casties
parents: 10
diff changeset
79 /**
abe25edf2178 storing and retrieving permissions works now.
casties
parents: 10
diff changeset
80 * Returns the uri (uses id if empty).
abe25edf2178 storing and retrieving permissions works now.
casties
parents: 10
diff changeset
81 *
abe25edf2178 storing and retrieving permissions works now.
casties
parents: 10
diff changeset
82 * @return the uri
abe25edf2178 storing and retrieving permissions works now.
casties
parents: 10
diff changeset
83 */
abe25edf2178 storing and retrieving permissions works now.
casties
parents: 10
diff changeset
84 public String getUriString() {
14
629e15b345aa permissions mostly work. need more server-side checking.
casties
parents: 13
diff changeset
85 if (uri == null) {
629e15b345aa permissions mostly work. need more server-side checking.
casties
parents: 13
diff changeset
86 return getUriFromId(id, isGroup());
629e15b345aa permissions mostly work. need more server-side checking.
casties
parents: 13
diff changeset
87 }
13
abe25edf2178 storing and retrieving permissions works now.
casties
parents: 10
diff changeset
88 return uri;
abe25edf2178 storing and retrieving permissions works now.
casties
parents: 10
diff changeset
89 }
abe25edf2178 storing and retrieving permissions works now.
casties
parents: 10
diff changeset
90
9
b2bfc3bc9ba8 new internal actor class for creator.
casties
parents:
diff changeset
91 /**
14
629e15b345aa permissions mostly work. need more server-side checking.
casties
parents: 13
diff changeset
92 * @param uri
629e15b345aa permissions mostly work. need more server-side checking.
casties
parents: 13
diff changeset
93 * the uri to set
9
b2bfc3bc9ba8 new internal actor class for creator.
casties
parents:
diff changeset
94 */
b2bfc3bc9ba8 new internal actor class for creator.
casties
parents:
diff changeset
95 public void setUri(String uri) {
b2bfc3bc9ba8 new internal actor class for creator.
casties
parents:
diff changeset
96 this.uri = uri;
b2bfc3bc9ba8 new internal actor class for creator.
casties
parents:
diff changeset
97 }
14
629e15b345aa permissions mostly work. need more server-side checking.
casties
parents: 13
diff changeset
98
9
b2bfc3bc9ba8 new internal actor class for creator.
casties
parents:
diff changeset
99 /**
b2bfc3bc9ba8 new internal actor class for creator.
casties
parents:
diff changeset
100 * @return the name
b2bfc3bc9ba8 new internal actor class for creator.
casties
parents:
diff changeset
101 */
b2bfc3bc9ba8 new internal actor class for creator.
casties
parents:
diff changeset
102 public String getName() {
b2bfc3bc9ba8 new internal actor class for creator.
casties
parents:
diff changeset
103 return name;
b2bfc3bc9ba8 new internal actor class for creator.
casties
parents:
diff changeset
104 }
14
629e15b345aa permissions mostly work. need more server-side checking.
casties
parents: 13
diff changeset
105
9
b2bfc3bc9ba8 new internal actor class for creator.
casties
parents:
diff changeset
106 /**
14
629e15b345aa permissions mostly work. need more server-side checking.
casties
parents: 13
diff changeset
107 * @param name
629e15b345aa permissions mostly work. need more server-side checking.
casties
parents: 13
diff changeset
108 * the name to set
9
b2bfc3bc9ba8 new internal actor class for creator.
casties
parents:
diff changeset
109 */
b2bfc3bc9ba8 new internal actor class for creator.
casties
parents:
diff changeset
110 public void setName(String name) {
b2bfc3bc9ba8 new internal actor class for creator.
casties
parents:
diff changeset
111 this.name = name;
b2bfc3bc9ba8 new internal actor class for creator.
casties
parents:
diff changeset
112 }
10
90911b2da322 more work on permissions...
casties
parents: 9
diff changeset
113
90911b2da322 more work on permissions...
casties
parents: 9
diff changeset
114 /**
90911b2da322 more work on permissions...
casties
parents: 9
diff changeset
115 * @return the id
90911b2da322 more work on permissions...
casties
parents: 9
diff changeset
116 */
90911b2da322 more work on permissions...
casties
parents: 9
diff changeset
117 public String getId() {
90911b2da322 more work on permissions...
casties
parents: 9
diff changeset
118 return id;
90911b2da322 more work on permissions...
casties
parents: 9
diff changeset
119 }
14
629e15b345aa permissions mostly work. need more server-side checking.
casties
parents: 13
diff changeset
120
10
90911b2da322 more work on permissions...
casties
parents: 9
diff changeset
121 /**
90911b2da322 more work on permissions...
casties
parents: 9
diff changeset
122 * Returns id as a String starting with "group:" for groups.
90911b2da322 more work on permissions...
casties
parents: 9
diff changeset
123 *
90911b2da322 more work on permissions...
casties
parents: 9
diff changeset
124 * @return
90911b2da322 more work on permissions...
casties
parents: 9
diff changeset
125 */
90911b2da322 more work on permissions...
casties
parents: 9
diff changeset
126 public abstract String getIdString();
14
629e15b345aa permissions mostly work. need more server-side checking.
casties
parents: 13
diff changeset
127
10
90911b2da322 more work on permissions...
casties
parents: 9
diff changeset
128 /**
14
629e15b345aa permissions mostly work. need more server-side checking.
casties
parents: 13
diff changeset
129 * @param id
629e15b345aa permissions mostly work. need more server-side checking.
casties
parents: 13
diff changeset
130 * the id to set
10
90911b2da322 more work on permissions...
casties
parents: 9
diff changeset
131 */
90911b2da322 more work on permissions...
casties
parents: 9
diff changeset
132 public void setId(String id) {
90911b2da322 more work on permissions...
casties
parents: 9
diff changeset
133 this.id = id;
90911b2da322 more work on permissions...
casties
parents: 9
diff changeset
134 }
14
629e15b345aa permissions mostly work. need more server-side checking.
casties
parents: 13
diff changeset
135
10
90911b2da322 more work on permissions...
casties
parents: 9
diff changeset
136 /**
90911b2da322 more work on permissions...
casties
parents: 9
diff changeset
137 * Returns a short id from an uri.
90911b2da322 more work on permissions...
casties
parents: 9
diff changeset
138 *
90911b2da322 more work on permissions...
casties
parents: 9
diff changeset
139 * @param uri
90911b2da322 more work on permissions...
casties
parents: 9
diff changeset
140 * @return
90911b2da322 more work on permissions...
casties
parents: 9
diff changeset
141 */
90911b2da322 more work on permissions...
casties
parents: 9
diff changeset
142 public static String getIdFromUri(String uri, boolean isGroup) {
90911b2da322 more work on permissions...
casties
parents: 9
diff changeset
143 String id = null;
58
f5c0e6df7e88 made uri prefixes in store configurable.
casties
parents: 18
diff changeset
144 String prefix = BaseRestlet.PERSONS_URI_PREFIX;
10
90911b2da322 more work on permissions...
casties
parents: 9
diff changeset
145 if (isGroup) {
58
f5c0e6df7e88 made uri prefixes in store configurable.
casties
parents: 18
diff changeset
146 prefix = BaseRestlet.GROUPS_URI_PREFIX;
10
90911b2da322 more work on permissions...
casties
parents: 9
diff changeset
147 }
90911b2da322 more work on permissions...
casties
parents: 9
diff changeset
148 if (uri != null && uri.startsWith(prefix)) {
90911b2da322 more work on permissions...
casties
parents: 9
diff changeset
149 id = uri.replace(prefix, "");
90911b2da322 more work on permissions...
casties
parents: 9
diff changeset
150 }
90911b2da322 more work on permissions...
casties
parents: 9
diff changeset
151 return id;
90911b2da322 more work on permissions...
casties
parents: 9
diff changeset
152 }
90911b2da322 more work on permissions...
casties
parents: 9
diff changeset
153
90911b2da322 more work on permissions...
casties
parents: 9
diff changeset
154 /**
90911b2da322 more work on permissions...
casties
parents: 9
diff changeset
155 * Returns an uri from a short id.
90911b2da322 more work on permissions...
casties
parents: 9
diff changeset
156 *
90911b2da322 more work on permissions...
casties
parents: 9
diff changeset
157 * @param id
90911b2da322 more work on permissions...
casties
parents: 9
diff changeset
158 * @return
90911b2da322 more work on permissions...
casties
parents: 9
diff changeset
159 */
90911b2da322 more work on permissions...
casties
parents: 9
diff changeset
160 public static String getUriFromId(String id, boolean isGroup) {
90911b2da322 more work on permissions...
casties
parents: 9
diff changeset
161 String uri = null;
58
f5c0e6df7e88 made uri prefixes in store configurable.
casties
parents: 18
diff changeset
162 String prefix = BaseRestlet.PERSONS_URI_PREFIX;
10
90911b2da322 more work on permissions...
casties
parents: 9
diff changeset
163 if (isGroup) {
58
f5c0e6df7e88 made uri prefixes in store configurable.
casties
parents: 18
diff changeset
164 prefix = BaseRestlet.GROUPS_URI_PREFIX;
10
90911b2da322 more work on permissions...
casties
parents: 9
diff changeset
165 }
14
629e15b345aa permissions mostly work. need more server-side checking.
casties
parents: 13
diff changeset
166 if (id != null && !id.startsWith("http://")) {
629e15b345aa permissions mostly work. need more server-side checking.
casties
parents: 13
diff changeset
167 uri = prefix + id;
10
90911b2da322 more work on permissions...
casties
parents: 9
diff changeset
168 }
90911b2da322 more work on permissions...
casties
parents: 9
diff changeset
169 return uri;
90911b2da322 more work on permissions...
casties
parents: 9
diff changeset
170 }
90911b2da322 more work on permissions...
casties
parents: 9
diff changeset
171
9
b2bfc3bc9ba8 new internal actor class for creator.
casties
parents:
diff changeset
172 }