1. Completed the caching-like version for temporal graph for grants.
2. Changed the timeout for front-end getter for temporal vis data since the first time a user requests grant comparison it might take a long time.
This commit is contained in:
parent
b1950352e8
commit
c49e8d1d75
8 changed files with 1906 additions and 1530 deletions
|
@ -1,288 +1,289 @@
|
||||||
/* $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$ */
|
||||||
|
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This will set intitial values of the constants present in constants.js
|
* This will set intitial values of the constants present in constants.js
|
||||||
* */
|
* */
|
||||||
initConstants();
|
initConstants();
|
||||||
/* This is used to cache the current state whether the user is allowed to select more entities from
|
/* This is used to cache the current state whether the user is allowed to select more entities from
|
||||||
the datatable or not. Once Max number of entity selection is reached the user can no longer select
|
the datatable or not. Once Max number of entity selection is reached the user can no longer select
|
||||||
more & this variable will be set to false. */
|
more & this variable will be set to false. */
|
||||||
$("#datatable").data("isEntitySelectionAllowed", true);
|
$("#datatable").data("isEntitySelectionAllowed", true);
|
||||||
|
|
||||||
$notificationContainer = $("#notification-container").notify();
|
$notificationContainer = $("#notification-container").notify();
|
||||||
|
|
||||||
graphContainer = $("#graphContainer");
|
graphContainer = $("#graphContainer");
|
||||||
tableDiv = $('#paginatedTable');
|
tableDiv = $('#paginatedTable');
|
||||||
|
|
||||||
//temporalGraphProcessor.initiateTemporalGraphRenderProcess(graphContainer, jsonString);
|
//temporalGraphProcessor.initiateTemporalGraphRenderProcess(graphContainer, jsonString);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* When the intra-entity parameters are clicked,
|
* When the intra-entity parameters are clicked,
|
||||||
* update the status accordingly.
|
* update the status accordingly.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$("select.comparisonValues").change(function(){
|
$("select.comparisonValues").change(function(){
|
||||||
|
|
||||||
var selectedValue = $("select.comparisonValues option:selected").val();
|
var selectedValue = $("select.comparisonValues option:selected").val();
|
||||||
|
|
||||||
var selectedParameter;
|
var selectedParameter;
|
||||||
|
|
||||||
$.each(COMPARISON_PARAMETERS_INFO, function(index, parameter) {
|
$.each(COMPARISON_PARAMETERS_INFO, function(index, parameter) {
|
||||||
|
|
||||||
if (parameter.value === selectedValue) {
|
if (parameter.value === selectedValue) {
|
||||||
selectedParameter = parameter;
|
selectedParameter = parameter;
|
||||||
window.location = parameter.viewLink;
|
window.location = parameter.viewLink;
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
//$("#body").empty().html("<div id='loading-comparisons'>Loading " + selectedValue + " <img src='" + loadingImageLink + "' /></div>");
|
//$("#body").empty().html("<div id='loading-comparisons'>Loading " + selectedValue + " <img src='" + loadingImageLink + "' /></div>");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This piece of code is not executed at all because the redirect happens before there is a chance
|
* This piece of code is not executed at all because the redirect happens before there is a chance
|
||||||
* to render the below contents.
|
* to render the below contents.
|
||||||
* */
|
* */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
||||||
$("#comparisonParameter").text("Total Number of " + selectedValue);
|
$("#comparisonParameter").text("Total Number of " + selectedValue);
|
||||||
$('#yaxislabel').html("Number of " + selectedValue).mbFlipText(false);
|
$('#yaxislabel').html("Number of " + selectedValue).mbFlipText(false);
|
||||||
$('#yaxislabel').css("color", "#595B5B");
|
$('#yaxislabel').css("color", "#595B5B");
|
||||||
$('#comparisonHeader').html(selectedValue).css('font-weight', 'bold');
|
$('#comparisonHeader').html(selectedValue).css('font-weight', 'bold');
|
||||||
|
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
//click event handler for clear button
|
//click event handler for clear button
|
||||||
$("a.clear-selected-entities").live('click', function(){
|
$("a.clear-selected-entities").live('click', function(){
|
||||||
clearRenderedObjects();
|
clearRenderedObjects();
|
||||||
});
|
});
|
||||||
|
|
||||||
$("input[type=checkbox].easyDeselectCheckbox").live('click', function(){
|
$("input[type=checkbox].easyDeselectCheckbox").live('click', function(){
|
||||||
|
|
||||||
var checkbox = $(this);
|
var checkbox = $(this);
|
||||||
var checkboxValue = $(this).attr("value");
|
var checkboxValue = $(this).attr("value");
|
||||||
var linkedCheckbox = labelToCheckedEntities[checkboxValue];
|
var linkedCheckbox = labelToCheckedEntities[checkboxValue];
|
||||||
var entityToBeRemoved = labelToEntityRecord[checkboxValue];
|
var entityToBeRemoved = labelToEntityRecord[checkboxValue];
|
||||||
|
|
||||||
if(!checkbox.is(':checked')){
|
if(!checkbox.is(':checked')){
|
||||||
//console.log("Easy deselect checkbox is unclicked!");
|
//console.log("Easy deselect checkbox is unclicked!");
|
||||||
updateRowHighlighter(linkedCheckbox);
|
updateRowHighlighter(linkedCheckbox);
|
||||||
removeUsedColor(entityToBeRemoved);
|
removeUsedColor(entityToBeRemoved);
|
||||||
removeEntityUnChecked(renderedObjects, entityToBeRemoved);
|
removeEntityUnChecked(renderedObjects, entityToBeRemoved);
|
||||||
removeLegendRow(linkedCheckbox);
|
removeLegendRow(linkedCheckbox);
|
||||||
removeCheckBoxFromGlobalSet(linkedCheckbox);
|
removeCheckBoxFromGlobalSet(linkedCheckbox);
|
||||||
$(linkedCheckbox).attr('checked', false);
|
$(linkedCheckbox).attr('checked', false);
|
||||||
checkIfColorLimitIsReached();
|
checkIfColorLimitIsReached();
|
||||||
displayLineGraphs();
|
displayLineGraphs();
|
||||||
updateCounter();
|
updateCounter();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
$(".disabled-checkbox-event-receiver").live("click", function () {
|
$(".disabled-checkbox-event-receiver").live("click", function () {
|
||||||
|
|
||||||
if ($(this).next().is(':disabled')) {
|
if ($(this).next().is(':disabled')) {
|
||||||
|
|
||||||
createNotification("warning-notification", {
|
createNotification("warning-notification", {
|
||||||
title: 'Error',
|
title: 'Error',
|
||||||
text: 'A Maximum 10 entities can be compared. Please remove some & try again.'
|
text: 'A Maximum 10 entities can be compared. Please remove some & try again.'
|
||||||
}, {
|
}, {
|
||||||
custom: true,
|
custom: true,
|
||||||
expires: false
|
expires: false
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
function performEntityCheckboxUnselectedActions(entity, checkboxValue, checkbox) {
|
function performEntityCheckboxUnselectedActions(entity, checkboxValue, checkbox) {
|
||||||
|
|
||||||
removeUsedColor(entity);
|
removeUsedColor(entity);
|
||||||
removeEntityUnChecked(renderedObjects, entity);
|
removeEntityUnChecked(renderedObjects, entity);
|
||||||
removeLegendRow(checkbox);
|
removeLegendRow(checkbox);
|
||||||
removeCheckBoxFromGlobalSet(checkbox);
|
removeCheckBoxFromGlobalSet(checkbox);
|
||||||
|
|
||||||
checkbox.closest("tr").removeClass('datatablerowhighlight');
|
checkbox.closest("tr").removeClass('datatablerowhighlight');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function performEntityCheckboxSelectedActions(entity, checkboxValue, checkbox) {
|
function performEntityCheckboxSelectedActions(entity, checkboxValue, checkbox) {
|
||||||
|
|
||||||
getNextFreeColor(entity);
|
getNextFreeColor(entity);
|
||||||
|
|
||||||
//Generate the bar, checkbox and label for the legend.
|
//Generate the bar, checkbox and label for the legend.
|
||||||
createLegendRow(entity, $("#bottom"));
|
createLegendRow(entity, $("#bottom"));
|
||||||
|
|
||||||
renderLineGraph(renderedObjects, entity);
|
renderLineGraph(renderedObjects, entity);
|
||||||
labelToCheckedEntities[checkboxValue] = checkbox;
|
labelToCheckedEntities[checkboxValue] = checkbox;
|
||||||
labelToCheckedEntities[checkboxValue].entity = entity;
|
labelToCheckedEntities[checkboxValue].entity = entity;
|
||||||
|
|
||||||
// console.log(labelToCheckedEntities[checkboxValue], entity);
|
// console.log(labelToCheckedEntities[checkboxValue], entity);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* To highlight the rows belonging to selected entities.
|
* To highlight the rows belonging to selected entities.
|
||||||
* */
|
* */
|
||||||
checkbox.closest("tr").addClass('datatablerowhighlight');
|
checkbox.closest("tr").addClass('datatablerowhighlight');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function performEntityCheckboxClickedRedrawActions() {
|
function performEntityCheckboxClickedRedrawActions() {
|
||||||
|
|
||||||
setTickSizeOfAxes();
|
setTickSizeOfAxes();
|
||||||
checkIfColorLimitIsReached();
|
checkIfColorLimitIsReached();
|
||||||
displayLineGraphs();
|
displayLineGraphs();
|
||||||
updateCounter();
|
updateCounter();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* function to populate the labelToEntityRecord object with the
|
* function to populate the labelToEntityRecord object with the
|
||||||
* values from the json file and
|
* values from the json file and
|
||||||
* dynamically generate checkboxes
|
* dynamically generate checkboxes
|
||||||
*/
|
*/
|
||||||
function loadData(jsonData, dataTableParams) {
|
function loadData(jsonData, dataTableParams) {
|
||||||
|
|
||||||
$.each(jsonData, function (index, val) {
|
$.each(jsonData, function (index, val) {
|
||||||
setOfLabels.push(val.label);
|
setOfLabels.push(val.label);
|
||||||
labelToEntityRecord[val.label] = val;
|
labelToEntityRecord[val.label] = val;
|
||||||
});
|
});
|
||||||
|
|
||||||
prepareTableForDataTablePagination(jsonData, dataTableParams);
|
prepareTableForDataTablePagination(jsonData, dataTableParams);
|
||||||
setEntityLevel(getEntityVisMode(jsonData));
|
setEntityLevel(getEntityVisMode(jsonData));
|
||||||
|
|
||||||
entityCheckboxOperatedOnEventListener();
|
entityCheckboxOperatedOnEventListener();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function entityCheckboxOperatedOnEventListener() {
|
function entityCheckboxOperatedOnEventListener() {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* When the elements in the paginated div
|
* When the elements in the paginated div
|
||||||
* are clicked this event handler is called
|
* are clicked this event handler is called
|
||||||
*/
|
*/
|
||||||
$("input." + entityCheckboxSelectorDOMClass).live('click', function () {
|
$("input." + entityCheckboxSelectorDOMClass).live('click', function () {
|
||||||
|
|
||||||
var checkbox = $(this);
|
var checkbox = $(this);
|
||||||
var checkboxValue = $(this).attr("value");
|
var checkboxValue = $(this).attr("value");
|
||||||
var entity = labelToEntityRecord[checkboxValue];
|
var entity = labelToEntityRecord[checkboxValue];
|
||||||
|
|
||||||
if (checkbox.is(':checked')) {
|
if (checkbox.is(':checked')) {
|
||||||
|
|
||||||
performEntityCheckboxSelectedActions(entity, checkboxValue, checkbox);
|
performEntityCheckboxSelectedActions(entity, checkboxValue, checkbox);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
performEntityCheckboxUnselectedActions(entity, checkboxValue, checkbox);
|
performEntityCheckboxUnselectedActions(entity, checkboxValue, checkbox);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
performEntityCheckboxClickedRedrawActions();
|
performEntityCheckboxClickedRedrawActions();
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This method will setup the options for loading screen & then activate the
|
* This method will setup the options for loading screen & then activate the
|
||||||
* loading screen.
|
* loading screen.
|
||||||
* */
|
* */
|
||||||
function setupLoadingScreen(visContainerDIV) {
|
function setupLoadingScreen(visContainerDIV) {
|
||||||
|
|
||||||
$.blockUI.defaults.overlayCSS = {
|
$.blockUI.defaults.overlayCSS = {
|
||||||
backgroundColor: '#fff',
|
backgroundColor: '#fff',
|
||||||
opacity: 1.0
|
opacity: 1.0
|
||||||
};
|
};
|
||||||
|
|
||||||
$.blockUI.defaults.css.width = '500px';
|
$.blockUI.defaults.css.width = '500px';
|
||||||
$.blockUI.defaults.css.border = '0px';
|
$.blockUI.defaults.css.border = '0px';
|
||||||
$.blockUI.defaults.css.top = '15%';
|
$.blockUI.defaults.css.top = '15%';
|
||||||
|
|
||||||
visContainerDIV.block({
|
visContainerDIV.block({
|
||||||
message: '<h3><img src="' + loadingImageLink
|
message: '<h3><img src="' + loadingImageLink
|
||||||
+ '" /> Loading data for <i>'
|
+ '" /> Loading data for <i>'
|
||||||
+ organizationLabel
|
+ organizationLabel
|
||||||
+ '</i></h3>'
|
+ '</i></h3>'
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This function gets json data for temporal graph & after rendering removes the
|
* This function gets json data for temporal graph & after rendering removes the
|
||||||
* loading message. It will also display the error container in case of any error.
|
* loading message. It will also display the error container in case of any error.
|
||||||
* */
|
* */
|
||||||
function getTemporalGraphData(temporalGraphDataURL,
|
function getTemporalGraphData(temporalGraphDataURL,
|
||||||
graphBodyDIV,
|
graphBodyDIV,
|
||||||
errorBodyDIV,
|
errorBodyDIV,
|
||||||
visContainerDIV) {
|
visContainerDIV) {
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: temporalGraphDataURL,
|
url: temporalGraphDataURL,
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
success: function (data) {
|
timeout: 5 * 60 * 1000,
|
||||||
|
success: function (data) {
|
||||||
if (data.error) {
|
|
||||||
graphBodyDIV.remove();
|
if (data.error) {
|
||||||
errorBodyDIV.show();
|
graphBodyDIV.remove();
|
||||||
visContainerDIV.unblock();
|
errorBodyDIV.show();
|
||||||
|
visContainerDIV.unblock();
|
||||||
} else {
|
|
||||||
graphBodyDIV.show();
|
} else {
|
||||||
errorBodyDIV.remove();
|
graphBodyDIV.show();
|
||||||
temporalGraphProcessor.initiateTemporalGraphRenderProcess(graphContainer, data);
|
errorBodyDIV.remove();
|
||||||
visContainerDIV.unblock();
|
temporalGraphProcessor.initiateTemporalGraphRenderProcess(graphContainer, data);
|
||||||
}
|
visContainerDIV.unblock();
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
});
|
||||||
}
|
|
||||||
|
}
|
||||||
temporalGraphProcessor = {
|
|
||||||
|
temporalGraphProcessor = {
|
||||||
initiateTemporalGraphRenderProcess: function(givenGraphContainer, jsonData) {
|
|
||||||
|
initiateTemporalGraphRenderProcess: function(givenGraphContainer, jsonData) {
|
||||||
this.dataTableParams = {
|
|
||||||
searchBarParentContainerDIVClass : "searchbar",
|
this.dataTableParams = {
|
||||||
paginationContainerDIVClass : "paginatedtabs"
|
searchBarParentContainerDIVClass : "searchbar",
|
||||||
};
|
paginationContainerDIVClass : "paginatedtabs"
|
||||||
|
};
|
||||||
|
|
||||||
/*
|
|
||||||
* initial display of the grid when the page loads
|
/*
|
||||||
* */
|
* initial display of the grid when the page loads
|
||||||
init(givenGraphContainer);
|
* */
|
||||||
|
init(givenGraphContainer);
|
||||||
/*
|
|
||||||
* render the temporal graph per the sent content.
|
/*
|
||||||
* */
|
* render the temporal graph per the sent content.
|
||||||
loadData(jsonData, this.dataTableParams);
|
* */
|
||||||
|
loadData(jsonData, this.dataTableParams);
|
||||||
/*
|
|
||||||
* This will make sure that top 3 entities are selected by default when the page loads.
|
/*
|
||||||
*/
|
* This will make sure that top 3 entities are selected by default when the page loads.
|
||||||
$.each($("input." + entityCheckboxSelectorDOMClass), function(index, checkbox) {
|
*/
|
||||||
|
$.each($("input." + entityCheckboxSelectorDOMClass), function(index, checkbox) {
|
||||||
if (index > 2) {
|
|
||||||
return false;
|
if (index > 2) {
|
||||||
}
|
return false;
|
||||||
|
}
|
||||||
$(this).attr('checked', true);
|
|
||||||
|
$(this).attr('checked', true);
|
||||||
var checkboxValue = $(this).attr("value");
|
|
||||||
var entity = labelToEntityRecord[checkboxValue];
|
var checkboxValue = $(this).attr("value");
|
||||||
|
var entity = labelToEntityRecord[checkboxValue];
|
||||||
performEntityCheckboxSelectedActions(entity, checkboxValue, $(this));
|
|
||||||
|
performEntityCheckboxSelectedActions(entity, checkboxValue, $(this));
|
||||||
performEntityCheckboxClickedRedrawActions();
|
|
||||||
|
performEntityCheckboxClickedRedrawActions();
|
||||||
});
|
|
||||||
|
});
|
||||||
}
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,332 +1,354 @@
|
||||||
/* $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$ */
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.visualization.freemarker.entitycomparison.cached;
|
package edu.cornell.mannlib.vitro.webapp.visualization.freemarker.entitycomparison.cached;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringEscapeUtils;
|
import org.apache.commons.lang.StringEscapeUtils;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.hp.hpl.jena.query.Dataset;
|
import com.hp.hpl.jena.query.Dataset;
|
||||||
import com.hp.hpl.jena.rdf.model.Model;
|
import com.hp.hpl.jena.rdf.model.Model;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.Portal;
|
import edu.cornell.mannlib.vitro.webapp.beans.Portal;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
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.ResponseValues;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.TemplateResponseValues;
|
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.DataVisualizationController;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.visualization.freemarker.VisualizationFrameworkConstants;
|
import edu.cornell.mannlib.vitro.webapp.controller.visualization.freemarker.VisualizationFrameworkConstants;
|
||||||
import edu.cornell.mannlib.vitro.webapp.visualization.constants.VOConstants;
|
import edu.cornell.mannlib.vitro.webapp.visualization.constants.VOConstants;
|
||||||
import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException;
|
import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException;
|
||||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.entitycomparison.EntityComparisonUtilityFunctions;
|
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.entitycomparison.EntityComparisonUtilityFunctions;
|
||||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.valueobjects.Activity;
|
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.valueobjects.Activity;
|
||||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.valueobjects.ConstructedModelTracker;
|
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.valueobjects.ConstructedModelTracker;
|
||||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.valueobjects.Entity;
|
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.JsonObject;
|
||||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.valueobjects.SubEntity;
|
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.valueobjects.SubEntity;
|
||||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.SelectOnModelUtilities;
|
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.SelectOnModelUtilities;
|
||||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.UtilityFunctions;
|
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.UtilityFunctions;
|
||||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.VisualizationRequestHandler;
|
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.VisualizationRequestHandler;
|
||||||
|
|
||||||
|
|
||||||
public class TemporalGrantVisualizationRequestHandler implements
|
public class TemporalGrantVisualizationRequestHandler implements
|
||||||
VisualizationRequestHandler {
|
VisualizationRequestHandler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResponseValues generateStandardVisualization(
|
public ResponseValues generateStandardVisualization(
|
||||||
VitroRequest vitroRequest, Log log, Dataset dataset)
|
VitroRequest vitroRequest, Log log, Dataset dataset)
|
||||||
throws MalformedQueryParametersException {
|
throws MalformedQueryParametersException {
|
||||||
|
|
||||||
String entityURI = vitroRequest
|
String entityURI = vitroRequest
|
||||||
.getParameter(VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY);
|
.getParameter(VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY);
|
||||||
|
|
||||||
if (StringUtils.isBlank(entityURI)) {
|
if (StringUtils.isBlank(entityURI)) {
|
||||||
|
|
||||||
entityURI = EntityComparisonUtilityFunctions
|
entityURI = EntityComparisonUtilityFunctions
|
||||||
.getStaffProvidedOrComputedHighestLevelOrganization(
|
.getStaffProvidedOrComputedHighestLevelOrganization(
|
||||||
log,
|
log,
|
||||||
dataset,
|
dataset,
|
||||||
vitroRequest);
|
vitroRequest);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println("current models in the system are");
|
System.out.println("current models in the system are");
|
||||||
for (Map.Entry<String, Model> entry : ConstructedModelTracker.getAllModels().entrySet()) {
|
for (Map.Entry<String, Model> entry : ConstructedModelTracker.getAllModels().entrySet()) {
|
||||||
System.out.println(entry.getKey() + " -> " + entry.getValue().size());
|
System.out.println(entry.getKey() + " -> " + entry.getValue().size());
|
||||||
}
|
}
|
||||||
|
|
||||||
return prepareStandaloneMarkupResponse(vitroRequest, entityURI);
|
return prepareStandaloneMarkupResponse(vitroRequest, entityURI);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, String> generateDataVisualization(
|
public Map<String, String> generateDataVisualization(
|
||||||
VitroRequest vitroRequest, Log log, Dataset dataset)
|
VitroRequest vitroRequest, Log log, Dataset dataset)
|
||||||
throws MalformedQueryParametersException {
|
throws MalformedQueryParametersException {
|
||||||
|
|
||||||
String entityURI = vitroRequest
|
String entityURI = vitroRequest
|
||||||
.getParameter(VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY);
|
.getParameter(VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This will provide the data in json format mainly used for standalone temporal vis.
|
* This will provide the data in json format mainly used for standalone temporal vis.
|
||||||
* */
|
* */
|
||||||
if (VisualizationFrameworkConstants.TEMPORAL_GRAPH_JSON_DATA_VIS_MODE
|
if (VisualizationFrameworkConstants.TEMPORAL_GRAPH_JSON_DATA_VIS_MODE
|
||||||
.equalsIgnoreCase(vitroRequest
|
.equalsIgnoreCase(vitroRequest
|
||||||
.getParameter(VisualizationFrameworkConstants.VIS_MODE_KEY))) {
|
.getParameter(VisualizationFrameworkConstants.VIS_MODE_KEY))) {
|
||||||
|
|
||||||
if (StringUtils.isNotBlank(entityURI)) {
|
if (StringUtils.isNotBlank(entityURI)) {
|
||||||
|
|
||||||
return getSubjectEntityAndGenerateDataResponse(
|
return getSubjectEntityAndGenerateDataResponse(
|
||||||
vitroRequest,
|
vitroRequest,
|
||||||
log,
|
log,
|
||||||
dataset,
|
dataset,
|
||||||
entityURI,
|
entityURI,
|
||||||
EntityComparisonConstants.DataVisMode.JSON);
|
EntityComparisonConstants.DataVisMode.JSON);
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
return getSubjectEntityAndGenerateDataResponse(
|
return getSubjectEntityAndGenerateDataResponse(
|
||||||
vitroRequest,
|
vitroRequest,
|
||||||
log,
|
log,
|
||||||
dataset,
|
dataset,
|
||||||
EntityComparisonUtilityFunctions
|
EntityComparisonUtilityFunctions
|
||||||
.getStaffProvidedOrComputedHighestLevelOrganization(
|
.getStaffProvidedOrComputedHighestLevelOrganization(
|
||||||
log,
|
log,
|
||||||
dataset,
|
dataset,
|
||||||
vitroRequest),
|
vitroRequest),
|
||||||
EntityComparisonConstants.DataVisMode.JSON);
|
EntityComparisonConstants.DataVisMode.JSON);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
/*
|
/*
|
||||||
* This provides csv download files for the content in the tables.
|
* This provides csv download files for the content in the tables.
|
||||||
* */
|
* */
|
||||||
return getSubjectEntityAndGenerateDataResponse(
|
return getSubjectEntityAndGenerateDataResponse(
|
||||||
vitroRequest,
|
vitroRequest,
|
||||||
log,
|
log,
|
||||||
dataset,
|
dataset,
|
||||||
entityURI,
|
entityURI,
|
||||||
EntityComparisonConstants.DataVisMode.CSV);
|
EntityComparisonConstants.DataVisMode.CSV);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<String, String> prepareDataErrorResponse() {
|
private Map<String, String> prepareDataErrorResponse() {
|
||||||
|
|
||||||
String outputFileName = "no-organization_grants-per-year.csv";
|
String outputFileName = "no-organization_grants-per-year.csv";
|
||||||
|
|
||||||
Map<String, String> fileData = new HashMap<String, String>();
|
Map<String, String> fileData = new HashMap<String, String>();
|
||||||
|
|
||||||
fileData.put(DataVisualizationController.FILE_NAME_KEY,
|
fileData.put(DataVisualizationController.FILE_NAME_KEY,
|
||||||
outputFileName);
|
outputFileName);
|
||||||
fileData.put(DataVisualizationController.FILE_CONTENT_TYPE_KEY,
|
fileData.put(DataVisualizationController.FILE_CONTENT_TYPE_KEY,
|
||||||
"application/octet-stream");
|
"application/octet-stream");
|
||||||
fileData.put(DataVisualizationController.FILE_CONTENT_KEY, "");
|
fileData.put(DataVisualizationController.FILE_CONTENT_KEY, "");
|
||||||
return fileData;
|
return fileData;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object generateAjaxVisualization(VitroRequest vitroRequest, Log log,
|
public Object generateAjaxVisualization(VitroRequest vitroRequest, Log log,
|
||||||
Dataset dataset) throws MalformedQueryParametersException {
|
Dataset dataset) throws MalformedQueryParametersException {
|
||||||
|
|
||||||
throw new UnsupportedOperationException("Entity Grant Count "
|
throw new UnsupportedOperationException("Entity Grant Count "
|
||||||
+ "does not provide Ajax response.");
|
+ "does not provide Ajax response.");
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<String, String> getSubjectEntityAndGenerateDataResponse(
|
private Map<String, String> getSubjectEntityAndGenerateDataResponse(
|
||||||
VitroRequest vitroRequest, Log log, Dataset dataset,
|
VitroRequest vitroRequest, Log log, Dataset dataset,
|
||||||
String subjectEntityURI, EntityComparisonConstants.DataVisMode visMode)
|
String subjectEntityURI, EntityComparisonConstants.DataVisMode visMode)
|
||||||
throws MalformedQueryParametersException {
|
throws MalformedQueryParametersException {
|
||||||
|
|
||||||
Entity organizationEntity = SelectOnModelUtilities
|
Entity organizationEntity = SelectOnModelUtilities
|
||||||
.getSubjectOrganizationHierarchy(dataset, subjectEntityURI);
|
.getSubjectOrganizationHierarchy(dataset, subjectEntityURI);
|
||||||
|
|
||||||
if (organizationEntity.getSubEntities() == null) {
|
if (organizationEntity.getSubEntities() == null) {
|
||||||
|
|
||||||
if (EntityComparisonConstants.DataVisMode.JSON.equals(visMode)) {
|
if (EntityComparisonConstants.DataVisMode.JSON.equals(visMode)) {
|
||||||
return prepareStandaloneDataErrorResponse();
|
return prepareStandaloneDataErrorResponse();
|
||||||
} else {
|
} else {
|
||||||
return prepareDataErrorResponse();
|
return prepareDataErrorResponse();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, Activity> grantURIForAssociatedPeopleToVO = new HashMap<String, Activity>();
|
Map<String, Activity> grantURIForAssociatedPeopleToVO = new HashMap<String, Activity>();
|
||||||
Map<String, Activity> allGrantURIToVO = new HashMap<String, Activity>();
|
Map<String, Activity> allGrantURIToVO = new HashMap<String, Activity>();
|
||||||
|
|
||||||
allGrantURIToVO = SelectOnModelUtilities.getGrantsForAllSubOrganizations(dataset, organizationEntity);
|
/**
|
||||||
|
* TODO: Change this to use DataSet when an optimum solution is reached. Currently grant constructs are causing
|
||||||
if (allGrantURIToVO.isEmpty() && grantURIForAssociatedPeopleToVO.isEmpty()) {
|
* endless wait times on a large dataset like UFl. When I tried to add all the datasets manually to the Datasource
|
||||||
|
* it responded in an order of magnitude higher than with just the defaultOntModel.
|
||||||
if (EntityComparisonConstants.DataVisMode.JSON.equals(visMode)) {
|
* Brian Lowe is looking into this weird behavior see http://issues.library.cornell.edu/browse/NIHVIVO-2275
|
||||||
return prepareStandaloneDataErrorResponse();
|
*/
|
||||||
} else {
|
// DataSource dataSource = DatasetFactory.create();
|
||||||
return prepareDataErrorResponse();
|
// dataSource.setDefaultModel(vitroRequest.getJenaOntModel());
|
||||||
}
|
|
||||||
|
allGrantURIToVO = SelectOnModelUtilities.getGrantsForAllSubOrganizations(dataset, organizationEntity);
|
||||||
} else {
|
|
||||||
|
Entity organizationWithAssociatedPeople = SelectOnModelUtilities
|
||||||
if (EntityComparisonConstants.DataVisMode.JSON.equals(visMode)) {
|
.getSubjectOrganizationAssociatedPeople(dataset, subjectEntityURI);
|
||||||
return prepareStandaloneDataResponse(vitroRequest, organizationEntity);
|
|
||||||
} else {
|
if (organizationWithAssociatedPeople.getSubEntities() != null) {
|
||||||
return prepareDataResponse(organizationEntity);
|
|
||||||
}
|
grantURIForAssociatedPeopleToVO = SelectOnModelUtilities
|
||||||
}
|
.getPublicationsForAssociatedPeople(dataset, organizationWithAssociatedPeople.getSubEntities());
|
||||||
}
|
|
||||||
|
organizationEntity = EntityComparisonUtilityFunctions.mergeEntityIfShareSameURI(
|
||||||
private Map<String, String> prepareStandaloneDataErrorResponse() {
|
organizationEntity,
|
||||||
|
organizationWithAssociatedPeople);
|
||||||
Map<String, String> fileData = new HashMap<String, String>();
|
}
|
||||||
|
|
||||||
fileData.put(DataVisualizationController.FILE_CONTENT_TYPE_KEY,
|
if (allGrantURIToVO.isEmpty() && grantURIForAssociatedPeopleToVO.isEmpty()) {
|
||||||
"application/octet-stream");
|
|
||||||
fileData.put(DataVisualizationController.FILE_CONTENT_KEY,
|
if (EntityComparisonConstants.DataVisMode.JSON.equals(visMode)) {
|
||||||
"{\"error\" : \"No Grants for this Organization found in VIVO.\"}");
|
return prepareStandaloneDataErrorResponse();
|
||||||
return fileData;
|
} else {
|
||||||
}
|
return prepareDataErrorResponse();
|
||||||
|
}
|
||||||
|
|
||||||
private Map<String, String> prepareStandaloneDataResponse(
|
} else {
|
||||||
VitroRequest vitroRequest,
|
|
||||||
Entity entity) {
|
if (EntityComparisonConstants.DataVisMode.JSON.equals(visMode)) {
|
||||||
|
return prepareStandaloneDataResponse(vitroRequest, organizationEntity);
|
||||||
Map<String, String> fileData = new HashMap<String, String>();
|
} else {
|
||||||
|
return prepareDataResponse(organizationEntity);
|
||||||
fileData.put(DataVisualizationController.FILE_CONTENT_TYPE_KEY,
|
}
|
||||||
"application/octet-stream");
|
}
|
||||||
fileData.put(DataVisualizationController.FILE_CONTENT_KEY,
|
}
|
||||||
writeGrantsOverTimeJSON(vitroRequest,
|
|
||||||
entity.getSubEntities()));
|
private Map<String, String> prepareStandaloneDataErrorResponse() {
|
||||||
return fileData;
|
|
||||||
}
|
Map<String, String> fileData = new HashMap<String, String>();
|
||||||
|
|
||||||
/**
|
fileData.put(DataVisualizationController.FILE_CONTENT_TYPE_KEY,
|
||||||
* Provides response when json file containing the grant count over the
|
"application/octet-stream");
|
||||||
* years is requested.
|
fileData.put(DataVisualizationController.FILE_CONTENT_KEY,
|
||||||
*
|
"{\"error\" : \"No Grants for this Organization found in VIVO.\"}");
|
||||||
* @param entity
|
return fileData;
|
||||||
* @param subentities
|
}
|
||||||
* @param subOrganizationTypesResult
|
|
||||||
*/
|
|
||||||
private Map<String, String> prepareDataResponse(Entity entity) {
|
private Map<String, String> prepareStandaloneDataResponse(
|
||||||
|
VitroRequest vitroRequest,
|
||||||
String entityLabel = entity.getEntityLabel();
|
Entity entity) {
|
||||||
|
|
||||||
/*
|
Map<String, String> fileData = new HashMap<String, String>();
|
||||||
* To make sure that null/empty records for entity names do not cause any mischief.
|
|
||||||
* */
|
fileData.put(DataVisualizationController.FILE_CONTENT_TYPE_KEY,
|
||||||
if (StringUtils.isBlank(entityLabel)) {
|
"application/octet-stream");
|
||||||
entityLabel = "no-organization";
|
fileData.put(DataVisualizationController.FILE_CONTENT_KEY,
|
||||||
}
|
writeGrantsOverTimeJSON(vitroRequest,
|
||||||
|
entity.getSubEntities()));
|
||||||
String outputFileName = UtilityFunctions.slugify(entityLabel)
|
return fileData;
|
||||||
+ "_grants-per-year" + ".csv";
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
Map<String, String> fileData = new HashMap<String, String>();
|
* Provides response when json file containing the grant count over the
|
||||||
|
* years is requested.
|
||||||
fileData.put(DataVisualizationController.FILE_NAME_KEY,
|
*
|
||||||
outputFileName);
|
* @param entity
|
||||||
fileData.put(DataVisualizationController.FILE_CONTENT_TYPE_KEY,
|
* @param subentities
|
||||||
"application/octet-stream");
|
* @param subOrganizationTypesResult
|
||||||
fileData.put(DataVisualizationController.FILE_CONTENT_KEY,
|
*/
|
||||||
getEntityGrantsPerYearCSVContent(entity));
|
private Map<String, String> prepareDataResponse(Entity entity) {
|
||||||
return fileData;
|
|
||||||
}
|
String entityLabel = entity.getEntityLabel();
|
||||||
|
|
||||||
|
/*
|
||||||
private TemplateResponseValues prepareStandaloneMarkupResponse(VitroRequest vreq,
|
* To make sure that null/empty records for entity names do not cause any mischief.
|
||||||
String entityURI) {
|
* */
|
||||||
|
if (StringUtils.isBlank(entityLabel)) {
|
||||||
Portal portal = vreq.getPortal();
|
entityLabel = "no-organization";
|
||||||
String standaloneTemplate = "entityComparisonOnGrantsStandalone.ftl";
|
}
|
||||||
|
|
||||||
String organizationLabel = EntityComparisonUtilityFunctions.getEntityLabelFromDAO(vreq,
|
String outputFileName = UtilityFunctions.slugify(entityLabel)
|
||||||
entityURI);
|
+ "_grants-per-year" + ".csv";
|
||||||
|
|
||||||
Map<String, Object> body = new HashMap<String, Object>();
|
|
||||||
body.put("portalBean", portal);
|
Map<String, String> fileData = new HashMap<String, String>();
|
||||||
body.put("title", organizationLabel + " - Temporal Graph Visualization");
|
|
||||||
body.put("organizationURI", entityURI);
|
fileData.put(DataVisualizationController.FILE_NAME_KEY,
|
||||||
body.put("organizationLabel", organizationLabel);
|
outputFileName);
|
||||||
|
fileData.put(DataVisualizationController.FILE_CONTENT_TYPE_KEY,
|
||||||
return new TemplateResponseValues(standaloneTemplate, body);
|
"application/octet-stream");
|
||||||
}
|
fileData.put(DataVisualizationController.FILE_CONTENT_KEY,
|
||||||
|
getEntityGrantsPerYearCSVContent(entity));
|
||||||
/**
|
return fileData;
|
||||||
* Function to generate a json file for year <-> grant count mapping.
|
}
|
||||||
* @param vreq
|
|
||||||
* @param subentities
|
|
||||||
* @param subOrganizationTypesResult
|
private TemplateResponseValues prepareStandaloneMarkupResponse(VitroRequest vreq,
|
||||||
*/
|
String entityURI) {
|
||||||
private String writeGrantsOverTimeJSON(VitroRequest vreq,
|
|
||||||
Set<SubEntity> subentities) {
|
Portal portal = vreq.getPortal();
|
||||||
|
String standaloneTemplate = "entityComparisonOnGrantsStandalone.ftl";
|
||||||
Gson json = new Gson();
|
|
||||||
Set<JsonObject> subEntitiesJson = new HashSet<JsonObject>();
|
String organizationLabel = EntityComparisonUtilityFunctions.getEntityLabelFromDAO(vreq,
|
||||||
|
entityURI);
|
||||||
for (SubEntity subentity : subentities) {
|
|
||||||
JsonObject entityJson = new JsonObject(
|
Map<String, Object> body = new HashMap<String, Object>();
|
||||||
subentity.getIndividualLabel());
|
body.put("portalBean", portal);
|
||||||
|
body.put("title", organizationLabel + " - Temporal Graph Visualization");
|
||||||
List<List<Integer>> yearGrantCount = new ArrayList<List<Integer>>();
|
body.put("organizationURI", entityURI);
|
||||||
|
body.put("organizationLabel", organizationLabel);
|
||||||
for (Map.Entry<String, Integer> grantEntry : UtilityFunctions
|
|
||||||
.getYearToActivityCount(subentity.getActivities())
|
return new TemplateResponseValues(standaloneTemplate, body);
|
||||||
.entrySet()) {
|
}
|
||||||
|
|
||||||
List<Integer> currentGrantYear = new ArrayList<Integer>();
|
/**
|
||||||
if (grantEntry.getKey().equals(
|
* Function to generate a json file for year <-> grant count mapping.
|
||||||
VOConstants.DEFAULT_GRANT_YEAR)) {
|
* @param vreq
|
||||||
currentGrantYear.add(-1);
|
* @param subentities
|
||||||
} else {
|
* @param subOrganizationTypesResult
|
||||||
currentGrantYear.add(Integer.parseInt(grantEntry.getKey()));
|
*/
|
||||||
}
|
private String writeGrantsOverTimeJSON(VitroRequest vreq,
|
||||||
|
Set<SubEntity> subentities) {
|
||||||
currentGrantYear.add(grantEntry.getValue());
|
|
||||||
yearGrantCount.add(currentGrantYear);
|
Gson json = new Gson();
|
||||||
}
|
Set<JsonObject> subEntitiesJson = new HashSet<JsonObject>();
|
||||||
|
|
||||||
entityJson.setYearToActivityCount(yearGrantCount);
|
for (SubEntity subentity : subentities) {
|
||||||
|
JsonObject entityJson = new JsonObject(
|
||||||
entityJson.setOrganizationTypes(subentity.getEntityTypeLabels());
|
subentity.getIndividualLabel());
|
||||||
|
|
||||||
entityJson.setEntityURI(subentity.getIndividualURI());
|
List<List<Integer>> yearGrantCount = new ArrayList<List<Integer>>();
|
||||||
|
|
||||||
if (subentity.getEntityClass().equals(VOConstants.EntityClassType.PERSON)) {
|
for (Map.Entry<String, Integer> grantEntry : UtilityFunctions
|
||||||
entityJson.setVisMode("PERSON");
|
.getYearToActivityCount(subentity.getActivities())
|
||||||
} else if (subentity.getEntityClass().equals(VOConstants.EntityClassType.ORGANIZATION)) {
|
.entrySet()) {
|
||||||
entityJson.setVisMode("ORGANIZATION");
|
|
||||||
}
|
List<Integer> currentGrantYear = new ArrayList<Integer>();
|
||||||
|
if (grantEntry.getKey().equals(
|
||||||
subEntitiesJson.add(entityJson);
|
VOConstants.DEFAULT_GRANT_YEAR)) {
|
||||||
}
|
currentGrantYear.add(-1);
|
||||||
|
} else {
|
||||||
return json.toJson(subEntitiesJson);
|
currentGrantYear.add(Integer.parseInt(grantEntry.getKey()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getEntityGrantsPerYearCSVContent(Entity entity) {
|
currentGrantYear.add(grantEntry.getValue());
|
||||||
|
yearGrantCount.add(currentGrantYear);
|
||||||
StringBuilder csvFileContent = new StringBuilder();
|
}
|
||||||
|
|
||||||
csvFileContent.append("Entity Name, Grant Count, Entity Type\n");
|
entityJson.setYearToActivityCount(yearGrantCount);
|
||||||
|
|
||||||
for (SubEntity subEntity : entity.getSubEntities()) {
|
entityJson.setOrganizationTypes(subentity.getEntityTypeLabels());
|
||||||
|
|
||||||
csvFileContent.append(StringEscapeUtils.escapeCsv(subEntity.getIndividualLabel()));
|
entityJson.setEntityURI(subentity.getIndividualURI());
|
||||||
csvFileContent.append(", ");
|
|
||||||
csvFileContent.append(subEntity.getActivities().size());
|
if (subentity.getEntityClass().equals(VOConstants.EntityClassType.PERSON)) {
|
||||||
csvFileContent.append(", ");
|
entityJson.setVisMode("PERSON");
|
||||||
|
} else if (subentity.getEntityClass().equals(VOConstants.EntityClassType.ORGANIZATION)) {
|
||||||
String allTypes = StringUtils.join(subEntity.getEntityTypeLabels(), "; ");
|
entityJson.setVisMode("ORGANIZATION");
|
||||||
|
}
|
||||||
csvFileContent.append(StringEscapeUtils.escapeCsv(allTypes));
|
|
||||||
csvFileContent.append("\n");
|
subEntitiesJson.add(entityJson);
|
||||||
}
|
}
|
||||||
|
|
||||||
return csvFileContent.toString();
|
return json.toJson(subEntitiesJson);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
private String getEntityGrantsPerYearCSVContent(Entity entity) {
|
||||||
|
|
||||||
|
StringBuilder csvFileContent = new StringBuilder();
|
||||||
|
|
||||||
|
csvFileContent.append("Entity Name, Grant Count, Entity Type\n");
|
||||||
|
|
||||||
|
for (SubEntity subEntity : entity.getSubEntities()) {
|
||||||
|
|
||||||
|
csvFileContent.append(StringEscapeUtils.escapeCsv(subEntity.getIndividualLabel()));
|
||||||
|
csvFileContent.append(", ");
|
||||||
|
csvFileContent.append(subEntity.getActivities().size());
|
||||||
|
csvFileContent.append(", ");
|
||||||
|
|
||||||
|
String allTypes = StringUtils.join(subEntity.getEntityTypeLabels(), "; ");
|
||||||
|
|
||||||
|
csvFileContent.append(StringEscapeUtils.escapeCsv(allTypes));
|
||||||
|
csvFileContent.append("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
return csvFileContent.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,350 +1,347 @@
|
||||||
/* $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$ */
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.visualization.freemarker.entitycomparison.cached;
|
package edu.cornell.mannlib.vitro.webapp.visualization.freemarker.entitycomparison.cached;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringEscapeUtils;
|
import org.apache.commons.lang.StringEscapeUtils;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.hp.hpl.jena.query.Dataset;
|
import com.hp.hpl.jena.query.Dataset;
|
||||||
import com.hp.hpl.jena.rdf.model.Model;
|
import com.hp.hpl.jena.rdf.model.Model;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.Portal;
|
import edu.cornell.mannlib.vitro.webapp.beans.Portal;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
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.ResponseValues;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.TemplateResponseValues;
|
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.DataVisualizationController;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.visualization.freemarker.VisualizationFrameworkConstants;
|
import edu.cornell.mannlib.vitro.webapp.controller.visualization.freemarker.VisualizationFrameworkConstants;
|
||||||
import edu.cornell.mannlib.vitro.webapp.visualization.constants.VOConstants;
|
import edu.cornell.mannlib.vitro.webapp.visualization.constants.VOConstants;
|
||||||
import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException;
|
import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException;
|
||||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.entitycomparison.EntityComparisonUtilityFunctions;
|
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.entitycomparison.EntityComparisonUtilityFunctions;
|
||||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.valueobjects.Activity;
|
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.valueobjects.Activity;
|
||||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.valueobjects.ConstructedModelTracker;
|
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.valueobjects.ConstructedModelTracker;
|
||||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.valueobjects.Entity;
|
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.JsonObject;
|
||||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.valueobjects.SubEntity;
|
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.valueobjects.SubEntity;
|
||||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.SelectOnModelUtilities;
|
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.SelectOnModelUtilities;
|
||||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.UtilityFunctions;
|
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.UtilityFunctions;
|
||||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.VisualizationRequestHandler;
|
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.VisualizationRequestHandler;
|
||||||
|
|
||||||
public class TemporalPublicationVisualizationRequestHandler implements
|
public class TemporalPublicationVisualizationRequestHandler implements
|
||||||
VisualizationRequestHandler {
|
VisualizationRequestHandler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResponseValues generateStandardVisualization(
|
public ResponseValues generateStandardVisualization(
|
||||||
VitroRequest vitroRequest, Log log, Dataset dataset)
|
VitroRequest vitroRequest, Log log, Dataset dataset)
|
||||||
throws MalformedQueryParametersException {
|
throws MalformedQueryParametersException {
|
||||||
|
|
||||||
|
|
||||||
String entityURI = vitroRequest
|
String entityURI = vitroRequest
|
||||||
.getParameter(VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY);
|
.getParameter(VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY);
|
||||||
|
|
||||||
if (StringUtils.isBlank(entityURI)) {
|
if (StringUtils.isBlank(entityURI)) {
|
||||||
|
|
||||||
entityURI = EntityComparisonUtilityFunctions
|
entityURI = EntityComparisonUtilityFunctions
|
||||||
.getStaffProvidedOrComputedHighestLevelOrganization(
|
.getStaffProvidedOrComputedHighestLevelOrganization(
|
||||||
log,
|
log,
|
||||||
dataset,
|
dataset,
|
||||||
vitroRequest);
|
vitroRequest);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
System.out.println("current models in the system are");
|
System.out.println("current models in the system are");
|
||||||
for (Map.Entry<String, Model> entry : ConstructedModelTracker.getAllModels().entrySet()) {
|
for (Map.Entry<String, Model> entry : ConstructedModelTracker.getAllModels().entrySet()) {
|
||||||
System.out.println(entry.getKey() + " -> " + entry.getValue().size());
|
System.out.println(entry.getKey() + " -> " + entry.getValue().size());
|
||||||
}
|
}
|
||||||
|
|
||||||
return prepareStandaloneMarkupResponse(vitroRequest, entityURI);
|
return prepareStandaloneMarkupResponse(vitroRequest, entityURI);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<String, String> getSubjectEntityAndGenerateDataResponse(
|
private Map<String, String> getSubjectEntityAndGenerateDataResponse(
|
||||||
VitroRequest vitroRequest, Log log, Dataset dataset,
|
VitroRequest vitroRequest, Log log, Dataset dataset,
|
||||||
String subjectEntityURI, EntityComparisonConstants.DataVisMode visMode)
|
String subjectEntityURI, EntityComparisonConstants.DataVisMode visMode)
|
||||||
throws MalformedQueryParametersException {
|
throws MalformedQueryParametersException {
|
||||||
|
|
||||||
|
|
||||||
Entity organizationEntity = SelectOnModelUtilities
|
Entity organizationEntity = SelectOnModelUtilities
|
||||||
.getSubjectOrganizationHierarchy(dataset, subjectEntityURI);
|
.getSubjectOrganizationHierarchy(dataset, subjectEntityURI);
|
||||||
|
|
||||||
if (organizationEntity.getSubEntities() == null) {
|
if (organizationEntity.getSubEntities() == null) {
|
||||||
|
|
||||||
if (EntityComparisonConstants.DataVisMode.JSON.equals(visMode)) {
|
if (EntityComparisonConstants.DataVisMode.JSON.equals(visMode)) {
|
||||||
return prepareStandaloneDataErrorResponse();
|
return prepareStandaloneDataErrorResponse();
|
||||||
} else {
|
} else {
|
||||||
return prepareDataErrorResponse();
|
return prepareDataErrorResponse();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
||||||
|
Map<String, Activity> documentURIForAssociatedPeopleTOVO = new HashMap<String, Activity>();
|
||||||
Map<String, Activity> documentURIForAssociatedPeopleTOVO = new HashMap<String, Activity>();
|
Map<String, Activity> allDocumentURIToVOs = new HashMap<String, Activity>();
|
||||||
Map<String, Activity> allDocumentURIToVOs = new HashMap<String, Activity>();
|
|
||||||
|
allDocumentURIToVOs = SelectOnModelUtilities.getPublicationsForAllSubOrganizations(dataset, organizationEntity);
|
||||||
allDocumentURIToVOs = SelectOnModelUtilities.getPublicationsForAllSubOrganizations(dataset, organizationEntity);
|
|
||||||
|
Entity organizationWithAssociatedPeople = SelectOnModelUtilities
|
||||||
Entity organizationWithAssociatedPeople = SelectOnModelUtilities
|
.getSubjectOrganizationAssociatedPeople(dataset, subjectEntityURI);
|
||||||
.getSubjectOrganizationAssociatedPeople(dataset, subjectEntityURI);
|
|
||||||
|
|
||||||
|
if (organizationWithAssociatedPeople.getSubEntities() != null) {
|
||||||
if (organizationWithAssociatedPeople.getSubEntities() != null) {
|
|
||||||
|
documentURIForAssociatedPeopleTOVO = SelectOnModelUtilities
|
||||||
documentURIForAssociatedPeopleTOVO = SelectOnModelUtilities
|
.getPublicationsForAssociatedPeople(dataset, organizationWithAssociatedPeople.getSubEntities());
|
||||||
.getPublicationsForAssociatedPeople(dataset, organizationWithAssociatedPeople.getSubEntities());
|
|
||||||
|
organizationEntity = EntityComparisonUtilityFunctions.mergeEntityIfShareSameURI(
|
||||||
organizationEntity = EntityComparisonUtilityFunctions.mergeEntityIfShareSameURI(
|
organizationEntity,
|
||||||
organizationEntity,
|
organizationWithAssociatedPeople);
|
||||||
organizationWithAssociatedPeople);
|
}
|
||||||
}
|
|
||||||
|
if (allDocumentURIToVOs.isEmpty() && documentURIForAssociatedPeopleTOVO.isEmpty()) {
|
||||||
if (allDocumentURIToVOs.isEmpty() && documentURIForAssociatedPeopleTOVO.isEmpty()) {
|
|
||||||
|
if (EntityComparisonConstants.DataVisMode.JSON.equals(visMode)) {
|
||||||
if (EntityComparisonConstants.DataVisMode.JSON.equals(visMode)) {
|
return prepareStandaloneDataErrorResponse();
|
||||||
return prepareStandaloneDataErrorResponse();
|
} else {
|
||||||
} else {
|
return prepareDataErrorResponse();
|
||||||
return prepareDataErrorResponse();
|
}
|
||||||
}
|
|
||||||
|
} else {
|
||||||
} else {
|
|
||||||
|
if (EntityComparisonConstants.DataVisMode.JSON.equals(visMode)) {
|
||||||
if (EntityComparisonConstants.DataVisMode.JSON.equals(visMode)) {
|
return prepareStandaloneDataResponse(vitroRequest, organizationEntity);
|
||||||
return prepareStandaloneDataResponse(vitroRequest, organizationEntity);
|
} else {
|
||||||
} else {
|
return prepareDataResponse(organizationEntity);
|
||||||
return prepareDataResponse(organizationEntity);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
/**
|
||||||
/**
|
* Provides response when json file containing the publication count over the
|
||||||
* Provides response when json file containing the publication count over the
|
* years is requested.
|
||||||
* years is requested.
|
*
|
||||||
*
|
* @param entity
|
||||||
* @param entity
|
* @param subentities
|
||||||
* @param subentities
|
* @param subOrganizationTypesResult
|
||||||
* @param subOrganizationTypesResult
|
*/
|
||||||
*/
|
private Map<String, String> prepareDataResponse(Entity entity) {
|
||||||
private Map<String, String> prepareDataResponse(Entity entity) {
|
|
||||||
|
String entityLabel = entity.getEntityLabel();
|
||||||
String entityLabel = entity.getEntityLabel();
|
|
||||||
|
/*
|
||||||
/*
|
* To make sure that null/empty records for entity names do not cause any mischief.
|
||||||
* To make sure that null/empty records for entity names do not cause any mischief.
|
* */
|
||||||
* */
|
if (StringUtils.isBlank(entityLabel)) {
|
||||||
if (StringUtils.isBlank(entityLabel)) {
|
entityLabel = "no-organization";
|
||||||
entityLabel = "no-organization";
|
}
|
||||||
}
|
|
||||||
|
String outputFileName = UtilityFunctions.slugify(entityLabel)
|
||||||
String outputFileName = UtilityFunctions.slugify(entityLabel)
|
+ "_publications-per-year" + ".csv";
|
||||||
+ "_publications-per-year" + ".csv";
|
|
||||||
|
|
||||||
|
Map<String, String> fileData = new HashMap<String, String>();
|
||||||
Map<String, String> fileData = new HashMap<String, String>();
|
|
||||||
|
fileData.put(DataVisualizationController.FILE_NAME_KEY,
|
||||||
fileData.put(DataVisualizationController.FILE_NAME_KEY,
|
outputFileName);
|
||||||
outputFileName);
|
fileData.put(DataVisualizationController.FILE_CONTENT_TYPE_KEY,
|
||||||
fileData.put(DataVisualizationController.FILE_CONTENT_TYPE_KEY,
|
"application/octet-stream");
|
||||||
"application/octet-stream");
|
fileData.put(DataVisualizationController.FILE_CONTENT_KEY,
|
||||||
fileData.put(DataVisualizationController.FILE_CONTENT_KEY,
|
getEntityPublicationsPerYearCSVContent(entity));
|
||||||
getEntityPublicationsPerYearCSVContent(entity));
|
return fileData;
|
||||||
return fileData;
|
}
|
||||||
}
|
|
||||||
|
private Map<String, String> prepareDataErrorResponse() {
|
||||||
private Map<String, String> prepareDataErrorResponse() {
|
|
||||||
|
String outputFileName = "no-organization_publications-per-year.csv";
|
||||||
String outputFileName = "no-organization_publications-per-year.csv";
|
|
||||||
|
Map<String, String> fileData = new HashMap<String, String>();
|
||||||
Map<String, String> fileData = new HashMap<String, String>();
|
|
||||||
|
fileData.put(DataVisualizationController.FILE_NAME_KEY,
|
||||||
fileData.put(DataVisualizationController.FILE_NAME_KEY,
|
outputFileName);
|
||||||
outputFileName);
|
fileData.put(DataVisualizationController.FILE_CONTENT_TYPE_KEY,
|
||||||
fileData.put(DataVisualizationController.FILE_CONTENT_TYPE_KEY,
|
"application/octet-stream");
|
||||||
"application/octet-stream");
|
fileData.put(DataVisualizationController.FILE_CONTENT_KEY, "");
|
||||||
fileData.put(DataVisualizationController.FILE_CONTENT_KEY, "");
|
return fileData;
|
||||||
return fileData;
|
}
|
||||||
}
|
|
||||||
|
private Map<String, String> prepareStandaloneDataErrorResponse() {
|
||||||
private Map<String, String> prepareStandaloneDataErrorResponse() {
|
|
||||||
|
Map<String, String> fileData = new HashMap<String, String>();
|
||||||
Map<String, String> fileData = new HashMap<String, String>();
|
|
||||||
|
fileData.put(DataVisualizationController.FILE_CONTENT_TYPE_KEY,
|
||||||
fileData.put(DataVisualizationController.FILE_CONTENT_TYPE_KEY,
|
"application/octet-stream");
|
||||||
"application/octet-stream");
|
fileData.put(DataVisualizationController.FILE_CONTENT_KEY,
|
||||||
fileData.put(DataVisualizationController.FILE_CONTENT_KEY,
|
"{\"error\" : \"No Publications for this Organization found in VIVO.\"}");
|
||||||
"{\"error\" : \"No Publications for this Organization found in VIVO.\"}");
|
return fileData;
|
||||||
return fileData;
|
}
|
||||||
}
|
|
||||||
|
@Override
|
||||||
@Override
|
public Map<String, String> generateDataVisualization(
|
||||||
public Map<String, String> generateDataVisualization(
|
VitroRequest vitroRequest, Log log, Dataset dataset)
|
||||||
VitroRequest vitroRequest, Log log, Dataset dataset)
|
throws MalformedQueryParametersException {
|
||||||
throws MalformedQueryParametersException {
|
|
||||||
|
String entityURI = vitroRequest
|
||||||
String entityURI = vitroRequest
|
.getParameter(VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY);
|
||||||
.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 tmeporal vis.
|
* */
|
||||||
* */
|
if (VisualizationFrameworkConstants.TEMPORAL_GRAPH_JSON_DATA_VIS_MODE
|
||||||
if (VisualizationFrameworkConstants.TEMPORAL_GRAPH_JSON_DATA_VIS_MODE
|
.equalsIgnoreCase(vitroRequest.getParameter(
|
||||||
.equalsIgnoreCase(vitroRequest.getParameter(
|
VisualizationFrameworkConstants.VIS_MODE_KEY))) {
|
||||||
VisualizationFrameworkConstants.VIS_MODE_KEY))) {
|
|
||||||
|
if (StringUtils.isNotBlank(entityURI)) {
|
||||||
if (StringUtils.isNotBlank(entityURI)) {
|
|
||||||
|
return getSubjectEntityAndGenerateDataResponse(
|
||||||
return getSubjectEntityAndGenerateDataResponse(
|
vitroRequest,
|
||||||
vitroRequest,
|
log,
|
||||||
log,
|
dataset,
|
||||||
dataset,
|
entityURI,
|
||||||
entityURI,
|
EntityComparisonConstants.DataVisMode.JSON);
|
||||||
EntityComparisonConstants.DataVisMode.JSON);
|
} else {
|
||||||
} else {
|
|
||||||
|
return getSubjectEntityAndGenerateDataResponse(
|
||||||
return getSubjectEntityAndGenerateDataResponse(
|
vitroRequest,
|
||||||
vitroRequest,
|
log,
|
||||||
log,
|
dataset,
|
||||||
dataset,
|
EntityComparisonUtilityFunctions
|
||||||
EntityComparisonUtilityFunctions
|
.getStaffProvidedOrComputedHighestLevelOrganization(
|
||||||
.getStaffProvidedOrComputedHighestLevelOrganization(
|
log,
|
||||||
log,
|
dataset,
|
||||||
dataset,
|
vitroRequest),
|
||||||
vitroRequest),
|
EntityComparisonConstants.DataVisMode.JSON);
|
||||||
EntityComparisonConstants.DataVisMode.JSON);
|
}
|
||||||
}
|
|
||||||
|
} else {
|
||||||
} else {
|
/*
|
||||||
/*
|
* This provides csv download files for the content in the tables.
|
||||||
* This provides csv download files for the content in the tables.
|
* */
|
||||||
* */
|
|
||||||
|
return getSubjectEntityAndGenerateDataResponse(
|
||||||
return getSubjectEntityAndGenerateDataResponse(
|
vitroRequest,
|
||||||
vitroRequest,
|
log,
|
||||||
log,
|
dataset,
|
||||||
dataset,
|
entityURI,
|
||||||
entityURI,
|
EntityComparisonConstants.DataVisMode.CSV);
|
||||||
EntityComparisonConstants.DataVisMode.CSV);
|
|
||||||
|
}
|
||||||
}
|
|
||||||
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
@Override
|
||||||
@Override
|
public Object generateAjaxVisualization(VitroRequest vitroRequest, Log log,
|
||||||
public Object generateAjaxVisualization(VitroRequest vitroRequest, Log log,
|
Dataset dataset) throws MalformedQueryParametersException {
|
||||||
Dataset dataset) throws MalformedQueryParametersException {
|
throw new UnsupportedOperationException("Entity Pub Count does not provide Ajax Response.");
|
||||||
throw new UnsupportedOperationException("Entity Pub Count does not provide Ajax Response.");
|
}
|
||||||
}
|
|
||||||
|
private Map<String, String> prepareStandaloneDataResponse(
|
||||||
private Map<String, String> prepareStandaloneDataResponse(
|
VitroRequest vitroRequest,
|
||||||
VitroRequest vitroRequest,
|
Entity entity) {
|
||||||
Entity entity) {
|
|
||||||
|
Map<String, String> fileData = new HashMap<String, String>();
|
||||||
Map<String, String> fileData = new HashMap<String, String>();
|
|
||||||
|
fileData.put(DataVisualizationController.FILE_CONTENT_TYPE_KEY,
|
||||||
fileData.put(DataVisualizationController.FILE_CONTENT_TYPE_KEY,
|
"application/octet-stream");
|
||||||
"application/octet-stream");
|
fileData.put(DataVisualizationController.FILE_CONTENT_KEY,
|
||||||
fileData.put(DataVisualizationController.FILE_CONTENT_KEY,
|
writePublicationsOverTimeJSON(vitroRequest,
|
||||||
writePublicationsOverTimeJSON(vitroRequest,
|
entity.getSubEntities()));
|
||||||
entity.getSubEntities()));
|
return fileData;
|
||||||
return fileData;
|
}
|
||||||
}
|
|
||||||
|
private TemplateResponseValues prepareStandaloneMarkupResponse(VitroRequest vreq,
|
||||||
private TemplateResponseValues prepareStandaloneMarkupResponse(VitroRequest vreq,
|
String entityURI) {
|
||||||
String entityURI) {
|
|
||||||
|
Portal portal = vreq.getPortal();
|
||||||
Portal portal = vreq.getPortal();
|
String standaloneTemplate = "entityComparisonOnPublicationsStandalone.ftl";
|
||||||
String standaloneTemplate = "entityComparisonOnPublicationsStandalone.ftl";
|
|
||||||
|
String organizationLabel = EntityComparisonUtilityFunctions
|
||||||
String organizationLabel = EntityComparisonUtilityFunctions
|
.getEntityLabelFromDAO(vreq,
|
||||||
.getEntityLabelFromDAO(vreq,
|
entityURI);
|
||||||
entityURI);
|
|
||||||
|
Map<String, Object> body = new HashMap<String, Object>();
|
||||||
Map<String, Object> body = new HashMap<String, Object>();
|
body.put("portalBean", portal);
|
||||||
body.put("portalBean", portal);
|
body.put("title", organizationLabel + " - Temporal Graph Visualization");
|
||||||
body.put("title", organizationLabel + " - Temporal Graph Visualization");
|
body.put("organizationURI", entityURI);
|
||||||
body.put("organizationURI", entityURI);
|
body.put("organizationLabel", organizationLabel);
|
||||||
body.put("organizationLabel", organizationLabel);
|
|
||||||
|
return new TemplateResponseValues(standaloneTemplate, body);
|
||||||
return new TemplateResponseValues(standaloneTemplate, body);
|
}
|
||||||
}
|
|
||||||
|
/**
|
||||||
/**
|
* Function to generate a json file for year <-> publication count mapping.
|
||||||
* Function to generate a json file for year <-> publication count mapping.
|
* @param vreq
|
||||||
* @param vreq
|
* @param subentities
|
||||||
* @param subentities
|
* @param subOrganizationTypesResult
|
||||||
* @param subOrganizationTypesResult
|
*/
|
||||||
*/
|
private String writePublicationsOverTimeJSON(VitroRequest vreq,
|
||||||
private String writePublicationsOverTimeJSON(VitroRequest vreq,
|
Set<SubEntity> subentities) {
|
||||||
Set<SubEntity> subentities) {
|
|
||||||
|
Gson json = new Gson();
|
||||||
Gson json = new Gson();
|
Set<JsonObject> subEntitiesJson = new HashSet<JsonObject>();
|
||||||
Set<JsonObject> subEntitiesJson = new HashSet<JsonObject>();
|
|
||||||
|
for (SubEntity subentity : subentities) {
|
||||||
for (SubEntity subentity : subentities) {
|
|
||||||
|
JsonObject entityJson = new JsonObject(
|
||||||
System.out.println("in write json current sub entity " + subentity.getIndividualLabel());
|
subentity.getIndividualLabel());
|
||||||
|
|
||||||
JsonObject entityJson = new JsonObject(
|
List<List<Integer>> yearPubCount = new ArrayList<List<Integer>>();
|
||||||
subentity.getIndividualLabel());
|
|
||||||
|
for (Map.Entry<String, Integer> pubEntry : UtilityFunctions
|
||||||
List<List<Integer>> yearPubCount = new ArrayList<List<Integer>>();
|
.getYearToActivityCount(subentity.getActivities())
|
||||||
|
.entrySet()) {
|
||||||
for (Map.Entry<String, Integer> pubEntry : UtilityFunctions
|
|
||||||
.getYearToActivityCount(subentity.getActivities())
|
List<Integer> currentPubYear = new ArrayList<Integer>();
|
||||||
.entrySet()) {
|
if (pubEntry.getKey().equals(VOConstants.DEFAULT_PUBLICATION_YEAR)) {
|
||||||
|
currentPubYear.add(-1);
|
||||||
List<Integer> currentPubYear = new ArrayList<Integer>();
|
} else {
|
||||||
if (pubEntry.getKey().equals(VOConstants.DEFAULT_PUBLICATION_YEAR)) {
|
currentPubYear.add(Integer.parseInt(pubEntry.getKey()));
|
||||||
currentPubYear.add(-1);
|
}
|
||||||
} else {
|
|
||||||
currentPubYear.add(Integer.parseInt(pubEntry.getKey()));
|
currentPubYear.add(pubEntry.getValue());
|
||||||
}
|
yearPubCount.add(currentPubYear);
|
||||||
|
}
|
||||||
currentPubYear.add(pubEntry.getValue());
|
|
||||||
yearPubCount.add(currentPubYear);
|
entityJson.setYearToActivityCount(yearPubCount);
|
||||||
}
|
|
||||||
|
entityJson.setOrganizationTypes(subentity.getEntityTypeLabels());
|
||||||
entityJson.setYearToActivityCount(yearPubCount);
|
|
||||||
|
entityJson.setEntityURI(subentity.getIndividualURI());
|
||||||
entityJson.setOrganizationTypes(subentity.getEntityTypeLabels());
|
|
||||||
|
if (subentity.getEntityClass().equals(VOConstants.EntityClassType.PERSON)) {
|
||||||
entityJson.setEntityURI(subentity.getIndividualURI());
|
entityJson.setVisMode("PERSON");
|
||||||
|
} else if (subentity.getEntityClass().equals(VOConstants.EntityClassType.ORGANIZATION)) {
|
||||||
if (subentity.getEntityClass().equals(VOConstants.EntityClassType.PERSON)) {
|
entityJson.setVisMode("ORGANIZATION");
|
||||||
entityJson.setVisMode("PERSON");
|
}
|
||||||
} else if (subentity.getEntityClass().equals(VOConstants.EntityClassType.ORGANIZATION)) {
|
|
||||||
entityJson.setVisMode("ORGANIZATION");
|
subEntitiesJson.add(entityJson);
|
||||||
}
|
}
|
||||||
|
return json.toJson(subEntitiesJson);
|
||||||
subEntitiesJson.add(entityJson);
|
}
|
||||||
}
|
|
||||||
return json.toJson(subEntitiesJson);
|
private String getEntityPublicationsPerYearCSVContent(Entity entity) {
|
||||||
}
|
|
||||||
|
StringBuilder csvFileContent = new StringBuilder();
|
||||||
private String getEntityPublicationsPerYearCSVContent(Entity entity) {
|
|
||||||
|
csvFileContent.append("Entity Name, Publication Count, Entity Type\n");
|
||||||
StringBuilder csvFileContent = new StringBuilder();
|
|
||||||
|
for (SubEntity subEntity : entity.getSubEntities()) {
|
||||||
csvFileContent.append("Entity Name, Publication Count, Entity Type\n");
|
|
||||||
|
csvFileContent.append(StringEscapeUtils.escapeCsv(subEntity.getIndividualLabel()));
|
||||||
for (SubEntity subEntity : entity.getSubEntities()) {
|
csvFileContent.append(", ");
|
||||||
|
csvFileContent.append(subEntity.getActivities().size());
|
||||||
csvFileContent.append(StringEscapeUtils.escapeCsv(subEntity.getIndividualLabel()));
|
csvFileContent.append(", ");
|
||||||
csvFileContent.append(", ");
|
|
||||||
csvFileContent.append(subEntity.getActivities().size());
|
String allTypes = StringUtils.join(subEntity.getEntityTypeLabels(), "; ");
|
||||||
csvFileContent.append(", ");
|
|
||||||
|
csvFileContent.append(StringEscapeUtils.escapeCsv(allTypes));
|
||||||
String allTypes = StringUtils.join(subEntity.getEntityTypeLabels(), "; ");
|
csvFileContent.append("\n");
|
||||||
|
}
|
||||||
csvFileContent.append(StringEscapeUtils.escapeCsv(allTypes));
|
return csvFileContent.toString();
|
||||||
csvFileContent.append("\n");
|
}
|
||||||
}
|
|
||||||
return csvFileContent.toString();
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -1,33 +1,35 @@
|
||||||
/* $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$ */
|
||||||
package edu.cornell.mannlib.vitro.webapp.visualization.freemarker.modelconstructor;
|
package edu.cornell.mannlib.vitro.webapp.visualization.freemarker.modelconstructor;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import com.hp.hpl.jena.query.Dataset;
|
import com.hp.hpl.jena.query.Dataset;
|
||||||
import com.hp.hpl.jena.rdf.model.Model;
|
import com.hp.hpl.jena.rdf.model.Model;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException;
|
import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException;
|
||||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.modelconstructor.factory.ModelFactoryInterface;
|
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.modelconstructor.factory.ModelFactoryInterface;
|
||||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.modelconstructor.factory.OrganizationAssociatedPeopleModelWithTypesFactory;
|
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.modelconstructor.factory.OrganizationAssociatedPeopleModelWithTypesFactory;
|
||||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.modelconstructor.factory.OrganizationModelWithTypesFactory;
|
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.modelconstructor.factory.OrganizationModelWithTypesFactory;
|
||||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.modelconstructor.factory.OrganizationToGrantsForSubOrganizationsFactory;
|
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.modelconstructor.factory.OrganizationToGrantsForSubOrganizationsFactory;
|
||||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.modelconstructor.factory.OrganizationToPublicationsForSubOrganizationsFactory;
|
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.modelconstructor.factory.OrganizationToPublicationsForSubOrganizationsFactory;
|
||||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.modelconstructor.factory.PersonToPublicationsFactory;
|
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.modelconstructor.factory.PersonToGrantsFactory;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.modelconstructor.factory.PersonToPublicationsFactory;
|
||||||
public class ModelConstructorUtilities {
|
|
||||||
|
public class ModelConstructorUtilities {
|
||||||
@SuppressWarnings("serial")
|
|
||||||
private static final Map<String, ModelFactoryInterface> modelTypeIdentifierToFactory = new HashMap<String, ModelFactoryInterface>() {{
|
@SuppressWarnings("serial")
|
||||||
put(PersonToPublicationsModelConstructor.MODEL_TYPE, new PersonToPublicationsFactory());
|
private static final Map<String, ModelFactoryInterface> modelTypeIdentifierToFactory = new HashMap<String, ModelFactoryInterface>() {{
|
||||||
put(OrganizationToPublicationsForSubOrganizationsModelConstructor.MODEL_TYPE, new OrganizationToPublicationsForSubOrganizationsFactory());
|
put(PersonToPublicationsModelConstructor.MODEL_TYPE, new PersonToPublicationsFactory());
|
||||||
put(OrganizationToGrantsForSubOrganizationsModelConstructor.MODEL_TYPE, new OrganizationToGrantsForSubOrganizationsFactory());
|
put(PersonToGrantsModelConstructor.MODEL_TYPE, new PersonToGrantsFactory());
|
||||||
put(OrganizationAssociatedPeopleModelWithTypesConstructor.MODEL_TYPE, new OrganizationAssociatedPeopleModelWithTypesFactory());
|
put(OrganizationToPublicationsForSubOrganizationsModelConstructor.MODEL_TYPE, new OrganizationToPublicationsForSubOrganizationsFactory());
|
||||||
put(OrganizationModelWithTypesConstructor.MODEL_TYPE, new OrganizationModelWithTypesFactory());
|
put(OrganizationToGrantsForSubOrganizationsModelConstructor.MODEL_TYPE, new OrganizationToGrantsForSubOrganizationsFactory());
|
||||||
}};
|
put(OrganizationAssociatedPeopleModelWithTypesConstructor.MODEL_TYPE, new OrganizationAssociatedPeopleModelWithTypesFactory());
|
||||||
|
put(OrganizationModelWithTypesConstructor.MODEL_TYPE, new OrganizationModelWithTypesFactory());
|
||||||
public static Model getOrConstructModel(String uri, String modelType, Dataset dataset)
|
}};
|
||||||
throws MalformedQueryParametersException {
|
|
||||||
return modelTypeIdentifierToFactory.get(modelType).getOrCreateModel(uri, dataset);
|
public static Model getOrConstructModel(String uri, String modelType, Dataset dataset)
|
||||||
}
|
throws MalformedQueryParametersException {
|
||||||
}
|
return modelTypeIdentifierToFactory.get(modelType).getOrCreateModel(uri, dataset);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,133 +1,188 @@
|
||||||
/* $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$ */
|
||||||
package edu.cornell.mannlib.vitro.webapp.visualization.freemarker.modelconstructor;
|
package edu.cornell.mannlib.vitro.webapp.visualization.freemarker.modelconstructor;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import java.util.HashSet;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import java.util.Set;
|
||||||
|
|
||||||
import com.hp.hpl.jena.query.Dataset;
|
import org.apache.commons.logging.Log;
|
||||||
import com.hp.hpl.jena.query.Query;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import com.hp.hpl.jena.query.QueryExecution;
|
|
||||||
import com.hp.hpl.jena.query.QueryExecutionFactory;
|
import com.hp.hpl.jena.query.Dataset;
|
||||||
import com.hp.hpl.jena.query.QueryFactory;
|
import com.hp.hpl.jena.query.Query;
|
||||||
import com.hp.hpl.jena.query.Syntax;
|
import com.hp.hpl.jena.query.QueryExecution;
|
||||||
import com.hp.hpl.jena.rdf.model.Model;
|
import com.hp.hpl.jena.query.QueryExecutionFactory;
|
||||||
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
import com.hp.hpl.jena.query.QueryFactory;
|
||||||
|
import com.hp.hpl.jena.query.Syntax;
|
||||||
import edu.cornell.mannlib.vitro.webapp.visualization.constants.QueryConstants;
|
import com.hp.hpl.jena.rdf.model.Model;
|
||||||
import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException;
|
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
||||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.ModelConstructor;
|
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.visualization.constants.QueryConstants;
|
||||||
public class OrganizationToGrantsForSubOrganizationsModelConstructor implements ModelConstructor {
|
import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.ModelConstructor;
|
||||||
protected static final Syntax SYNTAX = Syntax.syntaxARQ;
|
|
||||||
|
public class OrganizationToGrantsForSubOrganizationsModelConstructor implements ModelConstructor {
|
||||||
private Dataset dataset;
|
|
||||||
|
protected static final Syntax SYNTAX = Syntax.syntaxARQ;
|
||||||
public static final String MODEL_TYPE = "ORGANIZATION_TO_GRANTS_FOR_SUBORGANIZATIONS";
|
|
||||||
|
private Dataset dataset;
|
||||||
private String organizationURI;
|
|
||||||
|
public static final String MODEL_TYPE = "ORGANIZATION_TO_GRANTS_FOR_SUBORGANIZATIONS";
|
||||||
private Log log = LogFactory.getLog(OrganizationToGrantsForSubOrganizationsModelConstructor.class.getName());
|
|
||||||
|
private String organizationURI;
|
||||||
private long before, after;
|
|
||||||
|
private Log log = LogFactory.getLog(OrganizationToGrantsForSubOrganizationsModelConstructor.class.getName());
|
||||||
public OrganizationToGrantsForSubOrganizationsModelConstructor(String organizationURI, Dataset dataset) {
|
|
||||||
this.organizationURI = organizationURI;
|
private long before, after;
|
||||||
this.dataset = dataset;
|
|
||||||
}
|
public OrganizationToGrantsForSubOrganizationsModelConstructor(String organizationURI, Dataset dataset) {
|
||||||
|
this.organizationURI = organizationURI;
|
||||||
private String constructOrganizationToGrantsQuery() {
|
this.dataset = dataset;
|
||||||
|
}
|
||||||
return ""
|
|
||||||
+ " CONSTRUCT { "
|
private Set<String> constructOrganizationGrantsQueryTemplate(String constructProperty, String roleTypeProperty) {
|
||||||
+ " <" + organizationURI + "> rdfs:label ?organizationLabel . "
|
|
||||||
+ " <" + organizationURI + "> vivosocnet:lastCachedAt ?now . "
|
Set<String> differentPerspectiveQueries = new HashSet<String>();
|
||||||
+ " <" + organizationURI + "> vivosocnet:hasPersonWithGrant ?Grant . "
|
|
||||||
+ " "
|
String justGrantsQuery = ""
|
||||||
+ " ?Grant rdf:type core:Grant . "
|
+ " CONSTRUCT { "
|
||||||
+ " ?Grant rdfs:label ?grantLabel . "
|
+ " <" + organizationURI + "> rdfs:label ?organizationLabel . "
|
||||||
+ " "
|
+ " <" + organizationURI + "> vivosocnet:lastCachedAt ?now . "
|
||||||
+ " ?Grant vivosocnet:startDateTimeOnGrant ?startDateTimeValueForGrant . "
|
+ " <" + organizationURI + "> vivosocnet:" + constructProperty + " ?Grant . "
|
||||||
+ " ?Grant vivosocnet:endDateTimeOnGrant ?endDateTimeValueForGrant . "
|
+ " "
|
||||||
+ " "
|
+ " ?Grant rdf:type core:Grant . "
|
||||||
+ " ?Grant vivosocnet:startDateTimeOnRole ?startDateTimeValue . "
|
+ " ?Grant rdfs:label ?grantLabel . "
|
||||||
+ " ?Grant vivosocnet:endDateTimeOnRole ?endDateTimeValue . "
|
+ " "
|
||||||
+ " } "
|
+ " } "
|
||||||
+ " WHERE { "
|
+ " WHERE { "
|
||||||
+ " <" + organizationURI + "> rdfs:label ?organizationLabel . "
|
+ " <" + organizationURI + "> rdfs:label ?organizationLabel . "
|
||||||
+ " <" + organizationURI + "> core:hasSubOrganization* ?subOrganization . "
|
+ " <" + organizationURI + "> core:hasSubOrganization* ?subOrganization . "
|
||||||
+ " ?subOrganization core:organizationForPosition ?Position . "
|
+ " ?subOrganization core:organizationForPosition ?Position . "
|
||||||
+ " ?Position core:positionForPerson ?Person . "
|
+ " ?Position core:positionForPerson ?Person . "
|
||||||
+ " ?Person core:hasInvestigatorRole ?Role . "
|
+ " ?Person core:" + roleTypeProperty + " ?Role . "
|
||||||
+ " ?Role core:roleIn ?Grant . "
|
+ " ?Role core:roleIn ?Grant . "
|
||||||
+ " ?Grant rdfs:label ?grantLabel . "
|
+ " ?Grant rdfs:label ?grantLabel . "
|
||||||
+ " "
|
+ " "
|
||||||
+ " OPTIONAL { "
|
+ " LET(?now := afn:now()) "
|
||||||
+ " ?Grant core:dateTimeInterval ?dateTimeIntervalValueForGrant . "
|
+ " } ";
|
||||||
+ " OPTIONAL { "
|
|
||||||
+ " ?dateTimeIntervalValueForGrant core:start ?startDateForGrant . "
|
String justDateTimeOnGrantsQuery = ""
|
||||||
+ " ?startDateForGrant core:dateTime ?startDateTimeValueForGrant . "
|
+ " CONSTRUCT { "
|
||||||
+ " } "
|
+ " <" + organizationURI + "> rdfs:label ?organizationLabel . "
|
||||||
+ " OPTIONAL { "
|
+ " <" + organizationURI + "> vivosocnet:lastCachedAt ?now . "
|
||||||
+ " ?dateTimeIntervalValueForGrant core:end ?endDateForGrant . "
|
+ " "
|
||||||
+ " ?endDateForGrant core:dateTime ?endDateTimeValueForGrant "
|
+ " ?Grant vivosocnet:startDateTimeOnGrant ?startDateTimeValueForGrant . "
|
||||||
+ " } "
|
// + " ?Grant vivosocnet:endDateTimeOnGrant ?endDateTimeValueForGrant . "
|
||||||
+ " } "
|
+ " "
|
||||||
+ " "
|
+ " } "
|
||||||
+ " OPTIONAL { "
|
+ " WHERE { "
|
||||||
+ " ?Role core:dateTimeInterval ?dateTimeIntervalValue . "
|
+ " <" + organizationURI + "> rdfs:label ?organizationLabel . "
|
||||||
+ " OPTIONAL { "
|
+ " <" + organizationURI + "> core:hasSubOrganization* ?subOrganization . "
|
||||||
+ " ?dateTimeIntervalValue core:start ?startDate . "
|
+ " ?subOrganization core:organizationForPosition ?Position . "
|
||||||
+ " ?startDate core:dateTime ?startDateTimeValue . "
|
+ " ?Position core:positionForPerson ?Person . "
|
||||||
+ " } "
|
+ " ?Person core:" + roleTypeProperty + " ?Role . "
|
||||||
+ " "
|
+ " ?Role core:roleIn ?Grant . "
|
||||||
+ " OPTIONAL { "
|
+ " "
|
||||||
+ " ?dateTimeIntervalValue core:end ?endDate . "
|
+ " ?Grant core:dateTimeInterval ?dateTimeIntervalValueForGrant . "
|
||||||
+ " ?endDate core:dateTime ?endDateTimeValue . "
|
// + " OPTIONAL { "
|
||||||
+ " } "
|
+ " ?dateTimeIntervalValueForGrant core:start ?startDateForGrant . "
|
||||||
+ " } "
|
+ " ?startDateForGrant core:dateTime ?startDateTimeValueForGrant . "
|
||||||
+ " "
|
// + " } "
|
||||||
+ " LET(?now := afn:now()) "
|
// + " OPTIONAL { "
|
||||||
+ " } ";
|
// + " ?dateTimeIntervalValueForGrant core:end ?endDateForGrant . "
|
||||||
|
// + " ?endDateForGrant core:dateTime ?endDateTimeValueForGrant "
|
||||||
}
|
// + " } "
|
||||||
|
+ " "
|
||||||
private Model executeQuery(String constructQuery) {
|
+ " LET(?now := afn:now()) "
|
||||||
|
+ " } ";
|
||||||
System.out.println("in execute query - org to grants for - " + organizationURI);
|
|
||||||
|
String justDateTimeOnRolesQuery = ""
|
||||||
Model constructedModel = ModelFactory.createDefaultModel();
|
+ " CONSTRUCT { "
|
||||||
|
+ " <" + organizationURI + "> rdfs:label ?organizationLabel . "
|
||||||
before = System.currentTimeMillis();
|
+ " <" + organizationURI + "> vivosocnet:lastCachedAt ?now . "
|
||||||
log.debug("CONSTRUCT query string : " + constructQuery);
|
+ " "
|
||||||
|
+ " ?Grant vivosocnet:startDateTimeOnRole ?startDateTimeValue . "
|
||||||
Query query = null;
|
// + " ?Grant vivosocnet:endDateTimeOnRole ?endDateTimeValue . "
|
||||||
|
+ " } "
|
||||||
try {
|
+ " WHERE { "
|
||||||
query = QueryFactory.create(QueryConstants.getSparqlPrefixQuery()
|
+ " <" + organizationURI + "> rdfs:label ?organizationLabel . "
|
||||||
+ constructQuery, SYNTAX);
|
+ " <" + organizationURI + "> core:hasSubOrganization* ?subOrganization . "
|
||||||
} catch (Throwable th) {
|
+ " ?subOrganization core:organizationForPosition ?Position . "
|
||||||
log.error("Could not create CONSTRUCT SPARQL query for query "
|
+ " ?Position core:positionForPerson ?Person . "
|
||||||
+ "string. " + th.getMessage());
|
+ " ?Person core:" + roleTypeProperty + " ?Role . "
|
||||||
log.error(constructQuery);
|
+ " ?Role core:roleIn ?Grant . "
|
||||||
}
|
+ " "
|
||||||
|
+ " ?Role core:dateTimeInterval ?dateTimeIntervalValue . "
|
||||||
QueryExecution qe = QueryExecutionFactory.create(query, dataset);
|
// + " OPTIONAL { "
|
||||||
|
+ " ?dateTimeIntervalValue core:start ?startDate . "
|
||||||
try {
|
+ " ?startDate core:dateTime ?startDateTimeValue . "
|
||||||
qe.execConstruct(constructedModel);
|
// + " } "
|
||||||
} finally {
|
// + " "
|
||||||
qe.close();
|
// + " OPTIONAL { "
|
||||||
}
|
// + " ?dateTimeIntervalValue core:end ?endDate . "
|
||||||
|
// + " ?endDate core:dateTime ?endDateTimeValue . "
|
||||||
after = System.currentTimeMillis();
|
// + " } "
|
||||||
log.debug("Time taken to execute the CONSTRUCT queries is in milliseconds: "
|
+ " "
|
||||||
+ (after - before));
|
+ " LET(?now := afn:now()) "
|
||||||
|
+ " } ";
|
||||||
return constructedModel;
|
|
||||||
}
|
differentPerspectiveQueries.add(justGrantsQuery);
|
||||||
|
differentPerspectiveQueries.add(justDateTimeOnGrantsQuery);
|
||||||
public Model getConstructedModel() throws MalformedQueryParametersException {
|
differentPerspectiveQueries.add(justDateTimeOnRolesQuery);
|
||||||
return executeQuery(constructOrganizationToGrantsQuery());
|
|
||||||
}
|
return differentPerspectiveQueries;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Set<String> constructOrganizationToGrantsQuery() {
|
||||||
|
|
||||||
|
Set<String> differentInvestigatorTypeQueries = new HashSet<String>();
|
||||||
|
|
||||||
|
Set<String> investigatorRoleQuery = constructOrganizationGrantsQueryTemplate("hasInvestigatorWithGrant", "hasInvestigatorRole");
|
||||||
|
Set<String> piRoleQuery = constructOrganizationGrantsQueryTemplate("hasPIWithGrant", "hasPrincipalInvestigatorRole");
|
||||||
|
Set<String> coPIRoleQuery = constructOrganizationGrantsQueryTemplate("hascoPIWithGrant", "hasCo-PrincipalInvestigatorRole");
|
||||||
|
|
||||||
|
differentInvestigatorTypeQueries.addAll(investigatorRoleQuery);
|
||||||
|
differentInvestigatorTypeQueries.addAll(piRoleQuery);
|
||||||
|
differentInvestigatorTypeQueries.addAll(coPIRoleQuery);
|
||||||
|
|
||||||
|
return differentInvestigatorTypeQueries;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Model executeQuery(Set<String> constructQueries) {
|
||||||
|
|
||||||
|
Model constructedModel = ModelFactory.createDefaultModel();
|
||||||
|
|
||||||
|
before = System.currentTimeMillis();
|
||||||
|
log.debug("CONSTRUCT query string : " + constructQueries);
|
||||||
|
|
||||||
|
for (String currentQuery : constructQueries) {
|
||||||
|
|
||||||
|
Query query = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
query = QueryFactory.create(QueryConstants.getSparqlPrefixQuery() + currentQuery, SYNTAX);
|
||||||
|
} catch (Throwable th) {
|
||||||
|
log.error("Could not create CONSTRUCT SPARQL query for query "
|
||||||
|
+ "string. " + th.getMessage());
|
||||||
|
log.error(currentQuery);
|
||||||
|
}
|
||||||
|
|
||||||
|
QueryExecution qe = QueryExecutionFactory.create(query, dataset);
|
||||||
|
|
||||||
|
try {
|
||||||
|
qe.execConstruct(constructedModel);
|
||||||
|
} finally {
|
||||||
|
qe.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
after = System.currentTimeMillis();
|
||||||
|
log.debug("Time taken to execute the CONSTRUCT queries is in milliseconds: "
|
||||||
|
+ (after - before));
|
||||||
|
|
||||||
|
return constructedModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Model getConstructedModel() throws MalformedQueryParametersException {
|
||||||
|
return executeQuery(constructOrganizationToGrantsQuery());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,171 @@
|
||||||
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
|
package edu.cornell.mannlib.vitro.webapp.visualization.freemarker.modelconstructor;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
|
import com.hp.hpl.jena.query.Dataset;
|
||||||
|
import com.hp.hpl.jena.query.Query;
|
||||||
|
import com.hp.hpl.jena.query.QueryExecution;
|
||||||
|
import com.hp.hpl.jena.query.QueryExecutionFactory;
|
||||||
|
import com.hp.hpl.jena.query.QueryFactory;
|
||||||
|
import com.hp.hpl.jena.query.Syntax;
|
||||||
|
import com.hp.hpl.jena.rdf.model.Model;
|
||||||
|
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
||||||
|
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.visualization.constants.QueryConstants;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.ModelConstructor;
|
||||||
|
|
||||||
|
public class PersonToGrantsModelConstructor implements ModelConstructor {
|
||||||
|
|
||||||
|
protected static final Syntax SYNTAX = Syntax.syntaxARQ;
|
||||||
|
|
||||||
|
private Dataset dataset;
|
||||||
|
|
||||||
|
public static final String MODEL_TYPE = "PERSON_TO_GRANTS";
|
||||||
|
|
||||||
|
private String personURI;
|
||||||
|
|
||||||
|
private Log log = LogFactory.getLog(PersonToGrantsModelConstructor.class.getName());
|
||||||
|
|
||||||
|
private long before, after;
|
||||||
|
|
||||||
|
public PersonToGrantsModelConstructor(String personURI, Dataset dataset) {
|
||||||
|
this.personURI = personURI;
|
||||||
|
this.dataset = dataset;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Set<String> constructPersonGrantsQueryTemplate(String constructProperty, String roleTypeProperty) {
|
||||||
|
|
||||||
|
Set<String> differentPerspectiveQueries = new HashSet<String>();
|
||||||
|
|
||||||
|
String justGrantsQuery = ""
|
||||||
|
+ " CONSTRUCT { "
|
||||||
|
+ " <" + personURI + "> vivosocnet:lastCachedAt ?now . "
|
||||||
|
+ " <" + personURI + "> vivosocnet:" + constructProperty + " ?Grant . "
|
||||||
|
+ " "
|
||||||
|
+ " ?Grant rdf:type core:Grant . "
|
||||||
|
+ " ?Grant rdfs:label ?grantLabel . "
|
||||||
|
+ " "
|
||||||
|
+ " } "
|
||||||
|
+ " WHERE { "
|
||||||
|
+ " ?Person core:" + roleTypeProperty + " ?Role . "
|
||||||
|
+ " ?Role core:roleIn ?Grant . "
|
||||||
|
+ " ?Grant rdfs:label ?grantLabel . "
|
||||||
|
+ " "
|
||||||
|
+ " LET(?now := afn:now()) "
|
||||||
|
+ " } ";
|
||||||
|
|
||||||
|
String justDateTimeOnGrantsQuery = ""
|
||||||
|
+ " CONSTRUCT { "
|
||||||
|
+ " <" + personURI + "> vivosocnet:lastCachedAt ?now . "
|
||||||
|
+ " ?Grant vivosocnet:startDateTimeOnGrant ?startDateTimeValueForGrant . "
|
||||||
|
// + " ?Grant vivosocnet:endDateTimeOnGrant ?endDateTimeValueForGrant . "
|
||||||
|
+ " "
|
||||||
|
+ " } "
|
||||||
|
+ " WHERE { "
|
||||||
|
+ " ?Person core:" + roleTypeProperty + " ?Role . "
|
||||||
|
+ " ?Role core:roleIn ?Grant . "
|
||||||
|
+ " "
|
||||||
|
+ " ?Grant core:dateTimeInterval ?dateTimeIntervalValueForGrant . "
|
||||||
|
// + " OPTIONAL { "
|
||||||
|
+ " ?dateTimeIntervalValueForGrant core:start ?startDateForGrant . "
|
||||||
|
+ " ?startDateForGrant core:dateTime ?startDateTimeValueForGrant . "
|
||||||
|
// + " } "
|
||||||
|
// + " OPTIONAL { "
|
||||||
|
// + " ?dateTimeIntervalValueForGrant core:end ?endDateForGrant . "
|
||||||
|
// + " ?endDateForGrant core:dateTime ?endDateTimeValueForGrant "
|
||||||
|
// + " } "
|
||||||
|
+ " "
|
||||||
|
+ " LET(?now := afn:now()) "
|
||||||
|
+ " } ";
|
||||||
|
|
||||||
|
String justDateTimeOnRolesQuery = ""
|
||||||
|
+ " CONSTRUCT { "
|
||||||
|
+ " <" + personURI + "> vivosocnet:lastCachedAt ?now . "
|
||||||
|
+ " ?Grant vivosocnet:startDateTimeOnRole ?startDateTimeValue . "
|
||||||
|
// + " ?Grant vivosocnet:endDateTimeOnRole ?endDateTimeValue . "
|
||||||
|
+ " } "
|
||||||
|
+ " WHERE { "
|
||||||
|
+ " ?Person core:" + roleTypeProperty + " ?Role . "
|
||||||
|
+ " ?Role core:roleIn ?Grant . "
|
||||||
|
+ " "
|
||||||
|
+ " ?Role core:dateTimeInterval ?dateTimeIntervalValue . "
|
||||||
|
// + " OPTIONAL { "
|
||||||
|
+ " ?dateTimeIntervalValue core:start ?startDate . "
|
||||||
|
+ " ?startDate core:dateTime ?startDateTimeValue . "
|
||||||
|
// + " } "
|
||||||
|
// + " "
|
||||||
|
// + " OPTIONAL { "
|
||||||
|
// + " ?dateTimeIntervalValue core:end ?endDate . "
|
||||||
|
// + " ?endDate core:dateTime ?endDateTimeValue . "
|
||||||
|
// + " } "
|
||||||
|
+ " "
|
||||||
|
+ " LET(?now := afn:now()) "
|
||||||
|
+ " } ";
|
||||||
|
|
||||||
|
differentPerspectiveQueries.add(justGrantsQuery);
|
||||||
|
differentPerspectiveQueries.add(justDateTimeOnGrantsQuery);
|
||||||
|
differentPerspectiveQueries.add(justDateTimeOnRolesQuery);
|
||||||
|
|
||||||
|
return differentPerspectiveQueries;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Set<String> constructPersonToGrantsQuery() {
|
||||||
|
|
||||||
|
Set<String> differentInvestigatorTypeQueries = new HashSet<String>();
|
||||||
|
|
||||||
|
Set<String> investigatorRoleQuery = constructPersonGrantsQueryTemplate("hasGrantAsAnInvestigator", "hasInvestigatorRole");
|
||||||
|
Set<String> piRoleQuery = constructPersonGrantsQueryTemplate("hasGrantAsPI", "hasPrincipalInvestigatorRole");
|
||||||
|
Set<String> coPIRoleQuery = constructPersonGrantsQueryTemplate("hasGrantAsCoPI", "hasCo-PrincipalInvestigatorRole");
|
||||||
|
|
||||||
|
differentInvestigatorTypeQueries.addAll(investigatorRoleQuery);
|
||||||
|
differentInvestigatorTypeQueries.addAll(piRoleQuery);
|
||||||
|
differentInvestigatorTypeQueries.addAll(coPIRoleQuery);
|
||||||
|
|
||||||
|
return differentInvestigatorTypeQueries;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Model executeQuery(Set<String> constructQueries) {
|
||||||
|
|
||||||
|
Model constructedModel = ModelFactory.createDefaultModel();
|
||||||
|
|
||||||
|
before = System.currentTimeMillis();
|
||||||
|
log.debug("CONSTRUCT query string : " + constructQueries);
|
||||||
|
|
||||||
|
for (String currentQuery : constructQueries) {
|
||||||
|
|
||||||
|
Query query = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
query = QueryFactory.create(QueryConstants.getSparqlPrefixQuery() + currentQuery, SYNTAX);
|
||||||
|
} catch (Throwable th) {
|
||||||
|
log.error("Could not create CONSTRUCT SPARQL query for query "
|
||||||
|
+ "string. " + th.getMessage());
|
||||||
|
log.error(currentQuery);
|
||||||
|
}
|
||||||
|
|
||||||
|
QueryExecution qe = QueryExecutionFactory.create(query, dataset);
|
||||||
|
|
||||||
|
try {
|
||||||
|
qe.execConstruct(constructedModel);
|
||||||
|
} finally {
|
||||||
|
qe.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
after = System.currentTimeMillis();
|
||||||
|
log.debug("Time taken to execute the CONSTRUCT queries is in milliseconds: "
|
||||||
|
+ (after - before));
|
||||||
|
|
||||||
|
return constructedModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Model getConstructedModel() throws MalformedQueryParametersException {
|
||||||
|
return executeQuery(constructPersonToGrantsQuery());
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,43 @@
|
||||||
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
|
package edu.cornell.mannlib.vitro.webapp.visualization.freemarker.modelconstructor.factory;
|
||||||
|
|
||||||
|
import com.hp.hpl.jena.query.Dataset;
|
||||||
|
import com.hp.hpl.jena.rdf.model.Model;
|
||||||
|
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.modelconstructor.PersonToGrantsModelConstructor;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.valueobjects.ConstructedModelTracker;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.ModelConstructor;
|
||||||
|
|
||||||
|
public class PersonToGrantsFactory implements ModelFactoryInterface {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Model getOrCreateModel(String uri, Dataset dataset)
|
||||||
|
throws MalformedQueryParametersException {
|
||||||
|
|
||||||
|
Model candidateModel = ConstructedModelTracker.getModel(
|
||||||
|
ConstructedModelTracker
|
||||||
|
.generateModelIdentifier(
|
||||||
|
uri,
|
||||||
|
PersonToGrantsModelConstructor.MODEL_TYPE));
|
||||||
|
|
||||||
|
if (candidateModel != null) {
|
||||||
|
|
||||||
|
return candidateModel;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
ModelConstructor model = new PersonToGrantsModelConstructor(uri, dataset);
|
||||||
|
|
||||||
|
Model constructedModel = model.getConstructedModel();
|
||||||
|
ConstructedModelTracker.trackModel(
|
||||||
|
ConstructedModelTracker
|
||||||
|
.generateModelIdentifier(
|
||||||
|
uri,
|
||||||
|
PersonToGrantsModelConstructor.MODEL_TYPE),
|
||||||
|
constructedModel);
|
||||||
|
|
||||||
|
return constructedModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,396 +1,481 @@
|
||||||
/* $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$ */
|
||||||
package edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils;
|
package edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
|
||||||
import com.hp.hpl.jena.query.Dataset;
|
import com.hp.hpl.jena.query.Dataset;
|
||||||
import com.hp.hpl.jena.query.QuerySolution;
|
import com.hp.hpl.jena.query.QuerySolution;
|
||||||
import com.hp.hpl.jena.query.ResultSet;
|
import com.hp.hpl.jena.query.ResultSet;
|
||||||
import com.hp.hpl.jena.rdf.model.Model;
|
import com.hp.hpl.jena.rdf.model.Model;
|
||||||
import com.hp.hpl.jena.rdf.model.RDFNode;
|
import com.hp.hpl.jena.rdf.model.RDFNode;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.visualization.constants.QueryFieldLabels;
|
import edu.cornell.mannlib.vitro.webapp.visualization.constants.QueryFieldLabels;
|
||||||
import edu.cornell.mannlib.vitro.webapp.visualization.constants.VOConstants;
|
import edu.cornell.mannlib.vitro.webapp.visualization.constants.VOConstants;
|
||||||
import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException;
|
import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException;
|
||||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.modelconstructor.ModelConstructorUtilities;
|
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.modelconstructor.ModelConstructorUtilities;
|
||||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.modelconstructor.OrganizationAssociatedPeopleModelWithTypesConstructor;
|
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.modelconstructor.OrganizationAssociatedPeopleModelWithTypesConstructor;
|
||||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.modelconstructor.OrganizationModelWithTypesConstructor;
|
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.modelconstructor.OrganizationModelWithTypesConstructor;
|
||||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.modelconstructor.OrganizationToGrantsForSubOrganizationsModelConstructor;
|
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.modelconstructor.OrganizationToGrantsForSubOrganizationsModelConstructor;
|
||||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.modelconstructor.OrganizationToPublicationsForSubOrganizationsModelConstructor;
|
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.modelconstructor.OrganizationToPublicationsForSubOrganizationsModelConstructor;
|
||||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.modelconstructor.PersonToPublicationsModelConstructor;
|
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.modelconstructor.PersonToGrantsModelConstructor;
|
||||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.valueobjects.Activity;
|
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.modelconstructor.PersonToPublicationsModelConstructor;
|
||||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.valueobjects.Entity;
|
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.valueobjects.Activity;
|
||||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.valueobjects.SubEntity;
|
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.valueobjects.Entity;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.valueobjects.SubEntity;
|
||||||
public class SelectOnModelUtilities {
|
|
||||||
|
public class SelectOnModelUtilities {
|
||||||
public static Entity getSubjectOrganizationHierarchy(Dataset dataset,
|
|
||||||
String subjectEntityURI) throws MalformedQueryParametersException {
|
public static Entity getSubjectOrganizationHierarchy(Dataset dataset,
|
||||||
Model organizationModel = ModelConstructorUtilities
|
String subjectEntityURI) throws MalformedQueryParametersException {
|
||||||
.getOrConstructModel(
|
Model organizationModel = ModelConstructorUtilities
|
||||||
null,
|
.getOrConstructModel(
|
||||||
OrganizationModelWithTypesConstructor.MODEL_TYPE,
|
null,
|
||||||
dataset);
|
OrganizationModelWithTypesConstructor.MODEL_TYPE,
|
||||||
|
dataset);
|
||||||
Map<String, String> fieldLabelToOutputFieldLabel = new HashMap<String, String>();
|
|
||||||
fieldLabelToOutputFieldLabel.put("organizationLabel", QueryFieldLabels.ORGANIZATION_LABEL);
|
Map<String, String> fieldLabelToOutputFieldLabel = new HashMap<String, String>();
|
||||||
fieldLabelToOutputFieldLabel.put("subOrganization", QueryFieldLabels.SUBORGANIZATION_URL);
|
fieldLabelToOutputFieldLabel.put("organizationLabel", QueryFieldLabels.ORGANIZATION_LABEL);
|
||||||
fieldLabelToOutputFieldLabel.put("subOrganizationLabel", QueryFieldLabels.SUBORGANIZATION_LABEL);
|
fieldLabelToOutputFieldLabel.put("subOrganization", QueryFieldLabels.SUBORGANIZATION_URL);
|
||||||
fieldLabelToOutputFieldLabel.put("subOrganizationTypeLabel", QueryFieldLabels.SUBORGANIZATION_TYPE_LABEL);
|
fieldLabelToOutputFieldLabel.put("subOrganizationLabel", QueryFieldLabels.SUBORGANIZATION_LABEL);
|
||||||
|
fieldLabelToOutputFieldLabel.put("subOrganizationTypeLabel", QueryFieldLabels.SUBORGANIZATION_TYPE_LABEL);
|
||||||
String whereClause = ""
|
|
||||||
+ " <" + subjectEntityURI + "> rdfs:label ?organizationLabel . "
|
String whereClause = ""
|
||||||
+ " <" + subjectEntityURI + "> core:hasSubOrganization ?subOrganization . "
|
+ " <" + subjectEntityURI + "> rdfs:label ?organizationLabel . "
|
||||||
+ " ?subOrganization rdfs:label ?subOrganizationLabel . "
|
+ " <" + subjectEntityURI + "> core:hasSubOrganization ?subOrganization . "
|
||||||
+ " ?subOrganization rdf:type ?subOrgType . "
|
+ " ?subOrganization rdfs:label ?subOrganizationLabel . "
|
||||||
+ " ?subOrgType rdfs:label ?subOrganizationTypeLabel . ";
|
+ " ?subOrganization rdf:type ?subOrgType . "
|
||||||
|
+ " ?subOrgType rdfs:label ?subOrganizationTypeLabel . ";
|
||||||
QueryRunner<ResultSet> subOrganizationsWithTypesQuery =
|
|
||||||
new GenericQueryRunnerOnModel(fieldLabelToOutputFieldLabel,
|
QueryRunner<ResultSet> subOrganizationsWithTypesQuery =
|
||||||
"",
|
new GenericQueryRunnerOnModel(fieldLabelToOutputFieldLabel,
|
||||||
whereClause,
|
"",
|
||||||
"",
|
whereClause,
|
||||||
organizationModel);
|
"",
|
||||||
|
organizationModel);
|
||||||
return getEntityWithSubOrganizations(subjectEntityURI,
|
|
||||||
subOrganizationsWithTypesQuery.getQueryResult());
|
return getEntityWithSubOrganizations(subjectEntityURI,
|
||||||
}
|
subOrganizationsWithTypesQuery.getQueryResult());
|
||||||
|
}
|
||||||
private static Entity getEntityWithSubOrganizations(String subjectEntityURI, ResultSet queryResult) {
|
|
||||||
|
private static Entity getEntityWithSubOrganizations(String subjectEntityURI, ResultSet queryResult) {
|
||||||
Entity entity = new Entity(subjectEntityURI);
|
|
||||||
Map<String, SubEntity> subOrganizationURIToVO = new HashMap<String, SubEntity>();
|
Entity entity = new Entity(subjectEntityURI);
|
||||||
|
Map<String, SubEntity> subOrganizationURIToVO = new HashMap<String, SubEntity>();
|
||||||
while (queryResult.hasNext()) {
|
|
||||||
|
while (queryResult.hasNext()) {
|
||||||
QuerySolution solution = queryResult.nextSolution();
|
|
||||||
|
QuerySolution solution = queryResult.nextSolution();
|
||||||
if (StringUtils.isEmpty(entity.getEntityLabel())) {
|
|
||||||
|
if (StringUtils.isEmpty(entity.getEntityLabel())) {
|
||||||
RDFNode organizationLabelNode = solution.get(QueryFieldLabels.ORGANIZATION_LABEL);
|
|
||||||
if (organizationLabelNode != null) {
|
RDFNode organizationLabelNode = solution.get(QueryFieldLabels.ORGANIZATION_LABEL);
|
||||||
entity.setIndividualLabel(organizationLabelNode.toString());
|
if (organizationLabelNode != null) {
|
||||||
}
|
entity.setIndividualLabel(organizationLabelNode.toString());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
RDFNode subOrganizationNode = solution.get(QueryFieldLabels.SUBORGANIZATION_URL);
|
|
||||||
|
RDFNode subOrganizationNode = solution.get(QueryFieldLabels.SUBORGANIZATION_URL);
|
||||||
SubEntity subEntity;
|
|
||||||
|
SubEntity subEntity;
|
||||||
if (subOrganizationURIToVO.containsKey(subOrganizationNode.toString())) {
|
|
||||||
|
if (subOrganizationURIToVO.containsKey(subOrganizationNode.toString())) {
|
||||||
subEntity = subOrganizationURIToVO.get(subOrganizationNode.toString());
|
|
||||||
|
subEntity = subOrganizationURIToVO.get(subOrganizationNode.toString());
|
||||||
} else {
|
|
||||||
|
} else {
|
||||||
subEntity = new SubEntity(subOrganizationNode.toString());
|
|
||||||
|
subEntity = new SubEntity(subOrganizationNode.toString());
|
||||||
subEntity.setEntityClass(VOConstants.EntityClassType.ORGANIZATION);
|
|
||||||
|
subEntity.setEntityClass(VOConstants.EntityClassType.ORGANIZATION);
|
||||||
subOrganizationURIToVO.put(subOrganizationNode.toString(), subEntity);
|
|
||||||
|
subOrganizationURIToVO.put(subOrganizationNode.toString(), subEntity);
|
||||||
RDFNode subOrganizationLabelNode = solution.get(QueryFieldLabels.SUBORGANIZATION_LABEL);
|
|
||||||
if (subOrganizationLabelNode != null) {
|
RDFNode subOrganizationLabelNode = solution.get(QueryFieldLabels.SUBORGANIZATION_LABEL);
|
||||||
subEntity.setIndividualLabel(subOrganizationLabelNode.toString());
|
if (subOrganizationLabelNode != null) {
|
||||||
}
|
subEntity.setIndividualLabel(subOrganizationLabelNode.toString());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
RDFNode subOrganizationTypeLabelNode = solution.get(QueryFieldLabels.SUBORGANIZATION_TYPE_LABEL);
|
|
||||||
if (subOrganizationTypeLabelNode != null) {
|
RDFNode subOrganizationTypeLabelNode = solution.get(QueryFieldLabels.SUBORGANIZATION_TYPE_LABEL);
|
||||||
subEntity.addEntityTypeLabel(subOrganizationTypeLabelNode.toString());
|
if (subOrganizationTypeLabelNode != null) {
|
||||||
}
|
subEntity.addEntityTypeLabel(subOrganizationTypeLabelNode.toString());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
entity.addSubEntitities(subOrganizationURIToVO.values());
|
|
||||||
|
entity.addSubEntitities(subOrganizationURIToVO.values());
|
||||||
return entity;
|
|
||||||
}
|
return entity;
|
||||||
|
}
|
||||||
public static Entity getSubjectOrganizationAssociatedPeople(Dataset dataset,
|
|
||||||
String subjectEntityURI) throws MalformedQueryParametersException {
|
public static Entity getSubjectOrganizationAssociatedPeople(Dataset dataset,
|
||||||
Model associatedPeopleModel = ModelConstructorUtilities
|
String subjectEntityURI) throws MalformedQueryParametersException {
|
||||||
.getOrConstructModel(
|
Model associatedPeopleModel = ModelConstructorUtilities
|
||||||
subjectEntityURI,
|
.getOrConstructModel(
|
||||||
OrganizationAssociatedPeopleModelWithTypesConstructor.MODEL_TYPE,
|
subjectEntityURI,
|
||||||
dataset);
|
OrganizationAssociatedPeopleModelWithTypesConstructor.MODEL_TYPE,
|
||||||
|
dataset);
|
||||||
Map<String, String> fieldLabelToOutputFieldLabel = new HashMap<String, String>();
|
|
||||||
fieldLabelToOutputFieldLabel.put("organizationLabel", QueryFieldLabels.ORGANIZATION_LABEL);
|
Map<String, String> fieldLabelToOutputFieldLabel = new HashMap<String, String>();
|
||||||
fieldLabelToOutputFieldLabel.put("person", QueryFieldLabels.PERSON_URL);
|
fieldLabelToOutputFieldLabel.put("organizationLabel", QueryFieldLabels.ORGANIZATION_LABEL);
|
||||||
fieldLabelToOutputFieldLabel.put("personLabel", QueryFieldLabels.PERSON_LABEL);
|
fieldLabelToOutputFieldLabel.put("person", QueryFieldLabels.PERSON_URL);
|
||||||
fieldLabelToOutputFieldLabel.put("personTypeLabel", QueryFieldLabels.PERSON_TYPE_LABEL);
|
fieldLabelToOutputFieldLabel.put("personLabel", QueryFieldLabels.PERSON_LABEL);
|
||||||
|
fieldLabelToOutputFieldLabel.put("personTypeLabel", QueryFieldLabels.PERSON_TYPE_LABEL);
|
||||||
String whereClause = ""
|
|
||||||
+ " <" + subjectEntityURI + "> rdfs:label ?organizationLabel . "
|
String whereClause = ""
|
||||||
+ " <" + subjectEntityURI + "> vivosocnet:hasPersonWithActivity ?person . "
|
+ " <" + subjectEntityURI + "> rdfs:label ?organizationLabel . "
|
||||||
+ " ?person rdfs:label ?personLabel . "
|
+ " <" + subjectEntityURI + "> vivosocnet:hasPersonWithActivity ?person . "
|
||||||
+ " ?person rdf:type ?personType . "
|
+ " ?person rdfs:label ?personLabel . "
|
||||||
+ " ?personType rdfs:label ?personTypeLabel . ";
|
+ " ?person rdf:type ?personType . "
|
||||||
|
+ " ?personType rdfs:label ?personTypeLabel . ";
|
||||||
QueryRunner<ResultSet> associatedPeopleWithTypesQuery =
|
|
||||||
new GenericQueryRunnerOnModel(fieldLabelToOutputFieldLabel,
|
QueryRunner<ResultSet> associatedPeopleWithTypesQuery =
|
||||||
"",
|
new GenericQueryRunnerOnModel(fieldLabelToOutputFieldLabel,
|
||||||
whereClause,
|
"",
|
||||||
"",
|
whereClause,
|
||||||
associatedPeopleModel);
|
"",
|
||||||
|
associatedPeopleModel);
|
||||||
return getEntityWithAssociatedPeopleSubEntitities(subjectEntityURI, associatedPeopleWithTypesQuery.getQueryResult());
|
|
||||||
}
|
return getEntityWithAssociatedPeopleSubEntitities(subjectEntityURI, associatedPeopleWithTypesQuery.getQueryResult());
|
||||||
|
}
|
||||||
private static Entity getEntityWithAssociatedPeopleSubEntitities(
|
|
||||||
String subjectEntityURI, ResultSet queryResult) {
|
private static Entity getEntityWithAssociatedPeopleSubEntitities(
|
||||||
|
String subjectEntityURI, ResultSet queryResult) {
|
||||||
Entity entity = new Entity(subjectEntityURI);
|
|
||||||
Map<String, SubEntity> associatedPeopleURIToVO = new HashMap<String, SubEntity>();
|
Entity entity = new Entity(subjectEntityURI);
|
||||||
|
Map<String, SubEntity> associatedPeopleURIToVO = new HashMap<String, SubEntity>();
|
||||||
while (queryResult.hasNext()) {
|
|
||||||
|
while (queryResult.hasNext()) {
|
||||||
QuerySolution solution = queryResult.nextSolution();
|
|
||||||
|
QuerySolution solution = queryResult.nextSolution();
|
||||||
if (StringUtils.isEmpty(entity.getEntityLabel())) {
|
|
||||||
|
if (StringUtils.isEmpty(entity.getEntityLabel())) {
|
||||||
RDFNode organizationLabelNode = solution.get(QueryFieldLabels.ORGANIZATION_LABEL);
|
|
||||||
if (organizationLabelNode != null) {
|
RDFNode organizationLabelNode = solution.get(QueryFieldLabels.ORGANIZATION_LABEL);
|
||||||
entity.setIndividualLabel(organizationLabelNode.toString());
|
if (organizationLabelNode != null) {
|
||||||
}
|
entity.setIndividualLabel(organizationLabelNode.toString());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
RDFNode personNode = solution.get(QueryFieldLabels.PERSON_URL);
|
|
||||||
|
RDFNode personNode = solution.get(QueryFieldLabels.PERSON_URL);
|
||||||
SubEntity subEntity;
|
|
||||||
|
SubEntity subEntity;
|
||||||
if (associatedPeopleURIToVO.containsKey(personNode.toString())) {
|
|
||||||
|
if (associatedPeopleURIToVO.containsKey(personNode.toString())) {
|
||||||
subEntity = associatedPeopleURIToVO.get(personNode.toString());
|
|
||||||
|
subEntity = associatedPeopleURIToVO.get(personNode.toString());
|
||||||
} else {
|
|
||||||
|
} else {
|
||||||
subEntity = new SubEntity(personNode.toString());
|
|
||||||
subEntity.setEntityClass(VOConstants.EntityClassType.PERSON);
|
subEntity = new SubEntity(personNode.toString());
|
||||||
associatedPeopleURIToVO.put(personNode.toString(), subEntity);
|
subEntity.setEntityClass(VOConstants.EntityClassType.PERSON);
|
||||||
|
associatedPeopleURIToVO.put(personNode.toString(), subEntity);
|
||||||
RDFNode personLabelNode = solution.get(QueryFieldLabels.PERSON_LABEL);
|
|
||||||
if (personLabelNode != null) {
|
RDFNode personLabelNode = solution.get(QueryFieldLabels.PERSON_LABEL);
|
||||||
subEntity.setIndividualLabel(personLabelNode.toString());
|
if (personLabelNode != null) {
|
||||||
}
|
subEntity.setIndividualLabel(personLabelNode.toString());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
RDFNode personTypeLabelNode = solution.get(QueryFieldLabels.PERSON_TYPE_LABEL);
|
|
||||||
if (personTypeLabelNode != null) {
|
RDFNode personTypeLabelNode = solution.get(QueryFieldLabels.PERSON_TYPE_LABEL);
|
||||||
subEntity.addEntityTypeLabel(personTypeLabelNode.toString());
|
if (personTypeLabelNode != null) {
|
||||||
}
|
subEntity.addEntityTypeLabel(personTypeLabelNode.toString());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
entity.addSubEntitities(associatedPeopleURIToVO.values());
|
|
||||||
return entity;
|
entity.addSubEntitities(associatedPeopleURIToVO.values());
|
||||||
}
|
return entity;
|
||||||
|
}
|
||||||
public static Map<String, Activity> getPublicationsForAllSubOrganizations(
|
|
||||||
Dataset dataset, Entity organizationEntity)
|
public static Map<String, Activity> getPublicationsForAllSubOrganizations(
|
||||||
throws MalformedQueryParametersException {
|
Dataset dataset, Entity organizationEntity)
|
||||||
Map<String, Activity> allDocumentURIToVOs = new HashMap<String, Activity>();
|
throws MalformedQueryParametersException {
|
||||||
|
Map<String, Activity> allDocumentURIToVOs = new HashMap<String, Activity>();
|
||||||
for (SubEntity subOrganization : organizationEntity.getSubEntities()) {
|
|
||||||
|
for (SubEntity subOrganization : organizationEntity.getSubEntities()) {
|
||||||
Model subOrganizationPublicationsModel = ModelConstructorUtilities
|
|
||||||
.getOrConstructModel(
|
Model subOrganizationPublicationsModel = ModelConstructorUtilities
|
||||||
subOrganization.getIndividualURI(),
|
.getOrConstructModel(
|
||||||
OrganizationToPublicationsForSubOrganizationsModelConstructor.MODEL_TYPE,
|
subOrganization.getIndividualURI(),
|
||||||
dataset);
|
OrganizationToPublicationsForSubOrganizationsModelConstructor.MODEL_TYPE,
|
||||||
|
dataset);
|
||||||
System.out.println("getting publications for " + subOrganization.getIndividualLabel());
|
|
||||||
|
System.out.println("getting publications for " + subOrganization.getIndividualLabel());
|
||||||
Map<String, String> fieldLabelToOutputFieldLabel = new HashMap<String, String>();
|
|
||||||
fieldLabelToOutputFieldLabel.put("document", QueryFieldLabels.DOCUMENT_URL);
|
Map<String, String> fieldLabelToOutputFieldLabel = new HashMap<String, String>();
|
||||||
fieldLabelToOutputFieldLabel.put("documentLabel", QueryFieldLabels.DOCUMENT_LABEL);
|
fieldLabelToOutputFieldLabel.put("document", QueryFieldLabels.DOCUMENT_URL);
|
||||||
fieldLabelToOutputFieldLabel.put("documentPublicationDate", QueryFieldLabels.DOCUMENT_PUBLICATION_DATE);
|
fieldLabelToOutputFieldLabel.put("documentLabel", QueryFieldLabels.DOCUMENT_LABEL);
|
||||||
|
fieldLabelToOutputFieldLabel.put("documentPublicationDate", QueryFieldLabels.DOCUMENT_PUBLICATION_DATE);
|
||||||
String whereClause = ""
|
|
||||||
+ " <" + subOrganization.getIndividualURI() + "> vivosocnet:hasPersonWithPublication ?document . "
|
String whereClause = ""
|
||||||
+ " ?document rdfs:label ?documentLabel . "
|
+ " <" + subOrganization.getIndividualURI() + "> vivosocnet:hasPersonWithPublication ?document . "
|
||||||
+ " OPTIONAL { "
|
+ " ?document rdfs:label ?documentLabel . "
|
||||||
+ " ?document core:dateTimeValue ?dateTimeValue . "
|
+ " OPTIONAL { "
|
||||||
+ " ?dateTimeValue core:dateTime ?documentPublicationDate } . ";
|
+ " ?document core:dateTimeValue ?dateTimeValue . "
|
||||||
|
+ " ?dateTimeValue core:dateTime ?documentPublicationDate } . ";
|
||||||
QueryRunner<ResultSet> subOrganizationPublicationsQuery =
|
|
||||||
new GenericQueryRunnerOnModel(fieldLabelToOutputFieldLabel,
|
QueryRunner<ResultSet> subOrganizationPublicationsQuery =
|
||||||
"",
|
new GenericQueryRunnerOnModel(fieldLabelToOutputFieldLabel,
|
||||||
whereClause,
|
"",
|
||||||
"",
|
whereClause,
|
||||||
subOrganizationPublicationsModel);
|
"",
|
||||||
|
subOrganizationPublicationsModel);
|
||||||
subOrganization.addActivities(getPublicationForEntity(
|
|
||||||
subOrganizationPublicationsQuery.getQueryResult(),
|
subOrganization.addActivities(getPublicationForEntity(
|
||||||
allDocumentURIToVOs));
|
subOrganizationPublicationsQuery.getQueryResult(),
|
||||||
|
allDocumentURIToVOs));
|
||||||
}
|
|
||||||
return allDocumentURIToVOs;
|
}
|
||||||
}
|
return allDocumentURIToVOs;
|
||||||
|
}
|
||||||
private static Collection<Activity> getPublicationForEntity(
|
|
||||||
ResultSet queryResult,
|
private static Collection<Activity> getPublicationForEntity(
|
||||||
Map<String, Activity> allDocumentURIToVOs) {
|
ResultSet queryResult,
|
||||||
|
Map<String, Activity> allDocumentURIToVOs) {
|
||||||
Set<Activity> currentEntityPublications = new HashSet<Activity>();
|
|
||||||
|
Set<Activity> currentEntityPublications = new HashSet<Activity>();
|
||||||
while (queryResult.hasNext()) {
|
|
||||||
|
while (queryResult.hasNext()) {
|
||||||
QuerySolution solution = queryResult.nextSolution();
|
|
||||||
|
QuerySolution solution = queryResult.nextSolution();
|
||||||
RDFNode documentNode = solution.get(QueryFieldLabels.DOCUMENT_URL);
|
|
||||||
Activity biboDocument;
|
RDFNode documentNode = solution.get(QueryFieldLabels.DOCUMENT_URL);
|
||||||
|
Activity biboDocument;
|
||||||
if (allDocumentURIToVOs.containsKey(documentNode.toString())) {
|
|
||||||
biboDocument = allDocumentURIToVOs.get(documentNode.toString());
|
if (allDocumentURIToVOs.containsKey(documentNode.toString())) {
|
||||||
|
biboDocument = allDocumentURIToVOs.get(documentNode.toString());
|
||||||
} else {
|
|
||||||
|
} else {
|
||||||
biboDocument = new Activity(documentNode.toString());
|
|
||||||
allDocumentURIToVOs.put(documentNode.toString(), biboDocument);
|
biboDocument = new Activity(documentNode.toString());
|
||||||
|
allDocumentURIToVOs.put(documentNode.toString(), biboDocument);
|
||||||
RDFNode publicationDateNode = solution.get(QueryFieldLabels
|
|
||||||
.DOCUMENT_PUBLICATION_DATE);
|
RDFNode publicationDateNode = solution.get(QueryFieldLabels
|
||||||
if (publicationDateNode != null) {
|
.DOCUMENT_PUBLICATION_DATE);
|
||||||
biboDocument.setActivityDate(publicationDateNode.toString());
|
if (publicationDateNode != null) {
|
||||||
}
|
biboDocument.setActivityDate(publicationDateNode.toString());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
currentEntityPublications.add(biboDocument);
|
|
||||||
|
currentEntityPublications.add(biboDocument);
|
||||||
}
|
|
||||||
|
}
|
||||||
return currentEntityPublications;
|
|
||||||
}
|
return currentEntityPublications;
|
||||||
|
}
|
||||||
|
|
||||||
private static Collection<Activity> getGrantForEntity(
|
|
||||||
ResultSet queryResult,
|
private static Collection<Activity> getGrantForEntity(
|
||||||
Map<String, Activity> allGrantURIToVO) {
|
ResultSet queryResult,
|
||||||
|
Map<String, Activity> allGrantURIToVO) {
|
||||||
Set<Activity> currentEntityGrants = new HashSet<Activity>();
|
|
||||||
|
Set<Activity> currentEntityGrants = new HashSet<Activity>();
|
||||||
while (queryResult.hasNext()) {
|
|
||||||
|
while (queryResult.hasNext()) {
|
||||||
QuerySolution solution = queryResult.nextSolution();
|
|
||||||
|
QuerySolution solution = queryResult.nextSolution();
|
||||||
RDFNode grantNode = solution.get(QueryFieldLabels.GRANT_URL);
|
|
||||||
Activity coreGrant;
|
RDFNode grantNode = solution.get(QueryFieldLabels.GRANT_URL);
|
||||||
|
Activity coreGrant;
|
||||||
if (allGrantURIToVO.containsKey(grantNode.toString())) {
|
|
||||||
coreGrant = allGrantURIToVO.get(grantNode.toString());
|
if (allGrantURIToVO.containsKey(grantNode.toString())) {
|
||||||
|
coreGrant = allGrantURIToVO.get(grantNode.toString());
|
||||||
} else {
|
|
||||||
|
} else {
|
||||||
coreGrant = new Activity(grantNode.toString());
|
|
||||||
allGrantURIToVO.put(grantNode.toString(), coreGrant);
|
coreGrant = new Activity(grantNode.toString());
|
||||||
|
allGrantURIToVO.put(grantNode.toString(), coreGrant);
|
||||||
RDFNode grantStartDateNode = solution.get(QueryFieldLabels.ROLE_START_DATE);
|
|
||||||
|
RDFNode grantStartDateNode = solution.get(QueryFieldLabels.ROLE_START_DATE);
|
||||||
if (grantStartDateNode != null) {
|
|
||||||
coreGrant.setActivityDate(grantStartDateNode.toString());
|
if (grantStartDateNode != null) {
|
||||||
} else {
|
coreGrant.setActivityDate(grantStartDateNode.toString());
|
||||||
grantStartDateNode = solution
|
} else {
|
||||||
.get(QueryFieldLabels.GRANT_START_DATE);
|
grantStartDateNode = solution
|
||||||
if (grantStartDateNode != null) {
|
.get(QueryFieldLabels.GRANT_START_DATE);
|
||||||
coreGrant.setActivityDate(grantStartDateNode.toString());
|
if (grantStartDateNode != null) {
|
||||||
}
|
coreGrant.setActivityDate(grantStartDateNode.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
currentEntityGrants.add(coreGrant);
|
}
|
||||||
}
|
currentEntityGrants.add(coreGrant);
|
||||||
return currentEntityGrants;
|
}
|
||||||
}
|
return currentEntityGrants;
|
||||||
|
}
|
||||||
public static Map<String, Activity> getGrantsForAllSubOrganizations(
|
|
||||||
Dataset dataset, Entity organizationEntity)
|
public static Map<String, Activity> getGrantsForAllSubOrganizations(
|
||||||
throws MalformedQueryParametersException {
|
Dataset dataset, Entity organizationEntity)
|
||||||
Map<String, Activity> allGrantURIToVO = new HashMap<String, Activity>();
|
throws MalformedQueryParametersException {
|
||||||
|
Map<String, Activity> allGrantURIToVO = new HashMap<String, Activity>();
|
||||||
for (SubEntity subOrganization : organizationEntity.getSubEntities()) {
|
|
||||||
|
for (SubEntity subOrganization : organizationEntity.getSubEntities()) {
|
||||||
Model subOrganizationGrantsModel = ModelConstructorUtilities
|
|
||||||
.getOrConstructModel(
|
System.out.println("constructing grants for " + subOrganization.getIndividualLabel() + " :: " + subOrganization.getIndividualURI());
|
||||||
subOrganization.getIndividualURI(),
|
|
||||||
OrganizationToGrantsForSubOrganizationsModelConstructor.MODEL_TYPE,
|
Model subOrganizationGrantsModel = ModelConstructorUtilities
|
||||||
dataset);
|
.getOrConstructModel(
|
||||||
|
subOrganization.getIndividualURI(),
|
||||||
System.out.println("getting grants for " + subOrganization.getIndividualLabel());
|
OrganizationToGrantsForSubOrganizationsModelConstructor.MODEL_TYPE,
|
||||||
|
dataset);
|
||||||
Map<String, String> fieldLabelToOutputFieldLabel = new HashMap<String, String>();
|
|
||||||
fieldLabelToOutputFieldLabel.put("grant", QueryFieldLabels.GRANT_URL);
|
Map<String, String> fieldLabelToOutputFieldLabel = new HashMap<String, String>();
|
||||||
fieldLabelToOutputFieldLabel.put("grantLabel", QueryFieldLabels.GRANT_LABEL);
|
fieldLabelToOutputFieldLabel.put("grant", QueryFieldLabels.GRANT_URL);
|
||||||
fieldLabelToOutputFieldLabel.put("grantStartDate", QueryFieldLabels.GRANT_START_DATE);
|
fieldLabelToOutputFieldLabel.put("grantLabel", QueryFieldLabels.GRANT_LABEL);
|
||||||
fieldLabelToOutputFieldLabel.put("roleStartDate", QueryFieldLabels.ROLE_START_DATE);
|
fieldLabelToOutputFieldLabel.put("grantStartDate", QueryFieldLabels.GRANT_START_DATE);
|
||||||
|
fieldLabelToOutputFieldLabel.put("roleStartDate", QueryFieldLabels.ROLE_START_DATE);
|
||||||
String whereClause = ""
|
|
||||||
+ " <" + subOrganization.getIndividualURI() + "> vivosocnet:hasPersonWithGrant ?grant . "
|
String whereClause = ""
|
||||||
+ " ?grant rdfs:label ?grantLabel . "
|
+ "{"
|
||||||
+ " OPTIONAL { "
|
+ " <" + subOrganization.getIndividualURI() + "> vivosocnet:hasInvestigatorWithGrant ?grant . "
|
||||||
+ " ?grant vivosocnet:startDateTimeOnGrant ?grantStartDate } . "
|
+ " ?grant rdfs:label ?grantLabel . "
|
||||||
+ " OPTIONAL { "
|
+ " OPTIONAL { "
|
||||||
+ " ?grant vivosocnet:startDateTimeOnRole ?roleStartDate } . ";
|
+ " ?grant vivosocnet:startDateTimeOnGrant ?grantStartDate } . "
|
||||||
|
+ " OPTIONAL { "
|
||||||
QueryRunner<ResultSet> subOrganizationGrantsQuery =
|
+ " ?grant vivosocnet:startDateTimeOnRole ?roleStartDate } . "
|
||||||
new GenericQueryRunnerOnModel(fieldLabelToOutputFieldLabel,
|
+ "}"
|
||||||
"",
|
+ "UNION"
|
||||||
whereClause,
|
+ "{"
|
||||||
"",
|
+ " <" + subOrganization.getIndividualURI() + "> vivosocnet:hasPIWithGrant ?grant . "
|
||||||
subOrganizationGrantsModel);
|
+ " ?grant rdfs:label ?grantLabel . "
|
||||||
|
+ " OPTIONAL { "
|
||||||
subOrganization.addActivities(getGrantForEntity(
|
+ " ?grant vivosocnet:startDateTimeOnGrant ?grantStartDate } . "
|
||||||
subOrganizationGrantsQuery.getQueryResult(),
|
+ " OPTIONAL { "
|
||||||
allGrantURIToVO));
|
+ " ?grant vivosocnet:startDateTimeOnRole ?roleStartDate } . "
|
||||||
|
+ "}"
|
||||||
}
|
+ "UNION"
|
||||||
return allGrantURIToVO;
|
+ "{"
|
||||||
}
|
+ " <" + subOrganization.getIndividualURI() + "> vivosocnet:hascoPIWithGrant ?grant . "
|
||||||
|
+ " ?grant rdfs:label ?grantLabel . "
|
||||||
public static Map<String, Activity> getPublicationsForAssociatedPeople(
|
+ " OPTIONAL { "
|
||||||
Dataset dataset, Collection<SubEntity> people)
|
+ " ?grant vivosocnet:startDateTimeOnGrant ?grantStartDate } . "
|
||||||
throws MalformedQueryParametersException {
|
+ " OPTIONAL { "
|
||||||
Map<String, Activity> allDocumentURIToVOs = new HashMap<String, Activity>();
|
+ " ?grant vivosocnet:startDateTimeOnRole ?roleStartDate } . "
|
||||||
|
+ "}";
|
||||||
for (SubEntity person : people) {
|
|
||||||
|
QueryRunner<ResultSet> subOrganizationGrantsQuery =
|
||||||
Model personPublicationsModel = ModelConstructorUtilities
|
new GenericQueryRunnerOnModel(fieldLabelToOutputFieldLabel,
|
||||||
.getOrConstructModel(
|
"",
|
||||||
person.getIndividualURI(),
|
whereClause,
|
||||||
PersonToPublicationsModelConstructor.MODEL_TYPE,
|
"",
|
||||||
dataset);
|
subOrganizationGrantsModel);
|
||||||
|
|
||||||
System.out.println("getting publications for " + person.getIndividualLabel());
|
subOrganization.addActivities(getGrantForEntity(
|
||||||
|
subOrganizationGrantsQuery.getQueryResult(),
|
||||||
Map<String, String> fieldLabelToOutputFieldLabel = new HashMap<String, String>();
|
allGrantURIToVO));
|
||||||
fieldLabelToOutputFieldLabel.put("document", QueryFieldLabels.DOCUMENT_URL);
|
|
||||||
fieldLabelToOutputFieldLabel.put("documentLabel", QueryFieldLabels.DOCUMENT_LABEL);
|
}
|
||||||
fieldLabelToOutputFieldLabel.put("documentPublicationDate", QueryFieldLabels.DOCUMENT_PUBLICATION_DATE);
|
return allGrantURIToVO;
|
||||||
|
}
|
||||||
String whereClause = ""
|
|
||||||
+ " <" + person.getIndividualURI() + "> vivosocnet:hasPublication ?document . "
|
public static Map<String, Activity> getGrantForAssociatedPeople(
|
||||||
+ " ?document rdfs:label ?documentLabel . "
|
Dataset dataset, Collection<SubEntity> people)
|
||||||
+ " OPTIONAL { "
|
throws MalformedQueryParametersException {
|
||||||
+ " ?document core:dateTimeValue ?dateTimeValue . "
|
Map<String, Activity> allGrantURIToVOs = new HashMap<String, Activity>();
|
||||||
+ " ?dateTimeValue core:dateTime ?documentPublicationDate } . ";
|
|
||||||
|
for (SubEntity person : people) {
|
||||||
QueryRunner<ResultSet> personPublicationsQuery =
|
|
||||||
new GenericQueryRunnerOnModel(fieldLabelToOutputFieldLabel,
|
System.out.println("constructing grants for " + person.getIndividualLabel() + " :: " + person.getIndividualURI());
|
||||||
"",
|
|
||||||
whereClause,
|
Model personGrantsModel = ModelConstructorUtilities
|
||||||
"",
|
.getOrConstructModel(
|
||||||
personPublicationsModel);
|
person.getIndividualURI(),
|
||||||
|
PersonToGrantsModelConstructor.MODEL_TYPE,
|
||||||
person.addActivities(getPublicationForEntity(
|
dataset);
|
||||||
personPublicationsQuery.getQueryResult(),
|
|
||||||
allDocumentURIToVOs));
|
Map<String, String> fieldLabelToOutputFieldLabel = new HashMap<String, String>();
|
||||||
|
fieldLabelToOutputFieldLabel.put("grant", QueryFieldLabels.GRANT_URL);
|
||||||
}
|
fieldLabelToOutputFieldLabel.put("grantLabel", QueryFieldLabels.GRANT_LABEL);
|
||||||
return allDocumentURIToVOs;
|
fieldLabelToOutputFieldLabel.put("grantStartDate", QueryFieldLabels.GRANT_START_DATE);
|
||||||
}
|
fieldLabelToOutputFieldLabel.put("roleStartDate", QueryFieldLabels.ROLE_START_DATE);
|
||||||
|
|
||||||
}
|
String whereClause = ""
|
||||||
|
+ "{"
|
||||||
|
+ " <" + person.getIndividualURI() + "> vivosocnet:hasGrantAsAnInvestigator ?grant . "
|
||||||
|
+ " ?grant rdfs:label ?grantLabel . "
|
||||||
|
+ " OPTIONAL { "
|
||||||
|
+ " ?grant vivosocnet:startDateTimeOnGrant ?grantStartDate } . "
|
||||||
|
+ " OPTIONAL { "
|
||||||
|
+ " ?grant vivosocnet:startDateTimeOnRole ?roleStartDate } . "
|
||||||
|
+ "}"
|
||||||
|
+ "UNION"
|
||||||
|
+ "{"
|
||||||
|
+ " <" + person.getIndividualURI() + "> vivosocnet:hasGrantAsPI ?grant . "
|
||||||
|
+ " ?grant rdfs:label ?grantLabel . "
|
||||||
|
+ " OPTIONAL { "
|
||||||
|
+ " ?grant vivosocnet:startDateTimeOnGrant ?grantStartDate } . "
|
||||||
|
+ " OPTIONAL { "
|
||||||
|
+ " ?grant vivosocnet:startDateTimeOnRole ?roleStartDate } . "
|
||||||
|
+ "}"
|
||||||
|
+ "UNION"
|
||||||
|
+ "{"
|
||||||
|
+ " <" + person.getIndividualURI() + "> vivosocnet:hasGrantAsCoPI ?grant . "
|
||||||
|
+ " ?grant rdfs:label ?grantLabel . "
|
||||||
|
+ " OPTIONAL { "
|
||||||
|
+ " ?grant vivosocnet:startDateTimeOnGrant ?grantStartDate } . "
|
||||||
|
+ " OPTIONAL { "
|
||||||
|
+ " ?grant vivosocnet:startDateTimeOnRole ?roleStartDate } . "
|
||||||
|
+ "}";
|
||||||
|
|
||||||
|
QueryRunner<ResultSet> personGrantsQuery =
|
||||||
|
new GenericQueryRunnerOnModel(fieldLabelToOutputFieldLabel,
|
||||||
|
"",
|
||||||
|
whereClause,
|
||||||
|
"",
|
||||||
|
personGrantsModel);
|
||||||
|
|
||||||
|
person.addActivities(getGrantForEntity(
|
||||||
|
personGrantsQuery.getQueryResult(),
|
||||||
|
allGrantURIToVOs));
|
||||||
|
|
||||||
|
}
|
||||||
|
return allGrantURIToVOs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Map<String, Activity> getPublicationsForAssociatedPeople(
|
||||||
|
Dataset dataset, Collection<SubEntity> people)
|
||||||
|
throws MalformedQueryParametersException {
|
||||||
|
Map<String, Activity> allDocumentURIToVOs = new HashMap<String, Activity>();
|
||||||
|
|
||||||
|
for (SubEntity person : people) {
|
||||||
|
|
||||||
|
Model personPublicationsModel = ModelConstructorUtilities
|
||||||
|
.getOrConstructModel(
|
||||||
|
person.getIndividualURI(),
|
||||||
|
PersonToPublicationsModelConstructor.MODEL_TYPE,
|
||||||
|
dataset);
|
||||||
|
|
||||||
|
System.out.println("getting publications for " + person.getIndividualLabel());
|
||||||
|
|
||||||
|
Map<String, String> fieldLabelToOutputFieldLabel = new HashMap<String, String>();
|
||||||
|
fieldLabelToOutputFieldLabel.put("document", QueryFieldLabels.DOCUMENT_URL);
|
||||||
|
fieldLabelToOutputFieldLabel.put("documentLabel", QueryFieldLabels.DOCUMENT_LABEL);
|
||||||
|
fieldLabelToOutputFieldLabel.put("documentPublicationDate", QueryFieldLabels.DOCUMENT_PUBLICATION_DATE);
|
||||||
|
|
||||||
|
String whereClause = ""
|
||||||
|
+ " <" + person.getIndividualURI() + "> vivosocnet:hasPublication ?document . "
|
||||||
|
+ " ?document rdfs:label ?documentLabel . "
|
||||||
|
+ " OPTIONAL { "
|
||||||
|
+ " ?document core:dateTimeValue ?dateTimeValue . "
|
||||||
|
+ " ?dateTimeValue core:dateTime ?documentPublicationDate } . ";
|
||||||
|
|
||||||
|
QueryRunner<ResultSet> personPublicationsQuery =
|
||||||
|
new GenericQueryRunnerOnModel(fieldLabelToOutputFieldLabel,
|
||||||
|
"",
|
||||||
|
whereClause,
|
||||||
|
"",
|
||||||
|
personPublicationsModel);
|
||||||
|
|
||||||
|
person.addActivities(getPublicationForEntity(
|
||||||
|
personPublicationsQuery.getQueryResult(),
|
||||||
|
allDocumentURIToVOs));
|
||||||
|
|
||||||
|
}
|
||||||
|
return allDocumentURIToVOs;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue