source: AnnotationManagerN4J/src/main/java/de/mpiwg/itgroup/annotations/Actor.java @ 70:2b1e6df5e21a

Last change on this file since 70:2b1e6df5e21a was 70:2b1e6df5e21a, checked in by casties, 10 years ago

added lgpl_v3 license information.

File size: 3.8 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            return store.isPersonInGroup(person, (Group) this);           
61        }
62        return false;
63    }
64
65    /**
66     * @return the uri
67     */
68    public String getUri() {
69        return uri;
70    }
71
72    /**
73     * Returns the uri (uses id if empty).
74     *
75     * @return the uri
76     */
77    public String getUriString() {
78        if (uri == null) {
79            return getUriFromId(id, isGroup());
80        }
81        return uri;
82    }
83
84    /**
85     * @param uri
86     *            the uri to set
87     */
88    public void setUri(String uri) {
89        this.uri = uri;
90    }
91
92    /**
93     * @return the name
94     */
95    public String getName() {
96        return name;
97    }
98
99    /**
100     * @param name
101     *            the name to set
102     */
103    public void setName(String name) {
104        this.name = name;
105    }
106
107    /**
108     * @return the id
109     */
110    public String getId() {
111        return id;
112    }
113
114    /**
115     * Returns id as a String starting with "group:" for groups.
116     *
117     * @return
118     */
119    public abstract String getIdString();
120
121    /**
122     * @param id
123     *            the id to set
124     */
125    public void setId(String id) {
126        this.id = id;
127    }
128
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;
137        String prefix = BaseRestlet.PERSONS_URI_PREFIX;
138        if (isGroup) {
139            prefix = BaseRestlet.GROUPS_URI_PREFIX;
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;
155        String prefix = BaseRestlet.PERSONS_URI_PREFIX;
156        if (isGroup) {
157            prefix = BaseRestlet.GROUPS_URI_PREFIX;
158        }
159        if (id != null && !id.startsWith("http://")) {
160            uri = prefix + id;
161        }
162        return uri;
163    }
164
165}
Note: See TracBrowser for help on using the repository browser.