diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/coauthorship/CoAuthorshipQueryRunner.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/coauthorship/CoAuthorshipQueryRunner.java index 438e30e9..15456fd0 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/coauthorship/CoAuthorshipQueryRunner.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/coauthorship/CoAuthorshipQueryRunner.java @@ -398,8 +398,8 @@ public class CoAuthorshipQueryRunner implements QueryRunner { + "core:relates ?coAuthorPerson . \n" + "?coAuthorPerson rdf:type foaf:Person ; \n" + "rdfs:label ?coAuthorPersonLabel . \n" - + "OPTIONAL { ?document core:dateTimeValue ?dateTimeValue . \n" - + " ?dateTimeValue core:dateTime ?publicationDate } .\n" + + "OPTIONAL { ?document core:dateTimeValue ?dateTimeValue . \n" + + " OPTIONAL { ?dateTimeValue core:dateTime ?publicationDate . } } .\n" + "} \n" + "ORDER BY ?document ?coAuthorPerson\n"; diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/personpubcount/PersonPublicationCountQueryRunner.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/personpubcount/PersonPublicationCountQueryRunner.java index d358f6cb..bf75a8be 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/personpubcount/PersonPublicationCountQueryRunner.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/personpubcount/PersonPublicationCountQueryRunner.java @@ -5,6 +5,9 @@ package edu.cornell.mannlib.vitro.webapp.visualization.personpubcount; import java.util.HashSet; import java.util.Set; +import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService; +import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceException; +import edu.cornell.mannlib.vitro.webapp.rdfservice.ResultSetConsumer; import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.jena.iri.IRI; @@ -41,91 +44,38 @@ public class PersonPublicationCountQueryRunner implements QueryRunner createJavaValueObjects(ResultSet resultSet) { - Set authorDocuments = new HashSet(); - - while (resultSet.hasNext()) { - QuerySolution solution = resultSet.nextSolution(); - - Activity biboDocument = new Activity( - solution.get(QueryFieldLabels.DOCUMENT_URL) - .toString()); - - RDFNode publicationDateNode = solution.get(QueryFieldLabels.DOCUMENT_PUBLICATION_DATE); - if (publicationDateNode != null) { - biboDocument.setActivityDate(publicationDateNode.toString()); - } - - /* - * Since we are getting publication count for just one author at a time we need - * to create only one "Individual" instance. We test against the null for "author" to - * make sure that it has not already been instantiated. - * */ - RDFNode authorURLNode = solution.get(QueryFieldLabels.AUTHOR_URL); - if (authorURLNode != null && author == null) { - author = new Individual(authorURLNode.toString()); - RDFNode authorLabelNode = solution.get(QueryFieldLabels.AUTHOR_LABEL); - if (authorLabelNode != null) { - author.setIndividualLabel(authorLabelNode.toString()); - } - } - - authorDocuments.add(biboDocument); - } - return authorDocuments; - } - - 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 ?authPersonLit)\n " + + "SELECT ?authorName ?document ?publicationDate\n" + "WHERE { \n" - + "<" + queryURI + "> rdf:type foaf:Person ;\n" - + " rdfs:label ?authorLabel \n;" - + " core:relatedBy ?authorshipNode . \n" - + " ?authorshipNode rdf:type core:Authorship ;" - + " core:relates ?document . \n" - + " ?document rdf:type bibo:Document . \n" - + SPARQL_QUERY_COMMON_WHERE_CLAUSE + + " <" + queryURI + "> rdf:type foaf:Person ;\n" + + " rdfs:label ?authorName ; \n" + + " core:relatedBy ?authorshipNode . \n" + + " ?authorshipNode rdf:type core:Authorship ;" + + " core:relates ?document . \n" + + " ?document rdf:type bibo:Document . \n" + + " ?document rdfs:label ?documentLabel .\n" + + " OPTIONAL { ?document core:dateTimeValue ?dateTimeValue . OPTIONAL { ?dateTimeValue core:dateTime ?publicationDate } } .\n" + "}\n"; log.debug(sparqlQuery); @@ -154,10 +104,46 @@ public class PersonPublicationCountQueryRunner implements QueryRunner authorDocuments = new HashSet(); + String authorName = null; + + @Override + protected void processQuerySolution(QuerySolution qs) { + Activity biboDocument = new Activity(qs.get("document").asResource().getURI()); + + RDFNode publicationDateNode = qs.get("publicationDate"); + if (publicationDateNode != null) { + biboDocument.setActivityDate(publicationDateNode.asLiteral().getString()); + } + + if (authorName == null) { + RDFNode authorNameNode = qs.get("authorName"); + if (authorNameNode != null) { + authorName = authorNameNode.asLiteral().getString(); + } + } + + authorDocuments.add(biboDocument); + } + + public Set getAuthorDocuments() { + return authorDocuments; + } + + public String getAuthorName() { + return authorName; + } + } } 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 7779dbf7..45215ee7 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/personpubcount/PersonPublicationCountRequestHandler.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/personpubcount/PersonPublicationCountRequestHandler.java @@ -67,8 +67,8 @@ VisualizationRequestHandler { VisualizationFrameworkConstants.REQUESTING_TEMPLATE_KEY); QueryRunner> queryManager = new PersonPublicationCountQueryRunner( - personURI, - dataset, + personURI, + vitroRequest.getRDFService(), log); Set authorDocuments = queryManager.getQueryResult(); @@ -80,8 +80,17 @@ VisualizationRequestHandler { Map yearToPublicationCount = UtilityFunctions.getYearToActivityCount(authorDocuments); - boolean shouldVIVOrenderVis = - yearToPublicationCount.size() > 0 ? true : false; + boolean shouldVIVOrenderVis = false; + + if (yearToPublicationCount.containsKey("Unknown")) { + if (yearToPublicationCount.size() > 1) { + shouldVIVOrenderVis = true; + } + } else { + if (yearToPublicationCount.size() > 0) { + shouldVIVOrenderVis = true; + } + } /* * Computations required to generate HTML for the sparkline & related @@ -118,8 +127,8 @@ VisualizationRequestHandler { .getParameter(VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY); QueryRunner> queryManager = new PersonPublicationCountQueryRunner( - personURI, - dataset, + personURI, + vitroRequest.getRDFService(), log); Set authorDocuments = queryManager.getQueryResult(); @@ -131,10 +140,10 @@ VisualizationRequestHandler { Map yearToPublicationCount = UtilityFunctions.getYearToActivityCount(authorDocuments); - Individual author = ((PersonPublicationCountQueryRunner) queryManager).getAuthor(); + String authorName = ((PersonPublicationCountQueryRunner) queryManager).getAuthorName(); - return prepareDataResponse(author, - authorDocuments, + + return prepareDataResponse(authorName, yearToPublicationCount); } @@ -154,8 +163,8 @@ VisualizationRequestHandler { VisualizationFrameworkConstants.VIS_CONTAINER_KEY); QueryRunner> queryManager = new PersonPublicationCountQueryRunner( - personURI, - dataset, + personURI, + vitroRequest.getRDFService(), log); Set authorDocuments = queryManager.getQueryResult(); @@ -213,20 +222,9 @@ VisualizationRequestHandler { * @param yearToPublicationCount * @return */ - private Map prepareDataResponse(Individual author, - Set authorDocuments, + private Map prepareDataResponse(String authorName, Map yearToPublicationCount) { - String authorName = null; - - /* - * To protect against cases where there are no author documents - * associated with the individual. - */ - if (authorDocuments.size() > 0) { - authorName = author.getIndividualLabel(); - } - /* * To make sure that null/empty records for author names do not cause * any mischief.