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 fa9d561..8a42f9b 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 @@ -9,21 +9,22 @@ import java.util.List; import java.util.Locale; import java.util.ResourceBundle; +import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; -import org.gcube.application.framework.core.session.ASLSession; -import org.gcube.application.framework.core.session.SessionManager; +import org.gcube.common.portal.PortalContext; import org.gcube.common.scope.api.ScopeProvider; import org.gcube.data.analysis.tabulardata.service.tabular.TabularResource; -import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper; import org.gcube.portlets.user.td.gwtservice.server.file.CSVFileUploadSession; import org.gcube.portlets.user.td.gwtservice.server.file.CodelistMappingFileUploadSession; import org.gcube.portlets.user.td.gwtservice.server.trservice.TRTasksManager; +import org.gcube.portlets.user.td.gwtservice.server.util.ServiceCredentials; import org.gcube.portlets.user.td.gwtservice.shared.Constants; import org.gcube.portlets.user.td.gwtservice.shared.chart.ChartTopRatingSession; import org.gcube.portlets.user.td.gwtservice.shared.codelisthelper.CodelistMappingSession; import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVExportSession; import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVImportSession; +import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTServiceException; import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTSessionExpiredException; import org.gcube.portlets.user.td.gwtservice.shared.extract.ExtractCodelistSession; import org.gcube.portlets.user.td.gwtservice.shared.file.FileUploadMonitor; @@ -75,6 +76,9 @@ import org.gcube.portlets.user.td.gwtservice.shared.tr.type.Codelist; import org.gcube.portlets.user.td.gwtservice.shared.tr.type.Dataset; import org.gcube.portlets.user.td.gwtservice.shared.tr.union.UnionSession; import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId; +import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager; +import org.gcube.vomanagement.usermanagement.model.GCubeGroup; +import org.gcube.vomanagement.usermanagement.model.GCubeUser; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -88,79 +92,210 @@ public class SessionUtil { private static Logger logger = LoggerFactory.getLogger(SessionUtil.class); - public static ASLSession getAslSession(HttpSession httpSession) - throws TDGWTSessionExpiredException { - String username = (String) httpSession - .getAttribute(ScopeHelper.USERNAME_ATTRIBUTE); - ASLSession aslSession; - if (username == null) { - InfoLocale infoLocale = getInfoLocale(httpSession); + /** + * + * @param httpServletRequest + * @return + * @throws TDGWTServiceException + */ + public static ServiceCredentials getServiceCredentials( + HttpServletRequest httpServletRequest) throws TDGWTServiceException { + return getServiceCredentials(httpServletRequest, null); + } + + /** + * + * @param httpServletRequest + * @param scopeGroupId + * @return + * @throws TDGWTServiceException + */ + public static ServiceCredentials getServiceCredentials( + HttpServletRequest httpServletRequest, String scopeGroupId) + throws TDGWTServiceException { + + ServiceCredentials sCredentials = null; + String userName = null; + String scope = null; + String token = null; + String groupId = null; + String groupName = null; + + if (Constants.DEBUG_MODE) { + logger.info("No credential found in session, use test user!"); + InfoLocale infoLocale = getInfoLocale(httpServletRequest, null); Locale locale = new Locale(infoLocale.getLanguage()); + @SuppressWarnings("unused") ResourceBundle messages = ResourceBundle.getBundle( TDGWTServiceMessagesConstants.TDGWTServiceMessages, locale); - if (Constants.DEBUG_MODE) { - logger.info("no user found in session, use test user"); - // Remove comment for Test - username = Constants.DEFAULT_USER; - String scope = Constants.DEFAULT_SCOPE; + userName = Constants.DEFAULT_USER; + scope = Constants.DEFAULT_SCOPE; + token = Constants.DEFAULT_TOKEN; + + sCredentials = new ServiceCredentials(userName, scope, token); + + } else { + logger.info("Retrieving credential in session!"); + PortalContext pContext = PortalContext.getConfiguration(); + boolean hasScopeGroupId = false; + + if (scopeGroupId != null && !scopeGroupId.isEmpty()) { + hasScopeGroupId = true; - httpSession.setAttribute(ScopeHelper.USERNAME_ATTRIBUTE, - username); - aslSession = SessionManager.getInstance().getASLSession( - httpSession.getId(), username); - aslSession.setScope(scope); } else { - logger.info("no user found in session, use test user"); - throw new TDGWTSessionExpiredException( - messages.getString(TDGWTServiceMessagesConstants.sessionExpired)); + hasScopeGroupId = false; + } + + if (hasScopeGroupId) { + scope = pContext.getCurrentScope(scopeGroupId); + } else { + scope = pContext.getCurrentScope(httpServletRequest); } - } else { - aslSession = SessionManager.getInstance().getASLSession( - httpSession.getId(), username); + if (scope == null || scope.isEmpty()) { + String error = "Error retrieving scope: " + scope; + logger.error(error); + throw new TDGWTServiceException(error); + } + + GCubeUser gCubeUser = pContext.getCurrentUser(httpServletRequest); + + if (gCubeUser == null) { + String error = "Error retrieving gCubeUser in scope " + scope + + ": " + gCubeUser; + logger.error(error); + throw new TDGWTServiceException(error); + } + + userName = gCubeUser.getUsername(); + + if (userName == null || userName.isEmpty()) { + String error = "Error retrieving username in scope " + scope + + ": " + userName; + logger.error(error); + throw new TDGWTServiceException(error); + } + + token = pContext.getCurrentUserToken(httpServletRequest); + + if (token == null || token.isEmpty()) { + String error = "Error retrieving token for " + userName + + " in " + scope + ": " + token; + logger.error(error); + throw new TDGWTServiceException(error); + } + + String name = gCubeUser.getFirstName(); + String lastName = gCubeUser.getLastName(); + String fullName = gCubeUser.getFullname(); + + String userAvatarURL = gCubeUser.getUserAvatarURL(); + + String email = gCubeUser.getEmail(); + + if (hasScopeGroupId) { + + groupId = scopeGroupId; + + long gId; + + try { + gId = Long.parseLong(scopeGroupId); + } catch (Throwable e) { + String error = "Error retrieving groupId: " + scopeGroupId; + logger.error(error, e); + throw new TDGWTServiceException(error); + } + + GCubeGroup group; + try { + group = new LiferayGroupManager().getGroup(gId); + } catch (Throwable e) { + String error = "Error retrieving group: " + groupName; + logger.error(error); + throw new TDGWTServiceException(error); + } + + groupName = group.getGroupName(); + + } else { + + groupId = String.valueOf(pContext + .getCurrentGroupId(httpServletRequest)); + + groupName = pContext.getCurrentGroupName(httpServletRequest); + + } + + sCredentials = new ServiceCredentials(userName, fullName, name, + lastName, email, scope, groupId, groupName, userAvatarURL, + token); } - logger.info("SessionUtil: aslSession " + aslSession.getUsername() + " " - + aslSession.getScope()); - - return aslSession; - } - - public static String getToken(ASLSession aslSession) { - String token = null; - if (Constants.DEBUG_MODE) { - token = Constants.DEFAULT_TOKEN; - } else { - token = aslSession.getSecurityToken(); - } - logger.info("received token: " + token); - return token; + logger.info("ServiceCredentials: " + sCredentials); + return sCredentials; } // - public static InfoLocale getInfoLocale(HttpSession httpSession) { - InfoLocale infoLocale = (InfoLocale) httpSession - .getAttribute(SessionConstants.INFO_LOCALE); - if (infoLocale != null) { - return infoLocale; + /** + * + * @param httpRequest + * @param scope + * @return + */ + public static InfoLocale getInfoLocale(HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials) { + InfoLocale infoLocale = null; + String scope = serviceCredentials.getScope(); + HttpSession session = httpRequest.getSession(); + + @SuppressWarnings("unchecked") + HashMap infoLocaleMap = (HashMap) session + .getAttribute(SessionConstants.INFO_LOCALE_MAP); + + if (infoLocaleMap != null) { + if (infoLocaleMap.containsKey(scope)) { + infoLocale = infoLocaleMap.get(scope); + } else { + infoLocale = new InfoLocale("en"); + infoLocaleMap.put(scope, infoLocale); + } } else { infoLocale = new InfoLocale("en"); - httpSession.setAttribute(SessionConstants.INFO_LOCALE, infoLocale); - return infoLocale; + infoLocaleMap = new HashMap<>(); + infoLocaleMap.put(scope, infoLocale); + session.setAttribute(SessionConstants.INFO_LOCALE_MAP, + infoLocaleMap); } + return infoLocale; } - public static void setInfoLocale(HttpSession httpSession, - InfoLocale infoLocale) { - InfoLocale infoL = (InfoLocale) httpSession - .getAttribute(SessionConstants.INFO_LOCALE); - if (infoL != null) { - httpSession.removeAttribute(SessionConstants.INFO_LOCALE); + /** + * + * @param httpRequest + * @param scope + * @param infoLocale + */ + public static void setInfoLocale(HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials, InfoLocale infoLocale) { + HttpSession httpSession = httpRequest.getSession(); + String scope = serviceCredentials.getScope(); + @SuppressWarnings("unchecked") + HashMap infoLocaleMap = (HashMap) httpSession + .getAttribute(SessionConstants.INFO_LOCALE_MAP); + if (infoLocaleMap != null) { + infoLocaleMap.put(scope, infoLocale); + } else { + infoLocale = new InfoLocale("en"); + infoLocaleMap = new HashMap<>(); + infoLocaleMap.put(scope, infoLocale); + httpSession.setAttribute(SessionConstants.INFO_LOCALE_MAP, + infoLocaleMap); + } - httpSession.setAttribute(SessionConstants.INFO_LOCALE, infoLocale); } @@ -168,208 +303,119 @@ public class SessionUtil { * Set in session the Tabular Resource List retrieved from service only for * caching * - * @param httpSession + * @param httpRequest + * @param serviceCredentials * @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); - + public static void setTabularResources(HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials, List trs) { + ScopeProvider.instance.set(serviceCredentials.getScope()); + SessionOp> sessionOp = new SessionOp<>(); + sessionOp.set(httpRequest, serviceCredentials, + SessionConstants.SCOPE_TO_TABULAR_RESOURCE_LIST_MAP, trs); } /** - * Set current TRId in current scope * - * @param httpSession + * @param httpRequest + * @param serviceCredentials * @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; + public static TRId getTRId(HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials) { + ScopeProvider.instance.set(serviceCredentials.getScope()); + SessionOp sessionOp = new SessionOp<>(); + TRId trId = sessionOp.get(httpRequest, serviceCredentials, + SessionConstants.SCOPE_TO_CURRENT_TRID_MAP); + return trId; } /** * - * @param httpSession + * @param httpRequest + * @param serviceCredentials * @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; - + public static void setTRId(HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials, TRId trId) { + ScopeProvider.instance.set(serviceCredentials.getScope()); + SessionOp sessionOp = new SessionOp<>(); + sessionOp.set(httpRequest, serviceCredentials, + SessionConstants.SCOPE_TO_CURRENT_TRID_MAP, trId); } /** * - * @param httpSession + * @param httpRequest + * @param serviceCredentials * @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"); - } - } + public static TabResource getTabResource(HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials) { + ScopeProvider.instance.set(serviceCredentials.getScope()); + SessionOp sessionOp = new SessionOp<>(); + TabResource tabResource = sessionOp.get(httpRequest, + serviceCredentials, + SessionConstants.SCOPE_TO_CURRENT_TABULAR_RESOURCE_MAP); return tabResource; } /** * - * @param httpSession + * @param httpRequest + * @param serviceCredentials * @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( + public static void setTabResource(HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials, TabResource tabResource) { + ScopeProvider.instance.set(serviceCredentials.getScope()); + SessionOp sessionOp = new SessionOp<>(); + sessionOp.set(httpRequest, serviceCredentials, SessionConstants.SCOPE_TO_CURRENT_TABULAR_RESOURCE_MAP, - scopeToTabResourceMap); - return; - + tabResource); } // /** * - * @param httpSession + * @param httpRequest + * @param serviceCredentials * @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"); - } - } + HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials) { + ScopeProvider.instance.set(serviceCredentials.getScope()); + SessionOp> sessionOp = new SessionOp<>(); + ArrayList currentTROpen = sessionOp.get(httpRequest, + serviceCredentials, + SessionConstants.SCOPE_TO_CURRENT_TABULAR_RESOURCES_OPEN_MAP); return currentTROpen; } /** * - * @param httpSession + * @param httpRequest + * @param serviceCredentials * @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( + public static void setCurrentTabularResourcesOpen( + HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials, + ArrayList currentTROpen) { + ScopeProvider.instance.set(serviceCredentials.getScope()); + SessionOp> sessionOp = new SessionOp<>(); + sessionOp.set(httpRequest, serviceCredentials, SessionConstants.SCOPE_TO_CURRENT_TABULAR_RESOURCES_OPEN_MAP, - scopeToTabResourceOpenMap); - return; + currentTROpen); } /** @@ -379,28 +425,34 @@ public class SessionUtil { * @throws TDGWTSessionExpiredException */ public static void addToCurrentTabularResourcesOpen( - HttpSession httpSession, TabResource tabResource) - throws TDGWTSessionExpiredException { + HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials, TabResource tabResource) { - ASLSession aslSession = getAslSession(httpSession); - ScopeProvider.instance.set(aslSession.getScope()); + ScopeProvider.instance.set(serviceCredentials.getScope()); if (tabResource.getTrId() != null && tabResource.getTrId().getId() != null - & !tabResource.getTrId().getId().isEmpty()) { + && !tabResource.getTrId().getId().isEmpty()) { + + HttpSession httpSession = httpRequest.getSession(); @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 = new HashMap<>(); + ArrayList openList = new ArrayList<>(); openList.add(tabResource); - scopeToTabResourceOpenMap.put(aslSession.getScope(), openList); + scopeToTabResourceOpenMap.put(serviceCredentials.getScope(), + openList); + httpSession + .setAttribute( + SessionConstants.SCOPE_TO_CURRENT_TABULAR_RESOURCES_OPEN_MAP, + scopeToTabResourceOpenMap); } else { ArrayList openList = scopeToTabResourceOpenMap - .get(aslSession.getScope()); + .get(serviceCredentials.getScope()); if (openList != null) { for (TabResource tr : openList) { @@ -412,17 +464,13 @@ public class SessionUtil { } openList.add(tabResource); } else { - openList = new ArrayList(); + openList = new ArrayList<>(); openList.add(tabResource); } - scopeToTabResourceOpenMap.put(aslSession.getScope(), openList); - httpSession - .removeAttribute(SessionConstants.SCOPE_TO_CURRENT_TABULAR_RESOURCES_OPEN_MAP); + scopeToTabResourceOpenMap.put(serviceCredentials.getScope(), + openList); } - httpSession - .setAttribute( - SessionConstants.SCOPE_TO_CURRENT_TABULAR_RESOURCES_OPEN_MAP, - scopeToTabResourceOpenMap); + } else { logger.error("Tabular Resource has invalid id"); } @@ -436,25 +484,30 @@ public class SessionUtil { * @throws TDGWTSessionExpiredException */ public static void removeFromCurrentTabularResourcesOpen( - HttpSession httpSession, TRId trId) - throws TDGWTSessionExpiredException { - ASLSession aslSession = getAslSession(httpSession); - ScopeProvider.instance.set(aslSession.getScope()); + HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials, TRId trId) { + ScopeProvider.instance.set(serviceCredentials.getScope()); if (trId != null && trId.getId() != null & !trId.getId().isEmpty()) { + HttpSession httpSession = httpRequest.getSession(); @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); + scopeToTabResourceOpenMap = new HashMap<>(); + ArrayList openList = new ArrayList<>(); + scopeToTabResourceOpenMap.put(serviceCredentials.getScope(), + openList); + httpSession + .setAttribute( + SessionConstants.SCOPE_TO_CURRENT_TABULAR_RESOURCES_OPEN_MAP, + scopeToTabResourceOpenMap); logger.debug("No open tr list in session"); } else { ArrayList openList = scopeToTabResourceOpenMap - .get(aslSession.getScope()); + .get(serviceCredentials.getScope()); if (openList != null) { for (TabResource tr : openList) { if (tr.getTrId().getId().compareTo(trId.getId()) == 0) { @@ -464,16 +517,12 @@ public class SessionUtil { } } else { - openList = new ArrayList(); + openList = new ArrayList<>(); } - scopeToTabResourceOpenMap.put(aslSession.getScope(), openList); - httpSession - .removeAttribute(SessionConstants.SCOPE_TO_CURRENT_TABULAR_RESOURCES_OPEN_MAP); + scopeToTabResourceOpenMap.put(serviceCredentials.getScope(), + openList); } - httpSession - .setAttribute( - SessionConstants.SCOPE_TO_CURRENT_TABULAR_RESOURCES_OPEN_MAP, - scopeToTabResourceOpenMap); + } else { logger.error("TRId request has invalid id"); } @@ -485,9 +534,10 @@ public class SessionUtil { * @throws TDGWTSessionExpiredException */ public static void removeAllFromCurrentTabularResourcesOpen( - HttpSession httpSession) throws TDGWTSessionExpiredException { - ASLSession aslSession = getAslSession(httpSession); - ScopeProvider.instance.set(aslSession.getScope()); + HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials) { + ScopeProvider.instance.set(serviceCredentials.getScope()); + HttpSession httpSession = httpRequest.getSession(); @SuppressWarnings("unchecked") HashMap> scopeToTabResourceOpenMap = (HashMap>) httpSession @@ -496,13 +546,7 @@ public class SessionUtil { 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); + scopeToTabResourceOpenMap.remove(serviceCredentials.getScope()); } } @@ -514,26 +558,19 @@ public class SessionUtil { * @throws TDGWTSessionExpiredException */ public static TabResource getFirstFromCurrentTabularResourcesOpen( - HttpSession httpSession) throws TDGWTSessionExpiredException { - ASLSession aslSession = getAslSession(httpSession); - ScopeProvider.instance.set(aslSession.getScope()); + HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials) { + ScopeProvider.instance.set(serviceCredentials.getScope()); + SessionOp> sessionOp = new SessionOp<>(); + ArrayList openList = sessionOp.get(httpRequest, + serviceCredentials, + SessionConstants.SCOPE_TO_CURRENT_TABULAR_RESOURCES_OPEN_MAP); - @SuppressWarnings("unchecked") - HashMap> scopeToTabResourceOpenMap = (HashMap>) httpSession - .getAttribute(SessionConstants.SCOPE_TO_CURRENT_TABULAR_RESOURCES_OPEN_MAP); - - if (scopeToTabResourceOpenMap == null) { + if (openList == null || openList.isEmpty()) { 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); - } + return openList.get(0); } } @@ -546,329 +583,313 @@ public class SessionUtil { * @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) { + HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials, TRId trId) { + ScopeProvider.instance.set(serviceCredentials.getScope()); + SessionOp> sessionOp = new SessionOp<>(); + ArrayList openList = sessionOp.get(httpRequest, + serviceCredentials, + SessionConstants.SCOPE_TO_CURRENT_TABULAR_RESOURCES_OPEN_MAP); + if (openList == null || openList.isEmpty()) { 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 { - logger.debug("Current Tabular Open In session: " - + aslSession.getScope() + ", trList: " + openList); - for (TabResource tabResource : openList) { - if (tabResource != null - && tabResource.getTrId() != null - && tabResource.getTrId().getId() - .compareTo(trId.getId()) == 0) { - return tabResource; - } + logger.debug("Current Tabular Open In session: " + + serviceCredentials.getScope() + ", trList: " + openList); + for (TabResource tabResource : openList) { + if (tabResource != null + && tabResource.getTrId() != null + && tabResource.getTrId().getId() + .compareTo(trId.getId()) == 0) { + return tabResource; } } + logger.info("No tabular resource open in session with: " + trId); + } return null; - } // /** * * @param httpSession - * @param s + * @param tdOpenSession * @throws TDGWTSessionExpiredException */ - public static void setTDOpenSession(HttpSession httpSession, TDOpenSession s) - throws TDGWTSessionExpiredException { - - TDOpenSession session = (TDOpenSession) httpSession - .getAttribute(SessionConstants.TDOPEN_SESSION); - if (session != null) - httpSession.removeAttribute(SessionConstants.TDOPEN_SESSION); - httpSession.setAttribute(SessionConstants.TDOPEN_SESSION, s); - ASLSession aslSession = getAslSession(httpSession); - ScopeProvider.instance.set(aslSession.getScope().toString()); - + public static void setTDOpenSession(HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials, TDOpenSession tdOpenSession) { + ScopeProvider.instance.set(serviceCredentials.getScope()); + SessionOp sessionOp = new SessionOp<>(); + sessionOp.set(httpRequest, serviceCredentials, + SessionConstants.TDOPEN_SESSION, tdOpenSession); } - public static void retrieveResources(HttpSession httpSession) - throws Exception { - - ASLSession aslSession = getAslSession(httpSession); - ScopeProvider.instance.set(aslSession.getScope().toString()); - return; - } + // TODO check + // public static void retrieveResources(HttpServletRequest httpRequest, + // ServiceCredentials serviceCredentials) { + // ScopeProvider.instance.set(serviceCredentials.getScope()); + // return; + // } // - public static TabResource getSDMXImportTabResource(HttpSession httpSession) { - TabResource tabResource = (TabResource) httpSession - .getAttribute(SessionConstants.SDMX_IMPORT_TABULAR_RESOURCE); - if (tabResource == null) { - logger.error("SDMX_IMPORT_TABULAR_RESOURCE was not acquired"); - } + public static TabResource getSDMXImportTabResource( + HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials) { + SessionOp sessionOp = new SessionOp<>(); + TabResource tabResource = sessionOp.get(httpRequest, + serviceCredentials, + SessionConstants.SDMX_IMPORT_TABULAR_RESOURCE); return tabResource; } - public static void setSDMXImportTabResource(HttpSession httpSession, - TabResource tabResource) throws TDGWTSessionExpiredException { - TabResource t = (TabResource) httpSession - .getAttribute(SessionConstants.SDMX_IMPORT_TABULAR_RESOURCE); - if (t != null) - httpSession - .removeAttribute(SessionConstants.SDMX_IMPORT_TABULAR_RESOURCE); - httpSession.setAttribute(SessionConstants.SDMX_IMPORT_TABULAR_RESOURCE, - tabResource); - ASLSession aslSession = getAslSession(httpSession); - ScopeProvider.instance.set(aslSession.getScope().toString()); + public static void setSDMXImportTabResource(HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials, TabResource tabResource) { + ScopeProvider.instance.set(serviceCredentials.getScope()); + SessionOp sessionOp = new SessionOp<>(); + sessionOp.set(httpRequest, serviceCredentials, + SessionConstants.SDMX_IMPORT_TABULAR_RESOURCE, tabResource); + } - // // - public static TabResource getCSVImportTabResource(HttpSession httpSession) { - TabResource tabResource = (TabResource) httpSession - .getAttribute(SessionConstants.CSV_IMPORT_TABULAR_RESOURCE); - if (tabResource == null) { - logger.error("CSV_IMPORT_TABULAR_RESOURCE was not acquired"); - } + // + public static TabResource getCSVImportTabResource( + HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials) { + SessionOp sessionOp = new SessionOp<>(); + TabResource tabResource = sessionOp.get(httpRequest, + serviceCredentials, + SessionConstants.CSV_IMPORT_TABULAR_RESOURCE); return tabResource; } - public static void setCSVImportTabResource(HttpSession httpSession, - TabResource tabResource) throws TDGWTSessionExpiredException { - TabResource t = (TabResource) httpSession - .getAttribute(SessionConstants.CSV_IMPORT_TABULAR_RESOURCE); - if (t != null) - httpSession - .removeAttribute(SessionConstants.CSV_IMPORT_TABULAR_RESOURCE); - httpSession.setAttribute(SessionConstants.CSV_IMPORT_TABULAR_RESOURCE, - tabResource); - ASLSession aslSession = getAslSession(httpSession); - ScopeProvider.instance.set(aslSession.getScope().toString()); - } - - // // - - public static void setSDMXImportSession(HttpSession httpSession, - SDMXImportSession s) throws TDGWTSessionExpiredException { - - SDMXImportSession session = (SDMXImportSession) httpSession - .getAttribute(SessionConstants.SDMX_IMPORT_SESSION); - if (session != null) - httpSession.removeAttribute(SessionConstants.SDMX_IMPORT_SESSION); - httpSession.setAttribute(SessionConstants.SDMX_IMPORT_SESSION, s); - ASLSession aslSession = getAslSession(httpSession); - ScopeProvider.instance.set(aslSession.getScope().toString()); - } - - public static SDMXImportSession getSDMXImportSession(HttpSession httpSession) { - SDMXImportSession importSession = (SDMXImportSession) httpSession - .getAttribute(SessionConstants.SDMX_IMPORT_SESSION); - if (importSession == null) { - logger.error("SDMXImportSession was not acquired"); - } - return importSession; - } - - public static void setCSVImportSession(HttpSession httpSession, - CSVImportSession s) throws TDGWTSessionExpiredException { - - CSVImportSession session = (CSVImportSession) httpSession - .getAttribute(SessionConstants.CSV_IMPORT_SESSION); - if (session != null) - httpSession.removeAttribute(SessionConstants.CSV_IMPORT_SESSION); - httpSession.setAttribute(SessionConstants.CSV_IMPORT_SESSION, s); - ASLSession aslSession = getAslSession(httpSession); - ScopeProvider.instance.set(aslSession.getScope().toString()); - } - - public static CSVImportSession getCSVImportSession(HttpSession httpSession) { - CSVImportSession importSession = (CSVImportSession) httpSession - .getAttribute(SessionConstants.CSV_IMPORT_SESSION); - if (importSession == null) { - logger.error("CSVImportSession was not acquired"); - } - return importSession; - } - - public static void setCSVExportSession(HttpSession httpSession, - CSVExportSession s) throws TDGWTSessionExpiredException { - - CSVExportSession session = (CSVExportSession) httpSession - .getAttribute(SessionConstants.CSV_EXPORT_SESSION); - if (session != null) - httpSession.removeAttribute(SessionConstants.CSV_EXPORT_SESSION); - httpSession.setAttribute(SessionConstants.CSV_EXPORT_SESSION, s); - ASLSession aslSession = getAslSession(httpSession); - ScopeProvider.instance.set(aslSession.getScope().toString()); - } - - public static CSVExportSession getCSVExportSession(HttpSession httpSession) { - CSVExportSession exportSession = (CSVExportSession) httpSession - .getAttribute(SessionConstants.CSV_EXPORT_SESSION); - if (exportSession == null) { - logger.error("CSVExportSession was not acquired"); - } - return exportSession; - } - - public static void setSDMXExportSession(HttpSession httpSession, - SDMXExportSession s) throws TDGWTSessionExpiredException { - - SDMXExportSession session = (SDMXExportSession) httpSession - .getAttribute(SessionConstants.SDMX_EXPORT_SESSION); - if (session != null) - httpSession.removeAttribute(SessionConstants.SDMX_EXPORT_SESSION); - httpSession.setAttribute(SessionConstants.SDMX_EXPORT_SESSION, s); - ASLSession aslSession = getAslSession(httpSession); - ScopeProvider.instance.set(aslSession.getScope().toString()); - } - - public static SDMXExportSession getSDMXExportSession(HttpSession httpSession) { - SDMXExportSession exportSession = (SDMXExportSession) httpSession - .getAttribute(SessionConstants.SDMX_EXPORT_SESSION); - if (exportSession == null) { - logger.error("SDMXExportSession was not acquired"); - } - return exportSession; + public static void setCSVImportTabResource(HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials, TabResource tabResource) { + ScopeProvider.instance.set(serviceCredentials.getScope()); + SessionOp sessionOp = new SessionOp<>(); + sessionOp.set(httpRequest, serviceCredentials, + SessionConstants.CSV_IMPORT_TABULAR_RESOURCE, tabResource); } // - public static void setJSONExportSession(HttpSession httpSession, - JSONExportSession s) throws TDGWTSessionExpiredException { - - JSONExportSession session = (JSONExportSession) httpSession - .getAttribute(SessionConstants.JSON_EXPORT_SESSION); - if (session != null) - httpSession.removeAttribute(SessionConstants.JSON_EXPORT_SESSION); - httpSession.setAttribute(SessionConstants.JSON_EXPORT_SESSION, s); - ASLSession aslSession = getAslSession(httpSession); - ScopeProvider.instance.set(aslSession.getScope().toString()); + public static void setSDMXImportSession(HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials, + SDMXImportSession sdmxImportSession) { + ScopeProvider.instance.set(serviceCredentials.getScope()); + SessionOp sessionOp = new SessionOp<>(); + sessionOp.set(httpRequest, serviceCredentials, + SessionConstants.SDMX_IMPORT_SESSION, sdmxImportSession); } - public static JSONExportSession getJSONExportSession(HttpSession httpSession) { - JSONExportSession exportSession = (JSONExportSession) httpSession - .getAttribute(SessionConstants.JSON_EXPORT_SESSION); - if (exportSession == null) { - logger.error("JSONExportSession was not acquired"); - } - return exportSession; + public static SDMXImportSession getSDMXImportSession( + HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials) { + + SessionOp sessionOp = new SessionOp<>(); + SDMXImportSession sdmxImportSession = sessionOp.get(httpRequest, + serviceCredentials, SessionConstants.SDMX_IMPORT_SESSION); + return sdmxImportSession; + } // - public static void setCSVFileUploadSession(HttpSession httpSession, - CSVFileUploadSession s) throws TDGWTSessionExpiredException { + public static void setCSVImportSession(HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials, + CSVImportSession csvImportSession) { + ScopeProvider.instance.set(serviceCredentials.getScope()); + SessionOp sessionOp = new SessionOp<>(); + sessionOp.set(httpRequest, serviceCredentials, + SessionConstants.CSV_IMPORT_SESSION, csvImportSession); + } + + public static CSVImportSession getCSVImportSession( + HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials) { + SessionOp sessionOp = new SessionOp<>(); + CSVImportSession csvImportSession = sessionOp.get(httpRequest, + serviceCredentials, SessionConstants.CSV_IMPORT_SESSION); + return csvImportSession; + } + + // + public static void setCSVExportSession(HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials, + CSVExportSession csvExportSession) { + ScopeProvider.instance.set(serviceCredentials.getScope()); + SessionOp sessionOp = new SessionOp<>(); + sessionOp.set(httpRequest, serviceCredentials, + SessionConstants.CSV_EXPORT_SESSION, csvExportSession); + } + + public static CSVExportSession getCSVExportSession( + HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials) { + SessionOp sessionOp = new SessionOp<>(); + CSVExportSession csvExportSession = sessionOp.get(httpRequest, + serviceCredentials, SessionConstants.CSV_EXPORT_SESSION); + return csvExportSession; + + } + + // + public static void setSDMXExportSession(HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials, + SDMXExportSession sdmxExportSession) { + ScopeProvider.instance.set(serviceCredentials.getScope()); + SessionOp sessionOp = new SessionOp<>(); + sessionOp.set(httpRequest, serviceCredentials, + SessionConstants.SDMX_EXPORT_SESSION, sdmxExportSession); + } + + public static SDMXExportSession getSDMXExportSession( + HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials) { + SessionOp sessionOp = new SessionOp<>(); + SDMXExportSession sdmxExportSession = sessionOp.get(httpRequest, + serviceCredentials, SessionConstants.SDMX_EXPORT_SESSION); + return sdmxExportSession; + } + + // + public static void setJSONExportSession(HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials, + JSONExportSession jsonExportSession) { + ScopeProvider.instance.set(serviceCredentials.getScope()); + SessionOp sessionOp = new SessionOp<>(); + sessionOp.set(httpRequest, serviceCredentials, + SessionConstants.JSON_EXPORT_SESSION, jsonExportSession); + + } + + public static JSONExportSession getJSONExportSession( + HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials) { + SessionOp sessionOp = new SessionOp<>(); + JSONExportSession jsonExportSession = sessionOp.get(httpRequest, + serviceCredentials, SessionConstants.JSON_EXPORT_SESSION); + return jsonExportSession; + + } + + // + public static void setCSVFileUploadSession(HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials, + CSVFileUploadSession csvFileUploadSession) { + ScopeProvider.instance.set(serviceCredentials.getScope()); + SessionOp sessionOp = new SessionOp<>(); + sessionOp.set(httpRequest, serviceCredentials, + SessionConstants.CSV_IMPORT_FILE_UPLOAD_SESSION, + csvFileUploadSession); - CSVFileUploadSession session = (CSVFileUploadSession) httpSession - .getAttribute(SessionConstants.CSV_IMPORT_FILE_UPLOAD_SESSION); - if (session != null) - httpSession - .removeAttribute(SessionConstants.CSV_IMPORT_FILE_UPLOAD_SESSION); - httpSession.setAttribute( - SessionConstants.CSV_IMPORT_FILE_UPLOAD_SESSION, s); - ASLSession aslSession = getAslSession(httpSession); - ScopeProvider.instance.set(aslSession.getScope().toString()); } public static CSVFileUploadSession getCSVFileUploadSession( - HttpSession httpSession) { - CSVFileUploadSession fileUploadSession = (CSVFileUploadSession) httpSession - .getAttribute(SessionConstants.CSV_IMPORT_FILE_UPLOAD_SESSION); - if (fileUploadSession == null) { - logger.error("CSVFileUploadSession was not acquired"); - } - return fileUploadSession; - } - - public static void setCodelistMappingFileUploadSession( - HttpSession httpSession, CodelistMappingFileUploadSession s) - throws TDGWTSessionExpiredException { - - CodelistMappingFileUploadSession session = (CodelistMappingFileUploadSession) httpSession - .getAttribute(SessionConstants.CODELIST_MAPPING_FILE_UPLOAD_SESSION); - if (session != null) - httpSession - .removeAttribute(SessionConstants.CODELIST_MAPPING_FILE_UPLOAD_SESSION); - httpSession.setAttribute( - SessionConstants.CODELIST_MAPPING_FILE_UPLOAD_SESSION, s); - ASLSession aslSession = getAslSession(httpSession); - ScopeProvider.instance.set(aslSession.getScope().toString()); - } - - public static CodelistMappingFileUploadSession getCodelistMappingFileUploadSession( - HttpSession httpSession) { - CodelistMappingFileUploadSession fileUploadSession = (CodelistMappingFileUploadSession) httpSession - .getAttribute(SessionConstants.CODELIST_MAPPING_FILE_UPLOAD_SESSION); - if (fileUploadSession == null) { - logger.error("CodelistMappingFileUploadSession was not acquired"); - } - return fileUploadSession; + HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials) { + SessionOp sessionOp = new SessionOp<>(); + CSVFileUploadSession csvFileUploadSession = sessionOp.get(httpRequest, + serviceCredentials, + SessionConstants.CSV_IMPORT_FILE_UPLOAD_SESSION); + return csvFileUploadSession; } // - public static ArrayList retrieveCodelists(HttpSession httpSession) - throws Exception { - logger.info("SessionUtil retriveCodelists"); - SDMXClient client = getSdmxClient(httpSession); - ASLSession aslSession = getAslSession(httpSession); - ScopeProvider.instance.set(aslSession.getScope().toString()); + public static void setCodelistMappingFileUploadSession( + HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials, + CodelistMappingFileUploadSession codelistMappingFileUploadSession) { + ScopeProvider.instance.set(serviceCredentials.getScope()); + SessionOp sessionOp = new SessionOp<>(); + sessionOp.set(httpRequest, serviceCredentials, + SessionConstants.CODELIST_MAPPING_FILE_UPLOAD_SESSION, + codelistMappingFileUploadSession); + } + + public static CodelistMappingFileUploadSession getCodelistMappingFileUploadSession( + HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials) { + SessionOp sessionOp = new SessionOp<>(); + CodelistMappingFileUploadSession codelistMappingFileUploadSession = sessionOp + .get(httpRequest, serviceCredentials, + SessionConstants.CODELIST_MAPPING_FILE_UPLOAD_SESSION); + return codelistMappingFileUploadSession; + + } + + // + public static ArrayList retrieveCodelists( + HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials) throws Exception { + logger.info("SessionUtil retrieveCodelists"); + ScopeProvider.instance.set(serviceCredentials.getScope()); + SDMXClient client = getSdmxClient(httpRequest, serviceCredentials); return client.getAllCodelists(); } - public static ArrayList retrieveDatasets(HttpSession httpSession) - throws Exception { - logger.info("SessionUtil retriveDatasets"); - SDMXClient client = getSdmxClient(httpSession); - ASLSession aslSession = getAslSession(httpSession); - ScopeProvider.instance.set(aslSession.getScope().toString()); + public static ArrayList retrieveDatasets( + HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials) throws Exception { + logger.info("SessionUtil retrieveDatasets"); + ScopeProvider.instance.set(serviceCredentials.getScope()); + SDMXClient client = getSdmxClient(httpRequest, serviceCredentials); return client.getAllDatasets(); } - public static ArrayList retrieveAgencies(HttpSession httpSession) - throws Exception { - logger.info("SessionUtil retriveAgencies"); - SDMXClient client = getSdmxClient(httpSession); - ASLSession aslSession = getAslSession(httpSession); - ScopeProvider.instance.set(aslSession.getScope().toString()); + public static ArrayList retrieveAgencies( + HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials) throws Exception { + logger.info("SessionUtil retrieveAgencies"); + ScopeProvider.instance.set(serviceCredentials.getScope()); + SDMXClient client = getSdmxClient(httpRequest, serviceCredentials); return client.getAllAgencies(); } - public static void setSDMXRegistrySource(HttpSession httpSession, - SDMXRegistrySource sdmxRegistrySource) - throws TDGWTSessionExpiredException { + // + public static void setSDMXRegistrySource(HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials, + SDMXRegistrySource sdmxRegistrySource) { + ScopeProvider.instance.set(serviceCredentials.getScope()); + SessionOp sessionOp = new SessionOp<>(); + sessionOp.set(httpRequest, serviceCredentials, + SessionConstants.SDMX_REGISTRY_SOURCE, sdmxRegistrySource); - SDMXRegistrySource source = (SDMXRegistrySource) httpSession - .getAttribute(SessionConstants.SDMX_REGISTRY_SOURCE); - if (source != null) - httpSession.removeAttribute(SessionConstants.SDMX_REGISTRY_SOURCE); - httpSession.setAttribute(SessionConstants.SDMX_REGISTRY_SOURCE, - sdmxRegistrySource); - ASLSession aslSession = getAslSession(httpSession); - ScopeProvider.instance.set(aslSession.getScope().toString()); } public static SDMXRegistrySource getSDMXRegistrySource( - HttpSession httpSession) { - SDMXRegistrySource sdmxRegistrySource = (SDMXRegistrySource) httpSession - .getAttribute(SessionConstants.SDMX_REGISTRY_SOURCE); - if (sdmxRegistrySource == null) { - logger.error("SDMXRegistrySource was not acquired"); - } + HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials) { + SessionOp sessionOp = new SessionOp<>(); + SDMXRegistrySource sdmxRegistrySource = sessionOp.get(httpRequest, + serviceCredentials, SessionConstants.SDMX_REGISTRY_SOURCE); return sdmxRegistrySource; + } - public static SDMXClient getSdmxClient(HttpSession httpSession) { - SDMXClient sdmxClient = (SDMXClient) httpSession - .getAttribute(SessionConstants.SDMX_CLIENT_ATTRIBUTE); - SDMXRegistrySource sdmxRegistrySource = (SDMXRegistrySource) httpSession - .getAttribute(SessionConstants.SDMX_REGISTRY_SOURCE); + // + public static SDMXClient getSDMXClientInSession( + HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials) { + SessionOp sessionOp = new SessionOp<>(); + SDMXClient sdmxClient = sessionOp.get(httpRequest, serviceCredentials, + SessionConstants.SDMX_CLIENT_ATTRIBUTE); + return sdmxClient; + } + + public static void setSDMXClientInSession(HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials, SDMXClient sdmxClient) { + ScopeProvider.instance.set(serviceCredentials.getScope()); + SessionOp sessionOp = new SessionOp<>(); + sessionOp.set(httpRequest, serviceCredentials, + SessionConstants.SDMX_CLIENT_ATTRIBUTE, sdmxClient); + } + + // + public static SDMXClient getSdmxClient(HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials) { + // HttpSession httpSession = httpRequest.getSession(); + SDMXClient sdmxClient = getSDMXClientInSession(httpRequest, + serviceCredentials); + SDMXRegistrySource sdmxRegistrySource = getSDMXRegistrySource( + httpRequest, serviceCredentials); if (sdmxRegistrySource == null) { logger.error("SDMXRegistrySource was not acquired"); } else { @@ -877,7 +898,7 @@ public class SessionUtil { if (sdmxClient == null) { sdmxClient = new SDMXClient(); } else { - if (sdmxClient.type.compareTo(SDMXClient.TYPE.ANOTHER) == 0) { + if (sdmxClient.getType().compareTo(SDMXClient.TYPE.ANOTHER) == 0) { sdmxClient = new SDMXClient(); } } @@ -885,17 +906,17 @@ public class SessionUtil { if (sdmxClient == null) { sdmxClient = new SDMXClient(url); } else { - if (sdmxClient.type.compareTo(SDMXClient.TYPE.INTERNAL) == 0) { + if (sdmxClient.getType() + .compareTo(SDMXClient.TYPE.INTERNAL) == 0) { sdmxClient = new SDMXClient(url); } else { - if (sdmxClient.url.compareTo(url) != 0) { + if (sdmxClient.getUrl().compareTo(url) != 0) { sdmxClient = new SDMXClient(url); } } } } - httpSession.setAttribute(SessionConstants.SDMX_CLIENT_ATTRIBUTE, - sdmxClient); + setSDMXClientInSession(httpRequest, serviceCredentials, sdmxClient); } @@ -903,504 +924,397 @@ public class SessionUtil { } // - public static void setCSVExportEnd(HttpSession httpSession, Boolean end) { - Boolean fin = (Boolean) httpSession - .getAttribute(SessionConstants.CSV_EXPORT_END); - if (fin != null) - httpSession.removeAttribute(SessionConstants.CSV_EXPORT_END); - httpSession.setAttribute(SessionConstants.CSV_EXPORT_END, end); + public static void setCSVExportEnd(HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials, Boolean end) { + ScopeProvider.instance.set(serviceCredentials.getScope()); + SessionOp sessionOp = new SessionOp<>(); + sessionOp.set(httpRequest, serviceCredentials, + SessionConstants.CSV_EXPORT_END, end); + } - public static Boolean getCSVExportEnd(HttpSession httpSession) { - Boolean end = (Boolean) httpSession - .getAttribute(SessionConstants.CSV_EXPORT_END); - logger.debug("getCSVExportEnd(): " + end); + public static Boolean getCSVExportEnd(HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials) { + SessionOp sessionOp = new SessionOp<>(); + Boolean end = sessionOp.get(httpRequest, serviceCredentials, + SessionConstants.CSV_EXPORT_END); if (end == null) { - logger.error("CSV_EXPORT_END was not acquired"); end = false; } return end; } // - public static void setJSONExportEnd(HttpSession httpSession, Boolean end) { - Boolean fin = (Boolean) httpSession - .getAttribute(SessionConstants.JSON_EXPORT_END); - if (fin != null) - httpSession.removeAttribute(SessionConstants.JSON_EXPORT_END); - httpSession.setAttribute(SessionConstants.JSON_EXPORT_END, end); + public static void setJSONExportEnd(HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials, Boolean end) { + SessionOp sessionOp = new SessionOp<>(); + sessionOp.set(httpRequest, serviceCredentials, + SessionConstants.JSON_EXPORT_END, end); + } - public static Boolean getJSONExportEnd(HttpSession httpSession) { - Boolean end = (Boolean) httpSession - .getAttribute(SessionConstants.JSON_EXPORT_END); - logger.debug("getJSONExportEnd(): " + end); + public static Boolean getJSONExportEnd(HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials) { + SessionOp sessionOp = new SessionOp<>(); + Boolean end = sessionOp.get(httpRequest, serviceCredentials, + SessionConstants.JSON_EXPORT_END); if (end == null) { - logger.error("JSON_EXPORT_END was not acquired"); end = false; } return end; } // - public static TRTasksManager getTRTasksManager(HttpSession httpSession) { - TRTasksManager tasksManager = (TRTasksManager) httpSession - .getAttribute(SessionConstants.TR_TASK_MANAGER); - if (tasksManager != null) { - return tasksManager; - } else { - tasksManager = new TRTasksManager(); - httpSession.setAttribute(SessionConstants.TR_TASK_MANAGER, - tasksManager); - return tasksManager; - } + public static TRTasksManager getTRTasksManager( + HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials) throws TDGWTServiceException { + SessionOp sessionOp = new SessionOp<>(); + TRTasksManager tasksManager = sessionOp.get(httpRequest, + serviceCredentials, SessionConstants.TR_TASK_MANAGER, + TRTasksManager.class); + + return tasksManager; + } - public static void setTRTasksManager(HttpSession httpSession, - TRTasksManager trTasksManager) { - TRTasksManager tm = (TRTasksManager) httpSession - .getAttribute(SessionConstants.TR_TASK_MANAGER); - if (tm != null) { - httpSession.removeAttribute(SessionConstants.TR_TASK_MANAGER); - } - httpSession.setAttribute(SessionConstants.TR_TASK_MANAGER, - trTasksManager); - + public static void setTRTasksManager(HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials, TRTasksManager trTasksManager) { + SessionOp sessionOp = new SessionOp<>(); + sessionOp.set(httpRequest, serviceCredentials, + SessionConstants.TR_TASK_MANAGER, trTasksManager); } // public static ChangeColumnTypeSession getChangeColumnTypeSession( - HttpSession httpSession) { - ChangeColumnTypeSession changeColumnTypeSession = (ChangeColumnTypeSession) httpSession - .getAttribute(SessionConstants.CHANGE_COLUMN_TYPE_SESSION); - if (changeColumnTypeSession != null) { - return changeColumnTypeSession; - } else { - changeColumnTypeSession = new ChangeColumnTypeSession(); - httpSession.setAttribute( - SessionConstants.CHANGE_COLUMN_TYPE_SESSION, - changeColumnTypeSession); - return changeColumnTypeSession; - } + HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials) throws TDGWTServiceException { + SessionOp sessionOp = new SessionOp<>(); + ChangeColumnTypeSession changeColumnTypeSession = sessionOp.get( + httpRequest, serviceCredentials, + SessionConstants.CHANGE_COLUMN_TYPE_SESSION, + ChangeColumnTypeSession.class); + + return changeColumnTypeSession; + } - public static void setChangeColumnTypeSession(HttpSession httpSession, + public static void setChangeColumnTypeSession( + HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials, ChangeColumnTypeSession changeColumnTypeSession) { - ChangeColumnTypeSession ct = (ChangeColumnTypeSession) httpSession - .getAttribute(SessionConstants.CHANGE_COLUMN_TYPE_SESSION); - if (ct != null) { - httpSession - .removeAttribute(SessionConstants.CHANGE_COLUMN_TYPE_SESSION); - } - httpSession.setAttribute(SessionConstants.CHANGE_COLUMN_TYPE_SESSION, + SessionOp sessionOp = new SessionOp<>(); + sessionOp.set(httpRequest, serviceCredentials, + SessionConstants.CHANGE_COLUMN_TYPE_SESSION, changeColumnTypeSession); - } - // / - + // public static LabelColumnSession getLabelColumnSession( - HttpSession httpSession) { - LabelColumnSession labelColumnSession = (LabelColumnSession) httpSession - .getAttribute(SessionConstants.CHANGE_THE_COLUMN_LABEL_SESSION); - if (labelColumnSession != null) { - return labelColumnSession; - } else { - labelColumnSession = new LabelColumnSession(); - httpSession.setAttribute( - SessionConstants.CHANGE_THE_COLUMN_LABEL_SESSION, - labelColumnSession); - return labelColumnSession; - } + HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials) throws TDGWTServiceException { + SessionOp sessionOp = new SessionOp<>(); + LabelColumnSession labelColumnSession = sessionOp.get(httpRequest, + serviceCredentials, + SessionConstants.CHANGE_THE_COLUMN_LABEL_SESSION, + LabelColumnSession.class); + + return labelColumnSession; } - public static void setLabelColumnSession(HttpSession httpSession, + // + public static void setLabelColumnSession(HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials, LabelColumnSession labelColumnSession) { - LabelColumnSession lc = (LabelColumnSession) httpSession - .getAttribute(SessionConstants.CHANGE_THE_COLUMN_LABEL_SESSION); - if (lc != null) { - httpSession - .removeAttribute(SessionConstants.CHANGE_THE_COLUMN_LABEL_SESSION); - } - httpSession.setAttribute( + SessionOp sessionOp = new SessionOp<>(); + sessionOp.set(httpRequest, serviceCredentials, SessionConstants.CHANGE_THE_COLUMN_LABEL_SESSION, labelColumnSession); - } // + public static AddColumnSession getAddColumnSession(HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials) throws TDGWTServiceException { + SessionOp sessionOp = new SessionOp<>(); + AddColumnSession addColumnSession = sessionOp.get(httpRequest, + serviceCredentials, + SessionConstants.ADD_COLUMN_SESSION, + AddColumnSession.class); - public static AddColumnSession getAddColumnSession(HttpSession httpSession) { - AddColumnSession addColumnSession = (AddColumnSession) httpSession - .getAttribute(SessionConstants.ADD_COLUMN_SESSION); - if (addColumnSession != null) { - return addColumnSession; - } else { - addColumnSession = new AddColumnSession(); - httpSession.setAttribute(SessionConstants.ADD_COLUMN_SESSION, - addColumnSession); - return addColumnSession; - } + return addColumnSession; } - public static void setAddColumnSession(HttpSession httpSession, + public static void setAddColumnSession(HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials, AddColumnSession addColumnSession) { - AddColumnSession ac = (AddColumnSession) httpSession - .getAttribute(SessionConstants.ADD_COLUMN_SESSION); - if (ac != null) { - httpSession.removeAttribute(SessionConstants.ADD_COLUMN_SESSION); - } - httpSession.setAttribute(SessionConstants.ADD_COLUMN_SESSION, + SessionOp sessionOp = new SessionOp<>(); + sessionOp.set(httpRequest, serviceCredentials, + SessionConstants.ADD_COLUMN_SESSION, addColumnSession); - } // - public static DeleteColumnSession getDeleteColumnSession( - HttpSession httpSession) { - DeleteColumnSession deleteColumnSession = (DeleteColumnSession) httpSession - .getAttribute(SessionConstants.DELETE_COLUMN_SESSION); - if (deleteColumnSession != null) { - return deleteColumnSession; - } else { - deleteColumnSession = new DeleteColumnSession(); - httpSession.setAttribute(SessionConstants.DELETE_COLUMN_SESSION, - deleteColumnSession); - return deleteColumnSession; - } + HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials) throws TDGWTServiceException { + SessionOp sessionOp = new SessionOp<>(); + DeleteColumnSession deleteColumnSession = sessionOp.get(httpRequest, + serviceCredentials, + SessionConstants.DELETE_COLUMN_SESSION, + DeleteColumnSession.class); + + return deleteColumnSession; + } - public static void setDeleteColumnSession(HttpSession httpSession, + public static void setDeleteColumnSession(HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials, DeleteColumnSession deleteColumnSession) { - DeleteColumnSession dc = (DeleteColumnSession) httpSession - .getAttribute(SessionConstants.DELETE_COLUMN_SESSION); - if (dc != null) { - httpSession.removeAttribute(SessionConstants.DELETE_COLUMN_SESSION); - } - httpSession.setAttribute(SessionConstants.DELETE_COLUMN_SESSION, + SessionOp sessionOp = new SessionOp<>(); + sessionOp.set(httpRequest, serviceCredentials, + SessionConstants.DELETE_COLUMN_SESSION, deleteColumnSession); - } + // - public static FilterColumnSession getFilterColumnSession( - HttpSession httpSession) { - FilterColumnSession filterColumnSession = (FilterColumnSession) httpSession - .getAttribute(SessionConstants.FILTER_COLUMN_SESSION); - if (filterColumnSession != null) { - return filterColumnSession; - } else { - filterColumnSession = new FilterColumnSession(); - httpSession.setAttribute(SessionConstants.FILTER_COLUMN_SESSION, - filterColumnSession); - return filterColumnSession; - } + HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials) throws TDGWTServiceException { + SessionOp sessionOp = new SessionOp<>(); + FilterColumnSession filterColumnSession = sessionOp.get(httpRequest, + serviceCredentials, + SessionConstants.FILTER_COLUMN_SESSION, + FilterColumnSession.class); + return filterColumnSession; + + } - public static void setFilterColumnSession(HttpSession httpSession, + public static void setFilterColumnSession(HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials, FilterColumnSession filterColumnSession) { - FilterColumnSession fc = (FilterColumnSession) httpSession - .getAttribute(SessionConstants.FILTER_COLUMN_SESSION); - if (fc != null) { - httpSession.removeAttribute(SessionConstants.FILTER_COLUMN_SESSION); - } - httpSession.setAttribute(SessionConstants.FILTER_COLUMN_SESSION, + SessionOp sessionOp = new SessionOp<>(); + sessionOp.set(httpRequest, serviceCredentials, + SessionConstants.FILTER_COLUMN_SESSION, filterColumnSession); } // public static ReplaceColumnByExpressionSession getReplaceColumnByExpressionSession( - HttpSession httpSession) { - ReplaceColumnByExpressionSession replaceColumnByExpressionSession = (ReplaceColumnByExpressionSession) httpSession - .getAttribute(SessionConstants.REPLACE_COLUMN_BY_EXPRESSION_SESSION); - if (replaceColumnByExpressionSession != null) { - return replaceColumnByExpressionSession; - } else { - replaceColumnByExpressionSession = new ReplaceColumnByExpressionSession(); - httpSession.setAttribute( - SessionConstants.REPLACE_COLUMN_BY_EXPRESSION_SESSION, - replaceColumnByExpressionSession); - return replaceColumnByExpressionSession; - } + HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials) throws TDGWTServiceException { + SessionOp sessionOp = new SessionOp<>(); + ReplaceColumnByExpressionSession replaceColumnByExpressionSession = sessionOp.get(httpRequest, + serviceCredentials, + SessionConstants.REPLACE_COLUMN_BY_EXPRESSION_SESSION, + ReplaceColumnByExpressionSession.class); + return replaceColumnByExpressionSession; } public static void setReplaceColumnByExpressionSession( - HttpSession httpSession, + HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials, ReplaceColumnByExpressionSession replaceColumnByExpressionSession) { - ReplaceColumnByExpressionSession rce = (ReplaceColumnByExpressionSession) httpSession - .getAttribute(SessionConstants.REPLACE_COLUMN_BY_EXPRESSION_SESSION); - if (rce != null) { - httpSession - .removeAttribute(SessionConstants.REPLACE_COLUMN_BY_EXPRESSION_SESSION); - } - httpSession.setAttribute( + SessionOp sessionOp = new SessionOp<>(); + sessionOp.set(httpRequest, serviceCredentials, SessionConstants.REPLACE_COLUMN_BY_EXPRESSION_SESSION, replaceColumnByExpressionSession); - } // public static ApplyAndDetachColumnRulesSession getRulesOnColumnApplyAndDetachSession( - HttpSession httpSession) { - ApplyAndDetachColumnRulesSession applyColumnRulesSession = (ApplyAndDetachColumnRulesSession) httpSession - .getAttribute(SessionConstants.RULES_ON_COLUMN_APPLY_AND_DETACH_SESSION); - if (applyColumnRulesSession != null) { - return applyColumnRulesSession; - } else { - applyColumnRulesSession = new ApplyAndDetachColumnRulesSession(); - httpSession.setAttribute( - SessionConstants.RULES_ON_COLUMN_APPLY_AND_DETACH_SESSION, - applyColumnRulesSession); - return applyColumnRulesSession; - } + HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials) throws TDGWTServiceException { + SessionOp sessionOp = new SessionOp<>(); + ApplyAndDetachColumnRulesSession applyColumnRulesSession = sessionOp.get(httpRequest, + serviceCredentials, + SessionConstants.RULES_ON_COLUMN_APPLY_AND_DETACH_SESSION, + ApplyAndDetachColumnRulesSession.class); + return applyColumnRulesSession; } + public static void setRulesOnColumnApplyAndDetachSession( - HttpSession httpSession, + HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials, ApplyAndDetachColumnRulesSession applyColumnRulesSession) { - ApplyAndDetachColumnRulesSession rules = (ApplyAndDetachColumnRulesSession) httpSession - .getAttribute(SessionConstants.RULES_ON_COLUMN_APPLY_AND_DETACH_SESSION); - if (rules != null) { - httpSession - .removeAttribute(SessionConstants.RULES_ON_COLUMN_APPLY_AND_DETACH_SESSION); - } - httpSession.setAttribute( + SessionOp sessionOp = new SessionOp<>(); + sessionOp.set(httpRequest, serviceCredentials, SessionConstants.RULES_ON_COLUMN_APPLY_AND_DETACH_SESSION, applyColumnRulesSession); - } // public static ApplyTableRuleSession getApplyTableRuleSession( - HttpSession httpSession) { - ApplyTableRuleSession applyTableRuleSession = (ApplyTableRuleSession) httpSession - .getAttribute(SessionConstants.RULES_ON_TABLE_APPLY_SESSION); - if (applyTableRuleSession != null) { - return applyTableRuleSession; - } else { - applyTableRuleSession = new ApplyTableRuleSession(); - httpSession.setAttribute( - SessionConstants.RULES_ON_TABLE_APPLY_SESSION, - applyTableRuleSession); - return applyTableRuleSession; - } + HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials) throws TDGWTServiceException { + SessionOp sessionOp = new SessionOp<>(); + ApplyTableRuleSession applyTableRuleSession = sessionOp.get(httpRequest, + serviceCredentials, + SessionConstants.RULES_ON_TABLE_APPLY_SESSION, + ApplyTableRuleSession.class); + return applyTableRuleSession; } - public static void setApplyTableRuleSession(HttpSession httpSession, + public static void setApplyTableRuleSession(HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials, ApplyTableRuleSession applyTableRuleSession) { - ApplyTableRuleSession atrs = (ApplyTableRuleSession) httpSession - .getAttribute(SessionConstants.RULES_ON_TABLE_APPLY_SESSION); - if (atrs != null) { - httpSession - .removeAttribute(SessionConstants.RULES_ON_TABLE_APPLY_SESSION); - } - httpSession.setAttribute(SessionConstants.RULES_ON_TABLE_APPLY_SESSION, + SessionOp sessionOp = new SessionOp<>(); + sessionOp.set(httpRequest, serviceCredentials, + SessionConstants.RULES_ON_TABLE_APPLY_SESSION, applyTableRuleSession); - } // public static DetachColumnRulesSession getDetachColumnRulesSession( - HttpSession httpSession) { - DetachColumnRulesSession detachColumnRulesSession = (DetachColumnRulesSession) httpSession - .getAttribute(SessionConstants.RULES_ON_COLUMN_DETACH_SESSION); - if (detachColumnRulesSession != null) { - return detachColumnRulesSession; - } else { - detachColumnRulesSession = new DetachColumnRulesSession(); - httpSession.setAttribute( - SessionConstants.RULES_ON_COLUMN_DETACH_SESSION, - detachColumnRulesSession); - return detachColumnRulesSession; - } + HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials) throws TDGWTServiceException { + SessionOp sessionOp = new SessionOp<>(); + DetachColumnRulesSession detachColumnRulesSession = sessionOp.get(httpRequest, + serviceCredentials, + SessionConstants.RULES_ON_COLUMN_DETACH_SESSION, + DetachColumnRulesSession.class); + return detachColumnRulesSession; } - public static void setDetachColumnRulesSession(HttpSession httpSession, + public static void setDetachColumnRulesSession(HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials, DetachColumnRulesSession detachColumnRulesSession) { - DetachColumnRulesSession rules = (DetachColumnRulesSession) httpSession - .getAttribute(SessionConstants.RULES_ON_COLUMN_DETACH_SESSION); - if (rules != null) { - httpSession - .removeAttribute(SessionConstants.RULES_ON_COLUMN_DETACH_SESSION); - } - httpSession.setAttribute( + SessionOp sessionOp = new SessionOp<>(); + sessionOp.set(httpRequest, serviceCredentials, SessionConstants.RULES_ON_COLUMN_DETACH_SESSION, detachColumnRulesSession); - } // public static DetachTableRulesSession getDetachTableRulesSession( - HttpSession httpSession) { - DetachTableRulesSession detachTableRulesSession = (DetachTableRulesSession) httpSession - .getAttribute(SessionConstants.RULES_ON_TABLE_DETACH_SESSION); - if (detachTableRulesSession != null) { - return detachTableRulesSession; - } else { - detachTableRulesSession = new DetachTableRulesSession(); - httpSession.setAttribute( - SessionConstants.RULES_ON_TABLE_DETACH_SESSION, - detachTableRulesSession); - return detachTableRulesSession; - } + HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials) throws TDGWTServiceException { + SessionOp sessionOp = new SessionOp<>(); + DetachTableRulesSession detachTableRulesSession = sessionOp.get(httpRequest, + serviceCredentials, + SessionConstants.RULES_ON_TABLE_DETACH_SESSION, + DetachTableRulesSession.class); + return detachTableRulesSession; } - - public static void setDetachTableRulesSession(HttpSession httpSession, + + + public static void setDetachTableRulesSession(HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials, DetachTableRulesSession detachTableRulesSession) { - DetachTableRulesSession rules = (DetachTableRulesSession) httpSession - .getAttribute(SessionConstants.RULES_ON_TABLE_DETACH_SESSION); - if (rules != null) { - httpSession - .removeAttribute(SessionConstants.RULES_ON_TABLE_DETACH_SESSION); - } - httpSession.setAttribute( + SessionOp sessionOp = new SessionOp<>(); + sessionOp.set(httpRequest, serviceCredentials, SessionConstants.RULES_ON_TABLE_DETACH_SESSION, detachTableRulesSession); - } // public static TaskResubmitSession getTaskResubmitSession( - HttpSession httpSession) { - TaskResubmitSession taskResubmitSession = (TaskResubmitSession) httpSession - .getAttribute(SessionConstants.TASK_RESUBMIT_SESSION); - if (taskResubmitSession != null) { - return taskResubmitSession; - } else { - taskResubmitSession = new TaskResubmitSession(); - httpSession.setAttribute(SessionConstants.TASK_RESUBMIT_SESSION, - taskResubmitSession); - return taskResubmitSession; - } + HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials) throws TDGWTServiceException { + SessionOp sessionOp = new SessionOp<>(); + TaskResubmitSession taskResubmitSession = sessionOp.get(httpRequest, + serviceCredentials, + SessionConstants.TASK_RESUBMIT_SESSION, + TaskResubmitSession.class); + return taskResubmitSession; } - public static void setTaskResubmitSession(HttpSession httpSession, + public static void setTaskResubmitSession(HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials, TaskResubmitSession taskResubmitSession) { - TaskResubmitSession tr = (TaskResubmitSession) httpSession - .getAttribute(SessionConstants.TASK_RESUBMIT_SESSION); - if (tr != null) { - httpSession.removeAttribute(SessionConstants.TASK_RESUBMIT_SESSION); - } - httpSession.setAttribute(SessionConstants.TASK_RESUBMIT_SESSION, + SessionOp sessionOp = new SessionOp<>(); + sessionOp.set(httpRequest, serviceCredentials, + SessionConstants.TASK_RESUBMIT_SESSION, taskResubmitSession); - } // - public static TaskResumeSession getTaskResumeSession(HttpSession httpSession) { - TaskResumeSession taskResumeSession = (TaskResumeSession) httpSession - .getAttribute(SessionConstants.TASK_RESUME_SESSION); - if (taskResumeSession != null) { - return taskResumeSession; - } else { - taskResumeSession = new TaskResumeSession(); - httpSession.setAttribute(SessionConstants.TASK_RESUME_SESSION, - taskResumeSession); - return taskResumeSession; - } + public static TaskResumeSession getTaskResumeSession(HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials) throws TDGWTServiceException { + SessionOp sessionOp = new SessionOp<>(); + TaskResumeSession taskResumeSession = sessionOp.get(httpRequest, + serviceCredentials, + SessionConstants.TASK_RESUME_SESSION, + TaskResumeSession.class); + return taskResumeSession; + } - public static void setTaskResumeSession(HttpSession httpSession, + public static void setTaskResumeSession(HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials, TaskResumeSession taskResumeSession) { - TaskResumeSession tr = (TaskResumeSession) httpSession - .getAttribute(SessionConstants.TASK_RESUME_SESSION); - if (tr != null) { - httpSession.removeAttribute(SessionConstants.TASK_RESUME_SESSION); - } - httpSession.setAttribute(SessionConstants.TASK_RESUME_SESSION, + SessionOp sessionOp = new SessionOp<>(); + sessionOp.set(httpRequest, serviceCredentials, + SessionConstants.TASK_RESUME_SESSION, taskResumeSession); - } // - public static EditRowSession getEditRowSession(HttpSession httpSession) { - EditRowSession editRowSession = (EditRowSession) httpSession - .getAttribute(SessionConstants.EDIT_ROW_SESSION); - if (editRowSession != null) { - return editRowSession; - } else { - editRowSession = new EditRowSession(); - httpSession.setAttribute(SessionConstants.EDIT_ROW_SESSION, - editRowSession); - return editRowSession; - } + public static EditRowSession getEditRowSession(HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials) throws TDGWTServiceException { + SessionOp sessionOp = new SessionOp<>(); + EditRowSession editRowSession = sessionOp.get(httpRequest, + serviceCredentials, + SessionConstants.EDIT_ROW_SESSION, + EditRowSession.class); + return editRowSession; } - public static void setEditRowSession(HttpSession httpSession, + + public static void setEditRowSession(HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials, EditRowSession editRowSession) { - EditRowSession er = (EditRowSession) httpSession - .getAttribute(SessionConstants.EDIT_ROW_SESSION); - if (er != null) { - httpSession.removeAttribute(SessionConstants.EDIT_ROW_SESSION); - } - httpSession.setAttribute(SessionConstants.EDIT_ROW_SESSION, + SessionOp sessionOp = new SessionOp<>(); + sessionOp.set(httpRequest, serviceCredentials, + SessionConstants.EDIT_ROW_SESSION, editRowSession); - } // - public static ReplaceColumnSession getReplaceColumnSession( - HttpSession httpSession) { - ReplaceColumnSession replaceColumnSession = (ReplaceColumnSession) httpSession - .getAttribute(SessionConstants.REPLACE_COLUMN_SESSION); - if (replaceColumnSession != null) { - return replaceColumnSession; - } else { - replaceColumnSession = new ReplaceColumnSession(); - httpSession.setAttribute(SessionConstants.REPLACE_COLUMN_SESSION, - replaceColumnSession); - return replaceColumnSession; - } + HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials) throws TDGWTServiceException { + SessionOp sessionOp = new SessionOp<>(); + ReplaceColumnSession replaceColumnSession = sessionOp.get(httpRequest, + serviceCredentials, + SessionConstants.REPLACE_COLUMN_SESSION, + ReplaceColumnSession.class); + return replaceColumnSession; } - public static void setReplaceColumnSession(HttpSession httpSession, + public static void setReplaceColumnSession(HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials, ReplaceColumnSession replaceColumnSession) { - ReplaceColumnSession rc = (ReplaceColumnSession) httpSession - .getAttribute(SessionConstants.REPLACE_COLUMN_SESSION); - if (rc != null) { - httpSession - .removeAttribute(SessionConstants.REPLACE_COLUMN_SESSION); - } - httpSession.setAttribute(SessionConstants.REPLACE_COLUMN_SESSION, + SessionOp sessionOp = new SessionOp<>(); + sessionOp.set(httpRequest, serviceCredentials, + SessionConstants.REPLACE_COLUMN_SESSION, replaceColumnSession); - } // public static ReplaceBatchColumnSession getReplaceBatchColumnSession( - HttpSession httpSession) { - ReplaceBatchColumnSession replaceBatchColumnSession = (ReplaceBatchColumnSession) httpSession - .getAttribute(SessionConstants.REPLACE_BATCH_COLUMN_SESSION); - if (replaceBatchColumnSession != null) { - return replaceBatchColumnSession; - } else { - replaceBatchColumnSession = new ReplaceBatchColumnSession(); - httpSession.setAttribute( - SessionConstants.REPLACE_BATCH_COLUMN_SESSION, - replaceBatchColumnSession); - return replaceBatchColumnSession; - } + HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials) throws TDGWTServiceException { + SessionOp sessionOp = new SessionOp<>(); + ReplaceBatchColumnSession replaceBatchColumnSession = sessionOp.get(httpRequest, + serviceCredentials, + SessionConstants.REPLACE_BATCH_COLUMN_SESSION, + ReplaceBatchColumnSession.class); + return replaceBatchColumnSession; } - public static void setReplaceBatchColumnSession(HttpSession httpSession, + public static void setReplaceBatchColumnSession(HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials, ReplaceBatchColumnSession replaceBatchColumnSession) { - ReplaceBatchColumnSession rbc = (ReplaceBatchColumnSession) httpSession - .getAttribute(SessionConstants.REPLACE_BATCH_COLUMN_SESSION); - if (rbc != null) { - httpSession - .removeAttribute(SessionConstants.REPLACE_BATCH_COLUMN_SESSION); - } - httpSession.setAttribute(SessionConstants.REPLACE_BATCH_COLUMN_SESSION, + SessionOp sessionOp = new SessionOp<>(); + sessionOp.set(httpRequest, serviceCredentials, + SessionConstants.REPLACE_BATCH_COLUMN_SESSION, replaceBatchColumnSession); - } - // - + //TODO public static ChangeTableTypeSession getChangeTableTypeSession( HttpSession httpSession) { ChangeTableTypeSession changeTableTypeSession = (ChangeTableTypeSession) httpSession