diff --git a/productMods/templates/freemarker/body/partials/individual/individual-sparklineVisualization.ftl b/productMods/templates/freemarker/body/partials/individual/individual-sparklineVisualization.ftl index 829b7c02..3c6be712 100644 --- a/productMods/templates/freemarker/body/partials/individual/individual-sparklineVisualization.ftl +++ b/productMods/templates/freemarker/body/partials/individual/individual-sparklineVisualization.ftl @@ -40,11 +40,23 @@ $(document).ready(function(){ - /* - Collaboratorship links do not show up by default. They should show up only if there any data to - show on that page. - */ - $("#coinvestigator_link_container").show(); + $.ajax({ + url: "${urls.base}/visualizationAjax", + data: ({vis: "utilities", vis_mode: "SHOW_GRANTS_LINK", uri: '${individual.uri}'}), + dataType: "json", + success:function(data){ + + /* + Collaboratorship links do not show up by default. They should show up only if there any data to + show on that page. + */ + if (data.numOfGrants !== undefined && data.numOfGrants > 0) { + $("#coinvestigator_link_container").show(); + } + + } + }); + }); diff --git a/productMods/templates/freemarker/visualization/personlevel/coAuthorPersonLevel.ftl b/productMods/templates/freemarker/visualization/personlevel/coAuthorPersonLevel.ftl index b941ee10..70da509d 100644 --- a/productMods/templates/freemarker/visualization/personlevel/coAuthorPersonLevel.ftl +++ b/productMods/templates/freemarker/visualization/personlevel/coAuthorPersonLevel.ftl @@ -82,11 +82,22 @@ $(document).ready(function(){ - /* - Collaboratorship links do not show up by default. They should show up only if there any data to - show on that page. - */ - $("#coinvestigator_link_container").show(); + $.ajax({ + url: "${urls.base}/visualizationAjax", + data: ({vis: "utilities", vis_mode: "SHOW_GRANTS_LINK", uri: '${egoURIParam}'}), + dataType: "json", + success:function(data){ + + /* + Collaboratorship links do not show up by default. They should show up only if there any data to + show on that page. + */ + if (data.numOfGrants !== undefined && data.numOfGrants > 0) { + $("#coinvestigator_link_container").show(); + } + + } + }); }); diff --git a/productMods/templates/freemarker/visualization/personlevel/coPIPersonLevel.ftl b/productMods/templates/freemarker/visualization/personlevel/coPIPersonLevel.ftl index 4e288a7a..7cc5ebee 100644 --- a/productMods/templates/freemarker/visualization/personlevel/coPIPersonLevel.ftl +++ b/productMods/templates/freemarker/visualization/personlevel/coPIPersonLevel.ftl @@ -81,11 +81,22 @@ $(document).ready(function(){ - /* - Collaboratorship links do not show up by default. They should show up only if there any data to - show on that page. - */ - $("#coauthorship_link_container").show(); + $.ajax({ + url: "${urls.base}/visualizationAjax", + data: ({vis: "utilities", vis_mode: "SHOW_AUTHORSHIP_LINK", uri: '${egoURIParam}'}), + dataType: "json", + success:function(data){ + + /* + Collaboratorship links do not show up by default. They should show up only if there any data to + show on that page. + */ + if (data.numOfPublications !== undefined && data.numOfPublications > 0) { + $("#coauthorship_link_container").show(); + } + + } + }); }); diff --git a/src/edu/cornell/mannlib/vitro/webapp/controller/visualization/freemarker/VisualizationFrameworkConstants.java b/src/edu/cornell/mannlib/vitro/webapp/controller/visualization/freemarker/VisualizationFrameworkConstants.java index ff799464..1b089de8 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/controller/visualization/freemarker/VisualizationFrameworkConstants.java +++ b/src/edu/cornell/mannlib/vitro/webapp/controller/visualization/freemarker/VisualizationFrameworkConstants.java @@ -84,6 +84,8 @@ public class VisualizationFrameworkConstants { public static final String PERSON_LEVEL_UTILS_VIS_MODE = "PERSON_LEVEL_URL"; public static final String COPI_UTILS_VIS_MODE = "COPI_URL"; public static final String IMAGE_UTILS_VIS_MODE = "IMAGE_URL"; + public static final String ARE_PUBLICATIONS_AVAILABLE_UTILS_VIS_MODE = "SHOW_AUTHORSHIP_LINK"; + public static final String ARE_GRANTS_AVAILABLE_UTILS_VIS_MODE = "SHOW_GRANTS_LINK"; public static final String UNIVERSITY_COMPARISON_VIS_MODE = "UNIVERSITY"; public static final String SCHOOL_COMPARISON_VIS_MODE = "SCHOOL"; public static final String DEPARTMENT_COMPARISON_VIS_MODE = "DEPARTMENT"; 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 bc440500..4a33eec4 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 @@ -406,35 +406,35 @@ public class CoAuthorshipQueryRunner implements QueryRunner { // Resource uri1 = ResourceFactory.createResource(queryURI); String sparqlQuery = QueryConstants.getSparqlPrefixQuery() - + "SELECT " - + " (str(<" + queryURI + ">) as ?" + QueryFieldLabels.AUTHOR_URL + ") " - + " (str(?authorLabel) as ?" + QueryFieldLabels.AUTHOR_LABEL + ") " - + " (str(?coAuthorPerson) as ?" + QueryFieldLabels.CO_AUTHOR_URL + ") " - + " (str(?coAuthorPersonLabel) as ?" + QueryFieldLabels.CO_AUTHOR_LABEL + ") " - + " (str(?document) as ?" + QueryFieldLabels.DOCUMENT_URL + ") " - + " (str(?documentLabel) as ?" + QueryFieldLabels.DOCUMENT_LABEL + ") " - + " (str(?documentMoniker) as ?" + QueryFieldLabels.DOCUMENT_MONIKER + ") " - + " (str(?documentBlurb) as ?" + QueryFieldLabels.DOCUMENT_BLURB + ") " - + " (str(?publicationDate) as ?" + QueryFieldLabels.DOCUMENT_PUBLICATION_DATE + ") " - + " (str(?publicationYearUsing_1_1_property) as ?" + QueryFieldLabels.DOCUMENT_PUBLICATION_YEAR_USING_1_1_PROPERTY + ") " - + "WHERE { " + + "SELECT \n" + + " (str(<" + queryURI + ">) as ?" + QueryFieldLabels.AUTHOR_URL + ") \n" + + " (str(?authorLabel) as ?" + QueryFieldLabels.AUTHOR_LABEL + ") \n" + + " (str(?coAuthorPerson) as ?" + QueryFieldLabels.CO_AUTHOR_URL + ") \n" + + " (str(?coAuthorPersonLabel) as ?" + QueryFieldLabels.CO_AUTHOR_LABEL + ") \n" + + " (str(?document) as ?" + QueryFieldLabels.DOCUMENT_URL + ") \n" + + " (str(?documentLabel) as ?" + QueryFieldLabels.DOCUMENT_LABEL + ") \n" + + " (str(?documentMoniker) as ?" + QueryFieldLabels.DOCUMENT_MONIKER + ") \n" + + " (str(?documentBlurb) as ?" + QueryFieldLabels.DOCUMENT_BLURB + ") \n" + + " (str(?publicationDate) as ?" + QueryFieldLabels.DOCUMENT_PUBLICATION_DATE + ") \n" + + " (str(?publicationYearUsing_1_1_property) as ?" + QueryFieldLabels.DOCUMENT_PUBLICATION_YEAR_USING_1_1_PROPERTY + ") \n" + + "WHERE { \n" + "<" + queryURI + "> rdf:type foaf:Person ;" + " rdfs:label ?authorLabel ;" - + " core:authorInAuthorship ?authorshipNode . " + + " core:authorInAuthorship ?authorshipNode . \n" + "?authorshipNode rdf:type core:Authorship ;" - + " core:linkedInformationResource ?document . " - + "?document rdfs:label ?documentLabel . " - + "?document core:informationResourceInAuthorship ?coAuthorshipNode . " - + "?coAuthorshipNode core:linkedAuthor ?coAuthorPerson . " - + "?coAuthorPerson rdfs:label ?coAuthorPersonLabel . " - + "OPTIONAL { ?document core:dateTimeValue ?dateTimeValue . " - + " ?dateTimeValue core:dateTime ?publicationDate } ." - + "OPTIONAL { ?document core:year ?publicationYearUsing_1_1_property } ." - + "OPTIONAL { ?document vitro:moniker ?documentMoniker } . " - + "OPTIONAL { ?document vitro:blurb ?documentBlurb } . " - + "OPTIONAL { ?document vitro:description ?documentDescription } " - + "} " - + "ORDER BY ?document ?coAuthorPerson"; + + " core:linkedInformationResource ?document . \n" + + "?document rdfs:label ?documentLabel . \n" + + "?document core:informationResourceInAuthorship ?coAuthorshipNode . \n" + + "?coAuthorshipNode core:linkedAuthor ?coAuthorPerson . \n" + + "?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" + + "OPTIONAL { ?document vitro:moniker ?documentMoniker } . \n" + + "OPTIONAL { ?document vitro:blurb ?documentBlurb } . \n" + + "OPTIONAL { ?document vitro:description ?documentDescription } \n" + + "} \n" + + "ORDER BY ?document ?coAuthorPerson\n"; // System.out.println("COAUTHORSHIP QUERY - " + sparqlQuery); 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 4ab328df..f2029b02 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 @@ -52,23 +52,23 @@ public class PersonPublicationCountQueryRunner implements QueryRunner) as ?authPersonLit) " - + "WHERE { " - + "<" + queryURI + "> rdf:type foaf:Person ;" - + " rdfs:label ?authorLabel ;" - + " core:authorInAuthorship ?authorshipNode . " + + "(str(<" + queryURI + ">) as ?authPersonLit)\n " + + "WHERE { \n" + + "<" + queryURI + "> rdf:type foaf:Person ;\n" + + " rdfs:label ?authorLabel \n;" + + " core:authorInAuthorship ?authorshipNode . \n" + " ?authorshipNode rdf:type core:Authorship ;" - + " core:linkedInformationResource ?document . " + + " core:linkedInformationResource ?document . \n" + SPARQL_QUERY_COMMON_WHERE_CLAUSE - + "}"; + + "}\n"; // System.out.println(sparqlQuery); 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 a2b35707..aa9e14c2 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 @@ -110,6 +110,58 @@ public class UtilitiesRequestHandler implements VisualizationRequestHandler { return getThumbnailInformation(imageQueryHandler.getQueryResult(), fieldLabelToOutputFieldLabel); + } else if (VisualizationFrameworkConstants.ARE_PUBLICATIONS_AVAILABLE_UTILS_VIS_MODE + .equalsIgnoreCase(visMode)) { + + Map fieldLabelToOutputFieldLabel = new HashMap(); + + 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 groupOrderClause = "GROUP BY ?" + QueryFieldLabels.AUTHOR_URL + " \n"; + + QueryRunner numberOfPublicationsQueryHandler = + new GenericQueryRunner(fieldLabelToOutputFieldLabel, + aggregationRules, + whereClause, + groupOrderClause, + dataSource, log); + + Gson publicationsInformation = new Gson(); + + return publicationsInformation.toJson(getNumberOfPublicationsForIndividual( + numberOfPublicationsQueryHandler.getQueryResult())); + + } else if (VisualizationFrameworkConstants.ARE_GRANTS_AVAILABLE_UTILS_VIS_MODE + .equalsIgnoreCase(visMode)) { + + Map fieldLabelToOutputFieldLabel = new HashMap(); + + String aggregationRules = "(count(DISTINCT ?Grant) AS ?numOfGrants)"; + + 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" + + "?Role core:roleIn ?Grant . }" + + "UNION \n" + + "{ <" + individualURI + "> rdf:type foaf:Person ; core:hasInvestigatorRole ?Role . \n" + + "?Role core:roleIn ?Grant . }"; + + QueryRunner numberOfGrantsQueryHandler = + new GenericQueryRunner(fieldLabelToOutputFieldLabel, + aggregationRules, + whereClause, + "", + dataSource, log); + + Gson grantsInformation = new Gson(); + + return grantsInformation.toJson(getNumberOfGrantsForIndividual( + numberOfGrantsQueryHandler.getQueryResult())); + } else if (VisualizationFrameworkConstants.COAUTHOR_UTILS_VIS_MODE .equalsIgnoreCase(visMode)) { @@ -222,18 +274,6 @@ public class UtilitiesRequestHandler implements VisualizationRequestHandler { highestLevelOrganizationQueryHandler.getQueryResult(), fieldLabelToOutputFieldLabel); - /* - - GenericQueryMap highestLevelOrganizationToValues = getHighestLevelOrganizationInformation( - highestLevelOrganizationQueryHandler.getQueryResult(), - fieldLabelToOutputFieldLabel); - - Gson highestLevelOrganizationInformation = new Gson(); - - return highestLevelOrganizationInformation.toJson(highestLevelOrganizationToValues); - - */ - } else { ParamMap individualProfileURLParams = new ParamMap(VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY, @@ -288,10 +328,47 @@ public class UtilitiesRequestHandler implements VisualizationRequestHandler { } } -// return queryResult; return ""; } + private GenericQueryMap getNumberOfGrantsForIndividual (ResultSet resultSet) { + + GenericQueryMap queryResult = new GenericQueryMap(); + + + while (resultSet.hasNext()) { + QuerySolution solution = resultSet.nextSolution(); + + RDFNode numberOfGrantsNode = solution.getLiteral("numOfGrants"); + + if (numberOfGrantsNode != null) { + queryResult.addEntry("numOfGrants", String.valueOf(numberOfGrantsNode.asLiteral().getInt())); + } + } + + return queryResult; + } + + + private GenericQueryMap getNumberOfPublicationsForIndividual (ResultSet resultSet) { + + GenericQueryMap queryResult = new GenericQueryMap(); + + + while (resultSet.hasNext()) { + QuerySolution solution = resultSet.nextSolution(); + + RDFNode numberOfPublicationsNode = solution.getLiteral("numOfPublications"); + + if (numberOfPublicationsNode != null) { + queryResult.addEntry("numOfPublications", String.valueOf(numberOfPublicationsNode.asLiteral().getInt())); + } + } + + return queryResult; + } + + private String getThumbnailInformation(ResultSet resultSet, Map fieldLabelToOutputFieldLabel) {