From 1c87006467b3fb17623adeeb9b8e1cb3f4f1b373 Mon Sep 17 00:00:00 2001 From: Giancarlo Panichi Date: Fri, 12 Dec 2014 17:31:49 +0000 Subject: [PATCH] Fixed Tabular Resource Open in multi scope git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-gwt-service@102027 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../gwtservice/server/SessionConstants.java | 25 +- .../td/gwtservice/server/SessionUtil.java | 1079 ++++++++++++----- .../gwtservice/server/TDGWTServiceImpl.java | 5 +- 3 files changed, 798 insertions(+), 311 deletions(-) diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/server/SessionConstants.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/SessionConstants.java index f162720..f3dd15f 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/server/SessionConstants.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/SessionConstants.java @@ -7,17 +7,19 @@ package org.gcube.portlets.user.td.gwtservice.server; * */ public class SessionConstants { - public static final String CURRENT_TR_ID = "CURRENT_TR_ID"; - public static final String CURRENT_TABULAR_RESOURCE = "CURRENT_TABULAR_RESOURCE"; - public static final String CURRENT_TABULAR_RESOURCES_OPEN = "CURRENT_TABULAR_RESOURCES_OPEN"; - + public static final String SCOPE_TO_CURRENT_TRID_MAP = "SCOPE_TO_CURRENT_TRID_MAP"; + public static final String SCOPE_TO_CURRENT_TABULAR_RESOURCE_MAP = "SCOPE_TO_CURRENT_TABULAR_RESOURCE_MAP"; + public static final String SCOPE_TO_CURRENT_TABULAR_RESOURCES_OPEN_MAP = "SCOPE_TO_CURRENT_TABULAR_RESOURCES_OPEN_MAP"; + + public static final String SCOPE_TO_OPERATIONS_TASKS_STARTED_MAP="SCOPE_TO_OPERATIONS_TASKS_STARTED_MAP"; + public static final String SCOPE_TO_OPERATIONS_TASKS_IN_BACKGROUND_MAP="SCOPE_TO_OPERATIONS_TASKS_IN_BACKGROUND_MAP"; + public static final String SCOPE_TO_OPERATIONS_TASKS_ABORTED_MAP="SCOPE_TO_OPERATIONS_TASKS_ABORTED_MAP"; + public static final String SCOPE_TO_OPERATIONS_TASKS_HIDDEN_MAP="SCOPE_TO_OPERATIONS_TASKS_HIDDEN_MAP"; + + public static final String SCOPE_TO_TABULAR_RESOURCE_LIST_MAP = "SCOPE_TO_TABULAR_RESOURCE_LIST_MAP"; + public static final String TDOPEN_SESSION = "TDOPEN_SESSION"; - public static final String TABULAR_RESOURCE_LIST = "TABULAR_RESOURCE_LIST"; - - public static final String OPERATIONS_TASKS_STARTED="OPERATION_TASKS_STARTED"; - public static final String OPERATIONS_TASKS_IN_BACKGROUND="OPERATION_TASKS_IN_BACKGROUND"; - public static final String OPERATIONS_TASKS_ABORTED="OPERATION_TASKS_ABORTED"; - public static final String OPERATIONS_TASKS_HIDDEN="OPERATION_TASKS_HIDDEN"; + public static final String FILE_UPLOAD_MONITOR = "FILE_UPLOAD_MONITOR"; public static final String TR_TASK_MANAGER = "TR_TASK_MANAGER"; @@ -106,4 +108,7 @@ public class SessionConstants { public static final String CHART_TOPRATING_SESSION = "CHART_TOPRATING_SESSION"; public static final String RESOURCE_SAVE_SESSION = "RESOURCE_SAVE_SESSION"; + + + } diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/server/SessionUtil.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/SessionUtil.java index d41090d..6b9f8a3 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/server/SessionUtil.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/SessionUtil.java @@ -87,14 +87,13 @@ public class SessionUtil { // Remove comment for Test /* - username = Constants.DEFAULT_USER; - String scope = Constants.DEFAULT_SCOPE; - - httpSession.setAttribute(ScopeHelper.USERNAME_ATTRIBUTE, username); - session = SessionManager.getInstance().getASLSession( - httpSession.getId(), username); - session.setScope(scope); - */ + * username = Constants.DEFAULT_USER; String scope = + * Constants.DEFAULT_SCOPE; + * + * httpSession.setAttribute(ScopeHelper.USERNAME_ATTRIBUTE, + * username); session = SessionManager.getInstance().getASLSession( + * httpSession.getId(), username); session.setScope(scope); + */ } else { session = SessionManager.getInstance().getASLSession( httpSession.getId(), username); @@ -108,6 +107,427 @@ public class SessionUtil { } + /** + * Set in session the Tabular Resource List retrieved from service only for + * caching + * + * @param httpSession + * @param trs + * @throws TDGWTSessionExpiredException + */ + public static void setTabularResources(HttpSession httpSession, + List trs) throws TDGWTSessionExpiredException { + + ASLSession aslSession = getAslSession(httpSession); + ScopeProvider.instance.set(aslSession.getScope()); + + @SuppressWarnings("unchecked") + HashMap> scopeToTabularResourcesMap = (HashMap>) httpSession + .getAttribute(SessionConstants.SCOPE_TO_TABULAR_RESOURCE_LIST_MAP); + + if (scopeToTabularResourcesMap == null) { + scopeToTabularResourcesMap = new HashMap>(); + scopeToTabularResourcesMap.put(aslSession.getScope(), trs); + } else { + scopeToTabularResourcesMap.put(aslSession.getScope(), trs); + httpSession + .removeAttribute(SessionConstants.SCOPE_TO_TABULAR_RESOURCE_LIST_MAP); + + } + httpSession.setAttribute( + SessionConstants.SCOPE_TO_TABULAR_RESOURCE_LIST_MAP, + scopeToTabularResourcesMap); + + } + + /** + * Set current TRId in current scope + * + * @param httpSession + * @return + * @throws TDGWTSessionExpiredException + */ + public static TRId getTRId(HttpSession httpSession) + throws TDGWTSessionExpiredException { + ASLSession aslSession = getAslSession(httpSession); + ScopeProvider.instance.set(aslSession.getScope()); + + @SuppressWarnings("unchecked") + HashMap scopeToTRIdMap = (HashMap) httpSession + .getAttribute(SessionConstants.SCOPE_TO_CURRENT_TRID_MAP); + + TRId id = null; + if (scopeToTRIdMap == null) { + logger.error("TR_ID was not acquired"); + } else { + id = scopeToTRIdMap.get(aslSession.getScope()); + if (id == null) { + logger.error("TR_ID was not acquired"); + } + } + return id; + } + + /** + * + * @param httpSession + * @param trId + * @throws TDGWTSessionExpiredException + */ + public static void setTRId(HttpSession httpSession, TRId trId) + throws TDGWTSessionExpiredException { + ASLSession aslSession = getAslSession(httpSession); + ScopeProvider.instance.set(aslSession.getScope()); + + @SuppressWarnings("unchecked") + HashMap scopeToTRIdMap = (HashMap) httpSession + .getAttribute(SessionConstants.SCOPE_TO_CURRENT_TRID_MAP); + + if (scopeToTRIdMap == null) { + scopeToTRIdMap = new HashMap(); + scopeToTRIdMap.put(aslSession.getScope(), trId); + } else { + scopeToTRIdMap.put(aslSession.getScope(), trId); + httpSession + .removeAttribute(SessionConstants.SCOPE_TO_CURRENT_TRID_MAP); + } + httpSession.setAttribute(SessionConstants.SCOPE_TO_CURRENT_TRID_MAP, + scopeToTRIdMap); + return; + + } + + /** + * + * @param httpSession + * @return + * @throws TDGWTSessionExpiredException + */ + public static TabResource getTabResource(HttpSession httpSession) + throws TDGWTSessionExpiredException { + ASLSession aslSession = getAslSession(httpSession); + ScopeProvider.instance.set(aslSession.getScope()); + + @SuppressWarnings("unchecked") + HashMap scopeToTabResourceMap = (HashMap) httpSession + .getAttribute(SessionConstants.SCOPE_TO_CURRENT_TABULAR_RESOURCE_MAP); + + TabResource tabResource = null; + if (scopeToTabResourceMap == null) { + logger.error("CURRENT_TABULAR_RESOURCE was not acquired"); + } else { + tabResource = scopeToTabResourceMap.get(aslSession.getScope()); + if (tabResource == null) { + logger.error("CURRENT_TABULAR_RESOURCE was not acquired"); + } + } + return tabResource; + + } + + /** + * + * @param httpSession + * @param tabResource + * @throws TDGWTSessionExpiredException + */ + public static void setTabResource(HttpSession httpSession, + TabResource tabResource) throws TDGWTSessionExpiredException { + + ASLSession aslSession = getAslSession(httpSession); + ScopeProvider.instance.set(aslSession.getScope()); + + @SuppressWarnings("unchecked") + HashMap scopeToTabResourceMap = (HashMap) httpSession + .getAttribute(SessionConstants.SCOPE_TO_CURRENT_TABULAR_RESOURCE_MAP); + + if (scopeToTabResourceMap == null) { + scopeToTabResourceMap = new HashMap(); + scopeToTabResourceMap.put(aslSession.getScope(), tabResource); + } else { + scopeToTabResourceMap.put(aslSession.getScope(), tabResource); + httpSession + .removeAttribute(SessionConstants.SCOPE_TO_CURRENT_TABULAR_RESOURCE_MAP); + } + httpSession.setAttribute( + SessionConstants.SCOPE_TO_CURRENT_TABULAR_RESOURCE_MAP, + scopeToTabResourceMap); + return; + + } + + // + /** + * + * @param httpSession + * @return + * @throws TDGWTSessionExpiredException + */ + public static ArrayList getCurrentTabularResourcesOpen( + HttpSession httpSession) throws TDGWTSessionExpiredException { + ASLSession aslSession = getAslSession(httpSession); + ScopeProvider.instance.set(aslSession.getScope()); + + @SuppressWarnings("unchecked") + HashMap> scopeToTabResourceOpenMap = (HashMap>) httpSession + .getAttribute(SessionConstants.SCOPE_TO_CURRENT_TABULAR_RESOURCES_OPEN_MAP); + + ArrayList currentTROpen = null; + if (scopeToTabResourceOpenMap == null) { + logger.error("CURRENT_TABULAR_RESOURCES_OPEN was not acquired"); + } else { + currentTROpen = scopeToTabResourceOpenMap + .get(aslSession.getScope()); + if (currentTROpen == null) { + logger.error("CURRENT_TABULAR_RESOURCES_OPEN was not acquired"); + } + } + return currentTROpen; + } + + /** + * + * @param httpSession + * @param currentTROpen + * @throws TDGWTSessionExpiredException + */ + public static void setCurrentTabularResourcesOpen(HttpSession httpSession, + ArrayList currentTROpen) + throws TDGWTSessionExpiredException { + ASLSession aslSession = getAslSession(httpSession); + ScopeProvider.instance.set(aslSession.getScope()); + + @SuppressWarnings("unchecked") + HashMap> scopeToTabResourceOpenMap = (HashMap>) httpSession + .getAttribute(SessionConstants.SCOPE_TO_CURRENT_TABULAR_RESOURCES_OPEN_MAP); + + if (scopeToTabResourceOpenMap == null) { + scopeToTabResourceOpenMap = new HashMap>(); + scopeToTabResourceOpenMap.put(aslSession.getScope(), currentTROpen); + } else { + scopeToTabResourceOpenMap.put(aslSession.getScope(), currentTROpen); + httpSession + .removeAttribute(SessionConstants.SCOPE_TO_CURRENT_TABULAR_RESOURCES_OPEN_MAP); + } + httpSession.setAttribute( + SessionConstants.SCOPE_TO_CURRENT_TABULAR_RESOURCES_OPEN_MAP, + scopeToTabResourceOpenMap); + return; + } + + /** + * + * @param httpSession + * @param tabResource + * @throws TDGWTSessionExpiredException + */ + public static void addToCurrentTabularResourcesOpen( + HttpSession httpSession, TabResource tabResource) + throws TDGWTSessionExpiredException { + + ASLSession aslSession = getAslSession(httpSession); + ScopeProvider.instance.set(aslSession.getScope()); + + if (tabResource.getTrId() != null + && tabResource.getTrId().getId() != null + & !tabResource.getTrId().getId().isEmpty()) { + + @SuppressWarnings("unchecked") + HashMap> scopeToTabResourceOpenMap = (HashMap>) httpSession + .getAttribute(SessionConstants.SCOPE_TO_CURRENT_TABULAR_RESOURCES_OPEN_MAP); + + if (scopeToTabResourceOpenMap == null) { + scopeToTabResourceOpenMap = new HashMap>(); + ArrayList openList = new ArrayList(); + openList.add(tabResource); + scopeToTabResourceOpenMap.put(aslSession.getScope(), openList); + } else { + ArrayList openList = scopeToTabResourceOpenMap + .get(aslSession.getScope()); + + if (openList != null) { + for (TabResource tr : openList) { + if (tr.getTrId().getId() + .compareTo(tabResource.getTrId().getId()) == 0) { + openList.remove(tr); + break; + } + } + openList.add(tabResource); + } else { + openList = new ArrayList(); + openList.add(tabResource); + } + scopeToTabResourceOpenMap.put(aslSession.getScope(), openList); + httpSession + .removeAttribute(SessionConstants.SCOPE_TO_CURRENT_TABULAR_RESOURCES_OPEN_MAP); + } + httpSession + .setAttribute( + SessionConstants.SCOPE_TO_CURRENT_TABULAR_RESOURCES_OPEN_MAP, + scopeToTabResourceOpenMap); + } else { + logger.error("Tabular Resource has invalid id"); + } + + } + + /** + * + * @param httpSession + * @param trId + * @throws TDGWTSessionExpiredException + */ + public static void removeFromCurrentTabularResourcesOpen( + HttpSession httpSession, TRId trId) + throws TDGWTSessionExpiredException { + ASLSession aslSession = getAslSession(httpSession); + ScopeProvider.instance.set(aslSession.getScope()); + + if (trId != null && trId.getId() != null & !trId.getId().isEmpty()) { + + @SuppressWarnings("unchecked") + HashMap> scopeToTabResourceOpenMap = (HashMap>) httpSession + .getAttribute(SessionConstants.SCOPE_TO_CURRENT_TABULAR_RESOURCES_OPEN_MAP); + + if (scopeToTabResourceOpenMap == null) { + scopeToTabResourceOpenMap = new HashMap>(); + ArrayList openList = new ArrayList(); + scopeToTabResourceOpenMap.put(aslSession.getScope(), openList); + logger.debug("No open tr list in session"); + } else { + ArrayList openList = scopeToTabResourceOpenMap + .get(aslSession.getScope()); + if (openList != null) { + for (TabResource tr : openList) { + if (tr.getTrId().getId().compareTo(trId.getId()) == 0) { + openList.remove(tr); + break; + } + } + + } else { + openList = new ArrayList(); + } + scopeToTabResourceOpenMap.put(aslSession.getScope(), openList); + httpSession + .removeAttribute(SessionConstants.SCOPE_TO_CURRENT_TABULAR_RESOURCES_OPEN_MAP); + } + httpSession + .setAttribute( + SessionConstants.SCOPE_TO_CURRENT_TABULAR_RESOURCES_OPEN_MAP, + scopeToTabResourceOpenMap); + } else { + logger.error("TRId request has invalid id"); + } + } + + /** + * + * @param httpSession + * @throws TDGWTSessionExpiredException + */ + public static void removeAllFromCurrentTabularResourcesOpen( + HttpSession httpSession) throws TDGWTSessionExpiredException { + ASLSession aslSession = getAslSession(httpSession); + ScopeProvider.instance.set(aslSession.getScope()); + + @SuppressWarnings("unchecked") + HashMap> scopeToTabResourceOpenMap = (HashMap>) httpSession + .getAttribute(SessionConstants.SCOPE_TO_CURRENT_TABULAR_RESOURCES_OPEN_MAP); + + if (scopeToTabResourceOpenMap == null) { + logger.debug("No open tr list in session"); + } else { + scopeToTabResourceOpenMap.remove(aslSession.getScope()); + httpSession + .removeAttribute(SessionConstants.SCOPE_TO_CURRENT_TABULAR_RESOURCES_OPEN_MAP); + httpSession + .setAttribute( + SessionConstants.SCOPE_TO_CURRENT_TABULAR_RESOURCES_OPEN_MAP, + scopeToTabResourceOpenMap); + } + + } + + /** + * + * @param httpSession + * @return + * @throws TDGWTSessionExpiredException + */ + public static TabResource getFirstFromCurrentTabularResourcesOpen( + HttpSession httpSession) throws TDGWTSessionExpiredException { + ASLSession aslSession = getAslSession(httpSession); + ScopeProvider.instance.set(aslSession.getScope()); + + @SuppressWarnings("unchecked") + HashMap> scopeToTabResourceOpenMap = (HashMap>) httpSession + .getAttribute(SessionConstants.SCOPE_TO_CURRENT_TABULAR_RESOURCES_OPEN_MAP); + + if (scopeToTabResourceOpenMap == null) { + logger.info("No open tr in session"); + return null; + } else { + ArrayList openList = scopeToTabResourceOpenMap + .get(aslSession.getScope()); + if (openList == null || openList.isEmpty()) { + logger.info("No open tr in session"); + return null; + } else { + return openList.get(0); + } + } + + } + + /** + * + * @param httpSession + * @param trId + * @return + * @throws TDGWTSessionExpiredException + */ + public static TabResource getFromCurrentTabularResourcesOpen( + HttpSession httpSession, TRId trId) + throws TDGWTSessionExpiredException { + ASLSession aslSession = getAslSession(httpSession); + ScopeProvider.instance.set(aslSession.getScope()); + + @SuppressWarnings("unchecked") + HashMap> scopeToTabResourceOpenMap = (HashMap>) httpSession + .getAttribute(SessionConstants.SCOPE_TO_CURRENT_TABULAR_RESOURCES_OPEN_MAP); + + if (scopeToTabResourceOpenMap == null) { + logger.info("No open tr in session"); + return null; + } else { + ArrayList openList = scopeToTabResourceOpenMap + .get(aslSession.getScope()); + if (openList == null || openList.isEmpty()) { + logger.info("No open tr in session"); + } else { + for (TabResource tabResource : openList) { + if (tabResource != null + && tabResource.getTrId() != null + && tabResource.getTrId().getId() + .compareTo(trId.getId()) == 0) { + return tabResource; + } + } + } + } + return null; + + } + + // + /** + * + * @param httpSession + * @param s + * @throws TDGWTSessionExpiredException + */ public static void setTDOpenSession(HttpSession httpSession, TDOpenSession s) throws TDGWTSessionExpiredException { @@ -129,179 +549,6 @@ public class SessionUtil { return; } - public static void setTabularResources(HttpSession httpSession, - List trs) throws TDGWTSessionExpiredException { - - @SuppressWarnings("unchecked") - List tabularResources = (List) httpSession - .getAttribute(SessionConstants.TABULAR_RESOURCE_LIST); - if (tabularResources != null) - httpSession.removeAttribute(SessionConstants.TABULAR_RESOURCE_LIST); - httpSession.setAttribute(SessionConstants.TABULAR_RESOURCE_LIST, trs); - ASLSession aslSession = getAslSession(httpSession); - ScopeProvider.instance.set(aslSession.getScope().toString()); - } - - public static TRId getTRId(HttpSession httpSession) { - TRId id = (TRId) httpSession - .getAttribute(SessionConstants.CURRENT_TR_ID); - if (id == null) { - logger.error("TR_ID was not acquired"); - } - return id; - } - - public static void setTRId(HttpSession httpSession, TRId trId) - throws TDGWTSessionExpiredException { - TRId id = (TRId) httpSession - .getAttribute(SessionConstants.CURRENT_TR_ID); - if (id != null) - httpSession.removeAttribute(SessionConstants.CURRENT_TR_ID); - httpSession.setAttribute(SessionConstants.CURRENT_TR_ID, trId); - ASLSession aslSession = getAslSession(httpSession); - ScopeProvider.instance.set(aslSession.getScope().toString()); - } - - public static TabResource getTabResource(HttpSession httpSession) { - TabResource tabResource = (TabResource) httpSession - .getAttribute(SessionConstants.CURRENT_TABULAR_RESOURCE); - if (tabResource == null) { - logger.error("CURRENT_TABULAR_RESOURCE was not acquired"); - } - return tabResource; - } - - public static void setTabResource(HttpSession httpSession, - TabResource tabResource) throws TDGWTSessionExpiredException { - TabResource t = (TabResource) httpSession - .getAttribute(SessionConstants.CURRENT_TABULAR_RESOURCE); - if (t != null) - httpSession - .removeAttribute(SessionConstants.CURRENT_TABULAR_RESOURCE); - httpSession.setAttribute(SessionConstants.CURRENT_TABULAR_RESOURCE, - tabResource); - ASLSession aslSession = getAslSession(httpSession); - ScopeProvider.instance.set(aslSession.getScope().toString()); - } - - // - public static ArrayList getCurrentTabularResourcesOpen( - HttpSession httpSession) { - @SuppressWarnings("unchecked") - ArrayList currentTROpen = (ArrayList) httpSession - .getAttribute(SessionConstants.CURRENT_TABULAR_RESOURCES_OPEN); - if (currentTROpen == null) { - logger.error("CURRENT_TABULAR_RESOURCES_OPEN was not acquired"); - } - return currentTROpen; - } - - public static void setCurrentTabularResourcesOpen(HttpSession httpSession, - ArrayList currentTROpen) { - @SuppressWarnings("unchecked") - ArrayList t = (ArrayList) httpSession - .getAttribute(SessionConstants.CURRENT_TABULAR_RESOURCES_OPEN); - if (t != null) - httpSession - .removeAttribute(SessionConstants.CURRENT_TABULAR_RESOURCES_OPEN); - httpSession.setAttribute( - SessionConstants.CURRENT_TABULAR_RESOURCES_OPEN, currentTROpen); - - } - - public static void addToCurrentTabularResourcesOpen( - HttpSession httpSession, TabResource tabResource) { - if (tabResource.getTrId() != null - && tabResource.getTrId().getId() != null - & !tabResource.getTrId().getId().isEmpty()) { - - @SuppressWarnings("unchecked") - ArrayList t = (ArrayList) httpSession - .getAttribute(SessionConstants.CURRENT_TABULAR_RESOURCES_OPEN); - if (t != null) { - for (TabResource tr : t) { - if (tr.getTrId().getId() - .compareTo(tabResource.getTrId().getId()) == 0) { - t.remove(tr); - break; - } - } - t.add(tabResource); - httpSession - .removeAttribute(SessionConstants.CURRENT_TABULAR_RESOURCES_OPEN); - } else { - t = new ArrayList(); - t.add(tabResource); - } - httpSession.setAttribute( - SessionConstants.CURRENT_TABULAR_RESOURCES_OPEN, t); - } - } - - public static void removeFromCurrentTabularResourcesOpen( - HttpSession httpSession, TRId trId) { - if (trId != null && trId.getId() != null & !trId.getId().isEmpty()) { - @SuppressWarnings("unchecked") - ArrayList t = (ArrayList) httpSession - .getAttribute(SessionConstants.CURRENT_TABULAR_RESOURCES_OPEN); - if (t != null && !t.isEmpty()) { - for (TabResource tabR : t) { - if (tabR.getTrId().getId().compareTo(trId.getId()) == 0) { - - t.remove(tabR); - httpSession - .removeAttribute(SessionConstants.CURRENT_TABULAR_RESOURCES_OPEN); - httpSession - .setAttribute( - SessionConstants.CURRENT_TABULAR_RESOURCES_OPEN, - t); - return; - } - } - } - } - } - - public static void removeAllFromCurrentTabularResourcesOpen( - HttpSession httpSession) { - httpSession - .removeAttribute(SessionConstants.CURRENT_TABULAR_RESOURCES_OPEN); - } - - public static TabResource getFirstFromCurrentTabularResourcesOpen( - HttpSession httpSession) { - @SuppressWarnings("unchecked") - ArrayList currentTROpen = (ArrayList) httpSession - .getAttribute(SessionConstants.CURRENT_TABULAR_RESOURCES_OPEN); - if (currentTROpen == null || currentTROpen.isEmpty()) { - logger.error("No CURRENT_TABULAR_RESOURCES_OPEN"); - return null; - } else { - return currentTROpen.get(0); - } - } - - public static TabResource getFromCurrentTabularResourcesOpen( - HttpSession httpSession, TRId trId) { - @SuppressWarnings("unchecked") - ArrayList currentTROpen = (ArrayList) httpSession - .getAttribute(SessionConstants.CURRENT_TABULAR_RESOURCES_OPEN); - if (currentTROpen == null || currentTROpen.isEmpty()) { - logger.error("No CURRENT_TABULAR_RESOURCES_OPEN"); - } else { - for (TabResource tabResource : currentTROpen) { - if (tabResource != null - && tabResource.getTrId() != null - && tabResource.getTrId().getId() - .compareTo(trId.getId()) == 0) { - return tabResource; - } - } - - } - return null; - } - // public static TabResource getSDMXImportTabResource(HttpSession httpSession) { TabResource tabResource = (TabResource) httpSession @@ -1574,34 +1821,61 @@ public class SessionUtil { } - // - + /** + * Retrieve task started + * + * @param httpSession + * @param taskId + * @return + * @throws TDGWTSessionExpiredException + */ public static TaskWrapper getStartedTask(HttpSession httpSession, - String taskId) { + String taskId) throws TDGWTSessionExpiredException { + ASLSession aslSession = getAslSession(httpSession); + ScopeProvider.instance.set(aslSession.getScope()); + TaskWrapper taskWrapper = null; if (taskId == null || taskId.isEmpty()) { logger.error("TaskId is not valid: " + taskId); - return taskWrapper; - } + } else { + @SuppressWarnings("unchecked") + HashMap> scopeToTasksStartedMap = (HashMap>) httpSession + .getAttribute(SessionConstants.SCOPE_TO_OPERATIONS_TASKS_STARTED_MAP); - @SuppressWarnings("unchecked") - HashMap tasksStarted = (HashMap) httpSession - .getAttribute(SessionConstants.OPERATIONS_TASKS_STARTED); - if (tasksStarted == null) { - logger.error("Task with id=" + taskId + " was not acquired"); - return taskWrapper; - } + if (scopeToTasksStartedMap == null) { + logger.debug("Task with id=" + taskId + " was not acquired"); + } else { + HashMap tasksStarted = scopeToTasksStartedMap + .get(aslSession.getScope()); + if (tasksStarted == null) { + logger.debug("Task with id=" + taskId + " was not acquired"); + } else { + taskWrapper = tasksStarted.get(taskId); + if (taskWrapper == null) { + logger.debug("Task with id=" + taskId + + " was not acquired"); + } + } + } - taskWrapper = tasksStarted.get(taskId); - if (taskWrapper == null) { - logger.error("Task with id=" + taskId + " was not acquired"); } return taskWrapper; - }; + } + + /** + * Remove Task Started + * + * @param httpSession + * @param taskWrapper + * @throws TDGWTSessionExpiredException + */ public static void removeStartedTask(HttpSession httpSession, - TaskWrapper taskWrapper) { + TaskWrapper taskWrapper) throws TDGWTSessionExpiredException { + ASLSession aslSession = getAslSession(httpSession); + ScopeProvider.instance.set(aslSession.getScope()); + if (taskWrapper == null) { logger.error("TaskWrapper is null"); return; @@ -1615,23 +1889,43 @@ public class SessionUtil { } @SuppressWarnings("unchecked") - HashMap tasksStarted = ((HashMap) httpSession - .getAttribute(SessionConstants.OPERATIONS_TASKS_STARTED)); - if (tasksStarted == null) { - tasksStarted = new HashMap(); + HashMap> scopeToTasksStartedMap = (HashMap>) httpSession + .getAttribute(SessionConstants.SCOPE_TO_OPERATIONS_TASKS_STARTED_MAP); + + if (scopeToTasksStartedMap == null) { + logger.debug("TaskWrapper was not acquired: " + taskWrapper); } else { - httpSession - .removeAttribute(SessionConstants.OPERATIONS_TASKS_STARTED); + HashMap tasksStarted = scopeToTasksStartedMap + .get(aslSession.getScope()); + if (tasksStarted == null) { + logger.debug("TaskWrapper was not acquired: " + taskWrapper); + } else { + tasksStarted.remove(taskWrapper.getTask().getId().getValue()); + scopeToTasksStartedMap.put(aslSession.getScope(), tasksStarted); + httpSession + .removeAttribute(SessionConstants.SCOPE_TO_OPERATIONS_TASKS_STARTED_MAP); + httpSession.setAttribute( + SessionConstants.SCOPE_TO_OPERATIONS_TASKS_STARTED_MAP, + scopeToTasksStartedMap); + } } - tasksStarted.remove(taskWrapper.getTask().getId().getValue()); - httpSession.setAttribute(SessionConstants.OPERATIONS_TASKS_STARTED, - tasksStarted); + return; } - + + /** + * Add Task Started + * + * @param httpSession + * @param taskWrapper + * @throws TDGWTSessionExpiredException + */ public static void setStartedTask(HttpSession httpSession, - TaskWrapper taskWrapper) { + TaskWrapper taskWrapper) throws TDGWTSessionExpiredException { + ASLSession aslSession = getAslSession(httpSession); + ScopeProvider.instance.set(aslSession.getScope()); + if (taskWrapper == null) { logger.error("TaskWrapper is null"); return; @@ -1645,162 +1939,349 @@ public class SessionUtil { } @SuppressWarnings("unchecked") - HashMap tasksStarted = ((HashMap) httpSession - .getAttribute(SessionConstants.OPERATIONS_TASKS_STARTED)); - if (tasksStarted == null) { - tasksStarted = new HashMap(); - } else { - httpSession - .removeAttribute(SessionConstants.OPERATIONS_TASKS_STARTED); - } + HashMap> scopeToTasksStartedMap = (HashMap>) httpSession + .getAttribute(SessionConstants.SCOPE_TO_OPERATIONS_TASKS_STARTED_MAP); - tasksStarted.put(taskWrapper.getTask().getId().getValue(), taskWrapper); - httpSession.setAttribute(SessionConstants.OPERATIONS_TASKS_STARTED, - tasksStarted); + if (scopeToTasksStartedMap == null) { + scopeToTasksStartedMap = new HashMap>(); + HashMap tasksStarted = new HashMap(); + tasksStarted.put(taskWrapper.getTask().getId().getValue(), + taskWrapper); + scopeToTasksStartedMap.put(aslSession.getScope(), tasksStarted); + } else { + HashMap tasksStarted = scopeToTasksStartedMap + .get(aslSession.getScope()); + if (tasksStarted == null) { + tasksStarted = new HashMap(); + tasksStarted.put(taskWrapper.getTask().getId().getValue(), + taskWrapper); + scopeToTasksStartedMap.put(aslSession.getScope(), tasksStarted); + } else { + tasksStarted.put(taskWrapper.getTask().getId().getValue(), + taskWrapper); + scopeToTasksStartedMap.put(aslSession.getScope(), tasksStarted); + + } + httpSession + .removeAttribute(SessionConstants.SCOPE_TO_OPERATIONS_TASKS_STARTED_MAP); + } + httpSession.setAttribute( + SessionConstants.SCOPE_TO_OPERATIONS_TASKS_STARTED_MAP, + scopeToTasksStartedMap); + + return; } - + + /** + * Retrieve Aborted Task Map + * + * @param httpSession + * @return + * @throws TDGWTSessionExpiredException + */ public static HashMap getAbortedTaskMap( - HttpSession httpSession) { - @SuppressWarnings("unchecked") - HashMap tasksAborted = (HashMap) httpSession - .getAttribute(SessionConstants.OPERATIONS_TASKS_ABORTED); - return tasksAborted; - }; + HttpSession httpSession) throws TDGWTSessionExpiredException { + ASLSession aslSession = getAslSession(httpSession); + ScopeProvider.instance.set(aslSession.getScope()); + @SuppressWarnings("unchecked") + HashMap> scopeToTasksAbortedMap = (HashMap>) httpSession + .getAttribute(SessionConstants.SCOPE_TO_OPERATIONS_TASKS_ABORTED_MAP); + if (scopeToTasksAbortedMap == null) { + return null; + } else { + HashMap tasksAborted = scopeToTasksAbortedMap + .get(aslSession.getScope()); + return tasksAborted; + + } + + } + + /** + * + * @param httpSession + * @param taskWrapper + * @throws TDGWTSessionExpiredException + */ public static void setAbortedTasks(HttpSession httpSession, - TaskWrapper taskWrapper) { + TaskWrapper taskWrapper) throws TDGWTSessionExpiredException { + ASLSession aslSession = getAslSession(httpSession); + ScopeProvider.instance.set(aslSession.getScope()); + if (taskWrapper == null) { logger.error("TaskWrapper is null"); return; } - if (taskWrapper.getTask().getId() == null + if (taskWrapper.getTask() == null + || taskWrapper.getTask().getId() == null || taskWrapper.getTask().getId().getValue() == null || taskWrapper.getTask().getId().getValue().isEmpty()) { - logger.error("TaskWrapper contains Task with invalid task id"); + logger.error("TaskWrapper contains Task with invalid task id: " + + taskWrapper); return; } @SuppressWarnings("unchecked") - HashMap tasksAborted = ((HashMap) httpSession - .getAttribute(SessionConstants.OPERATIONS_TASKS_ABORTED)); - if (tasksAborted == null) { - tasksAborted = new HashMap(); + HashMap> scopeToTasksAbortedMap = (HashMap>) httpSession + .getAttribute(SessionConstants.SCOPE_TO_OPERATIONS_TASKS_ABORTED_MAP); + + if (scopeToTasksAbortedMap == null) { + scopeToTasksAbortedMap = new HashMap>(); + HashMap tasksAborted = new HashMap(); + tasksAborted.put(taskWrapper.getTask().getId().getValue(), + taskWrapper); + scopeToTasksAbortedMap.put(aslSession.getScope(), tasksAborted); } else { + HashMap tasksAborted = scopeToTasksAbortedMap + .get(aslSession.getScope()); + + if (tasksAborted == null) { + tasksAborted = new HashMap(); + tasksAborted.put(taskWrapper.getTask().getId().getValue(), + taskWrapper); + scopeToTasksAbortedMap.put(aslSession.getScope(), tasksAborted); + } else { + tasksAborted.put(taskWrapper.getTask().getId().getValue(), + taskWrapper); + scopeToTasksAbortedMap.put(aslSession.getScope(), tasksAborted); + + } httpSession - .removeAttribute(SessionConstants.OPERATIONS_TASKS_ABORTED); + .removeAttribute(SessionConstants.SCOPE_TO_OPERATIONS_TASKS_ABORTED_MAP); } - tasksAborted.put(taskWrapper.getTask().getId().getValue(), taskWrapper); - httpSession.setAttribute(SessionConstants.OPERATIONS_TASKS_ABORTED, - tasksAborted); + httpSession.setAttribute( + SessionConstants.SCOPE_TO_OPERATIONS_TASKS_ABORTED_MAP, + scopeToTasksAbortedMap); + + return; } - + + /** + * Retrive Hidden Task Map + * + * @param httpSession + * @return + * @throws TDGWTSessionExpiredException + */ public static HashMap getHiddenTaskMap( - HttpSession httpSession) { - @SuppressWarnings("unchecked") - HashMap hiddenTasks = (HashMap) httpSession - .getAttribute(SessionConstants.OPERATIONS_TASKS_HIDDEN); - return hiddenTasks; - }; + HttpSession httpSession) throws TDGWTSessionExpiredException { + ASLSession aslSession = getAslSession(httpSession); + ScopeProvider.instance.set(aslSession.getScope()); + @SuppressWarnings("unchecked") + HashMap> scopeToHiddenTasksMap = (HashMap>) httpSession + .getAttribute(SessionConstants.SCOPE_TO_OPERATIONS_TASKS_HIDDEN_MAP); + if (scopeToHiddenTasksMap == null) { + return null; + } else { + HashMap hiddenTasks = scopeToHiddenTasksMap + .get(aslSession.getScope()); + return hiddenTasks; + + } + + } + + /** + * + * @param httpSession + * @param taskWrapper + * @throws TDGWTSessionExpiredException + */ public static void setHiddenTask(HttpSession httpSession, - TaskWrapper taskWrapper) { + TaskWrapper taskWrapper) throws TDGWTSessionExpiredException { + ASLSession aslSession = getAslSession(httpSession); + ScopeProvider.instance.set(aslSession.getScope()); + if (taskWrapper == null) { logger.error("TaskWrapper is null"); return; } - if (taskWrapper.getTask().getId() == null + if (taskWrapper.getTask() == null + || taskWrapper.getTask().getId() == null || taskWrapper.getTask().getId().getValue() == null || taskWrapper.getTask().getId().getValue().isEmpty()) { - logger.error("TaskWrapper contains Task with invalid task id"); + logger.error("TaskWrapper contains Task with invalid task id: " + + taskWrapper); return; } @SuppressWarnings("unchecked") - HashMap hiddenTasks = ((HashMap) httpSession - .getAttribute(SessionConstants.OPERATIONS_TASKS_HIDDEN)); - if (hiddenTasks == null) { - hiddenTasks = new HashMap(); + HashMap> scopeToHiddenTasksMap = (HashMap>) httpSession + .getAttribute(SessionConstants.SCOPE_TO_OPERATIONS_TASKS_HIDDEN_MAP); + + if (scopeToHiddenTasksMap == null) { + scopeToHiddenTasksMap = new HashMap>(); + HashMap hiddenTasks = new HashMap(); + hiddenTasks.put(taskWrapper.getTask().getId().getValue(), + taskWrapper); + scopeToHiddenTasksMap.put(aslSession.getScope(), hiddenTasks); } else { + HashMap hiddenTasks = scopeToHiddenTasksMap + .get(aslSession.getScope()); + + if (hiddenTasks == null) { + hiddenTasks = new HashMap(); + hiddenTasks.put(taskWrapper.getTask().getId().getValue(), + taskWrapper); + scopeToHiddenTasksMap.put(aslSession.getScope(), hiddenTasks); + } else { + hiddenTasks.put(taskWrapper.getTask().getId().getValue(), + taskWrapper); + scopeToHiddenTasksMap.put(aslSession.getScope(), hiddenTasks); + + } httpSession - .removeAttribute(SessionConstants.OPERATIONS_TASKS_HIDDEN); + .removeAttribute(SessionConstants.SCOPE_TO_OPERATIONS_TASKS_HIDDEN_MAP); } - hiddenTasks.put(taskWrapper.getTask().getId().getValue(), taskWrapper); - httpSession.setAttribute(SessionConstants.OPERATIONS_TASKS_HIDDEN, - hiddenTasks); + httpSession.setAttribute( + SessionConstants.SCOPE_TO_OPERATIONS_TASKS_HIDDEN_MAP, + scopeToHiddenTasksMap); + + return; } - + + /** + * Retrieve Tasks In Background + * + * @param httpSession + * @return + * @throws TDGWTSessionExpiredException + */ public static HashMap getTaskInBackgroundMap( - HttpSession httpSession) { - @SuppressWarnings("unchecked") - HashMap tasksInBackground = (HashMap) httpSession - .getAttribute(SessionConstants.OPERATIONS_TASKS_IN_BACKGROUND); - return tasksInBackground; - }; + HttpSession httpSession) throws TDGWTSessionExpiredException { + ASLSession aslSession = getAslSession(httpSession); + ScopeProvider.instance.set(aslSession.getScope()); + @SuppressWarnings("unchecked") + HashMap> scopeToTasksInBackgroundMap = (HashMap>) httpSession + .getAttribute(SessionConstants.SCOPE_TO_OPERATIONS_TASKS_IN_BACKGROUND_MAP); + if (scopeToTasksInBackgroundMap == null) { + return null; + } else { + HashMap tasksInBackground = scopeToTasksInBackgroundMap + .get(aslSession.getScope()); + return tasksInBackground; + + } + + } + + /** + * Add Task In Background + * + * @param httpSession + * @param taskWrapper + * @throws TDGWTSessionExpiredException + */ public static void setTaskInBackground(HttpSession httpSession, - TaskWrapper taskWrapper) { + TaskWrapper taskWrapper) throws TDGWTSessionExpiredException { + ASLSession aslSession = getAslSession(httpSession); + ScopeProvider.instance.set(aslSession.getScope()); + if (taskWrapper == null) { logger.error("TaskWrapper is null"); return; } - if (taskWrapper.getTask().getId() == null + if (taskWrapper.getTask()==null||taskWrapper.getTask().getId() == null || taskWrapper.getTask().getId().getValue() == null || taskWrapper.getTask().getId().getValue().isEmpty()) { - logger.error("TaskWrapper contains Task with invalid task id"); + logger.error("TaskWrapper contains Task with invalid task id: "+taskWrapper); return; } - + + @SuppressWarnings("unchecked") - HashMap tasksInBackground = ((HashMap) httpSession - .getAttribute(SessionConstants.OPERATIONS_TASKS_IN_BACKGROUND)); - if (tasksInBackground == null) { - tasksInBackground = new HashMap(); - } else { - httpSession - .removeAttribute(SessionConstants.OPERATIONS_TASKS_IN_BACKGROUND); - } - tasksInBackground.put(taskWrapper.getTask().getId().getValue(), - taskWrapper); - httpSession.setAttribute( - SessionConstants.OPERATIONS_TASKS_IN_BACKGROUND, - tasksInBackground); + HashMap> scopeToTasksInBackgroundMap = (HashMap>) httpSession + .getAttribute(SessionConstants.SCOPE_TO_OPERATIONS_TASKS_IN_BACKGROUND_MAP); + if (scopeToTasksInBackgroundMap == null) { + scopeToTasksInBackgroundMap = new HashMap>(); + HashMap tasksInBackground = new HashMap(); + tasksInBackground.put(taskWrapper.getTask().getId().getValue(), + taskWrapper); + scopeToTasksInBackgroundMap.put(aslSession.getScope(), tasksInBackground); + } else { + HashMap tasksInBackground = scopeToTasksInBackgroundMap + .get(aslSession.getScope()); + + if (tasksInBackground == null) { + tasksInBackground = new HashMap(); + tasksInBackground.put(taskWrapper.getTask().getId().getValue(), + taskWrapper); + scopeToTasksInBackgroundMap.put(aslSession.getScope(), tasksInBackground); + } else { + tasksInBackground.put(taskWrapper.getTask().getId().getValue(), + taskWrapper); + scopeToTasksInBackgroundMap.put(aslSession.getScope(), tasksInBackground); + + } + httpSession + .removeAttribute(SessionConstants.SCOPE_TO_OPERATIONS_TASKS_IN_BACKGROUND_MAP); + } + httpSession.setAttribute( + SessionConstants.SCOPE_TO_OPERATIONS_TASKS_IN_BACKGROUND_MAP, + scopeToTasksInBackgroundMap); + + return; } + /** + * Reomove Task from Tasks In Background + * + * @param httpSession + * @param taskWrapper + * @throws TDGWTSessionExpiredException + */ public static void removeTaskInBackground(HttpSession httpSession, - TaskWrapper taskWrapper) { + TaskWrapper taskWrapper) throws TDGWTSessionExpiredException { + + ASLSession aslSession = getAslSession(httpSession); + ScopeProvider.instance.set(aslSession.getScope()); + if (taskWrapper == null) { logger.error("TaskWrapper is null"); return; } - if (taskWrapper.getTask().getId() == null + if (taskWrapper.getTask()==null || taskWrapper.getTask().getId() == null || taskWrapper.getTask().getId().getValue() == null || taskWrapper.getTask().getId().getValue().isEmpty()) { - logger.error("TaskWrapper contains Task with invalid task id"); + logger.error("TaskWrapper contains Task with invalid task id: "+taskWrapper); return; } - + + @SuppressWarnings("unchecked") - HashMap tasksInBackground = ((HashMap) httpSession - .getAttribute(SessionConstants.OPERATIONS_TASKS_IN_BACKGROUND)); - if (tasksInBackground == null) { - tasksInBackground = new HashMap(); - } else { - httpSession - .removeAttribute(SessionConstants.OPERATIONS_TASKS_IN_BACKGROUND); - } - tasksInBackground.remove(taskWrapper.getTask().getId().getValue()); - httpSession.setAttribute( - SessionConstants.OPERATIONS_TASKS_IN_BACKGROUND, - tasksInBackground); + HashMap> scopeToTasksInBackgroundMap = (HashMap>) httpSession + .getAttribute(SessionConstants.SCOPE_TO_OPERATIONS_TASKS_IN_BACKGROUND_MAP); + if (scopeToTasksInBackgroundMap == null) { + logger.debug("TaskWrapper was not acquired: " + taskWrapper); + } else { + HashMap tasksInBackground = scopeToTasksInBackgroundMap + .get(aslSession.getScope()); + if (tasksInBackground == null) { + logger.debug("TaskWrapper was not acquired: " + taskWrapper); + } else { + tasksInBackground.remove(taskWrapper.getTask().getId().getValue()); + scopeToTasksInBackgroundMap.put(aslSession.getScope(),tasksInBackground); + httpSession + .removeAttribute(SessionConstants.SCOPE_TO_OPERATIONS_TASKS_IN_BACKGROUND_MAP); + httpSession.setAttribute( + SessionConstants.SCOPE_TO_OPERATIONS_TASKS_IN_BACKGROUND_MAP, + scopeToTasksInBackgroundMap); + } + } + return; + } // @@ -1828,9 +2309,10 @@ public class SessionUtil { fileUploadMonitor); } - + // - public static SaveResourceSession getSaveResourceSession(HttpSession httpSession) { + public static SaveResourceSession getSaveResourceSession( + HttpSession httpSession) { SaveResourceSession saveResourceSession = (SaveResourceSession) httpSession .getAttribute(SessionConstants.RESOURCE_SAVE_SESSION); if (saveResourceSession != null) { @@ -1854,6 +2336,5 @@ public class SessionUtil { saveResourceSession); } - } diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/server/TDGWTServiceImpl.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/TDGWTServiceImpl.java index 133d23f..a5cf165 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/server/TDGWTServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/TDGWTServiceImpl.java @@ -317,8 +317,9 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements public TRId restoreUISession() throws TDGWTServiceException { try { HttpSession session = this.getThreadLocalRequest().getSession(); - SessionUtil.getAslSession(session); - + ASLSession aslSession=SessionUtil.getAslSession(session); + + TRId trId = SessionUtil.getTRId(session); logger.debug("restoreUISession()"); if (trId == null) {