diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/EditLinkSuppressor.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/EditLinkSuppressor.java new file mode 100644 index 000000000..87682ba6b --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/EditLinkSuppressor.java @@ -0,0 +1,94 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + +package edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual; + +import java.util.Arrays; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; + +/** + * Sometimes we don't want to show an Add, Edit, or Delete link for a particular + * property, no matter who the user is. + * + * TODO These are hard-coded while we wait for the Application Ontology to be + * implemented. + */ +public class EditLinkSuppressor { + private static final Log log = LogFactory.getLog(EditLinkSuppressor.class); + + private static final String CORE = "http://vivoweb.org/ontology/core#"; + private static final String PUB_TO_AUTHORSHIP = core("informationResourceInAuthorship"); + private static final String PERSON_TO_AUTHORSHIP = core("authorInAuthorship"); + private static final String AUTHORSHIP_TO_PERSON = core("linkedAuthor"); + private static final String AUTHORSHIP_TO_PUB = core("linkedInformationResource"); + private static final String INDIVIDUAL_TO_WEBPAGE = core("webpage"); + private static final String WEBPAGE_TO_INDIVIDUAL = core("webpageOf"); + private static final String HAS_RESEARCH_AREA = core("hasResearchArea"); + private static final String HAS_SUBJECT_AREA = core("hasSubjectArea"); + private static final String RESEARCH_AREA_OF = core("researchAreaOf"); + private static final String SUBJECT_AREA_FOR = core("subjectAreaFor"); + + private static String core(String localName) { + return CORE + localName; + } + + private static final List suppressAddLinksForThese = Arrays + .asList(new String[] { AUTHORSHIP_TO_PERSON, AUTHORSHIP_TO_PUB, + WEBPAGE_TO_INDIVIDUAL }); + + private static final List suppressEditLinksForThese = Arrays + .asList(new String[] { WEBPAGE_TO_INDIVIDUAL }); + + private static final List suppressDeleteLinksForThese = Arrays + .asList(new String[] { PUB_TO_AUTHORSHIP, PERSON_TO_AUTHORSHIP, + AUTHORSHIP_TO_PERSON, AUTHORSHIP_TO_PUB, + INDIVIDUAL_TO_WEBPAGE, WEBPAGE_TO_INDIVIDUAL, + HAS_RESEARCH_AREA, RESEARCH_AREA_OF, HAS_SUBJECT_AREA, + SUBJECT_AREA_FOR }); + + // TODO When we remove the hard-coding, vreq will allow us to find the + // application ontology model. + @SuppressWarnings("unused") + private final VitroRequest vreq; + + public EditLinkSuppressor(VitroRequest vreq) { + this.vreq = vreq; + } + + /** + * Should we suppress the Add link on this property? + */ + public boolean isAddLinkSuppressed(String propertyUri) { + if (propertyUri == null) { + log.error("Suppressing the add link on a null property."); + return true; + } + return suppressAddLinksForThese.contains(propertyUri); + } + + /** + * Should we suppress the Edit link on this property? + */ + public boolean isEditLinkSuppressed(String propertyUri) { + if (propertyUri == null) { + log.error("Suppressing the edit link on a null property."); + return true; + } + return suppressEditLinksForThese.contains(propertyUri); + } + + /** + * Should we suppress the Delete link on this property? + */ + public boolean isDeleteLinkSuppressed(String propertyUri) { + if (propertyUri == null) { + log.error("Suppressing the delete link on a null property."); + return true; + } + return suppressDeleteLinksForThese.contains(propertyUri); + } +} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/ObjectPropertyStatementTemplateModel.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/ObjectPropertyStatementTemplateModel.java index c47f02f68..81389cdd2 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/ObjectPropertyStatementTemplateModel.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/ObjectPropertyStatementTemplateModel.java @@ -49,6 +49,11 @@ public class ObjectPropertyStatementTemplateModel extends PropertyStatementTempl } private String makeDeleteUrl() { + // Is the delete link suppressed for this property? + if (new EditLinkSuppressor(vreq).isDeleteLinkSuppressed(propertyUri)) { + return ""; + } + // Determine whether the statement can be deleted RequestedAction action = new DropObjectPropStmt(subjectUri, propertyUri, objectUri); if ( ! PolicyHelper.isAuthorizedForActions(vreq, action) ) { @@ -85,7 +90,12 @@ public class ObjectPropertyStatementTemplateModel extends PropertyStatementTempl } private String makeEditUrl(ObjectPropertyStatement ops) { - // Determine whether the statement can be edited + // Is the edit link suppressed for this property? + if (new EditLinkSuppressor(vreq).isEditLinkSuppressed(propertyUri)) { + return ""; + } + + // Determine whether the statement can be edited RequestedAction action = new EditObjPropStmt(ops); if ( ! PolicyHelper.isAuthorizedForActions(vreq, action) ) { return ""; diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/ObjectPropertyTemplateModel.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/ObjectPropertyTemplateModel.java index 8761bf0e1..fa2f27ef8 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/ObjectPropertyTemplateModel.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/ObjectPropertyTemplateModel.java @@ -102,6 +102,10 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel } protected void setAddUrl(Property property) { + // Is the add link suppressed for this property? + if (new EditLinkSuppressor(vreq).isAddLinkSuppressed(propertyUri)) { + return; + } // Determine whether a new statement can be added RequestedAction action = new AddObjectPropStmt(subjectUri, propertyUri, RequestActionConstants.SOME_URI);