[VIVO-1245] Cleanup Template Model classes

This commit is contained in:
Graham Triggs 2016-05-25 19:47:40 +01:00
parent b5db288cd3
commit 46ca84d519
6 changed files with 54 additions and 35 deletions

View file

@ -3,17 +3,16 @@
package edu.cornell.mannlib.vitro.webapp.controller; package edu.cornell.mannlib.vitro.webapp.controller;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; 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.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.QuerySolution;
import com.hp.hpl.jena.query.ResultSet; 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.beans.Individual;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerHttpServlet; 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.IndividualRequestAnalyzer;
import edu.cornell.mannlib.vitro.webapp.controller.individual.IndividualRequestInfo; import edu.cornell.mannlib.vitro.webapp.controller.individual.IndividualRequestInfo;
import edu.cornell.mannlib.vitro.webapp.dao.jena.QueryUtils; 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.ext.beans.BeansWrapper;
import freemarker.template.DefaultObjectWrapper; import freemarker.template.DefaultObjectWrapper;
@ -67,7 +66,7 @@ public class ExportQrCodeController extends FreemarkerHttpServlet {
wrapper.setExposureLevel(BeansWrapper.EXPOSE_SAFE); wrapper.setExposureLevel(BeansWrapper.EXPOSE_SAFE);
Map<String, Object> body = new HashMap<String, Object>(); Map<String, Object> body = new HashMap<String, Object>();
body.put("individual", wrapper.wrap(new IndividualTemplateModel(individual, vreq))); body.put("individual", wrapper.wrap(IndividualTemplateModelBuilder.build(individual, vreq)));
body.put("qrData", qrData); body.put("qrData", qrData);
return new TemplateResponseValues(TEMPLATE_DEFAULT, body); return new TemplateResponseValues(TEMPLATE_DEFAULT, body);
} catch (Throwable e) { } catch (Throwable e) {

View file

@ -2,16 +2,12 @@
package edu.cornell.mannlib.vitro.webapp.controller.ajax; package edu.cornell.mannlib.vitro.webapp.controller.ajax;
import java.io.IOException; import java.io.IOException;
import java.lang.Integer;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; 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.QuerySolution;
import com.hp.hpl.jena.query.ResultSet; 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.beans.Individual;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; 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.IndividualRequestAnalysisContextImpl;
import edu.cornell.mannlib.vitro.webapp.controller.individual.IndividualRequestAnalyzer; import edu.cornell.mannlib.vitro.webapp.controller.individual.IndividualRequestAnalyzer;
import edu.cornell.mannlib.vitro.webapp.controller.individual.IndividualRequestInfo; import edu.cornell.mannlib.vitro.webapp.controller.individual.IndividualRequestInfo;
import edu.cornell.mannlib.vitro.webapp.dao.jena.QueryUtils; import edu.cornell.mannlib.vitro.webapp.dao.jena.QueryUtils;
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual.IndividualTemplateModel;
public class QrCodeDetails extends AbstractAjaxResponder { public class QrCodeDetails extends AbstractAjaxResponder {

View file

@ -2,32 +2,19 @@
package edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual; 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.Log;
import org.apache.commons.logging.LogFactory; 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.beans.Individual;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; 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;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder.ParamMap; 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.freemarker.UrlBuilder.Route;
import edu.cornell.mannlib.vitro.webapp.controller.visualization.VisualizationFrameworkConstants; 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 FOAF = "http://xmlns.com/foaf/0.1/";
private static final String PERSON_CLASS = FOAF + "Person"; private static final String PERSON_CLASS = FOAF + "Person";
@ -42,10 +29,19 @@ public class IndividualTemplateModel extends BaseIndividualTemplateModel {
private static final String BASE_VISUALIZATION_URL = private static final String BASE_VISUALIZATION_URL =
UrlBuilder.getUrl(Route.VISUALIZATION_SHORT.path()); UrlBuilder.getUrl(Route.VISUALIZATION_SHORT.path());
public IndividualTemplateModel(Individual individual, VitroRequest vreq) { VIVOIndividualTemplateModel(Individual individual, VitroRequest vreq) {
super(individual, 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) { private String getVisUrl(String visPath) {
String visUrl; String visUrl;
boolean isUsingDefaultNameSpace = UrlBuilder.isUriInDefaultNamespace( boolean isUsingDefaultNameSpace = UrlBuilder.isUriInDefaultNamespace(

View file

@ -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.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.dao.jena.QueryUtils; import edu.cornell.mannlib.vitro.webapp.dao.jena.QueryUtils;
public class ListedIndividual extends BaseListedIndividual { public class VIVOListedIndividual extends ListedIndividual {
private static final Log log = LogFactory.getLog(ListedIndividual.class); private static final Log log = LogFactory.getLog(VIVOListedIndividual.class);
private static String VCARD_DATA_QUERY = "" private static String VCARD_DATA_QUERY = ""
+ "PREFIX obo: <http://purl.obolibrary.org/obo/> \n" + "PREFIX obo: <http://purl.obolibrary.org/obo/> \n"
@ -28,11 +28,21 @@ public class ListedIndividual extends BaseListedIndividual {
private final String title; private final String title;
public ListedIndividual(Individual individual, VitroRequest vreq) { VIVOListedIndividual(Individual individual, VitroRequest vreq) {
super(individual, vreq); super(individual, vreq);
title = findPreferredTitle(); 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() { private String findPreferredTitle() {
String queryStr = QueryUtils.subUriForQueryVar(VCARD_DATA_QUERY, "subject", individual.getURI()); String queryStr = QueryUtils.subUriForQueryVar(VCARD_DATA_QUERY, "subject", individual.getURI());
log.debug("queryStr = " + queryStr); log.debug("queryStr = " + queryStr);

View file

@ -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) {
}
}

View file

@ -60,6 +60,7 @@ edu.cornell.mannlib.vitro.webapp.visualization.setup.VisualizationSetup
org.vivoweb.webapp.startup.DataGetterN3Setup org.vivoweb.webapp.startup.DataGetterN3Setup
org.vivoweb.webapp.startup.GeneratorSetup org.vivoweb.webapp.startup.GeneratorSetup
org.vivoweb.webapp.startup.MenuManagementSetup org.vivoweb.webapp.startup.MenuManagementSetup
org.vivoweb.webapp.startup.TemplateModelSetup
org.vivoweb.webapp.startup.SearchResultTemplateModelSetup org.vivoweb.webapp.startup.SearchResultTemplateModelSetup
edu.ucsf.vitro.opensocial.OpenSocialSmokeTests edu.ucsf.vitro.opensocial.OpenSocialSmokeTests