diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/client/rpc/TDGWTService.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/client/rpc/TDGWTService.java index d333b27..1bc63ae 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/client/rpc/TDGWTService.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/client/rpc/TDGWTService.java @@ -219,11 +219,21 @@ public interface TDGWTService extends RemoteService { /** * Close current tabular resource * - * @param trId + * @return * @throws TDGWTServiceException */ - public void closeTabularResource() throws TDGWTServiceException; + public TRId closeTabularResource() throws TDGWTServiceException; + + /** + * Close All Tabular Resources + * + * + * @throws TDGWTServiceException + */ + public void closeAllTabularResources() throws TDGWTServiceException; + + // Task /** * Resubmit task diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/client/rpc/TDGWTServiceAsync.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/client/rpc/TDGWTServiceAsync.java index a2b3e7d..1dc782a 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/client/rpc/TDGWTServiceAsync.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/client/rpc/TDGWTServiceAsync.java @@ -132,7 +132,9 @@ public interface TDGWTServiceAsync { void getConnection(RefColumn refColumn, AsyncCallback callback); - void closeTabularResource(AsyncCallback callback); + void closeTabularResource(AsyncCallback callback); + + void closeAllTabularResources(AsyncCallback callback); // Task void startTaskResubmit(TaskResubmitSession taskResubmitSession, 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 9d2ef06..a8cd485 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,8 +7,10 @@ package org.gcube.portlets.user.td.gwtservice.server; * */ public class SessionConstants { - protected static final String CURRENT_TABULAR_RESOURCE = "CURRENT_TABULAR_RESOURCE"; protected static final String CURRENT_TR_ID = "CURRENT_TR_ID"; + protected static final String CURRENT_TABULAR_RESOURCE = "CURRENT_TABULAR_RESOURCE"; + protected static final String CURRENT_TABULAR_RESOURCES_OPEN = "CURRENT_TABULAR_RESOURCES_OPEN"; + protected static final String TDOPEN_SESSION = "TDOPEN_SESSION"; protected static final String TABULAR_RESOURCE_LIST = "TABULAR_RESOURCE_LIST"; 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 64ba20f..2f708a8 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 @@ -178,7 +178,79 @@ public class SessionUtil { 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){ + @SuppressWarnings("unchecked") + ArrayList t = (ArrayList) httpSession + .getAttribute(SessionConstants.CURRENT_TABULAR_RESOURCES_OPEN); + if (t != null){ + t.add(tabResource); + httpSession.setAttribute(SessionConstants.CURRENT_TABULAR_RESOURCES_OPEN, + t); + } else { + t=new ArrayList(); + t.add(tabResource); + httpSession.setAttribute(SessionConstants.CURRENT_TABULAR_RESOURCES_OPEN, + t); + } + } + + public static void removeFromCurrentTabularResourcesOpen(HttpSession httpSession, + TabResource tabResource){ + @SuppressWarnings("unchecked") + ArrayList t = (ArrayList) httpSession + .getAttribute(SessionConstants.CURRENT_TABULAR_RESOURCES_OPEN); + if (t != null && !t.isEmpty()){ + t.remove(tabResource); + httpSession.setAttribute(SessionConstants.CURRENT_TABULAR_RESOURCES_OPEN, + t); + + } + } + + 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 getSDMXImportTabResource(HttpSession httpSession) { TabResource tabResource = (TabResource) httpSession .getAttribute(SessionConstants.SDMX_IMPORT_TABULAR_RESOURCE); 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 2ca6241..c04f442 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 @@ -304,6 +304,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements SessionUtil.setTabResource(session, tabResource); SessionUtil.setTRId(session, tabResource.getTrId()); + SessionUtil.addToCurrentTabularResourcesOpen(session, tabResource); return; } catch (TDGWTServiceException e) { @@ -359,13 +360,14 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements * {@inheritDoc} */ @Override - public void closeTabularResource() throws TDGWTServiceException { + public void closeAllTabularResources() throws TDGWTServiceException { try { HttpSession session = this.getThreadLocalRequest().getSession(); SessionUtil.getAslSession(session); - + SessionUtil.setTabResource(session, null); SessionUtil.setTRId(session, null); + SessionUtil.removeAllFromCurrentTabularResourcesOpen(session); return; } catch (TDGWTServiceException e) { @@ -381,6 +383,40 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements } } + + @Override + public TRId closeTabularResource() throws TDGWTServiceException { + try { + HttpSession session = this.getThreadLocalRequest().getSession(); + SessionUtil.getAslSession(session); + TabResource currentTR=SessionUtil.getTabResource(session); + SessionUtil.removeFromCurrentTabularResourcesOpen(session, currentTR); + TabResource firstTR=SessionUtil.getFirstFromCurrentTabularResourcesOpen(session); + if(firstTR==null){ + SessionUtil.setTabResource(session, null); + SessionUtil.setTRId(session, null); + return null; + } else { + SessionUtil.setTabResource(session, firstTR); + SessionUtil.setTRId(session, firstTR.getTrId()); + return firstTR.getTrId(); + } + + + } catch (TDGWTServiceException e) { + throw e; + } catch (SecurityException e) { + e.printStackTrace(); + throw new TDGWTServiceException( + "Security exception, you haven't rights!"); + } catch (Throwable e) { + logger.error("getCurrentTRID(): " + e.getLocalizedMessage(), e); + throw new TDGWTServiceException("Error retrieving TR id: " + + e.getLocalizedMessage()); + } + + } + /** *