1. Removed unused construct query runner.
2. Refactored all construct query runners to implement a common interface. 3. Changed AjaxVis*Controller & DataVisContoller to use Dataset instead of Datasource.
This commit is contained in:
parent
a4223e7ac6
commit
844c8e30be
16 changed files with 303 additions and 589 deletions
|
@ -11,17 +11,14 @@ import javax.servlet.http.HttpServletResponse;
|
|||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import com.hp.hpl.jena.query.DataSource;
|
||||
import com.hp.hpl.jena.query.DatasetFactory;
|
||||
import com.hp.hpl.jena.query.Dataset;
|
||||
import com.hp.hpl.jena.query.Syntax;
|
||||
import com.hp.hpl.jena.rdf.model.Model;
|
||||
import com.hp.hpl.jena.rdf.model.ModelMaker;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerHttpServlet;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.TemplateProcessingHelper.TemplateProcessingException;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.TemplateResponseValues;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.constants.VisConstants;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.UtilityFunctions;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.VisualizationRequestHandler;
|
||||
|
@ -110,14 +107,14 @@ public class AjaxVisualizationController extends FreemarkerHttpServlet {
|
|||
|
||||
}
|
||||
|
||||
DataSource dataSource = setupJENADataSource(model, vitroRequest);
|
||||
Dataset dataset = setupJENADataSource(vitroRequest);
|
||||
|
||||
if (dataSource != null && visRequestHandler != null) {
|
||||
if (dataset != null && visRequestHandler != null) {
|
||||
|
||||
try {
|
||||
return visRequestHandler.generateAjaxVisualization(vitroRequest,
|
||||
log,
|
||||
dataSource);
|
||||
dataset);
|
||||
} catch (MalformedQueryParametersException e) {
|
||||
return UtilityFunctions.handleMalformedParameters(
|
||||
"Ajax Visualization Query Error - Individual Publication Count",
|
||||
|
@ -160,16 +157,8 @@ public class AjaxVisualizationController extends FreemarkerHttpServlet {
|
|||
return visRequestHandler;
|
||||
}
|
||||
|
||||
private DataSource setupJENADataSource(Model model, VitroRequest vreq) {
|
||||
|
||||
log.debug("rdfResultFormat was: " + VisConstants.RDF_RESULT_FORMAT_PARAM);
|
||||
|
||||
DataSource dataSource = DatasetFactory.create();
|
||||
ModelMaker maker = (ModelMaker) getServletContext().getAttribute("vitroJenaModelMaker");
|
||||
|
||||
dataSource.setDefaultModel(model);
|
||||
|
||||
return dataSource;
|
||||
private Dataset setupJENADataSource(VitroRequest vreq) {
|
||||
return vreq.getDataset();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -12,11 +12,9 @@ import javax.servlet.http.HttpServletResponse;
|
|||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import com.hp.hpl.jena.query.DataSource;
|
||||
import com.hp.hpl.jena.query.DatasetFactory;
|
||||
import com.hp.hpl.jena.query.Dataset;
|
||||
import com.hp.hpl.jena.query.Syntax;
|
||||
import com.hp.hpl.jena.rdf.model.Model;
|
||||
import com.hp.hpl.jena.rdf.model.ModelMaker;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroHttpServlet;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||
|
@ -124,12 +122,12 @@ public class DataVisualizationController extends VitroHttpServlet {
|
|||
throw new MalformedQueryParametersException(errorMessage);
|
||||
}
|
||||
|
||||
DataSource dataSource = setupJENADataSource(model, vitroRequest);
|
||||
Dataset dataset = setupJENADataSource(vitroRequest);
|
||||
|
||||
if (dataSource != null && visRequestHandler != null) {
|
||||
if (dataset != null && visRequestHandler != null) {
|
||||
return visRequestHandler.generateDataVisualization(vitroRequest,
|
||||
log,
|
||||
dataSource);
|
||||
dataset);
|
||||
|
||||
} else {
|
||||
|
||||
|
@ -148,29 +146,24 @@ public class DataVisualizationController extends VitroHttpServlet {
|
|||
.VIS_TYPE_KEY);
|
||||
VisualizationRequestHandler visRequestHandler = null;
|
||||
|
||||
|
||||
try {
|
||||
|
||||
visRequestHandler = VisualizationsDependencyInjector
|
||||
.getVisualizationIDsToClassMap(getServletContext())
|
||||
.get(visType);
|
||||
|
||||
} catch (NullPointerException nullKeyException) {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
return visRequestHandler;
|
||||
}
|
||||
|
||||
private DataSource setupJENADataSource(Model model, VitroRequest vreq) {
|
||||
private Dataset setupJENADataSource(VitroRequest vreq) {
|
||||
|
||||
log.debug("rdfResultFormat was: " + VisConstants.RDF_RESULT_FORMAT_PARAM);
|
||||
|
||||
DataSource dataSource = DatasetFactory.create();
|
||||
ModelMaker maker = (ModelMaker) getServletContext().getAttribute("vitroJenaModelMaker");
|
||||
|
||||
dataSource.setDefaultModel(model);
|
||||
|
||||
return dataSource;
|
||||
return vreq.getDataset();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -5,12 +5,9 @@ package edu.cornell.mannlib.vitro.webapp.controller.visualization.freemarker;
|
|||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import com.hp.hpl.jena.query.DataSource;
|
||||
import com.hp.hpl.jena.query.Dataset;
|
||||
import com.hp.hpl.jena.query.DatasetFactory;
|
||||
import com.hp.hpl.jena.query.Syntax;
|
||||
import com.hp.hpl.jena.rdf.model.Model;
|
||||
import com.hp.hpl.jena.rdf.model.ModelMaker;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerHttpServlet;
|
||||
|
@ -135,11 +132,6 @@ public class StandardVisualizationController extends FreemarkerHttpServlet {
|
|||
|
||||
log.debug("rdfResultFormat was: " + VisConstants.RDF_RESULT_FORMAT_PARAM);
|
||||
|
||||
// DataSource dataSource = DatasetFactory.create();
|
||||
// ModelMaker maker = (ModelMaker) getServletContext().getAttribute("vitroJenaModelMaker");
|
||||
//
|
||||
// dataSource.setDefaultModel(model);
|
||||
|
||||
return vreq.getDataset();
|
||||
}
|
||||
|
||||
|
|
|
@ -22,250 +22,288 @@ import com.hp.hpl.jena.rdf.model.ModelFactory;
|
|||
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.constants.QueryConstants;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.ModelConstructor;
|
||||
|
||||
public class CoPIGrantCountConstructQueryRunner implements ModelConstructor {
|
||||
|
||||
public class CoPIGrantCountConstructQueryRunner {
|
||||
|
||||
protected static final Syntax SYNTAX = Syntax.syntaxARQ;
|
||||
|
||||
|
||||
private String egoURI;
|
||||
|
||||
|
||||
private Dataset Dataset;
|
||||
|
||||
|
||||
private long before, after;
|
||||
|
||||
private Log log = LogFactory.getLog(CoPIGrantCountConstructQueryRunner.class.getName());
|
||||
private Log log = LogFactory
|
||||
.getLog(CoPIGrantCountConstructQueryRunner.class.getName());
|
||||
|
||||
|
||||
private static final String SPARQL_QUERY_COMMON_CONSTRUCT_AND_WHERE_STRING =
|
||||
"?Role core:roleIn ?Grant . "
|
||||
+ "?Grant rdfs:label ?GrantLabel . "
|
||||
+ "?Grant core:relatedRole ?RelatedRole . ";
|
||||
|
||||
public CoPIGrantCountConstructQueryRunner(String egoURI, Dataset Dataset, Log log){
|
||||
private static final String SPARQL_QUERY_COMMON_CONSTRUCT_AND_WHERE_STRING = "?Role core:roleIn ?Grant . "
|
||||
+ "?Grant rdfs:label ?GrantLabel . "
|
||||
+ "?Grant core:relatedRole ?RelatedRole . ";
|
||||
|
||||
public CoPIGrantCountConstructQueryRunner(String egoURI, Dataset Dataset,
|
||||
Log log) {
|
||||
this.egoURI = egoURI;
|
||||
this.Dataset = Dataset;
|
||||
//this.log = log;
|
||||
// this.log = log;
|
||||
}
|
||||
|
||||
private String generateConstructQueryForInvestigatorLabel(String queryURI) {
|
||||
|
||||
String sparqlQuery =
|
||||
"CONSTRUCT { "
|
||||
+ "<"+queryURI+ "> rdfs:label ?investigatorLabel ."
|
||||
+ "}"
|
||||
+ "WHERE {"
|
||||
+ "<"+queryURI+ "> rdfs:label ?investigatorLabel "
|
||||
+ "}";
|
||||
|
||||
|
||||
String sparqlQuery = "CONSTRUCT { " + "<" + queryURI
|
||||
+ "> rdfs:label ?investigatorLabel ." + "}" + "WHERE {" + "<"
|
||||
+ queryURI + "> rdfs:label ?investigatorLabel " + "}";
|
||||
|
||||
return sparqlQuery;
|
||||
}
|
||||
|
||||
private String generateConstructQueryForInvestigatorRoleOfProperty(String queryURI, String preboundProperty){
|
||||
|
||||
String sparqlQuery =
|
||||
"CONSTRUCT { "
|
||||
+ "<"+queryURI+ ">" + preboundProperty + " ?Role . "
|
||||
+ SPARQL_QUERY_COMMON_CONSTRUCT_AND_WHERE_STRING
|
||||
+ "?RelatedRole core:investigatorRoleOf ?coInvestigator ."
|
||||
+ "?coInvestigator rdfs:label ?coInvestigatorLabel . "
|
||||
+ "}"
|
||||
+ "WHERE { "
|
||||
+ "<"+queryURI+ ">" + preboundProperty + " ?Role . "
|
||||
+ SPARQL_QUERY_COMMON_CONSTRUCT_AND_WHERE_STRING
|
||||
+ "?RelatedRole core:investigatorRoleOf ?coInvestigator ."
|
||||
+ "?coInvestigator rdfs:label ?coInvestigatorLabel . "
|
||||
+ "}";
|
||||
|
||||
|
||||
private String generateConstructQueryForInvestigatorRoleOfProperty(
|
||||
String queryURI, String preboundProperty) {
|
||||
|
||||
String sparqlQuery = "CONSTRUCT { " + "<" + queryURI + ">"
|
||||
+ preboundProperty + " ?Role . "
|
||||
+ SPARQL_QUERY_COMMON_CONSTRUCT_AND_WHERE_STRING
|
||||
+ "?RelatedRole core:investigatorRoleOf ?coInvestigator ."
|
||||
+ "?coInvestigator rdfs:label ?coInvestigatorLabel . " + "}"
|
||||
+ "WHERE { " + "<" + queryURI + ">" + preboundProperty
|
||||
+ " ?Role . " + SPARQL_QUERY_COMMON_CONSTRUCT_AND_WHERE_STRING
|
||||
+ "?RelatedRole core:investigatorRoleOf ?coInvestigator ."
|
||||
+ "?coInvestigator rdfs:label ?coInvestigatorLabel . " + "}";
|
||||
|
||||
return sparqlQuery;
|
||||
}
|
||||
|
||||
private String generateConstructQueryForPrincipalInvestigatorRoleOfProperty(String queryURI, String preboundProperty){
|
||||
|
||||
String sparqlQuery =
|
||||
"CONSTRUCT { "
|
||||
+ "<"+queryURI+ ">" + preboundProperty + " ?Role . "
|
||||
+ SPARQL_QUERY_COMMON_CONSTRUCT_AND_WHERE_STRING
|
||||
+ "?RelatedRole core:principalInvestigatorRoleOf ?coInvestigator ."
|
||||
+ "?coInvestigator rdfs:label ?coInvestigatorLabel . "
|
||||
+ "}"
|
||||
+ "WHERE { "
|
||||
+ "<"+queryURI+ ">" + preboundProperty + " ?Role . "
|
||||
+ SPARQL_QUERY_COMMON_CONSTRUCT_AND_WHERE_STRING
|
||||
+ "?RelatedRole core:principalInvestigatorRoleOf ?coInvestigator ."
|
||||
+ "?coInvestigator rdfs:label ?coInvestigatorLabel . "
|
||||
+ "}";
|
||||
|
||||
|
||||
private String generateConstructQueryForPrincipalInvestigatorRoleOfProperty(
|
||||
String queryURI, String preboundProperty) {
|
||||
|
||||
String sparqlQuery = "CONSTRUCT { "
|
||||
+ "<"
|
||||
+ queryURI
|
||||
+ ">"
|
||||
+ preboundProperty
|
||||
+ " ?Role . "
|
||||
+ SPARQL_QUERY_COMMON_CONSTRUCT_AND_WHERE_STRING
|
||||
+ "?RelatedRole core:principalInvestigatorRoleOf ?coInvestigator ."
|
||||
+ "?coInvestigator rdfs:label ?coInvestigatorLabel . "
|
||||
+ "}"
|
||||
+ "WHERE { "
|
||||
+ "<"
|
||||
+ queryURI
|
||||
+ ">"
|
||||
+ preboundProperty
|
||||
+ " ?Role . "
|
||||
+ SPARQL_QUERY_COMMON_CONSTRUCT_AND_WHERE_STRING
|
||||
+ "?RelatedRole core:principalInvestigatorRoleOf ?coInvestigator ."
|
||||
+ "?coInvestigator rdfs:label ?coInvestigatorLabel . " + "}";
|
||||
|
||||
return sparqlQuery;
|
||||
}
|
||||
|
||||
private String generateConstructQueryForCoPrincipalInvestigatorRoleOfProperty(String queryURI, String preboundProperty){
|
||||
|
||||
String sparqlQuery =
|
||||
"CONSTRUCT { "
|
||||
+ "<"+queryURI+ ">" + preboundProperty + " ?Role . "
|
||||
+ SPARQL_QUERY_COMMON_CONSTRUCT_AND_WHERE_STRING
|
||||
+ "?RelatedRole core:co-PrincipalInvestigatorRoleOf ?coInvestigator ."
|
||||
+ "?coInvestigator rdfs:label ?coInvestigatorLabel . "
|
||||
+ "}"
|
||||
+ "WHERE { "
|
||||
+ "<"+queryURI+ ">" + preboundProperty + " ?Role . "
|
||||
+ SPARQL_QUERY_COMMON_CONSTRUCT_AND_WHERE_STRING
|
||||
+ "?RelatedRole core:co-PrincipalInvestigatorRoleOf ?coInvestigator ."
|
||||
+ "?coInvestigator rdfs:label ?coInvestigatorLabel . "
|
||||
+ "}";
|
||||
|
||||
}
|
||||
|
||||
private String generateConstructQueryForCoPrincipalInvestigatorRoleOfProperty(
|
||||
String queryURI, String preboundProperty) {
|
||||
|
||||
String sparqlQuery = "CONSTRUCT { "
|
||||
+ "<"
|
||||
+ queryURI
|
||||
+ ">"
|
||||
+ preboundProperty
|
||||
+ " ?Role . "
|
||||
+ SPARQL_QUERY_COMMON_CONSTRUCT_AND_WHERE_STRING
|
||||
+ "?RelatedRole core:co-PrincipalInvestigatorRoleOf ?coInvestigator ."
|
||||
+ "?coInvestigator rdfs:label ?coInvestigatorLabel . "
|
||||
+ "}"
|
||||
+ "WHERE { "
|
||||
+ "<"
|
||||
+ queryURI
|
||||
+ ">"
|
||||
+ preboundProperty
|
||||
+ " ?Role . "
|
||||
+ SPARQL_QUERY_COMMON_CONSTRUCT_AND_WHERE_STRING
|
||||
+ "?RelatedRole core:co-PrincipalInvestigatorRoleOf ?coInvestigator ."
|
||||
+ "?coInvestigator rdfs:label ?coInvestigatorLabel . " + "}";
|
||||
|
||||
return sparqlQuery;
|
||||
}
|
||||
|
||||
private String generateConstructQueryForDateTimeValueofRole(String queryURI, String preboundProperty){
|
||||
|
||||
String sparqlQuery =
|
||||
"CONSTRUCT { "
|
||||
+ "<"+queryURI+ ">" + preboundProperty + " ?Role . "
|
||||
+ "?Role core:dateTimeInterval ?dateTimeIntervalValue . "
|
||||
+ "?dateTimeIntervalValue core:start ?startDate . "
|
||||
+ "?startDate core:dateTime ?startDateTimeValue . "
|
||||
+ "?dateTimeIntervalValue core:end ?endDate . "
|
||||
+ "?endDate core:dateTime ?endDateTimeValue . "
|
||||
+ "}"
|
||||
+ "WHERE { "
|
||||
+ "{"
|
||||
+ "<"+queryURI+ ">" + preboundProperty + " ?Role . "
|
||||
+ "?Role core:dateTimeInterval ?dateTimeIntervalValue . "
|
||||
+ "?dateTimeIntervalValue core:start ?startDate . "
|
||||
+ "?startDate core:dateTime ?startDateTimeValue . "
|
||||
+ "} UNION "
|
||||
+ "{"
|
||||
+ "<"+queryURI+ ">" + preboundProperty + " ?Role . "
|
||||
+ "?Role core:dateTimeInterval ?dateTimeIntervalValue . "
|
||||
+ "?dateTimeIntervalValue core:end ?endDate . "
|
||||
+ "?endDate core:dateTime ?endDateTimeValue . "
|
||||
+ "}"
|
||||
+ "}";
|
||||
|
||||
}
|
||||
|
||||
private String generateConstructQueryForDateTimeValueofRole(
|
||||
String queryURI, String preboundProperty) {
|
||||
|
||||
String sparqlQuery = "CONSTRUCT { " + "<" + queryURI + ">"
|
||||
+ preboundProperty + " ?Role . "
|
||||
+ "?Role core:dateTimeInterval ?dateTimeIntervalValue . "
|
||||
+ "?dateTimeIntervalValue core:start ?startDate . "
|
||||
+ "?startDate core:dateTime ?startDateTimeValue . "
|
||||
+ "?dateTimeIntervalValue core:end ?endDate . "
|
||||
+ "?endDate core:dateTime ?endDateTimeValue . " + "}"
|
||||
+ "WHERE { " + "{" + "<" + queryURI + ">" + preboundProperty
|
||||
+ " ?Role . "
|
||||
+ "?Role core:dateTimeInterval ?dateTimeIntervalValue . "
|
||||
+ "?dateTimeIntervalValue core:start ?startDate . "
|
||||
+ "?startDate core:dateTime ?startDateTimeValue . "
|
||||
+ "} UNION " + "{" + "<" + queryURI + ">" + 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+ ">" + 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+ ">" + preboundProperty + " ?Role . "
|
||||
+ "?Role core:roleIn ?Grant ."
|
||||
+ "?Grant core:dateTimeInterval ?dateTimeIntervalValueForGrant . "
|
||||
+ "?dateTimeIntervalValueForGrant core:start ?startDateForGrant . "
|
||||
+ "?startDateForGrant core:dateTime ?startDateTimeValueForGrant . "
|
||||
+ "} UNION "
|
||||
+ "{"
|
||||
+ "<"+queryURI+ ">" + preboundProperty + " ?Role . "
|
||||
+ "?Role core:roleIn ?Grant ."
|
||||
+ "?Grant core:dateTimeInterval ?dateTimeIntervalValueForGrant . "
|
||||
+ "?dateTimeIntervalValueForGrant core:end ?endDateForGrant . "
|
||||
+ "?endDateForGrant core:dateTime ?endDateTimeValueForGrant . "
|
||||
+ "}"
|
||||
+ "}";
|
||||
|
||||
}
|
||||
|
||||
private String generateConstructQueryForDateTimeValueofGrant(
|
||||
String queryURI, String preboundProperty) {
|
||||
|
||||
String sparqlQuery = "CONSTRUCT { " + "<"
|
||||
+ queryURI
|
||||
+ ">"
|
||||
+ 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
|
||||
+ ">"
|
||||
+ preboundProperty
|
||||
+ " ?Role . "
|
||||
+ "?Role core:roleIn ?Grant ."
|
||||
+ "?Grant core:dateTimeInterval ?dateTimeIntervalValueForGrant . "
|
||||
+ "?dateTimeIntervalValueForGrant core:start ?startDateForGrant . "
|
||||
+ "?startDateForGrant core:dateTime ?startDateTimeValueForGrant . "
|
||||
+ "} UNION "
|
||||
+ "{"
|
||||
+ "<"
|
||||
+ queryURI
|
||||
+ ">"
|
||||
+ preboundProperty
|
||||
+ " ?Role . "
|
||||
+ "?Role core:roleIn ?Grant ."
|
||||
+ "?Grant core:dateTimeInterval ?dateTimeIntervalValueForGrant . "
|
||||
+ "?dateTimeIntervalValueForGrant core:end ?endDateForGrant . "
|
||||
+ "?endDateForGrant core:dateTime ?endDateTimeValueForGrant . "
|
||||
+ "}" + "}";
|
||||
|
||||
return sparqlQuery;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private Model executeQuery(Set<String> constructQueries, Dataset Dataset) {
|
||||
|
||||
Model constructedModel = ModelFactory.createDefaultModel();
|
||||
|
||||
Model constructedModel = ModelFactory.createDefaultModel();
|
||||
|
||||
for (String queryString : constructQueries) {
|
||||
|
||||
before = System.currentTimeMillis();
|
||||
for (String queryString : constructQueries) {
|
||||
|
||||
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 query is in milliseconds: " + (after - before) );
|
||||
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 query is in milliseconds: "
|
||||
+ (after - before));
|
||||
|
||||
}
|
||||
|
||||
return constructedModel;
|
||||
}
|
||||
|
||||
public Model getConstructedModel()
|
||||
throws MalformedQueryParametersException {
|
||||
}
|
||||
|
||||
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 HashSet<String>();
|
||||
|
||||
populateConstructQueries(constructQueries);
|
||||
|
||||
Model model = executeQuery(constructQueries, this.Dataset);
|
||||
|
||||
return model;
|
||||
|
||||
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 HashSet<String>();
|
||||
|
||||
populateConstructQueries(constructQueries);
|
||||
|
||||
Model model = executeQuery(constructQueries,
|
||||
this.Dataset);
|
||||
|
||||
return model;
|
||||
|
||||
}
|
||||
|
||||
private void populateConstructQueries(Set<String> constructQueries) {
|
||||
|
||||
constructQueries.add(generateConstructQueryForInvestigatorLabel(this.egoURI));
|
||||
constructQueries.add(generateConstructQueryForInvestigatorRoleOfProperty(this.egoURI, "core:hasInvestigatorRole"));
|
||||
constructQueries.add(generateConstructQueryForCoPrincipalInvestigatorRoleOfProperty(this.egoURI, "core:hasInvestigatorRole"));
|
||||
constructQueries.add(generateConstructQueryForPrincipalInvestigatorRoleOfProperty(this.egoURI, "core:hasInvestigatorRole"));
|
||||
constructQueries.add(generateConstructQueryForDateTimeValueofRole(this.egoURI, "core:hasInvestigatorRole"));
|
||||
constructQueries.add(generateConstructQueryForDateTimeValueofGrant(this.egoURI, "core:hasInvestigatorRole"));
|
||||
|
||||
constructQueries.add(generateConstructQueryForInvestigatorRoleOfProperty(this.egoURI, "core:hasPrincipalInvestigatorRole"));
|
||||
constructQueries.add(generateConstructQueryForCoPrincipalInvestigatorRoleOfProperty(this.egoURI, "core:hasPrincipalInvestigatorRole"));
|
||||
constructQueries.add(generateConstructQueryForPrincipalInvestigatorRoleOfProperty(this.egoURI, "core:hasPrincipalInvestigatorRole"));
|
||||
constructQueries.add(generateConstructQueryForDateTimeValueofRole(this.egoURI, "core:hasPrincipalInvestigatorRole"));
|
||||
constructQueries.add(generateConstructQueryForDateTimeValueofGrant(this.egoURI, "core:hasPrincipalInvestigatorRole"));
|
||||
|
||||
constructQueries.add(generateConstructQueryForInvestigatorRoleOfProperty(this.egoURI, "core:hasCo-PrincipalInvestigatorRole"));
|
||||
constructQueries.add(generateConstructQueryForCoPrincipalInvestigatorRoleOfProperty(this.egoURI, "core:hasCo-PrincipalInvestigatorRole"));
|
||||
constructQueries.add(generateConstructQueryForPrincipalInvestigatorRoleOfProperty(this.egoURI, "core:hasCo-PrincipalInvestigatorRole"));
|
||||
constructQueries.add(generateConstructQueryForDateTimeValueofRole(this.egoURI, "core:hasCo-PrincipalInvestigatorRole"));
|
||||
constructQueries.add(generateConstructQueryForDateTimeValueofGrant(this.egoURI, "core:hasCo-PrincipalInvestigatorRole"));
|
||||
|
||||
}
|
||||
constructQueries
|
||||
.add(generateConstructQueryForInvestigatorLabel(this.egoURI));
|
||||
constructQueries
|
||||
.add(generateConstructQueryForInvestigatorRoleOfProperty(
|
||||
this.egoURI, "core:hasInvestigatorRole"));
|
||||
constructQueries
|
||||
.add(generateConstructQueryForCoPrincipalInvestigatorRoleOfProperty(
|
||||
this.egoURI, "core:hasInvestigatorRole"));
|
||||
constructQueries
|
||||
.add(generateConstructQueryForPrincipalInvestigatorRoleOfProperty(
|
||||
this.egoURI, "core:hasInvestigatorRole"));
|
||||
constructQueries.add(generateConstructQueryForDateTimeValueofRole(
|
||||
this.egoURI, "core:hasInvestigatorRole"));
|
||||
constructQueries.add(generateConstructQueryForDateTimeValueofGrant(
|
||||
this.egoURI, "core:hasInvestigatorRole"));
|
||||
|
||||
constructQueries
|
||||
.add(generateConstructQueryForInvestigatorRoleOfProperty(
|
||||
this.egoURI, "core:hasPrincipalInvestigatorRole"));
|
||||
constructQueries
|
||||
.add(generateConstructQueryForCoPrincipalInvestigatorRoleOfProperty(
|
||||
this.egoURI, "core:hasPrincipalInvestigatorRole"));
|
||||
constructQueries
|
||||
.add(generateConstructQueryForPrincipalInvestigatorRoleOfProperty(
|
||||
this.egoURI, "core:hasPrincipalInvestigatorRole"));
|
||||
constructQueries.add(generateConstructQueryForDateTimeValueofRole(
|
||||
this.egoURI, "core:hasPrincipalInvestigatorRole"));
|
||||
constructQueries.add(generateConstructQueryForDateTimeValueofGrant(
|
||||
this.egoURI, "core:hasPrincipalInvestigatorRole"));
|
||||
|
||||
constructQueries
|
||||
.add(generateConstructQueryForInvestigatorRoleOfProperty(
|
||||
this.egoURI, "core:hasCo-PrincipalInvestigatorRole"));
|
||||
constructQueries
|
||||
.add(generateConstructQueryForCoPrincipalInvestigatorRoleOfProperty(
|
||||
this.egoURI, "core:hasCo-PrincipalInvestigatorRole"));
|
||||
constructQueries
|
||||
.add(generateConstructQueryForPrincipalInvestigatorRoleOfProperty(
|
||||
this.egoURI, "core:hasCo-PrincipalInvestigatorRole"));
|
||||
constructQueries.add(generateConstructQueryForDateTimeValueofRole(
|
||||
this.egoURI, "core:hasCo-PrincipalInvestigatorRole"));
|
||||
constructQueries.add(generateConstructQueryForDateTimeValueofGrant(
|
||||
this.egoURI, "core:hasCo-PrincipalInvestigatorRole"));
|
||||
|
||||
}
|
||||
}
|
|
@ -13,15 +13,14 @@ import org.apache.commons.logging.Log;
|
|||
import com.hp.hpl.jena.query.Dataset;
|
||||
import com.hp.hpl.jena.rdf.model.Model;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Portal;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ResponseValues;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.TemplateResponseValues;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.visualization.freemarker.DataVisualizationController;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.visualization.freemarker.VisualizationFrameworkConstants;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.collaborationutils.CollaborationData;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.valueobjects.Collaborator;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.ModelConstructor;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.QueryRunner;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.UtilityFunctions;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.VisualizationRequestHandler;
|
||||
|
@ -46,7 +45,7 @@ public class CoPIGrantCountRequestHandler implements VisualizationRequestHandler
|
|||
String egoURI = vitroRequest.getParameter(VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY);
|
||||
String visMode = vitroRequest.getParameter(VisualizationFrameworkConstants.VIS_MODE_KEY);
|
||||
|
||||
CoPIGrantCountConstructQueryRunner constructQueryRunner = new CoPIGrantCountConstructQueryRunner(egoURI, Dataset, log);
|
||||
ModelConstructor constructQueryRunner = new CoPIGrantCountConstructQueryRunner(egoURI, Dataset, log);
|
||||
Model constructedModel = constructQueryRunner.getConstructedModel();
|
||||
|
||||
QueryRunner<CollaborationData> queryManager = new CoPIGrantCountQueryRunner(egoURI, constructedModel, log);
|
||||
|
@ -104,51 +103,12 @@ public class CoPIGrantCountRequestHandler implements VisualizationRequestHandler
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* When the page for person level visualization is requested.
|
||||
* @param egoURI
|
||||
* @param vitroRequest
|
||||
* @param coPIVO
|
||||
*/
|
||||
private TemplateResponseValues prepareStandaloneResponse(String egoURI,
|
||||
CollaborationData coPIVO, VitroRequest vitroRequest) {
|
||||
|
||||
Portal portal = vitroRequest.getPortal();
|
||||
|
||||
String title = "";
|
||||
Map<String, Object> body = new HashMap<String, Object>();
|
||||
|
||||
|
||||
if (coPIVO.getCollaborators() != null
|
||||
&& coPIVO.getCollaborators().size() > 0) {
|
||||
title = coPIVO.getEgoCollaborator().getCollaboratorName() + " - ";
|
||||
body.put("numOfInvestigators", coPIVO.getCollaborators().size());
|
||||
|
||||
title = coPIVO.getEgoCollaborator().getCollaboratorName() + " - ";
|
||||
}
|
||||
|
||||
if (coPIVO.getCollaborations() != null
|
||||
&& coPIVO.getCollaborations().size() > 0) {
|
||||
body.put("numOfCoInvestigations", coPIVO.getCollaborations().size());
|
||||
}
|
||||
|
||||
String standaloneTemplate = "coInvestigation.ftl";
|
||||
|
||||
body.put("portalBean", portal);
|
||||
body.put("egoURIParam", egoURI);
|
||||
body.put("title", title + "Co-PI Visualization");
|
||||
|
||||
return new TemplateResponseValues(standaloneTemplate, body);
|
||||
}
|
||||
|
||||
|
||||
private String getCoPIsListCSVContent(CollaborationData coPIData) {
|
||||
|
||||
StringBuilder csvFileContent = new StringBuilder();
|
||||
|
||||
csvFileContent.append("Co-investigator, Count\n");
|
||||
|
||||
// for (Entry<String, Integer> currentEntry : coPIData.entrySet()) {
|
||||
for (Collaborator currNode : coPIData.getCollaborators()) {
|
||||
|
||||
/*
|
||||
|
|
|
@ -24,6 +24,7 @@ import edu.cornell.mannlib.vitro.webapp.visualization.constants.QueryFieldLabels
|
|||
import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.valueobjects.GenericQueryMap;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.GenericQueryRunner;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.ModelConstructor;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.QueryRunner;
|
||||
|
||||
public class EntityComparisonUtilityFunctions {
|
||||
|
@ -102,7 +103,7 @@ public class EntityComparisonUtilityFunctions {
|
|||
Dataset Dataset, String subjectOrganization)
|
||||
throws MalformedQueryParametersException {
|
||||
|
||||
EntitySubOrganizationTypesConstructQueryRunner constructQueryRunnerForSubOrganizationTypes = new EntitySubOrganizationTypesConstructQueryRunner(subjectOrganization, Dataset, log) ;
|
||||
ModelConstructor constructQueryRunnerForSubOrganizationTypes = new EntitySubOrganizationTypesConstructQueryRunner(subjectOrganization, Dataset, log) ;
|
||||
Model constructedModelForSubOrganizationTypes = constructQueryRunnerForSubOrganizationTypes.getConstructedModel();
|
||||
|
||||
QueryRunner<Map<String, Set<String>>> queryManagerForsubOrganisationTypes = new EntitySubOrganizationTypesQueryRunner(
|
||||
|
|
|
@ -22,8 +22,9 @@ import com.hp.hpl.jena.rdf.model.ModelFactory;
|
|||
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.constants.QueryConstants;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.ModelConstructor;
|
||||
|
||||
public class EntityPublicationCountConstructQueryRunner {
|
||||
public class EntityPublicationCountConstructQueryRunner implements ModelConstructor{
|
||||
|
||||
protected static final Syntax SYNTAX = Syntax.syntaxARQ;
|
||||
|
||||
|
|
|
@ -12,7 +12,6 @@ import java.util.Set;
|
|||
import org.apache.commons.lang.StringEscapeUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.hp.hpl.jena.query.Dataset;
|
||||
|
@ -29,6 +28,7 @@ import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryP
|
|||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.valueobjects.Entity;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.valueobjects.JsonObject;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.valueobjects.SubEntity;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.ModelConstructor;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.QueryRunner;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.UtilityFunctions;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.VisualizationRequestHandler;
|
||||
|
@ -36,8 +36,6 @@ import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.Visual
|
|||
public class EntityPublicationCountRequestHandler implements
|
||||
VisualizationRequestHandler {
|
||||
|
||||
private Log log = LogFactory.getLog(EntityPublicationCountRequestHandler.class.getName());
|
||||
|
||||
@Override
|
||||
public ResponseValues generateStandardVisualization(
|
||||
VitroRequest vitroRequest, Log log, Dataset Dataset)
|
||||
|
@ -59,7 +57,7 @@ public class EntityPublicationCountRequestHandler implements
|
|||
String subjectEntityURI)
|
||||
throws MalformedQueryParametersException {
|
||||
|
||||
EntityPublicationCountConstructQueryRunner constructQueryRunner = new EntityPublicationCountConstructQueryRunner(subjectEntityURI, Dataset, log);
|
||||
ModelConstructor constructQueryRunner = new EntityPublicationCountConstructQueryRunner(subjectEntityURI, Dataset, log);
|
||||
Model constructedModel = constructQueryRunner.getConstructedModel();
|
||||
|
||||
QueryRunner<Entity> queryManager = new EntityPublicationCountQueryRunner(
|
||||
|
@ -140,7 +138,7 @@ public class EntityPublicationCountRequestHandler implements
|
|||
* This provides csv download files for the content in the tables.
|
||||
* */
|
||||
|
||||
EntityPublicationCountConstructQueryRunner constructQueryRunner = new EntityPublicationCountConstructQueryRunner(entityURI, Dataset, log);
|
||||
ModelConstructor constructQueryRunner = new EntityPublicationCountConstructQueryRunner(entityURI, Dataset, log);
|
||||
Model constructedModel = constructQueryRunner.getConstructedModel();
|
||||
|
||||
QueryRunner<Entity> queryManager = new EntityPublicationCountQueryRunner(
|
||||
|
@ -232,33 +230,6 @@ public class EntityPublicationCountRequestHandler implements
|
|||
return new TemplateResponseValues(standaloneTemplate, body);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @deprecated This method should not be called anymore although the templates being
|
||||
* called by this method are still in use, so we should not get rid of it.
|
||||
* @param vitroRequest
|
||||
* @param entityURI
|
||||
* @return
|
||||
*/
|
||||
private ResponseValues prepareStandaloneErrorResponse(
|
||||
VitroRequest vitroRequest, String entityURI) {
|
||||
|
||||
Portal portal = vitroRequest.getPortal();
|
||||
String standaloneTemplate = "entityPublicationComparisonError.ftl";
|
||||
Map<String, Object> body = new HashMap<String, Object>();
|
||||
|
||||
String organizationLabel = EntityComparisonUtilityFunctions.getEntityLabelFromDAO(vitroRequest,
|
||||
entityURI);
|
||||
|
||||
body.put("organizationLabel", organizationLabel);
|
||||
body.put("portalBean", portal);
|
||||
body.put("title", organizationLabel + " - Temporal Graph Visualization");
|
||||
body.put("organizationURI", entityURI);
|
||||
|
||||
return new TemplateResponseValues(standaloneTemplate, body);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* function to generate a json file for year <-> publication count mapping
|
||||
* @param vreq
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
package edu.cornell.mannlib.vitro.webapp.visualization.freemarker.entitycomparison;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -23,8 +22,9 @@ import com.hp.hpl.jena.rdf.model.ModelFactory;
|
|||
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.constants.QueryConstants;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.ModelConstructor;
|
||||
|
||||
public class EntitySubOrganizationTypesConstructQueryRunner {
|
||||
public class EntitySubOrganizationTypesConstructQueryRunner implements ModelConstructor {
|
||||
|
||||
protected static final Syntax SYNTAX = Syntax.syntaxARQ;
|
||||
|
||||
|
|
|
@ -23,8 +23,9 @@ import com.hp.hpl.jena.rdf.model.ModelFactory;
|
|||
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.constants.QueryConstants;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.ModelConstructor;
|
||||
|
||||
public class EntityGrantCountConstructQueryRunner {
|
||||
public class EntityGrantCountConstructQueryRunner implements ModelConstructor {
|
||||
|
||||
protected static final Syntax SYNTAX = Syntax.syntaxARQ;
|
||||
|
||||
|
|
|
@ -12,7 +12,6 @@ import java.util.Set;
|
|||
import org.apache.commons.lang.StringEscapeUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.hp.hpl.jena.query.Dataset;
|
||||
|
@ -30,6 +29,7 @@ import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.entitycompariso
|
|||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.valueobjects.Entity;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.valueobjects.JsonObject;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.valueobjects.SubEntity;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.ModelConstructor;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.QueryRunner;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.UtilityFunctions;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.VisualizationRequestHandler;
|
||||
|
@ -38,8 +38,6 @@ import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.Visual
|
|||
public class EntityGrantCountRequestHandler implements
|
||||
VisualizationRequestHandler {
|
||||
|
||||
private Log log = LogFactory.getLog(EntityGrantCountRequestHandler.class.getName());
|
||||
|
||||
@Override
|
||||
public ResponseValues generateStandardVisualization(
|
||||
VitroRequest vitroRequest, Log log, Dataset Dataset)
|
||||
|
@ -66,7 +64,7 @@ public class EntityGrantCountRequestHandler implements
|
|||
.getParameter(VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY);
|
||||
|
||||
/*
|
||||
* This will provide the data in json format mainly used for standalone tmeporal vis.
|
||||
* This will provide the data in json format mainly used for standalone temporal vis.
|
||||
* */
|
||||
if (VisualizationFrameworkConstants.TEMPORAL_GRAPH_JSON_DATA_VIS_MODE
|
||||
.equalsIgnoreCase(vitroRequest.getParameter(VisualizationFrameworkConstants.VIS_MODE_KEY))) {
|
||||
|
@ -95,7 +93,7 @@ public class EntityGrantCountRequestHandler implements
|
|||
* This provides csv download files for the content in the tables.
|
||||
* */
|
||||
|
||||
EntityGrantCountConstructQueryRunner constructQueryRunner = new EntityGrantCountConstructQueryRunner(entityURI, Dataset, log);
|
||||
ModelConstructor constructQueryRunner = new EntityGrantCountConstructQueryRunner(entityURI, Dataset, log);
|
||||
Model constructedModel = constructQueryRunner.getConstructedModel();
|
||||
|
||||
QueryRunner<Entity> queryManager = new EntityGrantCountQueryRunner(
|
||||
|
@ -124,7 +122,7 @@ public class EntityGrantCountRequestHandler implements
|
|||
String subjectEntityURI)
|
||||
throws MalformedQueryParametersException {
|
||||
|
||||
EntityGrantCountConstructQueryRunner constructQueryRunner = new EntityGrantCountConstructQueryRunner(subjectEntityURI, Dataset, log);
|
||||
ModelConstructor constructQueryRunner = new EntityGrantCountConstructQueryRunner(subjectEntityURI, Dataset, log);
|
||||
Model constructedModel = constructQueryRunner.getConstructedModel();
|
||||
|
||||
QueryRunner<Entity> queryManager = new EntityGrantCountQueryRunner(
|
||||
|
@ -234,32 +232,6 @@ public class EntityGrantCountRequestHandler implements
|
|||
return new TemplateResponseValues(standaloneTemplate, body);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated This method should not be called anymore although the templates being
|
||||
* called by this method are still in use, so we should not get rid of it.
|
||||
* @return
|
||||
*/
|
||||
private ResponseValues prepareStandaloneErrorResponse(
|
||||
VitroRequest vitroRequest, String entityURI) {
|
||||
|
||||
Portal portal = vitroRequest.getPortal();
|
||||
String standaloneTemplate = "entityGrantComparisonError.ftl";
|
||||
Map<String, Object> body = new HashMap<String, Object>();
|
||||
|
||||
String organizationLabel = EntityComparisonUtilityFunctions.getEntityLabelFromDAO(vitroRequest,
|
||||
entityURI);
|
||||
|
||||
body.put("organizationLabel", organizationLabel);
|
||||
|
||||
|
||||
body.put("portalBean", portal);
|
||||
body.put("title", organizationLabel + " - Temporal Graph Visualization");
|
||||
body.put("organizationURI", entityURI);
|
||||
|
||||
return new TemplateResponseValues(standaloneTemplate, body);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* function to generate a json file for year <-> grant count mapping
|
||||
* @param vreq
|
||||
|
@ -293,8 +265,6 @@ public class EntityGrantCountRequestHandler implements
|
|||
yearGrantCount.add(currentGrantYear);
|
||||
}
|
||||
|
||||
// log.info("entityJson.getLabel() : " + entityJson.getLabel() + " subOrganizationTypesResult " + subOrganizationTypesResult.toString());
|
||||
|
||||
entityJson.setYearToActivityCount(yearGrantCount);
|
||||
entityJson.getOrganizationType().addAll(subOrganizationTypesResult.get(entityJson.getLabel()));
|
||||
|
||||
|
@ -308,11 +278,9 @@ public class EntityGrantCountRequestHandler implements
|
|||
entityJson.setVisMode("ORGANIZATION");
|
||||
}
|
||||
|
||||
// setEntityVisMode(entityJson);
|
||||
subEntitiesJson.add(entityJson);
|
||||
}
|
||||
|
||||
// System.out.println("\nStopWords are "+ EntitySubOrganizationTypesQueryRunner.stopWords.toString() + "\n");
|
||||
return json.toJson(subEntitiesJson);
|
||||
|
||||
}
|
||||
|
|
|
@ -1,213 +0,0 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.visualization.freemarker.persongrantcount;
|
||||
|
||||
import java.util.HashSet;
|
||||
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;
|
||||
|
||||
public class PersonGrantCountConstructQueryRunner {
|
||||
|
||||
protected static final Syntax SYNTAX = Syntax.syntaxARQ;
|
||||
|
||||
private String egoURI;
|
||||
|
||||
private Dataset Dataset;
|
||||
|
||||
private Log log = LogFactory.getLog(PersonGrantCountConstructQueryRunner.class.getName());
|
||||
|
||||
public PersonGrantCountConstructQueryRunner(String egoURI, Dataset Dataset, Log log){
|
||||
this.egoURI = egoURI;
|
||||
this.Dataset = Dataset;
|
||||
//this.log = log;
|
||||
}
|
||||
|
||||
private String generateConstructQueryForInvestigatorLabel(String queryURI) {
|
||||
|
||||
String sparqlQuery =
|
||||
"CONSTRUCT { "
|
||||
+ "<"+queryURI+ "> rdfs:label ?investigatorLabel ."
|
||||
+ "}"
|
||||
+ "WHERE {"
|
||||
+ "<"+queryURI+ "> rdfs:label ?investigatorLabel "
|
||||
+ "}";
|
||||
|
||||
return sparqlQuery;
|
||||
}
|
||||
|
||||
private String generateConstructQueryForInvestigatorGrants(String queryURI, String preboundProperty){
|
||||
|
||||
String sparqlQuery = ""
|
||||
+ "CONSTRUCT { "
|
||||
+ "<"+queryURI+ ">" + preboundProperty + " ?Role . "
|
||||
+ "?Role core:roleIn ?Grant ."
|
||||
+ "?Grant rdfs:label ?GrantLabel "
|
||||
+ "} "
|
||||
+ "WHERE { "
|
||||
+ "<"+queryURI+ ">" + preboundProperty + " ?Role . "
|
||||
+ "?Role core:roleIn ?Grant ."
|
||||
+ "?Grant rdfs:label ?GrantLabel "
|
||||
+ "} ";
|
||||
|
||||
return sparqlQuery;
|
||||
|
||||
}
|
||||
|
||||
private String generateConstructQueryForDateTimeValueofRole(String queryURI, String preboundProperty){
|
||||
|
||||
String sparqlQuery =
|
||||
"CONSTRUCT { "
|
||||
+ "<"+queryURI+ ">" + preboundProperty + " ?Role . "
|
||||
+ "?Role core:dateTimeInterval ?dateTimeIntervalValue . "
|
||||
+ "?dateTimeIntervalValue core:start ?startDate . "
|
||||
+ "?startDate core:dateTime ?startDateTimeValue . "
|
||||
+ "?dateTimeIntervalValue core:end ?endDate . "
|
||||
+ "?endDate core:dateTime ?endDateTimeValue . "
|
||||
+ "}"
|
||||
+ "WHERE { "
|
||||
+ "{"
|
||||
+ "<"+queryURI+ ">" + preboundProperty + " ?Role . "
|
||||
+ "?Role core:dateTimeInterval ?dateTimeIntervalValue . "
|
||||
+ "?dateTimeIntervalValue core:start ?startDate . "
|
||||
+ "?startDate core:dateTime ?startDateTimeValue . "
|
||||
+ "} UNION "
|
||||
+ "{"
|
||||
+ "<"+queryURI+ ">" + 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+ ">" + 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+ ">" + preboundProperty + " ?Role . "
|
||||
+ "?Role core:roleIn ?Grant ."
|
||||
+ "?Grant core:dateTimeInterval ?dateTimeIntervalValueForGrant . "
|
||||
+ "?dateTimeIntervalValueForGrant core:start ?startDateForGrant . "
|
||||
+ "?startDateForGrant core:dateTime ?startDateTimeValueForGrant . "
|
||||
+ "} UNION "
|
||||
+ "{"
|
||||
+ "<"+queryURI+ ">" + preboundProperty + " ?Role . "
|
||||
+ "?Role core:roleIn ?Grant ."
|
||||
+ "?Grant core:dateTimeInterval ?dateTimeIntervalValueForGrant . "
|
||||
+ "?dateTimeIntervalValueForGrant core:end ?endDateForGrant . "
|
||||
+ "?endDateForGrant core:dateTime ?endDateTimeValueForGrant . "
|
||||
+ "}"
|
||||
+ "}";
|
||||
|
||||
return sparqlQuery;
|
||||
}
|
||||
|
||||
private Model executeQuery(Set<String> constructQueries, Dataset Dataset) {
|
||||
|
||||
Model constructedModel = ModelFactory.createDefaultModel();
|
||||
|
||||
for (String queryString : constructQueries) {
|
||||
long start = 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 construct: " + (System.currentTimeMillis() - start));
|
||||
}
|
||||
|
||||
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("Person 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 HashSet<String>();
|
||||
|
||||
populateConstructQueries(constructQueries);
|
||||
|
||||
Model model = executeQuery(constructQueries,
|
||||
this.Dataset);
|
||||
|
||||
return model;
|
||||
|
||||
}
|
||||
|
||||
private void populateConstructQueries(Set<String> constructQueries) {
|
||||
|
||||
constructQueries.add(generateConstructQueryForInvestigatorLabel(this.egoURI));
|
||||
|
||||
constructQueries.add(generateConstructQueryForInvestigatorGrants(this.egoURI, " core:hasInvestigatorRole "));
|
||||
constructQueries.add(generateConstructQueryForDateTimeValueofRole(this.egoURI, " core:hasInvestigatorRole "));
|
||||
constructQueries.add(generateConstructQueryForDateTimeValueofGrant(this.egoURI, " core:hasInvestigatorRole "));
|
||||
|
||||
constructQueries.add(generateConstructQueryForInvestigatorGrants(this.egoURI, " core:hasPrincipalInvestigatorRole "));
|
||||
constructQueries.add(generateConstructQueryForDateTimeValueofRole(this.egoURI, " core:hasPrincipalInvestigatorRole "));
|
||||
constructQueries.add(generateConstructQueryForDateTimeValueofGrant(this.egoURI, " core:hasPrincipalInvestigatorRole "));
|
||||
|
||||
constructQueries.add(generateConstructQueryForInvestigatorGrants(this.egoURI, " core:hasCo-PrincipalInvestigatorRole "));
|
||||
constructQueries.add(generateConstructQueryForDateTimeValueofRole(this.egoURI, " core:hasCo-PrincipalInvestigatorRole "));
|
||||
constructQueries.add(generateConstructQueryForDateTimeValueofGrant(this.egoURI, " core:hasCo-PrincipalInvestigatorRole "));
|
||||
}
|
||||
|
||||
}
|
|
@ -29,6 +29,7 @@ import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.personpubcount.
|
|||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.personpubcount.PersonPublicationCountVisCodeGenerator;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.valueobjects.Activity;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.valueobjects.SparklineData;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.ModelConstructor;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.QueryRunner;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.UtilityFunctions;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.VisualizationRequestHandler;
|
||||
|
@ -80,7 +81,7 @@ public class PersonLevelRequestHandler implements VisualizationRequestHandler {
|
|||
|
||||
if (VisualizationFrameworkConstants.COPI_VIS_MODE.equalsIgnoreCase(visMode)){
|
||||
|
||||
CoPIGrantCountConstructQueryRunner constructQueryRunner = new CoPIGrantCountConstructQueryRunner(egoURI, Dataset, log);
|
||||
ModelConstructor constructQueryRunner = new CoPIGrantCountConstructQueryRunner(egoURI, Dataset, log);
|
||||
Model constructedModel = constructQueryRunner.getConstructedModel();
|
||||
|
||||
QueryRunner<CollaborationData> coPIQueryManager = new CoPIGrantCountQueryRunner(egoURI, constructedModel, log);
|
||||
|
|
|
@ -45,7 +45,7 @@ VisualizationRequestHandler {
|
|||
|
||||
@Override
|
||||
public Object generateAjaxVisualization(VitroRequest vitroRequest, Log log,
|
||||
Dataset Dataset) throws MalformedQueryParametersException {
|
||||
Dataset dataset) throws MalformedQueryParametersException {
|
||||
|
||||
String personURI = vitroRequest
|
||||
.getParameter(
|
||||
|
@ -61,7 +61,7 @@ VisualizationRequestHandler {
|
|||
|
||||
QueryRunner<Set<Activity>> queryManager = new PersonPublicationCountQueryRunner(
|
||||
personURI,
|
||||
Dataset,
|
||||
dataset,
|
||||
log);
|
||||
|
||||
Set<Activity> authorDocuments = queryManager.getQueryResult();
|
||||
|
@ -97,14 +97,14 @@ VisualizationRequestHandler {
|
|||
|
||||
@Override
|
||||
public Map<String, String> generateDataVisualization(VitroRequest vitroRequest, Log log,
|
||||
Dataset Dataset) throws MalformedQueryParametersException {
|
||||
Dataset dataset) throws MalformedQueryParametersException {
|
||||
|
||||
String personURI = vitroRequest
|
||||
.getParameter(VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY);
|
||||
|
||||
QueryRunner<Set<Activity>> queryManager = new PersonPublicationCountQueryRunner(
|
||||
personURI,
|
||||
Dataset,
|
||||
dataset,
|
||||
log);
|
||||
|
||||
Set<Activity> authorDocuments = queryManager.getQueryResult();
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils;
|
||||
|
||||
import com.hp.hpl.jena.rdf.model.Model;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException;
|
||||
|
||||
public interface ModelConstructor {
|
||||
|
||||
Model getConstructedModel() throws MalformedQueryParametersException;
|
||||
|
||||
}
|
|
@ -5,7 +5,6 @@ import java.util.Map;
|
|||
|
||||
import org.apache.commons.logging.Log;
|
||||
|
||||
import com.hp.hpl.jena.query.DataSource;
|
||||
import com.hp.hpl.jena.query.Dataset;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||
|
@ -22,7 +21,7 @@ import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryP
|
|||
*
|
||||
* @author cdtank
|
||||
*/
|
||||
public interface VisualizationRequestHandler{
|
||||
public interface VisualizationRequestHandler {
|
||||
|
||||
ResponseValues generateStandardVisualization(VitroRequest vitroRequest,
|
||||
Log log,
|
||||
|
@ -34,6 +33,6 @@ public interface VisualizationRequestHandler{
|
|||
|
||||
Map<String, String> generateDataVisualization(VitroRequest vitroRequest,
|
||||
Log log,
|
||||
Dataset dataSource) throws MalformedQueryParametersException;
|
||||
Dataset dataset) throws MalformedQueryParametersException;
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue