From 10f8849a19bfbb2d26d0a559cc52d235a1fa3848 Mon Sep 17 00:00:00 2001 From: Giancarlo Panichi Date: Fri, 20 Jan 2017 17:08:37 +0000 Subject: [PATCH] Updated to new PortalContext git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-gwt-service@141675 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../user/td/gwtservice/server/SessionOp.java | 14 + .../td/gwtservice/server/SessionUtil.java | 1750 +++++++---------- 2 files changed, 701 insertions(+), 1063 deletions(-) diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/server/SessionOp.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/SessionOp.java index 711f07f..e723017 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/server/SessionOp.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/SessionOp.java @@ -102,5 +102,19 @@ public class SessionOp { httpSession.setAttribute(attribute, map); } } + + public void remove(HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials, String attribute) { + HttpSession httpSession = httpRequest.getSession(); + + @SuppressWarnings("unchecked") + HashMap map = (HashMap) httpSession + .getAttribute(attribute); + + if (map != null) { + map.remove(serviceCredentials.getScope()); + } + } + } 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 8a42f9b..2341d0b 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 @@ -25,7 +25,6 @@ import org.gcube.portlets.user.td.gwtservice.shared.codelisthelper.CodelistMappi 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; import org.gcube.portlets.user.td.gwtservice.shared.geometry.GeometryCreatePointSession; @@ -153,7 +152,7 @@ public class SessionUtil { scope = pContext.getCurrentScope(httpServletRequest); } - + scope = pContext.getCurrentScope(scopeGroupId); if (scope == null || scope.isEmpty()) { String error = "Error retrieving scope: " + scope; logger.error(error); @@ -178,7 +177,7 @@ public class SessionUtil { throw new TDGWTServiceException(error); } - token = pContext.getCurrentUserToken(httpServletRequest); + token = pContext.getCurrentUserToken(scope, userName); if (token == null || token.isEmpty()) { String error = "Error retrieving token for " + userName @@ -243,7 +242,7 @@ public class SessionUtil { /** * * @param httpRequest - * @param scope + * @param serviceCredentials * @return */ public static InfoLocale getInfoLocale(HttpServletRequest httpRequest, @@ -276,7 +275,7 @@ public class SessionUtil { /** * * @param httpRequest - * @param scope + * @param serviceCredentials * @param infoLocale */ public static void setInfoLocale(HttpServletRequest httpRequest, @@ -303,10 +302,10 @@ public class SessionUtil { * Set in session the Tabular Resource List retrieved from service only for * caching * + * * @param httpRequest * @param serviceCredentials * @param trs - * @throws TDGWTSessionExpiredException */ public static void setTabularResources(HttpServletRequest httpRequest, ServiceCredentials serviceCredentials, List trs) { @@ -321,7 +320,6 @@ public class SessionUtil { * @param httpRequest * @param serviceCredentials * @return - * @throws TDGWTSessionExpiredException */ public static TRId getTRId(HttpServletRequest httpRequest, ServiceCredentials serviceCredentials) { @@ -337,7 +335,6 @@ public class SessionUtil { * @param httpRequest * @param serviceCredentials * @param trId - * @throws TDGWTSessionExpiredException */ public static void setTRId(HttpServletRequest httpRequest, ServiceCredentials serviceCredentials, TRId trId) { @@ -352,7 +349,6 @@ public class SessionUtil { * @param httpRequest * @param serviceCredentials * @return - * @throws TDGWTSessionExpiredException */ public static TabResource getTabResource(HttpServletRequest httpRequest, ServiceCredentials serviceCredentials) { @@ -370,7 +366,6 @@ public class SessionUtil { * @param httpRequest * @param serviceCredentials * @param tabResource - * @throws TDGWTSessionExpiredException */ public static void setTabResource(HttpServletRequest httpRequest, ServiceCredentials serviceCredentials, TabResource tabResource) { @@ -387,7 +382,6 @@ public class SessionUtil { * @param httpRequest * @param serviceCredentials * @return - * @throws TDGWTSessionExpiredException */ public static ArrayList getCurrentTabularResourcesOpen( HttpServletRequest httpRequest, @@ -405,7 +399,6 @@ public class SessionUtil { * @param httpRequest * @param serviceCredentials * @param currentTROpen - * @throws TDGWTSessionExpiredException */ public static void setCurrentTabularResourcesOpen( HttpServletRequest httpRequest, @@ -420,9 +413,9 @@ public class SessionUtil { /** * - * @param httpSession + * @param httpRequest + * @param serviceCredentials * @param tabResource - * @throws TDGWTSessionExpiredException */ public static void addToCurrentTabularResourcesOpen( HttpServletRequest httpRequest, @@ -479,9 +472,9 @@ public class SessionUtil { /** * - * @param httpSession + * @param httpRequest + * @param serviceCredentials * @param trId - * @throws TDGWTSessionExpiredException */ public static void removeFromCurrentTabularResourcesOpen( HttpServletRequest httpRequest, @@ -530,32 +523,23 @@ public class SessionUtil { /** * - * @param httpSession - * @throws TDGWTSessionExpiredException + * @param httpRequest + * @param serviceCredentials */ public static void removeAllFromCurrentTabularResourcesOpen( HttpServletRequest httpRequest, ServiceCredentials serviceCredentials) { ScopeProvider.instance.set(serviceCredentials.getScope()); - HttpSession httpSession = httpRequest.getSession(); - - @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(serviceCredentials.getScope()); - } - + SessionOp> sessionOp = new SessionOp<>(); + sessionOp.remove(httpRequest, serviceCredentials, + SessionConstants.SCOPE_TO_CURRENT_TABULAR_RESOURCES_OPEN_MAP); } /** * - * @param httpSession + * @param httpRequest + * @param serviceCredentials * @return - * @throws TDGWTSessionExpiredException */ public static TabResource getFirstFromCurrentTabularResourcesOpen( HttpServletRequest httpRequest, @@ -577,10 +561,10 @@ public class SessionUtil { /** * - * @param httpSession + * @param httpRequest + * @param serviceCredentials * @param trId * @return - * @throws TDGWTSessionExpiredException */ public static TabResource getFromCurrentTabularResourcesOpen( HttpServletRequest httpRequest, @@ -612,9 +596,9 @@ public class SessionUtil { // /** * - * @param httpSession + * @param httpRequest + * @param serviceCredentials * @param tdOpenSession - * @throws TDGWTSessionExpiredException */ public static void setTDOpenSession(HttpServletRequest httpRequest, ServiceCredentials serviceCredentials, TDOpenSession tdOpenSession) { @@ -1008,7 +992,7 @@ public class SessionUtil { changeColumnTypeSession); } - // + // public static LabelColumnSession getLabelColumnSession( HttpServletRequest httpRequest, ServiceCredentials serviceCredentials) throws TDGWTServiceException { @@ -1032,12 +1016,12 @@ public class SessionUtil { } // - public static AddColumnSession getAddColumnSession(HttpServletRequest httpRequest, + public static AddColumnSession getAddColumnSession( + HttpServletRequest httpRequest, ServiceCredentials serviceCredentials) throws TDGWTServiceException { SessionOp sessionOp = new SessionOp<>(); AddColumnSession addColumnSession = sessionOp.get(httpRequest, - serviceCredentials, - SessionConstants.ADD_COLUMN_SESSION, + serviceCredentials, SessionConstants.ADD_COLUMN_SESSION, AddColumnSession.class); return addColumnSession; @@ -1048,8 +1032,7 @@ public class SessionUtil { AddColumnSession addColumnSession) { SessionOp sessionOp = new SessionOp<>(); sessionOp.set(httpRequest, serviceCredentials, - SessionConstants.ADD_COLUMN_SESSION, - addColumnSession); + SessionConstants.ADD_COLUMN_SESSION, addColumnSession); } // @@ -1058,12 +1041,11 @@ public class SessionUtil { ServiceCredentials serviceCredentials) throws TDGWTServiceException { SessionOp sessionOp = new SessionOp<>(); DeleteColumnSession deleteColumnSession = sessionOp.get(httpRequest, - serviceCredentials, - SessionConstants.DELETE_COLUMN_SESSION, + serviceCredentials, SessionConstants.DELETE_COLUMN_SESSION, DeleteColumnSession.class); return deleteColumnSession; - + } public static void setDeleteColumnSession(HttpServletRequest httpRequest, @@ -1071,23 +1053,19 @@ public class SessionUtil { DeleteColumnSession deleteColumnSession) { SessionOp sessionOp = new SessionOp<>(); sessionOp.set(httpRequest, serviceCredentials, - SessionConstants.DELETE_COLUMN_SESSION, - deleteColumnSession); + SessionConstants.DELETE_COLUMN_SESSION, deleteColumnSession); } - // public static FilterColumnSession getFilterColumnSession( HttpServletRequest httpRequest, ServiceCredentials serviceCredentials) throws TDGWTServiceException { SessionOp sessionOp = new SessionOp<>(); FilterColumnSession filterColumnSession = sessionOp.get(httpRequest, - serviceCredentials, - SessionConstants.FILTER_COLUMN_SESSION, + serviceCredentials, SessionConstants.FILTER_COLUMN_SESSION, FilterColumnSession.class); return filterColumnSession; - - + } public static void setFilterColumnSession(HttpServletRequest httpRequest, @@ -1095,8 +1073,7 @@ public class SessionUtil { FilterColumnSession filterColumnSession) { SessionOp sessionOp = new SessionOp<>(); sessionOp.set(httpRequest, serviceCredentials, - SessionConstants.FILTER_COLUMN_SESSION, - filterColumnSession); + SessionConstants.FILTER_COLUMN_SESSION, filterColumnSession); } @@ -1105,10 +1082,10 @@ public class SessionUtil { HttpServletRequest httpRequest, ServiceCredentials serviceCredentials) throws TDGWTServiceException { SessionOp sessionOp = new SessionOp<>(); - ReplaceColumnByExpressionSession replaceColumnByExpressionSession = sessionOp.get(httpRequest, - serviceCredentials, - SessionConstants.REPLACE_COLUMN_BY_EXPRESSION_SESSION, - ReplaceColumnByExpressionSession.class); + ReplaceColumnByExpressionSession replaceColumnByExpressionSession = sessionOp + .get(httpRequest, serviceCredentials, + SessionConstants.REPLACE_COLUMN_BY_EXPRESSION_SESSION, + ReplaceColumnByExpressionSession.class); return replaceColumnByExpressionSession; } @@ -1125,16 +1102,16 @@ public class SessionUtil { // public static ApplyAndDetachColumnRulesSession getRulesOnColumnApplyAndDetachSession( HttpServletRequest httpRequest, - ServiceCredentials serviceCredentials) throws TDGWTServiceException { + ServiceCredentials serviceCredentials) throws TDGWTServiceException { SessionOp sessionOp = new SessionOp<>(); - ApplyAndDetachColumnRulesSession applyColumnRulesSession = sessionOp.get(httpRequest, - serviceCredentials, - SessionConstants.RULES_ON_COLUMN_APPLY_AND_DETACH_SESSION, - ApplyAndDetachColumnRulesSession.class); + ApplyAndDetachColumnRulesSession applyColumnRulesSession = sessionOp + .get(httpRequest, + serviceCredentials, + SessionConstants.RULES_ON_COLUMN_APPLY_AND_DETACH_SESSION, + ApplyAndDetachColumnRulesSession.class); return applyColumnRulesSession; } - public static void setRulesOnColumnApplyAndDetachSession( HttpServletRequest httpRequest, ServiceCredentials serviceCredentials, @@ -1148,10 +1125,10 @@ public class SessionUtil { // public static ApplyTableRuleSession getApplyTableRuleSession( HttpServletRequest httpRequest, - ServiceCredentials serviceCredentials) throws TDGWTServiceException { + ServiceCredentials serviceCredentials) throws TDGWTServiceException { SessionOp sessionOp = new SessionOp<>(); - ApplyTableRuleSession applyTableRuleSession = sessionOp.get(httpRequest, - serviceCredentials, + ApplyTableRuleSession applyTableRuleSession = sessionOp.get( + httpRequest, serviceCredentials, SessionConstants.RULES_ON_TABLE_APPLY_SESSION, ApplyTableRuleSession.class); return applyTableRuleSession; @@ -1171,14 +1148,15 @@ public class SessionUtil { HttpServletRequest httpRequest, ServiceCredentials serviceCredentials) throws TDGWTServiceException { SessionOp sessionOp = new SessionOp<>(); - DetachColumnRulesSession detachColumnRulesSession = sessionOp.get(httpRequest, - serviceCredentials, + DetachColumnRulesSession detachColumnRulesSession = sessionOp.get( + httpRequest, serviceCredentials, SessionConstants.RULES_ON_COLUMN_DETACH_SESSION, DetachColumnRulesSession.class); return detachColumnRulesSession; } - public static void setDetachColumnRulesSession(HttpServletRequest httpRequest, + public static void setDetachColumnRulesSession( + HttpServletRequest httpRequest, ServiceCredentials serviceCredentials, DetachColumnRulesSession detachColumnRulesSession) { SessionOp sessionOp = new SessionOp<>(); @@ -1192,15 +1170,15 @@ public class SessionUtil { HttpServletRequest httpRequest, ServiceCredentials serviceCredentials) throws TDGWTServiceException { SessionOp sessionOp = new SessionOp<>(); - DetachTableRulesSession detachTableRulesSession = sessionOp.get(httpRequest, - serviceCredentials, + DetachTableRulesSession detachTableRulesSession = sessionOp.get( + httpRequest, serviceCredentials, SessionConstants.RULES_ON_TABLE_DETACH_SESSION, DetachTableRulesSession.class); return detachTableRulesSession; } - - - public static void setDetachTableRulesSession(HttpServletRequest httpRequest, + + public static void setDetachTableRulesSession( + HttpServletRequest httpRequest, ServiceCredentials serviceCredentials, DetachTableRulesSession detachTableRulesSession) { SessionOp sessionOp = new SessionOp<>(); @@ -1214,9 +1192,8 @@ public class SessionUtil { HttpServletRequest httpRequest, ServiceCredentials serviceCredentials) throws TDGWTServiceException { SessionOp sessionOp = new SessionOp<>(); - TaskResubmitSession taskResubmitSession = sessionOp.get(httpRequest, - serviceCredentials, - SessionConstants.TASK_RESUBMIT_SESSION, + TaskResubmitSession taskResubmitSession = sessionOp.get(httpRequest, + serviceCredentials, SessionConstants.TASK_RESUBMIT_SESSION, TaskResubmitSession.class); return taskResubmitSession; } @@ -1226,20 +1203,19 @@ public class SessionUtil { TaskResubmitSession taskResubmitSession) { SessionOp sessionOp = new SessionOp<>(); sessionOp.set(httpRequest, serviceCredentials, - SessionConstants.TASK_RESUBMIT_SESSION, - taskResubmitSession); + SessionConstants.TASK_RESUBMIT_SESSION, taskResubmitSession); } // - public static TaskResumeSession getTaskResumeSession(HttpServletRequest httpRequest, + 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 taskResumeSession = sessionOp.get(httpRequest, + serviceCredentials, SessionConstants.TASK_RESUME_SESSION, TaskResumeSession.class); return taskResumeSession; - + } public static void setTaskResumeSession(HttpServletRequest httpRequest, @@ -1247,29 +1223,25 @@ public class SessionUtil { TaskResumeSession taskResumeSession) { SessionOp sessionOp = new SessionOp<>(); sessionOp.set(httpRequest, serviceCredentials, - SessionConstants.TASK_RESUME_SESSION, - taskResumeSession); + SessionConstants.TASK_RESUME_SESSION, taskResumeSession); } // - public static EditRowSession getEditRowSession(HttpServletRequest httpRequest, + 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 editRowSession = sessionOp.get(httpRequest, + serviceCredentials, SessionConstants.EDIT_ROW_SESSION, EditRowSession.class); return editRowSession; } - public static void setEditRowSession(HttpServletRequest httpRequest, - ServiceCredentials serviceCredentials, - EditRowSession editRowSession) { + ServiceCredentials serviceCredentials, EditRowSession editRowSession) { SessionOp sessionOp = new SessionOp<>(); sessionOp.set(httpRequest, serviceCredentials, - SessionConstants.EDIT_ROW_SESSION, - editRowSession); + SessionConstants.EDIT_ROW_SESSION, editRowSession); } // @@ -1277,9 +1249,8 @@ public class SessionUtil { HttpServletRequest httpRequest, ServiceCredentials serviceCredentials) throws TDGWTServiceException { SessionOp sessionOp = new SessionOp<>(); - ReplaceColumnSession replaceColumnSession = sessionOp.get(httpRequest, - serviceCredentials, - SessionConstants.REPLACE_COLUMN_SESSION, + ReplaceColumnSession replaceColumnSession = sessionOp.get(httpRequest, + serviceCredentials, SessionConstants.REPLACE_COLUMN_SESSION, ReplaceColumnSession.class); return replaceColumnSession; } @@ -1289,8 +1260,7 @@ public class SessionUtil { ReplaceColumnSession replaceColumnSession) { SessionOp sessionOp = new SessionOp<>(); sessionOp.set(httpRequest, serviceCredentials, - SessionConstants.REPLACE_COLUMN_SESSION, - replaceColumnSession); + SessionConstants.REPLACE_COLUMN_SESSION, replaceColumnSession); } // @@ -1298,14 +1268,15 @@ public class SessionUtil { HttpServletRequest httpRequest, ServiceCredentials serviceCredentials) throws TDGWTServiceException { SessionOp sessionOp = new SessionOp<>(); - ReplaceBatchColumnSession replaceBatchColumnSession = sessionOp.get(httpRequest, - serviceCredentials, + ReplaceBatchColumnSession replaceBatchColumnSession = sessionOp.get( + httpRequest, serviceCredentials, SessionConstants.REPLACE_BATCH_COLUMN_SESSION, ReplaceBatchColumnSession.class); return replaceBatchColumnSession; } - public static void setReplaceBatchColumnSession(HttpServletRequest httpRequest, + public static void setReplaceBatchColumnSession( + HttpServletRequest httpRequest, ServiceCredentials serviceCredentials, ReplaceBatchColumnSession replaceBatchColumnSession) { SessionOp sessionOp = new SessionOp<>(); @@ -1314,765 +1285,570 @@ public class SessionUtil { replaceBatchColumnSession); } - //TODO + // public static ChangeTableTypeSession getChangeTableTypeSession( - HttpSession httpSession) { - ChangeTableTypeSession changeTableTypeSession = (ChangeTableTypeSession) httpSession - .getAttribute(SessionConstants.CHANGE_TABLE_TYPE_SESSION); - if (changeTableTypeSession != null) { - return changeTableTypeSession; - } else { - changeTableTypeSession = new ChangeTableTypeSession(); - httpSession.setAttribute( - SessionConstants.CHANGE_TABLE_TYPE_SESSION, - changeTableTypeSession); - return changeTableTypeSession; - } + HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials) throws TDGWTServiceException { + SessionOp sessionOp = new SessionOp<>(); + ChangeTableTypeSession changeTableTypeSession = sessionOp.get( + httpRequest, serviceCredentials, + SessionConstants.CHANGE_TABLE_TYPE_SESSION, + ChangeTableTypeSession.class); + return changeTableTypeSession; } - public static void setChangeTableTypeSession(HttpSession httpSession, + public static void setChangeTableTypeSession( + HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials, ChangeTableTypeSession changeTableTypeSession) { - ChangeTableTypeSession ctts = (ChangeTableTypeSession) httpSession - .getAttribute(SessionConstants.CHANGE_TABLE_TYPE_SESSION); - if (ctts != null) { - httpSession - .removeAttribute(SessionConstants.CHANGE_TABLE_TYPE_SESSION); - } - httpSession.setAttribute(SessionConstants.CHANGE_TABLE_TYPE_SESSION, + SessionOp sessionOp = new SessionOp<>(); + sessionOp.set(httpRequest, serviceCredentials, + SessionConstants.CHANGE_TABLE_TYPE_SESSION, changeTableTypeSession); - } - // / - + // public static CloneTabularResourceSession getCloneTabularResourceSession( - HttpSession httpSession) { - CloneTabularResourceSession cloneTabularResourceSession = (CloneTabularResourceSession) httpSession - .getAttribute(SessionConstants.CLONE_TABULAR_RESOURCE_SESSION); - if (cloneTabularResourceSession != null) { - return cloneTabularResourceSession; - } else { - cloneTabularResourceSession = new CloneTabularResourceSession(); - httpSession.setAttribute( - SessionConstants.CLONE_TABULAR_RESOURCE_SESSION, - cloneTabularResourceSession); - return cloneTabularResourceSession; - } + HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials) throws TDGWTServiceException { + SessionOp sessionOp = new SessionOp<>(); + CloneTabularResourceSession cloneTabularResourceSession = sessionOp + .get(httpRequest, serviceCredentials, + SessionConstants.CLONE_TABULAR_RESOURCE_SESSION, + CloneTabularResourceSession.class); + return cloneTabularResourceSession; } - public static void setCloneTabularResourceSession(HttpSession httpSession, + public static void setCloneTabularResourceSession( + HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials, CloneTabularResourceSession cloneTabularResourceSession) { - CloneTabularResourceSession c = (CloneTabularResourceSession) httpSession - .getAttribute(SessionConstants.CLONE_TABULAR_RESOURCE_SESSION); - if (c != null) { - httpSession - .removeAttribute(SessionConstants.CLONE_TABULAR_RESOURCE_SESSION); - } - httpSession.setAttribute( + SessionOp sessionOp = new SessionOp<>(); + sessionOp.set(httpRequest, serviceCredentials, SessionConstants.CLONE_TABULAR_RESOURCE_SESSION, cloneTabularResourceSession); - } - // / - - public static DeleteRowsSession getDeleteRowsSession(HttpSession httpSession) { - DeleteRowsSession deleteRowsSession = (DeleteRowsSession) httpSession - .getAttribute(SessionConstants.DELETE_ROWS_SESSION); - if (deleteRowsSession != null) { - return deleteRowsSession; - } else { - deleteRowsSession = new DeleteRowsSession(); - httpSession.setAttribute(SessionConstants.DELETE_ROWS_SESSION, - deleteRowsSession); - return deleteRowsSession; - } + // + public static DeleteRowsSession getDeleteRowsSession( + HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials) throws TDGWTServiceException { + SessionOp sessionOp = new SessionOp<>(); + DeleteRowsSession deleteRowsSession = sessionOp.get(httpRequest, + serviceCredentials, SessionConstants.DELETE_ROWS_SESSION, + DeleteRowsSession.class); + return deleteRowsSession; } - public static void setDeleteRowsSession(HttpSession httpSession, + public static void setDeleteRowsSession(HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials, DeleteRowsSession deleteRowsSession) { - DeleteRowsSession dr = (DeleteRowsSession) httpSession - .getAttribute(SessionConstants.DELETE_ROWS_SESSION); - if (dr != null) { - httpSession.removeAttribute(SessionConstants.DELETE_ROWS_SESSION); - } - httpSession.setAttribute(SessionConstants.DELETE_ROWS_SESSION, - deleteRowsSession); - + SessionOp sessionOp = new SessionOp<>(); + sessionOp.set(httpRequest, serviceCredentials, + SessionConstants.DELETE_ROWS_SESSION, deleteRowsSession); } // - public static TemplateApplySession getTemplateApplySession( - HttpSession httpSession) { - TemplateApplySession templateApplySession = (TemplateApplySession) httpSession - .getAttribute(SessionConstants.TEMPLATE_APPLY_SESSION); - if (templateApplySession != null) { - return templateApplySession; - } else { - templateApplySession = new TemplateApplySession(); - httpSession.setAttribute(SessionConstants.TEMPLATE_APPLY_SESSION, - templateApplySession); - return templateApplySession; - } + HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials) throws TDGWTServiceException { + SessionOp sessionOp = new SessionOp<>(); + TemplateApplySession templateApplySession = sessionOp.get(httpRequest, + serviceCredentials, SessionConstants.TEMPLATE_APPLY_SESSION, + TemplateApplySession.class); + return templateApplySession; } - public static void setTemplateApplySession(HttpSession httpSession, + public static void setTemplateApplySession(HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials, TemplateApplySession templateApplySession) { - TemplateApplySession dr = (TemplateApplySession) httpSession - .getAttribute(SessionConstants.TEMPLATE_APPLY_SESSION); - if (dr != null) { - httpSession - .removeAttribute(SessionConstants.TEMPLATE_APPLY_SESSION); - } - httpSession.setAttribute(SessionConstants.TEMPLATE_APPLY_SESSION, - templateApplySession); - + SessionOp sessionOp = new SessionOp<>(); + sessionOp.set(httpRequest, serviceCredentials, + SessionConstants.TEMPLATE_APPLY_SESSION, templateApplySession); } // + public static DuplicatesSession getDuplicatesSession( + HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials) throws TDGWTServiceException { + SessionOp sessionOp = new SessionOp<>(); + DuplicatesSession duplicatesSession = sessionOp.get(httpRequest, + serviceCredentials, SessionConstants.DUPLICATES_ROWS_SESSION, + DuplicatesSession.class); + return duplicatesSession; - public static DuplicatesSession getDuplicatesSession(HttpSession httpSession) { - DuplicatesSession duplicatesSession = (DuplicatesSession) httpSession - .getAttribute(SessionConstants.DUPLICATES_ROWS_SESSION); - if (duplicatesSession != null) { - return duplicatesSession; - } else { - duplicatesSession = new DuplicatesSession(); - httpSession.setAttribute(SessionConstants.DUPLICATES_ROWS_SESSION, - duplicatesSession); - return duplicatesSession; - } } - public static void setDuplicatesSession(HttpSession httpSession, + public static void setDuplicatesSession(HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials, DuplicatesSession duplicatesSession) { - DuplicatesSession dr = (DuplicatesSession) httpSession - .getAttribute(SessionConstants.DUPLICATES_ROWS_SESSION); - if (dr != null) { - httpSession - .removeAttribute(SessionConstants.DUPLICATES_ROWS_SESSION); - } - httpSession.setAttribute(SessionConstants.DUPLICATES_ROWS_SESSION, - duplicatesSession); - + SessionOp sessionOp = new SessionOp<>(); + sessionOp.set(httpRequest, serviceCredentials, + SessionConstants.DUPLICATES_ROWS_SESSION, duplicatesSession); } // - public static ArrayList getCodelistsPagingLoaded( - HttpSession httpSession) { - @SuppressWarnings("unchecked") - ArrayList ltr = ((ArrayList) httpSession - .getAttribute(SessionConstants.CODELISTS_PAGING_LOADED)); - if (ltr == null) { - logger.error("CODELISTS_PAGING_LOADED was not acquired"); - } + HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials) throws TDGWTServiceException { + SessionOp> sessionOp = new SessionOp<>(); + ArrayList ltr = sessionOp.get(httpRequest, + serviceCredentials, SessionConstants.CODELISTS_PAGING_LOADED); return ltr; } - public static void setCodelistsPagingLoaded(HttpSession httpSession, + public static void setCodelistsPagingLoaded(HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials, ArrayList listCodelists) { - @SuppressWarnings("unchecked") - ArrayList ltr = ((ArrayList) httpSession - .getAttribute(SessionConstants.CODELISTS_PAGING_LOADED)); - if (ltr != null) - httpSession - .removeAttribute(SessionConstants.CODELISTS_PAGING_LOADED); - httpSession.setAttribute(SessionConstants.CODELISTS_PAGING_LOADED, - listCodelists); + SessionOp> sessionOp = new SessionOp<>(); + sessionOp.set(httpRequest, serviceCredentials, + SessionConstants.CODELISTS_PAGING_LOADED, listCodelists); } + // public static ArrayList getCodelistsPagingLoadedFilteredCopy( - HttpSession httpSession) { - @SuppressWarnings("unchecked") - ArrayList ltrFilteredCopy = ((ArrayList) httpSession - .getAttribute(SessionConstants.CODELISTS_PAGING_LOADED_FILTERED_COPY)); - if (ltrFilteredCopy == null) { - logger.error("CODELISTS_PAGING_LOADED_FILTERED_COPY was not acquired"); - } + HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials) throws TDGWTServiceException { + SessionOp> sessionOp = new SessionOp<>(); + ArrayList ltrFilteredCopy = sessionOp.get(httpRequest, + serviceCredentials, + SessionConstants.CODELISTS_PAGING_LOADED_FILTERED_COPY); return ltrFilteredCopy; } public static void setCodelistsPagingLoadedFilteredCopy( - HttpSession httpSession, + HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials, ArrayList listCodelistsFilteredCopy) { - @SuppressWarnings("unchecked") - ArrayList ltrFilteredCopy = ((ArrayList) httpSession - .getAttribute(SessionConstants.CODELISTS_PAGING_LOADED_FILTERED_COPY)); - if (ltrFilteredCopy != null) - httpSession - .removeAttribute(SessionConstants.CODELISTS_PAGING_LOADED_FILTERED_COPY); - httpSession.setAttribute( + SessionOp> sessionOp = new SessionOp<>(); + sessionOp.set(httpRequest, serviceCredentials, SessionConstants.CODELISTS_PAGING_LOADED_FILTERED_COPY, listCodelistsFilteredCopy); } - public static String getCodelistsPagingLoadedFilter(HttpSession httpSession) { - String filter = (String) httpSession - .getAttribute(SessionConstants.CODELISTS_PAGING_LOADED_FILTER); - if (filter == null) { - logger.error("CODELISTS_PAGING_LOADED_FILTER was not acquired"); - } + // + public static String getCodelistsPagingLoadedFilter( + HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials) throws TDGWTServiceException { + SessionOp sessionOp = new SessionOp<>(); + String filter = sessionOp.get(httpRequest, serviceCredentials, + SessionConstants.CODELISTS_PAGING_LOADED_FILTER); return filter; + } - public static void setCodelistsPagingLoadedFilter(HttpSession httpSession, - String filter) { - - String fil = ((String) httpSession - .getAttribute(SessionConstants.CODELISTS_PAGING_LOADED_FILTER)); - if (fil != null) - httpSession - .removeAttribute(SessionConstants.CODELISTS_PAGING_LOADED_FILTER); - httpSession.setAttribute( + public static void setCodelistsPagingLoadedFilter( + HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials, String filter) { + SessionOp sessionOp = new SessionOp<>(); + sessionOp.set(httpRequest, serviceCredentials, SessionConstants.CODELISTS_PAGING_LOADED_FILTER, filter); } // - - public static RollBackSession getRollBackSession(HttpSession httpSession) { - RollBackSession rollBackSession = (RollBackSession) httpSession - .getAttribute(SessionConstants.ROLLBACK_SESSION); - if (rollBackSession != null) { - return rollBackSession; - } else { - rollBackSession = new RollBackSession(); - httpSession.setAttribute(SessionConstants.ROLLBACK_SESSION, - rollBackSession); - return rollBackSession; - } + public static RollBackSession getRollBackSession( + HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials) throws TDGWTServiceException { + SessionOp sessionOp = new SessionOp<>(); + RollBackSession rollBackSession = sessionOp.get(httpRequest, + serviceCredentials, SessionConstants.ROLLBACK_SESSION, + RollBackSession.class); + return rollBackSession; } - public static void setRollBackSession(HttpSession httpSession, + public static void setRollBackSession(HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials, RollBackSession rollBackSession) { - RollBackSession rb = (RollBackSession) httpSession - .getAttribute(SessionConstants.ROLLBACK_SESSION); - if (rb != null) { - httpSession.removeAttribute(SessionConstants.ROLLBACK_SESSION); - } - httpSession.setAttribute(SessionConstants.ROLLBACK_SESSION, - rollBackSession); - + SessionOp sessionOp = new SessionOp<>(); + sessionOp.set(httpRequest, serviceCredentials, + SessionConstants.ROLLBACK_SESSION, rollBackSession); } // public static ExtractCodelistSession getExtractCodelistSession( - HttpSession httpSession) { - ExtractCodelistSession extractCodelistSession = (ExtractCodelistSession) httpSession - .getAttribute(SessionConstants.EXTRACT_CODELIST_SESSION); - if (extractCodelistSession != null) { - return extractCodelistSession; - } else { - extractCodelistSession = new ExtractCodelistSession(); - httpSession.setAttribute(SessionConstants.EXTRACT_CODELIST_SESSION, - extractCodelistSession); - return extractCodelistSession; - } + HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials) throws TDGWTServiceException { + SessionOp sessionOp = new SessionOp<>(); + ExtractCodelistSession extractCodelistSession = sessionOp.get( + httpRequest, serviceCredentials, + SessionConstants.EXTRACT_CODELIST_SESSION, + ExtractCodelistSession.class); + return extractCodelistSession; } - public static void setExtractCodelistSession(HttpSession httpSession, + public static void setExtractCodelistSession( + HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials, ExtractCodelistSession extractCodelistSession) { - ExtractCodelistSession ec = (ExtractCodelistSession) httpSession - .getAttribute(SessionConstants.EXTRACT_CODELIST_SESSION); - if (ec != null) { - httpSession - .removeAttribute(SessionConstants.EXTRACT_CODELIST_SESSION); - } - httpSession.setAttribute(SessionConstants.EXTRACT_CODELIST_SESSION, + SessionOp sessionOp = new SessionOp<>(); + sessionOp.set(httpRequest, serviceCredentials, + SessionConstants.EXTRACT_CODELIST_SESSION, extractCodelistSession); - } // public static SplitColumnSession getSplitColumnSession( - HttpSession httpSession) { - SplitColumnSession splitColumnSession = (SplitColumnSession) httpSession - .getAttribute(SessionConstants.SPLIT_COLUMN_SESSION); - if (splitColumnSession != null) { - return splitColumnSession; - } else { - splitColumnSession = new SplitColumnSession(); - httpSession.setAttribute(SessionConstants.SPLIT_COLUMN_SESSION, - splitColumnSession); - return splitColumnSession; - } + HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials) throws TDGWTServiceException { + SessionOp sessionOp = new SessionOp<>(); + SplitColumnSession splitColumnSession = sessionOp.get(httpRequest, + serviceCredentials, SessionConstants.SPLIT_COLUMN_SESSION, + SplitColumnSession.class); + return splitColumnSession; } - public static void setSplitColumnSession(HttpSession httpSession, + public static void setSplitColumnSession(HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials, SplitColumnSession splitColumnSession) { - SplitColumnSession sc = (SplitColumnSession) httpSession - .getAttribute(SessionConstants.SPLIT_COLUMN_SESSION); - if (sc != null) { - httpSession.removeAttribute(SessionConstants.SPLIT_COLUMN_SESSION); - } - httpSession.setAttribute(SessionConstants.SPLIT_COLUMN_SESSION, - splitColumnSession); - + SessionOp sessionOp = new SessionOp<>(); + sessionOp.set(httpRequest, serviceCredentials, + SessionConstants.SPLIT_COLUMN_SESSION, splitColumnSession); } // public static MergeColumnSession getMergeColumnSession( - HttpSession httpSession) { - MergeColumnSession mergeColumnSession = (MergeColumnSession) httpSession - .getAttribute(SessionConstants.MERGE_COLUMN_SESSION); - if (mergeColumnSession != null) { - return mergeColumnSession; - } else { - mergeColumnSession = new MergeColumnSession(); - httpSession.setAttribute(SessionConstants.MERGE_COLUMN_SESSION, - mergeColumnSession); - return mergeColumnSession; - } + HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials) throws TDGWTServiceException { + SessionOp sessionOp = new SessionOp<>(); + MergeColumnSession mergeColumnSession = sessionOp.get(httpRequest, + serviceCredentials, SessionConstants.MERGE_COLUMN_SESSION, + MergeColumnSession.class); + return mergeColumnSession; } - public static void setMergeColumnSession(HttpSession httpSession, - MergeColumnSession splitColumnSession) { - MergeColumnSession mc = (MergeColumnSession) httpSession - .getAttribute(SessionConstants.MERGE_COLUMN_SESSION); - if (mc != null) { - httpSession.removeAttribute(SessionConstants.MERGE_COLUMN_SESSION); - } - httpSession.setAttribute(SessionConstants.MERGE_COLUMN_SESSION, - splitColumnSession); - + public static void setMergeColumnSession(HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials, + MergeColumnSession mergeColumnSession) { + SessionOp sessionOp = new SessionOp<>(); + sessionOp.set(httpRequest, serviceCredentials, + SessionConstants.MERGE_COLUMN_SESSION, mergeColumnSession); } // - public static GroupBySession getGroupBySession(HttpSession httpSession) { - GroupBySession groupBySession = (GroupBySession) httpSession - .getAttribute(SessionConstants.GROUPBY_SESSION); - if (groupBySession != null) { - return groupBySession; - } else { - groupBySession = new GroupBySession(); - httpSession.setAttribute(SessionConstants.GROUPBY_SESSION, - groupBySession); - return groupBySession; - } + public static GroupBySession getGroupBySession( + HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials) throws TDGWTServiceException { + SessionOp sessionOp = new SessionOp<>(); + GroupBySession groupBySession = sessionOp.get(httpRequest, + serviceCredentials, SessionConstants.GROUPBY_SESSION, + GroupBySession.class); + return groupBySession; + } - public static void setGroupBySession(HttpSession httpSession, - GroupBySession groupBySession) { - GroupBySession gb = (GroupBySession) httpSession - .getAttribute(SessionConstants.GROUPBY_SESSION); - if (gb != null) { - httpSession.removeAttribute(SessionConstants.GROUPBY_SESSION); - } - httpSession.setAttribute(SessionConstants.GROUPBY_SESSION, - groupBySession); - + public static void setGroupBySession(HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials, GroupBySession groupBySession) { + SessionOp sessionOp = new SessionOp<>(); + sessionOp.set(httpRequest, serviceCredentials, + SessionConstants.GROUPBY_SESSION, groupBySession); } // public static TimeAggregationSession getTimeAggregationSession( - HttpSession httpSession) { - TimeAggregationSession timeAggregationSession = (TimeAggregationSession) httpSession - .getAttribute(SessionConstants.TIME_AGGREGATION_SESSION); - if (timeAggregationSession != null) { - return timeAggregationSession; - } else { - timeAggregationSession = new TimeAggregationSession(); - httpSession.setAttribute(SessionConstants.TIME_AGGREGATION_SESSION, - timeAggregationSession); - return timeAggregationSession; - } + HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials) throws TDGWTServiceException { + SessionOp sessionOp = new SessionOp<>(); + TimeAggregationSession timeAggregationSession = sessionOp.get( + httpRequest, serviceCredentials, + SessionConstants.TIME_AGGREGATION_SESSION, + TimeAggregationSession.class); + return timeAggregationSession; } - public static void setTimeAggregationSession(HttpSession httpSession, + public static void setTimeAggregationSession( + HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials, TimeAggregationSession timeAggregationSession) { - TimeAggregationSession timeAggr = (TimeAggregationSession) httpSession - .getAttribute(SessionConstants.TIME_AGGREGATION_SESSION); - if (timeAggr != null) { - httpSession - .removeAttribute(SessionConstants.TIME_AGGREGATION_SESSION); - } - httpSession.setAttribute(SessionConstants.TIME_AGGREGATION_SESSION, + SessionOp sessionOp = new SessionOp<>(); + sessionOp.set(httpRequest, serviceCredentials, + SessionConstants.TIME_AGGREGATION_SESSION, timeAggregationSession); - } // public static CodelistMappingSession getCodelistMappingSession( - HttpSession httpSession) { - CodelistMappingSession importSession = (CodelistMappingSession) httpSession - .getAttribute(SessionConstants.CODELIST_MAPPING_SESSION); - if (importSession == null) { - logger.error("CSVImportSession was not acquired"); - } - return importSession; + HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials) throws TDGWTServiceException { + SessionOp sessionOp = new SessionOp<>(); + CodelistMappingSession codelistMappingSession = sessionOp.get( + httpRequest, serviceCredentials, + SessionConstants.CODELIST_MAPPING_SESSION); + return codelistMappingSession; } - public static void setCodelistMappingSession(HttpSession httpSession, - CodelistMappingSession codelistMappingSession) - throws TDGWTSessionExpiredException { - - CodelistMappingSession session = (CodelistMappingSession) httpSession - .getAttribute(SessionConstants.CODELIST_MAPPING_SESSION); - if (session != null) - httpSession - .removeAttribute(SessionConstants.CODELIST_MAPPING_SESSION); - httpSession.setAttribute(SessionConstants.CODELIST_MAPPING_SESSION, + public static void setCodelistMappingSession( + HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials, + CodelistMappingSession codelistMappingSession) { + ScopeProvider.instance.set(serviceCredentials.getScope()); + SessionOp sessionOp = new SessionOp<>(); + sessionOp.set(httpRequest, serviceCredentials, + SessionConstants.CODELIST_MAPPING_SESSION, codelistMappingSession); - ASLSession aslSession = getAslSession(httpSession); - ScopeProvider.instance.set(aslSession.getScope().toString()); } // public static NormalizationSession getNormalizationSession( - HttpSession httpSession) { - NormalizationSession normalizationSession = (NormalizationSession) httpSession - .getAttribute(SessionConstants.NORMALIZATION_SESSION); - if (normalizationSession != null) { - return normalizationSession; - } else { - normalizationSession = new NormalizationSession(); - httpSession.setAttribute(SessionConstants.NORMALIZATION_SESSION, - normalizationSession); - return normalizationSession; - } + HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials) throws TDGWTServiceException { + SessionOp sessionOp = new SessionOp<>(); + NormalizationSession normalizationSession = sessionOp.get(httpRequest, + serviceCredentials, SessionConstants.NORMALIZATION_SESSION, + NormalizationSession.class); + return normalizationSession; + } - public static void setNormalizationSession(HttpSession httpSession, + public static void setNormalizationSession(HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials, NormalizationSession normalizationSession) { - NormalizationSession gb = (NormalizationSession) httpSession - .getAttribute(SessionConstants.NORMALIZATION_SESSION); - if (gb != null) { - httpSession.removeAttribute(SessionConstants.NORMALIZATION_SESSION); - } - httpSession.setAttribute(SessionConstants.NORMALIZATION_SESSION, - normalizationSession); - + SessionOp sessionOp = new SessionOp<>(); + sessionOp.set(httpRequest, serviceCredentials, + SessionConstants.NORMALIZATION_SESSION, normalizationSession); } // public static DenormalizationSession getDenormalizationSession( - HttpSession httpSession) { - DenormalizationSession denormalizationSession = (DenormalizationSession) httpSession - .getAttribute(SessionConstants.DENORMALIZATION_SESSION); - if (denormalizationSession != null) { - return denormalizationSession; - } else { - denormalizationSession = new DenormalizationSession(); - httpSession.setAttribute(SessionConstants.DENORMALIZATION_SESSION, - denormalizationSession); - return denormalizationSession; - } + HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials) throws TDGWTServiceException { + SessionOp sessionOp = new SessionOp<>(); + DenormalizationSession denormalizationSession = sessionOp.get( + httpRequest, serviceCredentials, + SessionConstants.DENORMALIZATION_SESSION, + DenormalizationSession.class); + return denormalizationSession; } - public static void setDenormalizationSession(HttpSession httpSession, + public static void setDenormalizationSession( + HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials, DenormalizationSession denormalizationSession) { - DenormalizationSession dn = (DenormalizationSession) httpSession - .getAttribute(SessionConstants.DENORMALIZATION_SESSION); - if (dn != null) { - httpSession - .removeAttribute(SessionConstants.DENORMALIZATION_SESSION); - } - httpSession.setAttribute(SessionConstants.DENORMALIZATION_SESSION, + SessionOp sessionOp = new SessionOp<>(); + sessionOp.set(httpRequest, serviceCredentials, + SessionConstants.DENORMALIZATION_SESSION, denormalizationSession); - } // - public static UnionSession getUnionSession(HttpSession httpSession) { - UnionSession unionSession = (UnionSession) httpSession - .getAttribute(SessionConstants.UNION_SESSION); - if (unionSession != null) { - return unionSession; - } else { - unionSession = new UnionSession(); - httpSession.setAttribute(SessionConstants.UNION_SESSION, - unionSession); - return unionSession; - } + public static UnionSession getUnionSession(HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials) throws TDGWTServiceException { + SessionOp sessionOp = new SessionOp<>(); + UnionSession unionSession = sessionOp.get(httpRequest, + serviceCredentials, SessionConstants.UNION_SESSION, + UnionSession.class); + return unionSession; } - public static void setUnionSession(HttpSession httpSession, - UnionSession unionSession) { - UnionSession us = (UnionSession) httpSession - .getAttribute(SessionConstants.UNION_SESSION); - if (us != null) { - httpSession.removeAttribute(SessionConstants.UNION_SESSION); - } - httpSession.setAttribute(SessionConstants.UNION_SESSION, unionSession); - + public static void setUnionSession(HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials, UnionSession unionSession) { + SessionOp sessionOp = new SessionOp<>(); + sessionOp.set(httpRequest, serviceCredentials, + SessionConstants.UNION_SESSION, unionSession); } // public static ChangeColumnsPositionSession getChangeColumnsPositionSession( - HttpSession httpSession) { - ChangeColumnsPositionSession changeColumnsPositionSession = (ChangeColumnsPositionSession) httpSession - .getAttribute(SessionConstants.CHANGE_COLUMNS_POSITION_SESSION); - if (changeColumnsPositionSession != null) { - return changeColumnsPositionSession; - } else { - changeColumnsPositionSession = new ChangeColumnsPositionSession(); - httpSession.setAttribute( - SessionConstants.CHANGE_COLUMNS_POSITION_SESSION, - changeColumnsPositionSession); - return changeColumnsPositionSession; - } + HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials) throws TDGWTServiceException { + SessionOp sessionOp = new SessionOp<>(); + ChangeColumnsPositionSession changeColumnsPositionSession = sessionOp + .get(httpRequest, serviceCredentials, + SessionConstants.CHANGE_COLUMNS_POSITION_SESSION, + ChangeColumnsPositionSession.class); + return changeColumnsPositionSession; } - public static void setChangeColumnsPositionSession(HttpSession httpSession, + public static void setChangeColumnsPositionSession( + HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials, ChangeColumnsPositionSession changeColumnsPositionSession) { - ChangeColumnsPositionSession ccps = (ChangeColumnsPositionSession) httpSession - .getAttribute(SessionConstants.CHANGE_COLUMNS_POSITION_SESSION); - if (ccps != null) { - httpSession - .removeAttribute(SessionConstants.CHANGE_COLUMNS_POSITION_SESSION); - } - httpSession.setAttribute( + SessionOp sessionOp = new SessionOp<>(); + sessionOp.set(httpRequest, serviceCredentials, SessionConstants.CHANGE_COLUMNS_POSITION_SESSION, changeColumnsPositionSession); - } // public static ReplaceByExternalSession getReplaceByExternalSession( - HttpSession httpSession) { - ReplaceByExternalSession replaceByExternalSession = (ReplaceByExternalSession) httpSession - .getAttribute(SessionConstants.REPLACE_BY_EXTERNAL_SESSION); - if (replaceByExternalSession != null) { - return replaceByExternalSession; - } else { - replaceByExternalSession = new ReplaceByExternalSession(); - httpSession.setAttribute( - SessionConstants.REPLACE_BY_EXTERNAL_SESSION, - replaceByExternalSession); - return replaceByExternalSession; - } + HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials) throws TDGWTServiceException { + SessionOp sessionOp = new SessionOp<>(); + ReplaceByExternalSession replaceByExternalSession = sessionOp.get( + httpRequest, serviceCredentials, + SessionConstants.REPLACE_BY_EXTERNAL_SESSION, + ReplaceByExternalSession.class); + return replaceByExternalSession; } - public static void setReplaceByExternalSession(HttpSession httpSession, + public static void setReplaceByExternalSession( + HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials, ReplaceByExternalSession replaceByExternalSession) { - ReplaceByExternalSession re = (ReplaceByExternalSession) httpSession - .getAttribute(SessionConstants.REPLACE_BY_EXTERNAL_SESSION); - if (re != null) { - httpSession - .removeAttribute(SessionConstants.REPLACE_BY_EXTERNAL_SESSION); - } - httpSession.setAttribute(SessionConstants.REPLACE_BY_EXTERNAL_SESSION, + SessionOp sessionOp = new SessionOp<>(); + sessionOp.set(httpRequest, serviceCredentials, + SessionConstants.REPLACE_BY_EXTERNAL_SESSION, replaceByExternalSession); - } // public static StatisticalOperationSession getStatisticalOperationSession( - HttpSession httpSession) { - StatisticalOperationSession statisticalOperationSession = (StatisticalOperationSession) httpSession - .getAttribute(SessionConstants.STATISTICAL_OPERATION_SESSION); - if (statisticalOperationSession != null) { - return statisticalOperationSession; - } else { - statisticalOperationSession = new StatisticalOperationSession(); - httpSession.setAttribute( - SessionConstants.STATISTICAL_OPERATION_SESSION, - statisticalOperationSession); - return statisticalOperationSession; - } + HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials) throws TDGWTServiceException { + SessionOp sessionOp = new SessionOp<>(); + StatisticalOperationSession statisticalOperationSession = sessionOp + .get(httpRequest, serviceCredentials, + SessionConstants.STATISTICAL_OPERATION_SESSION, + StatisticalOperationSession.class); + return statisticalOperationSession; } - public static void setStatisticalOperationSession(HttpSession httpSession, + public static void setStatisticalOperationSession( + HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials, StatisticalOperationSession statisticalOperationSession) { - StatisticalOperationSession so = (StatisticalOperationSession) httpSession - .getAttribute(SessionConstants.STATISTICAL_OPERATION_SESSION); - if (so != null) { - httpSession - .removeAttribute(SessionConstants.STATISTICAL_OPERATION_SESSION); - } - httpSession.setAttribute( + SessionOp sessionOp = new SessionOp<>(); + sessionOp.set(httpRequest, serviceCredentials, SessionConstants.STATISTICAL_OPERATION_SESSION, statisticalOperationSession); - } - // / - + // public static MapCreationSession getMapCreationSession( - HttpSession httpSession) { - MapCreationSession mapCreationSession = (MapCreationSession) httpSession - .getAttribute(SessionConstants.MAP_CREATION_SESSION); - if (mapCreationSession != null) { - return mapCreationSession; - } else { - mapCreationSession = new MapCreationSession(); - httpSession.setAttribute(SessionConstants.MAP_CREATION_SESSION, - mapCreationSession); - return mapCreationSession; - } + HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials) throws TDGWTServiceException { + SessionOp sessionOp = new SessionOp<>(); + MapCreationSession mapCreationSession = sessionOp.get(httpRequest, + serviceCredentials, SessionConstants.MAP_CREATION_SESSION, + MapCreationSession.class); + return mapCreationSession; } - public static void setMapCreationSession(HttpSession httpSession, + public static void setMapCreationSession(HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials, MapCreationSession mapCreationSession) { - MapCreationSession mapC = (MapCreationSession) httpSession - .getAttribute(SessionConstants.MAP_CREATION_SESSION); - if (mapC != null) { - httpSession.removeAttribute(SessionConstants.MAP_CREATION_SESSION); - } - httpSession.setAttribute(SessionConstants.MAP_CREATION_SESSION, - mapCreationSession); - + SessionOp sessionOp = new SessionOp<>(); + sessionOp.set(httpRequest, serviceCredentials, + SessionConstants.MAP_CREATION_SESSION, mapCreationSession); } - // / - + // public static ChartTopRatingSession getChartTopRatingSession( - HttpSession httpSession) { - ChartTopRatingSession chartTopRatingSession = (ChartTopRatingSession) httpSession - .getAttribute(SessionConstants.CHART_TOPRATING_SESSION); - if (chartTopRatingSession != null) { - return chartTopRatingSession; - } else { - chartTopRatingSession = new ChartTopRatingSession(); - httpSession.setAttribute(SessionConstants.CHART_TOPRATING_SESSION, - chartTopRatingSession); - return chartTopRatingSession; - } + HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials) throws TDGWTServiceException { + SessionOp sessionOp = new SessionOp<>(); + ChartTopRatingSession chartTopRatingSession = sessionOp.get( + httpRequest, serviceCredentials, + SessionConstants.CHART_TOPRATING_SESSION, + ChartTopRatingSession.class); + return chartTopRatingSession; } - public static void setChartTopRatingSession(HttpSession httpSession, + public static void setChartTopRatingSession(HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials, ChartTopRatingSession chartTopRatingSession) { - ChartTopRatingSession chart = (ChartTopRatingSession) httpSession - .getAttribute(SessionConstants.CHART_TOPRATING_SESSION); - if (chart != null) { - httpSession - .removeAttribute(SessionConstants.CHART_TOPRATING_SESSION); - } - httpSession.setAttribute(SessionConstants.CHART_TOPRATING_SESSION, - chartTopRatingSession); - + SessionOp sessionOp = new SessionOp<>(); + sessionOp + .set(httpRequest, serviceCredentials, + SessionConstants.CHART_TOPRATING_SESSION, + chartTopRatingSession); } // Geospatial public static GeospatialCreateCoordinatesSession getGeospatialCreateCoordinatesSession( - HttpSession httpSession) { - GeospatialCreateCoordinatesSession geospatialCreateCoordinatesSession = (GeospatialCreateCoordinatesSession) httpSession - .getAttribute(SessionConstants.GEOSPATIAL_CREATE_COORDINATES_SESSION); - if (geospatialCreateCoordinatesSession != null) { - return geospatialCreateCoordinatesSession; - } else { - geospatialCreateCoordinatesSession = new GeospatialCreateCoordinatesSession(); - httpSession.setAttribute( - SessionConstants.GEOSPATIAL_CREATE_COORDINATES_SESSION, - geospatialCreateCoordinatesSession); - return geospatialCreateCoordinatesSession; - } + HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials) throws TDGWTServiceException { + SessionOp sessionOp = new SessionOp<>(); + GeospatialCreateCoordinatesSession geospatialCreateCoordinatesSession = sessionOp + .get(httpRequest, serviceCredentials, + SessionConstants.GEOSPATIAL_CREATE_COORDINATES_SESSION, + GeospatialCreateCoordinatesSession.class); + return geospatialCreateCoordinatesSession; } public static void setGeospatialCreateCoordinatesSession( - HttpSession httpSession, + HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials, GeospatialCreateCoordinatesSession geospatialCreateCoordinateSession) { - GeospatialCreateCoordinatesSession sc = (GeospatialCreateCoordinatesSession) httpSession - .getAttribute(SessionConstants.GEOSPATIAL_CREATE_COORDINATES_SESSION); - if (sc != null) { - httpSession - .removeAttribute(SessionConstants.GEOSPATIAL_CREATE_COORDINATES_SESSION); - } - httpSession.setAttribute( + SessionOp sessionOp = new SessionOp<>(); + sessionOp.set(httpRequest, serviceCredentials, SessionConstants.GEOSPATIAL_CREATE_COORDINATES_SESSION, geospatialCreateCoordinateSession); - } + // public static GeospatialDownscaleCSquareSession getGeospatialDownscaleCSquareSession( - HttpSession httpSession) { - GeospatialDownscaleCSquareSession geospatialDownscaleCSquareSession = (GeospatialDownscaleCSquareSession) httpSession - .getAttribute(SessionConstants.GEOSPATIAL_DOWNSCALE_CSQUARE_SESSION); - if (geospatialDownscaleCSquareSession != null) { - return geospatialDownscaleCSquareSession; - } else { - geospatialDownscaleCSquareSession = new GeospatialDownscaleCSquareSession(); - httpSession.setAttribute( - SessionConstants.GEOSPATIAL_DOWNSCALE_CSQUARE_SESSION, - geospatialDownscaleCSquareSession); - return geospatialDownscaleCSquareSession; - } + HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials) throws TDGWTServiceException { + SessionOp sessionOp = new SessionOp<>(); + GeospatialDownscaleCSquareSession geospatialDownscaleCSquareSession = sessionOp + .get(httpRequest, serviceCredentials, + SessionConstants.GEOSPATIAL_DOWNSCALE_CSQUARE_SESSION, + GeospatialDownscaleCSquareSession.class); + return geospatialDownscaleCSquareSession; } public static void setGeospatialDownscaleCSquareSession( - HttpSession httpSession, + HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials, GeospatialDownscaleCSquareSession geospatialDownscaleCSquareSession) { - GeospatialDownscaleCSquareSession sc = (GeospatialDownscaleCSquareSession) httpSession - .getAttribute(SessionConstants.GEOSPATIAL_DOWNSCALE_CSQUARE_SESSION); - if (sc != null) { - httpSession - .removeAttribute(SessionConstants.GEOSPATIAL_DOWNSCALE_CSQUARE_SESSION); - } - httpSession.setAttribute( + SessionOp sessionOp = new SessionOp<>(); + sessionOp.set(httpRequest, serviceCredentials, SessionConstants.GEOSPATIAL_DOWNSCALE_CSQUARE_SESSION, geospatialDownscaleCSquareSession); - } // Geometry public static GeometryCreatePointSession getGeometryCreatePointSession( - HttpSession httpSession) { - GeometryCreatePointSession geometryCreatePointSession = (GeometryCreatePointSession) httpSession - .getAttribute(SessionConstants.GEOMETRY_CREATE_POINT_SESSION); - if (geometryCreatePointSession != null) { - return geometryCreatePointSession; - } else { - geometryCreatePointSession = new GeometryCreatePointSession(); - httpSession.setAttribute( - SessionConstants.GEOMETRY_CREATE_POINT_SESSION, - geometryCreatePointSession); - return geometryCreatePointSession; - } + HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials) throws TDGWTServiceException { + SessionOp sessionOp = new SessionOp<>(); + GeometryCreatePointSession geometryCreatePointSession = sessionOp.get( + httpRequest, serviceCredentials, + SessionConstants.GEOMETRY_CREATE_POINT_SESSION, + GeometryCreatePointSession.class); + return geometryCreatePointSession; } - public static void setGeometryCreatePointSession(HttpSession httpSession, + public static void setGeometryCreatePointSession( + HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials, GeometryCreatePointSession geometryCreatePointSession) { - GeometryCreatePointSession geom = (GeometryCreatePointSession) httpSession - .getAttribute(SessionConstants.GEOMETRY_CREATE_POINT_SESSION); - if (geom != null) { - httpSession - .removeAttribute(SessionConstants.GEOMETRY_CREATE_POINT_SESSION); - } - httpSession.setAttribute( + SessionOp sessionOp = new SessionOp<>(); + sessionOp.set(httpRequest, serviceCredentials, SessionConstants.GEOMETRY_CREATE_POINT_SESSION, geometryCreatePointSession); - } + // /** * Retrieve task started * - * @param httpSession + * @param httpRequest + * @param serviceCredentials * @param taskId * @return - * @throws TDGWTSessionExpiredException */ - public static TaskWrapper getStartedTask(HttpSession httpSession, - String taskId) throws TDGWTSessionExpiredException { - ASLSession aslSession = getAslSession(httpSession); - ScopeProvider.instance.set(aslSession.getScope()); + public static TaskWrapper getStartedTask(HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials, String taskId) { + ScopeProvider.instance.set(serviceCredentials.getScope()); TaskWrapper taskWrapper = null; if (taskId == null || taskId.isEmpty()) { logger.error("TaskId is not valid: " + taskId); } else { - @SuppressWarnings("unchecked") - HashMap> scopeToTasksStartedMap = (HashMap>) httpSession - .getAttribute(SessionConstants.SCOPE_TO_OPERATIONS_TASKS_STARTED_MAP); - - if (scopeToTasksStartedMap == null) { + SessionOp> sessionOp = new SessionOp<>(); + HashMap tasksStarted = sessionOp.get( + httpRequest, serviceCredentials, + SessionConstants.SCOPE_TO_OPERATIONS_TASKS_STARTED_MAP); + if (tasksStarted == null) { logger.debug("Task with id=" + taskId + " was not acquired"); } else { - HashMap tasksStarted = scopeToTasksStartedMap - .get(aslSession.getScope()); - if (tasksStarted == null) { + taskWrapper = tasksStarted.get(taskId); + if (taskWrapper == 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"); - } } } - } return taskWrapper; @@ -2081,235 +1857,183 @@ public class SessionUtil { /** * Remove Task Started * - * @param httpSession + * + * @param httpRequest + * @param serviceCredentials * @param taskWrapper - * @throws TDGWTSessionExpiredException */ - public static void removeStartedTask(HttpSession httpSession, - TaskWrapper taskWrapper) throws TDGWTSessionExpiredException { - ASLSession aslSession = getAslSession(httpSession); - ScopeProvider.instance.set(aslSession.getScope()); + public static void removeStartedTask(HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials, TaskWrapper taskWrapper) { + ScopeProvider.instance.set(serviceCredentials.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 invalid Task: " + taskWrapper); return; } - @SuppressWarnings("unchecked") - HashMap> scopeToTasksStartedMap = (HashMap>) httpSession - .getAttribute(SessionConstants.SCOPE_TO_OPERATIONS_TASKS_STARTED_MAP); - - if (scopeToTasksStartedMap == null) { - logger.debug("TaskWrapper was not acquired: " + taskWrapper); + SessionOp> sessionOp = new SessionOp<>(); + HashMap tasksStarted = sessionOp.get(httpRequest, + serviceCredentials, + SessionConstants.SCOPE_TO_OPERATIONS_TASKS_STARTED_MAP); + if (tasksStarted == null) { + logger.debug("Started tasks was not acquired: " + taskWrapper); } else { - HashMap tasksStarted = scopeToTasksStartedMap - .get(aslSession.getScope()); - if (tasksStarted == null) { - logger.debug("TaskWrapper was not acquired: " + taskWrapper); - } else { + if (tasksStarted.containsKey(taskWrapper.getTask().getId() + .getValue())) { 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); + logger.debug("Remove task: " + taskWrapper); + } else { + logger.debug("Started tasks was not acquired: " + taskWrapper); } } - - return; - } /** * Add Task Started * - * @param httpSession + * @param httpRequest + * @param serviceCredentials * @param taskWrapper - * @throws TDGWTSessionExpiredException */ - public static void setStartedTask(HttpSession httpSession, - TaskWrapper taskWrapper) throws TDGWTSessionExpiredException { - ASLSession aslSession = getAslSession(httpSession); - ScopeProvider.instance.set(aslSession.getScope()); + public static void setStartedTask(HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials, TaskWrapper taskWrapper) { + + ScopeProvider.instance.set(serviceCredentials.getScope()); if (taskWrapper == null) { logger.error("TaskWrapper is null"); return; } + if (taskWrapper.getTask() == null + || taskWrapper.getTask().getId() == null + || taskWrapper.getTask().getId().getValue() == null + || taskWrapper.getTask().getId().getValue().isEmpty()) { + logger.error("TaskWrapper contains invalid Task: " + taskWrapper); + return; + } + + SessionOp> sessionOp = new SessionOp<>(); + HashMap tasksStarted = sessionOp.get(httpRequest, + serviceCredentials, + SessionConstants.SCOPE_TO_OPERATIONS_TASKS_STARTED_MAP); + + if (tasksStarted == null) { + tasksStarted = new HashMap(); + tasksStarted.put(taskWrapper.getTask().getId().getValue(), + taskWrapper); + sessionOp = new SessionOp<>(); + sessionOp.set(httpRequest, serviceCredentials, + SessionConstants.SCOPE_TO_OPERATIONS_TASKS_STARTED_MAP, + tasksStarted); + } else { + tasksStarted.put(taskWrapper.getTask().getId().getValue(), + taskWrapper); + } + } + + // + /** + * Retrieve Aborted Task Map + * + * @param httpRequest + * @param serviceCredentials + * @return + */ + public static HashMap getAbortedTaskMap( + HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials) { + ScopeProvider.instance.set(serviceCredentials.getScope()); + + SessionOp> sessionOp = new SessionOp<>(); + HashMap tasksAborted = sessionOp.get(httpRequest, + serviceCredentials, + SessionConstants.SCOPE_TO_OPERATIONS_TASKS_ABORTED_MAP); + + return tasksAborted; + } + + /** + * + * @param httpRequest + * @param serviceCredentials + * @param taskWrapper + */ + public static void setAbortedTasks(HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials, TaskWrapper taskWrapper) { + ScopeProvider.instance.set(serviceCredentials.getScope()); + + if (taskWrapper == null || taskWrapper.getTask() == null) { + logger.error("TaskWrapper is null"); + return; + } + if (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 invalid Task: " + taskWrapper); return; } - @SuppressWarnings("unchecked") - HashMap> scopeToTasksStartedMap = (HashMap>) httpSession - .getAttribute(SessionConstants.SCOPE_TO_OPERATIONS_TASKS_STARTED_MAP); + SessionOp> sessionOp = new SessionOp<>(); + HashMap tasksAborted = sessionOp.get(httpRequest, + serviceCredentials, + SessionConstants.SCOPE_TO_OPERATIONS_TASKS_ABORTED_MAP); - 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) 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) throws TDGWTSessionExpiredException { - ASLSession aslSession = getAslSession(httpSession); - ScopeProvider.instance.set(aslSession.getScope()); - - if (taskWrapper == null) { - logger.error("TaskWrapper is null"); - return; - } - - 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: " - + taskWrapper); - return; - } - - @SuppressWarnings("unchecked") - HashMap> scopeToTasksAbortedMap = (HashMap>) httpSession - .getAttribute(SessionConstants.SCOPE_TO_OPERATIONS_TASKS_ABORTED_MAP); - - if (scopeToTasksAbortedMap == null) { - scopeToTasksAbortedMap = new HashMap>(); - HashMap tasksAborted = new HashMap(); + if (tasksAborted == null) { + tasksAborted = new HashMap(); tasksAborted.put(taskWrapper.getTask().getId().getValue(), taskWrapper); - scopeToTasksAbortedMap.put(aslSession.getScope(), tasksAborted); + sessionOp = new SessionOp<>(); + sessionOp.set(httpRequest, serviceCredentials, + SessionConstants.SCOPE_TO_OPERATIONS_TASKS_ABORTED_MAP, + 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.SCOPE_TO_OPERATIONS_TASKS_ABORTED_MAP); + tasksAborted.put(taskWrapper.getTask().getId().getValue(), + taskWrapper); } - httpSession.setAttribute( - SessionConstants.SCOPE_TO_OPERATIONS_TASKS_ABORTED_MAP, - scopeToTasksAbortedMap); - - return; } + // /** - * Retrive Hidden Task Map + * Retrieve Hidden Task Map * - * @param httpSession + * + * @param httpRequest + * @param serviceCredentials * @return - * @throws TDGWTSessionExpiredException */ public static HashMap getHiddenTaskMap( - HttpSession httpSession) throws TDGWTSessionExpiredException { - ASLSession aslSession = getAslSession(httpSession); - ScopeProvider.instance.set(aslSession.getScope()); + HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials) { + ScopeProvider.instance.set(serviceCredentials.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; - - } + SessionOp> sessionOp = new SessionOp<>(); + HashMap tasksHidden = sessionOp.get(httpRequest, + serviceCredentials, + SessionConstants.SCOPE_TO_OPERATIONS_TASKS_HIDDEN_MAP); + return tasksHidden; } /** * - * @param httpSession + * @param httpRequest + * @param serviceCredentials * @param taskWrapper - * @throws TDGWTSessionExpiredException */ - public static void setHiddenTask(HttpSession httpSession, - TaskWrapper taskWrapper) throws TDGWTSessionExpiredException { - ASLSession aslSession = getAslSession(httpSession); - ScopeProvider.instance.set(aslSession.getScope()); + public static void setHiddenTask(HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials, TaskWrapper taskWrapper) { + ScopeProvider.instance.set(serviceCredentials.getScope()); if (taskWrapper == null) { logger.error("TaskWrapper is null"); @@ -2320,84 +2044,59 @@ public class SessionUtil { || taskWrapper.getTask().getId() == null || taskWrapper.getTask().getId().getValue() == null || taskWrapper.getTask().getId().getValue().isEmpty()) { - logger.error("TaskWrapper contains Task with invalid task id: " - + taskWrapper); + logger.error("TaskWrapper contains invalid Task: " + taskWrapper); return; } - @SuppressWarnings("unchecked") - HashMap> scopeToHiddenTasksMap = (HashMap>) httpSession - .getAttribute(SessionConstants.SCOPE_TO_OPERATIONS_TASKS_HIDDEN_MAP); + SessionOp> sessionOp = new SessionOp<>(); + HashMap tasksHidden = sessionOp.get(httpRequest, + serviceCredentials, + SessionConstants.SCOPE_TO_OPERATIONS_TASKS_HIDDEN_MAP); - if (scopeToHiddenTasksMap == null) { - scopeToHiddenTasksMap = new HashMap>(); - HashMap hiddenTasks = new HashMap(); - hiddenTasks.put(taskWrapper.getTask().getId().getValue(), + if (tasksHidden == null) { + tasksHidden = new HashMap(); + tasksHidden.put(taskWrapper.getTask().getId().getValue(), taskWrapper); - scopeToHiddenTasksMap.put(aslSession.getScope(), hiddenTasks); + sessionOp = new SessionOp<>(); + sessionOp.set(httpRequest, serviceCredentials, + SessionConstants.SCOPE_TO_OPERATIONS_TASKS_HIDDEN_MAP, + tasksHidden); } 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.SCOPE_TO_OPERATIONS_TASKS_HIDDEN_MAP); + tasksHidden.put(taskWrapper.getTask().getId().getValue(), + taskWrapper); } - httpSession.setAttribute( - SessionConstants.SCOPE_TO_OPERATIONS_TASKS_HIDDEN_MAP, - scopeToHiddenTasksMap); - - return; - } /** * Retrieve Tasks In Background * - * @param httpSession + * @param httpRequest + * @param serviceCredentials * @return - * @throws TDGWTSessionExpiredException */ public static HashMap getTaskInBackgroundMap( - 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; - - } + HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials) { + ScopeProvider.instance.set(serviceCredentials.getScope()); + SessionOp> sessionOp = new SessionOp<>(); + HashMap tasksInBackground = sessionOp.get( + httpRequest, serviceCredentials, + SessionConstants.SCOPE_TO_OPERATIONS_TASKS_IN_BACKGROUND_MAP); + return tasksInBackground; } /** * Add Task In Background * - * @param httpSession + * + * @param httpRequest + * @param serviceCredentials * @param taskWrapper - * @throws TDGWTSessionExpiredException */ - public static void setTaskInBackground(HttpSession httpSession, - TaskWrapper taskWrapper) throws TDGWTSessionExpiredException { - ASLSession aslSession = getAslSession(httpSession); - ScopeProvider.instance.set(aslSession.getScope()); + public static void setTaskInBackground(HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials, TaskWrapper taskWrapper) { + ScopeProvider.instance.set(serviceCredentials.getScope()); if (taskWrapper == null) { logger.error("TaskWrapper is null"); @@ -2408,61 +2107,44 @@ public class SessionUtil { || taskWrapper.getTask().getId() == null || taskWrapper.getTask().getId().getValue() == null || taskWrapper.getTask().getId().getValue().isEmpty()) { - logger.error("TaskWrapper contains Task with invalid task id: " - + taskWrapper); + logger.error("TaskWrapper contains invalid Task: " + taskWrapper); return; } - @SuppressWarnings("unchecked") - HashMap> scopeToTasksInBackgroundMap = (HashMap>) httpSession - .getAttribute(SessionConstants.SCOPE_TO_OPERATIONS_TASKS_IN_BACKGROUND_MAP); + SessionOp> sessionOp = new SessionOp<>(); + HashMap tasksInBackground = sessionOp.get( + httpRequest, serviceCredentials, + SessionConstants.SCOPE_TO_OPERATIONS_TASKS_IN_BACKGROUND_MAP); - if (scopeToTasksInBackgroundMap == null) { - scopeToTasksInBackgroundMap = new HashMap>(); - HashMap tasksInBackground = new HashMap(); + if (tasksInBackground == null) { + tasksInBackground = new HashMap(); tasksInBackground.put(taskWrapper.getTask().getId().getValue(), taskWrapper); - scopeToTasksInBackgroundMap.put(aslSession.getScope(), - tasksInBackground); + sessionOp = new SessionOp<>(); + sessionOp + .set(httpRequest, + serviceCredentials, + SessionConstants.SCOPE_TO_OPERATIONS_TASKS_IN_BACKGROUND_MAP, + 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); + tasksInBackground.put(taskWrapper.getTask().getId().getValue(), + taskWrapper); } - httpSession.setAttribute( - SessionConstants.SCOPE_TO_OPERATIONS_TASKS_IN_BACKGROUND_MAP, - scopeToTasksInBackgroundMap); - return; } /** - * Reomove Task from Tasks In Background + * Remove Task from Tasks In Background * - * @param httpSession + * + * @param httpRequest + * @param serviceCredentials * @param taskWrapper - * @throws TDGWTSessionExpiredException */ - public static void removeTaskInBackground(HttpSession httpSession, - TaskWrapper taskWrapper) throws TDGWTSessionExpiredException { + public static void removeTaskInBackground(HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials, TaskWrapper taskWrapper) { - ASLSession aslSession = getAslSession(httpSession); - ScopeProvider.instance.set(aslSession.getScope()); + ScopeProvider.instance.set(serviceCredentials.getScope()); if (taskWrapper == null) { logger.error("TaskWrapper is null"); @@ -2473,90 +2155,59 @@ public class SessionUtil { || taskWrapper.getTask().getId() == null || taskWrapper.getTask().getId().getValue() == null || taskWrapper.getTask().getId().getValue().isEmpty()) { - logger.error("TaskWrapper contains Task with invalid task id: " - + taskWrapper); + logger.error("TaskWrapper contains invalid Task: " + taskWrapper); return; } - @SuppressWarnings("unchecked") - HashMap> scopeToTasksInBackgroundMap = (HashMap>) httpSession - .getAttribute(SessionConstants.SCOPE_TO_OPERATIONS_TASKS_IN_BACKGROUND_MAP); - - if (scopeToTasksInBackgroundMap == null) { - logger.debug("TaskWrapper was not acquired: " + taskWrapper); + SessionOp> sessionOp = new SessionOp<>(); + HashMap tasksInBackground = sessionOp.get( + httpRequest, serviceCredentials, + SessionConstants.SCOPE_TO_OPERATIONS_TASKS_IN_BACKGROUND_MAP); + if (tasksInBackground == null) { + logger.debug("Tasks In Background was not acquired: " + taskWrapper); } else { - HashMap tasksInBackground = scopeToTasksInBackgroundMap - .get(aslSession.getScope()); - if (tasksInBackground == null) { - logger.debug("TaskWrapper was not acquired: " + taskWrapper); - } else { + if (tasksInBackground.containsKey(taskWrapper.getTask().getId() + .getValue())) { 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; - - } - - /** - * Reomove All Background Tasks in the scope - * - * @param httpSession - * @param taskWrapper - * @throws TDGWTSessionExpiredException - */ - public static void removeAllTasksInBackground(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) { - logger.debug("No tasks in background in session"); - } else { - HashMap tasksInBackground = scopeToTasksInBackgroundMap - .get(aslSession.getScope()); - if (tasksInBackground == null) { - logger.debug("No tasks in background in session for scope: " - + aslSession.getScope()); + logger.debug("Remove Task In Background: " + taskWrapper); } else { - scopeToTasksInBackgroundMap.remove(aslSession.getScope()); - httpSession - .removeAttribute(SessionConstants.SCOPE_TO_OPERATIONS_TASKS_IN_BACKGROUND_MAP); - httpSession - .setAttribute( - SessionConstants.SCOPE_TO_OPERATIONS_TASKS_IN_BACKGROUND_MAP, - scopeToTasksInBackgroundMap); + logger.debug("Task In Background was not acquired: " + + taskWrapper); } } - return; } /** - * Reomove Task on specific tabular resource from Tasks In Background + * Remove All Background Tasks in the scope * - * @param httpSession - * @param taskWrapper - * @throws TDGWTSessionExpiredException + * @param httpRequest + * @param serviceCredentials */ - public static void removeTaskInBackgroundOnTRId(HttpSession httpSession, - TRId trId) throws TDGWTSessionExpiredException { + public static void removeAllTasksInBackground( + HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials) { + ScopeProvider.instance.set(serviceCredentials.getScope()); - ASLSession aslSession = getAslSession(httpSession); - ScopeProvider.instance.set(aslSession.getScope()); + SessionOp> sessionOp = new SessionOp<>(); + sessionOp.remove(httpRequest, serviceCredentials, + SessionConstants.SCOPE_TO_OPERATIONS_TASKS_IN_BACKGROUND_MAP); + + } + + /** + * Remove Task on specific tabular resource from Tasks In Background + * + * + * @param httpRequest + * @param serviceCredentials + * @param trId + */ + public static void removeTaskInBackgroundOnTRId( + HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials, TRId trId) { + ScopeProvider.instance.set(serviceCredentials.getScope()); if (trId == null) { logger.error("TRId is null"); @@ -2568,96 +2219,69 @@ public class SessionUtil { return; } - @SuppressWarnings("unchecked") - HashMap> scopeToTasksInBackgroundMap = (HashMap>) httpSession - .getAttribute(SessionConstants.SCOPE_TO_OPERATIONS_TASKS_IN_BACKGROUND_MAP); + SessionOp> sessionOp = new SessionOp<>(); + HashMap tasksInBackground = sessionOp.get( + httpRequest, serviceCredentials, + SessionConstants.SCOPE_TO_OPERATIONS_TASKS_IN_BACKGROUND_MAP); - if (scopeToTasksInBackgroundMap == null) { - logger.debug("No Background task in Session for TRId: " + trId); + if (tasksInBackground == null) { + logger.debug("No Background task for TRId: " + trId); } else { - HashMap tasksInBackground = scopeToTasksInBackgroundMap - .get(aslSession.getScope()); - if (tasksInBackground == null) { - logger.debug("No Background task for TRId: " + trId); - } else { - ArrayList removableKeys = new ArrayList(); - for (String key : tasksInBackground.keySet()) { - TaskWrapper taskWrapper = tasksInBackground.get(key); - if (taskWrapper.getTrId() != null - && taskWrapper.getTrId().getId() != null - && taskWrapper.getTrId().getId() - .compareTo(trId.getId()) == 0) { - removableKeys.add(key); - } + ArrayList removableKeys = new ArrayList(); + for (String key : tasksInBackground.keySet()) { + TaskWrapper taskWrapper = tasksInBackground.get(key); + if (taskWrapper.getTrId() != null + && taskWrapper.getTrId().getId() != null + && taskWrapper.getTrId().getId() + .compareTo(trId.getId()) == 0) { + removableKeys.add(key); } - - for (String key : removableKeys) { - tasksInBackground.remove(key); - } - - 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); } + + for (String key : removableKeys) { + tasksInBackground.remove(key); + } + } - return; + } - // - public static FileUploadMonitor getFileUploadMonitor(HttpSession httpSession) { - FileUploadMonitor fileUploadMonitor = (FileUploadMonitor) httpSession - .getAttribute(SessionConstants.FILE_UPLOAD_MONITOR); - if (fileUploadMonitor != null) { - return fileUploadMonitor; - } else { - fileUploadMonitor = new FileUploadMonitor(); - httpSession.setAttribute(SessionConstants.FILE_UPLOAD_MONITOR, - fileUploadMonitor); - return fileUploadMonitor; - } + // TODO + public static FileUploadMonitor getFileUploadMonitor( + HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials) throws TDGWTServiceException { + SessionOp sessionOp = new SessionOp<>(); + FileUploadMonitor fileUploadMonitor = sessionOp.get(httpRequest, + serviceCredentials, SessionConstants.FILE_UPLOAD_MONITOR, + FileUploadMonitor.class); + return fileUploadMonitor; } - public static void setFileUploadMonitor(HttpSession httpSession, + public static void setFileUploadMonitor(HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials, FileUploadMonitor fileUploadMonitor) { - FileUploadMonitor fum = (FileUploadMonitor) httpSession - .getAttribute(SessionConstants.FILE_UPLOAD_MONITOR); - if (fum != null) { - httpSession.removeAttribute(SessionConstants.FILE_UPLOAD_MONITOR); - } - httpSession.setAttribute(SessionConstants.FILE_UPLOAD_MONITOR, - fileUploadMonitor); - + SessionOp sessionOp = new SessionOp<>(); + sessionOp.set(httpRequest, serviceCredentials, + SessionConstants.FILE_UPLOAD_MONITOR, fileUploadMonitor); } - // + // TODO public static SaveResourceSession getSaveResourceSession( - HttpSession httpSession) { - SaveResourceSession saveResourceSession = (SaveResourceSession) httpSession - .getAttribute(SessionConstants.RESOURCE_SAVE_SESSION); - if (saveResourceSession != null) { - return saveResourceSession; - } else { - saveResourceSession = new SaveResourceSession(); - httpSession.setAttribute(SessionConstants.RESOURCE_SAVE_SESSION, - saveResourceSession); - return saveResourceSession; - } + HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials) throws TDGWTServiceException { + SessionOp sessionOp = new SessionOp<>(); + SaveResourceSession saveResourceSession = sessionOp.get(httpRequest, + serviceCredentials, SessionConstants.RESOURCE_SAVE_SESSION, + SaveResourceSession.class); + return saveResourceSession; } - public static void setSaveResourceSession(HttpSession httpSession, + public static void setSaveResourceSession(HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials, SaveResourceSession saveResourceSession) { - SaveResourceSession srs = (SaveResourceSession) httpSession - .getAttribute(SessionConstants.RESOURCE_SAVE_SESSION); - if (srs != null) { - httpSession.removeAttribute(SessionConstants.RESOURCE_SAVE_SESSION); - } - httpSession.setAttribute(SessionConstants.RESOURCE_SAVE_SESSION, - saveResourceSession); + SessionOp sessionOp = new SessionOp<>(); + sessionOp.set(httpRequest, serviceCredentials, + SessionConstants.RESOURCE_SAVE_SESSION, saveResourceSession); }