1. Changed icon for map of science.

2. Bug fixes for map of science edge cases.
3. Included a default error message when there are no publications to be found.
4. Improved text for map of sience info.
This commit is contained in:
tankchintan 2011-07-13 22:39:28 +00:00
parent 431036c1b0
commit 6f213a61fa
14 changed files with 614 additions and 532 deletions

View file

@ -210,4 +210,26 @@ a.map-of-science-links {
.paginatedtabs { .paginatedtabs {
font-size: 0.81em; font-size: 0.81em;
}
/* --------------------------------------------------------------> */
/* SPECIAL STYLES FOR THE error */
/* --------------------------------------------------------------> */
#error-container {
display: none;
}
#noPublications-header {
font-size: 1.375em;
color: #2485ae;
line-height: 1.3em;
padding-top:15px;
padding-bottom:10px;
}
#noPublications-span {
font-size:22px;
}
#noPublications-span a {
color: #84a655;
font-size:16px;
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.4 KiB

View file

@ -237,7 +237,7 @@ var DataTableWidget = Class.extend({
} }
me.currentSelectedFilter = SCIMAP_TYPE.SUBDISCIPLINE; me.currentSelectedFilter = SCIMAP_TYPE.SUBDISCIPLINE;
$("a#csv").attr("href", entityMapOfScienceSubDisciplineCSVURL); $("a#csv").attr("href", entityMapOfScienceSubDisciplineCSVURL);
$("a#csv").html("Export All Sub-Displines"); $("a#csv").html("Export All Sub-Disciplines");
} else { } else {
@ -247,7 +247,7 @@ var DataTableWidget = Class.extend({
me.widget.fnSettings()._iDisplayLength = 13; me.widget.fnSettings()._iDisplayLength = 13;
} }
$("a#csv").attr("href", entityMapOfScienceDisciplineCSVURL); $("a#csv").attr("href", entityMapOfScienceDisciplineCSVURL);
$("a#csv").html("Export All Displines"); $("a#csv").html("Export All Disciplines");
} }

View file

@ -1,207 +1,207 @@
/* $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$ */
/** /**
* The MarkerManager is more like a composite class of Marker. It manages * The MarkerManager is more like a composite class of Marker. It manages
* markers by grouping the markers by keys. * markers by grouping the markers by keys.
*/ */
var MarkerManager = Class.extend({ var MarkerManager = Class.extend({
init: function() { init: function() {
this.keyToMarker = {}; this.keyToMarker = {};
}, },
addMarker: function(key, marker) { addMarker: function(key, marker) {
this.keyToMarker[key] = marker; this.keyToMarker[key] = marker;
}, },
length: function() { length: function() {
var size = 0; var size = 0;
for (var key in this.keyToMarker) { for (var key in this.keyToMarker) {
if (this.keyToMarker.hasOwnProperty(key)) size++; if (this.keyToMarker.hasOwnProperty(key)) size++;
} }
return size; return size;
}, },
getMarker: function(key) { getMarker: function(key) {
return this.keyToMarker[key]; return this.keyToMarker[key];
}, },
getMarkerArray: function() { getMarkerArray: function() {
var array = []; var array = [];
$.each(this.keyToMarker, function(i, e){ array.push(e); }); $.each(this.keyToMarker, function(i, e){ array.push(e); });
return array; return array;
}, },
hasKey: function(key) { hasKey: function(key) {
return (this.keyToMarker.hasOwnProperty(key)); return (this.keyToMarker.hasOwnProperty(key));
}, },
showMarkers: function() { showMarkers: function() {
$.each(this.keyToMarker, function(i, marker) { $.each(this.keyToMarker, function(i, marker) {
marker.show(); marker.show();
}); });
}, },
hideMarkers: function() { hideMarkers: function() {
$.each(this.keyToMarker, function(i, marker) { $.each(this.keyToMarker, function(i, marker) {
marker.hide(); marker.hide();
}); });
}, },
addMarkersToMap: function() { addMarkersToMap: function() {
$.each(this.keyToMarker, function(i, marker) { $.each(this.keyToMarker, function(i, marker) {
marker.addToMap(); marker.addToMap();
}); });
}, },
removeMarkersFromMap: function() { removeMarkersFromMap: function() {
$.each(this.keyToMarker, function(i, marker) { $.each(this.keyToMarker, function(i, marker) {
marker.removeFromMap(); marker.removeFromMap();
}); });
} }
}); });
/** /**
* Customized Discipline labels MarkerManager for Science map purpose. It is an abstract class * Customized Discipline labels MarkerManager for Science map purpose. It is an abstract class
*/ */
var DisciplineLabelsMarkerManager = MarkerManager.extend({ var DisciplineLabelsMarkerManager = MarkerManager.extend({
init: function(map) { init: function(map) {
this._super(); this._super();
this.map = map; this.map = map;
this.initMarkers(map); this.initMarkers(map);
}, },
initMarkers: function(map) { initMarkers: function(map) {
me = this; me = this;
$.each(DISCIPLINES, function(id, discipline) { $.each(DISCIPLINES, function(id, discipline) {
var opts = { var opts = {
map: map, map: map,
position: createNoWrapLatLng(discipline.labelLatitude, discipline.labelLongitude), position: createNoWrapLatLng(discipline.labelLatitude, discipline.labelLongitude),
icon: getDisciplineLabelImageURL(id), icon: getDisciplineLabelImageURL(id),
clickable: false clickable: false
}; };
me.addMarker(id, new Marker(opts)); me.addMarker(id, new Marker(opts));
}); });
}, },
showMarkers: function() { showMarkers: function() {
this._super(); this._super();
} }
}); });
/** /**
* Customized MarkerManager for Science map purpose. It is an abstract class * Customized MarkerManager for Science map purpose. It is an abstract class
*/ */
var ScimapMarkerManager = MarkerManager.extend({ var ScimapMarkerManager = MarkerManager.extend({
init: function(map, colorStrategy, sizeCoder) { init: function(map, colorStrategy, sizeCoder) {
this._super(); this._super();
this.colorStrategy = colorStrategy; this.colorStrategy = colorStrategy;
this.sizeCoder = sizeCoder; this.sizeCoder = sizeCoder;
this.map = map; this.map = map;
this.maxValue = 1; this.maxValue = 1;
this.layer = {}; this.layer = {};
}, },
setSizeCoder: function(sizeCoder) { setSizeCoder: function(sizeCoder) {
this.sizeCoder = sizeCoder; this.sizeCoder = sizeCoder;
this.maxValue = sizeCoder.getMaxValue(); this.maxValue = sizeCoder.getMaxValue();
}, },
createMarker: function(key, density) { createMarker: function(key, density) {
var me = this; var me = this;
var marker; var marker;
if (!me.hasKey(key)) { if (!me.hasKey(key)) {
var size = me.sizeCoder.getSize(density); var size = me.sizeCoder.getSize(density);
var color = me.colorStrategy.getColor(key); var color = me.colorStrategy.getColor(key);
var layer = me.layer; var layer = me.layer;
var label = layer[key].label; var label = layer[key].label;
var latlng = createNoWrapLatLng(layer[key].latitude, layer[key].longitude); var latlng = createNoWrapLatLng(layer[key].latitude, layer[key].longitude);
marker = createScinodeMarker(me.map, label, density, size, color, latlng); marker = createScinodeMarker(me.map, label, density, size, color, latlng);
me.addMarker(key, marker); me.addMarker(key, marker);
} else { } else {
marker = me.keyToMarker[key]; marker = me.keyToMarker[key];
marker.setValue(marker.getValue() + density); marker.setValue(marker.getValue() + density);
marker.setSize(me.sizeCoder.getSize(marker.getValue())); marker.setSize(me.sizeCoder.getSize(marker.getValue()));
} }
return marker; return marker;
}, },
updateMarkerViews: function() { updateMarkerViews: function() {
var me = this; var me = this;
for (var key in me.keyToMarker) { for (var key in me.keyToMarker) {
var marker = me.keyToMarker[key]; var marker = me.keyToMarker[key];
marker.setSize(me.sizeCodingFunc(marker.getValue())); marker.setSize(me.sizeCodingFunc(marker.getValue()));
marker.setColor(me.colorStrategy.getColor(key)); marker.setColor(me.colorStrategy.getColor(key));
} }
}, },
display: function(numberOfMarkers) { display: function(numberOfMarkers) {
var markerArray = this.sortedMarkers; var markerArray = this.sortedMarkers;
if (!markerArray || !markerArray.length) { if (!markerArray || !markerArray.length) {
markerArray = this.getMarkerArray(); markerArray = this.getMarkerArray();
} }
$.each(markerArray, function() { $.each(markerArray, function() {
if (numberOfMarkers > 0) { if (numberOfMarkers > 0) {
this.show(); this.show();
numberOfMarkers--; numberOfMarkers--;
} else { } else {
this.hide(); this.hide();
} }
}); });
}, },
mouseIn: function(key) { mouseIn: function(key) {
var marker = this.getMarker(key); var marker = this.getMarker(key);
if (marker) { if (marker) {
marker.focus(); marker.focus();
} }
}, },
mouseInAll: function() { mouseInAll: function() {
$.each(this.keyToMarker, function(i, marker) { $.each(this.keyToMarker, function(i, marker) {
marker.focus(); marker.focus();
}); });
}, },
mouseOut: function(key) { mouseOut: function(key) {
var marker = this.getMarker(key); var marker = this.getMarker(key);
if (marker) { if (marker) {
marker.unfocus(); marker.unfocus();
} }
}, },
mouseOutAll: function() { mouseOutAll: function() {
$.each(this.keyToMarker, function(i, marker) { $.each(this.keyToMarker, function(i, marker) {
marker.unfocus(); marker.unfocus();
}); });
}, },
sort: function() { sort: function() {
this.sortedMarkers = this.getMarkerArray(); this.sortedMarkers = this.getMarkerArray();
this.sortedMarkers.sort(function(a, b) { this.sortedMarkers.sort(function(a, b) {
return b.getValue() -a.getValue(); return b.getValue() -a.getValue();
}); });
} }
}); });
var DisciplineMarkerManager = ScimapMarkerManager.extend({ var DisciplineMarkerManager = ScimapMarkerManager.extend({
init: function(map, colorStrategy, sizeCoder) { init: function(map, colorStrategy, sizeCoder) {
this._super(map, colorStrategy, sizeCoder); this._super(map, colorStrategy, sizeCoder);
this.layer = DISCIPLINES; this.layer = DISCIPLINES;
}, },
createMarker: function(subdisciplineKey, density) { createMarker: function(subdisciplineKey, density) {
var me = this; var me = this;
var key = SUBDISCIPLINES[subdisciplineKey].discipline; var key = SUBDISCIPLINES[subdisciplineKey].discipline;
var marker = this._super(key, density); var marker = this._super(key, density);
var poly = marker.polygon; var poly = marker.polygon;
marker.setContent( marker.setContent(
'<div style="font-size: 80%; padding: 5px; text-align: left;"><b>' '<div style="font-size: 80%; padding: 5px; text-align: left;"><b>'
+ poly.label +'</b><br />' + poly.label +'</b><br />'
+ addCommasToNumber(poly.value.toFixed(2)) + ' of publications (pubs.)<br />' + addCommasToNumber(poly.value.toFixed(2)) + ' publications (pubs.)<br />'
+ (poly.value * 100 / this.maxValue).toFixed(2) + '% of activity</div>' + (poly.value * 100 / this.maxValue).toFixed(2) + '% activity</div>'
); );
return marker; return marker;
} }
}); });
var SubdisciplineMarkerManager = ScimapMarkerManager.extend({ var SubdisciplineMarkerManager = ScimapMarkerManager.extend({
init: function(map, colorStrategy, sizeCoder) { init: function(map, colorStrategy, sizeCoder) {
this._super(map, colorStrategy, sizeCoder); this._super(map, colorStrategy, sizeCoder);
this.layer = SUBDISCIPLINES; this.layer = SUBDISCIPLINES;
}, },
createMarker: function(subdisciplineKey, density) { createMarker: function(subdisciplineKey, density) {
var marker = this._super(subdisciplineKey, density); var marker = this._super(subdisciplineKey, density);
var disciplineId = SUBDISCIPLINES[subdisciplineKey].discipline; var disciplineId = SUBDISCIPLINES[subdisciplineKey].discipline;
var disciplineLabel = DISCIPLINES[disciplineId].label; var disciplineLabel = DISCIPLINES[disciplineId].label;
var poly = marker.polygon; var poly = marker.polygon;
/* Override the getContent for Subdiscipline */ /* Override the getContent for Subdiscipline */
marker.setContent( marker.setContent(
'<div style="font-size: 80%; padding: 5px; text-align: left;"><b>' '<div style="font-size: 80%; padding: 5px; text-align: left;"><b>'
+ poly.label + '</b> in ' + disciplineLabel +'<br />' + poly.label + '</b> in ' + disciplineLabel +'<br />'
+ addCommasToNumber(poly.value.toFixed(2)) + ' of publications (pubs.)<br />' + addCommasToNumber(poly.value.toFixed(2)) + ' publications (pubs.)<br />'
+ (poly.value * 100 / this.maxValue).toFixed(2) + '% of activity</div>' + (poly.value * 100 / this.maxValue).toFixed(2) + '% activity</div>'
); );
return marker; return marker;
} }
}); });

View file

