Updated Replace By Expression

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-gwt-service@100140 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2014-09-23 16:32:11 +00:00
parent 2655349bed
commit f8dfee1c57
4 changed files with 202 additions and 57 deletions

View File

@ -144,6 +144,8 @@ import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVFileUtil;
import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVImportSession;
import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVParserConfiguration;
import org.gcube.portlets.user.td.gwtservice.shared.csv.CheckCSVSession;
import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTIsFinalException;
import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTIsLockedException;
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.extract.ExtractCodelistSession;
@ -1135,12 +1137,12 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
Table table = service.getLastTable(new TabularResourceId(Long
.valueOf(trId.getId())));
logger.debug("Table retrieved: " + table);
if(table==null){
logger.error("Last Table is Null: "+ Long
.valueOf(trId.getId()));
if (table == null) {
logger.error("Last Table is Null: "
+ Long.valueOf(trId.getId()));
new TDGWTServiceException("Last Table is Null");
}
Table viewTable = null;
if (table.contains(DatasetViewTableMetadata.class)) {
@ -3518,11 +3520,35 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
.getTabularResource(tabularResourceId);
if (tabularResource.isLocked()) {
throw new TDGWTServiceException("Tabular Resource Is Locked");
throw new TDGWTIsLockedException("Tabular Resource Is Locked");
}
} catch (TDGWTSessionExpiredException e) {
} catch (SecurityException e) {
throw e;
} catch (Throwable e) {
e.printStackTrace();
throw new TDGWTServiceException(e.getLocalizedMessage());
}
}
/**
*
*
* @param service
* @param trId
* @throws TDGWTServiceException
*/
protected void checkTabularResourceIsFinal(TabularDataService service,
TRId trId) throws TDGWTServiceException {
try {
TabularResourceId tabularResourceId = new TabularResourceId(
Long.valueOf(trId.getId()));
TabularResource tabularResource = service
.getTabularResource(tabularResourceId);
if (tabularResource.isFinalized()) {
throw new TDGWTIsFinalException("Tabular Resource Is Final");
}
} catch (SecurityException e) {
throw e;
} catch (Throwable e) {
@ -3649,6 +3675,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
aslSession.getUsername(), aslSession.getScope()));
TabularDataService service = TabularDataServiceFactory.getService();
checkTabularResourceLocked(service, trId);
// Export CSV file
OperationDefinition exportCSVFileOperation = OperationDefinitionMap
@ -3703,6 +3730,8 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
TabularDataService service = TabularDataServiceFactory.getService();
checkTabularResourceLocked(service, changeColumnTypeSession
.getColumnData().getTrId());
checkTabularResourceIsFinal(service, changeColumnTypeSession
.getColumnData().getTrId());
OpExecution4ChangeColumnType opEx = new OpExecution4ChangeColumnType(
service, changeColumnTypeSession);
@ -3758,6 +3787,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
aslSession.getUsername(), aslSession.getScope()));
TabularDataService service = TabularDataServiceFactory.getService();
checkTabularResourceLocked(service, addColumnSession.getTrId());
checkTabularResourceIsFinal(service, addColumnSession.getTrId());
OpExecution4AddColumn opEx = new OpExecution4AddColumn(service,
addColumnSession);
@ -3812,6 +3842,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
aslSession.getUsername(), aslSession.getScope()));
TabularDataService service = TabularDataServiceFactory.getService();
checkTabularResourceLocked(service, deleteColumnSession.getTrId());
checkTabularResourceIsFinal(service, deleteColumnSession.getTrId());
OpExecution4DeleteColumn opEx = new OpExecution4DeleteColumn(
service, deleteColumnSession);
@ -3881,14 +3912,15 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
TabularDataService service = TabularDataServiceFactory.getService();
checkTabularResourceLocked(service, filterColumnSession.getColumn()
.getTrId());
checkTabularResourceIsFinal(service, filterColumnSession
.getColumn().getTrId());
OpExecution4FilterColumn opEx = new OpExecution4FilterColumn(
service, filterColumnSession, expression);
OpExecutionDirector director = new OpExecutionDirector();
director.setOperationExecutionBuilder(opEx);
director.constructOperationExecution();
OperationExecution invocation = director
.getOperationExecution();
OperationExecution invocation = director.getOperationExecution();
if (invocation == null) {
throw new TDGWTServiceException(
@ -3921,7 +3953,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
}
}
/**
* Start Replace Column by Expression
*
@ -3932,12 +3964,14 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
* @return
* @throws TDGWTServiceException
*/
public String startReplaceColumnByExpression(ReplaceColumnByExpressionSession replaceColumnByExpressionSession,
Expression conditionExpression, Expression replaceExpression,HttpSession session)
throws TDGWTServiceException {
public String startReplaceColumnByExpression(
ReplaceColumnByExpressionSession replaceColumnByExpressionSession,
Expression conditionExpression, Expression replaceExpression,
HttpSession session) throws TDGWTServiceException {
try {
// HttpSession session = this.getThreadLocalRequest().getSession();
SessionUtil.setReplaceColumnByExpressionSession(session, replaceColumnByExpressionSession);
SessionUtil.setReplaceColumnByExpressionSession(session,
replaceColumnByExpressionSession);
ASLSession aslSession = SessionUtil.getAslSession(session);
if (replaceColumnByExpressionSession == null) {
logger.error("ReplaceColumnByExpressionSession is null");
@ -3945,36 +3979,40 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
"Error in replace column by expression: ReplaceColumnByExpressionSession is null");
}
logger.debug("StartReplaceColumnByExpression: " + replaceColumnByExpressionSession);
logger.debug("StartReplaceColumnByExpression: "
+ replaceColumnByExpressionSession);
AuthorizationProvider.instance.set(new AuthorizationToken(
aslSession.getUsername(), aslSession.getScope()));
TabularDataService service = TabularDataServiceFactory.getService();
checkTabularResourceLocked(service, replaceColumnByExpressionSession.getColumn()
.getTrId());
checkTabularResourceLocked(service,
replaceColumnByExpressionSession.getColumn().getTrId());
checkTabularResourceIsFinal(service,
replaceColumnByExpressionSession.getColumn().getTrId());
OpExecution4ReplaceColumnByExpression opEx = new OpExecution4ReplaceColumnByExpression(
service, replaceColumnByExpressionSession, conditionExpression,replaceExpression);
service, replaceColumnByExpressionSession,
conditionExpression, replaceExpression);
OpExecutionDirector director = new OpExecutionDirector();
director.setOperationExecutionBuilder(opEx);
director.constructOperationExecution();
OperationExecution invocation = director
.getOperationExecution();
OperationExecution invocation = director.getOperationExecution();
if (invocation == null) {
throw new TDGWTServiceException(
"Error in invocation: Operation not supported");
}
Long id = Long.valueOf(replaceColumnByExpressionSession.getColumn().getTrId()
.getId());
Long id = Long.valueOf(replaceColumnByExpressionSession.getColumn()
.getTrId().getId());
TabularResourceId serviceTR = new TabularResourceId(id);
logger.debug("OperationInvocation: \n" + invocation.toString());
Task trTask = service.execute(invocation, serviceTR);
logger.debug("Replace Column by Expression on service: TaskId " + trTask.getId());
logger.debug("Replace Column by Expression on service: TaskId "
+ trTask.getId());
TaskWrapper taskWrapper = new TaskWrapper(trTask,
UIOperationsId.ReplaceByExpression, replaceColumnByExpressionSession
.getColumn().getTrId());
UIOperationsId.ReplaceByExpression,
replaceColumnByExpressionSession.getColumn().getTrId());
SessionUtil.setStartedTask(session, taskWrapper);
return trTask.getId().getValue();
@ -3986,13 +4024,12 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
"Security exception, you haven't rights!");
} catch (Throwable e) {
e.printStackTrace();
throw new TDGWTServiceException("Error in replace column by expression: "
+ e.getLocalizedMessage());
throw new TDGWTServiceException(
"Error in replace column by expression: "
+ e.getLocalizedMessage());
}
}
/**
*
@ -4010,6 +4047,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
aslSession.getUsername(), aslSession.getScope()));
TabularDataService service = TabularDataServiceFactory.getService();
checkTabularResourceLocked(service, labelColumnSession.getTrId());
checkTabularResourceIsFinal(service, labelColumnSession.getTrId());
OpExecution4LabelColumn opEx = new OpExecution4LabelColumn(service,
labelColumnSession);
@ -4066,6 +4104,8 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
TabularDataService service = TabularDataServiceFactory.getService();
checkTabularResourceLocked(service,
changeTableTypeSession.getTrId());
checkTabularResourceIsFinal(service,
changeTableTypeSession.getTrId());
OpExecution4ChangeTableType opEx = new OpExecution4ChangeTableType(
service, changeTableTypeSession);
@ -4238,6 +4278,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
aslSession.getUsername(), aslSession.getScope()));
TabularDataService service = TabularDataServiceFactory.getService();
checkTabularResourceLocked(service, deleteRowsSession.getTrId());
checkTabularResourceIsFinal(service, deleteRowsSession.getTrId());
OpExecution4DeleteRows opEx = new OpExecution4DeleteRows(service,
deleteRowsSession);
@ -4298,6 +4339,8 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
TabularDataService service = TabularDataServiceFactory.getService();
checkTabularResourceLocked(service,
cloneTabularResourceSession.getTrId());
checkTabularResourceIsFinal(service,
cloneTabularResourceSession.getTrId());
OpExecution4Clone opEx = new OpExecution4Clone(service,
cloneTabularResourceSession);
@ -4379,6 +4422,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
aslSession.getUsername(), aslSession.getScope()));
TabularDataService service = TabularDataServiceFactory.getService();
checkTabularResourceLocked(service, duplicatesSession.getTrId());
checkTabularResourceIsFinal(service, duplicatesSession.getTrId());
OpExecution4Duplicates opEx = new OpExecution4Duplicates(service,
duplicatesSession);
@ -4567,6 +4611,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
aslSession.getUsername(), aslSession.getScope()));
TabularDataService service = TabularDataServiceFactory.getService();
checkTabularResourceLocked(service, tabResource.getTrId());
checkTabularResourceIsFinal(service, tabResource.getTrId());
TabularResourceId tabularResourceId = new TabularResourceId(
new Long(tabResource.getTrId().getId()));
@ -4788,6 +4833,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
aslSession.getUsername(), aslSession.getScope()));
TabularDataService service = TabularDataServiceFactory.getService();
checkTabularResourceLocked(service, templateApplySession.getTrId());
checkTabularResourceIsFinal(service, templateApplySession.getTrId());
TemplateId templateId = new TemplateId(templateApplySession
.getTemplateData().getId());
@ -4877,6 +4923,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
aslSession.getUsername(), aslSession.getScope()));
TabularDataService service = TabularDataServiceFactory.getService();
checkTabularResourceLocked(service, replaceColumnSession.getTrId());
checkTabularResourceIsFinal(service, replaceColumnSession.getTrId());
OpExecution4ReplaceColumn opEx = new OpExecution4ReplaceColumn(
service, replaceColumnSession);
@ -4937,6 +4984,8 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
TabularDataService service = TabularDataServiceFactory.getService();
checkTabularResourceLocked(service,
replaceBatchColumnSession.getTrId());
checkTabularResourceIsFinal(service,
replaceBatchColumnSession.getTrId());
OpExecution4ReplaceBatch opEx = new OpExecution4ReplaceBatch(
service, replaceBatchColumnSession);
@ -5270,6 +5319,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
aslSession.getUsername(), aslSession.getScope()));
TabularDataService service = TabularDataServiceFactory.getService();
checkTabularResourceLocked(service, trId);
checkTabularResourceIsFinal(service, trId);
TabularResourceId tabularResourceId = new TabularResourceId(
Long.valueOf(trId.getId()));
@ -5340,6 +5390,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
aslSession.getUsername(), aslSession.getScope()));
TabularDataService service = TabularDataServiceFactory.getService();
checkTabularResourceLocked(service, rollBackSession.getTrId());
checkTabularResourceIsFinal(service, rollBackSession.getTrId());
TabularResourceId tabularResourceId = new TabularResourceId(
Long.valueOf(rollBackSession.getTrId().getId()));
@ -5480,6 +5531,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
aslSession.getUsername(), aslSession.getScope()));
TabularDataService service = TabularDataServiceFactory.getService();
checkTabularResourceLocked(service, editRowSession.getTrId());
checkTabularResourceIsFinal(service, editRowSession.getTrId());
OpExecution4EditRow opEx = new OpExecution4EditRow(service,
editRowSession);
@ -5586,6 +5638,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
aslSession.getUsername(), aslSession.getScope()));
TabularDataService service = TabularDataServiceFactory.getService();
checkTabularResourceLocked(service, taskResubmitSession.getTrId());
checkTabularResourceIsFinal(service, taskResubmitSession.getTrId());
if (taskResubmitSession.getTaskId() == null
|| taskResubmitSession.getTaskId().isEmpty()) {
@ -5636,6 +5689,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
aslSession.getUsername(), aslSession.getScope()));
TabularDataService service = TabularDataServiceFactory.getService();
checkTabularResourceLocked(service, taskResumeSession.getTrId());
checkTabularResourceIsFinal(service, taskResumeSession.getTrId());
if (taskResumeSession.getTaskId() == null
|| taskResumeSession.getTaskId().isEmpty()) {
@ -5836,6 +5890,8 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
TabularDataService service = TabularDataServiceFactory.getService();
checkTabularResourceLocked(service, splitColumnSession
.getColumnData().getTrId());
checkTabularResourceIsFinal(service, splitColumnSession
.getColumnData().getTrId());
OpExecution4SplitColumn opEx = new OpExecution4SplitColumn(service,
splitColumnSession);
@ -5896,6 +5952,8 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
TabularDataService service = TabularDataServiceFactory.getService();
checkTabularResourceLocked(service, mergeColumnSession
.getColumnDataSource1().getTrId());
checkTabularResourceIsFinal(service, mergeColumnSession
.getColumnDataSource1().getTrId());
OpExecution4MergeColumn opEx = new OpExecution4MergeColumn(service,
mergeColumnSession);
@ -6137,7 +6195,8 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
.getUsername(), aslSession.getScope()));
TabularDataService service = TabularDataServiceFactory.getService();
checkTabularResourceLocked(service, codelistMappingSession.getTrId());
checkTabularResourceIsFinal(service, codelistMappingSession.getTrId());
OpExecution4CodelistMapping opEx = new OpExecution4CodelistMapping(
service, codelistMappingSession, importUrl);
OpExecutionDirector director = new OpExecutionDirector();
@ -6177,7 +6236,8 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
aslSession.getUsername(), aslSession.getScope()));
TabularDataService service = TabularDataServiceFactory.getService();
checkTabularResourceLocked(service, groupBySession.getTrId());
checkTabularResourceIsFinal(service, groupBySession.getTrId());
OpExecution4GroupBy opEx = new OpExecution4GroupBy(service,
groupBySession);
OpExecutionDirector director = new OpExecutionDirector();
@ -6231,7 +6291,8 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
aslSession.getUsername(), aslSession.getScope()));
TabularDataService service = TabularDataServiceFactory.getService();
checkTabularResourceLocked(service, normalizationSession.getTrId());
checkTabularResourceIsFinal(service, normalizationSession.getTrId());
OpExecution4Normalization opEx = new OpExecution4Normalization(
service, normalizationSession);
OpExecutionDirector director = new OpExecutionDirector();
@ -6291,7 +6352,8 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
TabularDataService service = TabularDataServiceFactory.getService();
checkTabularResourceLocked(service,
denormalizationSession.getTrId());
checkTabularResourceIsFinal(service, denormalizationSession.getTrId());
OpExecution4Denormalization opEx = new OpExecution4Denormalization(
service, denormalizationSession);
OpExecutionDirector director = new OpExecutionDirector();
@ -6346,7 +6408,8 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
aslSession.getUsername(), aslSession.getScope()));
TabularDataService service = TabularDataServiceFactory.getService();
checkTabularResourceLocked(service, unionSession.getTrId());
checkTabularResourceIsFinal(service, unionSession.getTrId());
OpExecution4Union opEx = new OpExecution4Union(service,
unionSession);
OpExecutionDirector director = new OpExecutionDirector();
@ -6492,7 +6555,8 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
operationMonitorSession);
OperationMonitor operationMonitor = backgroundOperationMonitorCreator
.create();
logger.debug("BackgroundOperationMonitor(): " + operationMonitor);
logger.debug("BackgroundOperationMonitor(): "
+ operationMonitor);
backgroundOperationMonitorList.add(operationMonitor);
}

View File

@ -0,0 +1,37 @@
package org.gcube.portlets.user.td.gwtservice.shared.exception;
/**
* ASL Session Expired Exception
*
* @author "Giancarlo Panichi"
*
*/
public class TDGWTIsFinalException extends TDGWTServiceException {
private static final long serialVersionUID = 4306091799912937920L;
/**
*
*/
public TDGWTIsFinalException() {
super();
}
/**
* @param message
*/
public TDGWTIsFinalException(String message) {
super(message);
}
/**
*
* @param message
* @param t
*/
public TDGWTIsFinalException(String message,Throwable t) {
super(message,t);
}
}

View File

@ -0,0 +1,37 @@
package org.gcube.portlets.user.td.gwtservice.shared.exception;
/**
* ASL Session Expired Exception
*
* @author "Giancarlo Panichi"
*
*/
public class TDGWTIsLockedException extends TDGWTServiceException {
private static final long serialVersionUID = 4306091799912937920L;
/**
*
*/
public TDGWTIsLockedException() {
super();
}
/**
* @param message
*/
public TDGWTIsLockedException(String message) {
super(message);
}
/**
*
* @param message
* @param t
*/
public TDGWTIsLockedException(String message,Throwable t) {
super(message,t);
}
}

View File

@ -113,12 +113,14 @@ public class OperationMonitorCreator {
SessionUtil.removeStartedTask(session, taskWrapper);
postOperation(operationMonitor);
} else {
TaskStatus status=null;
TaskStatus status = null;
try {
status=taskWrapper.getTask().getStatus();
} catch(Throwable e){
logger.debug("Error retrieving task status: "+taskWrapper.getTask()+" "+e.getLocalizedMessage());
status = taskWrapper.getTask().getStatus();
} catch (Throwable e) {
logger.debug("Error retrieving task status: "
+ taskWrapper.getTask() + " "
+ e.getLocalizedMessage());
e.printStackTrace();
}
if (status == null) {
@ -133,13 +135,13 @@ public class OperationMonitorCreator {
postOperation(operationMonitor);
}
}
}
return operationMonitor;
}
protected TaskS createTaskS() {
protected TaskS createTaskS() throws TDGWTServiceException {
TaskS taskS = new TaskS();
ArrayList<JobS> jobSList = new ArrayList<JobS>();
@ -168,13 +170,19 @@ public class OperationMonitorCreator {
}
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 {
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);
} 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;
}
@ -285,18 +293,17 @@ public class OperationMonitorCreator {
new Long(trId.getId()));
TabularResource tr = service.getTabularResource(tabularResourceId);
if(tr==null){
logger.error("Tabular Resource Null [id="+trId.getId()+"]");
throw new TDGWTServiceException("Tabular Resource Null "+trId);
if (tr == null) {
logger.error("Tabular Resource Null [id=" + trId.getId() + "]");
throw new TDGWTServiceException("Tabular Resource Null " + trId);
}
Table table = service.getLastTable(tabularResourceId);
if(table==null){
if (table == null) {
logger.error("Last Table Null");
throw new TDGWTServiceException("Last Table Null for "+tr);
throw new TDGWTServiceException("Last Table Null for " + tr);
}
Table viewTable = null;
if (table.contains(DatasetViewTableMetadata.class)) {