From 844c8e30be789419ebfb98d8ebeb1c8bc2f9ba7d Mon Sep 17 00:00:00 2001 From: cdtank Date: Fri, 25 Feb 2011 00:47:39 +0000 Subject: [PATCH] 1. Removed unused construct query runner. 2. Refactored all construct query runners to implement a common interface. 3. Changed AjaxVis*Controller & DataVisContoller to use Dataset instead of Datasource. --- .../AjaxVisualizationController.java | 23 +- .../DataVisualizationController.java | 23 +- .../StandardVisualizationController.java | 8 - .../CoPIGrantCountConstructQueryRunner.java | 464 ++++++++++-------- .../CoPIGrantCountRequestHandler.java | 44 +- .../EntityComparisonUtilityFunctions.java | 3 +- ...yPublicationCountConstructQueryRunner.java | 3 +- .../EntityPublicationCountRequestHandler.java | 35 +- ...OrganizationTypesConstructQueryRunner.java | 4 +- .../EntityGrantCountConstructQueryRunner.java | 3 +- .../EntityGrantCountRequestHandler.java | 40 +- .../PersonGrantCountConstructQueryRunner.java | 213 -------- .../PersonLevelRequestHandler.java | 3 +- .../PersonPublicationCountRequestHandler.java | 8 +- .../freemarker/visutils/ModelConstructor.java | 13 + .../visutils/VisualizationRequestHandler.java | 5 +- 16 files changed, 303 insertions(+), 589 deletions(-) delete mode 100644 src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/persongrantcount/PersonGrantCountConstructQueryRunner.java create mode 100644 src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/visutils/ModelConstructor.java diff --git a/src/edu/cornell/mannlib/vitro/webapp/controller/visualization/freemarker/AjaxVisualizationController.java b/src/edu/cornell/mannlib/vitro/webapp/controller/visualization/freemarker/AjaxVisualizationController.java index 5a403450..5ddbcca9 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/controller/visualization/freemarker/AjaxVisualizationController.java +++ b/src/edu/cornell/mannlib/vitro/webapp/controller/visualization/freemarker/AjaxVisualizationController.java @@ -11,17 +11,14 @@ import javax.servlet.http.HttpServletResponse; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import com.hp.hpl.jena.query.DataSource; -import com.hp.hpl.jena.query.DatasetFactory; +import com.hp.hpl.jena.query.Dataset; import com.hp.hpl.jena.query.Syntax; import com.hp.hpl.jena.rdf.model.Model; -import com.hp.hpl.jena.rdf.model.ModelMaker; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; import edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerHttpServlet; import edu.cornell.mannlib.vitro.webapp.controller.freemarker.TemplateProcessingHelper.TemplateProcessingException; import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.TemplateResponseValues; -import edu.cornell.mannlib.vitro.webapp.visualization.constants.VisConstants; import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException; import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.UtilityFunctions; import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.VisualizationRequestHandler; @@ -110,14 +107,14 @@ public class AjaxVisualizationController extends FreemarkerHttpServlet { } - DataSource dataSource = setupJENADataSource(model, vitroRequest); + Dataset dataset = setupJENADataSource(vitroRequest); - if (dataSource != null && visRequestHandler != null) { + if (dataset != null && visRequestHandler != null) { try { return visRequestHandler.generateAjaxVisualization(vitroRequest, log, - dataSource); + dataset); } catch (MalformedQueryParametersException e) { return UtilityFunctions.handleMalformedParameters( "Ajax Visualization Query Error - Individual Publication Count", @@ -160,16 +157,8 @@ public class AjaxVisualizationController extends FreemarkerHttpServlet { return visRequestHandler; } - private DataSource setupJENADataSource(Model model, VitroRequest vreq) { - - log.debug("rdfResultFormat was: " + VisConstants.RDF_RESULT_FORMAT_PARAM); - - DataSource dataSource = DatasetFactory.create(); - ModelMaker maker = (ModelMaker) getServletContext().getAttribute("vitroJenaModelMaker"); - - dataSource.setDefaultModel(model); - - return dataSource; + private Dataset setupJENADataSource(VitroRequest vreq) { + return vreq.getDataset(); } } diff --git a/src/edu/cornell/mannlib/vitro/webapp/controller/visualization/freemarker/DataVisualizationController.java b/src/edu/cornell/mannlib/vitro/webapp/controller/visualization/freemarker/DataVisualizationController.java index 82ea47a2..9d4eeaa3 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/controller/visualization/freemarker/DataVisualizationController.java +++ b/src/edu/cornell/mannlib/vitro/webapp/controller/visualization/freemarker/DataVisualizationController.java @@ -12,11 +12,9 @@ import javax.servlet.http.HttpServletResponse; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import com.hp.hpl.jena.query.DataSource; -import com.hp.hpl.jena.query.DatasetFactory; +import com.hp.hpl.jena.query.Dataset; import com.hp.hpl.jena.query.Syntax; import com.hp.hpl.jena.rdf.model.Model; -import com.hp.hpl.jena.rdf.model.ModelMaker; import edu.cornell.mannlib.vitro.webapp.controller.VitroHttpServlet; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; @@ -124,12 +122,12 @@ public class DataVisualizationController extends VitroHttpServlet { throw new MalformedQueryParametersException(errorMessage); } - DataSource dataSource = setupJENADataSource(model, vitroRequest); + Dataset dataset = setupJENADataSource(vitroRequest); - if (dataSource != null && visRequestHandler != null) { + if (dataset != null && visRequestHandler != null) { return visRequestHandler.generateDataVisualization(vitroRequest, log, - dataSource); + dataset); } else { @@ -148,29 +146,24 @@ public class DataVisualizationController extends VitroHttpServlet { .VIS_TYPE_KEY); VisualizationRequestHandler visRequestHandler = null; - try { + visRequestHandler = VisualizationsDependencyInjector .getVisualizationIDsToClassMap(getServletContext()) .get(visType); + } catch (NullPointerException nullKeyException) { - return null; } return visRequestHandler; } - private DataSource setupJENADataSource(Model model, VitroRequest vreq) { + private Dataset setupJENADataSource(VitroRequest vreq) { log.debug("rdfResultFormat was: " + VisConstants.RDF_RESULT_FORMAT_PARAM); - DataSource dataSource = DatasetFactory.create(); - ModelMaker maker = (ModelMaker) getServletContext().getAttribute("vitroJenaModelMaker"); - - dataSource.setDefaultModel(model); - - return dataSource; + return vreq.getDataset(); } } diff --git a/src/edu/cornell/mannlib/vitro/webapp/controller/visualization/freemarker/StandardVisualizationController.java b/src/edu/cornell/mannlib/vitro/webapp/controller/visualization/freemarker/StandardVisualizationController.java index f7b30fba..897ee52d 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/controller/visualization/freemarker/StandardVisualizationController.java +++ b/src/edu/cornell/mannlib/vitro/webapp/controller/visualization/freemarker/StandardVisualizationController.java @@ -5,12 +5,9 @@ package edu.cornell.mannlib.vitro.webapp.controller.visualization.freemarker; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import com.hp.hpl.jena.query.DataSource; import com.hp.hpl.jena.query.Dataset; -import com.hp.hpl.jena.query.DatasetFactory; import com.hp.hpl.jena.query.Syntax; import com.hp.hpl.jena.rdf.model.Model; -import com.hp.hpl.jena.rdf.model.ModelMaker; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; import edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerHttpServlet; @@ -135,11 +132,6 @@ public class StandardVisualizationController extends FreemarkerHttpServlet { log.debug("rdfResultFormat was: " + VisConstants.RDF_RESULT_FORMAT_PARAM); -// DataSource dataSource = DatasetFactory.create(); -// ModelMaker maker = (ModelMaker) getServletContext().getAttribute("vitroJenaModelMaker"); -// -// dataSource.setDefaultModel(model); - return vreq.getDataset(); } diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/coprincipalinvestigator/CoPIGrantCountConstructQueryRunner.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/coprincipalinvestigator/CoPIGrantCountConstructQueryRunner.java index d38dd96f..560e13bd 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/coprincipalinvestigator/CoPIGrantCountConstructQueryRunner.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/coprincipalinvestigator/CoPIGrantCountConstructQueryRunner.java @@ -22,250 +22,288 @@ import com.hp.hpl.jena.rdf.model.ModelFactory; import edu.cornell.mannlib.vitro.webapp.visualization.constants.QueryConstants; import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException; +import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.ModelConstructor; +public class CoPIGrantCountConstructQueryRunner implements ModelConstructor { -public class CoPIGrantCountConstructQueryRunner { - protected static final Syntax SYNTAX = Syntax.syntaxARQ; - + private String egoURI; - + private Dataset Dataset; - + private long before, after; - private Log log = LogFactory.getLog(CoPIGrantCountConstructQueryRunner.class.getName()); + private Log log = LogFactory + .getLog(CoPIGrantCountConstructQueryRunner.class.getName()); - - private static final String SPARQL_QUERY_COMMON_CONSTRUCT_AND_WHERE_STRING = - "?Role core:roleIn ?Grant . " - + "?Grant rdfs:label ?GrantLabel . " - + "?Grant core:relatedRole ?RelatedRole . "; - - public CoPIGrantCountConstructQueryRunner(String egoURI, Dataset Dataset, Log log){ + private static final String SPARQL_QUERY_COMMON_CONSTRUCT_AND_WHERE_STRING = "?Role core:roleIn ?Grant . " + + "?Grant rdfs:label ?GrantLabel . " + + "?Grant core:relatedRole ?RelatedRole . "; + + public CoPIGrantCountConstructQueryRunner(String egoURI, Dataset Dataset, + Log log) { this.egoURI = egoURI; this.Dataset = Dataset; - //this.log = log; + // this.log = log; } private String generateConstructQueryForInvestigatorLabel(String queryURI) { - - String sparqlQuery = - "CONSTRUCT { " - + "<"+queryURI+ "> rdfs:label ?investigatorLabel ." - + "}" - + "WHERE {" - + "<"+queryURI+ "> rdfs:label ?investigatorLabel " - + "}"; - + + String sparqlQuery = "CONSTRUCT { " + "<" + queryURI + + "> rdfs:label ?investigatorLabel ." + "}" + "WHERE {" + "<" + + queryURI + "> rdfs:label ?investigatorLabel " + "}"; + return sparqlQuery; } - - private String generateConstructQueryForInvestigatorRoleOfProperty(String queryURI, String preboundProperty){ - - String sparqlQuery = - "CONSTRUCT { " - + "<"+queryURI+ ">" + preboundProperty + " ?Role . " - + SPARQL_QUERY_COMMON_CONSTRUCT_AND_WHERE_STRING - + "?RelatedRole core:investigatorRoleOf ?coInvestigator ." - + "?coInvestigator rdfs:label ?coInvestigatorLabel . " - + "}" - + "WHERE { " - + "<"+queryURI+ ">" + preboundProperty + " ?Role . " - + SPARQL_QUERY_COMMON_CONSTRUCT_AND_WHERE_STRING - + "?RelatedRole core:investigatorRoleOf ?coInvestigator ." - + "?coInvestigator rdfs:label ?coInvestigatorLabel . " - + "}"; - + + private String generateConstructQueryForInvestigatorRoleOfProperty( + String queryURI, String preboundProperty) { + + String sparqlQuery = "CONSTRUCT { " + "<" + queryURI + ">" + + preboundProperty + " ?Role . " + + SPARQL_QUERY_COMMON_CONSTRUCT_AND_WHERE_STRING + + "?RelatedRole core:investigatorRoleOf ?coInvestigator ." + + "?coInvestigator rdfs:label ?coInvestigatorLabel . " + "}" + + "WHERE { " + "<" + queryURI + ">" + preboundProperty + + " ?Role . " + SPARQL_QUERY_COMMON_CONSTRUCT_AND_WHERE_STRING + + "?RelatedRole core:investigatorRoleOf ?coInvestigator ." + + "?coInvestigator rdfs:label ?coInvestigatorLabel . " + "}"; + return sparqlQuery; } - - private String generateConstructQueryForPrincipalInvestigatorRoleOfProperty(String queryURI, String preboundProperty){ - - String sparqlQuery = - "CONSTRUCT { " - + "<"+queryURI+ ">" + preboundProperty + " ?Role . " - + SPARQL_QUERY_COMMON_CONSTRUCT_AND_WHERE_STRING - + "?RelatedRole core:principalInvestigatorRoleOf ?coInvestigator ." - + "?coInvestigator rdfs:label ?coInvestigatorLabel . " - + "}" - + "WHERE { " - + "<"+queryURI+ ">" + preboundProperty + " ?Role . " - + SPARQL_QUERY_COMMON_CONSTRUCT_AND_WHERE_STRING - + "?RelatedRole core:principalInvestigatorRoleOf ?coInvestigator ." - + "?coInvestigator rdfs:label ?coInvestigatorLabel . " - + "}"; - + + private String generateConstructQueryForPrincipalInvestigatorRoleOfProperty( + String queryURI, String preboundProperty) { + + String sparqlQuery = "CONSTRUCT { " + + "<" + + queryURI + + ">" + + preboundProperty + + " ?Role . " + + SPARQL_QUERY_COMMON_CONSTRUCT_AND_WHERE_STRING + + "?RelatedRole core:principalInvestigatorRoleOf ?coInvestigator ." + + "?coInvestigator rdfs:label ?coInvestigatorLabel . " + + "}" + + "WHERE { " + + "<" + + queryURI + + ">" + + preboundProperty + + " ?Role . " + + SPARQL_QUERY_COMMON_CONSTRUCT_AND_WHERE_STRING + + "?RelatedRole core:principalInvestigatorRoleOf ?coInvestigator ." + + "?coInvestigator rdfs:label ?coInvestigatorLabel . " + "}"; + return sparqlQuery; - } - - private String generateConstructQueryForCoPrincipalInvestigatorRoleOfProperty(String queryURI, String preboundProperty){ - - String sparqlQuery = - "CONSTRUCT { " - + "<"+queryURI+ ">" + preboundProperty + " ?Role . " - + SPARQL_QUERY_COMMON_CONSTRUCT_AND_WHERE_STRING - + "?RelatedRole core:co-PrincipalInvestigatorRoleOf ?coInvestigator ." - + "?coInvestigator rdfs:label ?coInvestigatorLabel . " - + "}" - + "WHERE { " - + "<"+queryURI+ ">" + preboundProperty + " ?Role . " - + SPARQL_QUERY_COMMON_CONSTRUCT_AND_WHERE_STRING - + "?RelatedRole core:co-PrincipalInvestigatorRoleOf ?coInvestigator ." - + "?coInvestigator rdfs:label ?coInvestigatorLabel . " - + "}"; - + } + + private String generateConstructQueryForCoPrincipalInvestigatorRoleOfProperty( + String queryURI, String preboundProperty) { + + String sparqlQuery = "CONSTRUCT { " + + "<" + + queryURI + + ">" + + preboundProperty + + " ?Role . " + + SPARQL_QUERY_COMMON_CONSTRUCT_AND_WHERE_STRING + + "?RelatedRole core:co-PrincipalInvestigatorRoleOf ?coInvestigator ." + + "?coInvestigator rdfs:label ?coInvestigatorLabel . " + + "}" + + "WHERE { " + + "<" + + queryURI + + ">" + + preboundProperty + + " ?Role . " + + SPARQL_QUERY_COMMON_CONSTRUCT_AND_WHERE_STRING + + "?RelatedRole core:co-PrincipalInvestigatorRoleOf ?coInvestigator ." + + "?coInvestigator rdfs:label ?coInvestigatorLabel . " + "}"; + return sparqlQuery; - } - - private String generateConstructQueryForDateTimeValueofRole(String queryURI, String preboundProperty){ - - String sparqlQuery = - "CONSTRUCT { " - + "<"+queryURI+ ">" + preboundProperty + " ?Role . " - + "?Role core:dateTimeInterval ?dateTimeIntervalValue . " - + "?dateTimeIntervalValue core:start ?startDate . " - + "?startDate core:dateTime ?startDateTimeValue . " - + "?dateTimeIntervalValue core:end ?endDate . " - + "?endDate core:dateTime ?endDateTimeValue . " - + "}" - + "WHERE { " - + "{" - + "<"+queryURI+ ">" + preboundProperty + " ?Role . " - + "?Role core:dateTimeInterval ?dateTimeIntervalValue . " - + "?dateTimeIntervalValue core:start ?startDate . " - + "?startDate core:dateTime ?startDateTimeValue . " - + "} UNION " - + "{" - + "<"+queryURI+ ">" + preboundProperty + " ?Role . " - + "?Role core:dateTimeInterval ?dateTimeIntervalValue . " - + "?dateTimeIntervalValue core:end ?endDate . " - + "?endDate core:dateTime ?endDateTimeValue . " - + "}" - + "}"; - + } + + private String generateConstructQueryForDateTimeValueofRole( + String queryURI, String preboundProperty) { + + String sparqlQuery = "CONSTRUCT { " + "<" + queryURI + ">" + + preboundProperty + " ?Role . " + + "?Role core:dateTimeInterval ?dateTimeIntervalValue . " + + "?dateTimeIntervalValue core:start ?startDate . " + + "?startDate core:dateTime ?startDateTimeValue . " + + "?dateTimeIntervalValue core:end ?endDate . " + + "?endDate core:dateTime ?endDateTimeValue . " + "}" + + "WHERE { " + "{" + "<" + queryURI + ">" + preboundProperty + + " ?Role . " + + "?Role core:dateTimeInterval ?dateTimeIntervalValue . " + + "?dateTimeIntervalValue core:start ?startDate . " + + "?startDate core:dateTime ?startDateTimeValue . " + + "} UNION " + "{" + "<" + queryURI + ">" + preboundProperty + + " ?Role . " + + "?Role core:dateTimeInterval ?dateTimeIntervalValue . " + + "?dateTimeIntervalValue core:end ?endDate . " + + "?endDate core:dateTime ?endDateTimeValue . " + "}" + "}"; + return sparqlQuery; - } - - private String generateConstructQueryForDateTimeValueofGrant(String queryURI, String preboundProperty){ - - String sparqlQuery = - "CONSTRUCT { " - + "<"+queryURI+ ">" + preboundProperty + " ?Role . " - + "?Role core:roleIn ?Grant ." - + "?Grant core:dateTimeInterval ?dateTimeIntervalValueForGrant . " - + "?dateTimeIntervalValueForGrant core:start ?startDateForGrant . " - + "?startDateForGrant core:dateTime ?startDateTimeValueForGrant . " - + "?dateTimeIntervalValueForGrant core:end ?endDateForGrant . " - + "?endDateForGrant core:dateTime ?endDateTimeValueForGrant . " - + "}" - + "WHERE { " - + "{" - + "<"+queryURI+ ">" + preboundProperty + " ?Role . " - + "?Role core:roleIn ?Grant ." - + "?Grant core:dateTimeInterval ?dateTimeIntervalValueForGrant . " - + "?dateTimeIntervalValueForGrant core:start ?startDateForGrant . " - + "?startDateForGrant core:dateTime ?startDateTimeValueForGrant . " - + "} UNION " - + "{" - + "<"+queryURI+ ">" + preboundProperty + " ?Role . " - + "?Role core:roleIn ?Grant ." - + "?Grant core:dateTimeInterval ?dateTimeIntervalValueForGrant . " - + "?dateTimeIntervalValueForGrant core:end ?endDateForGrant . " - + "?endDateForGrant core:dateTime ?endDateTimeValueForGrant . " - + "}" - + "}"; - + } + + private String generateConstructQueryForDateTimeValueofGrant( + String queryURI, String preboundProperty) { + + String sparqlQuery = "CONSTRUCT { " + "<" + + queryURI + + ">" + + preboundProperty + + " ?Role . " + + "?Role core:roleIn ?Grant ." + + "?Grant core:dateTimeInterval ?dateTimeIntervalValueForGrant . " + + "?dateTimeIntervalValueForGrant core:start ?startDateForGrant . " + + "?startDateForGrant core:dateTime ?startDateTimeValueForGrant . " + + "?dateTimeIntervalValueForGrant core:end ?endDateForGrant . " + + "?endDateForGrant core:dateTime ?endDateTimeValueForGrant . " + + "}" + + "WHERE { " + + "{" + + "<" + + queryURI + + ">" + + preboundProperty + + " ?Role . " + + "?Role core:roleIn ?Grant ." + + "?Grant core:dateTimeInterval ?dateTimeIntervalValueForGrant . " + + "?dateTimeIntervalValueForGrant core:start ?startDateForGrant . " + + "?startDateForGrant core:dateTime ?startDateTimeValueForGrant . " + + "} UNION " + + "{" + + "<" + + queryURI + + ">" + + preboundProperty + + " ?Role . " + + "?Role core:roleIn ?Grant ." + + "?Grant core:dateTimeInterval ?dateTimeIntervalValueForGrant . " + + "?dateTimeIntervalValueForGrant core:end ?endDateForGrant . " + + "?endDateForGrant core:dateTime ?endDateTimeValueForGrant . " + + "}" + "}"; + return sparqlQuery; - } - + } + private Model executeQuery(Set constructQueries, Dataset Dataset) { - - Model constructedModel = ModelFactory.createDefaultModel(); + Model constructedModel = ModelFactory.createDefaultModel(); - for (String queryString : constructQueries) { - - before = System.currentTimeMillis(); + for (String queryString : constructQueries) { - log.debug("CONSTRUCT query string : " + queryString); - - Query query = null; - - try{ - query = QueryFactory.create(QueryConstants.getSparqlPrefixQuery() + queryString, SYNTAX); - }catch(Throwable th){ - log.error("Could not create CONSTRUCT SPARQL query for query " + - "string. " + th.getMessage()); - log.error(queryString); - } - - QueryExecution qe = QueryExecutionFactory.create( - query, Dataset); - try { - qe.execConstruct(constructedModel); - } finally { - qe.close(); - } - - after = System.currentTimeMillis(); - log.debug("Time taken to execute the CONSTRUCT query is in milliseconds: " + (after - before) ); + before = System.currentTimeMillis(); - } + log.debug("CONSTRUCT query string : " + queryString); + + Query query = null; + + try { + query = QueryFactory.create( + QueryConstants.getSparqlPrefixQuery() + queryString, + SYNTAX); + } catch (Throwable th) { + log.error("Could not create CONSTRUCT SPARQL query for query " + + "string. " + th.getMessage()); + log.error(queryString); + } + + QueryExecution qe = QueryExecutionFactory.create(query, Dataset); + try { + qe.execConstruct(constructedModel); + } finally { + qe.close(); + } + + after = System.currentTimeMillis(); + log.debug("Time taken to execute the CONSTRUCT query is in milliseconds: " + + (after - before)); + + } return constructedModel; - } - - public Model getConstructedModel() - throws MalformedQueryParametersException { + } + + public Model getConstructedModel() throws MalformedQueryParametersException { + + if (StringUtils.isNotBlank(this.egoURI)) { + /* + * To test for the validity of the URI submitted. + */ + IRIFactory iRIFactory = IRIFactory.jenaImplementation(); + IRI iri = iRIFactory.create(this.egoURI); + if (iri.hasViolation(false)) { + String errorMsg = ((Violation) iri.violations(false).next()) + .getShortMessage(); + log.error("Ego Co-PI Vis Query " + errorMsg); + throw new MalformedQueryParametersException( + "URI provided for an individual is malformed."); + } + } else { + throw new MalformedQueryParametersException( + "URI parameter is either null or empty."); + } + + Set constructQueries = new HashSet(); + + populateConstructQueries(constructQueries); + + Model model = executeQuery(constructQueries, this.Dataset); + + return model; - if (StringUtils.isNotBlank(this.egoURI)) { - /* - * To test for the validity of the URI submitted. - * */ - IRIFactory iRIFactory = IRIFactory.jenaImplementation(); - IRI iri = iRIFactory.create(this.egoURI); - if (iri.hasViolation(false)) { - String errorMsg = ((Violation) iri.violations(false).next()).getShortMessage(); - log.error("Ego Co-PI Vis Query " + errorMsg); - throw new MalformedQueryParametersException( - "URI provided for an individual is malformed."); - } - } else { - throw new MalformedQueryParametersException("URI parameter is either null or empty."); - } - - Set constructQueries = new HashSet(); - - populateConstructQueries(constructQueries); - - Model model = executeQuery(constructQueries, - this.Dataset); - - return model; - } private void populateConstructQueries(Set constructQueries) { - - constructQueries.add(generateConstructQueryForInvestigatorLabel(this.egoURI)); - constructQueries.add(generateConstructQueryForInvestigatorRoleOfProperty(this.egoURI, "core:hasInvestigatorRole")); - constructQueries.add(generateConstructQueryForCoPrincipalInvestigatorRoleOfProperty(this.egoURI, "core:hasInvestigatorRole")); - constructQueries.add(generateConstructQueryForPrincipalInvestigatorRoleOfProperty(this.egoURI, "core:hasInvestigatorRole")); - constructQueries.add(generateConstructQueryForDateTimeValueofRole(this.egoURI, "core:hasInvestigatorRole")); - constructQueries.add(generateConstructQueryForDateTimeValueofGrant(this.egoURI, "core:hasInvestigatorRole")); - - constructQueries.add(generateConstructQueryForInvestigatorRoleOfProperty(this.egoURI, "core:hasPrincipalInvestigatorRole")); - constructQueries.add(generateConstructQueryForCoPrincipalInvestigatorRoleOfProperty(this.egoURI, "core:hasPrincipalInvestigatorRole")); - constructQueries.add(generateConstructQueryForPrincipalInvestigatorRoleOfProperty(this.egoURI, "core:hasPrincipalInvestigatorRole")); - constructQueries.add(generateConstructQueryForDateTimeValueofRole(this.egoURI, "core:hasPrincipalInvestigatorRole")); - constructQueries.add(generateConstructQueryForDateTimeValueofGrant(this.egoURI, "core:hasPrincipalInvestigatorRole")); - constructQueries.add(generateConstructQueryForInvestigatorRoleOfProperty(this.egoURI, "core:hasCo-PrincipalInvestigatorRole")); - constructQueries.add(generateConstructQueryForCoPrincipalInvestigatorRoleOfProperty(this.egoURI, "core:hasCo-PrincipalInvestigatorRole")); - constructQueries.add(generateConstructQueryForPrincipalInvestigatorRoleOfProperty(this.egoURI, "core:hasCo-PrincipalInvestigatorRole")); - constructQueries.add(generateConstructQueryForDateTimeValueofRole(this.egoURI, "core:hasCo-PrincipalInvestigatorRole")); - constructQueries.add(generateConstructQueryForDateTimeValueofGrant(this.egoURI, "core:hasCo-PrincipalInvestigatorRole")); - - } + constructQueries + .add(generateConstructQueryForInvestigatorLabel(this.egoURI)); + constructQueries + .add(generateConstructQueryForInvestigatorRoleOfProperty( + this.egoURI, "core:hasInvestigatorRole")); + constructQueries + .add(generateConstructQueryForCoPrincipalInvestigatorRoleOfProperty( + this.egoURI, "core:hasInvestigatorRole")); + constructQueries + .add(generateConstructQueryForPrincipalInvestigatorRoleOfProperty( + this.egoURI, "core:hasInvestigatorRole")); + constructQueries.add(generateConstructQueryForDateTimeValueofRole( + this.egoURI, "core:hasInvestigatorRole")); + constructQueries.add(generateConstructQueryForDateTimeValueofGrant( + this.egoURI, "core:hasInvestigatorRole")); + + constructQueries + .add(generateConstructQueryForInvestigatorRoleOfProperty( + this.egoURI, "core:hasPrincipalInvestigatorRole")); + constructQueries + .add(generateConstructQueryForCoPrincipalInvestigatorRoleOfProperty( + this.egoURI, "core:hasPrincipalInvestigatorRole")); + constructQueries + .add(generateConstructQueryForPrincipalInvestigatorRoleOfProperty( + this.egoURI, "core:hasPrincipalInvestigatorRole")); + constructQueries.add(generateConstructQueryForDateTimeValueofRole( + this.egoURI, "core:hasPrincipalInvestigatorRole")); + constructQueries.add(generateConstructQueryForDateTimeValueofGrant( + this.egoURI, "core:hasPrincipalInvestigatorRole")); + + constructQueries + .add(generateConstructQueryForInvestigatorRoleOfProperty( + this.egoURI, "core:hasCo-PrincipalInvestigatorRole")); + constructQueries + .add(generateConstructQueryForCoPrincipalInvestigatorRoleOfProperty( + this.egoURI, "core:hasCo-PrincipalInvestigatorRole")); + constructQueries + .add(generateConstructQueryForPrincipalInvestigatorRoleOfProperty( + this.egoURI, "core:hasCo-PrincipalInvestigatorRole")); + constructQueries.add(generateConstructQueryForDateTimeValueofRole( + this.egoURI, "core:hasCo-PrincipalInvestigatorRole")); + constructQueries.add(generateConstructQueryForDateTimeValueofGrant( + this.egoURI, "core:hasCo-PrincipalInvestigatorRole")); + + } } \ No newline at end of file diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/coprincipalinvestigator/CoPIGrantCountRequestHandler.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/coprincipalinvestigator/CoPIGrantCountRequestHandler.java index 7246d9cf..8c1b005b 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/coprincipalinvestigator/CoPIGrantCountRequestHandler.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/coprincipalinvestigator/CoPIGrantCountRequestHandler.java @@ -13,15 +13,14 @@ import org.apache.commons.logging.Log; import com.hp.hpl.jena.query.Dataset; import com.hp.hpl.jena.rdf.model.Model; -import edu.cornell.mannlib.vitro.webapp.beans.Portal; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; 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.visualization.freemarker.DataVisualizationController; import edu.cornell.mannlib.vitro.webapp.controller.visualization.freemarker.VisualizationFrameworkConstants; import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException; import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.collaborationutils.CollaborationData; import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.valueobjects.Collaborator; +import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.ModelConstructor; import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.QueryRunner; import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.UtilityFunctions; import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.VisualizationRequestHandler; @@ -46,7 +45,7 @@ public class CoPIGrantCountRequestHandler implements VisualizationRequestHandler String egoURI = vitroRequest.getParameter(VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY); String visMode = vitroRequest.getParameter(VisualizationFrameworkConstants.VIS_MODE_KEY); - CoPIGrantCountConstructQueryRunner constructQueryRunner = new CoPIGrantCountConstructQueryRunner(egoURI, Dataset, log); + ModelConstructor constructQueryRunner = new CoPIGrantCountConstructQueryRunner(egoURI, Dataset, log); Model constructedModel = constructQueryRunner.getConstructedModel(); QueryRunner queryManager = new CoPIGrantCountQueryRunner(egoURI, constructedModel, log); @@ -104,51 +103,12 @@ public class CoPIGrantCountRequestHandler implements VisualizationRequestHandler } - /** - * When the page for person level visualization is requested. - * @param egoURI - * @param vitroRequest - * @param coPIVO - */ - private TemplateResponseValues prepareStandaloneResponse(String egoURI, - CollaborationData coPIVO, VitroRequest vitroRequest) { - - Portal portal = vitroRequest.getPortal(); - - String title = ""; - Map body = new HashMap(); - - - if (coPIVO.getCollaborators() != null - && coPIVO.getCollaborators().size() > 0) { - title = coPIVO.getEgoCollaborator().getCollaboratorName() + " - "; - body.put("numOfInvestigators", coPIVO.getCollaborators().size()); - - title = coPIVO.getEgoCollaborator().getCollaboratorName() + " - "; - } - - if (coPIVO.getCollaborations() != null - && coPIVO.getCollaborations().size() > 0) { - body.put("numOfCoInvestigations", coPIVO.getCollaborations().size()); - } - - String standaloneTemplate = "coInvestigation.ftl"; - - body.put("portalBean", portal); - body.put("egoURIParam", egoURI); - body.put("title", title + "Co-PI Visualization"); - - return new TemplateResponseValues(standaloneTemplate, body); - } - - private String getCoPIsListCSVContent(CollaborationData coPIData) { StringBuilder csvFileContent = new StringBuilder(); csvFileContent.append("Co-investigator, Count\n"); -// for (Entry currentEntry : coPIData.entrySet()) { for (Collaborator currNode : coPIData.getCollaborators()) { /* diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitycomparison/EntityComparisonUtilityFunctions.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitycomparison/EntityComparisonUtilityFunctions.java index 354fe6be..2410d086 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitycomparison/EntityComparisonUtilityFunctions.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitycomparison/EntityComparisonUtilityFunctions.java @@ -24,6 +24,7 @@ import edu.cornell.mannlib.vitro.webapp.visualization.constants.QueryFieldLabels import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException; import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.valueobjects.GenericQueryMap; import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.GenericQueryRunner; +import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.ModelConstructor; import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.QueryRunner; public class EntityComparisonUtilityFunctions { @@ -102,7 +103,7 @@ public class EntityComparisonUtilityFunctions { Dataset Dataset, String subjectOrganization) throws MalformedQueryParametersException { - EntitySubOrganizationTypesConstructQueryRunner constructQueryRunnerForSubOrganizationTypes = new EntitySubOrganizationTypesConstructQueryRunner(subjectOrganization, Dataset, log) ; + ModelConstructor constructQueryRunnerForSubOrganizationTypes = new EntitySubOrganizationTypesConstructQueryRunner(subjectOrganization, Dataset, log) ; Model constructedModelForSubOrganizationTypes = constructQueryRunnerForSubOrganizationTypes.getConstructedModel(); QueryRunner>> queryManagerForsubOrganisationTypes = new EntitySubOrganizationTypesQueryRunner( diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitycomparison/EntityPublicationCountConstructQueryRunner.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitycomparison/EntityPublicationCountConstructQueryRunner.java index 4a99ce63..0e287729 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitycomparison/EntityPublicationCountConstructQueryRunner.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitycomparison/EntityPublicationCountConstructQueryRunner.java @@ -22,8 +22,9 @@ import com.hp.hpl.jena.rdf.model.ModelFactory; import edu.cornell.mannlib.vitro.webapp.visualization.constants.QueryConstants; import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException; +import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.ModelConstructor; -public class EntityPublicationCountConstructQueryRunner { +public class EntityPublicationCountConstructQueryRunner implements ModelConstructor{ protected static final Syntax SYNTAX = Syntax.syntaxARQ; diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitycomparison/EntityPublicationCountRequestHandler.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitycomparison/EntityPublicationCountRequestHandler.java index aeab0877..16a74cb1 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitycomparison/EntityPublicationCountRequestHandler.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitycomparison/EntityPublicationCountRequestHandler.java @@ -12,7 +12,6 @@ import java.util.Set; import org.apache.commons.lang.StringEscapeUtils; import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import com.google.gson.Gson; import com.hp.hpl.jena.query.Dataset; @@ -29,6 +28,7 @@ import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryP import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.valueobjects.Entity; import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.valueobjects.JsonObject; import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.valueobjects.SubEntity; +import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.ModelConstructor; import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.QueryRunner; import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.UtilityFunctions; import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.VisualizationRequestHandler; @@ -36,8 +36,6 @@ import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.Visual public class EntityPublicationCountRequestHandler implements VisualizationRequestHandler { - private Log log = LogFactory.getLog(EntityPublicationCountRequestHandler.class.getName()); - @Override public ResponseValues generateStandardVisualization( VitroRequest vitroRequest, Log log, Dataset Dataset) @@ -59,7 +57,7 @@ public class EntityPublicationCountRequestHandler implements String subjectEntityURI) throws MalformedQueryParametersException { - EntityPublicationCountConstructQueryRunner constructQueryRunner = new EntityPublicationCountConstructQueryRunner(subjectEntityURI, Dataset, log); + ModelConstructor constructQueryRunner = new EntityPublicationCountConstructQueryRunner(subjectEntityURI, Dataset, log); Model constructedModel = constructQueryRunner.getConstructedModel(); QueryRunner queryManager = new EntityPublicationCountQueryRunner( @@ -140,7 +138,7 @@ public class EntityPublicationCountRequestHandler implements * This provides csv download files for the content in the tables. * */ - EntityPublicationCountConstructQueryRunner constructQueryRunner = new EntityPublicationCountConstructQueryRunner(entityURI, Dataset, log); + ModelConstructor constructQueryRunner = new EntityPublicationCountConstructQueryRunner(entityURI, Dataset, log); Model constructedModel = constructQueryRunner.getConstructedModel(); QueryRunner queryManager = new EntityPublicationCountQueryRunner( @@ -232,33 +230,6 @@ public class EntityPublicationCountRequestHandler implements return new TemplateResponseValues(standaloneTemplate, body); } - - /** - * @deprecated This method should not be called anymore although the templates being - * called by this method are still in use, so we should not get rid of it. - * @param vitroRequest - * @param entityURI - * @return - */ - private ResponseValues prepareStandaloneErrorResponse( - VitroRequest vitroRequest, String entityURI) { - - Portal portal = vitroRequest.getPortal(); - String standaloneTemplate = "entityPublicationComparisonError.ftl"; - Map body = new HashMap(); - - String organizationLabel = EntityComparisonUtilityFunctions.getEntityLabelFromDAO(vitroRequest, - entityURI); - - body.put("organizationLabel", organizationLabel); - body.put("portalBean", portal); - body.put("title", organizationLabel + " - Temporal Graph Visualization"); - body.put("organizationURI", entityURI); - - return new TemplateResponseValues(standaloneTemplate, body); - - } - /** * function to generate a json file for year <-> publication count mapping * @param vreq diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitycomparison/EntitySubOrganizationTypesConstructQueryRunner.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitycomparison/EntitySubOrganizationTypesConstructQueryRunner.java index 2225f030..de596ae6 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitycomparison/EntitySubOrganizationTypesConstructQueryRunner.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitycomparison/EntitySubOrganizationTypesConstructQueryRunner.java @@ -1,7 +1,6 @@ /* $This file is distributed under the terms of the license in /doc/license.txt$ */ package edu.cornell.mannlib.vitro.webapp.visualization.freemarker.entitycomparison; -import java.util.HashSet; import java.util.LinkedHashSet; import java.util.Set; @@ -23,8 +22,9 @@ import com.hp.hpl.jena.rdf.model.ModelFactory; import edu.cornell.mannlib.vitro.webapp.visualization.constants.QueryConstants; import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException; +import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.ModelConstructor; -public class EntitySubOrganizationTypesConstructQueryRunner { +public class EntitySubOrganizationTypesConstructQueryRunner implements ModelConstructor { protected static final Syntax SYNTAX = Syntax.syntaxARQ; diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitygrantcount/EntityGrantCountConstructQueryRunner.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitygrantcount/EntityGrantCountConstructQueryRunner.java index 78c49365..8faee5d8 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitygrantcount/EntityGrantCountConstructQueryRunner.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitygrantcount/EntityGrantCountConstructQueryRunner.java @@ -23,8 +23,9 @@ import com.hp.hpl.jena.rdf.model.ModelFactory; import edu.cornell.mannlib.vitro.webapp.visualization.constants.QueryConstants; import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException; +import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.ModelConstructor; -public class EntityGrantCountConstructQueryRunner { +public class EntityGrantCountConstructQueryRunner implements ModelConstructor { protected static final Syntax SYNTAX = Syntax.syntaxARQ; diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitygrantcount/EntityGrantCountRequestHandler.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitygrantcount/EntityGrantCountRequestHandler.java index dcf6cb21..9a4656d1 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitygrantcount/EntityGrantCountRequestHandler.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitygrantcount/EntityGrantCountRequestHandler.java @@ -12,7 +12,6 @@ import java.util.Set; import org.apache.commons.lang.StringEscapeUtils; import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import com.google.gson.Gson; import com.hp.hpl.jena.query.Dataset; @@ -30,6 +29,7 @@ import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.entitycompariso import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.valueobjects.Entity; import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.valueobjects.JsonObject; import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.valueobjects.SubEntity; +import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.ModelConstructor; import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.QueryRunner; import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.UtilityFunctions; import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.VisualizationRequestHandler; @@ -38,8 +38,6 @@ import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.Visual public class EntityGrantCountRequestHandler implements VisualizationRequestHandler { - private Log log = LogFactory.getLog(EntityGrantCountRequestHandler.class.getName()); - @Override public ResponseValues generateStandardVisualization( VitroRequest vitroRequest, Log log, Dataset Dataset) @@ -66,7 +64,7 @@ public class EntityGrantCountRequestHandler implements .getParameter(VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY); /* - * This will provide the data in json format mainly used for standalone tmeporal vis. + * This will provide the data in json format mainly used for standalone temporal vis. * */ if (VisualizationFrameworkConstants.TEMPORAL_GRAPH_JSON_DATA_VIS_MODE .equalsIgnoreCase(vitroRequest.getParameter(VisualizationFrameworkConstants.VIS_MODE_KEY))) { @@ -95,7 +93,7 @@ public class EntityGrantCountRequestHandler implements * This provides csv download files for the content in the tables. * */ - EntityGrantCountConstructQueryRunner constructQueryRunner = new EntityGrantCountConstructQueryRunner(entityURI, Dataset, log); + ModelConstructor constructQueryRunner = new EntityGrantCountConstructQueryRunner(entityURI, Dataset, log); Model constructedModel = constructQueryRunner.getConstructedModel(); QueryRunner queryManager = new EntityGrantCountQueryRunner( @@ -124,7 +122,7 @@ public class EntityGrantCountRequestHandler implements String subjectEntityURI) throws MalformedQueryParametersException { - EntityGrantCountConstructQueryRunner constructQueryRunner = new EntityGrantCountConstructQueryRunner(subjectEntityURI, Dataset, log); + ModelConstructor constructQueryRunner = new EntityGrantCountConstructQueryRunner(subjectEntityURI, Dataset, log); Model constructedModel = constructQueryRunner.getConstructedModel(); QueryRunner queryManager = new EntityGrantCountQueryRunner( @@ -234,32 +232,6 @@ public class EntityGrantCountRequestHandler implements return new TemplateResponseValues(standaloneTemplate, body); } - /** - * @deprecated This method should not be called anymore although the templates being - * called by this method are still in use, so we should not get rid of it. - * @return - */ - private ResponseValues prepareStandaloneErrorResponse( - VitroRequest vitroRequest, String entityURI) { - - Portal portal = vitroRequest.getPortal(); - String standaloneTemplate = "entityGrantComparisonError.ftl"; - Map body = new HashMap(); - - String organizationLabel = EntityComparisonUtilityFunctions.getEntityLabelFromDAO(vitroRequest, - entityURI); - - body.put("organizationLabel", organizationLabel); - - - body.put("portalBean", portal); - body.put("title", organizationLabel + " - Temporal Graph Visualization"); - body.put("organizationURI", entityURI); - - return new TemplateResponseValues(standaloneTemplate, body); - } - - /** * function to generate a json file for year <-> grant count mapping * @param vreq @@ -293,8 +265,6 @@ public class EntityGrantCountRequestHandler implements yearGrantCount.add(currentGrantYear); } - // log.info("entityJson.getLabel() : " + entityJson.getLabel() + " subOrganizationTypesResult " + subOrganizationTypesResult.toString()); - entityJson.setYearToActivityCount(yearGrantCount); entityJson.getOrganizationType().addAll(subOrganizationTypesResult.get(entityJson.getLabel())); @@ -308,11 +278,9 @@ public class EntityGrantCountRequestHandler implements entityJson.setVisMode("ORGANIZATION"); } -// setEntityVisMode(entityJson); subEntitiesJson.add(entityJson); } - // System.out.println("\nStopWords are "+ EntitySubOrganizationTypesQueryRunner.stopWords.toString() + "\n"); return json.toJson(subEntitiesJson); } diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/persongrantcount/PersonGrantCountConstructQueryRunner.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/persongrantcount/PersonGrantCountConstructQueryRunner.java deleted file mode 100644 index cfa3da61..00000000 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/persongrantcount/PersonGrantCountConstructQueryRunner.java +++ /dev/null @@ -1,213 +0,0 @@ -/* $This file is distributed under the terms of the license in /doc/license.txt$ */ - -package edu.cornell.mannlib.vitro.webapp.visualization.freemarker.persongrantcount; - -import java.util.HashSet; -import java.util.Set; - -import org.apache.commons.lang.StringUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import com.hp.hpl.jena.iri.IRI; -import com.hp.hpl.jena.iri.IRIFactory; -import com.hp.hpl.jena.iri.Violation; -import com.hp.hpl.jena.query.Dataset; -import com.hp.hpl.jena.query.Query; -import com.hp.hpl.jena.query.QueryExecution; -import com.hp.hpl.jena.query.QueryExecutionFactory; -import com.hp.hpl.jena.query.QueryFactory; -import com.hp.hpl.jena.query.Syntax; -import com.hp.hpl.jena.rdf.model.Model; -import com.hp.hpl.jena.rdf.model.ModelFactory; - -import edu.cornell.mannlib.vitro.webapp.visualization.constants.QueryConstants; -import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException; - -public class PersonGrantCountConstructQueryRunner { - - protected static final Syntax SYNTAX = Syntax.syntaxARQ; - - private String egoURI; - - private Dataset Dataset; - - private Log log = LogFactory.getLog(PersonGrantCountConstructQueryRunner.class.getName()); - - public PersonGrantCountConstructQueryRunner(String egoURI, Dataset Dataset, Log log){ - this.egoURI = egoURI; - this.Dataset = Dataset; - //this.log = log; - } - - private String generateConstructQueryForInvestigatorLabel(String queryURI) { - - String sparqlQuery = - "CONSTRUCT { " - + "<"+queryURI+ "> rdfs:label ?investigatorLabel ." - + "}" - + "WHERE {" - + "<"+queryURI+ "> rdfs:label ?investigatorLabel " - + "}"; - - return sparqlQuery; - } - - private String generateConstructQueryForInvestigatorGrants(String queryURI, String preboundProperty){ - - String sparqlQuery = "" - + "CONSTRUCT { " - + "<"+queryURI+ ">" + preboundProperty + " ?Role . " - + "?Role core:roleIn ?Grant ." - + "?Grant rdfs:label ?GrantLabel " - + "} " - + "WHERE { " - + "<"+queryURI+ ">" + preboundProperty + " ?Role . " - + "?Role core:roleIn ?Grant ." - + "?Grant rdfs:label ?GrantLabel " - + "} "; - - return sparqlQuery; - - } - - private String generateConstructQueryForDateTimeValueofRole(String queryURI, String preboundProperty){ - - String sparqlQuery = - "CONSTRUCT { " - + "<"+queryURI+ ">" + preboundProperty + " ?Role . " - + "?Role core:dateTimeInterval ?dateTimeIntervalValue . " - + "?dateTimeIntervalValue core:start ?startDate . " - + "?startDate core:dateTime ?startDateTimeValue . " - + "?dateTimeIntervalValue core:end ?endDate . " - + "?endDate core:dateTime ?endDateTimeValue . " - + "}" - + "WHERE { " - + "{" - + "<"+queryURI+ ">" + preboundProperty + " ?Role . " - + "?Role core:dateTimeInterval ?dateTimeIntervalValue . " - + "?dateTimeIntervalValue core:start ?startDate . " - + "?startDate core:dateTime ?startDateTimeValue . " - + "} UNION " - + "{" - + "<"+queryURI+ ">" + preboundProperty + " ?Role . " - + "?Role core:dateTimeInterval ?dateTimeIntervalValue . " - + "?dateTimeIntervalValue core:end ?endDate . " - + "?endDate core:dateTime ?endDateTimeValue . " - + "}" - + "}"; - - return sparqlQuery; - } - - private String generateConstructQueryForDateTimeValueofGrant(String queryURI, String preboundProperty){ - - String sparqlQuery = - "CONSTRUCT { " - + "<"+queryURI+ ">" + preboundProperty + " ?Role . " - + "?Role core:roleIn ?Grant ." - + "?Grant core:dateTimeInterval ?dateTimeIntervalValueForGrant . " - + "?dateTimeIntervalValueForGrant core:start ?startDateForGrant . " - + "?startDateForGrant core:dateTime ?startDateTimeValueForGrant . " - + "?dateTimeIntervalValueForGrant core:end ?endDateForGrant . " - + "?endDateForGrant core:dateTime ?endDateTimeValueForGrant . " - + "}" - + "WHERE { " - + "{" - + "<"+queryURI+ ">" + preboundProperty + " ?Role . " - + "?Role core:roleIn ?Grant ." - + "?Grant core:dateTimeInterval ?dateTimeIntervalValueForGrant . " - + "?dateTimeIntervalValueForGrant core:start ?startDateForGrant . " - + "?startDateForGrant core:dateTime ?startDateTimeValueForGrant . " - + "} UNION " - + "{" - + "<"+queryURI+ ">" + preboundProperty + " ?Role . " - + "?Role core:roleIn ?Grant ." - + "?Grant core:dateTimeInterval ?dateTimeIntervalValueForGrant . " - + "?dateTimeIntervalValueForGrant core:end ?endDateForGrant . " - + "?endDateForGrant core:dateTime ?endDateTimeValueForGrant . " - + "}" - + "}"; - - return sparqlQuery; - } - - private Model executeQuery(Set constructQueries, Dataset Dataset) { - - Model constructedModel = ModelFactory.createDefaultModel(); - - for (String queryString : constructQueries) { - long start = System.currentTimeMillis(); - log.debug("CONSTRUCT query string : " + queryString); - - Query query = null; - - try{ - query = QueryFactory.create(QueryConstants.getSparqlPrefixQuery() + queryString, SYNTAX); - }catch(Throwable th){ - log.error("Could not create CONSTRUCT SPARQL query for query " + - "string. " + th.getMessage()); - log.error(queryString); - } - - QueryExecution qe = QueryExecutionFactory.create( - query, Dataset); - try { - qe.execConstruct(constructedModel); - } finally { - qe.close(); - } - log.debug("time to run construct: " + (System.currentTimeMillis() - start)); - } - - return constructedModel; - } - - public Model getConstructedModel() - throws MalformedQueryParametersException { - - if (StringUtils.isNotBlank(this.egoURI)) { - /* - * To test for the validity of the URI submitted. - * */ - IRIFactory iRIFactory = IRIFactory.jenaImplementation(); - IRI iri = iRIFactory.create(this.egoURI); - if (iri.hasViolation(false)) { - String errorMsg = ((Violation) iri.violations(false).next()).getShortMessage(); - log.error("Person Grant Count Construct Query " + errorMsg); - throw new MalformedQueryParametersException( - "URI provided for an individual is malformed."); - } - } else { - throw new MalformedQueryParametersException("URI parameter is either null or empty."); - } - - Set constructQueries = new HashSet(); - - populateConstructQueries(constructQueries); - - Model model = executeQuery(constructQueries, - this.Dataset); - - return model; - - } - - private void populateConstructQueries(Set constructQueries) { - - constructQueries.add(generateConstructQueryForInvestigatorLabel(this.egoURI)); - - constructQueries.add(generateConstructQueryForInvestigatorGrants(this.egoURI, " core:hasInvestigatorRole ")); - constructQueries.add(generateConstructQueryForDateTimeValueofRole(this.egoURI, " core:hasInvestigatorRole ")); - constructQueries.add(generateConstructQueryForDateTimeValueofGrant(this.egoURI, " core:hasInvestigatorRole ")); - - constructQueries.add(generateConstructQueryForInvestigatorGrants(this.egoURI, " core:hasPrincipalInvestigatorRole ")); - constructQueries.add(generateConstructQueryForDateTimeValueofRole(this.egoURI, " core:hasPrincipalInvestigatorRole ")); - constructQueries.add(generateConstructQueryForDateTimeValueofGrant(this.egoURI, " core:hasPrincipalInvestigatorRole ")); - - constructQueries.add(generateConstructQueryForInvestigatorGrants(this.egoURI, " core:hasCo-PrincipalInvestigatorRole ")); - constructQueries.add(generateConstructQueryForDateTimeValueofRole(this.egoURI, " core:hasCo-PrincipalInvestigatorRole ")); - constructQueries.add(generateConstructQueryForDateTimeValueofGrant(this.egoURI, " core:hasCo-PrincipalInvestigatorRole ")); - } - -} \ No newline at end of file diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/personlevel/PersonLevelRequestHandler.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/personlevel/PersonLevelRequestHandler.java index 977db3a0..14c4e7af 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/personlevel/PersonLevelRequestHandler.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/personlevel/PersonLevelRequestHandler.java @@ -29,6 +29,7 @@ import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.personpubcount. import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.personpubcount.PersonPublicationCountVisCodeGenerator; import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.valueobjects.Activity; import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.valueobjects.SparklineData; +import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.ModelConstructor; import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.QueryRunner; import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.UtilityFunctions; import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.VisualizationRequestHandler; @@ -80,7 +81,7 @@ public class PersonLevelRequestHandler implements VisualizationRequestHandler { if (VisualizationFrameworkConstants.COPI_VIS_MODE.equalsIgnoreCase(visMode)){ - CoPIGrantCountConstructQueryRunner constructQueryRunner = new CoPIGrantCountConstructQueryRunner(egoURI, Dataset, log); + ModelConstructor constructQueryRunner = new CoPIGrantCountConstructQueryRunner(egoURI, Dataset, log); Model constructedModel = constructQueryRunner.getConstructedModel(); QueryRunner coPIQueryManager = new CoPIGrantCountQueryRunner(egoURI, constructedModel, log); diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/personpubcount/PersonPublicationCountRequestHandler.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/personpubcount/PersonPublicationCountRequestHandler.java index 35a09aac..cae4fe9c 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/personpubcount/PersonPublicationCountRequestHandler.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/personpubcount/PersonPublicationCountRequestHandler.java @@ -45,7 +45,7 @@ VisualizationRequestHandler { @Override public Object generateAjaxVisualization(VitroRequest vitroRequest, Log log, - Dataset Dataset) throws MalformedQueryParametersException { + Dataset dataset) throws MalformedQueryParametersException { String personURI = vitroRequest .getParameter( @@ -61,7 +61,7 @@ VisualizationRequestHandler { QueryRunner> queryManager = new PersonPublicationCountQueryRunner( personURI, - Dataset, + dataset, log); Set authorDocuments = queryManager.getQueryResult(); @@ -97,14 +97,14 @@ VisualizationRequestHandler { @Override public Map generateDataVisualization(VitroRequest vitroRequest, Log log, - Dataset Dataset) throws MalformedQueryParametersException { + Dataset dataset) throws MalformedQueryParametersException { String personURI = vitroRequest .getParameter(VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY); QueryRunner> queryManager = new PersonPublicationCountQueryRunner( personURI, - Dataset, + dataset, log); Set authorDocuments = queryManager.getQueryResult(); diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/visutils/ModelConstructor.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/visutils/ModelConstructor.java new file mode 100644 index 00000000..5306ca78 --- /dev/null +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/visutils/ModelConstructor.java @@ -0,0 +1,13 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + +package edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils; + +import com.hp.hpl.jena.rdf.model.Model; + +import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException; + +public interface ModelConstructor { + + Model getConstructedModel() throws MalformedQueryParametersException; + +} diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/visutils/VisualizationRequestHandler.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/visutils/VisualizationRequestHandler.java index dd387299..ffe92245 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/visutils/VisualizationRequestHandler.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/visutils/VisualizationRequestHandler.java @@ -5,7 +5,6 @@ import java.util.Map; import org.apache.commons.logging.Log; -import com.hp.hpl.jena.query.DataSource; import com.hp.hpl.jena.query.Dataset; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; @@ -22,7 +21,7 @@ import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryP * * @author cdtank */ -public interface VisualizationRequestHandler{ +public interface VisualizationRequestHandler { ResponseValues generateStandardVisualization(VitroRequest vitroRequest, Log log, @@ -34,6 +33,6 @@ public interface VisualizationRequestHandler{ Map generateDataVisualization(VitroRequest vitroRequest, Log log, - Dataset dataSource) throws MalformedQueryParametersException; + Dataset dataset) throws MalformedQueryParametersException; }