Mercurial > hg > AnnotationManagerN4J
annotate src/main/java/de/mpiwg/itgroup/annotations/Actor.java @ 70:2b1e6df5e21a
added lgpl_v3 license information.
author | casties |
---|---|
date | Thu, 06 Mar 2014 15:09:04 +0100 |
parents | f5c0e6df7e88 |
children | b406507a953d |
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 | |
60 return store.isPersonInGroup(person, (Group) this); | |
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
61 } |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
62 return false; |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
63 } |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
64 |
9 | 65 /** |
66 * @return the uri | |
67 */ | |
68 public String getUri() { | |
69 return uri; | |
70 } | |
13 | 71 |
72 /** | |
73 * Returns the uri (uses id if empty). | |
74 * | |
75 * @return the uri | |
76 */ | |
77 public String getUriString() { | |
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
78 if (uri == null) { |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
79 return getUriFromId(id, isGroup()); |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
80 } |
13 | 81 return uri; |
82 } | |
83 | |
9 | 84 /** |
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
85 * @param uri |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
86 * the uri to set |
9 | 87 */ |
88 public void setUri(String uri) { | |
89 this.uri = uri; | |
90 } | |
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
91 |
9 | 92 /** |
93 * @return the name | |
94 */ | |
95 public String getName() { | |
96 return name; | |
97 } | |
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
98 |
9 | 99 /** |
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
100 * @param name |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
101 * the name to set |
9 | 102 */ |
103 public void setName(String name) { | |
104 this.name = name; | |
105 } | |
10 | 106 |
107 /** | |
108 * @return the id | |
109 */ | |
110 public String getId() { | |
111 return id; | |
112 } | |
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
113 |
10 | 114 /** |
115 * Returns id as a String starting with "group:" for groups. | |
116 * | |
117 * @return | |
118 */ | |
119 public abstract String getIdString(); | |
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
120 |
10 | 121 /** |
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
122 * @param id |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
123 * the id to set |
10 | 124 */ |
125 public void setId(String id) { | |
126 this.id = id; | |
127 } | |
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
128 |
10 | 129 /** |
130 * Returns a short id from an uri. | |
131 * | |
132 * @param uri | |
133 * @return | |
134 */ | |
135 public static String getIdFromUri(String uri, boolean isGroup) { | |
136 String id = null; | |
58 | 137 String prefix = BaseRestlet.PERSONS_URI_PREFIX; |
10 | 138 if (isGroup) { |
58 | 139 prefix = BaseRestlet.GROUPS_URI_PREFIX; |
10 | 140 } |
141 if (uri != null && uri.startsWith(prefix)) { | |
142 id = uri.replace(prefix, ""); | |
143 } | |
144 return id; | |
145 } | |
146 | |
147 /** | |
148 * Returns an uri from a short id. | |
149 * | |
150 * @param id | |
151 * @return | |
152 */ | |
153 public static String getUriFromId(String id, boolean isGroup) { | |
154 String uri = null; | |
58 | 155 String prefix = BaseRestlet.PERSONS_URI_PREFIX; |
10 | 156 if (isGroup) { |
58 | 157 prefix = BaseRestlet.GROUPS_URI_PREFIX; |
10 | 158 } |
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
159 if (id != null && !id.startsWith("http://")) { |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
13
diff
changeset
|
160 uri = prefix + id; |
10 | 161 } |
162 return uri; | |
163 } | |
164 | |
9 | 165 } |