From 4299483b817bf76004dbb517188ef74ae24fb308 Mon Sep 17 00:00:00 2001 From: bkoniden Date: Tue, 8 Feb 2011 21:44:17 +0000 Subject: [PATCH] NIHVIVO- 1993 Testing CONSTRUCT + SELECT for CoPIGrantCount, EntityPubCount, EntityGrantCount and EntitySubOrganizationTypesCount. --- .../CoPIGrantCountConstructQueryRunner.java | 252 +++++++++++++ .../CoPIGrantCountQueryRunner.java | 7 +- .../CoPIGrantCountRequestHandler.java | 6 +- .../EntityComparisonUtilityFunctions.java | 12 +- ...yPublicationCountConstructQueryRunner.java | 258 +++++++++++++ .../EntityPublicationCountQueryRunner.java | 29 +- .../EntityPublicationCountRequestHandler.java | 17 +- ...OrganizationTypesConstructQueryRunner.java | 178 +++++++++ ...EntitySubOrganizationTypesQueryRunner.java | 26 +- .../EntityGrantCountConstructQueryRunner.java | 342 ++++++++++++++++++ .../EntityGrantCountQueryRunner.java | 53 ++- .../EntityGrantCountRequestHandler.java | 16 +- .../PersonLevelRequestHandler.java | 11 +- 13 files changed, 1133 insertions(+), 74 deletions(-) create mode 100644 src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/coprincipalinvestigator/CoPIGrantCountConstructQueryRunner.java create mode 100644 src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitycomparison/EntityPublicationCountConstructQueryRunner.java create mode 100644 src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitycomparison/EntitySubOrganizationTypesConstructQueryRunner.java create mode 100644 src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitygrantcount/EntityGrantCountConstructQueryRunner.java 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 new file mode 100644 index 00000000..210dc91e --- /dev/null +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/coprincipalinvestigator/CoPIGrantCountConstructQueryRunner.java @@ -0,0 +1,252 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ +package edu.cornell.mannlib.vitro.webapp.visualization.freemarker.coprincipalinvestigator; + +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.DataSource; +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 CoPIGrantCountConstructQueryRunner { + + protected static final Syntax SYNTAX = Syntax.syntaxARQ; + + private String egoURI; + + private DataSource dataSource; + + 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, DataSource dataSource, Log log){ + this.egoURI = egoURI; + this.dataSource = dataSource; + //this.log = log; + } + + private String generateConstructQueryForInvestigatorLabel(String queryURI) { + + String sparqlQuery = + "CONSTRUCT { " + + "<"+queryURI+ "> rdfs:label ?investigatorLabel ." + + "}" + + "WHERE {" + + "<"+queryURI+ "> rdfs:label ?investigatorLabel " + + "}"; + + return sparqlQuery; + } + + private String generateConstructQueryForInvestigatorRoleOfProperty(String queryURI){ + + 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 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 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 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 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, DataSource dataSource) { + + Model constructedModel = ModelFactory.createDefaultModel(); + + 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, dataSource); + try { + qe.execConstruct(constructedModel); + } finally { + qe.close(); + } + + } + + 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("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.dataSource); + + return model; + + } + + private void populateConstructQueries(Set constructQueries) { + + constructQueries.add(generateConstructQueryForInvestigatorLabel(this.egoURI)); + constructQueries.add(generateConstructQueryForInvestigatorRoleOfProperty(this.egoURI)); + constructQueries.add(generateConstructQueryForCoPrincipalInvestigatorRoleOfProperty(this.egoURI)); + constructQueries.add(generateConstructQueryForPrincipalInvestigatorRoleOfProperty(this.egoURI)); + constructQueries.add(generateConstructQueryForDateTimeValueofRole(this.egoURI)); + constructQueries.add(generateConstructQueryForDateTimeValueofGrant(this.egoURI)); + + + } +} \ No newline at end of file diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/coprincipalinvestigator/CoPIGrantCountQueryRunner.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/coprincipalinvestigator/CoPIGrantCountQueryRunner.java index 8fb49116..f7991250 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/coprincipalinvestigator/CoPIGrantCountQueryRunner.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/coprincipalinvestigator/CoPIGrantCountQueryRunner.java @@ -24,6 +24,7 @@ import com.hp.hpl.jena.query.QueryFactory; import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.ResultSet; import com.hp.hpl.jena.query.Syntax; +import com.hp.hpl.jena.rdf.model.Model; import com.hp.hpl.jena.rdf.model.RDFNode; import edu.cornell.mannlib.vitro.webapp.visualization.constants.QueryConstants; @@ -47,7 +48,7 @@ public class CoPIGrantCountQueryRunner implements QueryRunner { private String egoURI; - private DataSource dataSource; + private Model dataSource; private Log log; @@ -79,7 +80,7 @@ public class CoPIGrantCountQueryRunner implements QueryRunner { public CoPIGrantCountQueryRunner(String egoURI, - DataSource dataSource, Log log) { + Model dataSource, Log log) { this.egoURI = egoURI; this.dataSource = dataSource; @@ -322,7 +323,7 @@ public class CoPIGrantCountQueryRunner implements QueryRunner { } - private ResultSet executeQuery(String queryText, DataSource dataSource) { + private ResultSet executeQuery(String queryText, Model dataSource) { QueryExecution queryExecution = null; Query query = QueryFactory.create(queryText, SYNTAX); 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 fa6b6422..5b941427 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 @@ -12,6 +12,7 @@ import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import com.hp.hpl.jena.query.DataSource; +import com.hp.hpl.jena.rdf.model.Model; import edu.cornell.mannlib.vitro.webapp.beans.Portal; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; @@ -46,7 +47,10 @@ public class CoPIGrantCountRequestHandler implements VisualizationRequestHandler String egoURI = vitroRequest.getParameter(VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY); String visMode = vitroRequest.getParameter(VisualizationFrameworkConstants.VIS_MODE_KEY); - QueryRunner queryManager = new CoPIGrantCountQueryRunner(egoURI, dataSource, log); + CoPIGrantCountConstructQueryRunner constructQueryRunner = new CoPIGrantCountConstructQueryRunner(egoURI, dataSource, log); + Model constructedModel = constructQueryRunner.getConstructedModel(); + + QueryRunner queryManager = new CoPIGrantCountQueryRunner(egoURI, constructedModel, log); CoPIData PINodesAndEdges = queryManager.getQueryResult(); 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 494a9f3e..aa753a06 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 @@ -10,6 +10,7 @@ import org.apache.commons.logging.Log; import com.hp.hpl.jena.query.DataSource; import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.ResultSet; +import com.hp.hpl.jena.rdf.model.Model; import com.hp.hpl.jena.rdf.model.RDFNode; import edu.cornell.mannlib.vitro.webapp.visualization.constants.QueryFieldLabels; @@ -93,11 +94,16 @@ public class EntityComparisonUtilityFunctions { public static Map> getSubEntityTypes(Log log, DataSource dataSource, String subjectOrganization) throws MalformedQueryParametersException { - QueryRunner>> queryManagerForsubOrganisationTypes = new EntitySubOrganizationTypesQueryRunner( - subjectOrganization, dataSource, log); + EntitySubOrganizationTypesConstructQueryRunner constructQueryRunnerForSubOrganizationTypes = new EntitySubOrganizationTypesConstructQueryRunner(subjectOrganization, dataSource, log) ; + Model constructedModelForSubOrganizationTypes = constructQueryRunnerForSubOrganizationTypes.getConstructedModel(); + + QueryRunner>> queryManagerForsubOrganisationTypes = new EntitySubOrganizationTypesQueryRunner( + subjectOrganization, constructedModelForSubOrganizationTypes, log); + Map> subOrganizationTypesResult = queryManagerForsubOrganisationTypes - .getQueryResult(); + .getQueryResult(); + return subOrganizationTypesResult; } 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 new file mode 100644 index 00000000..a1f3b486 --- /dev/null +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitycomparison/EntityPublicationCountConstructQueryRunner.java @@ -0,0 +1,258 @@ +/* $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.LinkedHashSet; +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.DataSource; +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 EntityPublicationCountConstructQueryRunner { + + protected static final Syntax SYNTAX = Syntax.syntaxARQ; + + private String egoURI; + + private DataSource dataSource; + + private Log log = LogFactory.getLog(EntityPublicationCountConstructQueryRunner.class.getName()); + + public EntityPublicationCountConstructQueryRunner(String egoURI, DataSource dataSource, Log log){ + this.egoURI = egoURI; + this.dataSource = dataSource; + //this.log = log; + } + + private String generateConstructQueryForOrganizationLabel(String queryURI) { + + String sparqlQuery = + "CONSTRUCT { " + + "<"+queryURI+ "> rdfs:label ?organizationLabel ." + + "}" + + "WHERE {" + + "<"+queryURI+ "> rdfs:label ?organizationLabel " + + "}"; + + return sparqlQuery; + } + + private String generateConstructQueryForSubOrganizations(String queryURI){ + + String sparqlQuery = + + "CONSTRUCT { " + + "<"+queryURI+ "> core:hasSubOrganization ?subOrganization . " + + "?subOrganization rdfs:label ?subOrganizationLabel . " + + "?subOrganization core:organizationForPosition ?Position . " + + "?Position core:positionForPerson ?Person . " + + "?Person core:authorInAuthorship ?Resource . " + + "?Person rdfs:label ?PersonLabel . " + + "?Resource core:linkedInformationResource ?Document . " + + "?Document rdf:type bibo:Document . " + + "?Document rdfs:label ?DocumentLabel " + +"}" + + "WHERE { " + + "<"+queryURI+ "> core:hasSubOrganization ?subOrganization . " + + "?subOrganization rdfs:label ?subOrganizationLabel . " + + "?subOrganization core:organizationForPosition ?Position . " + + "?Position core:positionForPerson ?Person . " + + "?Person core:authorInAuthorship ?Resource . " + + "?Person rdfs:label ?PersonLabel . " + + "?Resource core:linkedInformationResource ?Document . " + + "?Document rdf:type bibo:Document . " + + "?Document rdfs:label ?DocumentLabel " + + "}" ; + + + return sparqlQuery; + + } + + private String generateConstructQueryForPersons(String queryURI){ + + String sparqlQuery = + + "CONSTRUCT { " + + "<"+queryURI+ "> core:organizationForPosition ?Position . " + + "?Position core:positionForPerson ?Person . " + + "?Person core:authorInAuthorship ?Resource . " + + "?Person rdfs:label ?PersonLabel . " + + "?Resource core:linkedInformationResource ?Document . " + + "?Document rdf:type bibo:Document . " + + "?Document rdfs:label ?DocumentLabel " + +"}" + + "WHERE { " + + "<"+queryURI+ "> core:organizationForPosition ?Position . " + + "?Position core:positionForPerson ?Person . " + + "?Person core:authorInAuthorship ?Resource . " + + "?Person rdfs:label ?PersonLabel . " + + "?Resource core:linkedInformationResource ?Document . " + + "?Document rdf:type bibo:Document . " + + "?Document rdfs:label ?DocumentLabel " + + "}" ; + + + return sparqlQuery; + + } + + private String generateConstructQueryForDocumentDateTimeValueOneLevelDeep(String queryURI){ + + String sparqlQuery = + + "CONSTRUCT { " + + "<"+queryURI+ "> core:hasSubOrganization ?subOrganization . " + + "?subOrganization core:organizationForPosition ?Position . " + + "?Position core:positionForPerson ?Person . " + + "?Person core:authorInAuthorship ?Resource . " + + "?Resource core:linkedInformationResource ?Document . " + + "?Document rdf:type bibo:Document . " + + "?Document core:dateTimeValue ?dateTimeValue . " + + "?dateTimeValue core:dateTime ?publicationDate . " + + "?Document core:year ?publicationYearUsing_1_1_property " + +"}" + + "WHERE { " + + "<"+queryURI+ "> core:hasSubOrganization ?subOrganization . " + + "?subOrganization core:organizationForPosition ?Position . " + + "?Position core:positionForPerson ?Person . " + + "?Person core:authorInAuthorship ?Resource . " + + "?Resource core:linkedInformationResource ?Document . " + + "?Document rdf:type bibo:Document . " + + "{" + + "?Document core:dateTimeValue ?dateTimeValue . " + + "?dateTimeValue core:dateTime ?publicationDate " + + "}" + + "UNION " + + "{" + + "?Document core:year ?publicationYearUsing_1_1_property " + + "}" + + "}" ; + + + return sparqlQuery; + + } + + private String generateConstructQueryForDocumentDateTimeValue(String queryURI){ + + String sparqlQuery = + + "CONSTRUCT { " + + "<"+queryURI+ "> core:organizationForPosition ?Position . " + + "?Position core:positionForPerson ?Person . " + + "?Person core:authorInAuthorship ?Resource . " + + "?Resource core:linkedInformationResource ?Document . " + + "?Document rdf:type bibo:Document . " + + "?Document core:dateTimeValue ?dateTimeValue . " + + "?dateTimeValue core:dateTime ?publicationDate . " + + "?Document core:year ?publicationYearUsing_1_1_property " + +"}" + + "WHERE { " + + "<"+queryURI+ "> core:organizationForPosition ?Position . " + + "?Position core:positionForPerson ?Person . " + + "?Person core:authorInAuthorship ?Resource . " + + "?Resource core:linkedInformationResource ?Document . " + + "?Document rdf:type bibo:Document . " + + "{" + + "?Document core:dateTimeValue ?dateTimeValue . " + + "?dateTimeValue core:dateTime ?publicationDate " + + "}" + + "UNION " + + "{" + + "?Document core:year ?publicationYearUsing_1_1_property " + + "}" + + "}" ; + + + return sparqlQuery; + + } + + private Model executeQuery(Set constructQueries, DataSource dataSource) { + + Model constructedModel = ModelFactory.createDefaultModel(); + + for (String queryString : constructQueries) { + + log.debug("CONSTRUCT query string : " + queryString); + + Query query = null; + + try{ + query = QueryFactory.create(QueryConstants.getSparqlPrefixQuery() + queryString, SYNTAX); + //log.info("query: "+ queryString); + }catch(Throwable th){ + log.error("Could not create CONSTRUCT SPARQL query for query " + + "string. " + th.getMessage()); + log.error(queryString); + } + + QueryExecution qe = QueryExecutionFactory.create( + query, dataSource); + try { + qe.execConstruct(constructedModel); + } finally { + qe.close(); + } + + } + // constructedModel.write(System.out); + 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("Entity Pub 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 LinkedHashSet(); + + populateConstructQueries(constructQueries); + + Model model = executeQuery(constructQueries, + this.dataSource); + + return model; + + } + + private void populateConstructQueries(Set constructQueries) { + + constructQueries.add(generateConstructQueryForOrganizationLabel(this.egoURI)); + constructQueries.add(generateConstructQueryForSubOrganizations(this.egoURI)); + constructQueries.add(generateConstructQueryForPersons(this.egoURI)); + constructQueries.add(generateConstructQueryForDocumentDateTimeValueOneLevelDeep(this.egoURI)); + constructQueries.add(generateConstructQueryForDocumentDateTimeValue(this.egoURI)); + + } +} diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitycomparison/EntityPublicationCountQueryRunner.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitycomparison/EntityPublicationCountQueryRunner.java index a0535307..91f7a5b6 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitycomparison/EntityPublicationCountQueryRunner.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitycomparison/EntityPublicationCountQueryRunner.java @@ -12,7 +12,6 @@ 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.DataSource; import com.hp.hpl.jena.query.Query; import com.hp.hpl.jena.query.QueryExecution; import com.hp.hpl.jena.query.QueryExecutionFactory; @@ -21,6 +20,8 @@ import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.ResultSet; import com.hp.hpl.jena.query.Syntax; import com.hp.hpl.jena.rdf.model.RDFNode; +import com.hp.hpl.jena.rdf.model.Model; + import edu.cornell.mannlib.vitro.webapp.visualization.constants.QueryConstants; import edu.cornell.mannlib.vitro.webapp.visualization.constants.QueryFieldLabels; @@ -44,18 +45,16 @@ public class EntityPublicationCountQueryRunner implements QueryRunner { protected static final Syntax SYNTAX = Syntax.syntaxARQ; private String entityURI; - private DataSource dataSource; + private Model dataSource; private Log log = LogFactory.getLog(EntityPublicationCountQueryRunner.class.getName()); private static final String SPARQL_QUERY_COMMON_SELECT_CLAUSE = "" + " (str(?Person) as ?personLit) " + " (str(?PersonLabel) as ?personLabelLit) " - + " (str(?SecondaryPositionLabel) as ?SecondaryPositionLabelLit)" + " (str(?Document) as ?documentLit) " + " (str(?DocumentLabel) as ?documentLabelLit) " + " (str(?publicationDate) as ?" + QueryFieldLabels.DOCUMENT_PUBLICATION_DATE + ") " - + " (str(?publicationYearUsing_1_1_property) as ?" + QueryFieldLabels.DOCUMENT_PUBLICATION_YEAR_USING_1_1_PROPERTY + ") " - + " (str(?StartYear) as ?StartYearLit)"; + + " (str(?publicationYearUsing_1_1_property) as ?" + QueryFieldLabels.DOCUMENT_PUBLICATION_YEAR_USING_1_1_PROPERTY + ") "; private static final String SPARQL_QUERY_COMMON_WHERE_CLAUSE = "" @@ -63,8 +62,7 @@ public class EntityPublicationCountQueryRunner implements QueryRunner { + " rdfs:label ?DocumentLabel ." + "OPTIONAL { ?Document core:dateTimeValue ?dateTimeValue . " + " ?dateTimeValue core:dateTime ?publicationDate } ." - + "OPTIONAL { ?Document core:year ?publicationYearUsing_1_1_property } ." - + "OPTIONAL { ?SecondaryPosition core:startYear ?StartYear } ."; + + "OPTIONAL { ?Document core:year ?publicationYearUsing_1_1_property } ." ; private static String ENTITY_LABEL; private static String ENTITY_URL; @@ -72,7 +70,7 @@ public class EntityPublicationCountQueryRunner implements QueryRunner { private static String SUBENTITY_URL; public EntityPublicationCountQueryRunner(String entityURI, - DataSource dataSource, Log log) { + Model dataSource, Log log) { this.entityURI = entityURI; this.dataSource = dataSource; @@ -208,7 +206,7 @@ public class EntityPublicationCountQueryRunner implements QueryRunner { return entity; } - private ResultSet executeQuery(String queryURI, DataSource dataSource) { + private ResultSet executeQuery(String queryURI, Model dataSource) { QueryExecution queryExecution = null; Query query = QueryFactory.create( @@ -240,23 +238,20 @@ public class EntityPublicationCountQueryRunner implements QueryRunner { + " (str(?subOrganizationLabel) as ?subOrganizationLabelLit) " + SPARQL_QUERY_COMMON_SELECT_CLAUSE + " (str(<" + queryURI + ">) as ?" + ENTITY_URL + ") " - + "WHERE { " + "<" + queryURI + "> rdf:type foaf:Organization ;" - + " rdfs:label ?organizationLabel ." + + "WHERE { " + "<" + queryURI + "> rdfs:label ?organizationLabel ." + "{ " + "<" + queryURI + "> core:hasSubOrganization ?subOrganization ." + "?subOrganization rdfs:label ?subOrganizationLabel ; core:organizationForPosition ?Position . " - + " ?Position rdf:type core:Position ; core:positionForPerson ?Person ." - + " ?Person core:authorInAuthorship ?Resource ; rdfs:label ?PersonLabel ; core:personInPosition ?SecondaryPosition . " + + " ?Position core:positionForPerson ?Person ." + + " ?Person core:authorInAuthorship ?Resource ; rdfs:label ?PersonLabel . " + " ?Resource core:linkedInformationResource ?Document . " - + " ?SecondaryPosition rdfs:label ?SecondaryPositionLabel ." + SPARQL_QUERY_COMMON_WHERE_CLAUSE + "}" + "UNION " + "{ " + "<" + queryURI + "> core:organizationForPosition ?Position ." - + " ?Position rdf:type core:Position ; core:positionForPerson ?Person ." - + " ?Person core:authorInAuthorship ?Resource ; rdfs:label ?PersonLabel ; core:personInPosition ?SecondaryPosition . " + + " ?Position core:positionForPerson ?Person ." + + " ?Person core:authorInAuthorship ?Resource ; rdfs:label ?PersonLabel . " + " ?Resource core:linkedInformationResource ?Document ." - + " ?SecondaryPosition rdfs:label ?SecondaryPositionLabel ." + SPARQL_QUERY_COMMON_WHERE_CLAUSE + "}" + "}"; 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 9cf5e9a9..b1f68c82 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 @@ -19,6 +19,8 @@ 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.DataSource; +import com.hp.hpl.jena.rdf.model.Model; + import edu.cornell.mannlib.vitro.webapp.ConfigurationProperties; import edu.cornell.mannlib.vitro.webapp.beans.Portal; @@ -90,17 +92,21 @@ public class EntityPublicationCountRequestHandler implements } } - - + private ResponseValues getSubjectEntityAndGenerateResponse( VitroRequest vitroRequest, Log log, DataSource dataSource, String subjectEntityURI) throws MalformedQueryParametersException { + EntityPublicationCountConstructQueryRunner constructQueryRunner = new EntityPublicationCountConstructQueryRunner(subjectEntityURI, dataSource, log); + Model constructedModel = constructQueryRunner.getConstructedModel(); + QueryRunner queryManager = new EntityPublicationCountQueryRunner( - subjectEntityURI, dataSource, log); + subjectEntityURI, constructedModel, log); + Entity entity = queryManager.getQueryResult(); + if (entity.getEntityLabel().equals("no-label")) { @@ -136,8 +142,11 @@ public class EntityPublicationCountRequestHandler implements String entityURI = vitroRequest .getParameter(VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY); + EntityPublicationCountConstructQueryRunner constructQueryRunner = new EntityPublicationCountConstructQueryRunner(entityURI, dataSource, log); + Model constructedModel = constructQueryRunner.getConstructedModel(); + QueryRunner queryManager = new EntityPublicationCountQueryRunner( - entityURI, dataSource, log); + entityURI, constructedModel, log); Entity entity = queryManager.getQueryResult(); 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 new file mode 100644 index 00000000..f50516d0 --- /dev/null +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitycomparison/EntitySubOrganizationTypesConstructQueryRunner.java @@ -0,0 +1,178 @@ +/* $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; + +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.DataSource; +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 EntitySubOrganizationTypesConstructQueryRunner { + + protected static final Syntax SYNTAX = Syntax.syntaxARQ; + + private String egoURI; + + private DataSource dataSource; + + private Log log = LogFactory.getLog(EntitySubOrganizationTypesConstructQueryRunner.class.getName()); + + public EntitySubOrganizationTypesConstructQueryRunner(String egoURI, DataSource dataSource, Log log){ + this.egoURI = egoURI; + this.dataSource = dataSource; + //this.log = log; + } + + private String generateConstructQueryForOrganizationLabel(String queryURI) { + + String sparqlQuery = + "CONSTRUCT { " + + "<"+queryURI+ "> rdfs:label ?organizationLabel ." + + "}" + + "WHERE {" + + "<"+queryURI+ "> rdfs:label ?organizationLabel " + + "}"; + return sparqlQuery; + } + + private String generateConstructQueryForSubOrganizationTypes(String queryURI){ + + String sparqlQuery = + + "CONSTRUCT { " + + "<"+queryURI+ "> core:hasSubOrganization ?subOrganization . " + + "?subOrganization rdfs:label ?subOrganizationLabel . " + + "?subOrganization rdf:type ?subOrganizationType . " + + "?subOrganization core:organizationForPosition ?Position . " + + "?subOrganizationType rdfs:label ?subOrganizationTypeLabel . " + + "?Position core:positionForPerson ?Person ." + + "?Person rdfs:label ?PersonLabel ." + + "?Person rdf:type ?PersonType . " + + "?PersonType rdfs:label ?PersonTypeLabel " + +"}" + + "WHERE { " + + "<"+queryURI+ "> core:hasSubOrganization ?subOrganization . " + + "?subOrganization rdfs:label ?subOrganizationLabel . " + + "?subOrganization rdf:type ?subOrganizationType . " + + "?subOrganization core:organizationForPosition ?Position . " + + "?subOrganizationType rdfs:label ?subOrganizationTypeLabel . " + + "?Position core:positionForPerson ?Person " + + "}" ; + + + return sparqlQuery; + + } + + private String generateConstructQueryForPersonTypes(String queryURI){ + + String sparqlQuery = + + "CONSTRUCT { " + + "<"+queryURI+ "> core:organizationForPosition ?Position . " + + "?Position core:positionForPerson ?Person ." + + "?Person rdfs:label ?PersonLabel ." + + "?Person rdf:type ?PersonType . " + + "?PersonType rdfs:label ?PersonTypeLabel " + +"}" + + "WHERE { " + + "<"+queryURI+ "> core:organizationForPosition ?Position . " + + "?Position core:positionForPerson ?Person ." + + "?Person rdfs:label ?PersonLabel ." + + "?Person rdf:type ?PersonType . " + + "?PersonType rdfs:label ?PersonTypeLabel " + + "}" ; + + + return sparqlQuery; + + } + + private Model executeQuery(Set constructQueries, DataSource dataSource) { + + Model constructedModel = ModelFactory.createDefaultModel(); + + for (String queryString : constructQueries) { + + // log.info("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, dataSource); + try { + qe.execConstruct(constructedModel); + } finally { + qe.close(); + } + + } + + 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("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 LinkedHashSet(); + + populateConstructQueries(constructQueries); + + Model model = executeQuery(constructQueries, + this.dataSource); + model.write(System.out); + return model; + + } + + private void populateConstructQueries(Set constructQueries) { + + constructQueries.add(generateConstructQueryForOrganizationLabel(this.egoURI)); + constructQueries.add(generateConstructQueryForSubOrganizationTypes(this.egoURI)); + constructQueries.add(generateConstructQueryForPersonTypes(this.egoURI)); + + + } + +} diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitycomparison/EntitySubOrganizationTypesQueryRunner.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitycomparison/EntitySubOrganizationTypesQueryRunner.java index 655664dd..bcd1b8a4 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitycomparison/EntitySubOrganizationTypesQueryRunner.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitycomparison/EntitySubOrganizationTypesQueryRunner.java @@ -20,6 +20,8 @@ import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.ResultSet; import com.hp.hpl.jena.query.Syntax; import com.hp.hpl.jena.rdf.model.RDFNode; +import com.hp.hpl.jena.rdf.model.Model; + import edu.cornell.mannlib.vitro.webapp.visualization.constants.QueryConstants; import edu.cornell.mannlib.vitro.webapp.visualization.constants.QueryFieldLabels; @@ -39,7 +41,7 @@ public class EntitySubOrganizationTypesQueryRunner implements QueryRunner rdf:type foaf:Organization ;" - + " rdfs:label ?organizationLabel . " + + "> rdfs:label ?organizationLabel . " + "{ " + "<"+ queryURI + "> core:hasSubOrganization ?subOrganization . " - + "?subOrganization rdfs:label ?subOrganizationLabel ; rdf:type ?subOrganizationType ; core:organizationForPosition ?Position . " + + "?subOrganization rdfs:label ?subOrganizationLabel ; rdf:type ?subOrganizationType ;" + + " core:organizationForPosition ?Position . " + "?subOrganizationType rdfs:label ?subOrganizationTypeLabel . " - + "?Position rdf:type core:Position ; core:positionForPerson ?Person ." + + "?Position core:positionForPerson ?Person ." + "}" + "UNION " + "{ " + "<"+ queryURI + "> core:organizationForPosition ?Position . " - + "?Position rdf:type core:Position ; core:positionForPerson ?Person . " + + "?Position core:positionForPerson ?Person . " + "?Person rdfs:label ?PersonLabel ; rdf:type ?PersonType . " - + "?PersonType rdfs:label ??PersonTypeLabel . " + + "?PersonType rdfs:label ?PersonTypeLabel . " + "}" + "}"; - log.debug("\nThe sparql query is :\n" + sparqlQuery); + log.info("\n SubOrganizationTypesQuery :" + sparqlQuery); return sparqlQuery; @@ -105,8 +107,8 @@ public class EntitySubOrganizationTypesQueryRunner implements QueryRunner> createJavaValueObjects(ResultSet resultSet) { - /*Map> subOrganizationLabelToTypes = new HashMap>(); - Map> personLabelToTypes = new HashMap>();*/ + // Map> subOrganizationLabelToTypes = new HashMap>(); + // Map> personLabelToTypes = new HashMap>(); Map> subEntityLabelToTypes = new HashMap>(); while(resultSet.hasNext()){ 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 new file mode 100644 index 00000000..ef98530f --- /dev/null +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitygrantcount/EntityGrantCountConstructQueryRunner.java @@ -0,0 +1,342 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + +package edu.cornell.mannlib.vitro.webapp.visualization.freemarker.entitygrantcount; + +import java.util.LinkedHashSet; +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.DataSource; +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 EntityGrantCountConstructQueryRunner { + + protected static final Syntax SYNTAX = Syntax.syntaxARQ; + + private String egoURI; + + private DataSource dataSource; + + private Log log = LogFactory.getLog(EntityGrantCountConstructQueryRunner.class.getName()); + + public EntityGrantCountConstructQueryRunner(String egoURI, DataSource dataSource, Log log){ + this.egoURI = egoURI; + this.dataSource = dataSource; + //this.log = log; + } + + private String generateConstructQueryForOrganizationLabel(String queryURI) { + + String sparqlQuery = + "CONSTRUCT { " + + "<"+queryURI+ "> rdfs:label ?organizationLabel ." + + "}" + + "WHERE {" + + "<"+queryURI+ "> rdfs:label ?organizationLabel " + + "}"; + + return sparqlQuery; + } + + private String generateConstructQueryForDateTimeValueofRoleForOneLevelDeep(String queryURI){ + + String sparqlQuery = + "CONSTRUCT { " + + "<"+queryURI+ "> core:hasSubOrganization ?subOrganization . " + + "?subOrganization core:organizationForPosition ?Position . " + + "?Position core:positionForPerson ?Person . " + + "?Person ?preboundProperty ?Role . " + + "?Role core:dateTimeInterval ?dateTimeIntervalValue . " + + "?dateTimeIntervalValue core:start ?startDate . " + + "?startDate core:dateTime ?startDateTimeValue . " + + "?dateTimeIntervalValue core:end ?endDate . " + + "?endDate core:dateTime ?endDateTimeValue . " + + "}" + + "WHERE { " + + "{" + + "<"+queryURI+ "> core:hasSubOrganization ?subOrganization . " + + "?subOrganization core:organizationForPosition ?Position . " + + "?Position core:positionForPerson ?Person . " + + "?Person ?preboundProperty ?Role . " + + "?Role core:dateTimeInterval ?dateTimeIntervalValue . " + + "?dateTimeIntervalValue core:start ?startDate . " + + "?startDate core:dateTime ?startDateTimeValue . " + + "} UNION " + + "{" + + "<"+queryURI+ "> core:hasSubOrganization ?subOrganization . " + + "?subOrganization core:organizationForPosition ?Position . " + + "?Position core:positionForPerson ?Person . " + + "?Person ?preboundProperty ?Role . " + + "?Role core:dateTimeInterval ?dateTimeIntervalValue . " + + "?dateTimeIntervalValue core:end ?endDate . " + + "?endDate core:dateTime ?endDateTimeValue . " + + "}" + + "}"; + + return sparqlQuery; + } + + private String generateConstructQueryForDateTimeValueofGrantForOneLevelDeep(String queryURI){ + + String sparqlQuery = + "CONSTRUCT { " + + "<"+queryURI+ "> core:hasSubOrganization ?subOrganization . " + + "?subOrganization core:organizationForPosition ?Position . " + + "?Position core:positionForPerson ?Person . " + + "?Person ?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+ "> core:hasSubOrganization ?subOrganization . " + + "?subOrganization core:organizationForPosition ?Position . " + + "?Position core:positionForPerson ?Person . " + + "?Person ?preboundProperty ?Role . " + + "?Role core:roleIn ?Grant ." + + "?Grant core:dateTimeInterval ?dateTimeIntervalValueForGrant . " + + "?dateTimeIntervalValueForGrant core:start ?startDateForGrant . " + + "?startDateForGrant core:dateTime ?startDateTimeValueForGrant " + + "} UNION " + + "{" + + "<"+queryURI+ "> core:hasSubOrganization ?subOrganization . " + + "?subOrganization core:organizationForPosition ?Position . " + + "?Position core:positionForPerson ?Person . " + + "?Person ?preboundProperty ?Role . " + + "?Role core:roleIn ?Grant ." + + "?Grant core:dateTimeInterval ?dateTimeIntervalValueForGrant . " + + "?dateTimeIntervalValueForGrant core:end ?endDateForGrant . " + + "?endDateForGrant core:dateTime ?endDateTimeValueForGrant " + + "}" + + "}"; + + return sparqlQuery; + } + + private String generateConstructQueryForDateTimeValueofRole(String queryURI){ + + String sparqlQuery = + "CONSTRUCT { " + + "<"+queryURI+ "> core:organizationForPosition ?Position . " + + "?Position core:positionForPerson ?Person . " + + "?Person ?preboundProperty ?Role . " + + "?Role core:dateTimeInterval ?dateTimeIntervalValue . " + + "?dateTimeIntervalValue core:start ?startDate . " + + "?startDate core:dateTime ?startDateTimeValue . " + + "?dateTimeIntervalValue core:end ?endDate . " + + "?endDate core:dateTime ?endDateTimeValue " + + "}" + + "WHERE { " + + "{" + + "<"+queryURI+ "> core:organizationForPosition ?Position . " + + "?Position core:positionForPerson ?Person . " + + "?Person ?preboundProperty ?Role . " + + "?Role core:dateTimeInterval ?dateTimeIntervalValue . " + + "?dateTimeIntervalValue core:start ?startDate . " + + "?startDate core:dateTime ?startDateTimeValue " + + "} UNION " + + "{" + + "<"+queryURI+ "> core:organizationForPosition ?Position . " + + "?Position core:positionForPerson ?Person . " + + "?Person ?preboundProperty ?Role . " + + "?Role core:dateTimeInterval ?dateTimeIntervalValue . " + + "?dateTimeIntervalValue core:end ?endDate . " + + "?endDate core:dateTime ?endDateTimeValue " + + "}" + + "}"; + + return sparqlQuery; + } + + private String generateConstructQueryForDateTimeValueofGrant(String queryURI){ + + String sparqlQuery = + "CONSTRUCT { " + + "<"+queryURI+ "> core:organizationForPosition ?Position . " + + "?Position core:positionForPerson ?Person . " + + "?Person ?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+ "> core:organizationForPosition ?Position . " + + "?Position core:positionForPerson ?Person . " + + "?Person ?preboundProperty ?Role . " + + "?Role core:roleIn ?Grant ." + + "?Grant core:dateTimeInterval ?dateTimeIntervalValueForGrant . " + + "?dateTimeIntervalValueForGrant core:start ?startDateForGrant . " + + "?startDateForGrant core:dateTime ?startDateTimeValueForGrant " + + "} UNION " + + "{" + + "<"+queryURI+ "> core:organizationForPosition ?Position . " + + "?Position core:positionForPerson ?Person . " + + "?Person ?preboundProperty ?Role . " + + "?Role core:roleIn ?Grant ." + + "?Grant core:dateTimeInterval ?dateTimeIntervalValueForGrant . " + + "?dateTimeIntervalValueForGrant core:end ?endDateForGrant . " + + "?endDateForGrant core:dateTime ?endDateTimeValueForGrant " + + "}" + + "}"; + + return sparqlQuery; + } + + private String generateConstructQueryForSubOrganizations(String queryURI){ + + String sparqlQuery = + + "CONSTRUCT { " + + "<"+queryURI+ "> core:hasSubOrganization ?subOrganization . " + + "?subOrganization rdfs:label ?subOrganizationLabel . " + + "?subOrganization core:organizationForPosition ?Position . " + + "?Position core:positionForPerson ?Person . " + + "?Person rdfs:label ?PersonLabel ." + + "?Person ?preboundProperty ?Role . " + + "?Role core:roleIn ?Grant ." + + "?Grant rdfs:label ?GrantLabel " + +"}" + + "WHERE { " + + "<"+queryURI+ "> core:hasSubOrganization ?subOrganization . " + + "?subOrganization rdfs:label ?subOrganizationLabel . " + + "?subOrganization core:organizationForPosition ?Position . " + + "?Position core:positionForPerson ?Person . " + + "?Person rdfs:label ?PersonLabel ." + + "?Person ?preboundProperty ?Role . " + + "?Role core:roleIn ?Grant ." + + "?Grant rdfs:label ?GrantLabel " + + "}" ; + + + return sparqlQuery; + + } + + private String generateConstructQueryForPersons(String queryURI){ + + String sparqlQuery = + + "CONSTRUCT { " + + "<"+queryURI+ "> core:organizationForPosition ?Position . " + + "?Position core:positionForPerson ?Person . " + + "?Person rdfs:label ?PersonLabel ." + + "?Person ?preboundProperty ?Role . " + + "?Role core:roleIn ?Grant ." + + "?Grant rdfs:label ?GrantLabel " + +"}" + + "WHERE { " + + "<"+queryURI+ "> core:organizationForPosition ?Position . " + + "?Position core:positionForPerson ?Person . " + + "?Person rdfs:label ?PersonLabel ." + + "?Person ?preboundProperty ?Role . " + + "?Role core:roleIn ?Grant ." + + "?Grant rdfs:label ?GrantLabel " + + "}" ; + + + return sparqlQuery; + + } + + + + private Model executeQuery(Set constructQueries, DataSource dataSource) { + + Model constructedModel = ModelFactory.createDefaultModel(); + + for (String queryString : constructQueries) { + + log.debug("CONSTRUCT query string : " + queryString); + + Query query = null; + + try{ + query = QueryFactory.create(QueryConstants.getSparqlPrefixQuery() + queryString, SYNTAX); + // log.info("query: "+ queryString); + }catch(Throwable th){ + log.error("Could not create CONSTRUCT SPARQL query for query " + + "string. " + th.getMessage()); + log.error(queryString); + } + + QueryExecution qe = QueryExecutionFactory.create( + query, dataSource); + try { + qe.execConstruct(constructedModel); + } finally { + qe.close(); + } + + } + log.debug("Statements for constructed model of EntityGrantCount : "+ constructedModel.listStatements().toString()); + // constructedModel.write(System.out); + 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("Entity 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 LinkedHashSet(); + + populateConstructQueries(constructQueries); + + Model model = executeQuery(constructQueries, + this.dataSource); + + return model; + + } + + private void populateConstructQueries(Set constructQueries) { + + constructQueries.add(generateConstructQueryForOrganizationLabel(this.egoURI)); + constructQueries.add(generateConstructQueryForSubOrganizations(this.egoURI)); + constructQueries.add(generateConstructQueryForPersons(this.egoURI)); + constructQueries.add(generateConstructQueryForDateTimeValueofRoleForOneLevelDeep(this.egoURI)); + constructQueries.add(generateConstructQueryForDateTimeValueofRole(this.egoURI)); + constructQueries.add(generateConstructQueryForDateTimeValueofGrantForOneLevelDeep(this.egoURI)); + constructQueries.add(generateConstructQueryForDateTimeValueofGrant(this.egoURI)); + + + } + +} diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitygrantcount/EntityGrantCountQueryRunner.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitygrantcount/EntityGrantCountQueryRunner.java index 91bc36e1..3485f267 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitygrantcount/EntityGrantCountQueryRunner.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitygrantcount/EntityGrantCountQueryRunner.java @@ -20,13 +20,14 @@ import com.hp.hpl.jena.query.QueryFactory; import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.ResultSet; import com.hp.hpl.jena.query.Syntax; +import com.hp.hpl.jena.rdf.model.Model; import com.hp.hpl.jena.rdf.model.RDFNode; import edu.cornell.mannlib.vitro.webapp.visualization.constants.QueryConstants; 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.Entity; import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.valueobjects.Grant; +import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.valueobjects.Entity; import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.valueobjects.SubEntity; import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.QueryRunner; @@ -44,7 +45,7 @@ public class EntityGrantCountQueryRunner implements QueryRunner { protected static final Syntax SYNTAX = Syntax.syntaxARQ; private String entityURI; - private DataSource dataSource; + private Model dataSource; private Log log = LogFactory.getLog(EntityGrantCountQueryRunner.class.getName()); @@ -54,7 +55,6 @@ public class EntityGrantCountQueryRunner implements QueryRunner { + " (str(?subOrganizationLabel) as ?subOrganizationLabelLit) " + " (str(?Person) as ?personLit) " + " (str(?PersonLabel) as ?personLabelLit) " - + " (str(?SecondaryPositionLabel) as ?SecondaryPositionLabelLit)" + " (str(?Grant) as ?grantLit) " + " (str(?GrantLabel) as ?grantLabelLit) " + " (str(?startDateTimeValue) as ?grantStartDateLit) " @@ -63,7 +63,6 @@ public class EntityGrantCountQueryRunner implements QueryRunner { + " (str(?endDateTimeValueForGrant) as ?grantEndDateForGrantLit) " ; private static final String SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_ROLE_DATE_TIME = " " - + " ?SecondaryPosition rdfs:label ?SecondaryPositionLabel . " + " ?Role core:roleIn ?Grant . " + " ?Grant rdfs:label ?GrantLabel . " + "OPTIONAL {" @@ -77,7 +76,6 @@ public class EntityGrantCountQueryRunner implements QueryRunner { + "}" ; private static final String SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_GRANT_DATE_TIME = " " - + " ?SecondaryPosition rdfs:label ?SecondaryPositionLabel . " + " ?Role core:roleIn ?Grant . " + " ?Grant rdfs:label ?GrantLabel . " + "OPTIONAL {" @@ -98,22 +96,22 @@ public class EntityGrantCountQueryRunner implements QueryRunner { public EntityGrantCountQueryRunner(String entityURI, - DataSource dataSource, Log log) { + Model constructedModel, Log log) { this.entityURI = entityURI; - this.dataSource = dataSource; + this.dataSource = constructedModel; } private Entity createJavaValueObjects(ResultSet resultSet) { - + Entity entity = null; Map grantURIToVO = new HashMap(); Map subentityURLToVO = new HashMap(); Map personURLToVO = new HashMap(); while (resultSet.hasNext()) { - + // log.info("Checking whether EntityGrantCount produced any resultset against the Constructed Model"); QuerySolution solution = resultSet.nextSolution(); if (entity == null) { @@ -196,10 +194,8 @@ public class EntityGrantCountQueryRunner implements QueryRunner { person = new SubEntity(personURLNode.toString()); personURLToVO.put(personURLNode.toString(), person); } - - RDFNode personLabelNode = solution - .get(QueryFieldLabels.PERSON_LABEL); + RDFNode personLabelNode = solution.get(QueryFieldLabels.PERSON_LABEL); if (personLabelNode != null) { person.setIndividualLabel(personLabelNode.toString()); } @@ -235,12 +231,12 @@ public class EntityGrantCountQueryRunner implements QueryRunner { return entity; } - private ResultSet executeQuery(String queryURI, DataSource dataSource) { + private ResultSet executeQuery(String queryURI, Model dataSource2) { QueryExecution queryExecution = null; Query query = QueryFactory.create( getSparqlQuery(queryURI), SYNTAX); - queryExecution = QueryExecutionFactory.create(query, dataSource); + queryExecution = QueryExecutionFactory.create(query, dataSource2); return queryExecution.execSelect(); } @@ -249,57 +245,56 @@ public class EntityGrantCountQueryRunner implements QueryRunner { String sparqlQuery = QueryConstants.getSparqlPrefixQuery() + SPARQL_QUERY_COMMON_SELECT_CLAUSE + " (str(<" + queryURI + ">) as ?" + ENTITY_URL + ") " - + "WHERE { " + "<" + queryURI + "> rdf:type foaf:Organization ;" - + " rdfs:label ?organizationLabel ." + + "WHERE { " + "<" + queryURI + "> rdfs:label ?organizationLabel ." + "{ " + "<" + queryURI + "> core:hasSubOrganization ?subOrganization ." + " ?subOrganization rdfs:label ?subOrganizationLabel ; core:organizationForPosition ?Position . " - + " ?Position rdf:type core:Position ; core:positionForPerson ?Person ." - + " ?Person core:hasCo-PrincipalInvestigatorRole ?Role ; rdfs:label ?PersonLabel ; core:personInPosition ?SecondaryPosition . " + + " ?Position core:positionForPerson ?Person ." + + " ?Person core:hasCo-PrincipalInvestigatorRole ?Role ; rdfs:label ?PersonLabel ." + SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_ROLE_DATE_TIME + SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_GRANT_DATE_TIME + "}" + "UNION " + "{ " + "<" + queryURI + "> core:hasSubOrganization ?subOrganization . " + " ?subOrganization rdfs:label ?subOrganizationLabel ; core:organizationForPosition ?Position . " - + " ?Position rdf:type core:Position ; core:positionForPerson ?Person ." - + " ?Person core:hasPrincipalInvestigatorRole ?Role ; rdfs:label ?PersonLabel ; core:personInPosition ?SecondaryPosition . " + + " ?Position core:positionForPerson ?Person ." + + " ?Person core:hasPrincipalInvestigatorRole ?Role ; rdfs:label ?PersonLabel . " + SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_ROLE_DATE_TIME + SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_GRANT_DATE_TIME + "}" + "UNION " + "{ " + "<" + queryURI + "> core:hasSubOrganization ?subOrganization . " + " ?subOrganization rdfs:label ?subOrganizationLabel ; core:organizationForPosition ?Position . " - + " ?Position rdf:type core:Position ; core:positionForPerson ?Person ." - + " ?Person core:hasInvestigatorRole ?Role ; rdfs:label ?PersonLabel ; core:personInPosition ?SecondaryPosition . " + + " ?Position core:positionForPerson ?Person ." + + " ?Person core:hasInvestigatorRole ?Role ; rdfs:label ?PersonLabel . " + SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_ROLE_DATE_TIME + SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_GRANT_DATE_TIME + "}" + "UNION " + "{ " + "<" + queryURI + "> core:organizationForPosition ?Position . " - + " ?Position rdf:type core:Position ; core:positionForPerson ?Person ." - + " ?Person core:hasCo-PrincipalInvestigatorRole ?Role ; rdfs:label ?PersonLabel ; core:personInPosition ?SecondaryPosition . " + + " ?Position core:positionForPerson ?Person ." + + " ?Person core:hasCo-PrincipalInvestigatorRole ?Role ; rdfs:label ?PersonLabel . " + SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_ROLE_DATE_TIME + SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_GRANT_DATE_TIME + "}" + "UNION " + "{ " + "<" + queryURI + "> core:organizationForPosition ?Position . " - + " ?Position rdf:type core:Position ; core:positionForPerson ?Person ." - + " ?Person core:hasPrincipalInvestigatorRole ?Role ; rdfs:label ?PersonLabel ; core:personInPosition ?SecondaryPosition . " + + " ?Position core:positionForPerson ?Person ." + + " ?Person core:hasPrincipalInvestigatorRole ?Role ; rdfs:label ?PersonLabel . " + SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_ROLE_DATE_TIME + SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_GRANT_DATE_TIME + "}" + "UNION " + "{ " + "<" + queryURI + "> core:organizationForPosition ?Position . " - + " ?Position rdf:type core:Position ; core:positionForPerson ?Person ." - + " ?Person core:hasInvestigatorRole ?Role ; rdfs:label ?PersonLabel ; core:personInPosition ?SecondaryPosition . " + + " ?Position core:positionForPerson ?Person ." + + " ?Person core:hasInvestigatorRole ?Role ; rdfs:label ?PersonLabel . " + SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_ROLE_DATE_TIME + SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_GRANT_DATE_TIME + "}" + " } "; //System.out.println("\n\nEntity Grant Count query is: "+ sparqlQuery); - log.debug("\nThe sparql query is :\n" + sparqlQuery); + // log.info("\nThe sparql query is :\n" + sparqlQuery); return sparqlQuery; 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 63e74d82..6199fc0d 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,12 +12,14 @@ 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.iri.IRI; import com.hp.hpl.jena.iri.IRIFactory; import com.hp.hpl.jena.iri.Violation; import com.hp.hpl.jena.query.DataSource; +import com.hp.hpl.jena.rdf.model.Model; import edu.cornell.mannlib.vitro.webapp.ConfigurationProperties; import edu.cornell.mannlib.vitro.webapp.beans.Portal; @@ -40,6 +42,8 @@ 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, DataSource dataSource) @@ -100,8 +104,11 @@ public class EntityGrantCountRequestHandler implements String entityURI = vitroRequest .getParameter(VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY); + EntityGrantCountConstructQueryRunner constructQueryRunner = new EntityGrantCountConstructQueryRunner(entityURI, dataSource, log); + Model constructedModel = constructQueryRunner.getConstructedModel(); + QueryRunner queryManager = new EntityGrantCountQueryRunner( - entityURI, dataSource, log); + entityURI, constructedModel, log); Entity entity = queryManager.getQueryResult(); @@ -124,8 +131,11 @@ public class EntityGrantCountRequestHandler implements String subjectEntityURI) throws MalformedQueryParametersException { + EntityGrantCountConstructQueryRunner constructQueryRunner = new EntityGrantCountConstructQueryRunner(subjectEntityURI, dataSource, log); + Model constructedModel = constructQueryRunner.getConstructedModel(); + QueryRunner queryManager = new EntityGrantCountQueryRunner( - subjectEntityURI, dataSource, log); + subjectEntityURI, constructedModel, log); Entity entity = queryManager.getQueryResult(); @@ -269,6 +279,8 @@ 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())); 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 663665f8..02af6037 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 @@ -13,6 +13,7 @@ import javax.servlet.http.HttpServletRequest; import org.apache.commons.logging.Log; import com.hp.hpl.jena.query.DataSource; +import com.hp.hpl.jena.rdf.model.Model; import edu.cornell.mannlib.vitro.webapp.beans.Portal; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; @@ -22,6 +23,7 @@ import edu.cornell.mannlib.vitro.webapp.controller.visualization.freemarker.Visu import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException; import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.coauthorship.CoAuthorshipQueryRunner; import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.coauthorship.CoAuthorshipVisCodeGenerator; +import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.coprincipalinvestigator.CoPIGrantCountConstructQueryRunner; import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.coprincipalinvestigator.CoPIGrantCountQueryRunner; import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.coprincipalinvestigator.CoPIVisCodeGenerator; import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.persongrantcount.PersonGrantCountQueryRunner; @@ -82,10 +84,13 @@ public class PersonLevelRequestHandler implements VisualizationRequestHandler { VisualizationFrameworkConstants.VIS_MODE_KEY); - if (VisualizationFrameworkConstants.COPI_VIS_MODE.equalsIgnoreCase(visMode)) { + if (VisualizationFrameworkConstants.COPI_VIS_MODE.equalsIgnoreCase(visMode)){ - QueryRunner coPIQueryManager = new CoPIGrantCountQueryRunner(egoURI, dataSource, log); - + CoPIGrantCountConstructQueryRunner constructQueryRunner = new CoPIGrantCountConstructQueryRunner(egoURI, dataSource, log); + Model constructedModel = constructQueryRunner.getConstructedModel(); + + QueryRunner coPIQueryManager = new CoPIGrantCountQueryRunner(egoURI, constructedModel, log); + QueryRunner> grantQueryManager = new PersonGrantCountQueryRunner(egoURI, dataSource, log); CoPIData coPIData = coPIQueryManager.getQueryResult();