diff --git a/src/edu/cornell/mannlib/vitro/webapp/controller/visualization/freemarker/AjaxVisualizationController.java b/src/edu/cornell/mannlib/vitro/webapp/controller/visualization/freemarker/AjaxVisualizationController.java index 5ddbcca9..fc095d32 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/controller/visualization/freemarker/AjaxVisualizationController.java +++ b/src/edu/cornell/mannlib/vitro/webapp/controller/visualization/freemarker/AjaxVisualizationController.java @@ -73,18 +73,18 @@ public class AjaxVisualizationController extends FreemarkerHttpServlet { if (visRequestHandler != null) { /* - * Pass the query to the selected visualization request handler & render the visualization. - * Since the visualization content is directly added to the response object we are side- - * effecting this method. + * Pass the query to the selected visualization request handler & render the + * visualization. Since the visualization content is directly added to the response + * object we are side-effecting this method. * */ return renderVisualization(vreq, visRequestHandler); } else { - return UtilityFunctions.handleMalformedParameters("Visualization Query Error", - "Inappropriate query parameters were submitted.", - vreq); - + return UtilityFunctions.handleMalformedParameters( + "Visualization Query Error", + "Inappropriate query parameters were submitted.", + vreq); } } @@ -147,7 +147,8 @@ public class AjaxVisualizationController extends FreemarkerHttpServlet { try { visRequestHandler = VisualizationsDependencyInjector - .getVisualizationIDsToClassMap(getServletContext()).get(visType); + .getVisualizationIDsToClassMap( + getServletContext()).get(visType); } catch (NullPointerException nullKeyException) { diff --git a/src/edu/cornell/mannlib/vitro/webapp/controller/visualization/freemarker/DataVisualizationController.java b/src/edu/cornell/mannlib/vitro/webapp/controller/visualization/freemarker/DataVisualizationController.java index 9d4eeaa3..a18f8ae5 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/controller/visualization/freemarker/DataVisualizationController.java +++ b/src/edu/cornell/mannlib/vitro/webapp/controller/visualization/freemarker/DataVisualizationController.java @@ -58,7 +58,7 @@ public class DataVisualizationController extends VitroHttpServlet { if (visRequestHandler != null) { /* - * Pass the query to the selected visualization request handler & render the visualization. + * Pass the query to the selected visualization request handler & render the vis. * Since the visualization content is directly added to the response object we are side- * effecting this method. * */ @@ -92,12 +92,13 @@ public class DataVisualizationController extends VitroHttpServlet { } else { - UtilityFunctions.handleMalformedParameters("Visualization Query Error", - "Inappropriate query parameters were submitted.", - vreq, - request, - response, - log); + UtilityFunctions.handleMalformedParameters( + "Visualization Query Error", + "Inappropriate query parameters were submitted.", + vreq, + request, + response, + log); } diff --git a/src/edu/cornell/mannlib/vitro/webapp/controller/visualization/freemarker/StandardVisualizationController.java b/src/edu/cornell/mannlib/vitro/webapp/controller/visualization/freemarker/StandardVisualizationController.java index 897ee52d..975a10ba 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/controller/visualization/freemarker/StandardVisualizationController.java +++ b/src/edu/cornell/mannlib/vitro/webapp/controller/visualization/freemarker/StandardVisualizationController.java @@ -18,8 +18,8 @@ import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.Utilit import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.VisualizationRequestHandler; /** - * Services a standard visualization request, which involves templates. This will return a simple error message and a 501 if - * there is no jena Model. + * Services a standard visualization request, which involves templates. This will return a simple + * error message and a 501 if there is no jena Model. * * @author cdtank */ @@ -45,16 +45,17 @@ public class StandardVisualizationController extends FreemarkerHttpServlet { if (visRequestHandler != null) { /* - * Pass the query to the selected visualization request handler & render the visualization. + * Pass the query to the selected visualization request handler & render the vis. * Since the visualization content is directly added to the response object we are side- * effecting this method. * */ return renderVisualization(vreq, visRequestHandler); } else { - return UtilityFunctions.handleMalformedParameters("Visualization Query Error", - "Inappropriate query parameters were submitted.", - vreq); + return UtilityFunctions.handleMalformedParameters( + "Visualization Query Error", + "Inappropriate query parameters were submitted.", + vreq); } diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/coauthorship/CoAuthorshipGraphMLWriter.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/coauthorship/CoAuthorshipGraphMLWriter.java index 32bcb6e6..066d1f0b 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/coauthorship/CoAuthorshipGraphMLWriter.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/coauthorship/CoAuthorshipGraphMLWriter.java @@ -67,11 +67,13 @@ public class CoAuthorshipGraphMLWriter { graphMLContent.append("\n\n"); - if (coAuthorshipData.getCollaborators() != null & coAuthorshipData.getCollaborators().size() > 0) { + if (coAuthorshipData.getCollaborators() != null + && coAuthorshipData.getCollaborators().size() > 0) { generateNodeSectionContent(coAuthorshipData, graphMLContent); } - if (coAuthorshipData.getCollaborations() != null & coAuthorshipData.getCollaborations().size() > 0) { + if (coAuthorshipData.getCollaborations() != null + && coAuthorshipData.getCollaborations().size() > 0) { generateEdgeSectionContent(coAuthorshipData, graphMLContent); } @@ -92,8 +94,8 @@ public class CoAuthorshipGraphMLWriter { for (Collaboration currentEdge : orderedEdges) { /* - * This method actually creates the XML code for a single Collaboration. "graphMLContent" - * is being side-effected. + * This method actually creates the XML code for a single Collaboration. + * "graphMLContent" is being side-effected. * */ getEdgeContent(graphMLContent, currentEdge); } @@ -103,8 +105,10 @@ public class CoAuthorshipGraphMLWriter { graphMLContent.append("\n"); graphMLContent.append("\t" @@ -205,8 +209,9 @@ public class CoAuthorshipGraphMLWriter { private void getNodeContent(StringBuilder graphMLContent, Collaborator node) { - ParamMap individualProfileURLParams = new ParamMap(VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY, - node.getCollaboratorURI()); + ParamMap individualProfileURLParams = + new ParamMap(VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY, + node.getCollaboratorURI()); String profileURL = UrlBuilder.getUrl(VisualizationFrameworkConstants.INDIVIDUAL_URL_PREFIX, individualProfileURLParams); diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/coauthorship/CoAuthorshipQueryRunner.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/coauthorship/CoAuthorshipQueryRunner.java index 637e414b..79f0ca69 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/coauthorship/CoAuthorshipQueryRunner.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/coauthorship/CoAuthorshipQueryRunner.java @@ -53,7 +53,7 @@ public class CoAuthorshipQueryRunner implements QueryRunner { private String egoURI; - private Dataset Dataset; + private Dataset dataset; private Log log; @@ -62,10 +62,10 @@ public class CoAuthorshipQueryRunner implements QueryRunner { private UniqueIDGenerator edgeIDGenerator; public CoAuthorshipQueryRunner(String egoURI, - Dataset Dataset, Log log) { + Dataset dataset, Log log) { this.egoURI = egoURI; - this.Dataset = Dataset; + this.dataset = dataset; this.log = log; this.nodeIDGenerator = new UniqueIDGenerator(); @@ -78,7 +78,8 @@ public class CoAuthorshipQueryRunner implements QueryRunner { Set nodes = new HashSet(); Map biboDocumentURLToVO = new HashMap(); - Map> biboDocumentURLToCoAuthors = new HashMap>(); + Map> biboDocumentURLToCoAuthors = + new HashMap>(); Map nodeURLToVO = new HashMap(); Map edgeUniqueIdentifierToVO = new HashMap(); @@ -165,17 +166,19 @@ public class CoAuthorshipQueryRunner implements QueryRunner { coAuthorsForCurrentBiboDocument.add(coAuthorNode); - Collaboration egoCoAuthorEdge = getExistingEdge(egoNode, coAuthorNode, edgeUniqueIdentifierToVO); + Collaboration egoCoAuthorEdge = + getExistingEdge(egoNode, coAuthorNode, edgeUniqueIdentifierToVO); /* - * If "egoCoAuthorEdge" is null it means that no Collaboration exists in between the egoNode - * & current coAuthorNode. Else create a new Collaboration, add it to the edges set & add - * the collaborator document to it. + * If "egoCoAuthorEdge" is null it means that no Collaboration exists in between the + * egoNode & current coAuthorNode. Else create a new Collaboration, add it to the edges + * set & add the collaborator document to it. * */ if (egoCoAuthorEdge != null) { egoCoAuthorEdge.addActivity(biboDocument); } else { - egoCoAuthorEdge = new Collaboration(egoNode, coAuthorNode, biboDocument, edgeIDGenerator); + egoCoAuthorEdge = + new Collaboration(egoNode, coAuthorNode, biboDocument, edgeIDGenerator); edges.add(egoCoAuthorEdge); edgeUniqueIdentifierToVO.put( getEdgeUniqueIdentifier(egoNode.getCollaboratorID(), @@ -223,10 +226,11 @@ public class CoAuthorshipQueryRunner implements QueryRunner { return new CoAuthorshipData(egoNode, nodes, edges); } - private void removeLowQualityNodesAndEdges(Set nodes, - Map biboDocumentURLToVO, - Map> biboDocumentURLToCoAuthors, - Set edges) { + private void removeLowQualityNodesAndEdges( + Set nodes, + Map biboDocumentURLToVO, + Map> biboDocumentURLToCoAuthors, + Set edges) { Set nodesToBeRemoved = new HashSet(); for (Map.Entry> currentBiboDocumentEntry @@ -291,7 +295,9 @@ public class CoAuthorshipQueryRunner implements QueryRunner { * In order to leverage the nested "for loop" for making edges between all the * co-authors we need to create a list out of the set first. * */ - List coAuthorNodes = new ArrayList(currentBiboDocumentEntry.getValue()); + List coAuthorNodes = + new ArrayList(currentBiboDocumentEntry.getValue()); + Collections.sort(coAuthorNodes, new CollaboratorComparator()); int numOfCoAuthors = coAuthorNodes.size(); @@ -336,8 +342,9 @@ public class CoAuthorshipQueryRunner implements QueryRunner { Collaborator collaboratingNode2, Map edgeUniqueIdentifierToVO) { - String edgeUniqueIdentifier = getEdgeUniqueIdentifier(collaboratingNode1.getCollaboratorID(), - collaboratingNode2.getCollaboratorID()); + String edgeUniqueIdentifier = getEdgeUniqueIdentifier( + collaboratingNode1.getCollaboratorID(), + collaboratingNode2.getCollaboratorID()); return edgeUniqueIdentifierToVO.get(edgeUniqueIdentifier); @@ -368,17 +375,16 @@ public class CoAuthorshipQueryRunner implements QueryRunner { } private ResultSet executeQuery(String queryText, - Dataset Dataset) { + Dataset dataset) { QueryExecution queryExecution = null; Query query = QueryFactory.create(queryText, SYNTAX); - queryExecution = QueryExecutionFactory.create(query, Dataset); + queryExecution = QueryExecutionFactory.create(query, dataset); return queryExecution.execSelect(); } private String generateEgoCoAuthorshipSparqlQuery(String queryURI) { -// Resource uri1 = ResourceFactory.createResource(queryURI); String sparqlQuery = QueryConstants.getSparqlPrefixQuery() + "SELECT \n" @@ -387,8 +393,8 @@ public class CoAuthorshipQueryRunner implements QueryRunner { + " (str(?coAuthorPerson) as ?" + QueryFieldLabels.CO_AUTHOR_URL + ") \n" + " (str(?coAuthorPersonLabel) as ?" + QueryFieldLabels.CO_AUTHOR_LABEL + ") \n" + " (str(?document) as ?" + QueryFieldLabels.DOCUMENT_URL + ") \n" - + " (str(?publicationDate) as ?" + QueryFieldLabels.DOCUMENT_PUBLICATION_DATE + ") \n" - // + " (str(?publicationYearUsing_1_1_property) as ?" + QueryFieldLabels.DOCUMENT_PUBLICATION_YEAR_USING_1_1_PROPERTY + ") \n" + + " (str(?publicationDate) as ?" + + QueryFieldLabels.DOCUMENT_PUBLICATION_DATE + ") \n" + "WHERE { \n" + "<" + queryURI + "> rdf:type foaf:Person ;" + " rdfs:label ?authorLabel ;" @@ -400,7 +406,6 @@ public class CoAuthorshipQueryRunner implements QueryRunner { + "?coAuthorPerson rdfs:label ?coAuthorPersonLabel . \n" + "OPTIONAL { ?document core:dateTimeValue ?dateTimeValue . \n" + " ?dateTimeValue core:dateTime ?publicationDate } .\n" - // + "OPTIONAL { ?document core:year ?publicationYearUsing_1_1_property } .\n" + "} \n" + "ORDER BY ?document ?coAuthorPerson\n"; @@ -430,7 +435,7 @@ public class CoAuthorshipQueryRunner implements QueryRunner { } ResultSet resultSet = executeQuery(generateEgoCoAuthorshipSparqlQuery(this.egoURI), - this.Dataset); + this.dataset); return createQueryResult(resultSet); } diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/coauthorship/CoAuthorshipRequestHandler.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/coauthorship/CoAuthorshipRequestHandler.java index 76e25023..60adfbe2 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/coauthorship/CoAuthorshipRequestHandler.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/coauthorship/CoAuthorshipRequestHandler.java @@ -40,13 +40,13 @@ public class CoAuthorshipRequestHandler implements VisualizationRequestHandler { @Override public Object generateAjaxVisualization(VitroRequest vitroRequest, Log log, - Dataset Dataset) throws MalformedQueryParametersException { + Dataset dataset) throws MalformedQueryParametersException { throw new UnsupportedOperationException("CoAuthorship does not provide Ajax Response."); } @Override public Map generateDataVisualization( - VitroRequest vitroRequest, Log log, Dataset Dataset) + VitroRequest vitroRequest, Log log, Dataset dataset) throws MalformedQueryParametersException { @@ -59,7 +59,7 @@ public class CoAuthorshipRequestHandler implements VisualizationRequestHandler { .VIS_MODE_KEY); QueryRunner queryManager = - new CoAuthorshipQueryRunner(egoURI, Dataset, log); + new CoAuthorshipQueryRunner(egoURI, dataset, log); CollaborationData authorNodesAndEdges = queryManager.getQueryResult(); @@ -105,43 +105,20 @@ public class CoAuthorshipRequestHandler implements VisualizationRequestHandler { public ResponseValues generateStandardVisualization(VitroRequest vitroRequest, Log log, - Dataset Dataset) + Dataset dataset) throws MalformedQueryParametersException { - /* - * Support for this has ceased to exist. Standalone mode was created only for demo - * purposes for VIVO Conf. - * */ -/* String egoURI = vitroRequest.getParameter( - VisualizationFrameworkConstants - .INDIVIDUAL_URI_KEY); - - QueryRunner queryManager = - new CoAuthorshipQueryRunner(egoURI, Dataset, log); - - CoAuthorshipData authorNodesAndEdges = - queryManager.getQueryResult(); - - - return prepareStandaloneResponse(egoURI, - authorNodesAndEdges, - vitroRequest);*/ - - throw new UnsupportedOperationException("CoAuthorship does not provide Standalone Response."); - + throw new UnsupportedOperationException("CoAuthorship Visualization " + + "does not provide Standalone response."); } - - private String getCoauthorsListCSVContent(CollaborationData coAuthorshipData) { StringBuilder csvFileContent = new StringBuilder(); csvFileContent.append("Co-author, Count\n"); - //for (Entry currentEntry : coAuthorsToCount.entrySet()) { for (Collaborator currNode : coAuthorshipData.getCollaborators()) { - /* * We have already printed the Ego Node info. * */ @@ -157,7 +134,6 @@ public class CoAuthorshipRequestHandler implements VisualizationRequestHandler { } return csvFileContent.toString(); - } private String getCoauthorsPerYearCSVContent(Map> yearToCoauthors) { @@ -171,7 +147,8 @@ public class CoAuthorshipRequestHandler implements VisualizationRequestHandler { csvFileContent.append(","); csvFileContent.append(currentEntry.getValue().size()); csvFileContent.append(","); - csvFileContent.append(StringEscapeUtils.escapeCsv(getCoauthorNamesAsString(currentEntry.getValue()))); + csvFileContent.append(StringEscapeUtils.escapeCsv( + getCoauthorNamesAsString(currentEntry.getValue()))); csvFileContent.append("\n"); } @@ -197,12 +174,14 @@ public class CoAuthorshipRequestHandler implements VisualizationRequestHandler { * @param authorNodesAndEdges * @param response */ - private Map prepareCoauthorsCountPerYearDataResponse(CollaborationData authorNodesAndEdges) { + private Map prepareCoauthorsCountPerYearDataResponse( + CollaborationData authorNodesAndEdges) { String outputFileName; Map> yearToCoauthors = new TreeMap>(); - if (authorNodesAndEdges.getCollaborators() != null && authorNodesAndEdges.getCollaborators().size() > 0) { + if (authorNodesAndEdges.getCollaborators() != null + && authorNodesAndEdges.getCollaborators().size() > 0) { outputFileName = UtilityFunctions.slugify(authorNodesAndEdges .getEgoCollaborator().getCollaboratorName()) @@ -232,13 +211,16 @@ public class CoAuthorshipRequestHandler implements VisualizationRequestHandler { * @param authorNodesAndEdges * @param response */ - private Map prepareCoauthorsListDataResponse(CollaborationData coAuthorshipData) { + private Map prepareCoauthorsListDataResponse( + CollaborationData coAuthorshipData) { String outputFileName = ""; - if (coAuthorshipData.getCollaborators() != null && coAuthorshipData.getCollaborators().size() > 0) { + if (coAuthorshipData.getCollaborators() != null + && coAuthorshipData.getCollaborators().size() > 0) { - outputFileName = UtilityFunctions.slugify(coAuthorshipData.getEgoCollaborator().getCollaboratorName()) + outputFileName = UtilityFunctions.slugify(coAuthorshipData.getEgoCollaborator() + .getCollaboratorName()) + "_co-authors" + ".csv"; } else { outputFileName = "no_co-authors" + ".csv"; @@ -261,7 +243,8 @@ public class CoAuthorshipRequestHandler implements VisualizationRequestHandler { * @param authorNodesAndEdges * @param response */ - private Map prepareNetworkStreamDataResponse(CollaborationData authorNodesAndEdges) { + private Map prepareNetworkStreamDataResponse( + CollaborationData authorNodesAndEdges) { CoAuthorshipGraphMLWriter coAuthorshipGraphMLWriter = new CoAuthorshipGraphMLWriter(authorNodesAndEdges); @@ -276,13 +259,16 @@ public class CoAuthorshipRequestHandler implements VisualizationRequestHandler { } - private Map prepareNetworkDownloadDataResponse(CollaborationData authorNodesAndEdges) { + private Map prepareNetworkDownloadDataResponse( + CollaborationData authorNodesAndEdges) { String outputFileName = ""; - if (authorNodesAndEdges.getCollaborators() != null && authorNodesAndEdges.getCollaborators().size() > 0) { + if (authorNodesAndEdges.getCollaborators() != null + && authorNodesAndEdges.getCollaborators().size() > 0) { - outputFileName = UtilityFunctions.slugify(authorNodesAndEdges.getEgoCollaborator().getCollaboratorName()) + outputFileName = UtilityFunctions.slugify(authorNodesAndEdges + .getEgoCollaborator().getCollaboratorName()) + "_co-author-network.graphml" + ".xml"; } else { @@ -301,47 +287,5 @@ public class CoAuthorshipRequestHandler implements VisualizationRequestHandler { coAuthorshipGraphMLWriter.getCoAuthorshipGraphMLContent().toString()); return fileData; - } - - /** - * When the page for person level visualization is requested. - * @param egoURI - * @param coAuthorshipVO - * @param vitroRequest - * @param request - * @return - */ - private TemplateResponseValues prepareStandaloneResponse( - String egoURI, - CollaborationData coAuthorshipVO, - VitroRequest vitroRequest) { - - Portal portal = vitroRequest.getPortal(); - - String title = ""; - Map body = new HashMap(); - - if (coAuthorshipVO.getCollaborators() != null && coAuthorshipVO.getCollaborators().size() > 0) { - title = coAuthorshipVO.getEgoCollaborator().getCollaboratorName() + " - "; - body.put("numOfAuthors", coAuthorshipVO.getCollaborators().size()); - } - - if (coAuthorshipVO.getCollaborations() != null && coAuthorshipVO.getCollaborations().size() > 0) { - body.put("numOfCoAuthorShips", coAuthorshipVO.getCollaborations().size()); - } - - - //request.setAttribute("scripts", "/templates/visualization/person_level_inject_head.jsp"); - - String standaloneTemplate = "coAuthorship.ftl"; - - - body.put("portalBean", portal); - body.put("egoURIParam", egoURI); - body.put("title", title + "Co-Authorship Visualization"); - - return new TemplateResponseValues(standaloneTemplate, body); - } - } diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/coauthorship/CoAuthorshipVisCodeGenerator.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/coauthorship/CoAuthorshipVisCodeGenerator.java index 84465b01..d239824d 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/coauthorship/CoAuthorshipVisCodeGenerator.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/coauthorship/CoAuthorshipVisCodeGenerator.java @@ -124,14 +124,16 @@ public class CoAuthorshipVisCodeGenerator { int uniqueCoAuthorCounter = 0; Set allCoAuthorsWithKnownAuthorshipYears = new HashSet(); - List yearToUniqueCoauthorsCountDataTable = new ArrayList(); + List yearToUniqueCoauthorsCountDataTable = + new ArrayList(); for (int publicationYear = minPubYearConsidered; publicationYear <= currentYear; publicationYear++) { String publicationYearAsString = String.valueOf(publicationYear); - Set currentCoAuthors = yearToUniqueCoauthors.get(publicationYearAsString); + Set currentCoAuthors = yearToUniqueCoauthors + .get(publicationYearAsString); Integer currentUniqueCoAuthors = null; @@ -142,9 +144,10 @@ public class CoAuthorshipVisCodeGenerator { currentUniqueCoAuthors = 0; } - yearToUniqueCoauthorsCountDataTable.add(new YearToEntityCountDataElement(uniqueCoAuthorCounter, - publicationYearAsString, - currentUniqueCoAuthors)); + yearToUniqueCoauthorsCountDataTable.add( + new YearToEntityCountDataElement(uniqueCoAuthorCounter, + publicationYearAsString, + currentUniqueCoAuthors)); uniqueCoAuthorCounter++; } @@ -159,12 +162,13 @@ public class CoAuthorshipVisCodeGenerator { sparklineData.setYearToEntityCountDataTable(yearToUniqueCoauthorsCountDataTable); /* - * This is required only for the sparklines which convey collaborationships like coinvestigatorships - * and coauthorship. There are edge cases where a collaborator can be present for in a collaboration - * with known & unknown year. We do not want to repeat the count for this collaborator when we present - * it in the front-end. + * This is required only for the sparklines which convey collaborationships like + * coinvestigatorships and coauthorship. There are edge cases where a collaborator can be + * present for in a collaboration with known & unknown year. We do not want to repeat the + * count for this collaborator when we present it in the front-end. * */ - Set totalUniqueCoInvestigators = new HashSet(allCoAuthorsWithKnownAuthorshipYears); + Set totalUniqueCoInvestigators = + new HashSet(allCoAuthorsWithKnownAuthorshipYears); /* * Total publications will also consider publications that have no year associated with @@ -175,7 +179,8 @@ public class CoAuthorshipVisCodeGenerator { unknownYearCoauthors = yearToUniqueCoauthors .get(VOConstants.DEFAULT_PUBLICATION_YEAR).size(); - totalUniqueCoInvestigators.addAll(yearToUniqueCoauthors.get(VOConstants.DEFAULT_GRANT_YEAR)); + totalUniqueCoInvestigators.addAll( + yearToUniqueCoauthors.get(VOConstants.DEFAULT_GRANT_YEAR)); } sparklineData.setUnknownYearPublications(unknownYearCoauthors); @@ -214,19 +219,22 @@ public class CoAuthorshipVisCodeGenerator { if (yearToUniqueCoauthors.size() > 0) { - sparklineData.setFullTimelineNetworkLink(UtilityFunctions.getCollaboratorshipNetworkLink(individualURI, - VisualizationFrameworkConstants.PERSON_LEVEL_VIS, - VisualizationFrameworkConstants.COAUTHOR_VIS_MODE)); + sparklineData.setFullTimelineNetworkLink( + UtilityFunctions.getCollaboratorshipNetworkLink( + individualURI, + VisualizationFrameworkConstants.PERSON_LEVEL_VIS, + VisualizationFrameworkConstants.COAUTHOR_VIS_MODE)); - sparklineData.setDownloadDataLink(UtilityFunctions - .getCSVDownloadURL( - individualURI, - VisualizationFrameworkConstants.COAUTHORSHIP_VIS, - VisualizationFrameworkConstants.COAUTHORS_COUNT_PER_YEAR_VIS_MODE)); + sparklineData.setDownloadDataLink( + UtilityFunctions.getCSVDownloadURL( + individualURI, + VisualizationFrameworkConstants.COAUTHORSHIP_VIS, + VisualizationFrameworkConstants.COAUTHORS_COUNT_PER_YEAR_VIS_MODE)); Map yearToUniqueCoauthorsCount = new HashMap(); - for (Map.Entry> currentYearToCoAuthors : yearToUniqueCoauthors.entrySet()) { + for (Map.Entry> currentYearToCoAuthors + : yearToUniqueCoauthors.entrySet()) { yearToUniqueCoauthorsCount.put(currentYearToCoAuthors.getKey(), currentYearToCoAuthors.getValue().size()); } diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/coprincipalinvestigator/CoPIGrantCountConstructQueryRunner.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/coprincipalinvestigator/CoPIGrantCountConstructQueryRunner.java index 560e13bd..8f3b9025 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/coprincipalinvestigator/CoPIGrantCountConstructQueryRunner.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/coprincipalinvestigator/CoPIGrantCountConstructQueryRunner.java @@ -30,21 +30,22 @@ public class CoPIGrantCountConstructQueryRunner implements ModelConstructor { private String egoURI; - private Dataset Dataset; + private Dataset dataset; private long before, after; private Log log = LogFactory .getLog(CoPIGrantCountConstructQueryRunner.class.getName()); - private static final String SPARQL_QUERY_COMMON_CONSTRUCT_AND_WHERE_STRING = "?Role core:roleIn ?Grant . " + private static final String SPARQL_QUERY_COMMON_CONSTRUCT_AND_WHERE_STRING = + "?Role core:roleIn ?Grant . " + "?Grant rdfs:label ?GrantLabel . " + "?Grant core:relatedRole ?RelatedRole . "; - public CoPIGrantCountConstructQueryRunner(String egoURI, Dataset Dataset, + public CoPIGrantCountConstructQueryRunner(String egoURI, Dataset dataset, Log log) { this.egoURI = egoURI; - this.Dataset = Dataset; + this.dataset = dataset; // this.log = log; } @@ -191,7 +192,7 @@ public class CoPIGrantCountConstructQueryRunner implements ModelConstructor { return sparqlQuery; } - private Model executeQuery(Set constructQueries, Dataset Dataset) { + private Model executeQuery(Set constructQueries, Dataset dataset) { Model constructedModel = ModelFactory.createDefaultModel(); @@ -213,7 +214,7 @@ public class CoPIGrantCountConstructQueryRunner implements ModelConstructor { log.error(queryString); } - QueryExecution qe = QueryExecutionFactory.create(query, Dataset); + QueryExecution qe = QueryExecutionFactory.create(query, dataset); try { qe.execConstruct(constructedModel); } finally { @@ -253,7 +254,7 @@ public class CoPIGrantCountConstructQueryRunner implements ModelConstructor { populateConstructQueries(constructQueries); - Model model = executeQuery(constructQueries, this.Dataset); + Model model = executeQuery(constructQueries, this.dataset); return model; diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/coprincipalinvestigator/CoPIGrantCountQueryRunner.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/coprincipalinvestigator/CoPIGrantCountQueryRunner.java index 45f46908..c85d4dc8 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/coprincipalinvestigator/CoPIGrantCountQueryRunner.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/coprincipalinvestigator/CoPIGrantCountQueryRunner.java @@ -69,7 +69,7 @@ public class CoPIGrantCountQueryRunner implements QueryRunner + "?dateTimeIntervalValue core:end ?endDate . " + "?endDate core:dateTime ?endDateTimeValue . " + "}" - + "} . " ; + + "} . "; private static final String SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_GRANT_DATE_TIME = "" + "OPTIONAL {" @@ -80,7 +80,7 @@ public class CoPIGrantCountQueryRunner implements QueryRunner + "?dateTimeIntervalValueForGrant core:end ?endDateForGrant . " + "?endDateForGrant core:dateTime ?endDateTimeValueForGrant . " + "}" - + "}" ; + + "}"; public CoPIGrantCountQueryRunner(String egoURI, @@ -92,12 +92,10 @@ public class CoPIGrantCountQueryRunner implements QueryRunner this.nodeIDGenerator = new UniqueIDGenerator(); this.edgeIDGenerator = new UniqueIDGenerator(); - } private String generateEgoCoPIquery(String queryURI) { - String sparqlQuery = QueryConstants.getSparqlPrefixQuery() + "SELECT " + " (str(<" + queryURI + ">) as ?" + QueryFieldLabels.PI_URL + ") " @@ -319,13 +317,10 @@ public class CoPIGrantCountQueryRunner implements QueryRunner + "} " + "} "; - // log.debug("COPI QUERY - " + sparqlQuery); //System.out.println("\n\nCOPI QUERY - " + sparqlQuery + "\n\n"); - return sparqlQuery; } - private ResultSet executeQuery(String queryText, Model dataSource) { QueryExecution queryExecution = null; @@ -336,7 +331,7 @@ public class CoPIGrantCountQueryRunner implements QueryRunner } public CollaborationData getQueryResult() - throws MalformedQueryParametersException { + throws MalformedQueryParametersException { if (StringUtils.isNotBlank(this.egoURI)) { /* @@ -360,7 +355,7 @@ public class CoPIGrantCountQueryRunner implements QueryRunner after = System.currentTimeMillis(); - log.debug("Time taken to execute the SELECT queries is in milliseconds: " + (after - before) ); + log.debug("Time taken to execute the SELECT queries is in milliseconds: " + (after - before)); return createQueryResult(resultSet); } @@ -371,7 +366,8 @@ public class CoPIGrantCountQueryRunner implements QueryRunner Collaborator collaboratingNode2, Map edgeUniqueIdentifierToVO) { - String edgeUniqueIdentifier = getEdgeUniqueIdentifier(collaboratingNode1.getCollaboratorID(), + String edgeUniqueIdentifier = getEdgeUniqueIdentifier( + collaboratingNode1.getCollaboratorID(), collaboratingNode2.getCollaboratorID()); return edgeUniqueIdentifierToVO.get(edgeUniqueIdentifier); @@ -428,7 +424,7 @@ public class CoPIGrantCountQueryRunner implements QueryRunner egoNode.setCollaboratorName(authorLabelNode.toString()); } } - log.debug("PI: "+ egoNode.getIndividualLabel()); + log.debug("PI: " + egoNode.getIndividualLabel()); RDFNode grantNode = solution.get(QueryFieldLabels.GRANT_URL); Activity grant; @@ -441,7 +437,7 @@ public class CoPIGrantCountQueryRunner implements QueryRunner } egoNode.addActivity(grant); - log.debug("Adding grant: "+ grant.getIndividualLabel()); + log.debug("Adding grant: " + grant.getIndividualLabel()); /* * After some discussion we concluded that for the purpose of this visualization @@ -486,9 +482,10 @@ public class CoPIGrantCountQueryRunner implements QueryRunner } coPIsForCurrentGrant.add(coPINode); - log.debug("Co-PI for current grant : "+ coPINode.getIndividualLabel()); + log.debug("Co-PI for current grant : " + coPINode.getIndividualLabel()); - Collaboration egoCoPIEdge = getExistingEdge(egoNode, coPINode, edgeUniqueIdentifierToVO); + Collaboration egoCoPIEdge = + getExistingEdge(egoNode, coPINode, edgeUniqueIdentifierToVO); /* * If "egoCoPIEdge" is null it means that no edge exists in between the egoNode * & current coPINode. Else create a new edge, add it to the edges set & add @@ -506,13 +503,11 @@ public class CoPIGrantCountQueryRunner implements QueryRunner } } - /* * This method takes out all the PIs & edges between PIs that belong to grants * that have more than 100 PIs. We conjecture that these grants do not provide much * insight. However, we have left the grants be. - * * This method side-effects "nodes" & "edges". * */ removeLowQualityNodesAndEdges(nodes, @@ -527,20 +522,20 @@ public class CoPIGrantCountQueryRunner implements QueryRunner * The below sub-routine will take care of, * A - B * - * We are side-effecting "edges" here. The only reason to do this is because we are adding - * edges en masse for all the co-PIs on all the grants considered so far. The - * other reason being we dont want to compare against 2 sets of edges (edges created before - * & co-PI edges created during the course of this method) when we are creating a new - * edge. + * We are side-effecting "edges" here. The only reason to do this is because we are + * adding edges en masse for all the co-PIs on all the grants considered so far. The + * other reason being we dont want to compare against 2 sets of edges (edges created + * before & co-PI edges created during the course of this method) when we are creating + * a new edge. * */ createCoPIEdges(grantURLToVO, grantURLToCoPIs, edges, edgeUniqueIdentifierToVO); - after = System.currentTimeMillis(); - log.debug("Time taken to iterate through the ResultSet of SELECT queries is in milliseconds: " + (after - before) ); + log.debug("Time taken to iterate through the ResultSet of SELECT queries is in ms: " + + (after - before)); return new CoInvestigationData(egoNode, nodes, edges); } @@ -564,14 +559,14 @@ public class CoPIGrantCountQueryRunner implements QueryRunner && currentGrantEntry.getValue().size() <= MAX_PI_PER_GRANT_ALLOWED) { - Set newlyAddedEdges = new HashSet(); /* * In order to leverage the nested "for loop" for making edges between all the * co-PIs we need to create a list out of the set first. * */ - List coPINodes = new ArrayList(currentGrantEntry.getValue()); + List coPINodes = + new ArrayList(currentGrantEntry.getValue()); Collections.sort(coPINodes, new CollaboratorComparator()); int numOfCoPIs = coPINodes.size(); @@ -605,9 +600,7 @@ public class CoPIGrantCountQueryRunner implements QueryRunner } edges.addAll(newlyAddedEdges); } - } - } private void removeLowQualityNodesAndEdges(Set nodes, @@ -663,9 +656,9 @@ public class CoPIGrantCountQueryRunner implements QueryRunner RDFNode grantStartYear = solution.get(QueryFieldLabels.ROLE_START_DATE); if (grantStartYear != null) { grant.setActivityDate(grantStartYear.toString()); - }else{ + } else { grantStartYear = solution.get(QueryFieldLabels.GRANT_START_DATE); - if(grantStartYear != null){ + if (grantStartYear != null) { grant.setActivityDate(grantStartYear.toString()); } } diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/coprincipalinvestigator/CoPIGrantCountRequestHandler.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/coprincipalinvestigator/CoPIGrantCountRequestHandler.java index 8c1b005b..79bac3f2 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/coprincipalinvestigator/CoPIGrantCountRequestHandler.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/coprincipalinvestigator/CoPIGrantCountRequestHandler.java @@ -28,29 +28,33 @@ import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.Visual * @author bkoniden * Deepak Konidena */ -public class CoPIGrantCountRequestHandler implements VisualizationRequestHandler{ +public class CoPIGrantCountRequestHandler implements VisualizationRequestHandler { @Override public Object generateAjaxVisualization(VitroRequest vitroRequest, Log log, - Dataset Dataset) throws MalformedQueryParametersException { - throw new UnsupportedOperationException("Co-PI Grant Count does not provide Ajax Response."); + Dataset dataset) throws MalformedQueryParametersException { + throw new UnsupportedOperationException("Co-PI Grant Count" + + " does not provide Ajax response."); } @Override public Map generateDataVisualization( - VitroRequest vitroRequest, Log log, Dataset Dataset) + VitroRequest vitroRequest, Log log, Dataset dataset) throws MalformedQueryParametersException { - String egoURI = vitroRequest.getParameter(VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY); + String egoURI = vitroRequest.getParameter(VisualizationFrameworkConstants + .INDIVIDUAL_URI_KEY); String visMode = vitroRequest.getParameter(VisualizationFrameworkConstants.VIS_MODE_KEY); - ModelConstructor constructQueryRunner = new CoPIGrantCountConstructQueryRunner(egoURI, Dataset, log); + ModelConstructor constructQueryRunner = + new CoPIGrantCountConstructQueryRunner(egoURI, dataset, log); Model constructedModel = constructQueryRunner.getConstructedModel(); - QueryRunner queryManager = new CoPIGrantCountQueryRunner(egoURI, constructedModel, log); + QueryRunner queryManager = + new CoPIGrantCountQueryRunner(egoURI, constructedModel, log); - CollaborationData PINodesAndEdges = queryManager.getQueryResult(); + CollaborationData investigatorNodesAndEdges = queryManager.getQueryResult(); /* * We will be using the same visualization package for both sparkline & co-pi @@ -63,7 +67,7 @@ public class CoPIGrantCountRequestHandler implements VisualizationRequestHandler * When the csv file is required - based on which sparkline visualization will * be rendered. * */ - return prepareCoPIsCountPerYearDataResponse(PINodesAndEdges); + return prepareCoPIsCountPerYearDataResponse(investigatorNodesAndEdges); } else if (VisualizationFrameworkConstants.COPIS_LIST_VIS_MODE .equalsIgnoreCase(visMode)) { @@ -71,7 +75,7 @@ public class CoPIGrantCountRequestHandler implements VisualizationRequestHandler * When the csv file is required - based on which sparkline visualization will * be rendered. * */ - return prepareCoPIsListDataResponse(PINodesAndEdges); + return prepareCoPIsListDataResponse(investigatorNodesAndEdges); } else if (VisualizationFrameworkConstants.COPI_NETWORK_DOWNLOAD_VIS_MODE .equalsIgnoreCase(visMode)) { @@ -79,28 +83,27 @@ public class CoPIGrantCountRequestHandler implements VisualizationRequestHandler * When the csv file is required - based on which sparkline visualization will * be rendered. * */ - return prepareNetworkDownloadDataResponse(PINodesAndEdges); + return prepareNetworkDownloadDataResponse(investigatorNodesAndEdges); } else { /* * When the graphML file is required - based on which co-pi network * visualization will be rendered. * */ - return prepareNetworkStreamDataResponse(PINodesAndEdges); + return prepareNetworkStreamDataResponse(investigatorNodesAndEdges); } } @Override public ResponseValues generateStandardVisualization( - VitroRequest vitroRequest, Log log, Dataset Dataset) + VitroRequest vitroRequest, Log log, Dataset dataset) throws MalformedQueryParametersException { /* * Support for this has ceased to exist. Standalone mode was created only for demo * purposes for VIVO Conf. * */ - throw new UnsupportedOperationException("CoPI does not provide Standalone Response."); - + throw new UnsupportedOperationException("CoPI does not provide Standalone Response."); } private String getCoPIsListCSVContent(CollaborationData coPIData) { @@ -141,19 +144,20 @@ public class CoPIGrantCountRequestHandler implements VisualizationRequestHandler csvFileContent.append(","); csvFileContent.append(currentEntry.getValue().size()); csvFileContent.append(","); - csvFileContent.append(StringEscapeUtils.escapeCsv(getCoPINamesAsString(currentEntry.getValue()))); + csvFileContent.append(StringEscapeUtils.escapeCsv( + getCoPINamesAsString(currentEntry.getValue()))); csvFileContent.append("\n"); } return csvFileContent.toString(); } - private String getCoPINamesAsString(Set CoPIs) { + private String getCoPINamesAsString(Set coInvestigators) { StringBuilder coPIsMerged = new StringBuilder(); String coPISeparator = ";"; - for(Collaborator currentCoPI : CoPIs){ + for (Collaborator currentCoPI : coInvestigators) { coPIsMerged.append(currentCoPI.getCollaboratorName() + coPISeparator); } @@ -167,12 +171,14 @@ public class CoPIGrantCountRequestHandler implements VisualizationRequestHandler * @param piNodesAndEdges * @param response */ - private Map prepareCoPIsCountPerYearDataResponse(CollaborationData piNodesAndEdges) { + private Map prepareCoPIsCountPerYearDataResponse( + CollaborationData piNodesAndEdges) { String outputFileName; Map> yearToCoPIs = new TreeMap>(); - if (piNodesAndEdges.getCollaborators() != null && piNodesAndEdges.getCollaborators().size() > 0) { + if (piNodesAndEdges.getCollaborators() != null + && piNodesAndEdges.getCollaborators().size() > 0) { outputFileName = UtilityFunctions.slugify(piNodesAndEdges .getEgoCollaborator().getCollaboratorName()) @@ -208,7 +214,8 @@ public class CoPIGrantCountRequestHandler implements VisualizationRequestHandler if (coPIData.getCollaborators() != null && coPIData.getCollaborators().size() > 0) { - outputFileName = UtilityFunctions.slugify(coPIData.getEgoCollaborator().getCollaboratorName()) + outputFileName = UtilityFunctions.slugify(coPIData.getEgoCollaborator() + .getCollaboratorName()) + "_co-investigators" + ".csv"; } else { @@ -253,7 +260,8 @@ public class CoPIGrantCountRequestHandler implements VisualizationRequestHandler if (coPIData.getCollaborators() != null && coPIData.getCollaborators().size() > 0) { - outputFileName = UtilityFunctions.slugify(coPIData.getEgoCollaborator().getCollaboratorName()) + outputFileName = UtilityFunctions.slugify(coPIData.getEgoCollaborator() + .getCollaboratorName()) + "_co-investigator-network.graphml" + ".xml"; } else { @@ -274,8 +282,4 @@ public class CoPIGrantCountRequestHandler implements VisualizationRequestHandler return fileData; } - - - - -} +} \ No newline at end of file diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/coprincipalinvestigator/CoPIGraphMLWriter.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/coprincipalinvestigator/CoPIGraphMLWriter.java index 98e21b12..98a5d922 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/coprincipalinvestigator/CoPIGraphMLWriter.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/coprincipalinvestigator/CoPIGraphMLWriter.java @@ -32,7 +32,7 @@ public class CoPIGraphMLWriter { private final String GRAPHML_FOOTER = ""; - public CoPIGraphMLWriter(CollaborationData coPIData){ + public CoPIGraphMLWriter(CollaborationData coPIData) { coPIGraphMLContent = createCoPIGraphMLContent(coPIData); } @@ -105,8 +105,10 @@ public class CoPIGraphMLWriter { graphMLContent.append("\n"); graphMLContent.append("\t" @@ -208,8 +210,9 @@ public class CoPIGraphMLWriter { private void getNodeContent(StringBuilder graphMLContent, Collaborator node) { - ParamMap individualProfileURLParams = new ParamMap(VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY, - node.getCollaboratorURI()); + ParamMap individualProfileURLParams = new ParamMap( + VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY, + node.getCollaboratorURI()); String profileURL = UrlBuilder.getUrl(VisualizationFrameworkConstants.INDIVIDUAL_URL_PREFIX, individualProfileURLParams); diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/coprincipalinvestigator/CoPIVisCodeGenerator.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/coprincipalinvestigator/CoPIVisCodeGenerator.java index 62863017..50dddfb9 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/coprincipalinvestigator/CoPIVisCodeGenerator.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/coprincipalinvestigator/CoPIVisCodeGenerator.java @@ -39,7 +39,8 @@ public class CoPIVisCodeGenerator { * spanning the career of the person & last 10 years at the minimum, in case if * the person started his career in the last 10 years. * */ - private static final String DEFAULT_VISCONTAINER_DIV_ID = "unique_coinvestigators_vis_container"; + private static final String DEFAULT_VISCONTAINER_DIV_ID = + "unique_coinvestigators_vis_container"; private Map> yearToUniqueCoPIs; @@ -134,7 +135,8 @@ public class CoPIVisCodeGenerator { int uniqueCoPICounter = 0; Set allCoPIsWithKnownGrantShipYears = new HashSet(); - List yearToUniqueInvestigatorsCountDataTable = new ArrayList(); + List yearToUniqueInvestigatorsCountDataTable = + new ArrayList(); for (int grantYear = minGrantYearConsidered; grantYear <= currentYear; grantYear++) { @@ -151,7 +153,8 @@ public class CoPIVisCodeGenerator { currentUniqueCoPIs = 0; } - yearToUniqueInvestigatorsCountDataTable.add(new YearToEntityCountDataElement(uniqueCoPICounter, + yearToUniqueInvestigatorsCountDataTable.add(new YearToEntityCountDataElement( + uniqueCoPICounter, grantYearAsString, currentUniqueCoPIs)); @@ -169,12 +172,13 @@ public class CoPIVisCodeGenerator { sparklineData.setYearToEntityCountDataTable(yearToUniqueInvestigatorsCountDataTable); /* - * This is required only for the sparklines which convey collaborationships like coinvestigatorships - * and coauthorship. There are edge cases where a collaborator can be present for in a collaboration - * with known & unknown year. We do not want to repeat the count for this collaborator when we present - * it in the front-end. + * This is required only for the sparklines which convey collaborationships like + * coinvestigatorships and coauthorship. There are edge cases where a collaborator can be + * present for in a collaboration with known & unknown year. We do not want to repeat the + * count for this collaborator when we present it in the front-end. * */ - Set totalUniqueCoInvestigators = new HashSet(allCoPIsWithKnownGrantShipYears); + Set totalUniqueCoInvestigators = + new HashSet(allCoPIsWithKnownGrantShipYears); /* * Total grants will also consider grants that have no year @@ -184,9 +188,8 @@ public class CoPIVisCodeGenerator { if (yearToUniqueCoPIs.get(VOConstants.DEFAULT_GRANT_YEAR) != null) { unknownYearGrants = yearToUniqueCoPIs.get( VOConstants.DEFAULT_GRANT_YEAR).size(); - - totalUniqueCoInvestigators.addAll(yearToUniqueCoPIs.get(VOConstants.DEFAULT_GRANT_YEAR)); - + totalUniqueCoInvestigators.addAll( + yearToUniqueCoPIs.get(VOConstants.DEFAULT_GRANT_YEAR)); } sparklineData.setTotalCollaborationshipCount(totalUniqueCoInvestigators.size()); @@ -227,18 +230,22 @@ public class CoPIVisCodeGenerator { if (yearToUniqueCoPIs.size() > 0) { - sparklineData.setFullTimelineNetworkLink(UtilityFunctions.getCollaboratorshipNetworkLink(individualURI, - VisualizationFrameworkConstants.PERSON_LEVEL_VIS, - VisualizationFrameworkConstants.COPI_VIS_MODE)); + sparklineData.setFullTimelineNetworkLink( + UtilityFunctions.getCollaboratorshipNetworkLink( + individualURI, + VisualizationFrameworkConstants.PERSON_LEVEL_VIS, + VisualizationFrameworkConstants.COPI_VIS_MODE)); - sparklineData.setDownloadDataLink(UtilityFunctions - .getCSVDownloadURL( - individualURI, - VisualizationFrameworkConstants.CO_PI_VIS, - VisualizationFrameworkConstants.COPIS_COUNT_PER_YEAR_VIS_MODE)); + sparklineData.setDownloadDataLink( + UtilityFunctions.getCSVDownloadURL( + individualURI, + VisualizationFrameworkConstants.CO_PI_VIS, + VisualizationFrameworkConstants.COPIS_COUNT_PER_YEAR_VIS_MODE)); Map yearToUniqueCoPIsCount = new HashMap(); - for (Map.Entry> currentYearToUniqueCoPIsCount : yearToUniqueCoPIs.entrySet()) { + for (Map.Entry> currentYearToUniqueCoPIsCount + : yearToUniqueCoPIs.entrySet()) { + yearToUniqueCoPIsCount.put(currentYearToUniqueCoPIsCount.getKey(), currentYearToUniqueCoPIsCount.getValue().size()); } diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitycomparison/EntityComparisonUtilityFunctions.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitycomparison/EntityComparisonUtilityFunctions.java index c61659f4..455c0a36 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitycomparison/EntityComparisonUtilityFunctions.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitycomparison/EntityComparisonUtilityFunctions.java @@ -69,7 +69,7 @@ public class EntityComparisonUtilityFunctions { return ""; } - public static String getHighestLevelOrganizationURI(Log log, Dataset Dataset) + public static String getHighestLevelOrganizationURI(Log log, Dataset dataset) throws MalformedQueryParametersException { Map fieldLabelToOutputFieldLabel = new HashMap(); @@ -80,7 +80,8 @@ public class EntityComparisonUtilityFunctions { String aggregationRules = "(count(?organization) AS ?numOfChildren)"; - String whereClause = "?organization rdf:type foaf:Organization ; rdfs:label ?organizationLabel . \n" + String whereClause = "?organization rdf:type foaf:Organization ;" + + " rdfs:label ?organizationLabel . \n" + "OPTIONAL { ?organization core:hasSubOrganization ?subOrg } . \n" + "OPTIONAL { ?organization core:subOrganizationWithin ?parent } . \n" + "FILTER ( !bound(?parent) ). \n"; @@ -90,7 +91,7 @@ public class EntityComparisonUtilityFunctions { QueryRunner highestLevelOrganizationQueryHandler = new GenericQueryRunner( fieldLabelToOutputFieldLabel, aggregationRules, whereClause, - groupOrderClause, Dataset, log); + groupOrderClause, dataset, log); String highestLevelOrgURI = EntityComparisonUtilityFunctions .getHighestLevelOrganizationURI( @@ -100,14 +101,20 @@ public class EntityComparisonUtilityFunctions { } public static Map> getSubEntityTypes(Log log, - Dataset Dataset, String subjectOrganization) + Dataset dataset, String subjectOrganization) throws MalformedQueryParametersException { - ModelConstructor constructQueryRunnerForSubOrganizationTypes = new EntitySubOrganizationTypesConstructQueryRunner(subjectOrganization, Dataset, log) ; - Model constructedModelForSubOrganizationTypes = constructQueryRunnerForSubOrganizationTypes.getConstructedModel(); + ModelConstructor constructQueryRunnerForSubOrganizationTypes = + new EntitySubOrganizationTypesConstructQueryRunner(subjectOrganization, + dataset, + log); - QueryRunner>> queryManagerForsubOrganisationTypes = new EntitySubOrganizationTypesQueryRunner( - subjectOrganization, constructedModelForSubOrganizationTypes, log); + Model constructedModelForSubOrganizationTypes = constructQueryRunnerForSubOrganizationTypes + .getConstructedModel(); + + QueryRunner>> queryManagerForsubOrganisationTypes = + new EntitySubOrganizationTypesQueryRunner( + subjectOrganization, constructedModelForSubOrganizationTypes, log); Map> subOrganizationTypesResult = queryManagerForsubOrganisationTypes .getQueryResult(); @@ -130,12 +137,13 @@ public class EntityComparisonUtilityFunctions { } public static String getStaffProvidedOrComputedHighestLevelOrganization(Log log, - Dataset Dataset, VitroRequest vitroRequest) + Dataset dataset, VitroRequest vitroRequest) throws MalformedQueryParametersException { String finalHighestLevelOrganizationURI = ""; - String staffProvidedHighestLevelOrganization = ConfigurationProperties.getBean(vitroRequest).getProperty("visualization.topLevelOrg"); + String staffProvidedHighestLevelOrganization = ConfigurationProperties.getBean(vitroRequest) + .getProperty("visualization.topLevelOrg"); /* * First checking if the staff has provided highest level organization in deploy.properties @@ -150,12 +158,12 @@ public class EntityComparisonUtilityFunctions { IRI iri = iRIFactory.create(staffProvidedHighestLevelOrganization); if (iri.hasViolation(false)) { - finalHighestLevelOrganizationURI = EntityComparisonUtilityFunctions.getHighestLevelOrganizationURI(log, Dataset); + finalHighestLevelOrganizationURI = EntityComparisonUtilityFunctions + .getHighestLevelOrganizationURI(log, dataset); } else { finalHighestLevelOrganizationURI = staffProvidedHighestLevelOrganization; } } return finalHighestLevelOrganizationURI; } - } diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitycomparison/EntityPublicationCountConstructQueryRunner.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitycomparison/EntityPublicationCountConstructQueryRunner.java index 0e287729..02b9a88e 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitycomparison/EntityPublicationCountConstructQueryRunner.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitycomparison/EntityPublicationCountConstructQueryRunner.java @@ -24,21 +24,21 @@ 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.freemarker.visutils.ModelConstructor; -public class EntityPublicationCountConstructQueryRunner implements ModelConstructor{ +public class EntityPublicationCountConstructQueryRunner implements ModelConstructor { protected static final Syntax SYNTAX = Syntax.syntaxARQ; private String egoURI; - private Dataset Dataset; + private Dataset dataset; private Log log = LogFactory.getLog(EntityPublicationCountConstructQueryRunner.class.getName()); private long before, after; - public EntityPublicationCountConstructQueryRunner(String egoURI, Dataset Dataset, Log log){ + public EntityPublicationCountConstructQueryRunner(String egoURI, Dataset dataset, Log log) { this.egoURI = egoURI; - this.Dataset = Dataset; + this.dataset = dataset; //this.log = log; } @@ -46,21 +46,21 @@ public class EntityPublicationCountConstructQueryRunner implements ModelConstruc String sparqlQuery = "CONSTRUCT { " - + "<"+queryURI+ "> rdfs:label ?organizationLabel ." + + "<" + queryURI + "> rdfs:label ?organizationLabel ." + "}" + "WHERE {" - + "<"+queryURI+ "> rdfs:label ?organizationLabel " + + "<" + queryURI + "> rdfs:label ?organizationLabel " + "}"; return sparqlQuery; } - private String generateConstructQueryForSubOrganizations(String queryURI){ + private String generateConstructQueryForSubOrganizations(String queryURI) { String sparqlQuery = "CONSTRUCT { " - + "<"+queryURI+ "> core:hasSubOrganization ?subOrganization . " + + "<" + queryURI + "> core:hasSubOrganization ?subOrganization . " + "?subOrganization rdfs:label ?subOrganizationLabel . " + "?subOrganization core:organizationForPosition ?Position . " + "?Position core:positionForPerson ?Person . " @@ -71,18 +71,16 @@ public class EntityPublicationCountConstructQueryRunner implements ModelConstruc + "?Document rdfs:label ?DocumentLabel . " + "?Document core:dateTimeValue ?dateTimeValue . " + "?dateTimeValue core:dateTime ?publicationDate . " -// + "?Document core:year ?publicationYearUsing_1_1_property " - +"}" + + "}" + "WHERE { " + "{" - + "<"+queryURI+ "> core:hasSubOrganization ?subOrganization . " + + "<" + 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 " + "}" + "UNION " @@ -90,24 +88,17 @@ public class EntityPublicationCountConstructQueryRunner implements ModelConstruc + "?Document core:dateTimeValue ?dateTimeValue . " + "?dateTimeValue core:dateTime ?publicationDate " + "}" -// + "UNION " -// + "{" -// + "?Document core:year ?publicationYearUsing_1_1_property " -// + "}" - - + "}" ; - - + + "}"; + return sparqlQuery; - } - private String generateConstructQueryForPersons(String queryURI){ + private String generateConstructQueryForPersons(String queryURI) { String sparqlQuery = "CONSTRUCT { " - + "<"+queryURI+ "> core:organizationForPosition ?Position . " + + "<" + queryURI + "> core:organizationForPosition ?Position . " + "?Position core:positionForPerson ?Person . " + "?Person core:authorInAuthorship ?Resource . " + "?Person rdfs:label ?PersonLabel . " @@ -116,16 +107,14 @@ public class EntityPublicationCountConstructQueryRunner implements ModelConstruc + "?Document rdfs:label ?DocumentLabel . " + "?Document core:dateTimeValue ?dateTimeValue . " + "?dateTimeValue core:dateTime ?publicationDate . " -// + "?Document core:year ?publicationYearUsing_1_1_property ." - +"}" + + "}" + "WHERE { " + "{" - + "<"+queryURI+ "> core:organizationForPosition ?Position . " + + "<" + 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 " + "}" + "UNION" @@ -133,16 +122,9 @@ public class EntityPublicationCountConstructQueryRunner implements ModelConstruc + "?Document core:dateTimeValue ?dateTimeValue . " + "?dateTimeValue core:dateTime ?publicationDate " + "}" -// + "UNION " -// + "{" -// + "?Document core:year ?publicationYearUsing_1_1_property " -// + "}" - - + "}" ; - + + "}"; return sparqlQuery; - } // private String generateConstructQueryForDocumentDateTimeValueOneLevelDeep(String queryURI){ @@ -217,7 +199,7 @@ public class EntityPublicationCountConstructQueryRunner implements ModelConstruc // // } - private Model executeQuery(Set constructQueries, Dataset Dataset) { + private Model executeQuery(Set constructQueries, Dataset dataset) { Model constructedModel = ModelFactory.createDefaultModel(); @@ -227,16 +209,17 @@ public class EntityPublicationCountConstructQueryRunner implements ModelConstruc 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()); + 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); + query, dataset); try { qe.execConstruct(constructedModel); @@ -245,9 +228,9 @@ public class EntityPublicationCountConstructQueryRunner implements ModelConstruc } after = System.currentTimeMillis(); - log.debug("Time taken to execute the CONSTRUCT queries is in milliseconds: " + (after - before) ); + log.debug("Time taken to execute the CONSTRUCT queries is in milliseconds: " + + (after - before)); } - // constructedModel.write(System.out); return constructedModel; } @@ -275,7 +258,7 @@ public class EntityPublicationCountConstructQueryRunner implements ModelConstruc populateConstructQueries(constructQueries); Model model = executeQuery(constructQueries, - this.Dataset); + this.dataset); return model; @@ -286,8 +269,7 @@ public class EntityPublicationCountConstructQueryRunner implements ModelConstruc 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)); - +// constructQueries.add(generateConstructQueryForDocumentDateTimeValueOneLevelDeep(this.egoURI)); +// constructQueries.add(generateConstructQueryForDocumentDateTimeValue(this.egoURI)); } } diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitycomparison/EntityPublicationCountQueryRunner.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitycomparison/EntityPublicationCountQueryRunner.java index 6c8a1501..ffc7a151 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitycomparison/EntityPublicationCountQueryRunner.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitycomparison/EntityPublicationCountQueryRunner.java @@ -54,8 +54,7 @@ public class EntityPublicationCountQueryRunner implements QueryRunner { + " (str(?PersonLabel) as ?personLabelLit) " + " (str(?Document) as ?documentLit) " + " (str(?DocumentLabel) as ?documentLabelLit) " - + " (str(?publicationDate) as ?" + QueryFieldLabels.DOCUMENT_PUBLICATION_DATE + ") " - + " (str(?publicationYearUsing_1_1_property) as ?" + QueryFieldLabels.DOCUMENT_PUBLICATION_YEAR_USING_1_1_PROPERTY + ") "; + + " (str(?publicationDate) as ?" + QueryFieldLabels.DOCUMENT_PUBLICATION_DATE + ")"; private static final String SPARQL_QUERY_COMMON_WHERE_CLAUSE = "" @@ -63,13 +62,13 @@ public class EntityPublicationCountQueryRunner implements QueryRunner { + " rdfs:label ?DocumentLabel ." + "OPTIONAL { ?Document core:dateTimeValue ?dateTimeValue . " + " ?dateTimeValue core:dateTime ?publicationDate } ." - + "OPTIONAL { ?Document core:year ?publicationYearUsing_1_1_property } ." ; - - private static String ENTITY_LABEL; - private static String ENTITY_URL; - private static String SUBENTITY_LABEL; - private static String SUBENTITY_URL; + + "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) { @@ -108,13 +107,8 @@ public class EntityPublicationCountQueryRunner implements QueryRunner { biboDocument = new Activity(documentNode.toString()); biboDocumentURLToVO.put(documentNode.toString(), biboDocument); -// RDFNode documentLabelNode = solution -// .get(QueryFieldLabels.DOCUMENT_LABEL); -// if (documentLabelNode != null) { -// biboDocument.setDocumentLabel(documentLabelNode.toString()); -// } - - RDFNode publicationDateNode = solution.get(QueryFieldLabels.DOCUMENT_PUBLICATION_DATE); + RDFNode publicationDateNode = solution.get(QueryFieldLabels + .DOCUMENT_PUBLICATION_DATE); if (publicationDateNode != null) { biboDocument.setActivityDate(publicationDateNode.toString()); } @@ -163,8 +157,8 @@ public class EntityPublicationCountQueryRunner implements QueryRunner { /* * This makes sure that either, - * 1. the parent organization is a department-like organization with no organizations - * beneath it, or + * 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. * */ @@ -187,9 +181,9 @@ public class EntityPublicationCountQueryRunner implements QueryRunner { } - // log.debug("Returning entity that contains the following set of subentities: "+entity.getSubEntities().toString()); after = System.currentTimeMillis(); - log.debug("Time taken to iterate through the ResultSet of SELECT queries is in milliseconds: " + (after - before) ); + log.debug("Time taken to iterate through the ResultSet of SELECT queries is in ms: " + + (after - before)); return entity; } @@ -198,27 +192,12 @@ public class EntityPublicationCountQueryRunner implements QueryRunner { QueryExecution queryExecution = null; Query query = QueryFactory.create( - getSparqlQuery(queryURI), SYNTAX); + getSparqlQueryForOrganization(queryURI), SYNTAX); queryExecution = QueryExecutionFactory.create(query, dataSource); return queryExecution.execSelect(); } - private String getSparqlQuery(String queryURI) { - - String result = ""; - - ENTITY_URL = QueryFieldLabels.ORGANIZATION_URL; - ENTITY_LABEL = QueryFieldLabels.ORGANIZATION_LABEL; - SUBENTITY_URL = QueryFieldLabels.SUBORGANIZATION_URL; - SUBENTITY_LABEL = QueryFieldLabels.SUBORGANIZATION_LABEL; - - result = getSparqlQueryForOrganization(queryURI); - - return result; - } - - - private String getSparqlQueryForOrganization(String queryURI){ + private String getSparqlQueryForOrganization(String queryURI) { String sparqlQuery = QueryConstants.getSparqlPrefixQuery() + "SELECT (str(?organizationLabel) as ?organizationLabelLit) " @@ -229,7 +208,8 @@ public class EntityPublicationCountQueryRunner implements QueryRunner { + "WHERE { " + "<" + queryURI + "> rdfs:label ?organizationLabel ." + "{ " + "<" + queryURI + "> core:hasSubOrganization ?subOrganization ." - + "?subOrganization rdfs:label ?subOrganizationLabel ; core:organizationForPosition ?Position . " + + "?subOrganization rdfs:label ?subOrganizationLabel ;" + + " core:organizationForPosition ?Position . " + " ?Position core:positionForPerson ?Person ." + " ?Person core:authorInAuthorship ?Resource ; rdfs:label ?PersonLabel . " + " ?Resource core:linkedInformationResource ?Document . " @@ -242,10 +222,8 @@ public class EntityPublicationCountQueryRunner implements QueryRunner { + " ?Resource core:linkedInformationResource ?Document ." + SPARQL_QUERY_COMMON_WHERE_CLAUSE + "}" + "}"; - - //System.out.println("\n\nEntity Pub Count query is: "+ sparqlQuery); + log.debug("\nThe sparql query is :\n" + sparqlQuery); - return sparqlQuery; } @@ -253,7 +231,6 @@ public class EntityPublicationCountQueryRunner implements QueryRunner { public Entity getQueryResult() throws MalformedQueryParametersException { if (StringUtils.isNotBlank(this.entityURI)) { - /* * To test for the validity of the URI submitted. */ @@ -278,12 +255,9 @@ public class EntityPublicationCountQueryRunner implements QueryRunner { after = System.currentTimeMillis(); - log.debug("Time taken to execute the SELECT queries is in milliseconds: " + (after - before) ); + 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/freemarker/entitycomparison/EntityPublicationCountRequestHandler.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitycomparison/EntityPublicationCountRequestHandler.java index 242ac291..39fe9e4d 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitycomparison/EntityPublicationCountRequestHandler.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitycomparison/EntityPublicationCountRequestHandler.java @@ -38,26 +38,31 @@ public class EntityPublicationCountRequestHandler implements @Override public ResponseValues generateStandardVisualization( - VitroRequest vitroRequest, Log log, Dataset Dataset) + VitroRequest vitroRequest, Log log, Dataset dataset) throws MalformedQueryParametersException { String entityURI = vitroRequest .getParameter(VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY); - if (StringUtils.isBlank(entityURI)){ + if (StringUtils.isBlank(entityURI)) { entityURI = EntityComparisonUtilityFunctions - .getStaffProvidedOrComputedHighestLevelOrganization(log, Dataset, vitroRequest); + .getStaffProvidedOrComputedHighestLevelOrganization( + log, + dataset, + vitroRequest); } return prepareStandaloneMarkupResponse(vitroRequest, entityURI); } private Map getSubjectEntityAndGenerateDataResponse( - VitroRequest vitroRequest, Log log, Dataset Dataset, + VitroRequest vitroRequest, Log log, Dataset dataset, String subjectEntityURI) throws MalformedQueryParametersException { - ModelConstructor constructQueryRunner = new EntityPublicationCountConstructQueryRunner(subjectEntityURI, Dataset, log); + ModelConstructor constructQueryRunner = + new EntityPublicationCountConstructQueryRunner(subjectEntityURI, dataset, log); + Model constructedModel = constructQueryRunner.getConstructedModel(); QueryRunner queryManager = new EntityPublicationCountQueryRunner( @@ -72,7 +77,7 @@ public class EntityPublicationCountRequestHandler implements } else { return getSubEntityTypesAndComputeDataResponse( - vitroRequest, log, Dataset, + vitroRequest, log, dataset, subjectEntityURI, entity); } } @@ -84,17 +89,19 @@ public class EntityPublicationCountRequestHandler implements 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.\"}"); + 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, + VitroRequest vitroRequest, Log log, Dataset dataset, String subjectEntityURI, Entity entity) throws MalformedQueryParametersException { - Map> subOrganizationTypesResult = EntityComparisonUtilityFunctions.getSubEntityTypes( - log, Dataset, subjectEntityURI); + Map> subOrganizationTypesResult = + EntityComparisonUtilityFunctions.getSubEntityTypes( + log, dataset, subjectEntityURI); return prepareStandaloneDataResponse(vitroRequest, entity, entity.getSubEntities(), subOrganizationTypesResult); @@ -102,7 +109,7 @@ public class EntityPublicationCountRequestHandler implements @Override public Map generateDataVisualization( - VitroRequest vitroRequest, Log log, Dataset Dataset) + VitroRequest vitroRequest, Log log, Dataset dataset) throws MalformedQueryParametersException { String entityURI = vitroRequest @@ -112,25 +119,26 @@ public class EntityPublicationCountRequestHandler implements * This will provide the data in json format mainly used for standalone tmeporal vis. * */ if (VisualizationFrameworkConstants.TEMPORAL_GRAPH_JSON_DATA_VIS_MODE - .equalsIgnoreCase(vitroRequest.getParameter(VisualizationFrameworkConstants.VIS_MODE_KEY))) { + .equalsIgnoreCase(vitroRequest.getParameter( + VisualizationFrameworkConstants.VIS_MODE_KEY))) { - if (StringUtils.isNotBlank(entityURI)){ + if (StringUtils.isNotBlank(entityURI)) { return getSubjectEntityAndGenerateDataResponse( vitroRequest, log, - Dataset, + dataset, entityURI); } else { return getSubjectEntityAndGenerateDataResponse( vitroRequest, log, - Dataset, + dataset, EntityComparisonUtilityFunctions .getStaffProvidedOrComputedHighestLevelOrganization( log, - Dataset, + dataset, vitroRequest)); } @@ -139,7 +147,9 @@ public class EntityPublicationCountRequestHandler implements * This provides csv download files for the content in the tables. * */ - ModelConstructor constructQueryRunner = new EntityPublicationCountConstructQueryRunner(entityURI, Dataset, log); + ModelConstructor constructQueryRunner = + new EntityPublicationCountConstructQueryRunner(entityURI, dataset, log); + Model constructedModel = constructQueryRunner.getConstructedModel(); QueryRunner queryManager = new EntityPublicationCountQueryRunner( @@ -147,10 +157,11 @@ public class EntityPublicationCountRequestHandler implements Entity entity = queryManager.getQueryResult(); - Map> subOrganizationTypesResult = EntityComparisonUtilityFunctions.getSubEntityTypes( - log, Dataset, entityURI); + Map> subOrganizationTypesResult = + EntityComparisonUtilityFunctions.getSubEntityTypes( + log, dataset, entityURI); - return prepareDataResponse(entity, entity.getSubEntities(),subOrganizationTypesResult); + return prepareDataResponse(entity, entity.getSubEntities(), subOrganizationTypesResult); } @@ -159,7 +170,7 @@ public class EntityPublicationCountRequestHandler implements @Override public Object generateAjaxVisualization(VitroRequest vitroRequest, Log log, - Dataset Dataset) throws MalformedQueryParametersException { + Dataset dataset) throws MalformedQueryParametersException { throw new UnsupportedOperationException("Entity Pub Count does not provide Ajax Response."); } @@ -208,8 +219,10 @@ public class EntityPublicationCountRequestHandler implements fileData.put(DataVisualizationController.FILE_CONTENT_TYPE_KEY, "application/octet-stream"); - fileData.put(DataVisualizationController.FILE_CONTENT_KEY, - writePublicationsOverTimeJSON(vitroRequest, entity.getSubEntities(), subOrganizationTypesResult)); + fileData.put(DataVisualizationController.FILE_CONTENT_KEY, + writePublicationsOverTimeJSON(vitroRequest, + entity.getSubEntities(), + subOrganizationTypesResult)); return fileData; } @@ -219,8 +232,9 @@ public class EntityPublicationCountRequestHandler implements Portal portal = vreq.getPortal(); String standaloneTemplate = "entityComparisonOnPublicationsStandalone.ftl"; - String organizationLabel = EntityComparisonUtilityFunctions.getEntityLabelFromDAO(vreq, - entityURI); + String organizationLabel = EntityComparisonUtilityFunctions + .getEntityLabelFromDAO(vreq, + entityURI); Map body = new HashMap(); body.put("portalBean", portal); @@ -232,7 +246,7 @@ public class EntityPublicationCountRequestHandler implements } /** - * function to generate a json file for year <-> publication count mapping + * Function to generate a json file for year <-> publication count mapping. * @param vreq * @param subentities * @param subOrganizationTypesResult @@ -266,35 +280,33 @@ public class EntityPublicationCountRequestHandler implements yearPubCount.add(currentPubYear); } - //log.info("entityJson.getLabel() : " + entityJson.getLabel() + " subOrganizationTypesResult " + subOrganizationTypesResult.toString()); - entityJson.setYearToActivityCount(yearPubCount); - entityJson.getOrganizationType().addAll(subOrganizationTypesResult.get(entityJson.getLabel())); + entityJson.getOrganizationType().addAll( + subOrganizationTypesResult.get(entityJson.getLabel())); entityJson.setEntityURI(subentity.getIndividualURI()); boolean isPerson = UtilityFunctions.isEntityAPerson(vreq, subentity); - if(isPerson){ + if (isPerson) { entityJson.setVisMode("PERSON"); - } else{ + } else { entityJson.setVisMode("ORGANIZATION"); } - // setEntityVisMode(entityJson); subEntitiesJson.add(entityJson); } - return json.toJson(subEntitiesJson); - } - private String getEntityPublicationsPerYearCSVContent(Set subentities, Map> subOrganizationTypesResult) { + private String getEntityPublicationsPerYearCSVContent( + Set subentities, + Map> subOrganizationTypesResult) { StringBuilder csvFileContent = new StringBuilder(); csvFileContent.append("Entity Name, Publication Count, Entity Type\n"); - for(SubEntity subEntity : subentities){ + for (SubEntity subEntity : subentities) { csvFileContent.append(StringEscapeUtils.escapeCsv(subEntity.getIndividualLabel())); csvFileContent.append(", "); @@ -303,17 +315,14 @@ public class EntityPublicationCountRequestHandler implements StringBuilder joinedTypes = new StringBuilder(); - for(String subOrganizationType : subOrganizationTypesResult.get(subEntity.getIndividualLabel())){ + for (String subOrganizationType : subOrganizationTypesResult + .get(subEntity.getIndividualLabel())) { joinedTypes.append(subOrganizationType + "; "); } csvFileContent.append(StringEscapeUtils.escapeCsv(joinedTypes.toString())); csvFileContent.append("\n"); - } - return csvFileContent.toString(); - } - } \ No newline at end of file diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitycomparison/EntitySubOrganizationTypesConstructQueryRunner.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitycomparison/EntitySubOrganizationTypesConstructQueryRunner.java index de596ae6..f7aa55b6 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitycomparison/EntitySubOrganizationTypesConstructQueryRunner.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitycomparison/EntitySubOrganizationTypesConstructQueryRunner.java @@ -30,13 +30,14 @@ public class EntitySubOrganizationTypesConstructQueryRunner implements ModelCons private String egoURI; - private Dataset Dataset; + private Dataset dataset; - private Log log = LogFactory.getLog(EntitySubOrganizationTypesConstructQueryRunner.class.getName()); + private Log log = LogFactory.getLog(EntitySubOrganizationTypesConstructQueryRunner + .class.getName()); - public EntitySubOrganizationTypesConstructQueryRunner(String egoURI, Dataset Dataset, Log log){ + public EntitySubOrganizationTypesConstructQueryRunner(String egoURI, Dataset dataset, Log log) { this.egoURI = egoURI; - this.Dataset = Dataset; + this.dataset = dataset; //this.log = log; } @@ -44,20 +45,20 @@ public class EntitySubOrganizationTypesConstructQueryRunner implements ModelCons String sparqlQuery = "CONSTRUCT { " - + "<"+queryURI+ "> rdfs:label ?organizationLabel ." + + "<" + queryURI + "> rdfs:label ?organizationLabel ." + "}" + "WHERE {" - + "<"+queryURI+ "> rdfs:label ?organizationLabel " + + "<" + queryURI + "> rdfs:label ?organizationLabel " + "}"; return sparqlQuery; } - private String generateConstructQueryForSubOrganizationTypes(String queryURI){ + private String generateConstructQueryForSubOrganizationTypes(String queryURI) { String sparqlQuery = "CONSTRUCT { " - + "<"+queryURI+ "> core:hasSubOrganization ?subOrganization . " + + "<" + queryURI + "> core:hasSubOrganization ?subOrganization . " + "?subOrganization rdfs:label ?subOrganizationLabel . " + "?subOrganization rdf:type ?subOrganizationType . " + "?subOrganization core:organizationForPosition ?Position . " @@ -66,9 +67,9 @@ public class EntitySubOrganizationTypesConstructQueryRunner implements ModelCons + "?Person rdfs:label ?PersonLabel ." + "?Person rdf:type ?PersonType . " + "?PersonType rdfs:label ?PersonTypeLabel " - +"}" + + "}" + "WHERE { " - + "<"+queryURI+ "> core:hasSubOrganization ?subOrganization . " + + "<" + queryURI + "> core:hasSubOrganization ?subOrganization . " + "?subOrganization rdfs:label ?subOrganizationLabel . " + "?subOrganization rdf:type ?subOrganizationType . " + "?subOrganizationType rdfs:label ?subOrganizationTypeLabel . " @@ -77,39 +78,34 @@ public class EntitySubOrganizationTypesConstructQueryRunner implements ModelCons + "?Person rdfs:label ?PersonLabel ." + "?Person rdf:type ?PersonType . " + "?PersonType rdfs:label ?PersonTypeLabel " - - + "}" ; + + "}"; - return sparqlQuery; - } - private String generateConstructQueryForPersonTypes(String queryURI){ + private String generateConstructQueryForPersonTypes(String queryURI) { String sparqlQuery = "CONSTRUCT { " - + "<"+queryURI+ "> core:organizationForPosition ?Position . " + + "<" + 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 . " + + "<" + 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) { + private Model executeQuery(Set constructQueries, Dataset dataset) { Model constructedModel = ModelFactory.createDefaultModel(); long before = 0; @@ -121,30 +117,31 @@ public class EntitySubOrganizationTypesConstructQueryRunner implements ModelCons 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()); + 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); + query, dataset); try { qe.execConstruct(constructedModel); } finally { qe.close(); } - log.debug("Time to run " + (before - System.currentTimeMillis()) ); + log.debug("Time to run " + (before - System.currentTimeMillis())); } return constructedModel; } public Model getConstructedModel() - throws MalformedQueryParametersException { + throws MalformedQueryParametersException { if (StringUtils.isNotBlank(this.egoURI)) { /* @@ -167,19 +164,14 @@ public class EntitySubOrganizationTypesConstructQueryRunner implements ModelCons populateConstructQueries(constructQueries); Model model = executeQuery(constructQueries, - this.Dataset); + 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/freemarker/entitycomparison/EntitySubOrganizationTypesQueryRunner.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitycomparison/EntitySubOrganizationTypesQueryRunner.java index c5f1a317..2ba8f8d4 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitycomparison/EntitySubOrganizationTypesQueryRunner.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitycomparison/EntitySubOrganizationTypesQueryRunner.java @@ -2,7 +2,9 @@ package edu.cornell.mannlib.vitro.webapp.visualization.freemarker.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; @@ -11,7 +13,6 @@ 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.DataSource; import com.hp.hpl.jena.query.Query; import com.hp.hpl.jena.query.QueryExecution; import com.hp.hpl.jena.query.QueryExecutionFactory; @@ -19,24 +20,21 @@ 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 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.freemarker.visutils.QueryRunner; -import java.util.Set; -import java.util.HashSet; - /** * @author bkoniden * Deepak Konidena */ -public class EntitySubOrganizationTypesQueryRunner implements QueryRunner>> { +public class EntitySubOrganizationTypesQueryRunner + implements QueryRunner>> { protected static final Syntax SYNTAX = Syntax.syntaxARQ; @@ -45,17 +43,18 @@ public class EntitySubOrganizationTypesQueryRunner implements QueryRunner rdfs:label ?organizationLabel . " + "{ " - + "<"+ queryURI + "> core:hasSubOrganization ?subOrganization . " - + "?subOrganization rdfs:label ?subOrganizationLabel ; rdf:type ?subOrganizationType ;" + + "<" + 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 . " + + "<" + queryURI + "> core:organizationForPosition ?Position . " + "?Position core:positionForPerson ?Person . " + "?Person rdfs:label ?PersonLabel ; rdf:type ?PersonType . " + "?PersonType rdfs:label ?PersonTypeLabel . " + "}" + "}"; - - - // log.debug("\n SubOrganizationTypesQuery :" + sparqlQuery); - return sparqlQuery; - } private Map> createJavaValueObjects(ResultSet resultSet) { - // Map> subOrganizationLabelToTypes = new HashMap>(); - // Map> personLabelToTypes = new HashMap>(); Map> subEntityLabelToTypes = new HashMap>(); - while(resultSet.hasNext()){ + while (resultSet.hasNext()) { QuerySolution solution = resultSet.nextSolution(); @@ -165,20 +158,13 @@ public class EntitySubOrganizationTypesQueryRunner implements QueryRunner " + subOrganizationLabelToTypes.size()); -// System.out.println("\n\nPeople Label Types Size --> " + personLabelToTypes.size()); - -// log.debug("Sub Organization Label Types Size : " + subEntityLabelToTypes.size()); - + return subEntityLabelToTypes; - //return (subOrganizationLabelToTypes.size() != 0 )? subOrganizationLabelToTypes : personLabelToTypes ; } public Map> getQueryResult() throws MalformedQueryParametersException { if (StringUtils.isNotBlank(this.entityURI)) { - /* * To test for the validity of the URI submitted. */ @@ -191,16 +177,13 @@ public class EntitySubOrganizationTypesQueryRunner implements QueryRunner rdfs:label ?organizationLabel ." - + "}" - + "WHERE {" - + "<"+queryURI+ "> rdfs:label ?organizationLabel " - + "}"; - + + 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 { + 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; - 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(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")); + + } - 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/freemarker/entitygrantcount/EntityGrantCountQueryRunner.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitygrantcount/EntityGrantCountQueryRunner.java index 8086527d..60b2382b 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitygrantcount/EntityGrantCountQueryRunner.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitygrantcount/EntityGrantCountQueryRunner.java @@ -60,7 +60,7 @@ public class EntityGrantCountQueryRunner implements QueryRunner { + " (str(?startDateTimeValue) as ?grantStartDateLit) " + " (str(?endDateTimeValue) as ?grantEndDateLit) " + " (str(?startDateTimeValueForGrant) as ?grantStartDateForGrantLit) " - + " (str(?endDateTimeValueForGrant) as ?grantEndDateForGrantLit) " ; + + " (str(?endDateTimeValueForGrant) as ?grantEndDateForGrantLit)"; private static final String SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_ROLE_DATE_TIME = " " + " ?Role core:roleIn ?Grant . " @@ -73,7 +73,7 @@ public class EntityGrantCountQueryRunner implements QueryRunner { + "?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 . " @@ -86,13 +86,13 @@ public class EntityGrantCountQueryRunner implements QueryRunner { + "?dateTimeIntervalValueForGrant core:end ?endDateForGrant . " + "?endDateForGrant core:dateTime ?endDateTimeValueForGrant . " + "}" - + "}" ; + + "}"; - private static String ENTITY_LABEL = QueryFieldLabels.ORGANIZATION_LABEL; - private static String ENTITY_URL = QueryFieldLabels.ORGANIZATION_URL; - private static String SUBENTITY_LABEL = QueryFieldLabels.SUBORGANIZATION_LABEL ; - private static String SUBENTITY_URL = QueryFieldLabels.SUBORGANIZATION_URL; + 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, @@ -113,7 +113,6 @@ public class EntityGrantCountQueryRunner implements QueryRunner { before = System.currentTimeMillis(); while (resultSet.hasNext()) { - // log.debug("Checking whether EntityGrantCount produced any resultset against the Constructed Model"); QuerySolution solution = resultSet.nextSolution(); if (entity == null) { @@ -207,15 +206,13 @@ public class EntityGrantCountQueryRunner implements QueryRunner { /* * This makes sure that either, - * 1. the parent organization is a department-like organization with no organizations - * beneath it, or + * 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); @@ -225,16 +222,13 @@ public class EntityGrantCountQueryRunner implements QueryRunner { entity.addActivity(grant); } - /*if (subentityURLToVO.size() == 0 && personURLToVO.size() != 0) { - for (SubEntity person : personURLToVO.values()) { - entity.addSubEntity(person); - } - } else */if (subentityURLToVO.size() == 0 && personURLToVO.size() == 0) { + 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 milliseconds: " + (after - before) ); + log.debug("Time taken to iterate through the ResultSet of SELECT queries is in ms: " + + (after - before)); return entity; } @@ -247,7 +241,7 @@ public class EntityGrantCountQueryRunner implements QueryRunner { return queryExecution.execSelect(); } - private String getSparqlQuery(String queryURI){ + private String getSparqlQuery(String queryURI) { String sparqlQuery = QueryConstants.getSparqlPrefixQuery() + SPARQL_QUERY_COMMON_SELECT_CLAUSE + " (str(<" + queryURI @@ -255,7 +249,8 @@ public class EntityGrantCountQueryRunner implements QueryRunner { + "WHERE { " + "<" + queryURI + "> rdfs:label ?organizationLabel ." + "{ " + "<" + queryURI + "> core:hasSubOrganization ?subOrganization ." - + " ?subOrganization rdfs:label ?subOrganizationLabel ; core:organizationForPosition ?Position . " + + " ?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 @@ -263,7 +258,8 @@ public class EntityGrantCountQueryRunner implements QueryRunner { + "UNION " + "{ " + "<" + queryURI + "> core:hasSubOrganization ?subOrganization . " - + " ?subOrganization rdfs:label ?subOrganizationLabel ; core:organizationForPosition ?Position . " + + " ?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 @@ -271,7 +267,8 @@ public class EntityGrantCountQueryRunner implements QueryRunner { + "UNION " + "{ " + "<" + queryURI + "> core:hasSubOrganization ?subOrganization . " - + " ?subOrganization rdfs:label ?subOrganizationLabel ; core:organizationForPosition ?Position . " + + " ?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 @@ -299,18 +296,12 @@ public class EntityGrantCountQueryRunner implements QueryRunner { + SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_GRANT_DATE_TIME + "}" + " } "; - //System.out.println("\n\nEntity Activity Count query is: "+ sparqlQuery); - - // 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. */ @@ -335,7 +326,8 @@ public class EntityGrantCountQueryRunner implements QueryRunner { after = System.currentTimeMillis(); - log.debug("Time taken to execute the SELECT queries is in milliseconds: " + (after - before) ); + log.debug("Time taken to execute the SELECT queries is in milliseconds: " + + (after - before)); return createJavaValueObjects(resultSet); } diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitygrantcount/EntityGrantCountRequestHandler.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitygrantcount/EntityGrantCountRequestHandler.java index adce0f9d..909ff7a5 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitygrantcount/EntityGrantCountRequestHandler.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitygrantcount/EntityGrantCountRequestHandler.java @@ -40,16 +40,19 @@ public class EntityGrantCountRequestHandler implements @Override public ResponseValues generateStandardVisualization( - VitroRequest vitroRequest, Log log, Dataset Dataset) + VitroRequest vitroRequest, Log log, Dataset dataset) throws MalformedQueryParametersException { String entityURI = vitroRequest .getParameter(VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY); - if (StringUtils.isBlank(entityURI)){ + if (StringUtils.isBlank(entityURI)) { entityURI = EntityComparisonUtilityFunctions - .getStaffProvidedOrComputedHighestLevelOrganization(log, Dataset, vitroRequest); + .getStaffProvidedOrComputedHighestLevelOrganization( + log, + dataset, + vitroRequest); } return prepareStandaloneMarkupResponse(vitroRequest, entityURI); @@ -57,7 +60,7 @@ public class EntityGrantCountRequestHandler implements @Override public Map generateDataVisualization( - VitroRequest vitroRequest, Log log, Dataset Dataset) + VitroRequest vitroRequest, Log log, Dataset dataset) throws MalformedQueryParametersException { String entityURI = vitroRequest @@ -67,25 +70,26 @@ public class EntityGrantCountRequestHandler implements * This will provide the data in json format mainly used for standalone temporal vis. * */ if (VisualizationFrameworkConstants.TEMPORAL_GRAPH_JSON_DATA_VIS_MODE - .equalsIgnoreCase(vitroRequest.getParameter(VisualizationFrameworkConstants.VIS_MODE_KEY))) { + .equalsIgnoreCase(vitroRequest + .getParameter(VisualizationFrameworkConstants.VIS_MODE_KEY))) { - if (StringUtils.isNotBlank(entityURI)){ + if (StringUtils.isNotBlank(entityURI)) { return getSubjectEntityAndGenerateDataResponse( vitroRequest, log, - Dataset, + dataset, entityURI); } else { return getSubjectEntityAndGenerateDataResponse( vitroRequest, log, - Dataset, + dataset, EntityComparisonUtilityFunctions .getStaffProvidedOrComputedHighestLevelOrganization( log, - Dataset, + dataset, vitroRequest)); } @@ -93,8 +97,9 @@ public class EntityGrantCountRequestHandler implements /* * This provides csv download files for the content in the tables. * */ + ModelConstructor constructQueryRunner = + new EntityGrantCountConstructQueryRunner(entityURI, dataset, log); - ModelConstructor constructQueryRunner = new EntityGrantCountConstructQueryRunner(entityURI, Dataset, log); Model constructedModel = constructQueryRunner.getConstructedModel(); QueryRunner queryManager = new EntityGrantCountQueryRunner( @@ -103,10 +108,11 @@ public class EntityGrantCountRequestHandler implements Entity entity = queryManager.getQueryResult(); - Map> subOrganizationTypesResult = EntityComparisonUtilityFunctions.getSubEntityTypes( - log, Dataset, entityURI); + Map> subOrganizationTypesResult = + EntityComparisonUtilityFunctions.getSubEntityTypes( + log, dataset, entityURI); - return prepareDataResponse(entity, entity.getSubEntities(),subOrganizationTypesResult); + return prepareDataResponse(entity, entity.getSubEntities(), subOrganizationTypesResult); } @@ -114,16 +120,20 @@ public class EntityGrantCountRequestHandler implements @Override public Object generateAjaxVisualization(VitroRequest vitroRequest, Log log, - Dataset Dataset) throws MalformedQueryParametersException { - throw new UnsupportedOperationException("Entity Grant Count does not provide Ajax Response."); + Dataset dataset) throws MalformedQueryParametersException { + + throw new UnsupportedOperationException("Entity Grant Count " + + "does not provide Ajax response."); } private Map getSubjectEntityAndGenerateDataResponse( - VitroRequest vitroRequest, Log log, Dataset Dataset, + VitroRequest vitroRequest, Log log, Dataset dataset, String subjectEntityURI) throws MalformedQueryParametersException { - ModelConstructor constructQueryRunner = new EntityGrantCountConstructQueryRunner(subjectEntityURI, Dataset, log); + ModelConstructor constructQueryRunner = + new EntityGrantCountConstructQueryRunner(subjectEntityURI, dataset, log); + Model constructedModel = constructQueryRunner.getConstructedModel(); QueryRunner queryManager = new EntityGrantCountQueryRunner( @@ -136,18 +146,19 @@ public class EntityGrantCountRequestHandler implements } else { return getSubEntityTypesAndComputeDataResponse( - vitroRequest, log, Dataset, + vitroRequest, log, dataset, subjectEntityURI, entity); } } private Map getSubEntityTypesAndComputeDataResponse( - VitroRequest vitroRequest, Log log, Dataset Dataset, + VitroRequest vitroRequest, Log log, Dataset dataset, String subjectOrganization, Entity entity) throws MalformedQueryParametersException { - Map> subOrganizationTypesResult = EntityComparisonUtilityFunctions.getSubEntityTypes( - log, Dataset, subjectOrganization); + Map> subOrganizationTypesResult = + EntityComparisonUtilityFunctions.getSubEntityTypes( + log, dataset, subjectOrganization); return prepareStandaloneDataResponse(vitroRequest, entity, subOrganizationTypesResult); } @@ -160,7 +171,8 @@ public class EntityGrantCountRequestHandler implements 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.\"}"); + fileData.put(DataVisualizationController.FILE_CONTENT_KEY, + "{\"error\" : \"No Grants for this Organization found in VIVO.\"}"); return fileData; } @@ -175,7 +187,9 @@ public class EntityGrantCountRequestHandler implements fileData.put(DataVisualizationController.FILE_CONTENT_TYPE_KEY, "application/octet-stream"); fileData.put(DataVisualizationController.FILE_CONTENT_KEY, - writeGrantsOverTimeJSON(vitroRequest, entity.getSubEntities(), subOrganizationTypesResult)); + writeGrantsOverTimeJSON(vitroRequest, + entity.getSubEntities(), + subOrganizationTypesResult)); return fileData; } @@ -234,12 +248,14 @@ public class EntityGrantCountRequestHandler implements } /** - * function to generate a json file for year <-> grant count mapping + * Function to generate a json file for year <-> grant count mapping. * @param vreq * @param subentities * @param subOrganizationTypesResult */ - private String writeGrantsOverTimeJSON(VitroRequest vreq, Set subentities, Map> subOrganizationTypesResult) { + private String writeGrantsOverTimeJSON(VitroRequest vreq, + Set subentities, + Map> subOrganizationTypesResult) { Gson json = new Gson(); Set subEntitiesJson = new HashSet(); @@ -267,15 +283,14 @@ public class EntityGrantCountRequestHandler implements } entityJson.setYearToActivityCount(yearGrantCount); - entityJson.getOrganizationType().addAll(subOrganizationTypesResult.get(entityJson.getLabel())); + entityJson.getOrganizationType().addAll( + subOrganizationTypesResult.get(entityJson.getLabel())); entityJson.setEntityURI(subentity.getIndividualURI()); - boolean isPerson = UtilityFunctions.isEntityAPerson(vreq, subentity); - - if(isPerson){ + if (UtilityFunctions.isEntityAPerson(vreq, subentity)) { entityJson.setVisMode("PERSON"); - } else{ + } else { entityJson.setVisMode("ORGANIZATION"); } @@ -285,15 +300,16 @@ public class EntityGrantCountRequestHandler implements return json.toJson(subEntitiesJson); } - - - private String getEntityGrantsPerYearCSVContent(Set subentities, Map> subOrganizationTypesResult) { + + private String getEntityGrantsPerYearCSVContent( + Set subentities, + Map> subOrganizationTypesResult) { StringBuilder csvFileContent = new StringBuilder(); csvFileContent.append("Entity Name, Grant Count, Entity Type\n"); - for(SubEntity subEntity : subentities){ + for (SubEntity subEntity : subentities) { csvFileContent.append(StringEscapeUtils.escapeCsv(subEntity.getIndividualLabel())); csvFileContent.append(", "); @@ -302,7 +318,8 @@ public class EntityGrantCountRequestHandler implements StringBuilder joinedTypes = new StringBuilder(); - for(String subOrganizationType : subOrganizationTypesResult.get(subEntity.getIndividualLabel())){ + for (String subOrganizationType : subOrganizationTypesResult + .get(subEntity.getIndividualLabel())) { joinedTypes.append(subOrganizationType + "; "); } @@ -312,6 +329,4 @@ public class EntityGrantCountRequestHandler implements return csvFileContent.toString(); } - - } diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/persongrantcount/PersonGrantCountQueryRunner.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/persongrantcount/PersonGrantCountQueryRunner.java index c416b44e..ad95526c 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/persongrantcount/PersonGrantCountQueryRunner.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/persongrantcount/PersonGrantCountQueryRunner.java @@ -30,20 +30,21 @@ import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.QueryR /** - * This query runner is used to execute Sparql query that will fetch all the grants for an individual + * 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>{ +public class PersonGrantCountQueryRunner implements QueryRunner> { protected static final Syntax SYNTAX = Syntax.syntaxARQ; private String personURI; - private Dataset Dataset; + private Dataset dataset; private Individual principalInvestigator; - public Individual getPrincipalInvestigator(){ + public Individual getPrincipalInvestigator() { return principalInvestigator; } @@ -69,7 +70,7 @@ public class PersonGrantCountQueryRunner implements QueryRunner>{ + "?dateTimeIntervalValue core:end ?endDate . " + "?endDate core:dateTime ?endDateTimeValue . " + "}" - + "} . " ; + + "} . "; private static final String SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_GRANT_DATE_TIME = "" + "OPTIONAL {" @@ -80,35 +81,35 @@ public class PersonGrantCountQueryRunner implements QueryRunner>{ + "?dateTimeIntervalValueForGrant core:end ?endDateForGrant . " + "?endDateForGrant core:dateTime ?endDateTimeValueForGrant . " + "}" - + "}" ; + + "}"; - public PersonGrantCountQueryRunner(String personURI, Dataset Dataset, Log log){ + public PersonGrantCountQueryRunner(String personURI, Dataset dataset, Log log) { this.personURI = personURI; - this.Dataset = Dataset; + this.dataset = dataset; this.log = log; } - private Set createJavaValueObjects(ResultSet resultSet){ - Set PIGrant = new HashSet(); + private Set createJavaValueObjects(ResultSet resultSet) { + Set grants = new HashSet(); - while(resultSet.hasNext()){ + 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){ + if (grantLabelNode != null) { grant.setIndividualLabel(grantLabelNode.toString()); } RDFNode grantStartDateNode = solution.get(QueryFieldLabels.ROLE_START_DATE); - if(grantStartDateNode != null){ + if (grantStartDateNode != null) { grant.setActivityDate(grantStartDateNode.toString()); - }else { + } else { grantStartDateNode = solution.get(QueryFieldLabels.GRANT_START_DATE); - if(grantStartDateNode != null){ + if (grantStartDateNode != null) { grant.setActivityDate(grantStartDateNode.toString()); } } @@ -131,33 +132,33 @@ public class PersonGrantCountQueryRunner implements QueryRunner>{ * to create only one "Individual" instance. We test against the null for "PI" to * make sure that it has not already been instantiated. * */ - RDFNode PIURLNode = solution.get(QueryFieldLabels.PI_URL); - if (PIURLNode != null && principalInvestigator == null) { - principalInvestigator = new Individual(PIURLNode.toString()); - RDFNode PILabelNode = solution.get(QueryFieldLabels.PI_LABEL); - if (PILabelNode != null) { - principalInvestigator.setIndividualLabel(PILabelNode.toString()); + 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()); } } - PIGrant.add(grant); + grants.add(grant); } - return PIGrant; + return grants; } - private ResultSet executeQuery(String queryURI, Dataset Dataset){ + private ResultSet executeQuery(String queryURI, Dataset dataset) { QueryExecution queryExecution = null; Query query = QueryFactory.create(getSparqlQuery(queryURI), SYNTAX); - queryExecution = QueryExecutionFactory.create(query,Dataset); + queryExecution = QueryExecutionFactory.create(query, dataset); return queryExecution.execSelect(); } - private String getSparqlQuery(String queryURI){ + private String getSparqlQuery(String queryURI) { String sparqlQuery = QueryConstants.getSparqlPrefixQuery() @@ -170,7 +171,7 @@ public class PersonGrantCountQueryRunner implements QueryRunner>{ + "<" + queryURI + "> rdfs:label ?PILabel . " + "{ " - + "<" + queryURI + "> core:hasCo-PrincipalInvestigatorRole ?Role . " + + "<" + queryURI + "> core:hasCo-PrincipalInvestigatorRole ?Role . " + "?Role core:roleIn ?Grant . " @@ -186,7 +187,7 @@ public class PersonGrantCountQueryRunner implements QueryRunner>{ + "{ " - + "<" + queryURI + "> core:hasPrincipalInvestigatorRole ?Role . " + + "<" + queryURI + "> core:hasPrincipalInvestigatorRole ?Role . " + "?Role core:roleIn ?Grant . " @@ -218,15 +219,15 @@ public class PersonGrantCountQueryRunner implements QueryRunner>{ + "} "; - log.debug("SPARQL query for person grant count -> \n"+ sparqlQuery); + 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{ + public Set getQueryResult() throws MalformedQueryParametersException { - if(StringUtils.isNotBlank(this.personURI)){ + if (StringUtils.isNotBlank(this.personURI)) { /* * To test the validity of the URI submitted @@ -234,7 +235,7 @@ public class PersonGrantCountQueryRunner implements QueryRunner>{ IRIFactory iriFactory = IRIFactory.jenaImplementation(); IRI iri = iriFactory.create(this.personURI); - if(iri.hasViolation(false)){ + if (iri.hasViolation(false)) { String errorMsg = ((Violation) iri.violations(false).next()).getShortMessage(); log.error("Grant Count vis Query " + errorMsg); throw new MalformedQueryParametersException( @@ -244,7 +245,7 @@ public class PersonGrantCountQueryRunner implements QueryRunner>{ throw new MalformedQueryParametersException("URL parameter is either null or empty."); } - ResultSet resultSet = executeQuery(this.personURI, this.Dataset); + ResultSet resultSet = executeQuery(this.personURI, this.dataset); return createJavaValueObjects(resultSet); } diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/persongrantcount/PersonGrantCountRequestHandler.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/persongrantcount/PersonGrantCountRequestHandler.java index 76257a46..1165c52f 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/persongrantcount/PersonGrantCountRequestHandler.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/persongrantcount/PersonGrantCountRequestHandler.java @@ -47,13 +47,14 @@ public class PersonGrantCountRequestHandler implements VisualizationRequestHandl @Override public Map generateDataVisualization( - VitroRequest vitroRequest, Log log, Dataset Dataset) + VitroRequest vitroRequest, Log log, Dataset dataset) throws MalformedQueryParametersException { String personURI = vitroRequest .getParameter(VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY); - QueryRunner> queryManager = new PersonGrantCountQueryRunner(personURI, Dataset, log ); + QueryRunner> queryManager = + new PersonGrantCountQueryRunner(personURI, dataset, log); Set piGrants = queryManager.getQueryResult(); @@ -64,7 +65,8 @@ public class PersonGrantCountRequestHandler implements VisualizationRequestHandl Map yearToGrantCount = UtilityFunctions.getYearToActivityCount(piGrants); - Individual investigator = ((PersonGrantCountQueryRunner) queryManager).getPrincipalInvestigator(); + Individual investigator = ((PersonGrantCountQueryRunner) queryManager) + .getPrincipalInvestigator(); return prepareDataResponse(investigator, piGrants, @@ -76,7 +78,7 @@ public class PersonGrantCountRequestHandler implements VisualizationRequestHandl @Override public Object generateAjaxVisualization(VitroRequest vitroRequest, Log log, - Dataset Dataset) throws MalformedQueryParametersException { + Dataset dataset) throws MalformedQueryParametersException { String personURI = vitroRequest .getParameter(VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY); @@ -87,7 +89,8 @@ public class PersonGrantCountRequestHandler implements VisualizationRequestHandl String visContainer = vitroRequest .getParameter(VisualizationFrameworkConstants.VIS_CONTAINER_KEY); - QueryRunner> queryManager = new PersonGrantCountQueryRunner(personURI, Dataset, log ); + QueryRunner> queryManager = + new PersonGrantCountQueryRunner(personURI, dataset, log); Set piGrants = queryManager.getQueryResult(); @@ -99,8 +102,7 @@ public class PersonGrantCountRequestHandler implements VisualizationRequestHandl UtilityFunctions.getYearToActivityCount(piGrants); - boolean shouldVIVOrenderVis = - yearToGrantCount.size() > 0 ? true : false; + boolean shouldVIVOrenderVis = yearToGrantCount.size() > 0 ? true : false; /* * Computations required to generate HTML for the sparkline & related context. @@ -125,7 +127,7 @@ public class PersonGrantCountRequestHandler implements VisualizationRequestHandl @Override public ResponseValues generateStandardVisualization( - VitroRequest vitroRequest, Log log, Dataset Dataset) + VitroRequest vitroRequest, Log log, Dataset dataset) throws MalformedQueryParametersException { String personURI = vitroRequest @@ -137,7 +139,8 @@ public class PersonGrantCountRequestHandler implements VisualizationRequestHandl String visContainer = vitroRequest .getParameter(VisualizationFrameworkConstants.VIS_CONTAINER_KEY); - QueryRunner> queryManager = new PersonGrantCountQueryRunner(personURI, Dataset, log ); + QueryRunner> queryManager = + new PersonGrantCountQueryRunner(personURI, dataset, log); Set piGrants = queryManager.getQueryResult(); diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/persongrantcount/PersonGrantCountVisCodeGenerator.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/persongrantcount/PersonGrantCountVisCodeGenerator.java index 3274fd90..a874655c 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/persongrantcount/PersonGrantCountVisCodeGenerator.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/persongrantcount/PersonGrantCountVisCodeGenerator.java @@ -136,7 +136,8 @@ public class PersonGrantCountVisCodeGenerator { */ int renderedFullSparks = 0; - List yearToGrantCountDataTable = new ArrayList(); + List yearToGrantCountDataTable = + new ArrayList(); for (int grantYear = minGrantYearConsidered; grantYear <= currentYear; grantYear++) { @@ -205,24 +206,22 @@ public class PersonGrantCountVisCodeGenerator { sparklineData.setShortVisMode(true); } else { - sparklineData.setShortVisMode(false); } if (yearToGrantCount.size() > 0) { - sparklineData.setFullTimelineNetworkLink(UtilityFunctions.getCollaboratorshipNetworkLink(individualURI, - VisualizationFrameworkConstants.PERSON_LEVEL_VIS, - VisualizationFrameworkConstants.COPI_VIS_MODE)); - - sparklineData.setDownloadDataLink(UtilityFunctions - .getCSVDownloadURL( - individualURI, - VisualizationFrameworkConstants.PERSON_GRANT_COUNT_VIS, - "")); + sparklineData.setFullTimelineNetworkLink( + UtilityFunctions.getCollaboratorshipNetworkLink(individualURI, + VisualizationFrameworkConstants.PERSON_LEVEL_VIS, + VisualizationFrameworkConstants.COPI_VIS_MODE)); + sparklineData.setDownloadDataLink( + UtilityFunctions.getCSVDownloadURL( + individualURI, + VisualizationFrameworkConstants.PERSON_GRANT_COUNT_VIS, + "")); } - return sparklineData; } diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/personlevel/PersonLevelRequestHandler.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/personlevel/PersonLevelRequestHandler.java index 14c4e7af..aea7938e 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/personlevel/PersonLevelRequestHandler.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/personlevel/PersonLevelRequestHandler.java @@ -55,13 +55,13 @@ public class PersonLevelRequestHandler implements VisualizationRequestHandler { @Override public Object generateAjaxVisualization(VitroRequest vitroRequest, Log log, - Dataset Dataset) throws MalformedQueryParametersException { + Dataset dataset) throws MalformedQueryParametersException { throw new UnsupportedOperationException("Person Level does not provide Ajax Response."); } @Override public Map generateDataVisualization( - VitroRequest vitroRequest, Log log, Dataset Dataset) + VitroRequest vitroRequest, Log log, Dataset dataset) throws MalformedQueryParametersException { throw new UnsupportedOperationException("Person Level does not provide Data Response."); } @@ -69,7 +69,7 @@ public class PersonLevelRequestHandler implements VisualizationRequestHandler { @Override public ResponseValues generateStandardVisualization( - VitroRequest vitroRequest, Log log, Dataset Dataset) + VitroRequest vitroRequest, Log log, Dataset dataset) throws MalformedQueryParametersException { String egoURI = vitroRequest.getParameter( @@ -79,14 +79,17 @@ public class PersonLevelRequestHandler implements VisualizationRequestHandler { VisualizationFrameworkConstants.VIS_MODE_KEY); - if (VisualizationFrameworkConstants.COPI_VIS_MODE.equalsIgnoreCase(visMode)){ + if (VisualizationFrameworkConstants.COPI_VIS_MODE.equalsIgnoreCase(visMode)) { - ModelConstructor constructQueryRunner = new CoPIGrantCountConstructQueryRunner(egoURI, Dataset, log); + ModelConstructor constructQueryRunner = + new CoPIGrantCountConstructQueryRunner(egoURI, dataset, log); Model constructedModel = constructQueryRunner.getConstructedModel(); - QueryRunner coPIQueryManager = new CoPIGrantCountQueryRunner(egoURI, constructedModel, log); + QueryRunner coPIQueryManager = + new CoPIGrantCountQueryRunner(egoURI, constructedModel, log); - QueryRunner> grantQueryManager = new PersonGrantCountQueryRunner(egoURI, Dataset, log); + QueryRunner> grantQueryManager = + new PersonGrantCountQueryRunner(egoURI, dataset, log); CollaborationData coPIData = coPIQueryManager.getQueryResult(); @@ -140,9 +143,11 @@ public class PersonLevelRequestHandler implements VisualizationRequestHandler { } else { - QueryRunner coAuthorshipQueryManager = new CoAuthorshipQueryRunner(egoURI, Dataset, log); + QueryRunner coAuthorshipQueryManager = + new CoAuthorshipQueryRunner(egoURI, dataset, log); - QueryRunner> publicationQueryManager = new PersonPublicationCountQueryRunner(egoURI, Dataset, log); + QueryRunner> publicationQueryManager = + new PersonPublicationCountQueryRunner(egoURI, dataset, log); CollaborationData coAuthorshipData = coAuthorshipQueryManager.getQueryResult(); @@ -196,7 +201,7 @@ public class PersonLevelRequestHandler implements VisualizationRequestHandler { } - private TemplateResponseValues prepareCoAuthorStandaloneResponse ( + private TemplateResponseValues prepareCoAuthorStandaloneResponse( String egoURI, SparklineData egoPubSparklineVO, SparklineData uniqueCoauthorsSparklineVO, @@ -212,12 +217,14 @@ public class PersonLevelRequestHandler implements VisualizationRequestHandler { String title = ""; - if (coAuthorshipVO.getCollaborators() != null && coAuthorshipVO.getCollaborators().size() > 0) { + if (coAuthorshipVO.getCollaborators() != null + && coAuthorshipVO.getCollaborators().size() > 0) { body.put("numOfAuthors", coAuthorshipVO.getCollaborators().size()); title = coAuthorshipVO.getEgoCollaborator().getCollaboratorName() + " - "; } - if (coAuthorshipVO.getCollaborations() != null && coAuthorshipVO.getCollaborations().size() > 0) { + if (coAuthorshipVO.getCollaborations() != null + && coAuthorshipVO.getCollaborations().size() > 0) { body.put("numOfCoAuthorShips", coAuthorshipVO.getCollaborations().size()); } @@ -231,7 +238,7 @@ public class PersonLevelRequestHandler implements VisualizationRequestHandler { } - private TemplateResponseValues prepareCoPIStandaloneResponse ( + private TemplateResponseValues prepareCoPIStandaloneResponse( String egoURI, SparklineData egoGrantSparklineVO, SparklineData uniqueCopisSparklineVO, diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/personpubcount/PersonPublicationCountQueryRunner.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/personpubcount/PersonPublicationCountQueryRunner.java index a6c59b7a..692b65fa 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/personpubcount/PersonPublicationCountQueryRunner.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/personpubcount/PersonPublicationCountQueryRunner.java @@ -41,7 +41,7 @@ public class PersonPublicationCountQueryRunner implements QueryRunner> queryManager = new PersonPublicationCountQueryRunner( personURI, - Dataset, + dataset, log); Set authorDocuments = queryManager.getQueryResult(); diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/personpubcount/PersonPublicationCountVisCodeGenerator.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/personpubcount/PersonPublicationCountVisCodeGenerator.java index 9ba5c2f9..5d9f0c5f 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/personpubcount/PersonPublicationCountVisCodeGenerator.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/personpubcount/PersonPublicationCountVisCodeGenerator.java @@ -135,7 +135,8 @@ public class PersonPublicationCountVisCodeGenerator { * */ int renderedFullSparks = 0; - List yearToPublicationCountDataTable = new ArrayList(); + List yearToPublicationCountDataTable = + new ArrayList(); for (int publicationYear = minPubYearConsidered; publicationYear <= currentYear; @@ -159,12 +160,10 @@ public class PersonPublicationCountVisCodeGenerator { * */ renderedFullSparks += currentPublications; publicationCounter++; - } sparklineData.setYearToEntityCountDataTable(yearToPublicationCountDataTable); sparklineData.setRenderedSparks(renderedFullSparks); - /* * Total publications will also consider publications that have no year associated with @@ -176,7 +175,6 @@ public class PersonPublicationCountVisCodeGenerator { .get(VOConstants.DEFAULT_PUBLICATION_YEAR); } - sparklineData.setUnknownYearPublications(unknownYearPublications); if (providedVisContainerID != null) { @@ -196,19 +194,19 @@ public class PersonPublicationCountVisCodeGenerator { sparklineData.setEarliestRenderedPublicationYear(minPublishedYear); sparklineData.setLatestRenderedPublicationYear(currentYear); - if (yearToPublicationCount.size() > 0) { - sparklineData.setFullTimelineNetworkLink(UtilityFunctions.getCollaboratorshipNetworkLink(individualURI, - VisualizationFrameworkConstants.PERSON_LEVEL_VIS, - VisualizationFrameworkConstants.COAUTHOR_VIS_MODE)); - - sparklineData.setDownloadDataLink(UtilityFunctions - .getCSVDownloadURL( - individualURI, - VisualizationFrameworkConstants.PERSON_PUBLICATION_COUNT_VIS, - "")); + sparklineData.setFullTimelineNetworkLink( + UtilityFunctions.getCollaboratorshipNetworkLink( + individualURI, + VisualizationFrameworkConstants.PERSON_LEVEL_VIS, + VisualizationFrameworkConstants.COAUTHOR_VIS_MODE)); + sparklineData.setDownloadDataLink( + UtilityFunctions.getCSVDownloadURL( + individualURI, + VisualizationFrameworkConstants.PERSON_PUBLICATION_COUNT_VIS, + "")); } /* @@ -224,7 +222,6 @@ public class PersonPublicationCountVisCodeGenerator { sparklineData.setShortVisMode(false); } - return sparklineData; } diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/utilities/UtilitiesRequestHandler.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/utilities/UtilitiesRequestHandler.java index b8ec2f13..2f37d877 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/utilities/UtilitiesRequestHandler.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/utilities/UtilitiesRequestHandler.java @@ -46,7 +46,7 @@ public class UtilitiesRequestHandler implements VisualizationRequestHandler { public Object generateAjaxVisualization(VitroRequest vitroRequest, Log log, - Dataset Dataset) + Dataset dataset) throws MalformedQueryParametersException { String individualURI = vitroRequest.getParameter( @@ -70,7 +70,7 @@ public class UtilitiesRequestHandler implements VisualizationRequestHandler { QueryRunner profileQueryHandler = new AllPropertiesQueryRunner(individualURI, filterRule, - Dataset, + dataset, log); GenericQueryMap profilePropertiesToValues = @@ -105,7 +105,7 @@ public class UtilitiesRequestHandler implements VisualizationRequestHandler { "", whereClause, "", - Dataset, log); + dataset, log); return getThumbnailInformation(imageQueryHandler.getQueryResult(), fieldLabelToOutputFieldLabel, vitroRequest); @@ -117,8 +117,11 @@ public class UtilitiesRequestHandler implements VisualizationRequestHandler { String aggregationRules = "(count(DISTINCT ?document) AS ?numOfPublications)"; - String whereClause = "<" + individualURI + "> rdf:type foaf:Person ; core:authorInAuthorship ?authorshipNode . \n" - + "?authorshipNode rdf:type core:Authorship ; core:linkedInformationResource ?document ."; + String whereClause = + "<" + individualURI + "> rdf:type foaf:Person ;" + + " core:authorInAuthorship ?authorshipNode . \n" + + "?authorshipNode rdf:type core:Authorship ;" + + " core:linkedInformationResource ?document ."; String groupOrderClause = "GROUP BY ?" + QueryFieldLabels.AUTHOR_URL + " \n"; @@ -127,7 +130,7 @@ public class UtilitiesRequestHandler implements VisualizationRequestHandler { aggregationRules, whereClause, groupOrderClause, - Dataset, log); + dataset, log); Gson publicationsInformation = new Gson(); @@ -141,13 +144,16 @@ public class UtilitiesRequestHandler implements VisualizationRequestHandler { String aggregationRules = "(count(DISTINCT ?Grant) AS ?numOfGrants)"; - String whereClause = "{ <" + individualURI + "> rdf:type foaf:Person ; core:hasCo-PrincipalInvestigatorRole ?Role . \n" + String whereClause = "{ <" + individualURI + "> rdf:type foaf:Person ;" + + " core:hasCo-PrincipalInvestigatorRole ?Role . \n" + "?Role core:roleIn ?Grant . }" + "UNION \n" - + "{ <" + individualURI + "> rdf:type foaf:Person ; core:hasPrincipalInvestigatorRole ?Role . \n" + + "{ <" + individualURI + "> rdf:type foaf:Person ;" + + " core:hasPrincipalInvestigatorRole ?Role . \n" + "?Role core:roleIn ?Grant . }" + "UNION \n" - + "{ <" + individualURI + "> rdf:type foaf:Person ; core:hasInvestigatorRole ?Role . \n" + + "{ <" + individualURI + "> rdf:type foaf:Person ;" + + " core:hasInvestigatorRole ?Role . \n" + "?Role core:roleIn ?Grant . }"; QueryRunner numberOfGrantsQueryHandler = @@ -155,7 +161,7 @@ public class UtilitiesRequestHandler implements VisualizationRequestHandler { aggregationRules, whereClause, "", - Dataset, log); + dataset, log); Gson grantsInformation = new Gson(); @@ -169,15 +175,17 @@ public class UtilitiesRequestHandler implements VisualizationRequestHandler { * By default we will be generating profile url else some specific url like * coAuthorShip vis url for that individual. * */ - ParamMap coAuthorProfileURLParams = new ParamMap(VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY, - individualURI, - VisualizationFrameworkConstants.VIS_TYPE_KEY, - VisualizationFrameworkConstants.COAUTHORSHIP_VIS, - VisualizationFrameworkConstants.RENDER_MODE_KEY, - VisualizationFrameworkConstants.STANDALONE_RENDER_MODE); + ParamMap coAuthorProfileURLParams = new ParamMap( + VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY, + individualURI, + VisualizationFrameworkConstants.VIS_TYPE_KEY, + VisualizationFrameworkConstants.COAUTHORSHIP_VIS, + VisualizationFrameworkConstants.RENDER_MODE_KEY, + VisualizationFrameworkConstants.STANDALONE_RENDER_MODE); - return UrlBuilder.getUrl(VisualizationFrameworkConstants.FREEMARKERIZED_VISUALIZATION_URL_PREFIX, - coAuthorProfileURLParams); + return UrlBuilder.getUrl( + VisualizationFrameworkConstants.FREEMARKERIZED_VISUALIZATION_URL_PREFIX, + coAuthorProfileURLParams); } else if (VisualizationFrameworkConstants.COPI_UTILS_VIS_MODE .equalsIgnoreCase(visMode)) { @@ -186,15 +194,17 @@ public class UtilitiesRequestHandler implements VisualizationRequestHandler { * By default we will be generating profile url else some specific url like * coPI vis url for that individual. * */ - ParamMap coInvestigatorProfileURLParams = new ParamMap(VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY, - individualURI, - VisualizationFrameworkConstants.VIS_TYPE_KEY, - VisualizationFrameworkConstants.PERSON_LEVEL_VIS, - VisualizationFrameworkConstants.VIS_MODE_KEY, - VisualizationFrameworkConstants.COPI_VIS_MODE); + ParamMap coInvestigatorProfileURLParams = new ParamMap( + VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY, + individualURI, + VisualizationFrameworkConstants.VIS_TYPE_KEY, + VisualizationFrameworkConstants.PERSON_LEVEL_VIS, + VisualizationFrameworkConstants.VIS_MODE_KEY, + VisualizationFrameworkConstants.COPI_VIS_MODE); - return UrlBuilder.getUrl(VisualizationFrameworkConstants.FREEMARKERIZED_VISUALIZATION_URL_PREFIX, - coInvestigatorProfileURLParams); + return UrlBuilder.getUrl( + VisualizationFrameworkConstants.FREEMARKERIZED_VISUALIZATION_URL_PREFIX, + coInvestigatorProfileURLParams); } else if (VisualizationFrameworkConstants.PERSON_LEVEL_UTILS_VIS_MODE .equalsIgnoreCase(visMode)) { @@ -202,24 +212,27 @@ public class UtilitiesRequestHandler implements VisualizationRequestHandler { * By default we will be generating profile url else some specific url like * coAuthorShip vis url for that individual. * */ - ParamMap personLevelURLParams = new ParamMap(VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY, - individualURI, - VisualizationFrameworkConstants.VIS_TYPE_KEY, - VisualizationFrameworkConstants.PERSON_LEVEL_VIS, - VisualizationFrameworkConstants.RENDER_MODE_KEY, - VisualizationFrameworkConstants.STANDALONE_RENDER_MODE); + ParamMap personLevelURLParams = new ParamMap( + VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY, + individualURI, + VisualizationFrameworkConstants.VIS_TYPE_KEY, + VisualizationFrameworkConstants.PERSON_LEVEL_VIS, + VisualizationFrameworkConstants.RENDER_MODE_KEY, + VisualizationFrameworkConstants.STANDALONE_RENDER_MODE); - return UrlBuilder.getUrl(VisualizationFrameworkConstants.FREEMARKERIZED_VISUALIZATION_URL_PREFIX, - personLevelURLParams); + return UrlBuilder.getUrl( + VisualizationFrameworkConstants.FREEMARKERIZED_VISUALIZATION_URL_PREFIX, + personLevelURLParams); } else if (VisualizationFrameworkConstants.HIGHEST_LEVEL_ORGANIZATION_VIS_MODE .equalsIgnoreCase(visMode)) { - String staffProvidedHighestLevelOrganization = ConfigurationProperties.getBean(vitroRequest).getProperty("visualization.topLevelOrg"); + String staffProvidedHighestLevelOrganization = ConfigurationProperties + .getBean(vitroRequest).getProperty("visualization.topLevelOrg"); /* - * First checking if the staff has provided highest level organization in deploy.properties - * if so use to temporal graph vis. + * First checking if the staff has provided highest level organization in + * deploy.properties if so use to temporal graph vis. * */ if (StringUtils.isNotBlank(staffProvidedHighestLevelOrganization)) { @@ -236,13 +249,15 @@ public class UtilitiesRequestHandler implements VisualizationRequestHandler { } else { - ParamMap highestLevelOrganizationTemporalGraphVisURLParams = new ParamMap(VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY, + ParamMap highestLevelOrganizationTemporalGraphVisURLParams = new ParamMap( + VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY, staffProvidedHighestLevelOrganization, VisualizationFrameworkConstants.VIS_TYPE_KEY, VisualizationFrameworkConstants.ENTITY_COMPARISON_VIS); - return UrlBuilder.getUrl(VisualizationFrameworkConstants.FREEMARKERIZED_VISUALIZATION_URL_PREFIX, - highestLevelOrganizationTemporalGraphVisURLParams); + return UrlBuilder.getUrl( + VisualizationFrameworkConstants.FREEMARKERIZED_VISUALIZATION_URL_PREFIX, + highestLevelOrganizationTemporalGraphVisURLParams); } } @@ -250,14 +265,16 @@ public class UtilitiesRequestHandler implements VisualizationRequestHandler { Map fieldLabelToOutputFieldLabel = new HashMap(); fieldLabelToOutputFieldLabel.put("organization", QueryFieldLabels.ORGANIZATION_URL); - fieldLabelToOutputFieldLabel.put("organizationLabel", QueryFieldLabels.ORGANIZATION_LABEL); + fieldLabelToOutputFieldLabel.put("organizationLabel", + QueryFieldLabels.ORGANIZATION_LABEL); String aggregationRules = "(count(?organization) AS ?numOfChildren)"; - String whereClause = "?organization rdf:type foaf:Organization ; rdfs:label ?organizationLabel . \n" - + "OPTIONAL { ?organization core:hasSubOrganization ?subOrg } . \n" - + "OPTIONAL { ?organization core:subOrganizationWithin ?parent } . \n" - + "FILTER ( !bound(?parent) ). \n"; + String whereClause = "?organization rdf:type foaf:Organization ;" + + " rdfs:label ?organizationLabel . \n" + + "OPTIONAL { ?organization core:hasSubOrganization ?subOrg } . \n" + + "OPTIONAL { ?organization core:subOrganizationWithin ?parent } . \n" + + "FILTER ( !bound(?parent) ). \n"; String groupOrderClause = "GROUP BY ?organization ?organizationLabel \n" + "ORDER BY DESC(?numOfChildren)\n" @@ -268,7 +285,7 @@ public class UtilitiesRequestHandler implements VisualizationRequestHandler { aggregationRules, whereClause, groupOrderClause, - Dataset, log); + dataset, log); return getHighestLevelOrganizationTemporalGraphVisURL( highestLevelOrganizationQueryHandler.getQueryResult(), @@ -276,8 +293,9 @@ public class UtilitiesRequestHandler implements VisualizationRequestHandler { } else { - ParamMap individualProfileURLParams = new ParamMap(VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY, - individualURI); + ParamMap individualProfileURLParams = new ParamMap( + VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY, + individualURI); return UrlBuilder.getUrl(VisualizationFrameworkConstants.INDIVIDUAL_URL_PREFIX, individualProfileURLParams); @@ -300,15 +318,18 @@ public class UtilitiesRequestHandler implements VisualizationRequestHandler { .get("organization")); if (organizationNode != null) { - queryResult.addEntry(fieldLabelToOutputFieldLabel.get("organization"), organizationNode.toString()); + queryResult.addEntry(fieldLabelToOutputFieldLabel.get("organization"), + organizationNode.toString()); - ParamMap highestLevelOrganizationTemporalGraphVisURLParams = new ParamMap(VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY, - organizationNode.toString(), - VisualizationFrameworkConstants.VIS_TYPE_KEY, - VisualizationFrameworkConstants.ENTITY_COMPARISON_VIS); + ParamMap highestLevelOrganizationTemporalGraphVisURLParams = new ParamMap( + VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY, + organizationNode.toString(), + VisualizationFrameworkConstants.VIS_TYPE_KEY, + VisualizationFrameworkConstants.ENTITY_COMPARISON_VIS); - return UrlBuilder.getUrl(VisualizationFrameworkConstants.FREEMARKERIZED_VISUALIZATION_URL_PREFIX, - highestLevelOrganizationTemporalGraphVisURLParams); + return UrlBuilder.getUrl( + VisualizationFrameworkConstants.FREEMARKERIZED_VISUALIZATION_URL_PREFIX, + highestLevelOrganizationTemporalGraphVisURLParams); } @@ -318,20 +339,22 @@ public class UtilitiesRequestHandler implements VisualizationRequestHandler { .get("organizationLabel")); if (organizationLabelNode != null) { - queryResult.addEntry(fieldLabelToOutputFieldLabel.get("organizationLabel"), organizationLabelNode.toString()); + queryResult.addEntry(fieldLabelToOutputFieldLabel.get("organizationLabel"), + organizationLabelNode.toString()); } RDFNode numberOfChildrenNode = solution.getLiteral("numOfChildren"); if (numberOfChildrenNode != null) { - queryResult.addEntry("numOfChildren", String.valueOf(numberOfChildrenNode.asLiteral().getInt())); + queryResult.addEntry("numOfChildren", + String.valueOf(numberOfChildrenNode.asLiteral().getInt())); } } return ""; } - private GenericQueryMap getNumberOfGrantsForIndividual (ResultSet resultSet) { + private GenericQueryMap getNumberOfGrantsForIndividual(ResultSet resultSet) { GenericQueryMap queryResult = new GenericQueryMap(); @@ -342,7 +365,8 @@ public class UtilitiesRequestHandler implements VisualizationRequestHandler { RDFNode numberOfGrantsNode = solution.getLiteral("numOfGrants"); if (numberOfGrantsNode != null) { - queryResult.addEntry("numOfGrants", String.valueOf(numberOfGrantsNode.asLiteral().getInt())); + queryResult.addEntry("numOfGrants", + String.valueOf(numberOfGrantsNode.asLiteral().getInt())); } } @@ -350,7 +374,7 @@ public class UtilitiesRequestHandler implements VisualizationRequestHandler { } - private GenericQueryMap getNumberOfPublicationsForIndividual (ResultSet resultSet) { + private GenericQueryMap getNumberOfPublicationsForIndividual(ResultSet resultSet) { GenericQueryMap queryResult = new GenericQueryMap(); @@ -361,7 +385,9 @@ public class UtilitiesRequestHandler implements VisualizationRequestHandler { RDFNode numberOfPublicationsNode = solution.getLiteral("numOfPublications"); if (numberOfPublicationsNode != null) { - queryResult.addEntry("numOfPublications", String.valueOf(numberOfPublicationsNode.asLiteral().getInt())); + queryResult.addEntry( + "numOfPublications", + String.valueOf(numberOfPublicationsNode.asLiteral().getInt())); } } @@ -397,14 +423,14 @@ public class UtilitiesRequestHandler implements VisualizationRequestHandler { @Override public Map generateDataVisualization( - VitroRequest vitroRequest, Log log, Dataset Dataset) + VitroRequest vitroRequest, Log log, Dataset dataset) throws MalformedQueryParametersException { throw new UnsupportedOperationException("Utilities does not provide Data Response."); } @Override public ResponseValues generateStandardVisualization( - VitroRequest vitroRequest, Log log, Dataset Dataset) + VitroRequest vitroRequest, Log log, Dataset dataset) throws MalformedQueryParametersException { throw new UnsupportedOperationException("Utilities does not provide Standard Response."); } diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/valueobjects/Activity.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/valueobjects/Activity.java index 25ba1fe7..cf3307bb 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/valueobjects/Activity.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/valueobjects/Activity.java @@ -11,7 +11,7 @@ import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.Utilit * published (or started). * @author cdtank */ -public class Activity extends Individual{ +public class Activity extends Individual { private String activityDate; diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/valueobjects/Collaboration.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/valueobjects/Collaboration.java index 9845fa9c..ccd1caa7 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/valueobjects/Collaboration.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/valueobjects/Collaboration.java @@ -80,7 +80,8 @@ public class Collaboration { * We do not want to consider the default Activity year when we are checking * for the min or max Activity year. * */ - Set yearsToBeConsidered = new HashSet(this.getYearToActivityCount().keySet()); + Set yearsToBeConsidered = new HashSet(this.getYearToActivityCount() + .keySet()); yearsToBeConsidered.remove(VOConstants.DEFAULT_ACTIVITY_YEAR); /* @@ -92,7 +93,8 @@ public class Collaboration { * */ if (yearsToBeConsidered.size() > 0) { final String earliestYear = Collections.min(yearsToBeConsidered); - final Integer earliestYearActivityCount = this.getYearToActivityCount().get(earliestYear); + final Integer earliestYearActivityCount = this.getYearToActivityCount() + .get(earliestYear); return new HashMap() { { put(earliestYear, earliestYearActivityCount); @@ -109,7 +111,8 @@ public class Collaboration { * We do not want to consider the default Activity year when we are checking * for the min or max Activity year. * */ - Set yearsToBeConsidered = new HashSet(this.getYearToActivityCount().keySet()); + Set yearsToBeConsidered = new HashSet(this.getYearToActivityCount() + .keySet()); yearsToBeConsidered.remove(VOConstants.DEFAULT_ACTIVITY_YEAR); /* diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/valueobjects/Collaborator.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/valueobjects/Collaborator.java index dae10ea2..dbf4592c 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/valueobjects/Collaborator.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/valueobjects/Collaborator.java @@ -79,7 +79,8 @@ public class Collaborator extends Individual { * We do not want to consider the default activity year when we are checking * for the min or max activity year. * */ - Set yearsToBeConsidered = new HashSet(this.getYearToActivityCount().keySet()); + Set yearsToBeConsidered = new HashSet(this.getYearToActivityCount() + .keySet()); yearsToBeConsidered.remove(VOConstants.DEFAULT_ACTIVITY_YEAR); /* @@ -91,7 +92,8 @@ public class Collaborator extends Individual { * */ if (yearsToBeConsidered.size() > 0) { final String earliestYear = Collections.min(yearsToBeConsidered); - final Integer earliestYearActivityCount = this.getYearToActivityCount().get(earliestYear); + final Integer earliestYearActivityCount = this.getYearToActivityCount() + .get(earliestYear); return new HashMap() { { put(earliestYear, earliestYearActivityCount); @@ -108,7 +110,8 @@ public class Collaborator extends Individual { * We do not want to consider the default Activity year when we are checking * for the min or max Activity year. * */ - Set yearsToBeConsidered = new HashSet(this.getYearToActivityCount().keySet()); + Set yearsToBeConsidered = new HashSet(this.getYearToActivityCount() + .keySet()); yearsToBeConsidered.remove(VOConstants.DEFAULT_ACTIVITY_YEAR); /* diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/valueobjects/Entity.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/valueobjects/Entity.java index f04664f1..04c24732 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/valueobjects/Entity.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/valueobjects/Entity.java @@ -11,20 +11,20 @@ import java.util.LinkedHashSet; * Deepak Konidena * */ -public class Entity extends Individual{ +public class Entity extends Individual { - Set activities = new HashSet(); - Set children = new LinkedHashSet(); + private Set activities = new HashSet(); + private Set children = new LinkedHashSet(); - public Entity(String departmentURI, String departmentLabel){ + public Entity(String departmentURI, String departmentLabel) { super(departmentURI, departmentLabel); } - public void setDepartmentLabel(String departmentURI){ + public void setDepartmentLabel(String departmentURI) { this.setIndividualLabel(departmentURI); } - public String getEntityURI(){ + public String getEntityURI() { return this.getIndividualURI(); } @@ -32,7 +32,7 @@ public class Entity extends Individual{ return activities; } - public String getEntityLabel(){ + public String getEntityLabel() { return this.getIndividualLabel(); } diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/valueobjects/JsonObject.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/valueobjects/JsonObject.java index 646c3d20..e4d85075 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/valueobjects/JsonObject.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/valueobjects/JsonObject.java @@ -63,11 +63,11 @@ public class JsonObject { return data; } - public JsonObject(String label){ + public JsonObject(String label) { this.label = label; } - public void setYearToActivityCount(List> yearToPublicationCount){ + public void setYearToActivityCount(List> yearToPublicationCount) { this.data = yearToPublicationCount; } diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/valueobjects/SubEntity.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/valueobjects/SubEntity.java index 53984af4..14145b0a 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/valueobjects/SubEntity.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/valueobjects/SubEntity.java @@ -12,8 +12,9 @@ import java.util.HashSet; */ public class SubEntity extends Individual { - Set activities = new HashSet(); - Map> personToPositionAndStartYear = new HashMap>(); + private Set activities = new HashSet(); + private Map> personToPositionAndStartYear = + new HashMap>(); public SubEntity(String individualURI) { super(individualURI); @@ -37,7 +38,7 @@ public class SubEntity extends Individual { } @Override - public String toString(){ + public String toString() { return this.getIndividualLabel(); } diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/visutils/AllPropertiesQueryRunner.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/visutils/AllPropertiesQueryRunner.java index 91efb108..85d45c83 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/visutils/AllPropertiesQueryRunner.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/visutils/AllPropertiesQueryRunner.java @@ -36,18 +36,18 @@ public class AllPropertiesQueryRunner implements QueryRunner { protected static final Syntax SYNTAX = Syntax.syntaxARQ; private String filterRule, individualURI; - private Dataset Dataset; + private Dataset dataset; private Log log; public AllPropertiesQueryRunner(String individualURI, String filterRule, - Dataset Dataset, + Dataset dataset, Log log) { this.individualURI = individualURI; this.filterRule = filterRule; - this.Dataset = Dataset; + this.dataset = dataset; this.log = log; } @@ -74,12 +74,12 @@ public class AllPropertiesQueryRunner implements QueryRunner { } private ResultSet executeQuery(String queryText, - Dataset Dataset) { + Dataset dataset) { QueryExecution queryExecution = null; Query query = QueryFactory.create(queryText, SYNTAX); - queryExecution = QueryExecutionFactory.create(query, Dataset); + queryExecution = QueryExecutionFactory.create(query, dataset); return queryExecution.execSelect(); } @@ -127,7 +127,7 @@ public class AllPropertiesQueryRunner implements QueryRunner { ResultSet resultSet = executeQuery(generateGenericSparqlQuery( this.individualURI, this.filterRule), - this.Dataset); + this.dataset); return createJavaValueObjects(resultSet); } diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/visutils/GenericQueryRunner.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/visutils/GenericQueryRunner.java index df90f178..08e9c9ed 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/visutils/GenericQueryRunner.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/visutils/GenericQueryRunner.java @@ -30,9 +30,7 @@ public class GenericQueryRunner implements QueryRunner { protected static final Syntax SYNTAX = Syntax.syntaxARQ; private String whereClause; - private Dataset Dataset; - - private Log log; + private Dataset dataset; private Map fieldLabelToOutputFieldLabel; @@ -44,23 +42,21 @@ public class GenericQueryRunner implements QueryRunner { String aggregationRules, String whereClause, String groupOrderClause, - Dataset Dataset, Log log) { + Dataset dataset, Log log) { this.fieldLabelToOutputFieldLabel = fieldLabelToOutputFieldLabel; this.aggregationRules = aggregationRules; this.whereClause = whereClause; this.groupOrderClause = groupOrderClause; - this.Dataset = Dataset; - this.log = log; - + this.dataset = dataset; } private ResultSet executeQuery(String queryText, - Dataset Dataset) { + Dataset dataset) { QueryExecution queryExecution = null; Query query = QueryFactory.create(queryText, SYNTAX); - queryExecution = QueryExecutionFactory.create(query, Dataset); + queryExecution = QueryExecutionFactory.create(query, dataset); return queryExecution.execSelect(); } @@ -96,7 +92,7 @@ public class GenericQueryRunner implements QueryRunner { throws MalformedQueryParametersException { ResultSet resultSet = executeQuery(generateGenericSparqlQuery(), - this.Dataset); + this.dataset); return resultSet; } diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/visutils/UtilityFunctions.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/visutils/UtilityFunctions.java index dbd78421..2a7a8ecb 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/visutils/UtilityFunctions.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/visutils/UtilityFunctions.java @@ -77,7 +77,8 @@ public class UtilityFunctions { public static Map> getActivityYearToCollaborators( CollaborationData collaborationData) { - Map> yearToCollaborators = new TreeMap>(); + Map> yearToCollaborators = new TreeMap>(); Collaborator egoCollaborator = collaborationData.getEgoCollaborator(); @@ -218,18 +219,18 @@ public class UtilityFunctions { public static String getCSVDownloadURL(String individualURI, String visType, String visMode) { - ParamMap CSVDownloadURLParams = null; + ParamMap csvDownloadURLParams = null; if (StringUtils.isBlank(visMode)) { - CSVDownloadURLParams = new ParamMap(VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY, + csvDownloadURLParams = new ParamMap(VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY, individualURI, VisualizationFrameworkConstants.VIS_TYPE_KEY, visType); } else { - CSVDownloadURLParams = new ParamMap(VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY, + csvDownloadURLParams = new ParamMap(VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY, individualURI, VisualizationFrameworkConstants.VIS_TYPE_KEY, visType, @@ -238,31 +239,39 @@ public class UtilityFunctions { } - String csvDownloadLink = UrlBuilder.getUrl(VisualizationFrameworkConstants.DATA_VISUALIZATION_SERVICE_URL_PREFIX, - CSVDownloadURLParams); + String csvDownloadLink = UrlBuilder.getUrl( + VisualizationFrameworkConstants + .DATA_VISUALIZATION_SERVICE_URL_PREFIX, + csvDownloadURLParams); return csvDownloadLink != null ? csvDownloadLink : "" ; } - public static String getCollaboratorshipNetworkLink(String individualURI, String visType, String visMode) { + public static String getCollaboratorshipNetworkLink(String individualURI, + String visType, + String visMode) { - ParamMap collaboratorshipNetworkURLParams = new ParamMap(VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY, - individualURI, - VisualizationFrameworkConstants.VIS_TYPE_KEY, - visType, - VisualizationFrameworkConstants.VIS_MODE_KEY, - visMode); + ParamMap collaboratorshipNetworkURLParams = new ParamMap( + VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY, + individualURI, + VisualizationFrameworkConstants.VIS_TYPE_KEY, + visType, + VisualizationFrameworkConstants.VIS_MODE_KEY, + visMode); String collaboratorshipNetworkURL = UrlBuilder.getUrl( - VisualizationFrameworkConstants.FREEMARKERIZED_VISUALIZATION_URL_PREFIX, - collaboratorshipNetworkURLParams); + VisualizationFrameworkConstants.FREEMARKERIZED_VISUALIZATION_URL_PREFIX, + collaboratorshipNetworkURLParams); return collaboratorshipNetworkURL != null ? collaboratorshipNetworkURL : "" ; } public static boolean isEntityAPerson(VitroRequest vreq, SubEntity subentity) { - return vreq.getWebappDaoFactory().getIndividualDao().getIndividualByURI(subentity.getIndividualURI()).isVClass("http://xmlns.com/foaf/0.1/Person"); + return vreq.getWebappDaoFactory() + .getIndividualDao() + .getIndividualByURI(subentity.getIndividualURI()) + .isVClass("http://xmlns.com/foaf/0.1/Person"); } }