1. Added temporal graph link for the highest organization code for "organizations" page.

2. Cleaned up some query runners.
3. Made GenericQueryRunner to accept sparql queries that does not depend on URIs.
4. Adde style for temporal graph link to wilma.css
This commit is contained in:
cdtank 2011-01-10 23:48:47 +00:00
parent f5e6fbf409
commit 3d8f5d921c
7 changed files with 161 additions and 90 deletions

View file

@ -1,7 +1,37 @@
<#-- $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$ -->
<#assign visualizationLink> <#assign visualizationLink>
<#-- Chintan...place your markup for the visualization link here -->
<a class="visualiztionMenupage" href="${urls.base}/vis/temporalGraph" title="Compare this organization">Temporal Graph</a> <#assign temporalGraphIcon = '${urls.images}/visualization/temporal_vis_small_icon.jpg'>
<div id="temporal-graph-link-container">
<div class="collaboratorship-icon">
<a class="temporal-graph-link" href="#"><img src="${temporalGraphIcon}" alt="Temporal Graph"/></a>
</div>
<div class="collaboratorship-link">
<h3><a class="temporal-graph-link" href="#">Temporal Graph</a></h3>
</div>
</div>
${stylesheets.add("css/visualization/visualization.css")}
<script type="text/javascript">
var contextPath = '${contextPath}';
$.ajax({
url: contextPath + "/visualizationAjax",
data: ({vis: "utilities", vis_mode: "HIGHEST_LEVEL_ORGANIZATION"}),
dataType: "text",
success:function(data){
if (data != null && data != "") {
$("#temporal-graph-link-container .temporal-graph-link").attr("href", data);
$("#temporal-graph-link-container").show();
}
}
});
</script>
</#assign> </#assign>
<#include "menupage.ftl"> <#include "menupage.ftl">

View file

