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