@ -61,11 +61,11 @@ var EntityVisModeController = Class.extend({
if (me.isUnloaded) { if (me.isUnloaded) {
if (sync) { if (sync) {
downloader.downloadAndWait(url, function(data) { downloader.downloadAndWait(url, function(data) {
me.loadJsonData(me, data[0]); me.loadJsonData(me, data);
}); });
} else { } else {
downloader.download(url, function(data) { downloader.download(url, function(data) {
me.loadJsonData(me, data[0]); me.loadJsonData(me, data);
}); });
} }
} // end if } // end if
@ -74,12 +74,20 @@ var EntityVisModeController = Class.extend({
$("#" + responseContainerID).unblock(); $("#" + responseContainerID).unblock();
if (data.error) {
$("#map-of-science-response").hide();
$("#error-container").show();
return;
}
data = data[0];
$.each(me.widgets, function(i, widget) { $.each(me.widgets, function(i, widget) {
widget.loadJsonData(data); widget.loadJsonData(data);
}); });
me.isUnloaded = false; me.isUnloaded = false;
me.initToolTipInfo(); me.initToolTipInfo();
}, },
initToolTipInfo: function() { initToolTipInfo: function() {

View file

@ -18,7 +18,7 @@
<section id="visualization" role="region"> <section id="visualization" role="region">
<#if isAuthor> <#if isAuthor>
<#assign coAuthorIcon = "${urls.images}/visualization/co_author_icon.png"> <#assign coAuthorIcon = "${urls.images}/visualization/co_author_icon.png">
<#assign mapOfScienceIcon = "${urls.images}/visualization/mapofscience/vivo_scimap_icon_v001.png"> <#assign mapOfScienceIcon = "${urls.images}/visualization/mapofscience/vivo_scimap.jpg">
<#assign coAuthorVisUrl = individual.coAuthorVisUrl> <#assign coAuthorVisUrl = individual.coAuthorVisUrl>
<#assign mapOfScienceVisUrl = individual.mapOfScienceUrl> <#assign mapOfScienceVisUrl = individual.mapOfScienceUrl>

View file

@ -3,5 +3,5 @@
<#-- Map Of Science visualization --> <#-- Map Of Science visualization -->
<div id="map-of-science"> <div id="map-of-science">
<h3><img src="${urls.images}/visualization/mapofscience/vivo_scimap_icon_v001.png" width="25px" height="25px" /><a href="${individual.mapOfScienceUrl}">Map of Science</a></h3> <h3><img src="${urls.images}/visualization/mapofscience/vivo_scimap.jpg" width="25px" height="25px" /><a href="${individual.mapOfScienceUrl}">Map of Science</a></h3>
</div> </div>

View file

@ -25,7 +25,7 @@
</#if> </#if>
<#assign mapOfScienceIcon = '${urls.images}/visualization/mapofscience/vivo_scimap_icon_v001.png'> <#assign mapOfScienceIcon = '${urls.images}/visualization/mapofscience/vivo_scimap.jpg'>
<#assign entityMapOfScienceDataURL = "${urls.base}${dataVisualizationURLRoot}?vis=${mapOfScienceVisParam}&uri=${entityURI}&output=json"> <#assign entityMapOfScienceDataURL = "${urls.base}${dataVisualizationURLRoot}?vis=${mapOfScienceVisParam}&uri=${entityURI}&output=json">
<#assign entityMapOfScienceDisciplineCSVURL = "${urls.base}${dataVisualizationURLRoot}?vis=${mapOfScienceVisParam}&uri=${entityURI}&output=csv&vis_mode=discipline"> <#assign entityMapOfScienceDisciplineCSVURL = "${urls.base}${dataVisualizationURLRoot}?vis=${mapOfScienceVisParam}&uri=${entityURI}&output=csv&vis_mode=discipline">

View file

@ -102,12 +102,25 @@ You can hover over a sub-discipline in the table below to show which overlaid ci
<br /><br /> <br /><br />
<#--
In the table below, <b># of pubs.</b> column indicates number of publications that fall under a particular field (sub-discipline or In the table below, <b># of pubs.</b> column indicates number of publications that fall under a particular field (sub-discipline or
discipline). Sometimes this number will be fractional. This happens when a journal in which the publication was published happens discipline). Sometimes this number will be fractional. This happens when a journal in which the publication was published is associated
to impact more than one field and hence the publication score is distributed into number of fractions based on the weight scores with more than one (sub)discipline. In these cases, the publication score is fractionally mapped based on the weight scores
of the journal in the different fields.<br /><br /> of the journal.<br /><br />
<b>% activity</b> column indicates the percentage of publications that fall under a particular field. <b>% activity</b> column indicates the percentage of publications that fall under a particular field.
-->
The table below summarizes this institution's body of publications as plotted on the map of science.
Each row corresponds to a field (discipline or sub-discipline) on the map.
<br /><br />
The <b># of pubs.</b> column shows how many of the publications were mapped to each field.
This count can be fractional because some publication venues are associated with more than one field.
Each publication in such a venue contributes fractionally to all associated fields according to a weighting scheme.
<br /><br />
The <b>% activity</b> column shows what proportion of the publications were mapped to each field.
</div> </div>
@ -122,7 +135,20 @@ may need to be cleaned up before they are recognized. You may contact a VIVO sys
concern.</div> concern.</div>
<div id="searchInfoTooltipText" style="display:none;"> <div id="searchInfoTooltipText" style="display:none;">
This search box is used to filter the table rows based on the sub-discipline (or discipline) label found in the first column. <!-- Search for specific sub-discipline (or discipline) label in the first column of the table. -->
List only map of science areas whose names contain this text.
</div>
<div id="error-container">
<h1 id="noPublications-header">${entityLabel}</h1>
<h3 id="alternative-vis-info">Map of Science Visualization</h3>
<div id="error-body">
<p>This organization has neither sub-organizations nor people with publications in the system.
Please visit the full ${entityLabel} <a href="${entityVivoProfileURL}">profile page</a> for a more complete overview.</p>
</div>
</div> </div>
${headScripts.add('<script type="text/javascript" src="${urls.base}/js/jquery_plugins/qtip/jquery.qtip-1.0.0-rc3.min.js"></script>')} ${headScripts.add('<script type="text/javascript" src="${urls.base}/js/jquery_plugins/qtip/jquery.qtip-1.0.0-rc3.min.js"></script>')}

View file

@ -35,7 +35,7 @@ import edu.cornell.mannlib.vitro.webapp.visualization.visutils.VisualizationRequ
public class EntityPublicationCountRequestHandler implements public class EntityPublicationCountRequestHandler implements
VisualizationRequestHandler { VisualizationRequestHandler {
@Override @Override
public ResponseValues generateStandardVisualization( public ResponseValues generateStandardVisualization(
VitroRequest vitroRequest, Log log, Dataset dataset) VitroRequest vitroRequest, Log log, Dataset dataset)
@ -43,7 +43,7 @@ public class EntityPublicationCountRequestHandler implements
String entityURI = vitroRequest String entityURI = vitroRequest
.getParameter(VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY); .getParameter(VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY);
return generateStandardVisualizationForPublicationTemporalVis( return generateStandardVisualizationForPublicationTemporalVis(
vitroRequest, log, dataset, entityURI); vitroRequest, log, dataset, entityURI);
} }
@ -51,19 +51,17 @@ public class EntityPublicationCountRequestHandler implements
private ResponseValues generateStandardVisualizationForPublicationTemporalVis( private ResponseValues generateStandardVisualizationForPublicationTemporalVis(
VitroRequest vitroRequest, Log log, Dataset dataset, VitroRequest vitroRequest, Log log, Dataset dataset,
String entityURI) throws MalformedQueryParametersException { String entityURI) throws MalformedQueryParametersException {
if (StringUtils.isBlank(entityURI)) { if (StringUtils.isBlank(entityURI)) {
entityURI = OrganizationUtilityFunctions entityURI = OrganizationUtilityFunctions
.getStaffProvidedOrComputedHighestLevelOrganization( .getStaffProvidedOrComputedHighestLevelOrganization(log,
log, dataset, vitroRequest);
dataset,
vitroRequest);
} }
return prepareStandaloneMarkupResponse(vitroRequest, entityURI); return prepareStandaloneMarkupResponse(vitroRequest, entityURI);
} }
@Override @Override
@ -72,46 +70,50 @@ public class EntityPublicationCountRequestHandler implements
Dataset dataSource) throws MalformedQueryParametersException { Dataset dataSource) throws MalformedQueryParametersException {
return generateStandardVisualizationForPublicationTemporalVis( return generateStandardVisualizationForPublicationTemporalVis(
vitroRequest, log, dataSource, parameters.get(VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY)); vitroRequest,
log,
dataSource,
parameters
.get(VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY));
} }
private Map<String, String> getSubjectEntityAndGenerateDataResponse( private Map<String, String> getSubjectEntityAndGenerateDataResponse(
VitroRequest vitroRequest, Log log, Dataset dataset, VitroRequest vitroRequest, Log log, Dataset dataset,
String subjectEntityURI) String subjectEntityURI) throws MalformedQueryParametersException {
throws MalformedQueryParametersException {
ModelConstructor constructQueryRunner = new EntityPublicationCountConstructQueryRunner(
ModelConstructor constructQueryRunner = subjectEntityURI, dataset, log);
new EntityPublicationCountConstructQueryRunner(subjectEntityURI, dataset, log);
Model constructedModel = constructQueryRunner.getConstructedModel(); Model constructedModel = constructQueryRunner.getConstructedModel();
QueryRunner<Entity> queryManager = new EntityPublicationCountQueryRunner( QueryRunner<Entity> queryManager = new EntityPublicationCountQueryRunner(
subjectEntityURI, constructedModel, log); subjectEntityURI, constructedModel, log);
Entity entity = queryManager.getQueryResult(); Entity entity = queryManager.getQueryResult();
if (entity.getEntityLabel().equals("no-label")) { if (entity.getEntityLabel().equals("no-label")) {
return prepareStandaloneDataErrorResponse(vitroRequest, subjectEntityURI); return prepareStandaloneDataErrorResponse(vitroRequest,
subjectEntityURI);
} else {
} else {
return getSubEntityTypesAndComputeDataResponse(
vitroRequest, log, dataset, return getSubEntityTypesAndComputeDataResponse(vitroRequest, log,
subjectEntityURI, entity); dataset, subjectEntityURI, entity);
} }
} }
private Map<String, String> prepareStandaloneDataErrorResponse( private Map<String, String> prepareStandaloneDataErrorResponse(
VitroRequest vitroRequest, String subjectEntityURI) { VitroRequest vitroRequest, String subjectEntityURI) {
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
"{\"error\" : \"No Publications for this Organization found in VIVO.\"}"); .put(DataVisualizationController.FILE_CONTENT_KEY,
"{\"error\" : \"No Publications for this Organization found in VIVO.\"}");
return fileData; return fileData;
} }
@ -119,13 +121,12 @@ public class EntityPublicationCountRequestHandler implements
VitroRequest vitroRequest, Log log, Dataset dataset, VitroRequest vitroRequest, Log log, Dataset dataset,
String subjectEntityURI, Entity entity) String subjectEntityURI, Entity entity)
throws MalformedQueryParametersException { throws MalformedQueryParametersException {
Map<String, Set<String>> subOrganizationTypesResult = Map<String, Set<String>> subOrganizationTypesResult = OrganizationUtilityFunctions
OrganizationUtilityFunctions.getSubEntityTypes( .getSubEntityTypes(log, dataset, subjectEntityURI);
log, dataset, subjectEntityURI);
return prepareStandaloneDataResponse(vitroRequest, entity, entity
return prepareStandaloneDataResponse(vitroRequest, entity, entity.getSubEntities(), .getSubEntities(), subOrganizationTypesResult);
subOrganizationTypesResult);
} }
@Override @Override
@ -135,154 +136,155 @@ public class EntityPublicationCountRequestHandler implements
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.JSON_OUTPUT_FORMAT if (VisualizationFrameworkConstants.JSON_OUTPUT_FORMAT
.equalsIgnoreCase(vitroRequest.getParameter( .equalsIgnoreCase(vitroRequest
VisualizationFrameworkConstants.VIS_MODE_KEY))) { .getParameter(VisualizationFrameworkConstants.VIS_MODE_KEY))) {
if (StringUtils.isNotBlank(entityURI)) { if (StringUtils.isNotBlank(entityURI)) {
return getSubjectEntityAndGenerateDataResponse( return getSubjectEntityAndGenerateDataResponse(vitroRequest,
vitroRequest, log, dataset, entityURI);
log,
dataset,
entityURI);
} else { } else {
return getSubjectEntityAndGenerateDataResponse( return getSubjectEntityAndGenerateDataResponse(
vitroRequest, vitroRequest,
log, log,
dataset, dataset,
OrganizationUtilityFunctions OrganizationUtilityFunctions
.getStaffProvidedOrComputedHighestLevelOrganization( .getStaffProvidedOrComputedHighestLevelOrganization(
log, log, dataset, vitroRequest));
dataset,
vitroRequest));
} }
} else { } else {
/* /*
* This provides csv download files for the content in the tables. * This provides csv download files for the content in the tables.
* */ */
ModelConstructor constructQueryRunner = ModelConstructor constructQueryRunner = new EntityPublicationCountConstructQueryRunner(
new EntityPublicationCountConstructQueryRunner(entityURI, dataset, log); entityURI, dataset, log);
Model constructedModel = constructQueryRunner.getConstructedModel(); Model constructedModel = constructQueryRunner.getConstructedModel();
QueryRunner<Entity> queryManager = new EntityPublicationCountQueryRunner( QueryRunner<Entity> queryManager = new EntityPublicationCountQueryRunner(
entityURI, constructedModel, log); entityURI, constructedModel, log);
Entity entity = queryManager.getQueryResult(); Entity entity = queryManager.getQueryResult();
Map<String, Set<String>> subOrganizationTypesResult = Map<String, Set<String>> subOrganizationTypesResult = OrganizationUtilityFunctions
OrganizationUtilityFunctions.getSubEntityTypes( .getSubEntityTypes(log, dataset, entityURI);
log, dataset, entityURI);
return prepareDataResponse(entity, entity.getSubEntities(),
subOrganizationTypesResult);
return prepareDataResponse(entity, entity.getSubEntities(), subOrganizationTypesResult);
} }
} }
@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.");
} }
/** /**
* Provides response when json file containing the publication count over the * Provides response when json file containing the publication count over
* years is requested. * the years is requested.
* *
* @param entity * @param entity
* @param subentities * @param subentities
* @param subOrganizationTypesResult * @param subOrganizationTypesResult
*/ */
private Map<String, String> prepareDataResponse(Entity entity, Set<SubEntity> subentities, private Map<String, String> prepareDataResponse(Entity entity,
Set<SubEntity> subentities,
Map<String, Set<String>> subOrganizationTypesResult) { Map<String, Set<String>> subOrganizationTypesResult) {
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>();
fileData.put(DataVisualizationController.FILE_NAME_KEY,
outputFileName);
fileData.put(DataVisualizationController.FILE_CONTENT_TYPE_KEY,
"application/octet-stream");
fileData.put(DataVisualizationController.FILE_CONTENT_KEY,
getEntityPublicationsPerYearCSVContent(subentities, subOrganizationTypesResult));
return fileData;
}
private Map<String, String> prepareStandaloneDataResponse(
VitroRequest vitroRequest,
Entity entity,
Set<SubEntity> subentities,
Map<String, Set<String>> subOrganizationTypesResult) {
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_NAME_KEY, outputFileName);
"application/octet-stream"); fileData.put(DataVisualizationController.FILE_CONTENT_TYPE_KEY,
"application/octet-stream");
fileData.put(DataVisualizationController.FILE_CONTENT_KEY, fileData.put(DataVisualizationController.FILE_CONTENT_KEY,
writePublicationsOverTimeJSON(vitroRequest, getEntityPublicationsPerYearCSVContent(subentities,
entity.getSubEntities(), subOrganizationTypesResult));
subOrganizationTypesResult));
return fileData; return fileData;
} }
private TemplateResponseValues prepareStandaloneMarkupResponse(VitroRequest vreq,
String entityURI) {
String standaloneTemplate = "entityComparisonOnPublicationsStandalone.ftl"; private Map<String, String> prepareStandaloneDataResponse(
VitroRequest vitroRequest, Entity entity,
String organizationLabel = OrganizationUtilityFunctions Set<SubEntity> subentities,
.getEntityLabelFromDAO(vreq, Map<String, Set<String>> subOrganizationTypesResult)
entityURI); throws MalformedQueryParametersException {
Map<String, Object> body = new HashMap<String, Object>(); Map<String, String> fileData = new HashMap<String, String>();
body.put("title", organizationLabel + " - Temporal Graph Visualization");
body.put("organizationURI", entityURI); fileData.put(DataVisualizationController.FILE_CONTENT_TYPE_KEY,
body.put("organizationLocalName", UtilityFunctions.getIndividualLocalName(entityURI, vreq)); "application/octet-stream");
body.put("vivoDefaultNamespace", vreq.getWebappDaoFactory().getDefaultNamespace()); fileData.put(DataVisualizationController.FILE_CONTENT_KEY,
body.put("organizationLabel", organizationLabel); writePublicationsOverTimeJSON(vitroRequest, entity
.getSubEntities(), subOrganizationTypesResult));
return new TemplateResponseValues(standaloneTemplate, body); return fileData;
}
private TemplateResponseValues prepareStandaloneMarkupResponse(
VitroRequest vreq, String entityURI) {
String standaloneTemplate = "entityComparisonOnPublicationsStandalone.ftl";
String organizationLabel = OrganizationUtilityFunctions
.getEntityLabelFromDAO(vreq, entityURI);
Map<String, Object> body = new HashMap<String, Object>();
body
.put("title", organizationLabel
+ " - Temporal Graph Visualization");
body.put("organizationURI", entityURI);
body.put("organizationLocalName", UtilityFunctions
.getIndividualLocalName(entityURI, vreq));
body.put("vivoDefaultNamespace", vreq.getWebappDaoFactory()
.getDefaultNamespace());
body.put("organizationLabel", organizationLabel);
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
* @throws MalformedQueryParametersException
*/ */
private String writePublicationsOverTimeJSON(VitroRequest vreq, private String writePublicationsOverTimeJSON(VitroRequest vreq,
Set<SubEntity> subentities, Set<SubEntity> subentities,
Map<String, Set<String>> Map<String, Set<String>> subOrganizationTypesResult)
subOrganizationTypesResult) { throws MalformedQueryParametersException {
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( JsonObject entityJson = new JsonObject(subentity
subentity.getIndividualLabel()); .getIndividualLabel());
List<List<Integer>> yearPubCount = new ArrayList<List<Integer>>(); List<List<Integer>> yearPubCount = new ArrayList<List<Integer>>();
@ -291,24 +293,26 @@ public class EntityPublicationCountRequestHandler implements
.entrySet()) { .entrySet()) {
List<Integer> currentPubYear = new ArrayList<Integer>(); List<Integer> currentPubYear = new ArrayList<Integer>();
if (pubEntry.getKey().equals(VOConstants.DEFAULT_PUBLICATION_YEAR)) { if (pubEntry.getKey().equals(
VOConstants.DEFAULT_PUBLICATION_YEAR)) {
currentPubYear.add(-1); currentPubYear.add(-1);
} else { } else {
currentPubYear.add(Integer.parseInt(pubEntry.getKey())); currentPubYear.add(Integer.parseInt(pubEntry.getKey()));
} }
currentPubYear.add(pubEntry.getValue()); currentPubYear.add(pubEntry.getValue());
yearPubCount.add(currentPubYear); yearPubCount.add(currentPubYear);
} }
entityJson.setYearToActivityCount(yearPubCount); entityJson.setYearToActivityCount(yearPubCount);
entityJson.getOrganizationTypes().addAll( entityJson.getOrganizationTypes().addAll(
subOrganizationTypesResult.get(entityJson.getLabel())); subOrganizationTypesResult.get(entityJson.getLabel()));
entityJson.setEntityURI(subentity.getIndividualURI()); entityJson.setEntityURI(subentity.getIndividualURI());
boolean isPerson = UtilityFunctions.isEntityAPerson(vreq, subentity.getIndividualURI()); boolean isPerson = UtilityFunctions.isEntityAPerson(vreq, subentity
.getIndividualURI());
if (isPerson) { if (isPerson) {
entityJson.setVisMode("PERSON"); entityJson.setVisMode("PERSON");
} else { } else {
@ -320,28 +324,30 @@ public class EntityPublicationCountRequestHandler implements
} }
private String getEntityPublicationsPerYearCSVContent( private String getEntityPublicationsPerYearCSVContent(
Set<SubEntity> subentities, Set<SubEntity> subentities,
Map<String, Set<String>> subOrganizationTypesResult) { Map<String, Set<String>> subOrganizationTypesResult) {
StringBuilder csvFileContent = new StringBuilder(); StringBuilder csvFileContent = new StringBuilder();
csvFileContent.append("Entity Name, Publication Count, Entity Type\n"); csvFileContent.append("Entity Name, Publication Count, Entity Type\n");
for (SubEntity subEntity : subentities) { for (SubEntity subEntity : subentities) {
csvFileContent.append(StringEscapeUtils.escapeCsv(subEntity.getIndividualLabel())); csvFileContent.append(StringEscapeUtils.escapeCsv(subEntity
.getIndividualLabel()));
csvFileContent.append(", "); csvFileContent.append(", ");
csvFileContent.append(subEntity.getActivities().size()); csvFileContent.append(subEntity.getActivities().size());
csvFileContent.append(", "); csvFileContent.append(", ");
StringBuilder joinedTypes = new StringBuilder(); StringBuilder joinedTypes = new StringBuilder();
for (String subOrganizationType : subOrganizationTypesResult for (String subOrganizationType : subOrganizationTypesResult
.get(subEntity.getIndividualLabel())) { .get(subEntity.getIndividualLabel())) {
joinedTypes.append(subOrganizationType + "; "); joinedTypes.append(subOrganizationType + "; ");
} }
csvFileContent.append(StringEscapeUtils.escapeCsv(joinedTypes.toString())); csvFileContent.append(StringEscapeUtils.escapeCsv(joinedTypes
.toString()));
csvFileContent.append("\n"); csvFileContent.append("\n");
} }
return csvFileContent.toString(); return csvFileContent.toString();
@ -353,4 +359,4 @@ public class EntityPublicationCountRequestHandler implements
return null; return null;
} }
} }

