NIHVIVO-1332 Move discovery of statement object variable name to ObjectPropertyTemplateModel, since needed to create editing links as well as for data postprocessing.
This commit is contained in:
parent
be8930ea5c
commit
4c7d97658c
6 changed files with 127 additions and 66 deletions
|
@ -19,13 +19,6 @@ public abstract class BaseObjectPropertyDataPostProcessor implements
|
||||||
|
|
||||||
private static final Log log = LogFactory.getLog(BaseObjectPropertyDataPostProcessor.class);
|
private static final Log log = LogFactory.getLog(BaseObjectPropertyDataPostProcessor.class);
|
||||||
|
|
||||||
private static String KEY_SUBJECT = "subject";
|
|
||||||
private static final String KEY_PROPERTY = "property";
|
|
||||||
private static final String DEFAULT_LIST_VIEW_QUERY_OBJECT_VARIABLE_NAME = "object";
|
|
||||||
private static final Pattern SUBJECT_PROPERTY_OBJECT_PATTERN =
|
|
||||||
// ?subject ?property ?\w+
|
|
||||||
Pattern.compile("\\?" + KEY_SUBJECT + "\\s+\\?" + KEY_PROPERTY + "\\s+\\?(\\w+)");
|
|
||||||
|
|
||||||
protected ObjectPropertyTemplateModel objectPropertyTemplateModel;
|
protected ObjectPropertyTemplateModel objectPropertyTemplateModel;
|
||||||
protected WebappDaoFactory wdf;
|
protected WebappDaoFactory wdf;
|
||||||
|
|
||||||
|
@ -59,7 +52,7 @@ public abstract class BaseObjectPropertyDataPostProcessor implements
|
||||||
* @param List<Map<String, String>> data
|
* @param List<Map<String, String>> data
|
||||||
*/
|
*/
|
||||||
protected void removeDuplicates(List<Map<String, String>> data) {
|
protected void removeDuplicates(List<Map<String, String>> data) {
|
||||||
String objectVariableName = getQueryObjectVariableName();
|
String objectVariableName = objectPropertyTemplateModel.getObjectKey();
|
||||||
if (objectVariableName == null) {
|
if (objectVariableName == null) {
|
||||||
log.error("Cannot remove duplicate statements for property " + objectPropertyTemplateModel.getName() + " because no object found to dedupe.");
|
log.error("Cannot remove duplicate statements for property " + objectPropertyTemplateModel.getName() + " because no object found to dedupe.");
|
||||||
return;
|
return;
|
||||||
|
@ -79,28 +72,6 @@ public abstract class BaseObjectPropertyDataPostProcessor implements
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Return the name of the primary object variable of the query by inspecting the query string.
|
|
||||||
* The primary object is the X in the assertion "?subject ?property ?X".
|
|
||||||
*/
|
|
||||||
private String getQueryObjectVariableName() {
|
|
||||||
|
|
||||||
String object = null;
|
|
||||||
|
|
||||||
if (objectPropertyTemplateModel.hasDefaultListView()) {
|
|
||||||
object = DEFAULT_LIST_VIEW_QUERY_OBJECT_VARIABLE_NAME;
|
|
||||||
log.debug("Using default list view for property " + objectPropertyTemplateModel.getUri() +
|
|
||||||
", so query object = '" + object + "'");
|
|
||||||
} else {
|
|
||||||
String queryString = objectPropertyTemplateModel.getQueryString();
|
|
||||||
Matcher m = SUBJECT_PROPERTY_OBJECT_PATTERN.matcher(queryString);
|
|
||||||
if (m.find()) {
|
|
||||||
object = m.group(1);
|
|
||||||
log.debug("Query object for property " + objectPropertyTemplateModel.getUri() + " = '" + object + "'");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return object;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Postprocessor methods callable from any postprocessor */
|
/* Postprocessor methods callable from any postprocessor */
|
||||||
|
|
||||||
|
@ -128,7 +99,4 @@ public abstract class BaseObjectPropertyDataPostProcessor implements
|
||||||
return wdf.getIndividualDao().getIndividualByURI(uri);
|
return wdf.getIndividualDao().getIndividualByURI(uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static void moveNullEndDateTimesToTop(List<ObjectPropertyStatementTemplateModel> list) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,18 +47,18 @@ public class DataPropertyTemplateModel extends PropertyTemplateModel {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
// @Override
|
||||||
public String getEditLink() {
|
// public String getEditLink() {
|
||||||
// TODO Auto-generated method stub
|
// // TODO Auto-generated method stub
|
||||||
return null;
|
// return null;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
@Override
|
// @Override
|
||||||
public String getDeleteLink() {
|
// public String getDeleteLink() {
|
||||||
// TODO Auto-generated method stub
|
// // TODO Auto-generated method stub
|
||||||
return null;
|
// return null;
|
||||||
}
|
// }
|
||||||
|
|
||||||
public List<DataPropertyStatementTemplateModel> getStatements() {
|
public List<DataPropertyStatementTemplateModel> getStatements() {
|
||||||
return statements;
|
return statements;
|
||||||
|
|
|
@ -0,0 +1,53 @@
|
||||||
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
|
|
||||||
|
package edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual;
|
||||||
|
|
||||||
|
import javax.servlet.ServletContext;
|
||||||
|
|
||||||
|
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.ServletIdentifierBundleFactory;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.auth.policy.PolicyList;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.auth.policy.RequestPolicyList;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.auth.policy.ServletPolicyList;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.auth.policy.ifaces.PolicyIface;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.BaseTemplateModel;
|
||||||
|
|
||||||
|
public class EditLinkHelper {
|
||||||
|
|
||||||
|
private static final Log log = LogFactory.getLog(EditLinkHelper.class);
|
||||||
|
|
||||||
|
private VitroRequest vreq;
|
||||||
|
private ServletContext context;
|
||||||
|
|
||||||
|
protected EditLinkHelper(VitroRequest vreq) {
|
||||||
|
this.vreq = vreq;
|
||||||
|
this.context = BaseTemplateModel.getServletContext();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected PolicyIface getPolicy() {
|
||||||
|
PolicyIface policy = RequestPolicyList.getPolicies(vreq);
|
||||||
|
if( policy == null || ( policy instanceof PolicyList && ((PolicyList)policy).size() == 0 )){
|
||||||
|
policy = ServletPolicyList.getPolicies( context );
|
||||||
|
if( policy == null || ( policy instanceof PolicyList && ((PolicyList)policy).size() == 0 )){
|
||||||
|
log.error("No policy found in request at " + RequestPolicyList.POLICY_LIST);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return policy;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected IdentifierBundle getIds() {
|
||||||
|
IdentifierBundle ids = (IdentifierBundle)ServletIdentifierBundleFactory
|
||||||
|
.getIdBundleForRequest(vreq, vreq.getSession(), context);
|
||||||
|
|
||||||
|
if (ids == null) {
|
||||||
|
log.error("No IdentifierBundle objects for request");
|
||||||
|
}
|
||||||
|
|
||||||
|
return ids;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -17,6 +17,9 @@ public class ObjectPropertyStatementTemplateModel extends BaseTemplateModel {
|
||||||
|
|
||||||
private static final Log log = LogFactory.getLog(ObjectPropertyStatementTemplateModel.class);
|
private static final Log log = LogFactory.getLog(ObjectPropertyStatementTemplateModel.class);
|
||||||
|
|
||||||
|
// RY WE may want to instead store the ObjectPropertyStatement; get the object from the data
|
||||||
|
// the same way we do in BaseObjectPropertyDataPostProcessor.getQueryObjectVariableName, then
|
||||||
|
// getting the value from the data.
|
||||||
private String subjectUri; // we'll use these to make the edit links
|
private String subjectUri; // we'll use these to make the edit links
|
||||||
private String propertyUri;
|
private String propertyUri;
|
||||||
private Map<String, String> data;
|
private Map<String, String> data;
|
||||||
|
|
|
@ -50,7 +50,15 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel
|
||||||
*/
|
*/
|
||||||
Pattern.compile("ORDER\\s+BY\\s+((DESC\\()?\\?subclass\\)?\\s+)?DESC\\s*\\(\\s*\\?" + END_DATE_TIME_VARIABLE + "\\)", Pattern.CASE_INSENSITIVE);
|
Pattern.compile("ORDER\\s+BY\\s+((DESC\\()?\\?subclass\\)?\\s+)?DESC\\s*\\(\\s*\\?" + END_DATE_TIME_VARIABLE + "\\)", Pattern.CASE_INSENSITIVE);
|
||||||
|
|
||||||
|
private static String KEY_SUBJECT = "subject";
|
||||||
|
private static final String KEY_PROPERTY = "property";
|
||||||
|
private static final String DEFAULT_LIST_VIEW_QUERY_OBJECT_VARIABLE_NAME = "object";
|
||||||
|
private static final Pattern SUBJECT_PROPERTY_OBJECT_PATTERN =
|
||||||
|
// ?subject ?property ?\w+
|
||||||
|
Pattern.compile("\\?" + KEY_SUBJECT + "\\s+\\?" + KEY_PROPERTY + "\\s+\\?(\\w+)");
|
||||||
|
|
||||||
private PropertyListConfig config;
|
private PropertyListConfig config;
|
||||||
|
private String objectKey;
|
||||||
|
|
||||||
ObjectPropertyTemplateModel(ObjectProperty op, Individual subject, VitroRequest vreq) {
|
ObjectPropertyTemplateModel(ObjectProperty op, Individual subject, VitroRequest vreq) {
|
||||||
super(op);
|
super(op);
|
||||||
|
@ -62,6 +70,8 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error(e, e);
|
log.error(e, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
objectKey = getQueryObjectVariableName();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String getQueryString() {
|
protected String getQueryString() {
|
||||||
|
@ -72,6 +82,29 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel
|
||||||
return config.isDefaultConfig;
|
return config.isDefaultConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Return the name of the primary object variable of the query by inspecting the query string.
|
||||||
|
* The primary object is the X in the assertion "?subject ?property ?X".
|
||||||
|
*/
|
||||||
|
private String getQueryObjectVariableName() {
|
||||||
|
|
||||||
|
String object = null;
|
||||||
|
|
||||||
|
if (hasDefaultListView()) {
|
||||||
|
object = DEFAULT_LIST_VIEW_QUERY_OBJECT_VARIABLE_NAME;
|
||||||
|
log.debug("Using default list view for property " + getUri() +
|
||||||
|
", so query object = '" + object + "'");
|
||||||
|
} else {
|
||||||
|
String queryString = getQueryString();
|
||||||
|
Matcher m = SUBJECT_PROPERTY_OBJECT_PATTERN.matcher(queryString);
|
||||||
|
if (m.find()) {
|
||||||
|
object = m.group(1);
|
||||||
|
log.debug("Query object for property " + getUri() + " = '" + object + "'");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return object;
|
||||||
|
}
|
||||||
|
|
||||||
protected static ObjectPropertyTemplateModel getObjectPropertyTemplateModel(ObjectProperty op, Individual subject, VitroRequest vreq) {
|
protected static ObjectPropertyTemplateModel getObjectPropertyTemplateModel(ObjectProperty op, Individual subject, VitroRequest vreq) {
|
||||||
if (op.getCollateBySubclass()) {
|
if (op.getCollateBySubclass()) {
|
||||||
try {
|
try {
|
||||||
|
@ -85,7 +118,7 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Apply postprocessing to query results to prepare for template */
|
/** Apply post-processing to query results to prepare for template */
|
||||||
protected void postprocess(List<Map<String, String>> data, WebappDaoFactory wdf) {
|
protected void postprocess(List<Map<String, String>> data, WebappDaoFactory wdf) {
|
||||||
String postprocessorName = config.postprocessor;
|
String postprocessorName = config.postprocessor;
|
||||||
if (postprocessorName == null) {
|
if (postprocessorName == null) {
|
||||||
|
@ -108,7 +141,7 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel
|
||||||
* like the pre-collation post-processing, but for now due to time constraints it applies to all views.
|
* like the pre-collation post-processing, but for now due to time constraints it applies to all views.
|
||||||
*/
|
*/
|
||||||
protected void postprocessStatementList(List<ObjectPropertyStatementTemplateModel> statements) {
|
protected void postprocessStatementList(List<ObjectPropertyStatementTemplateModel> statements) {
|
||||||
moveEndDateTimesToTop(statements);
|
moveNullEndDateTimesToTop(statements);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* SPARQL ORDER BY gives null values the lowest value, so null datetimes occur at the end
|
/* SPARQL ORDER BY gives null values the lowest value, so null datetimes occur at the end
|
||||||
|
@ -119,7 +152,7 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel
|
||||||
* name is hard-coded here. (Note, therefore, that using a different variable name
|
* name is hard-coded here. (Note, therefore, that using a different variable name
|
||||||
* effectively turns off this post-processing.)
|
* effectively turns off this post-processing.)
|
||||||
*/
|
*/
|
||||||
protected void moveEndDateTimesToTop(List<ObjectPropertyStatementTemplateModel> statements) {
|
protected void moveNullEndDateTimesToTop(List<ObjectPropertyStatementTemplateModel> statements) {
|
||||||
String queryString = getQueryString();
|
String queryString = getQueryString();
|
||||||
Matcher m = ORDER_BY_END_DATE_TIME_PATTERN.matcher(queryString);
|
Matcher m = ORDER_BY_END_DATE_TIME_PATTERN.matcher(queryString);
|
||||||
if ( ! m.find() ) {
|
if ( ! m.find() ) {
|
||||||
|
@ -151,6 +184,10 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected String getObjectKey() {
|
||||||
|
return objectKey;
|
||||||
|
}
|
||||||
|
|
||||||
protected abstract String getDefaultConfigFileName();
|
protected abstract String getDefaultConfigFileName();
|
||||||
|
|
||||||
private class PropertyListConfig {
|
private class PropertyListConfig {
|
||||||
|
@ -297,16 +334,16 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
// @Override
|
||||||
public String getEditLink() {
|
// public String getEditLink() {
|
||||||
// TODO Auto-generated method stub
|
// // TODO Auto-generated method stub
|
||||||
return null;
|
// return null;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
@Override
|
// @Override
|
||||||
public String getDeleteLink() {
|
// public String getDeleteLink() {
|
||||||
// TODO Auto-generated method stub
|
// // TODO Auto-generated method stub
|
||||||
return null;
|
// return null;
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,8 +45,8 @@ public abstract class PropertyTemplateModel extends BaseTemplateModel {
|
||||||
|
|
||||||
public abstract String getAddLink();
|
public abstract String getAddLink();
|
||||||
|
|
||||||
public abstract String getEditLink();
|
// public abstract String getEditLink();
|
||||||
|
//
|
||||||
public abstract String getDeleteLink();
|
// public abstract String getDeleteLink();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue