removing EditLinkSuppressor

This commit is contained in:
brianjlowe 2013-09-04 09:59:59 -04:00
parent 3204db0be4
commit e75b424c81
9 changed files with 118 additions and 101 deletions

View file

@ -17,6 +17,9 @@ public class Property extends BaseResourceBean {
private final boolean subjectSide = true; // only relevant to ObjectProperty private final boolean subjectSide = true; // only relevant to ObjectProperty
private String domainVClassURI = null; private String domainVClassURI = null;
private String rangeVClassURI = null; private String rangeVClassURI = null;
private boolean editLinkSuppressed = false;
private boolean addLinkSuppressed = false;
private boolean deleteLinkSuppressed = false;
public Property() { public Property() {
this.groupURI = null; this.groupURI = null;
@ -69,6 +72,33 @@ public class Property extends BaseResourceBean {
return subjectSide; 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. * Sorts Property objects, by property rank, then alphanumeric.
* @author bdc34 * @author bdc34

View file

@ -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 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_AUTH = "http://vitro.mannlib.cornell.edu/ns/vitro/authorization#";
public static final String VITRO_PUBLIC = "http://vitro.mannlib.cornell.edu/ns/vitro/public#"; 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_CUSTOM_LIST_VIEW_ANNOT = vitroURI + "customListViewAnnot";
public static final String PROPERTY_SELECTFROMEXISTINGANNOT = vitroURI+"selectFromExistingAnnot"; public static final String PROPERTY_SELECTFROMEXISTINGANNOT = vitroURI+"selectFromExistingAnnot";
public static final String PROPERTY_OFFERCREATENEWOPTIONANNOT = vitroURI+"offerCreateNewOptionAnnot"; 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 PROPERTY_INPROPERTYGROUPANNOT = vitroURI+"inPropertyGroupAnnot";
public static final String PROPERTYGROUP = vitroURI + "PropertyGroup"; public static final String PROPERTYGROUP = vitroURI + "PropertyGroup";
public static final String MASKS_PROPERTY = vitroURI + "masksProperty"; public static final String MASKS_PROPERTY = vitroURI + "masksProperty";

View file

@ -524,5 +524,35 @@ public class ObjectPropertyFiltering extends ObjectProperty {
innerObjectProperty.setCollateBySubclass(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);
}
} }

View file

@ -75,6 +75,9 @@ public class JenaBaseDaoCon {
protected AnnotationProperty PROPERTY_INPROPERTYGROUPANNOT = _constModel.createAnnotationProperty(VitroVocabulary.PROPERTY_INPROPERTYGROUPANNOT); protected AnnotationProperty PROPERTY_INPROPERTYGROUPANNOT = _constModel.createAnnotationProperty(VitroVocabulary.PROPERTY_INPROPERTYGROUPANNOT);
protected AnnotationProperty PROPERTY_COLLATEBYSUBCLASSANNOT = _constModel.createAnnotationProperty(VitroVocabulary.PROPERTY_COLLATEBYSUBCLASSANNOT); protected AnnotationProperty PROPERTY_COLLATEBYSUBCLASSANNOT = _constModel.createAnnotationProperty(VitroVocabulary.PROPERTY_COLLATEBYSUBCLASSANNOT);
protected AnnotationProperty PROPERTY_STUBOBJECTPROPERTYANNOT = _constModel.createAnnotationProperty(VitroVocabulary.PROPERTY_STUBOBJECTPROPERTYANNOT); 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); protected OntClass PROPERTYGROUP = _constModel.createClass(VitroVocabulary.PROPERTYGROUP);

View file

@ -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.Statement;
import com.hp.hpl.jena.rdf.model.StmtIterator; import com.hp.hpl.jena.rdf.model.StmtIterator;
import com.hp.hpl.jena.shared.Lock; 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.util.iterator.ClosableIterator;
import com.hp.hpl.jena.vocabulary.OWL; import com.hp.hpl.jena.vocabulary.OWL;
import com.hp.hpl.jena.vocabulary.RDF; import com.hp.hpl.jena.vocabulary.RDF;
@ -224,6 +225,13 @@ public class ObjectPropertyDaoJena extends PropertyDaoJena implements ObjectProp
Boolean collateBySubclass = getPropertyBooleanValue(op,PROPERTY_COLLATEBYSUBCLASSANNOT); Boolean collateBySubclass = getPropertyBooleanValue(op,PROPERTY_COLLATEBYSUBCLASSANNOT);
p.setCollateBySubclass(collateBySubclass==null ? false : collateBySubclass); 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); Resource groupRes = (Resource) op.getPropertyValue(PROPERTY_INPROPERTYGROUPANNOT);
if (groupRes != null) { if (groupRes != null) {
p.setGroupURI(groupRes.getURI()); p.setGroupURI(groupRes.getURI());
@ -297,7 +305,7 @@ public class ObjectPropertyDaoJena extends PropertyDaoJena implements ObjectProp
String propQuery = "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \n" + String propQuery = "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \n" +
"PREFIX config: <http://vitro.mannlib.cornell.edu/ns/vitro/ApplicationConfiguration#> \n" + "PREFIX config: <http://vitro.mannlib.cornell.edu/ns/vitro/ApplicationConfiguration#> \n" +
"PREFIX vitro: <http://vitro.mannlib.cornell.edu/ns/vitro/0.7#> \n" + "PREFIX vitro: <http://vitro.mannlib.cornell.edu/ns/vitro/0.7#> \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"; " ?context config:configContextFor <" + propertyURI + "> . \n";
if (domainURI != null) { if (domainURI != null) {
propQuery += " ?context config:qualifiedByDomain <" + domainURI + "> . \n"; propQuery += " ?context config:qualifiedByDomain <" + domainURI + "> . \n";
@ -310,6 +318,9 @@ public class ObjectPropertyDaoJena extends PropertyDaoJena implements ObjectProp
propQuery += " ?context config:hasConfiguration ?configuration . \n" + propQuery += " ?context config:hasConfiguration ?configuration . \n" +
" OPTIONAL { ?configuration config:propertyGroup ?group } \n" + " OPTIONAL { ?configuration config:propertyGroup ?group } \n" +
" OPTIONAL { ?configuration config:displayName ?label } \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:displayRankAnnot ?displayRank } \n" +
" OPTIONAL { ?configuration vitro:customEntryFormAnnot ?customForm } \n" + " OPTIONAL { ?configuration vitro:customEntryFormAnnot ?customForm } \n" +
" OPTIONAL { ?configuration vitro:hiddenFromDisplayBelowRoleLevelAnnot ?displayLevel } \n" + " OPTIONAL { ?configuration vitro:hiddenFromDisplayBelowRoleLevelAnnot ?displayLevel } \n" +
@ -351,6 +362,18 @@ public class ObjectPropertyDaoJena extends PropertyDaoJena implements ObjectProp
if (customFormLit != null) { if (customFormLit != null) {
op.setCustomEntryForm(customFormLit.getLexicalForm()); 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 { } finally {
qe.close(); qe.close();

View file

@ -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.ModelFactory;
import com.hp.hpl.jena.rdf.model.Resource; import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.rdf.model.ResourceFactory; import com.hp.hpl.jena.rdf.model.ResourceFactory;
import com.hp.hpl.jena.sparql.expr.NodeValue;
import com.hp.hpl.jena.vocabulary.RDFS; import com.hp.hpl.jena.vocabulary.RDFS;
import edu.cornell.mannlib.vitro.webapp.beans.BaseResourceBean; import edu.cornell.mannlib.vitro.webapp.beans.BaseResourceBean;
@ -55,7 +56,7 @@ public class ApplicationConfigurationOntologyUtils {
String queryStr = "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \n" + String queryStr = "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \n" +
"PREFIX config: <http://vitro.mannlib.cornell.edu/ns/vitro/ApplicationConfiguration#> \n" + "PREFIX config: <http://vitro.mannlib.cornell.edu/ns/vitro/ApplicationConfiguration#> \n" +
"PREFIX vitro: <http://vitro.mannlib.cornell.edu/ns/vitro/0.7#> \n" + "PREFIX vitro: <http://vitro.mannlib.cornell.edu/ns/vitro/0.7#> \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" + // " ?p rdfs:subPropertyOf ?property . \n" +
" ?context config:configContextFor ?property . \n" + " ?context config:configContextFor ?property . \n" +
" ?context config:qualifiedBy ?range . \n" + " ?context config:qualifiedBy ?range . \n" +
@ -63,6 +64,10 @@ public class ApplicationConfigurationOntologyUtils {
" OPTIONAL { ?context config:qualifiedByDomain ?domain } \n" + " OPTIONAL { ?context config:qualifiedByDomain ?domain } \n" +
" OPTIONAL { ?configuration config:propertyGroup ?group } \n" + " OPTIONAL { ?configuration config:propertyGroup ?group } \n" +
" OPTIONAL { ?configuration config:displayName ?label } \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:customEntryFormAnnot ?customForm } \n" +
" OPTIONAL { ?configuration vitro:hiddenFromDisplayBelowRoleLevelAnnot ?displayLevel } \n" + " OPTIONAL { ?configuration vitro:hiddenFromDisplayBelowRoleLevelAnnot ?displayLevel } \n" +
" OPTIONAL { ?configuration vitro:prohibitedFromUpdateBelowRoleLevelAnnot ?updateLevel } \n" + " OPTIONAL { ?configuration vitro:prohibitedFromUpdateBelowRoleLevelAnnot ?updateLevel } \n" +
@ -125,6 +130,11 @@ public class ApplicationConfigurationOntologyUtils {
} else { } else {
newProp.setCustomEntryForm(op.getCustomEntryForm()); newProp.setCustomEntryForm(op.getCustomEntryForm());
} }
Literal displayRankLit = qsoln.getLiteral("displayRank");
if(displayRankLit != null) {
op.setDomainDisplayTier(
Integer.parseInt(displayRankLit.getLexicalForm()));
}
Resource displayLevelRes = qsoln.getResource("displayLevel"); Resource displayLevelRes = qsoln.getResource("displayLevel");
if (displayLevelRes != null) { if (displayLevelRes != null) {
newProp.setHiddenFromDisplayBelowRoleLevel( newProp.setHiddenFromDisplayBelowRoleLevel(
@ -137,6 +147,18 @@ public class ApplicationConfigurationOntologyUtils {
BaseResourceBean.RoleLevel.getRoleByUri( BaseResourceBean.RoleLevel.getRoleByUri(
updateLevelRes.getURI())); updateLevelRes.getURI()));
} }
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); additionalProps.add(newProp);
} }
} finally { } finally {

View file

@ -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<String> suppressAddLinksForThese = Arrays
.asList(new String[] { AUTHORSHIP_TO_PERSON, AUTHORSHIP_TO_PUB,
WEBPAGE_TO_INDIVIDUAL });
private static final List<String> suppressEditLinksForThese = Arrays
.asList(new String[] { WEBPAGE_TO_INDIVIDUAL });
private static final List<String> 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());
}
}

View file

@ -53,7 +53,7 @@ public class ObjectPropertyStatementTemplateModel extends PropertyStatementTempl
private String makeDeleteUrl() { private String makeDeleteUrl() {
// Is the delete link suppressed for this property? // Is the delete link suppressed for this property?
if (new EditLinkSuppressor(vreq).isDeleteLinkSuppressed(property)) { if (property.isDeleteLinkSuppressed()) {
return ""; return "";
} }
@ -95,7 +95,7 @@ public class ObjectPropertyStatementTemplateModel extends PropertyStatementTempl
private String makeEditUrl(ObjectPropertyStatement ops) { private String makeEditUrl(ObjectPropertyStatement ops) {
// Is the edit link suppressed for this property? // Is the edit link suppressed for this property?
if (new EditLinkSuppressor(vreq).isEditLinkSuppressed(property)) { if (property.isEditLinkSuppressed()) {
return ""; return "";
} }

View file

@ -110,7 +110,7 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel
protected void setAddUrl(Property property) { protected void setAddUrl(Property property) {
// Is the add link suppressed for this property? // Is the add link suppressed for this property?
if (new EditLinkSuppressor(vreq).isAddLinkSuppressed(property)) { if (property.isAddLinkSuppressed()) {
return; return;
} }