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; public UserInfo hello() throws TDGWTServiceException;
/**
* Retrieve pending Tasks and set them as background tasks
*
* @throws TDGWTServiceException
*/
public Integer pendingTasksRetrieve() throws TDGWTServiceException;
/** /**
* Restore UI session * Restore UI session
* *

View File

@ -90,6 +90,8 @@ public interface TDGWTServiceAsync {
void hello(AsyncCallback<UserInfo> callback); void hello(AsyncCallback<UserInfo> callback);
void pendingTasksRetrieve(AsyncCallback<Integer> callback);
void restoreUISession(AsyncCallback<TRId> callback); void restoreUISession(AsyncCallback<TRId> callback);
void getUriFromResolver(UriResolverSession uriResolverSession, 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.AuthorizationToken;
import org.gcube.data.analysis.tabulardata.commons.utils.Licence; 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.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.TemplateDescription;
import org.gcube.data.analysis.tabulardata.commons.webservice.types.operations.OperationDefinition; import org.gcube.data.analysis.tabulardata.commons.webservice.types.operations.OperationDefinition;
import org.gcube.data.analysis.tabulardata.commons.webservice.types.operations.OperationExecution; import org.gcube.data.analysis.tabulardata.commons.webservice.types.operations.OperationExecution;
@ -311,6 +312,57 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
return userInfo; 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} * {@inheritDoc}
@ -926,8 +978,8 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
ColumnRelationship rel = c.getRelationship(); ColumnRelationship rel = c.getRelationship();
if (rel != null) { if (rel != null) {
RelationshipData relData = retrieveRelationship(service, RelationshipData relData = retrieveRelationship(
table, c, periodTypeMetadata, rel); service, table, c, periodTypeMetadata, rel);
cData.setRelationship(relData); cData.setRelationship(relData);
} }
@ -965,7 +1017,6 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
cData.setLocale(dataLocaleMetadata.getLocale()); cData.setLocale(dataLocaleMetadata.getLocale());
} }
cData.setTrId(trId); cData.setTrId(trId);
columns.add(cData); columns.add(cData);
i++; i++;
@ -1043,8 +1094,8 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
ColumnRelationship rel = c.getRelationship(); ColumnRelationship rel = c.getRelationship();
if (rel != null) { if (rel != null) {
RelationshipData relData = retrieveRelationship(service, RelationshipData relData = retrieveRelationship(
table, c, periodTypeMetadata, rel); service, table, c, periodTypeMetadata, rel);
cData.setRelationship(relData); cData.setRelationship(relData);
} }
@ -1083,8 +1134,6 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
cData.setLocale(dataLocaleMetadata.getLocale()); cData.setLocale(dataLocaleMetadata.getLocale());
} }
cData.setTrId(trId); cData.setTrId(trId);
columns.add(cData); columns.add(cData);
i++; i++;
@ -1157,8 +1206,8 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
ColumnRelationship rel = c.getRelationship(); ColumnRelationship rel = c.getRelationship();
if (rel != null) { if (rel != null) {
RelationshipData relData = retrieveRelationship(service, RelationshipData relData = retrieveRelationship(
table, c, periodTypeMetadata, rel); service, table, c, periodTypeMetadata, rel);
cData.setRelationship(relData); cData.setRelationship(relData);
} }
@ -1197,10 +1246,9 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
cData.setLocale(dataLocaleMetadata.getLocale()); cData.setLocale(dataLocaleMetadata.getLocale());
} }
if (c.contains(ViewColumnMetadata.class)) { if (c.contains(ViewColumnMetadata.class)) {
ColumnViewData columnViewData = retrieveColumnViewData(service, table, c, ColumnViewData columnViewData = retrieveColumnViewData(
periodTypeMetadata); service, table, c, periodTypeMetadata);
cData.setColumnViewData(columnViewData); cData.setColumnViewData(columnViewData);
cData.setViewColumn(true); cData.setViewColumn(true);
} else { } else {
@ -1281,8 +1329,8 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
ColumnRelationship rel = c.getRelationship(); ColumnRelationship rel = c.getRelationship();
if (rel != null) { if (rel != null) {
RelationshipData relData = retrieveRelationship(service, RelationshipData relData = retrieveRelationship(
table, c, periodTypeMetadata, rel); service, table, c, periodTypeMetadata, rel);
cData.setRelationship(relData); cData.setRelationship(relData);
} }
@ -1320,10 +1368,9 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
cData.setLocale(dataLocaleMetadata.getLocale()); cData.setLocale(dataLocaleMetadata.getLocale());
} }
if (c.contains(ViewColumnMetadata.class)) { if (c.contains(ViewColumnMetadata.class)) {
ColumnViewData columnViewData = retrieveColumnViewData(service, table, c, ColumnViewData columnViewData = retrieveColumnViewData(
periodTypeMetadata); service, table, c, periodTypeMetadata);
cData.setColumnViewData(columnViewData); cData.setColumnViewData(columnViewData);
cData.setViewColumn(true); cData.setViewColumn(true);
} else { } else {
@ -1391,19 +1438,18 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
Table timeTable = service Table timeTable = service
.getTimeTable(periodTypeMetadata.getType()); .getTimeTable(periodTypeMetadata.getType());
if (timeTable == null || timeTable.getId() == null) { if (timeTable == null || timeTable.getId() == null) {
throw new TDGWTServiceException( throw new TDGWTServiceException("Error retrieving Time Table: "
"Error retrieving Time Table: " + table); + table);
} }
logger.debug("Time Table Id: "+timeTable.getId()); logger.debug("Time Table Id: " + timeTable.getId());
Column timeColumn = timeTable Column timeColumn = timeTable.getColumnByName(periodTypeMetadata
.getColumnByName(periodTypeMetadata.getType() .getType().getName());
.getName()); relData = new RelationshipData(timeTable.getId().getValue(),
relData = new RelationshipData(timeTable.getId() timeColumn.getLocalId().getValue());
.getValue(), timeColumn.getLocalId().getValue());
} else { } else {
relData = new RelationshipData(rel.getTargetTableId() relData = new RelationshipData(rel.getTargetTableId().getValue(),
.getValue(), rel.getTargetColumnId().getValue()); rel.getTargetColumnId().getValue());
} }
return relData; return relData;
} }
@ -1413,10 +1459,9 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
throws TDGWTServiceException { throws TDGWTServiceException {
ViewColumnMetadata viewMetadata = c ViewColumnMetadata viewMetadata = c
.getMetadata(ViewColumnMetadata.class); .getMetadata(ViewColumnMetadata.class);
logger.debug("ViewColumnMetadata: " logger.debug("ViewColumnMetadata: " + viewMetadata.toString());
+ viewMetadata.toString());
ColumnViewData columnViewData=null; ColumnViewData columnViewData = null;
Column sourceColumn = table.getColumnById(viewMetadata Column sourceColumn = table.getColumnById(viewMetadata
.getSourceTableDimensionColumnId()); .getSourceTableDimensionColumnId());
if (sourceColumn.getColumnType().getCode() if (sourceColumn.getColumnType().getCode()
@ -1434,25 +1479,26 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
throw new TDGWTServiceException( throw new TDGWTServiceException(
"Error retrieving Time Table: " + table); "Error retrieving Time Table: " + table);
} }
logger.debug("Time Table Id: "+timeTable.getId()); logger.debug("Time Table Id: " + timeTable.getId());
Column timeColumn = timeTable Column timeColumn = timeTable
.getColumnByName(periodTypeMetadataSourceColumn.getType() .getColumnByName(periodTypeMetadataSourceColumn
.getName()); .getType().getName());
String sourceTableDimensionColumnId = viewMetadata String sourceTableDimensionColumnId = viewMetadata
.getSourceTableDimensionColumnId().getValue(); .getSourceTableDimensionColumnId().getValue();
String targetTableColumnId = timeColumn.getLocalId().getValue(); String targetTableColumnId = timeColumn.getLocalId().getValue();
long targetTableId = timeTable.getId() long targetTableId = timeTable.getId().getValue();
.getValue();
columnViewData = new ColumnViewData( columnViewData = new ColumnViewData(
sourceTableDimensionColumnId, sourceTableDimensionColumnId, targetTableColumnId,
targetTableColumnId, targetTableId); targetTableId);
} else { } 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( throw new TDGWTServiceException(
"Error retrieving Time Table, source column do not have a PeriodTypeMetadata"); "Error retrieving Time Table, source column do not have a PeriodTypeMetadata");
} }
@ -1461,18 +1507,15 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
String sourceTableDimensionColumnId = viewMetadata String sourceTableDimensionColumnId = viewMetadata
.getSourceTableDimensionColumnId().getValue(); .getSourceTableDimensionColumnId().getValue();
String targetTableColumnId = viewMetadata String targetTableColumnId = viewMetadata.getTargetTableColumnId()
.getTargetTableColumnId().getValue();
long targetTableId = viewMetadata.getTargetTableId()
.getValue(); .getValue();
columnViewData = new ColumnViewData( long targetTableId = viewMetadata.getTargetTableId().getValue();
sourceTableDimensionColumnId, columnViewData = new ColumnViewData(sourceTableDimensionColumnId,
targetTableColumnId, targetTableId); targetTableColumnId, targetTableId);
} }
return columnViewData; return columnViewData;
} }
/** /**
* *
* {@inheritDoc} * {@inheritDoc}
@ -1509,8 +1552,8 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
} }
if (c.contains(ViewColumnMetadata.class)) { if (c.contains(ViewColumnMetadata.class)) {
ColumnViewData columnViewData = retrieveColumnViewData(service, table, c, ColumnViewData columnViewData = retrieveColumnViewData(
periodTypeMetadata); service, table, c, periodTypeMetadata);
cData.setColumnViewData(columnViewData); cData.setColumnViewData(columnViewData);
cData.setViewColumn(true); cData.setViewColumn(true);
} else { } else {
@ -1578,8 +1621,6 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
} }
} }
/** /**
* *
* {@inheritDoc} * {@inheritDoc}
@ -1616,8 +1657,8 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
} }
if (c.contains(ViewColumnMetadata.class)) { if (c.contains(ViewColumnMetadata.class)) {
ColumnViewData columnViewData = retrieveColumnViewData(service, table, c, ColumnViewData columnViewData = retrieveColumnViewData(
periodTypeMetadata); service, table, c, periodTypeMetadata);
cData.setColumnViewData(columnViewData); cData.setColumnViewData(columnViewData);
cData.setViewColumn(true); cData.setViewColumn(true);
} else { } else {
@ -1664,8 +1705,6 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
cData.setLocale(dataLocaleMetadata.getLocale()); cData.setLocale(dataLocaleMetadata.getLocale());
} }
cData.setTrId(trId); cData.setTrId(trId);
} }
@ -1875,22 +1914,20 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
if (column.contains(PeriodTypeMetadata.class)) { if (column.contains(PeriodTypeMetadata.class)) {
periodTypeMetadata = column periodTypeMetadata = column
.getMetadata(PeriodTypeMetadata.class); .getMetadata(PeriodTypeMetadata.class);
PeriodType periodType = periodTypeMetadata PeriodType periodType = periodTypeMetadata.getType();
.getType(); colData.setPeriodDataType(PeriodTypeMap.map(periodType));
colData.setPeriodDataType(PeriodTypeMap
.map(periodType));
} }
ColumnRelationship rel = column.getRelationship(); ColumnRelationship rel = column.getRelationship();
if (rel != null) { if (rel != null) {
RelationshipData relData = retrieveRelationship(service, RelationshipData relData = retrieveRelationship(
table, column, periodTypeMetadata, rel); service, table, column, periodTypeMetadata, rel);
colData.setRelationship(relData); colData.setRelationship(relData);
} }
if (column.contains(ViewColumnMetadata.class)) { if (column.contains(ViewColumnMetadata.class)) {
ColumnViewData columnViewData = retrieveColumnViewData(service, table, column, ColumnViewData columnViewData = retrieveColumnViewData(
periodTypeMetadata); service, table, column, periodTypeMetadata);
colData.setColumnViewData(columnViewData); colData.setColumnViewData(columnViewData);
colData.setViewColumn(true); colData.setViewColumn(true);
@ -1937,22 +1974,21 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
if (column.contains(PeriodTypeMetadata.class)) { if (column.contains(PeriodTypeMetadata.class)) {
periodTypeMetadata = column periodTypeMetadata = column
.getMetadata(PeriodTypeMetadata.class); .getMetadata(PeriodTypeMetadata.class);
PeriodType periodType = periodTypeMetadata PeriodType periodType = periodTypeMetadata.getType();
.getType(); colData.setPeriodDataType(PeriodTypeMap.map(periodType));
colData.setPeriodDataType(PeriodTypeMap
.map(periodType));
} }
ColumnRelationship rel = column.getRelationship(); ColumnRelationship rel = column.getRelationship();
if (rel != null) { if (rel != null) {
RelationshipData relData = retrieveRelationship(service, RelationshipData relData = retrieveRelationship(
viewTable, column, periodTypeMetadata, rel); service, viewTable, column, periodTypeMetadata,
rel);
colData.setRelationship(relData); colData.setRelationship(relData);
} }
if (column.contains(ViewColumnMetadata.class)) { if (column.contains(ViewColumnMetadata.class)) {
ColumnViewData columnViewData = retrieveColumnViewData(service, viewTable, column, ColumnViewData columnViewData = retrieveColumnViewData(
periodTypeMetadata); service, viewTable, column, periodTypeMetadata);
colData.setColumnViewData(columnViewData); colData.setColumnViewData(columnViewData);
colData.setViewColumn(true); colData.setViewColumn(true);
@ -2047,23 +2083,20 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
if (column.contains(PeriodTypeMetadata.class)) { if (column.contains(PeriodTypeMetadata.class)) {
periodTypeMetadata = column periodTypeMetadata = column
.getMetadata(PeriodTypeMetadata.class); .getMetadata(PeriodTypeMetadata.class);
PeriodType periodType = periodTypeMetadata PeriodType periodType = periodTypeMetadata.getType();
.getType(); colData.setPeriodDataType(PeriodTypeMap.map(periodType));
colData.setPeriodDataType(PeriodTypeMap
.map(periodType));
} }
ColumnRelationship rel = column.getRelationship(); ColumnRelationship rel = column.getRelationship();
if (rel != null) { if (rel != null) {
RelationshipData relData = retrieveRelationship(service, RelationshipData relData = retrieveRelationship(
table, column, periodTypeMetadata, rel); service, table, column, periodTypeMetadata, rel);
colData.setRelationship(relData); colData.setRelationship(relData);
} }
if (column.contains(ViewColumnMetadata.class)) { if (column.contains(ViewColumnMetadata.class)) {
ColumnViewData columnViewData = retrieveColumnViewData(service, table, column, ColumnViewData columnViewData = retrieveColumnViewData(
periodTypeMetadata); service, table, column, periodTypeMetadata);
colData.setColumnViewData(columnViewData); colData.setColumnViewData(columnViewData);
colData.setViewColumn(true); colData.setViewColumn(true);
@ -2110,22 +2143,21 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
if (column.contains(PeriodTypeMetadata.class)) { if (column.contains(PeriodTypeMetadata.class)) {
periodTypeMetadata = column periodTypeMetadata = column
.getMetadata(PeriodTypeMetadata.class); .getMetadata(PeriodTypeMetadata.class);
PeriodType periodType = periodTypeMetadata PeriodType periodType = periodTypeMetadata.getType();
.getType(); colData.setPeriodDataType(PeriodTypeMap.map(periodType));
colData.setPeriodDataType(PeriodTypeMap
.map(periodType));
} }
ColumnRelationship rel = column.getRelationship(); ColumnRelationship rel = column.getRelationship();
if (rel != null) { if (rel != null) {
RelationshipData relData = retrieveRelationship(service, RelationshipData relData = retrieveRelationship(
viewTable, column, periodTypeMetadata, rel); service, viewTable, column, periodTypeMetadata,
rel);
colData.setRelationship(relData); colData.setRelationship(relData);
} }
if (column.contains(ViewColumnMetadata.class)) { if (column.contains(ViewColumnMetadata.class)) {
ColumnViewData columnViewData = retrieveColumnViewData(service, viewTable, column, ColumnViewData columnViewData = retrieveColumnViewData(
periodTypeMetadata); service, viewTable, column, periodTypeMetadata);
colData.setColumnViewData(columnViewData); colData.setColumnViewData(columnViewData);
colData.setViewColumn(true); colData.setViewColumn(true);
@ -2260,12 +2292,12 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
* @param tr * @param tr
* @throws TDGWTServiceException * @throws TDGWTServiceException
* *
private TabResource retrieveTRMetadataFromServiceAndLastTable( * private TabResource
TabularDataService service, TabularResource tr) * retrieveTRMetadataFromServiceAndLastTable( TabularDataService
throws TDGWTServiceException { * service, TabularResource tr) throws TDGWTServiceException {
return retrieveTRMetadataFromServiceAndLastTable(service, tr, 0); * return retrieveTRMetadataFromServiceAndLastTable(service, tr,
} * 0); }
*/ */
/** /**
* Retrieves the informations for a specific Tabular Resource from service * Retrieves the informations for a specific Tabular Resource from service
@ -2664,9 +2696,8 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
} }
private ArrayList<TabResource> OrderPagingRow( private ArrayList<TabResource> OrderPagingRow(CodelistPagingLoadConfig plc,
CodelistPagingLoadConfig plc, ArrayList<TabResource> ltrCopy, ArrayList<TabResource> ltrCopy, HttpSession session) {
HttpSession session) {
ArrayList<OrderInfo> orders = plc.getListOrderInfo(); ArrayList<OrderInfo> orders = plc.getListOrderInfo();
for (OrderInfo order : orders) { for (OrderInfo order : orders) {
@ -2989,9 +3020,6 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
} }
} }
/** /**
* *
* {@inheritDoc} * {@inheritDoc}
@ -3477,8 +3505,8 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
* @param csvImportSession * @param csvImportSession
* @return * @return
*/ */
private Map<String, Object> csvImportFileParameter( private Map<String, Object> csvImportFileParameter(String fileUrlOnStorage,
String fileUrlOnStorage, CSVFileUploadSession fileUploadSession, CSVFileUploadSession fileUploadSession,
CSVImportSession csvImportSession) { CSVImportSession csvImportSession) {
Map<String, Object> parameterInstances = new HashMap<String, Object>(); Map<String, Object> parameterInstances = new HashMap<String, Object>();
parameterInstances.put(Constants.PARAMETER_URL, fileUrlOnStorage); parameterInstances.put(Constants.PARAMETER_URL, fileUrlOnStorage);
@ -5165,8 +5193,6 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
cData.setLocale(dataLocaleMetadata.getLocale()); cData.setLocale(dataLocaleMetadata.getLocale());
} }
cData.setTrId(trId); cData.setTrId(trId);
columns.add(cData); columns.add(cData);
i++; i++;