diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/controller/ExportQrCodeController.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/controller/ExportQrCodeController.java index 6b5a82d7..76f4543f 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/controller/ExportQrCodeController.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/controller/ExportQrCodeController.java @@ -3,17 +3,16 @@ package edu.cornell.mannlib.vitro.webapp.controller; import java.util.ArrayList; -import java.util.Enumeration; import java.util.HashMap; import java.util.List; import java.util.Map; +import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual.IndividualTemplateModelBuilder; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.ResultSet; -import com.hp.hpl.jena.rdf.model.RDFNode; import edu.cornell.mannlib.vitro.webapp.beans.Individual; import edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerHttpServlet; @@ -25,7 +24,7 @@ import edu.cornell.mannlib.vitro.webapp.controller.individual.IndividualRequestA import edu.cornell.mannlib.vitro.webapp.controller.individual.IndividualRequestAnalyzer; import edu.cornell.mannlib.vitro.webapp.controller.individual.IndividualRequestInfo; import edu.cornell.mannlib.vitro.webapp.dao.jena.QueryUtils; -import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual.IndividualTemplateModel; +import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual.VIVOIndividualTemplateModel; import freemarker.ext.beans.BeansWrapper; import freemarker.template.DefaultObjectWrapper; @@ -67,7 +66,7 @@ public class ExportQrCodeController extends FreemarkerHttpServlet { wrapper.setExposureLevel(BeansWrapper.EXPOSE_SAFE); Map body = new HashMap(); - body.put("individual", wrapper.wrap(new IndividualTemplateModel(individual, vreq))); + body.put("individual", wrapper.wrap(IndividualTemplateModelBuilder.build(individual, vreq))); body.put("qrData", qrData); return new TemplateResponseValues(TEMPLATE_DEFAULT, body); } catch (Throwable e) { diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/controller/ajax/QrCodeDetails.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/controller/ajax/QrCodeDetails.java index 64ec4e6e..99fded21 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/controller/ajax/QrCodeDetails.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/controller/ajax/QrCodeDetails.java @@ -2,16 +2,12 @@ package edu.cornell.mannlib.vitro.webapp.controller.ajax; import java.io.IOException; -import java.lang.Integer; import java.util.ArrayList; -import java.util.Enumeration; import java.util.List; import java.util.Map; -import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletResponse; -import javax.servlet.http.HttpSession; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -19,21 +15,13 @@ import org.json.JSONException; import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.ResultSet; -import com.hp.hpl.jena.rdf.model.RDFNode; import edu.cornell.mannlib.vitro.webapp.beans.Individual; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; -import edu.cornell.mannlib.vitro.webapp.controller.ajax.VitroAjaxController; -import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder; -import edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerHttpServlet; -import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ExceptionResponseValues; -import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ResponseValues; -import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.TemplateResponseValues; import edu.cornell.mannlib.vitro.webapp.controller.individual.IndividualRequestAnalysisContextImpl; import edu.cornell.mannlib.vitro.webapp.controller.individual.IndividualRequestAnalyzer; import edu.cornell.mannlib.vitro.webapp.controller.individual.IndividualRequestInfo; import edu.cornell.mannlib.vitro.webapp.dao.jena.QueryUtils; -import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual.IndividualTemplateModel; public class QrCodeDetails extends AbstractAjaxResponder { diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/IndividualTemplateModel.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/VIVOIndividualTemplateModel.java similarity index 85% rename from api/src/main/java/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/IndividualTemplateModel.java rename to api/src/main/java/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/VIVOIndividualTemplateModel.java index 984cd393..8715d353 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/IndividualTemplateModel.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/VIVOIndividualTemplateModel.java @@ -2,32 +2,19 @@ package edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import com.hp.hpl.jena.query.QuerySolution; -import com.hp.hpl.jena.query.ResultSet; -import com.hp.hpl.jena.rdf.model.RDFNode; - -import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement; import edu.cornell.mannlib.vitro.webapp.beans.Individual; 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.controller.freemarker.UrlBuilder.Route; import edu.cornell.mannlib.vitro.webapp.controller.visualization.VisualizationFrameworkConstants; -import edu.cornell.mannlib.vitro.webapp.dao.jena.QueryUtils; -import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; -public class IndividualTemplateModel extends BaseIndividualTemplateModel { +public class VIVOIndividualTemplateModel extends IndividualTemplateModel { - private static final Log log = LogFactory.getLog(IndividualTemplateModel.class); + private static final Log log = LogFactory.getLog(VIVOIndividualTemplateModel.class); private static final String FOAF = "http://xmlns.com/foaf/0.1/"; private static final String PERSON_CLASS = FOAF + "Person"; @@ -42,9 +29,18 @@ public class IndividualTemplateModel extends BaseIndividualTemplateModel { private static final String BASE_VISUALIZATION_URL = UrlBuilder.getUrl(Route.VISUALIZATION_SHORT.path()); - public IndividualTemplateModel(Individual individual, VitroRequest vreq) { + VIVOIndividualTemplateModel(Individual individual, VitroRequest vreq) { super(individual, vreq); } + + public static void setAsDefault() { + IndividualTemplateModelBuilder.setCustomBuilder(new IndividualTemplateModelBuilder.IIndividualTemplateModelBuilder() { + @Override + public VIVOIndividualTemplateModel build(Individual individual, VitroRequest vreq) { + return new VIVOIndividualTemplateModel(individual, vreq); + } + }); + } private String getVisUrl(String visPath) { String visUrl; diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individuallist/ListedIndividual.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individuallist/VIVOListedIndividual.java similarity index 77% rename from api/src/main/java/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individuallist/ListedIndividual.java rename to api/src/main/java/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individuallist/VIVOListedIndividual.java index 24615507..ab03c272 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individuallist/ListedIndividual.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individuallist/VIVOListedIndividual.java @@ -13,8 +13,8 @@ import edu.cornell.mannlib.vitro.webapp.beans.Individual; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; import edu.cornell.mannlib.vitro.webapp.dao.jena.QueryUtils; -public class ListedIndividual extends BaseListedIndividual { - private static final Log log = LogFactory.getLog(ListedIndividual.class); +public class VIVOListedIndividual extends ListedIndividual { + private static final Log log = LogFactory.getLog(VIVOListedIndividual.class); private static String VCARD_DATA_QUERY = "" + "PREFIX obo: \n" @@ -28,11 +28,21 @@ public class ListedIndividual extends BaseListedIndividual { private final String title; - public ListedIndividual(Individual individual, VitroRequest vreq) { + VIVOListedIndividual(Individual individual, VitroRequest vreq) { super(individual, vreq); title = findPreferredTitle(); } + public static void setAsDefault() { + ListedIndividualBuilder.setCustomBuilder(new ListedIndividualBuilder.ILIstedIndividualBuilder() { + @Override + public ListedIndividual build(Individual individual, VitroRequest vreq) { + return new VIVOListedIndividual(individual, vreq); + } + }); + + } + private String findPreferredTitle() { String queryStr = QueryUtils.subUriForQueryVar(VCARD_DATA_QUERY, "subject", individual.getURI()); log.debug("queryStr = " + queryStr); diff --git a/api/src/main/java/org/vivoweb/webapp/startup/TemplateModelSetup.java b/api/src/main/java/org/vivoweb/webapp/startup/TemplateModelSetup.java new file mode 100644 index 00000000..0cea0bed --- /dev/null +++ b/api/src/main/java/org/vivoweb/webapp/startup/TemplateModelSetup.java @@ -0,0 +1,25 @@ +package org.vivoweb.webapp.startup; + +import edu.cornell.mannlib.vitro.webapp.beans.Individual; +import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; +import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual.VIVOIndividualTemplateModel; +import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual.IndividualTemplateModelBuilder; +import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individuallist.ListedIndividual; +import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individuallist.ListedIndividualBuilder; +import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individuallist.VIVOListedIndividual; + +import javax.servlet.ServletContextEvent; +import javax.servlet.ServletContextListener; + +public class TemplateModelSetup implements ServletContextListener { + @Override + public void contextInitialized(ServletContextEvent servletContextEvent) { + VIVOIndividualTemplateModel.setAsDefault(); + VIVOListedIndividual.setAsDefault(); + } + + @Override + public void contextDestroyed(ServletContextEvent servletContextEvent) { + + } +} diff --git a/webapp/src/main/webapp/WEB-INF/resources/startup_listeners.txt b/webapp/src/main/webapp/WEB-INF/resources/startup_listeners.txt index 54155694..d626eb21 100644 --- a/webapp/src/main/webapp/WEB-INF/resources/startup_listeners.txt +++ b/webapp/src/main/webapp/WEB-INF/resources/startup_listeners.txt @@ -60,6 +60,7 @@ edu.cornell.mannlib.vitro.webapp.visualization.setup.VisualizationSetup org.vivoweb.webapp.startup.DataGetterN3Setup org.vivoweb.webapp.startup.GeneratorSetup org.vivoweb.webapp.startup.MenuManagementSetup +org.vivoweb.webapp.startup.TemplateModelSetup org.vivoweb.webapp.startup.SearchResultTemplateModelSetup edu.ucsf.vitro.opensocial.OpenSocialSmokeTests