From 9971e5fa2bc2e09e2979820481fa2d0784e3e782 Mon Sep 17 00:00:00 2001 From: bkoniden Date: Wed, 12 Jan 2011 23:16:30 +0000 Subject: [PATCH] Committing the following changes 1) Handling Null pointer Exceptions for EntityPubCount, EntityGrantCount and EntitySubOrganizationTypes 2) Removing the dependency on vis_mode parameter in the server side code. The class the individual belongs to is retrieved using vitroRequest.getWebappDaoFactory().getIndividualDao().getIndividualByURI(IndividualURI).isVClass(ClassURI) 3) On the client side, the vis_mode parameter is set(from the value passed on by the requesthandler) to differentiate between personURL and SubOrganizationTemporalGraphURL on drill down. 4) Added entityComparisonErrorActivator.ftl to handle edge cases (if the resultset of the queries is NULL) --- productMods/WEB-INF/web.xml | 2 +- .../js/visualization/entitycomparison/util.js | 10 +- .../entityComparisonErrorActivator.ftl | 15 +++ .../entityComparisonStandaloneActivator.ftl | 2 +- .../EntityPublicationCountQueryRunner.java | 5 +- .../EntityPublicationCountRequestHandler.java | 93 +++++++++--------- ...EntitySubOrganizationTypesQueryRunner.java | 6 +- .../EntityGrantCountQueryRunner.java | 4 +- .../EntityGrantCountRequestHandler.java | 97 ++++++++----------- 9 files changed, 121 insertions(+), 113 deletions(-) create mode 100644 productMods/templates/freemarker/visualization/entitycomparison/entityComparisonErrorActivator.ftl diff --git a/productMods/WEB-INF/web.xml b/productMods/WEB-INF/web.xml index d1c097e6..798391eb 100644 --- a/productMods/WEB-INF/web.xml +++ b/productMods/WEB-INF/web.xml @@ -105,7 +105,7 @@ edu.cornell.mannlib.vitro.webapp.servlet.setup.PelletReasonerSetup - + diff --git a/productMods/js/visualization/entitycomparison/util.js b/productMods/js/visualization/entitycomparison/util.js index 714051fc..8eaf2842 100644 --- a/productMods/js/visualization/entitycomparison/util.js +++ b/productMods/js/visualization/entitycomparison/util.js @@ -464,7 +464,7 @@ function getTemporalVisURL(entity) { } else{ - result = subOrganizationTemporalGraphURL+ "&vis_mode=" + entity.visMode + "&" + + result = subOrganizationTemporalGraphURL + "&" + "uri=" + entity.entityURI ; } @@ -857,16 +857,16 @@ function setEntityLevel(){ function getEntityVisMode(jsonData){ $.each(jsonData, function(index, val) { - if (val.visMode == "SCHOOL" || val.visMode == "UNIVERSITY" || val.visMode == "DEPARTMENT"){ - entityLevel = "Organizations"; - } else { + if (val.visMode == "PERSON"){ entityLevel = "People"; + } else { + entityLevel = "Organizations"; } return; }); /* To provide graceful degradation set entity level to a default error message.*/ - entityElevel = "ENTITY LEVEL UNDEFINED ERROR"; + entitylevel = "ENTITY LEVEL UNDEFINED ERROR"; } function toCamelCase(string){ diff --git a/productMods/templates/freemarker/visualization/entitycomparison/entityComparisonErrorActivator.ftl b/productMods/templates/freemarker/visualization/entitycomparison/entityComparisonErrorActivator.ftl new file mode 100644 index 00000000..8ab1dbb3 --- /dev/null +++ b/productMods/templates/freemarker/visualization/entitycomparison/entityComparisonErrorActivator.ftl @@ -0,0 +1,15 @@ +<#-- $This file is distributed under the terms of the license in /doc/license.txt$ --> + +<#assign organizationURI ="${organizationURI?url}"> +<#assign organizationVivoProfileURL = "${urls.base}/individual?uri=${organizationURI}"> + +<#-- variables passed from server-side code --> + + +
+

This Organization has neither Sub-Organizations nor People. Please visit this Organization's profile page.

+
\ No newline at end of file diff --git a/productMods/templates/freemarker/visualization/entitycomparison/entityComparisonStandaloneActivator.ftl b/productMods/templates/freemarker/visualization/entitycomparison/entityComparisonStandaloneActivator.ftl index b2082105..06ef22c2 100644 --- a/productMods/templates/freemarker/visualization/entitycomparison/entityComparisonStandaloneActivator.ftl +++ b/productMods/templates/freemarker/visualization/entitycomparison/entityComparisonStandaloneActivator.ftl @@ -16,7 +16,7 @@ <#assign temporalGraphSmallIcon = '${urls.images}/visualization/temporal_vis_small_icon.jpg'> -<#assign TemporalGraphDownloadFile = '${urls.base}${dataVisualizationURLRoot}?vis=entity_comparison&uri=${organizationURI}&labelField=label&vis_mode=UNIVERSITY'> +<#assign TemporalGraphDownloadFile = '${urls.base}${dataVisualizationURLRoot}?vis=entity_comparison&uri=${organizationURI}&labelField=label'> <#-- Javascript files --> diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitycomparison/EntityPublicationCountQueryRunner.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitycomparison/EntityPublicationCountQueryRunner.java index 73e64699..9031049e 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitycomparison/EntityPublicationCountQueryRunner.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitycomparison/EntityPublicationCountQueryRunner.java @@ -183,11 +183,14 @@ public class EntityPublicationCountQueryRunner implements QueryRunner { entity.addPublications(biboDocument); } - if(subentityURLToVO.size() == 0){ + if(subentityURLToVO.size() == 0 && personURLToVO.size() != 0){ for(SubEntity person : personURLToVO.values()){ entity.addSubEntity(person); } + } else if (subentityURLToVO.size() == 0 && personURLToVO.size() == 0){ + entity = new Entity(this.entityURI, "no-label"); } + //TODO: return non-null value return entity; } diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitycomparison/EntityPublicationCountRequestHandler.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitycomparison/EntityPublicationCountRequestHandler.java index cb92068a..89c66cc2 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitycomparison/EntityPublicationCountRequestHandler.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitycomparison/EntityPublicationCountRequestHandler.java @@ -34,10 +34,6 @@ import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.Visual public class EntityPublicationCountRequestHandler implements VisualizationRequestHandler { - public static String ENTITY_VIS_MODE; - public static String SUB_ENTITY_VIS_MODE; - - @Override public ResponseValues generateStandardVisualization( VitroRequest vitroRequest, Log log, DataSource dataSource) @@ -45,28 +41,31 @@ public class EntityPublicationCountRequestHandler implements String entityURI = vitroRequest .getParameter(VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY); - - ENTITY_VIS_MODE = vitroRequest - .getParameter(VisualizationFrameworkConstants.VIS_MODE_KEY); QueryRunner queryManager = new EntityPublicationCountQueryRunner( entityURI, dataSource, log); + Entity entity = queryManager.getQueryResult(); - setVisModes(); - - QueryRunner>> queryManagerForsubOrganisationTypes = new EntitySubOrganizationTypesQueryRunner( - entityURI, dataSource, log); - - Map> subOrganizationTypesResult = queryManagerForsubOrganisationTypes - .getQueryResult(); - - return prepareStandaloneResponse(vitroRequest, entity, entityURI, - subOrganizationTypesResult); + if(entity.getEntityLabel().equals("no-label")){ + return prepareStandaloneErrorResponse(vitroRequest,entityURI); + + } else{ + + QueryRunner>> queryManagerForsubOrganisationTypes = new EntitySubOrganizationTypesQueryRunner( + entityURI, dataSource, log); + + Map> subOrganizationTypesResult = queryManagerForsubOrganisationTypes + .getQueryResult(); + + return prepareStandaloneResponse(vitroRequest, entity, entityURI, + subOrganizationTypesResult); + } + } - + @Override public Map generateDataVisualization( VitroRequest vitroRequest, Log log, DataSource dataSource) @@ -74,15 +73,12 @@ public class EntityPublicationCountRequestHandler implements String entityURI = vitroRequest .getParameter(VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY); - - ENTITY_VIS_MODE = vitroRequest - .getParameter(VisualizationFrameworkConstants.VIS_MODE_KEY); - + QueryRunner queryManager = new EntityPublicationCountQueryRunner( entityURI, dataSource, log); Entity entity = queryManager.getQueryResult(); - setVisModes(); + QueryRunner>> queryManagerForsubOrganisationTypes = new EntitySubOrganizationTypesQueryRunner( entityURI, dataSource, log); @@ -148,7 +144,7 @@ public class EntityPublicationCountRequestHandler implements String standaloneTemplate = "entityComparisonStandaloneActivator.ftl"; String jsonContent = ""; - jsonContent = writePublicationsOverTimeJSON(entity.getSubEntities(), subOrganizationTypesResult); + jsonContent = writePublicationsOverTimeJSON(vreq, entity.getSubEntities(), subOrganizationTypesResult); @@ -161,37 +157,32 @@ public class EntityPublicationCountRequestHandler implements return new TemplateResponseValues(standaloneTemplate, body); - } - - - private void setVisModes() { - - if (ENTITY_VIS_MODE.equalsIgnoreCase("DEPARTMENT")) { - SUB_ENTITY_VIS_MODE = "PERSON"; - }else if (ENTITY_VIS_MODE.equalsIgnoreCase("SCHOOL")) { - SUB_ENTITY_VIS_MODE = "DEPARTMENT"; - }else { - SUB_ENTITY_VIS_MODE = "SCHOOL"; - } } + + + private ResponseValues prepareStandaloneErrorResponse( + VitroRequest vitroRequest, String entityURI) { + + Portal portal = vitroRequest.getPortal(); + String standaloneTemplate = "entityComparisonErrorActivator.ftl"; + + Map body = new HashMap(); + body.put("portalBean", portal); + body.put("title", "Temporal Graph Visualization"); + body.put("organizationURI", entityURI); + + return new TemplateResponseValues(standaloneTemplate, body); - private void setEntityVisMode(JsonObject entityJson) { - if(entityJson.getOrganizationType().contains("Department")){ - entityJson.setVisMode("DEPARTMENT"); - }else if(entityJson.getOrganizationType().contains("School")){ - entityJson.setVisMode("SCHOOL"); - }else{ - entityJson.setVisMode(SUB_ENTITY_VIS_MODE); - } - } + /** * function to generate a json file for year <-> publication count mapping + * @param vreq * @param subentities * @param subOrganizationTypesResult */ - private String writePublicationsOverTimeJSON(Set subentities, Map> subOrganizationTypesResult) { + private String writePublicationsOverTimeJSON(VitroRequest vreq, Set subentities, Map> subOrganizationTypesResult) { Gson json = new Gson(); Set subEntitiesJson = new HashSet(); @@ -220,7 +211,15 @@ public class EntityPublicationCountRequestHandler implements entityJson.getOrganizationType().addAll(subOrganizationTypesResult.get(entityJson.getLabel())); entityJson.setEntityURI(subentity.getIndividualURI()); - setEntityVisMode(entityJson); + + boolean isPerson = vreq.getWebappDaoFactory().getIndividualDao().getIndividualByURI(subentity.getIndividualURI()).isVClass("http://xmlns.com/foaf/0.1/Person"); + + if(isPerson){ + entityJson.setVisMode("PERSON"); + } else{ + entityJson.setVisMode("ORGANIZATION"); + } + // setEntityVisMode(entityJson); subEntitiesJson.add(entityJson); } diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitycomparison/EntitySubOrganizationTypesQueryRunner.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitycomparison/EntitySubOrganizationTypesQueryRunner.java index cba3062b..eb0656ac 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitycomparison/EntitySubOrganizationTypesQueryRunner.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitycomparison/EntitySubOrganizationTypesQueryRunner.java @@ -95,7 +95,7 @@ public class EntitySubOrganizationTypesQueryRunner implements QueryRunner " + subOrganizationLabelToTypes.size()); - //System.out.println("\n\nPeople Label Types Size --> " + personLabelToTypes.size()); +// System.out.println("\n\nSub Organization Label Types Size --> " + subOrganizationLabelToTypes.size()); +// System.out.println("\n\nPeople Label Types Size --> " + personLabelToTypes.size()); return (subOrganizationLabelToTypes.size() != 0 )? subOrganizationLabelToTypes : personLabelToTypes ; } diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitygrantcount/EntityGrantCountQueryRunner.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitygrantcount/EntityGrantCountQueryRunner.java index 0cb25cbc..1f28e627 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitygrantcount/EntityGrantCountQueryRunner.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitygrantcount/EntityGrantCountQueryRunner.java @@ -173,10 +173,12 @@ public class EntityGrantCountQueryRunner implements QueryRunner { entity.addGrants(grant); } - if(subentityURLToVO.size() == 0){ + if(subentityURLToVO.size() == 0 && personURLToVO.size() != 0){ for(SubEntity person : personURLToVO.values()){ entity.addSubEntity(person); } + } else if (subentityURLToVO.size() == 0 && personURLToVO.size() == 0){ + entity = new Entity(this.entityURI, "no-label"); } return entity; diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitygrantcount/EntityGrantCountRequestHandler.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitygrantcount/EntityGrantCountRequestHandler.java index 992da4a0..1e58c20a 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitygrantcount/EntityGrantCountRequestHandler.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitygrantcount/EntityGrantCountRequestHandler.java @@ -35,10 +35,6 @@ import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.Visual public class EntityGrantCountRequestHandler implements VisualizationRequestHandler { - - public static String ENTITY_VIS_MODE; - public static String SUB_ENTITY_VIS_MODE; - @Override public ResponseValues generateStandardVisualization( @@ -47,33 +43,27 @@ public class EntityGrantCountRequestHandler implements String entityURI = vitroRequest .getParameter(VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY); - QueryRunner queryManager = new EntityGrantCountQueryRunner( entityURI, dataSource, log); - Entity entity = queryManager.getQueryResult(); - - ENTITY_VIS_MODE = vitroRequest - .getParameter(VisualizationFrameworkConstants.VIS_MODE_KEY); - setVisModes(); - -// for(SubEntity se : entity.getSubEntities()){ -// System.out.println("se key -->" + se.getIndividualLabel()); -// } - QueryRunner>> queryManagerForsubOrganisationTypes = new EntitySubOrganizationTypesQueryRunner( - entityURI, dataSource, log); + Entity entity = queryManager.getQueryResult(); + + if(entity.getEntityLabel().equals("no-label")){ + + return prepareStandaloneErrorResponse(vitroRequest,entityURI); - Map> subOrganizationTypesResult = queryManagerForsubOrganisationTypes.getQueryResult(); - -// for(Map.Entry soTR : subOrganizationTypesResult.entrySet()){ -// System.out.println("soTR key -->" + soTR.getKey()); -// } -// -// System.out.println(); - - return prepareStandaloneResponse(vitroRequest, - entity,entityURI, subOrganizationTypesResult); + } else{ + + QueryRunner>> queryManagerForsubOrganisationTypes = new EntitySubOrganizationTypesQueryRunner( + entityURI, dataSource, log); + + Map> subOrganizationTypesResult = queryManagerForsubOrganisationTypes + .getQueryResult(); + + return prepareStandaloneResponse(vitroRequest, entity, entityURI, + subOrganizationTypesResult); + } } @@ -84,11 +74,7 @@ public class EntityGrantCountRequestHandler implements String entityURI = vitroRequest .getParameter(VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY); - - ENTITY_VIS_MODE = vitroRequest - .getParameter(VisualizationFrameworkConstants.VIS_MODE_KEY); - setVisModes(); - + QueryRunner queryManager = new EntityGrantCountQueryRunner( entityURI, dataSource, log); @@ -158,7 +144,7 @@ public class EntityGrantCountRequestHandler implements String standaloneTemplate = "entityComparisonStandaloneActivator.ftl"; String jsonContent = ""; - jsonContent = writeGrantsOverTimeJSON(entity.getSubEntities(), subOrganizationTypesResult); + jsonContent = writeGrantsOverTimeJSON(vreq, entity.getSubEntities(), subOrganizationTypesResult); @@ -173,24 +159,29 @@ public class EntityGrantCountRequestHandler implements } - private void setVisModes() { + private ResponseValues prepareStandaloneErrorResponse( + VitroRequest vitroRequest, String entityURI) { - if (ENTITY_VIS_MODE.equalsIgnoreCase("DEPARTMENT")) { - SUB_ENTITY_VIS_MODE = "PERSON"; - }else if (ENTITY_VIS_MODE.equalsIgnoreCase("SCHOOL")) { - SUB_ENTITY_VIS_MODE = "DEPARTMENT"; - }else { - SUB_ENTITY_VIS_MODE = "SCHOOL"; - } - } + Portal portal = vitroRequest.getPortal(); + String standaloneTemplate = "entityComparisonErrorActivator.ftl"; + + Map body = new HashMap(); + body.put("portalBean", portal); + body.put("title", "Temporal Graph Visualization"); + body.put("organizationURI", entityURI); + + return new TemplateResponseValues(standaloneTemplate, body); + + } /** * function to generate a json file for year <-> grant count mapping + * @param vreq * @param subentities * @param subOrganizationTypesResult */ - private String writeGrantsOverTimeJSON(Set subentities, Map> subOrganizationTypesResult) { + private String writeGrantsOverTimeJSON(VitroRequest vreq, Set subentities, Map> subOrganizationTypesResult) { Gson json = new Gson(); Set subEntitiesJson = new HashSet(); @@ -219,7 +210,16 @@ public class EntityGrantCountRequestHandler implements entityJson.getOrganizationType().addAll(subOrganizationTypesResult.get(entityJson.getLabel())); entityJson.setEntityURI(subentity.getIndividualURI()); - setEntityVisMode(entityJson); + + boolean isPerson = vreq.getWebappDaoFactory().getIndividualDao().getIndividualByURI(subentity.getIndividualURI()).isVClass("http://xmlns.com/foaf/0.1/Person"); + + if(isPerson){ + entityJson.setVisMode("PERSON"); + } else{ + entityJson.setVisMode("ORGANIZATION"); + } + +// setEntityVisMode(entityJson); subEntitiesJson.add(entityJson); } @@ -228,17 +228,6 @@ public class EntityGrantCountRequestHandler implements } - private void setEntityVisMode(JsonObject entityJson) { - - if(entityJson.getOrganizationType().contains("Department")){ - entityJson.setVisMode("DEPARTMENT"); - }else if(entityJson.getOrganizationType().contains("School")){ - entityJson.setVisMode("SCHOOL"); - }else{ - entityJson.setVisMode(SUB_ENTITY_VIS_MODE); - } - - } private String getEntityGrantsPerYearCSVContent(Set subentities, Map> subOrganizationTypesResult) {