Added Pending Tasks Retrieve

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-gwt-service@111471 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2015-01-23 16:01:32 +00:00
parent d7495ce2a3
commit 2032afb8bb
3 changed files with 177 additions and 140 deletions

View File

@ -105,6 +105,15 @@ 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
*

View File

@ -90,6 +90,8 @@ public interface TDGWTServiceAsync {
void hello(AsyncCallback<UserInfo> callback);
void pendingTasksRetrieve(AsyncCallback<Integer> callback);
void restoreUISession(AsyncCallback<TRId> callback);
void getUriFromResolver(UriResolverSession uriResolverSession,

View File

@ -42,6 +42,7 @@ 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.utils.Licence;
import org.gcube.data.analysis.tabulardata.commons.webservice.types.TabularResourceType;
import org.gcube.data.analysis.tabulardata.commons.webservice.types.TaskStatus;
import org.gcube.data.analysis.tabulardata.commons.webservice.types.TemplateDescription;
import org.gcube.data.analysis.tabulardata.commons.webservice.types.operations.OperationDefinition;
import org.gcube.data.analysis.tabulardata.commons.webservice.types.operations.OperationExecution;
@ -311,6 +312,57 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
return userInfo;
}
/**
*
* {@inheritDoc}
*/
@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<TabularResource> pendingTR=new ArrayList<TabularResource>();
List<TabularResource> 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<Task> tasks=service.getTasks(tr.getId(), TaskStatus.IN_PROGRESS);
TRId trId=new TRId(String.valueOf(tr.getId().getValue()));
for(Task task:tasks){
TaskWrapper taskWrapper=new TaskWrapper(task,UIOperationsId.GenericPendingOperation, trId);
SessionUtil.setTaskInBackground(session, taskWrapper);
pendingNumber++;
}
}
logger.debug("Pending number: "+pendingNumber);
return pendingNumber;
} catch (TDGWTServiceException e) {
throw e;
} catch (SecurityException e) {
e.printStackTrace();
throw new TDGWTServiceException(SECURITY_EXCEPTION_RIGHTS);
} catch (Throwable e) {
logger.error("pendingTaskRetrieve(): " + e.getLocalizedMessage(), e);
throw new TDGWTServiceException("Error retrieving pending tasks: "
+ e.getLocalizedMessage());
}
}
/**
*
* {@inheritDoc}
@ -906,14 +958,14 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
if (c.contains(ViewColumnMetadata.class)) {
} else {
ColumnData cData = new ColumnData();
ColumnData cData = new ColumnData();
cData.setId(Integer.toString(i));
cData.setColumnId(c.getLocalId().getValue());
cData.setName(c.getName());
cData.setTypeCode(c.getColumnType().getCode());
cData.setTypeName(c.getColumnType().getName());
cData.setDataTypeName(c.getDataType().getName());
PeriodTypeMetadata periodTypeMetadata = null;
if (c.contains(PeriodTypeMetadata.class)) {
periodTypeMetadata = c
@ -922,12 +974,12 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
.getType();
cData.setPeriodDataType(PeriodTypeMap
.map(periodType));
}
}
ColumnRelationship rel = c.getRelationship();
if (rel != null) {
RelationshipData relData = retrieveRelationship(service,
table, c, periodTypeMetadata, rel);
RelationshipData relData = retrieveRelationship(
service, table, c, periodTypeMetadata, rel);
cData.setRelationship(relData);
}
@ -965,7 +1017,6 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
cData.setLocale(dataLocaleMetadata.getLocale());
}
cData.setTrId(trId);
columns.add(cData);
i++;
@ -1030,7 +1081,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
cData.setTypeCode(c.getColumnType().getCode());
cData.setTypeName(c.getColumnType().getName());
cData.setDataTypeName(c.getDataType().getName());
PeriodTypeMetadata periodTypeMetadata = null;
if (c.contains(PeriodTypeMetadata.class)) {
periodTypeMetadata = c
@ -1040,11 +1091,11 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
cData.setPeriodDataType(PeriodTypeMap
.map(periodType));
}
ColumnRelationship rel = c.getRelationship();
if (rel != null) {
RelationshipData relData = retrieveRelationship(service,
table, c, periodTypeMetadata, rel);
RelationshipData relData = retrieveRelationship(
service, table, c, periodTypeMetadata, rel);
cData.setRelationship(relData);
}
@ -1083,8 +1134,6 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
cData.setLocale(dataLocaleMetadata.getLocale());
}
cData.setTrId(trId);
columns.add(cData);
i++;
@ -1146,7 +1195,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
cData.setTypeCode(c.getColumnType().getCode());
cData.setTypeName(c.getColumnType().getName());
cData.setDataTypeName(c.getDataType().getName());
PeriodTypeMetadata periodTypeMetadata = null;
if (c.contains(PeriodTypeMetadata.class)) {
periodTypeMetadata = c
@ -1154,11 +1203,11 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
PeriodType periodType = periodTypeMetadata.getType();
cData.setPeriodDataType(PeriodTypeMap.map(periodType));
}
ColumnRelationship rel = c.getRelationship();
if (rel != null) {
RelationshipData relData = retrieveRelationship(service,
table, c, periodTypeMetadata, rel);
RelationshipData relData = retrieveRelationship(
service, table, c, periodTypeMetadata, rel);
cData.setRelationship(relData);
}
@ -1197,10 +1246,9 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
cData.setLocale(dataLocaleMetadata.getLocale());
}
if (c.contains(ViewColumnMetadata.class)) {
ColumnViewData columnViewData = retrieveColumnViewData(service, table, c,
periodTypeMetadata);
ColumnViewData columnViewData = retrieveColumnViewData(
service, table, c, periodTypeMetadata);
cData.setColumnViewData(columnViewData);
cData.setViewColumn(true);
} else {
@ -1270,7 +1318,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
cData.setTypeCode(c.getColumnType().getCode());
cData.setTypeName(c.getColumnType().getName());
cData.setDataTypeName(c.getDataType().getName());
PeriodTypeMetadata periodTypeMetadata = null;
if (c.contains(PeriodTypeMetadata.class)) {
periodTypeMetadata = c
@ -1278,11 +1326,11 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
PeriodType periodType = periodTypeMetadata.getType();
cData.setPeriodDataType(PeriodTypeMap.map(periodType));
}
ColumnRelationship rel = c.getRelationship();
if (rel != null) {
RelationshipData relData = retrieveRelationship(service,
table, c, periodTypeMetadata, rel);
RelationshipData relData = retrieveRelationship(
service, table, c, periodTypeMetadata, rel);
cData.setRelationship(relData);
}
@ -1320,12 +1368,11 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
cData.setLocale(dataLocaleMetadata.getLocale());
}
if (c.contains(ViewColumnMetadata.class)) {
ColumnViewData columnViewData = retrieveColumnViewData(service, table, c,
periodTypeMetadata);
ColumnViewData columnViewData = retrieveColumnViewData(
service, table, c, periodTypeMetadata);
cData.setColumnViewData(columnViewData);
cData.setViewColumn(true);
cData.setViewColumn(true);
} else {
cData.setViewColumn(false);
}
@ -1391,19 +1438,18 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
Table timeTable = service
.getTimeTable(periodTypeMetadata.getType());
if (timeTable == null || timeTable.getId() == null) {
throw new TDGWTServiceException(
"Error retrieving Time Table: " + table);
throw new TDGWTServiceException("Error retrieving Time Table: "
+ table);
}
logger.debug("Time Table Id: "+timeTable.getId());
Column timeColumn = timeTable
.getColumnByName(periodTypeMetadata.getType()
.getName());
relData = new RelationshipData(timeTable.getId()
.getValue(), timeColumn.getLocalId().getValue());
logger.debug("Time Table Id: " + timeTable.getId());
Column timeColumn = timeTable.getColumnByName(periodTypeMetadata
.getType().getName());
relData = new RelationshipData(timeTable.getId().getValue(),
timeColumn.getLocalId().getValue());
} else {
relData = new RelationshipData(rel.getTargetTableId()
.getValue(), rel.getTargetColumnId().getValue());
relData = new RelationshipData(rel.getTargetTableId().getValue(),
rel.getTargetColumnId().getValue());
}
return relData;
}
@ -1413,66 +1459,63 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
throws TDGWTServiceException {
ViewColumnMetadata viewMetadata = c
.getMetadata(ViewColumnMetadata.class);
logger.debug("ViewColumnMetadata: "
+ viewMetadata.toString());
ColumnViewData columnViewData=null;
logger.debug("ViewColumnMetadata: " + viewMetadata.toString());
ColumnViewData columnViewData = null;
Column sourceColumn = table.getColumnById(viewMetadata
.getSourceTableDimensionColumnId());
if (sourceColumn.getColumnType().getCode()
.compareTo(ColumnTypeCode.TIMEDIMENSION.toString()) == 0) {
PeriodTypeMetadata periodTypeMetadataSourceColumn = null;
if (sourceColumn.contains(PeriodTypeMetadata.class)) {
periodTypeMetadataSourceColumn = sourceColumn
.getMetadata(PeriodTypeMetadata.class);
Table timeTable = service
.getTimeTable(periodTypeMetadataSourceColumn.getType());
if (timeTable == null || timeTable.getId() == null) {
throw new TDGWTServiceException(
"Error retrieving Time Table: " + table);
}
logger.debug("Time Table Id: "+timeTable.getId());
logger.debug("Time Table Id: " + timeTable.getId());
Column timeColumn = timeTable
.getColumnByName(periodTypeMetadataSourceColumn.getType()
.getName());
.getColumnByName(periodTypeMetadataSourceColumn
.getType().getName());
String sourceTableDimensionColumnId = viewMetadata
.getSourceTableDimensionColumnId().getValue();
String targetTableColumnId = timeColumn.getLocalId().getValue();
long targetTableId = timeTable.getId()
.getValue();
long targetTableId = timeTable.getId().getValue();
columnViewData = new ColumnViewData(
sourceTableDimensionColumnId,
targetTableColumnId, targetTableId);
sourceTableDimensionColumnId, targetTableColumnId,
targetTableId);
} else {
logger.error("Error retrieving Time Table for view column:"+c+" , source column do not have a PeriodTypeMetadata: "+sourceColumn);
logger.error("Error retrieving Time Table for view column:" + c
+ " , source column do not have a PeriodTypeMetadata: "
+ sourceColumn);
throw new TDGWTServiceException(
"Error retrieving Time Table, source column do not have a PeriodTypeMetadata");
}
} else {
String sourceTableDimensionColumnId = viewMetadata
.getSourceTableDimensionColumnId().getValue();
String targetTableColumnId = viewMetadata
.getTargetTableColumnId().getValue();
long targetTableId = viewMetadata.getTargetTableId()
String targetTableColumnId = viewMetadata.getTargetTableColumnId()
.getValue();
columnViewData = new ColumnViewData(
sourceTableDimensionColumnId,
long targetTableId = viewMetadata.getTargetTableId().getValue();
columnViewData = new ColumnViewData(sourceTableDimensionColumnId,
targetTableColumnId, targetTableId);
}
return columnViewData;
}
/**
*
* {@inheritDoc}
@ -1508,9 +1551,9 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
cData.setPeriodDataType(PeriodTypeMap.map(periodType));
}
if (c.contains(ViewColumnMetadata.class)) {
ColumnViewData columnViewData = retrieveColumnViewData(service, table, c,
periodTypeMetadata);
if (c.contains(ViewColumnMetadata.class)) {
ColumnViewData columnViewData = retrieveColumnViewData(
service, table, c, periodTypeMetadata);
cData.setColumnViewData(columnViewData);
cData.setViewColumn(true);
} else {
@ -1578,8 +1621,6 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
}
}
/**
*
* {@inheritDoc}
@ -1606,7 +1647,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
cData.setId(Integer.toString(0));
cData.setColumnId(c.getLocalId().getValue());
cData.setName(c.getName());
PeriodTypeMetadata periodTypeMetadata = null;
if (c.contains(PeriodTypeMetadata.class)) {
periodTypeMetadata = c
@ -1614,10 +1655,10 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
PeriodType periodType = periodTypeMetadata.getType();
cData.setPeriodDataType(PeriodTypeMap.map(periodType));
}
if (c.contains(ViewColumnMetadata.class)) {
ColumnViewData columnViewData = retrieveColumnViewData(service, table, c,
periodTypeMetadata);
ColumnViewData columnViewData = retrieveColumnViewData(
service, table, c, periodTypeMetadata);
cData.setColumnViewData(columnViewData);
cData.setViewColumn(true);
} else {
@ -1664,8 +1705,6 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
cData.setLocale(dataLocaleMetadata.getLocale());
}
cData.setTrId(trId);
}
@ -1853,7 +1892,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
newTRId.setViewTable(false);
logger.debug("NewTRId: " + newTRId);
tData.setTrId(newTRId);
tData.setName(table.getName());
tData.setTypeName(table.getTableType().getName());
tData.setTypeCode(table.getTableType().getCode());
@ -1875,22 +1914,20 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
if (column.contains(PeriodTypeMetadata.class)) {
periodTypeMetadata = column
.getMetadata(PeriodTypeMetadata.class);
PeriodType periodType = periodTypeMetadata
.getType();
colData.setPeriodDataType(PeriodTypeMap
.map(periodType));
}
PeriodType periodType = periodTypeMetadata.getType();
colData.setPeriodDataType(PeriodTypeMap.map(periodType));
}
ColumnRelationship rel = column.getRelationship();
if (rel != null) {
RelationshipData relData = retrieveRelationship(service,
table, column, periodTypeMetadata, rel);
RelationshipData relData = retrieveRelationship(
service, table, column, periodTypeMetadata, rel);
colData.setRelationship(relData);
}
if (column.contains(ViewColumnMetadata.class)) {
ColumnViewData columnViewData = retrieveColumnViewData(service, table, column,
periodTypeMetadata);
ColumnViewData columnViewData = retrieveColumnViewData(
service, table, column, periodTypeMetadata);
colData.setColumnViewData(columnViewData);
colData.setViewColumn(true);
@ -1932,27 +1969,26 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
colData.setTypeCode(column.getColumnType().getCode());
colData.setDataTypeName(column.getDataType().getName());
colData.setTrId(newTRId);
PeriodTypeMetadata periodTypeMetadata = null;
if (column.contains(PeriodTypeMetadata.class)) {
periodTypeMetadata = column
.getMetadata(PeriodTypeMetadata.class);
PeriodType periodType = periodTypeMetadata
.getType();
colData.setPeriodDataType(PeriodTypeMap
.map(periodType));
}
PeriodType periodType = periodTypeMetadata.getType();
colData.setPeriodDataType(PeriodTypeMap.map(periodType));
}
ColumnRelationship rel = column.getRelationship();
if (rel != null) {
RelationshipData relData = retrieveRelationship(service,
viewTable, column, periodTypeMetadata, rel);
RelationshipData relData = retrieveRelationship(
service, viewTable, column, periodTypeMetadata,
rel);
colData.setRelationship(relData);
}
if (column.contains(ViewColumnMetadata.class)) {
ColumnViewData columnViewData = retrieveColumnViewData(service, viewTable, column,
periodTypeMetadata);
ColumnViewData columnViewData = retrieveColumnViewData(
service, viewTable, column, periodTypeMetadata);
colData.setColumnViewData(columnViewData);
colData.setViewColumn(true);
@ -2042,28 +2078,25 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
colData.setTypeCode(column.getColumnType().getCode());
colData.setDataTypeName(column.getDataType().getName());
colData.setTrId(newTRId);
PeriodTypeMetadata periodTypeMetadata = null;
if (column.contains(PeriodTypeMetadata.class)) {
periodTypeMetadata = column
.getMetadata(PeriodTypeMetadata.class);
PeriodType periodType = periodTypeMetadata
.getType();
colData.setPeriodDataType(PeriodTypeMap
.map(periodType));
}
PeriodType periodType = periodTypeMetadata.getType();
colData.setPeriodDataType(PeriodTypeMap.map(periodType));
}
ColumnRelationship rel = column.getRelationship();
if (rel != null) {
RelationshipData relData = retrieveRelationship(service,
table, column, periodTypeMetadata, rel);
RelationshipData relData = retrieveRelationship(
service, table, column, periodTypeMetadata, rel);
colData.setRelationship(relData);
}
if (column.contains(ViewColumnMetadata.class)) {
ColumnViewData columnViewData = retrieveColumnViewData(service, table, column,
periodTypeMetadata);
ColumnViewData columnViewData = retrieveColumnViewData(
service, table, column, periodTypeMetadata);
colData.setColumnViewData(columnViewData);
colData.setViewColumn(true);
@ -2105,27 +2138,26 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
colData.setTypeCode(column.getColumnType().getCode());
colData.setDataTypeName(column.getDataType().getName());
colData.setTrId(newTRId);
PeriodTypeMetadata periodTypeMetadata = null;
if (column.contains(PeriodTypeMetadata.class)) {
periodTypeMetadata = column
.getMetadata(PeriodTypeMetadata.class);
PeriodType periodType = periodTypeMetadata
.getType();
colData.setPeriodDataType(PeriodTypeMap
.map(periodType));
}
PeriodType periodType = periodTypeMetadata.getType();
colData.setPeriodDataType(PeriodTypeMap.map(periodType));
}
ColumnRelationship rel = column.getRelationship();
if (rel != null) {
RelationshipData relData = retrieveRelationship(service,
viewTable, column, periodTypeMetadata, rel);
RelationshipData relData = retrieveRelationship(
service, viewTable, column, periodTypeMetadata,
rel);
colData.setRelationship(relData);
}
if (column.contains(ViewColumnMetadata.class)) {
ColumnViewData columnViewData = retrieveColumnViewData(service, viewTable, column,
periodTypeMetadata);
ColumnViewData columnViewData = retrieveColumnViewData(
service, viewTable, column, periodTypeMetadata);
colData.setColumnViewData(columnViewData);
colData.setViewColumn(true);
@ -2260,12 +2292,12 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
* @param tr
* @throws TDGWTServiceException
*
private TabResource retrieveTRMetadataFromServiceAndLastTable(
TabularDataService service, TabularResource tr)
throws TDGWTServiceException {
return retrieveTRMetadataFromServiceAndLastTable(service, tr, 0);
}
*/
* private TabResource
* retrieveTRMetadataFromServiceAndLastTable( TabularDataService
* service, TabularResource tr) throws TDGWTServiceException {
* return retrieveTRMetadataFromServiceAndLastTable(service, tr,
* 0); }
*/
/**
* Retrieves the informations for a specific Tabular Resource from service
@ -2664,9 +2696,8 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
}
private ArrayList<TabResource> OrderPagingRow(
CodelistPagingLoadConfig plc, ArrayList<TabResource> ltrCopy,
HttpSession session) {
private ArrayList<TabResource> OrderPagingRow(CodelistPagingLoadConfig plc,
ArrayList<TabResource> ltrCopy, HttpSession session) {
ArrayList<OrderInfo> orders = plc.getListOrderInfo();
for (OrderInfo order : orders) {
@ -2989,9 +3020,6 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
}
}
/**
*
* {@inheritDoc}
@ -3477,8 +3505,8 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
* @param csvImportSession
* @return
*/
private Map<String, Object> csvImportFileParameter(
String fileUrlOnStorage, CSVFileUploadSession fileUploadSession,
private Map<String, Object> csvImportFileParameter(String fileUrlOnStorage,
CSVFileUploadSession fileUploadSession,
CSVImportSession csvImportSession) {
Map<String, Object> parameterInstances = new HashMap<String, Object>();
parameterInstances.put(Constants.PARAMETER_URL, fileUrlOnStorage);
@ -5165,8 +5193,6 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
cData.setLocale(dataLocaleMetadata.getLocale());
}
cData.setTrId(trId);
columns.add(cData);
i++;