diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/constants/QueryFieldLabels.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/constants/QueryFieldLabels.java index c898b09a..4e8afb46 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/constants/QueryFieldLabels.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/constants/QueryFieldLabels.java @@ -117,5 +117,8 @@ public class QueryFieldLabels { public static final String GRANT_LABEL = "grantLabelLit"; public static final String GRANT_START_DATE = "grantStartDateLit"; public static final String GRANT_END_DATE = "grantEndDateLit"; + public static final String GRANT_START_DATE_FOR_GRANT = "grantStartDateForGrantLit"; + public static final String GRANT_END_DATE_FOR_GRANT = "grantEndDateForGrantLit"; + } 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 4fece38e..61f18534 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 @@ -55,16 +55,28 @@ public class CoPIGrantCountQueryRunner implements QueryRunner { private UniqueIDGenerator edgeIDGenerator; - private static final String SPARQL_QUERY_COMMON_OPTIONAL_BLOCK = "" - + "OPTIONAL {" - + "?Role core:dateTimeInterval ?dateTimeIntervalValue . " + private static final String SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_ROLE_DATE_TIME = "" + + "OPTIONAL {" + + " ?Role core:dateTimeInterval ?dateTimeIntervalValue . " + "?dateTimeIntervalValue core:start ?startDate . " + "?startDate core:dateTime ?startDateTimeValue . " + "OPTIONAL {" + "?dateTimeIntervalValue core:end ?endDate . " + "?endDate core:dateTime ?endDateTimeValue . " + "}" - + "}" ; + + "} . " ; + + private static final String SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_GRANT_DATE_TIME = "" + + "OPTIONAL {" + + " ?Grant core:dateTimeInterval ?dateTimeIntervalValueForGrant . " + + "?dateTimeIntervalValueForGrant core:start ?startDateForGrant . " + + "?startDateForGrant core:dateTime ?startDateTimeValueForGrant . " + + "OPTIONAL {" + + "?dateTimeIntervalValueForGrant core:end ?endDateForGrant . " + + "?endDateForGrant core:dateTime ?endDateTimeValueForGrant . " + + "}" + + "}" ; + public CoPIGrantCountQueryRunner(String egoURI, DataSource dataSource, Log log) { @@ -89,6 +101,8 @@ public class CoPIGrantCountQueryRunner implements QueryRunner { + " (str(?GrantLabel) as ?" + QueryFieldLabels.GRANT_LABEL + ") " + " (str(?startDateTimeValue) as ?grantStartDateLit) " + " (str(?endDateTimeValue) as ?grantEndDateLit) " + + " (str(?startDateTimeValueForGrant) as ?grantStartDateForGrantLit) " + + " (str(?endDateTimeValueForGrant) as ?grantEndDateForGrantLit) " + " (str(?CoPI) as ?" + QueryFieldLabels.CO_PI_URL + ") " + " (str(?CoPILabel) as ?" + QueryFieldLabels.CO_PI_LABEL + ") " + "WHERE " @@ -108,7 +122,9 @@ public class CoPIGrantCountQueryRunner implements QueryRunner { + "?CoPI rdfs:label ?CoPILabel . " - + SPARQL_QUERY_COMMON_OPTIONAL_BLOCK + + SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_ROLE_DATE_TIME + + + SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_GRANT_DATE_TIME + "} " @@ -128,7 +144,10 @@ public class CoPIGrantCountQueryRunner implements QueryRunner { + "?CoPI rdfs:label ?CoPILabel . " - + SPARQL_QUERY_COMMON_OPTIONAL_BLOCK + + SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_ROLE_DATE_TIME + + + SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_GRANT_DATE_TIME + + "} " @@ -148,7 +167,10 @@ public class CoPIGrantCountQueryRunner implements QueryRunner { + "?CoPI rdfs:label ?CoPILabel . " - + SPARQL_QUERY_COMMON_OPTIONAL_BLOCK + + SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_ROLE_DATE_TIME + + + SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_GRANT_DATE_TIME + + "} " @@ -169,7 +191,10 @@ public class CoPIGrantCountQueryRunner implements QueryRunner { + "?CoPI rdfs:label ?CoPILabel . " - + SPARQL_QUERY_COMMON_OPTIONAL_BLOCK + + SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_ROLE_DATE_TIME + + + SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_GRANT_DATE_TIME + + "} " @@ -189,7 +214,10 @@ public class CoPIGrantCountQueryRunner implements QueryRunner { + "?CoPI rdfs:label ?CoPILabel . " - + SPARQL_QUERY_COMMON_OPTIONAL_BLOCK + + SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_ROLE_DATE_TIME + + + SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_GRANT_DATE_TIME + + "} " @@ -209,7 +237,10 @@ public class CoPIGrantCountQueryRunner implements QueryRunner { + "?CoPI rdfs:label ?CoPILabel . " - + SPARQL_QUERY_COMMON_OPTIONAL_BLOCK + + SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_ROLE_DATE_TIME + + + SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_GRANT_DATE_TIME + + "} " @@ -229,7 +260,10 @@ public class CoPIGrantCountQueryRunner implements QueryRunner { + "?CoPI rdfs:label ?CoPILabel . " - + SPARQL_QUERY_COMMON_OPTIONAL_BLOCK + + SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_ROLE_DATE_TIME + + + SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_GRANT_DATE_TIME + + "} " @@ -249,7 +283,10 @@ public class CoPIGrantCountQueryRunner implements QueryRunner { + "?CoPI rdfs:label ?CoPILabel . " - + SPARQL_QUERY_COMMON_OPTIONAL_BLOCK + + SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_ROLE_DATE_TIME + + + SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_GRANT_DATE_TIME + + "} " @@ -269,7 +306,10 @@ public class CoPIGrantCountQueryRunner implements QueryRunner { + "?CoPI rdfs:label ?CoPILabel . " - + SPARQL_QUERY_COMMON_OPTIONAL_BLOCK + + SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_ROLE_DATE_TIME + + + SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_GRANT_DATE_TIME + + "} " + "} "; @@ -609,12 +649,21 @@ public class CoPIGrantCountQueryRunner implements QueryRunner { RDFNode grantStartYear = solution.get(QueryFieldLabels.GRANT_START_DATE); if (grantStartYear != null) { grant.setGrantStartDate(grantStartYear.toString()); + }else{ + grantStartYear = solution.get(QueryFieldLabels.GRANT_START_DATE_FOR_GRANT); + if(grantStartYear != null){ + grant.setGrantStartDate(grantStartYear.toString()); + } } - RDFNode grantEndDate = solution.get(QueryFieldLabels - .GRANT_END_DATE); + RDFNode grantEndDate = solution.get(QueryFieldLabels.GRANT_END_DATE); if (grantEndDate != null) { grant.setGrantEndDate(grantEndDate.toString()); + }else{ + grantEndDate = solution.get(QueryFieldLabels.GRANT_END_DATE_FOR_GRANT); + if(grantEndDate != null){ + grant.setGrantEndDate(grantEndDate.toString()); + } } return grant; 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 5503d97b..f6edb5bb 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 @@ -57,21 +57,37 @@ public class EntityGrantCountQueryRunner implements QueryRunner { + " (str(?Grant) as ?grantLit) " + " (str(?GrantLabel) as ?grantLabelLit) " + " (str(?startDateTimeValue) as ?grantStartDateLit) " - + " (str(?endDateTimeValue) as ?grantEndDateLit) "; + + " (str(?endDateTimeValue) as ?grantEndDateLit) " + + " (str(?startDateTimeValueForGrant) as ?grantStartDateForGrantLit) " + + " (str(?endDateTimeValueForGrant) as ?grantEndDateForGrantLit) " ; - private static final String SPARQL_QUERY_COMMON_WHERE_CLAUSE = " " + private static final String SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_ROLE_DATE_TIME = " " + " ?SecondaryPosition rdfs:label ?SecondaryPositionLabel . " + " ?Role core:roleIn ?Grant . " + " ?Grant rdfs:label ?GrantLabel . " + "OPTIONAL {" - + "?Role core:dateTimeInterval ?dateTimeIntervalValue . " + + " ?Role core:dateTimeInterval ?dateTimeIntervalValue . " + "?dateTimeIntervalValue core:start ?startDate . " + "?startDate core:dateTime ?startDateTimeValue . " + "OPTIONAL {" + "?dateTimeIntervalValue core:end ?endDate . " + "?endDate core:dateTime ?endDateTimeValue . " + "}" - + "}" ; + + "}" ; + + private static final String SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_GRANT_DATE_TIME = " " + + " ?SecondaryPosition rdfs:label ?SecondaryPositionLabel . " + + " ?Role core:roleIn ?Grant . " + + " ?Grant rdfs:label ?GrantLabel . " + + "OPTIONAL {" + + " ?Grant core:dateTimeInterval ?dateTimeIntervalValueForGrant . " + + "?dateTimeIntervalValueForGrant core:start ?startDateForGrant . " + + "?startDateForGrant core:dateTime ?startDateTimeValueForGrant . " + + "OPTIONAL {" + + "?dateTimeIntervalValueForGrant core:end ?endDateForGrant . " + + "?endDateForGrant core:dateTime ?endDateTimeValueForGrant . " + + "}" + + "}" ; private static String ENTITY_LABEL = QueryFieldLabels.ORGANIZATION_LABEL; @@ -125,11 +141,21 @@ public class EntityGrantCountQueryRunner implements QueryRunner { RDFNode grantStartDateNode = solution.get(QueryFieldLabels.GRANT_START_DATE); if(grantStartDateNode != null){ grant.setGrantStartDate(grantStartDateNode.toString()); + }else { + grantStartDateNode = solution.get(QueryFieldLabels.GRANT_START_DATE_FOR_GRANT); + if(grantStartDateNode != null){ + grant.setGrantStartDate(grantStartDateNode.toString()); + } } RDFNode grantEndDateNode = solution.get(QueryFieldLabels.GRANT_END_DATE); if(grantEndDateNode != null){ grant.setGrantEndDate(grantEndDateNode.toString()); + }else { + grantEndDateNode = solution.get(QueryFieldLabels.GRANT_END_DATE_FOR_GRANT); + if(grantEndDateNode != null){ + grant.setGrantEndDate(grantEndDateNode.toString()); + } } } @@ -212,39 +238,45 @@ public class EntityGrantCountQueryRunner implements QueryRunner { + " ?subOrganization rdfs:label ?subOrganizationLabel ; core:organizationForPosition ?Position . " + " ?Position rdf:type core:Position ; core:positionForPerson ?Person ." + " ?Person core:hasCo-PrincipalInvestigatorRole ?Role ; rdfs:label ?PersonLabel ; core:personInPosition ?SecondaryPosition . " - + SPARQL_QUERY_COMMON_WHERE_CLAUSE + "}" + + SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_ROLE_DATE_TIME + + SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_GRANT_DATE_TIME + "}" + "UNION " + "{ " + "<" + queryURI + "> core:hasSubOrganization ?subOrganization . " + " ?subOrganization rdfs:label ?subOrganizationLabel ; core:organizationForPosition ?Position . " + " ?Position rdf:type core:Position ; core:positionForPerson ?Person ." + " ?Person core:hasPrincipalInvestigatorRole ?Role ; rdfs:label ?PersonLabel ; core:personInPosition ?SecondaryPosition . " - + SPARQL_QUERY_COMMON_WHERE_CLAUSE + "}" + + SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_ROLE_DATE_TIME + + SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_GRANT_DATE_TIME + "}" + "UNION " + "{ " + "<" + queryURI + "> core:hasSubOrganization ?subOrganization . " + " ?subOrganization rdfs:label ?subOrganizationLabel ; core:organizationForPosition ?Position . " + " ?Position rdf:type core:Position ; core:positionForPerson ?Person ." + " ?Person core:hasInvestigatorRole ?Role ; rdfs:label ?PersonLabel ; core:personInPosition ?SecondaryPosition . " - + SPARQL_QUERY_COMMON_WHERE_CLAUSE + "}" + + SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_ROLE_DATE_TIME + + SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_GRANT_DATE_TIME + "}" + "UNION " + "{ " + "<" + queryURI + "> core:organizationForPosition ?Position . " + " ?Position rdf:type core:Position ; core:positionForPerson ?Person ." + " ?Person core:hasCo-PrincipalInvestigatorRole ?Role ; rdfs:label ?PersonLabel ; core:personInPosition ?SecondaryPosition . " - + SPARQL_QUERY_COMMON_WHERE_CLAUSE + "}" + + SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_ROLE_DATE_TIME + + SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_GRANT_DATE_TIME + "}" + "UNION " + "{ " + "<" + queryURI + "> core:organizationForPosition ?Position . " + " ?Position rdf:type core:Position ; core:positionForPerson ?Person ." + " ?Person core:hasPrincipalInvestigatorRole ?Role ; rdfs:label ?PersonLabel ; core:personInPosition ?SecondaryPosition . " - + SPARQL_QUERY_COMMON_WHERE_CLAUSE + "}" + + SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_ROLE_DATE_TIME + + SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_GRANT_DATE_TIME + "}" + "UNION " + "{ " + "<" + queryURI + "> core:organizationForPosition ?Position . " + " ?Position rdf:type core:Position ; core:positionForPerson ?Person ." + " ?Person core:hasInvestigatorRole ?Role ; rdfs:label ?PersonLabel ; core:personInPosition ?SecondaryPosition . " - + SPARQL_QUERY_COMMON_WHERE_CLAUSE + "}" + + SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_ROLE_DATE_TIME + + SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_GRANT_DATE_TIME + "}" + " } "; //System.out.println("\n\nEntity Grant Count query is: "+ sparqlQuery); 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 10aa0f00..6de3e089 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 @@ -50,23 +50,39 @@ public class PersonGrantCountQueryRunner implements QueryRunner>{ private Log log; private static final String SPARQL_QUERY_COMMON_SELECT_CLAUSE = "" - + "SELECT (str(?PILabel) as ?PILabelLit) " - + "(str(?Grant) as ?grantLit)" - + "(str(?GrantLabel) as ?grantLabelLit)" + + " SELECT (str(?PILabel) as ?PILabelLit) " + + " (str(?Grant) as ?grantLit)" + + " (str(?GrantLabel) as ?grantLabelLit)" + " (str(?startDateTimeValue) as ?grantStartDateLit) " - + " (str(?endDateTimeValue) as ?grantEndDateLit) "; + + " (str(?endDateTimeValue) as ?grantEndDateLit) " + + " (str(?startDateTimeValueForGrant) as ?grantStartDateForGrantLit) " + + " (str(?endDateTimeValueForGrant) as ?grantEndDateForGrantLit) "; - private static final String SPARQL_QUERY_COMMON_OPTIONAL_BLOCK = "" - + "OPTIONAL {" - + "?Role core:dateTimeInterval ?dateTimeIntervalValue . " + + + private static final String SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_ROLE_DATE_TIME = "" + + "OPTIONAL {" + + " ?Role core:dateTimeInterval ?dateTimeIntervalValue . " + "?dateTimeIntervalValue core:start ?startDate . " + "?startDate core:dateTime ?startDateTimeValue . " + "OPTIONAL {" + "?dateTimeIntervalValue core:end ?endDate . " + "?endDate core:dateTime ?endDateTimeValue . " + "}" + + "} . " ; + + private static final String SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_GRANT_DATE_TIME = "" + + "OPTIONAL {" + + " ?Grant core:dateTimeInterval ?dateTimeIntervalValueForGrant . " + + "?dateTimeIntervalValueForGrant core:start ?startDateForGrant . " + + "?startDateForGrant core:dateTime ?startDateTimeValueForGrant . " + + "OPTIONAL {" + + "?dateTimeIntervalValueForGrant core:end ?endDateForGrant . " + + "?endDateForGrant core:dateTime ?endDateTimeValueForGrant . " + + "}" + "}" ; + public PersonGrantCountQueryRunner(String personURI, DataSource dataSource, Log log){ this.personURI = personURI; @@ -90,11 +106,21 @@ public class PersonGrantCountQueryRunner implements QueryRunner>{ RDFNode grantStartDateNode = solution.get(QueryFieldLabels.GRANT_START_DATE); if(grantStartDateNode != null){ grant.setGrantStartDate(grantStartDateNode.toString()); + }else { + grantStartDateNode = solution.get(QueryFieldLabels.GRANT_START_DATE_FOR_GRANT); + if(grantStartDateNode != null){ + grant.setGrantStartDate(grantStartDateNode.toString()); + } } RDFNode grantEndDateNode = solution.get(QueryFieldLabels.GRANT_END_DATE); if(grantEndDateNode != null){ grant.setGrantEndDate(grantEndDateNode.toString()); + }else { + grantEndDateNode = solution.get(QueryFieldLabels.GRANT_END_DATE_FOR_GRANT); + if(grantEndDateNode != null){ + grant.setGrantEndDate(grantEndDateNode.toString()); + } } /* @@ -147,7 +173,9 @@ public class PersonGrantCountQueryRunner implements QueryRunner>{ + "?Grant rdfs:label ?GrantLabel . " - + SPARQL_QUERY_COMMON_OPTIONAL_BLOCK + + SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_ROLE_DATE_TIME + + + SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_GRANT_DATE_TIME + "} " @@ -161,7 +189,10 @@ public class PersonGrantCountQueryRunner implements QueryRunner>{ + "?Grant rdfs:label ?GrantLabel . " - + SPARQL_QUERY_COMMON_OPTIONAL_BLOCK + + SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_ROLE_DATE_TIME + + + SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_GRANT_DATE_TIME + + "} " @@ -175,7 +206,10 @@ public class PersonGrantCountQueryRunner implements QueryRunner>{ + "?Grant rdfs:label ?GrantLabel . " - + SPARQL_QUERY_COMMON_OPTIONAL_BLOCK + + SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_ROLE_DATE_TIME + + + SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_GRANT_DATE_TIME + + "} " diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/valueobjects/Grant.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/valueobjects/Grant.java index 2be12499..0043bd3a 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/valueobjects/Grant.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/valueobjects/Grant.java @@ -63,7 +63,22 @@ public class Grant extends Individual { } } + + @Override + public boolean equals(Object other){ + boolean result = false; + if (other instanceof Grant){ + Grant grant = (Grant) other; + result = (this.getIndividualLabel().equals(grant.getIndividualLabel()) + && this.getIndividualURI().equals(grant.getIndividualURI())); + } + return result; + } + @Override + public int hashCode(){ + return(41*(getIndividualLabel().hashCode() + 41*(getIndividualURI().hashCode()))); + } public String getGrantStartDate() { return grantStartDate;