1. Made changes so that proper thumbnail image location can be retrieved

This commit is contained in:
cdtank 2010-07-15 16:42:47 +00:00
parent f275ba4444
commit 94d8de065e
6 changed files with 273 additions and 78 deletions

View file

@ -24,6 +24,12 @@ public class QueryFieldLabels {
public static final String DOCUMENT_PUBLICATION_DATE = "publicationDateLit";
/*
* Image related field labels
* */
public static final String THUMBNAIL_LOCATION_URL = "thumbnailDownloadLocationLit";
public static final String THUMBNAIL_FILENAME = "thumbnailFileNameLit";
/*
* Author related field labels
* */

View file

@ -84,21 +84,6 @@ public class VisualizationRequestHandler {
dataSource,
log);
System.out.println("*****************************************");
String thumbNailLocation;
try {
thumbNailLocation = URLEncoder.encode("http://vivo-trunk.indiana.edu/individual/n2188",
VisualizationController.URL_ENCODING_SCHEME).toString();
System.out.println(FileServingHelper.getBytestreamAliasUrl(thumbNailLocation, "thumbnail_flyer-draft.jpg"));
} catch (UnsupportedEncodingException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
try {
edu.cornell.mannlib.vitro.webapp.visualization.coauthorship.VisVOContainer coAuthorshipVO =

View file

@ -7,6 +7,8 @@ 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 java.util.Set;
import javax.servlet.RequestDispatcher;
@ -18,15 +20,21 @@ 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.Controllers;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.controller.visualization.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.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;
import edu.cornell.mannlib.vitro.webapp.visualization.visutils.AllPropertiesQueryHandler;
import edu.cornell.mannlib.vitro.webapp.visualization.visutils.GenericQueryHandler;
public class VisualizationRequestHandler {
@ -74,8 +82,8 @@ public class VisualizationRequestHandler {
if (profileInfoMode.equalsIgnoreCase(visMode)) {
String filterRule = "?predicate = vitro:imageThumb || ?predicate = vitro:moniker || ?predicate = rdfs:label";
GenericQueryHandler imageQueryHandler = new GenericQueryHandler(individualURIParam,
String filterRule = "?predicate = j.2:mainImage || ?predicate = vitro:moniker || ?predicate = rdfs:label";
AllPropertiesQueryHandler profileQueryHandler = new AllPropertiesQueryHandler(individualURIParam,
filterRule,
resultFormatParam,
rdfResultFormatParam,
@ -84,9 +92,9 @@ public class VisualizationRequestHandler {
try {
GenericQueryMap profilePropertiesToValues = imageQueryHandler.getJavaValueObjects();
GenericQueryMap profilePropertiesToValues = profileQueryHandler.getJavaValueObjects();
profilePropertiesToValues.addEntry("imageContextPath", request.getContextPath() + "/images/");
profilePropertiesToValues.addEntry("imageContextPath", request.getContextPath());
Gson profileInformation = new Gson();
@ -113,10 +121,18 @@ public class VisualizationRequestHandler {
* 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 filterRule = "?predicate = vitro:imageThumb";
GenericQueryHandler imageQueryHandler = new GenericQueryHandler(individualURIParam,
filterRule,
String whereClause = "<" + individualURIParam + "> j.2:thumbnailImage ?thumbnailImage . "
+ "?thumbnailImage j.2:downloadLocation ?downloadLocation ; j.2:filename ?fileName .";
GenericQueryHandler imageQueryHandler = new GenericQueryHandler(individualURIParam,
fieldLabelToOutputFieldLabel,
whereClause,
resultFormatParam,
rdfResultFormatParam,
dataSource,
@ -124,27 +140,12 @@ public class VisualizationRequestHandler {
try {
GenericQueryMap imagePropertyToValues = imageQueryHandler.getJavaValueObjects();
String thumbnailAccessURL = getThumnailInformation(
imageQueryHandler.getResultSet(),
fieldLabelToOutputFieldLabel);
String imagePath = "";
if (imagePropertyToValues.size() > 0) {
String vitroSparqlNamespace = QueryConstants.PREFIX_TO_NAMESPACE.get("vitro");
String imageThumbProperty = vitroSparqlNamespace + "imageThumb";
Set<String> personImageThumbPaths = imagePropertyToValues.get(imageThumbProperty);
/*
* Although we know that there can be only one imagePath we are restricted by Java's
* expression power.
* */
for (String providedImagePath : personImageThumbPaths) {
imagePath = request.getContextPath() + "/images/" + providedImagePath;
}
}
prepareVisualizationQueryResponse(imagePath);
System.out.println("thumnail access URL " + thumbnailAccessURL);
prepareVisualizationQueryResponse(thumbnailAccessURL);
return;
@ -229,6 +230,29 @@ public class VisualizationRequestHandler {
}
private String getThumnailInformation(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 void prepareVisualizationQueryResponse(String preparedURL) {
response.setContentType("text/plain");

View file

@ -0,0 +1,160 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.visualization.visutils;
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;
/**
* Very dumb name of the class. change it.
* @author cdtank
*
*/
public class AllPropertiesQueryHandler {
protected static final Syntax SYNTAX = Syntax.syntaxARQ;
private String filterRule, individualURLParam, resultFormatParam, rdfResultFormatParam;
private DataSource dataSource;
private Log log;
public AllPropertiesQueryHandler(String individualURLParam,
String filterRule,
String resultFormatParam,
String rdfResultFormatParam,
DataSource dataSource,
Log log) {
this.individualURLParam = individualURLParam;
this.filterRule = filterRule;
this.resultFormatParam = resultFormatParam;
this.rdfResultFormatParam = rdfResultFormatParam;
this.dataSource = dataSource;
this.log = log;
}
private GenericQueryMap createJavaValueObjects(ResultSet resultSet) {
GenericQueryMap queryResultVO = 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) {
queryResultVO.addEntry(predicateNode.toString(),
objectNode.toString());
}
}
return queryResultVO;
}
private ResultSet executeQuery(String queryText,
String resultFormatParam,
String rdfResultFormatParam,
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(String queryURI, String filterRule) {
// Resource uri1 = ResourceFactory.createResource(queryURI);
String filterClause;
if (filterRule == null || filterRule.trim().isEmpty()) {
filterClause = "";
} else {
filterClause = "FILTER ( " + filterRule + " ) . ";
}
String sparqlQuery = QueryConstants.getSparqlPrefixQuery()
+ "SELECT "
+ " (str(?predicate) as ?" + QueryFieldLabels.PREDICATE + ") "
+ " (str(?object) as ?" + QueryFieldLabels.OBJECT + ") "
+ "WHERE { "
+ "<" + queryURI + "> ?predicate ?object. "
+ filterClause
+ "}";
System.out.println(sparqlQuery);
return sparqlQuery;
}
public GenericQueryMap getJavaValueObjects()
throws MalformedQueryParametersException {
if (this.individualURLParam == null || "".equals(individualURLParam)) {
throw new MalformedQueryParametersException("URI parameter is either null or empty.");
} else {
/*
* 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.");
}
}
ResultSet resultSet = executeQuery(generateGenericSparqlQuery(this.individualURLParam, this.filterRule),
this.resultFormatParam,
this.rdfResultFormatParam,
this.dataSource);
return createJavaValueObjects(resultSet);
}
}

View file

@ -2,6 +2,8 @@
package edu.cornell.mannlib.vitro.webapp.visualization.visutils;
import java.util.Map;
import org.apache.commons.logging.Log;
import com.hp.hpl.jena.iri.IRI;
@ -16,6 +18,7 @@ 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.util.tuple.TupleSet;
import edu.cornell.mannlib.vitro.webapp.visualization.constants.QueryConstants;
import edu.cornell.mannlib.vitro.webapp.visualization.constants.QueryFieldLabels;
@ -25,7 +28,6 @@ import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.GenericQueryM
/**
* Very dumb name of the class. change it.
* @author cdtank
*
*/
@ -33,27 +35,31 @@ public class GenericQueryHandler {
protected static final Syntax SYNTAX = Syntax.syntaxARQ;
private String filterRule, individualURLParam, resultFormatParam, rdfResultFormatParam;
private String whereClause, individualURLParam, resultFormatParam, rdfResultFormatParam;
private DataSource dataSource;
private Log log;
private Map<String, String> fieldLabelToOutputFieldLabel;
public GenericQueryHandler(String individualURLParam,
String filterRule,
Map<String, String> fieldLabelToOutputFieldLabel,
String whereClause,
String resultFormatParam,
String rdfResultFormatParam,
DataSource dataSource,
Log log) {
this.individualURLParam = individualURLParam;
this.filterRule = filterRule;
this.fieldLabelToOutputFieldLabel = fieldLabelToOutputFieldLabel;
this.whereClause = whereClause;
this.resultFormatParam = resultFormatParam;
this.rdfResultFormatParam = rdfResultFormatParam;
this.dataSource = dataSource;
this.log = log;
}
/*
private GenericQueryMap createJavaValueObjects(ResultSet resultSet) {
GenericQueryMap queryResultVO = new GenericQueryMap();
@ -62,9 +68,6 @@ public class GenericQueryHandler {
QuerySolution solution = resultSet.nextSolution();
/*
* We only want to create only ONE ego node.
* */
RDFNode predicateNode = solution.get(QueryFieldLabels.PREDICATE);
RDFNode objectNode = solution.get(QueryFieldLabels.OBJECT);
@ -73,12 +76,24 @@ public class GenericQueryHandler {
objectNode.toString());
}
for (String currentOutputFieldLabel : this.fieldLabelToOutputFieldLabel.values()) {
RDFNode currentFieldNode = solution.get(currentOutputFieldLabel);
if (currentFieldNode != null) {
// biboDocument.setDocumentBlurb(currentFieldNode.toString());
TupleSet
}
}
}
return queryResultVO;
}
*/
private ResultSet executeQuery(String queryText,
String resultFormatParam,
String rdfResultFormatParam,
@ -107,32 +122,35 @@ public class GenericQueryHandler {
return null;
}
private String generateGenericSparqlQuery(String queryURI, String filterRule) {
private String generateGenericSparqlQuery() {
// Resource uri1 = ResourceFactory.createResource(queryURI);
String filterClause;
StringBuilder sparqlQuery = new StringBuilder();
sparqlQuery.append(QueryConstants.getSparqlPrefixQuery());
if (filterRule == null || filterRule.trim().isEmpty()) {
filterClause = "";
} else {
filterClause = "FILTER ( " + filterRule + " ) . ";
sparqlQuery.append("SELECT\n");
for (Map.Entry<String, String> currentfieldLabelToOutputFieldLabel
: this.fieldLabelToOutputFieldLabel.entrySet()) {
sparqlQuery.append("\t(str(?" + currentfieldLabelToOutputFieldLabel.getKey() + ") as ?"
+ currentfieldLabelToOutputFieldLabel.getValue() + ")\n");
}
String sparqlQuery = QueryConstants.getSparqlPrefixQuery()
+ "SELECT "
+ " (str(?predicate) as ?" + QueryFieldLabels.PREDICATE + ") "
+ " (str(?object) as ?" + QueryFieldLabels.OBJECT + ") "
+ "WHERE { "
+ "<" + queryURI + "> ?predicate ?object. "
+ filterClause
+ "}";
System.out.println(sparqlQuery);
return sparqlQuery;
sparqlQuery.append("WHERE {\n");
sparqlQuery.append(this.whereClause);
sparqlQuery.append("}\n");
System.out.println("GENERIC QEURY >>>>> " + sparqlQuery);
return sparqlQuery.toString();
}
public GenericQueryMap getJavaValueObjects()
public ResultSet getResultSet()
throws MalformedQueryParametersException {
if (this.individualURLParam == null || "".equals(individualURLParam)) {
@ -151,12 +169,12 @@ public class GenericQueryHandler {
}
}
ResultSet resultSet = executeQuery(generateGenericSparqlQuery(this.individualURLParam, this.filterRule),
ResultSet resultSet = executeQuery(generateGenericSparqlQuery(),
this.resultFormatParam,
this.rdfResultFormatParam,
this.dataSource);
return createJavaValueObjects(resultSet);
return resultSet;
}

View file

@ -80,11 +80,13 @@ $.fn.image = function(src, successFunc, failureFunc){
});
};
function setProfileImage(imageContainerID, rawPath, contextPath) {
function setProfileImage(imageContainerID, mainImageURL, contextPath) {
if (imageContainerID == "") {
if (imageContainerID == "" || !mainImageURL) {
return;
}
var rawPath = getWellFormedURLs(mainImageURL, "image");
var imageLink = contextPath + rawPath;
@ -153,13 +155,13 @@ function processProfileInformation(nameContainerID,
doMonikerEllipsis) {
var name, imageRawPath, imageContextPath, moniker;
var name, mainImageURL, imageContextPath, moniker;
$.each(profileInfoJSON, function(key, set){
if (key.search(/imageThumb/i) > -1) {
if (key.search(/mainImage/i) > -1) {
imageRawPath = set[0];
mainImageURL = set[0];
} else if (key.search(/imageContextPath/i) > -1) {
@ -179,7 +181,7 @@ function processProfileInformation(nameContainerID,
setProfileName(nameContainerID, name);
setProfileMoniker(monikerContainerID, moniker, doMonikerEllipsis);
setProfileImage(imageContainerID, imageRawPath, imageContextPath);
setProfileImage(imageContainerID, mainImageURL, imageContextPath);
}