view src/main/java/de/mpiwg/itgroup/annotations/Annotation.java @ 16:794077e6288c

CLOSED - # 252: Tags for Annotations https://it-dev.mpiwg-berlin.mpg.de/tracs/mpdl-project-software/ticket/252
author casties
date Tue, 04 Sep 2012 20:02:59 +0200
parents 58357a4b86de
children 715aa11d138b
line wrap: on
line source

/**
 * 
 */
package de.mpiwg.itgroup.annotations;

import java.util.List;
import java.util.Set;

import de.mpiwg.itgroup.annotations.neo4j.AnnotationStore;

/**
 * @author casties
 *
 */
public class Annotation {
    /**
     * The URI of this annotation.
     */
    protected String uri;

    /**
     * The annotation (body) text.
     */
    protected String bodyText;

    /**
     * The URI of the annotation text
     */
    protected String bodyUri;
    
    /**
     * The base URI of the annotation target.
     */
    protected String targetBaseUri;
    
    /**
     * The fragment part of the annotation target.
     */
    protected String targetFragment;
    
    /**
     * The types of annotation targets.
     *
     */
    public static enum FragmentTypes {
        XPOINTER, AREA
    };
    
    /**
     * The type of the annotation target fragment.
     */
    protected FragmentTypes fragmentType;
    
    /**
     * The creator of this annotation.
     */
    protected Actor creator;
    
    /**
     * The creation date of this annotation.
     */
    protected String created;

    /**
     * The user or group that has admin permissions.
     * null means any user.
     */
    protected Actor adminPermission;
    
    /**
     * The user or group that has delete permissions.
     * null means any user.
     */
    protected Actor deletePermission;
    
    /**
     * The user or group that has update permissions.
     * null means any user.
     */
    protected Actor updatePermission;
    
    /**
     * The user or group that has read permissions.
     * null means any user.
     */
    protected Actor readPermission;
       
    /**
     * List of tags on this Annotation.
     */
    protected Set<String> tags;
    
    /**
     * Returns if the requested action is allowed on this annotation.
     * 
     * @param action
     * @param user
     * @param store AnnotationStore to check group membership
     * @return
     */
    public boolean isActionAllowed(String action, Person user, AnnotationStore store) {
        if (action.equals("read")) {
            Actor reader = getReadPermission();
            if (reader == null) {
                return true;
            } else {
                return reader.isEquivalentWith(user, store);
            }
        } else if (action.equals("update")) {
            // require at least an authenticated user
            if (user == null) return false;
            Actor updater = getUpdatePermission();
            if (updater == null) {
                return true;
            } else {
                return updater.isEquivalentWith(user, store);
            }
        } else if (action.equals("delete")) {
            // require at least an authenticated user
            if (user == null) return false;
            Actor updater = getUpdatePermission();
            if (updater == null) {
                return true;
            } else {
                return updater.isEquivalentWith(user, store);
            }
        } else if (action.equals("admin")) {
            // require at least an authenticated user
            if (user == null) return false;
            Actor admin = getAdminPermission();
            if (admin == null) {
                return true;
            } else {
                return admin.isEquivalentWith(user, store);
            }
        }
        return false;
    }
    
    /**
     * @return the uri
     */
    public String getUri() {
        return uri;
    }

    /**
     * @param uri the uri to set
     */
    public void setUri(String uri) {
        this.uri = uri;
    }

    /**
     * @return the bodyText
     */
    public String getBodyText() {
        return bodyText;
    }

    /**
     * @param bodyText the bodyText to set
     */
    public void setBodyText(String bodyText) {
        this.bodyText = bodyText;
    }

    /**
     * @return the bodyUri
     */
    public String getBodyUri() {
        return bodyUri;
    }

    /**
     * @param bodyUri the bodyUri to set
     */
    public void setBodyUri(String bodyUri) {
        this.bodyUri = bodyUri;
    }

    /**
     * @return the targetBaseUri
     */
    public String getTargetBaseUri() {
        return targetBaseUri;
    }

    /**
     * @param targetBaseUri the targetBaseUri to set
     */
    public void setTargetBaseUri(String targetBaseUri) {
        this.targetBaseUri = targetBaseUri;
    }

    /**
     * @return the targetFragment
     */
    public String getTargetFragment() {
        return targetFragment;
    }

    /**
     * @param targetFragment the targetFragment to set
     */
    public void setTargetFragment(String targetFragment) {
        this.targetFragment = targetFragment;
    }

    /**
     * @return the targetType
     */
    public FragmentTypes getFragmentType() {
        return fragmentType;
    }

    /**
     * @param fragmentType the fragmentType to set
     */
    public void setFragmentType(FragmentTypes fragmentType) {
        this.fragmentType = fragmentType;
    }

    /**
     * @return the creator
     */
    public Actor getCreator() {
        return creator;
    }

    /**
     * @param creator the creator to set
     */
    public void setCreator(Actor creator) {
        this.creator = creator;
    }

    /**
     * @return the creatorUri
     */
    public String getCreatorUri() {
        if (creator != null) {
            return creator.getUri();
        }
        return null;
    }

    /**
     * @return the creatorName
     */
    public String getCreatorName() {
        if (creator != null) {
            return creator.getName();
        }
        return null;
    }

    /**
     * @return the created
     */
    public String getCreated() {
        return created;
    }

    /**
     * @param created the created to set
     */
    public void setCreated(String created) {
        this.created = created;
    }

    /**
     * @return the adminPermission
     */
    public Actor getAdminPermission() {
        return adminPermission;
    }

    /**
     * @param adminPermission the adminPermission to set
     */
    public void setAdminPermission(Actor adminPermission) {
        this.adminPermission = adminPermission;
    }

    /**
     * @return the deletePermission
     */
    public Actor getDeletePermission() {
        return deletePermission;
    }

    /**
     * @param deletePermission the deletePermission to set
     */
    public void setDeletePermission(Actor deletePermission) {
        this.deletePermission = deletePermission;
    }

    /**
     * @return the updatePermission
     */
    public Actor getUpdatePermission() {
        return updatePermission;
    }

    /**
     * @param updatePermission the updatePermission to set
     */
    public void setUpdatePermission(Actor updatePermission) {
        this.updatePermission = updatePermission;
    }

    /**
     * @return the readPermission
     */
    public Actor getReadPermission() {
        return readPermission;
    }

    /**
     * @param readPermission the readPermission to set
     */
    public void setReadPermission(Actor readPermission) {
        this.readPermission = readPermission;
    }

    /**
     * @return the tags
     */
    public Set<String> getTags() {
        return tags;
    }

    /**
     * @param tags the tags to set
     */
    public void setTags(Set<String> tags) {
        this.tags = tags;
    }
    
    
}