1. Removing dead code belonging to uncached version for temporal graphs.
This commit is contained in:
parent
207f26081c
commit
d1f8bdc7c1
12 changed files with 4 additions and 2384 deletions
|
@ -28,17 +28,11 @@
|
|||
<bean id="coprincipalinvestigator"
|
||||
class="edu.cornell.mannlib.vitro.webapp.visualization.coprincipalinvestigator.CoPIGrantCountRequestHandler" />
|
||||
|
||||
<bean id="entity_comparison"
|
||||
class="edu.cornell.mannlib.vitro.webapp.visualization.entitycomparison.EntityPublicationCountRequestHandler" />
|
||||
|
||||
<bean id="pub_temporal"
|
||||
class="edu.cornell.mannlib.vitro.webapp.visualization.entitycomparison.cached.TemporalPublicationVisualizationRequestHandler" />
|
||||
|
||||
<bean id="entity_grant_count"
|
||||
class="edu.cornell.mannlib.vitro.webapp.visualization.entitygrantcount.EntityGrantCountRequestHandler" />
|
||||
class="edu.cornell.mannlib.vitro.webapp.visualization.entitycomparison.TemporalPublicationVisualizationRequestHandler" />
|
||||
|
||||
<bean id="grant_temporal"
|
||||
class="edu.cornell.mannlib.vitro.webapp.visualization.entitycomparison.cached.TemporalGrantVisualizationRequestHandler" />
|
||||
class="edu.cornell.mannlib.vitro.webapp.visualization.entitycomparison.TemporalGrantVisualizationRequestHandler" />
|
||||
|
||||
<bean id="map_of_science"
|
||||
class="edu.cornell.mannlib.vitro.webapp.visualization.mapofscience.MapOfScienceVisualizationRequestHandler" />
|
||||
|
|
|
@ -1,275 +0,0 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
package edu.cornell.mannlib.vitro.webapp.visualization.entitycomparison;
|
||||
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
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.IRIFactory;
|
||||
import com.hp.hpl.jena.iri.Violation;
|
||||
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.visutils.ModelConstructor;
|
||||
|
||||
public class EntityPublicationCountConstructQueryRunner implements ModelConstructor {
|
||||
|
||||
protected static final Syntax SYNTAX = Syntax.syntaxARQ;
|
||||
|
||||
private String egoURI;
|
||||
|
||||
private Dataset dataset;
|
||||
|
||||
private Log log = LogFactory.getLog(EntityPublicationCountConstructQueryRunner.class.getName());
|
||||
|
||||
private long before, after;
|
||||
|
||||
public EntityPublicationCountConstructQueryRunner(String egoURI, Dataset dataset, Log log) {
|
||||
this.egoURI = egoURI;
|
||||
this.dataset = dataset;
|
||||
//this.log = log;
|
||||
}
|
||||
|
||||
private String generateConstructQueryForOrganizationLabel(String queryURI) {
|
||||
|
||||
String sparqlQuery =
|
||||
"CONSTRUCT { "
|
||||
+ "<" + queryURI + "> rdfs:label ?organizationLabel ."
|
||||
+ "}"
|
||||
+ "WHERE {"
|
||||
+ "<" + queryURI + "> rdfs:label ?organizationLabel "
|
||||
+ "}";
|
||||
|
||||
return sparqlQuery;
|
||||
}
|
||||
|
||||
private String generateConstructQueryForSubOrganizations(String queryURI) {
|
||||
|
||||
String sparqlQuery =
|
||||
|
||||
"CONSTRUCT { "
|
||||
+ "<" + queryURI + "> core:hasSubOrganization ?subOrganization . "
|
||||
+ "?subOrganization rdfs:label ?subOrganizationLabel . "
|
||||
+ "?subOrganization core:organizationForPosition ?Position . "
|
||||
+ "?Position core:positionForPerson ?Person . "
|
||||
+ "?Person core:authorInAuthorship ?Resource . "
|
||||
+ "?Person rdfs:label ?PersonLabel . "
|
||||
+ "?Resource core:linkedInformationResource ?Document . "
|
||||
+ "?Document rdf:type bibo:Document . "
|
||||
+ "?Document rdfs:label ?DocumentLabel . "
|
||||
+ "?Document core:dateTimeValue ?dateTimeValue . "
|
||||
+ "?dateTimeValue core:dateTime ?publicationDate . "
|
||||
+ "}"
|
||||
+ "WHERE { "
|
||||
+ "{"
|
||||
+ "<" + queryURI + "> core:hasSubOrganization ?subOrganization . "
|
||||
+ "?subOrganization rdfs:label ?subOrganizationLabel . "
|
||||
+ "?subOrganization core:organizationForPosition ?Position . "
|
||||
+ "?Position core:positionForPerson ?Person . "
|
||||
+ "?Person core:authorInAuthorship ?Resource . "
|
||||
+ "?Person rdfs:label ?PersonLabel . "
|
||||
+ "?Resource core:linkedInformationResource ?Document . "
|
||||
+ "?Document rdfs:label ?DocumentLabel "
|
||||
+ "}"
|
||||
+ "UNION "
|
||||
+ "{"
|
||||
+ "?Document core:dateTimeValue ?dateTimeValue . "
|
||||
+ "?dateTimeValue core:dateTime ?publicationDate "
|
||||
+ "}"
|
||||
+ "}";
|
||||
|
||||
return sparqlQuery;
|
||||
}
|
||||
|
||||
private String generateConstructQueryForPersons(String queryURI) {
|
||||
|
||||
String sparqlQuery =
|
||||
|
||||
"CONSTRUCT { "
|
||||
+ "<" + queryURI + "> core:organizationForPosition ?Position . "
|
||||
+ "?Position core:positionForPerson ?Person . "
|
||||
+ "?Person core:authorInAuthorship ?Resource . "
|
||||
+ "?Person rdfs:label ?PersonLabel . "
|
||||
+ "?Resource core:linkedInformationResource ?Document . "
|
||||
+ "?Document rdf:type bibo:Document . "
|
||||
+ "?Document rdfs:label ?DocumentLabel . "
|
||||
+ "?Document core:dateTimeValue ?dateTimeValue . "
|
||||
+ "?dateTimeValue core:dateTime ?publicationDate . "
|
||||
+ "}"
|
||||
+ "WHERE { "
|
||||
+ "{"
|
||||
+ "<" + queryURI + "> core:organizationForPosition ?Position . "
|
||||
+ "?Position core:positionForPerson ?Person . "
|
||||
+ "?Person core:authorInAuthorship ?Resource . "
|
||||
+ "?Person rdfs:label ?PersonLabel . "
|
||||
+ "?Resource core:linkedInformationResource ?Document . "
|
||||
+ "?Document rdfs:label ?DocumentLabel "
|
||||
+ "}"
|
||||
+ "UNION"
|
||||
+ "{"
|
||||
+ "?Document core:dateTimeValue ?dateTimeValue . "
|
||||
+ "?dateTimeValue core:dateTime ?publicationDate "
|
||||
+ "}"
|
||||
+ "}";
|
||||
|
||||
return sparqlQuery;
|
||||
}
|
||||
|
||||
// private String generateConstructQueryForDocumentDateTimeValueOneLevelDeep(String queryURI){
|
||||
//
|
||||
// String sparqlQuery =
|
||||
//
|
||||
// "CONSTRUCT { "
|
||||
// + "<"+queryURI+ "> core:hasSubOrganization ?subOrganization . "
|
||||
// + "?subOrganization core:organizationForPosition ?Position . "
|
||||
// + "?Position core:positionForPerson ?Person . "
|
||||
// + "?Person core:authorInAuthorship ?Resource . "
|
||||
// + "?Resource core:linkedInformationResource ?Document . "
|
||||
// + "?Document rdf:type bibo:Document . "
|
||||
// + "?Document core:dateTimeValue ?dateTimeValue . "
|
||||
// + "?dateTimeValue core:dateTime ?publicationDate . "
|
||||
// + "?Document core:year ?publicationYearUsing_1_1_property "
|
||||
// +"}"
|
||||
// + "WHERE { "
|
||||
// + "<"+queryURI+ "> core:hasSubOrganization ?subOrganization . "
|
||||
// + "?subOrganization core:organizationForPosition ?Position . "
|
||||
// + "?Position core:positionForPerson ?Person . "
|
||||
// + "?Person core:authorInAuthorship ?Resource . "
|
||||
// + "?Resource core:linkedInformationResource ?Document . "
|
||||
// + "?Document rdf:type bibo:Document . "
|
||||
// + "{"
|
||||
// + "?Document core:dateTimeValue ?dateTimeValue . "
|
||||
// + "?dateTimeValue core:dateTime ?publicationDate "
|
||||
// + "}"
|
||||
// + "UNION "
|
||||
// + "{"
|
||||
// + "?Document core:year ?publicationYearUsing_1_1_property "
|
||||
// + "}"
|
||||
// + "}" ;
|
||||
//
|
||||
//
|
||||
// return sparqlQuery;
|
||||
//
|
||||
// }
|
||||
|
||||
// private String generateConstructQueryForDocumentDateTimeValue(String queryURI){
|
||||
//
|
||||
// String sparqlQuery =
|
||||
//
|
||||
// "CONSTRUCT { "
|
||||
// + "<"+queryURI+ "> core:organizationForPosition ?Position . "
|
||||
// + "?Position core:positionForPerson ?Person . "
|
||||
// + "?Person core:authorInAuthorship ?Resource . "
|
||||
// + "?Resource core:linkedInformationResource ?Document . "
|
||||
// + "?Document rdf:type bibo:Document . "
|
||||
// + "?Document core:dateTimeValue ?dateTimeValue . "
|
||||
// + "?dateTimeValue core:dateTime ?publicationDate . "
|
||||
// + "?Document core:year ?publicationYearUsing_1_1_property "
|
||||
// +"}"
|
||||
// + "WHERE { "
|
||||
// + "<"+queryURI+ "> core:organizationForPosition ?Position . "
|
||||
// + "?Position core:positionForPerson ?Person . "
|
||||
// + "?Person core:authorInAuthorship ?Resource . "
|
||||
// + "?Resource core:linkedInformationResource ?Document . "
|
||||
// + "?Document rdf:type bibo:Document . "
|
||||
// + "{"
|
||||
// + "?Document core:dateTimeValue ?dateTimeValue . "
|
||||
// + "?dateTimeValue core:dateTime ?publicationDate "
|
||||
// + "}"
|
||||
// + "UNION "
|
||||
// + "{"
|
||||
// + "?Document core:year ?publicationYearUsing_1_1_property "
|
||||
// + "}"
|
||||
// + "}" ;
|
||||
//
|
||||
//
|
||||
// return sparqlQuery;
|
||||
//
|
||||
// }
|
||||
|
||||
private Model executeQuery(Set<String> constructQueries, Dataset dataset) {
|
||||
|
||||
Model constructedModel = ModelFactory.createDefaultModel();
|
||||
|
||||
for (String queryString : constructQueries) {
|
||||
before = System.currentTimeMillis();
|
||||
log.debug("CONSTRUCT query string : " + queryString);
|
||||
|
||||
Query query = null;
|
||||
|
||||
try {
|
||||
query = QueryFactory.create(QueryConstants.getSparqlPrefixQuery()
|
||||
+ queryString, SYNTAX);
|
||||
} catch (Throwable th) {
|
||||
log.error("Could not create CONSTRUCT SPARQL query for query "
|
||||
+ "string. " + th.getMessage());
|
||||
log.error(queryString);
|
||||
}
|
||||
|
||||
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 {
|
||||
|
||||
if (StringUtils.isNotBlank(this.egoURI)) {
|
||||
/*
|
||||
* To test for the validity of the URI submitted.
|
||||
* */
|
||||
IRIFactory iRIFactory = IRIFactory.jenaImplementation();
|
||||
IRI iri = iRIFactory.create(this.egoURI);
|
||||
if (iri.hasViolation(false)) {
|
||||
String errorMsg = ((Violation) iri.violations(false).next()).getShortMessage();
|
||||
log.error("Entity Pub Count Construct Query " + errorMsg);
|
||||
throw new MalformedQueryParametersException(
|
||||
"URI provided for an individual is malformed.");
|
||||
}
|
||||
} else {
|
||||
throw new MalformedQueryParametersException("URI parameter is either null or empty.");
|
||||
}
|
||||
|
||||
Set<String> constructQueries = new LinkedHashSet<String>();
|
||||
|
||||
populateConstructQueries(constructQueries);
|
||||
|
||||
Model model = executeQuery(constructQueries,
|
||||
this.dataset);
|
||||
|
||||
return model;
|
||||
|
||||
}
|
||||
|
||||
private void populateConstructQueries(Set<String> constructQueries) {
|
||||
|
||||
constructQueries.add(generateConstructQueryForOrganizationLabel(this.egoURI));
|
||||
constructQueries.add(generateConstructQueryForSubOrganizations(this.egoURI));
|
||||
constructQueries.add(generateConstructQueryForPersons(this.egoURI));
|
||||
// constructQueries.add(generateConstructQueryForDocumentDateTimeValueOneLevelDeep(this.egoURI));
|
||||
// constructQueries.add(generateConstructQueryForDocumentDateTimeValue(this.egoURI));
|
||||
}
|
||||
}
|
|
@ -1,263 +0,0 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.visualization.entitycomparison;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
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.IRIFactory;
|
||||
import com.hp.hpl.jena.iri.Violation;
|
||||
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.QuerySolution;
|
||||
import com.hp.hpl.jena.query.ResultSet;
|
||||
import com.hp.hpl.jena.query.Syntax;
|
||||
import com.hp.hpl.jena.rdf.model.RDFNode;
|
||||
import com.hp.hpl.jena.rdf.model.Model;
|
||||
|
||||
|
||||
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.exceptions.MalformedQueryParametersException;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.Activity;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.Entity;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.SubEntity;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.visutils.QueryRunner;
|
||||
|
||||
|
||||
/**
|
||||
* This query runner is used to execute a sparql query that will fetch all the
|
||||
* publications defined by bibo:Document property for a particular
|
||||
* department/school/university.
|
||||
*
|
||||
* Deepak Konidena.
|
||||
* @author bkoniden
|
||||
*/
|
||||
public class EntityPublicationCountQueryRunner implements QueryRunner<Entity> {
|
||||
|
||||
protected static final Syntax SYNTAX = Syntax.syntaxARQ;
|
||||
|
||||
private String entityURI;
|
||||
private Model dataSource;
|
||||
private Log log = LogFactory.getLog(EntityPublicationCountQueryRunner.class.getName());
|
||||
private long before, after;
|
||||
|
||||
private static final String SPARQL_QUERY_COMMON_SELECT_CLAUSE = ""
|
||||
+ " (str(?Person) as ?personLit) "
|
||||
+ " (str(?PersonLabel) as ?personLabelLit) "
|
||||
+ " (str(?Document) as ?documentLit) "
|
||||
+ " (str(?DocumentLabel) as ?documentLabelLit) "
|
||||
+ " (str(?publicationDate) as ?" + QueryFieldLabels.DOCUMENT_PUBLICATION_DATE + ")";
|
||||
|
||||
|
||||
private static final String SPARQL_QUERY_COMMON_WHERE_CLAUSE = ""
|
||||
+ "?Document rdf:type bibo:Document ;"
|
||||
+ " rdfs:label ?DocumentLabel ."
|
||||
+ "OPTIONAL { ?Document core:dateTimeValue ?dateTimeValue . "
|
||||
+ " ?dateTimeValue core:dateTime ?publicationDate } ."
|
||||
+ "OPTIONAL { ?Document core:year ?publicationYearUsing_1_1_property } .";
|
||||
|
||||
private static final String ENTITY_LABEL = QueryFieldLabels.ORGANIZATION_LABEL;
|
||||
private static final String ENTITY_URL = QueryFieldLabels.ORGANIZATION_URL;
|
||||
private static final String SUBENTITY_LABEL = QueryFieldLabels.SUBORGANIZATION_LABEL;
|
||||
private static final String SUBENTITY_URL = QueryFieldLabels.SUBORGANIZATION_URL;
|
||||
|
||||
public EntityPublicationCountQueryRunner(String entityURI,
|
||||
Model dataSource, Log log) {
|
||||
|
||||
this.entityURI = entityURI;
|
||||
this.dataSource = dataSource;
|
||||
// this.log = log;
|
||||
|
||||
}
|
||||
|
||||
private Entity createJavaValueObjects(ResultSet resultSet) {
|
||||
|
||||
Entity entity = null;
|
||||
Map<String, Activity> biboDocumentURLToVO = new HashMap<String, Activity>();
|
||||
Map<String, SubEntity> subentityURLToVO = new HashMap<String, SubEntity>();
|
||||
Map<String, SubEntity> personURLToVO = new HashMap<String, SubEntity>();
|
||||
|
||||
before = System.currentTimeMillis();
|
||||
|
||||
while (resultSet.hasNext()) {
|
||||
|
||||
QuerySolution solution = resultSet.nextSolution();
|
||||
|
||||
if (entity == null) {
|
||||
entity = new Entity(solution.get(ENTITY_URL).toString(),
|
||||
solution.get(ENTITY_LABEL).toString());
|
||||
}
|
||||
|
||||
RDFNode documentNode = solution.get(QueryFieldLabels.DOCUMENT_URL);
|
||||
Activity biboDocument;
|
||||
|
||||
if (biboDocumentURLToVO.containsKey(documentNode.toString())) {
|
||||
biboDocument = biboDocumentURLToVO.get(documentNode.toString());
|
||||
|
||||
} else {
|
||||
|
||||
biboDocument = new Activity(documentNode.toString());
|
||||
biboDocumentURLToVO.put(documentNode.toString(), biboDocument);
|
||||
|
||||
RDFNode publicationDateNode = solution.get(QueryFieldLabels
|
||||
.DOCUMENT_PUBLICATION_DATE);
|
||||
if (publicationDateNode != null) {
|
||||
biboDocument.setActivityDate(publicationDateNode.toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
RDFNode subEntityURLNode = solution.get(SUBENTITY_URL);
|
||||
|
||||
if (subEntityURLNode != null) {
|
||||
SubEntity subEntity;
|
||||
if (subentityURLToVO.containsKey(subEntityURLNode.toString())) {
|
||||
subEntity = subentityURLToVO.get(subEntityURLNode
|
||||
.toString());
|
||||
} else {
|
||||
subEntity = new SubEntity(subEntityURLNode.toString());
|
||||
subentityURLToVO
|
||||
.put(subEntityURLNode.toString(), subEntity);
|
||||
}
|
||||
|
||||
RDFNode subEntityLabelNode = solution.get(SUBENTITY_LABEL);
|
||||
if (subEntityLabelNode != null) {
|
||||
subEntity.setIndividualLabel(subEntityLabelNode.toString());
|
||||
}
|
||||
|
||||
entity.addSubEntity(subEntity);
|
||||
|
||||
subEntity.addActivity(biboDocument);
|
||||
}
|
||||
|
||||
RDFNode personURLNode = solution.get(QueryFieldLabels.PERSON_URL);
|
||||
|
||||
if (personURLNode != null) {
|
||||
SubEntity person;
|
||||
|
||||
if (personURLToVO.containsKey(personURLNode.toString())) {
|
||||
person = personURLToVO.get(personURLNode.toString());
|
||||
} else {
|
||||
person = new SubEntity(personURLNode.toString());
|
||||
personURLToVO.put(personURLNode.toString(), person);
|
||||
}
|
||||
|
||||
RDFNode personLabelNode = solution.get(QueryFieldLabels.PERSON_LABEL);
|
||||
if (personLabelNode != null) {
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
person.addActivity(biboDocument);
|
||||
|
||||
}
|
||||
|
||||
// entity.addActivity(biboDocument);
|
||||
}
|
||||
|
||||
if (subentityURLToVO.size() == 0 && personURLToVO.size() == 0) {
|
||||
|
||||
entity = new Entity(this.entityURI, "no-label");
|
||||
|
||||
}
|
||||
|
||||
after = System.currentTimeMillis();
|
||||
log.debug("Time taken to iterate through the ResultSet of SELECT queries is in ms: "
|
||||
+ (after - before));
|
||||
|
||||
return entity;
|
||||
}
|
||||
|
||||
private ResultSet executeQuery(String queryURI, Model dataSource) {
|
||||
|
||||
QueryExecution queryExecution = null;
|
||||
Query query = QueryFactory.create(
|
||||
getSparqlQueryForOrganization(queryURI), SYNTAX);
|
||||
queryExecution = QueryExecutionFactory.create(query, dataSource);
|
||||
return queryExecution.execSelect();
|
||||
}
|
||||
|
||||
private String getSparqlQueryForOrganization(String queryURI) {
|
||||
|
||||
String sparqlQuery = QueryConstants.getSparqlPrefixQuery()
|
||||
+ "SELECT (str(?organizationLabel) as ?organizationLabelLit) "
|
||||
+ " (str(?subOrganization) as ?subOrganizationLit) "
|
||||
+ " (str(?subOrganizationLabel) as ?subOrganizationLabelLit) "
|
||||
+ SPARQL_QUERY_COMMON_SELECT_CLAUSE + " (str(<" + queryURI
|
||||
+ ">) as ?" + ENTITY_URL + ") "
|
||||
+ "WHERE { " + "<" + queryURI + "> rdfs:label ?organizationLabel ."
|
||||
+ "{ "
|
||||
+ "<" + queryURI + "> core:hasSubOrganization ?subOrganization ."
|
||||
+ "?subOrganization rdfs:label ?subOrganizationLabel ;"
|
||||
+ " core:organizationForPosition ?Position . "
|
||||
+ " ?Position core:positionForPerson ?Person ."
|
||||
+ " ?Person core:authorInAuthorship ?Resource ; rdfs:label ?PersonLabel . "
|
||||
+ " ?Resource core:linkedInformationResource ?Document . "
|
||||
+ SPARQL_QUERY_COMMON_WHERE_CLAUSE + "}"
|
||||
+ "UNION "
|
||||
+ "{ "
|
||||
+ "<" + queryURI + "> core:organizationForPosition ?Position ."
|
||||
+ " ?Position core:positionForPerson ?Person ."
|
||||
+ " ?Person core:authorInAuthorship ?Resource ; rdfs:label ?PersonLabel . "
|
||||
+ " ?Resource core:linkedInformationResource ?Document ."
|
||||
+ SPARQL_QUERY_COMMON_WHERE_CLAUSE + "}"
|
||||
+ "}";
|
||||
|
||||
log.debug("\nThe sparql query is :\n" + sparqlQuery);
|
||||
return sparqlQuery;
|
||||
|
||||
}
|
||||
|
||||
public Entity getQueryResult() throws MalformedQueryParametersException {
|
||||
|
||||
if (StringUtils.isNotBlank(this.entityURI)) {
|
||||
/*
|
||||
* To test for the validity of the URI submitted.
|
||||
*/
|
||||
IRIFactory iRIFactory = IRIFactory.jenaImplementation();
|
||||
IRI iri = iRIFactory.create(this.entityURI);
|
||||
if (iri.hasViolation(false)) {
|
||||
String errorMsg = ((Violation) iri.violations(false).next())
|
||||
.getShortMessage();
|
||||
log.error("Entity Pub Count Query " + errorMsg);
|
||||
throw new MalformedQueryParametersException(
|
||||
"URI provided for an entity is malformed.");
|
||||
}
|
||||
|
||||
} else {
|
||||
throw new MalformedQueryParametersException(
|
||||
"URL parameter is either null or empty.");
|
||||
}
|
||||
|
||||
before = System.currentTimeMillis();
|
||||
|
||||
ResultSet resultSet = executeQuery(this.entityURI, this.dataSource);
|
||||
|
||||
after = System.currentTimeMillis();
|
||||
|
||||
log.debug("Time taken to execute the SELECT queries is in milliseconds: "
|
||||
+ (after - before));
|
||||
|
||||
return createJavaValueObjects(resultSet);
|
||||
}
|
||||
}
|
|
@ -1,362 +0,0 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.visualization.entitycomparison;
|
||||
|
||||
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.auth.requestedAction.Actions;
|
||||
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.DataVisualizationController;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.visualization.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.valueobjects.Entity;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.SubEntity;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.json.JsonObject;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.visutils.ModelConstructor;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.visutils.QueryRunner;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.visutils.UtilityFunctions;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.visutils.VisualizationRequestHandler;
|
||||
|
||||
public class EntityPublicationCountRequestHandler implements
|
||||
VisualizationRequestHandler {
|
||||
|
||||
@Override
|
||||
public ResponseValues generateStandardVisualization(
|
||||
VitroRequest vitroRequest, Log log, Dataset dataset)
|
||||
throws MalformedQueryParametersException {
|
||||
|
||||
String entityURI = vitroRequest
|
||||
.getParameter(VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY);
|
||||
|
||||
return generateStandardVisualizationForPublicationTemporalVis(
|
||||
vitroRequest, log, dataset, entityURI);
|
||||
}
|
||||
|
||||
private ResponseValues generateStandardVisualizationForPublicationTemporalVis(
|
||||
VitroRequest vitroRequest, Log log, Dataset dataset,
|
||||
String entityURI) throws MalformedQueryParametersException {
|
||||
|
||||
if (StringUtils.isBlank(entityURI)) {
|
||||
|
||||
entityURI = OrganizationUtilityFunctions
|
||||
.getStaffProvidedOrComputedHighestLevelOrganization(log,
|
||||
dataset, vitroRequest);
|
||||
|
||||
}
|
||||
|
||||
return prepareStandaloneMarkupResponse(vitroRequest, entityURI);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseValues generateVisualizationForShortURLRequests(
|
||||
Map<String, String> parameters, VitroRequest vitroRequest, Log log,
|
||||
Dataset dataSource) throws MalformedQueryParametersException {
|
||||
|
||||
return generateStandardVisualizationForPublicationTemporalVis(
|
||||
vitroRequest,
|
||||
log,
|
||||
dataSource,
|
||||
parameters
|
||||
.get(VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY));
|
||||
|
||||
}
|
||||
|
||||
private Map<String, String> getSubjectEntityAndGenerateDataResponse(
|
||||
VitroRequest vitroRequest, Log log, Dataset dataset,
|
||||
String subjectEntityURI) throws MalformedQueryParametersException {
|
||||
|
||||
ModelConstructor constructQueryRunner = new EntityPublicationCountConstructQueryRunner(
|
||||
subjectEntityURI, dataset, log);
|
||||
|
||||
Model constructedModel = constructQueryRunner.getConstructedModel();
|
||||
|
||||
QueryRunner<Entity> queryManager = new EntityPublicationCountQueryRunner(
|
||||
subjectEntityURI, constructedModel, log);
|
||||
|
||||
Entity entity = queryManager.getQueryResult();
|
||||
|
||||
if (entity.getEntityLabel().equals("no-label")) {
|
||||
|
||||
return prepareStandaloneDataErrorResponse(vitroRequest,
|
||||
subjectEntityURI);
|
||||
|
||||
} else {
|
||||
|
||||
return getSubEntityTypesAndComputeDataResponse(vitroRequest, log,
|
||||
dataset, subjectEntityURI, entity);
|
||||
}
|
||||
}
|
||||
|
||||
private Map<String, String> prepareStandaloneDataErrorResponse(
|
||||
VitroRequest vitroRequest, String subjectEntityURI) {
|
||||
|
||||
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 Publications for this Organization found in VIVO.\"}");
|
||||
return fileData;
|
||||
}
|
||||
|
||||
private Map<String, String> getSubEntityTypesAndComputeDataResponse(
|
||||
VitroRequest vitroRequest, Log log, Dataset dataset,
|
||||
String subjectEntityURI, Entity entity)
|
||||
throws MalformedQueryParametersException {
|
||||
|
||||
Map<String, Set<String>> subOrganizationTypesResult = OrganizationUtilityFunctions
|
||||
.getSubEntityTypes(log, dataset, subjectEntityURI);
|
||||
|
||||
return prepareStandaloneDataResponse(vitroRequest, entity, entity
|
||||
.getSubEntities(), subOrganizationTypesResult);
|
||||
}
|
||||
|
||||
@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
|
||||
* tmeporal vis.
|
||||
*/
|
||||
if (VisualizationFrameworkConstants.JSON_OUTPUT_FORMAT
|
||||
.equalsIgnoreCase(vitroRequest
|
||||
.getParameter(VisualizationFrameworkConstants.VIS_MODE_KEY))) {
|
||||
|
||||
if (StringUtils.isNotBlank(entityURI)) {
|
||||
|
||||
return getSubjectEntityAndGenerateDataResponse(vitroRequest,
|
||||
log, dataset, entityURI);
|
||||
} else {
|
||||
|
||||
return getSubjectEntityAndGenerateDataResponse(
|
||||
vitroRequest,
|
||||
log,
|
||||
dataset,
|
||||
OrganizationUtilityFunctions
|
||||
.getStaffProvidedOrComputedHighestLevelOrganization(
|
||||
log, dataset, vitroRequest));
|
||||
}
|
||||
|
||||
} else {
|
||||
/*
|
||||
* This provides csv download files for the content in the tables.
|
||||
*/
|
||||
|
||||
ModelConstructor constructQueryRunner = new EntityPublicationCountConstructQueryRunner(
|
||||
entityURI, dataset, log);
|
||||
|
||||
Model constructedModel = constructQueryRunner.getConstructedModel();
|
||||
|
||||
QueryRunner<Entity> queryManager = new EntityPublicationCountQueryRunner(
|
||||
entityURI, constructedModel, log);
|
||||
|
||||
Entity entity = queryManager.getQueryResult();
|
||||
|
||||
Map<String, Set<String>> subOrganizationTypesResult = OrganizationUtilityFunctions
|
||||
.getSubEntityTypes(log, dataset, entityURI);
|
||||
|
||||
return prepareDataResponse(entity, entity.getSubEntities(),
|
||||
subOrganizationTypesResult);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object generateAjaxVisualization(VitroRequest vitroRequest, Log log,
|
||||
Dataset dataset) throws MalformedQueryParametersException {
|
||||
throw new UnsupportedOperationException(
|
||||
"Entity Pub Count does not provide Ajax Response.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides response when json file containing the publication count over
|
||||
* the years is requested.
|
||||
*
|
||||
* @param entity
|
||||
* @param subentities
|
||||
* @param subOrganizationTypesResult
|
||||
*/
|
||||
private Map<String, String> prepareDataResponse(Entity entity,
|
||||
Set<SubEntity> subentities,
|
||||
Map<String, Set<String>> subOrganizationTypesResult) {
|
||||
|
||||
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)
|
||||
+ "_publications-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,
|
||||
getEntityPublicationsPerYearCSVContent(subentities,
|
||||
subOrganizationTypesResult));
|
||||
return fileData;
|
||||
}
|
||||
|
||||
private Map<String, String> prepareStandaloneDataResponse(
|
||||
VitroRequest vitroRequest, Entity entity,
|
||||
Set<SubEntity> subentities,
|
||||
Map<String, Set<String>> subOrganizationTypesResult)
|
||||
throws MalformedQueryParametersException {
|
||||
|
||||
Map<String, String> fileData = new HashMap<String, String>();
|
||||
|
||||
fileData.put(DataVisualizationController.FILE_CONTENT_TYPE_KEY,
|
||||
"application/octet-stream");
|
||||
fileData.put(DataVisualizationController.FILE_CONTENT_KEY,
|
||||
writePublicationsOverTimeJSON(vitroRequest, entity
|
||||
.getSubEntities(), subOrganizationTypesResult));
|
||||
return fileData;
|
||||
}
|
||||
|
||||
private TemplateResponseValues prepareStandaloneMarkupResponse(
|
||||
VitroRequest vreq, String entityURI) {
|
||||
|
||||
String standaloneTemplate = "entityComparisonOnPublicationsStandalone.ftl";
|
||||
|
||||
String organizationLabel = OrganizationUtilityFunctions
|
||||
.getEntityLabelFromDAO(vreq, entityURI);
|
||||
|
||||
Map<String, Object> body = new HashMap<String, Object>();
|
||||
body
|
||||
.put("title", organizationLabel
|
||||
+ " - Temporal Graph Visualization");
|
||||
body.put("organizationURI", entityURI);
|
||||
body.put("organizationLocalName", UtilityFunctions
|
||||
.getIndividualLocalName(entityURI, vreq));
|
||||
body.put("vivoDefaultNamespace", vreq.getWebappDaoFactory()
|
||||
.getDefaultNamespace());
|
||||
body.put("organizationLabel", organizationLabel);
|
||||
|
||||
return new TemplateResponseValues(standaloneTemplate, body);
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to generate a json file for year <-> publication count mapping.
|
||||
*
|
||||
* @param vreq
|
||||
* @param subentities
|
||||
* @param subOrganizationTypesResult
|
||||
* @throws MalformedQueryParametersException
|
||||
*/
|
||||
private String writePublicationsOverTimeJSON(VitroRequest vreq,
|
||||
Set<SubEntity> subentities,
|
||||
Map<String, Set<String>> subOrganizationTypesResult)
|
||||
throws MalformedQueryParametersException {
|
||||
|
||||
Gson json = new Gson();
|
||||
Set<JsonObject> subEntitiesJson = new HashSet<JsonObject>();
|
||||
|
||||
for (SubEntity subentity : subentities) {
|
||||
JsonObject entityJson = new JsonObject(subentity
|
||||
.getIndividualLabel());
|
||||
|
||||
List<List<Integer>> yearPubCount = new ArrayList<List<Integer>>();
|
||||
|
||||
for (Map.Entry<String, Integer> pubEntry : UtilityFunctions
|
||||
.getYearToActivityCount(subentity.getActivities())
|
||||
.entrySet()) {
|
||||
|
||||
List<Integer> currentPubYear = new ArrayList<Integer>();
|
||||
if (pubEntry.getKey().equals(
|
||||
VOConstants.DEFAULT_PUBLICATION_YEAR)) {
|
||||
currentPubYear.add(-1);
|
||||
} else {
|
||||
currentPubYear.add(Integer.parseInt(pubEntry.getKey()));
|
||||
}
|
||||
|
||||
currentPubYear.add(pubEntry.getValue());
|
||||
yearPubCount.add(currentPubYear);
|
||||
}
|
||||
|
||||
entityJson.setYearToActivityCount(yearPubCount);
|
||||
entityJson.getOrganizationTypes().addAll(
|
||||
subOrganizationTypesResult.get(entityJson.getLabel()));
|
||||
|
||||
entityJson.setEntityURI(subentity.getIndividualURI());
|
||||
|
||||
boolean isPerson = UtilityFunctions.isEntityAPerson(vreq, subentity
|
||||
.getIndividualURI());
|
||||
|
||||
if (isPerson) {
|
||||
entityJson.setVisMode("PERSON");
|
||||
} else {
|
||||
entityJson.setVisMode("ORGANIZATION");
|
||||
}
|
||||
subEntitiesJson.add(entityJson);
|
||||
}
|
||||
return json.toJson(subEntitiesJson);
|
||||
}
|
||||
|
||||
private String getEntityPublicationsPerYearCSVContent(
|
||||
Set<SubEntity> subentities,
|
||||
Map<String, Set<String>> subOrganizationTypesResult) {
|
||||
|
||||
StringBuilder csvFileContent = new StringBuilder();
|
||||
|
||||
csvFileContent.append("Entity Name, Publication Count, Entity Type\n");
|
||||
|
||||
for (SubEntity subEntity : subentities) {
|
||||
|
||||
csvFileContent.append(StringEscapeUtils.escapeCsv(subEntity
|
||||
.getIndividualLabel()));
|
||||
csvFileContent.append(", ");
|
||||
csvFileContent.append(subEntity.getActivities().size());
|
||||
csvFileContent.append(", ");
|
||||
|
||||
StringBuilder joinedTypes = new StringBuilder();
|
||||
|
||||
for (String subOrganizationType : subOrganizationTypesResult
|
||||
.get(subEntity.getIndividualLabel())) {
|
||||
joinedTypes.append(subOrganizationType + "; ");
|
||||
}
|
||||
|
||||
csvFileContent.append(StringEscapeUtils.escapeCsv(joinedTypes
|
||||
.toString()));
|
||||
csvFileContent.append("\n");
|
||||
}
|
||||
return csvFileContent.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Actions getRequiredPrivileges() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,177 +0,0 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
package edu.cornell.mannlib.vitro.webapp.visualization.entitycomparison;
|
||||
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
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.IRIFactory;
|
||||
import com.hp.hpl.jena.iri.Violation;
|
||||
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.visutils.ModelConstructor;
|
||||
|
||||
public class EntitySubOrganizationTypesConstructQueryRunner implements ModelConstructor {
|
||||
|
||||
protected static final Syntax SYNTAX = Syntax.syntaxARQ;
|
||||
|
||||
private String egoURI;
|
||||
|
||||
private Dataset dataset;
|
||||
|
||||
private Log log = LogFactory.getLog(EntitySubOrganizationTypesConstructQueryRunner
|
||||
.class.getName());
|
||||
|
||||
public EntitySubOrganizationTypesConstructQueryRunner(String egoURI, Dataset dataset, Log log) {
|
||||
this.egoURI = egoURI;
|
||||
this.dataset = dataset;
|
||||
//this.log = log;
|
||||
}
|
||||
|
||||
private String generateConstructQueryForOrganizationLabel(String queryURI) {
|
||||
|
||||
String sparqlQuery =
|
||||
"CONSTRUCT { "
|
||||
+ "<" + queryURI + "> rdfs:label ?organizationLabel ."
|
||||
+ "}"
|
||||
+ "WHERE {"
|
||||
+ "<" + queryURI + "> rdfs:label ?organizationLabel "
|
||||
+ "}";
|
||||
return sparqlQuery;
|
||||
}
|
||||
|
||||
private String generateConstructQueryForSubOrganizationTypes(String queryURI) {
|
||||
|
||||
String sparqlQuery =
|
||||
|
||||
"CONSTRUCT { "
|
||||
+ "<" + queryURI + "> core:hasSubOrganization ?subOrganization . "
|
||||
+ "?subOrganization rdfs:label ?subOrganizationLabel . "
|
||||
+ "?subOrganization rdf:type ?subOrganizationType . "
|
||||
+ "?subOrganization core:organizationForPosition ?Position . "
|
||||
+ "?subOrganizationType rdfs:label ?subOrganizationTypeLabel . "
|
||||
+ "?Position core:positionForPerson ?Person ."
|
||||
+ "?Person rdfs:label ?PersonLabel ."
|
||||
+ "?Person rdf:type ?PersonType . "
|
||||
+ "?PersonType rdfs:label ?PersonTypeLabel "
|
||||
+ "}"
|
||||
+ "WHERE { "
|
||||
+ "<" + queryURI + "> core:hasSubOrganization ?subOrganization . "
|
||||
+ "?subOrganization rdfs:label ?subOrganizationLabel . "
|
||||
+ "?subOrganization rdf:type ?subOrganizationType . "
|
||||
+ "?subOrganizationType rdfs:label ?subOrganizationTypeLabel . "
|
||||
+ "?subOrganization core:organizationForPosition ?Position . "
|
||||
+ "?Position core:positionForPerson ?Person . "
|
||||
+ "?Person rdfs:label ?PersonLabel ."
|
||||
+ "?Person rdf:type ?PersonType . "
|
||||
+ "?PersonType rdfs:label ?PersonTypeLabel "
|
||||
+ "}";
|
||||
|
||||
return sparqlQuery;
|
||||
}
|
||||
|
||||
private String generateConstructQueryForPersonTypes(String queryURI) {
|
||||
|
||||
String sparqlQuery =
|
||||
|
||||
"CONSTRUCT { "
|
||||
+ "<" + queryURI + "> core:organizationForPosition ?Position . "
|
||||
+ "?Position core:positionForPerson ?Person ."
|
||||
+ "?Person rdfs:label ?PersonLabel ."
|
||||
+ "?Person rdf:type ?PersonType . "
|
||||
+ "?PersonType rdfs:label ?PersonTypeLabel "
|
||||
+ "}"
|
||||
+ "WHERE { "
|
||||
+ "<" + queryURI + "> core:organizationForPosition ?Position . "
|
||||
+ "?Position core:positionForPerson ?Person ."
|
||||
+ "?Person rdfs:label ?PersonLabel ."
|
||||
+ "?Person rdf:type ?PersonType . "
|
||||
+ "?PersonType rdfs:label ?PersonTypeLabel "
|
||||
+ "}";
|
||||
|
||||
return sparqlQuery;
|
||||
}
|
||||
|
||||
private Model executeQuery(Set<String> constructQueries, Dataset dataset) {
|
||||
|
||||
Model constructedModel = ModelFactory.createDefaultModel();
|
||||
long before = 0;
|
||||
|
||||
for (String queryString : constructQueries) {
|
||||
|
||||
before = System.currentTimeMillis();
|
||||
log.debug("CONSTRUCT query string : " + queryString);
|
||||
|
||||
Query query = null;
|
||||
|
||||
try {
|
||||
query = QueryFactory.create(QueryConstants.getSparqlPrefixQuery()
|
||||
+ queryString, SYNTAX);
|
||||
} catch (Throwable th) {
|
||||
log.error("Could not create CONSTRUCT SPARQL query for query "
|
||||
+ "string. " + th.getMessage());
|
||||
log.error(queryString);
|
||||
}
|
||||
|
||||
QueryExecution qe = QueryExecutionFactory.create(
|
||||
query, dataset);
|
||||
try {
|
||||
qe.execConstruct(constructedModel);
|
||||
} finally {
|
||||
qe.close();
|
||||
}
|
||||
|
||||
log.debug("Time to run " + (before - System.currentTimeMillis()));
|
||||
}
|
||||
|
||||
return constructedModel;
|
||||
}
|
||||
|
||||
public Model getConstructedModel()
|
||||
throws MalformedQueryParametersException {
|
||||
|
||||
if (StringUtils.isNotBlank(this.egoURI)) {
|
||||
/*
|
||||
* To test for the validity of the URI submitted.
|
||||
* */
|
||||
IRIFactory iRIFactory = IRIFactory.jenaImplementation();
|
||||
IRI iri = iRIFactory.create(this.egoURI);
|
||||
if (iri.hasViolation(false)) {
|
||||
String errorMsg = ((Violation) iri.violations(false).next()).getShortMessage();
|
||||
log.error("Ego Co-PI Vis Query " + errorMsg);
|
||||
throw new MalformedQueryParametersException(
|
||||
"URI provided for an individual is malformed.");
|
||||
}
|
||||
} else {
|
||||
throw new MalformedQueryParametersException("URI parameter is either null or empty.");
|
||||
}
|
||||
|
||||
Set<String> constructQueries = new LinkedHashSet<String>();
|
||||
|
||||
populateConstructQueries(constructQueries);
|
||||
|
||||
Model model = executeQuery(constructQueries,
|
||||
this.dataset);
|
||||
//model.write(System.out);
|
||||
return model;
|
||||
}
|
||||
|
||||
private void populateConstructQueries(Set<String> constructQueries) {
|
||||
constructQueries.add(generateConstructQueryForOrganizationLabel(this.egoURI));
|
||||
constructQueries.add(generateConstructQueryForSubOrganizationTypes(this.egoURI));
|
||||
constructQueries.add(generateConstructQueryForPersonTypes(this.egoURI));
|
||||
}
|
||||
}
|
|
@ -1,189 +0,0 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
package edu.cornell.mannlib.vitro.webapp.visualization.entitycomparison;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
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.IRIFactory;
|
||||
import com.hp.hpl.jena.iri.Violation;
|
||||
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.QuerySolution;
|
||||
import com.hp.hpl.jena.query.ResultSet;
|
||||
import com.hp.hpl.jena.query.Syntax;
|
||||
import com.hp.hpl.jena.rdf.model.Model;
|
||||
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.QueryFieldLabels;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.visutils.QueryRunner;
|
||||
|
||||
|
||||
/**
|
||||
* @author bkoniden
|
||||
* Deepak Konidena
|
||||
*/
|
||||
public class EntitySubOrganizationTypesQueryRunner
|
||||
implements QueryRunner<Map<String, Set<String>>> {
|
||||
|
||||
protected static final Syntax SYNTAX = Syntax.syntaxARQ;
|
||||
|
||||
private String entityURI;
|
||||
private Model dataSource;
|
||||
private Log log = LogFactory.getLog(EntitySubOrganizationTypesQueryRunner.class.getName());
|
||||
|
||||
private static final String SPARQL_QUERY_SELECT_CLAUSE = ""
|
||||
+ " (str(?organizationLabel) as ?" + QueryFieldLabels.ORGANIZATION_LABEL + ") "
|
||||
+ " (str(?subOrganizationLabel) as ?" + QueryFieldLabels.SUBORGANIZATION_LABEL + ") "
|
||||
+ " (str(?subOrganizationType) as ?" + QueryFieldLabels.SUBORGANIZATION_TYPE + ")"
|
||||
+ " (str(?subOrganizationTypeLabel) as ?"
|
||||
+ QueryFieldLabels.SUBORGANIZATION_TYPE_LABEL + ") "
|
||||
+ " (str(?Person) as ?personLit) "
|
||||
+ " (str(?PersonLabel) as ?personLabelLit) "
|
||||
+ " (str(?PersonTypeLabel) as ?personTypeLabelLit) ";
|
||||
|
||||
|
||||
public EntitySubOrganizationTypesQueryRunner(String entityURI,
|
||||
Model dataSource, Log log) {
|
||||
|
||||
this.entityURI = entityURI;
|
||||
this.dataSource = dataSource;
|
||||
// this.log = log;
|
||||
}
|
||||
|
||||
private ResultSet executeQuery(String queryURI, Model dataSource) {
|
||||
|
||||
QueryExecution queryExecution = null;
|
||||
Query query = QueryFactory.create(
|
||||
getSparqlQuery(queryURI), SYNTAX);
|
||||
queryExecution = QueryExecutionFactory.create(query, dataSource);
|
||||
return queryExecution.execSelect();
|
||||
}
|
||||
|
||||
private String getSparqlQuery(String queryURI) {
|
||||
|
||||
String sparqlQuery = "";
|
||||
|
||||
sparqlQuery = QueryConstants.getSparqlPrefixQuery()
|
||||
+ "SELECT "
|
||||
+ SPARQL_QUERY_SELECT_CLAUSE
|
||||
+ " WHERE { "
|
||||
+ "<"
|
||||
+ queryURI
|
||||
+ "> rdfs:label ?organizationLabel . "
|
||||
+ "{ "
|
||||
+ "<" + queryURI + "> core:hasSubOrganization ?subOrganization . "
|
||||
+ "?subOrganization rdfs:label ?subOrganizationLabel ;"
|
||||
+ " rdf:type ?subOrganizationType ;"
|
||||
+ " core:organizationForPosition ?Position . "
|
||||
+ "?subOrganizationType rdfs:label ?subOrganizationTypeLabel . "
|
||||
+ "?Position core:positionForPerson ?Person ."
|
||||
+ "}"
|
||||
+ "UNION "
|
||||
+ "{ "
|
||||
+ "<" + queryURI + "> core:organizationForPosition ?Position . "
|
||||
+ "?Position core:positionForPerson ?Person . "
|
||||
+ "?Person rdfs:label ?PersonLabel ; rdf:type ?PersonType . "
|
||||
+ "?PersonType rdfs:label ?PersonTypeLabel . "
|
||||
+ "}"
|
||||
+ "}";
|
||||
return sparqlQuery;
|
||||
}
|
||||
|
||||
private Map<String, Set<String>> createJavaValueObjects(ResultSet resultSet) {
|
||||
|
||||
Map<String, Set<String>> subEntityLabelToTypes = new HashMap<String, Set<String>>();
|
||||
|
||||
while (resultSet.hasNext()) {
|
||||
|
||||
QuerySolution solution = resultSet.nextSolution();
|
||||
|
||||
RDFNode subOrganizationLabel = solution.get(QueryFieldLabels.SUBORGANIZATION_LABEL);
|
||||
|
||||
if (subOrganizationLabel != null) {
|
||||
|
||||
if (subEntityLabelToTypes.containsKey(subOrganizationLabel.toString())) {
|
||||
RDFNode subOrganizationType = solution
|
||||
.get(QueryFieldLabels.SUBORGANIZATION_TYPE_LABEL);
|
||||
if (subOrganizationType != null) {
|
||||
subEntityLabelToTypes.get(
|
||||
subOrganizationLabel.toString()).add(
|
||||
subOrganizationType.toString());
|
||||
}
|
||||
} else {
|
||||
RDFNode subOrganizationType = solution
|
||||
.get(QueryFieldLabels.SUBORGANIZATION_TYPE_LABEL);
|
||||
if (subOrganizationType != null) {
|
||||
subEntityLabelToTypes.put(
|
||||
subOrganizationLabel.toString(),
|
||||
new HashSet<String>());
|
||||
subEntityLabelToTypes.get(
|
||||
subOrganizationLabel.toString()).add(
|
||||
subOrganizationType.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RDFNode personLabel = solution.get(QueryFieldLabels.PERSON_LABEL);
|
||||
|
||||
if (personLabel != null) {
|
||||
if (subEntityLabelToTypes.containsKey(personLabel.toString())) {
|
||||
RDFNode personType = solution
|
||||
.get(QueryFieldLabels.PERSON_TYPE_LABEL);
|
||||
if (personType != null
|
||||
&& !personType.toString().startsWith("http")) {
|
||||
subEntityLabelToTypes.get(personLabel.toString()).add(
|
||||
personType.toString());
|
||||
}
|
||||
} else {
|
||||
RDFNode personType = solution
|
||||
.get(QueryFieldLabels.PERSON_TYPE_LABEL);
|
||||
if (personType != null
|
||||
&& !personType.toString().startsWith("http")) {
|
||||
subEntityLabelToTypes.put(personLabel.toString(),
|
||||
new HashSet<String>());
|
||||
subEntityLabelToTypes.get(personLabel.toString()).add(
|
||||
personType.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return subEntityLabelToTypes;
|
||||
}
|
||||
|
||||
public Map<String, Set<String>> getQueryResult() throws MalformedQueryParametersException {
|
||||
|
||||
if (StringUtils.isNotBlank(this.entityURI)) {
|
||||
/*
|
||||
* To test for the validity of the URI submitted.
|
||||
*/
|
||||
IRIFactory iRIFactory = IRIFactory.jenaImplementation();
|
||||
IRI iri = iRIFactory.create(this.entityURI);
|
||||
if (iri.hasViolation(false)) {
|
||||
String errorMsg = ((Violation) iri.violations(false).next())
|
||||
.getShortMessage();
|
||||
log.error("Entity Comparison sub organization types query " + errorMsg);
|
||||
throw new MalformedQueryParametersException(
|
||||
"URI provided for an entity is malformed.");
|
||||
}
|
||||
} else {
|
||||
throw new MalformedQueryParametersException(
|
||||
"URL parameter is either null or empty.");
|
||||
}
|
||||
|
||||
ResultSet resultSet = executeQuery(this.entityURI, this.dataSource);
|
||||
return createJavaValueObjects(resultSet);
|
||||
}
|
||||
}
|
||||
|
|
@ -3,7 +3,6 @@ package edu.cornell.mannlib.vitro.webapp.visualization.entitycomparison;
|
|||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.logging.Log;
|
||||
|
@ -13,7 +12,6 @@ import com.hp.hpl.jena.iri.IRIFactory;
|
|||
import com.hp.hpl.jena.query.Dataset;
|
||||
import com.hp.hpl.jena.query.QuerySolution;
|
||||
import com.hp.hpl.jena.query.ResultSet;
|
||||
import com.hp.hpl.jena.rdf.model.Model;
|
||||
import com.hp.hpl.jena.rdf.model.RDFNode;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||
|
@ -25,7 +23,6 @@ import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryP
|
|||
import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.Entity;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.GenericQueryMap;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.visutils.GenericQueryRunner;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.visutils.ModelConstructor;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.visutils.QueryRunner;
|
||||
|
||||
public class OrganizationUtilityFunctions {
|
||||
|
@ -101,28 +98,6 @@ public class OrganizationUtilityFunctions {
|
|||
return highestLevelOrgURI;
|
||||
}
|
||||
|
||||
public static Map<String, Set<String>> getSubEntityTypes(Log log,
|
||||
Dataset dataset, String subjectOrganization)
|
||||
throws MalformedQueryParametersException {
|
||||
|
||||
ModelConstructor constructQueryRunnerForSubOrganizationTypes =
|
||||
new EntitySubOrganizationTypesConstructQueryRunner(subjectOrganization,
|
||||
dataset,
|
||||
log);
|
||||
|
||||
Model constructedModelForSubOrganizationTypes = constructQueryRunnerForSubOrganizationTypes
|
||||
.getConstructedModel();
|
||||
|
||||
QueryRunner<Map<String, Set<String>>> queryManagerForsubOrganisationTypes =
|
||||
new EntitySubOrganizationTypesQueryRunner(
|
||||
subjectOrganization, constructedModelForSubOrganizationTypes, log);
|
||||
|
||||
Map<String, Set<String>> subOrganizationTypesResult = queryManagerForsubOrganisationTypes
|
||||
.getQueryResult();
|
||||
|
||||
return subOrganizationTypesResult;
|
||||
}
|
||||
|
||||
public static String getEntityLabelFromDAO(VitroRequest vitroRequest,
|
||||
String entityURI) {
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.visualization.entitycomparison.cached;
|
||||
package edu.cornell.mannlib.vitro.webapp.visualization.entitycomparison;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
@ -24,7 +24,6 @@ import edu.cornell.mannlib.vitro.webapp.controller.visualization.DataVisualizati
|
|||
import edu.cornell.mannlib.vitro.webapp.controller.visualization.VisualizationFrameworkConstants;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.constants.VOConstants;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.constants.VisConstants;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.entitycomparison.OrganizationUtilityFunctions;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.Activity;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.Entity;
|
|
@ -1,6 +1,6 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.visualization.entitycomparison.cached;
|
||||
package edu.cornell.mannlib.vitro.webapp.visualization.entitycomparison;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
@ -24,7 +24,6 @@ import edu.cornell.mannlib.vitro.webapp.controller.visualization.DataVisualizati
|
|||
import edu.cornell.mannlib.vitro.webapp.controller.visualization.VisualizationFrameworkConstants;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.constants.VOConstants;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.constants.VisConstants;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.entitycomparison.OrganizationUtilityFunctions;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.Activity;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.Entity;
|
|
@ -1,390 +0,0 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.visualization.entitygrantcount;
|
||||
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
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.IRIFactory;
|
||||
import com.hp.hpl.jena.iri.Violation;
|
||||
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.visutils.ModelConstructor;
|
||||
|
||||
public class EntityGrantCountConstructQueryRunner implements ModelConstructor {
|
||||
|
||||
protected static final Syntax SYNTAX = Syntax.syntaxARQ;
|
||||
|
||||
private String egoURI;
|
||||
|
||||
private Dataset dataset;
|
||||
|
||||
private long before, after;
|
||||
|
||||
private Log log = LogFactory
|
||||
.getLog(EntityGrantCountConstructQueryRunner.class.getName());
|
||||
|
||||
public EntityGrantCountConstructQueryRunner(String egoURI, Dataset dataset,
|
||||
Log log) {
|
||||
this.egoURI = egoURI;
|
||||
this.dataset = dataset;
|
||||
// this.log = log;
|
||||
}
|
||||
|
||||
private String generateConstructQueryForOrganizationLabel(String queryURI) {
|
||||
|
||||
String sparqlQuery = "CONSTRUCT { " + "<" + queryURI
|
||||
+ "> rdfs:label ?organizationLabel ." + "}" + "WHERE {" + "<"
|
||||
+ queryURI + "> rdfs:label ?organizationLabel " + "}";
|
||||
|
||||
return sparqlQuery;
|
||||
}
|
||||
|
||||
private String generateConstructQueryForDateTimeValueofRoleForOneLevelDeep(
|
||||
String queryURI, String preboundProperty) {
|
||||
|
||||
String sparqlQuery = "CONSTRUCT { " + "<" + queryURI
|
||||
+ "> core:hasSubOrganization ?subOrganization . "
|
||||
+ "?subOrganization core:organizationForPosition ?Position . "
|
||||
+ "?Position core:positionForPerson ?Person . " + "?Person "
|
||||
+ preboundProperty + " ?Role . "
|
||||
+ "?Role core:dateTimeInterval ?dateTimeIntervalValue . "
|
||||
+ "?dateTimeIntervalValue core:start ?startDate . "
|
||||
+ "?startDate core:dateTime ?startDateTimeValue . "
|
||||
+ "?dateTimeIntervalValue core:end ?endDate . "
|
||||
+ "?endDate core:dateTime ?endDateTimeValue . " + "}"
|
||||
+ "WHERE { " + "{" + "<" + queryURI
|
||||
+ "> core:hasSubOrganization ?subOrganization . "
|
||||
+ "?subOrganization core:organizationForPosition ?Position . "
|
||||
+ "?Position core:positionForPerson ?Person . " + "?Person "
|
||||
+ preboundProperty + " ?Role . "
|
||||
+ "?Role core:dateTimeInterval ?dateTimeIntervalValue . "
|
||||
+ "?dateTimeIntervalValue core:start ?startDate . "
|
||||
+ "?startDate core:dateTime ?startDateTimeValue . "
|
||||
+ "} UNION " + "{" + "<" + queryURI
|
||||
+ "> core:hasSubOrganization ?subOrganization . "
|
||||
+ "?subOrganization core:organizationForPosition ?Position . "
|
||||
+ "?Position core:positionForPerson ?Person . " + "?Person "
|
||||
+ preboundProperty + " ?Role . "
|
||||
+ "?Role core:dateTimeInterval ?dateTimeIntervalValue . "
|
||||
+ "?dateTimeIntervalValue core:end ?endDate . "
|
||||
+ "?endDate core:dateTime ?endDateTimeValue . " + "}" + "}";
|
||||
|
||||
return sparqlQuery;
|
||||
}
|
||||
|
||||
private String generateConstructQueryForDateTimeValueofGrantForOneLevelDeep(
|
||||
String queryURI, String preboundProperty) {
|
||||
|
||||
String sparqlQuery = "CONSTRUCT { " + "<"
|
||||
+ queryURI
|
||||
+ "> core:hasSubOrganization ?subOrganization . "
|
||||
+ "?subOrganization core:organizationForPosition ?Position . "
|
||||
+ "?Position core:positionForPerson ?Person . "
|
||||
+ "?Person "
|
||||
+ preboundProperty
|
||||
+ " ?Role . "
|
||||
+ "?Role core:roleIn ?Grant ."
|
||||
+ "?Grant core:dateTimeInterval ?dateTimeIntervalValueForGrant . "
|
||||
+ "?dateTimeIntervalValueForGrant core:start ?startDateForGrant . "
|
||||
+ "?startDateForGrant core:dateTime ?startDateTimeValueForGrant . "
|
||||
+ "?dateTimeIntervalValueForGrant core:end ?endDateForGrant . "
|
||||
+ "?endDateForGrant core:dateTime ?endDateTimeValueForGrant "
|
||||
+ "}"
|
||||
+ "WHERE { "
|
||||
+ "{"
|
||||
+ "<"
|
||||
+ queryURI
|
||||
+ "> core:hasSubOrganization ?subOrganization . "
|
||||
+ "?subOrganization core:organizationForPosition ?Position . "
|
||||
+ "?Position core:positionForPerson ?Person . "
|
||||
+ "?Person "
|
||||
+ preboundProperty
|
||||
+ " ?Role . "
|
||||
+ "?Role core:roleIn ?Grant ."
|
||||
+ "?Grant core:dateTimeInterval ?dateTimeIntervalValueForGrant . "
|
||||
+ "?dateTimeIntervalValueForGrant core:start ?startDateForGrant . "
|
||||
+ "?startDateForGrant core:dateTime ?startDateTimeValueForGrant "
|
||||
+ "} UNION "
|
||||
+ "{"
|
||||
+ "<"
|
||||
+ queryURI
|
||||
+ "> core:hasSubOrganization ?subOrganization . "
|
||||
+ "?subOrganization core:organizationForPosition ?Position . "
|
||||
+ "?Position core:positionForPerson ?Person . "
|
||||
+ "?Person "
|
||||
+ preboundProperty
|
||||
+ " ?Role . "
|
||||
+ "?Role core:roleIn ?Grant ."
|
||||
+ "?Grant core:dateTimeInterval ?dateTimeIntervalValueForGrant . "
|
||||
+ "?dateTimeIntervalValueForGrant core:end ?endDateForGrant . "
|
||||
+ "?endDateForGrant core:dateTime ?endDateTimeValueForGrant "
|
||||
+ "}" + "}";
|
||||
|
||||
return sparqlQuery;
|
||||
}
|
||||
|
||||
private String generateConstructQueryForDateTimeValueofRole(
|
||||
String queryURI, String preboundProperty) {
|
||||
|
||||
String sparqlQuery = "CONSTRUCT { " + "<" + queryURI
|
||||
+ "> core:organizationForPosition ?Position . "
|
||||
+ "?Position core:positionForPerson ?Person . " + "?Person "
|
||||
+ preboundProperty + " ?Role . "
|
||||
+ "?Role core:dateTimeInterval ?dateTimeIntervalValue . "
|
||||
+ "?dateTimeIntervalValue core:start ?startDate . "
|
||||
+ "?startDate core:dateTime ?startDateTimeValue . "
|
||||
+ "?dateTimeIntervalValue core:end ?endDate . "
|
||||
+ "?endDate core:dateTime ?endDateTimeValue " + "}"
|
||||
+ "WHERE { " + "{" + "<" + queryURI
|
||||
+ "> core:organizationForPosition ?Position . "
|
||||
+ "?Position core:positionForPerson ?Person . " + "?Person "
|
||||
+ preboundProperty + " ?Role . "
|
||||
+ "?Role core:dateTimeInterval ?dateTimeIntervalValue . "
|
||||
+ "?dateTimeIntervalValue core:start ?startDate . "
|
||||
+ "?startDate core:dateTime ?startDateTimeValue " + "} UNION "
|
||||
+ "{" + "<" + queryURI
|
||||
+ "> core:organizationForPosition ?Position . "
|
||||
+ "?Position core:positionForPerson ?Person . " + "?Person "
|
||||
+ preboundProperty + " ?Role . "
|
||||
+ "?Role core:dateTimeInterval ?dateTimeIntervalValue . "
|
||||
+ "?dateTimeIntervalValue core:end ?endDate . "
|
||||
+ "?endDate core:dateTime ?endDateTimeValue " + "}" + "}";
|
||||
|
||||
return sparqlQuery;
|
||||
}
|
||||
|
||||
private String generateConstructQueryForDateTimeValueofGrant(
|
||||
String queryURI, String preboundProperty) {
|
||||
|
||||
String sparqlQuery = "CONSTRUCT { " + "<"
|
||||
+ queryURI
|
||||
+ "> core:organizationForPosition ?Position . "
|
||||
+ "?Position core:positionForPerson ?Person . "
|
||||
+ "?Person "
|
||||
+ preboundProperty
|
||||
+ " ?Role . "
|
||||
+ "?Role core:roleIn ?Grant ."
|
||||
+ "?Grant core:dateTimeInterval ?dateTimeIntervalValueForGrant . "
|
||||
+ "?dateTimeIntervalValueForGrant core:start ?startDateForGrant . "
|
||||
+ "?startDateForGrant core:dateTime ?startDateTimeValueForGrant . "
|
||||
+ "?dateTimeIntervalValueForGrant core:end ?endDateForGrant . "
|
||||
+ "?endDateForGrant core:dateTime ?endDateTimeValueForGrant "
|
||||
+ "}"
|
||||
+ "WHERE { "
|
||||
+ "{"
|
||||
+ "<"
|
||||
+ queryURI
|
||||
+ "> core:organizationForPosition ?Position . "
|
||||
+ "?Position core:positionForPerson ?Person . "
|
||||
+ "?Person "
|
||||
+ preboundProperty
|
||||
+ " ?Role . "
|
||||
+ "?Role core:roleIn ?Grant ."
|
||||
+ "?Grant core:dateTimeInterval ?dateTimeIntervalValueForGrant . "
|
||||
+ "?dateTimeIntervalValueForGrant core:start ?startDateForGrant . "
|
||||
+ "?startDateForGrant core:dateTime ?startDateTimeValueForGrant "
|
||||
+ "} UNION "
|
||||
+ "{"
|
||||
+ "<"
|
||||
+ queryURI
|
||||
+ "> core:organizationForPosition ?Position . "
|
||||
+ "?Position core:positionForPerson ?Person . "
|
||||
+ "?Person "
|
||||
+ preboundProperty
|
||||
+ " ?Role . "
|
||||
+ "?Role core:roleIn ?Grant ."
|
||||
+ "?Grant core:dateTimeInterval ?dateTimeIntervalValueForGrant . "
|
||||
+ "?dateTimeIntervalValueForGrant core:end ?endDateForGrant . "
|
||||
+ "?endDateForGrant core:dateTime ?endDateTimeValueForGrant "
|
||||
+ "}" + "}";
|
||||
|
||||
return sparqlQuery;
|
||||
}
|
||||
|
||||
private String generateConstructQueryForSubOrganizations(String queryURI,
|
||||
String preboundProperty) {
|
||||
|
||||
String sparqlQuery =
|
||||
|
||||
"CONSTRUCT { " + "<" + queryURI
|
||||
+ "> core:hasSubOrganization ?subOrganization . "
|
||||
+ "?subOrganization rdfs:label ?subOrganizationLabel . "
|
||||
+ "?subOrganization core:organizationForPosition ?Position . "
|
||||
+ "?Position core:positionForPerson ?Person . "
|
||||
+ "?Person rdfs:label ?PersonLabel ." + "?Person "
|
||||
+ preboundProperty + " ?Role . " + "?Role core:roleIn ?Grant ."
|
||||
+ "?Grant rdfs:label ?GrantLabel " + "}" + "WHERE { " + "<"
|
||||
+ queryURI + "> core:hasSubOrganization ?subOrganization . "
|
||||
+ "?subOrganization rdfs:label ?subOrganizationLabel . "
|
||||
+ "?subOrganization core:organizationForPosition ?Position . "
|
||||
+ "?Position core:positionForPerson ?Person . "
|
||||
+ "?Person rdfs:label ?PersonLabel ." + "?Person "
|
||||
+ preboundProperty + " ?Role . " + "?Role core:roleIn ?Grant ."
|
||||
+ "?Grant rdfs:label ?GrantLabel " + "}";
|
||||
|
||||
return sparqlQuery;
|
||||
|
||||
}
|
||||
|
||||
private String generateConstructQueryForPersons(String queryURI,
|
||||
String preboundProperty) {
|
||||
|
||||
String sparqlQuery =
|
||||
|
||||
"CONSTRUCT { " + "<" + queryURI
|
||||
+ "> core:organizationForPosition ?Position . "
|
||||
+ "?Position core:positionForPerson ?Person . "
|
||||
+ "?Person rdfs:label ?PersonLabel ." + "?Person "
|
||||
+ preboundProperty + " ?Role . " + "?Role core:roleIn ?Grant ."
|
||||
+ "?Grant rdfs:label ?GrantLabel " + "}" + "WHERE { " + "<"
|
||||
+ queryURI + "> core:organizationForPosition ?Position . "
|
||||
+ "?Position core:positionForPerson ?Person . "
|
||||
+ "?Person rdfs:label ?PersonLabel ." + "?Person "
|
||||
+ preboundProperty + " ?Role . " + "?Role core:roleIn ?Grant ."
|
||||
+ "?Grant rdfs:label ?GrantLabel " + "}";
|
||||
|
||||
return sparqlQuery;
|
||||
|
||||
}
|
||||
|
||||
private Model executeQuery(Set<String> constructQueries, Dataset dataset) {
|
||||
|
||||
Model constructedModel = ModelFactory.createDefaultModel();
|
||||
|
||||
before = System.currentTimeMillis();
|
||||
|
||||
for (String queryString : constructQueries) {
|
||||
|
||||
log.debug("CONSTRUCT query string : " + queryString);
|
||||
|
||||
Query query = null;
|
||||
|
||||
try {
|
||||
query = QueryFactory.create(QueryConstants
|
||||
.getSparqlPrefixQuery()
|
||||
+ queryString, SYNTAX);
|
||||
// log.debug("query: "+ queryString);
|
||||
} catch (Throwable th) {
|
||||
log.error("Could not create CONSTRUCT SPARQL query for query "
|
||||
+ "string. " + th.getMessage());
|
||||
log.error(queryString);
|
||||
}
|
||||
|
||||
QueryExecution qe = QueryExecutionFactory.create(query, dataset);
|
||||
try {
|
||||
qe.execConstruct(constructedModel);
|
||||
} finally {
|
||||
qe.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
after = System.currentTimeMillis();
|
||||
|
||||
// log.debug("Statements for constructed model of EntityGrantCount : "+
|
||||
// constructedModel.listStatements().toString());
|
||||
log
|
||||
.debug("Time taken to execute the CONSTRUCT queries is in milliseconds: "
|
||||
+ (after - before));
|
||||
// constructedModel.write(System.out);
|
||||
return constructedModel;
|
||||
}
|
||||
|
||||
public Model getConstructedModel() throws MalformedQueryParametersException {
|
||||
|
||||
if (StringUtils.isNotBlank(this.egoURI)) {
|
||||
/*
|
||||
* To test for the validity of the URI submitted.
|
||||
*/
|
||||
IRIFactory iRIFactory = IRIFactory.jenaImplementation();
|
||||
IRI iri = iRIFactory.create(this.egoURI);
|
||||
if (iri.hasViolation(false)) {
|
||||
String errorMsg = ((Violation) iri.violations(false).next())
|
||||
.getShortMessage();
|
||||
log.error("Entity Grant Count Construct Query " + errorMsg);
|
||||
throw new MalformedQueryParametersException(
|
||||
"URI provided for an individual is malformed.");
|
||||
}
|
||||
} else {
|
||||
throw new MalformedQueryParametersException(
|
||||
"URI parameter is either null or empty.");
|
||||
}
|
||||
|
||||
Set<String> constructQueries = new LinkedHashSet<String>();
|
||||
|
||||
populateConstructQueries(constructQueries);
|
||||
|
||||
Model model = executeQuery(constructQueries, this.dataset);
|
||||
|
||||
return model;
|
||||
|
||||
}
|
||||
|
||||
private void populateConstructQueries(Set<String> constructQueries) {
|
||||
|
||||
constructQueries
|
||||
.add(generateConstructQueryForOrganizationLabel(this.egoURI));
|
||||
|
||||
constructQueries.add(generateConstructQueryForSubOrganizations(
|
||||
this.egoURI, "core:hasInvestigatorRole"));
|
||||
constructQueries.add(generateConstructQueryForPersons(this.egoURI,
|
||||
"core:hasInvestigatorRole"));
|
||||
constructQueries
|
||||
.add(generateConstructQueryForDateTimeValueofRoleForOneLevelDeep(
|
||||
this.egoURI, "core:hasInvestigatorRole"));
|
||||
constructQueries.add(generateConstructQueryForDateTimeValueofRole(
|
||||
this.egoURI, "core:hasInvestigatorRole"));
|
||||
constructQueries
|
||||
.add(generateConstructQueryForDateTimeValueofGrantForOneLevelDeep(
|
||||
this.egoURI, "core:hasInvestigatorRole"));
|
||||
constructQueries.add(generateConstructQueryForDateTimeValueofGrant(
|
||||
this.egoURI, "core:hasInvestigatorRole"));
|
||||
|
||||
constructQueries.add(generateConstructQueryForSubOrganizations(
|
||||
this.egoURI, "core:hasPrincipalInvestigatorRole"));
|
||||
constructQueries.add(generateConstructQueryForPersons(this.egoURI,
|
||||
"core:hasPrincipalInvestigatorRole"));
|
||||
constructQueries
|
||||
.add(generateConstructQueryForDateTimeValueofRoleForOneLevelDeep(
|
||||
this.egoURI, "core:hasPrincipalInvestigatorRole"));
|
||||
constructQueries.add(generateConstructQueryForDateTimeValueofRole(
|
||||
this.egoURI, "core:hasPrincipalInvestigatorRole"));
|
||||
constructQueries
|
||||
.add(generateConstructQueryForDateTimeValueofGrantForOneLevelDeep(
|
||||
this.egoURI, "core:hasPrincipalInvestigatorRole"));
|
||||
constructQueries.add(generateConstructQueryForDateTimeValueofGrant(
|
||||
this.egoURI, "core:hasPrincipalInvestigatorRole"));
|
||||
|
||||
constructQueries.add(generateConstructQueryForSubOrganizations(
|
||||
this.egoURI, "core:hasCo-PrincipalInvestigatorRole"));
|
||||
constructQueries.add(generateConstructQueryForPersons(this.egoURI,
|
||||
"core:hasCo-PrincipalInvestigatorRole"));
|
||||
constructQueries
|
||||
.add(generateConstructQueryForDateTimeValueofRoleForOneLevelDeep(
|
||||
this.egoURI, "core:hasCo-PrincipalInvestigatorRole"));
|
||||
constructQueries.add(generateConstructQueryForDateTimeValueofRole(
|
||||
this.egoURI, "core:hasCo-PrincipalInvestigatorRole"));
|
||||
constructQueries
|
||||
.add(generateConstructQueryForDateTimeValueofGrantForOneLevelDeep(
|
||||
this.egoURI, "core:hasCo-PrincipalInvestigatorRole"));
|
||||
constructQueries.add(generateConstructQueryForDateTimeValueofGrant(
|
||||
this.egoURI, "core:hasCo-PrincipalInvestigatorRole"));
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,334 +0,0 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.visualization.entitygrantcount;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
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.IRIFactory;
|
||||
import com.hp.hpl.jena.iri.Violation;
|
||||
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.QuerySolution;
|
||||
import com.hp.hpl.jena.query.ResultSet;
|
||||
import com.hp.hpl.jena.query.Syntax;
|
||||
import com.hp.hpl.jena.rdf.model.Model;
|
||||
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.QueryFieldLabels;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.Activity;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.Entity;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.SubEntity;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.visutils.QueryRunner;
|
||||
|
||||
/**
|
||||
* This query runner is used to execute a sparql query that will fetch all the
|
||||
* grants defined by core:Grant property for a particular
|
||||
* department/school/university.
|
||||
*
|
||||
* Deepak Konidena
|
||||
*
|
||||
* @author bkoniden
|
||||
*/
|
||||
public class EntityGrantCountQueryRunner implements QueryRunner<Entity> {
|
||||
|
||||
protected static final Syntax SYNTAX = Syntax.syntaxARQ;
|
||||
|
||||
private String entityURI;
|
||||
private Model dataSource;
|
||||
private Log log = LogFactory.getLog(EntityGrantCountQueryRunner.class.getName());
|
||||
private long before, after;
|
||||
|
||||
|
||||
private static final String SPARQL_QUERY_COMMON_SELECT_CLAUSE = "SELECT "
|
||||
+ " (str(?organizationLabel) as ?organizationLabelLit) "
|
||||
+ " (str(?subOrganization) as ?subOrganizationLit) "
|
||||
+ " (str(?subOrganizationLabel) as ?subOrganizationLabelLit) "
|
||||
+ " (str(?Person) as ?personLit) "
|
||||
+ " (str(?PersonLabel) as ?personLabelLit) "
|
||||
+ " (str(?Grant) as ?grantLit) "
|
||||
+ " (str(?GrantLabel) as ?grantLabelLit) "
|
||||
+ " (str(?startDateTimeValue) as ?grantStartDateLit) "
|
||||
+ " (str(?endDateTimeValue) as ?grantEndDateLit) "
|
||||
+ " (str(?startDateTimeValueForGrant) as ?grantStartDateForGrantLit) "
|
||||
+ " (str(?endDateTimeValueForGrant) as ?grantEndDateForGrantLit)";
|
||||
|
||||
private static final String SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_ROLE_DATE_TIME = " "
|
||||
+ " ?Role core:roleIn ?Grant . "
|
||||
+ " ?Grant rdfs:label ?GrantLabel . "
|
||||
+ "OPTIONAL {"
|
||||
+ " ?Role core:dateTimeInterval ?dateTimeIntervalValue . "
|
||||
+ "?dateTimeIntervalValue core:start ?startDate . "
|
||||
+ "?startDate core:dateTime ?startDateTimeValue . "
|
||||
+ "OPTIONAL {"
|
||||
+ "?dateTimeIntervalValue core:end ?endDate . "
|
||||
+ "?endDate core:dateTime ?endDateTimeValue . "
|
||||
+ "}"
|
||||
+ "}";
|
||||
|
||||
private static final String SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_GRANT_DATE_TIME = " "
|
||||
+ " ?Role core:roleIn ?Grant . "
|
||||
+ " ?Grant rdfs:label ?GrantLabel . "
|
||||
+ "OPTIONAL {"
|
||||
+ " ?Grant core:dateTimeInterval ?dateTimeIntervalValueForGrant . "
|
||||
+ "?dateTimeIntervalValueForGrant core:start ?startDateForGrant . "
|
||||
+ "?startDateForGrant core:dateTime ?startDateTimeValueForGrant . "
|
||||
+ "OPTIONAL {"
|
||||
+ "?dateTimeIntervalValueForGrant core:end ?endDateForGrant . "
|
||||
+ "?endDateForGrant core:dateTime ?endDateTimeValueForGrant . "
|
||||
+ "}"
|
||||
+ "}";
|
||||
|
||||
|
||||
private static final String ENTITY_LABEL = QueryFieldLabels.ORGANIZATION_LABEL;
|
||||
private static final String ENTITY_URL = QueryFieldLabels.ORGANIZATION_URL;
|
||||
private static final String SUBENTITY_LABEL = QueryFieldLabels.SUBORGANIZATION_LABEL;
|
||||
private static final String SUBENTITY_URL = QueryFieldLabels.SUBORGANIZATION_URL;
|
||||
|
||||
|
||||
public EntityGrantCountQueryRunner(String entityURI,
|
||||
Model constructedModel, Log log) {
|
||||
|
||||
this.entityURI = entityURI;
|
||||
this.dataSource = constructedModel;
|
||||
|
||||
}
|
||||
|
||||
private Entity createJavaValueObjects(ResultSet resultSet) {
|
||||
|
||||
Entity entity = null;
|
||||
Map<String, Activity> grantURIToVO = new HashMap<String, Activity>();
|
||||
Map<String, SubEntity> subentityURLToVO = new HashMap<String, SubEntity>();
|
||||
Map<String, SubEntity> personURLToVO = new HashMap<String, SubEntity>();
|
||||
|
||||
before = System.currentTimeMillis();
|
||||
|
||||
while (resultSet.hasNext()) {
|
||||
QuerySolution solution = resultSet.nextSolution();
|
||||
|
||||
if (entity == null) {
|
||||
entity = new Entity(solution.get(ENTITY_URL).toString(),
|
||||
solution.get(ENTITY_LABEL).toString());
|
||||
}
|
||||
|
||||
RDFNode grantNode = solution.get(QueryFieldLabels.GRANT_URL);
|
||||
Activity grant;
|
||||
|
||||
if (grantURIToVO.containsKey(grantNode.toString())) {
|
||||
grant = grantURIToVO.get(grantNode.toString());
|
||||
|
||||
} else {
|
||||
|
||||
grant = new Activity(grantNode.toString());
|
||||
grantURIToVO.put(grantNode.toString(), grant);
|
||||
|
||||
RDFNode grantLabelNode = solution
|
||||
.get(QueryFieldLabels.GRANT_LABEL);
|
||||
if (grantLabelNode != null) {
|
||||
grant.setActivityLabel(grantLabelNode.toString());
|
||||
}
|
||||
|
||||
RDFNode grantStartDateNode = solution
|
||||
.get(QueryFieldLabels.ROLE_START_DATE);
|
||||
if (grantStartDateNode != null) {
|
||||
grant.setActivityDate(grantStartDateNode.toString());
|
||||
} else {
|
||||
grantStartDateNode = solution
|
||||
.get(QueryFieldLabels.GRANT_START_DATE);
|
||||
if (grantStartDateNode != null) {
|
||||
grant.setActivityDate(grantStartDateNode.toString());
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: Verify grant end date not needed.
|
||||
/*
|
||||
RDFNode grantEndDateNode = solution
|
||||
.get(QueryFieldLabels.ROLE_END_DATE);
|
||||
if (grantEndDateNode != null) {
|
||||
grant.setGrantEndDate(grantEndDateNode.toString());
|
||||
} else {
|
||||
grantEndDateNode = solution
|
||||
.get(QueryFieldLabels.GRANT_END_DATE);
|
||||
if (grantEndDateNode != null) {
|
||||
grant.setGrantEndDate(grantEndDateNode.toString());
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
RDFNode subEntityURLNode = solution.get(SUBENTITY_URL);
|
||||
|
||||
if (subEntityURLNode != null) {
|
||||
SubEntity subEntity;
|
||||
if (subentityURLToVO.containsKey(subEntityURLNode.toString())) {
|
||||
subEntity = subentityURLToVO.get(subEntityURLNode
|
||||
.toString());
|
||||
} else {
|
||||
subEntity = new SubEntity(subEntityURLNode.toString());
|
||||
subentityURLToVO
|
||||
.put(subEntityURLNode.toString(), subEntity);
|
||||
}
|
||||
|
||||
RDFNode subEntityLabelNode = solution.get(SUBENTITY_LABEL);
|
||||
if (subEntityLabelNode != null) {
|
||||
subEntity.setIndividualLabel(subEntityLabelNode.toString());
|
||||
}
|
||||
entity.addSubEntity(subEntity);
|
||||
subEntity.addActivity(grant);
|
||||
}
|
||||
|
||||
RDFNode personURLNode = solution.get(QueryFieldLabels.PERSON_URL);
|
||||
|
||||
if (personURLNode != null) {
|
||||
SubEntity person;
|
||||
|
||||
if (personURLToVO.containsKey(personURLNode.toString())) {
|
||||
person = personURLToVO.get(personURLNode.toString());
|
||||
} else {
|
||||
person = new SubEntity(personURLNode.toString());
|
||||
personURLToVO.put(personURLNode.toString(), person);
|
||||
}
|
||||
|
||||
RDFNode personLabelNode = solution.get(QueryFieldLabels.PERSON_LABEL);
|
||||
if (personLabelNode != null) {
|
||||
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);
|
||||
}
|
||||
|
||||
person.addActivity(grant);
|
||||
|
||||
}
|
||||
|
||||
// entity.addActivity(grant);
|
||||
}
|
||||
|
||||
if (subentityURLToVO.size() == 0 && personURLToVO.size() == 0) {
|
||||
entity = new Entity(this.entityURI, "no-label");
|
||||
}
|
||||
|
||||
after = System.currentTimeMillis();
|
||||
log.debug("Time taken to iterate through the ResultSet of SELECT queries is in ms: "
|
||||
+ (after - before));
|
||||
return entity;
|
||||
}
|
||||
|
||||
private ResultSet executeQuery(String queryURI, Model dataSource2) {
|
||||
|
||||
QueryExecution queryExecution = null;
|
||||
Query query = QueryFactory.create(
|
||||
getSparqlQuery(queryURI), SYNTAX);
|
||||
queryExecution = QueryExecutionFactory.create(query, dataSource2);
|
||||
return queryExecution.execSelect();
|
||||
}
|
||||
|
||||
private String getSparqlQuery(String queryURI) {
|
||||
|
||||
String sparqlQuery = QueryConstants.getSparqlPrefixQuery()
|
||||
+ SPARQL_QUERY_COMMON_SELECT_CLAUSE + " (str(<" + queryURI
|
||||
+ ">) as ?" + ENTITY_URL + ") "
|
||||
+ "WHERE { " + "<" + queryURI + "> rdfs:label ?organizationLabel ."
|
||||
+ "{ "
|
||||
+ "<" + queryURI + "> core:hasSubOrganization ?subOrganization ."
|
||||
+ " ?subOrganization rdfs:label ?subOrganizationLabel ;"
|
||||
+ " core:organizationForPosition ?Position . "
|
||||
+ " ?Position core:positionForPerson ?Person ."
|
||||
+ " ?Person core:hasCo-PrincipalInvestigatorRole ?Role ; rdfs:label ?PersonLabel ."
|
||||
+ SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_ROLE_DATE_TIME
|
||||
+ SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_GRANT_DATE_TIME + "}"
|
||||
+ "UNION "
|
||||
+ "{ "
|
||||
+ "<" + queryURI + "> core:hasSubOrganization ?subOrganization . "
|
||||
+ " ?subOrganization rdfs:label ?subOrganizationLabel ;"
|
||||
+ " core:organizationForPosition ?Position . "
|
||||
+ " ?Position core:positionForPerson ?Person ."
|
||||
+ " ?Person core:hasPrincipalInvestigatorRole ?Role ; rdfs:label ?PersonLabel . "
|
||||
+ SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_ROLE_DATE_TIME
|
||||
+ SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_GRANT_DATE_TIME + "}"
|
||||
+ "UNION "
|
||||
+ "{ "
|
||||
+ "<" + queryURI + "> core:hasSubOrganization ?subOrganization . "
|
||||
+ " ?subOrganization rdfs:label ?subOrganizationLabel ;"
|
||||
+ " core:organizationForPosition ?Position . "
|
||||
+ " ?Position core:positionForPerson ?Person ."
|
||||
+ " ?Person core:hasInvestigatorRole ?Role ; rdfs:label ?PersonLabel . "
|
||||
+ SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_ROLE_DATE_TIME
|
||||
+ SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_GRANT_DATE_TIME + "}"
|
||||
+ "UNION "
|
||||
+ "{ "
|
||||
+ "<" + queryURI + "> core:organizationForPosition ?Position . "
|
||||
+ " ?Position core:positionForPerson ?Person ."
|
||||
+ " ?Person core:hasCo-PrincipalInvestigatorRole ?Role ; rdfs:label ?PersonLabel . "
|
||||
+ SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_ROLE_DATE_TIME
|
||||
+ SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_GRANT_DATE_TIME + "}"
|
||||
+ "UNION "
|
||||
+ "{ "
|
||||
+ "<" + queryURI + "> core:organizationForPosition ?Position . "
|
||||
+ " ?Position core:positionForPerson ?Person ."
|
||||
+ " ?Person core:hasPrincipalInvestigatorRole ?Role ; rdfs:label ?PersonLabel . "
|
||||
+ SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_ROLE_DATE_TIME
|
||||
+ SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_GRANT_DATE_TIME + "}"
|
||||
+ "UNION "
|
||||
+ "{ "
|
||||
+ "<" + queryURI + "> core:organizationForPosition ?Position . "
|
||||
+ " ?Position core:positionForPerson ?Person ."
|
||||
+ " ?Person core:hasInvestigatorRole ?Role ; rdfs:label ?PersonLabel . "
|
||||
+ SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_ROLE_DATE_TIME
|
||||
+ SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_GRANT_DATE_TIME + "}"
|
||||
+ " } ";
|
||||
|
||||
return sparqlQuery;
|
||||
}
|
||||
|
||||
public Entity getQueryResult() throws MalformedQueryParametersException {
|
||||
|
||||
if (StringUtils.isNotBlank(this.entityURI)) {
|
||||
/*
|
||||
* To test for the validity of the URI submitted.
|
||||
*/
|
||||
IRIFactory iRIFactory = IRIFactory.jenaImplementation();
|
||||
IRI iri = iRIFactory.create(this.entityURI);
|
||||
if (iri.hasViolation(false)) {
|
||||
String errorMsg = ((Violation) iri.violations(false).next())
|
||||
.getShortMessage();
|
||||
log.error("Entity Grant Count Query " + errorMsg);
|
||||
throw new MalformedQueryParametersException(
|
||||
"URI provided for an entity is malformed.");
|
||||
}
|
||||
|
||||
} else {
|
||||
throw new MalformedQueryParametersException(
|
||||
"URL parameter is either null or empty.");
|
||||
}
|
||||
|
||||
before = System.currentTimeMillis();
|
||||
|
||||
ResultSet resultSet = executeQuery(this.entityURI, this.dataSource);
|
||||
|
||||
after = System.currentTimeMillis();
|
||||
|
||||
log.debug("Time taken to execute the SELECT queries is in milliseconds: "
|
||||
+ (after - before));
|
||||
|
||||
return createJavaValueObjects(resultSet);
|
||||
}
|
||||
}
|
|
@ -1,357 +0,0 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.visualization.entitygrantcount;
|
||||
|
||||
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.auth.requestedAction.Actions;
|
||||
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.DataVisualizationController;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.visualization.VisualizationFrameworkConstants;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.constants.VOConstants;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.entitycomparison.OrganizationUtilityFunctions;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.Entity;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.SubEntity;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.json.JsonObject;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.visutils.ModelConstructor;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.visutils.QueryRunner;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.visutils.UtilityFunctions;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.visutils.VisualizationRequestHandler;
|
||||
|
||||
public class EntityGrantCountRequestHandler implements
|
||||
VisualizationRequestHandler {
|
||||
|
||||
@Override
|
||||
public ResponseValues generateStandardVisualization(
|
||||
VitroRequest vitroRequest, Log log, Dataset dataset)
|
||||
throws MalformedQueryParametersException {
|
||||
|
||||
String entityURI = vitroRequest
|
||||
.getParameter(VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY);
|
||||
|
||||
return generateStandardVisualizationForGrantTemporalVis(vitroRequest,
|
||||
log, dataset, entityURI);
|
||||
}
|
||||
|
||||
private ResponseValues generateStandardVisualizationForGrantTemporalVis(
|
||||
VitroRequest vitroRequest, Log log, Dataset dataset,
|
||||
String entityURI) throws MalformedQueryParametersException {
|
||||
if (StringUtils.isBlank(entityURI)) {
|
||||
|
||||
entityURI = OrganizationUtilityFunctions
|
||||
.getStaffProvidedOrComputedHighestLevelOrganization(log,
|
||||
dataset, vitroRequest);
|
||||
|
||||
}
|
||||
return prepareStandaloneMarkupResponse(vitroRequest, entityURI);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseValues generateVisualizationForShortURLRequests(
|
||||
Map<String, String> parameters, VitroRequest vitroRequest, Log log,
|
||||
Dataset dataSource) throws MalformedQueryParametersException {
|
||||
|
||||
return generateStandardVisualizationForGrantTemporalVis(
|
||||
vitroRequest,
|
||||
log,
|
||||
dataSource,
|
||||
parameters
|
||||
.get(VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY));
|
||||
|
||||
}
|
||||
|
||||
@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.JSON_OUTPUT_FORMAT
|
||||
.equalsIgnoreCase(vitroRequest
|
||||
.getParameter(VisualizationFrameworkConstants.VIS_MODE_KEY))) {
|
||||
|
||||
if (StringUtils.isNotBlank(entityURI)) {
|
||||
|
||||
return getSubjectEntityAndGenerateDataResponse(vitroRequest,
|
||||
log, dataset, entityURI);
|
||||
} else {
|
||||
|
||||
return getSubjectEntityAndGenerateDataResponse(
|
||||
vitroRequest,
|
||||
log,
|
||||
dataset,
|
||||
OrganizationUtilityFunctions
|
||||
.getStaffProvidedOrComputedHighestLevelOrganization(
|
||||
log, dataset, vitroRequest));
|
||||
}
|
||||
|
||||
} else {
|
||||
/*
|
||||
* This provides csv download files for the content in the tables.
|
||||
*/
|
||||
ModelConstructor constructQueryRunner = new EntityGrantCountConstructQueryRunner(
|
||||
entityURI, dataset, log);
|
||||
|
||||
Model constructedModel = constructQueryRunner.getConstructedModel();
|
||||
|
||||
QueryRunner<Entity> queryManager = new EntityGrantCountQueryRunner(
|
||||
entityURI, constructedModel, log);
|
||||
|
||||
Entity entity = queryManager.getQueryResult();
|
||||
|
||||
Map<String, Set<String>> subOrganizationTypesResult = OrganizationUtilityFunctions
|
||||
.getSubEntityTypes(log, dataset, entityURI);
|
||||
|
||||
return prepareDataResponse(entity, entity.getSubEntities(),
|
||||
subOrganizationTypesResult);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@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) throws MalformedQueryParametersException {
|
||||
|
||||
ModelConstructor constructQueryRunner = new EntityGrantCountConstructQueryRunner(
|
||||
subjectEntityURI, dataset, log);
|
||||
|
||||
Model constructedModel = constructQueryRunner.getConstructedModel();
|
||||
|
||||
QueryRunner<Entity> queryManager = new EntityGrantCountQueryRunner(
|
||||
subjectEntityURI, constructedModel, log);
|
||||
|
||||
Entity entity = queryManager.getQueryResult();
|
||||
|
||||
if (entity.getEntityLabel().equals("no-label")) {
|
||||
return prepareStandaloneDataErrorResponse(vitroRequest,
|
||||
subjectEntityURI);
|
||||
} else {
|
||||
|
||||
return getSubEntityTypesAndComputeDataResponse(vitroRequest, log,
|
||||
dataset, subjectEntityURI, entity);
|
||||
}
|
||||
}
|
||||
|
||||
private Map<String, String> getSubEntityTypesAndComputeDataResponse(
|
||||
VitroRequest vitroRequest, Log log, Dataset dataset,
|
||||
String subjectOrganization, Entity entity)
|
||||
throws MalformedQueryParametersException {
|
||||
|
||||
Map<String, Set<String>> subOrganizationTypesResult = OrganizationUtilityFunctions
|
||||
.getSubEntityTypes(log, dataset, subjectOrganization);
|
||||
|
||||
return prepareStandaloneDataResponse(vitroRequest, entity,
|
||||
subOrganizationTypesResult);
|
||||
}
|
||||
|
||||
private Map<String, String> prepareStandaloneDataErrorResponse(
|
||||
VitroRequest vitroRequest, String subjectEntityURI) {
|
||||
|
||||
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, Set<String>> subOrganizationTypesResult)
|
||||
throws MalformedQueryParametersException {
|
||||
|
||||
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(),
|
||||
subOrganizationTypesResult));
|
||||
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,
|
||||
Set<SubEntity> subentities,
|
||||
Map<String, Set<String>> subOrganizationTypesResult) {
|
||||
|
||||
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(subentities,
|
||||
subOrganizationTypesResult));
|
||||
return fileData;
|
||||
}
|
||||
|
||||
private TemplateResponseValues prepareStandaloneMarkupResponse(
|
||||
VitroRequest vreq, String entityURI) {
|
||||
|
||||
String standaloneTemplate = "entityComparisonOnGrantsStandalone.ftl";
|
||||
|
||||
String organizationLabel = OrganizationUtilityFunctions
|
||||
.getEntityLabelFromDAO(vreq, entityURI);
|
||||
|
||||
Map<String, Object> body = new HashMap<String, Object>();
|
||||
body
|
||||
.put("title", organizationLabel
|
||||
+ " - Temporal Graph Visualization");
|
||||
body.put("organizationURI", entityURI);
|
||||
body.put("organizationLocalName", UtilityFunctions
|
||||
.getIndividualLocalName(entityURI, vreq));
|
||||
body.put("vivoDefaultNamespace", vreq.getWebappDaoFactory()
|
||||
.getDefaultNamespace());
|
||||
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
|
||||
* @throws MalformedQueryParametersException
|
||||
*/
|
||||
private String writeGrantsOverTimeJSON(VitroRequest vreq,
|
||||
Set<SubEntity> subentities,
|
||||
Map<String, Set<String>> subOrganizationTypesResult)
|
||||
throws MalformedQueryParametersException {
|
||||
|
||||
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.getOrganizationTypes().addAll(
|
||||
subOrganizationTypesResult.get(entityJson.getLabel()));
|
||||
|
||||
entityJson.setEntityURI(subentity.getIndividualURI());
|
||||
|
||||
if (UtilityFunctions.isEntityAPerson(vreq, subentity
|
||||
.getIndividualURI())) {
|
||||
entityJson.setVisMode("PERSON");
|
||||
} else {
|
||||
entityJson.setVisMode("ORGANIZATION");
|
||||
}
|
||||
|
||||
subEntitiesJson.add(entityJson);
|
||||
}
|
||||
|
||||
return json.toJson(subEntitiesJson);
|
||||
|
||||
}
|
||||
|
||||
private String getEntityGrantsPerYearCSVContent(Set<SubEntity> subentities,
|
||||
Map<String, Set<String>> subOrganizationTypesResult) {
|
||||
|
||||
StringBuilder csvFileContent = new StringBuilder();
|
||||
|
||||
csvFileContent.append("Entity Name, Grant Count, Entity Type\n");
|
||||
|
||||
for (SubEntity subEntity : subentities) {
|
||||
|
||||
csvFileContent.append(StringEscapeUtils.escapeCsv(subEntity
|
||||
.getIndividualLabel()));
|
||||
csvFileContent.append(", ");
|
||||
csvFileContent.append(subEntity.getActivities().size());
|
||||
csvFileContent.append(", ");
|
||||
|
||||
StringBuilder joinedTypes = new StringBuilder();
|
||||
|
||||
for (String subOrganizationType : subOrganizationTypesResult
|
||||
.get(subEntity.getIndividualLabel())) {
|
||||
joinedTypes.append(subOrganizationType + "; ");
|
||||
}
|
||||
|
||||
csvFileContent.append(StringEscapeUtils.escapeCsv(joinedTypes
|
||||
.toString()));
|
||||
csvFileContent.append("\n");
|
||||
}
|
||||
|
||||
return csvFileContent.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Actions getRequiredPrivileges() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue