From 7185351cccf28a667386d8603ed01b97d26e0d10 Mon Sep 17 00:00:00 2001 From: Giancarlo Panichi Date: Wed, 15 Oct 2014 16:45:04 +0000 Subject: [PATCH] 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 --- .../gwtservice/client/rpc/TDGWTService.java | 54 ++- .../client/rpc/TDGWTServiceAsync.java | 14 +- .../td/gwtservice/server/SessionUtil.java | 122 ++++-- .../gwtservice/server/TDGWTServiceImpl.java | 354 +++++++++++++++--- .../td/gwtservice/shared/tr/TabResource.java | 18 +- .../td/gwtservice/shared/user/UserInfo.java | 8 +- 6 files changed, 455 insertions(+), 115 deletions(-) diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/client/rpc/TDGWTService.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/client/rpc/TDGWTService.java index 1bc63ae..dc5479d 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/client/rpc/TDGWTService.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/client/rpc/TDGWTService.java @@ -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.Dataset; 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 com.google.gwt.user.client.rpc.RemoteService; @@ -94,7 +95,7 @@ public interface TDGWTService extends RemoteService { * @return * @throws TDGWTServiceException */ - public String hello() throws TDGWTServiceException; + public UserInfo hello() throws TDGWTServiceException; // TabularResource /** @@ -106,7 +107,17 @@ public interface TDGWTService extends RemoteService { 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 * @throws TDGWTServiceException @@ -216,15 +227,6 @@ public interface TDGWTService extends RemoteService { public ColumnData getConnection(RefColumn refColumn) throws TDGWTServiceException; - /** - * Close current tabular resource - * - * @return - * @throws TDGWTServiceException - */ - public TRId closeTabularResource() throws TDGWTServiceException; - - /** * Close All Tabular Resources * @@ -233,7 +235,35 @@ public interface TDGWTService extends RemoteService { */ 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 /** * Resubmit task @@ -315,7 +345,7 @@ public interface TDGWTService extends RemoteService { * @return * @throws TDGWTServiceException */ - public ShareInfo getShareInfo(TRId trId) throws TDGWTServiceException; + //public ShareInfo getShareInfo(TRId trId) throws TDGWTServiceException; /** * Share sabular resource diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/client/rpc/TDGWTServiceAsync.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/client/rpc/TDGWTServiceAsync.java index 1dc782a..fc905e8 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/client/rpc/TDGWTServiceAsync.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/client/rpc/TDGWTServiceAsync.java @@ -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.Dataset; 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 com.google.gwt.core.client.GWT; @@ -79,7 +80,7 @@ public interface TDGWTServiceAsync { public static TDGWTServiceAsync INSTANCE = (TDGWTServiceAsync) GWT .create(TDGWTService.class); - void hello(AsyncCallback callback); + void hello(AsyncCallback callback); // TabularResource void getCurrentTRId(AsyncCallback callback); @@ -91,6 +92,8 @@ public interface TDGWTServiceAsync { void isTabularResourceValid(TRId trId, AsyncCallback callback); + void getInSessionTabResourceInfo(AsyncCallback callback); + void getTabResourceInformation(AsyncCallback callback); void getTabResourceInformation(TRId trId, @@ -132,10 +135,15 @@ public interface TDGWTServiceAsync { void getConnection(RefColumn refColumn, AsyncCallback callback); - void closeTabularResource(AsyncCallback callback); void closeAllTabularResources(AsyncCallback callback); + void closeTabularResourceAndOpen(TRId openTRId, TRId closeTRId, AsyncCallback callback); + + void closeTabularResource(TRId closeTRId, AsyncCallback callback); + + void setActiveTabularResource(TRId activeTRId,AsyncCallback callback); + // Task void startTaskResubmit(TaskResubmitSession taskResubmitSession, AsyncCallback callback); @@ -160,7 +168,7 @@ public interface TDGWTServiceAsync { void startDiscard(TRId trId, AsyncCallback callback); // Share - void getShareInfo(TRId trId, AsyncCallback callback); + //void getShareInfo(TRId trId, AsyncCallback callback); void setShare(ShareInfo shareInfo, AsyncCallback callback); 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 2f708a8..2e8fb9d 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 @@ -78,10 +78,10 @@ public class SessionUtil { ASLSession session; if (username == null) { logger.warn("no user found in session, using test one"); - throw new TDGWTSessionExpiredException("Session Expired!"); + throw new TDGWTSessionExpiredException("Session Expired!"); // Remove comment for Test - /* + /* username = Constants.DEFAULT_USER; String scope = Constants.DEFAULT_SCOPE; @@ -178,12 +178,13 @@ public class SessionUtil { ASLSession aslSession = getAslSession(httpSession); ScopeProvider.instance.set(aslSession.getScope().toString()); } - - // - public static ArrayList getCurrentTabularResourcesOpen(HttpSession httpSession) { + + // + public static ArrayList getCurrentTabularResourcesOpen( + HttpSession httpSession) { @SuppressWarnings("unchecked") ArrayList currentTROpen = (ArrayList) httpSession - .getAttribute(SessionConstants.CURRENT_TABULAR_RESOURCES_OPEN ); + .getAttribute(SessionConstants.CURRENT_TABULAR_RESOURCES_OPEN); if (currentTROpen == null) { logger.error("CURRENT_TABULAR_RESOURCES_OPEN was not acquired"); } @@ -191,56 +192,77 @@ public class SessionUtil { } public static void setCurrentTabularResourcesOpen(HttpSession httpSession, - ArrayList currentTROpen){ + ArrayList currentTROpen) { @SuppressWarnings("unchecked") ArrayList t = (ArrayList) httpSession .getAttribute(SessionConstants.CURRENT_TABULAR_RESOURCES_OPEN); if (t != null) httpSession .removeAttribute(SessionConstants.CURRENT_TABULAR_RESOURCES_OPEN); - httpSession.setAttribute(SessionConstants.CURRENT_TABULAR_RESOURCES_OPEN, - currentTROpen); - + httpSession.setAttribute( + SessionConstants.CURRENT_TABULAR_RESOURCES_OPEN, currentTROpen); + } - - public static void addToCurrentTabularResourcesOpen(HttpSession httpSession, - TabResource tabResource){ + + public static void addToCurrentTabularResourcesOpen( + HttpSession httpSession, TabResource tabResource) { @SuppressWarnings("unchecked") ArrayList t = (ArrayList) httpSession .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); - httpSession.setAttribute(SessionConstants.CURRENT_TABULAR_RESOURCES_OPEN, - t); + httpSession + .removeAttribute(SessionConstants.CURRENT_TABULAR_RESOURCES_OPEN); } else { - t=new ArrayList(); + t = new ArrayList(); 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 t = (ArrayList) 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, - TabResource tabResource){ - @SuppressWarnings("unchecked") - ArrayList t = (ArrayList) httpSession - .getAttribute(SessionConstants.CURRENT_TABULAR_RESOURCES_OPEN); - if (t != null && !t.isEmpty()){ - t.remove(tabResource); - httpSession.setAttribute(SessionConstants.CURRENT_TABULAR_RESOURCES_OPEN, - t); - - } + + public static void removeAllFromCurrentTabularResourcesOpen( + HttpSession httpSession) { + httpSession + .removeAttribute(SessionConstants.CURRENT_TABULAR_RESOURCES_OPEN); } - - public static void removeAllFromCurrentTabularResourcesOpen(HttpSession httpSession){ - httpSession.removeAttribute(SessionConstants.CURRENT_TABULAR_RESOURCES_OPEN); - } - - public static TabResource getFirstFromCurrentTabularResourcesOpen(HttpSession httpSession) { + + public static TabResource getFirstFromCurrentTabularResourcesOpen( + HttpSession httpSession) { @SuppressWarnings("unchecked") ArrayList currentTROpen = (ArrayList) httpSession - .getAttribute(SessionConstants.CURRENT_TABULAR_RESOURCES_OPEN ); + .getAttribute(SessionConstants.CURRENT_TABULAR_RESOURCES_OPEN); if (currentTROpen == null || currentTROpen.isEmpty()) { logger.error("No CURRENT_TABULAR_RESOURCES_OPEN"); return null; @@ -248,8 +270,28 @@ public class SessionUtil { return currentTROpen.get(0); } } - - + + public static TabResource getFromCurrentTabularResourcesOpen( + HttpSession httpSession, TRId trId) { + @SuppressWarnings("unchecked") + ArrayList currentTROpen = (ArrayList) 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) { TabResource tabResource = (TabResource) httpSession diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/server/TDGWTServiceImpl.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/TDGWTServiceImpl.java index c04f442..5cc4b71 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/server/TDGWTServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/TDGWTServiceImpl.java @@ -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.Dataset; 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.tr.column.RelationshipData; import org.gcube.resources.discovery.client.api.DiscoveryClient; @@ -278,11 +279,14 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements * {@inheritDoc} */ @Override - public String hello() throws TDGWTServiceException { + public UserInfo hello() throws TDGWTServiceException { HttpSession session = this.getThreadLocalRequest().getSession(); ASLSession aslSession = SessionUtil.getAslSession(session); - String user = aslSession.getUsername(); - return user; + UserInfo userInfo = new UserInfo(aslSession.getUsername(), + aslSession.getGroupId(), aslSession.getGroupName(), + aslSession.getScope(), aslSession.getScopeName(), + aslSession.getUserEmailAddress(), aslSession.getUserFullName()); + return userInfo; } /** @@ -364,7 +368,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements try { HttpSession session = this.getThreadLocalRequest().getSession(); SessionUtil.getAslSession(session); - + SessionUtil.setTabResource(session, null); SessionUtil.setTRId(session, null); SessionUtil.removeAllFromCurrentTabularResourcesOpen(session); @@ -383,25 +387,40 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements } } - + + /** + * + * {@inheritDoc} + */ @Override - public TRId closeTabularResource() throws TDGWTServiceException { + public void closeTabularResourceAndOpen(TRId openTRId, TRId closeTRId) + throws TDGWTServiceException { try { + logger.debug("closeTabularResourceAndOpen(): Open[" + openTRId + + "], Close[" + closeTRId + "]"); 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.removeFromCurrentTabularResourcesOpen(session, + closeTRId); + + 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.setTRId(session, null); - return null; - } else { - SessionUtil.setTabResource(session, firstTR); - SessionUtil.setTRId(session, firstTR.getTrId()); - return firstTR.getTrId(); } - + return; } catch (TDGWTServiceException e) { throw e; @@ -416,7 +435,101 @@ 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()); - ArrayList trMetadatas = getTRMetadata(currentTR - .getTrId()); - updateTabResourceInformation(currentTR, trMetadatas); - AuthorizationProvider.instance.set(new AuthorizationToken( aslSession.getUsername(), aslSession.getScope())); TabularDataService service = TabularDataServiceFactory.getService(); @@ -456,12 +565,17 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements .getTabularResource(new TabularResourceId(Long .valueOf(currentTR.getTrId().getId()))); + ArrayList trMetadatas = getTRMetadata(tr); + updateTabResourceInformation(currentTR, trMetadatas); + currentTR.setDate(sdf.format(tr.getCreationDate().getTime())); currentTR.setValid(tr.isValid()); currentTR.setFinalized(tr.isFinalized()); currentTR.setLocked(tr.isLocked()); Contacts owner = new Contacts("", tr.getOwner(), false); currentTR.setOwner(owner); + currentTR.setContacts(retrieveShareInfo(tr)); + SessionUtil.setTabResource(session, currentTR); logger.debug("GetTabResourceInformation() updated information:" + currentTR.toString()); @@ -504,10 +618,6 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements TabResource currentTR = new TabResource(); currentTR.setTrId(trId); - ArrayList trMetadatas = getTRMetadata(currentTR - .getTrId()); - updateTabResourceInformation(currentTR, trMetadatas); - AuthorizationProvider.instance.set(new AuthorizationToken( aslSession.getUsername(), aslSession.getScope())); TabularDataService service = TabularDataServiceFactory.getService(); @@ -517,12 +627,17 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements .valueOf(currentTR.getTrId().getId()))); logger.debug("GetTabResourceInformation() TR on service: " + tr); + ArrayList trMetadatas = getTRMetadata(tr); + updateTabResourceInformation(currentTR, trMetadatas); + currentTR.setDate(sdf.format(tr.getCreationDate().getTime())); currentTR.setValid(tr.isValid()); currentTR.setFinalized(tr.isFinalized()); currentTR.setLocked(tr.isLocked()); Contacts owner = new Contacts("", tr.getOwner(), false); currentTR.setOwner(owner); + currentTR.setContacts(retrieveShareInfo(tr)); + logger.debug("GetTabResourceInformation() updated information:" + currentTR); return currentTR; @@ -3193,10 +3308,101 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements } } + protected ArrayList getTRMetadata(TabularResource tr) + throws TDGWTServiceException { + try { + + Collection> trMetas = tr + .getAllMetadata(); + + logger.debug("GetTRMetadata size: " + trMetas.size()); + ArrayList listTRMetadata = new ArrayList(); + + 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} */ + @Override public ArrayList getTRMetadata(TRId trId) throws TDGWTServiceException { try { @@ -4588,10 +4794,46 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements } + protected ArrayList retrieveShareInfo(TabularResource tr) + throws TDGWTServiceException { + try { + + ArrayList contacts = new ArrayList(); + List 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 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} */ + /* @Override public ShareInfo getShareInfo(TRId trId) throws TDGWTServiceException { try { @@ -4640,7 +4882,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements throw new TDGWTServiceException("Error in getShareInfo: " + e.getLocalizedMessage()); } - } + }*/ /** * @@ -6747,13 +6989,16 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements aslSession.getUsername(), aslSession.getScope())); TabularDataService service = TabularDataServiceFactory.getService(); checkTabularResourceLocked(service, trId); - TabularResourceId tabularResourceId=new TabularResourceId(Long.parseLong(trId.getId())); - - List resources=service.getResources(tabularResourceId); - ResourceTDCreator resourceTDCreator=new ResourceTDCreator(); - - ArrayList resourcesTD=resourceTDCreator.createResourcesDescriptorTD(resources); - + TabularResourceId tabularResourceId = new TabularResourceId( + Long.parseLong(trId.getId())); + + List resources = service + .getResources(tabularResourceId); + ResourceTDCreator resourceTDCreator = new ResourceTDCreator(); + + ArrayList resourcesTD = resourceTDCreator + .createResourcesDescriptorTD(resources); + return resourcesTD; } catch (TDGWTServiceException e) { throw e; @@ -6762,16 +7007,16 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements throw new TDGWTServiceException( "Security exception, you haven't rights!"); } catch (Throwable e) { - logger.error("Error retrieving resources: " + e.getLocalizedMessage(), - e); + logger.error( + "Error retrieving resources: " + e.getLocalizedMessage(), e); throw new TDGWTServiceException("Error retrieving resources: " + e.getLocalizedMessage()); } } - + @Override - public ArrayList getResourcesTDByType(TRId trId, ResourceTDType resourceTDType) - throws TDGWTServiceException { + public ArrayList getResourcesTDByType(TRId trId, + ResourceTDType resourceTDType) throws TDGWTServiceException { try { HttpSession session = this.getThreadLocalRequest().getSession(); ASLSession aslSession = SessionUtil.getAslSession(session); @@ -6780,14 +7025,18 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements aslSession.getUsername(), aslSession.getScope())); TabularDataService service = TabularDataServiceFactory.getService(); checkTabularResourceLocked(service, trId); - TabularResourceId tabularResourceId=new TabularResourceId(Long.parseLong(trId.getId())); - ResourceType resourceType=ResourceTDTypeMap.getResourceType(resourceTDType); - - List resources=service.getResourcesByType(tabularResourceId,resourceType); - ResourceTDCreator resourceTDCreator=new ResourceTDCreator(); - - ArrayList resourcesTD=resourceTDCreator.createResourcesDescriptorTD(resources); - + TabularResourceId tabularResourceId = new TabularResourceId( + Long.parseLong(trId.getId())); + ResourceType resourceType = ResourceTDTypeMap + .getResourceType(resourceTDType); + + List resources = service.getResourcesByType( + tabularResourceId, resourceType); + ResourceTDCreator resourceTDCreator = new ResourceTDCreator(); + + ArrayList resourcesTD = resourceTDCreator + .createResourcesDescriptorTD(resources); + return resourcesTD; } catch (TDGWTServiceException e) { throw e; @@ -6796,10 +7045,12 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements throw new TDGWTServiceException( "Security exception, you haven't rights!"); } catch (Throwable e) { - logger.error("Error retrieving resources by type: " + e.getLocalizedMessage(), - e); - throw new TDGWTServiceException("Error retrieving resources by type: " - + e.getLocalizedMessage()); + logger.error( + "Error retrieving resources by type: " + + e.getLocalizedMessage(), e); + throw new TDGWTServiceException( + "Error retrieving resources by type: " + + e.getLocalizedMessage()); } } @@ -6815,7 +7066,6 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements aslSession.getUsername(), aslSession.getScope())); TabularDataService service = TabularDataServiceFactory.getService(); checkTabularResourceLocked(service, mapCreationSession.getTrId()); - OpExecution4MapCreation opEx = new OpExecution4MapCreation(service, mapCreationSession); @@ -6853,7 +7103,5 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements } } - - } diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/TabResource.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/TabResource.java index 4856708..5af88fd 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/TabResource.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/TabResource.java @@ -1,6 +1,7 @@ package org.gcube.portlets.user.td.gwtservice.shared.tr; import java.io.Serializable; +import java.util.ArrayList; import org.gcube.portlets.user.td.gwtservice.shared.share.Contacts; import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId; @@ -26,6 +27,7 @@ public class TabResource implements Serializable { protected String validUntilTo; protected String licence; protected Contacts owner; + protected ArrayList contacts; protected boolean valid; protected boolean finalized; protected boolean locked; @@ -174,6 +176,14 @@ public class TabResource implements Serializable { public void setLocked(boolean locked) { this.locked = locked; } + + public ArrayList getContacts() { + return contacts; + } + + public void setContacts(ArrayList contacts) { + this.contacts = contacts; + } @Override public String toString() { @@ -181,9 +191,11 @@ public class TabResource implements Serializable { + ", description=" + description + ", agency=" + agency + ", date=" + date + ", right=" + right + ", validFrom=" + validFrom + ", validUntilTo=" + validUntilTo + ", licence=" - + licence + ", owner=" + owner + ", valid=" + valid - + ", finalized=" + finalized + ", locked=" + locked + "]"; + + licence + ", owner=" + owner + ", contacts=" + contacts + + ", valid=" + valid + ", finalized=" + finalized + ", locked=" + + locked + "]"; } - + + } diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/user/UserInfo.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/user/UserInfo.java index 6d8b429..b7a345d 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/user/UserInfo.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/user/UserInfo.java @@ -13,7 +13,7 @@ public class UserInfo implements Serializable { private static final long serialVersionUID = -2826549639677017234L; private String username; - private int groupId; + private long groupId; private String groupName; private String scope; private String scopeName; @@ -34,7 +34,7 @@ public class UserInfo implements Serializable { * @param userEmailAddress * @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 userFullName) { super(); @@ -55,11 +55,11 @@ public class UserInfo implements Serializable { this.username = username; } - public int getGroupId() { + public long getGroupId() { return groupId; } - public void setGroupId(int groupId) { + public void setGroupId(long groupId) { this.groupId = groupId; }