View file

@ -34,18 +34,17 @@ import edu.cornell.mannlib.vitro.webapp.visualization.visutils.QueryRunner;
import edu.cornell.mannlib.vitro.webapp.visualization.visutils.UtilityFunctions; import edu.cornell.mannlib.vitro.webapp.visualization.visutils.UtilityFunctions;
import edu.cornell.mannlib.vitro.webapp.visualization.visutils.VisualizationRequestHandler; import edu.cornell.mannlib.vitro.webapp.visualization.visutils.VisualizationRequestHandler;
public class EntityGrantCountRequestHandler implements public class EntityGrantCountRequestHandler 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);
return generateStandardVisualizationForGrantTemporalVis(vitroRequest, return generateStandardVisualizationForGrantTemporalVis(vitroRequest,
log, dataset, entityURI); log, dataset, entityURI);
} }
@ -54,13 +53,11 @@ public class EntityGrantCountRequestHandler implements
VitroRequest vitroRequest, Log log, Dataset dataset, VitroRequest vitroRequest, Log log, Dataset dataset,
String entityURI) throws MalformedQueryParametersException { String entityURI) throws MalformedQueryParametersException {
if (StringUtils.isBlank(entityURI)) { if (StringUtils.isBlank(entityURI)) {
entityURI = OrganizationUtilityFunctions entityURI = OrganizationUtilityFunctions
.getStaffProvidedOrComputedHighestLevelOrganization( .getStaffProvidedOrComputedHighestLevelOrganization(log,
log, dataset, vitroRequest);
dataset,
vitroRequest);
} }
return prepareStandaloneMarkupResponse(vitroRequest, entityURI); return prepareStandaloneMarkupResponse(vitroRequest, entityURI);
} }
@ -71,7 +68,11 @@ public class EntityGrantCountRequestHandler implements
Dataset dataSource) throws MalformedQueryParametersException { Dataset dataSource) throws MalformedQueryParametersException {
return generateStandardVisualizationForGrantTemporalVis( return generateStandardVisualizationForGrantTemporalVis(
vitroRequest, log, dataSource, parameters.get(VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY)); vitroRequest,
log,
dataSource,
parameters
.get(VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY));
} }
@ -82,89 +83,83 @@ public class EntityGrantCountRequestHandler implements
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.JSON_OUTPUT_FORMAT if (VisualizationFrameworkConstants.JSON_OUTPUT_FORMAT
.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, dataset, entityURI);
log,
dataset,
entityURI);
} else { } else {
return getSubjectEntityAndGenerateDataResponse( return getSubjectEntityAndGenerateDataResponse(
vitroRequest, vitroRequest,
log, log,
dataset, dataset,
OrganizationUtilityFunctions OrganizationUtilityFunctions
.getStaffProvidedOrComputedHighestLevelOrganization( .getStaffProvidedOrComputedHighestLevelOrganization(
log, log, dataset, vitroRequest));
dataset,
vitroRequest));
} }
} else { } else {
/* /*
* This provides csv download files for the content in the tables. * This provides csv download files for the content in the tables.
* */ */
ModelConstructor constructQueryRunner = ModelConstructor constructQueryRunner = new EntityGrantCountConstructQueryRunner(
new EntityGrantCountConstructQueryRunner(entityURI, dataset, log); entityURI, dataset, log);
Model constructedModel = constructQueryRunner.getConstructedModel(); Model constructedModel = constructQueryRunner.getConstructedModel();
QueryRunner<Entity> queryManager = new EntityGrantCountQueryRunner( QueryRunner<Entity> queryManager = new EntityGrantCountQueryRunner(
entityURI, constructedModel, log); entityURI, constructedModel, log);
Entity entity = queryManager.getQueryResult(); Entity entity = queryManager.getQueryResult();
Map<String, Set<String>> subOrganizationTypesResult = OrganizationUtilityFunctions
Map<String, Set<String>> subOrganizationTypesResult = .getSubEntityTypes(log, dataset, entityURI);
OrganizationUtilityFunctions.getSubEntityTypes(
log, dataset, entityURI); return prepareDataResponse(entity, entity.getSubEntities(),
subOrganizationTypesResult);
return prepareDataResponse(entity, entity.getSubEntities(), subOrganizationTypesResult);
} }
} }
@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) String subjectEntityURI) throws MalformedQueryParametersException {
throws MalformedQueryParametersException {
ModelConstructor constructQueryRunner = new EntityGrantCountConstructQueryRunner(
ModelConstructor constructQueryRunner = subjectEntityURI, dataset, log);
new EntityGrantCountConstructQueryRunner(subjectEntityURI, dataset, log);
Model constructedModel = constructQueryRunner.getConstructedModel(); Model constructedModel = constructQueryRunner.getConstructedModel();
QueryRunner<Entity> queryManager = new EntityGrantCountQueryRunner( QueryRunner<Entity> queryManager = new EntityGrantCountQueryRunner(
subjectEntityURI, constructedModel, log); subjectEntityURI, constructedModel, log);
Entity entity = queryManager.getQueryResult(); Entity entity = queryManager.getQueryResult();
if (entity.getEntityLabel().equals("no-label")) { if (entity.getEntityLabel().equals("no-label")) {
return prepareStandaloneDataErrorResponse(vitroRequest, subjectEntityURI); return prepareStandaloneDataErrorResponse(vitroRequest,
} else { subjectEntityURI);
} else {
return getSubEntityTypesAndComputeDataResponse(
vitroRequest, log, dataset, return getSubEntityTypesAndComputeDataResponse(vitroRequest, log,
subjectEntityURI, entity); dataset, subjectEntityURI, entity);
} }
} }
@ -172,41 +167,39 @@ public class EntityGrantCountRequestHandler implements
VitroRequest vitroRequest, Log log, Dataset dataset, VitroRequest vitroRequest, Log log, Dataset dataset,
String subjectOrganization, Entity entity) String subjectOrganization, Entity entity)
throws MalformedQueryParametersException { throws MalformedQueryParametersException {
Map<String, Set<String>> subOrganizationTypesResult = Map<String, Set<String>> subOrganizationTypesResult = OrganizationUtilityFunctions
OrganizationUtilityFunctions.getSubEntityTypes( .getSubEntityTypes(log, dataset, subjectOrganization);
log, dataset, subjectOrganization);
return prepareStandaloneDataResponse(vitroRequest, entity,
return prepareStandaloneDataResponse(vitroRequest, entity, subOrganizationTypesResult); subOrganizationTypesResult);
} }
private Map<String, String> prepareStandaloneDataErrorResponse( private Map<String, String> prepareStandaloneDataErrorResponse(
VitroRequest vitroRequest, String subjectEntityURI) { VitroRequest vitroRequest, String subjectEntityURI) {
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
"{\"error\" : \"No Grants for this Organization found in VIVO.\"}"); .put(DataVisualizationController.FILE_CONTENT_KEY,
"{\"error\" : \"No Grants for this Organization found in VIVO.\"}");
return fileData; return fileData;
} }
private Map<String, String> prepareStandaloneDataResponse( private Map<String, String> prepareStandaloneDataResponse(
VitroRequest vitroRequest, VitroRequest vitroRequest, Entity entity,
Entity entity, Map<String, Set<String>> subOrganizationTypesResult)
Map<String, Set<String>> subOrganizationTypesResult) { throws MalformedQueryParametersException {
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,
writeGrantsOverTimeJSON(vitroRequest, writeGrantsOverTimeJSON(vitroRequest, entity.getSubEntities(),
entity.getSubEntities(), subOrganizationTypesResult));
subOrganizationTypesResult));
return fileData; return fileData;
} }
@ -218,68 +211,75 @@ public class EntityGrantCountRequestHandler implements
* @param subentities * @param subentities
* @param subOrganizationTypesResult * @param subOrganizationTypesResult
*/ */
private Map<String, String> prepareDataResponse(Entity entity, Set<SubEntity> subentities, private Map<String, String> prepareDataResponse(Entity entity,
Set<SubEntity> subentities,
Map<String, Set<String>> subOrganizationTypesResult) { Map<String, Set<String>> subOrganizationTypesResult) {
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)
+ "_grants-per-year" + ".csv"; + "_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, getEntityGrantsPerYearCSVContent(subentities,
getEntityGrantsPerYearCSVContent(subentities, subOrganizationTypesResult)); subOrganizationTypesResult));
return fileData; return fileData;
} }
private TemplateResponseValues prepareStandaloneMarkupResponse(VitroRequest vreq, private TemplateResponseValues prepareStandaloneMarkupResponse(
String entityURI) { VitroRequest vreq, String entityURI) {
String standaloneTemplate = "entityComparisonOnGrantsStandalone.ftl"; String standaloneTemplate = "entityComparisonOnGrantsStandalone.ftl";
String organizationLabel = OrganizationUtilityFunctions.getEntityLabelFromDAO(vreq, String organizationLabel = OrganizationUtilityFunctions
entityURI); .getEntityLabelFromDAO(vreq, entityURI);
Map<String, Object> body = new HashMap<String, Object>(); Map<String, Object> body = new HashMap<String, Object>();
body.put("title", organizationLabel + " - Temporal Graph Visualization"); body
.put("title", organizationLabel
+ " - Temporal Graph Visualization");
body.put("organizationURI", entityURI); body.put("organizationURI", entityURI);
body.put("organizationLocalName", UtilityFunctions.getIndividualLocalName(entityURI, vreq)); body.put("organizationLocalName", UtilityFunctions
body.put("vivoDefaultNamespace", vreq.getWebappDaoFactory().getDefaultNamespace()); .getIndividualLocalName(entityURI, vreq));
body.put("vivoDefaultNamespace", vreq.getWebappDaoFactory()
.getDefaultNamespace());
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 <-> grant count mapping. * Function to generate a json file for year <-> grant count mapping.
* @param vreq *
* @param vreq
* @param subentities * @param subentities
* @param subOrganizationTypesResult * @param subOrganizationTypesResult
* @throws MalformedQueryParametersException
*/ */
private String writeGrantsOverTimeJSON(VitroRequest vreq, private String writeGrantsOverTimeJSON(VitroRequest vreq,
Set<SubEntity> subentities, Set<SubEntity> subentities,
Map<String, Set<String>> subOrganizationTypesResult) { Map<String, Set<String>> subOrganizationTypesResult)
throws MalformedQueryParametersException {
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( JsonObject entityJson = new JsonObject(subentity
subentity.getIndividualLabel()); .getIndividualLabel());
List<List<Integer>> yearGrantCount = new ArrayList<List<Integer>>(); List<List<Integer>> yearGrantCount = new ArrayList<List<Integer>>();
@ -288,13 +288,12 @@ public class EntityGrantCountRequestHandler implements
.entrySet()) { .entrySet()) {
List<Integer> currentGrantYear = new ArrayList<Integer>(); List<Integer> currentGrantYear = new ArrayList<Integer>();
if (grantEntry.getKey().equals( if (grantEntry.getKey().equals(VOConstants.DEFAULT_GRANT_YEAR)) {
VOConstants.DEFAULT_GRANT_YEAR)) {
currentGrantYear.add(-1); currentGrantYear.add(-1);
} else { } else {
currentGrantYear.add(Integer.parseInt(grantEntry.getKey())); currentGrantYear.add(Integer.parseInt(grantEntry.getKey()));
} }
currentGrantYear.add(grantEntry.getValue()); currentGrantYear.add(grantEntry.getValue());
yearGrantCount.add(currentGrantYear); yearGrantCount.add(currentGrantYear);
} }
@ -304,45 +303,47 @@ public class EntityGrantCountRequestHandler implements
subOrganizationTypesResult.get(entityJson.getLabel())); subOrganizationTypesResult.get(entityJson.getLabel()));
entityJson.setEntityURI(subentity.getIndividualURI()); entityJson.setEntityURI(subentity.getIndividualURI());
if (UtilityFunctions.isEntityAPerson(vreq, subentity.getIndividualURI())) { if (UtilityFunctions.isEntityAPerson(vreq, subentity
.getIndividualURI())) {
entityJson.setVisMode("PERSON"); entityJson.setVisMode("PERSON");
} else { } else {
entityJson.setVisMode("ORGANIZATION"); entityJson.setVisMode("ORGANIZATION");
} }
subEntitiesJson.add(entityJson); subEntitiesJson.add(entityJson);
} }
return json.toJson(subEntitiesJson); return json.toJson(subEntitiesJson);
} }
private String getEntityGrantsPerYearCSVContent( private String getEntityGrantsPerYearCSVContent(Set<SubEntity> subentities,
Set<SubEntity> subentities, Map<String, Set<String>> subOrganizationTypesResult) {
Map<String, Set<String>> subOrganizationTypesResult) {
StringBuilder csvFileContent = new StringBuilder(); StringBuilder csvFileContent = new StringBuilder();
csvFileContent.append("Entity Name, Grant Count, Entity Type\n"); csvFileContent.append("Entity Name, Grant Count, Entity Type\n");
for (SubEntity subEntity : subentities) { for (SubEntity subEntity : subentities) {
csvFileContent.append(StringEscapeUtils.escapeCsv(subEntity.getIndividualLabel())); csvFileContent.append(StringEscapeUtils.escapeCsv(subEntity
.getIndividualLabel()));
csvFileContent.append(", "); csvFileContent.append(", ");
csvFileContent.append(subEntity.getActivities().size()); csvFileContent.append(subEntity.getActivities().size());
csvFileContent.append(", "); csvFileContent.append(", ");
StringBuilder joinedTypes = new StringBuilder(); StringBuilder joinedTypes = new StringBuilder();
for (String subOrganizationType : subOrganizationTypesResult for (String subOrganizationType : subOrganizationTypesResult
.get(subEntity.getIndividualLabel())) { .get(subEntity.getIndividualLabel())) {
joinedTypes.append(subOrganizationType + "; "); joinedTypes.append(subOrganizationType + "; ");
} }
csvFileContent.append(StringEscapeUtils.escapeCsv(joinedTypes.toString())); csvFileContent.append(StringEscapeUtils.escapeCsv(joinedTypes
.toString()));
csvFileContent.append("\n"); csvFileContent.append("\n");
} }
return csvFileContent.toString(); return csvFileContent.toString();
} }
@ -352,5 +353,5 @@ public class EntityGrantCountRequestHandler implements
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }
} }

