1. Completed the caching-like version for temporal graph for grants.
2. Changed the timeout for front-end getter for temporal vis data since the first time a user requests grant comparison it might take a long time.
This commit is contained in:
parent
b1950352e8
commit
c49e8d1d75
8 changed files with 1906 additions and 1530 deletions
|
@ -225,6 +225,7 @@ function getTemporalGraphData(temporalGraphDataURL,
|
|||
$.ajax({
|
||||
url: temporalGraphDataURL,
|
||||
dataType: "json",
|
||||
timeout: 5 * 60 * 1000,
|
||||
success: function (data) {
|
||||
|
||||
if (data.error) {
|
||||
|
|
|
@ -157,8 +157,30 @@ public class TemporalGrantVisualizationRequestHandler implements
|
|||
Map<String, Activity> grantURIForAssociatedPeopleToVO = new HashMap<String, Activity>();
|
||||
Map<String, Activity> allGrantURIToVO = new HashMap<String, Activity>();
|
||||
|
||||
/**
|
||||
* TODO: Change this to use DataSet when an optimum solution is reached. Currently grant constructs are causing
|
||||
* endless wait times on a large dataset like UFl. When I tried to add all the datasets manually to the Datasource
|
||||
* it responded in an order of magnitude higher than with just the defaultOntModel.
|
||||
* Brian Lowe is looking into this weird behavior see http://issues.library.cornell.edu/browse/NIHVIVO-2275
|
||||
*/
|
||||
// DataSource dataSource = DatasetFactory.create();
|
||||
// dataSource.setDefaultModel(vitroRequest.getJenaOntModel());
|
||||
|
||||
allGrantURIToVO = SelectOnModelUtilities.getGrantsForAllSubOrganizations(dataset, organizationEntity);
|
||||
|
||||
Entity organizationWithAssociatedPeople = SelectOnModelUtilities
|
||||
.getSubjectOrganizationAssociatedPeople(dataset, subjectEntityURI);
|
||||
|
||||
if (organizationWithAssociatedPeople.getSubEntities() != null) {
|
||||
|
||||
grantURIForAssociatedPeopleToVO = SelectOnModelUtilities
|
||||
.getPublicationsForAssociatedPeople(dataset, organizationWithAssociatedPeople.getSubEntities());
|
||||
|
||||
organizationEntity = EntityComparisonUtilityFunctions.mergeEntityIfShareSameURI(
|
||||
organizationEntity,
|
||||
organizationWithAssociatedPeople);
|
||||
}
|
||||
|
||||
if (allGrantURIToVO.isEmpty() && grantURIForAssociatedPeopleToVO.isEmpty()) {
|
||||
|
||||
if (EntityComparisonConstants.DataVisMode.JSON.equals(visMode)) {
|
||||
|
|
|
@ -82,7 +82,6 @@ public class TemporalPublicationVisualizationRequestHandler implements
|
|||
} else {
|
||||
return prepareDataErrorResponse();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Map<String, Activity> documentURIForAssociatedPeopleTOVO = new HashMap<String, Activity>();
|
||||
|
@ -288,8 +287,6 @@ public class TemporalPublicationVisualizationRequestHandler implements
|
|||
|
||||
for (SubEntity subentity : subentities) {
|
||||
|
||||
System.out.println("in write json current sub entity " + subentity.getIndividualLabel());
|
||||
|
||||
JsonObject entityJson = new JsonObject(
|
||||
subentity.getIndividualLabel());
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.modelconstructo
|
|||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.modelconstructor.factory.OrganizationModelWithTypesFactory;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.modelconstructor.factory.OrganizationToGrantsForSubOrganizationsFactory;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.modelconstructor.factory.OrganizationToPublicationsForSubOrganizationsFactory;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.modelconstructor.factory.PersonToGrantsFactory;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.modelconstructor.factory.PersonToPublicationsFactory;
|
||||
|
||||
public class ModelConstructorUtilities {
|
||||
|
@ -20,6 +21,7 @@ public class ModelConstructorUtilities {
|
|||
@SuppressWarnings("serial")
|
||||
private static final Map<String, ModelFactoryInterface> modelTypeIdentifierToFactory = new HashMap<String, ModelFactoryInterface>() {{
|
||||
put(PersonToPublicationsModelConstructor.MODEL_TYPE, new PersonToPublicationsFactory());
|
||||
put(PersonToGrantsModelConstructor.MODEL_TYPE, new PersonToGrantsFactory());
|
||||
put(OrganizationToPublicationsForSubOrganizationsModelConstructor.MODEL_TYPE, new OrganizationToPublicationsForSubOrganizationsFactory());
|
||||
put(OrganizationToGrantsForSubOrganizationsModelConstructor.MODEL_TYPE, new OrganizationToGrantsForSubOrganizationsFactory());
|
||||
put(OrganizationAssociatedPeopleModelWithTypesConstructor.MODEL_TYPE, new OrganizationAssociatedPeopleModelWithTypesFactory());
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
package edu.cornell.mannlib.vitro.webapp.visualization.freemarker.modelconstructor;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
|
@ -36,80 +39,131 @@ public class OrganizationToGrantsForSubOrganizationsModelConstructor implements
|
|||
this.dataset = dataset;
|
||||
}
|
||||
|
||||
private String constructOrganizationToGrantsQuery() {
|
||||
private Set<String> constructOrganizationGrantsQueryTemplate(String constructProperty, String roleTypeProperty) {
|
||||
|
||||
return ""
|
||||
Set<String> differentPerspectiveQueries = new HashSet<String>();
|
||||
|
||||
String justGrantsQuery = ""
|
||||
+ " CONSTRUCT { "
|
||||
+ " <" + organizationURI + "> rdfs:label ?organizationLabel . "
|
||||
+ " <" + organizationURI + "> vivosocnet:lastCachedAt ?now . "
|
||||
+ " <" + organizationURI + "> vivosocnet:hasPersonWithGrant ?Grant . "
|
||||
+ " <" + organizationURI + "> vivosocnet:" + constructProperty + " ?Grant . "
|
||||
+ " "
|
||||
+ " ?Grant rdf:type core:Grant . "
|
||||
+ " ?Grant rdfs:label ?grantLabel . "
|
||||
+ " "
|
||||
+ " ?Grant vivosocnet:startDateTimeOnGrant ?startDateTimeValueForGrant . "
|
||||
+ " ?Grant vivosocnet:endDateTimeOnGrant ?endDateTimeValueForGrant . "
|
||||
+ " "
|
||||
+ " ?Grant vivosocnet:startDateTimeOnRole ?startDateTimeValue . "
|
||||
+ " ?Grant vivosocnet:endDateTimeOnRole ?endDateTimeValue . "
|
||||
+ " } "
|
||||
+ " WHERE { "
|
||||
+ " <" + organizationURI + "> rdfs:label ?organizationLabel . "
|
||||
+ " <" + organizationURI + "> core:hasSubOrganization* ?subOrganization . "
|
||||
+ " ?subOrganization core:organizationForPosition ?Position . "
|
||||
+ " ?Position core:positionForPerson ?Person . "
|
||||
+ " ?Person core:hasInvestigatorRole ?Role . "
|
||||
+ " ?Person core:" + roleTypeProperty + " ?Role . "
|
||||
+ " ?Role core:roleIn ?Grant . "
|
||||
+ " ?Grant rdfs:label ?grantLabel . "
|
||||
+ " "
|
||||
+ " OPTIONAL { "
|
||||
+ " ?Grant core:dateTimeInterval ?dateTimeIntervalValueForGrant . "
|
||||
+ " OPTIONAL { "
|
||||
+ " ?dateTimeIntervalValueForGrant core:start ?startDateForGrant . "
|
||||
+ " ?startDateForGrant core:dateTime ?startDateTimeValueForGrant . "
|
||||
+ " } "
|
||||
+ " OPTIONAL { "
|
||||
+ " ?dateTimeIntervalValueForGrant core:end ?endDateForGrant . "
|
||||
+ " ?endDateForGrant core:dateTime ?endDateTimeValueForGrant "
|
||||
+ " } "
|
||||
+ " } "
|
||||
+ " "
|
||||
+ " OPTIONAL { "
|
||||
+ " ?Role core:dateTimeInterval ?dateTimeIntervalValue . "
|
||||
+ " OPTIONAL { "
|
||||
+ " ?dateTimeIntervalValue core:start ?startDate . "
|
||||
+ " ?startDate core:dateTime ?startDateTimeValue . "
|
||||
+ " } "
|
||||
+ " "
|
||||
+ " OPTIONAL { "
|
||||
+ " ?dateTimeIntervalValue core:end ?endDate . "
|
||||
+ " ?endDate core:dateTime ?endDateTimeValue . "
|
||||
+ " } "
|
||||
+ " } "
|
||||
+ " "
|
||||
+ " LET(?now := afn:now()) "
|
||||
+ " } ";
|
||||
|
||||
String justDateTimeOnGrantsQuery = ""
|
||||
+ " CONSTRUCT { "
|
||||
+ " <" + organizationURI + "> rdfs:label ?organizationLabel . "
|
||||
+ " <" + organizationURI + "> vivosocnet:lastCachedAt ?now . "
|
||||
+ " "
|
||||
+ " ?Grant vivosocnet:startDateTimeOnGrant ?startDateTimeValueForGrant . "
|
||||
// + " ?Grant vivosocnet:endDateTimeOnGrant ?endDateTimeValueForGrant . "
|
||||
+ " "
|
||||
+ " } "
|
||||
+ " WHERE { "
|
||||
+ " <" + organizationURI + "> rdfs:label ?organizationLabel . "
|
||||
+ " <" + organizationURI + "> core:hasSubOrganization* ?subOrganization . "
|
||||
+ " ?subOrganization core:organizationForPosition ?Position . "
|
||||
+ " ?Position core:positionForPerson ?Person . "
|
||||
+ " ?Person core:" + roleTypeProperty + " ?Role . "
|
||||
+ " ?Role core:roleIn ?Grant . "
|
||||
+ " "
|
||||
+ " ?Grant core:dateTimeInterval ?dateTimeIntervalValueForGrant . "
|
||||
// + " OPTIONAL { "
|
||||
+ " ?dateTimeIntervalValueForGrant core:start ?startDateForGrant . "
|
||||
+ " ?startDateForGrant core:dateTime ?startDateTimeValueForGrant . "
|
||||
// + " } "
|
||||
// + " OPTIONAL { "
|
||||
// + " ?dateTimeIntervalValueForGrant core:end ?endDateForGrant . "
|
||||
// + " ?endDateForGrant core:dateTime ?endDateTimeValueForGrant "
|
||||
// + " } "
|
||||
+ " "
|
||||
+ " LET(?now := afn:now()) "
|
||||
+ " } ";
|
||||
|
||||
String justDateTimeOnRolesQuery = ""
|
||||
+ " CONSTRUCT { "
|
||||
+ " <" + organizationURI + "> rdfs:label ?organizationLabel . "
|
||||
+ " <" + organizationURI + "> vivosocnet:lastCachedAt ?now . "
|
||||
+ " "
|
||||
+ " ?Grant vivosocnet:startDateTimeOnRole ?startDateTimeValue . "
|
||||
// + " ?Grant vivosocnet:endDateTimeOnRole ?endDateTimeValue . "
|
||||
+ " } "
|
||||
+ " WHERE { "
|
||||
+ " <" + organizationURI + "> rdfs:label ?organizationLabel . "
|
||||
+ " <" + organizationURI + "> core:hasSubOrganization* ?subOrganization . "
|
||||
+ " ?subOrganization core:organizationForPosition ?Position . "
|
||||
+ " ?Position core:positionForPerson ?Person . "
|
||||
+ " ?Person core:" + roleTypeProperty + " ?Role . "
|
||||
+ " ?Role core:roleIn ?Grant . "
|
||||
+ " "
|
||||
+ " ?Role core:dateTimeInterval ?dateTimeIntervalValue . "
|
||||
// + " OPTIONAL { "
|
||||
+ " ?dateTimeIntervalValue core:start ?startDate . "
|
||||
+ " ?startDate core:dateTime ?startDateTimeValue . "
|
||||
// + " } "
|
||||
// + " "
|
||||
// + " OPTIONAL { "
|
||||
// + " ?dateTimeIntervalValue core:end ?endDate . "
|
||||
// + " ?endDate core:dateTime ?endDateTimeValue . "
|
||||
// + " } "
|
||||
+ " "
|
||||
+ " LET(?now := afn:now()) "
|
||||
+ " } ";
|
||||
|
||||
differentPerspectiveQueries.add(justGrantsQuery);
|
||||
differentPerspectiveQueries.add(justDateTimeOnGrantsQuery);
|
||||
differentPerspectiveQueries.add(justDateTimeOnRolesQuery);
|
||||
|
||||
return differentPerspectiveQueries;
|
||||
}
|
||||
|
||||
private Model executeQuery(String constructQuery) {
|
||||
private Set<String> constructOrganizationToGrantsQuery() {
|
||||
|
||||
System.out.println("in execute query - org to grants for - " + organizationURI);
|
||||
Set<String> differentInvestigatorTypeQueries = new HashSet<String>();
|
||||
|
||||
Set<String> investigatorRoleQuery = constructOrganizationGrantsQueryTemplate("hasInvestigatorWithGrant", "hasInvestigatorRole");
|
||||
Set<String> piRoleQuery = constructOrganizationGrantsQueryTemplate("hasPIWithGrant", "hasPrincipalInvestigatorRole");
|
||||
Set<String> coPIRoleQuery = constructOrganizationGrantsQueryTemplate("hascoPIWithGrant", "hasCo-PrincipalInvestigatorRole");
|
||||
|
||||
differentInvestigatorTypeQueries.addAll(investigatorRoleQuery);
|
||||
differentInvestigatorTypeQueries.addAll(piRoleQuery);
|
||||
differentInvestigatorTypeQueries.addAll(coPIRoleQuery);
|
||||
|
||||
return differentInvestigatorTypeQueries;
|
||||
}
|
||||
|
||||
private Model executeQuery(Set<String> constructQueries) {
|
||||
|
||||
Model constructedModel = ModelFactory.createDefaultModel();
|
||||
|
||||
before = System.currentTimeMillis();
|
||||
log.debug("CONSTRUCT query string : " + constructQuery);
|
||||
log.debug("CONSTRUCT query string : " + constructQueries);
|
||||
|
||||
for (String currentQuery : constructQueries) {
|
||||
|
||||
Query query = null;
|
||||
|
||||
try {
|
||||
query = QueryFactory.create(QueryConstants.getSparqlPrefixQuery()
|
||||
+ constructQuery, SYNTAX);
|
||||
query = QueryFactory.create(QueryConstants.getSparqlPrefixQuery() + currentQuery, SYNTAX);
|
||||
} catch (Throwable th) {
|
||||
log.error("Could not create CONSTRUCT SPARQL query for query "
|
||||
+ "string. " + th.getMessage());
|
||||
log.error(constructQuery);
|
||||
log.error(currentQuery);
|
||||
}
|
||||
|
||||
QueryExecution qe = QueryExecutionFactory.create(query, dataset);
|
||||
|
@ -119,6 +173,7 @@ public class OrganizationToGrantsForSubOrganizationsModelConstructor implements
|
|||
} finally {
|
||||
qe.close();
|
||||
}
|
||||
}
|
||||
|
||||
after = System.currentTimeMillis();
|
||||
log.debug("Time taken to execute the CONSTRUCT queries is in milliseconds: "
|
||||
|
|
|
@ -0,0 +1,171 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
package edu.cornell.mannlib.vitro.webapp.visualization.freemarker.modelconstructor;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import com.hp.hpl.jena.query.Dataset;
|
||||
import com.hp.hpl.jena.query.Query;
|
||||
import com.hp.hpl.jena.query.QueryExecution;
|
||||
import com.hp.hpl.jena.query.QueryExecutionFactory;
|
||||
import com.hp.hpl.jena.query.QueryFactory;
|
||||
import com.hp.hpl.jena.query.Syntax;
|
||||
import com.hp.hpl.jena.rdf.model.Model;
|
||||
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
||||
|
||||
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 PersonToGrantsModelConstructor implements ModelConstructor {
|
||||
|
||||
protected static final Syntax SYNTAX = Syntax.syntaxARQ;
|
||||
|
||||
private Dataset dataset;
|
||||
|
||||
public static final String MODEL_TYPE = "PERSON_TO_GRANTS";
|
||||
|
||||
private String personURI;
|
||||
|
||||
private Log log = LogFactory.getLog(PersonToGrantsModelConstructor.class.getName());
|
||||
|
||||
private long before, after;
|
||||
|
||||
public PersonToGrantsModelConstructor(String personURI, Dataset dataset) {
|
||||
this.personURI = personURI;
|
||||
this.dataset = dataset;
|
||||
}
|
||||
|
||||
private Set<String> constructPersonGrantsQueryTemplate(String constructProperty, String roleTypeProperty) {
|
||||
|
||||
Set<String> differentPerspectiveQueries = new HashSet<String>();
|
||||
|
||||
String justGrantsQuery = ""
|
||||
+ " CONSTRUCT { "
|
||||
+ " <" + personURI + "> vivosocnet:lastCachedAt ?now . "
|
||||
+ " <" + personURI + "> vivosocnet:" + constructProperty + " ?Grant . "
|
||||
+ " "
|
||||
+ " ?Grant rdf:type core:Grant . "
|
||||
+ " ?Grant rdfs:label ?grantLabel . "
|
||||
+ " "
|
||||
+ " } "
|
||||
+ " WHERE { "
|
||||
+ " ?Person core:" + roleTypeProperty + " ?Role . "
|
||||
+ " ?Role core:roleIn ?Grant . "
|
||||
+ " ?Grant rdfs:label ?grantLabel . "
|
||||
+ " "
|
||||
+ " LET(?now := afn:now()) "
|
||||
+ " } ";
|
||||
|
||||
String justDateTimeOnGrantsQuery = ""
|
||||
+ " CONSTRUCT { "
|
||||
+ " <" + personURI + "> vivosocnet:lastCachedAt ?now . "
|
||||
+ " ?Grant vivosocnet:startDateTimeOnGrant ?startDateTimeValueForGrant . "
|
||||
// + " ?Grant vivosocnet:endDateTimeOnGrant ?endDateTimeValueForGrant . "
|
||||
+ " "
|
||||
+ " } "
|
||||
+ " WHERE { "
|
||||
+ " ?Person core:" + roleTypeProperty + " ?Role . "
|
||||
+ " ?Role core:roleIn ?Grant . "
|
||||
+ " "
|
||||
+ " ?Grant core:dateTimeInterval ?dateTimeIntervalValueForGrant . "
|
||||
// + " OPTIONAL { "
|
||||
+ " ?dateTimeIntervalValueForGrant core:start ?startDateForGrant . "
|
||||
+ " ?startDateForGrant core:dateTime ?startDateTimeValueForGrant . "
|
||||
// + " } "
|
||||
// + " OPTIONAL { "
|
||||
// + " ?dateTimeIntervalValueForGrant core:end ?endDateForGrant . "
|
||||
// + " ?endDateForGrant core:dateTime ?endDateTimeValueForGrant "
|
||||
// + " } "
|
||||
+ " "
|
||||
+ " LET(?now := afn:now()) "
|
||||
+ " } ";
|
||||
|
||||
String justDateTimeOnRolesQuery = ""
|
||||
+ " CONSTRUCT { "
|
||||
+ " <" + personURI + "> vivosocnet:lastCachedAt ?now . "
|
||||
+ " ?Grant vivosocnet:startDateTimeOnRole ?startDateTimeValue . "
|
||||
// + " ?Grant vivosocnet:endDateTimeOnRole ?endDateTimeValue . "
|
||||
+ " } "
|
||||
+ " WHERE { "
|
||||
+ " ?Person core:" + roleTypeProperty + " ?Role . "
|
||||
+ " ?Role core:roleIn ?Grant . "
|
||||
+ " "
|
||||
+ " ?Role core:dateTimeInterval ?dateTimeIntervalValue . "
|
||||
// + " OPTIONAL { "
|
||||
+ " ?dateTimeIntervalValue core:start ?startDate . "
|
||||
+ " ?startDate core:dateTime ?startDateTimeValue . "
|
||||
// + " } "
|
||||
// + " "
|
||||
// + " OPTIONAL { "
|
||||
// + " ?dateTimeIntervalValue core:end ?endDate . "
|
||||
// + " ?endDate core:dateTime ?endDateTimeValue . "
|
||||
// + " } "
|
||||
+ " "
|
||||
+ " LET(?now := afn:now()) "
|
||||
+ " } ";
|
||||
|
||||
differentPerspectiveQueries.add(justGrantsQuery);
|
||||
differentPerspectiveQueries.add(justDateTimeOnGrantsQuery);
|
||||
differentPerspectiveQueries.add(justDateTimeOnRolesQuery);
|
||||
|
||||
return differentPerspectiveQueries;
|
||||
}
|
||||
|
||||
private Set<String> constructPersonToGrantsQuery() {
|
||||
|
||||
Set<String> differentInvestigatorTypeQueries = new HashSet<String>();
|
||||
|
||||
Set<String> investigatorRoleQuery = constructPersonGrantsQueryTemplate("hasGrantAsAnInvestigator", "hasInvestigatorRole");
|
||||
Set<String> piRoleQuery = constructPersonGrantsQueryTemplate("hasGrantAsPI", "hasPrincipalInvestigatorRole");
|
||||
Set<String> coPIRoleQuery = constructPersonGrantsQueryTemplate("hasGrantAsCoPI", "hasCo-PrincipalInvestigatorRole");
|
||||
|
||||
differentInvestigatorTypeQueries.addAll(investigatorRoleQuery);
|
||||
differentInvestigatorTypeQueries.addAll(piRoleQuery);
|
||||
differentInvestigatorTypeQueries.addAll(coPIRoleQuery);
|
||||
|
||||
return differentInvestigatorTypeQueries;
|
||||
}
|
||||
|
||||
private Model executeQuery(Set<String> constructQueries) {
|
||||
|
||||
Model constructedModel = ModelFactory.createDefaultModel();
|
||||
|
||||
before = System.currentTimeMillis();
|
||||
log.debug("CONSTRUCT query string : " + constructQueries);
|
||||
|
||||
for (String currentQuery : constructQueries) {
|
||||
|
||||
Query query = null;
|
||||
|
||||
try {
|
||||
query = QueryFactory.create(QueryConstants.getSparqlPrefixQuery() + currentQuery, SYNTAX);
|
||||
} catch (Throwable th) {
|
||||
log.error("Could not create CONSTRUCT SPARQL query for query "
|
||||
+ "string. " + th.getMessage());
|
||||
log.error(currentQuery);
|
||||
}
|
||||
|
||||
QueryExecution qe = QueryExecutionFactory.create(query, dataset);
|
||||
|
||||
try {
|
||||
qe.execConstruct(constructedModel);
|
||||
} finally {
|
||||
qe.close();
|
||||
}
|
||||
}
|
||||
|
||||
after = System.currentTimeMillis();
|
||||
log.debug("Time taken to execute the CONSTRUCT queries is in milliseconds: "
|
||||
+ (after - before));
|
||||
|
||||
return constructedModel;
|
||||
}
|
||||
|
||||
public Model getConstructedModel() throws MalformedQueryParametersException {
|
||||
return executeQuery(constructPersonToGrantsQuery());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
package edu.cornell.mannlib.vitro.webapp.visualization.freemarker.modelconstructor.factory;
|
||||
|
||||
import com.hp.hpl.jena.query.Dataset;
|
||||
import com.hp.hpl.jena.rdf.model.Model;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.modelconstructor.PersonToGrantsModelConstructor;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.valueobjects.ConstructedModelTracker;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.ModelConstructor;
|
||||
|
||||
public class PersonToGrantsFactory implements ModelFactoryInterface {
|
||||
|
||||
@Override
|
||||
public Model getOrCreateModel(String uri, Dataset dataset)
|
||||
throws MalformedQueryParametersException {
|
||||
|
||||
Model candidateModel = ConstructedModelTracker.getModel(
|
||||
ConstructedModelTracker
|
||||
.generateModelIdentifier(
|
||||
uri,
|
||||
PersonToGrantsModelConstructor.MODEL_TYPE));
|
||||
|
||||
if (candidateModel != null) {
|
||||
|
||||
return candidateModel;
|
||||
|
||||
} else {
|
||||
|
||||
ModelConstructor model = new PersonToGrantsModelConstructor(uri, dataset);
|
||||
|
||||
Model constructedModel = model.getConstructedModel();
|
||||
ConstructedModelTracker.trackModel(
|
||||
ConstructedModelTracker
|
||||
.generateModelIdentifier(
|
||||
uri,
|
||||
PersonToGrantsModelConstructor.MODEL_TYPE),
|
||||
constructedModel);
|
||||
|
||||
return constructedModel;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -23,6 +23,7 @@ import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.modelconstructo
|
|||
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.OrganizationToPublicationsForSubOrganizationsModelConstructor;
|
||||
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.valueobjects.Activity;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.valueobjects.Entity;
|
||||
|
@ -314,14 +315,14 @@ public class SelectOnModelUtilities {
|
|||
|
||||
for (SubEntity subOrganization : organizationEntity.getSubEntities()) {
|
||||
|
||||
System.out.println("constructing grants for " + subOrganization.getIndividualLabel() + " :: " + subOrganization.getIndividualURI());
|
||||
|
||||
Model subOrganizationGrantsModel = ModelConstructorUtilities
|
||||
.getOrConstructModel(
|
||||
subOrganization.getIndividualURI(),
|
||||
OrganizationToGrantsForSubOrganizationsModelConstructor.MODEL_TYPE,
|
||||
dataset);
|
||||
|
||||
System.out.println("getting grants for " + subOrganization.getIndividualLabel());
|
||||
|
||||
Map<String, String> fieldLabelToOutputFieldLabel = new HashMap<String, String>();
|
||||
fieldLabelToOutputFieldLabel.put("grant", QueryFieldLabels.GRANT_URL);
|
||||
fieldLabelToOutputFieldLabel.put("grantLabel", QueryFieldLabels.GRANT_LABEL);
|
||||
|
@ -329,12 +330,32 @@ public class SelectOnModelUtilities {
|
|||
fieldLabelToOutputFieldLabel.put("roleStartDate", QueryFieldLabels.ROLE_START_DATE);
|
||||
|
||||
String whereClause = ""
|
||||
+ " <" + subOrganization.getIndividualURI() + "> vivosocnet:hasPersonWithGrant ?grant . "
|
||||
+ "{"
|
||||
+ " <" + subOrganization.getIndividualURI() + "> vivosocnet:hasInvestigatorWithGrant ?grant . "
|
||||
+ " ?grant rdfs:label ?grantLabel . "
|
||||
+ " OPTIONAL { "
|
||||
+ " ?grant vivosocnet:startDateTimeOnGrant ?grantStartDate } . "
|
||||
+ " OPTIONAL { "
|
||||
+ " ?grant vivosocnet:startDateTimeOnRole ?roleStartDate } . ";
|
||||
+ " ?grant vivosocnet:startDateTimeOnRole ?roleStartDate } . "
|
||||
+ "}"
|
||||
+ "UNION"
|
||||
+ "{"
|
||||
+ " <" + subOrganization.getIndividualURI() + "> vivosocnet:hasPIWithGrant ?grant . "
|
||||
+ " ?grant rdfs:label ?grantLabel . "
|
||||
+ " OPTIONAL { "
|
||||
+ " ?grant vivosocnet:startDateTimeOnGrant ?grantStartDate } . "
|
||||
+ " OPTIONAL { "
|
||||
+ " ?grant vivosocnet:startDateTimeOnRole ?roleStartDate } . "
|
||||
+ "}"
|
||||
+ "UNION"
|
||||
+ "{"
|
||||
+ " <" + subOrganization.getIndividualURI() + "> vivosocnet:hascoPIWithGrant ?grant . "
|
||||
+ " ?grant rdfs:label ?grantLabel . "
|
||||
+ " OPTIONAL { "
|
||||
+ " ?grant vivosocnet:startDateTimeOnGrant ?grantStartDate } . "
|
||||
+ " OPTIONAL { "
|
||||
+ " ?grant vivosocnet:startDateTimeOnRole ?roleStartDate } . "
|
||||
+ "}";
|
||||
|
||||
QueryRunner<ResultSet> subOrganizationGrantsQuery =
|
||||
new GenericQueryRunnerOnModel(fieldLabelToOutputFieldLabel,
|
||||
|
@ -351,6 +372,70 @@ public class SelectOnModelUtilities {
|
|||
return allGrantURIToVO;
|
||||
}
|
||||
|
||||
public static Map<String, Activity> getGrantForAssociatedPeople(
|
||||
Dataset dataset, Collection<SubEntity> people)
|
||||
throws MalformedQueryParametersException {
|
||||
Map<String, Activity> allGrantURIToVOs = new HashMap<String, Activity>();
|
||||
|
||||
for (SubEntity person : people) {
|
||||
|
||||
System.out.println("constructing grants for " + person.getIndividualLabel() + " :: " + person.getIndividualURI());
|
||||
|
||||
Model personGrantsModel = ModelConstructorUtilities
|
||||
.getOrConstructModel(
|
||||
person.getIndividualURI(),
|
||||
PersonToGrantsModelConstructor.MODEL_TYPE,
|
||||
dataset);
|
||||
|
||||
Map<String, String> fieldLabelToOutputFieldLabel = new HashMap<String, String>();
|
||||
fieldLabelToOutputFieldLabel.put("grant", QueryFieldLabels.GRANT_URL);
|
||||
fieldLabelToOutputFieldLabel.put("grantLabel", QueryFieldLabels.GRANT_LABEL);
|
||||
fieldLabelToOutputFieldLabel.put("grantStartDate", QueryFieldLabels.GRANT_START_DATE);
|
||||
fieldLabelToOutputFieldLabel.put("roleStartDate", QueryFieldLabels.ROLE_START_DATE);
|
||||
|
||||
String whereClause = ""
|
||||
+ "{"
|
||||
+ " <" + person.getIndividualURI() + "> vivosocnet:hasGrantAsAnInvestigator ?grant . "
|
||||
+ " ?grant rdfs:label ?grantLabel . "
|
||||
+ " OPTIONAL { "
|
||||
+ " ?grant vivosocnet:startDateTimeOnGrant ?grantStartDate } . "
|
||||
+ " OPTIONAL { "
|
||||
+ " ?grant vivosocnet:startDateTimeOnRole ?roleStartDate } . "
|
||||
+ "}"
|
||||
+ "UNION"
|
||||
+ "{"
|
||||
+ " <" + person.getIndividualURI() + "> vivosocnet:hasGrantAsPI ?grant . "
|
||||
+ " ?grant rdfs:label ?grantLabel . "
|
||||
+ " OPTIONAL { "
|
||||
+ " ?grant vivosocnet:startDateTimeOnGrant ?grantStartDate } . "
|
||||
+ " OPTIONAL { "
|
||||
+ " ?grant vivosocnet:startDateTimeOnRole ?roleStartDate } . "
|
||||
+ "}"
|
||||
+ "UNION"
|
||||
+ "{"
|
||||
+ " <" + person.getIndividualURI() + "> vivosocnet:hasGrantAsCoPI ?grant . "
|
||||
+ " ?grant rdfs:label ?grantLabel . "
|
||||
+ " OPTIONAL { "
|
||||
+ " ?grant vivosocnet:startDateTimeOnGrant ?grantStartDate } . "
|
||||
+ " OPTIONAL { "
|
||||
+ " ?grant vivosocnet:startDateTimeOnRole ?roleStartDate } . "
|
||||
+ "}";
|
||||
|
||||
QueryRunner<ResultSet> personGrantsQuery =
|
||||
new GenericQueryRunnerOnModel(fieldLabelToOutputFieldLabel,
|
||||
"",
|
||||
whereClause,
|
||||
"",
|
||||
personGrantsModel);
|
||||
|
||||
person.addActivities(getGrantForEntity(
|
||||
personGrantsQuery.getQueryResult(),
|
||||
allGrantURIToVOs));
|
||||
|
||||
}
|
||||
return allGrantURIToVOs;
|
||||
}
|
||||
|
||||
public static Map<String, Activity> getPublicationsForAssociatedPeople(
|
||||
Dataset dataset, Collection<SubEntity> people)
|
||||
throws MalformedQueryParametersException {
|
||||
|
|
Loading…
Add table
Reference in a new issue