diff --git a/productMods/js/visualization/entitycomparison/gui-event-manager.js b/productMods/js/visualization/entitycomparison/gui-event-manager.js index 98b752c1..35447471 100644 --- a/productMods/js/visualization/entitycomparison/gui-event-manager.js +++ b/productMods/js/visualization/entitycomparison/gui-event-manager.js @@ -192,6 +192,17 @@ function entityCheckboxOperatedOnEventListener() { } +function renderTemporalGraphVisualization(parameters) { + + setupLoadingScreen(parameters.responseContainer); + + getTemporalGraphData(parameters.dataURL, + parameters.bodyContainer, + parameters.errorContainer, + parameters.responseContainer); + +} + /* * This method will setup the options for loading screen & then activate the * loading screen. @@ -208,14 +219,38 @@ function setupLoadingScreen(visContainerDIV) { $.blockUI.defaults.css.top = '15%'; visContainerDIV.block({ - message: '

 Loading data for ' + organizationLabel - + '

' + + '' }); + + setTimeout(function() { + $("#loading-data-container") + .html('

 Data for ' + organizationLabel + + ' is now being refreshed. The visualization will load as soon as we are done computing, ' + + 'or you can come back in a few minutes.

') + .css({'cursor': 'pointer'}); + + }, 10 * 1000); } +$("#reload-data").live('click', function() { + + options = { + responseContainer: $("div#temporal-graph-response"), + bodyContainer: $("#body"), + errorContainer: $("#error-container"), + dataURL: temporalGraphDataURL + }; + + renderTemporalGraphVisualization(options); + +}); + /* * 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. @@ -225,25 +260,34 @@ function getTemporalGraphData(temporalGraphDataURL, errorBodyDIV, visContainerDIV) { - $.ajax({ - url: temporalGraphDataURL, - dataType: "json", - timeout: 5 * 60 * 1000, - success: function (data) { - - if (data.error) { - graphBodyDIV.remove(); - errorBodyDIV.show(); - visContainerDIV.unblock(); - - } else { - graphBodyDIV.show(); - errorBodyDIV.remove(); - temporalGraphProcessor.initiateTemporalGraphRenderProcess(graphContainer, data); - visContainerDIV.unblock(); - } - } - }); + if (!isDataRequestSentViaAJAX) { + + isDataRequestSentViaAJAX = true; + + $.ajax({ + url: temporalGraphDataURL, + dataType: "json", + timeout: 5 * 60 * 1000, + success: function (data) { + + if (data.error) { + graphBodyDIV.remove(); + errorBodyDIV.show(); + visContainerDIV.unblock(); + + } else { + graphBodyDIV.show(); + errorBodyDIV.remove(); + temporalGraphProcessor.initiateTemporalGraphRenderProcess(graphContainer, data); + visContainerDIV.unblock(); + } + }, + complete: function() { + isDataRequestSentViaAJAX = false; + } + }); + + } } diff --git a/productMods/templates/freemarker/visualization/entitycomparison/entityComparisonOnGrantsStandalone.ftl b/productMods/templates/freemarker/visualization/entitycomparison/entityComparisonOnGrantsStandalone.ftl index dda437a1..9a1de299 100644 --- a/productMods/templates/freemarker/visualization/entitycomparison/entityComparisonOnGrantsStandalone.ftl +++ b/productMods/templates/freemarker/visualization/entitycomparison/entityComparisonOnGrantsStandalone.ftl @@ -19,14 +19,18 @@ This is used in util.js to print grant temporal graph links for all sub-organiza */ var subOrganizationTemporalGraphURL = "${subOrganizationGrantTemporalGraphCommonURL}"; +var temporalGraphDataURL = '${temporalGraphDataURL}'; + $(document).ready(function () { - setupLoadingScreen($("div#temporal-graph-response")); - - getTemporalGraphData('${temporalGraphDataURL}', - $("#body"), - $("#error-container"), - $("div#temporal-graph-response")); + options = { + responseContainer: $("div#temporal-graph-response"), + bodyContainer: $("#body"), + errorContainer: $("#error-container"), + dataURL: temporalGraphDataURL + }; + + renderTemporalGraphVisualization(options); }); diff --git a/productMods/templates/freemarker/visualization/entitycomparison/entityComparisonOnPublicationsStandalone.ftl b/productMods/templates/freemarker/visualization/entitycomparison/entityComparisonOnPublicationsStandalone.ftl index a68b4371..be1b6eb1 100644 --- a/productMods/templates/freemarker/visualization/entitycomparison/entityComparisonOnPublicationsStandalone.ftl +++ b/productMods/templates/freemarker/visualization/entitycomparison/entityComparisonOnPublicationsStandalone.ftl @@ -19,14 +19,18 @@ This is used in util.js to print grant temporal graph links for all sub-organiza */ var subOrganizationTemporalGraphURL = "${subOrganizationPublicationTemporalGraphCommonURL}"; +var temporalGraphDataURL = '${temporalGraphDataURL}'; + $(document).ready(function () { - setupLoadingScreen($("div#temporal-graph-response")); - - getTemporalGraphData('${temporalGraphDataURL}', - $("#body"), - $("#error-container"), - $("div#temporal-graph-response")); + options = { + responseContainer: $("div#temporal-graph-response"), + bodyContainer: $("#body"), + errorContainer: $("#error-container"), + dataURL: temporalGraphDataURL + }; + + renderTemporalGraphVisualization(options); }); diff --git a/productMods/templates/freemarker/visualization/entitycomparison/entityComparisonSetup.ftl b/productMods/templates/freemarker/visualization/entitycomparison/entityComparisonSetup.ftl index cf17959d..799d6b93 100644 --- a/productMods/templates/freemarker/visualization/entitycomparison/entityComparisonSetup.ftl +++ b/productMods/templates/freemarker/visualization/entitycomparison/entityComparisonSetup.ftl @@ -74,9 +74,12 @@ var organizationLabel = '${organizationLabel}'; var organizationVIVOProfileURL = "${organizationVivoProfileURL}"; var loadingImageLink = contextPath + "/images/visualization/ajax-loader-indicator.gif"; +var refreshPageImageLink = contextPath + "/images/visualization/refresh-green.png"; var entityCheckboxSelectorDOMClass = "${entityCheckboxSelectorDOMClass}"; +var isDataRequestSentViaAJAX = false; + var temporalGraphProcessor; /* @@ -100,4 +103,4 @@ var COMPARISON_PARAMETERS_INFO = { -${scripts.add('')} +${scripts.add('')} \ No newline at end of file diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitycomparison/cached/TemporalGrantVisualizationRequestHandler.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitycomparison/cached/TemporalGrantVisualizationRequestHandler.java index 21834bf7..5835a854 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitycomparison/cached/TemporalGrantVisualizationRequestHandler.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitycomparison/cached/TemporalGrantVisualizationRequestHandler.java @@ -57,10 +57,10 @@ public class TemporalGrantVisualizationRequestHandler implements } -// System.out.println("current models in the system are"); -// for (Map.Entry entry : ConstructedModelTracker.getAllModels().entrySet()) { -// System.out.println(entry.getKey() + " -> " + entry.getValue().size()); -// } + System.out.println("current models in the system are"); + for (Map.Entry entry : ConstructedModelTracker.getAllModels().entrySet()) { + System.out.println(entry.getKey() + " -> " + entry.getValue().size()); + } // return prepareStandaloneMarkupResponse(vitroRequest, entityURI); } diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/visutils/SelectOnModelUtilities.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/visutils/SelectOnModelUtilities.java index e982bebd..04561b97 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/visutils/SelectOnModelUtilities.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/visutils/SelectOnModelUtilities.java @@ -211,11 +211,9 @@ public class SelectOnModelUtilities { fieldLabelToOutputFieldLabel.put("document", QueryFieldLabels.DOCUMENT_URL); fieldLabelToOutputFieldLabel.put("documentLabel", QueryFieldLabels.DOCUMENT_LABEL); fieldLabelToOutputFieldLabel.put("documentPublicationDate", QueryFieldLabels.DOCUMENT_PUBLICATION_DATE); - fieldLabelToOutputFieldLabel.put("lastCachedDateTime", QueryFieldLabels.LAST_CACHED_AT_DATETIME); String whereClause = "" + " <" + subOrganization.getIndividualURI() + "> vivosocnet:hasPersonWithPublication ?document . " - + " <" + subOrganization.getIndividualURI() + "> vivosocnet:lastCachedAt ?lastCachedDateTime . " + " ?document rdfs:label ?documentLabel . " + " OPTIONAL { " + " ?document core:dateTimeValue ?dateTimeValue . " @@ -232,6 +230,12 @@ public class SelectOnModelUtilities { subOrganization, allDocumentURIToVOs); + String lastCachedAtForEntity = getLastCachedAtDateTimeForEntityInModel( + subOrganization, + subOrganizationPublicationsModel); + + subOrganization.setLastCachedAtDateTime(lastCachedAtForEntity); + } return allDocumentURIToVOs; } @@ -276,6 +280,22 @@ public class SelectOnModelUtilities { subEntity.addActivities(currentEntityPublications); } + public static String getLastCachedAtForEntity(ResultSet queryResult) { + + String lastCachedAtDateTime = null; + + while (queryResult.hasNext()) { + + QuerySolution solution = queryResult.nextSolution(); + + RDFNode lastCachedAtNode = solution.get(QueryFieldLabels.LAST_CACHED_AT_DATETIME); + if (lastCachedAtNode != null) { + lastCachedAtDateTime = lastCachedAtNode.toString(); + } + } + + return lastCachedAtDateTime; + } private static void getGrantForEntity( ResultSet queryResult, @@ -334,22 +354,26 @@ public class SelectOnModelUtilities { System.out.println("constructing grants for " + subOrganization.getIndividualLabel() + " :: " + subOrganization.getIndividualURI()); + long before = System.currentTimeMillis(); + Model subOrganizationGrantsModel = ModelConstructorUtilities .getOrConstructModel( subOrganization.getIndividualURI(), OrganizationToGrantsForSubOrganizationsModelConstructor.MODEL_TYPE, dataset); + System.out.println("\t construct -> " + (System.currentTimeMillis() - before)); + + before = System.currentTimeMillis(); + Map fieldLabelToOutputFieldLabel = new HashMap(); fieldLabelToOutputFieldLabel.put("grant", QueryFieldLabels.GRANT_URL); fieldLabelToOutputFieldLabel.put("grantLabel", QueryFieldLabels.GRANT_LABEL); fieldLabelToOutputFieldLabel.put("grantStartDate", QueryFieldLabels.GRANT_START_DATE); fieldLabelToOutputFieldLabel.put("roleStartDate", QueryFieldLabels.ROLE_START_DATE); - fieldLabelToOutputFieldLabel.put("lastCachedAtDateTime", QueryFieldLabels.LAST_CACHED_AT_DATETIME); String whereClause = "" + "{" - + " <" + subOrganization.getIndividualURI() + "> vivosocnet:lastCachedAt ?lastCachedAtDateTime . " + " <" + subOrganization.getIndividualURI() + "> vivosocnet:hasInvestigatorWithGrant ?grant . " + " ?grant rdfs:label ?grantLabel . " + " OPTIONAL { " @@ -359,7 +383,6 @@ public class SelectOnModelUtilities { + "}" + "UNION" + "{" - + " <" + subOrganization.getIndividualURI() + "> vivosocnet:lastCachedAt ?lastCachedAtDateTime . " + " <" + subOrganization.getIndividualURI() + "> vivosocnet:hasPIWithGrant ?grant . " + " ?grant rdfs:label ?grantLabel . " + " OPTIONAL { " @@ -369,7 +392,6 @@ public class SelectOnModelUtilities { + "}" + "UNION" + "{" - + " <" + subOrganization.getIndividualURI() + "> vivosocnet:lastCachedAt ?lastCachedAtDateTime . " + " <" + subOrganization.getIndividualURI() + "> vivosocnet:hascoPIWithGrant ?grant . " + " ?grant rdfs:label ?grantLabel . " + " OPTIONAL { " @@ -385,19 +407,45 @@ public class SelectOnModelUtilities { "", subOrganizationGrantsModel); -// subOrganization.addActivities(getGrantForEntity( -// subOrganizationGrantsQuery.getQueryResult(), -// allGrantURIToVO)); - /* * This method side-affects the subOrganization entity & the map containing all the grants for * the subject organization. * */ getGrantForEntity(subOrganizationGrantsQuery.getQueryResult(), subOrganization, allGrantURIToVO); + String lastCachedAtForEntity = getLastCachedAtDateTimeForEntityInModel( + subOrganization, + subOrganizationGrantsModel); + + subOrganization.setLastCachedAtDateTime(lastCachedAtForEntity); + + System.out.println("\t select -> " + (System.currentTimeMillis() - before)); } return allGrantURIToVO; } + + private static String getLastCachedAtDateTimeForEntityInModel( + SubEntity entity, Model subOrganizationGrantsModel) + throws MalformedQueryParametersException { + + Map fieldLabelToOutputFieldLabel = new HashMap(); + fieldLabelToOutputFieldLabel.put("lastCachedAtDateTime", QueryFieldLabels.LAST_CACHED_AT_DATETIME); + + String whereClause = "" + + "{" + + " <" + entity.getIndividualURI() + "> vivosocnet:lastCachedAt ?lastCachedAtDateTime . " + + "}"; + + QueryRunner entityLastCachedAtQuery = + new GenericQueryRunnerOnModel(fieldLabelToOutputFieldLabel, + "", + whereClause, + "", + subOrganizationGrantsModel); + + String lastCachedAtForEntity = getLastCachedAtForEntity(entityLastCachedAtQuery.getQueryResult()); + return lastCachedAtForEntity; + } public static Map getGrantsForAssociatedPeople( Dataset dataset, Collection people) @@ -417,11 +465,9 @@ public class SelectOnModelUtilities { fieldLabelToOutputFieldLabel.put("grantLabel", QueryFieldLabels.GRANT_LABEL); fieldLabelToOutputFieldLabel.put("grantStartDate", QueryFieldLabels.GRANT_START_DATE); fieldLabelToOutputFieldLabel.put("roleStartDate", QueryFieldLabels.ROLE_START_DATE); - fieldLabelToOutputFieldLabel.put("lastCachedAtDateTime", QueryFieldLabels.LAST_CACHED_AT_DATETIME); String whereClause = "" + "{" - + " <" + person.getIndividualURI() + "> vivosocnet:lastCachedAt ?lastCachedAtDateTime . " + " <" + person.getIndividualURI() + "> vivosocnet:hasGrantAsAnInvestigator ?grant . " + " ?grant rdfs:label ?grantLabel . " + " OPTIONAL { " @@ -431,7 +477,6 @@ public class SelectOnModelUtilities { + "}" + "UNION" + "{" - + " <" + person.getIndividualURI() + "> vivosocnet:lastCachedAt ?lastCachedAtDateTime . " + " <" + person.getIndividualURI() + "> vivosocnet:hasGrantAsPI ?grant . " + " ?grant rdfs:label ?grantLabel . " + " OPTIONAL { " @@ -441,7 +486,6 @@ public class SelectOnModelUtilities { + "}" + "UNION" + "{" - + " <" + person.getIndividualURI() + "> vivosocnet:lastCachedAt ?lastCachedAtDateTime . " + " <" + person.getIndividualURI() + "> vivosocnet:hasGrantAsCoPI ?grant . " + " ?grant rdfs:label ?grantLabel . " + " OPTIONAL { " @@ -458,6 +502,14 @@ public class SelectOnModelUtilities { peopleGrantsModel); getGrantForEntity(personGrantsQuery.getQueryResult(), person, allGrantURIToVOs); + + String lastCachedAtForEntity = getLastCachedAtDateTimeForEntityInModel( + person, + peopleGrantsModel); + + person.setLastCachedAtDateTime(lastCachedAtForEntity); + + } return allGrantURIToVOs; } @@ -481,10 +533,8 @@ public class SelectOnModelUtilities { fieldLabelToOutputFieldLabel.put("document", QueryFieldLabels.DOCUMENT_URL); fieldLabelToOutputFieldLabel.put("documentLabel", QueryFieldLabels.DOCUMENT_LABEL); fieldLabelToOutputFieldLabel.put("documentPublicationDate", QueryFieldLabels.DOCUMENT_PUBLICATION_DATE); - fieldLabelToOutputFieldLabel.put("lastCachedAtDateTime", QueryFieldLabels.LAST_CACHED_AT_DATETIME); String whereClause = "" - + " <" + person.getIndividualURI() + "> vivosocnet:lastCachedAt ?lastCachedAtDateTime . " + " <" + person.getIndividualURI() + "> vivosocnet:hasPublication ?document . " + " ?document rdfs:label ?documentLabel . " + " OPTIONAL { " @@ -502,6 +552,12 @@ public class SelectOnModelUtilities { person, allDocumentURIToVOs); + String lastCachedAtForEntity = getLastCachedAtDateTimeForEntityInModel( + person, + peoplePublicationsModel); + + person.setLastCachedAtDateTime(lastCachedAtForEntity); + } return allDocumentURIToVOs; }