1. Refactored some back-end code for temporal graph vis.
2. Made sure that if no uri is provided to grants temporal graph vis, then the one for highest level is selected. 3. Made sure that any entity (person or organization) directly attached to an organization is considered for temporal graph vis. 4. Changed the page title for temporal graph vis to always start with the label of the entity in question.
This commit is contained in:
parent
b440465220
commit
35487d0f30
7 changed files with 301 additions and 200 deletions
|
@ -0,0 +1,91 @@
|
||||||
|
package edu.cornell.mannlib.vitro.webapp.visualization.freemarker.entitycomparison;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
|
||||||
|
import com.hp.hpl.jena.query.DataSource;
|
||||||
|
import com.hp.hpl.jena.query.QuerySolution;
|
||||||
|
import com.hp.hpl.jena.query.ResultSet;
|
||||||
|
import com.hp.hpl.jena.rdf.model.RDFNode;
|
||||||
|
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.visualization.constants.QueryFieldLabels;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.valueobjects.GenericQueryMap;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.GenericQueryRunner;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.QueryRunner;
|
||||||
|
|
||||||
|
public class EntityComparisonUtilityFunctions {
|
||||||
|
|
||||||
|
public static String getHighestLevelOrganizationURI(ResultSet resultSet,
|
||||||
|
Map<String, String> fieldLabelToOutputFieldLabel) {
|
||||||
|
|
||||||
|
GenericQueryMap queryResult = new GenericQueryMap();
|
||||||
|
|
||||||
|
while (resultSet.hasNext()) {
|
||||||
|
QuerySolution solution = resultSet.nextSolution();
|
||||||
|
|
||||||
|
RDFNode organizationNode = solution
|
||||||
|
.get(fieldLabelToOutputFieldLabel.get("organization"));
|
||||||
|
|
||||||
|
if (organizationNode != null) {
|
||||||
|
queryResult.addEntry(
|
||||||
|
fieldLabelToOutputFieldLabel.get("organization"),
|
||||||
|
organizationNode.toString());
|
||||||
|
|
||||||
|
return organizationNode.toString();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
RDFNode organizationLabelNode = solution
|
||||||
|
.get(fieldLabelToOutputFieldLabel.get("organizationLabel"));
|
||||||
|
|
||||||
|
if (organizationLabelNode != null) {
|
||||||
|
queryResult.addEntry(
|
||||||
|
fieldLabelToOutputFieldLabel.get("organizationLabel"),
|
||||||
|
organizationLabelNode.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
RDFNode numberOfChildrenNode = solution.getLiteral("numOfChildren");
|
||||||
|
|
||||||
|
if (numberOfChildrenNode != null) {
|
||||||
|
queryResult.addEntry("numOfChildren", String
|
||||||
|
.valueOf(numberOfChildrenNode.asLiteral().getInt()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getHighestLevelOrganizationURI(Log log, DataSource dataSource)
|
||||||
|
throws MalformedQueryParametersException {
|
||||||
|
|
||||||
|
Map<String, String> fieldLabelToOutputFieldLabel = new HashMap<String, String>();
|
||||||
|
fieldLabelToOutputFieldLabel.put("organization",
|
||||||
|
QueryFieldLabels.ORGANIZATION_URL);
|
||||||
|
fieldLabelToOutputFieldLabel.put("organizationLabel",
|
||||||
|
QueryFieldLabels.ORGANIZATION_LABEL);
|
||||||
|
|
||||||
|
String aggregationRules = "(count(?organization) AS ?numOfChildren)";
|
||||||
|
|
||||||
|
String whereClause = "?organization rdf:type foaf:Organization ; rdfs:label ?organizationLabel . \n"
|
||||||
|
+ "OPTIONAL { ?organization core:hasSubOrganization ?subOrg } . \n"
|
||||||
|
+ "OPTIONAL { ?organization core:subOrganizationWithin ?parent } . \n"
|
||||||
|
+ "FILTER ( !bound(?parent) ). \n";
|
||||||
|
|
||||||
|
String groupOrderClause = "GROUP BY ?organization ?organizationLabel \n"
|
||||||
|
+ "ORDER BY DESC(?numOfChildren)\n" + "LIMIT 1\n";
|
||||||
|
|
||||||
|
QueryRunner<ResultSet> highestLevelOrganizationQueryHandler = new GenericQueryRunner(
|
||||||
|
fieldLabelToOutputFieldLabel, aggregationRules, whereClause,
|
||||||
|
groupOrderClause, dataSource, log);
|
||||||
|
|
||||||
|
String highestLevelOrgURI = EntityComparisonUtilityFunctions
|
||||||
|
.getHighestLevelOrganizationURI(
|
||||||
|
highestLevelOrganizationQueryHandler.getQueryResult(),
|
||||||
|
fieldLabelToOutputFieldLabel);
|
||||||
|
return highestLevelOrgURI;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -87,7 +87,6 @@ public class EntityPublicationCountQueryRunner implements QueryRunner<Entity> {
|
||||||
Map<String, SubEntity> subentityURLToVO = new HashMap<String, SubEntity>();
|
Map<String, SubEntity> subentityURLToVO = new HashMap<String, SubEntity>();
|
||||||
Map<String, SubEntity> personURLToVO = new HashMap<String, SubEntity>();
|
Map<String, SubEntity> personURLToVO = new HashMap<String, SubEntity>();
|
||||||
|
|
||||||
|
|
||||||
while (resultSet.hasNext()) {
|
while (resultSet.hasNext()) {
|
||||||
|
|
||||||
QuerySolution solution = resultSet.nextSolution();
|
QuerySolution solution = resultSet.nextSolution();
|
||||||
|
@ -149,7 +148,7 @@ public class EntityPublicationCountQueryRunner implements QueryRunner<Entity> {
|
||||||
|
|
||||||
entity.addSubEntity(subEntity);
|
entity.addSubEntity(subEntity);
|
||||||
|
|
||||||
subEntity.addPublications(biboDocument);
|
subEntity.addPublication(biboDocument);
|
||||||
}
|
}
|
||||||
|
|
||||||
RDFNode personURLNode = solution.get(QueryFieldLabels.PERSON_URL);
|
RDFNode personURLNode = solution.get(QueryFieldLabels.PERSON_URL);
|
||||||
|
@ -182,11 +181,11 @@ public class EntityPublicationCountQueryRunner implements QueryRunner<Entity> {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
person.addPublications(biboDocument);
|
person.addPublication(biboDocument);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
entity.addPublications(biboDocument);
|
entity.addPublication(biboDocument);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -19,25 +19,19 @@ import com.hp.hpl.jena.iri.IRI;
|
||||||
import com.hp.hpl.jena.iri.IRIFactory;
|
import com.hp.hpl.jena.iri.IRIFactory;
|
||||||
import com.hp.hpl.jena.iri.Violation;
|
import com.hp.hpl.jena.iri.Violation;
|
||||||
import com.hp.hpl.jena.query.DataSource;
|
import com.hp.hpl.jena.query.DataSource;
|
||||||
import com.hp.hpl.jena.query.QuerySolution;
|
|
||||||
import com.hp.hpl.jena.query.ResultSet;
|
|
||||||
import com.hp.hpl.jena.rdf.model.RDFNode;
|
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.ConfigurationProperties;
|
import edu.cornell.mannlib.vitro.webapp.ConfigurationProperties;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.Portal;
|
import edu.cornell.mannlib.vitro.webapp.beans.Portal;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
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.ResponseValues;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.TemplateResponseValues;
|
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.TemplateResponseValues;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.visualization.freemarker.VisualizationFrameworkConstants;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.visualization.freemarker.DataVisualizationController;
|
import edu.cornell.mannlib.vitro.webapp.controller.visualization.freemarker.DataVisualizationController;
|
||||||
import edu.cornell.mannlib.vitro.webapp.visualization.constants.QueryFieldLabels;
|
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.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.valueobjects.Entity;
|
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.valueobjects.Entity;
|
||||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.valueobjects.GenericQueryMap;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.valueobjects.JsonObject;
|
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.valueobjects.SubEntity;
|
||||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.GenericQueryRunner;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.QueryRunner;
|
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.QueryRunner;
|
||||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.UtilityFunctions;
|
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.UtilityFunctions;
|
||||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.VisualizationRequestHandler;
|
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.VisualizationRequestHandler;
|
||||||
|
@ -55,28 +49,10 @@ public class EntityPublicationCountRequestHandler implements
|
||||||
String entityURI = vitroRequest
|
String entityURI = vitroRequest
|
||||||
.getParameter(VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY);
|
.getParameter(VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY);
|
||||||
|
|
||||||
if(StringUtils.isNotBlank(entityURI)){
|
if (StringUtils.isNotBlank(entityURI)){
|
||||||
|
|
||||||
QueryRunner<Entity> queryManager = new EntityPublicationCountQueryRunner(
|
return getSubjectEntityAndGenerateResponse(vitroRequest, log,
|
||||||
entityURI, dataSource, log);
|
dataSource, entityURI);
|
||||||
|
|
||||||
Entity entity = queryManager.getQueryResult();
|
|
||||||
|
|
||||||
if(entity.getEntityLabel().equals("no-label")){
|
|
||||||
|
|
||||||
return prepareStandaloneErrorResponse(vitroRequest,entityURI);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
QueryRunner<Map<String, Set<String>>> queryManagerForsubOrganisationTypes = new EntitySubOrganizationTypesQueryRunner(
|
|
||||||
entityURI, dataSource, log);
|
|
||||||
|
|
||||||
Map<String, Set<String>> subOrganizationTypesResult = queryManagerForsubOrganisationTypes
|
|
||||||
.getQueryResult();
|
|
||||||
|
|
||||||
return prepareStandaloneResponse(vitroRequest, entity, entityURI,
|
|
||||||
subOrganizationTypesResult);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
String staffProvidedHighestLevelOrganization = ConfigurationProperties.getProperty("visualization.topLevelOrg");
|
String staffProvidedHighestLevelOrganization = ConfigurationProperties.getProperty("visualization.topLevelOrg");
|
||||||
|
@ -100,80 +76,59 @@ public class EntityPublicationCountRequestHandler implements
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
QueryRunner<Entity> queryManager = new EntityPublicationCountQueryRunner(
|
return getSubjectEntityAndGenerateResponse(vitroRequest,
|
||||||
staffProvidedHighestLevelOrganization, dataSource, log);
|
log, dataSource,
|
||||||
|
staffProvidedHighestLevelOrganization);
|
||||||
Entity entity = queryManager.getQueryResult();
|
|
||||||
|
|
||||||
if(entity.getEntityLabel().equals("no-label")){
|
|
||||||
|
|
||||||
return prepareStandaloneErrorResponse(vitroRequest,staffProvidedHighestLevelOrganization);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
QueryRunner<Map<String, Set<String>>> queryManagerForsubOrganisationTypes = new EntitySubOrganizationTypesQueryRunner(
|
|
||||||
staffProvidedHighestLevelOrganization, dataSource, log);
|
|
||||||
|
|
||||||
Map<String, Set<String>> subOrganizationTypesResult = queryManagerForsubOrganisationTypes
|
|
||||||
.getQueryResult();
|
|
||||||
|
|
||||||
return prepareStandaloneResponse(vitroRequest, entity, staffProvidedHighestLevelOrganization,
|
|
||||||
subOrganizationTypesResult);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, String> fieldLabelToOutputFieldLabel = new HashMap<String, String>();
|
String highestLevelOrgURI = EntityComparisonUtilityFunctions.getHighestLevelOrganizationURI(log,
|
||||||
fieldLabelToOutputFieldLabel.put("organization",
|
dataSource);
|
||||||
QueryFieldLabels.ORGANIZATION_URL);
|
|
||||||
fieldLabelToOutputFieldLabel.put("organizationLabel", QueryFieldLabels.ORGANIZATION_LABEL);
|
|
||||||
|
|
||||||
String aggregationRules = "(count(?organization) AS ?numOfChildren)";
|
return getSubjectEntityAndGenerateResponse(vitroRequest, log,
|
||||||
|
dataSource, highestLevelOrgURI);
|
||||||
String whereClause = "?organization rdf:type foaf:Organization ; rdfs:label ?organizationLabel . \n"
|
|
||||||
+ "OPTIONAL { ?organization core:hasSubOrganization ?subOrg } . \n"
|
|
||||||
+ "OPTIONAL { ?organization core:subOrganizationWithin ?parent } . \n"
|
|
||||||
+ "FILTER ( !bound(?parent) ). \n";
|
|
||||||
|
|
||||||
String groupOrderClause = "GROUP BY ?organization ?organizationLabel \n"
|
|
||||||
+ "ORDER BY DESC(?numOfChildren)\n"
|
|
||||||
+ "LIMIT 1\n";
|
|
||||||
|
|
||||||
QueryRunner<ResultSet> highestLevelOrganizationQueryHandler =
|
|
||||||
new GenericQueryRunner(fieldLabelToOutputFieldLabel,
|
|
||||||
aggregationRules,
|
|
||||||
whereClause,
|
|
||||||
groupOrderClause,
|
|
||||||
dataSource, log);
|
|
||||||
|
|
||||||
|
|
||||||
String highestLevelOrgURI = getHighestLevelOrganizationURI(
|
|
||||||
highestLevelOrganizationQueryHandler.getQueryResult(),
|
|
||||||
fieldLabelToOutputFieldLabel);
|
|
||||||
|
|
||||||
QueryRunner<Entity> queryManager = new EntityPublicationCountQueryRunner(
|
|
||||||
highestLevelOrgURI, dataSource, log);
|
|
||||||
|
|
||||||
Entity entity = queryManager.getQueryResult();
|
|
||||||
|
|
||||||
if(entity.getEntityLabel().equals("no-label")){
|
|
||||||
|
|
||||||
return prepareStandaloneErrorResponse(vitroRequest,highestLevelOrgURI);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
QueryRunner<Map<String, Set<String>>> queryManagerForsubOrganisationTypes = new EntitySubOrganizationTypesQueryRunner(
|
|
||||||
highestLevelOrgURI, dataSource, log);
|
|
||||||
|
|
||||||
Map<String, Set<String>> subOrganizationTypesResult = queryManagerForsubOrganisationTypes
|
|
||||||
.getQueryResult();
|
|
||||||
|
|
||||||
return prepareStandaloneResponse(vitroRequest, entity, highestLevelOrgURI,
|
|
||||||
subOrganizationTypesResult);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private ResponseValues getSubjectEntityAndGenerateResponse(
|
||||||
|
VitroRequest vitroRequest, Log log, DataSource dataSource,
|
||||||
|
String subjectEntityURI)
|
||||||
|
throws MalformedQueryParametersException {
|
||||||
|
|
||||||
|
QueryRunner<Entity> queryManager = new EntityPublicationCountQueryRunner(
|
||||||
|
subjectEntityURI, dataSource, log);
|
||||||
|
|
||||||
|
Entity entity = queryManager.getQueryResult();
|
||||||
|
|
||||||
|
if (entity.getEntityLabel().equals("no-label")) {
|
||||||
|
|
||||||
|
return prepareStandaloneErrorResponse(vitroRequest, subjectEntityURI);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
return getSubEntityTypesAndRenderStandaloneResponse(
|
||||||
|
vitroRequest, log, dataSource,
|
||||||
|
subjectEntityURI, entity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private ResponseValues getSubEntityTypesAndRenderStandaloneResponse(
|
||||||
|
VitroRequest vitroRequest, Log log, DataSource dataSource,
|
||||||
|
String subjectEntityURI, Entity entity)
|
||||||
|
throws MalformedQueryParametersException {
|
||||||
|
|
||||||
|
QueryRunner<Map<String, Set<String>>> queryManagerForsubOrganisationTypes = new EntitySubOrganizationTypesQueryRunner(
|
||||||
|
subjectEntityURI, dataSource, log);
|
||||||
|
|
||||||
|
Map<String, Set<String>> subOrganizationTypesResult = queryManagerForsubOrganisationTypes
|
||||||
|
.getQueryResult();
|
||||||
|
|
||||||
|
return prepareStandaloneResponse(vitroRequest, entity, subjectEntityURI,
|
||||||
|
subOrganizationTypesResult);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -256,11 +211,15 @@ public class EntityPublicationCountRequestHandler implements
|
||||||
String jsonContent = "";
|
String jsonContent = "";
|
||||||
jsonContent = writePublicationsOverTimeJSON(vreq, entity.getSubEntities(), subOrganizationTypesResult);
|
jsonContent = writePublicationsOverTimeJSON(vreq, entity.getSubEntities(), subOrganizationTypesResult);
|
||||||
|
|
||||||
|
String title = "";
|
||||||
|
|
||||||
|
if (StringUtils.isNotBlank(entity.getEntityLabel())) {
|
||||||
|
title = entity.getEntityLabel() + " - ";
|
||||||
|
}
|
||||||
|
|
||||||
Map<String, Object> body = new HashMap<String, Object>();
|
Map<String, Object> body = new HashMap<String, Object>();
|
||||||
body.put("portalBean", portal);
|
body.put("portalBean", portal);
|
||||||
body.put("title", "Temporal Graph Visualization");
|
body.put("title", title + "Temporal Graph Visualization");
|
||||||
body.put("organizationURI", entityURI);
|
body.put("organizationURI", entityURI);
|
||||||
body.put("organizationLabel", entity.getEntityLabel());
|
body.put("organizationLabel", entity.getEntityLabel());
|
||||||
body.put("jsonContent", jsonContent);
|
body.put("jsonContent", jsonContent);
|
||||||
|
@ -292,7 +251,10 @@ public class EntityPublicationCountRequestHandler implements
|
||||||
* @param subentities
|
* @param subentities
|
||||||
* @param subOrganizationTypesResult
|
* @param subOrganizationTypesResult
|
||||||
*/
|
*/
|
||||||
private String writePublicationsOverTimeJSON(VitroRequest vreq, Set<SubEntity> subentities, Map<String, Set<String>> subOrganizationTypesResult) {
|
private String writePublicationsOverTimeJSON(VitroRequest vreq,
|
||||||
|
Set<SubEntity> subentities,
|
||||||
|
Map<String, Set<String>>
|
||||||
|
subOrganizationTypesResult) {
|
||||||
|
|
||||||
Gson json = new Gson();
|
Gson json = new Gson();
|
||||||
Set<JsonObject> subEntitiesJson = new HashSet<JsonObject>();
|
Set<JsonObject> subEntitiesJson = new HashSet<JsonObject>();
|
||||||
|
@ -368,44 +330,4 @@ public class EntityPublicationCountRequestHandler implements
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getHighestLevelOrganizationURI(ResultSet resultSet,
|
|
||||||
Map<String, String> fieldLabelToOutputFieldLabel) {
|
|
||||||
|
|
||||||
GenericQueryMap queryResult = new GenericQueryMap();
|
|
||||||
|
|
||||||
|
|
||||||
while (resultSet.hasNext()) {
|
|
||||||
QuerySolution solution = resultSet.nextSolution();
|
|
||||||
|
|
||||||
|
|
||||||
RDFNode organizationNode = solution.get(
|
|
||||||
fieldLabelToOutputFieldLabel
|
|
||||||
.get("organization"));
|
|
||||||
|
|
||||||
if (organizationNode != null) {
|
|
||||||
queryResult.addEntry(fieldLabelToOutputFieldLabel.get("organization"), organizationNode.toString());
|
|
||||||
|
|
||||||
return organizationNode.toString();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
RDFNode organizationLabelNode = solution.get(
|
|
||||||
fieldLabelToOutputFieldLabel
|
|
||||||
.get("organizationLabel"));
|
|
||||||
|
|
||||||
if (organizationLabelNode != null) {
|
|
||||||
queryResult.addEntry(fieldLabelToOutputFieldLabel.get("organizationLabel"), organizationLabelNode.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
RDFNode numberOfChildrenNode = solution.getLiteral("numOfChildren");
|
|
||||||
|
|
||||||
if (numberOfChildrenNode != null) {
|
|
||||||
queryResult.addEntry("numOfChildren", String.valueOf(numberOfChildrenNode.asLiteral().getInt()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -7,6 +7,7 @@ import java.util.Map;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
import com.hp.hpl.jena.iri.IRI;
|
import com.hp.hpl.jena.iri.IRI;
|
||||||
import com.hp.hpl.jena.iri.IRIFactory;
|
import com.hp.hpl.jena.iri.IRIFactory;
|
||||||
|
@ -24,8 +25,8 @@ import com.hp.hpl.jena.rdf.model.RDFNode;
|
||||||
import edu.cornell.mannlib.vitro.webapp.visualization.constants.QueryConstants;
|
import edu.cornell.mannlib.vitro.webapp.visualization.constants.QueryConstants;
|
||||||
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.exceptions.MalformedQueryParametersException;
|
import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException;
|
||||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.valueobjects.Grant;
|
|
||||||
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.Grant;
|
||||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.valueobjects.SubEntity;
|
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.valueobjects.SubEntity;
|
||||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.QueryRunner;
|
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.QueryRunner;
|
||||||
|
|
||||||
|
@ -44,7 +45,7 @@ public class EntityGrantCountQueryRunner implements QueryRunner<Entity> {
|
||||||
|
|
||||||
private String entityURI;
|
private String entityURI;
|
||||||
private DataSource dataSource;
|
private DataSource dataSource;
|
||||||
private Log log;
|
private Log log = LogFactory.getLog(EntityGrantCountQueryRunner.class.getName());
|
||||||
|
|
||||||
|
|
||||||
private static final String SPARQL_QUERY_COMMON_SELECT_CLAUSE = "SELECT "
|
private static final String SPARQL_QUERY_COMMON_SELECT_CLAUSE = "SELECT "
|
||||||
|
@ -101,7 +102,6 @@ public class EntityGrantCountQueryRunner implements QueryRunner<Entity> {
|
||||||
|
|
||||||
this.entityURI = entityURI;
|
this.entityURI = entityURI;
|
||||||
this.dataSource = dataSource;
|
this.dataSource = dataSource;
|
||||||
this.log = log;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,24 +138,28 @@ public class EntityGrantCountQueryRunner implements QueryRunner<Entity> {
|
||||||
grant.setGrantLabel(grantLabelNode.toString());
|
grant.setGrantLabel(grantLabelNode.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
RDFNode grantStartDateNode = solution.get(QueryFieldLabels.ROLE_START_DATE);
|
RDFNode grantStartDateNode = solution
|
||||||
if(grantStartDateNode != null){
|
.get(QueryFieldLabels.ROLE_START_DATE);
|
||||||
|
if (grantStartDateNode != null) {
|
||||||
grant.setGrantStartDate(grantStartDateNode.toString());
|
grant.setGrantStartDate(grantStartDateNode.toString());
|
||||||
}else {
|
} else {
|
||||||
grantStartDateNode = solution.get(QueryFieldLabels.GRANT_START_DATE);
|
grantStartDateNode = solution
|
||||||
if(grantStartDateNode != null){
|
.get(QueryFieldLabels.GRANT_START_DATE);
|
||||||
|
if (grantStartDateNode != null) {
|
||||||
grant.setGrantStartDate(grantStartDateNode.toString());
|
grant.setGrantStartDate(grantStartDateNode.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
RDFNode grantEndDateNode = solution.get(QueryFieldLabels.ROLE_END_DATE);
|
RDFNode grantEndDateNode = solution
|
||||||
if(grantEndDateNode != null){
|
.get(QueryFieldLabels.ROLE_END_DATE);
|
||||||
|
if (grantEndDateNode != null) {
|
||||||
grant.setGrantEndDate(grantEndDateNode.toString());
|
grant.setGrantEndDate(grantEndDateNode.toString());
|
||||||
}else {
|
} else {
|
||||||
grantEndDateNode = solution.get(QueryFieldLabels.GRANT_END_DATE);
|
grantEndDateNode = solution
|
||||||
if(grantEndDateNode != null){
|
.get(QueryFieldLabels.GRANT_END_DATE);
|
||||||
|
if (grantEndDateNode != null) {
|
||||||
grant.setGrantEndDate(grantEndDateNode.toString());
|
grant.setGrantEndDate(grantEndDateNode.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -178,39 +182,53 @@ public class EntityGrantCountQueryRunner implements QueryRunner<Entity> {
|
||||||
subEntity.setIndividualLabel(subEntityLabelNode.toString());
|
subEntity.setIndividualLabel(subEntityLabelNode.toString());
|
||||||
}
|
}
|
||||||
entity.addSubEntity(subEntity);
|
entity.addSubEntity(subEntity);
|
||||||
subEntity.addGrants(grant);
|
subEntity.addGrant(grant);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
RDFNode personURLNode = solution.get(QueryFieldLabels.PERSON_URL);
|
RDFNode personURLNode = solution.get(QueryFieldLabels.PERSON_URL);
|
||||||
|
|
||||||
if(personURLNode != null){
|
if (personURLNode != null) {
|
||||||
SubEntity person ;
|
SubEntity person;
|
||||||
if(personURLToVO.containsKey(personURLNode.toString())) {
|
|
||||||
|
if (personURLToVO.containsKey(personURLNode.toString())) {
|
||||||
person = personURLToVO.get(personURLNode.toString());
|
person = personURLToVO.get(personURLNode.toString());
|
||||||
} else {
|
} else {
|
||||||
person = new SubEntity(personURLNode.toString());
|
person = new SubEntity(personURLNode.toString());
|
||||||
personURLToVO.put(personURLNode.toString(), person);
|
personURLToVO.put(personURLNode.toString(), person);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RDFNode personLabelNode = solution
|
||||||
|
.get(QueryFieldLabels.PERSON_LABEL);
|
||||||
|
|
||||||
RDFNode personLabelNode = solution.get(QueryFieldLabels.PERSON_LABEL);
|
|
||||||
if (personLabelNode != null) {
|
if (personLabelNode != null) {
|
||||||
person.setIndividualLabel(personLabelNode.toString());
|
person.setIndividualLabel(personLabelNode.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This makes sure that either,
|
||||||
|
* 1. the parent organization is a department-like organization with no organizations
|
||||||
|
* beneath it, or
|
||||||
|
* 2. the parent organizations has both sub-organizations and people directly
|
||||||
|
* attached to that organizations e.g. president of a university.
|
||||||
|
* */
|
||||||
|
if (subEntityURLNode == null) {
|
||||||
|
|
||||||
|
entity.addSubEntity(person);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// entity.addSubEntity(person);
|
person.addGrant(grant);
|
||||||
person.addGrants(grant);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
entity.addGrants(grant);
|
entity.addGrant(grant);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(subentityURLToVO.size() == 0 && personURLToVO.size() != 0){
|
/*if (subentityURLToVO.size() == 0 && personURLToVO.size() != 0) {
|
||||||
for(SubEntity person : personURLToVO.values()){
|
for (SubEntity person : personURLToVO.values()) {
|
||||||
entity.addSubEntity(person);
|
entity.addSubEntity(person);
|
||||||
}
|
}
|
||||||
} else if (subentityURLToVO.size() == 0 && personURLToVO.size() == 0){
|
} else */if (subentityURLToVO.size() == 0 && personURLToVO.size() == 0) {
|
||||||
entity = new Entity(this.entityURI, "no-label");
|
entity = new Entity(this.entityURI, "no-label");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,21 +14,26 @@ import org.apache.commons.lang.StringUtils;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
|
import com.hp.hpl.jena.iri.IRI;
|
||||||
|
import com.hp.hpl.jena.iri.IRIFactory;
|
||||||
|
import com.hp.hpl.jena.iri.Violation;
|
||||||
import com.hp.hpl.jena.query.DataSource;
|
import com.hp.hpl.jena.query.DataSource;
|
||||||
|
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.ConfigurationProperties;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.Portal;
|
import edu.cornell.mannlib.vitro.webapp.beans.Portal;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
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.ResponseValues;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.TemplateResponseValues;
|
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.TemplateResponseValues;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.visualization.freemarker.VisualizationFrameworkConstants;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.visualization.freemarker.DataVisualizationController;
|
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.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.entitycomparison.EntityComparisonUtilityFunctions;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.entitycomparison.EntitySubOrganizationTypesQueryRunner;
|
||||||
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.JsonObject;
|
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.valueobjects.SubEntity;
|
||||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.QueryRunner;
|
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.QueryRunner;
|
||||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.entitycomparison.EntitySubOrganizationTypesQueryRunner;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.UtilityFunctions;
|
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.UtilityFunctions;
|
||||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.VisualizationRequestHandler;
|
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.VisualizationRequestHandler;
|
||||||
|
|
||||||
|
@ -44,29 +49,50 @@ public class EntityGrantCountRequestHandler implements
|
||||||
String entityURI = vitroRequest
|
String entityURI = vitroRequest
|
||||||
.getParameter(VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY);
|
.getParameter(VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY);
|
||||||
|
|
||||||
QueryRunner<Entity> queryManager = new EntityGrantCountQueryRunner(
|
if (StringUtils.isNotBlank(entityURI)){
|
||||||
entityURI, dataSource, log);
|
|
||||||
|
|
||||||
Entity entity = queryManager.getQueryResult();
|
|
||||||
|
|
||||||
if(entity.getEntityLabel().equals("no-label")){
|
|
||||||
|
|
||||||
return prepareStandaloneErrorResponse(vitroRequest,entityURI);
|
|
||||||
|
|
||||||
} else{
|
|
||||||
|
|
||||||
QueryRunner<Map<String, Set<String>>> queryManagerForsubOrganisationTypes = new EntitySubOrganizationTypesQueryRunner(
|
return getSubjectEntityAndGenerateResponse(vitroRequest, log,
|
||||||
entityURI, dataSource, log);
|
dataSource, entityURI);
|
||||||
|
|
||||||
Map<String, Set<String>> subOrganizationTypesResult = queryManagerForsubOrganisationTypes
|
} else {
|
||||||
.getQueryResult();
|
|
||||||
|
String staffProvidedHighestLevelOrganization = ConfigurationProperties.getProperty("visualization.topLevelOrg");
|
||||||
return prepareStandaloneResponse(vitroRequest, entity, entityURI,
|
|
||||||
subOrganizationTypesResult);
|
/*
|
||||||
|
* First checking if the staff has provided highest level organization in deploy.properties
|
||||||
|
* if so use to temporal graph vis.
|
||||||
|
*/
|
||||||
|
if (StringUtils.isNotBlank(staffProvidedHighestLevelOrganization)) {
|
||||||
|
|
||||||
|
/*
|
||||||
|
* To test for the validity of the URI submitted.
|
||||||
|
*/
|
||||||
|
IRIFactory iRIFactory = IRIFactory.jenaImplementation();
|
||||||
|
IRI iri = iRIFactory.create(staffProvidedHighestLevelOrganization);
|
||||||
|
|
||||||
|
if (iri.hasViolation(false)) {
|
||||||
|
|
||||||
|
String errorMsg = ((Violation) iri.violations(false).next()).getShortMessage();
|
||||||
|
log.error("Highest Level Organization URI provided is invalid " + errorMsg);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
return getSubjectEntityAndGenerateResponse(vitroRequest,
|
||||||
|
log, dataSource,
|
||||||
|
staffProvidedHighestLevelOrganization);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String highestLevelOrgURI = EntityComparisonUtilityFunctions.getHighestLevelOrganizationURI(log,
|
||||||
|
dataSource);
|
||||||
|
|
||||||
|
return getSubjectEntityAndGenerateResponse(vitroRequest, log,
|
||||||
|
dataSource, highestLevelOrgURI);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, String> generateDataVisualization(
|
public Map<String, String> generateDataVisualization(
|
||||||
VitroRequest vitroRequest, Log log, DataSource dataSource)
|
VitroRequest vitroRequest, Log log, DataSource dataSource)
|
||||||
|
@ -96,6 +122,44 @@ public class EntityGrantCountRequestHandler implements
|
||||||
throw new UnsupportedOperationException("Entity Grant Count does not provide Ajax Response.");
|
throw new UnsupportedOperationException("Entity Grant Count does not provide Ajax Response.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ResponseValues getSubjectEntityAndGenerateResponse(
|
||||||
|
VitroRequest vitroRequest, Log log, DataSource dataSource,
|
||||||
|
String subjectEntityURI)
|
||||||
|
throws MalformedQueryParametersException {
|
||||||
|
|
||||||
|
QueryRunner<Entity> queryManager = new EntityGrantCountQueryRunner(
|
||||||
|
subjectEntityURI, dataSource, log);
|
||||||
|
|
||||||
|
Entity entity = queryManager.getQueryResult();
|
||||||
|
|
||||||
|
if (entity.getEntityLabel().equals("no-label")) {
|
||||||
|
|
||||||
|
return prepareStandaloneErrorResponse(vitroRequest, subjectEntityURI);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
return getSubEntityTypesAndRenderStandaloneResponse(
|
||||||
|
vitroRequest, log, dataSource,
|
||||||
|
subjectEntityURI, entity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private ResponseValues getSubEntityTypesAndRenderStandaloneResponse(
|
||||||
|
VitroRequest vitroRequest, Log log, DataSource dataSource,
|
||||||
|
String subjectOrganization, Entity entity)
|
||||||
|
throws MalformedQueryParametersException {
|
||||||
|
|
||||||
|
QueryRunner<Map<String, Set<String>>> queryManagerForsubOrganisationTypes = new EntitySubOrganizationTypesQueryRunner(
|
||||||
|
subjectOrganization, dataSource, log);
|
||||||
|
|
||||||
|
Map<String, Set<String>> subOrganizationTypesResult = queryManagerForsubOrganisationTypes
|
||||||
|
.getQueryResult();
|
||||||
|
|
||||||
|
return prepareStandaloneResponse(vitroRequest, entity, subjectOrganization,
|
||||||
|
subOrganizationTypesResult);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides response when json file containing the grant count over the
|
* Provides response when json file containing the grant count over the
|
||||||
* years is requested.
|
* years is requested.
|
||||||
|
@ -146,11 +210,16 @@ public class EntityGrantCountRequestHandler implements
|
||||||
String jsonContent = "";
|
String jsonContent = "";
|
||||||
jsonContent = writeGrantsOverTimeJSON(vreq, entity.getSubEntities(), subOrganizationTypesResult);
|
jsonContent = writeGrantsOverTimeJSON(vreq, entity.getSubEntities(), subOrganizationTypesResult);
|
||||||
|
|
||||||
|
String title = "";
|
||||||
|
|
||||||
|
if (StringUtils.isNotBlank(entity.getEntityLabel())) {
|
||||||
|
title = entity.getEntityLabel() + " - ";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Map<String, Object> body = new HashMap<String, Object>();
|
Map<String, Object> body = new HashMap<String, Object>();
|
||||||
body.put("portalBean", portal);
|
body.put("portalBean", portal);
|
||||||
body.put("title", "Temporal Graph Visualization");
|
body.put("title", title + "Temporal Graph Visualization");
|
||||||
body.put("organizationURI", entityURI);
|
body.put("organizationURI", entityURI);
|
||||||
body.put("organizationLabel", entity.getEntityLabel());
|
body.put("organizationLabel", entity.getEntityLabel());
|
||||||
body.put("jsonContent", jsonContent);
|
body.put("jsonContent", jsonContent);
|
||||||
|
@ -197,10 +266,12 @@ public class EntityGrantCountRequestHandler implements
|
||||||
|
|
||||||
List<Integer> currentGrantYear = new ArrayList<Integer>();
|
List<Integer> currentGrantYear = new ArrayList<Integer>();
|
||||||
if (grantEntry.getKey().equals(
|
if (grantEntry.getKey().equals(
|
||||||
VOConstants.DEFAULT_GRANT_YEAR))
|
VOConstants.DEFAULT_GRANT_YEAR)) {
|
||||||
currentGrantYear.add(-1);
|
currentGrantYear.add(-1);
|
||||||
else
|
} else {
|
||||||
currentGrantYear.add(Integer.parseInt(grantEntry.getKey()));
|
currentGrantYear.add(Integer.parseInt(grantEntry.getKey()));
|
||||||
|
}
|
||||||
|
|
||||||
currentGrantYear.add(grantEntry.getValue());
|
currentGrantYear.add(grantEntry.getValue());
|
||||||
yearGrantCount.add(currentGrantYear);
|
yearGrantCount.add(currentGrantYear);
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,7 @@ public class Entity extends Individual{
|
||||||
return children;
|
return children;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addPublications(BiboDocument biboDocument) {
|
public void addPublication(BiboDocument biboDocument) {
|
||||||
this.publications.add(biboDocument);
|
this.publications.add(biboDocument);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ public class Entity extends Individual{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addGrants(Grant grant) {
|
public void addGrant(Grant grant) {
|
||||||
this.grants.add(grant);
|
this.grants.add(grant);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -63,12 +63,12 @@ public class SubEntity extends Individual {
|
||||||
return this.getIndividualLabel();
|
return this.getIndividualLabel();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addPublications(BiboDocument biboDocument) {
|
public void addPublication(BiboDocument biboDocument) {
|
||||||
this.publications.add(biboDocument);
|
this.publications.add(biboDocument);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void addGrants(Grant grant) {
|
public void addGrant(Grant grant) {
|
||||||
this.grants.add(grant);
|
this.grants.add(grant);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue