Minor Update

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-gwt-service@99231 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2014-08-07 16:26:33 +00:00
parent a78ae2f365
commit d2f778559e
7 changed files with 522 additions and 235 deletions

View File

@ -0,0 +1,94 @@
/**
*
*/
package org.gcube.portlets.user.td.gwtservice.shared.monitor;
import java.io.Serializable;
import org.gcube.portlets.user.td.gwtservice.shared.task.State;
import org.gcube.portlets.user.td.gwtservice.shared.tr.table.metadata.TabExportMetadata;
import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId;
/**
*
* @author "Giancarlo Panichi"
* <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class CSVExportMonitor implements Serializable {
private static final long serialVersionUID = -5998841163159590481L;
protected float progress;
protected State status;
protected String statusDescription;
protected Throwable error;
protected TRId trId;
protected TabExportMetadata trExportMetadata;
public float getProgress(){
return progress;
};
public State getStatus(){
return status;
}
public String getStatusDescription(){
return statusDescription;
}
public void setProgress(float progress) {
this.progress = progress;
}
public void setStatus(State status) {
this.status = status;
}
public void setStatus(int status) {
this.status = State.values()[status];
}
public TabExportMetadata getTrExportMetadata() {
return trExportMetadata;
}
public void setTrExportMetadata(TabExportMetadata trExportMetadata) {
this.trExportMetadata = trExportMetadata;
}
public void setStatusDescription(String statusDescription) {
this.statusDescription = statusDescription;
}
public Throwable getError() {
return error;
}
public void setError(Throwable error) {
this.error = error;
}
public TRId getTrId() {
return trId;
}
public void setTrId(TRId trId) {
this.trId = trId;
}
@Override
public String toString() {
return "CSVExportMonitor [progress=" + progress + ", status=" + status
+ ", statusDescription=" + statusDescription + ", error="
+ error + ", trId=" + trId + ", trExportMetadata="
+ trExportMetadata + "]";
}
}

View File

@ -0,0 +1,81 @@
/**
*
*/
package org.gcube.portlets.user.td.gwtservice.shared.monitor;
import java.io.Serializable;
import org.gcube.portlets.user.td.gwtservice.shared.task.State;
import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId;
/**
*
* @author "Giancarlo Panichi"
* <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class CSVImportMonitor implements Serializable {
private static final long serialVersionUID = -5998841163159590481L;
protected float progress;
protected State status;
protected String statusDescription;
protected Throwable error;
protected TRId trId;
public float getProgress(){
return progress;
};
public State getStatus(){
return status;
}
public String getStatusDescription(){
return statusDescription;
}
public void setProgress(float progress) {
this.progress = progress;
}
public void setStatus(State status) {
this.status = status;
}
public void setStatus(int status) {
this.status = State.values()[status];
}
public void setStatusDescription(String statusDescription) {
this.statusDescription = statusDescription;
}
public Throwable getError() {
return error;
}
public void setError(Throwable error) {
this.error = error;
}
public TRId getTrId() {
return trId;
}
public void setTrId(TRId trId) {
this.trId = trId;
}
@Override
public String toString() {
return "CSVImportMonitor [progress=" + progress + ", status=" + status
+ ", statusDescription=" + statusDescription + ", error="
+ error + ", trId=" + trId + "]";
}
}

View File

@ -19,23 +19,19 @@ public class OperationMonitor implements Serializable {
private static final long serialVersionUID = 5378053063599667767L;
protected UIOperationsId operationId;
protected String taskId;
// protected float progress;
// protected State status;
// protected String statusDescription;
protected TaskS task;
protected boolean inBackground;
protected boolean abort;
protected TRId trId;
// protected String columnName;
private String taskId;
private UIOperationsId operationId;
private TaskS task;
private boolean inBackground;
private boolean abort;
private TRId trId;
public OperationMonitor() {
}
public OperationMonitor(UIOperationsId operationId, String taskId) {
public OperationMonitor(String taskId, UIOperationsId operationId) {
this.operationId = operationId;
this.taskId = taskId;
}
@ -90,9 +86,10 @@ public class OperationMonitor implements Serializable {
@Override
public String toString() {
return "OperationMonitor [operationId=" + operationId + ", taskId="
+ taskId + ", task=" + task + ", inBackground=" + inBackground
+ ", abort=" + abort + ", trId=" + trId + "]";
return "OperationMonitor [taskId=" + taskId + ", operationId="
+ operationId + ", task=" + task + ", inBackground="
+ inBackground + ", abort=" + abort + ", trId=" + trId + "]";
}
}

View File

@ -1,5 +1,6 @@
package org.gcube.portlets.user.td.gwtservice.shared.monitor;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import javax.servlet.http.HttpSession;
@ -9,32 +10,31 @@ 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.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.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.ValidationJob;
import org.gcube.data.analysis.tabulardata.service.tabular.TabularResource;
import org.gcube.data.analysis.tabulardata.service.tabular.TabularResourceId;
import org.gcube.portlets.user.td.gwtservice.server.SessionUtil;
import org.gcube.portlets.user.td.gwtservice.server.storage.FilesStorage;
import org.gcube.portlets.user.td.gwtservice.server.trservice.TaskStateMap;
import org.gcube.portlets.user.td.gwtservice.server.trservice.WorkerStateMap;
import org.gcube.portlets.user.td.gwtservice.shared.UIOperationsId;
import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVExportSession;
import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTServiceException;
import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTSessionExpiredException;
import org.gcube.portlets.user.td.gwtservice.shared.task.JobS;
import org.gcube.portlets.user.td.gwtservice.shared.task.TaskS;
import org.gcube.portlets.user.td.gwtservice.shared.task.TaskWrapper;
import org.gcube.portlets.user.td.gwtservice.shared.task.ValidationsJobS;
import org.gcube.portlets.user.td.gwtservice.shared.tr.TabResource;
import org.gcube.portlets.user.td.gwtservice.shared.tr.clone.CloneTabularResourceSession;
import org.gcube.portlets.user.td.gwtservice.shared.tr.union.UnionSession;
import org.gcube.portlets.user.td.gwtservice.shared.tr.table.metadata.TabExportMetadata;
import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
* @author "Giancarlo Panichi" email: <a
@ -44,10 +44,17 @@ import org.slf4j.LoggerFactory;
public class OperationMonitorCreator {
protected static Logger logger = LoggerFactory
.getLogger(OperationMonitorCreator.class);
protected static SimpleDateFormat sdf = new SimpleDateFormat(
"yyyy/MM/dd HH:mm");
protected static SimpleDateFormat sdfDate = new SimpleDateFormat(
"yyyy/MM/dd");
protected HttpSession session;
protected Task task;
protected TaskWrapper taskWrapper;
protected OperationMonitorSession operationMonitorSession;
protected ASLSession aslSession;
/**
*
@ -55,10 +62,12 @@ public class OperationMonitorCreator {
* @param startTRId
* @param operationMonitorSession
*/
public OperationMonitorCreator(HttpSession session, Task task,
public OperationMonitorCreator(HttpSession session, ASLSession aslSession,
TaskWrapper taskWrapper,
OperationMonitorSession operationMonitorSession) {
this.session=session;
this.task = task;
this.session = session;
this.aslSession = aslSession;
this.taskWrapper = taskWrapper;
this.operationMonitorSession = operationMonitorSession;
}
@ -70,17 +79,21 @@ public class OperationMonitorCreator {
*/
public OperationMonitor create() throws TDGWTServiceException {
OperationMonitor operationMonitor = new OperationMonitor(
operationMonitorSession.getOperationId(),
operationMonitorSession.getTaskId());
operationMonitorSession.getTaskId(),
taskWrapper.getOperationId());
if (task == null) {
if (taskWrapper == null || taskWrapper.getTask() == null
|| taskWrapper.getTask().getId() == null
|| taskWrapper.getTask().getId().getValue() == null
|| taskWrapper.getTask().getId().getValue().isEmpty()) {
logger.debug("Task is null");
throw new TDGWTServiceException(
"Error in Operation Monitor task is null");
} else {
operationMonitor.setTaskId(task.getId().getValue());
operationMonitor
.setTaskId(taskWrapper.getTask().getId().getValue());
TaskStatus status = task.getStatus();
TaskStatus status = taskWrapper.getTask().getStatus();
if (status == null) {
logger.debug("Services TaskStatus : null");
throw new TDGWTServiceException(
@ -89,7 +102,7 @@ public class OperationMonitorCreator {
TaskS taskS = createTaskS();
operationMonitor.setTask(taskS);
}
SessionUtil.setTaskById(session, task);
SessionUtil.setTaskStarted(session, taskWrapper);
postOperation(operationMonitor);
}
@ -101,7 +114,7 @@ public class OperationMonitorCreator {
ArrayList<JobS> jobSList = new ArrayList<JobS>();
int i = 1;
for (Job job : task.getTaskJobs()) {
for (Job job : taskWrapper.getTask().getTaskJobs()) {
ArrayList<ValidationsJobS> validationsJobS = new ArrayList<ValidationsJobS>();
int j = 1;
@ -124,44 +137,36 @@ public class OperationMonitorCreator {
j++;
}
taskS = new TaskS(task.getId().getValue(), task.getProgress(),
TaskStateMap.map(task.getStatus()), task.getErrorCause(), task.getSubmitter(),
task.getStartTime(), task.getEndTime(), jobSList);
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);
logger.debug("Retrieved task information");
return taskS;
}
protected void postOperation(OperationMonitor operationMonitor) throws TDGWTServiceException {
TRId startTRId=retrieveTabularResourceIdFromOperation();
// Table table;
TRId trId;
TabResource tabResource;
protected void postOperation(OperationMonitor operationMonitor)
throws TDGWTServiceException {
switch (operationMonitor.getTask().getState()) {
case FAILED:
if (task.getResult() != null) {
logger.debug("Task exception: " + task.getErrorCause());
task.getErrorCause().printStackTrace();
Throwable errorCause = taskWrapper.getTask().getErrorCause();
if (errorCause == null) {
logger.error("Task Exception: task is failed");
} else {
logger.debug("Task exception: Error In Operation no Error Cause present");
logger.error("Task exception: "
+ errorCause.getLocalizedMessage());
errorCause.printStackTrace();
}
break;
case SUCCEDED:
logger.debug("Task Result:" + task.getResult());
trId = new TRId();
trId.setId(startTRId.getId());
trId = retrieveTabularResourceBasicData(trId);
operationMonitor.setTrId(trId);
tabResource = SessionUtil.getTabResource(session);
tabResource.setTrId(trId);
SessionUtil.setTabResource(session, tabResource);
SessionUtil.setTRId(session, trId);
logger.debug("Task Result:" + taskWrapper.getTask().getResult());
updateInformations(operationMonitor);
break;
case IN_PROGRESS:
break;
@ -172,16 +177,8 @@ public class OperationMonitorCreator {
case ABORTED:
break;
case STOPPED:
logger.debug("Task Result:" + task.getResult());
trId = new TRId();
trId.setId(startTRId.getId());
trId = retrieveTabularResourceBasicData(trId);
operationMonitor.setTrId(trId);
tabResource = SessionUtil.getTabResource(session);
tabResource.setTrId(trId);
SessionUtil.setTabResource(session, tabResource);
SessionUtil.setTRId(session, trId);
logger.debug("Task Result:" + taskWrapper.getTask().getResult());
updateInformations(operationMonitor);
break;
case INITIALIZING:
break;
@ -190,9 +187,57 @@ public class OperationMonitorCreator {
}
}
protected void updateInformations(OperationMonitor operationMonitor)
throws TDGWTServiceException {
TRId trId;
TabResource tabResource;
Table table;
ExportMetadata exportMetadata;
switch(taskWrapper.getOperationId()){
case CSVExport:
table = taskWrapper.getTask().getResult().getPrimaryTable();
logger.debug("Table retrived: " + table.toString());
exportMetadata = table
.getMetadata(ExportMetadata.class);
logger.debug("ExportMetadata: " + exportMetadata);
operationMonitor.setTrId(SessionUtil.getTRId(session));
TabExportMetadata trExportMetadata;
trExportMetadata = new TabExportMetadata();
trExportMetadata.setUrl(exportMetadata.getUri());
trExportMetadata.setDestinationType(exportMetadata
.getDestinationType());
trExportMetadata.setExportDate(sdf.format(exportMetadata
.getExportDate()));
saveCSVExportInDestination(exportMetadata);
break;
case SDMXExport:
table = taskWrapper.getTask().getResult().getPrimaryTable();
logger.debug("Table retrived: " + table.toString());
exportMetadata = table
.getMetadata(ExportMetadata.class);
logger.debug("ExportMetadata: " + exportMetadata);
operationMonitor.setTrId(SessionUtil.getTRId(session));
break;
default:
trId = new TRId();
trId.setId(taskWrapper.getTrId().getId());
trId = retrieveTabularResourceBasicData(trId);
operationMonitor.setTrId(trId);
tabResource = SessionUtil.getTabResource(session);
tabResource.setTrId(trId);
SessionUtil.setTabResource(session, tabResource);
SessionUtil.setTRId(session, trId);
break;
}
}
protected TRId retrieveTabularResourceBasicData(TRId trId)
throws TDGWTServiceException {
try {
@ -250,141 +295,51 @@ public class OperationMonitorCreator {
+ e.getLocalizedMessage());
}
}
protected TRId retrieveTabularResourceIdFromOperation() {
TRId trId = null;
UIOperationsId operationId = operationMonitorSession.getOperationId();
switch (operationId) {
case AddColumn:
break;
case AddRow:
break;
case AmbiguousExternalReferenceCheck:
break;
case CLONE:
CloneTabularResourceSession cloneTabularResourceSession = SessionUtil
.getCloneTabularResourceSession(session);
trId = cloneTabularResourceSession.getTrId();
break;
case CSVExport:
break;
case CSVImport:
break;
case ChangeTableType:
break;
case ChangeToAnnotationColumn:
break;
case ChangeToAttributeColumn:
break;
case ChangeToCodeColumn:
break;
case ChangeToCodeDescription:
break;
case ChangeToCodeName:
break;
case ChangeToDimensionColumn:
break;
case ChangeToMeasureColumn:
break;
case ChangeToTimeDimensionColumn:
break;
case CodelistMappingImport:
break;
case CodelistValidation:
break;
case ColumnNameAdd:
break;
case ColumnNameRemove:
break;
case ColumnTypeCastCheck:
break;
case CreateDatasetView:
break;
case Denormalize:
break;
case DimensionColumnValidator:
break;
case DuplicateTupleValidation:
break;
case DuplicateValuesInColumnValidator:
break;
case ExportToStatisticalOperation:
break;
case ExpressionValidation:
break;
case ExtractCodelist:
break;
case FilterByExpression:
break;
case GroupBy:
break;
case GuessCodelist:
break;
case ImportFromStatistical:
break;
case JSONExport:
break;
case JSONImport:
break;
case ModifyTuplesValuesByExpression:
break;
case ModifyTuplesValuesById:
break;
case ModifyTuplesValuesByValidation:
break;
case Normalize:
break;
case PeriodFormatCheck:
break;
case RemoveColumn:
break;
case RemoveDuplicateTuples:
break;
case RemoveRowById:
break;
case ReplaceById:
break;
case ReplaceColumnByExpression:
break;
case SDMXCodelistExport:
break;
case SDMXCodelistImport:
break;
case SDMXDatasetExport:
break;
case SDMXDatasetImport:
break;
case StatisticalOperation:
break;
case TableNameAdd:
break;
case TableNameRemove:
break;
case Union:
UnionSession unionSession = SessionUtil.getUnionSession(session);
trId = unionSession.getTrId();
break;
case ValidateCodelist:
break;
case ValidateDataSet:
break;
case ValidateDataset:
break;
case ValidateGeneric:
break;
case ValidateTable:
break;
default:
break;
/**
* Save export data on Workspace
*
* @param session
* @param user
* @param exportMetadata
* @param exportSession
* @throws TDGWTServiceException
*/
protected void saveCSVExportInDestination(ExportMetadata exportMetadata)
throws TDGWTServiceException {
CSVExportSession exportSession = SessionUtil
.getCSVExportSession(session);
String user = aslSession.getUsername();
logger.debug("Save Export In Destination");
logger.debug("Destination: " + exportSession.getDestination().getId());
if (exportSession.getDestination().getId().compareTo("Workspace") == 0) {
logger.debug("Save on Workspace");
boolean end = SessionUtil.getCSVExportEnd(session);
if (end == false) {
SessionUtil.setCSVExportEnd(session, true);
FilesStorage storage = new FilesStorage();
logger.debug("Create Item On Workspace: [ uri: "
+ exportMetadata.getUri() + " ,user: " + user
+ " ,fileName: " + exportSession.getFileName()
+ " ,fileDescription: "
+ exportSession.getFileDescription()
+ " ,mimetype: text/csv" + " ,folder: "
+ exportSession.getItemId() + "]");
storage.createItemOnWorkspace(exportMetadata.getUri(), user,
exportSession.getFileName(),
exportSession.getFileDescription(), "text/csv",
exportSession.getItemId());
} else {
logger.debug("getCSVExportEnd(): true");
}
} else {
logger.error("Destination No Present");
throw new TDGWTServiceException(
"Error in exportCSV CSVExportMonitor: no destination present");
}
return trId;
}
}

View File

@ -2,8 +2,6 @@ package org.gcube.portlets.user.td.gwtservice.shared.monitor;
import java.io.Serializable;
import org.gcube.portlets.user.td.gwtservice.shared.UIOperationsId;
/**
*
* @author "Giancarlo Panichi"
@ -15,37 +13,21 @@ public class OperationMonitorSession implements Serializable {
private static final long serialVersionUID = 7998971732364151219L;
protected UIOperationsId operationId;
protected String taskId;
protected boolean inBackground;
protected boolean abort;
private String taskId;
private boolean inBackground;
private boolean abort;
public OperationMonitorSession(){
}
public OperationMonitorSession(UIOperationsId operationId){
this.operationId=operationId;
taskId=null;
inBackground=false;
abort=false;
}
public OperationMonitorSession(UIOperationsId operationId,String taskId){
this.operationId=operationId;
public OperationMonitorSession(String taskId){
this.taskId=taskId;
inBackground=false;
abort=false;
}
public UIOperationsId getOperationId() {
return operationId;
}
public void setOperationId(UIOperationsId operationId) {
this.operationId = operationId;
}
public String getTaskId() {
return taskId;
}
@ -76,13 +58,13 @@ public class OperationMonitorSession implements Serializable {
@Override
public String toString() {
return "MonitorSession [operationId=" + operationId + ", taskId="
+ taskId + ", inBackground=" + inBackground + ", abort="
+ abort + "]";
return "OperationMonitorSession [taskId=" + taskId + ", inBackground="
+ inBackground + ", abort=" + abort + "]";
}
}

View File

@ -0,0 +1,100 @@
package org.gcube.portlets.user.td.gwtservice.shared.monitor;
import java.io.Serializable;
import org.gcube.portlets.user.td.gwtservice.shared.task.State;
import org.gcube.portlets.user.td.gwtservice.shared.tr.table.metadata.TabExportMetadata;
import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId;
/**
*
* @author "Giancarlo Panichi"
* <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class SDMXExportMonitor implements Serializable {
private static final long serialVersionUID = -5998841163159590481L;
protected float progress;
protected State status;
protected String statusDescription;
protected Throwable error;
protected String url;
protected TabExportMetadata tabExportMetadata;
protected TRId trId;
public TRId getTrId() {
return trId;
}
public void setTrId(TRId trId) {
this.trId = trId;
}
public float getProgress(){
return progress;
};
public State getStatus(){
return status;
}
public String getStatusDescription(){
return statusDescription;
}
public void setProgress(float progress) {
this.progress = progress;
}
public void setStatus(State status) {
this.status = status;
}
public void setStatus(int status) {
this.status = State.values()[status];
}
public void setStatusDescription(String statusDescription) {
this.statusDescription = statusDescription;
}
public Throwable getError() {
return error;
}
public void setError(Throwable error) {
this.error = error;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public TabExportMetadata getTabExportMetadata() {
return tabExportMetadata;
}
public void setTabExportMetadata(TabExportMetadata tabExportMetadata) {
this.tabExportMetadata = tabExportMetadata;
}
@Override
public String toString() {
return "SDMXExportMonitor [progress=" + progress + ", status=" + status
+ ", statusDescription=" + statusDescription + ", error="
+ error + ", url=" + url + ", tabExportMetadata="
+ tabExportMetadata + ", trId=" + trId + "]";
}
}

View File

@ -0,0 +1,78 @@
package org.gcube.portlets.user.td.gwtservice.shared.monitor;
import java.io.Serializable;
import org.gcube.portlets.user.td.gwtservice.shared.task.State;
import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId;
/**
*
* @author "Giancarlo Panichi"
* <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class SDMXImportMonitor implements Serializable {
private static final long serialVersionUID = -5998841163159590481L;
protected float progress;
protected State status;
protected String statusDescription;
protected Throwable error;
protected TRId trId;
public float getProgress(){
return progress;
};
public State getStatus(){
return status;
}
public String getStatusDescription(){
return statusDescription;
}
public void setProgress(float progress) {
this.progress = progress;
}
public void setStatus(State status) {
this.status = status;
}
public void setStatus(int status) {
this.status = State.values()[status];
}
public void setStatusDescription(String statusDescription) {
this.statusDescription = statusDescription;
}
public Throwable getError() {
return error;
}
public void setError(Throwable error) {
this.error = error;
}
public TRId getTrId() {
return trId;
}
public void setTrId(TRId trId) {
this.trId = trId;
}
@Override
public String toString() {
return "SDMXImportMonitor [progress=" + progress + ", status=" + status
+ ", statusDescription=" + statusDescription + ", error="
+ error + ", trId=" + trId + "]";
}
}