diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/modelconstructor/ModelConstructorUtilities.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/modelconstructor/ModelConstructorUtilities.java index e43ff0c1..285b2647 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/modelconstructor/ModelConstructorUtilities.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/modelconstructor/ModelConstructorUtilities.java @@ -7,6 +7,7 @@ import java.util.Map; import com.hp.hpl.jena.query.Dataset; import com.hp.hpl.jena.rdf.model.Model; +import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService; import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException; import edu.cornell.mannlib.vitro.webapp.visualization.modelconstructor.factory.ModelFactoryInterface; import edu.cornell.mannlib.vitro.webapp.visualization.modelconstructor.factory.OrganizationAssociatedPeopleModelWithTypesFactory; @@ -50,4 +51,9 @@ public class ModelConstructorUtilities { throws MalformedQueryParametersException { return modelTypeIdentifierToFactory.get(modelType).getOrCreateModel(uri, dataset); } + + public static Model getOrConstructModel(String uri, String modelType, RDFService rdfService) + throws MalformedQueryParametersException { + return modelTypeIdentifierToFactory.get(modelType).getOrCreateModel(uri, rdfService); + } } \ No newline at end of file diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/modelconstructor/PersonToGrantsModelConstructor.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/modelconstructor/PersonToGrantsModelConstructor.java index 6e867ca3..8ef83a01 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/modelconstructor/PersonToGrantsModelConstructor.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/modelconstructor/PersonToGrantsModelConstructor.java @@ -4,14 +4,10 @@ package edu.cornell.mannlib.vitro.webapp.visualization.modelconstructor; import java.util.HashSet; import java.util.Set; +import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -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; @@ -24,7 +20,7 @@ public class PersonToGrantsModelConstructor implements ModelConstructor { protected static final Syntax SYNTAX = Syntax.syntaxARQ; - private Dataset dataset; + private RDFService rdfService; public static final String MODEL_TYPE = "PERSON_TO_GRANTS"; public static final String MODEL_TYPE_HUMAN_READABLE = "Grants for specific person via all roles"; @@ -35,9 +31,9 @@ public class PersonToGrantsModelConstructor implements ModelConstructor { private long before, after; - public PersonToGrantsModelConstructor(String personURI, Dataset dataset) { + public PersonToGrantsModelConstructor(String personURI, RDFService rdfService) { this.personURI = personURI; - this.dataset = dataset; + this.rdfService = rdfService; } private Set constructPersonGrantsQueryTemplate(String constructProperty, String roleType) { @@ -138,33 +134,20 @@ private Set constructPersonGrantsQueryTemplate(String constructProperty, } private Model executeQuery(Set constructQueries) { - Model constructedModel = ModelFactory.createDefaultModel(); before = System.currentTimeMillis(); log.debug("CONSTRUCT query string : " + constructQueries); for (String currentQuery : constructQueries) { - - - Query query = null; - try { - query = QueryFactory.create(QueryConstants.getSparqlPrefixQuery() + currentQuery, SYNTAX); + rdfService.sparqlConstructQuery(QueryConstants.getSparqlPrefixQuery() + currentQuery, constructedModel); } catch (Throwable th) { log.error("Could not create CONSTRUCT SPARQL query for query " + "string. " + th.getMessage()); log.error(currentQuery); } - - - QueryExecution qe = QueryExecutionFactory.create(query, dataset); - - try { - qe.execConstruct(constructedModel); - } finally { - qe.close(); - } + } after = System.currentTimeMillis(); diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/modelconstructor/factory/ModelFactoryInterface.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/modelconstructor/factory/ModelFactoryInterface.java index a3aa7f55..500c4aa8 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/modelconstructor/factory/ModelFactoryInterface.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/modelconstructor/factory/ModelFactoryInterface.java @@ -4,10 +4,12 @@ package edu.cornell.mannlib.vitro.webapp.visualization.modelconstructor.factory; import com.hp.hpl.jena.query.Dataset; import com.hp.hpl.jena.rdf.model.Model; +import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService; import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException; public interface ModelFactoryInterface { public Model getOrCreateModel(String uri, Dataset dataset) throws MalformedQueryParametersException; + public Model getOrCreateModel(String uri, RDFService rdfService) throws MalformedQueryParametersException; } diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/modelconstructor/factory/OrganizationAssociatedPeopleModelWithTypesFactory.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/modelconstructor/factory/OrganizationAssociatedPeopleModelWithTypesFactory.java index 789e97e3..dd07f169 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/modelconstructor/factory/OrganizationAssociatedPeopleModelWithTypesFactory.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/modelconstructor/factory/OrganizationAssociatedPeopleModelWithTypesFactory.java @@ -4,6 +4,7 @@ package edu.cornell.mannlib.vitro.webapp.visualization.modelconstructor.factory; import com.hp.hpl.jena.query.Dataset; import com.hp.hpl.jena.rdf.model.Model; +import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService; import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException; import edu.cornell.mannlib.vitro.webapp.visualization.modelconstructor.OrganizationAssociatedPeopleModelWithTypesConstructor; import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.ConstructedModelTracker; @@ -43,4 +44,9 @@ public class OrganizationAssociatedPeopleModelWithTypesFactory implements } + @Override + public Model getOrCreateModel(String uri, RDFService rdfService) throws MalformedQueryParametersException { + return null; + } + } diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/modelconstructor/factory/OrganizationModelWithTypesFactory.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/modelconstructor/factory/OrganizationModelWithTypesFactory.java index f1cd50ea..22c357e3 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/modelconstructor/factory/OrganizationModelWithTypesFactory.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/modelconstructor/factory/OrganizationModelWithTypesFactory.java @@ -4,6 +4,7 @@ package edu.cornell.mannlib.vitro.webapp.visualization.modelconstructor.factory; import com.hp.hpl.jena.query.Dataset; import com.hp.hpl.jena.rdf.model.Model; +import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService; import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException; import edu.cornell.mannlib.vitro.webapp.visualization.modelconstructor.OrganizationModelWithTypesConstructor; import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.ConstructedModelTracker; @@ -39,4 +40,9 @@ public class OrganizationModelWithTypesFactory implements ModelFactoryInterface return constructedModel; } } + + @Override + public Model getOrCreateModel(String uri, RDFService rdfService) throws MalformedQueryParametersException { + return null; + } } diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/modelconstructor/factory/OrganizationToGrantsForSubOrganizationsFactory.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/modelconstructor/factory/OrganizationToGrantsForSubOrganizationsFactory.java index 92d469c9..fce2b153 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/modelconstructor/factory/OrganizationToGrantsForSubOrganizationsFactory.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/modelconstructor/factory/OrganizationToGrantsForSubOrganizationsFactory.java @@ -4,6 +4,7 @@ package edu.cornell.mannlib.vitro.webapp.visualization.modelconstructor.factory; import com.hp.hpl.jena.query.Dataset; import com.hp.hpl.jena.rdf.model.Model; +import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService; import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException; import edu.cornell.mannlib.vitro.webapp.visualization.modelconstructor.OrganizationToGrantsForSubOrganizationsModelConstructor; import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.ConstructedModelTracker; @@ -43,4 +44,9 @@ public class OrganizationToGrantsForSubOrganizationsFactory implements } + @Override + public Model getOrCreateModel(String uri, RDFService rdfService) throws MalformedQueryParametersException { + return null; + } + } diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/modelconstructor/factory/OrganizationToPublicationsForSubOrganizationsFactory.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/modelconstructor/factory/OrganizationToPublicationsForSubOrganizationsFactory.java index 3220e87c..b5a97869 100755 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/modelconstructor/factory/OrganizationToPublicationsForSubOrganizationsFactory.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/modelconstructor/factory/OrganizationToPublicationsForSubOrganizationsFactory.java @@ -4,6 +4,7 @@ package edu.cornell.mannlib.vitro.webapp.visualization.modelconstructor.factory; import com.hp.hpl.jena.query.Dataset; import com.hp.hpl.jena.rdf.model.Model; +import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService; import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException; import edu.cornell.mannlib.vitro.webapp.visualization.modelconstructor.OrganizationToPublicationsForSubOrganizationsModelConstructor; import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.ConstructedModelTracker; @@ -58,7 +59,12 @@ public class OrganizationToPublicationsForSubOrganizationsFactory implements } } } - + + @Override + public Model getOrCreateModel(String uri, RDFService rdfService) throws MalformedQueryParametersException { + return null; } +} + diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/modelconstructor/factory/PeopleToGrantsFactory.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/modelconstructor/factory/PeopleToGrantsFactory.java index 3523268f..7c23ad12 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/modelconstructor/factory/PeopleToGrantsFactory.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/modelconstructor/factory/PeopleToGrantsFactory.java @@ -4,6 +4,7 @@ package edu.cornell.mannlib.vitro.webapp.visualization.modelconstructor.factory; import com.hp.hpl.jena.query.Dataset; import com.hp.hpl.jena.rdf.model.Model; +import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService; import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException; import edu.cornell.mannlib.vitro.webapp.visualization.modelconstructor.PeopleToGrantsModelConstructor; import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.ConstructedModelTracker; @@ -40,4 +41,9 @@ public class PeopleToGrantsFactory implements ModelFactoryInterface { return constructedModel; } } + + @Override + public Model getOrCreateModel(String uri, RDFService rdfService) throws MalformedQueryParametersException { + return null; + } } \ No newline at end of file diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/modelconstructor/factory/PeopleToPublicationsFactory.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/modelconstructor/factory/PeopleToPublicationsFactory.java index 4cb11cc0..f6984672 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/modelconstructor/factory/PeopleToPublicationsFactory.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/modelconstructor/factory/PeopleToPublicationsFactory.java @@ -4,6 +4,7 @@ package edu.cornell.mannlib.vitro.webapp.visualization.modelconstructor.factory; import com.hp.hpl.jena.query.Dataset; import com.hp.hpl.jena.rdf.model.Model; +import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService; import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException; import edu.cornell.mannlib.vitro.webapp.visualization.modelconstructor.PeopleToPublicationsModelConstructor; import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.ConstructedModelTracker; @@ -42,4 +43,9 @@ public class PeopleToPublicationsFactory implements ModelFactoryInterface { } + @Override + public Model getOrCreateModel(String uri, RDFService rdfService) throws MalformedQueryParametersException { + return null; + } + } diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/modelconstructor/factory/PersonToGrantsFactory.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/modelconstructor/factory/PersonToGrantsFactory.java index 27d0ac08..75cf7656 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/modelconstructor/factory/PersonToGrantsFactory.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/modelconstructor/factory/PersonToGrantsFactory.java @@ -4,6 +4,7 @@ package edu.cornell.mannlib.vitro.webapp.visualization.modelconstructor.factory; import com.hp.hpl.jena.query.Dataset; import com.hp.hpl.jena.rdf.model.Model; +import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService; import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException; import edu.cornell.mannlib.vitro.webapp.visualization.modelconstructor.PersonToGrantsModelConstructor; import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.ConstructedModelTracker; @@ -12,7 +13,12 @@ import edu.cornell.mannlib.vitro.webapp.visualization.visutils.ModelConstructor; public class PersonToGrantsFactory implements ModelFactoryInterface { @Override - public Model getOrCreateModel(String uri, Dataset dataset) + public Model getOrCreateModel(String uri, Dataset dataset) { + return null; + } + + @Override + public Model getOrCreateModel(String uri, RDFService rdfService) throws MalformedQueryParametersException { Model candidateModel = ConstructedModelTracker.getModel( @@ -27,7 +33,7 @@ public class PersonToGrantsFactory implements ModelFactoryInterface { } else { - ModelConstructor model = new PersonToGrantsModelConstructor(uri, dataset); + ModelConstructor model = new PersonToGrantsModelConstructor(uri, rdfService); Model constructedModel = model.getConstructedModel(); ConstructedModelTracker.trackModel( diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/modelconstructor/factory/PersonToPublicationsFactory.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/modelconstructor/factory/PersonToPublicationsFactory.java index 503d15c3..eb069bbb 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/modelconstructor/factory/PersonToPublicationsFactory.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/modelconstructor/factory/PersonToPublicationsFactory.java @@ -4,6 +4,7 @@ package edu.cornell.mannlib.vitro.webapp.visualization.modelconstructor.factory; import com.hp.hpl.jena.query.Dataset; import com.hp.hpl.jena.rdf.model.Model; +import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService; import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException; import edu.cornell.mannlib.vitro.webapp.visualization.modelconstructor.PersonToPublicationsModelConstructor; import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.ConstructedModelTracker; @@ -42,4 +43,9 @@ public class PersonToPublicationsFactory implements ModelFactoryInterface { } + @Override + public Model getOrCreateModel(String uri, RDFService rdfService) throws MalformedQueryParametersException { + return null; + } + } diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/modelconstructor/factory/SubOrganizationWithinModelFactory.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/modelconstructor/factory/SubOrganizationWithinModelFactory.java index ea9c2d15..57a33b30 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/modelconstructor/factory/SubOrganizationWithinModelFactory.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/modelconstructor/factory/SubOrganizationWithinModelFactory.java @@ -4,6 +4,7 @@ package edu.cornell.mannlib.vitro.webapp.visualization.modelconstructor.factory; import com.hp.hpl.jena.query.Dataset; import com.hp.hpl.jena.rdf.model.Model; +import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService; import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException; import edu.cornell.mannlib.vitro.webapp.visualization.modelconstructor.SubOrganizationWithinModelConstructor; import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.ConstructedModelTracker; @@ -39,4 +40,9 @@ public class SubOrganizationWithinModelFactory implements ModelFactoryInterface return constructedModel; } } + + @Override + public Model getOrCreateModel(String uri, RDFService rdfService) throws MalformedQueryParametersException { + return null; + } } diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/persongrantcount/PersonGrantCountRequestHandler.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/persongrantcount/PersonGrantCountRequestHandler.java index a0a4927b..d6c64ea6 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/persongrantcount/PersonGrantCountRequestHandler.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/persongrantcount/PersonGrantCountRequestHandler.java @@ -55,7 +55,7 @@ public class PersonGrantCountRequestHandler implements VisualizationRequestHandl personURI, UtilityFunctions.getIndividualLabelFromDAO(vitroRequest, personURI)); - Map grantsToURI = SelectOnModelUtilities.getGrantsForPerson(dataset, person, false); + Map grantsToURI = SelectOnModelUtilities.getGrantsForPerson(vitroRequest.getRDFService(), person, false); /* @@ -96,7 +96,7 @@ public class PersonGrantCountRequestHandler implements VisualizationRequestHandl personURI, UtilityFunctions.getIndividualLabelFromDAO(vitroRequest, personURI)); - Map grantsToURI = SelectOnModelUtilities.getGrantsForPerson(dataset, person, false); + Map grantsToURI = SelectOnModelUtilities.getGrantsForPerson(vitroRequest.getRDFService(), person, false); /* * Create a map from the year to number of grants. Use the Grant's @@ -147,7 +147,7 @@ public class PersonGrantCountRequestHandler implements VisualizationRequestHandl personURI, UtilityFunctions.getIndividualLabelFromDAO(vitroRequest, personURI)); - Map grantsToURI = SelectOnModelUtilities.getGrantsForPerson(dataset, person, false); + Map grantsToURI = SelectOnModelUtilities.getGrantsForPerson(vitroRequest.getRDFService(), person, false); /* * Create a map from the year to number of grants. Use the Grant's diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/personlevel/PersonLevelRequestHandler.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/personlevel/PersonLevelRequestHandler.java index b096b2d5..0e27a351 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/personlevel/PersonLevelRequestHandler.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/personlevel/PersonLevelRequestHandler.java @@ -123,7 +123,7 @@ public class PersonLevelRequestHandler implements VisualizationRequestHandler { UtilityFunctions .getIndividualLabelFromDAO(vitroRequest, egoURI)); - Map grantsToURI = SelectOnModelUtilities.getGrantsForPerson(dataset, person, false); + Map grantsToURI = SelectOnModelUtilities.getGrantsForPerson(vitroRequest.getRDFService(), person, false); /* * Create a map from the year to number of grants. Use the Grant's diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/utilities/UtilitiesRequestHandler.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/utilities/UtilitiesRequestHandler.java index fb60732c..efc78001 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/utilities/UtilitiesRequestHandler.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/utilities/UtilitiesRequestHandler.java @@ -5,6 +5,8 @@ package edu.cornell.mannlib.vitro.webapp.visualization.utilities; import java.util.HashMap; import java.util.Map; +import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceException; +import edu.cornell.mannlib.vitro.webapp.rdfservice.ResultSetConsumer; import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.jena.iri.IRI; @@ -71,10 +73,10 @@ public class UtilitiesRequestHandler implements VisualizationRequestHandler { + " || ?predicate = rdfs:label " + " || ?predicate = "; - QueryRunner profileQueryHandler = + AllPropertiesQueryRunner profileQueryHandler = new AllPropertiesQueryRunner(individualURI, filterRule, - dataset, + vitroRequest.getRDFService(), log); GenericQueryMap profilePropertiesToValues = @@ -104,15 +106,16 @@ public class UtilitiesRequestHandler implements VisualizationRequestHandler { - QueryRunner imageQueryHandler = + GenericQueryRunner imageQueryHandler = new GenericQueryRunner(fieldLabelToOutputFieldLabel, "", whereClause, "", dataset); - - return getThumbnailInformation(imageQueryHandler.getQueryResult(), - fieldLabelToOutputFieldLabel, vitroRequest); + + ThumbnailInformationConsumer consumer = new ThumbnailInformationConsumer(vitroRequest, fieldLabelToOutputFieldLabel); + imageQueryHandler.sparqlSelectQuery(vitroRequest.getRDFService(), consumer); + return consumer.getInformation(); } else if (VisualizationFrameworkConstants.ARE_PUBLICATIONS_AVAILABLE_UTILS_VIS_MODE .equalsIgnoreCase(visMode)) { @@ -130,7 +133,7 @@ public class UtilitiesRequestHandler implements VisualizationRequestHandler { String groupOrderClause = "GROUP BY ?" + QueryFieldLabels.AUTHOR_URL + " \n"; - QueryRunner numberOfPublicationsQueryHandler = + GenericQueryRunner numberOfPublicationsQueryHandler = new GenericQueryRunner(fieldLabelToOutputFieldLabel, aggregationRules, whereClause, @@ -138,9 +141,10 @@ public class UtilitiesRequestHandler implements VisualizationRequestHandler { dataset); Gson publicationsInformation = new Gson(); - - return publicationsInformation.toJson(getNumberOfPublicationsForIndividual( - numberOfPublicationsQueryHandler.getQueryResult())); + + NumPubsForIndividualConsumer consumer = new NumPubsForIndividualConsumer(); + numberOfPublicationsQueryHandler.sparqlSelectQuery(vitroRequest.getRDFService(), consumer); + return publicationsInformation.toJson(consumer.getMap()); } else if (VisualizationFrameworkConstants.ARE_GRANTS_AVAILABLE_UTILS_VIS_MODE .equalsIgnoreCase(visMode)) { @@ -170,7 +174,7 @@ public class UtilitiesRequestHandler implements VisualizationRequestHandler { + "FILTER (?subclass != core:PrincipalInvestigatorRole && " + "?subclass != core:CoPrincipalInvestigatorRole)}"; - QueryRunner numberOfGrantsQueryHandler = + GenericQueryRunner numberOfGrantsQueryHandler = new GenericQueryRunner(fieldLabelToOutputFieldLabel, aggregationRules, whereClause, @@ -178,9 +182,11 @@ public class UtilitiesRequestHandler implements VisualizationRequestHandler { dataset); Gson grantsInformation = new Gson(); - - return grantsInformation.toJson(getNumberOfGrantsForIndividual( - numberOfGrantsQueryHandler.getQueryResult())); + + NumGrantsForIndividualConsumer consumer = new NumGrantsForIndividualConsumer(); + numberOfGrantsQueryHandler.sparqlSelectQuery(vitroRequest.getRDFService(), consumer); + + return grantsInformation.toJson(consumer.getMap()); } else if (VisualizationFrameworkConstants.COAUTHOR_UTILS_VIS_MODE .equalsIgnoreCase(visMode)) { @@ -319,17 +325,16 @@ public class UtilitiesRequestHandler implements VisualizationRequestHandler { + "ORDER BY DESC(?numOfChildren)\n" + "LIMIT 1\n"; - QueryRunner highestLevelOrganizationQueryHandler = + GenericQueryRunner highestLevelOrganizationQueryHandler = new GenericQueryRunner(fieldLabelToOutputFieldLabel, aggregationRules, whereClause, groupOrderClause, dataset); - - return getHighestLevelOrganizationTemporalGraphVisURL( - highestLevelOrganizationQueryHandler.getQueryResult(), - fieldLabelToOutputFieldLabel, - vitroRequest); + + HighetTopLevelOrgTemporalGraphURLConsumer consumer = new HighetTopLevelOrgTemporalGraphURLConsumer(vitroRequest, fieldLabelToOutputFieldLabel); + highestLevelOrganizationQueryHandler.sparqlSelectQuery(vitroRequest.getRDFService(), consumer); + return consumer.getTopLevelURL(); } else { @@ -343,110 +348,136 @@ public class UtilitiesRequestHandler implements VisualizationRequestHandler { } - private String getHighestLevelOrganizationTemporalGraphVisURL(ResultSet resultSet, - Map fieldLabelToOutputFieldLabel, - VitroRequest vitroRequest) { + private class HighetTopLevelOrgTemporalGraphURLConsumer extends ResultSetConsumer { + private VitroRequest vitroRequest; + private Map fieldLabelToOutputFieldLabel; + private String topLevelURL = null; + private GenericQueryMap queryResult = new GenericQueryMap(); + + HighetTopLevelOrgTemporalGraphURLConsumer(VitroRequest vitroRequest, Map fieldLabelToOutputFieldLabel) { + this.vitroRequest = vitroRequest; + this.fieldLabelToOutputFieldLabel = fieldLabelToOutputFieldLabel; + } + + @Override + protected void processQuerySolution(QuerySolution qs) { + if (topLevelURL != null) { + return; + } + + RDFNode organizationNode = qs.get(fieldLabelToOutputFieldLabel.get("organization")); - GenericQueryMap queryResult = new GenericQueryMap(); - - - while (resultSet.hasNext()) { - QuerySolution solution = resultSet.nextSolution(); - - - RDFNode organizationNode = solution.get( - fieldLabelToOutputFieldLabel - .get("organization")); - if (organizationNode != null) { - queryResult.addEntry(fieldLabelToOutputFieldLabel.get("organization"), - organizationNode.toString()); - - String individualLocalName = UtilityFunctions.getIndividualLocalName( - organizationNode.toString(), - vitroRequest); - - if (StringUtils.isNotBlank(individualLocalName)) { - - return UrlBuilder.getUrl(VisualizationFrameworkConstants.SHORT_URL_VISUALIZATION_REQUEST_PREFIX) - + "/" + VisualizationFrameworkConstants.PUBLICATION_TEMPORAL_VIS_SHORT_URL - + "/" + individualLocalName; - } - - ParamMap highestLevelOrganizationTemporalGraphVisURLParams = new ParamMap( - VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY, - organizationNode.toString(), - VisualizationFrameworkConstants.VIS_TYPE_KEY, - VisualizationFrameworkConstants.ENTITY_COMPARISON_VIS); + queryResult.addEntry(fieldLabelToOutputFieldLabel.get("organization"), organizationNode.toString()); - return UrlBuilder.getUrl( + String individualLocalName = UtilityFunctions.getIndividualLocalName(organizationNode.toString(), vitroRequest); + + if (StringUtils.isNotBlank(individualLocalName)) { + + topLevelURL = UrlBuilder.getUrl(VisualizationFrameworkConstants.SHORT_URL_VISUALIZATION_REQUEST_PREFIX) + + "/" + VisualizationFrameworkConstants.PUBLICATION_TEMPORAL_VIS_SHORT_URL + + "/" + individualLocalName; + } else { + + ParamMap highestLevelOrganizationTemporalGraphVisURLParams = new ParamMap( + VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY, + organizationNode.toString(), + VisualizationFrameworkConstants.VIS_TYPE_KEY, + VisualizationFrameworkConstants.ENTITY_COMPARISON_VIS); + + topLevelURL = UrlBuilder.getUrl( VisualizationFrameworkConstants.FREEMARKERIZED_VISUALIZATION_URL_PREFIX, highestLevelOrganizationTemporalGraphVisURLParams); - - - } - - RDFNode organizationLabelNode = solution.get( - fieldLabelToOutputFieldLabel - .get("organizationLabel")); - - if (organizationLabelNode != null) { - queryResult.addEntry(fieldLabelToOutputFieldLabel.get("organizationLabel"), - organizationLabelNode.toString()); - } - - RDFNode numberOfChildrenNode = solution.getLiteral("numOfChildren"); - - if (numberOfChildrenNode != null) { - queryResult.addEntry("numOfChildren", - String.valueOf(numberOfChildrenNode.asLiteral().getInt())); - } - } - - return ""; - } - - private GenericQueryMap getNumberOfGrantsForIndividual(ResultSet resultSet) { - GenericQueryMap queryResult = new GenericQueryMap(); - - - while (resultSet.hasNext()) { - QuerySolution solution = resultSet.nextSolution(); - - RDFNode numberOfGrantsNode = solution.getLiteral("numOfGrants"); - - if (numberOfGrantsNode != null) { - queryResult.addEntry("numOfGrants", - String.valueOf(numberOfGrantsNode.asLiteral().getInt())); - } - } - - return queryResult; - } - - - private GenericQueryMap getNumberOfPublicationsForIndividual(ResultSet resultSet) { - - GenericQueryMap queryResult = new GenericQueryMap(); - - - while (resultSet.hasNext()) { - QuerySolution solution = resultSet.nextSolution(); - - RDFNode numberOfPublicationsNode = solution.getLiteral("numOfPublications"); - - if (numberOfPublicationsNode != null) { - queryResult.addEntry( - "numOfPublications", - String.valueOf(numberOfPublicationsNode.asLiteral().getInt())); } + } else { + RDFNode organizationLabelNode = qs.get(fieldLabelToOutputFieldLabel.get("organizationLabel")); + + if (organizationLabelNode != null) { + queryResult.addEntry(fieldLabelToOutputFieldLabel.get("organizationLabel"), organizationLabelNode.toString()); + } + + RDFNode numberOfChildrenNode = qs.getLiteral("numOfChildren"); + + if (numberOfChildrenNode != null) { + queryResult.addEntry("numOfChildren", + String.valueOf(numberOfChildrenNode.asLiteral().getInt())); + } + } + } + + public String getTopLevelURL() { + return topLevelURL == null ? "" : topLevelURL; + } + } + + private static class NumGrantsForIndividualConsumer extends ResultSetConsumer { + GenericQueryMap queryResult = new GenericQueryMap(); + + @Override + protected void processQuerySolution(QuerySolution qs) { + RDFNode numberOfGrantsNode = qs.getLiteral("numOfGrants"); + + if (numberOfGrantsNode != null) { + queryResult.addEntry("numOfGrants", String.valueOf(numberOfGrantsNode.asLiteral().getInt())); + } + + } + + public GenericQueryMap getMap() { + return queryResult; + } + } + + private static class NumPubsForIndividualConsumer extends ResultSetConsumer { + GenericQueryMap queryResult = new GenericQueryMap(); + + @Override + protected void processQuerySolution(QuerySolution qs) { + RDFNode numberOfPublicationsNode = qs.getLiteral("numOfPublications"); + + if (numberOfPublicationsNode != null) { + queryResult.addEntry("numOfPublications", String.valueOf(numberOfPublicationsNode.asLiteral().getInt())); + } + + } + + public GenericQueryMap getMap() { + return queryResult; + } + } + + private static class ThumbnailInformationConsumer extends ResultSetConsumer { + private VitroRequest vitroRequest; + private Map fieldLabelToOutputFieldLabel; + private String finalThumbNailLocation = ""; + + ThumbnailInformationConsumer(VitroRequest vitroRequest, Map fieldLabelToOutputFieldLabel) { + this.vitroRequest = vitroRequest; + this.fieldLabelToOutputFieldLabel = fieldLabelToOutputFieldLabel; + } + + @Override + protected void processQuerySolution(QuerySolution qs) { + RDFNode downloadLocationNode = qs.get( + fieldLabelToOutputFieldLabel + .get("downloadLocation")); + RDFNode fileNameNode = qs.get(fieldLabelToOutputFieldLabel.get("fileName")); + + if (downloadLocationNode != null && fileNameNode != null) { + finalThumbNailLocation = + FileServingHelper + .getBytestreamAliasUrl(downloadLocationNode.toString(), + fileNameNode.toString(), + vitroRequest.getSession().getServletContext()); + } + } + + public String getInformation() { + return finalThumbNailLocation; } - - return queryResult; } - private String getThumbnailInformation(ResultSet resultSet, Map fieldLabelToOutputFieldLabel, VitroRequest vitroRequest) { @@ -457,18 +488,6 @@ public class UtilitiesRequestHandler implements VisualizationRequestHandler { QuerySolution solution = resultSet.nextSolution(); - RDFNode downloadLocationNode = solution.get( - fieldLabelToOutputFieldLabel - .get("downloadLocation")); - RDFNode fileNameNode = solution.get(fieldLabelToOutputFieldLabel.get("fileName")); - - if (downloadLocationNode != null && fileNameNode != null) { - finalThumbNailLocation = - FileServingHelper - .getBytestreamAliasUrl(downloadLocationNode.toString(), - fileNameNode.toString(), - vitroRequest.getSession().getServletContext()); - } } return finalThumbNailLocation; } diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/visutils/AllPropertiesQueryRunner.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/visutils/AllPropertiesQueryRunner.java index df27c229..c8b0b07b 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/visutils/AllPropertiesQueryRunner.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/visutils/AllPropertiesQueryRunner.java @@ -2,6 +2,9 @@ package edu.cornell.mannlib.vitro.webapp.visualization.visutils; +import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService; +import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceException; +import edu.cornell.mannlib.vitro.webapp.rdfservice.ResultSetConsumer; import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -37,53 +40,22 @@ public class AllPropertiesQueryRunner implements QueryRunner { protected static final Syntax SYNTAX = Syntax.syntaxARQ; private String filterRule, individualURI; - private Dataset dataset; + private RDFService rdfService; private Log log = LogFactory.getLog(AllPropertiesQueryRunner.class.getName()); public AllPropertiesQueryRunner(String individualURI, String filterRule, - Dataset dataset, + RDFService rdfService, Log log) { this.individualURI = individualURI; this.filterRule = filterRule; - this.dataset = dataset; + this.rdfService = rdfService; this.log = log; } - private GenericQueryMap createJavaValueObjects(ResultSet resultSet) { - - GenericQueryMap queryResult = new GenericQueryMap(); - - while (resultSet.hasNext()) { - QuerySolution solution = resultSet.nextSolution(); - - - RDFNode predicateNode = solution.get(QueryFieldLabels.PREDICATE); - RDFNode objectNode = solution.get(QueryFieldLabels.OBJECT); - - if (predicateNode != null && objectNode != null) { - queryResult.addEntry(predicateNode.toString(), - objectNode.toString()); - } - - } - - return queryResult; - } - - private ResultSet executeQuery(String queryText, - Dataset dataset) { - - QueryExecution queryExecution = null; - Query query = QueryFactory.create(queryText, SYNTAX); - - queryExecution = QueryExecutionFactory.create(query, dataset); - return queryExecution.execSelect(); - } - private String generateGenericSparqlQuery(String queryURI, String filterRule) { // Resource uri1 = ResourceFactory.createResource(queryURI); String filterClause; @@ -130,11 +102,35 @@ public class AllPropertiesQueryRunner implements QueryRunner { throw new MalformedQueryParametersException("URI parameter is either null or empty."); } - ResultSet resultSet = executeQuery(generateGenericSparqlQuery( - this.individualURI, - this.filterRule), - this.dataset); + CreateJavaVOConsumer consumer = new CreateJavaVOConsumer(); + try { + rdfService.sparqlSelectQuery(generateGenericSparqlQuery( + this.individualURI, + this.filterRule), + consumer); + } catch (RDFServiceException e) { + log.error("Unable to execute query", e); + throw new MalformedQueryParametersException(e); + } + return consumer.getMap(); + } - return createJavaValueObjects(resultSet); + private class CreateJavaVOConsumer extends ResultSetConsumer { + GenericQueryMap queryResult = new GenericQueryMap(); + + @Override + protected void processQuerySolution(QuerySolution qs) { + RDFNode predicateNode = qs.get(QueryFieldLabels.PREDICATE); + RDFNode objectNode = qs.get(QueryFieldLabels.OBJECT); + + if (predicateNode != null && objectNode != null) { + queryResult.addEntry(predicateNode.toString(), + objectNode.toString()); + } + } + + public GenericQueryMap getMap() { + return queryResult; + } } } diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/visutils/GenericQueryRunner.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/visutils/GenericQueryRunner.java index 3c53918b..5214740d 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/visutils/GenericQueryRunner.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/visutils/GenericQueryRunner.java @@ -4,6 +4,9 @@ package edu.cornell.mannlib.vitro.webapp.visualization.visutils; import java.util.Map; +import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService; +import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceException; +import edu.cornell.mannlib.vitro.webapp.rdfservice.ResultSetConsumer; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -101,4 +104,13 @@ public class GenericQueryRunner implements QueryRunner { return resultSet; } + + public void sparqlSelectQuery(RDFService rdfService, ResultSetConsumer consumer) throws MalformedQueryParametersException { + try { + rdfService.sparqlSelectQuery(generateGenericSparqlQuery(), consumer); + } catch (RDFServiceException e) { + log.error("Unable to execute: [" + generateGenericSparqlQuery() + "]", e); + throw new MalformedQueryParametersException(e); + } + } } diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/visutils/SelectOnModelUtilities.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/visutils/SelectOnModelUtilities.java index 213e1820..d810cf39 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/visutils/SelectOnModelUtilities.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/visutils/SelectOnModelUtilities.java @@ -7,6 +7,7 @@ import java.util.HashSet; import java.util.Map; import java.util.Set; +import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService; import org.apache.commons.lang.StringUtils; import com.hp.hpl.jena.query.Dataset; @@ -75,53 +76,6 @@ public class SelectOnModelUtilities { return entityWithSubOrganizations; } - public static Entity getSubjectPersonEntity(Dataset dataset, - String subjectEntityURI) throws MalformedQueryParametersException { - - Map fieldLabelToOutputFieldLabel = new HashMap(); - fieldLabelToOutputFieldLabel.put("authorLabel", QueryFieldLabels.AUTHOR_LABEL); - - String whereClause = "" - + " <" + subjectEntityURI + "> rdfs:label ?authorLabel . "; - - QueryRunner personQuery = - new GenericQueryRunner(fieldLabelToOutputFieldLabel, - "", - whereClause, - "", - dataset); - - Entity personEntity = new Entity(subjectEntityURI); - - ResultSet queryResult = personQuery.getQueryResult(); - - while (queryResult.hasNext()) { - - QuerySolution solution = queryResult.nextSolution(); - - RDFNode personLabelNode = solution.get(QueryFieldLabels.AUTHOR_LABEL); - if (personLabelNode != null) { - personEntity.setEntityLabel(personLabelNode.toString()); - } - - } - - /* - * We are adding A person as it's own subentity in order to make our code for geenrating csv, json - * & other data as streamlined as possible between entities of type Organization & Person. - * */ - SubEntity subEntity = new SubEntity(subjectEntityURI, personEntity.getEntityLabel()); - subEntity.setEntityClass(VOConstants.EntityClassType.PERSON); - - personEntity.addSubEntity(subEntity); - -// Entity entityWithParentOrganizations = getAllParentOrganizations(dataset, subjectEntityURI); -// -// personEntity.addParents(entityWithParentOrganizations.getParents()); - - return personEntity; - } - public static Entity getAllParentOrganizations(Dataset dataset, String subjectEntityURI) throws MalformedQueryParametersException { Model organizationModel = ModelConstructorUtilities @@ -757,7 +711,7 @@ public class SelectOnModelUtilities { } public static Map getGrantsForPerson( - Dataset dataset, SubEntity person, boolean doCache) + RDFService rdfService, SubEntity person, boolean doCache) throws MalformedQueryParametersException { Map allGrantURIToVOs = new HashMap(); @@ -775,10 +729,10 @@ public class SelectOnModelUtilities { .getOrConstructModel( person.getIndividualURI(), PersonToGrantsModelConstructor.MODEL_TYPE, - dataset); + rdfService); } else { - ModelConstructor model = new PersonToGrantsModelConstructor(person.getIndividualURI(), dataset); + ModelConstructor model = new PersonToGrantsModelConstructor(person.getIndividualURI(), rdfService); personGrantsModel = model.getConstructedModel(); }