source: AnnotationManagerN4J/src/main/java/de/mpiwg/itgroup/annotations/Actor.java @ 14:629e15b345aa

Last change on this file since 14:629e15b345aa was 14:629e15b345aa, checked in by casties, 12 years ago

permissions mostly work. need more server-side checking.

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