Added Delete Rows

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-gwt-service@92751 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2014-03-06 14:17:25 +00:00
parent 31e4c8667e
commit a55db93c3a
7 changed files with 362 additions and 16 deletions

View File

@ -32,6 +32,8 @@ import org.gcube.portlets.user.td.gwtservice.shared.tr.metadata.TRMetadata;
import org.gcube.portlets.user.td.gwtservice.shared.tr.open.TDOpenSession;
import org.gcube.portlets.user.td.gwtservice.shared.tr.paging.CodelistPagingLoadConfig;
import org.gcube.portlets.user.td.gwtservice.shared.tr.paging.CodelistPagingLoadResult;
import org.gcube.portlets.user.td.gwtservice.shared.tr.rows.DeleteRowsMonitor;
import org.gcube.portlets.user.td.gwtservice.shared.tr.rows.DeleteRowsSession;
import org.gcube.portlets.user.td.gwtservice.shared.tr.table.ChangeTableTypeMonitor;
import org.gcube.portlets.user.td.gwtservice.shared.tr.table.ChangeTableTypeSession;
import org.gcube.portlets.user.td.gwtservice.shared.tr.table.metadata.TabMetadata;
@ -402,7 +404,7 @@ public interface TDGWTService extends RemoteService {
public void startSDMXExport(SDMXExportSession exportSession)
throws TDGWTServiceException;
// Change Table Type
// Table Operations
/**
* Get Operation Monitor during the Change Table Type operation
*
@ -423,6 +425,30 @@ public interface TDGWTService extends RemoteService {
ChangeTableTypeSession changeTableTypeSession)
throws TDGWTServiceException;
//Rows Operations
/**
* Get Operation Monitor during the Delete Rows operation
*
*
* @return
* @throws TDGWTServiceException
*/
public DeleteRowsMonitor getDeleteRowsMonitor()
throws TDGWTServiceException;
/**
* Start delete rows
*
* @param labelColumnSession
* @throws TDGWTServiceException
*/
public void startDeleteRows(
DeleteRowsSession deleteRowsSession)
throws TDGWTServiceException;
// Column Operation
/**

View File

@ -31,6 +31,8 @@ import org.gcube.portlets.user.td.gwtservice.shared.tr.metadata.TRMetadata;
import org.gcube.portlets.user.td.gwtservice.shared.tr.open.TDOpenSession;
import org.gcube.portlets.user.td.gwtservice.shared.tr.paging.CodelistPagingLoadConfig;
import org.gcube.portlets.user.td.gwtservice.shared.tr.paging.CodelistPagingLoadResult;
import org.gcube.portlets.user.td.gwtservice.shared.tr.rows.DeleteRowsMonitor;
import org.gcube.portlets.user.td.gwtservice.shared.tr.rows.DeleteRowsSession;
import org.gcube.portlets.user.td.gwtservice.shared.tr.table.ChangeTableTypeMonitor;
import org.gcube.portlets.user.td.gwtservice.shared.tr.table.ChangeTableTypeSession;
import org.gcube.portlets.user.td.gwtservice.shared.tr.table.metadata.TabMetadata;
@ -139,11 +141,15 @@ public interface TDGWTServiceAsync {
void startSDMXExport(SDMXExportSession exportSession, AsyncCallback<Void> callback);
//Change Table Type
//Table Operation
void getChangeTableTypeMonitor(AsyncCallback<ChangeTableTypeMonitor> callback);
void startChangeTableType(ChangeTableTypeSession changeTableTypeSession,AsyncCallback<Void> callback);
//Rows Operation
void getDeleteRowsMonitor(AsyncCallback<DeleteRowsMonitor> callback);
void startDeleteRows(DeleteRowsSession deleteRowsSession,AsyncCallback<Void> callback);
//Column Operation
void getChangeColumnTypeMonitor(AsyncCallback<ChangeColumnTypeMonitor> callback);
void startChangeColumnType(ChangeColumnTypeSession changeColumnTypeSession,AsyncCallback<Void> callback);

View File

@ -30,6 +30,8 @@ import org.gcube.portlets.user.td.gwtservice.shared.tr.column.LabelColumnSession
import org.gcube.portlets.user.td.gwtservice.shared.tr.column.type.ChangeColumnTypeMonitor;
import org.gcube.portlets.user.td.gwtservice.shared.tr.column.type.ChangeColumnTypeSession;
import org.gcube.portlets.user.td.gwtservice.shared.tr.open.TDOpenSession;
import org.gcube.portlets.user.td.gwtservice.shared.tr.rows.DeleteRowsMonitor;
import org.gcube.portlets.user.td.gwtservice.shared.tr.rows.DeleteRowsSession;
import org.gcube.portlets.user.td.gwtservice.shared.tr.table.ChangeTableTypeMonitor;
import org.gcube.portlets.user.td.gwtservice.shared.tr.table.ChangeTableTypeSession;
import org.gcube.portlets.user.td.gwtservice.shared.tr.type.Agencies;
@ -90,6 +92,9 @@ public class SessionUtil {
protected static final String CHANGE_TABLE_TYPE_MONITOR = "CHANGE_TABLE_TYPE_MONITOR";
protected static final String CHANGE_TABLE_TYPE_TASK = "CHANGE_TABLE_TYPE_TASK";
protected static final String DELETE_ROWS_SESSION = "DELETE_ROWS_SESSION";
protected static final String DELETE_ROWS_MONITOR = "DELETE_ROWS_MONITOR";
protected static final String DELETE_ROWS_TASK = "DELETE_ROWS_TASK";
protected static final String CODELISTS_PAGING_LOADED = "CODELISTS_PAGING_LOADED";
protected static final String CODELISTS_PAGING_LOADED_FILTERED_COPY="CODELISTS_PAGING_LOADED_FILTERED_COPY";
@ -813,6 +818,78 @@ public class SessionUtil {
///
public static DeleteRowsSession getDeleteRowsSession(
HttpSession httpSession) {
DeleteRowsSession deleteRowsSession = (DeleteRowsSession) httpSession
.getAttribute(DELETE_ROWS_SESSION);
if (deleteRowsSession != null) {
return deleteRowsSession;
} else {
deleteRowsSession = new DeleteRowsSession();
httpSession.setAttribute(DELETE_ROWS_SESSION,
deleteRowsSession);
return deleteRowsSession;
}
}
public static void setDeleteRowsSession(HttpSession httpSession,
DeleteRowsSession deleteRowsSession) {
DeleteRowsSession dr = (DeleteRowsSession) httpSession
.getAttribute(DELETE_ROWS_SESSION);
if (dr != null) {
httpSession.removeAttribute(DELETE_ROWS_SESSION);
}
httpSession.setAttribute(DELETE_ROWS_SESSION,
deleteRowsSession);
}
public static DeleteRowsMonitor getDeleteRowsMonitor(
HttpSession httpSession) {
DeleteRowsMonitor deleteRowsMonitor = (DeleteRowsMonitor) httpSession
.getAttribute(DELETE_ROWS_MONITOR);
if (deleteRowsMonitor != null) {
return deleteRowsMonitor;
} else {
deleteRowsMonitor = new DeleteRowsMonitor();
httpSession.setAttribute(DELETE_ROWS_MONITOR,
deleteRowsMonitor);
return deleteRowsMonitor;
}
}
public static void setDeleteRowsMonitor(HttpSession httpSession,
DeleteRowsMonitor deleteRowsMonitor) {
DeleteRowsMonitor ctt = (DeleteRowsMonitor) httpSession
.getAttribute(DELETE_ROWS_MONITOR);
if (ctt != null) {
httpSession.removeAttribute(DELETE_ROWS_MONITOR);
}
httpSession.setAttribute(DELETE_ROWS_MONITOR,
deleteRowsMonitor);
}
public static Task getDeleteRowsTask(HttpSession httpSession) {
Task monitor = (Task) httpSession.getAttribute(DELETE_ROWS_TASK);
if (monitor == null) {
logger.error("DELETE_ROWS_TASK was not acquired");
}
return monitor;
}
public static void setDeleteRowsTask(HttpSession httpSession,
Task task) {
Task monitor = (Task) httpSession.getAttribute(DELETE_ROWS_TASK);
if (monitor != null)
httpSession.removeAttribute(DELETE_ROWS_TASK);
httpSession.setAttribute(DELETE_ROWS_TASK, task);
}
///
public static ArrayList<TabResource> getCodelistsPagingLoaded(
HttpSession httpSession) {
@SuppressWarnings("unchecked")
@ -875,5 +952,9 @@ public class SessionUtil {
httpSession.removeAttribute(CODELISTS_PAGING_LOADED_FILTER);
httpSession.setAttribute(CODELISTS_PAGING_LOADED_FILTER, filter);
}
}

View File

@ -118,6 +118,8 @@ import org.gcube.portlets.user.td.gwtservice.shared.tr.paging.CodelistPagingLoad
import org.gcube.portlets.user.td.gwtservice.shared.tr.paging.CodelistPagingLoadResult;
import org.gcube.portlets.user.td.gwtservice.shared.tr.paging.Direction;
import org.gcube.portlets.user.td.gwtservice.shared.tr.paging.OrderInfo;
import org.gcube.portlets.user.td.gwtservice.shared.tr.rows.DeleteRowsMonitor;
import org.gcube.portlets.user.td.gwtservice.shared.tr.rows.DeleteRowsSession;
import org.gcube.portlets.user.td.gwtservice.shared.tr.table.ChangeTableTypeMonitor;
import org.gcube.portlets.user.td.gwtservice.shared.tr.table.ChangeTableTypeSession;
import org.gcube.portlets.user.td.gwtservice.shared.tr.table.metadata.TabDescriptionsMetadata;
@ -664,9 +666,9 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
* @param tr
* @throws TDGWTServiceException
*/
protected void retriveTRMetadataFromService(TabularDataService service,
protected void retrieveTRMetadataFromService(TabularDataService service,
TabularResource tr) throws TDGWTServiceException {
retriveTRMetadataFromService(service, tr, 0);
retrieveTRMetadataFromService(service, tr, 0);
}
/**
@ -679,7 +681,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
* @return TabResource for Grid
* @throws TDGWTServiceException
*/
protected TabResource retriveTRMetadataFromService(
protected TabResource retrieveTRMetadataFromService(
TabularDataService service, TabularResource tr, int i)
throws TDGWTServiceException {
@ -745,7 +747,8 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
for (i = 0; i < trs.size(); i++) {
TabularResource tr = trs.get(i);
try {
TabResource t = retriveTRMetadataFromService(service, tr, i);
TabResource t = retrieveTRMetadataFromService(service, tr,
i);
if (t.getTrId() != null) {
ltr.add(t);
}
@ -1103,7 +1106,8 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
for (i = 0; i < trs.size(); i++) {
TabularResource tr = trs.get(i);
try {
TabResource t = retriveTRMetadataFromService(service, tr, i);
TabResource t = retrieveTRMetadataFromService(service, tr,
i);
if (t.getTrId() != null) {
ltr.add(t);
@ -2621,7 +2625,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
* @param changeColumnTypeSession
* @return
*/
protected OperationExecution retriveOperationExecution(
protected OperationExecution retrieveOperationExecution(
TabularDataService service,
ChangeColumnTypeSession changeColumnTypeSession)
throws TDGWTServiceException {
@ -2726,7 +2730,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
return invocation;
}
protected OperationExecution retriveOperationExecution(
protected OperationExecution retrieveOperationExecution(
TabularDataService service, DeleteColumnSession deleteColumnSession)
throws TDGWTServiceException {
@ -2746,7 +2750,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
return invocation;
}
protected OperationExecution retriveOperationExecution(
protected OperationExecution retrieveOperationExecution(
TabularDataService service, LabelColumnSession labelColumnSession)
throws TDGWTServiceException {
@ -2766,7 +2770,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
return invocation;
}
protected OperationExecution retriveOperationExecution(
protected OperationExecution retrieveOperationExecution(
TabularDataService service,
ChangeTableTypeSession changeTableTypeSession)
throws TDGWTServiceException {
@ -2789,6 +2793,37 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
return invocation;
}
protected OperationExecution retrieveOperationExecution(
TabularDataService service, DeleteRowsSession deleteRowsSession)
throws TDGWTServiceException {
OperationExecution invocation = null;
List<OperationDefinition> capabilities = service.getCapabilities();
logger.debug(deleteRowsSession.toString());
OperationDefinition operationDefinition;
Map<String, Object> map = new HashMap<String, Object>();
ArrayList<String> rows = deleteRowsSession.getRows();
ArrayList<Integer> rowsInt = new ArrayList<Integer>();
for (String r : rows) {
try {
Integer row = new Integer(r);
rowsInt.add(row);
} catch (NumberFormatException e) {
logger.error("Row:" + r + " is invalid Integer");
}
}
operationDefinition = OperationDefinitionMap.map(
OperationsId.RemoveRowById.toString(), capabilities);
map.put(Constants.PARAMETER_ROW_ID, rows);
invocation = new OperationExecution(
operationDefinition.getOperationId(), map);
return invocation;
}
/**
*
* {@inheritDoc}
@ -2806,7 +2841,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
aslSession.getUsername()));
TabularDataService service = TabularDataServiceFactory.getService();
OperationExecution invocation = retriveOperationExecution(service,
OperationExecution invocation = retrieveOperationExecution(service,
changeColumnTypeSession);
if (invocation == null) {
throw new TDGWTServiceException(
@ -2950,7 +2985,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
aslSession.getUsername()));
TabularDataService service = TabularDataServiceFactory.getService();
OperationExecution invocation = retriveOperationExecution(service,
OperationExecution invocation = retrieveOperationExecution(service,
deleteColumnSession);
if (invocation == null) {
throw new TDGWTServiceException(
@ -3096,7 +3131,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
aslSession.getUsername()));
TabularDataService service = TabularDataServiceFactory.getService();
OperationExecution invocation = retriveOperationExecution(service,
OperationExecution invocation = retrieveOperationExecution(service,
labelColumnSession);
if (invocation == null) {
throw new TDGWTServiceException(
@ -3245,7 +3280,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
aslSession.getUsername()));
TabularDataService service = TabularDataServiceFactory.getService();
OperationExecution invocation = retriveOperationExecution(service,
OperationExecution invocation = retrieveOperationExecution(service,
changeTableTypeSession);
if (invocation == null) {
throw new TDGWTServiceException(
@ -3448,4 +3483,141 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
}
}
@Override
public DeleteRowsMonitor getDeleteRowsMonitor()
throws TDGWTServiceException {
try {
HttpSession session = this.getThreadLocalRequest().getSession();
DeleteRowsSession deleteRowsSession = SessionUtil
.getDeleteRowsSession(session);
Task task = SessionUtil.getDeleteRowsTask(session);
DeleteRowsMonitor deleteRowsMonitor = new DeleteRowsMonitor();
if (task == null) {
logger.debug("Task null");
throw new TDGWTServiceException(
"Error in DeleteRowsMonitor task null");
} else {
TaskStatus status = task.getStatus();
if (status == null) {
logger.debug("Services TaskStatus : null");
throw new TDGWTServiceException(
"Error in DeleteRowsMonitor Status null");
} else {
logger.debug("Services TaskStatus: " + task.getStatus());
deleteRowsMonitor.setStatus(TaskStateMap.map(task
.getStatus()));
Table table;
TRId trId;
TabResource tabResource;
switch (deleteRowsMonitor.getStatus()) {
case FAILED:
if (task.getResult() != null) {
logger.debug("Task exception:"
+ task.getErrorCause());
deleteRowsMonitor.setError(new Throwable(task
.getErrorCause()));
} else {
logger.debug("Task exception: Error In DeleteRowsMonitor");
deleteRowsMonitor.setError(new Throwable(
"Error deleting rows"));
}
deleteRowsMonitor.setProgress(task.getProgress());
break;
case SUCCEDED:
logger.debug("Task Result:" + task.getResult());
deleteRowsMonitor.setProgress(task.getProgress());
table = task.getResult().getPrimaryTable();
logger.debug("Table retrived: " + table.toString());
trId = new TRId();
trId.setId(deleteRowsSession.getTrId().getId());
trId.setTableId(String
.valueOf(table.getId().getValue()));
trId.setTableType(table.getTableType().getName());
deleteRowsMonitor.setTrId(trId);
tabResource = SessionUtil.getTabResource(session);
tabResource.setTrId(trId);
SessionUtil.setTabResource(session, tabResource);
SessionUtil.setTRId(session, trId);
break;
case IN_PROGRESS:
deleteRowsMonitor.setProgress(task.getProgress());
break;
case VALIDATING_RULES:
deleteRowsMonitor.setProgress(task.getProgress());
break;
case ABORTED:
break;
case STOPPED:
logger.debug("Task Result:" + task.getResult());
deleteRowsMonitor.setProgress(task.getProgress());
table = task.getResult().getPrimaryTable();
logger.debug("Table retrived: " + table.toString());
trId = new TRId();
trId.setId(deleteRowsSession.getTrId().getId());
trId.setTableId(String
.valueOf(table.getId().getValue()));
trId.setTableType(table.getTableType().getName());
deleteRowsMonitor.setTrId(trId);
tabResource = SessionUtil.getTabResource(session);
tabResource.setTrId(trId);
SessionUtil.setTabResource(session, tabResource);
SessionUtil.setTRId(session, trId);
break;
case INITIALIZING:
break;
default:
break;
}
}
SessionUtil.setDeleteRowsTask(session, task);
}
logger.info("DeleteRowsMonitor(): " + deleteRowsMonitor);
return deleteRowsMonitor;
} catch (Exception e) {
e.printStackTrace();
throw new TDGWTServiceException(
"Error in monitor DeleteRowsMonitor: "
+ e.getLocalizedMessage());
}
}
@Override
public void startDeleteRows(DeleteRowsSession deleteRowsSession)
throws TDGWTServiceException {
try {
HttpSession session = this.getThreadLocalRequest().getSession();
SessionUtil.setDeleteRowsSession(session, deleteRowsSession);
ASLSession aslSession = SessionUtil.getAslSession(session);
AuthorizationProvider.instance.set(new AuthorizationToken(
aslSession.getUsername()));
TabularDataService service = TabularDataServiceFactory.getService();
OperationExecution invocation = retrieveOperationExecution(service,
deleteRowsSession);
if (invocation == null) {
throw new TDGWTServiceException(
"Error Delete Rows invocation: Operation not supported");
}
TabularResourceId serviceTR = new TabularResourceId(
Long.valueOf(deleteRowsSession.getTrId().getId()));
logger.debug("OperationInvocation: \n" + invocation.toString());
Task trTask = service.execute(invocation, serviceTR);
logger.debug("Start Task on service: TaskId " + trTask.getId());
SessionUtil.setDeleteRowsTask(session, trTask);
return;
} catch (Exception e) {
e.printStackTrace();
throw new TDGWTServiceException("Error Deleting Rows: "
+ e.getLocalizedMessage());
}
}
}

View File

@ -29,6 +29,7 @@ public class Constants {
public static final String PARAMETER_DATA_TYPE="dataType";
public static final String PARAMETER_TARGET_DATA_TYPE="targetDataType";
public static final String PARAMETER_REFERENCE_COLUMN="refColumn";
public static final String PARAMETER_PERIOD_FORMAT="periodFormat";
@ -36,5 +37,6 @@ public class Constants {
public static final String PARAMETER_TABLE_TYPE="tableType";
public static final String PARAMETER_ROW_ID="rowId";
}

View File

@ -0,0 +1,13 @@
package org.gcube.portlets.user.td.gwtservice.shared.tr.rows;
import java.io.Serializable;
import org.gcube.portlets.user.td.gwtservice.shared.OperationMonitor;
public class DeleteRowsMonitor extends OperationMonitor implements Serializable {
/**
*
*/
private static final long serialVersionUID = -1547897501452634298L;
}

View File

@ -0,0 +1,46 @@
package org.gcube.portlets.user.td.gwtservice.shared.tr.rows;
import java.io.Serializable;
import java.util.ArrayList;
import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId;
public class DeleteRowsSession implements Serializable {
private static final long serialVersionUID = -4503878699159491057L;
protected TRId trId;
protected ArrayList<String> rows;
public DeleteRowsSession(){
}
public DeleteRowsSession(TRId trId, ArrayList<String> rows){
this.trId=trId;
this.rows=rows;
}
public TRId getTrId() {
return trId;
}
public void setTrId(TRId trId) {
this.trId = trId;
}
public ArrayList<String> getRows() {
return rows;
}
public void setRows(ArrayList<String> rows) {
this.rows = rows;
}
@Override
public String toString() {
return "DeleteRowsSession [trId=" + trId + ", rows=" + rows + "]";
}
}