source: AnnotationManagerN4J/src/main/java/de/mpiwg/itgroup/annotations/Actor.java @ 15:58357a4b86de

Last change on this file since 15:58357a4b86de was 15:58357a4b86de, checked in by casties, 12 years ago

ASSIGNED - # 249: Annotations shared in groups
https://it-dev.mpiwg-berlin.mpg.de/tracs/mpdl-project-software/ticket/249

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