From 9773cf651280d1509135bbe8a72090913561ebde Mon Sep 17 00:00:00 2001 From: Giancarlo Panichi Date: Wed, 29 Oct 2014 09:14:34 +0000 Subject: [PATCH] Added Remove Resource git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-gwt-service@101111 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../gwtservice/client/rpc/TDGWTService.java | 31 +++++---- .../gwtservice/server/TDGWTServiceImpl.java | 68 +++++++++++++++++++ .../tr/resources/RemoveResourceSession.java | 54 +++++++++++++++ 3 files changed, 141 insertions(+), 12 deletions(-) create mode 100644 src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/resources/RemoveResourceSession.java 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 695563c..28811c8 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 @@ -53,6 +53,7 @@ import org.gcube.portlets.user.td.gwtservice.shared.tr.normalization.Normalizati import org.gcube.portlets.user.td.gwtservice.shared.tr.open.TDOpenSession; import org.gcube.portlets.user.td.gwtservice.shared.tr.paging.CodelistPagingLoadConfig; import org.gcube.portlets.user.td.gwtservice.shared.tr.paging.CodelistPagingLoadResult; +import org.gcube.portlets.user.td.gwtservice.shared.tr.resources.RemoveResourceSession; import org.gcube.portlets.user.td.gwtservice.shared.tr.resources.ResourceTDDescriptor; import org.gcube.portlets.user.td.gwtservice.shared.tr.resources.ResourceTDType; import org.gcube.portlets.user.td.gwtservice.shared.tr.rows.DeleteRowsSession; @@ -455,10 +456,10 @@ public interface TDGWTService extends RemoteService { */ public ArrayList getColumns(TRId trId) throws TDGWTServiceException; - + /** - * Retrieves the list of columns in the table provided by trId - * view columns included + * Retrieves the list of columns in the table provided by trId view columns + * included * * @param trId * @return @@ -467,10 +468,9 @@ public interface TDGWTService extends RemoteService { public ArrayList getColumnWithViewColumnIncluded(TRId trId) throws TDGWTServiceException; - /** - * Retrieves the list of columns in the table provided by trId - * for statistical + * Retrieves the list of columns in the table provided by trId for + * statistical * * @param trId * @return @@ -1016,6 +1016,15 @@ public interface TDGWTService extends RemoteService { public ArrayList getResourcesTDByType(TRId trId, ResourceTDType resourceTDType) throws TDGWTServiceException; + /** + * Remove resource + * + * @param removeResourceSession + * @throws TDGWTServiceException + */ + public void removeResource(RemoveResourceSession removeResourceSession) + throws TDGWTServiceException; + // GIS MAP /** * Start Map Creation and invokes the client library @@ -1026,8 +1035,7 @@ public interface TDGWTService extends RemoteService { */ public String startMapCreation(MapCreationSession mapCreationSession) throws TDGWTServiceException; - - + // Statistical /** * @@ -1035,9 +1043,8 @@ public interface TDGWTService extends RemoteService { * @return * @throws TDGWTServiceException */ - public String startStatisticalOperation(StatisticalOperationSession statisticalOperationSession) - throws TDGWTServiceException; - - + public String startStatisticalOperation( + StatisticalOperationSession statisticalOperationSession) + throws TDGWTServiceException; } 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 8b8f2ba..bd676d8 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 @@ -232,6 +232,7 @@ import org.gcube.portlets.user.td.gwtservice.shared.tr.paging.CodelistPagingLoad import org.gcube.portlets.user.td.gwtservice.shared.tr.paging.CodelistPagingLoadResult; import org.gcube.portlets.user.td.gwtservice.shared.tr.paging.Direction; import org.gcube.portlets.user.td.gwtservice.shared.tr.paging.OrderInfo; +import org.gcube.portlets.user.td.gwtservice.shared.tr.resources.RemoveResourceSession; import org.gcube.portlets.user.td.gwtservice.shared.tr.resources.ResourceTDDescriptor; import org.gcube.portlets.user.td.gwtservice.shared.tr.resources.ResourceTDType; import org.gcube.portlets.user.td.gwtservice.shared.tr.rows.DeleteRowsSession; @@ -2793,6 +2794,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements * @param tabResource * @throws TDGWTServiceException */ + @Override public void removeTabularResource(TRId trId) throws TDGWTServiceException { try { HttpSession session = this.getThreadLocalRequest().getSession(); @@ -7801,6 +7803,72 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements } } + /** + * + * @param tabResource + * @throws TDGWTServiceException + */ + @Override + public void removeResource(RemoveResourceSession removeResourceSession) + throws TDGWTServiceException { + try { + HttpSession session = this.getThreadLocalRequest().getSession(); + ASLSession aslSession = SessionUtil.getAslSession(session); + logger.debug("Remove Resource: " + removeResourceSession); + + if (removeResourceSession == null) { + logger.error("Error removing Resource: removeResourceSession null"); + throw new TDGWTServiceException( + "Error removing Resource no parameters set"); + } + TRId trId = removeResourceSession.getTrId(); + if (trId == null) { + logger.error("Error removing Resource: trId is null"); + throw new TDGWTServiceException( + "Error removing Resource no tabular resource set"); + } + AuthorizationProvider.instance.set(new AuthorizationToken( + aslSession.getUsername(), aslSession.getScope())); + TabularDataService service = TabularDataServiceFactory.getService(); + checkTRId(trId); + TabularResourceId tabResourceId = new TabularResourceId( + Long.valueOf(trId.getId())); + TabularResource tabularResource = service + .getTabularResource(tabResourceId); + + checkTabularResourceLocked(tabularResource); + + String owner = tabularResource.getOwner(); + if (owner != null && owner.compareTo(aslSession.getUsername()) == 0) { + if (removeResourceSession.getResourceTDDescriptor() == null) { + logger.error("Error removing Resource: descriptor null"); + throw new TDGWTServiceException( + "Error removing Resource no descriptor set"); + } + service.removeResurce(removeResourceSession + .getResourceTDDescriptor().getId()); + } else { + throw new TDGWTServiceException( + "You are not the owner of this tabular resource (owner: " + + owner + ")"); + } + 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( + "Error deleting the resource: " + e.getLocalizedMessage(), + e); + throw new TDGWTServiceException("Error deleting the resource: " + + e.getLocalizedMessage()); + } + } + @Override public String startMapCreation(MapCreationSession mapCreationSession) throws TDGWTServiceException { diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/resources/RemoveResourceSession.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/resources/RemoveResourceSession.java new file mode 100644 index 0000000..20f44f6 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/resources/RemoveResourceSession.java @@ -0,0 +1,54 @@ +package org.gcube.portlets.user.td.gwtservice.shared.tr.resources; + +import java.io.Serializable; + +import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId; + +/** + * + * @author giancarlo + * email: g.panichi@isti.cnr.it + * + */ +public class RemoveResourceSession implements Serializable { + + private static final long serialVersionUID = -48669918467995522L; + protected TRId trId; + protected ResourceTDDescriptor resourceTDDescriptor; + + public RemoveResourceSession(){ + + } + + public RemoveResourceSession(TRId trId, + ResourceTDDescriptor resourceTDDescriptor) { + super(); + this.trId = trId; + this.resourceTDDescriptor = resourceTDDescriptor; + } + + public TRId getTrId() { + return trId; + } + + public void setTrId(TRId trId) { + this.trId = trId; + } + + public ResourceTDDescriptor getResourceTDDescriptor() { + return resourceTDDescriptor; + } + + public void setResourceTDDescriptor(ResourceTDDescriptor resourceTDDescriptor) { + this.resourceTDDescriptor = resourceTDDescriptor; + } + + @Override + public String toString() { + return "RemoveResourceSession [trId=" + trId + + ", resourceTDDescriptor=" + resourceTDDescriptor + "]"; + } + + + +}