NIHVIVO-2508 Change template properties to methods so not pre-computed.
This commit is contained in:
parent
ddd6469a3a
commit
b5b44b73c1
6 changed files with 114 additions and 97 deletions
|
@ -105,10 +105,6 @@ public abstract class BaseIndividualTemplateModel extends BaseTemplateModel {
|
||||||
: UrlBuilder.addParams(profileUrl, "format", "rdfxml");
|
: UrlBuilder.addParams(profileUrl, "format", "rdfxml");
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getEditUrl() {
|
|
||||||
return UrlBuilder.getUrl(Route.INDIVIDUAL_EDIT, "uri", getUri());
|
|
||||||
}
|
|
||||||
|
|
||||||
public GroupedPropertyList getPropertyList() {
|
public GroupedPropertyList getPropertyList() {
|
||||||
if (propertyList == null) {
|
if (propertyList == null) {
|
||||||
propertyList = new GroupedPropertyList(individual, vreq, policyHelper);
|
propertyList = new GroupedPropertyList(individual, vreq, policyHelper);
|
||||||
|
@ -167,38 +163,61 @@ public abstract class BaseIndividualTemplateModel extends BaseTemplateModel {
|
||||||
return individual.getLocalName();
|
return individual.getLocalName();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String nullString() {
|
// For testing dump
|
||||||
return null;
|
// // Properties
|
||||||
}
|
// public String getANullString() {
|
||||||
|
// return null;
|
||||||
|
// }
|
||||||
|
// public String getAnEmptyString() {
|
||||||
|
// return "";
|
||||||
|
// }
|
||||||
|
// public String[] getANullArray() {
|
||||||
|
// return null;
|
||||||
|
// }
|
||||||
|
// public String[] getAnEmptyArray() {
|
||||||
|
// String[] a = {};
|
||||||
|
// return a;
|
||||||
|
// }
|
||||||
|
// public List<String> getANullList() {
|
||||||
|
// return null;
|
||||||
|
// }
|
||||||
|
// public List<String> getAnEmptyList() {
|
||||||
|
// return Collections.emptyList();
|
||||||
|
// }
|
||||||
|
// public Map<String, String> getANullMap() {
|
||||||
|
// return null;
|
||||||
|
// }
|
||||||
|
// public Map<String, String> getAnEmptyMap() {
|
||||||
|
// return Collections.emptyMap();
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// // Methods
|
||||||
|
// public String nullString() {
|
||||||
|
// return null;
|
||||||
|
// }
|
||||||
|
// public String emptyString() {
|
||||||
|
// return "";
|
||||||
|
// }
|
||||||
|
// public String[] nullArray() {
|
||||||
|
// return null;
|
||||||
|
// }
|
||||||
|
// public String[] emptyArray() {
|
||||||
|
// String[] a = {};
|
||||||
|
// return a;
|
||||||
|
// }
|
||||||
|
// public List<String> nullList() {
|
||||||
|
// return null;
|
||||||
|
// }
|
||||||
|
// public List<String> emptyList() {
|
||||||
|
// return Collections.emptyList();
|
||||||
|
// }
|
||||||
|
// public Map<String, String> nullMap() {
|
||||||
|
// return null;
|
||||||
|
// }
|
||||||
|
// public Map<String, String> emptyMap() {
|
||||||
|
// return Collections.emptyMap();
|
||||||
|
// }
|
||||||
|
|
||||||
public String emptyString() {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
public String[] nullArray() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String[] emptyArray() {
|
|
||||||
String[] a = {};
|
|
||||||
return a;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<String> nullList() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<String> emptyList() {
|
|
||||||
return Collections.emptyList();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map<String, String> nullMap() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map<String, String> emptyMap() {
|
|
||||||
return Collections.emptyMap();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Template methods */
|
/* Template methods */
|
||||||
|
|
||||||
|
@ -217,4 +236,8 @@ public abstract class BaseIndividualTemplateModel extends BaseTemplateModel {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String controlPanelUrl() {
|
||||||
|
return UrlBuilder.getUrl(Route.INDIVIDUAL_EDIT, "uri", getUri());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,13 +53,13 @@ public class DataPropertyTemplateModel extends PropertyTemplateModel {
|
||||||
log.debug("Data property " + getUri() + " is unpopulated.");
|
log.debug("Data property " + getUri() + " is unpopulated.");
|
||||||
}
|
}
|
||||||
|
|
||||||
setAddAccess(policyHelper, dp);
|
setAddUrl(policyHelper, dp);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Determine whether a new statement can be added
|
// Determine whether a new statement can be added
|
||||||
@Override
|
@Override
|
||||||
protected void setAddAccess(EditingPolicyHelper policyHelper, Property property) {
|
protected void setAddUrl(EditingPolicyHelper policyHelper, Property property) {
|
||||||
|
this.addUrl = "";
|
||||||
if (policyHelper != null) {
|
if (policyHelper != null) {
|
||||||
|
|
||||||
DataProperty dp = (DataProperty) property;
|
DataProperty dp = (DataProperty) property;
|
||||||
|
@ -68,13 +68,22 @@ public class DataPropertyTemplateModel extends PropertyTemplateModel {
|
||||||
if (dp.getURI().equals(VitroVocabulary.MONIKER)) {
|
if (dp.getURI().equals(VitroVocabulary.MONIKER)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// If the display limit has already been reached, we can't add a new statement
|
// If the display limit has already been reached, we can't add a new statement.
|
||||||
|
// NB This appears to be a misuse of a value called "display limit". Note that it's
|
||||||
|
// not used to limit display, either, so should be renamed.
|
||||||
int displayLimit = dp.getDisplayLimit();
|
int displayLimit = dp.getDisplayLimit();
|
||||||
// Display limit of -1 (default value for new property) means no display limit
|
// Display limit of -1 (default value for new property) means no display limit
|
||||||
if ( (displayLimit < 0) || (displayLimit > statements.size()) ) {
|
if ( (displayLimit < 0) || (displayLimit > statements.size()) ) {
|
||||||
RequestedAction action = new AddDataPropStmt(subjectUri, propertyUri,RequestActionConstants.SOME_LITERAL, null, null);
|
RequestedAction action = new AddDataPropStmt(subjectUri, propertyUri,RequestActionConstants.SOME_LITERAL, null, null);
|
||||||
if (policyHelper.isAuthorizedAction(action)) {
|
if (policyHelper.isAuthorizedAction(action)) {
|
||||||
addAccess = true;
|
|
||||||
|
ParamMap params = new ParamMap(
|
||||||
|
"subjectUri", subjectUri,
|
||||||
|
"predicateUri", propertyUri);
|
||||||
|
|
||||||
|
params.putAll(UrlBuilder.getModelParams(vreq));
|
||||||
|
|
||||||
|
addUrl = UrlBuilder.getUrl(EDIT_PATH, params);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -90,37 +99,25 @@ public class DataPropertyTemplateModel extends PropertyTemplateModel {
|
||||||
return Route.DATA_PROPERTY_EDIT;
|
return Route.DATA_PROPERTY_EDIT;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Access methods for templates */
|
/* Template properties */
|
||||||
|
|
||||||
public String getType() {
|
public String getType() {
|
||||||
return TYPE;
|
return TYPE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getAddUrl() {
|
|
||||||
String addUrl = "";
|
|
||||||
if (addAccess) {
|
|
||||||
ParamMap params = new ParamMap(
|
|
||||||
"subjectUri", subjectUri,
|
|
||||||
"predicateUri", propertyUri);
|
|
||||||
|
|
||||||
params.putAll(UrlBuilder.getModelParams(vreq));
|
|
||||||
|
|
||||||
addUrl = UrlBuilder.getUrl(EDIT_PATH, params);
|
|
||||||
}
|
|
||||||
return addUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<DataPropertyStatementTemplateModel> getStatements() {
|
public List<DataPropertyStatementTemplateModel> getStatements() {
|
||||||
return statements;
|
return statements;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DataPropertyStatementTemplateModel getFirst() {
|
|
||||||
|
/* Template methods */
|
||||||
|
|
||||||
|
public DataPropertyStatementTemplateModel first() {
|
||||||
return ( (statements == null || statements.isEmpty()) ) ? null : statements.get(0);
|
return ( (statements == null || statements.isEmpty()) ) ? null : statements.get(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getFirstValue() {
|
public String firstValue() {
|
||||||
DataPropertyStatementTemplateModel first = getFirst();
|
DataPropertyStatementTemplateModel first = first();
|
||||||
return first == null ? null : first.getValue();
|
return first == null ? null : first.getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -111,16 +111,29 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel
|
||||||
|
|
||||||
objectKey = getQueryObjectVariableName();
|
objectKey = getQueryObjectVariableName();
|
||||||
|
|
||||||
setAddAccess(policyHelper, op);
|
setAddUrl(policyHelper, op);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Determine whether a new statement can be added
|
// Determine whether a new statement can be added
|
||||||
@Override
|
@Override
|
||||||
protected void setAddAccess(EditingPolicyHelper policyHelper, Property property) {
|
protected void setAddUrl(EditingPolicyHelper policyHelper, Property property) {
|
||||||
|
addUrl = "";
|
||||||
if (policyHelper != null) {
|
if (policyHelper != null) {
|
||||||
RequestedAction action = new AddObjectPropStmt(subjectUri, propertyUri, RequestActionConstants.SOME_URI);
|
RequestedAction action = new AddObjectPropStmt(subjectUri, propertyUri, RequestActionConstants.SOME_URI);
|
||||||
if (policyHelper.isAuthorizedAction(action)) {
|
if (policyHelper.isAuthorizedAction(action)) {
|
||||||
addAccess = true;
|
|
||||||
|
if (propertyUri.equals(VitroVocabulary.IND_MAIN_IMAGE)) {
|
||||||
|
addUrl = getImageUploadUrl(subjectUri, "add");
|
||||||
|
} else {
|
||||||
|
ParamMap params = new ParamMap(
|
||||||
|
"subjectUri", subjectUri,
|
||||||
|
"predicateUri", propertyUri);
|
||||||
|
|
||||||
|
params.putAll(UrlBuilder.getModelParams(vreq));
|
||||||
|
|
||||||
|
addUrl = UrlBuilder.getUrl(EDIT_PATH, params);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -167,7 +180,7 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel
|
||||||
return config.isDefaultConfig;
|
return config.isDefaultConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getImageUploadUrl(String subjectUri, String action) {
|
protected static String getImageUploadUrl(String subjectUri, String action) {
|
||||||
ParamMap params = new ParamMap(
|
ParamMap params = new ParamMap(
|
||||||
"entityUri", subjectUri,
|
"entityUri", subjectUri,
|
||||||
"action", action);
|
"action", action);
|
||||||
|
@ -560,7 +573,7 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Access methods for templates */
|
/* Template properties */
|
||||||
|
|
||||||
public String getType() {
|
public String getType() {
|
||||||
return TYPE;
|
return TYPE;
|
||||||
|
@ -572,23 +585,4 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel
|
||||||
|
|
||||||
public abstract boolean isCollatedBySubclass();
|
public abstract boolean isCollatedBySubclass();
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getAddUrl() {
|
|
||||||
String addUrl = "";
|
|
||||||
if (addAccess) {
|
|
||||||
if (propertyUri.equals(VitroVocabulary.IND_MAIN_IMAGE)) {
|
|
||||||
return getImageUploadUrl(subjectUri, "add");
|
|
||||||
}
|
|
||||||
ParamMap params = new ParamMap(
|
|
||||||
"subjectUri", subjectUri,
|
|
||||||
"predicateUri", propertyUri);
|
|
||||||
|
|
||||||
params.putAll(UrlBuilder.getModelParams(vreq));
|
|
||||||
|
|
||||||
addUrl = UrlBuilder.getUrl(EDIT_PATH, params);
|
|
||||||
|
|
||||||
}
|
|
||||||
return addUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,8 @@ public abstract class PropertyTemplateModel extends BaseTemplateModel {
|
||||||
private final String localName;
|
private final String localName;
|
||||||
|
|
||||||
protected Map<String, Object> verboseDisplay;
|
protected Map<String, Object> verboseDisplay;
|
||||||
protected boolean addAccess; // defaults to false
|
protected String addUrl;
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
PropertyTemplateModel(Property property, Individual subject, EditingPolicyHelper policyHelper, VitroRequest vreq) {
|
PropertyTemplateModel(Property property, Individual subject, EditingPolicyHelper policyHelper, VitroRequest vreq) {
|
||||||
|
@ -42,6 +43,7 @@ public abstract class PropertyTemplateModel extends BaseTemplateModel {
|
||||||
localName = property.getLocalName();
|
localName = property.getLocalName();
|
||||||
log.debug("Local name for property " + propertyUri + ": " + localName);
|
log.debug("Local name for property " + propertyUri + ": " + localName);
|
||||||
setVerboseDisplayValues(property);
|
setVerboseDisplayValues(property);
|
||||||
|
|
||||||
// Do in subclass constructor. The label has not been set on the property, and the
|
// Do in subclass constructor. The label has not been set on the property, and the
|
||||||
// means of getting the label differs between object and data properties.
|
// means of getting the label differs between object and data properties.
|
||||||
// this.name = property.getLabel();
|
// this.name = property.getLabel();
|
||||||
|
@ -90,11 +92,10 @@ public abstract class PropertyTemplateModel extends BaseTemplateModel {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Determine whether a new statement can be added
|
protected abstract void setAddUrl(EditingPolicyHelper policyHelper, Property property);
|
||||||
protected abstract void setAddAccess(EditingPolicyHelper policyHelper, Property property);
|
|
||||||
|
|
||||||
|
|
||||||
/* Access methods for templates */
|
/* Template properties */
|
||||||
|
|
||||||
public abstract String getType();
|
public abstract String getType();
|
||||||
|
|
||||||
|
@ -110,7 +111,9 @@ public abstract class PropertyTemplateModel extends BaseTemplateModel {
|
||||||
return propertyUri;
|
return propertyUri;
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract String getAddUrl();
|
public String getAddUrl() {
|
||||||
|
return addUrl;
|
||||||
|
}
|
||||||
|
|
||||||
public Map<String, Object> getVerboseDisplay() {
|
public Map<String, Object> getVerboseDisplay() {
|
||||||
return verboseDisplay;
|
return verboseDisplay;
|
||||||
|
|
|
@ -6,10 +6,10 @@
|
||||||
|
|
||||||
<#if individual.showAdminPanel>
|
<#if individual.showAdminPanel>
|
||||||
<section id="admin">
|
<section id="admin">
|
||||||
<h3>Admin Panel</h3><a class="edit-individual" href="${individual.editUrl}">Edit this individual</a>
|
<h3>Admin Panel</h3><a class="edit-individual" href="${individual.controlPanelUrl()}">Edit this individual</a>
|
||||||
|
|
||||||
<section id = "verbose-mode">
|
<section id = "verbose-mode">
|
||||||
<#if verbosePropertySwitch??>
|
<#if verbosePropertySwitch?has_content>
|
||||||
<#assign anchorId = "verbosePropertySwitch">
|
<#assign anchorId = "verbosePropertySwitch">
|
||||||
<#assign currentValue = verbosePropertySwitch.currentValue?string("on", "off")>
|
<#assign currentValue = verbosePropertySwitch.currentValue?string("on", "off")>
|
||||||
<#assign newValue = verbosePropertySwitch.currentValue?string("off", "on")>
|
<#assign newValue = verbosePropertySwitch.currentValue?string("off", "on")>
|
||||||
|
|
|
@ -201,7 +201,7 @@ name will be used as the label. -->
|
||||||
If there's a mainImage statement but no thumbnail image, treat it as if there is no image. -->
|
If there's a mainImage statement but no thumbnail image, treat it as if there is no image. -->
|
||||||
<#if (mainImage.statements)?has_content && thumbUrl?has_content>
|
<#if (mainImage.statements)?has_content && thumbUrl?has_content>
|
||||||
<a href="${individual.imageUrl}"><img class="individual-photo" src="${thumbUrl}" title="click to view larger image" alt="${individual.name}" width="160" /></a>
|
<a href="${individual.imageUrl}"><img class="individual-photo" src="${thumbUrl}" title="click to view larger image" alt="${individual.name}" width="160" /></a>
|
||||||
<@editingLinks "${mainImage.localName}" mainImage.first editable extraParams />
|
<@editingLinks "${mainImage.localName}" mainImage.first() editable extraParams />
|
||||||
<#else>
|
<#else>
|
||||||
<#local imageLabel><@addLinkWithLabel mainImage editable "Photo" extraParams /></#local>
|
<#local imageLabel><@addLinkWithLabel mainImage editable "Photo" extraParams /></#local>
|
||||||
${imageLabel}
|
${imageLabel}
|
||||||
|
|
Loading…
Add table
Reference in a new issue