NIHVIVO-3542 Clean up the PropertyStatementTemplateModel hierarchy. Make each of the subclasses immutable. Make NameStatementTemplateModel inherit from PropertySTM, not from DataPropertySTM. Remove the editing flag.
This commit is contained in:
parent
e0594b2681
commit
122a34f7d9
11 changed files with 203 additions and 178 deletions
|
@ -9,8 +9,6 @@ import javax.servlet.ServletContextListener;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.BaseTemplateModel;
|
|
||||||
|
|
||||||
public class FreemarkerSetup implements ServletContextListener {
|
public class FreemarkerSetup implements ServletContextListener {
|
||||||
|
|
||||||
private static final Log log = LogFactory.getLog(FreemarkerSetup.class);
|
private static final Log log = LogFactory.getLog(FreemarkerSetup.class);
|
||||||
|
|
|
@ -4,8 +4,6 @@ package edu.cornell.mannlib.vitro.webapp.web.templatemodels;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.servlet.ServletContext;
|
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
|
|
|
@ -450,7 +450,7 @@ public class EditConfigurationTemplateModel extends BaseTemplateModel {
|
||||||
predicateUri,
|
predicateUri,
|
||||||
objectKey,
|
objectKey,
|
||||||
statementDisplay,
|
statementDisplay,
|
||||||
false, null, vreq);
|
null, vreq);
|
||||||
ReadOnlyBeansWrapper wrapper = new ReadOnlyBeansWrapper();
|
ReadOnlyBeansWrapper wrapper = new ReadOnlyBeansWrapper();
|
||||||
return wrapper.wrap(osm);
|
return wrapper.wrap(osm);
|
||||||
}
|
}
|
||||||
|
|
|
@ -131,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, editing);
|
return new NameStatementTemplateModel(getUri(), vreq);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 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
|
||||||
|
|
|
@ -218,7 +218,7 @@ public class CollatedObjectPropertyTemplateModel extends ObjectPropertyTemplateM
|
||||||
}
|
}
|
||||||
|
|
||||||
listForThisSubclass.add(new ObjectPropertyStatementTemplateModel(subjectUri,
|
listForThisSubclass.add(new ObjectPropertyStatementTemplateModel(subjectUri,
|
||||||
propertyUri, objectKey, map, editing, getTemplateName(), vreq));
|
propertyUri, objectKey, map, getTemplateName(), vreq));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,97 +20,61 @@ import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.RdfLiteralHash;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.RdfLiteralHash;
|
||||||
|
|
||||||
public class DataPropertyStatementTemplateModel extends PropertyStatementTemplateModel {
|
public class DataPropertyStatementTemplateModel extends PropertyStatementTemplateModel {
|
||||||
|
|
||||||
private static final Log log = LogFactory.getLog(DataPropertyStatementTemplateModel.class);
|
private static final Log log = LogFactory.getLog(DataPropertyStatementTemplateModel.class);
|
||||||
private static final String EDIT_PATH = "editRequestDispatch";
|
|
||||||
|
|
||||||
protected String value;
|
private final Literal literalValue;
|
||||||
|
private final String deleteUrl;
|
||||||
|
private final String editUrl;
|
||||||
|
|
||||||
//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, boolean editing, VitroRequest vreq) {
|
Literal literal, VitroRequest vreq) {
|
||||||
super(subjectUri, propertyUri, vreq);
|
super(subjectUri, propertyUri, vreq);
|
||||||
|
|
||||||
//attempt to strip any odd HTML
|
this.literalValue = literal;
|
||||||
this.value = cleanTextForDisplay( literal.getLexicalForm() );
|
|
||||||
|
|
||||||
setEditUrls(literal, editing, propertyUri);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* 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. It is not possible
|
|
||||||
* to handle rdfs:label like vitro links and vitroPublic image, because it is not possible to construct a DataProperty from
|
|
||||||
* rdfs:label.
|
|
||||||
*/
|
|
||||||
DataPropertyStatementTemplateModel(String subjectUri, String propertyUri, VitroRequest vreq) {
|
|
||||||
super(subjectUri, propertyUri, vreq);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setValue(String value) {
|
|
||||||
this.value = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void setEditUrls(Literal value, boolean editing, String propertyUri) {
|
|
||||||
|
|
||||||
if ( ! editing ) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
DataPropertyStatement dps = new DataPropertyStatementImpl(subjectUri, propertyUri, value.getLexicalForm());
|
|
||||||
// Language and datatype are needed to get the correct hash value
|
|
||||||
dps.setLanguage(value.getLanguage());
|
|
||||||
dps.setDatatypeURI(value.getDatatypeURI());
|
|
||||||
String dataPropHash = String.valueOf(RdfLiteralHash.makeRdfLiteralHash(dps));
|
|
||||||
|
|
||||||
// Do delete url first, since used in building edit url
|
// Do delete url first, since used in building edit url
|
||||||
setDeleteUrl(propertyUri, dps, dataPropHash);
|
this.deleteUrl = makeDeleteUrl();
|
||||||
setEditUrl(propertyUri, dps, dataPropHash);
|
this.editUrl = makeEditUrl();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String makeDeleteUrl() {
|
||||||
protected void setDeleteUrl(String propertyUri, DataPropertyStatement dps, String dataPropHash) {
|
|
||||||
|
|
||||||
// Hack for rdfs:label - the policy doesn't prevent deletion.
|
|
||||||
if (propertyUri.equals(VitroVocabulary.LABEL)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Determine whether the statement can be deleted
|
// Determine whether the statement can be deleted
|
||||||
|
DataPropertyStatement dps = makeStatement();
|
||||||
RequestedAction action = new DropDataPropStmt(dps);
|
RequestedAction action = new DropDataPropStmt(dps);
|
||||||
if ( ! PolicyHelper.isAuthorizedForActions(vreq, action) ) {
|
if ( ! PolicyHelper.isAuthorizedForActions(vreq, action) ) {
|
||||||
return;
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
ParamMap params = new ParamMap(
|
ParamMap params = new ParamMap(
|
||||||
"subjectUri", subjectUri,
|
"subjectUri", subjectUri,
|
||||||
"predicateUri", propertyUri,
|
"predicateUri", propertyUri,
|
||||||
"datapropKey", dataPropHash,
|
"datapropKey", makeHash(dps),
|
||||||
"cmd", "delete");
|
"cmd", "delete");
|
||||||
|
|
||||||
params.putAll(UrlBuilder.getModelParams(vreq));
|
params.putAll(UrlBuilder.getModelParams(vreq));
|
||||||
|
|
||||||
deleteUrl = UrlBuilder.getUrl(EDIT_PATH, params);
|
return UrlBuilder.getUrl(EDIT_PATH, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setEditUrl(String propertyUri, DataPropertyStatement dps, String dataPropHash) {
|
|
||||||
|
|
||||||
|
private String makeEditUrl() {
|
||||||
// vitro:moniker is deprecated. We display existing data values so editors can
|
// vitro:moniker is deprecated. We display existing data values so editors can
|
||||||
// move them to other properties and delete, but don't allow editing.
|
// move them to other properties and delete, but don't allow editing.
|
||||||
if ( propertyUri.equals(VitroVocabulary.MONIKER) ) {
|
if ( propertyUri.equals(VitroVocabulary.MONIKER) ) {
|
||||||
return;
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Determine whether the statement can be edited
|
// Determine whether the statement can be edited
|
||||||
|
DataPropertyStatement dps = makeStatement();
|
||||||
RequestedAction action = new EditDataPropStmt(dps);
|
RequestedAction action = new EditDataPropStmt(dps);
|
||||||
if ( ! PolicyHelper.isAuthorizedForActions(vreq, action) ) {
|
if ( ! PolicyHelper.isAuthorizedForActions(vreq, action) ) {
|
||||||
return;
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
ParamMap params = new ParamMap(
|
ParamMap params = new ParamMap(
|
||||||
"subjectUri", subjectUri,
|
"subjectUri", subjectUri,
|
||||||
"predicateUri", propertyUri,
|
"predicateUri", propertyUri,
|
||||||
"datapropKey", dataPropHash);
|
"datapropKey", makeHash(dps));
|
||||||
|
|
||||||
if ( deleteUrl.isEmpty() ) {
|
if ( deleteUrl.isEmpty() ) {
|
||||||
params.put("deleteProhibited", "prohibited");
|
params.put("deleteProhibited", "prohibited");
|
||||||
|
@ -118,14 +82,36 @@ public class DataPropertyStatementTemplateModel extends PropertyStatementTemplat
|
||||||
|
|
||||||
params.putAll(UrlBuilder.getModelParams(vreq));
|
params.putAll(UrlBuilder.getModelParams(vreq));
|
||||||
|
|
||||||
editUrl = UrlBuilder.getUrl(EDIT_PATH, params);
|
return UrlBuilder.getUrl(EDIT_PATH, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private DataPropertyStatement makeStatement() {
|
||||||
|
DataPropertyStatement dps = new DataPropertyStatementImpl(subjectUri, propertyUri, literalValue.getLexicalForm());
|
||||||
|
// Language and datatype are needed to get the correct hash value
|
||||||
|
dps.setLanguage(literalValue.getLanguage());
|
||||||
|
dps.setDatatypeURI(literalValue.getDatatypeURI());
|
||||||
|
return dps;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String makeHash(DataPropertyStatement dps) {
|
||||||
|
// Language and datatype are needed to get the correct hash value
|
||||||
|
return String.valueOf(RdfLiteralHash.makeRdfLiteralHash(dps));
|
||||||
|
}
|
||||||
|
|
||||||
/* Template properties */
|
/* Template properties */
|
||||||
|
|
||||||
public String getValue() {
|
public String getValue() {
|
||||||
return value;
|
//attempt to strip any odd HTML
|
||||||
|
return cleanTextForDisplay( literalValue.getLexicalForm() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDeleteUrl() {
|
||||||
|
return deleteUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getEditUrl() {
|
||||||
|
return editUrl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,7 +47,7 @@ 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, editing, vreq));
|
statements.add(new DataPropertyStatementTemplateModel(subjectUri, propertyUri, value, vreq));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log.debug("Data property " + getUri() + " is unpopulated.");
|
log.debug("Data property " + getUri() + " is unpopulated.");
|
||||||
|
|
|
@ -7,42 +7,105 @@ import org.apache.commons.logging.LogFactory;
|
||||||
import org.openrdf.model.URI;
|
import org.openrdf.model.URI;
|
||||||
import org.openrdf.model.impl.URIImpl;
|
import org.openrdf.model.impl.URIImpl;
|
||||||
|
|
||||||
|
import com.hp.hpl.jena.rdf.model.Literal;
|
||||||
|
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.auth.policy.PolicyHelper;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ifaces.RequestedAction;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.propstmt.EditDataPropStmt;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatementImpl;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder.ParamMap;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao;
|
import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.EditLiteral;
|
import edu.cornell.mannlib.vitro.webapp.edit.EditLiteral;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.RdfLiteralHash;
|
||||||
|
|
||||||
public class NameStatementTemplateModel extends
|
/**
|
||||||
DataPropertyStatementTemplateModel {
|
* This allows the template to treat an rdfs:label like a data property statement, and thus
|
||||||
|
* have an editing link.
|
||||||
|
*
|
||||||
|
* This has the same accessor methods as a DataPropertyStatementTemplateModel, but it is never
|
||||||
|
* part of the GroupedPropertyList, and it never has a deleteUrl.
|
||||||
|
*/
|
||||||
|
public class NameStatementTemplateModel extends PropertyStatementTemplateModel {
|
||||||
private static final Log log = LogFactory.getLog(NameStatementTemplateModel.class);
|
private static final Log log = LogFactory.getLog(NameStatementTemplateModel.class);
|
||||||
|
|
||||||
/*
|
private final String stringValue;
|
||||||
* This method handles the special case where we are creating a DataPropertyStatementTemplateModel outside the GroupedPropertyList.
|
private final String editUrl;
|
||||||
* Specifically, it allows rdfs:label to be treated like a data property statement and thus have editing links.
|
|
||||||
*/
|
|
||||||
NameStatementTemplateModel(String subjectUri, VitroRequest vreq, boolean editing) {
|
|
||||||
super(subjectUri, VitroVocabulary.LABEL, vreq);
|
|
||||||
|
|
||||||
WebappDaoFactory wdf = vreq.getWebappDaoFactory();
|
NameStatementTemplateModel(String subjectUri, VitroRequest vreq) {
|
||||||
|
super(subjectUri, VitroVocabulary.LABEL, vreq);
|
||||||
|
|
||||||
// NIHVIVO-2466 Use the same methods to get the label that are used elsewhere in the
|
// NIHVIVO-2466 Use the same methods to get the label that are used elsewhere in the
|
||||||
// application, to guarantee consistent results for individuals with multiple labels
|
// application, to guarantee consistent results for individuals with multiple labels
|
||||||
// across the application.
|
// across the application.
|
||||||
|
WebappDaoFactory wdf = vreq.getWebappDaoFactory();
|
||||||
IndividualDao iDao = wdf.getIndividualDao();
|
IndividualDao iDao = wdf.getIndividualDao();
|
||||||
EditLiteral literal = iDao.getLabelEditLiteral(subjectUri);
|
EditLiteral literal = iDao.getLabelEditLiteral(subjectUri);
|
||||||
|
|
||||||
if (literal != null) {
|
if (literal == null) {
|
||||||
value = cleanTextForDisplay( literal.getLexicalForm() );
|
// If the individual has no rdfs:label, use the local name. It will not be editable. (This replicates previous behavior;
|
||||||
setEditUrls(literal, editing, propertyUri);
|
// perhaps we would want to allow a label to be added. But such individuals do not usually have their profiles viewed or
|
||||||
|
// edited directly.)
|
||||||
|
URI uri = new URIImpl(subjectUri);
|
||||||
|
this.stringValue = uri.getLocalName();
|
||||||
|
this.editUrl = "";
|
||||||
} else {
|
} else {
|
||||||
// If the individual has no rdfs:label, use the local name. It will not be editable. (This replicates previous behavior;
|
this.stringValue = cleanTextForDisplay( literal.getLexicalForm() );
|
||||||
// perhaps we would want to allow a label to be added. But such individuals do not usually have their profiles viewed or
|
this.editUrl = makeEditUrl(literal);
|
||||||
// edited directly.)
|
|
||||||
URI uri = new URIImpl(subjectUri);
|
|
||||||
value = uri.getLocalName();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String makeEditUrl(Literal literal) {
|
||||||
|
// Determine whether the statement can be edited
|
||||||
|
DataPropertyStatement dps = makeStatement(literal);
|
||||||
|
RequestedAction action = new EditDataPropStmt(dps);
|
||||||
|
if ( ! PolicyHelper.isAuthorizedForActions(vreq, action) ) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
ParamMap params = new ParamMap(
|
||||||
|
"subjectUri", subjectUri,
|
||||||
|
"predicateUri", propertyUri,
|
||||||
|
"datapropKey", makeHash(dps),
|
||||||
|
"deleteProhibited", "prohibited");
|
||||||
|
|
||||||
|
params.putAll(UrlBuilder.getModelParams(vreq));
|
||||||
|
|
||||||
|
return UrlBuilder.getUrl(EDIT_PATH, params);
|
||||||
|
}
|
||||||
|
|
||||||
|
private DataPropertyStatement makeStatement(Literal literalValue) {
|
||||||
|
DataPropertyStatement dps = new DataPropertyStatementImpl(subjectUri,
|
||||||
|
propertyUri, literalValue.getLexicalForm());
|
||||||
|
// Language and datatype are needed to get the correct hash value
|
||||||
|
dps.setLanguage(literalValue.getLanguage());
|
||||||
|
dps.setDatatypeURI(literalValue.getDatatypeURI());
|
||||||
|
return dps;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String makeHash(DataPropertyStatement dps) {
|
||||||
|
// Language and datatype are needed to get the correct hash value
|
||||||
|
return String.valueOf(RdfLiteralHash.makeRdfLiteralHash(dps));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Template properties */
|
||||||
|
|
||||||
|
public String getValue() {
|
||||||
|
return stringValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDeleteUrl() {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getEditUrl() {
|
||||||
|
return editUrl;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual;
|
package edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
|
@ -19,107 +21,93 @@ import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder.ParamMa
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
||||||
|
|
||||||
public class ObjectPropertyStatementTemplateModel extends PropertyStatementTemplateModel {
|
public class ObjectPropertyStatementTemplateModel extends PropertyStatementTemplateModel {
|
||||||
|
|
||||||
private static final Log log = LogFactory.getLog(ObjectPropertyStatementTemplateModel.class);
|
private static final Log log = LogFactory.getLog(ObjectPropertyStatementTemplateModel.class);
|
||||||
|
|
||||||
private static final String EDIT_PATH = "editRequestDispatch";
|
|
||||||
|
|
||||||
private final Map<String, String> data;
|
private final Map<String, String> data;
|
||||||
|
|
||||||
// Used for editing
|
|
||||||
private final String objectUri;
|
private final String objectUri;
|
||||||
private final String templateName;
|
private final String templateName;
|
||||||
private final String objectKey;
|
private final String objectKey;
|
||||||
|
private final String editUrl;
|
||||||
|
private final String deleteUrl;
|
||||||
|
|
||||||
public ObjectPropertyStatementTemplateModel(String subjectUri, String propertyUri, String objectKey,
|
public ObjectPropertyStatementTemplateModel(String subjectUri, String propertyUri, String objectKey,
|
||||||
Map<String, String> data, boolean editing, String templateName, VitroRequest vreq) {
|
Map<String, String> data, String templateName, VitroRequest vreq) {
|
||||||
super(subjectUri, propertyUri, vreq);
|
super(subjectUri, propertyUri, vreq);
|
||||||
|
|
||||||
this.data = data;
|
this.data = Collections.unmodifiableMap(new HashMap<String, String>(data));
|
||||||
this.objectUri = data.get(objectKey);
|
this.objectUri = data.get(objectKey);
|
||||||
this.templateName = templateName;
|
this.templateName = templateName;
|
||||||
//to keep track of later
|
//to keep track of later
|
||||||
this.objectKey = objectKey;
|
this.objectKey = objectKey;
|
||||||
|
|
||||||
if ( editing ) {
|
|
||||||
setEditUrls();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void setEditUrls() {
|
|
||||||
// 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
|
|
||||||
// whether a delete is allowed.
|
|
||||||
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 it is used in building edit url
|
||||||
setDeleteUrl();
|
this.deleteUrl = makeDeleteUrl();
|
||||||
setEditUrl(ops);
|
this.editUrl = makeEditUrl(ops);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setDeleteUrl() {
|
private String makeDeleteUrl() {
|
||||||
|
|
||||||
// Determine whether the statement can be deleted
|
// Determine whether the statement can be deleted
|
||||||
RequestedAction action = new DropObjectPropStmt(subjectUri, propertyUri, objectUri);
|
RequestedAction action = new DropObjectPropStmt(subjectUri, propertyUri, objectUri);
|
||||||
if ( ! PolicyHelper.isAuthorizedForActions(vreq, action) ) {
|
if ( ! PolicyHelper.isAuthorizedForActions(vreq, action) ) {
|
||||||
return;
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (propertyUri.equals(VitroVocabulary.IND_MAIN_IMAGE)) {
|
if (propertyUri.equals(VitroVocabulary.IND_MAIN_IMAGE)) {
|
||||||
deleteUrl = ObjectPropertyTemplateModel.getImageUploadUrl(subjectUri, "delete");
|
return ObjectPropertyTemplateModel.getImageUploadUrl(subjectUri, "delete");
|
||||||
} else {
|
|
||||||
ParamMap params = new ParamMap(
|
|
||||||
"subjectUri", subjectUri,
|
|
||||||
"predicateUri", propertyUri,
|
|
||||||
"objectUri", objectUri,
|
|
||||||
"cmd", "delete",
|
|
||||||
"objectKey", objectKey);
|
|
||||||
|
|
||||||
for ( String key : data.keySet() ) {
|
|
||||||
String value = data.get(key);
|
|
||||||
// Remove an entry with a null value instead of letting it get passed
|
|
||||||
// as a param with an empty value, in order to align with behavior on
|
|
||||||
// profile page. E.g., if statement.moniker is null, a test for
|
|
||||||
// statement.moniker?? will yield different results if null on the
|
|
||||||
// profile page but an empty string on the deletion page.
|
|
||||||
if (value != null) {
|
|
||||||
params.put("statement_" + key, data.get(key));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
params.put("templateName", templateName);
|
|
||||||
|
|
||||||
params.putAll(UrlBuilder.getModelParams(vreq));
|
|
||||||
|
|
||||||
deleteUrl = UrlBuilder.getUrl(EDIT_PATH, params);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
protected void setEditUrl(ObjectPropertyStatement ops) {
|
ParamMap params = new ParamMap(
|
||||||
|
"subjectUri", subjectUri,
|
||||||
|
"predicateUri", propertyUri,
|
||||||
|
"objectUri", objectUri,
|
||||||
|
"cmd", "delete",
|
||||||
|
"objectKey", objectKey);
|
||||||
|
|
||||||
|
for ( String key : data.keySet() ) {
|
||||||
|
String value = data.get(key);
|
||||||
|
// Remove an entry with a null value instead of letting it get passed
|
||||||
|
// as a param with an empty value, in order to align with behavior on
|
||||||
|
// profile page. E.g., if statement.moniker is null, a test for
|
||||||
|
// statement.moniker?? will yield different results if null on the
|
||||||
|
// profile page but an empty string on the deletion page.
|
||||||
|
if (value != null) {
|
||||||
|
params.put("statement_" + key, data.get(key));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
params.put("templateName", templateName);
|
||||||
|
params.putAll(UrlBuilder.getModelParams(vreq));
|
||||||
|
|
||||||
|
return UrlBuilder.getUrl(EDIT_PATH, params);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String makeEditUrl(ObjectPropertyStatement ops) {
|
||||||
// Determine whether the statement can be edited
|
// Determine whether the statement can be edited
|
||||||
RequestedAction action = new EditObjPropStmt(ops);
|
RequestedAction action = new EditObjPropStmt(ops);
|
||||||
if ( ! PolicyHelper.isAuthorizedForActions(vreq, action) ) {
|
if ( ! PolicyHelper.isAuthorizedForActions(vreq, action) ) {
|
||||||
return;
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (propertyUri.equals(VitroVocabulary.IND_MAIN_IMAGE)) {
|
if (propertyUri.equals(VitroVocabulary.IND_MAIN_IMAGE)) {
|
||||||
editUrl = ObjectPropertyTemplateModel.getImageUploadUrl(subjectUri, "edit");
|
return ObjectPropertyTemplateModel.getImageUploadUrl(subjectUri, "edit");
|
||||||
} else {
|
|
||||||
ParamMap params = new ParamMap(
|
|
||||||
"subjectUri", subjectUri,
|
|
||||||
"predicateUri", propertyUri,
|
|
||||||
"objectUri", objectUri);
|
|
||||||
|
|
||||||
if ( deleteUrl.isEmpty() ) {
|
|
||||||
params.put("deleteProhibited", "prohibited");
|
|
||||||
}
|
|
||||||
|
|
||||||
params.putAll(UrlBuilder.getModelParams(vreq));
|
|
||||||
|
|
||||||
editUrl = UrlBuilder.getUrl(EDIT_PATH, params);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
ParamMap params = new ParamMap(
|
||||||
|
"subjectUri", subjectUri,
|
||||||
|
"predicateUri", propertyUri,
|
||||||
|
"objectUri", objectUri);
|
||||||
|
|
||||||
|
if ( deleteUrl.isEmpty() ) {
|
||||||
|
params.put("deleteProhibited", "prohibited");
|
||||||
|
}
|
||||||
|
|
||||||
|
params.putAll(UrlBuilder.getModelParams(vreq));
|
||||||
|
|
||||||
|
return UrlBuilder.getUrl(EDIT_PATH, params);
|
||||||
|
}
|
||||||
|
|
||||||
/* Template methods */
|
/* Template methods */
|
||||||
|
|
||||||
|
@ -131,4 +119,14 @@ public class ObjectPropertyStatementTemplateModel extends PropertyStatementTempl
|
||||||
return cleanURIForDisplay(data.get(key));
|
return cleanURIForDisplay(data.get(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDeleteUrl() {
|
||||||
|
return deleteUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getEditUrl() {
|
||||||
|
return editUrl;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,46 +2,28 @@
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual;
|
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.controller.VitroRequest;
|
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||||
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.BaseTemplateModel;
|
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.BaseTemplateModel;
|
||||||
|
|
||||||
public abstract class PropertyStatementTemplateModel extends BaseTemplateModel {
|
public abstract class PropertyStatementTemplateModel extends BaseTemplateModel {
|
||||||
|
protected static final String EDIT_PATH = "editRequestDispatch";
|
||||||
private static final Log log = LogFactory.getLog(PropertyStatementTemplateModel.class);
|
|
||||||
|
|
||||||
protected final VitroRequest vreq;
|
protected final VitroRequest vreq;
|
||||||
// Used for editing
|
|
||||||
protected final String subjectUri;
|
protected final String subjectUri;
|
||||||
protected final String propertyUri;
|
protected final String propertyUri;
|
||||||
protected String editUrl;
|
|
||||||
protected String deleteUrl;
|
|
||||||
|
|
||||||
|
|
||||||
PropertyStatementTemplateModel(String subjectUri, String propertyUri, VitroRequest vreq) {
|
PropertyStatementTemplateModel(String subjectUri, String propertyUri, VitroRequest vreq) {
|
||||||
this.vreq = vreq;
|
this.vreq = vreq;
|
||||||
this.subjectUri = subjectUri;
|
this.subjectUri = subjectUri;
|
||||||
this.propertyUri = propertyUri;
|
this.propertyUri = propertyUri;
|
||||||
editUrl = "";
|
|
||||||
deleteUrl = "";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Template properties */
|
/* Template properties */
|
||||||
|
|
||||||
public String getEditUrl() {
|
public abstract String getEditUrl();
|
||||||
return editUrl;
|
public abstract String getDeleteUrl();
|
||||||
}
|
|
||||||
|
|
||||||
public String getDeleteUrl() {
|
|
||||||
return deleteUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isEditable() {
|
public boolean isEditable() {
|
||||||
return ! editUrl.isEmpty();
|
return ! getEditUrl().isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,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, editing, getTemplateName(), vreq));
|
propertyUri, objectKey, map, getTemplateName(), vreq));
|
||||||
}
|
}
|
||||||
|
|
||||||
postprocessStatementList(statements);
|
postprocessStatementList(statements);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue