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 3e55e0e..6334ec6 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 @@ -23,6 +23,7 @@ import org.gcube.portlets.user.td.gwtservice.shared.source.SDMXRegistrySource; import org.gcube.portlets.user.td.gwtservice.shared.template.TemplateApplyMonitor; import org.gcube.portlets.user.td.gwtservice.shared.template.TemplateApplySession; import org.gcube.portlets.user.td.gwtservice.shared.template.TemplateData; +import org.gcube.portlets.user.td.gwtservice.shared.template.TemplateDeleteSession; import org.gcube.portlets.user.td.gwtservice.shared.tr.ColumnData; import org.gcube.portlets.user.td.gwtservice.shared.tr.TabResource; import org.gcube.portlets.user.td.gwtservice.shared.tr.TableData; @@ -201,6 +202,15 @@ public interface TDGWTService extends RemoteService { */ public ArrayList getTabularResources() throws TDGWTServiceException; + + /** + * Return all tabular resource of a user and last tables + * + * @return + * @throws TDGWTServiceException + */ + /*public ArrayList getTabularResourcesAndLastTables() + throws TDGWTServiceException;*/ //Clone /** @@ -598,7 +608,7 @@ public interface TDGWTService extends RemoteService { public ArrayList getTemplates() throws TDGWTServiceException; /** - * Get Operation Monitor during ApplyTemplate operation + * Get Operation Monitor during Apply Template operation * * @param callback */ @@ -611,7 +621,17 @@ public interface TDGWTService extends RemoteService { * @param applyTemplateSession * */ - void startTemplateApply(TemplateApplySession applyTemplateSession) throws TDGWTServiceException; + void startTemplateApply(TemplateApplySession templateApplySession) throws TDGWTServiceException; + + /** + * Start Delete Template + * + * @param applyTemplateSession + * + */ + void startTemplateDelete(TemplateDeleteSession templateDeleteSession) throws TDGWTServiceException; + + } 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 37ef1d1..8b2fa1c 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 @@ -22,6 +22,7 @@ import org.gcube.portlets.user.td.gwtservice.shared.source.SDMXRegistrySource; import org.gcube.portlets.user.td.gwtservice.shared.template.TemplateApplyMonitor; import org.gcube.portlets.user.td.gwtservice.shared.template.TemplateApplySession; import org.gcube.portlets.user.td.gwtservice.shared.template.TemplateData; +import org.gcube.portlets.user.td.gwtservice.shared.template.TemplateDeleteSession; import org.gcube.portlets.user.td.gwtservice.shared.tr.ColumnData; import org.gcube.portlets.user.td.gwtservice.shared.tr.TabResource; import org.gcube.portlets.user.td.gwtservice.shared.tr.TableData; @@ -80,6 +81,8 @@ public interface TDGWTServiceAsync { void getTabularResources(AsyncCallback> callback); + //void getTabularResourcesAndLastTables(AsyncCallback> callback); + void getLastTable(TRId trId, AsyncCallback callback); void getTable(TRId trId, AsyncCallback callback); @@ -187,7 +190,9 @@ public interface TDGWTServiceAsync { //Templates void getTemplates(AsyncCallback> callback); void getTemplateApplyMonitor(AsyncCallback callback); - void startTemplateApply(TemplateApplySession applyTemplateSession,AsyncCallback callback); + void startTemplateApply(TemplateApplySession templateDeleteSession,AsyncCallback callback); + void startTemplateDelete(TemplateDeleteSession templateDeleteSession,AsyncCallback callback); + 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 6d34a07..00afac8 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 @@ -65,6 +65,7 @@ import org.gcube.data.analysis.tabulardata.model.table.Table; import org.gcube.data.analysis.tabulardata.model.table.TableId; import org.gcube.data.analysis.tabulardata.model.table.type.CodelistTableType; import org.gcube.data.analysis.tabulardata.service.TabularDataService; +import org.gcube.data.analysis.tabulardata.service.exception.NoSuchTemplateException; import org.gcube.data.analysis.tabulardata.service.impl.TabularDataServiceFactory; import org.gcube.data.analysis.tabulardata.service.operation.Task; import org.gcube.data.analysis.tabulardata.service.tabular.TabularResource; @@ -110,6 +111,7 @@ import org.gcube.portlets.user.td.gwtservice.shared.source.SDMXRegistrySource; import org.gcube.portlets.user.td.gwtservice.shared.template.TemplateApplyMonitor; import org.gcube.portlets.user.td.gwtservice.shared.template.TemplateApplySession; import org.gcube.portlets.user.td.gwtservice.shared.template.TemplateData; +import org.gcube.portlets.user.td.gwtservice.shared.template.TemplateDeleteSession; import org.gcube.portlets.user.td.gwtservice.shared.tr.ColumnData; import org.gcube.portlets.user.td.gwtservice.shared.tr.ColumnViewData; import org.gcube.portlets.user.td.gwtservice.shared.tr.TabResource; @@ -1163,7 +1165,60 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements /** * * {@inheritDoc} + + @Override + public ArrayList getTabularResourcesAndLastTables() + throws TDGWTServiceException { + try { + HttpSession session = this.getThreadLocalRequest().getSession(); + ASLSession aslSession = SessionUtil.getAslSession(session); + logger.debug("GetTabularResources"); + AuthorizationProvider.instance.set(new AuthorizationToken( + aslSession.getUsername())); + TabularDataService service = TabularDataServiceFactory.getService(); + + List trs = service.getTabularResources(); + SessionUtil.setTabularResources(session, trs); + + ArrayList ltr = new ArrayList(); + + int i; + for (i = 0; i < trs.size(); i++) { + TabularResource tr = trs.get(i); + logger.debug("GetTabularResources RetrieveMetadata"); + try { + TabResource t = retrieveTRMetadataFromService(service, tr, + i); + + if (t.getTrId() != null) { + ltr.add(t); + } + } catch (Throwable e) { + logger.error("TabResource discarded: " + tr + " cause: " + + e.getMessage()); + } + } + + logger.debug("Tabular Resources retrived: " + ltr); + return ltr; + } catch (Throwable e) { + e.printStackTrace(); + logger.error("Error retrieving TabularResources: " + + e.getLocalizedMessage()); + throw new TDGWTServiceException( + "Error retrieving TabularResources: " + + e.getLocalizedMessage()); + } + + } + */ + + /** + * + * + * {@inheritDoc} */ + @Override public ArrayList getTabularResources() throws TDGWTServiceException { try { @@ -1208,6 +1263,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements } } + /** * @@ -4378,7 +4434,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements AuthorizationProvider.instance.set(new AuthorizationToken( aslSession.getUsername())); TabularDataService service = TabularDataServiceFactory.getService(); - + TemplateId templateId=new TemplateId(templateApplySession.getTemplateData().getId()); TabularResourceId tabularResourceId=new TabularResourceId(new Long(templateApplySession.getTrId().getId())); Task task=service.applyTemplate(templateId, tabularResourceId); @@ -4501,5 +4557,45 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements } } + + /** + * + * {@inheritDoc} + */ + @Override + public void startTemplateDelete(TemplateDeleteSession templateDeleteSession) + throws TDGWTServiceException { + try { + HttpSession session = this.getThreadLocalRequest().getSession(); + ASLSession aslSession = SessionUtil.getAslSession(session); + logger.debug("startTemplateDelete: "+ templateDeleteSession); + + AuthorizationProvider.instance.set(new AuthorizationToken( + aslSession.getUsername())); + TabularDataService service = TabularDataServiceFactory.getService(); + + TemplateId templateId; + for(TemplateData template: templateDeleteSession.getTemplates()){ + templateId=new TemplateId(template.getId()); + service.remove(templateId); + } + + } catch (NoSuchTemplateException e) { + logger.debug("Error StartTemplateDelete: No such Template"); + e.printStackTrace(); + throw new TDGWTServiceException( + "Error StartTemplateDelete: No such Template"); + } catch (Throwable e) { + logger.debug("Error StartTemplateDelete: " + + e.getLocalizedMessage()); + e.printStackTrace(); + throw new TDGWTServiceException( + "Error StartTemplateDelete: " + + e.getLocalizedMessage()); + } + + + } + } diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/template/TemplateDeleteSession.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/template/TemplateDeleteSession.java new file mode 100644 index 0000000..f4a4363 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/template/TemplateDeleteSession.java @@ -0,0 +1,36 @@ +package org.gcube.portlets.user.td.gwtservice.shared.template; + +import java.io.Serializable; +import java.util.ArrayList; + +import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId; + +/** + * Delete Template Session + * + * @author "Giancarlo Panichi" g.panichi@isti.cnr.it + * + */ +public class TemplateDeleteSession implements Serializable { + + private static final long serialVersionUID = -8834066207159106968L; + protected ArrayList templates; + + public ArrayList getTemplates() { + return templates; + } + + public void setTemplates(ArrayList templates) { + this.templates = templates; + } + + @Override + public String toString() { + return "TemplateDeleteSession [templates=" + templates + "]"; + } + + + + +}