View file

@ -32,6 +32,7 @@ import edu.cornell.mannlib.vitro.webapp.visualization.entitycomparison.Organizat
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.valueobjects.Activity; import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.Activity;
import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.Entity; import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.Entity;
import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.GenericQueryMap;
import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.MapOfScienceActivity; import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.MapOfScienceActivity;
import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.SubEntity; import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.SubEntity;
import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.json.MapOfScience; import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.json.MapOfScience;
@ -261,13 +262,19 @@ public class MapOfScienceVisualizationRequestHandler implements
} }
private Map<String, String> prepareStandaloneDataErrorResponse() { private Map<String, String> prepareStandaloneDataErrorResponse() {
GenericQueryMap errorDataResponse = new GenericQueryMap();
errorDataResponse.addEntry("error", "No Publications for this Entity found in VIVO.");
Gson jsonErrorResponse = new Gson();
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,
"{\"error\" : \"No Publications for this Entity found in VIVO.\"}"); fileData.put(DataVisualizationController.FILE_CONTENT_KEY, jsonErrorResponse.toJson(errorDataResponse));
return fileData; return fileData;
} }
@ -326,7 +333,8 @@ public class MapOfScienceVisualizationRequestHandler implements
private Map<String, String> prepareStandaloneDataResponse( private Map<String, String> prepareStandaloneDataResponse(
VitroRequest vitroRequest, VitroRequest vitroRequest,
Entity entity) { Entity entity)
throws MalformedQueryParametersException {
Map<String, String> fileData = new HashMap<String, String>(); Map<String, String> fileData = new HashMap<String, String>();
@ -362,9 +370,10 @@ public class MapOfScienceVisualizationRequestHandler implements
* @param vreq * @param vreq
* @param subentities * @param subentities
* @param subOrganizationTypesResult * @param subOrganizationTypesResult
* @throws MalformedQueryParametersException
*/ */
private String writeMapOfScienceDataJSON(VitroRequest vreq, private String writeMapOfScienceDataJSON(VitroRequest vreq,
Entity subjectEntity) { Entity subjectEntity) throws MalformedQueryParametersException {
Gson json = new Gson(); Gson json = new Gson();
Set jsonContent = new HashSet(); Set jsonContent = new HashSet();

View file

@ -29,6 +29,7 @@ import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao;
import edu.cornell.mannlib.vitro.webapp.visualization.collaborationutils.CollaborationData; import edu.cornell.mannlib.vitro.webapp.visualization.collaborationutils.CollaborationData;
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.constants.VisConstants; import edu.cornell.mannlib.vitro.webapp.visualization.constants.VisConstants;
import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException;
import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.Activity; import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.Activity;
import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.Collaborator; import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.Collaborator;
import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.GenericQueryMap; import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.GenericQueryMap;
@ -251,11 +252,20 @@ public class UtilityFunctions {
return collaboratorshipNetworkURL != null ? collaboratorshipNetworkURL : "" ; return collaboratorshipNetworkURL != null ? collaboratorshipNetworkURL : "" ;
} }
public static boolean isEntityAPerson(VitroRequest vreq, String individualURI) { public static boolean isEntityAPerson(VitroRequest vreq, String individualURI)
return vreq.getWebappDaoFactory() throws MalformedQueryParametersException {
.getIndividualDao() Individual individualByURI = vreq.getWebappDaoFactory()
.getIndividualByURI(individualURI) .getIndividualDao()
.isVClass("http://xmlns.com/foaf/0.1/Person"); .getIndividualByURI(individualURI);
if (individualByURI != null) {
return individualByURI
.isVClass("http://xmlns.com/foaf/0.1/Person");
} else {
throw new MalformedQueryParametersException("Individual with " + individualURI + " not found in the system.");
}
} }