NIHVIVO-3542 Use a boolean flag to indicate whether the page is editable, instead of the presence or absence of an EditingPolicyHelper.
This commit is contained in:
parent
1b2ac02770
commit
b731c17f6a
13 changed files with 62 additions and 117 deletions
|
@ -37,13 +37,8 @@ import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.FieldVTwo;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.SelectListGeneratorVTwo;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.SelectListGeneratorVTwo;
|
||||||
import edu.cornell.mannlib.vitro.webapp.web.beanswrappers.ReadOnlyBeansWrapper;
|
import edu.cornell.mannlib.vitro.webapp.web.beanswrappers.ReadOnlyBeansWrapper;
|
||||||
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.BaseTemplateModel;
|
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.BaseTemplateModel;
|
||||||
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual.DataPropertyStatementTemplateModel;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual.EditingPolicyHelper;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual.ObjectPropertyStatementTemplateModel;
|
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual.ObjectPropertyStatementTemplateModel;
|
||||||
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual.ObjectPropertyTemplateModel;
|
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual.ObjectPropertyTemplateModel;
|
||||||
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual.PropertyStatementTemplateModel;
|
|
||||||
import freemarker.ext.beans.BeansWrapper;
|
|
||||||
import freemarker.template.DefaultObjectWrapper;
|
|
||||||
import freemarker.template.TemplateModel;
|
import freemarker.template.TemplateModel;
|
||||||
import freemarker.template.TemplateModelException;
|
import freemarker.template.TemplateModelException;
|
||||||
|
|
||||||
|
@ -455,7 +450,7 @@ public class EditConfigurationTemplateModel extends BaseTemplateModel {
|
||||||
predicateUri,
|
predicateUri,
|
||||||
objectKey,
|
objectKey,
|
||||||
statementDisplay,
|
statementDisplay,
|
||||||
null, null, vreq);
|
false, null, vreq);
|
||||||
ReadOnlyBeansWrapper wrapper = new ReadOnlyBeansWrapper();
|
ReadOnlyBeansWrapper wrapper = new ReadOnlyBeansWrapper();
|
||||||
return wrapper.wrap(osm);
|
return wrapper.wrap(osm);
|
||||||
}
|
}
|
||||||
|
@ -466,8 +461,7 @@ public class EditConfigurationTemplateModel extends BaseTemplateModel {
|
||||||
ObjectProperty op = EditConfigurationUtils.getObjectProperty(vreq);
|
ObjectProperty op = EditConfigurationUtils.getObjectProperty(vreq);
|
||||||
List<ObjectProperty> propList = new ArrayList<ObjectProperty>();
|
List<ObjectProperty> propList = new ArrayList<ObjectProperty>();
|
||||||
propList.add(op);
|
propList.add(op);
|
||||||
EditingPolicyHelper policyHelper = new EditingPolicyHelper(vreq);
|
ObjectPropertyTemplateModel otm = ObjectPropertyTemplateModel.getObjectPropertyTemplateModel(op, subject, vreq, true, propList);
|
||||||
ObjectPropertyTemplateModel otm = ObjectPropertyTemplateModel.getObjectPropertyTemplateModel(op, subject, vreq, policyHelper,propList);
|
|
||||||
ReadOnlyBeansWrapper wrapper = new ReadOnlyBeansWrapper();
|
ReadOnlyBeansWrapper wrapper = new ReadOnlyBeansWrapper();
|
||||||
return wrapper.wrap(otm);
|
return wrapper.wrap(otm);
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,21 +37,17 @@ public abstract class BaseIndividualTemplateModel extends BaseTemplateModel {
|
||||||
protected final Individual individual;
|
protected final Individual individual;
|
||||||
protected final LoginStatusBean loginStatusBean;
|
protected final LoginStatusBean loginStatusBean;
|
||||||
protected final VitroRequest vreq;
|
protected final VitroRequest vreq;
|
||||||
|
private final boolean editing;
|
||||||
|
|
||||||
protected GroupedPropertyList propertyList;
|
protected GroupedPropertyList propertyList;
|
||||||
|
|
||||||
private EditingPolicyHelper policyHelper;
|
|
||||||
|
|
||||||
public BaseIndividualTemplateModel(Individual individual, VitroRequest vreq) {
|
public BaseIndividualTemplateModel(Individual individual, VitroRequest vreq) {
|
||||||
this.vreq = vreq;
|
this.vreq = vreq;
|
||||||
this.individual = individual;
|
this.individual = individual;
|
||||||
this.loginStatusBean = LoginStatusBean.getBean(vreq);
|
this.loginStatusBean = LoginStatusBean.getBean(vreq);
|
||||||
// Needed for getting portal-sensitive urls. Remove if multi-portal support is removed.
|
// Needed for getting portal-sensitive urls. Remove if multi-portal support is removed.
|
||||||
|
|
||||||
// If editing, create a helper object to check requested actions against policies
|
this.editing = isEditable();
|
||||||
if (isEditable()) {
|
|
||||||
policyHelper = new EditingPolicyHelper(vreq);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean isVClass(String vClassUri) {
|
protected boolean isVClass(String vClassUri) {
|
||||||
|
@ -106,7 +102,7 @@ public abstract class BaseIndividualTemplateModel extends BaseTemplateModel {
|
||||||
|
|
||||||
public GroupedPropertyList getPropertyList() {
|
public GroupedPropertyList getPropertyList() {
|
||||||
if (propertyList == null) {
|
if (propertyList == null) {
|
||||||
propertyList = new GroupedPropertyList(individual, vreq, policyHelper);
|
propertyList = new GroupedPropertyList(individual, vreq, editing);
|
||||||
}
|
}
|
||||||
return propertyList;
|
return propertyList;
|
||||||
}
|
}
|
||||||
|
@ -135,7 +131,7 @@ public abstract class BaseIndividualTemplateModel extends BaseTemplateModel {
|
||||||
* are handled like ordinary ObjectProperty instances.
|
* are handled like ordinary ObjectProperty instances.
|
||||||
*/
|
*/
|
||||||
public NameStatementTemplateModel getNameStatement() {
|
public NameStatementTemplateModel getNameStatement() {
|
||||||
return new NameStatementTemplateModel(getUri(), vreq, policyHelper);
|
return new NameStatementTemplateModel(getUri(), vreq, editing);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* These methods simply forward to the methods of the wrapped individual. It would be desirable to
|
/* These methods simply forward to the methods of the wrapped individual. It would be desirable to
|
||||||
|
|
|
@ -39,11 +39,11 @@ public class CollatedObjectPropertyTemplateModel extends ObjectPropertyTemplateM
|
||||||
private final VClassDao vclassDao;
|
private final VClassDao vclassDao;
|
||||||
|
|
||||||
CollatedObjectPropertyTemplateModel(ObjectProperty op, Individual subject,
|
CollatedObjectPropertyTemplateModel(ObjectProperty op, Individual subject,
|
||||||
VitroRequest vreq, EditingPolicyHelper policyHelper,
|
VitroRequest vreq, boolean editing,
|
||||||
List<ObjectProperty> populatedObjectPropertyList)
|
List<ObjectProperty> populatedObjectPropertyList)
|
||||||
throws InvalidConfigurationException {
|
throws InvalidConfigurationException {
|
||||||
|
|
||||||
super(op, subject, vreq, policyHelper);
|
super(op, subject, vreq, editing);
|
||||||
|
|
||||||
vclassDao = vreq.getWebappDaoFactory().getVClassDao();
|
vclassDao = vreq.getWebappDaoFactory().getVClassDao();
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ public class CollatedObjectPropertyTemplateModel extends ObjectPropertyTemplateM
|
||||||
postprocess(statementData);
|
postprocess(statementData);
|
||||||
|
|
||||||
/* Collate the data */
|
/* Collate the data */
|
||||||
subclasses = collate(subjectUri, propertyUri, statementData, policyHelper);
|
subclasses = collate(subjectUri, propertyUri, statementData, editing);
|
||||||
|
|
||||||
for (SubclassTemplateModel subclass : subclasses) {
|
for (SubclassTemplateModel subclass : subclasses) {
|
||||||
List<ObjectPropertyStatementTemplateModel> list = subclass.getStatements();
|
List<ObjectPropertyStatementTemplateModel> list = subclass.getStatements();
|
||||||
|
@ -188,7 +188,7 @@ public class CollatedObjectPropertyTemplateModel extends ObjectPropertyTemplateM
|
||||||
|
|
||||||
// Collate the statements by subclass.
|
// Collate the statements by subclass.
|
||||||
private List<SubclassTemplateModel> collate(String subjectUri, String propertyUri,
|
private List<SubclassTemplateModel> collate(String subjectUri, String propertyUri,
|
||||||
List<Map<String, String>> statementData, EditingPolicyHelper policyHelper) {
|
List<Map<String, String>> statementData, boolean editing) {
|
||||||
|
|
||||||
String objectKey = getObjectKey();
|
String objectKey = getObjectKey();
|
||||||
|
|
||||||
|
@ -217,7 +217,7 @@ public class CollatedObjectPropertyTemplateModel extends ObjectPropertyTemplateM
|
||||||
}
|
}
|
||||||
|
|
||||||
listForThisSubclass.add(new ObjectPropertyStatementTemplateModel(subjectUri,
|
listForThisSubclass.add(new ObjectPropertyStatementTemplateModel(subjectUri,
|
||||||
propertyUri, objectKey, map, policyHelper, getTemplateName(), vreq));
|
propertyUri, objectKey, map, editing, getTemplateName(), vreq));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,13 +28,13 @@ public class DataPropertyStatementTemplateModel extends PropertyStatementTemplat
|
||||||
|
|
||||||
//Extended to include vitro request to check for special parameters
|
//Extended to include vitro request to check for special parameters
|
||||||
public DataPropertyStatementTemplateModel(String subjectUri, String propertyUri,
|
public DataPropertyStatementTemplateModel(String subjectUri, String propertyUri,
|
||||||
Literal literal, EditingPolicyHelper policyHelper, VitroRequest vreq) {
|
Literal literal, boolean editing, VitroRequest vreq) {
|
||||||
super(subjectUri, propertyUri, vreq);
|
super(subjectUri, propertyUri, vreq);
|
||||||
|
|
||||||
//attempt to strip any odd HTML
|
//attempt to strip any odd HTML
|
||||||
this.value = cleanTextForDisplay( literal.getLexicalForm() );
|
this.value = cleanTextForDisplay( literal.getLexicalForm() );
|
||||||
|
|
||||||
setEditUrls(literal, policyHelper, propertyUri);
|
setEditUrls(literal, editing, propertyUri);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -51,9 +51,9 @@ public class DataPropertyStatementTemplateModel extends PropertyStatementTemplat
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setEditUrls(Literal value, EditingPolicyHelper policyHelper, String propertyUri) {
|
protected void setEditUrls(Literal value, boolean editing, String propertyUri) {
|
||||||
|
|
||||||
if (policyHelper == null) {
|
if ( ! editing ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,9 +34,9 @@ public class DataPropertyTemplateModel extends PropertyTemplateModel {
|
||||||
private final List<DataPropertyStatementTemplateModel> statements;
|
private final List<DataPropertyStatementTemplateModel> statements;
|
||||||
|
|
||||||
DataPropertyTemplateModel(DataProperty dp, Individual subject, VitroRequest vreq,
|
DataPropertyTemplateModel(DataProperty dp, Individual subject, VitroRequest vreq,
|
||||||
EditingPolicyHelper policyHelper, List<DataProperty> populatedDataPropertyList) {
|
boolean editing, List<DataProperty> populatedDataPropertyList) {
|
||||||
|
|
||||||
super(dp, subject, policyHelper, vreq);
|
super(dp, subject, vreq);
|
||||||
setName(dp.getPublicName());
|
setName(dp.getPublicName());
|
||||||
|
|
||||||
statements = new ArrayList<DataPropertyStatementTemplateModel>();
|
statements = new ArrayList<DataPropertyStatementTemplateModel>();
|
||||||
|
@ -47,21 +47,19 @@ public class DataPropertyTemplateModel extends PropertyTemplateModel {
|
||||||
DataPropertyStatementDao dpDao = vreq.getWebappDaoFactory().getDataPropertyStatementDao();
|
DataPropertyStatementDao dpDao = vreq.getWebappDaoFactory().getDataPropertyStatementDao();
|
||||||
List<Literal> values = dpDao.getDataPropertyValuesForIndividualByProperty(subject, dp);
|
List<Literal> values = dpDao.getDataPropertyValuesForIndividualByProperty(subject, dp);
|
||||||
for (Literal value : values) {
|
for (Literal value : values) {
|
||||||
statements.add(new DataPropertyStatementTemplateModel(subjectUri, propertyUri, value, policyHelper, vreq));
|
statements.add(new DataPropertyStatementTemplateModel(subjectUri, propertyUri, value, editing, vreq));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log.debug("Data property " + getUri() + " is unpopulated.");
|
log.debug("Data property " + getUri() + " is unpopulated.");
|
||||||
}
|
}
|
||||||
|
|
||||||
setAddUrl(policyHelper, dp);
|
if ( editing ) {
|
||||||
|
setAddUrl(dp);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected void setAddUrl(EditingPolicyHelper policyHelper, Property property) {
|
protected void setAddUrl(Property property) {
|
||||||
|
|
||||||
if (policyHelper == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
DataProperty dp = (DataProperty) property;
|
DataProperty dp = (DataProperty) property;
|
||||||
// NIHVIVO-2790 vitro:moniker now included in the display, but don't allow new statements
|
// NIHVIVO-2790 vitro:moniker now included in the display, but don't allow new statements
|
||||||
|
|
|
@ -1,36 +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 org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundle;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.auth.identifier.RequestIdentifiers;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.auth.policy.RequestPolicyList;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.auth.policy.ifaces.Authorization;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.auth.policy.ifaces.PolicyDecision;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.auth.policy.ifaces.PolicyIface;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ifaces.RequestedAction;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
|
||||||
|
|
||||||
public class EditingPolicyHelper {
|
|
||||||
private static final Log log = LogFactory.getLog(EditingPolicyHelper.class);
|
|
||||||
|
|
||||||
private final PolicyIface policy;
|
|
||||||
private final IdentifierBundle ids;
|
|
||||||
|
|
||||||
public EditingPolicyHelper(VitroRequest vreq) {
|
|
||||||
this.policy = RequestPolicyList.getPolicies(vreq);
|
|
||||||
this.ids = RequestIdentifiers.getIdBundleForRequest(vreq);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected boolean isAuthorizedAction(RequestedAction action) {
|
|
||||||
PolicyDecision decision = getPolicyDecision(action);
|
|
||||||
return (decision != null && decision.getAuthorized() == Authorization.AUTHORIZED);
|
|
||||||
}
|
|
||||||
|
|
||||||
private PolicyDecision getPolicyDecision(RequestedAction action) {
|
|
||||||
return policy.isAuthorized(ids, action);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -56,13 +56,11 @@ public class GroupedPropertyList extends BaseTemplateModel {
|
||||||
private List<PropertyGroupTemplateModel> groups;
|
private List<PropertyGroupTemplateModel> groups;
|
||||||
|
|
||||||
GroupedPropertyList(Individual subject, VitroRequest vreq,
|
GroupedPropertyList(Individual subject, VitroRequest vreq,
|
||||||
EditingPolicyHelper policyHelper) {
|
boolean editing) {
|
||||||
this.vreq = vreq;
|
this.vreq = vreq;
|
||||||
this.subject = subject;
|
this.subject = subject;
|
||||||
this.wdf = vreq.getWebappDaoFactory();
|
this.wdf = vreq.getWebappDaoFactory();
|
||||||
|
|
||||||
boolean editing = policyHelper != null;
|
|
||||||
|
|
||||||
// Create the property list for the subject. The properties will be put
|
// Create the property list for the subject. The properties will be put
|
||||||
// into groups later.
|
// into groups later.
|
||||||
List<Property> propertyList = new ArrayList<Property>();
|
List<Property> propertyList = new ArrayList<Property>();
|
||||||
|
@ -107,7 +105,7 @@ public class GroupedPropertyList extends BaseTemplateModel {
|
||||||
propertyGroupList.size());
|
propertyGroupList.size());
|
||||||
for (PropertyGroup propertyGroup : propertyGroupList) {
|
for (PropertyGroup propertyGroup : propertyGroupList) {
|
||||||
groups.add(new PropertyGroupTemplateModel(vreq, propertyGroup,
|
groups.add(new PropertyGroupTemplateModel(vreq, propertyGroup,
|
||||||
subject, policyHelper, populatedDataPropertyList,
|
subject, editing, populatedDataPropertyList,
|
||||||
populatedObjectPropertyList));
|
populatedObjectPropertyList));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ public class NameStatementTemplateModel extends
|
||||||
* This method handles the special case where we are creating a DataPropertyStatementTemplateModel outside the GroupedPropertyList.
|
* This method handles the special case where we are creating a DataPropertyStatementTemplateModel outside the GroupedPropertyList.
|
||||||
* Specifically, it allows rdfs:label to be treated like a data property statement and thus have editing links.
|
* Specifically, it allows rdfs:label to be treated like a data property statement and thus have editing links.
|
||||||
*/
|
*/
|
||||||
NameStatementTemplateModel(String subjectUri, VitroRequest vreq, EditingPolicyHelper policyHelper) {
|
NameStatementTemplateModel(String subjectUri, VitroRequest vreq, boolean editing) {
|
||||||
super(subjectUri, VitroVocabulary.LABEL, vreq);
|
super(subjectUri, VitroVocabulary.LABEL, vreq);
|
||||||
|
|
||||||
WebappDaoFactory wdf = vreq.getWebappDaoFactory();
|
WebappDaoFactory wdf = vreq.getWebappDaoFactory();
|
||||||
|
@ -35,7 +35,7 @@ public class NameStatementTemplateModel extends
|
||||||
|
|
||||||
if (literal != null) {
|
if (literal != null) {
|
||||||
value = cleanTextForDisplay( literal.getLexicalForm() );
|
value = cleanTextForDisplay( literal.getLexicalForm() );
|
||||||
setEditUrls(literal, policyHelper, propertyUri);
|
setEditUrls(literal, editing, propertyUri);
|
||||||
} else {
|
} else {
|
||||||
// If the individual has no rdfs:label, use the local name. It will not be editable. (This replicates previous behavior;
|
// If the individual has no rdfs:label, use the local name. It will not be editable. (This replicates previous behavior;
|
||||||
// perhaps we would want to allow a label to be added. But such individuals do not usually have their profiles viewed or
|
// perhaps we would want to allow a label to be added. But such individuals do not usually have their profiles viewed or
|
||||||
|
|
|
@ -31,7 +31,7 @@ public class ObjectPropertyStatementTemplateModel extends PropertyStatementTempl
|
||||||
private final String templateName;
|
private final String templateName;
|
||||||
private final String objectKey;
|
private final String objectKey;
|
||||||
public ObjectPropertyStatementTemplateModel(String subjectUri, String propertyUri, String objectKey,
|
public ObjectPropertyStatementTemplateModel(String subjectUri, String propertyUri, String objectKey,
|
||||||
Map<String, String> data, EditingPolicyHelper policyHelper, String templateName, VitroRequest vreq) {
|
Map<String, String> data, boolean editing, String templateName, VitroRequest vreq) {
|
||||||
super(subjectUri, propertyUri, vreq);
|
super(subjectUri, propertyUri, vreq);
|
||||||
|
|
||||||
this.data = data;
|
this.data = data;
|
||||||
|
@ -39,21 +39,22 @@ public class ObjectPropertyStatementTemplateModel extends PropertyStatementTempl
|
||||||
this.templateName = templateName;
|
this.templateName = templateName;
|
||||||
//to keep track of later
|
//to keep track of later
|
||||||
this.objectKey = objectKey;
|
this.objectKey = objectKey;
|
||||||
setEditUrls(policyHelper);
|
|
||||||
|
if ( editing ) {
|
||||||
|
setEditUrls();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setEditUrls(EditingPolicyHelper policyHelper) {
|
protected void setEditUrls() {
|
||||||
// If the policyHelper is non-null, we are in edit mode, so create the list of editing permissions.
|
// If we are in edit mode, create the list of editing permissions.
|
||||||
// We do this now rather than in getEditUrl() and getDeleteUrl(), because getEditUrl() also needs to know
|
// We do this now rather than in getEditUrl() and getDeleteUrl(), because getEditUrl() also needs to know
|
||||||
// whether a delete is allowed.
|
// whether a delete is allowed.
|
||||||
if (policyHelper != null) {
|
|
||||||
ObjectPropertyStatement ops = new ObjectPropertyStatementImpl(subjectUri, propertyUri, objectUri);
|
ObjectPropertyStatement ops = new ObjectPropertyStatementImpl(subjectUri, propertyUri, objectUri);
|
||||||
|
|
||||||
// Do delete url first, since used in building edit url
|
// Do delete url first, since used in building edit url
|
||||||
setDeleteUrl();
|
setDeleteUrl();
|
||||||
setEditUrl(ops);
|
setEditUrl(ops);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
protected void setDeleteUrl() {
|
protected void setDeleteUrl() {
|
||||||
|
|
||||||
|
|
|
@ -90,15 +90,15 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel
|
||||||
private String objectKey;
|
private String objectKey;
|
||||||
|
|
||||||
ObjectPropertyTemplateModel(ObjectProperty op, Individual subject, VitroRequest vreq,
|
ObjectPropertyTemplateModel(ObjectProperty op, Individual subject, VitroRequest vreq,
|
||||||
EditingPolicyHelper policyHelper)
|
boolean editing)
|
||||||
throws InvalidConfigurationException {
|
throws InvalidConfigurationException {
|
||||||
|
|
||||||
super(op, subject, policyHelper, vreq);
|
super(op, subject, vreq);
|
||||||
setName(op.getDomainPublic());
|
setName(op.getDomainPublic());
|
||||||
|
|
||||||
// Get the config for this object property
|
// Get the config for this object property
|
||||||
try {
|
try {
|
||||||
config = new PropertyListConfig(op, policyHelper);
|
config = new PropertyListConfig(op, editing);
|
||||||
} catch (InvalidConfigurationException e) {
|
} catch (InvalidConfigurationException e) {
|
||||||
throw e;
|
throw e;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -107,14 +107,12 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel
|
||||||
|
|
||||||
objectKey = getQueryObjectVariableName();
|
objectKey = getQueryObjectVariableName();
|
||||||
|
|
||||||
setAddUrl(policyHelper, op);
|
if (editing) {
|
||||||
|
setAddUrl(op);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setAddUrl(EditingPolicyHelper policyHelper, Property property) {
|
protected void setAddUrl(Property property) {
|
||||||
|
|
||||||
if (policyHelper == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Determine whether a new statement can be added
|
// Determine whether a new statement can be added
|
||||||
RequestedAction action = new AddObjectPropStmt(subjectUri, propertyUri, RequestActionConstants.SOME_URI);
|
RequestedAction action = new AddObjectPropStmt(subjectUri, propertyUri, RequestActionConstants.SOME_URI);
|
||||||
|
@ -207,19 +205,19 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ObjectPropertyTemplateModel getObjectPropertyTemplateModel(ObjectProperty op,
|
public static ObjectPropertyTemplateModel getObjectPropertyTemplateModel(ObjectProperty op,
|
||||||
Individual subject, VitroRequest vreq, EditingPolicyHelper policyHelper,
|
Individual subject, VitroRequest vreq, boolean editing,
|
||||||
List<ObjectProperty> populatedObjectPropertyList) {
|
List<ObjectProperty> populatedObjectPropertyList) {
|
||||||
|
|
||||||
if (op.getCollateBySubclass()) {
|
if (op.getCollateBySubclass()) {
|
||||||
try {
|
try {
|
||||||
return new CollatedObjectPropertyTemplateModel(op, subject, vreq, policyHelper, populatedObjectPropertyList);
|
return new CollatedObjectPropertyTemplateModel(op, subject, vreq, editing, populatedObjectPropertyList);
|
||||||
} catch (InvalidConfigurationException e) {
|
} catch (InvalidConfigurationException e) {
|
||||||
log.warn(e.getMessage());
|
log.warn(e.getMessage());
|
||||||
// If the collated config is invalid, instantiate an UncollatedObjectPropertyTemplateModel instead.
|
// If the collated config is invalid, instantiate an UncollatedObjectPropertyTemplateModel instead.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
return new UncollatedObjectPropertyTemplateModel(op, subject, vreq, policyHelper, populatedObjectPropertyList);
|
return new UncollatedObjectPropertyTemplateModel(op, subject, vreq, editing, populatedObjectPropertyList);
|
||||||
} catch (InvalidConfigurationException e) {
|
} catch (InvalidConfigurationException e) {
|
||||||
log.error(e.getMessage());
|
log.error(e.getMessage());
|
||||||
return null;
|
return null;
|
||||||
|
@ -363,7 +361,7 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel
|
||||||
private String templateName;
|
private String templateName;
|
||||||
private ObjectPropertyDataPostProcessor postprocessor = null;
|
private ObjectPropertyDataPostProcessor postprocessor = null;
|
||||||
|
|
||||||
PropertyListConfig(ObjectProperty op, EditingPolicyHelper policyHelper)
|
PropertyListConfig(ObjectProperty op, boolean editing)
|
||||||
throws InvalidConfigurationException {
|
throws InvalidConfigurationException {
|
||||||
|
|
||||||
// Get the custom config filename
|
// Get the custom config filename
|
||||||
|
@ -383,7 +381,7 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel
|
||||||
configFilePath = getConfigFilePath(DEFAULT_CONFIG_FILE_NAME);
|
configFilePath = getConfigFilePath(DEFAULT_CONFIG_FILE_NAME);
|
||||||
// Should we test for the existence of the default, and throw an error if it doesn't exist?
|
// Should we test for the existence of the default, and throw an error if it doesn't exist?
|
||||||
}
|
}
|
||||||
setValuesFromConfigFile(configFilePath, op, vreq.getWebappDaoFactory(), policyHelper);
|
setValuesFromConfigFile(configFilePath, op, vreq.getWebappDaoFactory(), editing);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Error processing config file " + configFilePath + " for object property " + op.getURI(), e);
|
log.error("Error processing config file " + configFilePath + " for object property " + op.getURI(), e);
|
||||||
|
@ -403,7 +401,7 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel
|
||||||
" in " + configFilePath + ":\n" +
|
" in " + configFilePath + ":\n" +
|
||||||
configError + " Using default config instead.");
|
configError + " Using default config instead.");
|
||||||
configFilePath = getConfigFilePath(DEFAULT_CONFIG_FILE_NAME);
|
configFilePath = getConfigFilePath(DEFAULT_CONFIG_FILE_NAME);
|
||||||
setValuesFromConfigFile(configFilePath, op, vreq.getWebappDaoFactory(), policyHelper);
|
setValuesFromConfigFile(configFilePath, op, vreq.getWebappDaoFactory(), editing);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -443,7 +441,7 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setValuesFromConfigFile(String configFilePath, ObjectProperty op, WebappDaoFactory wdf,
|
private void setValuesFromConfigFile(String configFilePath, ObjectProperty op, WebappDaoFactory wdf,
|
||||||
EditingPolicyHelper policyHelper) {
|
boolean editing) {
|
||||||
|
|
||||||
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
||||||
DocumentBuilder db;
|
DocumentBuilder db;
|
||||||
|
@ -454,7 +452,7 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel
|
||||||
String propertyUri = op.getURI();
|
String propertyUri = op.getURI();
|
||||||
|
|
||||||
// Required values
|
// Required values
|
||||||
selectQuery = getSelectQuery(doc, propertyUri, policyHelper);
|
selectQuery = getSelectQuery(doc, propertyUri, editing);
|
||||||
|
|
||||||
templateName = getConfigValue(doc, NODE_NAME_TEMPLATE, propertyUri);
|
templateName = getConfigValue(doc, NODE_NAME_TEMPLATE, propertyUri);
|
||||||
|
|
||||||
|
@ -482,19 +480,19 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getSelectQuery(Document doc, String propertyUri, EditingPolicyHelper policyHelper) {
|
private String getSelectQuery(Document doc, String propertyUri, boolean editing) {
|
||||||
Node selectQueryNode = doc.getElementsByTagName(NODE_NAME_QUERY_SELECT).item(0);
|
Node selectQueryNode = doc.getElementsByTagName(NODE_NAME_QUERY_SELECT).item(0);
|
||||||
String value = null;
|
String value = null;
|
||||||
if (selectQueryNode != null) {
|
if (selectQueryNode != null) {
|
||||||
boolean collated = ObjectPropertyTemplateModel.this instanceof CollatedObjectPropertyTemplateModel;
|
boolean collated = ObjectPropertyTemplateModel.this instanceof CollatedObjectPropertyTemplateModel;
|
||||||
/* If not editing the page (policyHelper == null), hide statements with missing linked individual or other
|
/* If not editing the page (editing == false), hide statements with missing linked individual or other
|
||||||
* critical information missing (e.g., anchor and url on a link); otherwise, show these statements.
|
* critical information missing (e.g., anchor and url on a link); otherwise, show these statements.
|
||||||
* We might want to refine this based on whether the user can edit the statement in question, but that
|
* We might want to refine this based on whether the user can edit the statement in question, but that
|
||||||
* would require a completely different approach: include the statement in the query results, and then during the
|
* would require a completely different approach: include the statement in the query results, and then during the
|
||||||
* postprocessing phase, check the editing policy, and remove the statement if it's not editable. We would not
|
* postprocessing phase, check the editing policy, and remove the statement if it's not editable. We would not
|
||||||
* preprocess the query, as here.
|
* preprocess the query, as here.
|
||||||
*/
|
*/
|
||||||
boolean criticalDataRequired = policyHelper == null;
|
boolean criticalDataRequired = editing;
|
||||||
NodeList children = selectQueryNode.getChildNodes();
|
NodeList children = selectQueryNode.getChildNodes();
|
||||||
int childCount = children.getLength();
|
int childCount = children.getLength();
|
||||||
value = "";
|
value = "";
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
package edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual;
|
package edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
|
@ -15,7 +14,6 @@ import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.Property;
|
import edu.cornell.mannlib.vitro.webapp.beans.Property;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.PropertyGroup;
|
import edu.cornell.mannlib.vitro.webapp.beans.PropertyGroup;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.BaseTemplateModel;
|
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.BaseTemplateModel;
|
||||||
|
|
||||||
public class PropertyGroupTemplateModel extends BaseTemplateModel {
|
public class PropertyGroupTemplateModel extends BaseTemplateModel {
|
||||||
|
@ -26,7 +24,7 @@ public class PropertyGroupTemplateModel extends BaseTemplateModel {
|
||||||
private final List<PropertyTemplateModel> properties;
|
private final List<PropertyTemplateModel> properties;
|
||||||
|
|
||||||
PropertyGroupTemplateModel(VitroRequest vreq, PropertyGroup group,
|
PropertyGroupTemplateModel(VitroRequest vreq, PropertyGroup group,
|
||||||
Individual subject, EditingPolicyHelper policyHelper,
|
Individual subject, boolean editing,
|
||||||
List<DataProperty> populatedDataPropertyList, List<ObjectProperty> populatedObjectPropertyList) {
|
List<DataProperty> populatedDataPropertyList, List<ObjectProperty> populatedObjectPropertyList) {
|
||||||
|
|
||||||
this.name = group.getName();
|
this.name = group.getName();
|
||||||
|
@ -36,9 +34,9 @@ public class PropertyGroupTemplateModel extends BaseTemplateModel {
|
||||||
for (Property p : propertyList) {
|
for (Property p : propertyList) {
|
||||||
if (p instanceof ObjectProperty) {
|
if (p instanceof ObjectProperty) {
|
||||||
ObjectProperty op = (ObjectProperty)p;
|
ObjectProperty op = (ObjectProperty)p;
|
||||||
properties.add(ObjectPropertyTemplateModel.getObjectPropertyTemplateModel(op, subject, vreq, policyHelper, populatedObjectPropertyList));
|
properties.add(ObjectPropertyTemplateModel.getObjectPropertyTemplateModel(op, subject, vreq, editing, populatedObjectPropertyList));
|
||||||
} else {
|
} else {
|
||||||
properties.add(new DataPropertyTemplateModel((DataProperty)p, subject, vreq, policyHelper, populatedDataPropertyList));
|
properties.add(new DataPropertyTemplateModel((DataProperty)p, subject, vreq, editing, populatedDataPropertyList));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,7 @@ public abstract class PropertyTemplateModel extends BaseTemplateModel {
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
PropertyTemplateModel(Property property, Individual subject, EditingPolicyHelper policyHelper, VitroRequest vreq) {
|
PropertyTemplateModel(Property property, Individual subject, VitroRequest vreq) {
|
||||||
this.vreq = vreq;
|
this.vreq = vreq;
|
||||||
subjectUri = subject.getURI();
|
subjectUri = subject.getURI();
|
||||||
propertyUri = property.getURI();
|
propertyUri = property.getURI();
|
||||||
|
|
|
@ -12,8 +12,6 @@ import org.apache.commons.logging.LogFactory;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty;
|
import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.ObjectPropertyStatementDao;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
|
||||||
|
|
||||||
public class UncollatedObjectPropertyTemplateModel extends ObjectPropertyTemplateModel {
|
public class UncollatedObjectPropertyTemplateModel extends ObjectPropertyTemplateModel {
|
||||||
|
|
||||||
|
@ -22,11 +20,11 @@ public class UncollatedObjectPropertyTemplateModel extends ObjectPropertyTemplat
|
||||||
private final List<ObjectPropertyStatementTemplateModel> statements;
|
private final List<ObjectPropertyStatementTemplateModel> statements;
|
||||||
|
|
||||||
UncollatedObjectPropertyTemplateModel(ObjectProperty op, Individual subject,
|
UncollatedObjectPropertyTemplateModel(ObjectProperty op, Individual subject,
|
||||||
VitroRequest vreq, EditingPolicyHelper policyHelper,
|
VitroRequest vreq, boolean editing,
|
||||||
List<ObjectProperty> populatedObjectPropertyList)
|
List<ObjectProperty> populatedObjectPropertyList)
|
||||||
throws InvalidConfigurationException {
|
throws InvalidConfigurationException {
|
||||||
|
|
||||||
super(op, subject, vreq, policyHelper);
|
super(op, subject, vreq, editing);
|
||||||
statements = new ArrayList<ObjectPropertyStatementTemplateModel>();
|
statements = new ArrayList<ObjectPropertyStatementTemplateModel>();
|
||||||
|
|
||||||
if (populatedObjectPropertyList.contains(op)) {
|
if (populatedObjectPropertyList.contains(op)) {
|
||||||
|
@ -42,7 +40,7 @@ public class UncollatedObjectPropertyTemplateModel extends ObjectPropertyTemplat
|
||||||
String objectKey = getObjectKey();
|
String objectKey = getObjectKey();
|
||||||
for (Map<String, String> map : statementData) {
|
for (Map<String, String> map : statementData) {
|
||||||
statements.add(new ObjectPropertyStatementTemplateModel(subjectUri,
|
statements.add(new ObjectPropertyStatementTemplateModel(subjectUri,
|
||||||
propertyUri, objectKey, map, policyHelper, getTemplateName(), vreq));
|
propertyUri, objectKey, map, editing, getTemplateName(), vreq));
|
||||||
}
|
}
|
||||||
|
|
||||||
postprocessStatementList(statements);
|
postprocessStatementList(statements);
|
||||||
|
|
Loading…
Add table
Reference in a new issue