/** * */ package de.mpiwg.itgroup.annotations; import de.mpiwg.itgroup.annotations.neo4j.AnnotationStore; import de.mpiwg.itgroup.annotations.restlet.BaseRestlet; /** * @author casties * */ public abstract class Actor { public String uri; public String name; public String id; /** * @return if this Actor is a Group */ public abstract boolean isGroup(); /** * Returns if this Actor is equivalent to Person person. If this is * a Group returns true when the Person is in the Group. * * @param person * @param store AnnotationStore to check group membership * @return */ public boolean isEquivalentWith(Person person, AnnotationStore store) { if (person == null) return false; if (person.equals(this)) return true; if (person.getIdString().equals(this.getIdString())) return true; if (isGroup() && store != null) { // check if person in group return store.isPersonInGroup(person, (Group) this); } return false; } /** * @return the uri */ public String getUri() { return uri; } /** * Returns the uri (uses id if empty). * * @return the uri */ public String getUriString() { if (uri == null) { return getUriFromId(id, isGroup()); } return uri; } /** * @param uri * the uri to set */ public void setUri(String uri) { this.uri = uri; } /** * @return the name */ public String getName() { return name; } /** * @param name * the name to set */ public void setName(String name) { this.name = name; } /** * @return the id */ public String getId() { return id; } /** * Returns id as a String starting with "group:" for groups. * * @return */ public abstract String getIdString(); /** * @param id * the id to set */ public void setId(String id) { this.id = id; } /** * Returns a short id from an uri. * * @param uri * @return */ public static String getIdFromUri(String uri, boolean isGroup) { String id = null; String prefix = BaseRestlet.PERSONS_URI_PREFIX; if (isGroup) { prefix = BaseRestlet.GROUPS_URI_PREFIX; } if (uri != null && uri.startsWith(prefix)) { id = uri.replace(prefix, ""); } return id; } /** * Returns an uri from a short id. * * @param id * @return */ public static String getUriFromId(String id, boolean isGroup) { String uri = null; String prefix = BaseRestlet.PERSONS_URI_PREFIX; if (isGroup) { prefix = BaseRestlet.GROUPS_URI_PREFIX; } if (id != null && !id.startsWith("http://")) { uri = prefix + id; } return uri; } }