source: AnnotationManagerN4J/src/main/java/de/mpiwg/itgroup/annotations/Actor.java @ 58:f5c0e6df7e88

Last change on this file since 58:f5c0e6df7e88 was 58:f5c0e6df7e88, checked in by casties, 11 years ago

made uri prefixes in store configurable.

File size: 3.0 KB
Line 
1/**
2 *
3 */
4package de.mpiwg.itgroup.annotations;
5
6import de.mpiwg.itgroup.annotations.neo4j.AnnotationStore;
7import de.mpiwg.itgroup.annotations.restlet.BaseRestlet;
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(this)) return true;
35        if (person.getIdString().equals(this.getIdString())) return true;
36        if (isGroup() && store != null) {
37            // check if person in group
38            return store.isPersonInGroup(person, (Group) this);           
39        }
40        return false;
41    }
42
43    /**
44     * @return the uri
45     */
46    public String getUri() {
47        return uri;
48    }
49
50    /**
51     * Returns the uri (uses id if empty).
52     *
53     * @return the uri
54     */
55    public String getUriString() {
56        if (uri == null) {
57            return getUriFromId(id, isGroup());
58        }
59        return uri;
60    }
61
62    /**
63     * @param uri
64     *            the uri to set
65     */
66    public void setUri(String uri) {
67        this.uri = uri;
68    }
69
70    /**
71     * @return the name
72     */
73    public String getName() {
74        return name;
75    }
76
77    /**
78     * @param name
79     *            the name to set
80     */
81    public void setName(String name) {
82        this.name = name;
83    }
84
85    /**
86     * @return the id
87     */
88    public String getId() {
89        return id;
90    }
91
92    /**
93     * Returns id as a String starting with "group:" for groups.
94     *
95     * @return
96     */
97    public abstract String getIdString();
98
99    /**
100     * @param id
101     *            the id to set
102     */
103    public void setId(String id) {
104        this.id = id;
105    }
106
107    /**
108     * Returns a short id from an uri.
109     *
110     * @param uri
111     * @return
112     */
113    public static String getIdFromUri(String uri, boolean isGroup) {
114        String id = null;
115        String prefix = BaseRestlet.PERSONS_URI_PREFIX;
116        if (isGroup) {
117            prefix = BaseRestlet.GROUPS_URI_PREFIX;
118        }
119        if (uri != null && uri.startsWith(prefix)) {
120            id = uri.replace(prefix, "");
121        }
122        return id;
123    }
124
125    /**
126     * Returns an uri from a short id.
127     *
128     * @param id
129     * @return
130     */
131    public static String getUriFromId(String id, boolean isGroup) {
132        String uri = null;
133        String prefix = BaseRestlet.PERSONS_URI_PREFIX;
134        if (isGroup) {
135            prefix = BaseRestlet.GROUPS_URI_PREFIX;
136        }
137        if (id != null && !id.startsWith("http://")) {
138            uri = prefix + id;
139        }
140        return uri;
141    }
142
143}
Note: See TracBrowser for help on using the repository browser.