diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/beans/Property.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/beans/Property.java index e63d0858e..3eac69b34 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/beans/Property.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/beans/Property.java @@ -17,6 +17,9 @@ public class Property extends BaseResourceBean { private final boolean subjectSide = true; // only relevant to ObjectProperty private String domainVClassURI = null; private String rangeVClassURI = null; + private boolean editLinkSuppressed = false; + private boolean addLinkSuppressed = false; + private boolean deleteLinkSuppressed = false; public Property() { this.groupURI = null; @@ -69,6 +72,33 @@ public class Property extends BaseResourceBean { return subjectSide; } + public boolean isEditLinkSuppressed() { + return editLinkSuppressed; + } + + public boolean isAddLinkSuppressed() { + return addLinkSuppressed; + } + + public boolean isDeleteLinkSuppressed() { + return deleteLinkSuppressed; + } + + public void setEditLinkSuppressed(boolean editLinkSuppressed) { + this.editLinkSuppressed = editLinkSuppressed; + } + + public void setAddLinkSuppressed(boolean addLinkSuppressed) { + if (this.addLinkSuppressed) { + throw new RuntimeException("addLinkSuppressed already true"); + } + this.addLinkSuppressed = addLinkSuppressed; + } + + public void setDeleteLinkSuppressed(boolean deleteLinkSuppressed) { + this.deleteLinkSuppressed = deleteLinkSuppressed; + } + /** * Sorts Property objects, by property rank, then alphanumeric. * @author bdc34 diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/VitroVocabulary.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/VitroVocabulary.java index ae21af42d..a24f26c3e 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/VitroVocabulary.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/VitroVocabulary.java @@ -7,6 +7,7 @@ public class VitroVocabulary { public static final String vitroURI = "http://vitro.mannlib.cornell.edu/ns/vitro/0.7#"; + public static final String configURI= "http://vitro.mannlib.cornell.edu/ns/vitro/ApplicationConfiguration#"; public static final String VITRO_AUTH = "http://vitro.mannlib.cornell.edu/ns/vitro/authorization#"; public static final String VITRO_PUBLIC = "http://vitro.mannlib.cornell.edu/ns/vitro/public#"; @@ -95,6 +96,9 @@ public class VitroVocabulary { public static final String PROPERTY_CUSTOM_LIST_VIEW_ANNOT = vitroURI + "customListViewAnnot"; public static final String PROPERTY_SELECTFROMEXISTINGANNOT = vitroURI+"selectFromExistingAnnot"; public static final String PROPERTY_OFFERCREATENEWOPTIONANNOT = vitroURI+"offerCreateNewOptionAnnot"; + public static final String PROPERTY_EDITLINKSUPPRESSED = configURI + "editLinkSuppressed"; + public static final String PROPERTY_ADDLINKSUPPRESSED = configURI + "addLinkSuppressed"; + public static final String PROPERTY_DELETELINKSUPPRESSED = configURI + "deleteLinkSuppressed"; public static final String PROPERTY_INPROPERTYGROUPANNOT = vitroURI+"inPropertyGroupAnnot"; public static final String PROPERTYGROUP = vitroURI + "PropertyGroup"; public static final String MASKS_PROPERTY = vitroURI + "masksProperty"; diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/filtering/ObjectPropertyFiltering.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/filtering/ObjectPropertyFiltering.java index bf711c970..0706ba42e 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/filtering/ObjectPropertyFiltering.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/filtering/ObjectPropertyFiltering.java @@ -523,6 +523,36 @@ public class ObjectPropertyFiltering extends ObjectProperty { public void setCollateBySubclass(boolean collate) { innerObjectProperty.setCollateBySubclass(collate); } + + @Override + public boolean isEditLinkSuppressed() { + return innerObjectProperty.isEditLinkSuppressed(); + } + + @Override + public boolean isAddLinkSuppressed() { + return innerObjectProperty.isAddLinkSuppressed(); + } + + @Override + public boolean isDeleteLinkSuppressed() { + return innerObjectProperty.isDeleteLinkSuppressed(); + } + + @Override + public void setEditLinkSuppressed(boolean editLinkSuppressed) { + innerObjectProperty.setEditLinkSuppressed(editLinkSuppressed); + } + + @Override + public void setAddLinkSuppressed(boolean addLinkSuppressed) { + innerObjectProperty.setAddLinkSuppressed(addLinkSuppressed); + } + + @Override + public void setDeleteLinkSuppressed(boolean deleteLinkSuppressed) { + innerObjectProperty.setDeleteLinkSuppressed(deleteLinkSuppressed); + } } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/JenaBaseDaoCon.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/JenaBaseDaoCon.java index c315b4856..f8eb9e0cf 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/JenaBaseDaoCon.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/JenaBaseDaoCon.java @@ -75,6 +75,9 @@ public class JenaBaseDaoCon { protected AnnotationProperty PROPERTY_INPROPERTYGROUPANNOT = _constModel.createAnnotationProperty(VitroVocabulary.PROPERTY_INPROPERTYGROUPANNOT); protected AnnotationProperty PROPERTY_COLLATEBYSUBCLASSANNOT = _constModel.createAnnotationProperty(VitroVocabulary.PROPERTY_COLLATEBYSUBCLASSANNOT); protected AnnotationProperty PROPERTY_STUBOBJECTPROPERTYANNOT = _constModel.createAnnotationProperty(VitroVocabulary.PROPERTY_STUBOBJECTPROPERTYANNOT); + protected AnnotationProperty PROPERTY_EDITLINKSUPPRESSED = _constModel.createAnnotationProperty(VitroVocabulary.PROPERTY_EDITLINKSUPPRESSED); + protected AnnotationProperty PROPERTY_ADDLINKSUPPRESSED = _constModel.createAnnotationProperty(VitroVocabulary.PROPERTY_ADDLINKSUPPRESSED); + protected AnnotationProperty PROPERTY_DELETELINKSUPPRESSED = _constModel.createAnnotationProperty(VitroVocabulary.PROPERTY_DELETELINKSUPPRESSED); protected OntClass PROPERTYGROUP = _constModel.createClass(VitroVocabulary.PROPERTYGROUP); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/ObjectPropertyDaoJena.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/ObjectPropertyDaoJena.java index 0f0be8bf4..5e8dd058f 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/ObjectPropertyDaoJena.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/ObjectPropertyDaoJena.java @@ -37,6 +37,7 @@ import com.hp.hpl.jena.rdf.model.ResourceFactory; import com.hp.hpl.jena.rdf.model.Statement; import com.hp.hpl.jena.rdf.model.StmtIterator; import com.hp.hpl.jena.shared.Lock; +import com.hp.hpl.jena.sparql.expr.NodeValue; import com.hp.hpl.jena.util.iterator.ClosableIterator; import com.hp.hpl.jena.vocabulary.OWL; import com.hp.hpl.jena.vocabulary.RDF; @@ -224,6 +225,13 @@ public class ObjectPropertyDaoJena extends PropertyDaoJena implements ObjectProp Boolean collateBySubclass = getPropertyBooleanValue(op,PROPERTY_COLLATEBYSUBCLASSANNOT); p.setCollateBySubclass(collateBySubclass==null ? false : collateBySubclass); + Boolean editLinkSuppressed = getPropertyBooleanValue(op, PROPERTY_EDITLINKSUPPRESSED); + p.setEditLinkSuppressed(editLinkSuppressed == null ? false : editLinkSuppressed); + Boolean addLinkSuppressed = getPropertyBooleanValue(op, PROPERTY_ADDLINKSUPPRESSED); + p.setAddLinkSuppressed(addLinkSuppressed == null ? false : addLinkSuppressed); + Boolean deleteLinkSuppressed = getPropertyBooleanValue(op, PROPERTY_DELETELINKSUPPRESSED); + p.setDeleteLinkSuppressed(deleteLinkSuppressed == null ? false : deleteLinkSuppressed); + Resource groupRes = (Resource) op.getPropertyValue(PROPERTY_INPROPERTYGROUPANNOT); if (groupRes != null) { p.setGroupURI(groupRes.getURI()); @@ -297,7 +305,7 @@ public class ObjectPropertyDaoJena extends PropertyDaoJena implements ObjectProp String propQuery = "PREFIX rdfs: \n" + "PREFIX config: \n" + "PREFIX vitro: \n" + - "SELECT ?range ?label ?group ?customForm ?displayRank ?displayLevel ?updateLevel WHERE { \n" + + "SELECT ?range ?label ?group ?customForm ?displayRank ?displayLevel ?updateLevel ?editLinkSuppressed ?addLinkSuppressed ?deleteLinkSuppressed WHERE { \n" + " ?context config:configContextFor <" + propertyURI + "> . \n"; if (domainURI != null) { propQuery += " ?context config:qualifiedByDomain <" + domainURI + "> . \n"; @@ -310,6 +318,9 @@ public class ObjectPropertyDaoJena extends PropertyDaoJena implements ObjectProp propQuery += " ?context config:hasConfiguration ?configuration . \n" + " OPTIONAL { ?configuration config:propertyGroup ?group } \n" + " OPTIONAL { ?configuration config:displayName ?label } \n" + + " OPTIONAL { ?configuration config:editLinkSuppressed ?editLinkSuppressed } \n" + + " OPTIONAL { ?configuration config:addLinkSuppressed ?addLinkSuppressed } \n" + + " OPTIONAL { ?configuration config:deleteLinkSuppressed ?deleteLinkSuppressed } \n" + " OPTIONAL { ?configuration vitro:displayRankAnnot ?displayRank } \n" + " OPTIONAL { ?configuration vitro:customEntryFormAnnot ?customForm } \n" + " OPTIONAL { ?configuration vitro:hiddenFromDisplayBelowRoleLevelAnnot ?displayLevel } \n" + @@ -351,6 +362,18 @@ public class ObjectPropertyDaoJena extends PropertyDaoJena implements ObjectProp if (customFormLit != null) { op.setCustomEntryForm(customFormLit.getLexicalForm()); } + Literal editLinkSuppressedLit = qsoln.getLiteral("editLinkSuppressed"); + if (editLinkSuppressedLit != null ) { + op.setEditLinkSuppressed(editLinkSuppressedLit.getBoolean()); + } + Literal addLinkSuppressedLit = qsoln.getLiteral("addLinkSuppressed"); + if (addLinkSuppressedLit != null ) { + op.setAddLinkSuppressed(addLinkSuppressedLit.getBoolean()); + } + Literal deleteLinkSuppressedLit = qsoln.getLiteral("deleteLinkSuppressed"); + if (deleteLinkSuppressedLit != null ) { + op.setDeleteLinkSuppressed(deleteLinkSuppressedLit.getBoolean()); + } } } finally { qe.close(); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/ApplicationConfigurationOntologyUtils.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/ApplicationConfigurationOntologyUtils.java index d8f561a9b..281916a21 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/ApplicationConfigurationOntologyUtils.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/ApplicationConfigurationOntologyUtils.java @@ -23,6 +23,7 @@ import com.hp.hpl.jena.rdf.model.Model; import com.hp.hpl.jena.rdf.model.ModelFactory; import com.hp.hpl.jena.rdf.model.Resource; import com.hp.hpl.jena.rdf.model.ResourceFactory; +import com.hp.hpl.jena.sparql.expr.NodeValue; import com.hp.hpl.jena.vocabulary.RDFS; import edu.cornell.mannlib.vitro.webapp.beans.BaseResourceBean; @@ -55,7 +56,7 @@ public class ApplicationConfigurationOntologyUtils { String queryStr = "PREFIX rdfs: \n" + "PREFIX config: \n" + "PREFIX vitro: \n" + - "SELECT DISTINCT ?range ?domain ?label ?group ?customForm ?displayLevel ?updateLevel ?property WHERE { \n" + + "SELECT DISTINCT ?range ?domain ?label ?group ?customForm ?displayRank ?displayLevel ?updateLevel ?editLinkSuppressed ?addLinkSuppressed ?deleteLinkSuppressed ?property WHERE { \n" + // " ?p rdfs:subPropertyOf ?property . \n" + " ?context config:configContextFor ?property . \n" + " ?context config:qualifiedBy ?range . \n" + @@ -63,6 +64,10 @@ public class ApplicationConfigurationOntologyUtils { " OPTIONAL { ?context config:qualifiedByDomain ?domain } \n" + " OPTIONAL { ?configuration config:propertyGroup ?group } \n" + " OPTIONAL { ?configuration config:displayName ?label } \n" + + " OPTIONAL { ?configuration vitro:displayRankAnnot ?displayRank } \n" + + " OPTIONAL { ?configuration config:editLinkSuppressed ?editLinkSuppressed } \n" + + " OPTIONAL { ?configuration config:addLinkSuppressed ?addLinkSuppressed } \n" + + " OPTIONAL { ?configuration config:deleteLinkSuppressed ?deleteLinkSuppressed } \n" + " OPTIONAL { ?configuration vitro:customEntryFormAnnot ?customForm } \n" + " OPTIONAL { ?configuration vitro:hiddenFromDisplayBelowRoleLevelAnnot ?displayLevel } \n" + " OPTIONAL { ?configuration vitro:prohibitedFromUpdateBelowRoleLevelAnnot ?updateLevel } \n" + @@ -125,6 +130,11 @@ public class ApplicationConfigurationOntologyUtils { } else { newProp.setCustomEntryForm(op.getCustomEntryForm()); } + Literal displayRankLit = qsoln.getLiteral("displayRank"); + if(displayRankLit != null) { + op.setDomainDisplayTier( + Integer.parseInt(displayRankLit.getLexicalForm())); + } Resource displayLevelRes = qsoln.getResource("displayLevel"); if (displayLevelRes != null) { newProp.setHiddenFromDisplayBelowRoleLevel( @@ -137,7 +147,19 @@ public class ApplicationConfigurationOntologyUtils { BaseResourceBean.RoleLevel.getRoleByUri( updateLevelRes.getURI())); } - additionalProps.add(newProp); + Literal editLinkSuppressedLit = qsoln.getLiteral("editLinkSuppressed"); + if (editLinkSuppressedLit != null ) { + op.setEditLinkSuppressed(editLinkSuppressedLit.getBoolean()); + } + Literal addLinkSuppressedLit = qsoln.getLiteral("addLinkSuppressed"); + if (addLinkSuppressedLit != null ) { + op.setAddLinkSuppressed(addLinkSuppressedLit.getBoolean()); + } + Literal deleteLinkSuppressedLit = qsoln.getLiteral("deleteLinkSuppressed"); + if (deleteLinkSuppressedLit != null ) { + op.setDeleteLinkSuppressed(deleteLinkSuppressedLit.getBoolean()); + } + additionalProps.add(newProp); } } finally { qe.close(); 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 deleted file mode 100644 index 773d913a5..000000000 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/EditLinkSuppressor.java +++ /dev/null @@ -1,95 +0,0 @@ -/* $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.beans.Property; -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(Property property) { - if (property == null) { - log.error("Suppressing the add link on a null property."); - return true; - } - return suppressAddLinksForThese.contains(property.getURI()); - } - - /** - * Should we suppress the Edit link on this property? - */ - public boolean isEditLinkSuppressed(Property property) { - if (property == null || property.getURI() == null) { - log.error("Suppressing the edit link on a null property."); - return true; - } - return suppressEditLinksForThese.contains(property.getURI()); - } - - /** - * Should we suppress the Delete link on this property? - */ - public boolean isDeleteLinkSuppressed(Property property) { - if (property == null || property.getURI() == null) { - log.error("Suppressing the delete link on a null property."); - return true; - } - return suppressDeleteLinksForThese.contains(property.getURI()); - } -} 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 757fab213..c9da36ce8 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 @@ -53,7 +53,7 @@ public class ObjectPropertyStatementTemplateModel extends PropertyStatementTempl private String makeDeleteUrl() { // Is the delete link suppressed for this property? - if (new EditLinkSuppressor(vreq).isDeleteLinkSuppressed(property)) { + if (property.isDeleteLinkSuppressed()) { return ""; } @@ -95,7 +95,7 @@ public class ObjectPropertyStatementTemplateModel extends PropertyStatementTempl private String makeEditUrl(ObjectPropertyStatement ops) { // Is the edit link suppressed for this property? - if (new EditLinkSuppressor(vreq).isEditLinkSuppressed(property)) { + if (property.isEditLinkSuppressed()) { 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 9392de857..2e8c59397 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 @@ -110,7 +110,7 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel protected void setAddUrl(Property property) { // Is the add link suppressed for this property? - if (new EditLinkSuppressor(vreq).isAddLinkSuppressed(property)) { + if (property.isAddLinkSuppressed()) { return; }