Create Multi Tab Management

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-gwt-service@100720 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2014-10-15 16:45:04 +00:00
parent 13316a1efa
commit 7185351ccc
6 changed files with 455 additions and 115 deletions

View File

@ -63,6 +63,7 @@ import org.gcube.portlets.user.td.gwtservice.shared.tr.type.Agencies;
import org.gcube.portlets.user.td.gwtservice.shared.tr.type.Codelist; import org.gcube.portlets.user.td.gwtservice.shared.tr.type.Codelist;
import org.gcube.portlets.user.td.gwtservice.shared.tr.type.Dataset; import org.gcube.portlets.user.td.gwtservice.shared.tr.type.Dataset;
import org.gcube.portlets.user.td.gwtservice.shared.tr.union.UnionSession; import org.gcube.portlets.user.td.gwtservice.shared.tr.union.UnionSession;
import org.gcube.portlets.user.td.gwtservice.shared.user.UserInfo;
import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId; import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId;
import com.google.gwt.user.client.rpc.RemoteService; import com.google.gwt.user.client.rpc.RemoteService;
@ -94,7 +95,7 @@ public interface TDGWTService extends RemoteService {
* @return * @return
* @throws TDGWTServiceException * @throws TDGWTServiceException
*/ */
public String hello() throws TDGWTServiceException; public UserInfo hello() throws TDGWTServiceException;
// TabularResource // TabularResource
/** /**
@ -106,7 +107,17 @@ public interface TDGWTService extends RemoteService {
public TRId getCurrentTRId() throws TDGWTServiceException; public TRId getCurrentTRId() throws TDGWTServiceException;
/** /**
* Get informations on the current tabular resource * Get information on the current tabular resource don't call service
*
* @return
* @throws TDGWTServiceException
*/
public TabResource getInSessionTabResourceInfo() throws TDGWTServiceException;
/**
* Get informations on the current tabular resource call service
*
* *
* @return * @return
* @throws TDGWTServiceException * @throws TDGWTServiceException
@ -216,15 +227,6 @@ public interface TDGWTService extends RemoteService {
public ColumnData getConnection(RefColumn refColumn) public ColumnData getConnection(RefColumn refColumn)
throws TDGWTServiceException; throws TDGWTServiceException;
/**
* Close current tabular resource
*
* @return
* @throws TDGWTServiceException
*/
public TRId closeTabularResource() throws TDGWTServiceException;
/** /**
* Close All Tabular Resources * Close All Tabular Resources
* *
@ -233,6 +235,34 @@ public interface TDGWTService extends RemoteService {
*/ */
public void closeAllTabularResources() throws TDGWTServiceException; public void closeAllTabularResources() throws TDGWTServiceException;
/**
* Close Tabular Resource with TRId equals to closeTRId
* and open if not null that with TRId equals to openTRId
*
* @param openTRId
* @throws TDGWTServiceException
*/
public void closeTabularResourceAndOpen(TRId openTRId, TRId closeTRId)
throws TDGWTServiceException;
/**
* Close Tabular Resource with TRId equals to closeTRId
*
* @param closeTRId
* @throws TDGWTServiceException
*/
public void closeTabularResource(TRId closeTRId)
throws TDGWTServiceException;
/**
* Set Current Tabular Resource that passed as parameter if not null
*
*
* @param activeTRId
* @throws TDGWTServiceException
*/
public void setActiveTabularResource(TRId activeTRId)
throws TDGWTServiceException;
// Task // Task
/** /**
@ -315,7 +345,7 @@ public interface TDGWTService extends RemoteService {
* @return * @return
* @throws TDGWTServiceException * @throws TDGWTServiceException
*/ */
public ShareInfo getShareInfo(TRId trId) throws TDGWTServiceException; //public ShareInfo getShareInfo(TRId trId) throws TDGWTServiceException;
/** /**
* Share sabular resource * Share sabular resource

View File

@ -62,6 +62,7 @@ import org.gcube.portlets.user.td.gwtservice.shared.tr.type.Agencies;
import org.gcube.portlets.user.td.gwtservice.shared.tr.type.Codelist; import org.gcube.portlets.user.td.gwtservice.shared.tr.type.Codelist;
import org.gcube.portlets.user.td.gwtservice.shared.tr.type.Dataset; import org.gcube.portlets.user.td.gwtservice.shared.tr.type.Dataset;
import org.gcube.portlets.user.td.gwtservice.shared.tr.union.UnionSession; import org.gcube.portlets.user.td.gwtservice.shared.tr.union.UnionSession;
import org.gcube.portlets.user.td.gwtservice.shared.user.UserInfo;
import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId; import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId;
import com.google.gwt.core.client.GWT; import com.google.gwt.core.client.GWT;
@ -79,7 +80,7 @@ public interface TDGWTServiceAsync {
public static TDGWTServiceAsync INSTANCE = (TDGWTServiceAsync) GWT public static TDGWTServiceAsync INSTANCE = (TDGWTServiceAsync) GWT
.create(TDGWTService.class); .create(TDGWTService.class);
void hello(AsyncCallback<String> callback); void hello(AsyncCallback<UserInfo> callback);
// TabularResource // TabularResource
void getCurrentTRId(AsyncCallback<TRId> callback); void getCurrentTRId(AsyncCallback<TRId> callback);
@ -91,6 +92,8 @@ public interface TDGWTServiceAsync {
void isTabularResourceValid(TRId trId, AsyncCallback<Boolean> callback); void isTabularResourceValid(TRId trId, AsyncCallback<Boolean> callback);
void getInSessionTabResourceInfo(AsyncCallback<TabResource> callback);
void getTabResourceInformation(AsyncCallback<TabResource> callback); void getTabResourceInformation(AsyncCallback<TabResource> callback);
void getTabResourceInformation(TRId trId, void getTabResourceInformation(TRId trId,
@ -132,10 +135,15 @@ public interface TDGWTServiceAsync {
void getConnection(RefColumn refColumn, AsyncCallback<ColumnData> callback); void getConnection(RefColumn refColumn, AsyncCallback<ColumnData> callback);
void closeTabularResource(AsyncCallback<TRId> callback);
void closeAllTabularResources(AsyncCallback<Void> callback); void closeAllTabularResources(AsyncCallback<Void> callback);
void closeTabularResourceAndOpen(TRId openTRId, TRId closeTRId, AsyncCallback<Void> callback);
void closeTabularResource(TRId closeTRId, AsyncCallback<Void> callback);
void setActiveTabularResource(TRId activeTRId,AsyncCallback<Void> callback);
// Task // Task
void startTaskResubmit(TaskResubmitSession taskResubmitSession, void startTaskResubmit(TaskResubmitSession taskResubmitSession,
AsyncCallback<String> callback); AsyncCallback<String> callback);
@ -160,7 +168,7 @@ public interface TDGWTServiceAsync {
void startDiscard(TRId trId, AsyncCallback<String> callback); void startDiscard(TRId trId, AsyncCallback<String> callback);
// Share // Share
void getShareInfo(TRId trId, AsyncCallback<ShareInfo> callback); //void getShareInfo(TRId trId, AsyncCallback<ShareInfo> callback);
void setShare(ShareInfo shareInfo, AsyncCallback<Void> callback); void setShare(ShareInfo shareInfo, AsyncCallback<Void> callback);

View File

@ -78,10 +78,10 @@ public class SessionUtil {
ASLSession session; ASLSession session;
if (username == null) { if (username == null) {
logger.warn("no user found in session, using test one"); logger.warn("no user found in session, using test one");
throw new TDGWTSessionExpiredException("Session Expired!"); throw new TDGWTSessionExpiredException("Session Expired!");
// Remove comment for Test // Remove comment for Test
/* /*
username = Constants.DEFAULT_USER; username = Constants.DEFAULT_USER;
String scope = Constants.DEFAULT_SCOPE; String scope = Constants.DEFAULT_SCOPE;
@ -180,10 +180,11 @@ public class SessionUtil {
} }
// //
public static ArrayList<TabResource> getCurrentTabularResourcesOpen(HttpSession httpSession) { public static ArrayList<TabResource> getCurrentTabularResourcesOpen(
HttpSession httpSession) {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
ArrayList<TabResource> currentTROpen = (ArrayList<TabResource>) httpSession ArrayList<TabResource> currentTROpen = (ArrayList<TabResource>) httpSession
.getAttribute(SessionConstants.CURRENT_TABULAR_RESOURCES_OPEN ); .getAttribute(SessionConstants.CURRENT_TABULAR_RESOURCES_OPEN);
if (currentTROpen == null) { if (currentTROpen == null) {
logger.error("CURRENT_TABULAR_RESOURCES_OPEN was not acquired"); logger.error("CURRENT_TABULAR_RESOURCES_OPEN was not acquired");
} }
@ -191,56 +192,77 @@ public class SessionUtil {
} }
public static void setCurrentTabularResourcesOpen(HttpSession httpSession, public static void setCurrentTabularResourcesOpen(HttpSession httpSession,
ArrayList<TabResource> currentTROpen){ ArrayList<TabResource> currentTROpen) {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
ArrayList<TabResource> t = (ArrayList<TabResource>) httpSession ArrayList<TabResource> t = (ArrayList<TabResource>) httpSession
.getAttribute(SessionConstants.CURRENT_TABULAR_RESOURCES_OPEN); .getAttribute(SessionConstants.CURRENT_TABULAR_RESOURCES_OPEN);
if (t != null) if (t != null)
httpSession httpSession
.removeAttribute(SessionConstants.CURRENT_TABULAR_RESOURCES_OPEN); .removeAttribute(SessionConstants.CURRENT_TABULAR_RESOURCES_OPEN);
httpSession.setAttribute(SessionConstants.CURRENT_TABULAR_RESOURCES_OPEN, httpSession.setAttribute(
currentTROpen); SessionConstants.CURRENT_TABULAR_RESOURCES_OPEN, currentTROpen);
} }
public static void addToCurrentTabularResourcesOpen(HttpSession httpSession, public static void addToCurrentTabularResourcesOpen(
TabResource tabResource){ HttpSession httpSession, TabResource tabResource) {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
ArrayList<TabResource> t = (ArrayList<TabResource>) httpSession ArrayList<TabResource> t = (ArrayList<TabResource>) httpSession
.getAttribute(SessionConstants.CURRENT_TABULAR_RESOURCES_OPEN); .getAttribute(SessionConstants.CURRENT_TABULAR_RESOURCES_OPEN);
if (t != null){ if (t != null) {
for (TabResource tr : t) {
if (tr.getTrId().getId()
.compareTo(tabResource.getTrId().getId()) == 0) {
t.remove(tr);
break;
}
}
t.add(tabResource); t.add(tabResource);
httpSession.setAttribute(SessionConstants.CURRENT_TABULAR_RESOURCES_OPEN, httpSession
t); .removeAttribute(SessionConstants.CURRENT_TABULAR_RESOURCES_OPEN);
} else { } else {
t=new ArrayList<TabResource>(); t = new ArrayList<TabResource>();
t.add(tabResource); t.add(tabResource);
httpSession.setAttribute(SessionConstants.CURRENT_TABULAR_RESOURCES_OPEN, }
t); httpSession.setAttribute(
SessionConstants.CURRENT_TABULAR_RESOURCES_OPEN, t);
}
public static void removeFromCurrentTabularResourcesOpen(
HttpSession httpSession, TRId trId) {
if (trId != null && trId.getId() != null & !trId.getId().isEmpty()) {
@SuppressWarnings("unchecked")
ArrayList<TabResource> t = (ArrayList<TabResource>) httpSession
.getAttribute(SessionConstants.CURRENT_TABULAR_RESOURCES_OPEN);
if (t != null && !t.isEmpty()) {
for (TabResource tabR : t) {
if (tabR.getTrId().getId().compareTo(trId.getId()) == 0) {
t.remove(tabR);
httpSession
.removeAttribute(SessionConstants.CURRENT_TABULAR_RESOURCES_OPEN);
httpSession
.setAttribute(
SessionConstants.CURRENT_TABULAR_RESOURCES_OPEN,
t);
return;
}
}
}
} }
} }
public static void removeFromCurrentTabularResourcesOpen(HttpSession httpSession, public static void removeAllFromCurrentTabularResourcesOpen(
TabResource tabResource){ HttpSession httpSession) {
@SuppressWarnings("unchecked") httpSession
ArrayList<TabResource> t = (ArrayList<TabResource>) httpSession .removeAttribute(SessionConstants.CURRENT_TABULAR_RESOURCES_OPEN);
.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){ public static TabResource getFirstFromCurrentTabularResourcesOpen(
httpSession.removeAttribute(SessionConstants.CURRENT_TABULAR_RESOURCES_OPEN); HttpSession httpSession) {
}
public static TabResource getFirstFromCurrentTabularResourcesOpen(HttpSession httpSession) {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
ArrayList<TabResource> currentTROpen = (ArrayList<TabResource>) httpSession ArrayList<TabResource> currentTROpen = (ArrayList<TabResource>) httpSession
.getAttribute(SessionConstants.CURRENT_TABULAR_RESOURCES_OPEN ); .getAttribute(SessionConstants.CURRENT_TABULAR_RESOURCES_OPEN);
if (currentTROpen == null || currentTROpen.isEmpty()) { if (currentTROpen == null || currentTROpen.isEmpty()) {
logger.error("No CURRENT_TABULAR_RESOURCES_OPEN"); logger.error("No CURRENT_TABULAR_RESOURCES_OPEN");
return null; return null;
@ -249,6 +271,26 @@ public class SessionUtil {
} }
} }
public static TabResource getFromCurrentTabularResourcesOpen(
HttpSession httpSession, TRId trId) {
@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");
} else {
for (TabResource tabResource : currentTROpen) {
if (tabResource != null
&& tabResource.getTrId() != null
&& tabResource.getTrId().getId()
.compareTo(trId.getId()) == 0) {
return tabResource;
}
}
}
return null;
}
// //
public static TabResource getSDMXImportTabResource(HttpSession httpSession) { public static TabResource getSDMXImportTabResource(HttpSession httpSession) {

View File

@ -242,6 +242,7 @@ import org.gcube.portlets.user.td.gwtservice.shared.tr.type.Agencies;
import org.gcube.portlets.user.td.gwtservice.shared.tr.type.Codelist; import org.gcube.portlets.user.td.gwtservice.shared.tr.type.Codelist;
import org.gcube.portlets.user.td.gwtservice.shared.tr.type.Dataset; import org.gcube.portlets.user.td.gwtservice.shared.tr.type.Dataset;
import org.gcube.portlets.user.td.gwtservice.shared.tr.union.UnionSession; import org.gcube.portlets.user.td.gwtservice.shared.tr.union.UnionSession;
import org.gcube.portlets.user.td.gwtservice.shared.user.UserInfo;
import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId; import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId;
import org.gcube.portlets.user.td.widgetcommonevent.shared.tr.column.RelationshipData; import org.gcube.portlets.user.td.widgetcommonevent.shared.tr.column.RelationshipData;
import org.gcube.resources.discovery.client.api.DiscoveryClient; import org.gcube.resources.discovery.client.api.DiscoveryClient;
@ -278,11 +279,14 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public String hello() throws TDGWTServiceException { public UserInfo hello() throws TDGWTServiceException {
HttpSession session = this.getThreadLocalRequest().getSession(); HttpSession session = this.getThreadLocalRequest().getSession();
ASLSession aslSession = SessionUtil.getAslSession(session); ASLSession aslSession = SessionUtil.getAslSession(session);
String user = aslSession.getUsername(); UserInfo userInfo = new UserInfo(aslSession.getUsername(),
return user; aslSession.getGroupId(), aslSession.getGroupName(),
aslSession.getScope(), aslSession.getScopeName(),
aslSession.getUserEmailAddress(), aslSession.getUserFullName());
return userInfo;
} }
/** /**
@ -384,24 +388,39 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
} }
/**
*
* {@inheritDoc}
*/
@Override @Override
public TRId closeTabularResource() throws TDGWTServiceException { public void closeTabularResourceAndOpen(TRId openTRId, TRId closeTRId)
throws TDGWTServiceException {
try { try {
logger.debug("closeTabularResourceAndOpen(): Open[" + openTRId
+ "], Close[" + closeTRId + "]");
HttpSession session = this.getThreadLocalRequest().getSession(); HttpSession session = this.getThreadLocalRequest().getSession();
SessionUtil.getAslSession(session); SessionUtil.getAslSession(session);
TabResource currentTR=SessionUtil.getTabResource(session); SessionUtil.removeFromCurrentTabularResourcesOpen(session,
SessionUtil.removeFromCurrentTabularResourcesOpen(session, currentTR); closeTRId);
TabResource firstTR=SessionUtil.getFirstFromCurrentTabularResourcesOpen(session);
if(firstTR==null){ if (openTRId != null) {
TabResource tabResource = SessionUtil
.getFromCurrentTabularResourcesOpen(session, openTRId);
if (tabResource != null) {
SessionUtil.setTabResource(session, tabResource);
SessionUtil.setTRId(session, tabResource.getTrId());
} else {
logger.error("Set Active Tabular Resource failed, no valid id!: Open["
+ openTRId + ", " + tabResource);
throw new TDGWTServiceException(
"Set Active Tabular Resource failed, no valid id!: Open["
+ openTRId + ", " + tabResource);
}
} else {
SessionUtil.setTabResource(session, null); SessionUtil.setTabResource(session, null);
SessionUtil.setTRId(session, null); SessionUtil.setTRId(session, null);
return null;
} else {
SessionUtil.setTabResource(session, firstTR);
SessionUtil.setTRId(session, firstTR.getTrId());
return firstTR.getTrId();
} }
return;
} catch (TDGWTServiceException e) { } catch (TDGWTServiceException e) {
throw e; throw e;
@ -417,6 +436,100 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
} }
@Override
public void closeTabularResource(TRId closeTRId)
throws TDGWTServiceException {
try {
logger.debug("closeTabularResource(): " + closeTRId);
HttpSession session = this.getThreadLocalRequest().getSession();
SessionUtil.getAslSession(session);
SessionUtil.removeFromCurrentTabularResourcesOpen(session,
closeTRId);
SessionUtil.setTabResource(session, null);
SessionUtil.setTRId(session, null);
return;
} 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());
}
}
/**
*
* {@inheritDoc}
*/
@Override
public void setActiveTabularResource(TRId activeTRId)
throws TDGWTServiceException {
try {
logger.debug("setActiveTabularResource(): " + activeTRId);
HttpSession session = this.getThreadLocalRequest().getSession();
SessionUtil.getAslSession(session);
TabResource tabResource = SessionUtil
.getFromCurrentTabularResourcesOpen(session, activeTRId);
if (tabResource != null) {
SessionUtil.setTabResource(session, tabResource);
SessionUtil.setTRId(session, tabResource.getTrId());
} else {
logger.error("Set Active Tabular Resource failed, no valid id!: "
+ activeTRId);
throw new TDGWTServiceException(
"Set Active Tabular Resource failed, no valid id!");
}
return;
} 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());
}
}
@Override
public TabResource getInSessionTabResourceInfo()
throws TDGWTServiceException {
try {
HttpSession session = this.getThreadLocalRequest().getSession();
SessionUtil.getAslSession(session);
TabResource currentTR = SessionUtil.getTabResource(session);
return currentTR;
} catch (TDGWTServiceException e) {
throw e;
} catch (SecurityException e) {
e.printStackTrace();
throw new TDGWTServiceException(
"Security exception, you haven't rights!");
} catch (Throwable e) {
logger.error(
"Error setting TabResource parameter: "
+ e.getLocalizedMessage(), e);
throw new TDGWTServiceException(
"Error setting TabResource parameter: "
+ e.getLocalizedMessage());
}
}
/** /**
* *
@ -444,10 +557,6 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
} }
logger.debug("Current TRId: " + currentTR.getTrId()); logger.debug("Current TRId: " + currentTR.getTrId());
ArrayList<TRMetadata> trMetadatas = getTRMetadata(currentTR
.getTrId());
updateTabResourceInformation(currentTR, trMetadatas);
AuthorizationProvider.instance.set(new AuthorizationToken( AuthorizationProvider.instance.set(new AuthorizationToken(
aslSession.getUsername(), aslSession.getScope())); aslSession.getUsername(), aslSession.getScope()));
TabularDataService service = TabularDataServiceFactory.getService(); TabularDataService service = TabularDataServiceFactory.getService();
@ -456,12 +565,17 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
.getTabularResource(new TabularResourceId(Long .getTabularResource(new TabularResourceId(Long
.valueOf(currentTR.getTrId().getId()))); .valueOf(currentTR.getTrId().getId())));
ArrayList<TRMetadata> trMetadatas = getTRMetadata(tr);
updateTabResourceInformation(currentTR, trMetadatas);
currentTR.setDate(sdf.format(tr.getCreationDate().getTime())); currentTR.setDate(sdf.format(tr.getCreationDate().getTime()));
currentTR.setValid(tr.isValid()); currentTR.setValid(tr.isValid());
currentTR.setFinalized(tr.isFinalized()); currentTR.setFinalized(tr.isFinalized());
currentTR.setLocked(tr.isLocked()); currentTR.setLocked(tr.isLocked());
Contacts owner = new Contacts("", tr.getOwner(), false); Contacts owner = new Contacts("", tr.getOwner(), false);
currentTR.setOwner(owner); currentTR.setOwner(owner);
currentTR.setContacts(retrieveShareInfo(tr));
SessionUtil.setTabResource(session, currentTR); SessionUtil.setTabResource(session, currentTR);
logger.debug("GetTabResourceInformation() updated information:" logger.debug("GetTabResourceInformation() updated information:"
+ currentTR.toString()); + currentTR.toString());
@ -504,10 +618,6 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
TabResource currentTR = new TabResource(); TabResource currentTR = new TabResource();
currentTR.setTrId(trId); currentTR.setTrId(trId);
ArrayList<TRMetadata> trMetadatas = getTRMetadata(currentTR
.getTrId());
updateTabResourceInformation(currentTR, trMetadatas);
AuthorizationProvider.instance.set(new AuthorizationToken( AuthorizationProvider.instance.set(new AuthorizationToken(
aslSession.getUsername(), aslSession.getScope())); aslSession.getUsername(), aslSession.getScope()));
TabularDataService service = TabularDataServiceFactory.getService(); TabularDataService service = TabularDataServiceFactory.getService();
@ -517,12 +627,17 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
.valueOf(currentTR.getTrId().getId()))); .valueOf(currentTR.getTrId().getId())));
logger.debug("GetTabResourceInformation() TR on service: " + tr); logger.debug("GetTabResourceInformation() TR on service: " + tr);
ArrayList<TRMetadata> trMetadatas = getTRMetadata(tr);
updateTabResourceInformation(currentTR, trMetadatas);
currentTR.setDate(sdf.format(tr.getCreationDate().getTime())); currentTR.setDate(sdf.format(tr.getCreationDate().getTime()));
currentTR.setValid(tr.isValid()); currentTR.setValid(tr.isValid());
currentTR.setFinalized(tr.isFinalized()); currentTR.setFinalized(tr.isFinalized());
currentTR.setLocked(tr.isLocked()); currentTR.setLocked(tr.isLocked());
Contacts owner = new Contacts("", tr.getOwner(), false); Contacts owner = new Contacts("", tr.getOwner(), false);
currentTR.setOwner(owner); currentTR.setOwner(owner);
currentTR.setContacts(retrieveShareInfo(tr));
logger.debug("GetTabResourceInformation() updated information:" logger.debug("GetTabResourceInformation() updated information:"
+ currentTR); + currentTR);
return currentTR; return currentTR;
@ -3193,10 +3308,101 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
} }
} }
protected ArrayList<TRMetadata> getTRMetadata(TabularResource tr)
throws TDGWTServiceException {
try {
Collection<TabularResourceMetadata<?>> trMetas = tr
.getAllMetadata();
logger.debug("GetTRMetadata size: " + trMetas.size());
ArrayList<TRMetadata> listTRMetadata = new ArrayList<TRMetadata>();
for (TabularResourceMetadata<?> trMetadata : trMetas) {
if (trMetadata instanceof org.gcube.data.analysis.tabulardata.service.tabular.metadata.DescriptionMetadata) {
TRDescriptionMetadata trDescriptionMetadata = new TRDescriptionMetadata();
trDescriptionMetadata
.setValue(((org.gcube.data.analysis.tabulardata.service.tabular.metadata.DescriptionMetadata) trMetadata)
.getValue());
listTRMetadata.add(trDescriptionMetadata);
} else {
if (trMetadata instanceof org.gcube.data.analysis.tabulardata.service.tabular.metadata.NameMetadata) {
TRNameMetadata trNameMetadata = new TRNameMetadata();
trNameMetadata
.setValue(((org.gcube.data.analysis.tabulardata.service.tabular.metadata.NameMetadata) trMetadata)
.getValue());
listTRMetadata.add(trNameMetadata);
} else {
if (trMetadata instanceof AgencyMetadata) {
TRAgencyMetadata trAgencyMetadata = new TRAgencyMetadata();
trAgencyMetadata
.setValue(((AgencyMetadata) trMetadata)
.getValue());
listTRMetadata.add(trAgencyMetadata);
} else {
if (trMetadata instanceof RightsMetadata) {
TRRightsMetadata trRightsMetadata = new TRRightsMetadata();
trRightsMetadata
.setValue(((RightsMetadata) trMetadata)
.getValue());
listTRMetadata.add(trRightsMetadata);
} else {
if (trMetadata instanceof ValidSinceMetadata) {
TRValidSinceMetadata validSinceMetadata = new TRValidSinceMetadata();
Calendar cal = ((ValidSinceMetadata) trMetadata)
.getValue();
validSinceMetadata.setValue(sdfDate
.format(cal.getTime()));
listTRMetadata.add(validSinceMetadata);
} else {
if (trMetadata instanceof ValidUntilMetadata) {
TRValidUntilMetadata validUntilMetadata = new TRValidUntilMetadata();
Calendar cal = ((ValidUntilMetadata) trMetadata)
.getValue();
validUntilMetadata.setValue(sdfDate
.format(cal.getTime()));
listTRMetadata.add(validUntilMetadata);
} else {
if (trMetadata instanceof LicenceMetadata) {
TRLicenceMetadata licenceMetadata = new TRLicenceMetadata();
licenceMetadata
.setValue(((LicenceMetadata) trMetadata)
.getValue()
.toString());
listTRMetadata.add(licenceMetadata);
} else {
}
}
}
}
}
}
}
}
logger.debug("GetTRMetadata retrived: " + listTRMetadata.size());
logger.debug("GetTRMetadata: [" + listTRMetadata + "]");
return listTRMetadata;
} catch (SecurityException e) {
e.printStackTrace();
throw new TDGWTServiceException(
"Security exception, you haven't rights!");
} catch (Throwable e) {
logger.error(
"Error in getTRMetadata(): " + e.getLocalizedMessage(), e);
throw new TDGWTServiceException("Error in getTRMetadata(): "
+ e.getLocalizedMessage());
}
}
/** /**
* *
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override
public ArrayList<TRMetadata> getTRMetadata(TRId trId) public ArrayList<TRMetadata> getTRMetadata(TRId trId)
throws TDGWTServiceException { throws TDGWTServiceException {
try { try {
@ -4588,10 +4794,46 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
} }
protected ArrayList<Contacts> retrieveShareInfo(TabularResource tr)
throws TDGWTServiceException {
try {
ArrayList<Contacts> contacts = new ArrayList<Contacts>();
List<String> sharedWithUsers = tr.getSharedWithUsers();
logger.debug("Shared with Users: " + sharedWithUsers);
if (sharedWithUsers != null) {
for (String user : sharedWithUsers) {
Contacts cont = new Contacts(user, user, false);
contacts.add(cont);
}
}
List<String> sharedWithGroups = tr.getSharedWithGroup();
logger.debug("Shared with Groups: " + sharedWithUsers);
if (sharedWithGroups != null) {
for (String group : sharedWithGroups) {
Contacts cont = new Contacts(group, group, true);
contacts.add(cont);
}
}
return contacts;
} catch (SecurityException e) {
e.printStackTrace();
throw new TDGWTServiceException(
"Security exception, you haven't rights!");
} catch (Throwable e) {
e.printStackTrace();
throw new TDGWTServiceException("Error in retrieveShareInfo: "
+ e.getLocalizedMessage());
}
}
/** /**
* *
* {@inheritDoc} * {@inheritDoc}
*/ */
/*
@Override @Override
public ShareInfo getShareInfo(TRId trId) throws TDGWTServiceException { public ShareInfo getShareInfo(TRId trId) throws TDGWTServiceException {
try { try {
@ -4640,7 +4882,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
throw new TDGWTServiceException("Error in getShareInfo: " throw new TDGWTServiceException("Error in getShareInfo: "
+ e.getLocalizedMessage()); + e.getLocalizedMessage());
} }
} }*/
/** /**
* *
@ -6747,12 +6989,15 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
aslSession.getUsername(), aslSession.getScope())); aslSession.getUsername(), aslSession.getScope()));
TabularDataService service = TabularDataServiceFactory.getService(); TabularDataService service = TabularDataServiceFactory.getService();
checkTabularResourceLocked(service, trId); checkTabularResourceLocked(service, trId);
TabularResourceId tabularResourceId=new TabularResourceId(Long.parseLong(trId.getId())); TabularResourceId tabularResourceId = new TabularResourceId(
Long.parseLong(trId.getId()));
List<ResourceDescriptor> resources=service.getResources(tabularResourceId); List<ResourceDescriptor> resources = service
ResourceTDCreator resourceTDCreator=new ResourceTDCreator(); .getResources(tabularResourceId);
ResourceTDCreator resourceTDCreator = new ResourceTDCreator();
ArrayList<ResourceTDDescriptor> resourcesTD=resourceTDCreator.createResourcesDescriptorTD(resources); ArrayList<ResourceTDDescriptor> resourcesTD = resourceTDCreator
.createResourcesDescriptorTD(resources);
return resourcesTD; return resourcesTD;
} catch (TDGWTServiceException e) { } catch (TDGWTServiceException e) {
@ -6762,16 +7007,16 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
throw new TDGWTServiceException( throw new TDGWTServiceException(
"Security exception, you haven't rights!"); "Security exception, you haven't rights!");
} catch (Throwable e) { } catch (Throwable e) {
logger.error("Error retrieving resources: " + e.getLocalizedMessage(), logger.error(
e); "Error retrieving resources: " + e.getLocalizedMessage(), e);
throw new TDGWTServiceException("Error retrieving resources: " throw new TDGWTServiceException("Error retrieving resources: "
+ e.getLocalizedMessage()); + e.getLocalizedMessage());
} }
} }
@Override @Override
public ArrayList<ResourceTDDescriptor> getResourcesTDByType(TRId trId, ResourceTDType resourceTDType) public ArrayList<ResourceTDDescriptor> getResourcesTDByType(TRId trId,
throws TDGWTServiceException { ResourceTDType resourceTDType) throws TDGWTServiceException {
try { try {
HttpSession session = this.getThreadLocalRequest().getSession(); HttpSession session = this.getThreadLocalRequest().getSession();
ASLSession aslSession = SessionUtil.getAslSession(session); ASLSession aslSession = SessionUtil.getAslSession(session);
@ -6780,13 +7025,17 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
aslSession.getUsername(), aslSession.getScope())); aslSession.getUsername(), aslSession.getScope()));
TabularDataService service = TabularDataServiceFactory.getService(); TabularDataService service = TabularDataServiceFactory.getService();
checkTabularResourceLocked(service, trId); checkTabularResourceLocked(service, trId);
TabularResourceId tabularResourceId=new TabularResourceId(Long.parseLong(trId.getId())); TabularResourceId tabularResourceId = new TabularResourceId(
ResourceType resourceType=ResourceTDTypeMap.getResourceType(resourceTDType); Long.parseLong(trId.getId()));
ResourceType resourceType = ResourceTDTypeMap
.getResourceType(resourceTDType);
List<ResourceDescriptor> resources=service.getResourcesByType(tabularResourceId,resourceType); List<ResourceDescriptor> resources = service.getResourcesByType(
ResourceTDCreator resourceTDCreator=new ResourceTDCreator(); tabularResourceId, resourceType);
ResourceTDCreator resourceTDCreator = new ResourceTDCreator();
ArrayList<ResourceTDDescriptor> resourcesTD=resourceTDCreator.createResourcesDescriptorTD(resources); ArrayList<ResourceTDDescriptor> resourcesTD = resourceTDCreator
.createResourcesDescriptorTD(resources);
return resourcesTD; return resourcesTD;
} catch (TDGWTServiceException e) { } catch (TDGWTServiceException e) {
@ -6796,10 +7045,12 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
throw new TDGWTServiceException( throw new TDGWTServiceException(
"Security exception, you haven't rights!"); "Security exception, you haven't rights!");
} catch (Throwable e) { } catch (Throwable e) {
logger.error("Error retrieving resources by type: " + e.getLocalizedMessage(), logger.error(
e); "Error retrieving resources by type: "
throw new TDGWTServiceException("Error retrieving resources by type: " + e.getLocalizedMessage(), e);
+ e.getLocalizedMessage()); throw new TDGWTServiceException(
"Error retrieving resources by type: "
+ e.getLocalizedMessage());
} }
} }
@ -6816,7 +7067,6 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
TabularDataService service = TabularDataServiceFactory.getService(); TabularDataService service = TabularDataServiceFactory.getService();
checkTabularResourceLocked(service, mapCreationSession.getTrId()); checkTabularResourceLocked(service, mapCreationSession.getTrId());
OpExecution4MapCreation opEx = new OpExecution4MapCreation(service, OpExecution4MapCreation opEx = new OpExecution4MapCreation(service,
mapCreationSession); mapCreationSession);
OpExecutionDirector director = new OpExecutionDirector(); OpExecutionDirector director = new OpExecutionDirector();
@ -6854,6 +7104,4 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
} }
} }

View File

@ -1,6 +1,7 @@
package org.gcube.portlets.user.td.gwtservice.shared.tr; package org.gcube.portlets.user.td.gwtservice.shared.tr;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList;
import org.gcube.portlets.user.td.gwtservice.shared.share.Contacts; import org.gcube.portlets.user.td.gwtservice.shared.share.Contacts;
import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId; import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId;
@ -26,6 +27,7 @@ public class TabResource implements Serializable {
protected String validUntilTo; protected String validUntilTo;
protected String licence; protected String licence;
protected Contacts owner; protected Contacts owner;
protected ArrayList<Contacts> contacts;
protected boolean valid; protected boolean valid;
protected boolean finalized; protected boolean finalized;
protected boolean locked; protected boolean locked;
@ -175,15 +177,25 @@ public class TabResource implements Serializable {
this.locked = locked; this.locked = locked;
} }
public ArrayList<Contacts> getContacts() {
return contacts;
}
public void setContacts(ArrayList<Contacts> contacts) {
this.contacts = contacts;
}
@Override @Override
public String toString() { public String toString() {
return "TabResource [trId=" + trId + ", id=" + id + ", name=" + name return "TabResource [trId=" + trId + ", id=" + id + ", name=" + name
+ ", description=" + description + ", agency=" + agency + ", description=" + description + ", agency=" + agency
+ ", date=" + date + ", right=" + right + ", validFrom=" + ", date=" + date + ", right=" + right + ", validFrom="
+ validFrom + ", validUntilTo=" + validUntilTo + ", licence=" + validFrom + ", validUntilTo=" + validUntilTo + ", licence="
+ licence + ", owner=" + owner + ", valid=" + valid + licence + ", owner=" + owner + ", contacts=" + contacts
+ ", finalized=" + finalized + ", locked=" + locked + "]"; + ", valid=" + valid + ", finalized=" + finalized + ", locked="
+ locked + "]";
} }
} }

View File

@ -13,7 +13,7 @@ public class UserInfo implements Serializable {
private static final long serialVersionUID = -2826549639677017234L; private static final long serialVersionUID = -2826549639677017234L;
private String username; private String username;
private int groupId; private long groupId;
private String groupName; private String groupName;
private String scope; private String scope;
private String scopeName; private String scopeName;
@ -34,7 +34,7 @@ public class UserInfo implements Serializable {
* @param userEmailAddress * @param userEmailAddress
* @param userFullName * @param userFullName
*/ */
public UserInfo(String username, int groupId, String groupName, public UserInfo(String username, long groupId, String groupName,
String scope, String scopeName, String userEmailAddress, String scope, String scopeName, String userEmailAddress,
String userFullName) { String userFullName) {
super(); super();
@ -55,11 +55,11 @@ public class UserInfo implements Serializable {
this.username = username; this.username = username;
} }
public int getGroupId() { public long getGroupId() {
return groupId; return groupId;
} }
public void setGroupId(int groupId) { public void setGroupId(long groupId) {
this.groupId = groupId; this.groupId = groupId;
} }