/** * */ package de.mpiwg.itgroup.annotations; import de.mpiwg.itgroup.annotations.old.NS; /** * @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 an Actor with this id. If this is * a Group returns true when the Person is in the Group. * * @param userId * @return */ public boolean isEquivalentWith(String userId) { if (userId == null) return false; if (userId.equals(getIdString())) { return true; } if (isGroup()) { // TODO: check if person in group } 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 = NS.MPIWG_PERSONS_URL; if (isGroup) { prefix = NS.MPIWG_GROUPS_URL; } 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 = NS.MPIWG_PERSONS_URL; if (isGroup) { prefix = NS.MPIWG_GROUPS_URL; } if (id != null && !id.startsWith("http://")) { uri = prefix + id; } return uri; } }