1. Added license information in the recetly added freemarker templates.
2. Added Utilities vis to the freemarker branch.
This commit is contained in:
parent
65972bcd75
commit
f15022e264
12 changed files with 534 additions and 6 deletions
|
@ -1,3 +1,4 @@
|
|||
<#-- $This file is distributed under the terms of the license in /doc/license.txt$ -->
|
||||
${headScripts.add("http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js")}
|
||||
${headScripts.add("http://www.google.com/jsapi?autoload=%7B%22modules%22%3A%5B%7B%22name%22%3A%22visualization%22%2C%22version%22%3A%221%22%2C%22packages%22%3A%5B%22areachart%22%2C%22imagesparkline%22%5D%7D%5D%7D")}
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
<#-- $This file is distributed under the terms of the license in /doc/license.txt$ -->
|
||||
<#assign visContainerID = '${sparklineVO.visContainerDivID}'>
|
||||
|
||||
<#if sparklineVO.shortVisMode>
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
<#-- $This file is distributed under the terms of the license in /doc/license.txt$ -->
|
||||
|
||||
${utilityResopnse}
|
|
@ -1,4 +1,4 @@
|
|||
<%-- $This file is distributed under the terms of the license in /doc/license.txt$ --%>
|
||||
<#-- $This file is distributed under the terms of the license in /doc/license.txt$ -->
|
||||
|
||||
<div class="staticPageBackground">
|
||||
|
||||
|
|
|
@ -24,6 +24,8 @@ public class VisualizationFrameworkConstants {
|
|||
* Vis URL prefix that is seen by all the users
|
||||
*/
|
||||
public static final String VISUALIZATION_URL_PREFIX = "/visualization";
|
||||
public static final String FREEMARKERIZED_VISUALIZATION_URL_PREFIX = "/visualizationfm";
|
||||
|
||||
public static final String INDIVIDUAL_URL_PREFIX = "/individual";
|
||||
|
||||
/*
|
||||
|
|
|
@ -60,14 +60,11 @@ public class VisualizationController extends FreemarkerHttpServlet {
|
|||
|
||||
if (StringUtils.equalsIgnoreCase(renderMode, VisualizationFrameworkConstants.DYNAMIC_RENDER_MODE)) {
|
||||
|
||||
System.out.println("inside doing ajax request that is dynamic response");
|
||||
|
||||
Configuration config = getConfig(vreq);
|
||||
TemplateResponseValues trv = (TemplateResponseValues) processRequest(vreq);
|
||||
writeTemplate(trv.getTemplateName(), trv.getMap(), config, request, response);
|
||||
|
||||
} else {
|
||||
System.out.println("inside doing super.doGet that is normal response");
|
||||
super.doGet(request, response);
|
||||
}
|
||||
|
||||
|
|
|
@ -142,8 +142,6 @@ public class PersonPublicationCountRequestHandler implements VisualizationReques
|
|||
sparklineData,
|
||||
yearToPublicationCount);
|
||||
|
||||
// requestDispatcher = request.getRequestDispatcher("/templates/page/blankPage.jsp");
|
||||
|
||||
} else {
|
||||
return prepareStandaloneResponse(vitroRequest,
|
||||
sparklineData);
|
||||
|
|
|
@ -0,0 +1,236 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.visualization.freemarker.utilities;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.hp.hpl.jena.query.DataSource;
|
||||
import com.hp.hpl.jena.query.QuerySolution;
|
||||
import com.hp.hpl.jena.query.ResultSet;
|
||||
import com.hp.hpl.jena.rdf.model.RDFNode;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Portal;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder.ParamMap;
|
||||
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.VisualizationController;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.visualization.VisualizationFrameworkConstants;
|
||||
import edu.cornell.mannlib.vitro.webapp.filestorage.FileServingHelper;
|
||||
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.GenericQueryMap;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.AllPropertiesQueryRunner;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.GenericQueryRunner;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.QueryRunner;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.UtilityFunctions;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.VisualizationRequestHandler;
|
||||
|
||||
/**
|
||||
* This request handler is used when you need helpful information to add more context
|
||||
* to the visualization. It does not have any code for generating the visualization,
|
||||
* just fires sparql queries to get info for specific cases like,
|
||||
* 1. thumbnail/image location for a particular individual
|
||||
* 2. profile information for a particular individual like label, moniker etc
|
||||
* 3. person level vis url for a particular individual
|
||||
* etc.
|
||||
* @author cdtank
|
||||
*/
|
||||
public class UtilitiesRequestHandler implements VisualizationRequestHandler {
|
||||
|
||||
public ResponseValues generateVisualization(VitroRequest vitroRequest,
|
||||
Log log,
|
||||
DataSource dataSource) {
|
||||
|
||||
String individualURI = vitroRequest.getParameter(
|
||||
VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY);
|
||||
|
||||
String visMode = vitroRequest.getParameter(
|
||||
VisualizationFrameworkConstants.VIS_MODE_KEY);
|
||||
|
||||
String preparedURL = "";
|
||||
|
||||
UrlBuilder urlBuilder = new UrlBuilder(vitroRequest.getPortal());
|
||||
|
||||
/*
|
||||
* If the info being requested is about a profile which includes the name, moniker
|
||||
* & image url.
|
||||
* */
|
||||
if (VisualizationFrameworkConstants.PROFILE_INFO_UTILS_VIS_MODE
|
||||
.equalsIgnoreCase(visMode)) {
|
||||
|
||||
|
||||
String filterRule = "?predicate = j.2:mainImage "
|
||||
+ "|| ?predicate = vitro:moniker "
|
||||
+ "|| ?predicate = rdfs:label";
|
||||
|
||||
QueryRunner<GenericQueryMap> profileQueryHandler =
|
||||
new AllPropertiesQueryRunner(individualURI,
|
||||
filterRule,
|
||||
dataSource,
|
||||
log);
|
||||
|
||||
try {
|
||||
|
||||
GenericQueryMap profilePropertiesToValues =
|
||||
profileQueryHandler.getQueryResult();
|
||||
|
||||
profilePropertiesToValues.addEntry("imageContextPath",
|
||||
urlBuilder.getBaseUrl());
|
||||
|
||||
Gson profileInformation = new Gson();
|
||||
|
||||
return prepareUtilitiesResponse(
|
||||
profileInformation.toJson(profilePropertiesToValues),
|
||||
vitroRequest);
|
||||
|
||||
|
||||
|
||||
} catch (MalformedQueryParametersException e) {
|
||||
return UtilityFunctions.handleMalformedParameters(
|
||||
"Visualization Query Error - Utilities Profile Info",
|
||||
e.getMessage(),
|
||||
vitroRequest);
|
||||
}
|
||||
} else if (VisualizationFrameworkConstants.IMAGE_UTILS_VIS_MODE
|
||||
.equalsIgnoreCase(visMode)) {
|
||||
/*
|
||||
* If the url being requested is about a standalone image, which is used when we
|
||||
* want to render an image & other info for a co-author OR ego for that matter.
|
||||
* */
|
||||
|
||||
Map<String, String> fieldLabelToOutputFieldLabel = new HashMap<String, String>();
|
||||
fieldLabelToOutputFieldLabel.put("downloadLocation",
|
||||
QueryFieldLabels.THUMBNAIL_LOCATION_URL);
|
||||
fieldLabelToOutputFieldLabel.put("fileName", QueryFieldLabels.THUMBNAIL_FILENAME);
|
||||
|
||||
String whereClause = "<" + individualURI
|
||||
+ "> j.2:thumbnailImage ?thumbnailImage . "
|
||||
+ "?thumbnailImage j.2:downloadLocation "
|
||||
+ "?downloadLocation ; j.2:filename ?fileName .";
|
||||
|
||||
|
||||
|
||||
QueryRunner<ResultSet> imageQueryHandler =
|
||||
new GenericQueryRunner(individualURI,
|
||||
fieldLabelToOutputFieldLabel,
|
||||
whereClause,
|
||||
dataSource,
|
||||
log);
|
||||
|
||||
try {
|
||||
|
||||
String thumbnailAccessURL =
|
||||
getThumbnailInformation(
|
||||
imageQueryHandler.getQueryResult(),
|
||||
fieldLabelToOutputFieldLabel);
|
||||
|
||||
return prepareUtilitiesResponse(thumbnailAccessURL, vitroRequest);
|
||||
|
||||
} catch (MalformedQueryParametersException e) {
|
||||
return UtilityFunctions.handleMalformedParameters(
|
||||
"Visualization Query Error - Utilities Image Info",
|
||||
e.getMessage(),
|
||||
vitroRequest);
|
||||
}
|
||||
} else if (VisualizationFrameworkConstants.COAUTHOR_UTILS_VIS_MODE
|
||||
.equalsIgnoreCase(visMode)) {
|
||||
|
||||
/*
|
||||
* By default we will be generating profile url else some specific url like
|
||||
* coAuthorShip vis url for that individual.
|
||||
* */
|
||||
ParamMap coAuthorProfileURLParams = new ParamMap(VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY,
|
||||
individualURI,
|
||||
VisualizationFrameworkConstants.VIS_TYPE_KEY,
|
||||
VisualizationFrameworkConstants.COAUTHORSHIP_VIS,
|
||||
VisualizationFrameworkConstants.RENDER_MODE_KEY,
|
||||
VisualizationFrameworkConstants.STANDALONE_RENDER_MODE);
|
||||
|
||||
preparedURL = UrlBuilder.getUrl(VisualizationFrameworkConstants.FREEMARKERIZED_VISUALIZATION_URL_PREFIX,
|
||||
coAuthorProfileURLParams);
|
||||
|
||||
|
||||
return prepareUtilitiesResponse(preparedURL, vitroRequest);
|
||||
|
||||
} else if (VisualizationFrameworkConstants.PERSON_LEVEL_UTILS_VIS_MODE
|
||||
.equalsIgnoreCase(visMode)) {
|
||||
/*
|
||||
* By default we will be generating profile url else some specific url like
|
||||
* coAuthorShip vis url for that individual.
|
||||
* */
|
||||
ParamMap personLevelURLParams = new ParamMap(VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY,
|
||||
individualURI,
|
||||
VisualizationFrameworkConstants.VIS_TYPE_KEY,
|
||||
VisualizationFrameworkConstants.PERSON_LEVEL_VIS,
|
||||
VisualizationFrameworkConstants.RENDER_MODE_KEY,
|
||||
VisualizationFrameworkConstants.STANDALONE_RENDER_MODE);
|
||||
|
||||
preparedURL = UrlBuilder.getUrl(VisualizationFrameworkConstants.FREEMARKERIZED_VISUALIZATION_URL_PREFIX,
|
||||
personLevelURLParams);
|
||||
|
||||
return prepareUtilitiesResponse(preparedURL, vitroRequest);
|
||||
} else {
|
||||
|
||||
ParamMap individualProfileURLParams = new ParamMap(VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY,
|
||||
individualURI);
|
||||
|
||||
preparedURL = UrlBuilder.getUrl(VisualizationFrameworkConstants.INDIVIDUAL_URL_PREFIX,
|
||||
individualProfileURLParams);
|
||||
|
||||
return prepareUtilitiesResponse(preparedURL, vitroRequest);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private String getThumbnailInformation(ResultSet resultSet,
|
||||
Map<String, String> fieldLabelToOutputFieldLabel) {
|
||||
|
||||
String finalThumbNailLocation = "";
|
||||
|
||||
while (resultSet.hasNext()) {
|
||||
QuerySolution solution = resultSet.nextSolution();
|
||||
|
||||
|
||||
RDFNode downloadLocationNode = solution.get(
|
||||
fieldLabelToOutputFieldLabel
|
||||
.get("downloadLocation"));
|
||||
RDFNode fileNameNode = solution.get(fieldLabelToOutputFieldLabel.get("fileName"));
|
||||
|
||||
if (downloadLocationNode != null && fileNameNode != null) {
|
||||
finalThumbNailLocation =
|
||||
FileServingHelper
|
||||
.getBytestreamAliasUrl(downloadLocationNode.toString(),
|
||||
fileNameNode.toString());
|
||||
}
|
||||
}
|
||||
return finalThumbNailLocation;
|
||||
}
|
||||
|
||||
private TemplateResponseValues prepareUtilitiesResponse(String preparedContent, VitroRequest vreq) {
|
||||
|
||||
// response.setContentType("text/plain");
|
||||
|
||||
String utilitiesTemplate = "/visualization/utilities.ftl";
|
||||
|
||||
Map<String, Object> body = new HashMap<String, Object>();
|
||||
body.put("utilityResopnse", preparedContent);
|
||||
|
||||
return new TemplateResponseValues(utilitiesTemplate, body);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,148 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.logging.Log;
|
||||
|
||||
import com.hp.hpl.jena.iri.IRI;
|
||||
import com.hp.hpl.jena.iri.IRIFactory;
|
||||
import com.hp.hpl.jena.iri.Violation;
|
||||
import com.hp.hpl.jena.query.DataSource;
|
||||
import com.hp.hpl.jena.query.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 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.GenericQueryMap;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* This query runner is used to execute a sparql query that will fetch all the
|
||||
* properties available for the provided individual URI.
|
||||
*
|
||||
* @author cdtank
|
||||
*/
|
||||
public class AllPropertiesQueryRunner implements QueryRunner<GenericQueryMap> {
|
||||
|
||||
protected static final Syntax SYNTAX = Syntax.syntaxARQ;
|
||||
|
||||
private String filterRule, individualURI;
|
||||
private DataSource dataSource;
|
||||
|
||||
private Log log;
|
||||
|
||||
public AllPropertiesQueryRunner(String individualURI,
|
||||
String filterRule,
|
||||
DataSource dataSource,
|
||||
Log log) {
|
||||
|
||||
this.individualURI = individualURI;
|
||||
this.filterRule = filterRule;
|
||||
this.dataSource = dataSource;
|
||||
this.log = log;
|
||||
|
||||
}
|
||||
|
||||
private GenericQueryMap createJavaValueObjects(ResultSet resultSet) {
|
||||
|
||||
GenericQueryMap queryResult = new GenericQueryMap();
|
||||
|
||||
while (resultSet.hasNext()) {
|
||||
QuerySolution solution = resultSet.nextSolution();
|
||||
|
||||
|
||||
RDFNode predicateNode = solution.get(QueryFieldLabels.PREDICATE);
|
||||
RDFNode objectNode = solution.get(QueryFieldLabels.OBJECT);
|
||||
|
||||
if (predicateNode != null && objectNode != null) {
|
||||
queryResult.addEntry(predicateNode.toString(),
|
||||
objectNode.toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return queryResult;
|
||||
}
|
||||
|
||||
private ResultSet executeQuery(String queryText,
|
||||
DataSource dataSource) {
|
||||
|
||||
QueryExecution queryExecution = null;
|
||||
// try {
|
||||
Query query = QueryFactory.create(queryText, SYNTAX);
|
||||
|
||||
// QuerySolutionMap qs = new QuerySolutionMap();
|
||||
// qs.add("authPerson", queryParam); // bind resource to s
|
||||
|
||||
queryExecution = QueryExecutionFactory.create(query, dataSource);
|
||||
|
||||
// if (query.isSelectType()) {
|
||||
return queryExecution.execSelect();
|
||||
// }
|
||||
// } finally {
|
||||
// if (queryExecution != null) {
|
||||
// queryExecution.close();
|
||||
// }
|
||||
//
|
||||
// }
|
||||
// return null;
|
||||
}
|
||||
|
||||
private String generateGenericSparqlQuery(String queryURI, String filterRule) {
|
||||
// Resource uri1 = ResourceFactory.createResource(queryURI);
|
||||
String filterClause;
|
||||
|
||||
if (StringUtils.isNotBlank(filterRule)) {
|
||||
filterClause = "FILTER ( " + filterRule + " ) . ";
|
||||
} else {
|
||||
filterClause = "";
|
||||
}
|
||||
|
||||
String sparqlQuery = QueryConstants.getSparqlPrefixQuery()
|
||||
+ "SELECT "
|
||||
+ " (str(?predicate) as ?" + QueryFieldLabels.PREDICATE + ") "
|
||||
+ " (str(?object) as ?" + QueryFieldLabels.OBJECT + ") "
|
||||
+ "WHERE { "
|
||||
+ "<" + queryURI + "> ?predicate ?object. "
|
||||
+ filterClause
|
||||
+ "}";
|
||||
|
||||
return sparqlQuery;
|
||||
}
|
||||
|
||||
public GenericQueryMap getQueryResult()
|
||||
throws MalformedQueryParametersException {
|
||||
if (StringUtils.isNotBlank(this.individualURI)) {
|
||||
/*
|
||||
* To test for the validity of the URI submitted.
|
||||
* */
|
||||
IRIFactory iRIFactory = IRIFactory.jenaImplementation();
|
||||
IRI iri = iRIFactory.create(this.individualURI);
|
||||
if (iri.hasViolation(false)) {
|
||||
String errorMsg = ((Violation) iri.violations(false).next()).getShortMessage();
|
||||
log.error("Generic Query " + errorMsg);
|
||||
throw new MalformedQueryParametersException(
|
||||
"URI provided for an individual is malformed.");
|
||||
}
|
||||
|
||||
} else {
|
||||
throw new MalformedQueryParametersException("URI parameter is either null or empty.");
|
||||
}
|
||||
|
||||
ResultSet resultSet = executeQuery(generateGenericSparqlQuery(
|
||||
this.individualURI,
|
||||
this.filterRule),
|
||||
this.dataSource);
|
||||
|
||||
return createJavaValueObjects(resultSet);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,131 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.logging.Log;
|
||||
|
||||
import com.hp.hpl.jena.iri.IRI;
|
||||
import com.hp.hpl.jena.iri.IRIFactory;
|
||||
import com.hp.hpl.jena.iri.Violation;
|
||||
import com.hp.hpl.jena.query.DataSource;
|
||||
import com.hp.hpl.jena.query.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.ResultSet;
|
||||
import com.hp.hpl.jena.query.Syntax;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.constants.QueryConstants;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* This query runner is used to run a generic sparql query based on the "select",
|
||||
* "where" & "filter" rules provided to it.
|
||||
*
|
||||
* @author cdtank
|
||||
*/
|
||||
public class GenericQueryRunner implements QueryRunner<ResultSet> {
|
||||
|
||||
protected static final Syntax SYNTAX = Syntax.syntaxARQ;
|
||||
|
||||
private String whereClause, individualURLParam;
|
||||
private DataSource dataSource;
|
||||
|
||||
private Log log;
|
||||
|
||||
private Map<String, String> fieldLabelToOutputFieldLabel;
|
||||
|
||||
public GenericQueryRunner(String individualURLParam,
|
||||
Map<String, String> fieldLabelToOutputFieldLabel,
|
||||
String whereClause,
|
||||
DataSource dataSource,
|
||||
Log log) {
|
||||
|
||||
this.individualURLParam = individualURLParam;
|
||||
this.fieldLabelToOutputFieldLabel = fieldLabelToOutputFieldLabel;
|
||||
this.whereClause = whereClause;
|
||||
this.dataSource = dataSource;
|
||||
this.log = log;
|
||||
|
||||
}
|
||||
|
||||
private ResultSet executeQuery(String queryText,
|
||||
DataSource dataSource) {
|
||||
|
||||
QueryExecution queryExecution = null;
|
||||
// try {
|
||||
Query query = QueryFactory.create(queryText, SYNTAX);
|
||||
|
||||
// QuerySolutionMap qs = new QuerySolutionMap();
|
||||
// qs.add("authPerson", queryParam); // bind resource to s
|
||||
|
||||
queryExecution = QueryExecutionFactory.create(query, dataSource);
|
||||
|
||||
|
||||
//remocve this if loop after knowing what is describe & construct sparql stuff.
|
||||
// if (query.isSelectType()) {
|
||||
return queryExecution.execSelect();
|
||||
// }
|
||||
// } finally {
|
||||
// if (queryExecution != null) {
|
||||
// queryExecution.close();
|
||||
// }
|
||||
//
|
||||
// }
|
||||
// return null;
|
||||
}
|
||||
|
||||
private String generateGenericSparqlQuery() {
|
||||
// Resource uri1 = ResourceFactory.createResource(queryURI);
|
||||
|
||||
StringBuilder sparqlQuery = new StringBuilder();
|
||||
sparqlQuery.append(QueryConstants.getSparqlPrefixQuery());
|
||||
|
||||
sparqlQuery.append("SELECT\n");
|
||||
|
||||
for (Map.Entry<String, String> currentfieldLabelToOutputFieldLabel
|
||||
: this.fieldLabelToOutputFieldLabel.entrySet()) {
|
||||
|
||||
sparqlQuery.append("\t(str(?" + currentfieldLabelToOutputFieldLabel.getKey() + ") as ?"
|
||||
+ currentfieldLabelToOutputFieldLabel.getValue() + ")\n");
|
||||
|
||||
}
|
||||
|
||||
sparqlQuery.append("WHERE {\n");
|
||||
|
||||
sparqlQuery.append(this.whereClause);
|
||||
|
||||
sparqlQuery.append("}\n");
|
||||
|
||||
return sparqlQuery.toString();
|
||||
}
|
||||
|
||||
public ResultSet getQueryResult()
|
||||
throws MalformedQueryParametersException {
|
||||
if (StringUtils.isNotBlank(this.individualURLParam)) {
|
||||
/*
|
||||
* To test for the validity of the URI submitted.
|
||||
* */
|
||||
IRIFactory iRIFactory = IRIFactory.jenaImplementation();
|
||||
IRI iri = iRIFactory.create(this.individualURLParam);
|
||||
if (iri.hasViolation(false)) {
|
||||
String errorMsg = ((Violation) iri.violations(false).next()).getShortMessage();
|
||||
log.error("Generic Query " + errorMsg);
|
||||
throw new MalformedQueryParametersException(
|
||||
"URI provided for an individual is malformed.");
|
||||
}
|
||||
} else {
|
||||
throw new MalformedQueryParametersException("URI parameter is either null or empty.");
|
||||
}
|
||||
|
||||
ResultSet resultSet = executeQuery(generateGenericSparqlQuery(),
|
||||
this.dataSource);
|
||||
|
||||
return resultSet;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException;
|
||||
|
||||
public interface QueryRunner<QueryResult> {
|
||||
|
||||
QueryResult getQueryResult() throws MalformedQueryParametersException;
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue