Replace PR #99 (#125)

* [VIVO-1656] Extension mechansim for passing properties to templates for Individuals

* [VIVO-1656] Extension mechansim for passing properties to templates for Individuals
This commit is contained in:
Graham Triggs 2019-06-07 18:01:40 +01:00 committed by hudajkhan
parent 47ae42c019
commit f011af1339

View file

@ -4,7 +4,9 @@ package edu.cornell.mannlib.vitro.webapp.controller.individual;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.jena.rdf.model.RDFNode;
@ -49,6 +51,16 @@ class IndividualResponseBuilder {
private static final Log log = LogFactory
.getLog(IndividualResponseBuilder.class);
public interface ExtendedResponse {
void addOptions(VitroRequest vreq, Map<String, Object> body);
}
private static List<ExtendedResponse> extendedResponses = new ArrayList<>();
public static void registerExtendedResponse(ExtendedResponse extendedResponse) {
extendedResponses.add(extendedResponse);
}
private static final Map<String, String> namespaces = new HashMap<String, String>() {{
put("display", VitroVocabulary.DISPLAY);
put("vitro", VitroVocabulary.vitroURI);
@ -85,8 +97,9 @@ class IndividualResponseBuilder {
body.put("profilePageTypesEnabled", getprofilePageTypesFlag());
body.put("verbosePropertySwitch", getVerbosePropertyValues());
addAltMetricOptions(body);
addPlumPrintOptions(body);
for (ExtendedResponse extendedResponse : extendedResponses) {
extendedResponse.addOptions(vreq, body);
}
//Execute data getters that might apply to this individual, e.g. because of the class of the individual
try{
@ -174,52 +187,6 @@ class IndividualResponseBuilder {
return map;
}
private void addAltMetricOptions(Map<String, Object> body) {
ConfigurationProperties properties = ConfigurationProperties.getBean(vreq);
if (properties != null) {
String enabled = properties.getProperty("resource.altmetric", "enabled");
String displayTo = properties.getProperty("resource.altmetric.displayto", "right");
String badgeType = properties.getProperty("resource.altmetric.badge-type", "donut");
String badgeHideEmpty = properties.getProperty("resource.altmetric.hide-no-mentions", "true");
String badgePopover = properties.getProperty("resource.altmetric.badge-popover", "right");
String badgeDetails = properties.getProperty("resource.altmetric.badge-details");
if (!"disabled".equalsIgnoreCase(enabled)) {
body.put("altmetricEnabled", true);
body.put("altmetricDisplayTo", displayTo);
body.put("altmetricBadgeType", badgeType);
if ("true".equalsIgnoreCase(badgeHideEmpty)) {
body.put("altmetricHideEmpty", true);
}
body.put("altmetricPopover", badgePopover);
body.put("altmetricDetails", badgeDetails);
}
}
}
private void addPlumPrintOptions(Map<String, Object> body) {
ConfigurationProperties properties = ConfigurationProperties.getBean(vreq);
if (properties != null) {
String enabled = properties.getProperty("resource.plum-print", "enabled");
String displayTo = properties.getProperty("resource.plum-print.displayto", "right");
String printHideEmpty = properties.getProperty("resource.plum-print.hide-when-empty", "true");
String printPopover = properties.getProperty("resource.plum-print.popover", "right");
String printSize = properties.getProperty("resource.plum-print.size", "medium");
if (!"disabled".equalsIgnoreCase(enabled)) {
body.put("plumPrintEnabled", true);
body.put("plumPrintDisplayTo", displayTo);
body.put("plumPrintHideEmpty", "true".equalsIgnoreCase(printHideEmpty) ? "true" : "false");
body.put("plumPrintPopover", printPopover);
body.put("plumPrintSize", printSize);
}
}
}
private boolean getTemporalVisualizationFlag() {
String property = ConfigurationProperties.getBean(vreq).getProperty(
"visualization.temporal");