1. Refactored the enetity grant code.
2. Started initial restructuring of the tmeporal vis code. Now entitycomparison means just that - a container for different vis that do entity comparison. So the newly anointed TemporalGrantVis* goes in there and resides along with TemporalPublicationVis* 3. Added new model constructor for organizations TO grants via investigator role. 4. First attempt at using the new layout for grants but currently restricted only to construct+select on grants via the investigator role.
This commit is contained in:
parent
82a6e06e35
commit
a3ffff2adf
8 changed files with 630 additions and 24 deletions
|
@ -32,11 +32,13 @@
|
|||
class="edu.cornell.mannlib.vitro.webapp.visualization.freemarker.entitycomparison.EntityPublicationCountRequestHandler" />
|
||||
|
||||
<bean id="pub_temporal"
|
||||
class="edu.cornell.mannlib.vitro.webapp.visualization.freemarker.entitycomparison.cached.EntityPublicationRequestHandler" />
|
||||
class="edu.cornell.mannlib.vitro.webapp.visualization.freemarker.entitycomparison.cached.TemporalPublicationVisualizationRequestHandler" />
|
||||
|
||||
<bean id="entity_grant_count"
|
||||
class="edu.cornell.mannlib.vitro.webapp.visualization.freemarker.entitygrantcount.EntityGrantCountRequestHandler" />
|
||||
|
||||
|
||||
<bean id="grant_temporal"
|
||||
class="edu.cornell.mannlib.vitro.webapp.visualization.freemarker.entitycomparison.cached.TemporalGrantVisualizationRequestHandler" />
|
||||
|
||||
<bean id="visualizationInjector"
|
||||
class="edu.cornell.mannlib.vitro.webapp.controller.visualization.freemarker.VisualizationInjector">
|
||||
|
@ -62,16 +64,16 @@
|
|||
<ref bean="person_level"></ref>
|
||||
</entry>
|
||||
|
||||
<!--
|
||||
<entry key="entity_comparison">
|
||||
<ref bean="entity_comparison"></ref>
|
||||
</entry>
|
||||
-->
|
||||
|
||||
<entry key="entity_comparison">
|
||||
<ref bean="entity_comparison"></ref>
|
||||
</entry>
|
||||
|
||||
<!--
|
||||
<entry key="entity_comparison">
|
||||
<ref bean="pub_temporal"></ref>
|
||||
</entry>
|
||||
-->
|
||||
|
||||
<entry key="pub_temporal">
|
||||
<ref bean="pub_temporal"></ref>
|
||||
|
@ -83,7 +85,11 @@
|
|||
|
||||
<entry key="entity_grant_count">
|
||||
<ref bean="entity_grant_count"></ref>
|
||||
</entry>
|
||||
</entry>
|
||||
|
||||
<entry key="grant_temporal">
|
||||
<ref bean="grant_temporal"></ref>
|
||||
</entry>
|
||||
|
||||
</map>
|
||||
</property>
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.visualization.freemarker.entitycomparison.cached;
|
||||
|
||||
public class EntityComparisonConstants {
|
||||
|
||||
public static enum DataVisMode {
|
||||
CSV, JSON
|
||||
};
|
||||
|
||||
}
|
|
@ -0,0 +1,332 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.visualization.freemarker.entitycomparison.cached;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.lang.StringEscapeUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.logging.Log;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.hp.hpl.jena.query.Dataset;
|
||||
import com.hp.hpl.jena.rdf.model.Model;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Portal;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ResponseValues;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.TemplateResponseValues;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.visualization.freemarker.DataVisualizationController;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.visualization.freemarker.VisualizationFrameworkConstants;
|
||||
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.freemarker.entitycomparison.EntityComparisonUtilityFunctions;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.valueobjects.Activity;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.valueobjects.ConstructedModelTracker;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.valueobjects.Entity;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.valueobjects.JsonObject;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.valueobjects.SubEntity;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.SelectOnModelUtilities;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.UtilityFunctions;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.VisualizationRequestHandler;
|
||||
|
||||
|
||||
public class TemporalGrantVisualizationRequestHandler implements
|
||||
VisualizationRequestHandler {
|
||||
|
||||
@Override
|
||||
public ResponseValues generateStandardVisualization(
|
||||
VitroRequest vitroRequest, Log log, Dataset dataset)
|
||||
throws MalformedQueryParametersException {
|
||||
|
||||
String entityURI = vitroRequest
|
||||
.getParameter(VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY);
|
||||
|
||||
if (StringUtils.isBlank(entityURI)) {
|
||||
|
||||
entityURI = EntityComparisonUtilityFunctions
|
||||
.getStaffProvidedOrComputedHighestLevelOrganization(
|
||||
log,
|
||||
dataset,
|
||||
vitroRequest);
|
||||
|
||||
}
|
||||
|
||||
System.out.println("current models in the system are");
|
||||
for (Map.Entry<String, Model> entry : ConstructedModelTracker.getAllModels().entrySet()) {
|
||||
System.out.println(entry.getKey() + " -> " + entry.getValue().size());
|
||||
}
|
||||
|
||||
return prepareStandaloneMarkupResponse(vitroRequest, entityURI);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> generateDataVisualization(
|
||||
VitroRequest vitroRequest, Log log, Dataset dataset)
|
||||
throws MalformedQueryParametersException {
|
||||
|
||||
String entityURI = vitroRequest
|
||||
.getParameter(VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY);
|
||||
|
||||
/*
|
||||
* This will provide the data in json format mainly used for standalone temporal vis.
|
||||
* */
|
||||
if (VisualizationFrameworkConstants.TEMPORAL_GRAPH_JSON_DATA_VIS_MODE
|
||||
.equalsIgnoreCase(vitroRequest
|
||||
.getParameter(VisualizationFrameworkConstants.VIS_MODE_KEY))) {
|
||||
|
||||
if (StringUtils.isNotBlank(entityURI)) {
|
||||
|
||||
return getSubjectEntityAndGenerateDataResponse(
|
||||
vitroRequest,
|
||||
log,
|
||||
dataset,
|
||||
entityURI,
|
||||
EntityComparisonConstants.DataVisMode.JSON);
|
||||
} else {
|
||||
|
||||
return getSubjectEntityAndGenerateDataResponse(
|
||||
vitroRequest,
|
||||
log,
|
||||
dataset,
|
||||
EntityComparisonUtilityFunctions
|
||||
.getStaffProvidedOrComputedHighestLevelOrganization(
|
||||
log,
|
||||
dataset,
|
||||
vitroRequest),
|
||||
EntityComparisonConstants.DataVisMode.JSON);
|
||||
}
|
||||
|
||||
} else {
|
||||
/*
|
||||
* This provides csv download files for the content in the tables.
|
||||
* */
|
||||
return getSubjectEntityAndGenerateDataResponse(
|
||||
vitroRequest,
|
||||
log,
|
||||
dataset,
|
||||
entityURI,
|
||||
EntityComparisonConstants.DataVisMode.CSV);
|
||||
}
|
||||
}
|
||||
|
||||
private Map<String, String> prepareDataErrorResponse() {
|
||||
|
||||
String outputFileName = "no-organization_grants-per-year.csv";
|
||||
|
||||
Map<String, String> fileData = new HashMap<String, String>();
|
||||
|
||||
fileData.put(DataVisualizationController.FILE_NAME_KEY,
|
||||
outputFileName);
|
||||
fileData.put(DataVisualizationController.FILE_CONTENT_TYPE_KEY,
|
||||
"application/octet-stream");
|
||||
fileData.put(DataVisualizationController.FILE_CONTENT_KEY, "");
|
||||
return fileData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object generateAjaxVisualization(VitroRequest vitroRequest, Log log,
|
||||
Dataset dataset) throws MalformedQueryParametersException {
|
||||
|
||||
throw new UnsupportedOperationException("Entity Grant Count "
|
||||
+ "does not provide Ajax response.");
|
||||
}
|
||||
|
||||
private Map<String, String> getSubjectEntityAndGenerateDataResponse(
|
||||
VitroRequest vitroRequest, Log log, Dataset dataset,
|
||||
String subjectEntityURI, EntityComparisonConstants.DataVisMode visMode)
|
||||
throws MalformedQueryParametersException {
|
||||
|
||||
Entity organizationEntity = SelectOnModelUtilities
|
||||
.getSubjectOrganizationHierarchy(dataset, subjectEntityURI);
|
||||
|
||||
if (organizationEntity.getSubEntities() == null) {
|
||||
|
||||
if (EntityComparisonConstants.DataVisMode.JSON.equals(visMode)) {
|
||||
return prepareStandaloneDataErrorResponse();
|
||||
} else {
|
||||
return prepareDataErrorResponse();
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, Activity> grantURIForAssociatedPeopleToVO = new HashMap<String, Activity>();
|
||||
Map<String, Activity> allGrantURIToVO = new HashMap<String, Activity>();
|
||||
|
||||
allGrantURIToVO = SelectOnModelUtilities.getGrantsForAllSubOrganizations(dataset, organizationEntity);
|
||||
|
||||
if (allGrantURIToVO.isEmpty() && grantURIForAssociatedPeopleToVO.isEmpty()) {
|
||||
|
||||
if (EntityComparisonConstants.DataVisMode.JSON.equals(visMode)) {
|
||||
return prepareStandaloneDataErrorResponse();
|
||||
} else {
|
||||
return prepareDataErrorResponse();
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
if (EntityComparisonConstants.DataVisMode.JSON.equals(visMode)) {
|
||||
return prepareStandaloneDataResponse(vitroRequest, organizationEntity);
|
||||
} else {
|
||||
return prepareDataResponse(organizationEntity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Map<String, String> prepareStandaloneDataErrorResponse() {
|
||||
|
||||
Map<String, String> fileData = new HashMap<String, String>();
|
||||
|
||||
fileData.put(DataVisualizationController.FILE_CONTENT_TYPE_KEY,
|
||||
"application/octet-stream");
|
||||
fileData.put(DataVisualizationController.FILE_CONTENT_KEY,
|
||||
"{\"error\" : \"No Grants for this Organization found in VIVO.\"}");
|
||||
return fileData;
|
||||
}
|
||||
|
||||
|
||||
private Map<String, String> prepareStandaloneDataResponse(
|
||||
VitroRequest vitroRequest,
|
||||
Entity entity) {
|
||||
|
||||
Map<String, String> fileData = new HashMap<String, String>();
|
||||
|
||||
fileData.put(DataVisualizationController.FILE_CONTENT_TYPE_KEY,
|
||||
"application/octet-stream");
|
||||
fileData.put(DataVisualizationController.FILE_CONTENT_KEY,
|
||||
writeGrantsOverTimeJSON(vitroRequest,
|
||||
entity.getSubEntities()));
|
||||
return fileData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides response when json file containing the grant count over the
|
||||
* years is requested.
|
||||
*
|
||||
* @param entity
|
||||
* @param subentities
|
||||
* @param subOrganizationTypesResult
|
||||
*/
|
||||
private Map<String, String> prepareDataResponse(Entity entity) {
|
||||
|
||||
String entityLabel = entity.getEntityLabel();
|
||||
|
||||
/*
|
||||
* To make sure that null/empty records for entity names do not cause any mischief.
|
||||
* */
|
||||
if (StringUtils.isBlank(entityLabel)) {
|
||||
entityLabel = "no-organization";
|
||||
}
|
||||
|
||||
String outputFileName = UtilityFunctions.slugify(entityLabel)
|
||||
+ "_grants-per-year" + ".csv";
|
||||
|
||||
|
||||
Map<String, String> fileData = new HashMap<String, String>();
|
||||
|
||||
fileData.put(DataVisualizationController.FILE_NAME_KEY,
|
||||
outputFileName);
|
||||
fileData.put(DataVisualizationController.FILE_CONTENT_TYPE_KEY,
|
||||
"application/octet-stream");
|
||||
fileData.put(DataVisualizationController.FILE_CONTENT_KEY,
|
||||
getEntityGrantsPerYearCSVContent(entity));
|
||||
return fileData;
|
||||
}
|
||||
|
||||
|
||||
private TemplateResponseValues prepareStandaloneMarkupResponse(VitroRequest vreq,
|
||||
String entityURI) {
|
||||
|
||||
Portal portal = vreq.getPortal();
|
||||
String standaloneTemplate = "entityComparisonOnGrantsStandalone.ftl";
|
||||
|
||||
String organizationLabel = EntityComparisonUtilityFunctions.getEntityLabelFromDAO(vreq,
|
||||
entityURI);
|
||||
|
||||
Map<String, Object> body = new HashMap<String, Object>();
|
||||
body.put("portalBean", portal);
|
||||
body.put("title", organizationLabel + " - Temporal Graph Visualization");
|
||||
body.put("organizationURI", entityURI);
|
||||
body.put("organizationLabel", organizationLabel);
|
||||
|
||||
return new TemplateResponseValues(standaloneTemplate, body);
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to generate a json file for year <-> grant count mapping.
|
||||
* @param vreq
|
||||
* @param subentities
|
||||
* @param subOrganizationTypesResult
|
||||
*/
|
||||
private String writeGrantsOverTimeJSON(VitroRequest vreq,
|
||||
Set<SubEntity> subentities) {
|
||||
|
||||
Gson json = new Gson();
|
||||
Set<JsonObject> subEntitiesJson = new HashSet<JsonObject>();
|
||||
|
||||
for (SubEntity subentity : subentities) {
|
||||
JsonObject entityJson = new JsonObject(
|
||||
subentity.getIndividualLabel());
|
||||
|
||||
List<List<Integer>> yearGrantCount = new ArrayList<List<Integer>>();
|
||||
|
||||
for (Map.Entry<String, Integer> grantEntry : UtilityFunctions
|
||||
.getYearToActivityCount(subentity.getActivities())
|
||||
.entrySet()) {
|
||||
|
||||
List<Integer> currentGrantYear = new ArrayList<Integer>();
|
||||
if (grantEntry.getKey().equals(
|
||||
VOConstants.DEFAULT_GRANT_YEAR)) {
|
||||
currentGrantYear.add(-1);
|
||||
} else {
|
||||
currentGrantYear.add(Integer.parseInt(grantEntry.getKey()));
|
||||
}
|
||||
|
||||
currentGrantYear.add(grantEntry.getValue());
|
||||
yearGrantCount.add(currentGrantYear);
|
||||
}
|
||||
|
||||
entityJson.setYearToActivityCount(yearGrantCount);
|
||||
|
||||
entityJson.setOrganizationTypes(subentity.getEntityTypeLabels());
|
||||
|
||||
entityJson.setEntityURI(subentity.getIndividualURI());
|
||||
|
||||
if (subentity.getEntityClass().equals(VOConstants.EntityClassType.PERSON)) {
|
||||
entityJson.setVisMode("PERSON");
|
||||
} else if (subentity.getEntityClass().equals(VOConstants.EntityClassType.ORGANIZATION)) {
|
||||
entityJson.setVisMode("ORGANIZATION");
|
||||
}
|
||||
|
||||
subEntitiesJson.add(entityJson);
|
||||
}
|
||||
|
||||
return json.toJson(subEntitiesJson);
|
||||
}
|
||||
|
||||
private String getEntityGrantsPerYearCSVContent(Entity entity) {
|
||||
|
||||
StringBuilder csvFileContent = new StringBuilder();
|
||||
|
||||
csvFileContent.append("Entity Name, Grant Count, Entity Type\n");
|
||||
|
||||
for (SubEntity subEntity : entity.getSubEntities()) {
|
||||
|
||||
csvFileContent.append(StringEscapeUtils.escapeCsv(subEntity.getIndividualLabel()));
|
||||
csvFileContent.append(", ");
|
||||
csvFileContent.append(subEntity.getActivities().size());
|
||||
csvFileContent.append(", ");
|
||||
|
||||
String allTypes = StringUtils.join(subEntity.getEntityTypeLabels(), "; ");
|
||||
|
||||
csvFileContent.append(StringEscapeUtils.escapeCsv(allTypes));
|
||||
csvFileContent.append("\n");
|
||||
}
|
||||
|
||||
return csvFileContent.toString();
|
||||
}
|
||||
}
|
|
@ -35,13 +35,9 @@ import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.Select
|
|||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.UtilityFunctions;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.VisualizationRequestHandler;
|
||||
|
||||
public class EntityPublicationRequestHandler implements
|
||||
public class TemporalPublicationVisualizationRequestHandler implements
|
||||
VisualizationRequestHandler {
|
||||
|
||||
public enum DataVisMode {
|
||||
CSV, JSON
|
||||
};
|
||||
|
||||
@Override
|
||||
public ResponseValues generateStandardVisualization(
|
||||
VitroRequest vitroRequest, Log log, Dataset dataset)
|
||||
|
@ -67,15 +63,12 @@ public class EntityPublicationRequestHandler implements
|
|||
System.out.println(entry.getKey() + " -> " + entry.getValue().size());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
return prepareStandaloneMarkupResponse(vitroRequest, entityURI);
|
||||
}
|
||||
|
||||
private Map<String, String> getSubjectEntityAndGenerateDataResponse(
|
||||
VitroRequest vitroRequest, Log log, Dataset dataset,
|
||||
String subjectEntityURI, DataVisMode visMode)
|
||||
String subjectEntityURI, EntityComparisonConstants.DataVisMode visMode)
|
||||
throws MalformedQueryParametersException {
|
||||
|
||||
|
||||
|
@ -84,7 +77,7 @@ public class EntityPublicationRequestHandler implements
|
|||
|
||||
if (organizationEntity.getSubEntities() == null) {
|
||||
|
||||
if (DataVisMode.JSON.equals(visMode)) {
|
||||
if (EntityComparisonConstants.DataVisMode.JSON.equals(visMode)) {
|
||||
return prepareStandaloneDataErrorResponse();
|
||||
} else {
|
||||
return prepareDataErrorResponse();
|
||||
|
@ -113,7 +106,7 @@ public class EntityPublicationRequestHandler implements
|
|||
|
||||
if (allDocumentURIToVOs.isEmpty() && documentURIForAssociatedPeopleTOVO.isEmpty()) {
|
||||
|
||||
if (DataVisMode.JSON.equals(visMode)) {
|
||||
if (EntityComparisonConstants.DataVisMode.JSON.equals(visMode)) {
|
||||
return prepareStandaloneDataErrorResponse();
|
||||
} else {
|
||||
return prepareDataErrorResponse();
|
||||
|
@ -121,7 +114,7 @@ public class EntityPublicationRequestHandler implements
|
|||
|
||||
} else {
|
||||
|
||||
if (DataVisMode.JSON.equals(visMode)) {
|
||||
if (EntityComparisonConstants.DataVisMode.JSON.equals(visMode)) {
|
||||
return prepareStandaloneDataResponse(vitroRequest, organizationEntity);
|
||||
} else {
|
||||
return prepareDataResponse(organizationEntity);
|
||||
|
@ -210,7 +203,7 @@ public class EntityPublicationRequestHandler implements
|
|||
log,
|
||||
dataset,
|
||||
entityURI,
|
||||
DataVisMode.JSON);
|
||||
EntityComparisonConstants.DataVisMode.JSON);
|
||||
} else {
|
||||
|
||||
return getSubjectEntityAndGenerateDataResponse(
|
||||
|
@ -222,7 +215,7 @@ public class EntityPublicationRequestHandler implements
|
|||
log,
|
||||
dataset,
|
||||
vitroRequest),
|
||||
DataVisMode.JSON);
|
||||
EntityComparisonConstants.DataVisMode.JSON);
|
||||
}
|
||||
|
||||
} else {
|
||||
|
@ -235,7 +228,7 @@ public class EntityPublicationRequestHandler implements
|
|||
log,
|
||||
dataset,
|
||||
entityURI,
|
||||
DataVisMode.CSV);
|
||||
EntityComparisonConstants.DataVisMode.CSV);
|
||||
|
||||
}
|
||||
|
||||
|
@ -321,7 +314,6 @@ public class EntityPublicationRequestHandler implements
|
|||
|
||||
entityJson.setOrganizationTypes(subentity.getEntityTypeLabels());
|
||||
|
||||
|
||||
entityJson.setEntityURI(subentity.getIndividualURI());
|
||||
|
||||
if (subentity.getEntityClass().equals(VOConstants.EntityClassType.PERSON)) {
|
|
@ -11,6 +11,7 @@ import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryP
|
|||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.modelconstructor.factory.ModelFactoryInterface;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.modelconstructor.factory.OrganizationAssociatedPeopleModelWithTypesFactory;
|
||||
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.PersonToPublicationsFactory;
|
||||
|
||||
|
@ -20,6 +21,7 @@ public class ModelConstructorUtilities {
|
|||
private static final Map<String, ModelFactoryInterface> modelTypeIdentifierToFactory = new HashMap<String, ModelFactoryInterface>() {{
|
||||
put(PersonToPublicationsModelConstructor.MODEL_TYPE, new PersonToPublicationsFactory());
|
||||
put(OrganizationToPublicationsForSubOrganizationsModelConstructor.MODEL_TYPE, new OrganizationToPublicationsForSubOrganizationsFactory());
|
||||
put(OrganizationToGrantsForSubOrganizationsModelConstructor.MODEL_TYPE, new OrganizationToGrantsForSubOrganizationsFactory());
|
||||
put(OrganizationAssociatedPeopleModelWithTypesConstructor.MODEL_TYPE, new OrganizationAssociatedPeopleModelWithTypesFactory());
|
||||
put(OrganizationModelWithTypesConstructor.MODEL_TYPE, new OrganizationModelWithTypesFactory());
|
||||
}};
|
||||
|
|
|
@ -0,0 +1,133 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
package edu.cornell.mannlib.vitro.webapp.visualization.freemarker.modelconstructor;
|
||||
|
||||
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 OrganizationToGrantsForSubOrganizationsModelConstructor implements ModelConstructor {
|
||||
|
||||
protected static final Syntax SYNTAX = Syntax.syntaxARQ;
|
||||
|
||||
private Dataset dataset;
|
||||
|
||||
public static final String MODEL_TYPE = "ORGANIZATION_TO_GRANTS_FOR_SUBORGANIZATIONS";
|
||||
|
||||
private String organizationURI;
|
||||
|
||||
private Log log = LogFactory.getLog(OrganizationToGrantsForSubOrganizationsModelConstructor.class.getName());
|
||||
|
||||
private long before, after;
|
||||
|
||||
public OrganizationToGrantsForSubOrganizationsModelConstructor(String organizationURI, Dataset dataset) {
|
||||
this.organizationURI = organizationURI;
|
||||
this.dataset = dataset;
|
||||
}
|
||||
|
||||
private String constructOrganizationToGrantsQuery() {
|
||||
|
||||
return ""
|
||||
+ " CONSTRUCT { "
|
||||
+ " <" + organizationURI + "> rdfs:label ?organizationLabel . "
|
||||
+ " <" + organizationURI + "> vivosocnet:lastCachedAt ?now . "
|
||||
+ " <" + organizationURI + "> vivosocnet:hasPersonWithGrant ?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 . "
|
||||
+ " ?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()) "
|
||||
+ " } ";
|
||||
|
||||
}
|
||||
|
||||
private Model executeQuery(String constructQuery) {
|
||||
|
||||
System.out.println("in execute query - org to grants for - " + organizationURI);
|
||||
|
||||
Model constructedModel = ModelFactory.createDefaultModel();
|
||||
|
||||
before = System.currentTimeMillis();
|
||||
log.debug("CONSTRUCT query string : " + constructQuery);
|
||||
|
||||
Query query = null;
|
||||
|
||||
try {
|
||||
query = QueryFactory.create(QueryConstants.getSparqlPrefixQuery()
|
||||
+ constructQuery, SYNTAX);
|
||||
} catch (Throwable th) {
|
||||
log.error("Could not create CONSTRUCT SPARQL query for query "
|
||||
+ "string. " + th.getMessage());
|
||||
log.error(constructQuery);
|
||||
}
|
||||
|
||||
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(constructOrganizationToGrantsQuery());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
/* $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.OrganizationToGrantsForSubOrganizationsModelConstructor;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.valueobjects.ConstructedModelTracker;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.ModelConstructor;
|
||||
|
||||
public class OrganizationToGrantsForSubOrganizationsFactory implements
|
||||
ModelFactoryInterface {
|
||||
|
||||
@Override
|
||||
public Model getOrCreateModel(String uri, Dataset dataset)
|
||||
throws MalformedQueryParametersException {
|
||||
|
||||
Model candidateModel = ConstructedModelTracker.getModel(
|
||||
ConstructedModelTracker
|
||||
.generateModelIdentifier(
|
||||
uri,
|
||||
OrganizationToGrantsForSubOrganizationsModelConstructor.MODEL_TYPE));
|
||||
|
||||
if (candidateModel != null) {
|
||||
|
||||
return candidateModel;
|
||||
|
||||
} else {
|
||||
|
||||
ModelConstructor model = new OrganizationToGrantsForSubOrganizationsModelConstructor(uri, dataset);
|
||||
|
||||
Model constructedModel = model.getConstructedModel();
|
||||
ConstructedModelTracker.trackModel(
|
||||
ConstructedModelTracker
|
||||
.generateModelIdentifier(
|
||||
uri,
|
||||
OrganizationToGrantsForSubOrganizationsModelConstructor.MODEL_TYPE),
|
||||
constructedModel);
|
||||
|
||||
return constructedModel;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -21,6 +21,7 @@ import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryP
|
|||
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.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.PersonToPublicationsModelConstructor;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.valueobjects.Activity;
|
||||
|
@ -267,6 +268,89 @@ public class SelectOnModelUtilities {
|
|||
return currentEntityPublications;
|
||||
}
|
||||
|
||||
|
||||
private static Collection<Activity> getGrantForEntity(
|
||||
ResultSet queryResult,
|
||||
Map<String, Activity> allGrantURIToVO) {
|
||||
|
||||
Set<Activity> currentEntityGrants = new HashSet<Activity>();
|
||||
|
||||
while (queryResult.hasNext()) {
|
||||
|
||||
QuerySolution solution = queryResult.nextSolution();
|
||||
|
||||
RDFNode grantNode = solution.get(QueryFieldLabels.GRANT_URL);
|
||||
Activity coreGrant;
|
||||
|
||||
if (allGrantURIToVO.containsKey(grantNode.toString())) {
|
||||
coreGrant = allGrantURIToVO.get(grantNode.toString());
|
||||
|
||||
} else {
|
||||
|
||||
coreGrant = new Activity(grantNode.toString());
|
||||
allGrantURIToVO.put(grantNode.toString(), coreGrant);
|
||||
|
||||
RDFNode grantStartDateNode = solution.get(QueryFieldLabels.ROLE_START_DATE);
|
||||
|
||||
if (grantStartDateNode != null) {
|
||||
coreGrant.setActivityDate(grantStartDateNode.toString());
|
||||
} else {
|
||||
grantStartDateNode = solution
|
||||
.get(QueryFieldLabels.GRANT_START_DATE);
|
||||
if (grantStartDateNode != null) {
|
||||
coreGrant.setActivityDate(grantStartDateNode.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
currentEntityGrants.add(coreGrant);
|
||||
}
|
||||
return currentEntityGrants;
|
||||
}
|
||||
|
||||
public static Map<String, Activity> getGrantsForAllSubOrganizations(
|
||||
Dataset dataset, Entity organizationEntity)
|
||||
throws MalformedQueryParametersException {
|
||||
Map<String, Activity> allGrantURIToVO = new HashMap<String, Activity>();
|
||||
|
||||
for (SubEntity subOrganization : organizationEntity.getSubEntities()) {
|
||||
|
||||
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);
|
||||
fieldLabelToOutputFieldLabel.put("grantStartDate", QueryFieldLabels.GRANT_START_DATE);
|
||||
fieldLabelToOutputFieldLabel.put("roleStartDate", QueryFieldLabels.ROLE_START_DATE);
|
||||
|
||||
String whereClause = ""
|
||||
+ " <" + subOrganization.getIndividualURI() + "> vivosocnet:hasPersonWithGrant ?grant . "
|
||||
+ " ?grant rdfs:label ?grantLabel . "
|
||||
+ " OPTIONAL { "
|
||||
+ " ?grant vivosocnet:startDateTimeOnGrant ?grantStartDate } . "
|
||||
+ " OPTIONAL { "
|
||||
+ " ?grant vivosocnet:startDateTimeOnRole ?roleStartDate } . ";
|
||||
|
||||
QueryRunner<ResultSet> subOrganizationGrantsQuery =
|
||||
new GenericQueryRunnerOnModel(fieldLabelToOutputFieldLabel,
|
||||
"",
|
||||
whereClause,
|
||||
"",
|
||||
subOrganizationGrantsModel);
|
||||
|
||||
subOrganization.addActivities(getGrantForEntity(
|
||||
subOrganizationGrantsQuery.getQueryResult(),
|
||||
allGrantURIToVO));
|
||||
|
||||
}
|
||||
return allGrantURIToVO;
|
||||
}
|
||||
|
||||
public static Map<String, Activity> getPublicationsForAssociatedPeople(
|
||||
Dataset dataset, Collection<SubEntity> people)
|
||||
throws MalformedQueryParametersException {
|
||||
|
|
Loading…
Add table
Reference in a new issue