NIHVIVO-2508 Change template properties to methods so not pre-computed.

This commit is contained in:
ryounes 2011-08-05 22:25:44 +00:00
parent ddd6469a3a
commit b5b44b73c1
6 changed files with 114 additions and 97 deletions

View file

@ -105,10 +105,6 @@ public abstract class BaseIndividualTemplateModel extends BaseTemplateModel {
: UrlBuilder.addParams(profileUrl, "format", "rdfxml");
}
public String getEditUrl() {
return UrlBuilder.getUrl(Route.INDIVIDUAL_EDIT, "uri", getUri());
}
public GroupedPropertyList getPropertyList() {
if (propertyList == null) {
propertyList = new GroupedPropertyList(individual, vreq, policyHelper);
@ -167,38 +163,61 @@ public abstract class BaseIndividualTemplateModel extends BaseTemplateModel {
return individual.getLocalName();
}
public String nullString() {
return null;
}
// For testing dump
// // 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 */
@ -217,4 +236,8 @@ public abstract class BaseIndividualTemplateModel extends BaseTemplateModel {
return id;
}
public String controlPanelUrl() {
return UrlBuilder.getUrl(Route.INDIVIDUAL_EDIT, "uri", getUri());
}
}

View file

@ -53,13 +53,13 @@ public class DataPropertyTemplateModel extends PropertyTemplateModel {
log.debug("Data property " + getUri() + " is unpopulated.");
}
setAddAccess(policyHelper, dp);
setAddUrl(policyHelper, dp);
}
// Determine whether a new statement can be added
@Override
protected void setAddAccess(EditingPolicyHelper policyHelper, Property property) {
protected void setAddUrl(EditingPolicyHelper policyHelper, Property property) {
this.addUrl = "";
if (policyHelper != null) {
DataProperty dp = (DataProperty) property;
@ -68,13 +68,22 @@ public class DataPropertyTemplateModel extends PropertyTemplateModel {
if (dp.getURI().equals(VitroVocabulary.MONIKER)) {
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();
// Display limit of -1 (default value for new property) means no display limit
if ( (displayLimit < 0) || (displayLimit > statements.size()) ) {
RequestedAction action = new AddDataPropStmt(subjectUri, propertyUri,RequestActionConstants.SOME_LITERAL, null, null);
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;
}
/* Access methods for templates */
/* Template properties */
public String getType() {
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() {
return statements;
}
public DataPropertyStatementTemplateModel getFirst() {
/* Template methods */
public DataPropertyStatementTemplateModel first() {
return ( (statements == null || statements.isEmpty()) ) ? null : statements.get(0);
}
public String getFirstValue() {
DataPropertyStatementTemplateModel first = getFirst();
public String firstValue() {
DataPropertyStatementTemplateModel first = first();
return first == null ? null : first.getValue();
}

View file

@ -111,16 +111,29 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel
objectKey = getQueryObjectVariableName();
setAddAccess(policyHelper, op);
setAddUrl(policyHelper, op);
}
// Determine whether a new statement can be added
@Override
protected void setAddAccess(EditingPolicyHelper policyHelper, Property property) {
protected void setAddUrl(EditingPolicyHelper policyHelper, Property property) {
addUrl = "";
if (policyHelper != null) {
RequestedAction action = new AddObjectPropStmt(subjectUri, propertyUri, RequestActionConstants.SOME_URI);
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;
}
public static String getImageUploadUrl(String subjectUri, String action) {
protected static String getImageUploadUrl(String subjectUri, String action) {
ParamMap params = new ParamMap(
"entityUri", subjectUri,
"action", action);
@ -560,7 +573,7 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel
}
}
/* Access methods for templates */
/* Template properties */
public String getType() {
return TYPE;
@ -572,23 +585,4 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel
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;
}
}

View file

@ -32,7 +32,8 @@ public abstract class PropertyTemplateModel extends BaseTemplateModel {
private final String localName;
protected Map<String, Object> verboseDisplay;
protected boolean addAccess; // defaults to false
protected String addUrl;
private String name;
PropertyTemplateModel(Property property, Individual subject, EditingPolicyHelper policyHelper, VitroRequest vreq) {
@ -42,6 +43,7 @@ public abstract class PropertyTemplateModel extends BaseTemplateModel {
localName = property.getLocalName();
log.debug("Local name for property " + propertyUri + ": " + localName);
setVerboseDisplayValues(property);
// 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.
// this.name = property.getLabel();
@ -90,11 +92,10 @@ public abstract class PropertyTemplateModel extends BaseTemplateModel {
this.name = name;
}
// Determine whether a new statement can be added
protected abstract void setAddAccess(EditingPolicyHelper policyHelper, Property property);
protected abstract void setAddUrl(EditingPolicyHelper policyHelper, Property property);
/* Access methods for templates */
/* Template properties */
public abstract String getType();
@ -110,7 +111,9 @@ public abstract class PropertyTemplateModel extends BaseTemplateModel {
return propertyUri;
}
public abstract String getAddUrl();
public String getAddUrl() {
return addUrl;
}
public Map<String, Object> getVerboseDisplay() {
return verboseDisplay;

View file

@ -6,10 +6,10 @@
<#if individual.showAdminPanel>
<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">
<#if verbosePropertySwitch??>
<#if verbosePropertySwitch?has_content>
<#assign anchorId = "verbosePropertySwitch">
<#assign currentValue = verbosePropertySwitch.currentValue?string("on", "off")>
<#assign newValue = verbosePropertySwitch.currentValue?string("off", "on")>

View file

@ -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 (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>
<@editingLinks "${mainImage.localName}" mainImage.first editable extraParams />
<@editingLinks "${mainImage.localName}" mainImage.first() editable extraParams />
<#else>
<#local imageLabel><@addLinkWithLabel mainImage editable "Photo" extraParams /></#local>
${imageLabel}