Minor update

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-gwt-service@100668 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2014-10-14 12:29:27 +00:00
parent 597e37348d
commit e06f2070ba
5 changed files with 128 additions and 6 deletions

View File

@ -219,11 +219,21 @@ public interface TDGWTService extends RemoteService {
/**
* Close current tabular resource
*
* @param trId
* @return
* @throws TDGWTServiceException
*/
public void closeTabularResource() throws TDGWTServiceException;
public TRId closeTabularResource() throws TDGWTServiceException;
/**
* Close All Tabular Resources
*
*
* @throws TDGWTServiceException
*/
public void closeAllTabularResources() throws TDGWTServiceException;
// Task
/**
* Resubmit task

View File

@ -132,7 +132,9 @@ public interface TDGWTServiceAsync {
void getConnection(RefColumn refColumn, AsyncCallback<ColumnData> callback);
void closeTabularResource(AsyncCallback<Void> callback);
void closeTabularResource(AsyncCallback<TRId> callback);
void closeAllTabularResources(AsyncCallback<Void> callback);
// Task
void startTaskResubmit(TaskResubmitSession taskResubmitSession,

View File

@ -7,8 +7,10 @@ package org.gcube.portlets.user.td.gwtservice.server;
*
*/
public class SessionConstants {
protected static final String CURRENT_TABULAR_RESOURCE = "CURRENT_TABULAR_RESOURCE";
protected static final String CURRENT_TR_ID = "CURRENT_TR_ID";
protected static final String CURRENT_TABULAR_RESOURCE = "CURRENT_TABULAR_RESOURCE";
protected static final String CURRENT_TABULAR_RESOURCES_OPEN = "CURRENT_TABULAR_RESOURCES_OPEN";
protected static final String TDOPEN_SESSION = "TDOPEN_SESSION";
protected static final String TABULAR_RESOURCE_LIST = "TABULAR_RESOURCE_LIST";

View File

@ -178,7 +178,79 @@ public class SessionUtil {
ASLSession aslSession = getAslSession(httpSession);
ScopeProvider.instance.set(aslSession.getScope().toString());
}
//
public static ArrayList<TabResource> getCurrentTabularResourcesOpen(HttpSession httpSession) {
@SuppressWarnings("unchecked")
ArrayList<TabResource> currentTROpen = (ArrayList<TabResource>) httpSession
.getAttribute(SessionConstants.CURRENT_TABULAR_RESOURCES_OPEN );
if (currentTROpen == null) {
logger.error("CURRENT_TABULAR_RESOURCES_OPEN was not acquired");
}
return currentTROpen;
}
public static void setCurrentTabularResourcesOpen(HttpSession httpSession,
ArrayList<TabResource> currentTROpen){
@SuppressWarnings("unchecked")
ArrayList<TabResource> t = (ArrayList<TabResource>) httpSession
.getAttribute(SessionConstants.CURRENT_TABULAR_RESOURCES_OPEN);
if (t != null)
httpSession
.removeAttribute(SessionConstants.CURRENT_TABULAR_RESOURCES_OPEN);
httpSession.setAttribute(SessionConstants.CURRENT_TABULAR_RESOURCES_OPEN,
currentTROpen);
}
public static void addToCurrentTabularResourcesOpen(HttpSession httpSession,
TabResource tabResource){
@SuppressWarnings("unchecked")
ArrayList<TabResource> t = (ArrayList<TabResource>) httpSession
.getAttribute(SessionConstants.CURRENT_TABULAR_RESOURCES_OPEN);
if (t != null){
t.add(tabResource);
httpSession.setAttribute(SessionConstants.CURRENT_TABULAR_RESOURCES_OPEN,
t);
} else {
t=new ArrayList<TabResource>();
t.add(tabResource);
httpSession.setAttribute(SessionConstants.CURRENT_TABULAR_RESOURCES_OPEN,
t);
}
}
public static void removeFromCurrentTabularResourcesOpen(HttpSession httpSession,
TabResource tabResource){
@SuppressWarnings("unchecked")
ArrayList<TabResource> t = (ArrayList<TabResource>) httpSession
.getAttribute(SessionConstants.CURRENT_TABULAR_RESOURCES_OPEN);
if (t != null && !t.isEmpty()){
t.remove(tabResource);
httpSession.setAttribute(SessionConstants.CURRENT_TABULAR_RESOURCES_OPEN,
t);
}
}
public static void removeAllFromCurrentTabularResourcesOpen(HttpSession httpSession){
httpSession.removeAttribute(SessionConstants.CURRENT_TABULAR_RESOURCES_OPEN);
}
public static TabResource getFirstFromCurrentTabularResourcesOpen(HttpSession httpSession) {
@SuppressWarnings("unchecked")
ArrayList<TabResource> currentTROpen = (ArrayList<TabResource>) httpSession
.getAttribute(SessionConstants.CURRENT_TABULAR_RESOURCES_OPEN );
if (currentTROpen == null || currentTROpen.isEmpty()) {
logger.error("No CURRENT_TABULAR_RESOURCES_OPEN");
return null;
} else {
return currentTROpen.get(0);
}
}
//
public static TabResource getSDMXImportTabResource(HttpSession httpSession) {
TabResource tabResource = (TabResource) httpSession
.getAttribute(SessionConstants.SDMX_IMPORT_TABULAR_RESOURCE);

View File

@ -304,6 +304,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
SessionUtil.setTabResource(session, tabResource);
SessionUtil.setTRId(session, tabResource.getTrId());
SessionUtil.addToCurrentTabularResourcesOpen(session, tabResource);
return;
} catch (TDGWTServiceException e) {
@ -359,13 +360,14 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
* {@inheritDoc}
*/
@Override
public void closeTabularResource() throws TDGWTServiceException {
public void closeAllTabularResources() throws TDGWTServiceException {
try {
HttpSession session = this.getThreadLocalRequest().getSession();
SessionUtil.getAslSession(session);
SessionUtil.setTabResource(session, null);
SessionUtil.setTRId(session, null);
SessionUtil.removeAllFromCurrentTabularResourcesOpen(session);
return;
} catch (TDGWTServiceException e) {
@ -381,6 +383,40 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
}
}
@Override
public TRId closeTabularResource() throws TDGWTServiceException {
try {
HttpSession session = this.getThreadLocalRequest().getSession();
SessionUtil.getAslSession(session);
TabResource currentTR=SessionUtil.getTabResource(session);
SessionUtil.removeFromCurrentTabularResourcesOpen(session, currentTR);
TabResource firstTR=SessionUtil.getFirstFromCurrentTabularResourcesOpen(session);
if(firstTR==null){
SessionUtil.setTabResource(session, null);
SessionUtil.setTRId(session, null);
return null;
} else {
SessionUtil.setTabResource(session, firstTR);
SessionUtil.setTRId(session, firstTR.getTrId());
return firstTR.getTrId();
}
} catch (TDGWTServiceException e) {
throw e;
} catch (SecurityException e) {
e.printStackTrace();
throw new TDGWTServiceException(
"Security exception, you haven't rights!");
} catch (Throwable e) {
logger.error("getCurrentTRID(): " + e.getLocalizedMessage(), e);
throw new TDGWTServiceException("Error retrieving TR id: "
+ e.getLocalizedMessage());
}
}
/**
*