diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/persongrantcount/PersonGrantCountQueryRunner.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/persongrantcount/PersonGrantCountQueryRunner.java deleted file mode 100644 index f90c34a6..00000000 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/persongrantcount/PersonGrantCountQueryRunner.java +++ /dev/null @@ -1,253 +0,0 @@ -/* $This file is distributed under the terms of the license in /doc/license.txt$ */ - -package edu.cornell.mannlib.vitro.webapp.visualization.persongrantcount; - -import java.util.HashSet; -import java.util.Set; - -import org.apache.commons.lang.StringUtils; -import org.apache.commons.logging.Log; - -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.QuerySolution; -import com.hp.hpl.jena.query.ResultSet; -import com.hp.hpl.jena.query.Syntax; -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.Individual; -import edu.cornell.mannlib.vitro.webapp.visualization.visutils.QueryRunner; - - -/** - * This query runner is used to execute Sparql query that will fetch all the grants for an - * individual. - * @author bkoniden - * Deepak Konidena - * - */ -public class PersonGrantCountQueryRunner implements QueryRunner> { - - protected static final Syntax SYNTAX = Syntax.syntaxARQ; - - private String personURI; - private Dataset dataset; - private Individual principalInvestigator; - - public Individual getPrincipalInvestigator() { - return principalInvestigator; - } - - private Log log; - - private static final String SPARQL_QUERY_COMMON_SELECT_CLAUSE = "" - + " SELECT (str(?PILabel) as ?PILabelLit) " - + " (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 = "" - + "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 = "" - + "OPTIONAL {" - + " ?Grant core:dateTimeInterval ?dateTimeIntervalValueForGrant . " - + "?dateTimeIntervalValueForGrant core:start ?startDateForGrant . " - + "?startDateForGrant core:dateTime ?startDateTimeValueForGrant . " - + "OPTIONAL {" - + "?dateTimeIntervalValueForGrant core:end ?endDateForGrant . " - + "?endDateForGrant core:dateTime ?endDateTimeValueForGrant . " - + "}" - + "}"; - - - public PersonGrantCountQueryRunner(String personURI, Dataset dataset, Log log) { - - this.personURI = personURI; - this.dataset = dataset; - this.log = log; - } - - private Set createJavaValueObjects(ResultSet resultSet) { - Set grants = new HashSet(); - - while (resultSet.hasNext()) { - QuerySolution solution = resultSet.nextSolution(); - - Activity grant = new Activity(solution.get(QueryFieldLabels.GRANT_URL).toString()); - - RDFNode grantLabelNode = solution.get(QueryFieldLabels.GRANT_LABEL); - if (grantLabelNode != null) { - grant.setIndividualLabel(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 is used or not. - /* - 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()); - } - } - */ - - /* - * Since we are getting grant count for just one PI at a time we need - * to create only one "Individual" instance. We test against the null for "PI" to - * make sure that it has not already been instantiated. - * */ - RDFNode investigatorURINode = solution.get(QueryFieldLabels.PI_URL); - if (investigatorURINode != null && principalInvestigator == null) { - principalInvestigator = new Individual(investigatorURINode.toString()); - RDFNode investigatorLabelNode = solution.get(QueryFieldLabels.PI_LABEL); - if (investigatorLabelNode != null) { - principalInvestigator.setIndividualLabel(investigatorLabelNode.toString()); - } - } - - grants.add(grant); - } - return grants; - } - - private ResultSet executeQuery(String queryURI, Dataset dataset) { - - QueryExecution queryExecution = null; - - Query query = QueryFactory.create(getSparqlQuery(queryURI), SYNTAX); - queryExecution = QueryExecutionFactory.create(query, dataset); - - return queryExecution.execSelect(); - } - - - - private String getSparqlQuery(String queryURI) { - - String sparqlQuery = QueryConstants.getSparqlPrefixQuery() - - + SPARQL_QUERY_COMMON_SELECT_CLAUSE - - + "(str(<" + queryURI + ">) as ?PILit) " - - + "WHERE " - + "{ " - + "<" + queryURI + "> rdfs:label ?PILabel . " - + "{ " - - + "<" + queryURI + "> core:hasCo-PrincipalInvestigatorRole ?Role . " - - + "?Role core:roleIn ?Grant . " - - + "?Grant rdfs:label ?GrantLabel . " - - + SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_ROLE_DATE_TIME - - + SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_GRANT_DATE_TIME - - + "} " - - + "UNION " - - + "{ " - - + "<" + queryURI + "> core:hasPrincipalInvestigatorRole ?Role . " - - + "?Role core:roleIn ?Grant . " - - + "?Grant rdfs:label ?GrantLabel . " - - + SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_ROLE_DATE_TIME - - + SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_GRANT_DATE_TIME - - - + "} " - - + "UNION " - - + "{ " - - + "<" + queryURI + "> core:hasInvestigatorRole ?Role . " - - + "?Role core:roleIn ?Grant . " - - + "?Grant rdfs:label ?GrantLabel . " - - + SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_ROLE_DATE_TIME - - + SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_GRANT_DATE_TIME - - - + "} " - - + "} "; - - log.debug("SPARQL query for person grant count -> \n" + sparqlQuery); - //System.out.println("SPARQL query for person grant count -> \n"+ sparqlQuery); - - return sparqlQuery; - } - - public Set getQueryResult() throws MalformedQueryParametersException { - - if (StringUtils.isNotBlank(this.personURI)) { - - /* - * To test the validity of the URI submitted - */ - IRIFactory iriFactory = IRIFactory.jenaImplementation(); - IRI iri = iriFactory.create(this.personURI); - - if (iri.hasViolation(false)) { - String errorMsg = ((Violation) iri.violations(false).next()).getShortMessage(); - log.error("Grant Count vis Query " + errorMsg); - throw new MalformedQueryParametersException( - "URI provided for an individual is malformed."); - } - } else { - throw new MalformedQueryParametersException("URL parameter is either null or empty."); - } - - ResultSet resultSet = executeQuery(this.personURI, this.dataset); - - return createJavaValueObjects(resultSet); - } - -} diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/persongrantcount/PersonGrantCountRequestHandler.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/persongrantcount/PersonGrantCountRequestHandler.java index 871dc5be..74c7a12a 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/persongrantcount/PersonGrantCountRequestHandler.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/persongrantcount/PersonGrantCountRequestHandler.java @@ -5,10 +5,8 @@ package edu.cornell.mannlib.vitro.webapp.visualization.persongrantcount; import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; -import java.util.Set; import org.apache.commons.lang.StringEscapeUtils; -import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import com.hp.hpl.jena.query.Dataset; @@ -21,9 +19,9 @@ 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.exceptions.MalformedQueryParametersException; import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.Activity; -import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.Individual; import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.SparklineData; -import edu.cornell.mannlib.vitro.webapp.visualization.visutils.QueryRunner; +import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.SubEntity; +import edu.cornell.mannlib.vitro.webapp.visualization.visutils.SelectOnModelUtilities; import edu.cornell.mannlib.vitro.webapp.visualization.visutils.UtilityFunctions; import edu.cornell.mannlib.vitro.webapp.visualization.visutils.VisualizationRequestHandler; @@ -53,23 +51,21 @@ public class PersonGrantCountRequestHandler implements VisualizationRequestHandl String personURI = vitroRequest .getParameter(VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY); - QueryRunner> queryManager = - new PersonGrantCountQueryRunner(personURI, dataset, log); + SubEntity person = new SubEntity( + personURI, + UtilityFunctions.getIndividualLabelFromDAO(vitroRequest, personURI)); + + Map grantsToURI = SelectOnModelUtilities.getGrantsForPerson(dataset, person, false); - Set piGrants = queryManager.getQueryResult(); /* * Create a map from the year to number of grants. Use the Grant's * parsedGrantYear to populate the data. * */ Map yearToGrantCount = - UtilityFunctions.getYearToActivityCount(piGrants); + UtilityFunctions.getYearToActivityCount(grantsToURI.values()); - Individual investigator = ((PersonGrantCountQueryRunner) queryManager) - .getPrincipalInvestigator(); - - return prepareDataResponse(investigator, - piGrants, + return prepareDataResponse(person, yearToGrantCount); @@ -96,17 +92,18 @@ public class PersonGrantCountRequestHandler implements VisualizationRequestHandl String visContainer = vitroRequest .getParameter(VisualizationFrameworkConstants.VIS_CONTAINER_KEY); - QueryRunner> queryManager = - new PersonGrantCountQueryRunner(personURI, dataset, log); - - Set piGrants = queryManager.getQueryResult(); + SubEntity person = new SubEntity( + personURI, + UtilityFunctions.getIndividualLabelFromDAO(vitroRequest, personURI)); + + Map grantsToURI = SelectOnModelUtilities.getGrantsForPerson(dataset, person, false); /* * Create a map from the year to number of grants. Use the Grant's * parsedGrantYear to populate the data. * */ Map yearToGrantCount = - UtilityFunctions.getYearToActivityCount(piGrants); + UtilityFunctions.getYearToActivityCount(grantsToURI.values()); boolean shouldVIVOrenderVis = yearToGrantCount.size() > 0 ? true : false; @@ -145,18 +142,19 @@ public class PersonGrantCountRequestHandler implements VisualizationRequestHandl String visContainer = vitroRequest .getParameter(VisualizationFrameworkConstants.VIS_CONTAINER_KEY); + + SubEntity person = new SubEntity( + personURI, + UtilityFunctions.getIndividualLabelFromDAO(vitroRequest, personURI)); - QueryRunner> queryManager = - new PersonGrantCountQueryRunner(personURI, dataset, log); - - Set piGrants = queryManager.getQueryResult(); + Map grantsToURI = SelectOnModelUtilities.getGrantsForPerson(dataset, person, false); /* * Create a map from the year to number of grants. Use the Grant's * parsedGrantYear to populate the data. * */ Map yearToGrantCount = - UtilityFunctions.getYearToActivityCount(piGrants); + UtilityFunctions.getYearToActivityCount(grantsToURI.values()); /* * Computations required to generate HTML for the sparkline & related context. @@ -195,32 +193,14 @@ public class PersonGrantCountRequestHandler implements VisualizationRequestHandl * Provides response when csv file containing the grant count over the years * is requested. * @param investigator - * @param piGrants * @param yearToGrantCount * @return */ private Map prepareDataResponse( - Individual investigator, - Set piGrants, + SubEntity investigator, Map yearToGrantCount) { - - String piName = null; - - /* - * To protect against cases where there are no PI grants associated with the - * individual. - * */ - if (piGrants.size() > 0) { - piName = investigator.getIndividualLabel(); - } - - /* - * To make sure that null/empty records for PI names do not cause any mischief. - * */ - if (StringUtils.isBlank(piName)) { - piName = "no-principal-investigator"; - } + String piName = investigator.getIndividualLabel(); String outputFileName = UtilityFunctions.slugify(piName) + "_grants-per-year" + ".csv"; diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/personlevel/PersonLevelRequestHandler.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/personlevel/PersonLevelRequestHandler.java index 7bdccb89..e3d3718e 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/personlevel/PersonLevelRequestHandler.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/personlevel/PersonLevelRequestHandler.java @@ -4,7 +4,6 @@ package edu.cornell.mannlib.vitro.webapp.visualization.personlevel; import java.util.HashMap; import java.util.Map; -import java.util.Set; import org.apache.commons.logging.Log; @@ -23,14 +22,14 @@ import edu.cornell.mannlib.vitro.webapp.visualization.coprincipalinvestigator.Co import edu.cornell.mannlib.vitro.webapp.visualization.coprincipalinvestigator.CoPIGrantCountQueryRunner; import edu.cornell.mannlib.vitro.webapp.visualization.coprincipalinvestigator.CoPIVisCodeGenerator; import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException; -import edu.cornell.mannlib.vitro.webapp.visualization.persongrantcount.PersonGrantCountQueryRunner; import edu.cornell.mannlib.vitro.webapp.visualization.persongrantcount.PersonGrantCountVisCodeGenerator; -import edu.cornell.mannlib.vitro.webapp.visualization.personpubcount.PersonPublicationCountQueryRunner; import edu.cornell.mannlib.vitro.webapp.visualization.personpubcount.PersonPublicationCountVisCodeGenerator; import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.Activity; import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.SparklineData; +import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.SubEntity; 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.SelectOnModelUtilities; import edu.cornell.mannlib.vitro.webapp.visualization.visutils.UtilityFunctions; import edu.cornell.mannlib.vitro.webapp.visualization.visutils.VisualizationRequestHandler; @@ -102,6 +101,8 @@ public class PersonLevelRequestHandler implements VisualizationRequestHandler { if (VisualizationFrameworkConstants.COPI_VIS_MODE.equalsIgnoreCase(visMode)) { + + ModelConstructor constructQueryRunner = new CoPIGrantCountConstructQueryRunner(egoURI, dataset, log); Model constructedModel = constructQueryRunner.getConstructedModel(); @@ -109,23 +110,24 @@ public class PersonLevelRequestHandler implements VisualizationRequestHandler { QueryRunner coPIQueryManager = new CoPIGrantCountQueryRunner(egoURI, constructedModel, log); - QueryRunner> grantQueryManager = - new PersonGrantCountQueryRunner(egoURI, dataset, log); - CollaborationData coPIData = coPIQueryManager.getQueryResult(); /* * grants over time sparkline */ - - Set piGrants = grantQueryManager.getQueryResult(); - - /* - * Create a map from the year to number of grants. Use the Grant's - * parsedGrantYear to populate the data. - * */ - Map yearToGrantCount = - UtilityFunctions.getYearToActivityCount(piGrants); + SubEntity person = new SubEntity(egoURI, + UtilityFunctions + .getIndividualLabelFromDAO(vitroRequest, egoURI)); + + Map grantsToURI = SelectOnModelUtilities.getGrantsForPerson(dataset, person, false); + + /* + * Create a map from the year to number of grants. Use the Grant's + * parsedGrantYear to populate the data. + * */ + Map yearToGrantCount = + UtilityFunctions.getYearToActivityCount(grantsToURI.values()); + PersonGrantCountVisCodeGenerator personGrantCountVisCodeGenerator = new PersonGrantCountVisCodeGenerator( @@ -166,9 +168,6 @@ public class PersonLevelRequestHandler implements VisualizationRequestHandler { QueryRunner coAuthorshipQueryManager = new CoAuthorshipQueryRunner(egoURI, dataset, log); - QueryRunner> publicationQueryManager = - new PersonPublicationCountQueryRunner(egoURI, dataset, log); - CollaborationData coAuthorshipData = coAuthorshipQueryManager.getQueryResult(); /* @@ -176,14 +175,18 @@ public class PersonLevelRequestHandler implements VisualizationRequestHandler { * sparklines. This will prepare all the data for the sparklines & other requested * files. * */ - Set authorDocuments = publicationQueryManager.getQueryResult(); + SubEntity person = new SubEntity(egoURI, + UtilityFunctions + .getIndividualLabelFromDAO(vitroRequest, egoURI)); + + Map publicationsToURI = SelectOnModelUtilities.getPublicationsForPerson(dataset, person, false); /* * Create a map from the year to number of publications. Use the BiboDocument's * parsedPublicationYear to populate the data. * */ Map yearToPublicationCount = - UtilityFunctions.getYearToActivityCount(authorDocuments); + UtilityFunctions.getYearToActivityCount(publicationsToURI.values()); /* * Computations required to generate HTML for the sparklines & related context. diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/personpubcount/PersonPublicationCountRequestHandler.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/personpubcount/PersonPublicationCountRequestHandler.java index 5871d1df..9e6d1c73 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/personpubcount/PersonPublicationCountRequestHandler.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/personpubcount/PersonPublicationCountRequestHandler.java @@ -4,8 +4,8 @@ package edu.cornell.mannlib.vitro.webapp.visualization.personpubcount; import java.util.HashMap; import java.util.Map; -import java.util.Map.Entry; import java.util.Set; +import java.util.Map.Entry; import org.apache.commons.lang.StringEscapeUtils; import org.apache.commons.lang.StringUtils; diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/temporalgraph/TemporalGrantVisualizationRequestHandler.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/temporalgraph/TemporalGrantVisualizationRequestHandler.java index e989bc2a..1decaae6 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/temporalgraph/TemporalGrantVisualizationRequestHandler.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/temporalgraph/TemporalGrantVisualizationRequestHandler.java @@ -87,6 +87,8 @@ public class TemporalGrantVisualizationRequestHandler implements String entityURI = vitroRequest .getParameter(VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY); + VisConstants.DataVisMode currentDataMode = VisConstants.DataVisMode.CSV; + /* * This will provide the data in json format mainly used for standalone temporal vis. * */ @@ -94,39 +96,27 @@ public class TemporalGrantVisualizationRequestHandler implements .equalsIgnoreCase(vitroRequest .getParameter(VisualizationFrameworkConstants.VIS_MODE_KEY))) { - if (StringUtils.isNotBlank(entityURI)) { - - return getSubjectEntityAndGenerateDataResponse( - vitroRequest, - log, - dataset, - entityURI, - VisConstants.DataVisMode.JSON); - } else { - - return getSubjectEntityAndGenerateDataResponse( - vitroRequest, - log, - dataset, - OrganizationUtilityFunctions - .getStaffProvidedOrComputedHighestLevelOrganization( - log, - dataset, - vitroRequest), - VisConstants.DataVisMode.JSON); - } + currentDataMode = VisConstants.DataVisMode.JSON; - } else { - /* - * This provides csv download files for the content in the tables. - * */ - return getSubjectEntityAndGenerateDataResponse( - vitroRequest, - log, - dataset, - entityURI, - VisConstants.DataVisMode.CSV); - } + if (StringUtils.isBlank(entityURI)) { + + entityURI = OrganizationUtilityFunctions + .getStaffProvidedOrComputedHighestLevelOrganization( + log, + dataset, + vitroRequest); + + } + + } + + return getSubjectEntityAndGenerateDataResponse( + vitroRequest, + log, + dataset, + entityURI, + currentDataMode); + } private Map prepareDataErrorResponse() { diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/temporalgraph/TemporalPublicationVisualizationRequestHandler.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/temporalgraph/TemporalPublicationVisualizationRequestHandler.java index 1fa6576c..eba08c5b 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/temporalgraph/TemporalPublicationVisualizationRequestHandler.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/temporalgraph/TemporalPublicationVisualizationRequestHandler.java @@ -76,11 +76,6 @@ public class TemporalPublicationVisualizationRequestHandler implements } -// System.out.println("current models in the system are"); -// for (Map.Entry entry : ConstructedModelTracker.getAllModels().entrySet()) { -// System.out.println(entry.getKey() + " -> " + entry.getValue().size()); -// } -// return prepareStandaloneMarkupResponse(vitroRequest, entityURI); } @@ -204,6 +199,8 @@ public class TemporalPublicationVisualizationRequestHandler implements String entityURI = vitroRequest .getParameter(VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY); + VisConstants.DataVisMode currentDataMode = VisConstants.DataVisMode.CSV; + /* * This will provide the data in json format mainly used for standalone tmeporal vis. * */ @@ -211,41 +208,26 @@ public class TemporalPublicationVisualizationRequestHandler implements .equalsIgnoreCase(vitroRequest.getParameter( VisualizationFrameworkConstants.VIS_MODE_KEY))) { - if (StringUtils.isNotBlank(entityURI)) { + currentDataMode = VisConstants.DataVisMode.JSON; + + if (StringUtils.isBlank(entityURI)) { - return getSubjectEntityAndGenerateDataResponse( - vitroRequest, - log, - dataset, - entityURI, - VisConstants.DataVisMode.JSON); - } else { + entityURI = OrganizationUtilityFunctions + .getStaffProvidedOrComputedHighestLevelOrganization( + log, + dataset, + vitroRequest); - return getSubjectEntityAndGenerateDataResponse( - vitroRequest, - log, - dataset, - OrganizationUtilityFunctions - .getStaffProvidedOrComputedHighestLevelOrganization( - log, - dataset, - vitroRequest), - VisConstants.DataVisMode.JSON); - } + } - } else { - /* - * This provides csv download files for the content in the tables. - * */ - - return getSubjectEntityAndGenerateDataResponse( - vitroRequest, - log, - dataset, - entityURI, - VisConstants.DataVisMode.CSV); - - } + } + + return getSubjectEntityAndGenerateDataResponse( + vitroRequest, + log, + dataset, + entityURI, + currentDataMode); } diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/visutils/SelectOnModelUtilities.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/visutils/SelectOnModelUtilities.java index a3c3b049..a78d7370 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/visutils/SelectOnModelUtilities.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/visutils/SelectOnModelUtilities.java @@ -25,6 +25,8 @@ import edu.cornell.mannlib.vitro.webapp.visualization.modelconstructor.Organizat import edu.cornell.mannlib.vitro.webapp.visualization.modelconstructor.OrganizationToPublicationsForSubOrganizationsModelConstructor; import edu.cornell.mannlib.vitro.webapp.visualization.modelconstructor.PeopleToGrantsModelConstructor; import edu.cornell.mannlib.vitro.webapp.visualization.modelconstructor.PeopleToPublicationsModelConstructor; +import edu.cornell.mannlib.vitro.webapp.visualization.modelconstructor.PersonToGrantsModelConstructor; +import edu.cornell.mannlib.vitro.webapp.visualization.modelconstructor.PersonToPublicationsModelConstructor; import edu.cornell.mannlib.vitro.webapp.visualization.modelconstructor.SubOrganizationWithinModelConstructor; import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.Activity; import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.Entity; @@ -419,7 +421,8 @@ public class SelectOnModelUtilities { private static void getPublicationForEntity( ResultSet queryResult, - SubEntity subEntity, Map allDocumentURIToVOs) { + SubEntity subEntity, + Map allDocumentURIToVOs) { Set currentEntityPublications = new HashSet(); @@ -685,60 +688,137 @@ public class SelectOnModelUtilities { dataset); for (SubEntity person : people) { - - Map fieldLabelToOutputFieldLabel = new HashMap(); - fieldLabelToOutputFieldLabel.put("grant", QueryFieldLabels.GRANT_URL); - fieldLabelToOutputFieldLabel.put("grantLabel", QueryFieldLabels.GRANT_LABEL); - fieldLabelToOutputFieldLabel.put("grantStartDate", QueryFieldLabels.GRANT_START_DATE); - fieldLabelToOutputFieldLabel.put("roleStartDate", QueryFieldLabels.ROLE_START_DATE); - - String whereClause = "" - + "{" - + " <" + person.getIndividualURI() + "> vivosocnet:hasGrantAsAnInvestigator ?grant . " - + " ?grant rdfs:label ?grantLabel . " - + " OPTIONAL { " - + " ?grant vivosocnet:startDateTimeOnGrant ?grantStartDate } . " - + " OPTIONAL { " - + " ?grant vivosocnet:startDateTimeOnRole ?roleStartDate } . " - + "}" - + "UNION" - + "{" - + " <" + person.getIndividualURI() + "> vivosocnet:hasGrantAsPI ?grant . " - + " ?grant rdfs:label ?grantLabel . " - + " OPTIONAL { " - + " ?grant vivosocnet:startDateTimeOnGrant ?grantStartDate } . " - + " OPTIONAL { " - + " ?grant vivosocnet:startDateTimeOnRole ?roleStartDate } . " - + "}" - + "UNION" - + "{" - + " <" + person.getIndividualURI() + "> vivosocnet:hasGrantAsCoPI ?grant . " - + " ?grant rdfs:label ?grantLabel . " - + " OPTIONAL { " - + " ?grant vivosocnet:startDateTimeOnGrant ?grantStartDate } . " - + " OPTIONAL { " - + " ?grant vivosocnet:startDateTimeOnRole ?roleStartDate } . " - + "}"; - - QueryRunner personGrantsQuery = - new GenericQueryRunnerOnModel(fieldLabelToOutputFieldLabel, - "", - whereClause, - "", - peopleGrantsModel); - - getGrantForEntity(personGrantsQuery.getQueryResult(), person, allGrantURIToVOs); - - String lastCachedAtForEntity = getLastCachedAtDateTimeForEntityInModel( - person, - peopleGrantsModel); - - person.setLastCachedAtDateTime(lastCachedAtForEntity); - - + updateGrantsForPerson(person, allGrantURIToVOs, peopleGrantsModel); } return allGrantURIToVOs; } + + /** + * This method side-effects person and the central grants map. + * @param person + * @param allGrantURIToVOs + * @param personGrantsModel + * @throws MalformedQueryParametersException + */ + private static void updateGrantsForPerson(SubEntity person, + Map allGrantURIToVOs, Model personGrantsModel) + throws MalformedQueryParametersException { + + Map fieldLabelToOutputFieldLabel = new HashMap(); + fieldLabelToOutputFieldLabel.put("grant", QueryFieldLabels.GRANT_URL); + fieldLabelToOutputFieldLabel.put("grantLabel", QueryFieldLabels.GRANT_LABEL); + fieldLabelToOutputFieldLabel.put("grantStartDate", QueryFieldLabels.GRANT_START_DATE); + fieldLabelToOutputFieldLabel.put("roleStartDate", QueryFieldLabels.ROLE_START_DATE); + + String whereClause = "" + + "{" + + " <" + person.getIndividualURI() + "> vivosocnet:hasGrantAsAnInvestigator ?grant . " + + " ?grant rdfs:label ?grantLabel . " + + " OPTIONAL { " + + " ?grant vivosocnet:startDateTimeOnGrant ?grantStartDate } . " + + " OPTIONAL { " + + " ?grant vivosocnet:startDateTimeOnRole ?roleStartDate } . " + + "}" + + "UNION" + + "{" + + " <" + person.getIndividualURI() + "> vivosocnet:hasGrantAsPI ?grant . " + + " ?grant rdfs:label ?grantLabel . " + + " OPTIONAL { " + + " ?grant vivosocnet:startDateTimeOnGrant ?grantStartDate } . " + + " OPTIONAL { " + + " ?grant vivosocnet:startDateTimeOnRole ?roleStartDate } . " + + "}" + + "UNION" + + "{" + + " <" + person.getIndividualURI() + "> vivosocnet:hasGrantAsCoPI ?grant . " + + " ?grant rdfs:label ?grantLabel . " + + " OPTIONAL { " + + " ?grant vivosocnet:startDateTimeOnGrant ?grantStartDate } . " + + " OPTIONAL { " + + " ?grant vivosocnet:startDateTimeOnRole ?roleStartDate } . " + + "}"; + + QueryRunner personGrantsQuery = + new GenericQueryRunnerOnModel(fieldLabelToOutputFieldLabel, + "", + whereClause, + "", + personGrantsModel); + + getGrantForEntity(personGrantsQuery.getQueryResult(), person, allGrantURIToVOs); + + String lastCachedAtForEntity = getLastCachedAtDateTimeForEntityInModel( + person, + personGrantsModel); + + person.setLastCachedAtDateTime(lastCachedAtForEntity); + } + + public static Map getGrantsForPerson( + Dataset dataset, SubEntity person, boolean doCache) + throws MalformedQueryParametersException { + + Map allGrantURIToVOs = new HashMap(); + + Model personGrantsModel = null; + + + /* + * If we dont want to cache the results then create the model directly without + * using the ModelConstructorUtilities. Use case is the co-pi ego-centric + * visualization. + * */ + if (doCache) { + personGrantsModel = ModelConstructorUtilities + .getOrConstructModel( + person.getIndividualURI(), + PersonToGrantsModelConstructor.MODEL_TYPE, + dataset); + } else { + + ModelConstructor model = new PersonToGrantsModelConstructor(person.getIndividualURI(), dataset); + personGrantsModel = model.getConstructedModel(); + } + + + updateGrantsForPerson(person, allGrantURIToVOs, personGrantsModel); + + + return allGrantURIToVOs; + } + + + public static Map getPublicationsForPerson( + Dataset dataset, SubEntity person, boolean doCache) + throws MalformedQueryParametersException { + + Map allPublicationURIToVOs = new HashMap(); + + Model personPublicationsModel = null; + + + /* + * If we dont want to cache the results then create the model directly without + * using the ModelConstructorUtilities. Use case is the co-author ego-centric + * visualization. + * */ + if (doCache) { + personPublicationsModel = ModelConstructorUtilities + .getOrConstructModel( + person.getIndividualURI(), + PersonToPublicationsModelConstructor.MODEL_TYPE, + dataset); + } else { + + ModelConstructor model = new PersonToPublicationsModelConstructor(person.getIndividualURI(), dataset); + personPublicationsModel = model.getConstructedModel(); + } + + + updatePublicationsForPerson(person, allPublicationURIToVOs, personPublicationsModel); + + return allPublicationURIToVOs; + } public static Map getPublicationsForAssociatedPeople( Dataset dataset, Collection people) @@ -753,40 +833,54 @@ public class SelectOnModelUtilities { for (SubEntity person : people) { -// System.out.println("getting publications for " + person.getIndividualLabel()); - - Map fieldLabelToOutputFieldLabel = new HashMap(); - fieldLabelToOutputFieldLabel.put("document", QueryFieldLabels.DOCUMENT_URL); - fieldLabelToOutputFieldLabel.put("documentLabel", QueryFieldLabels.DOCUMENT_LABEL); - fieldLabelToOutputFieldLabel.put("documentPublicationDate", QueryFieldLabels.DOCUMENT_PUBLICATION_DATE); - - String whereClause = "" - + " <" + person.getIndividualURI() + "> vivosocnet:hasPublication ?document . " - + " ?document rdfs:label ?documentLabel . " - + " OPTIONAL { " - + " ?document core:dateTimeValue ?dateTimeValue . " - + " ?dateTimeValue core:dateTime ?documentPublicationDate } . "; - - QueryRunner personPublicationsQuery = - new GenericQueryRunnerOnModel(fieldLabelToOutputFieldLabel, - "", - whereClause, - "", - peoplePublicationsModel); - - getPublicationForEntity(personPublicationsQuery.getQueryResult(), - person, - allDocumentURIToVOs); - - String lastCachedAtForEntity = getLastCachedAtDateTimeForEntityInModel( - person, + updatePublicationsForPerson(person, allDocumentURIToVOs, peoplePublicationsModel); - - person.setLastCachedAtDateTime(lastCachedAtForEntity); } return allDocumentURIToVOs; } + + /** + * This method side-effects the person and the central documents map. + * @param person + * @param allDocumentURIToVOs + * @param peoplePublicationsModel + * @throws MalformedQueryParametersException + */ + private static void updatePublicationsForPerson(SubEntity person, + Map allDocumentURIToVOs, + Model peoplePublicationsModel) + throws MalformedQueryParametersException { + + Map fieldLabelToOutputFieldLabel = new HashMap(); + fieldLabelToOutputFieldLabel.put("document", QueryFieldLabels.DOCUMENT_URL); + fieldLabelToOutputFieldLabel.put("documentLabel", QueryFieldLabels.DOCUMENT_LABEL); + fieldLabelToOutputFieldLabel.put("documentPublicationDate", QueryFieldLabels.DOCUMENT_PUBLICATION_DATE); + + String whereClause = "" + + " <" + person.getIndividualURI() + "> vivosocnet:hasPublication ?document . " + + " ?document rdfs:label ?documentLabel . " + + " OPTIONAL { " + + " ?document core:dateTimeValue ?dateTimeValue . " + + " ?dateTimeValue core:dateTime ?documentPublicationDate } . "; + + QueryRunner personPublicationsQuery = + new GenericQueryRunnerOnModel(fieldLabelToOutputFieldLabel, + "", + whereClause, + "", + peoplePublicationsModel); + + getPublicationForEntity(personPublicationsQuery.getQueryResult(), + person, + allDocumentURIToVOs); + + String lastCachedAtForEntity = getLastCachedAtDateTimeForEntityInModel( + person, + peoplePublicationsModel); + + person.setLastCachedAtDateTime(lastCachedAtForEntity); + } public static Map getPublicationsWithJournalForAssociatedPeople( Dataset dataset, Collection people) diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/visutils/UtilityFunctions.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/visutils/UtilityFunctions.java index 4e7c1bc7..4a99553c 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/visutils/UtilityFunctions.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/visutils/UtilityFunctions.java @@ -3,6 +3,7 @@ package edu.cornell.mannlib.vitro.webapp.visualization.visutils; import java.io.IOException; +import java.util.Collection; import java.util.HashMap; import java.util.HashSet; import java.util.Map; @@ -68,6 +69,11 @@ public class UtilityFunctions { return yearToActivityCount; } + public static Map getYearToActivityCount( + Collection activities) { + return getYearToActivityCount(new HashSet(activities)); + } + /** * This method is used to return a mapping between activity year & all the collaborators * that published with ego in that year.