@ -87,6 +87,7 @@ public class VisualizationFrameworkConstants {
public static final String UNIVERSITY_COMPARISON_VIS_MODE = "UNIVERSITY"; public static final String UNIVERSITY_COMPARISON_VIS_MODE = "UNIVERSITY";
public static final String SCHOOL_COMPARISON_VIS_MODE = "SCHOOL"; public static final String SCHOOL_COMPARISON_VIS_MODE = "SCHOOL";
public static final String DEPARTMENT_COMPARISON_VIS_MODE = "DEPARTMENT"; public static final String DEPARTMENT_COMPARISON_VIS_MODE = "DEPARTMENT";
public static final String HIGHEST_LEVEL_ORGANIZATION_VIS_MODE = "HIGHEST_LEVEL_ORGANIZATION";
/* /*

View file

@ -151,28 +151,12 @@ public class PersonPublicationCountQueryRunner implements QueryRunner<Set<BiboDo
DataSource dataSource) { DataSource dataSource) {
QueryExecution queryExecution = null; QueryExecution queryExecution = null;
// try { Query query = QueryFactory.create(getSparqlQuery(queryURI), SYNTAX);
Query query = QueryFactory.create(getSparqlQuery(queryURI), SYNTAX); queryExecution = QueryExecutionFactory.create(query, dataSource);
return queryExecution.execSelect();
// 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 getSparqlQuery(String queryURI) { private String getSparqlQuery(String queryURI) {
// Resource uri1 = ResourceFactory.createResource(queryURI);
String sparqlQuery = QueryConstants.getSparqlPrefixQuery() String sparqlQuery = QueryConstants.getSparqlPrefixQuery()
+ SPARQL_QUERY_COMMON_SELECT_CLAUSE + SPARQL_QUERY_COMMON_SELECT_CLAUSE
@ -186,7 +170,6 @@ public class PersonPublicationCountQueryRunner implements QueryRunner<Set<BiboDo
+ SPARQL_QUERY_COMMON_WHERE_CLAUSE + SPARQL_QUERY_COMMON_WHERE_CLAUSE
+ "}"; + "}";
// System.out.println("SPARQL query for person pub count -> \n" + sparqlQuery);
return sparqlQuery; return sparqlQuery;
} }

View file

@ -96,11 +96,11 @@ public class UtilitiesRequestHandler implements VisualizationRequestHandler {
QueryRunner<ResultSet> imageQueryHandler = QueryRunner<ResultSet> imageQueryHandler =
new GenericQueryRunner(individualURI, new GenericQueryRunner(fieldLabelToOutputFieldLabel,
fieldLabelToOutputFieldLabel, "",
whereClause, whereClause,
dataSource, "",
log); dataSource, log);
return getThumbnailInformation(imageQueryHandler.getQueryResult(), return getThumbnailInformation(imageQueryHandler.getQueryResult(),
fieldLabelToOutputFieldLabel); fieldLabelToOutputFieldLabel);
@ -155,6 +155,48 @@ public class UtilitiesRequestHandler implements VisualizationRequestHandler {
return UrlBuilder.getUrl(VisualizationFrameworkConstants.FREEMARKERIZED_VISUALIZATION_URL_PREFIX, return UrlBuilder.getUrl(VisualizationFrameworkConstants.FREEMARKERIZED_VISUALIZATION_URL_PREFIX,
personLevelURLParams); personLevelURLParams);
} else if (VisualizationFrameworkConstants.HIGHEST_LEVEL_ORGANIZATION_VIS_MODE
.equalsIgnoreCase(visMode)) {
Map<String, String> fieldLabelToOutputFieldLabel = new HashMap<String, String>();
fieldLabelToOutputFieldLabel.put("organization",
QueryFieldLabels.ORGANIZATION_URL);
fieldLabelToOutputFieldLabel.put("organizationLabel", QueryFieldLabels.ORGANIZATION_LABEL);
String aggregationRules = "(count(?organization) AS ?numOfChildren)";
String whereClause = "?organization rdf:type foaf:Organization ; rdfs:label ?organizationLabel . \n"
+ "OPTIONAL { ?organization core:hasSubOrganization ?subOrg } . \n"
+ "OPTIONAL { ?organization core:subOrganizationWithin ?parent } . \n"
+ "FILTER ( !bound(?parent) ). \n";
String groupOrderClause = "GROUP BY ?organization ?organizationLabel \n"
+ "ORDER BY DESC(?numOfChildren)\n"
+ "LIMIT 1\n";
QueryRunner<ResultSet> highestLevelOrganizationQueryHandler =
new GenericQueryRunner(fieldLabelToOutputFieldLabel,
aggregationRules,
whereClause,
groupOrderClause,
dataSource, log);
return getHighestLevelOrganizationTemporalGraphVisURL(
highestLevelOrganizationQueryHandler.getQueryResult(),
fieldLabelToOutputFieldLabel);
/*
GenericQueryMap highestLevelOrganizationToValues = getHighestLevelOrganizationInformation(
highestLevelOrganizationQueryHandler.getQueryResult(),
fieldLabelToOutputFieldLabel);
Gson highestLevelOrganizationInformation = new Gson();
return highestLevelOrganizationInformation.toJson(highestLevelOrganizationToValues);
*/
} else { } else {
ParamMap individualProfileURLParams = new ParamMap(VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY, ParamMap individualProfileURLParams = new ParamMap(VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY,
@ -166,6 +208,58 @@ public class UtilitiesRequestHandler implements VisualizationRequestHandler {
} }
private String getHighestLevelOrganizationTemporalGraphVisURL(ResultSet resultSet,
Map<String, String> fieldLabelToOutputFieldLabel) {
GenericQueryMap queryResult = new GenericQueryMap();
while (resultSet.hasNext()) {
QuerySolution solution = resultSet.nextSolution();
RDFNode organizationNode = solution.get(
fieldLabelToOutputFieldLabel
.get("organization"));
if (organizationNode != null) {
queryResult.addEntry(fieldLabelToOutputFieldLabel.get("organization"), organizationNode.toString());
ParamMap highestLevelOrganizationTemporalGraphVisURLParams = new ParamMap(VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY,
organizationNode.toString(),
VisualizationFrameworkConstants.VIS_TYPE_KEY,
VisualizationFrameworkConstants.ENTITY_COMPARISON_VIS,
/* Remove this hard-coded vis_mode once Deepak fixes the Temporal Graph Vis
* front-end to work without vis_modes. */
VisualizationFrameworkConstants.VIS_MODE_KEY,
"University");
return UrlBuilder.getUrl(VisualizationFrameworkConstants.FREEMARKERIZED_VISUALIZATION_URL_PREFIX,
highestLevelOrganizationTemporalGraphVisURLParams);
}
RDFNode organizationLabelNode = solution.get(
fieldLabelToOutputFieldLabel
.get("organizationLabel"));
if (organizationLabelNode != null) {
queryResult.addEntry(fieldLabelToOutputFieldLabel.get("organizationLabel"), organizationLabelNode.toString());
}
RDFNode numberOfChildrenNode = solution.getLiteral("numOfChildren");
if (numberOfChildrenNode != null) {
queryResult.addEntry("numOfChildren", String.valueOf(numberOfChildrenNode.asLiteral().getInt()));
}
}
// return queryResult;
return "";
}
private String getThumbnailInformation(ResultSet resultSet, private String getThumbnailInformation(ResultSet resultSet,
Map<String, String> fieldLabelToOutputFieldLabel) { Map<String, String> fieldLabelToOutputFieldLabel) {

View file

@ -77,24 +77,10 @@ public class AllPropertiesQueryRunner implements QueryRunner<GenericQueryMap> {
DataSource dataSource) { DataSource dataSource) {
QueryExecution queryExecution = null; QueryExecution queryExecution = null;
// try { Query query = QueryFactory.create(queryText, SYNTAX);
Query query = QueryFactory.create(queryText, SYNTAX);
// QuerySolutionMap qs = new QuerySolutionMap(); queryExecution = QueryExecutionFactory.create(query, dataSource);
// qs.add("authPerson", queryParam); // bind resource to s return queryExecution.execSelect();
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) { private String generateGenericSparqlQuery(String queryURI, String filterRule) {

View file

@ -4,12 +4,8 @@ package edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils;
import java.util.Map; import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log; 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.DataSource;
import com.hp.hpl.jena.query.Query; import com.hp.hpl.jena.query.Query;
import com.hp.hpl.jena.query.QueryExecution; import com.hp.hpl.jena.query.QueryExecution;
@ -33,22 +29,27 @@ public class GenericQueryRunner implements QueryRunner<ResultSet> {
protected static final Syntax SYNTAX = Syntax.syntaxARQ; protected static final Syntax SYNTAX = Syntax.syntaxARQ;
private String whereClause, individualURLParam; private String whereClause;
private DataSource dataSource; private DataSource dataSource;
private Log log; private Log log;
private Map<String, String> fieldLabelToOutputFieldLabel; private Map<String, String> fieldLabelToOutputFieldLabel;
public GenericQueryRunner(String individualURLParam, private String groupOrderClause;
Map<String, String> fieldLabelToOutputFieldLabel,
String whereClause, private String aggregationRules;
DataSource dataSource,
Log log) { public GenericQueryRunner(Map<String, String> fieldLabelToOutputFieldLabel,
String aggregationRules,
String whereClause,
String groupOrderClause,
DataSource dataSource, Log log) {
this.individualURLParam = individualURLParam;
this.fieldLabelToOutputFieldLabel = fieldLabelToOutputFieldLabel; this.fieldLabelToOutputFieldLabel = fieldLabelToOutputFieldLabel;
this.aggregationRules = aggregationRules;
this.whereClause = whereClause; this.whereClause = whereClause;
this.groupOrderClause = groupOrderClause;
this.dataSource = dataSource; this.dataSource = dataSource;
this.log = log; this.log = log;
@ -58,30 +59,12 @@ public class GenericQueryRunner implements QueryRunner<ResultSet> {
DataSource dataSource) { DataSource dataSource) {
QueryExecution queryExecution = null; QueryExecution queryExecution = null;
// try { Query query = QueryFactory.create(queryText, SYNTAX);
Query query = QueryFactory.create(queryText, SYNTAX); queryExecution = QueryExecutionFactory.create(query, dataSource);
return queryExecution.execSelect();
// 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() { private String generateGenericSparqlQuery() {
// Resource uri1 = ResourceFactory.createResource(queryURI);
StringBuilder sparqlQuery = new StringBuilder(); StringBuilder sparqlQuery = new StringBuilder();
sparqlQuery.append(QueryConstants.getSparqlPrefixQuery()); sparqlQuery.append(QueryConstants.getSparqlPrefixQuery());
@ -96,32 +79,21 @@ public class GenericQueryRunner implements QueryRunner<ResultSet> {
} }
sparqlQuery.append("\n" + this.aggregationRules + "\n");
sparqlQuery.append("WHERE {\n"); sparqlQuery.append("WHERE {\n");
sparqlQuery.append(this.whereClause); sparqlQuery.append(this.whereClause);
sparqlQuery.append("}\n"); sparqlQuery.append("}\n");
sparqlQuery.append(this.groupOrderClause);
return sparqlQuery.toString(); return sparqlQuery.toString();
} }
public ResultSet getQueryResult() public ResultSet getQueryResult()
throws MalformedQueryParametersException { 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(), ResultSet resultSet = executeQuery(generateGenericSparqlQuery(),
this.dataSource); this.dataSource);

View file

@ -837,6 +837,11 @@ ul#foaf-person-childClasses .count-classes {
font-size: .75em; font-size: .75em;
} }
/* VISUAL GRAPH CLASS:GENERIC (ORGANIZATION, RESEARCH, EVENT) ------> */ /* VISUAL GRAPH CLASS:GENERIC (ORGANIZATION, RESEARCH, EVENT) ------> */
#temporal-graph-link-container {
display: none;
float: right;
width: 128px;
}
#content-generic-class { #content-generic-class {
width: 900px; width: 900px;
} }