Mercurial > hg > AnnotationManagerN4J
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 |
rev | line source |
---|---|
9 | 1 /** |
2 * | |
3 */ | |
4 package de.mpiwg.itgroup.annotations; | |
5 | |
70 | 6 /* |
7 * #%L | |
8 * AnnotationManager | |
9 * %% | |
10 * Copyright (C) 2012 - 2014 MPIWG Berlin | |
11 * %% | |
12 * This program is free software: you can redistribute it and/or modify | |
13 * it under the terms of the GNU Lesser General Public License as | |
14 * published by the Free Software Foundation, either version 3 of the | |
15 * License, or (at your option) any later version. | |
16 * | |
17 * This program is distributed in the hope that it will be useful, | |
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 * GNU General Lesser Public License for more details. | |
21 * | |
22 * You should have received a copy of the GNU General Lesser Public | |
23 * License along with this program. If not, see | |
24 * <http://www.gnu.org/licenses/lgpl-3.0.html>. | |
25 * #L% | |
26 */ | |
27 | |
15 | 28 import de.mpiwg.itgroup.annotations.neo4j.AnnotationStore; |
58 | 29 import de.mpiwg.itgroup.annotations.restlet.BaseRestlet; |
10 | 30 |
9 | 31 /** |
32 * @author casties | |
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
33 * |
9 | 34 */ |
10 | 35 public abstract class Actor { |
9 | 36 |
37 public String uri; | |
38 public String name; | |
10 | 39 public String id; |
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
40 |
9 | 41 /** |
10 | 42 * @return if this Actor is a Group |
9 | 43 */ |
10 | 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 | 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 | 50 * @param person |
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 | 54 public boolean isEquivalentWith(Person person, AnnotationStore store) { |
55 if (person == null) return false; | |
16 | 56 if (person.equals(this)) return true; |
57 if (person.getIdString().equals(this.getIdString())) return true; | |
15 | 58 if (isGroup() && store != null) { |
59 // check if person in group | |
88 | 60 if (person.groups != null) { |
61 // check person's groups | |
62 if (person.groups.contains(this.id)) { | |
63 return true; | |
64 } | |
65 } | |
66 // check in store | |
15 | 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 | 72 /** |
73 * @return the uri | |
74 */ | |
75 public String getUri() { | |
76 return uri; | |
77 } | |
13 | 78 |
79 /** | |
80 * Returns the uri (uses id if empty). | |
81 * | |
82 * @return the uri | |
83 */ | |
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 | 88 return uri; |
89 } | |
90 | |
9 | 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 | 94 */ |
95 public void setUri(String uri) { | |
96 this.uri = uri; | |
97 } | |
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
98 |
9 | 99 /** |
100 * @return the name | |
101 */ | |
102 public String getName() { | |
103 return name; | |
104 } | |
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
105 |
9 | 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 | 109 */ |
110 public void setName(String name) { | |
111 this.name = name; | |
112 } | |
10 | 113 |
114 /** | |
115 * @return the id | |
116 */ | |
117 public String getId() { | |
118 return id; | |
119 } | |
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
120 |
10 | 121 /** |
122 * Returns id as a String starting with "group:" for groups. | |
123 * | |
124 * @return | |
125 */ | |
126 public abstract String getIdString(); | |
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
127 |
10 | 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 | 131 */ |
132 public void setId(String id) { | |
133 this.id = id; | |
134 } | |
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
135 |
10 | 136 /** |
137 * Returns a short id from an uri. | |
138 * | |
139 * @param uri | |
140 * @return | |
141 */ | |
142 public static String getIdFromUri(String uri, boolean isGroup) { | |
143 String id = null; | |
58 | 144 String prefix = BaseRestlet.PERSONS_URI_PREFIX; |
10 | 145 if (isGroup) { |
58 | 146 prefix = BaseRestlet.GROUPS_URI_PREFIX; |
10 | 147 } |
148 if (uri != null && uri.startsWith(prefix)) { | |
149 id = uri.replace(prefix, ""); | |
150 } | |
151 return id; | |
152 } | |
153 | |
154 /** | |
155 * Returns an uri from a short id. | |
156 * | |
157 * @param id | |
158 * @return | |
159 */ | |
160 public static String getUriFromId(String id, boolean isGroup) { | |
161 String uri = null; | |
58 | 162 String prefix = BaseRestlet.PERSONS_URI_PREFIX; |
10 | 163 if (isGroup) { |
58 | 164 prefix = BaseRestlet.GROUPS_URI_PREFIX; |
10 | 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 | 168 } |
169 return uri; | |
170 } | |
171 | |
9 | 172 } |