From 05bab63e7f7c1d6a457c21a96409c5b1ba616d75 Mon Sep 17 00:00:00 2001 From: Giancarlo Panichi Date: Fri, 30 Jan 2015 17:34:51 +0000 Subject: [PATCH] Updated Collateral Table git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-gwt-service@111577 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../gwtservice/client/rpc/TDGWTService.java | 35 ++-- .../client/rpc/TDGWTServiceAsync.java | 2 + .../gwtservice/server/TDGWTServiceImpl.java | 151 ++++++++++++++---- .../ExtractCodelistOperationMap.java | 5 +- .../extract/ExtractCodelistSession.java | 19 ++- .../BackgroundOperationMonitorCreator.java | 120 ++++++++++---- .../shared/monitor/OperationMonitor.java | 17 +- .../monitor/OperationMonitorCreator.java | 59 ++++++- .../user/td/gwtservice/shared/task/TaskS.java | 28 +++- .../column/type/ChangeColumnTypeSession.java | 55 ++++--- 10 files changed, 354 insertions(+), 137 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 6cabd7c..e0d75c1 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 @@ -105,15 +105,13 @@ public interface TDGWTService extends RemoteService { */ public UserInfo hello() throws TDGWTServiceException; - /** * Retrieve pending Tasks and set them as background tasks * * @throws TDGWTServiceException */ public Integer pendingTasksRetrieve() throws TDGWTServiceException; - - + /** * Restore UI session * @@ -168,6 +166,14 @@ public interface TDGWTService extends RemoteService { public void setTabResourceInformation(TabResource tabResource) throws TDGWTServiceException; + /** + * Set tabular resource to final + * + * @param trId + * @throws TDGWTServiceException + */ + public void setTabResourceToFinal(TRId trId) throws TDGWTServiceException; + /** * Get informations on tabular resource * @@ -454,7 +460,6 @@ public interface TDGWTService extends RemoteService { public void tdOpen(TDOpenSession tdOpenSession) throws TDGWTServiceException; - /** * Retrieve Time Table Id * @@ -462,9 +467,9 @@ public interface TDGWTService extends RemoteService { * @return * @throws TDGWTServiceException */ - public Long getTimeTableId(PeriodDataType periodDataType) + public Long getTimeTableId(PeriodDataType periodDataType) throws TDGWTServiceException; - + /** * Retrieves the list of columns in the current table * @@ -838,18 +843,17 @@ public interface TDGWTService extends RemoteService { public String startReplaceColumn(ReplaceColumnSession replaceColumnSession) throws TDGWTServiceException; - /** - * Start replace column by external tabular resource + * Start replace column by external tabular resource * * @param replaceByExternalSession * @return * @throws TDGWTServiceException */ - public String startReplaceByExternal(ReplaceByExternalSession replaceByExternalSession) + public String startReplaceByExternal( + ReplaceByExternalSession replaceByExternalSession) throws TDGWTServiceException; - // Templates /** * Retrieves templates of user @@ -1061,17 +1065,15 @@ public interface TDGWTService extends RemoteService { */ public void removeResource(RemoveResourceSession removeResourceSession) throws TDGWTServiceException; - + /** * Save resource on Workspace * * @param saveResourceSession * @throws TDGWTServiceException */ - public void saveResource( - SaveResourceSession saveResourceSession) + public void saveResource(SaveResourceSession saveResourceSession) throws TDGWTServiceException; - // GIS MAP /** @@ -1103,7 +1105,8 @@ public interface TDGWTService extends RemoteService { * @return * @throws TDGWTServiceException */ - public String startChartTopRating(ChartTopRatingSession chartTopRatingSession) + public String startChartTopRating( + ChartTopRatingSession chartTopRatingSession) 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 9d66ba3..fdfb0fd 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 @@ -117,6 +117,8 @@ public interface TDGWTServiceAsync { void setTabResourceInformation(TabResource tabResource, AsyncCallback callback); + void setTabResourceToFinal(TRId trId, AsyncCallback callback); + void getTRCreationDate(TRId trId, AsyncCallback callback); void setTabResource(TabResource tabResource, 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 26db88c..d13ecaa 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 @@ -91,6 +91,7 @@ import org.gcube.data.analysis.tabulardata.service.impl.TabularDataServiceFactor import org.gcube.data.analysis.tabulardata.service.operation.Job; import org.gcube.data.analysis.tabulardata.service.operation.Task; import org.gcube.data.analysis.tabulardata.service.operation.TaskId; +import org.gcube.data.analysis.tabulardata.service.operation.TaskResult; import org.gcube.data.analysis.tabulardata.service.tabular.HistoryStep; import org.gcube.data.analysis.tabulardata.service.tabular.HistoryStepId; import org.gcube.data.analysis.tabulardata.service.tabular.TabularResource; @@ -319,50 +320,53 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements @Override public Integer pendingTasksRetrieve() throws TDGWTServiceException { try { - + HttpSession session = this.getThreadLocalRequest().getSession(); ASLSession aslSession = SessionUtil.getAslSession(session); logger.debug("pendingTasksRetrieve()"); AuthorizationProvider.instance.set(new AuthorizationToken( aslSession.getUsername(), aslSession.getScope())); - TabularDataService service = TabularDataServiceFactory - .getService(); - - ArrayList pendingTR=new ArrayList(); - List trs=service.getTabularResources(); - for(TabularResource tr:trs){ - if(tr.isLocked()){ + TabularDataService service = TabularDataServiceFactory.getService(); + + ArrayList pendingTR = new ArrayList(); + List trs = service.getTabularResources(); + for (TabularResource tr : trs) { + if (tr.isLocked()) { pendingTR.add(tr); } } - - Integer pendingNumber=0; - - for(TabularResource tr:pendingTR){ - logger.debug("Pending Task:"+ tr.getId()); - List tasksInitializing=service.getTasks(tr.getId(), TaskStatus.INITIALIZING); - List tasksInProgress=service.getTasks(tr.getId(), TaskStatus.IN_PROGRESS); - List tasksValidatingRules=service.getTasks(tr.getId(), TaskStatus.VALIDATING_RULES); - HashMap tasks=new HashMap(); - for(Task t:tasksInitializing){ - tasks.put(t.getId().getValue(),t); + + Integer pendingNumber = 0; + + for (TabularResource tr : pendingTR) { + logger.debug("Pending Task:" + tr.getId()); + List tasksInitializing = service.getTasks(tr.getId(), + TaskStatus.INITIALIZING); + List tasksInProgress = service.getTasks(tr.getId(), + TaskStatus.IN_PROGRESS); + List tasksValidatingRules = service.getTasks(tr.getId(), + TaskStatus.VALIDATING_RULES); + HashMap tasks = new HashMap(); + for (Task t : tasksInitializing) { + tasks.put(t.getId().getValue(), t); } - for(Task t:tasksInProgress){ - tasks.put(t.getId().getValue(),t); + for (Task t : tasksInProgress) { + tasks.put(t.getId().getValue(), t); } - for(Task t:tasksValidatingRules){ - tasks.put(t.getId().getValue(),t); + for (Task t : tasksValidatingRules) { + tasks.put(t.getId().getValue(), t); } - - TRId trId=new TRId(String.valueOf(tr.getId().getValue())); - for(String key:tasks.keySet()){ - TaskWrapper taskWrapper=new TaskWrapper(tasks.get(key),UIOperationsId.Pending, trId); + + TRId trId = new TRId(String.valueOf(tr.getId().getValue())); + for (String key : tasks.keySet()) { + TaskWrapper taskWrapper = new TaskWrapper(tasks.get(key), + UIOperationsId.Pending, trId); SessionUtil.setTaskInBackground(session, taskWrapper); pendingNumber++; } } - - logger.debug("Pending number: "+pendingNumber); + + logger.debug("Pending number: " + pendingNumber); return pendingNumber; } catch (TDGWTServiceException e) { throw e; @@ -5719,6 +5723,57 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements } + /** + * + * {@inheritDoc} + */ + @Override + public void setTabResourceToFinal(TRId trId) throws TDGWTServiceException { + try { + HttpSession session = this.getThreadLocalRequest().getSession(); + ASLSession aslSession = SessionUtil.getAslSession(session); + logger.debug("SetTabResourceToFinal: " + trId); + AuthorizationProvider.instance.set(new AuthorizationToken( + aslSession.getUsername(), aslSession.getScope())); + TabularDataService service = TabularDataServiceFactory.getService(); + + checkTRId(trId); + + TabularResourceId tabularResourceId = new TabularResourceId( + Long.valueOf(trId.getId())); + TabularResource tr = service.getTabularResource(tabularResourceId); + + checkTabularResourceLocked(tr); + checkTabularResourceIsFinal(tr); + + logger.debug("setTabResourceToFinal: " + tr); + + if (tr.isValid()) { + if (!tr.isFinalized()) { + tr.finalize(); + } + } else { + throw new TDGWTServiceException( + "Only valid tabular resource can be finalized!"); + } + + logger.debug("setTabResourceToFinal - new information:" + tr); + + } catch (TDGWTServiceException e) { + throw e; + } catch (SecurityException e) { + e.printStackTrace(); + throw new TDGWTServiceException(SECURITY_EXCEPTION_RIGHTS); + } catch (Throwable e) { + logger.debug("Error in setTabResourceToFinal: " + + e.getLocalizedMessage()); + e.printStackTrace(); + throw new TDGWTServiceException("Error in setTabResourceToFinal: " + + e.getLocalizedMessage()); + } + + } + /** * * {@inheritDoc} @@ -6525,6 +6580,28 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements } } + private String retrieveTabularResourceIdFromTable(TabularDataService service, + TableId tableId) throws TDGWTServiceException { + try { + + Table table = service.getTable(tableId); + + if (table.contains(TableDescriptorMetadata.class)) { + TableDescriptorMetadata tdm = table + .getMetadata(TableDescriptorMetadata.class); + return String.valueOf(tdm.getRefId()); + } else { + throw new TDGWTServiceException( + "No TableDescriptorMetadata present in tableId: " + + tableId); + } + + } catch (Exception e) { + throw new TDGWTServiceException(e.getLocalizedMessage()); + } + + } + @Override public ValidationsTasksMetadata getValidationsTasksMetadata(TRId trId) throws TDGWTServiceException { @@ -6590,11 +6667,25 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements j++; } + + ArrayList collateralTRIds = new ArrayList(); + TaskResult taskResult = task.getResult(); + if (taskResult != null) { + List collateral = taskResult.getCollateralTables(); + for (TableId tId : collateral) { + String id=retrieveTabularResourceIdFromTable(service,tId); + TRId tabularRId= new TRId(id); + tabularRId.setTableId(String.valueOf(tId)); + collateralTRIds.add(tabularRId); + } + + } + State state = TaskStateMap.map(task.getStatus()); TaskS taskS = new TaskS(task.getId().getValue(), task.getProgress(), state, task.getErrorCause(), task.getSubmitter(), task.getStartTime(), - task.getEndTime(), jobSList); + task.getEndTime(), jobSList, collateralTRIds); taskSList.add(taskS); } diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/server/trservice/ExtractCodelistOperationMap.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/trservice/ExtractCodelistOperationMap.java index 169546a..11fde4f 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/server/trservice/ExtractCodelistOperationMap.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/trservice/ExtractCodelistOperationMap.java @@ -27,8 +27,9 @@ import org.slf4j.LoggerFactory; /** * - * @author "Giancarlo Panichi" - * + * @author giancarlo + * email: g.panichi@isti.cnr.it + * */ public class ExtractCodelistOperationMap { protected static Logger logger = LoggerFactory diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/extract/ExtractCodelistSession.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/extract/ExtractCodelistSession.java index 86b6f6d..2233d24 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/extract/ExtractCodelistSession.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/extract/ExtractCodelistSession.java @@ -25,6 +25,7 @@ public class ExtractCodelistSession implements Serializable { private ArrayList sourceColumns; private ArrayList targetColumns; private boolean automaticallyAttach; + private ColumnData attachColumn; public ExtractCodelistSession() { } @@ -32,12 +33,13 @@ public class ExtractCodelistSession implements Serializable { public ExtractCodelistSession(TRId trId, TabResource tabResource, ArrayList sourceColumns, ArrayList targetColumns, - boolean automaticallyAttach) { + boolean automaticallyAttach, ColumnData attachColumn) { this.trId = trId; this.tabResource = tabResource; this.sourceColumns = sourceColumns; this.targetColumns = targetColumns; this.automaticallyAttach = automaticallyAttach; + this.attachColumn = attachColumn; } public ArrayList getSourceColumns() { @@ -72,8 +74,7 @@ public class ExtractCodelistSession implements Serializable { public void setTrId(TRId trId) { this.trId = trId; } - - + public boolean isAutomaticallyAttach() { return automaticallyAttach; } @@ -82,14 +83,20 @@ public class ExtractCodelistSession implements Serializable { this.automaticallyAttach = automaticallyAttach; } + public ColumnData getAttachColumn() { + return attachColumn; + } + + public void setAttachColumn(ColumnData attachColumn) { + this.attachColumn = attachColumn; + } + @Override public String toString() { return "ExtractCodelistSession [trId=" + trId + ", tabResource=" + tabResource + ", sourceColumns=" + sourceColumns + ", targetColumns=" + targetColumns + ", automaticallyAttach=" - + automaticallyAttach + "]"; + + automaticallyAttach + ", attachColumn=" + attachColumn + "]"; } - - } diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/monitor/BackgroundOperationMonitorCreator.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/monitor/BackgroundOperationMonitorCreator.java index ebda723..5a26ba7 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/monitor/BackgroundOperationMonitorCreator.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/monitor/BackgroundOperationMonitorCreator.java @@ -2,6 +2,7 @@ package org.gcube.portlets.user.td.gwtservice.shared.monitor; import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.List; import javax.servlet.http.HttpSession; @@ -9,13 +10,16 @@ import org.gcube.application.framework.core.session.ASLSession; import org.gcube.data.analysis.tabulardata.commons.utils.AuthorizationProvider; import org.gcube.data.analysis.tabulardata.commons.utils.AuthorizationToken; import org.gcube.data.analysis.tabulardata.commons.webservice.types.TaskStatus; +import org.gcube.data.analysis.tabulardata.model.metadata.common.TableDescriptorMetadata; import org.gcube.data.analysis.tabulardata.model.metadata.table.DatasetViewTableMetadata; import org.gcube.data.analysis.tabulardata.model.metadata.table.ExportMetadata; import org.gcube.data.analysis.tabulardata.model.table.Table; +import org.gcube.data.analysis.tabulardata.model.table.TableId; import org.gcube.data.analysis.tabulardata.service.TabularDataService; import org.gcube.data.analysis.tabulardata.service.impl.TabularDataServiceFactory; import org.gcube.data.analysis.tabulardata.service.operation.Job; import org.gcube.data.analysis.tabulardata.service.operation.Task; +import org.gcube.data.analysis.tabulardata.service.operation.TaskResult; import org.gcube.data.analysis.tabulardata.service.operation.ValidationJob; import org.gcube.data.analysis.tabulardata.service.tabular.TabularResource; import org.gcube.data.analysis.tabulardata.service.tabular.TabularResourceId; @@ -46,7 +50,7 @@ import org.slf4j.LoggerFactory; */ public class BackgroundOperationMonitorCreator { private static final String SECURITY_EXCEPTION_RIGHTS = "Security exception, you don't have the required rights!"; - + private static Logger logger = LoggerFactory .getLogger(BackgroundOperationMonitorCreator.class); @@ -54,8 +58,7 @@ public class BackgroundOperationMonitorCreator { "yyyy-MM-dd HH:mm"); @SuppressWarnings("unused") - private static SimpleDateFormat sdfDate = new SimpleDateFormat( - "yyyy-MM-dd"); + private static SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd"); protected HttpSession session; protected TaskWrapper taskWrapper; @@ -147,7 +150,7 @@ public class BackgroundOperationMonitorCreator { return operationMonitor; } - protected TaskS createTaskS() { + protected TaskS createTaskS() throws TDGWTServiceException { TaskS taskS = new TaskS(); ArrayList jobSList = new ArrayList(); @@ -176,14 +179,40 @@ public class BackgroundOperationMonitorCreator { } - taskS = new TaskS(taskWrapper.getTask().getId().getValue(), taskWrapper - .getTask().getProgress(), TaskStateMap.map(taskWrapper - .getTask().getStatus()), taskWrapper.getTask().getErrorCause(), - taskWrapper.getTask().getSubmitter(), taskWrapper.getTask() - .getStartTime(), taskWrapper.getTask().getEndTime(), - jobSList); + try { + ArrayList collateralTRIds=new ArrayList(); + TaskResult taskResult=taskWrapper.getTask().getResult(); + if(taskResult!=null){ + List collaterals=taskResult.getCollateralTables(); + for(TableId tId:collaterals){ + String tabulRId=retrieveTabularResourceIdFromTable(tId); + TRId tabularRId=new TRId(tabulRId); + tabularRId.setTableId(String.valueOf(tId.getValue())); + collateralTRIds.add(tabularRId); + } + + } + + taskS = new TaskS(taskWrapper.getTask().getId().getValue(), + taskWrapper.getTask().getProgress(), + TaskStateMap.map(taskWrapper.getTask().getStatus()), + taskWrapper.getTask().getErrorCause(), taskWrapper + .getTask().getSubmitter(), taskWrapper.getTask() + .getStartTime(), + taskWrapper.getTask().getEndTime(), jobSList, + collateralTRIds); + + } catch (Throwable e) { + logger.error("error retrieving information about the task, " + + e.getLocalizedMessage()); + e.printStackTrace(); + throw new TDGWTServiceException( + "error retrieving information about the task, " + + e.getLocalizedMessage()); + } logger.debug("Retrieved task information"); + return taskS; } @@ -228,7 +257,7 @@ public class BackgroundOperationMonitorCreator { protected void updateInformations(OperationMonitor operationMonitor) throws TDGWTServiceException { TRId trId; - //TabResource tabResource; + // TabResource tabResource; Table table; ExportMetadata exportMetadata; @@ -265,7 +294,7 @@ public class BackgroundOperationMonitorCreator { logger.debug("ExportMetadata: " + exportMetadata); operationMonitor.setTrId(SessionUtil.getTRId(session)); - + trExportMetadata = new TabExportMetadata(); trExportMetadata.setUrl(exportMetadata.getUri()); trExportMetadata.setDestinationType(exportMetadata @@ -274,24 +303,22 @@ public class BackgroundOperationMonitorCreator { .getExportDate())); saveJSONExportInDestination(exportMetadata); - break; + break; default: trId = new TRId(); trId.setId(taskWrapper.getTrId().getId()); trId = retrieveTabularResourceBasicData(trId); operationMonitor.setTrId(trId); - /*tabResource = SessionUtil.getTabResource(session); - logger.debug("CurrentTabResource :" + tabResource); - if (tabResource != null) { - tabResource.setTrId(trId); - SessionUtil.setTabResource(session, tabResource); - } else { - tabResource = new TabResource(); - tabResource.setTrId(trId); - SessionUtil.setTabResource(session, tabResource); - } - SessionUtil.setTRId(session, trId);*/ + /* + * tabResource = SessionUtil.getTabResource(session); + * logger.debug("CurrentTabResource :" + tabResource); if + * (tabResource != null) { tabResource.setTrId(trId); + * SessionUtil.setTabResource(session, tabResource); } else { + * tabResource = new TabResource(); tabResource.setTrId(trId); + * SessionUtil.setTabResource(session, tabResource); } + * SessionUtil.setTRId(session, trId); + */ break; } @@ -327,14 +354,18 @@ public class BackgroundOperationMonitorCreator { TRId newTRId; if (viewTable == null) { - newTRId = new TRId(String.valueOf(tr.getId().getValue()), - TabularResourceTypeMap.map(tr.getTabularResourceType()), tr.getTableType(), String.valueOf(table.getId() - .getValue()), table.getTableType().getName()); + newTRId = new TRId( + String.valueOf(tr.getId().getValue()), + TabularResourceTypeMap.map(tr.getTabularResourceType()), + tr.getTableType(), String.valueOf(table.getId() + .getValue()), table.getTableType().getName()); } else { - newTRId = new TRId(String.valueOf(tr.getId().getValue()), - TabularResourceTypeMap.map(tr.getTabularResourceType()), tr.getTableType(), String.valueOf(viewTable.getId() - .getValue()), viewTable.getTableType() + newTRId = new TRId( + String.valueOf(tr.getId().getValue()), + TabularResourceTypeMap.map(tr.getTabularResourceType()), + tr.getTableType(), String.valueOf(viewTable.getId() + .getValue()), viewTable.getTableType() .getName(), String.valueOf(table.getId() .getValue()), true); @@ -347,8 +378,7 @@ public class BackgroundOperationMonitorCreator { throw e; } catch (SecurityException e) { e.printStackTrace(); - throw new TDGWTServiceException( - SECURITY_EXCEPTION_RIGHTS); + throw new TDGWTServiceException(SECURITY_EXCEPTION_RIGHTS); } catch (Throwable e) { e.printStackTrace(); throw new TDGWTServiceException("Error on Service: " @@ -448,4 +478,30 @@ public class BackgroundOperationMonitorCreator { } } + private String retrieveTabularResourceIdFromTable( + TableId tableId) throws TDGWTServiceException { + try { + AuthorizationProvider.instance.set(new AuthorizationToken( + aslSession.getUsername(), aslSession.getScope())); + TabularDataService service = TabularDataServiceFactory.getService(); + + Table table = service.getTable(tableId); + + if (table.contains(TableDescriptorMetadata.class)) { + TableDescriptorMetadata tdm = table + .getMetadata(TableDescriptorMetadata.class); + return String.valueOf(tdm.getRefId()); + } else { + throw new TDGWTServiceException( + "No TableDescriptorMetadata present in tableId: " + + tableId); + } + + } catch (Exception e) { + throw new TDGWTServiceException(e.getLocalizedMessage()); + } + + } + + } diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/monitor/OperationMonitor.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/monitor/OperationMonitor.java index c002a91..c40727a 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/monitor/OperationMonitor.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/monitor/OperationMonitor.java @@ -4,7 +4,6 @@ package org.gcube.portlets.user.td.gwtservice.shared.monitor; import java.io.Serializable; -import java.util.ArrayList; import org.gcube.portlets.user.td.gwtservice.shared.task.TaskS; import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId; @@ -27,7 +26,6 @@ public class OperationMonitor implements Serializable { private boolean abort; private boolean hidden; private TRId trId; - private ArrayList collateralTableIds; public OperationMonitor() { @@ -95,27 +93,14 @@ public class OperationMonitor implements Serializable { public void setHidden(boolean hidden) { this.hidden = hidden; } - - - public ArrayList getCollateralTableIds() { - return collateralTableIds; - } - - public void setCollateralTableIds(ArrayList collateralTableIds) { - this.collateralTableIds = collateralTableIds; - } @Override public String toString() { return "OperationMonitor [taskId=" + taskId + ", operationId=" + operationId + ", task=" + task + ", inBackground=" + inBackground + ", abort=" + abort + ", hidden=" + hidden - + ", trId=" + trId + ", collateralTableIds=" - + collateralTableIds + "]"; + + ", trId=" + trId + "]"; } - - - } diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/monitor/OperationMonitorCreator.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/monitor/OperationMonitorCreator.java index 79561ed..0e1ce8f 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/monitor/OperationMonitorCreator.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/monitor/OperationMonitorCreator.java @@ -2,6 +2,7 @@ package org.gcube.portlets.user.td.gwtservice.shared.monitor; import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.List; import javax.servlet.http.HttpSession; @@ -9,13 +10,16 @@ import org.gcube.application.framework.core.session.ASLSession; import org.gcube.data.analysis.tabulardata.commons.utils.AuthorizationProvider; import org.gcube.data.analysis.tabulardata.commons.utils.AuthorizationToken; import org.gcube.data.analysis.tabulardata.commons.webservice.types.TaskStatus; +import org.gcube.data.analysis.tabulardata.model.metadata.common.TableDescriptorMetadata; import org.gcube.data.analysis.tabulardata.model.metadata.table.DatasetViewTableMetadata; import org.gcube.data.analysis.tabulardata.model.metadata.table.ExportMetadata; import org.gcube.data.analysis.tabulardata.model.table.Table; +import org.gcube.data.analysis.tabulardata.model.table.TableId; import org.gcube.data.analysis.tabulardata.service.TabularDataService; import org.gcube.data.analysis.tabulardata.service.impl.TabularDataServiceFactory; import org.gcube.data.analysis.tabulardata.service.operation.Job; import org.gcube.data.analysis.tabulardata.service.operation.Task; +import org.gcube.data.analysis.tabulardata.service.operation.TaskResult; import org.gcube.data.analysis.tabulardata.service.operation.ValidationJob; import org.gcube.data.analysis.tabulardata.service.tabular.TabularResource; import org.gcube.data.analysis.tabulardata.service.tabular.TabularResourceId; @@ -58,10 +62,12 @@ public class OperationMonitorCreator { private static SimpleDateFormat sdfDate = new SimpleDateFormat( "yyyy-MM-dd"); - protected HttpSession session; - protected TaskWrapper taskWrapper; - protected OperationMonitorSession operationMonitorSession; - protected ASLSession aslSession; + private HttpSession session; + private TaskWrapper taskWrapper; + private OperationMonitorSession operationMonitorSession; + private ASLSession aslSession; + + /** * @@ -76,7 +82,10 @@ public class OperationMonitorCreator { this.aslSession = aslSession; this.taskWrapper = taskWrapper; this.operationMonitorSession = operationMonitorSession; + + + } /** @@ -176,13 +185,27 @@ public class OperationMonitorCreator { } try { + + ArrayList collateralTRIds=new ArrayList(); + TaskResult taskResult=taskWrapper.getTask().getResult(); + if(taskResult!=null){ + List collaterals=taskResult.getCollateralTables(); + for(TableId tId:collaterals){ + String tabulRId=retrieveTabularResourceIdFromTable(tId); + TRId tabularRId=new TRId(tabulRId); + tabularRId.setTableId(String.valueOf(tId.getValue())); + collateralTRIds.add(tabularRId); + } + + } + taskS = new TaskS(taskWrapper.getTask().getId().getValue(), taskWrapper.getTask().getProgress(), TaskStateMap.map(taskWrapper.getTask().getStatus()), taskWrapper.getTask().getErrorCause(), taskWrapper .getTask().getSubmitter(), taskWrapper.getTask() .getStartTime(), - taskWrapper.getTask().getEndTime(), jobSList); + taskWrapper.getTask().getEndTime(), jobSList, collateralTRIds); } catch (Throwable e) { logger.error("error retrieving information about the task, "+e.getLocalizedMessage()); e.printStackTrace(); @@ -507,5 +530,31 @@ public class OperationMonitorCreator { "Error in export json: no destination present"); } } + + private String retrieveTabularResourceIdFromTable( + TableId tableId) throws TDGWTServiceException { + try { + AuthorizationProvider.instance.set(new AuthorizationToken( + aslSession.getUsername(), aslSession.getScope())); + TabularDataService service = TabularDataServiceFactory.getService(); + + Table table = service.getTable(tableId); + + if (table.contains(TableDescriptorMetadata.class)) { + TableDescriptorMetadata tdm = table + .getMetadata(TableDescriptorMetadata.class); + return String.valueOf(tdm.getRefId()); + } else { + throw new TDGWTServiceException( + "No TableDescriptorMetadata present in tableId: " + + tableId); + } + + } catch (Exception e) { + throw new TDGWTServiceException(e.getLocalizedMessage()); + } + + } + } diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/task/TaskS.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/task/TaskS.java index 0952480..929f9dd 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/task/TaskS.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/task/TaskS.java @@ -4,6 +4,8 @@ import java.io.Serializable; import java.util.ArrayList; import java.util.Date; +import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId; + /** * * @author "Giancarlo Panichi" @@ -21,11 +23,12 @@ public class TaskS implements Serializable { protected Date startTime; protected Date endTime; protected ArrayList jobs; + protected ArrayList collateralTRIds; public TaskS() { } - + /** * * @param id @@ -36,17 +39,21 @@ public class TaskS implements Serializable { * @param startTime * @param endTime * @param jobs + * @param collateralTRIds + * */ - public TaskS(String id, float progress, State state, Throwable errorCause, String submitter, - Date startTime, Date endTime, ArrayList jobs) { + public TaskS(String id, float progress, State state, Throwable errorCause, + String submitter, Date startTime, Date endTime, + ArrayList jobs, ArrayList collateralTRIds) { this.id = id; this.progress = progress; this.state = state; - this.errorCause=errorCause; + this.errorCause = errorCause; this.submitter = submitter; this.startTime = startTime; this.endTime = endTime; this.jobs = jobs; + this.collateralTRIds = collateralTRIds; } public String getId() { @@ -113,14 +120,21 @@ public class TaskS implements Serializable { this.jobs = jobs; } + public ArrayList getCollateralTRIds() { + return collateralTRIds; + } + + public void setCollateralTRIds(ArrayList collateralTRIds) { + this.collateralTRIds = collateralTRIds; + } + @Override public String toString() { return "TaskS [id=" + id + ", progress=" + progress + ", state=" + state + ", errorCause=" + errorCause + ", submitter=" + submitter + ", startTime=" + startTime + ", endTime=" - + endTime + ", jobs=" + jobs + "]"; + + endTime + ", jobs=" + jobs + ", collateralTRIds=" + + collateralTRIds + "]"; } - - } diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/column/type/ChangeColumnTypeSession.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/column/type/ChangeColumnTypeSession.java index 62d0f1a..46dfa22 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/column/type/ChangeColumnTypeSession.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/column/type/ChangeColumnTypeSession.java @@ -18,36 +18,50 @@ public class ChangeColumnTypeSession implements Serializable { protected ColumnTypeCode columnTypeCodeTarget; protected ColumnDataType columnDataTypeTarget; protected String locale; - + protected TimeDimensionType timeDimensionType; protected ColumnData codelistColumnReference; - + protected ColumnMappingList columnMappingList; - - public ChangeColumnTypeSession(){ - + + public ChangeColumnTypeSession() { + } - + + /* + * For change to Dimension + */ + public ChangeColumnTypeSession(ColumnData columnData, + ColumnTypeCode columnTypeCode, ColumnDataType columnDataType, + ColumnTypeCode columnTypeCodeTarget, + ColumnDataType columnDataTypeTarget, + ColumnData codelistColumnReference) { + this.columnData = columnData; + this.columnTypeCode = columnTypeCode; + this.columnDataType = columnDataType; + this.columnTypeCodeTarget = columnTypeCodeTarget; + this.columnDataTypeTarget = columnDataTypeTarget; + this.codelistColumnReference = codelistColumnReference; + + } + /* * For change to Dimension with mapping */ public ChangeColumnTypeSession(ColumnData columnData, - ColumnTypeCode columnTypeCode, - ColumnDataType columnDataType, + ColumnTypeCode columnTypeCode, ColumnDataType columnDataType, ColumnTypeCode columnTypeCodeTarget, ColumnDataType columnDataTypeTarget, ColumnData codelistColumnReference, - ColumnMappingList columnMappingList){ - this.columnData=columnData; - this.columnTypeCode=columnTypeCode; - this.columnDataType=columnDataType; - this.columnTypeCodeTarget=columnTypeCodeTarget; - this.columnDataTypeTarget=columnDataTypeTarget; - this.codelistColumnReference=codelistColumnReference; - this.columnMappingList=columnMappingList; + ColumnMappingList columnMappingList) { + this.columnData = columnData; + this.columnTypeCode = columnTypeCode; + this.columnDataType = columnDataType; + this.columnTypeCodeTarget = columnTypeCodeTarget; + this.columnDataTypeTarget = columnDataTypeTarget; + this.codelistColumnReference = codelistColumnReference; + this.columnMappingList = columnMappingList; } - - public ColumnTypeCode getColumnTypeCode() { return columnTypeCode; @@ -112,8 +126,6 @@ public class ChangeColumnTypeSession implements Serializable { public void setLocale(String locale) { this.locale = locale; } - - public ColumnMappingList getColumnMappingList() { return columnMappingList; @@ -123,7 +135,6 @@ public class ChangeColumnTypeSession implements Serializable { this.columnMappingList = columnMappingList; } - @Override public String toString() { return "ChangeColumnTypeSession [columnData=" + columnData @@ -136,6 +147,4 @@ public class ChangeColumnTypeSession implements Serializable { + ", columnMappingList=" + columnMappingList + "]"; } - - }