1 | /** |
---|
2 | * |
---|
3 | */ |
---|
4 | package de.mpiwg.itgroup.annotations; |
---|
5 | |
---|
6 | import de.mpiwg.itgroup.annotations.neo4j.AnnotationStore; |
---|
7 | |
---|
8 | /** |
---|
9 | * @author casties |
---|
10 | * |
---|
11 | */ |
---|
12 | public abstract class Actor { |
---|
13 | |
---|
14 | public String uri; |
---|
15 | public String name; |
---|
16 | public String id; |
---|
17 | |
---|
18 | /** |
---|
19 | * @return if this Actor is a Group |
---|
20 | */ |
---|
21 | public abstract boolean isGroup(); |
---|
22 | |
---|
23 | /** |
---|
24 | * Returns if this Actor is equivalent to Person person. If this is |
---|
25 | * a Group returns true when the Person is in the Group. |
---|
26 | * |
---|
27 | * @param person |
---|
28 | * @param store AnnotationStore to check group membership |
---|
29 | * @return |
---|
30 | */ |
---|
31 | public boolean isEquivalentWith(Person person, AnnotationStore store) { |
---|
32 | if (person == null) return false; |
---|
33 | if (person.equals(this)) return true; |
---|
34 | if (person.getIdString().equals(this.getIdString())) return true; |
---|
35 | if (isGroup() && store != null) { |
---|
36 | // check if person in group |
---|
37 | return store.isPersonInGroup(person, (Group) this); |
---|
38 | } |
---|
39 | return false; |
---|
40 | } |
---|
41 | |
---|
42 | /** |
---|
43 | * @return the uri |
---|
44 | */ |
---|
45 | public String getUri() { |
---|
46 | return uri; |
---|
47 | } |
---|
48 | |
---|
49 | /** |
---|
50 | * Returns the uri (uses id if empty). |
---|
51 | * |
---|
52 | * @return the uri |
---|
53 | */ |
---|
54 | public String getUriString() { |
---|
55 | if (uri == null) { |
---|
56 | return getUriFromId(id, isGroup()); |
---|
57 | } |
---|
58 | return uri; |
---|
59 | } |
---|
60 | |
---|
61 | /** |
---|
62 | * @param uri |
---|
63 | * the uri to set |
---|
64 | */ |
---|
65 | public void setUri(String uri) { |
---|
66 | this.uri = uri; |
---|
67 | } |
---|
68 | |
---|
69 | /** |
---|
70 | * @return the name |
---|
71 | */ |
---|
72 | public String getName() { |
---|
73 | return name; |
---|
74 | } |
---|
75 | |
---|
76 | /** |
---|
77 | * @param name |
---|
78 | * the name to set |
---|
79 | */ |
---|
80 | public void setName(String name) { |
---|
81 | this.name = name; |
---|
82 | } |
---|
83 | |
---|
84 | /** |
---|
85 | * @return the id |
---|
86 | */ |
---|
87 | public String getId() { |
---|
88 | return id; |
---|
89 | } |
---|
90 | |
---|
91 | /** |
---|
92 | * Returns id as a String starting with "group:" for groups. |
---|
93 | * |
---|
94 | * @return |
---|
95 | */ |
---|
96 | public abstract String getIdString(); |
---|
97 | |
---|
98 | /** |
---|
99 | * @param id |
---|
100 | * the id to set |
---|
101 | */ |
---|
102 | public void setId(String id) { |
---|
103 | this.id = id; |
---|
104 | } |
---|
105 | |
---|
106 | /** |
---|
107 | * Returns a short id from an uri. |
---|
108 | * |
---|
109 | * @param uri |
---|
110 | * @return |
---|
111 | */ |
---|
112 | public static String getIdFromUri(String uri, boolean isGroup) { |
---|
113 | String id = null; |
---|
114 | String prefix = NS.MPIWG_PERSONS_URL; |
---|
115 | if (isGroup) { |
---|
116 | prefix = NS.MPIWG_GROUPS_URL; |
---|
117 | } |
---|
118 | if (uri != null && uri.startsWith(prefix)) { |
---|
119 | id = uri.replace(prefix, ""); |
---|
120 | } |
---|
121 | return id; |
---|
122 | } |
---|
123 | |
---|
124 | /** |
---|
125 | * Returns an uri from a short id. |
---|
126 | * |
---|
127 | * @param id |
---|
128 | * @return |
---|
129 | */ |
---|
130 | public static String getUriFromId(String id, boolean isGroup) { |
---|
131 | String uri = null; |
---|
132 | String prefix = NS.MPIWG_PERSONS_URL; |
---|
133 | if (isGroup) { |
---|
134 | prefix = NS.MPIWG_GROUPS_URL; |
---|
135 | } |
---|
136 | if (id != null && !id.startsWith("http://")) { |
---|
137 | uri = prefix + id; |
---|
138 | } |
---|
139 | return uri; |
---|
140 | } |
---|
141 | |
---|
142 | } |
---|