From d1f8bdc7c1067083633708ffd40a1b0cf488e7aa Mon Sep 17 00:00:00 2001 From: tankchintan Date: Fri, 22 Jul 2011 22:53:15 +0000 Subject: [PATCH] 1. Removing dead code belonging to uncached version for temporal graphs. --- .../visualizations-beans-injection-fm.xml | 10 +- ...yPublicationCountConstructQueryRunner.java | 275 ------------ .../EntityPublicationCountQueryRunner.java | 263 ------------ .../EntityPublicationCountRequestHandler.java | 362 ---------------- ...OrganizationTypesConstructQueryRunner.java | 177 -------- ...EntitySubOrganizationTypesQueryRunner.java | 189 --------- .../OrganizationUtilityFunctions.java | 25 -- ...poralGrantVisualizationRequestHandler.java | 3 +- ...ublicationVisualizationRequestHandler.java | 3 +- .../EntityGrantCountConstructQueryRunner.java | 390 ------------------ .../EntityGrantCountQueryRunner.java | 334 --------------- .../EntityGrantCountRequestHandler.java | 357 ---------------- 12 files changed, 4 insertions(+), 2384 deletions(-) delete mode 100644 src/edu/cornell/mannlib/vitro/webapp/visualization/entitycomparison/EntityPublicationCountConstructQueryRunner.java delete mode 100644 src/edu/cornell/mannlib/vitro/webapp/visualization/entitycomparison/EntityPublicationCountQueryRunner.java delete mode 100644 src/edu/cornell/mannlib/vitro/webapp/visualization/entitycomparison/EntityPublicationCountRequestHandler.java delete mode 100644 src/edu/cornell/mannlib/vitro/webapp/visualization/entitycomparison/EntitySubOrganizationTypesConstructQueryRunner.java delete mode 100644 src/edu/cornell/mannlib/vitro/webapp/visualization/entitycomparison/EntitySubOrganizationTypesQueryRunner.java rename src/edu/cornell/mannlib/vitro/webapp/visualization/entitycomparison/{cached => }/TemporalGrantVisualizationRequestHandler.java (96%) rename src/edu/cornell/mannlib/vitro/webapp/visualization/entitycomparison/{cached => }/TemporalPublicationVisualizationRequestHandler.java (96%) delete mode 100644 src/edu/cornell/mannlib/vitro/webapp/visualization/entitygrantcount/EntityGrantCountConstructQueryRunner.java delete mode 100644 src/edu/cornell/mannlib/vitro/webapp/visualization/entitygrantcount/EntityGrantCountQueryRunner.java delete mode 100644 src/edu/cornell/mannlib/vitro/webapp/visualization/entitygrantcount/EntityGrantCountRequestHandler.java diff --git a/productMods/WEB-INF/visualization/visualizations-beans-injection-fm.xml b/productMods/WEB-INF/visualization/visualizations-beans-injection-fm.xml index 6fe1234f..f27ef1eb 100644 --- a/productMods/WEB-INF/visualization/visualizations-beans-injection-fm.xml +++ b/productMods/WEB-INF/visualization/visualizations-beans-injection-fm.xml @@ -28,17 +28,11 @@ - - - - + class="edu.cornell.mannlib.vitro.webapp.visualization.entitycomparison.TemporalPublicationVisualizationRequestHandler" /> + class="edu.cornell.mannlib.vitro.webapp.visualization.entitycomparison.TemporalGrantVisualizationRequestHandler" /> diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/entitycomparison/EntityPublicationCountConstructQueryRunner.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/entitycomparison/EntityPublicationCountConstructQueryRunner.java deleted file mode 100644 index c9cf3838..00000000 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/entitycomparison/EntityPublicationCountConstructQueryRunner.java +++ /dev/null @@ -1,275 +0,0 @@ -/* $This file is distributed under the terms of the license in /doc/license.txt$ */ -package edu.cornell.mannlib.vitro.webapp.visualization.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.Dataset; -import com.hp.hpl.jena.query.Query; -import com.hp.hpl.jena.query.QueryExecution; -import com.hp.hpl.jena.query.QueryExecutionFactory; -import com.hp.hpl.jena.query.QueryFactory; -import com.hp.hpl.jena.query.Syntax; -import com.hp.hpl.jena.rdf.model.Model; -import com.hp.hpl.jena.rdf.model.ModelFactory; - -import edu.cornell.mannlib.vitro.webapp.visualization.constants.QueryConstants; -import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException; -import edu.cornell.mannlib.vitro.webapp.visualization.visutils.ModelConstructor; - -public class EntityPublicationCountConstructQueryRunner implements ModelConstructor { - - protected static final Syntax SYNTAX = Syntax.syntaxARQ; - - private String egoURI; - - private Dataset dataset; - - private Log log = LogFactory.getLog(EntityPublicationCountConstructQueryRunner.class.getName()); - - private long before, after; - - public EntityPublicationCountConstructQueryRunner(String egoURI, Dataset dataset, Log log) { - this.egoURI = egoURI; - this.dataset = dataset; - //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 . " - + "?Document core:dateTimeValue ?dateTimeValue . " - + "?dateTimeValue core:dateTime ?publicationDate . " - + "}" - + "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 rdfs:label ?DocumentLabel " - + "}" - + "UNION " - + "{" - + "?Document core:dateTimeValue ?dateTimeValue . " - + "?dateTimeValue core:dateTime ?publicationDate " - + "}" - + "}"; - - 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 . " - + "?Document core:dateTimeValue ?dateTimeValue . " - + "?dateTimeValue core:dateTime ?publicationDate . " - + "}" - + "WHERE { " - + "{" - + "<" + queryURI + "> core:organizationForPosition ?Position . " - + "?Position core:positionForPerson ?Person . " - + "?Person core:authorInAuthorship ?Resource . " - + "?Person rdfs:label ?PersonLabel . " - + "?Resource core:linkedInformationResource ?Document . " - + "?Document rdfs:label ?DocumentLabel " - + "}" - + "UNION" - + "{" - + "?Document core:dateTimeValue ?dateTimeValue . " - + "?dateTimeValue core:dateTime ?publicationDate " - + "}" - + "}"; - - 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, Dataset dataset) { - - Model constructedModel = ModelFactory.createDefaultModel(); - - for (String queryString : constructQueries) { - before = System.currentTimeMillis(); - log.debug("CONSTRUCT query string : " + queryString); - - Query query = null; - - try { - query = QueryFactory.create(QueryConstants.getSparqlPrefixQuery() - + queryString, SYNTAX); - } catch (Throwable th) { - log.error("Could not create CONSTRUCT SPARQL query for query " - + "string. " + th.getMessage()); - log.error(queryString); - } - - QueryExecution qe = QueryExecutionFactory.create( - query, dataset); - - try { - qe.execConstruct(constructedModel); - } finally { - qe.close(); - } - - after = System.currentTimeMillis(); - log.debug("Time taken to execute the CONSTRUCT queries is in milliseconds: " - + (after - before)); - } - 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.dataset); - - 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/entitycomparison/EntityPublicationCountQueryRunner.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/entitycomparison/EntityPublicationCountQueryRunner.java deleted file mode 100644 index b7b28467..00000000 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/entitycomparison/EntityPublicationCountQueryRunner.java +++ /dev/null @@ -1,263 +0,0 @@ -/* $This file is distributed under the terms of the license in /doc/license.txt$ */ - -package edu.cornell.mannlib.vitro.webapp.visualization.entitycomparison; - -import java.util.HashMap; -import java.util.Map; - -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.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.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; -import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException; -import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.Activity; -import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.Entity; -import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.SubEntity; -import edu.cornell.mannlib.vitro.webapp.visualization.visutils.QueryRunner; - - -/** - * This query runner is used to execute a sparql query that will fetch all the - * publications defined by bibo:Document property for a particular - * department/school/university. - * - * Deepak Konidena. - * @author bkoniden - */ -public class EntityPublicationCountQueryRunner implements QueryRunner { - - protected static final Syntax SYNTAX = Syntax.syntaxARQ; - - private String entityURI; - private Model dataSource; - private Log log = LogFactory.getLog(EntityPublicationCountQueryRunner.class.getName()); - private long before, after; - - private static final String SPARQL_QUERY_COMMON_SELECT_CLAUSE = "" - + " (str(?Person) as ?personLit) " - + " (str(?PersonLabel) as ?personLabelLit) " - + " (str(?Document) as ?documentLit) " - + " (str(?DocumentLabel) as ?documentLabelLit) " - + " (str(?publicationDate) as ?" + QueryFieldLabels.DOCUMENT_PUBLICATION_DATE + ")"; - - - private static final String SPARQL_QUERY_COMMON_WHERE_CLAUSE = "" - + "?Document rdf:type bibo:Document ;" - + " rdfs:label ?DocumentLabel ." - + "OPTIONAL { ?Document core:dateTimeValue ?dateTimeValue . " - + " ?dateTimeValue core:dateTime ?publicationDate } ." - + "OPTIONAL { ?Document core:year ?publicationYearUsing_1_1_property } ."; - - private static final String ENTITY_LABEL = QueryFieldLabels.ORGANIZATION_LABEL; - private static final String ENTITY_URL = QueryFieldLabels.ORGANIZATION_URL; - private static final String SUBENTITY_LABEL = QueryFieldLabels.SUBORGANIZATION_LABEL; - private static final String SUBENTITY_URL = QueryFieldLabels.SUBORGANIZATION_URL; - - public EntityPublicationCountQueryRunner(String entityURI, - Model dataSource, Log log) { - - this.entityURI = entityURI; - this.dataSource = dataSource; -// this.log = log; - - } - - private Entity createJavaValueObjects(ResultSet resultSet) { - - Entity entity = null; - Map biboDocumentURLToVO = new HashMap(); - Map subentityURLToVO = new HashMap(); - Map personURLToVO = new HashMap(); - - before = System.currentTimeMillis(); - - while (resultSet.hasNext()) { - - QuerySolution solution = resultSet.nextSolution(); - - if (entity == null) { - entity = new Entity(solution.get(ENTITY_URL).toString(), - solution.get(ENTITY_LABEL).toString()); - } - - RDFNode documentNode = solution.get(QueryFieldLabels.DOCUMENT_URL); - Activity biboDocument; - - if (biboDocumentURLToVO.containsKey(documentNode.toString())) { - biboDocument = biboDocumentURLToVO.get(documentNode.toString()); - - } else { - - biboDocument = new Activity(documentNode.toString()); - biboDocumentURLToVO.put(documentNode.toString(), biboDocument); - - RDFNode publicationDateNode = solution.get(QueryFieldLabels - .DOCUMENT_PUBLICATION_DATE); - if (publicationDateNode != null) { - biboDocument.setActivityDate(publicationDateNode.toString()); - } - - } - - RDFNode subEntityURLNode = solution.get(SUBENTITY_URL); - - if (subEntityURLNode != null) { - SubEntity subEntity; - if (subentityURLToVO.containsKey(subEntityURLNode.toString())) { - subEntity = subentityURLToVO.get(subEntityURLNode - .toString()); - } else { - subEntity = new SubEntity(subEntityURLNode.toString()); - subentityURLToVO - .put(subEntityURLNode.toString(), subEntity); - } - - RDFNode subEntityLabelNode = solution.get(SUBENTITY_LABEL); - if (subEntityLabelNode != null) { - subEntity.setIndividualLabel(subEntityLabelNode.toString()); - } - - entity.addSubEntity(subEntity); - - subEntity.addActivity(biboDocument); - } - - RDFNode personURLNode = solution.get(QueryFieldLabels.PERSON_URL); - - if (personURLNode != null) { - SubEntity person; - - if (personURLToVO.containsKey(personURLNode.toString())) { - person = personURLToVO.get(personURLNode.toString()); - } else { - person = new SubEntity(personURLNode.toString()); - personURLToVO.put(personURLNode.toString(), person); - } - - RDFNode personLabelNode = solution.get(QueryFieldLabels.PERSON_LABEL); - if (personLabelNode != null) { - person.setIndividualLabel(personLabelNode.toString()); - } - - /* - * This makes sure that either, - * 1. the parent organization is a department-like organization with no - * organizations beneath it, or - * 2. the parent organizations has both sub-organizations and people directly - * attached to that organizations e.g. president of a university. - * */ - if (subEntityURLNode == null) { - - entity.addSubEntity(person); - - } - - person.addActivity(biboDocument); - - } - -// entity.addActivity(biboDocument); - } - - if (subentityURLToVO.size() == 0 && personURLToVO.size() == 0) { - - entity = new Entity(this.entityURI, "no-label"); - - } - - after = System.currentTimeMillis(); - log.debug("Time taken to iterate through the ResultSet of SELECT queries is in ms: " - + (after - before)); - - return entity; - } - - private ResultSet executeQuery(String queryURI, Model dataSource) { - - QueryExecution queryExecution = null; - Query query = QueryFactory.create( - getSparqlQueryForOrganization(queryURI), SYNTAX); - queryExecution = QueryExecutionFactory.create(query, dataSource); - return queryExecution.execSelect(); - } - - private String getSparqlQueryForOrganization(String queryURI) { - - String sparqlQuery = QueryConstants.getSparqlPrefixQuery() - + "SELECT (str(?organizationLabel) as ?organizationLabelLit) " - + " (str(?subOrganization) as ?subOrganizationLit) " - + " (str(?subOrganizationLabel) as ?subOrganizationLabelLit) " - + SPARQL_QUERY_COMMON_SELECT_CLAUSE + " (str(<" + queryURI - + ">) as ?" + ENTITY_URL + ") " - + "WHERE { " + "<" + queryURI + "> rdfs:label ?organizationLabel ." - + "{ " - + "<" + queryURI + "> core:hasSubOrganization ?subOrganization ." - + "?subOrganization rdfs:label ?subOrganizationLabel ;" - + " core:organizationForPosition ?Position . " - + " ?Position core:positionForPerson ?Person ." - + " ?Person core:authorInAuthorship ?Resource ; rdfs:label ?PersonLabel . " - + " ?Resource core:linkedInformationResource ?Document . " - + SPARQL_QUERY_COMMON_WHERE_CLAUSE + "}" - + "UNION " - + "{ " - + "<" + queryURI + "> core:organizationForPosition ?Position ." - + " ?Position core:positionForPerson ?Person ." - + " ?Person core:authorInAuthorship ?Resource ; rdfs:label ?PersonLabel . " - + " ?Resource core:linkedInformationResource ?Document ." - + SPARQL_QUERY_COMMON_WHERE_CLAUSE + "}" - + "}"; - - log.debug("\nThe sparql query is :\n" + sparqlQuery); - return sparqlQuery; - - } - - public Entity getQueryResult() throws MalformedQueryParametersException { - - if (StringUtils.isNotBlank(this.entityURI)) { - /* - * To test for the validity of the URI submitted. - */ - IRIFactory iRIFactory = IRIFactory.jenaImplementation(); - IRI iri = iRIFactory.create(this.entityURI); - if (iri.hasViolation(false)) { - String errorMsg = ((Violation) iri.violations(false).next()) - .getShortMessage(); - log.error("Entity Pub Count Query " + errorMsg); - throw new MalformedQueryParametersException( - "URI provided for an entity is malformed."); - } - - } else { - throw new MalformedQueryParametersException( - "URL parameter is either null or empty."); - } - - before = System.currentTimeMillis(); - - ResultSet resultSet = executeQuery(this.entityURI, this.dataSource); - - after = System.currentTimeMillis(); - - log.debug("Time taken to execute the SELECT queries is in milliseconds: " - + (after - before)); - - return createJavaValueObjects(resultSet); - } -} \ No newline at end of file diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/entitycomparison/EntityPublicationCountRequestHandler.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/entitycomparison/EntityPublicationCountRequestHandler.java deleted file mode 100644 index 3af9f5c1..00000000 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/entitycomparison/EntityPublicationCountRequestHandler.java +++ /dev/null @@ -1,362 +0,0 @@ -/* $This file is distributed under the terms of the license in /doc/license.txt$ */ - -package edu.cornell.mannlib.vitro.webapp.visualization.entitycomparison; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.apache.commons.lang.StringEscapeUtils; -import org.apache.commons.lang.StringUtils; -import org.apache.commons.logging.Log; - -import com.google.gson.Gson; -import com.hp.hpl.jena.query.Dataset; -import com.hp.hpl.jena.rdf.model.Model; - -import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.Actions; -import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; -import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ResponseValues; -import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.TemplateResponseValues; -import edu.cornell.mannlib.vitro.webapp.controller.visualization.DataVisualizationController; -import edu.cornell.mannlib.vitro.webapp.controller.visualization.VisualizationFrameworkConstants; -import edu.cornell.mannlib.vitro.webapp.visualization.constants.VOConstants; -import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException; -import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.Entity; -import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.SubEntity; -import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.json.JsonObject; -import edu.cornell.mannlib.vitro.webapp.visualization.visutils.ModelConstructor; -import edu.cornell.mannlib.vitro.webapp.visualization.visutils.QueryRunner; -import edu.cornell.mannlib.vitro.webapp.visualization.visutils.UtilityFunctions; -import edu.cornell.mannlib.vitro.webapp.visualization.visutils.VisualizationRequestHandler; - -public class EntityPublicationCountRequestHandler implements - VisualizationRequestHandler { - - @Override - public ResponseValues generateStandardVisualization( - VitroRequest vitroRequest, Log log, Dataset dataset) - throws MalformedQueryParametersException { - - String entityURI = vitroRequest - .getParameter(VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY); - - return generateStandardVisualizationForPublicationTemporalVis( - vitroRequest, log, dataset, entityURI); - } - - private ResponseValues generateStandardVisualizationForPublicationTemporalVis( - VitroRequest vitroRequest, Log log, Dataset dataset, - String entityURI) throws MalformedQueryParametersException { - - if (StringUtils.isBlank(entityURI)) { - - entityURI = OrganizationUtilityFunctions - .getStaffProvidedOrComputedHighestLevelOrganization(log, - dataset, vitroRequest); - - } - - return prepareStandaloneMarkupResponse(vitroRequest, entityURI); - - } - - @Override - public ResponseValues generateVisualizationForShortURLRequests( - Map parameters, VitroRequest vitroRequest, Log log, - Dataset dataSource) throws MalformedQueryParametersException { - - return generateStandardVisualizationForPublicationTemporalVis( - vitroRequest, - log, - dataSource, - parameters - .get(VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY)); - - } - - private Map getSubjectEntityAndGenerateDataResponse( - VitroRequest vitroRequest, Log log, Dataset dataset, - String subjectEntityURI) throws MalformedQueryParametersException { - - ModelConstructor constructQueryRunner = new EntityPublicationCountConstructQueryRunner( - subjectEntityURI, dataset, log); - - Model constructedModel = constructQueryRunner.getConstructedModel(); - - QueryRunner queryManager = new EntityPublicationCountQueryRunner( - subjectEntityURI, constructedModel, log); - - Entity entity = queryManager.getQueryResult(); - - if (entity.getEntityLabel().equals("no-label")) { - - return prepareStandaloneDataErrorResponse(vitroRequest, - subjectEntityURI); - - } else { - - return getSubEntityTypesAndComputeDataResponse(vitroRequest, log, - dataset, subjectEntityURI, entity); - } - } - - private Map prepareStandaloneDataErrorResponse( - VitroRequest vitroRequest, String subjectEntityURI) { - - Map fileData = new HashMap(); - - fileData.put(DataVisualizationController.FILE_CONTENT_TYPE_KEY, - "application/octet-stream"); - fileData - .put(DataVisualizationController.FILE_CONTENT_KEY, - "{\"error\" : \"No Publications for this Organization found in VIVO.\"}"); - return fileData; - } - - private Map getSubEntityTypesAndComputeDataResponse( - VitroRequest vitroRequest, Log log, Dataset dataset, - String subjectEntityURI, Entity entity) - throws MalformedQueryParametersException { - - Map> subOrganizationTypesResult = OrganizationUtilityFunctions - .getSubEntityTypes(log, dataset, subjectEntityURI); - - return prepareStandaloneDataResponse(vitroRequest, entity, entity - .getSubEntities(), subOrganizationTypesResult); - } - - @Override - public Map generateDataVisualization( - VitroRequest vitroRequest, Log log, Dataset dataset) - throws MalformedQueryParametersException { - - String entityURI = vitroRequest - .getParameter(VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY); - - /* - * This will provide the data in json format mainly used for standalone - * tmeporal vis. - */ - if (VisualizationFrameworkConstants.JSON_OUTPUT_FORMAT - .equalsIgnoreCase(vitroRequest - .getParameter(VisualizationFrameworkConstants.VIS_MODE_KEY))) { - - if (StringUtils.isNotBlank(entityURI)) { - - return getSubjectEntityAndGenerateDataResponse(vitroRequest, - log, dataset, entityURI); - } else { - - return getSubjectEntityAndGenerateDataResponse( - vitroRequest, - log, - dataset, - OrganizationUtilityFunctions - .getStaffProvidedOrComputedHighestLevelOrganization( - log, dataset, vitroRequest)); - } - - } else { - /* - * This provides csv download files for the content in the tables. - */ - - ModelConstructor constructQueryRunner = new EntityPublicationCountConstructQueryRunner( - entityURI, dataset, log); - - Model constructedModel = constructQueryRunner.getConstructedModel(); - - QueryRunner queryManager = new EntityPublicationCountQueryRunner( - entityURI, constructedModel, log); - - Entity entity = queryManager.getQueryResult(); - - Map> subOrganizationTypesResult = OrganizationUtilityFunctions - .getSubEntityTypes(log, dataset, entityURI); - - return prepareDataResponse(entity, entity.getSubEntities(), - subOrganizationTypesResult); - - } - - } - - @Override - public Object generateAjaxVisualization(VitroRequest vitroRequest, Log log, - Dataset dataset) throws MalformedQueryParametersException { - throw new UnsupportedOperationException( - "Entity Pub Count does not provide Ajax Response."); - } - - /** - * Provides response when json file containing the publication count over - * the years is requested. - * - * @param entity - * @param subentities - * @param subOrganizationTypesResult - */ - private Map prepareDataResponse(Entity entity, - Set subentities, - Map> subOrganizationTypesResult) { - - String entityLabel = entity.getEntityLabel(); - - /* - * To make sure that null/empty records for entity names do not cause - * any mischief. - */ - if (StringUtils.isBlank(entityLabel)) { - entityLabel = "no-organization"; - } - - String outputFileName = UtilityFunctions.slugify(entityLabel) - + "_publications-per-year" + ".csv"; - - Map fileData = new HashMap(); - - fileData.put(DataVisualizationController.FILE_NAME_KEY, outputFileName); - fileData.put(DataVisualizationController.FILE_CONTENT_TYPE_KEY, - "application/octet-stream"); - fileData.put(DataVisualizationController.FILE_CONTENT_KEY, - getEntityPublicationsPerYearCSVContent(subentities, - subOrganizationTypesResult)); - return fileData; - } - - private Map prepareStandaloneDataResponse( - VitroRequest vitroRequest, Entity entity, - Set subentities, - Map> subOrganizationTypesResult) - throws MalformedQueryParametersException { - - Map fileData = new HashMap(); - - fileData.put(DataVisualizationController.FILE_CONTENT_TYPE_KEY, - "application/octet-stream"); - fileData.put(DataVisualizationController.FILE_CONTENT_KEY, - writePublicationsOverTimeJSON(vitroRequest, entity - .getSubEntities(), subOrganizationTypesResult)); - return fileData; - } - - private TemplateResponseValues prepareStandaloneMarkupResponse( - VitroRequest vreq, String entityURI) { - - String standaloneTemplate = "entityComparisonOnPublicationsStandalone.ftl"; - - String organizationLabel = OrganizationUtilityFunctions - .getEntityLabelFromDAO(vreq, entityURI); - - Map body = new HashMap(); - body - .put("title", organizationLabel - + " - Temporal Graph Visualization"); - body.put("organizationURI", entityURI); - body.put("organizationLocalName", UtilityFunctions - .getIndividualLocalName(entityURI, vreq)); - body.put("vivoDefaultNamespace", vreq.getWebappDaoFactory() - .getDefaultNamespace()); - body.put("organizationLabel", organizationLabel); - - return new TemplateResponseValues(standaloneTemplate, body); - } - - /** - * Function to generate a json file for year <-> publication count mapping. - * - * @param vreq - * @param subentities - * @param subOrganizationTypesResult - * @throws MalformedQueryParametersException - */ - private String writePublicationsOverTimeJSON(VitroRequest vreq, - Set subentities, - Map> subOrganizationTypesResult) - throws MalformedQueryParametersException { - - Gson json = new Gson(); - Set subEntitiesJson = new HashSet(); - - for (SubEntity subentity : subentities) { - JsonObject entityJson = new JsonObject(subentity - .getIndividualLabel()); - - List> yearPubCount = new ArrayList>(); - - for (Map.Entry pubEntry : UtilityFunctions - .getYearToActivityCount(subentity.getActivities()) - .entrySet()) { - - List currentPubYear = new ArrayList(); - if (pubEntry.getKey().equals( - VOConstants.DEFAULT_PUBLICATION_YEAR)) { - currentPubYear.add(-1); - } else { - currentPubYear.add(Integer.parseInt(pubEntry.getKey())); - } - - currentPubYear.add(pubEntry.getValue()); - yearPubCount.add(currentPubYear); - } - - entityJson.setYearToActivityCount(yearPubCount); - entityJson.getOrganizationTypes().addAll( - subOrganizationTypesResult.get(entityJson.getLabel())); - - entityJson.setEntityURI(subentity.getIndividualURI()); - - boolean isPerson = UtilityFunctions.isEntityAPerson(vreq, subentity - .getIndividualURI()); - - if (isPerson) { - entityJson.setVisMode("PERSON"); - } else { - entityJson.setVisMode("ORGANIZATION"); - } - subEntitiesJson.add(entityJson); - } - return json.toJson(subEntitiesJson); - } - - private String getEntityPublicationsPerYearCSVContent( - Set subentities, - Map> subOrganizationTypesResult) { - - StringBuilder csvFileContent = new StringBuilder(); - - csvFileContent.append("Entity Name, Publication Count, Entity Type\n"); - - for (SubEntity subEntity : subentities) { - - csvFileContent.append(StringEscapeUtils.escapeCsv(subEntity - .getIndividualLabel())); - csvFileContent.append(", "); - csvFileContent.append(subEntity.getActivities().size()); - csvFileContent.append(", "); - - StringBuilder joinedTypes = new StringBuilder(); - - for (String subOrganizationType : subOrganizationTypesResult - .get(subEntity.getIndividualLabel())) { - joinedTypes.append(subOrganizationType + "; "); - } - - csvFileContent.append(StringEscapeUtils.escapeCsv(joinedTypes - .toString())); - csvFileContent.append("\n"); - } - return csvFileContent.toString(); - } - - @Override - public Actions getRequiredPrivileges() { - // TODO Auto-generated method stub - return null; - } - -} \ No newline at end of file diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/entitycomparison/EntitySubOrganizationTypesConstructQueryRunner.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/entitycomparison/EntitySubOrganizationTypesConstructQueryRunner.java deleted file mode 100644 index 48cee0e1..00000000 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/entitycomparison/EntitySubOrganizationTypesConstructQueryRunner.java +++ /dev/null @@ -1,177 +0,0 @@ -/* $This file is distributed under the terms of the license in /doc/license.txt$ */ -package edu.cornell.mannlib.vitro.webapp.visualization.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.Dataset; -import com.hp.hpl.jena.query.Query; -import com.hp.hpl.jena.query.QueryExecution; -import com.hp.hpl.jena.query.QueryExecutionFactory; -import com.hp.hpl.jena.query.QueryFactory; -import com.hp.hpl.jena.query.Syntax; -import com.hp.hpl.jena.rdf.model.Model; -import com.hp.hpl.jena.rdf.model.ModelFactory; - -import edu.cornell.mannlib.vitro.webapp.visualization.constants.QueryConstants; -import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException; -import edu.cornell.mannlib.vitro.webapp.visualization.visutils.ModelConstructor; - -public class EntitySubOrganizationTypesConstructQueryRunner implements ModelConstructor { - - protected static final Syntax SYNTAX = Syntax.syntaxARQ; - - private String egoURI; - - private Dataset dataset; - - private Log log = LogFactory.getLog(EntitySubOrganizationTypesConstructQueryRunner - .class.getName()); - - public EntitySubOrganizationTypesConstructQueryRunner(String egoURI, Dataset dataset, Log log) { - this.egoURI = egoURI; - this.dataset = dataset; - //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 . " - + "?subOrganizationType rdfs:label ?subOrganizationTypeLabel . " - + "?subOrganization core:organizationForPosition ?Position . " - + "?Position core:positionForPerson ?Person . " - + "?Person rdfs:label ?PersonLabel ." - + "?Person rdf:type ?PersonType . " - + "?PersonType rdfs:label ?PersonTypeLabel " - + "}"; - - 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, Dataset dataset) { - - Model constructedModel = ModelFactory.createDefaultModel(); - long before = 0; - - for (String queryString : constructQueries) { - - before = System.currentTimeMillis(); - log.debug("CONSTRUCT query string : " + queryString); - - Query query = null; - - try { - query = QueryFactory.create(QueryConstants.getSparqlPrefixQuery() - + queryString, SYNTAX); - } catch (Throwable th) { - log.error("Could not create CONSTRUCT SPARQL query for query " - + "string. " + th.getMessage()); - log.error(queryString); - } - - QueryExecution qe = QueryExecutionFactory.create( - query, dataset); - try { - qe.execConstruct(constructedModel); - } finally { - qe.close(); - } - - log.debug("Time to run " + (before - System.currentTimeMillis())); - } - - 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.dataset); - //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/entitycomparison/EntitySubOrganizationTypesQueryRunner.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/entitycomparison/EntitySubOrganizationTypesQueryRunner.java deleted file mode 100644 index b9a62279..00000000 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/entitycomparison/EntitySubOrganizationTypesQueryRunner.java +++ /dev/null @@ -1,189 +0,0 @@ -/* $This file is distributed under the terms of the license in /doc/license.txt$ */ -package edu.cornell.mannlib.vitro.webapp.visualization.entitycomparison; - -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -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.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.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.visutils.QueryRunner; - - -/** - * @author bkoniden - * Deepak Konidena - */ -public class EntitySubOrganizationTypesQueryRunner - implements QueryRunner>> { - - protected static final Syntax SYNTAX = Syntax.syntaxARQ; - - private String entityURI; - private Model dataSource; - private Log log = LogFactory.getLog(EntitySubOrganizationTypesQueryRunner.class.getName()); - - private static final String SPARQL_QUERY_SELECT_CLAUSE = "" - + " (str(?organizationLabel) as ?" + QueryFieldLabels.ORGANIZATION_LABEL + ") " - + " (str(?subOrganizationLabel) as ?" + QueryFieldLabels.SUBORGANIZATION_LABEL + ") " - + " (str(?subOrganizationType) as ?" + QueryFieldLabels.SUBORGANIZATION_TYPE + ")" - + " (str(?subOrganizationTypeLabel) as ?" - + QueryFieldLabels.SUBORGANIZATION_TYPE_LABEL + ") " - + " (str(?Person) as ?personLit) " - + " (str(?PersonLabel) as ?personLabelLit) " - + " (str(?PersonTypeLabel) as ?personTypeLabelLit) "; - - - public EntitySubOrganizationTypesQueryRunner(String entityURI, - Model dataSource, Log log) { - - this.entityURI = entityURI; - this.dataSource = dataSource; - // this.log = log; - } - - private ResultSet executeQuery(String queryURI, Model dataSource) { - - QueryExecution queryExecution = null; - Query query = QueryFactory.create( - getSparqlQuery(queryURI), SYNTAX); - queryExecution = QueryExecutionFactory.create(query, dataSource); - return queryExecution.execSelect(); - } - - private String getSparqlQuery(String queryURI) { - - String sparqlQuery = ""; - - sparqlQuery = QueryConstants.getSparqlPrefixQuery() - + "SELECT " - + SPARQL_QUERY_SELECT_CLAUSE - + " WHERE { " - + "<" - + queryURI - + "> rdfs:label ?organizationLabel . " - + "{ " - + "<" + queryURI + "> core:hasSubOrganization ?subOrganization . " - + "?subOrganization rdfs:label ?subOrganizationLabel ;" - + " rdf:type ?subOrganizationType ;" - + " core:organizationForPosition ?Position . " - + "?subOrganizationType rdfs:label ?subOrganizationTypeLabel . " - + "?Position core:positionForPerson ?Person ." - + "}" - + "UNION " - + "{ " - + "<" + queryURI + "> core:organizationForPosition ?Position . " - + "?Position core:positionForPerson ?Person . " - + "?Person rdfs:label ?PersonLabel ; rdf:type ?PersonType . " - + "?PersonType rdfs:label ?PersonTypeLabel . " - + "}" - + "}"; - return sparqlQuery; - } - - private Map> createJavaValueObjects(ResultSet resultSet) { - - Map> subEntityLabelToTypes = new HashMap>(); - - while (resultSet.hasNext()) { - - QuerySolution solution = resultSet.nextSolution(); - - RDFNode subOrganizationLabel = solution.get(QueryFieldLabels.SUBORGANIZATION_LABEL); - - if (subOrganizationLabel != null) { - - if (subEntityLabelToTypes.containsKey(subOrganizationLabel.toString())) { - RDFNode subOrganizationType = solution - .get(QueryFieldLabels.SUBORGANIZATION_TYPE_LABEL); - if (subOrganizationType != null) { - subEntityLabelToTypes.get( - subOrganizationLabel.toString()).add( - subOrganizationType.toString()); - } - } else { - RDFNode subOrganizationType = solution - .get(QueryFieldLabels.SUBORGANIZATION_TYPE_LABEL); - if (subOrganizationType != null) { - subEntityLabelToTypes.put( - subOrganizationLabel.toString(), - new HashSet()); - subEntityLabelToTypes.get( - subOrganizationLabel.toString()).add( - subOrganizationType.toString()); - } - } - } - - RDFNode personLabel = solution.get(QueryFieldLabels.PERSON_LABEL); - - if (personLabel != null) { - if (subEntityLabelToTypes.containsKey(personLabel.toString())) { - RDFNode personType = solution - .get(QueryFieldLabels.PERSON_TYPE_LABEL); - if (personType != null - && !personType.toString().startsWith("http")) { - subEntityLabelToTypes.get(personLabel.toString()).add( - personType.toString()); - } - } else { - RDFNode personType = solution - .get(QueryFieldLabels.PERSON_TYPE_LABEL); - if (personType != null - && !personType.toString().startsWith("http")) { - subEntityLabelToTypes.put(personLabel.toString(), - new HashSet()); - subEntityLabelToTypes.get(personLabel.toString()).add( - personType.toString()); - } - } - } - } - - return subEntityLabelToTypes; - } - - public Map> getQueryResult() throws MalformedQueryParametersException { - - if (StringUtils.isNotBlank(this.entityURI)) { - /* - * To test for the validity of the URI submitted. - */ - IRIFactory iRIFactory = IRIFactory.jenaImplementation(); - IRI iri = iRIFactory.create(this.entityURI); - if (iri.hasViolation(false)) { - String errorMsg = ((Violation) iri.violations(false).next()) - .getShortMessage(); - log.error("Entity Comparison sub organization types query " + errorMsg); - throw new MalformedQueryParametersException( - "URI provided for an entity is malformed."); - } - } else { - throw new MalformedQueryParametersException( - "URL parameter is either null or empty."); - } - - ResultSet resultSet = executeQuery(this.entityURI, this.dataSource); - return createJavaValueObjects(resultSet); - } -} - diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/entitycomparison/OrganizationUtilityFunctions.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/entitycomparison/OrganizationUtilityFunctions.java index 72b68411..08fc6aa6 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/entitycomparison/OrganizationUtilityFunctions.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/entitycomparison/OrganizationUtilityFunctions.java @@ -3,7 +3,6 @@ package edu.cornell.mannlib.vitro.webapp.visualization.entitycomparison; import java.util.HashMap; import java.util.Map; -import java.util.Set; import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; @@ -13,7 +12,6 @@ import com.hp.hpl.jena.iri.IRIFactory; import com.hp.hpl.jena.query.Dataset; 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.beans.Individual; @@ -25,7 +23,6 @@ import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryP import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.Entity; import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.GenericQueryMap; import edu.cornell.mannlib.vitro.webapp.visualization.visutils.GenericQueryRunner; -import edu.cornell.mannlib.vitro.webapp.visualization.visutils.ModelConstructor; import edu.cornell.mannlib.vitro.webapp.visualization.visutils.QueryRunner; public class OrganizationUtilityFunctions { @@ -101,28 +98,6 @@ public class OrganizationUtilityFunctions { return highestLevelOrgURI; } - public static Map> getSubEntityTypes(Log log, - Dataset dataset, String subjectOrganization) - throws MalformedQueryParametersException { - - ModelConstructor constructQueryRunnerForSubOrganizationTypes = - new EntitySubOrganizationTypesConstructQueryRunner(subjectOrganization, - dataset, - log); - - Model constructedModelForSubOrganizationTypes = constructQueryRunnerForSubOrganizationTypes - .getConstructedModel(); - - QueryRunner>> queryManagerForsubOrganisationTypes = - new EntitySubOrganizationTypesQueryRunner( - subjectOrganization, constructedModelForSubOrganizationTypes, log); - - Map> subOrganizationTypesResult = queryManagerForsubOrganisationTypes - .getQueryResult(); - - return subOrganizationTypesResult; - } - public static String getEntityLabelFromDAO(VitroRequest vitroRequest, String entityURI) { diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/entitycomparison/cached/TemporalGrantVisualizationRequestHandler.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/entitycomparison/TemporalGrantVisualizationRequestHandler.java similarity index 96% rename from src/edu/cornell/mannlib/vitro/webapp/visualization/entitycomparison/cached/TemporalGrantVisualizationRequestHandler.java rename to src/edu/cornell/mannlib/vitro/webapp/visualization/entitycomparison/TemporalGrantVisualizationRequestHandler.java index a7455f60..5ce59b05 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/entitycomparison/cached/TemporalGrantVisualizationRequestHandler.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/entitycomparison/TemporalGrantVisualizationRequestHandler.java @@ -1,6 +1,6 @@ /* $This file is distributed under the terms of the license in /doc/license.txt$ */ -package edu.cornell.mannlib.vitro.webapp.visualization.entitycomparison.cached; +package edu.cornell.mannlib.vitro.webapp.visualization.entitycomparison; import java.util.ArrayList; import java.util.HashMap; @@ -24,7 +24,6 @@ import edu.cornell.mannlib.vitro.webapp.controller.visualization.DataVisualizati import edu.cornell.mannlib.vitro.webapp.controller.visualization.VisualizationFrameworkConstants; import edu.cornell.mannlib.vitro.webapp.visualization.constants.VOConstants; import edu.cornell.mannlib.vitro.webapp.visualization.constants.VisConstants; -import edu.cornell.mannlib.vitro.webapp.visualization.entitycomparison.OrganizationUtilityFunctions; import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException; import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.Activity; import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.Entity; diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/entitycomparison/cached/TemporalPublicationVisualizationRequestHandler.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/entitycomparison/TemporalPublicationVisualizationRequestHandler.java similarity index 96% rename from src/edu/cornell/mannlib/vitro/webapp/visualization/entitycomparison/cached/TemporalPublicationVisualizationRequestHandler.java rename to src/edu/cornell/mannlib/vitro/webapp/visualization/entitycomparison/TemporalPublicationVisualizationRequestHandler.java index 49a73356..9eb086be 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/entitycomparison/cached/TemporalPublicationVisualizationRequestHandler.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/entitycomparison/TemporalPublicationVisualizationRequestHandler.java @@ -1,6 +1,6 @@ /* $This file is distributed under the terms of the license in /doc/license.txt$ */ -package edu.cornell.mannlib.vitro.webapp.visualization.entitycomparison.cached; +package edu.cornell.mannlib.vitro.webapp.visualization.entitycomparison; import java.util.ArrayList; import java.util.HashMap; @@ -24,7 +24,6 @@ import edu.cornell.mannlib.vitro.webapp.controller.visualization.DataVisualizati import edu.cornell.mannlib.vitro.webapp.controller.visualization.VisualizationFrameworkConstants; import edu.cornell.mannlib.vitro.webapp.visualization.constants.VOConstants; import edu.cornell.mannlib.vitro.webapp.visualization.constants.VisConstants; -import edu.cornell.mannlib.vitro.webapp.visualization.entitycomparison.OrganizationUtilityFunctions; import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException; import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.Activity; import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.Entity; diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/entitygrantcount/EntityGrantCountConstructQueryRunner.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/entitygrantcount/EntityGrantCountConstructQueryRunner.java deleted file mode 100644 index 40bd5a8d..00000000 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/entitygrantcount/EntityGrantCountConstructQueryRunner.java +++ /dev/null @@ -1,390 +0,0 @@ -/* $This file is distributed under the terms of the license in /doc/license.txt$ */ - -package edu.cornell.mannlib.vitro.webapp.visualization.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.Dataset; -import com.hp.hpl.jena.query.Query; -import com.hp.hpl.jena.query.QueryExecution; -import com.hp.hpl.jena.query.QueryExecutionFactory; -import com.hp.hpl.jena.query.QueryFactory; -import com.hp.hpl.jena.query.Syntax; -import com.hp.hpl.jena.rdf.model.Model; -import com.hp.hpl.jena.rdf.model.ModelFactory; - -import edu.cornell.mannlib.vitro.webapp.visualization.constants.QueryConstants; -import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException; -import edu.cornell.mannlib.vitro.webapp.visualization.visutils.ModelConstructor; - -public class EntityGrantCountConstructQueryRunner implements ModelConstructor { - - protected static final Syntax SYNTAX = Syntax.syntaxARQ; - - private String egoURI; - - private Dataset dataset; - - private long before, after; - - private Log log = LogFactory - .getLog(EntityGrantCountConstructQueryRunner.class.getName()); - - public EntityGrantCountConstructQueryRunner(String egoURI, Dataset dataset, - Log log) { - this.egoURI = egoURI; - this.dataset = dataset; - // 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 preboundProperty) { - - 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 preboundProperty) { - - 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 preboundProperty) { - - 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 preboundProperty) { - - 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 preboundProperty) { - - 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 preboundProperty) { - - 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, Dataset dataset) { - - Model constructedModel = ModelFactory.createDefaultModel(); - - before = System.currentTimeMillis(); - - for (String queryString : constructQueries) { - - log.debug("CONSTRUCT query string : " + queryString); - - Query query = null; - - try { - query = QueryFactory.create(QueryConstants - .getSparqlPrefixQuery() - + queryString, SYNTAX); - // log.debug("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, dataset); - try { - qe.execConstruct(constructedModel); - } finally { - qe.close(); - } - - } - - after = System.currentTimeMillis(); - - // log.debug("Statements for constructed model of EntityGrantCount : "+ - // constructedModel.listStatements().toString()); - log - .debug("Time taken to execute the CONSTRUCT queries is in milliseconds: " - + (after - before)); - // 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.dataset); - - return model; - - } - - private void populateConstructQueries(Set constructQueries) { - - constructQueries - .add(generateConstructQueryForOrganizationLabel(this.egoURI)); - - constructQueries.add(generateConstructQueryForSubOrganizations( - this.egoURI, "core:hasInvestigatorRole")); - constructQueries.add(generateConstructQueryForPersons(this.egoURI, - "core:hasInvestigatorRole")); - constructQueries - .add(generateConstructQueryForDateTimeValueofRoleForOneLevelDeep( - this.egoURI, "core:hasInvestigatorRole")); - constructQueries.add(generateConstructQueryForDateTimeValueofRole( - this.egoURI, "core:hasInvestigatorRole")); - constructQueries - .add(generateConstructQueryForDateTimeValueofGrantForOneLevelDeep( - this.egoURI, "core:hasInvestigatorRole")); - constructQueries.add(generateConstructQueryForDateTimeValueofGrant( - this.egoURI, "core:hasInvestigatorRole")); - - constructQueries.add(generateConstructQueryForSubOrganizations( - this.egoURI, "core:hasPrincipalInvestigatorRole")); - constructQueries.add(generateConstructQueryForPersons(this.egoURI, - "core:hasPrincipalInvestigatorRole")); - constructQueries - .add(generateConstructQueryForDateTimeValueofRoleForOneLevelDeep( - this.egoURI, "core:hasPrincipalInvestigatorRole")); - constructQueries.add(generateConstructQueryForDateTimeValueofRole( - this.egoURI, "core:hasPrincipalInvestigatorRole")); - constructQueries - .add(generateConstructQueryForDateTimeValueofGrantForOneLevelDeep( - this.egoURI, "core:hasPrincipalInvestigatorRole")); - constructQueries.add(generateConstructQueryForDateTimeValueofGrant( - this.egoURI, "core:hasPrincipalInvestigatorRole")); - - constructQueries.add(generateConstructQueryForSubOrganizations( - this.egoURI, "core:hasCo-PrincipalInvestigatorRole")); - constructQueries.add(generateConstructQueryForPersons(this.egoURI, - "core:hasCo-PrincipalInvestigatorRole")); - constructQueries - .add(generateConstructQueryForDateTimeValueofRoleForOneLevelDeep( - this.egoURI, "core:hasCo-PrincipalInvestigatorRole")); - constructQueries.add(generateConstructQueryForDateTimeValueofRole( - this.egoURI, "core:hasCo-PrincipalInvestigatorRole")); - constructQueries - .add(generateConstructQueryForDateTimeValueofGrantForOneLevelDeep( - this.egoURI, "core:hasCo-PrincipalInvestigatorRole")); - constructQueries.add(generateConstructQueryForDateTimeValueofGrant( - this.egoURI, "core:hasCo-PrincipalInvestigatorRole")); - - } - -} diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/entitygrantcount/EntityGrantCountQueryRunner.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/entitygrantcount/EntityGrantCountQueryRunner.java deleted file mode 100644 index 58310d80..00000000 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/entitygrantcount/EntityGrantCountQueryRunner.java +++ /dev/null @@ -1,334 +0,0 @@ -/* $This file is distributed under the terms of the license in /doc/license.txt$ */ - -package edu.cornell.mannlib.vitro.webapp.visualization.entitygrantcount; - -import java.util.HashMap; -import java.util.Map; - -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.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.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.valueobjects.Activity; -import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.Entity; -import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.SubEntity; -import edu.cornell.mannlib.vitro.webapp.visualization.visutils.QueryRunner; - -/** - * This query runner is used to execute a sparql query that will fetch all the - * grants defined by core:Grant property for a particular - * department/school/university. - * - * Deepak Konidena - * - * @author bkoniden - */ -public class EntityGrantCountQueryRunner implements QueryRunner { - - protected static final Syntax SYNTAX = Syntax.syntaxARQ; - - private String entityURI; - private Model dataSource; - private Log log = LogFactory.getLog(EntityGrantCountQueryRunner.class.getName()); - private long before, after; - - - private static final String SPARQL_QUERY_COMMON_SELECT_CLAUSE = "SELECT " - + " (str(?organizationLabel) as ?organizationLabelLit) " - + " (str(?subOrganization) as ?subOrganizationLit) " - + " (str(?subOrganizationLabel) as ?subOrganizationLabelLit) " - + " (str(?Person) as ?personLit) " - + " (str(?PersonLabel) as ?personLabelLit) " - + " (str(?Grant) as ?grantLit) " - + " (str(?GrantLabel) as ?grantLabelLit) " - + " (str(?startDateTimeValue) as ?grantStartDateLit) " - + " (str(?endDateTimeValue) as ?grantEndDateLit) " - + " (str(?startDateTimeValueForGrant) as ?grantStartDateForGrantLit) " - + " (str(?endDateTimeValueForGrant) as ?grantEndDateForGrantLit)"; - - private static final String SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_ROLE_DATE_TIME = " " - + " ?Role core:roleIn ?Grant . " - + " ?Grant rdfs:label ?GrantLabel . " - + "OPTIONAL {" - + " ?Role core:dateTimeInterval ?dateTimeIntervalValue . " - + "?dateTimeIntervalValue core:start ?startDate . " - + "?startDate core:dateTime ?startDateTimeValue . " - + "OPTIONAL {" - + "?dateTimeIntervalValue core:end ?endDate . " - + "?endDate core:dateTime ?endDateTimeValue . " - + "}" - + "}"; - - private static final String SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_GRANT_DATE_TIME = " " - + " ?Role core:roleIn ?Grant . " - + " ?Grant rdfs:label ?GrantLabel . " - + "OPTIONAL {" - + " ?Grant core:dateTimeInterval ?dateTimeIntervalValueForGrant . " - + "?dateTimeIntervalValueForGrant core:start ?startDateForGrant . " - + "?startDateForGrant core:dateTime ?startDateTimeValueForGrant . " - + "OPTIONAL {" - + "?dateTimeIntervalValueForGrant core:end ?endDateForGrant . " - + "?endDateForGrant core:dateTime ?endDateTimeValueForGrant . " - + "}" - + "}"; - - - private static final String ENTITY_LABEL = QueryFieldLabels.ORGANIZATION_LABEL; - private static final String ENTITY_URL = QueryFieldLabels.ORGANIZATION_URL; - private static final String SUBENTITY_LABEL = QueryFieldLabels.SUBORGANIZATION_LABEL; - private static final String SUBENTITY_URL = QueryFieldLabels.SUBORGANIZATION_URL; - - - public EntityGrantCountQueryRunner(String entityURI, - Model constructedModel, Log log) { - - this.entityURI = entityURI; - this.dataSource = constructedModel; - - } - - private Entity createJavaValueObjects(ResultSet resultSet) { - - Entity entity = null; - Map grantURIToVO = new HashMap(); - Map subentityURLToVO = new HashMap(); - Map personURLToVO = new HashMap(); - - before = System.currentTimeMillis(); - - while (resultSet.hasNext()) { - QuerySolution solution = resultSet.nextSolution(); - - if (entity == null) { - entity = new Entity(solution.get(ENTITY_URL).toString(), - solution.get(ENTITY_LABEL).toString()); - } - - RDFNode grantNode = solution.get(QueryFieldLabels.GRANT_URL); - Activity grant; - - if (grantURIToVO.containsKey(grantNode.toString())) { - grant = grantURIToVO.get(grantNode.toString()); - - } else { - - grant = new Activity(grantNode.toString()); - grantURIToVO.put(grantNode.toString(), grant); - - RDFNode grantLabelNode = solution - .get(QueryFieldLabels.GRANT_LABEL); - if (grantLabelNode != null) { - grant.setActivityLabel(grantLabelNode.toString()); - } - - RDFNode grantStartDateNode = solution - .get(QueryFieldLabels.ROLE_START_DATE); - if (grantStartDateNode != null) { - grant.setActivityDate(grantStartDateNode.toString()); - } else { - grantStartDateNode = solution - .get(QueryFieldLabels.GRANT_START_DATE); - if (grantStartDateNode != null) { - grant.setActivityDate(grantStartDateNode.toString()); - } - } - - //TODO: Verify grant end date not needed. - /* - RDFNode grantEndDateNode = solution - .get(QueryFieldLabels.ROLE_END_DATE); - if (grantEndDateNode != null) { - grant.setGrantEndDate(grantEndDateNode.toString()); - } else { - grantEndDateNode = solution - .get(QueryFieldLabels.GRANT_END_DATE); - if (grantEndDateNode != null) { - grant.setGrantEndDate(grantEndDateNode.toString()); - } - } - */ - - } - - RDFNode subEntityURLNode = solution.get(SUBENTITY_URL); - - if (subEntityURLNode != null) { - SubEntity subEntity; - if (subentityURLToVO.containsKey(subEntityURLNode.toString())) { - subEntity = subentityURLToVO.get(subEntityURLNode - .toString()); - } else { - subEntity = new SubEntity(subEntityURLNode.toString()); - subentityURLToVO - .put(subEntityURLNode.toString(), subEntity); - } - - RDFNode subEntityLabelNode = solution.get(SUBENTITY_LABEL); - if (subEntityLabelNode != null) { - subEntity.setIndividualLabel(subEntityLabelNode.toString()); - } - entity.addSubEntity(subEntity); - subEntity.addActivity(grant); - } - - RDFNode personURLNode = solution.get(QueryFieldLabels.PERSON_URL); - - if (personURLNode != null) { - SubEntity person; - - if (personURLToVO.containsKey(personURLNode.toString())) { - person = personURLToVO.get(personURLNode.toString()); - } else { - person = new SubEntity(personURLNode.toString()); - personURLToVO.put(personURLNode.toString(), person); - } - - RDFNode personLabelNode = solution.get(QueryFieldLabels.PERSON_LABEL); - if (personLabelNode != null) { - person.setIndividualLabel(personLabelNode.toString()); - } - - /* - * This makes sure that either, - * 1. the parent organization is a department-like organization with no - * organizations beneath it, or - * 2. the parent organizations has both sub-organizations and people directly - * attached to that organizations e.g. president of a university. - * */ - if (subEntityURLNode == null) { - entity.addSubEntity(person); - } - - person.addActivity(grant); - - } - -// entity.addActivity(grant); - } - - if (subentityURLToVO.size() == 0 && personURLToVO.size() == 0) { - entity = new Entity(this.entityURI, "no-label"); - } - - after = System.currentTimeMillis(); - log.debug("Time taken to iterate through the ResultSet of SELECT queries is in ms: " - + (after - before)); - return entity; - } - - private ResultSet executeQuery(String queryURI, Model dataSource2) { - - QueryExecution queryExecution = null; - Query query = QueryFactory.create( - getSparqlQuery(queryURI), SYNTAX); - queryExecution = QueryExecutionFactory.create(query, dataSource2); - return queryExecution.execSelect(); - } - - private String getSparqlQuery(String queryURI) { - - String sparqlQuery = QueryConstants.getSparqlPrefixQuery() - + SPARQL_QUERY_COMMON_SELECT_CLAUSE + " (str(<" + queryURI - + ">) as ?" + ENTITY_URL + ") " - + "WHERE { " + "<" + queryURI + "> rdfs:label ?organizationLabel ." - + "{ " - + "<" + queryURI + "> core:hasSubOrganization ?subOrganization ." - + " ?subOrganization rdfs:label ?subOrganizationLabel ;" - + " core:organizationForPosition ?Position . " - + " ?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 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 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 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 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 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 + "}" - + " } "; - - return sparqlQuery; - } - - public Entity getQueryResult() throws MalformedQueryParametersException { - - if (StringUtils.isNotBlank(this.entityURI)) { - /* - * To test for the validity of the URI submitted. - */ - IRIFactory iRIFactory = IRIFactory.jenaImplementation(); - IRI iri = iRIFactory.create(this.entityURI); - if (iri.hasViolation(false)) { - String errorMsg = ((Violation) iri.violations(false).next()) - .getShortMessage(); - log.error("Entity Grant Count Query " + errorMsg); - throw new MalformedQueryParametersException( - "URI provided for an entity is malformed."); - } - - } else { - throw new MalformedQueryParametersException( - "URL parameter is either null or empty."); - } - - before = System.currentTimeMillis(); - - ResultSet resultSet = executeQuery(this.entityURI, this.dataSource); - - after = System.currentTimeMillis(); - - log.debug("Time taken to execute the SELECT queries is in milliseconds: " - + (after - before)); - - return createJavaValueObjects(resultSet); - } -} \ No newline at end of file diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/entitygrantcount/EntityGrantCountRequestHandler.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/entitygrantcount/EntityGrantCountRequestHandler.java deleted file mode 100644 index 2cb90cc2..00000000 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/entitygrantcount/EntityGrantCountRequestHandler.java +++ /dev/null @@ -1,357 +0,0 @@ -/* $This file is distributed under the terms of the license in /doc/license.txt$ */ - -package edu.cornell.mannlib.vitro.webapp.visualization.entitygrantcount; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.apache.commons.lang.StringEscapeUtils; -import org.apache.commons.lang.StringUtils; -import org.apache.commons.logging.Log; - -import com.google.gson.Gson; -import com.hp.hpl.jena.query.Dataset; -import com.hp.hpl.jena.rdf.model.Model; - -import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.Actions; -import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; -import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ResponseValues; -import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.TemplateResponseValues; -import edu.cornell.mannlib.vitro.webapp.controller.visualization.DataVisualizationController; -import edu.cornell.mannlib.vitro.webapp.controller.visualization.VisualizationFrameworkConstants; -import edu.cornell.mannlib.vitro.webapp.visualization.constants.VOConstants; -import edu.cornell.mannlib.vitro.webapp.visualization.entitycomparison.OrganizationUtilityFunctions; -import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException; -import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.Entity; -import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.SubEntity; -import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.json.JsonObject; -import edu.cornell.mannlib.vitro.webapp.visualization.visutils.ModelConstructor; -import edu.cornell.mannlib.vitro.webapp.visualization.visutils.QueryRunner; -import edu.cornell.mannlib.vitro.webapp.visualization.visutils.UtilityFunctions; -import edu.cornell.mannlib.vitro.webapp.visualization.visutils.VisualizationRequestHandler; - -public class EntityGrantCountRequestHandler implements - VisualizationRequestHandler { - - @Override - public ResponseValues generateStandardVisualization( - VitroRequest vitroRequest, Log log, Dataset dataset) - throws MalformedQueryParametersException { - - String entityURI = vitroRequest - .getParameter(VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY); - - return generateStandardVisualizationForGrantTemporalVis(vitroRequest, - log, dataset, entityURI); - } - - private ResponseValues generateStandardVisualizationForGrantTemporalVis( - VitroRequest vitroRequest, Log log, Dataset dataset, - String entityURI) throws MalformedQueryParametersException { - if (StringUtils.isBlank(entityURI)) { - - entityURI = OrganizationUtilityFunctions - .getStaffProvidedOrComputedHighestLevelOrganization(log, - dataset, vitroRequest); - - } - return prepareStandaloneMarkupResponse(vitroRequest, entityURI); - } - - @Override - public ResponseValues generateVisualizationForShortURLRequests( - Map parameters, VitroRequest vitroRequest, Log log, - Dataset dataSource) throws MalformedQueryParametersException { - - return generateStandardVisualizationForGrantTemporalVis( - vitroRequest, - log, - dataSource, - parameters - .get(VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY)); - - } - - @Override - public Map generateDataVisualization( - VitroRequest vitroRequest, Log log, Dataset dataset) - throws MalformedQueryParametersException { - - String entityURI = vitroRequest - .getParameter(VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY); - - /* - * This will provide the data in json format mainly used for standalone - * temporal vis. - */ - if (VisualizationFrameworkConstants.JSON_OUTPUT_FORMAT - .equalsIgnoreCase(vitroRequest - .getParameter(VisualizationFrameworkConstants.VIS_MODE_KEY))) { - - if (StringUtils.isNotBlank(entityURI)) { - - return getSubjectEntityAndGenerateDataResponse(vitroRequest, - log, dataset, entityURI); - } else { - - return getSubjectEntityAndGenerateDataResponse( - vitroRequest, - log, - dataset, - OrganizationUtilityFunctions - .getStaffProvidedOrComputedHighestLevelOrganization( - log, dataset, vitroRequest)); - } - - } else { - /* - * This provides csv download files for the content in the tables. - */ - ModelConstructor constructQueryRunner = new EntityGrantCountConstructQueryRunner( - entityURI, dataset, log); - - Model constructedModel = constructQueryRunner.getConstructedModel(); - - QueryRunner queryManager = new EntityGrantCountQueryRunner( - entityURI, constructedModel, log); - - Entity entity = queryManager.getQueryResult(); - - Map> subOrganizationTypesResult = OrganizationUtilityFunctions - .getSubEntityTypes(log, dataset, entityURI); - - return prepareDataResponse(entity, entity.getSubEntities(), - subOrganizationTypesResult); - - } - - } - - @Override - public Object generateAjaxVisualization(VitroRequest vitroRequest, Log log, - Dataset dataset) throws MalformedQueryParametersException { - - throw new UnsupportedOperationException("Entity Grant Count " - + "does not provide Ajax response."); - } - - private Map getSubjectEntityAndGenerateDataResponse( - VitroRequest vitroRequest, Log log, Dataset dataset, - String subjectEntityURI) throws MalformedQueryParametersException { - - ModelConstructor constructQueryRunner = new EntityGrantCountConstructQueryRunner( - subjectEntityURI, dataset, log); - - Model constructedModel = constructQueryRunner.getConstructedModel(); - - QueryRunner queryManager = new EntityGrantCountQueryRunner( - subjectEntityURI, constructedModel, log); - - Entity entity = queryManager.getQueryResult(); - - if (entity.getEntityLabel().equals("no-label")) { - return prepareStandaloneDataErrorResponse(vitroRequest, - subjectEntityURI); - } else { - - return getSubEntityTypesAndComputeDataResponse(vitroRequest, log, - dataset, subjectEntityURI, entity); - } - } - - private Map getSubEntityTypesAndComputeDataResponse( - VitroRequest vitroRequest, Log log, Dataset dataset, - String subjectOrganization, Entity entity) - throws MalformedQueryParametersException { - - Map> subOrganizationTypesResult = OrganizationUtilityFunctions - .getSubEntityTypes(log, dataset, subjectOrganization); - - return prepareStandaloneDataResponse(vitroRequest, entity, - subOrganizationTypesResult); - } - - private Map prepareStandaloneDataErrorResponse( - VitroRequest vitroRequest, String subjectEntityURI) { - - Map fileData = new HashMap(); - - fileData.put(DataVisualizationController.FILE_CONTENT_TYPE_KEY, - "application/octet-stream"); - fileData - .put(DataVisualizationController.FILE_CONTENT_KEY, - "{\"error\" : \"No Grants for this Organization found in VIVO.\"}"); - return fileData; - } - - private Map prepareStandaloneDataResponse( - VitroRequest vitroRequest, Entity entity, - Map> subOrganizationTypesResult) - throws MalformedQueryParametersException { - - Map fileData = new HashMap(); - - fileData.put(DataVisualizationController.FILE_CONTENT_TYPE_KEY, - "application/octet-stream"); - fileData.put(DataVisualizationController.FILE_CONTENT_KEY, - writeGrantsOverTimeJSON(vitroRequest, entity.getSubEntities(), - subOrganizationTypesResult)); - return fileData; - } - - /** - * Provides response when json file containing the grant count over the - * years is requested. - * - * @param entity - * @param subentities - * @param subOrganizationTypesResult - */ - private Map prepareDataResponse(Entity entity, - Set subentities, - Map> subOrganizationTypesResult) { - - String entityLabel = entity.getEntityLabel(); - - /* - * To make sure that null/empty records for entity names do not cause - * any mischief. - */ - if (StringUtils.isBlank(entityLabel)) { - entityLabel = "no-organization"; - } - - String outputFileName = UtilityFunctions.slugify(entityLabel) - + "_grants-per-year" + ".csv"; - - Map fileData = new HashMap(); - - fileData.put(DataVisualizationController.FILE_NAME_KEY, outputFileName); - fileData.put(DataVisualizationController.FILE_CONTENT_TYPE_KEY, - "application/octet-stream"); - fileData.put(DataVisualizationController.FILE_CONTENT_KEY, - getEntityGrantsPerYearCSVContent(subentities, - subOrganizationTypesResult)); - return fileData; - } - - private TemplateResponseValues prepareStandaloneMarkupResponse( - VitroRequest vreq, String entityURI) { - - String standaloneTemplate = "entityComparisonOnGrantsStandalone.ftl"; - - String organizationLabel = OrganizationUtilityFunctions - .getEntityLabelFromDAO(vreq, entityURI); - - Map body = new HashMap(); - body - .put("title", organizationLabel - + " - Temporal Graph Visualization"); - body.put("organizationURI", entityURI); - body.put("organizationLocalName", UtilityFunctions - .getIndividualLocalName(entityURI, vreq)); - body.put("vivoDefaultNamespace", vreq.getWebappDaoFactory() - .getDefaultNamespace()); - body.put("organizationLabel", organizationLabel); - - return new TemplateResponseValues(standaloneTemplate, body); - } - - /** - * Function to generate a json file for year <-> grant count mapping. - * - * @param vreq - * @param subentities - * @param subOrganizationTypesResult - * @throws MalformedQueryParametersException - */ - private String writeGrantsOverTimeJSON(VitroRequest vreq, - Set subentities, - Map> subOrganizationTypesResult) - throws MalformedQueryParametersException { - - Gson json = new Gson(); - Set subEntitiesJson = new HashSet(); - - for (SubEntity subentity : subentities) { - JsonObject entityJson = new JsonObject(subentity - .getIndividualLabel()); - - List> yearGrantCount = new ArrayList>(); - - for (Map.Entry grantEntry : UtilityFunctions - .getYearToActivityCount(subentity.getActivities()) - .entrySet()) { - - List currentGrantYear = new ArrayList(); - if (grantEntry.getKey().equals(VOConstants.DEFAULT_GRANT_YEAR)) { - currentGrantYear.add(-1); - } else { - currentGrantYear.add(Integer.parseInt(grantEntry.getKey())); - } - - currentGrantYear.add(grantEntry.getValue()); - yearGrantCount.add(currentGrantYear); - } - - entityJson.setYearToActivityCount(yearGrantCount); - entityJson.getOrganizationTypes().addAll( - subOrganizationTypesResult.get(entityJson.getLabel())); - - entityJson.setEntityURI(subentity.getIndividualURI()); - - if (UtilityFunctions.isEntityAPerson(vreq, subentity - .getIndividualURI())) { - entityJson.setVisMode("PERSON"); - } else { - entityJson.setVisMode("ORGANIZATION"); - } - - subEntitiesJson.add(entityJson); - } - - return json.toJson(subEntitiesJson); - - } - - private String getEntityGrantsPerYearCSVContent(Set subentities, - Map> subOrganizationTypesResult) { - - StringBuilder csvFileContent = new StringBuilder(); - - csvFileContent.append("Entity Name, Grant Count, Entity Type\n"); - - for (SubEntity subEntity : subentities) { - - csvFileContent.append(StringEscapeUtils.escapeCsv(subEntity - .getIndividualLabel())); - csvFileContent.append(", "); - csvFileContent.append(subEntity.getActivities().size()); - csvFileContent.append(", "); - - StringBuilder joinedTypes = new StringBuilder(); - - for (String subOrganizationType : subOrganizationTypesResult - .get(subEntity.getIndividualLabel())) { - joinedTypes.append(subOrganizationType + "; "); - } - - csvFileContent.append(StringEscapeUtils.escapeCsv(joinedTypes - .toString())); - csvFileContent.append("\n"); - } - - return csvFileContent.toString(); - } - - @Override - public Actions getRequiredPrivileges() { - // TODO Auto-generated method stub - return null; - } - -}