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

Last change on this file since 88:b406507a953d was 88:b406507a953d, checked in by casties, 9 years ago

upped version to 0.5.
can use display name and groups from auth token.

File size: 4.0 KB
Line 
1/**
2 *
3 */
4package de.mpiwg.itgroup.annotations;
5
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
28import de.mpiwg.itgroup.annotations.neo4j.AnnotationStore;
29import de.mpiwg.itgroup.annotations.restlet.BaseRestlet;
30
31/**
32 * @author casties
33 *
34 */
35public abstract class Actor {
36
37    public String uri;
38    public String name;
39    public String id;
40
41    /**
42     * @return if this Actor is a Group
43     */
44    public abstract boolean isGroup();
45
46    /**
47     * Returns if this Actor is equivalent to Person person. If this is
48     * a Group returns true when the Person is in the Group.
49     *
50     * @param person
51     * @param store AnnotationStore to check group membership
52     * @return
53     */
54    public boolean isEquivalentWith(Person person, AnnotationStore store) {
55        if (person == null) return false;
56        if (person.equals(this)) return true;
57        if (person.getIdString().equals(this.getIdString())) return true;
58        if (isGroup() && store != null) {
59            // check if person in group
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
67            return store.isPersonInGroup(person, (Group) this);           
68        }
69        return false;
70    }
71
72    /**
73     * @return the uri
74     */
75    public String getUri() {
76        return uri;
77    }
78
79    /**
80     * Returns the uri (uses id if empty).
81     *
82     * @return the uri
83     */
84    public String getUriString() {
85        if (uri == null) {
86            return getUriFromId(id, isGroup());
87        }
88        return uri;
89    }
90
91    /**
92     * @param uri
93     *            the uri to set
94     */
95    public void setUri(String uri) {
96        this.uri = uri;
97    }
98
99    /**
100     * @return the name
101     */
102    public String getName() {
103        return name;
104    }
105
106    /**
107     * @param name
108     *            the name to set
109     */
110    public void setName(String name) {
111        this.name = name;
112    }
113
114    /**
115     * @return the id
116     */
117    public String getId() {
118        return id;
119    }
120
121    /**
122     * Returns id as a String starting with "group:" for groups.
123     *
124     * @return
125     */
126    public abstract String getIdString();
127
128    /**
129     * @param id
130     *            the id to set
131     */
132    public void setId(String id) {
133        this.id = id;
134    }
135
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;
144        String prefix = BaseRestlet.PERSONS_URI_PREFIX;
145        if (isGroup) {
146            prefix = BaseRestlet.GROUPS_URI_PREFIX;
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;
162        String prefix = BaseRestlet.PERSONS_URI_PREFIX;
163        if (isGroup) {
164            prefix = BaseRestlet.GROUPS_URI_PREFIX;
165        }
166        if (id != null && !id.startsWith("http://")) {
167            uri = prefix + id;
168        }
169        return uri;
170    }
171
172}
Note: See TracBrowser for help on using the repository browser.