1. Fix for grants obtaining publication results

This commit is contained in:
cdtank 2011-03-21 19:33:03 +00:00
parent 81736350bb
commit aee1d00801

View file

@ -1,481 +1,494 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */ /* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils; package edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import com.hp.hpl.jena.query.Dataset; import com.hp.hpl.jena.query.Dataset;
import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.QuerySolution;
import com.hp.hpl.jena.query.ResultSet; import com.hp.hpl.jena.query.ResultSet;
import com.hp.hpl.jena.rdf.model.Model; import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.RDFNode; import com.hp.hpl.jena.rdf.model.RDFNode;
import edu.cornell.mannlib.vitro.webapp.visualization.constants.QueryFieldLabels; import edu.cornell.mannlib.vitro.webapp.visualization.constants.QueryFieldLabels;
import edu.cornell.mannlib.vitro.webapp.visualization.constants.VOConstants; import edu.cornell.mannlib.vitro.webapp.visualization.constants.VOConstants;
import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException; import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException;
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.modelconstructor.ModelConstructorUtilities; import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.modelconstructor.ModelConstructorUtilities;
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.modelconstructor.OrganizationAssociatedPeopleModelWithTypesConstructor; import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.modelconstructor.OrganizationAssociatedPeopleModelWithTypesConstructor;
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.modelconstructor.OrganizationModelWithTypesConstructor; import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.modelconstructor.OrganizationModelWithTypesConstructor;
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.modelconstructor.OrganizationToGrantsForSubOrganizationsModelConstructor; import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.modelconstructor.OrganizationToGrantsForSubOrganizationsModelConstructor;
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.modelconstructor.OrganizationToPublicationsForSubOrganizationsModelConstructor; import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.modelconstructor.OrganizationToPublicationsForSubOrganizationsModelConstructor;
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.modelconstructor.PersonToGrantsModelConstructor; import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.modelconstructor.PersonToGrantsModelConstructor;
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.modelconstructor.PersonToPublicationsModelConstructor; import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.modelconstructor.PersonToPublicationsModelConstructor;
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.valueobjects.Activity; import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.valueobjects.Activity;
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.valueobjects.Entity; import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.valueobjects.Entity;
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.valueobjects.SubEntity; import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.valueobjects.SubEntity;
public class SelectOnModelUtilities { public class SelectOnModelUtilities {
public static Entity getSubjectOrganizationHierarchy(Dataset dataset, public static Entity getSubjectOrganizationHierarchy(Dataset dataset,
String subjectEntityURI) throws MalformedQueryParametersException { String subjectEntityURI) throws MalformedQueryParametersException {
Model organizationModel = ModelConstructorUtilities Model organizationModel = ModelConstructorUtilities
.getOrConstructModel( .getOrConstructModel(
null, null,
OrganizationModelWithTypesConstructor.MODEL_TYPE, OrganizationModelWithTypesConstructor.MODEL_TYPE,
dataset); dataset);
Map<String, String> fieldLabelToOutputFieldLabel = new HashMap<String, String>(); Map<String, String> fieldLabelToOutputFieldLabel = new HashMap<String, String>();
fieldLabelToOutputFieldLabel.put("organizationLabel", QueryFieldLabels.ORGANIZATION_LABEL); fieldLabelToOutputFieldLabel.put("organizationLabel", QueryFieldLabels.ORGANIZATION_LABEL);
fieldLabelToOutputFieldLabel.put("subOrganization", QueryFieldLabels.SUBORGANIZATION_URL); fieldLabelToOutputFieldLabel.put("subOrganization", QueryFieldLabels.SUBORGANIZATION_URL);
fieldLabelToOutputFieldLabel.put("subOrganizationLabel", QueryFieldLabels.SUBORGANIZATION_LABEL); fieldLabelToOutputFieldLabel.put("subOrganizationLabel", QueryFieldLabels.SUBORGANIZATION_LABEL);
fieldLabelToOutputFieldLabel.put("subOrganizationTypeLabel", QueryFieldLabels.SUBORGANIZATION_TYPE_LABEL); fieldLabelToOutputFieldLabel.put("subOrganizationTypeLabel", QueryFieldLabels.SUBORGANIZATION_TYPE_LABEL);
String whereClause = "" String whereClause = ""
+ " <" + subjectEntityURI + "> rdfs:label ?organizationLabel . " + " <" + subjectEntityURI + "> rdfs:label ?organizationLabel . "
+ " <" + subjectEntityURI + "> core:hasSubOrganization ?subOrganization . " + " <" + subjectEntityURI + "> core:hasSubOrganization ?subOrganization . "
+ " ?subOrganization rdfs:label ?subOrganizationLabel . " + " ?subOrganization rdfs:label ?subOrganizationLabel . "
+ " ?subOrganization rdf:type ?subOrgType . " + " ?subOrganization rdf:type ?subOrgType . "
+ " ?subOrgType rdfs:label ?subOrganizationTypeLabel . "; + " ?subOrgType rdfs:label ?subOrganizationTypeLabel . ";
QueryRunner<ResultSet> subOrganizationsWithTypesQuery = QueryRunner<ResultSet> subOrganizationsWithTypesQuery =
new GenericQueryRunnerOnModel(fieldLabelToOutputFieldLabel, new GenericQueryRunnerOnModel(fieldLabelToOutputFieldLabel,
"", "",
whereClause, whereClause,
"", "",
organizationModel); organizationModel);
return getEntityWithSubOrganizations(subjectEntityURI, return getEntityWithSubOrganizations(subjectEntityURI,
subOrganizationsWithTypesQuery.getQueryResult()); subOrganizationsWithTypesQuery.getQueryResult());
} }
private static Entity getEntityWithSubOrganizations(String subjectEntityURI, ResultSet queryResult) { private static Entity getEntityWithSubOrganizations(String subjectEntityURI, ResultSet queryResult) {
Entity entity = new Entity(subjectEntityURI); Entity entity = new Entity(subjectEntityURI);
Map<String, SubEntity> subOrganizationURIToVO = new HashMap<String, SubEntity>(); Map<String, SubEntity> subOrganizationURIToVO = new HashMap<String, SubEntity>();
while (queryResult.hasNext()) { while (queryResult.hasNext()) {
QuerySolution solution = queryResult.nextSolution(); QuerySolution solution = queryResult.nextSolution();
if (StringUtils.isEmpty(entity.getEntityLabel())) { if (StringUtils.isEmpty(entity.getEntityLabel())) {
RDFNode organizationLabelNode = solution.get(QueryFieldLabels.ORGANIZATION_LABEL); RDFNode organizationLabelNode = solution.get(QueryFieldLabels.ORGANIZATION_LABEL);
if (organizationLabelNode != null) { if (organizationLabelNode != null) {
entity.setIndividualLabel(organizationLabelNode.toString()); entity.setIndividualLabel(organizationLabelNode.toString());
} }
} }
RDFNode subOrganizationNode = solution.get(QueryFieldLabels.SUBORGANIZATION_URL); RDFNode subOrganizationNode = solution.get(QueryFieldLabels.SUBORGANIZATION_URL);
SubEntity subEntity; SubEntity subEntity;
if (subOrganizationURIToVO.containsKey(subOrganizationNode.toString())) { if (subOrganizationURIToVO.containsKey(subOrganizationNode.toString())) {
subEntity = subOrganizationURIToVO.get(subOrganizationNode.toString()); subEntity = subOrganizationURIToVO.get(subOrganizationNode.toString());
} else { } else {
subEntity = new SubEntity(subOrganizationNode.toString()); subEntity = new SubEntity(subOrganizationNode.toString());
subEntity.setEntityClass(VOConstants.EntityClassType.ORGANIZATION); subEntity.setEntityClass(VOConstants.EntityClassType.ORGANIZATION);
subOrganizationURIToVO.put(subOrganizationNode.toString(), subEntity); subOrganizationURIToVO.put(subOrganizationNode.toString(), subEntity);
RDFNode subOrganizationLabelNode = solution.get(QueryFieldLabels.SUBORGANIZATION_LABEL); RDFNode subOrganizationLabelNode = solution.get(QueryFieldLabels.SUBORGANIZATION_LABEL);
if (subOrganizationLabelNode != null) { if (subOrganizationLabelNode != null) {
subEntity.setIndividualLabel(subOrganizationLabelNode.toString()); subEntity.setIndividualLabel(subOrganizationLabelNode.toString());
} }
} }
RDFNode subOrganizationTypeLabelNode = solution.get(QueryFieldLabels.SUBORGANIZATION_TYPE_LABEL); RDFNode subOrganizationTypeLabelNode = solution.get(QueryFieldLabels.SUBORGANIZATION_TYPE_LABEL);
if (subOrganizationTypeLabelNode != null) { if (subOrganizationTypeLabelNode != null) {
subEntity.addEntityTypeLabel(subOrganizationTypeLabelNode.toString()); subEntity.addEntityTypeLabel(subOrganizationTypeLabelNode.toString());
} }
} }
entity.addSubEntitities(subOrganizationURIToVO.values()); entity.addSubEntitities(subOrganizationURIToVO.values());
return entity; return entity;
} }
public static Entity getSubjectOrganizationAssociatedPeople(Dataset dataset, public static Entity getSubjectOrganizationAssociatedPeople(Dataset dataset,
String subjectEntityURI) throws MalformedQueryParametersException { String subjectEntityURI) throws MalformedQueryParametersException {
Model associatedPeopleModel = ModelConstructorUtilities Model associatedPeopleModel = ModelConstructorUtilities
.getOrConstructModel( .getOrConstructModel(
subjectEntityURI, subjectEntityURI,
OrganizationAssociatedPeopleModelWithTypesConstructor.MODEL_TYPE, OrganizationAssociatedPeopleModelWithTypesConstructor.MODEL_TYPE,
dataset); dataset);
Map<String, String> fieldLabelToOutputFieldLabel = new HashMap<String, String>(); Map<String, String> fieldLabelToOutputFieldLabel = new HashMap<String, String>();
fieldLabelToOutputFieldLabel.put("organizationLabel", QueryFieldLabels.ORGANIZATION_LABEL); fieldLabelToOutputFieldLabel.put("organizationLabel", QueryFieldLabels.ORGANIZATION_LABEL);
fieldLabelToOutputFieldLabel.put("person", QueryFieldLabels.PERSON_URL); fieldLabelToOutputFieldLabel.put("person", QueryFieldLabels.PERSON_URL);
fieldLabelToOutputFieldLabel.put("personLabel", QueryFieldLabels.PERSON_LABEL); fieldLabelToOutputFieldLabel.put("personLabel", QueryFieldLabels.PERSON_LABEL);
fieldLabelToOutputFieldLabel.put("personTypeLabel", QueryFieldLabels.PERSON_TYPE_LABEL); fieldLabelToOutputFieldLabel.put("personTypeLabel", QueryFieldLabels.PERSON_TYPE_LABEL);
String whereClause = "" String whereClause = ""
+ " <" + subjectEntityURI + "> rdfs:label ?organizationLabel . " + " <" + subjectEntityURI + "> rdfs:label ?organizationLabel . "
+ " <" + subjectEntityURI + "> vivosocnet:hasPersonWithActivity ?person . " + " <" + subjectEntityURI + "> vivosocnet:hasPersonWithActivity ?person . "
+ " ?person rdfs:label ?personLabel . " + " ?person rdfs:label ?personLabel . "
+ " ?person rdf:type ?personType . " + " ?person rdf:type ?personType . "
+ " ?personType rdfs:label ?personTypeLabel . "; + " ?personType rdfs:label ?personTypeLabel . ";
QueryRunner<ResultSet> associatedPeopleWithTypesQuery = QueryRunner<ResultSet> associatedPeopleWithTypesQuery =
new GenericQueryRunnerOnModel(fieldLabelToOutputFieldLabel, new GenericQueryRunnerOnModel(fieldLabelToOutputFieldLabel,
"", "",
whereClause, whereClause,
"", "",
associatedPeopleModel); associatedPeopleModel);
return getEntityWithAssociatedPeopleSubEntitities(subjectEntityURI, associatedPeopleWithTypesQuery.getQueryResult()); return getEntityWithAssociatedPeopleSubEntitities(subjectEntityURI, associatedPeopleWithTypesQuery.getQueryResult());
} }
private static Entity getEntityWithAssociatedPeopleSubEntitities( private static Entity getEntityWithAssociatedPeopleSubEntitities(
String subjectEntityURI, ResultSet queryResult) { String subjectEntityURI, ResultSet queryResult) {
Entity entity = new Entity(subjectEntityURI); Entity entity = new Entity(subjectEntityURI);
Map<String, SubEntity> associatedPeopleURIToVO = new HashMap<String, SubEntity>(); Map<String, SubEntity> associatedPeopleURIToVO = new HashMap<String, SubEntity>();
while (queryResult.hasNext()) { while (queryResult.hasNext()) {
QuerySolution solution = queryResult.nextSolution(); QuerySolution solution = queryResult.nextSolution();
if (StringUtils.isEmpty(entity.getEntityLabel())) { if (StringUtils.isEmpty(entity.getEntityLabel())) {
RDFNode organizationLabelNode = solution.get(QueryFieldLabels.ORGANIZATION_LABEL); RDFNode organizationLabelNode = solution.get(QueryFieldLabels.ORGANIZATION_LABEL);
if (organizationLabelNode != null) { if (organizationLabelNode != null) {
entity.setIndividualLabel(organizationLabelNode.toString()); entity.setIndividualLabel(organizationLabelNode.toString());
} }
} }
RDFNode personNode = solution.get(QueryFieldLabels.PERSON_URL); RDFNode personNode = solution.get(QueryFieldLabels.PERSON_URL);
SubEntity subEntity; SubEntity subEntity;
if (associatedPeopleURIToVO.containsKey(personNode.toString())) { if (associatedPeopleURIToVO.containsKey(personNode.toString())) {
subEntity = associatedPeopleURIToVO.get(personNode.toString()); subEntity = associatedPeopleURIToVO.get(personNode.toString());
} else { } else {
subEntity = new SubEntity(personNode.toString()); subEntity = new SubEntity(personNode.toString());
subEntity.setEntityClass(VOConstants.EntityClassType.PERSON); subEntity.setEntityClass(VOConstants.EntityClassType.PERSON);
associatedPeopleURIToVO.put(personNode.toString(), subEntity); associatedPeopleURIToVO.put(personNode.toString(), subEntity);
RDFNode personLabelNode = solution.get(QueryFieldLabels.PERSON_LABEL); RDFNode personLabelNode = solution.get(QueryFieldLabels.PERSON_LABEL);
if (personLabelNode != null) { if (personLabelNode != null) {
subEntity.setIndividualLabel(personLabelNode.toString()); subEntity.setIndividualLabel(personLabelNode.toString());
} }
} }
RDFNode personTypeLabelNode = solution.get(QueryFieldLabels.PERSON_TYPE_LABEL); RDFNode personTypeLabelNode = solution.get(QueryFieldLabels.PERSON_TYPE_LABEL);
if (personTypeLabelNode != null) { if (personTypeLabelNode != null) {
subEntity.addEntityTypeLabel(personTypeLabelNode.toString()); subEntity.addEntityTypeLabel(personTypeLabelNode.toString());
} }
} }
entity.addSubEntitities(associatedPeopleURIToVO.values()); entity.addSubEntitities(associatedPeopleURIToVO.values());
return entity; return entity;
} }
public static Map<String, Activity> getPublicationsForAllSubOrganizations( public static Map<String, Activity> getPublicationsForAllSubOrganizations(
Dataset dataset, Entity organizationEntity) Dataset dataset, Entity organizationEntity)
throws MalformedQueryParametersException { throws MalformedQueryParametersException {
Map<String, Activity> allDocumentURIToVOs = new HashMap<String, Activity>(); Map<String, Activity> allDocumentURIToVOs = new HashMap<String, Activity>();
for (SubEntity subOrganization : organizationEntity.getSubEntities()) { for (SubEntity subOrganization : organizationEntity.getSubEntities()) {
Model subOrganizationPublicationsModel = ModelConstructorUtilities Model subOrganizationPublicationsModel = ModelConstructorUtilities
.getOrConstructModel( .getOrConstructModel(
subOrganization.getIndividualURI(), subOrganization.getIndividualURI(),
OrganizationToPublicationsForSubOrganizationsModelConstructor.MODEL_TYPE, OrganizationToPublicationsForSubOrganizationsModelConstructor.MODEL_TYPE,
dataset); dataset);
System.out.println("getting publications for " + subOrganization.getIndividualLabel()); System.out.println("getting publications for " + subOrganization.getIndividualLabel());
Map<String, String> fieldLabelToOutputFieldLabel = new HashMap<String, String>(); Map<String, String> fieldLabelToOutputFieldLabel = new HashMap<String, String>();
fieldLabelToOutputFieldLabel.put("document", QueryFieldLabels.DOCUMENT_URL); fieldLabelToOutputFieldLabel.put("document", QueryFieldLabels.DOCUMENT_URL);
fieldLabelToOutputFieldLabel.put("documentLabel", QueryFieldLabels.DOCUMENT_LABEL); fieldLabelToOutputFieldLabel.put("documentLabel", QueryFieldLabels.DOCUMENT_LABEL);
fieldLabelToOutputFieldLabel.put("documentPublicationDate", QueryFieldLabels.DOCUMENT_PUBLICATION_DATE); fieldLabelToOutputFieldLabel.put("documentPublicationDate", QueryFieldLabels.DOCUMENT_PUBLICATION_DATE);
fieldLabelToOutputFieldLabel.put("lastCachedDateTime", QueryFieldLabels.LAST_CACHED_AT_DATETIME);
String whereClause = ""
+ " <" + subOrganization.getIndividualURI() + "> vivosocnet:hasPersonWithPublication ?document . " String whereClause = ""
+ " ?document rdfs:label ?documentLabel . " + " <" + subOrganization.getIndividualURI() + "> vivosocnet:hasPersonWithPublication ?document . "
+ " OPTIONAL { " + " <" + subOrganization.getIndividualURI() + "> vivosocnet:lastCachedAt ?lastCachedDateTime . "
+ " ?document core:dateTimeValue ?dateTimeValue . " + " ?document rdfs:label ?documentLabel . "
+ " ?dateTimeValue core:dateTime ?documentPublicationDate } . "; + " OPTIONAL { "
+ " ?document core:dateTimeValue ?dateTimeValue . "
QueryRunner<ResultSet> subOrganizationPublicationsQuery = + " ?dateTimeValue core:dateTime ?documentPublicationDate } . ";
new GenericQueryRunnerOnModel(fieldLabelToOutputFieldLabel,
"", QueryRunner<ResultSet> subOrganizationPublicationsQuery =
whereClause, new GenericQueryRunnerOnModel(fieldLabelToOutputFieldLabel,
"", "",
subOrganizationPublicationsModel); whereClause,
"",
subOrganization.addActivities(getPublicationForEntity( subOrganizationPublicationsModel);
subOrganizationPublicationsQuery.getQueryResult(),
allDocumentURIToVOs)); subOrganization.addActivities(getPublicationForEntity(
subOrganizationPublicationsQuery.getQueryResult(),
} allDocumentURIToVOs));
return allDocumentURIToVOs;
} }
return allDocumentURIToVOs;
private static Collection<Activity> getPublicationForEntity( }
ResultSet queryResult,
Map<String, Activity> allDocumentURIToVOs) { private static Collection<Activity> getPublicationForEntity(
ResultSet queryResult,
Set<Activity> currentEntityPublications = new HashSet<Activity>(); Map<String, Activity> allDocumentURIToVOs) {
while (queryResult.hasNext()) { Set<Activity> currentEntityPublications = new HashSet<Activity>();
QuerySolution solution = queryResult.nextSolution(); while (queryResult.hasNext()) {
RDFNode documentNode = solution.get(QueryFieldLabels.DOCUMENT_URL); QuerySolution solution = queryResult.nextSolution();
Activity biboDocument;
RDFNode documentNode = solution.get(QueryFieldLabels.DOCUMENT_URL);
if (allDocumentURIToVOs.containsKey(documentNode.toString())) { Activity biboDocument;
biboDocument = allDocumentURIToVOs.get(documentNode.toString());
if (allDocumentURIToVOs.containsKey(documentNode.toString())) {
} else { biboDocument = allDocumentURIToVOs.get(documentNode.toString());
biboDocument = new Activity(documentNode.toString()); } else {
allDocumentURIToVOs.put(documentNode.toString(), biboDocument);
biboDocument = new Activity(documentNode.toString());
RDFNode publicationDateNode = solution.get(QueryFieldLabels allDocumentURIToVOs.put(documentNode.toString(), biboDocument);
.DOCUMENT_PUBLICATION_DATE);
if (publicationDateNode != null) { RDFNode publicationDateNode = solution.get(QueryFieldLabels
biboDocument.setActivityDate(publicationDateNode.toString()); .DOCUMENT_PUBLICATION_DATE);
} if (publicationDateNode != null) {
} biboDocument.setActivityDate(publicationDateNode.toString());
}
currentEntityPublications.add(biboDocument); }
} currentEntityPublications.add(biboDocument);
return currentEntityPublications; }
}
return currentEntityPublications;
}
private static Collection<Activity> getGrantForEntity(
ResultSet queryResult,
Map<String, Activity> allGrantURIToVO) { private static Collection<Activity> getGrantForEntity(
ResultSet queryResult,
Set<Activity> currentEntityGrants = new HashSet<Activity>(); Map<String, Activity> allGrantURIToVO) {
while (queryResult.hasNext()) { Set<Activity> currentEntityGrants = new HashSet<Activity>();
QuerySolution solution = queryResult.nextSolution(); while (queryResult.hasNext()) {
RDFNode grantNode = solution.get(QueryFieldLabels.GRANT_URL); QuerySolution solution = queryResult.nextSolution();
Activity coreGrant;
RDFNode grantNode = solution.get(QueryFieldLabels.GRANT_URL);
if (allGrantURIToVO.containsKey(grantNode.toString())) { Activity coreGrant;
coreGrant = allGrantURIToVO.get(grantNode.toString());
if (allGrantURIToVO.containsKey(grantNode.toString())) {
} else { coreGrant = allGrantURIToVO.get(grantNode.toString());
coreGrant = new Activity(grantNode.toString()); } else {
allGrantURIToVO.put(grantNode.toString(), coreGrant);
coreGrant = new Activity(grantNode.toString());
RDFNode grantStartDateNode = solution.get(QueryFieldLabels.ROLE_START_DATE); allGrantURIToVO.put(grantNode.toString(), coreGrant);
if (grantStartDateNode != null) { RDFNode grantStartDateNode = solution.get(QueryFieldLabels.ROLE_START_DATE);
coreGrant.setActivityDate(grantStartDateNode.toString());
} else { if (grantStartDateNode != null) {
grantStartDateNode = solution coreGrant.setActivityDate(grantStartDateNode.toString());
.get(QueryFieldLabels.GRANT_START_DATE); } else {
if (grantStartDateNode != null) { grantStartDateNode = solution
coreGrant.setActivityDate(grantStartDateNode.toString()); .get(QueryFieldLabels.GRANT_START_DATE);
} if (grantStartDateNode != null) {
} coreGrant.setActivityDate(grantStartDateNode.toString());
} }
currentEntityGrants.add(coreGrant); }
} }
return currentEntityGrants; currentEntityGrants.add(coreGrant);
} }
return currentEntityGrants;
public static Map<String, Activity> getGrantsForAllSubOrganizations( }
Dataset dataset, Entity organizationEntity)
throws MalformedQueryParametersException { public static Map<String, Activity> getGrantsForAllSubOrganizations(
Map<String, Activity> allGrantURIToVO = new HashMap<String, Activity>(); Dataset dataset, Entity organizationEntity)
throws MalformedQueryParametersException {
for (SubEntity subOrganization : organizationEntity.getSubEntities()) { Map<String, Activity> allGrantURIToVO = new HashMap<String, Activity>();
System.out.println("constructing grants for " + subOrganization.getIndividualLabel() + " :: " + subOrganization.getIndividualURI()); for (SubEntity subOrganization : organizationEntity.getSubEntities()) {
Model subOrganizationGrantsModel = ModelConstructorUtilities System.out.println("constructing grants for " + subOrganization.getIndividualLabel() + " :: " + subOrganization.getIndividualURI());
.getOrConstructModel(
subOrganization.getIndividualURI(), Model subOrganizationGrantsModel = ModelConstructorUtilities
OrganizationToGrantsForSubOrganizationsModelConstructor.MODEL_TYPE, .getOrConstructModel(
dataset); subOrganization.getIndividualURI(),
OrganizationToGrantsForSubOrganizationsModelConstructor.MODEL_TYPE,
Map<String, String> fieldLabelToOutputFieldLabel = new HashMap<String, String>(); dataset);
fieldLabelToOutputFieldLabel.put("grant", QueryFieldLabels.GRANT_URL);
fieldLabelToOutputFieldLabel.put("grantLabel", QueryFieldLabels.GRANT_LABEL); Map<String, String> fieldLabelToOutputFieldLabel = new HashMap<String, String>();
fieldLabelToOutputFieldLabel.put("grantStartDate", QueryFieldLabels.GRANT_START_DATE); fieldLabelToOutputFieldLabel.put("grant", QueryFieldLabels.GRANT_URL);
fieldLabelToOutputFieldLabel.put("roleStartDate", QueryFieldLabels.ROLE_START_DATE); fieldLabelToOutputFieldLabel.put("grantLabel", QueryFieldLabels.GRANT_LABEL);
fieldLabelToOutputFieldLabel.put("grantStartDate", QueryFieldLabels.GRANT_START_DATE);
String whereClause = "" fieldLabelToOutputFieldLabel.put("roleStartDate", QueryFieldLabels.ROLE_START_DATE);
+ "{"
+ " <" + subOrganization.getIndividualURI() + "> vivosocnet:hasInvestigatorWithGrant ?grant . " String whereClause = ""
+ " ?grant rdfs:label ?grantLabel . " + "{"
+ " OPTIONAL { " + " <" + subOrganization.getIndividualURI() + "> vivosocnet:hasInvestigatorWithGrant ?grant . "
+ " ?grant vivosocnet:startDateTimeOnGrant ?grantStartDate } . " + " ?grant rdfs:label ?grantLabel . "
+ " OPTIONAL { " + " OPTIONAL { "
+ " ?grant vivosocnet:startDateTimeOnRole ?roleStartDate } . " + " ?grant vivosocnet:startDateTimeOnGrant ?grantStartDate } . "
+ "}" + " OPTIONAL { "
+ "UNION" + " ?grant vivosocnet:startDateTimeOnRole ?roleStartDate } . "
+ "{" + "}"
+ " <" + subOrganization.getIndividualURI() + "> vivosocnet:hasPIWithGrant ?grant . " + "UNION"
+ " ?grant rdfs:label ?grantLabel . " + "{"
+ " OPTIONAL { " + " <" + subOrganization.getIndividualURI() + "> vivosocnet:hasPIWithGrant ?grant . "
+ " ?grant vivosocnet:startDateTimeOnGrant ?grantStartDate } . " + " ?grant rdfs:label ?grantLabel . "
+ " OPTIONAL { " + " OPTIONAL { "
+ " ?grant vivosocnet:startDateTimeOnRole ?roleStartDate } . " + " ?grant vivosocnet:startDateTimeOnGrant ?grantStartDate } . "
+ "}" + " OPTIONAL { "
+ "UNION" + " ?grant vivosocnet:startDateTimeOnRole ?roleStartDate } . "
+ "{" + "}"
+ " <" + subOrganization.getIndividualURI() + "> vivosocnet:hascoPIWithGrant ?grant . " + "UNION"
+ " ?grant rdfs:label ?grantLabel . " + "{"
+ " OPTIONAL { " + " <" + subOrganization.getIndividualURI() + "> vivosocnet:hascoPIWithGrant ?grant . "
+ " ?grant vivosocnet:startDateTimeOnGrant ?grantStartDate } . " + " ?grant rdfs:label ?grantLabel . "
+ " OPTIONAL { " + " OPTIONAL { "
+ " ?grant vivosocnet:startDateTimeOnRole ?roleStartDate } . " + " ?grant vivosocnet:startDateTimeOnGrant ?grantStartDate } . "
+ "}"; + " OPTIONAL { "
+ " ?grant vivosocnet:startDateTimeOnRole ?roleStartDate } . "
QueryRunner<ResultSet> subOrganizationGrantsQuery = + "}";
new GenericQueryRunnerOnModel(fieldLabelToOutputFieldLabel,
"", QueryRunner<ResultSet> subOrganizationGrantsQuery =
whereClause, new GenericQueryRunnerOnModel(fieldLabelToOutputFieldLabel,
"", "",
subOrganizationGrantsModel); whereClause,
"",
subOrganization.addActivities(getGrantForEntity( subOrganizationGrantsModel);
subOrganizationGrantsQuery.getQueryResult(),
allGrantURIToVO)); subOrganization.addActivities(getGrantForEntity(
subOrganizationGrantsQuery.getQueryResult(),
} allGrantURIToVO));
return allGrantURIToVO;
} }
return allGrantURIToVO;
public static Map<String, Activity> getGrantForAssociatedPeople( }
Dataset dataset, Collection<SubEntity> people)
throws MalformedQueryParametersException { public static Map<String, Activity> getGrantsForAssociatedPeople(
Map<String, Activity> allGrantURIToVOs = new HashMap<String, Activity>(); Dataset dataset, Collection<SubEntity> people)
throws MalformedQueryParametersException {
for (SubEntity person : people) { Map<String, Activity> allGrantURIToVOs = new HashMap<String, Activity>();
System.out.println("constructing grants for " + person.getIndividualLabel() + " :: " + person.getIndividualURI()); System.out.println("peopel for grants under consideration are ");
for (SubEntity person : people) {
Model personGrantsModel = ModelConstructorUtilities System.out.println(person.getIndividualURI() + " -- " + person.getIndividualLabel());
.getOrConstructModel( }
person.getIndividualURI(),
PersonToGrantsModelConstructor.MODEL_TYPE, for (SubEntity person : people) {
dataset);
System.out.println("constructing grants for " + person.getIndividualLabel() + " :: " + person.getIndividualURI());
Map<String, String> fieldLabelToOutputFieldLabel = new HashMap<String, String>();
fieldLabelToOutputFieldLabel.put("grant", QueryFieldLabels.GRANT_URL); long before = System.currentTimeMillis();
fieldLabelToOutputFieldLabel.put("grantLabel", QueryFieldLabels.GRANT_LABEL);
fieldLabelToOutputFieldLabel.put("grantStartDate", QueryFieldLabels.GRANT_START_DATE); Model personGrantsModel = ModelConstructorUtilities
fieldLabelToOutputFieldLabel.put("roleStartDate", QueryFieldLabels.ROLE_START_DATE); .getOrConstructModel(
person.getIndividualURI(),
String whereClause = "" PersonToGrantsModelConstructor.MODEL_TYPE,
+ "{" dataset);
+ " <" + person.getIndividualURI() + "> vivosocnet:hasGrantAsAnInvestigator ?grant . "
+ " ?grant rdfs:label ?grantLabel . " System.out.print("\t construct took " + (System.currentTimeMillis() - before));
+ " OPTIONAL { "
+ " ?grant vivosocnet:startDateTimeOnGrant ?grantStartDate } . " before = System.currentTimeMillis();
+ " OPTIONAL { "
+ " ?grant vivosocnet:startDateTimeOnRole ?roleStartDate } . " Map<String, String> fieldLabelToOutputFieldLabel = new HashMap<String, String>();
+ "}" fieldLabelToOutputFieldLabel.put("grant", QueryFieldLabels.GRANT_URL);
+ "UNION" fieldLabelToOutputFieldLabel.put("grantLabel", QueryFieldLabels.GRANT_LABEL);
+ "{" fieldLabelToOutputFieldLabel.put("grantStartDate", QueryFieldLabels.GRANT_START_DATE);
+ " <" + person.getIndividualURI() + "> vivosocnet:hasGrantAsPI ?grant . " fieldLabelToOutputFieldLabel.put("roleStartDate", QueryFieldLabels.ROLE_START_DATE);
+ " ?grant rdfs:label ?grantLabel . "
+ " OPTIONAL { " String whereClause = ""
+ " ?grant vivosocnet:startDateTimeOnGrant ?grantStartDate } . " + "{"
+ " OPTIONAL { " + " <" + person.getIndividualURI() + "> vivosocnet:hasGrantAsAnInvestigator ?grant . "
+ " ?grant vivosocnet:startDateTimeOnRole ?roleStartDate } . " + " ?grant rdfs:label ?grantLabel . "
+ "}" + " OPTIONAL { "
+ "UNION" + " ?grant vivosocnet:startDateTimeOnGrant ?grantStartDate } . "
+ "{" + " OPTIONAL { "
+ " <" + person.getIndividualURI() + "> vivosocnet:hasGrantAsCoPI ?grant . " + " ?grant vivosocnet:startDateTimeOnRole ?roleStartDate } . "
+ " ?grant rdfs:label ?grantLabel . " + "}"
+ " OPTIONAL { " + "UNION"
+ " ?grant vivosocnet:startDateTimeOnGrant ?grantStartDate } . " + "{"
+ " OPTIONAL { " + " <" + person.getIndividualURI() + "> vivosocnet:hasGrantAsPI ?grant . "
+ " ?grant vivosocnet:startDateTimeOnRole ?roleStartDate } . " + " ?grant rdfs:label ?grantLabel . "
+ "}"; + " OPTIONAL { "
+ " ?grant vivosocnet:startDateTimeOnGrant ?grantStartDate } . "
QueryRunner<ResultSet> personGrantsQuery = + " OPTIONAL { "
new GenericQueryRunnerOnModel(fieldLabelToOutputFieldLabel, + " ?grant vivosocnet:startDateTimeOnRole ?roleStartDate } . "
"", + "}"
whereClause, + "UNION"
"", + "{"
personGrantsModel); + " <" + person.getIndividualURI() + "> vivosocnet:hasGrantAsCoPI ?grant . "
+ " ?grant rdfs:label ?grantLabel . "
person.addActivities(getGrantForEntity( + " OPTIONAL { "
personGrantsQuery.getQueryResult(), + " ?grant vivosocnet:startDateTimeOnGrant ?grantStartDate } . "
allGrantURIToVOs)); + " OPTIONAL { "
+ " ?grant vivosocnet:startDateTimeOnRole ?roleStartDate } . "
} + "}";
return allGrantURIToVOs;
} QueryRunner<ResultSet> personGrantsQuery =
new GenericQueryRunnerOnModel(fieldLabelToOutputFieldLabel,
public static Map<String, Activity> getPublicationsForAssociatedPeople( "",
Dataset dataset, Collection<SubEntity> people) whereClause,
throws MalformedQueryParametersException { "",
Map<String, Activity> allDocumentURIToVOs = new HashMap<String, Activity>(); personGrantsModel);
for (SubEntity person : people) { person.addActivities(getGrantForEntity(
personGrantsQuery.getQueryResult(),
Model personPublicationsModel = ModelConstructorUtilities allGrantURIToVOs));
.getOrConstructModel(
person.getIndividualURI(), System.out.println("\t || select took " + (System.currentTimeMillis() - before));
PersonToPublicationsModelConstructor.MODEL_TYPE,
dataset); }
return allGrantURIToVOs;
System.out.println("getting publications for " + person.getIndividualLabel()); }
Map<String, String> fieldLabelToOutputFieldLabel = new HashMap<String, String>(); public static Map<String, Activity> getPublicationsForAssociatedPeople(
fieldLabelToOutputFieldLabel.put("document", QueryFieldLabels.DOCUMENT_URL); Dataset dataset, Collection<SubEntity> people)
fieldLabelToOutputFieldLabel.put("documentLabel", QueryFieldLabels.DOCUMENT_LABEL); throws MalformedQueryParametersException {
fieldLabelToOutputFieldLabel.put("documentPublicationDate", QueryFieldLabels.DOCUMENT_PUBLICATION_DATE); Map<String, Activity> allDocumentURIToVOs = new HashMap<String, Activity>();
String whereClause = "" for (SubEntity person : people) {
+ " <" + person.getIndividualURI() + "> vivosocnet:hasPublication ?document . "
+ " ?document rdfs:label ?documentLabel . " Model personPublicationsModel = ModelConstructorUtilities
+ " OPTIONAL { " .getOrConstructModel(
+ " ?document core:dateTimeValue ?dateTimeValue . " person.getIndividualURI(),
+ " ?dateTimeValue core:dateTime ?documentPublicationDate } . "; PersonToPublicationsModelConstructor.MODEL_TYPE,
dataset);
QueryRunner<ResultSet> personPublicationsQuery =
new GenericQueryRunnerOnModel(fieldLabelToOutputFieldLabel, System.out.println("getting publications for " + person.getIndividualLabel());
"",
whereClause, Map<String, String> fieldLabelToOutputFieldLabel = new HashMap<String, String>();
"", fieldLabelToOutputFieldLabel.put("document", QueryFieldLabels.DOCUMENT_URL);
personPublicationsModel); fieldLabelToOutputFieldLabel.put("documentLabel", QueryFieldLabels.DOCUMENT_LABEL);
fieldLabelToOutputFieldLabel.put("documentPublicationDate", QueryFieldLabels.DOCUMENT_PUBLICATION_DATE);
person.addActivities(getPublicationForEntity(
personPublicationsQuery.getQueryResult(), String whereClause = ""
allDocumentURIToVOs)); + " <" + person.getIndividualURI() + "> vivosocnet:hasPublication ?document . "
+ " ?document rdfs:label ?documentLabel . "
} + " OPTIONAL { "
return allDocumentURIToVOs; + " ?document core:dateTimeValue ?dateTimeValue . "
} + " ?dateTimeValue core:dateTime ?documentPublicationDate } . ";
} QueryRunner<ResultSet> personPublicationsQuery =
new GenericQueryRunnerOnModel(fieldLabelToOutputFieldLabel,
"",
whereClause,
"",
personPublicationsModel);
person.addActivities(getPublicationForEntity(
personPublicationsQuery.getQueryResult(),
allDocumentURIToVOs));
}
return allDocumentURIToVOs;
}
}