Added Union

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-gwt-service@98653 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2014-07-15 15:32:32 +00:00
parent 3239ef8bb8
commit 16cb6efd2c
10 changed files with 464 additions and 15 deletions

View File

@ -79,6 +79,8 @@ import org.gcube.portlets.user.td.gwtservice.shared.tr.table.metadata.TabValidat
import org.gcube.portlets.user.td.gwtservice.shared.tr.type.Agencies;
import org.gcube.portlets.user.td.gwtservice.shared.tr.type.Codelist;
import org.gcube.portlets.user.td.gwtservice.shared.tr.type.Dataset;
import org.gcube.portlets.user.td.gwtservice.shared.tr.union.UnionMonitor;
import org.gcube.portlets.user.td.gwtservice.shared.tr.union.UnionSession;
import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId;
import com.google.gwt.user.client.rpc.RemoteService;
@ -645,6 +647,23 @@ public interface TDGWTService extends RemoteService {
ChangeTableTypeSession changeTableTypeSession)
throws TDGWTServiceException;
/**
* Get Operation Monitor during the union operation
*
* @return
* @throws TDGWTServiceException
*/
public UnionMonitor getUnionMonitor() throws TDGWTServiceException;
/**
* Start Union and invokes the client library
*
* @param unionSession
* @throws TDGWTServiceException
*/
public void startUnion(UnionSession unionSession)
throws TDGWTServiceException;
// Rows Operations
/**
* Get Operation Monitor during the Edit Row operation

View File

@ -78,6 +78,8 @@ import org.gcube.portlets.user.td.gwtservice.shared.tr.table.metadata.TabValidat
import org.gcube.portlets.user.td.gwtservice.shared.tr.type.Agencies;
import org.gcube.portlets.user.td.gwtservice.shared.tr.type.Codelist;
import org.gcube.portlets.user.td.gwtservice.shared.tr.type.Dataset;
import org.gcube.portlets.user.td.gwtservice.shared.tr.union.UnionMonitor;
import org.gcube.portlets.user.td.gwtservice.shared.tr.union.UnionSession;
import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId;
import com.google.gwt.core.client.GWT;
@ -201,6 +203,10 @@ public interface TDGWTServiceAsync {
//Table Operation
void getChangeTableTypeMonitor(AsyncCallback<ChangeTableTypeMonitor> callback);
void startChangeTableType(ChangeTableTypeSession changeTableTypeSession,AsyncCallback<Void> callback);
void getUnionMonitor(AsyncCallback<UnionMonitor> callback);
void startUnion(UnionSession unionSession, AsyncCallback<Void> callback);
//Rows Operation
void getEditRowMonitor(AsyncCallback<EditRowMonitor> callback);

View File

@ -62,6 +62,10 @@ public class SessionConstants {
protected static final String GROUPBY_MONITOR = "GROUPBY_MONITOR";
protected static final String GROUPBY_TASK = "GROUPBY_TASK";
protected static final String UNION_SESSION = "UNION_SESSION";
protected static final String UNION_MONITOR = "UNION_MONITOR";
protected static final String UNION_TASK = "UNION_TASK";
protected static final String NORMALIZATION_SESSION = "NORMALIZATION_SESSION";
protected static final String NORMALIZATION_MONITOR = "NORMALIZATION_MONITOR";
protected static final String NORMALIZATION_TASK = "NORMALIZATION_TASK";

View File

@ -72,6 +72,8 @@ import org.gcube.portlets.user.td.gwtservice.shared.tr.table.ChangeTableTypeSess
import org.gcube.portlets.user.td.gwtservice.shared.tr.type.Agencies;
import org.gcube.portlets.user.td.gwtservice.shared.tr.type.Codelist;
import org.gcube.portlets.user.td.gwtservice.shared.tr.type.Dataset;
import org.gcube.portlets.user.td.gwtservice.shared.tr.union.UnionMonitor;
import org.gcube.portlets.user.td.gwtservice.shared.tr.union.UnionSession;
import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -2069,5 +2071,74 @@ public class SessionUtil {
//
public static UnionSession getUnionSession(
HttpSession httpSession) {
UnionSession unionSession = (UnionSession) httpSession
.getAttribute(SessionConstants.UNION_SESSION);
if (unionSession != null) {
return unionSession;
} else {
unionSession = new UnionSession();
httpSession
.setAttribute(SessionConstants.UNION_SESSION, unionSession);
return unionSession;
}
}
public static void setUnionSession(HttpSession httpSession,
UnionSession unionSession) {
UnionSession us = (UnionSession) httpSession
.getAttribute(SessionConstants.UNION_SESSION);
if (us != null) {
httpSession.removeAttribute(SessionConstants.UNION_SESSION);
}
httpSession.setAttribute(SessionConstants.UNION_SESSION, unionSession);
}
public static UnionMonitor getUnionMonitor(
HttpSession httpSession) {
UnionMonitor unionMonitor = (UnionMonitor) httpSession
.getAttribute(SessionConstants.UNION_MONITOR);
if (unionMonitor != null) {
return unionMonitor;
} else {
unionMonitor = new UnionMonitor();
httpSession
.setAttribute(SessionConstants.UNION_MONITOR, unionMonitor);
return unionMonitor;
}
}
public static void setUnionMonitor(HttpSession httpSession,
UnionMonitor unionMonitor) {
UnionMonitor um = (UnionMonitor) httpSession
.getAttribute(SessionConstants.UNION_MONITOR);
if (um != null) {
httpSession.removeAttribute(SessionConstants.UNION_MONITOR);
}
httpSession.setAttribute(SessionConstants.UNION_MONITOR, unionMonitor);
}
public static Task getUnionTask(HttpSession httpSession) {
Task monitor = (Task) httpSession.getAttribute(SessionConstants.UNION_TASK);
if (monitor == null) {
logger.error("UNION_TASK was not acquired");
}
return monitor;
}
public static void setUnionTask(HttpSession httpSession, Task task) {
Task monitor = (Task) httpSession.getAttribute(SessionConstants.UNION_TASK);
if (monitor != null)
httpSession.removeAttribute(SessionConstants.UNION_TASK);
httpSession.setAttribute(SessionConstants.UNION_TASK, task);
}
}

View File

@ -113,6 +113,7 @@ import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4Norm
import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4ReplaceBatch;
import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4ReplaceColumn;
import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4SplitColumn;
import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4Union;
import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecutionDirector;
import org.gcube.portlets.user.td.gwtservice.server.storage.FilesStorage;
import org.gcube.portlets.user.td.gwtservice.server.trservice.ExtractReferences;
@ -226,6 +227,8 @@ import org.gcube.portlets.user.td.gwtservice.shared.tr.table.metadata.TabVersion
import org.gcube.portlets.user.td.gwtservice.shared.tr.type.Agencies;
import org.gcube.portlets.user.td.gwtservice.shared.tr.type.Codelist;
import org.gcube.portlets.user.td.gwtservice.shared.tr.type.Dataset;
import org.gcube.portlets.user.td.gwtservice.shared.tr.union.UnionMonitor;
import org.gcube.portlets.user.td.gwtservice.shared.tr.union.UnionSession;
import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId;
import org.gcube.portlets.user.td.widgetcommonevent.shared.tr.column.RelationshipData;
import org.gcube.resources.discovery.client.api.DiscoveryClient;
@ -8407,5 +8410,170 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
}
}
/**
*
* {@inheritDoc}
*/
@Override
public void startUnion(UnionSession unionSession)
throws TDGWTServiceException {
try {
HttpSession session = this.getThreadLocalRequest().getSession();
SessionUtil.setUnionSession(session, unionSession);
ASLSession aslSession = SessionUtil.getAslSession(session);
AuthorizationProvider.instance.set(new AuthorizationToken(
aslSession.getUsername(), aslSession.getScope()));
TabularDataService service = TabularDataServiceFactory.getService();
OpExecution4Union opEx = new OpExecution4Union(
service, unionSession);
OpExecutionDirector director = new OpExecutionDirector();
director.setOperationExecutionBuilder(opEx);
director.constructOperationExecution();
OperationExecution invocation = director.getOperationExecution();
if (invocation == null) {
throw new TDGWTServiceException(
"Error Union invocation: Operation not supported");
}
TabularResourceId serviceTR = new TabularResourceId(
Long.valueOf(unionSession.getTrId().getId()));
logger.debug("OperationInvocation: \n" + invocation.toString());
Task trTask = service.execute(invocation, serviceTR);
logger.debug("Start Task on service: TaskId " + trTask.getId());
SessionUtil.setUnionTask(session, trTask);
return;
} catch (TDGWTSessionExpiredException e) {
throw e;
} catch (SecurityException e) {
e.printStackTrace();
throw new TDGWTServiceException(
"Security exception, you haven't rights!");
} catch (Throwable e) {
e.printStackTrace();
throw new TDGWTServiceException(
"Error in union: "
+ e.getLocalizedMessage());
}
}
/**
*
* {@inheritDoc}
*/
@Override
public UnionMonitor getUnionMonitor()
throws TDGWTServiceException {
try {
HttpSession session = this.getThreadLocalRequest().getSession();
UnionSession unionSession = SessionUtil
.getUnionSession(session);
Task task = SessionUtil.getUnionTask(session);
UnionMonitor unionMonitor = new UnionMonitor();
if (task == null) {
logger.debug("Task null");
throw new TDGWTServiceException(
"Error in UnionMonitor task null");
} else {
TaskStatus status = task.getStatus();
if (status == null) {
logger.debug("Services TaskStatus : null");
throw new TDGWTServiceException(
"Error in UnionMonitor Status null");
} else {
logger.debug("Services TaskStatus: " + task.getStatus());
unionMonitor.setStatus(TaskStateMap.map(task
.getStatus()));
TRId trId;
TabResource tabResource;
switch (unionMonitor.getStatus()) {
case FAILED:
if (task.getResult() != null) {
logger.debug("Task exception:"
+ task.getErrorCause());
task.getErrorCause().printStackTrace();
unionMonitor.setError(new Throwable(task
.getErrorCause()));
} else {
logger.debug("Task exception: Error In UnionMonitor");
unionMonitor.setError(new Throwable(
"Error in the union of tabular resources"));
}
unionMonitor.setProgress(task.getProgress());
break;
case SUCCEDED:
logger.debug("Task Result:" + task.getResult());
unionMonitor.setProgress(task.getProgress());
trId = new TRId();
trId.setId(unionSession.getTrId().getId());
trId = retrieveTabularResourceBasicData(trId);
unionMonitor.setTrId(trId);
tabResource = SessionUtil.getTabResource(session);
tabResource.setTrId(trId);
SessionUtil.setTabResource(session, tabResource);
SessionUtil.setTRId(session, trId);
break;
case IN_PROGRESS:
unionMonitor.setProgress(task.getProgress());
break;
case VALIDATING_RULES:
unionMonitor.setProgress(task.getProgress());
break;
case GENERATING_VIEW:
break;
case ABORTED:
break;
case STOPPED:
logger.debug("Task Result:" + task.getResult());
unionMonitor.setProgress(task.getProgress());
trId = new TRId();
trId.setId(unionSession.getTrId().getId());
trId = retrieveTabularResourceBasicData(trId);
unionMonitor.setTrId(trId);
tabResource = SessionUtil.getTabResource(session);
tabResource.setTrId(trId);
SessionUtil.setTabResource(session, tabResource);
SessionUtil.setTRId(session, trId);
break;
case INITIALIZING:
break;
default:
break;
}
}
SessionUtil.setUnionTask(session, task);
}
logger.debug("UnionMonitor(): " + unionMonitor);
return unionMonitor;
} catch (TDGWTSessionExpiredException e) {
throw e;
} catch (Throwable e) {
logger.debug("Error in UnionMonitor: "
+ e.getLocalizedMessage());
e.printStackTrace();
throw new TDGWTServiceException(
"Error in union monitor: "
+ e.getLocalizedMessage());
}
}
}

View File

@ -0,0 +1,66 @@
package org.gcube.portlets.user.td.gwtservice.server.opexecution;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
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.service.TabularDataService;
import org.gcube.portlets.user.td.gwtservice.server.trservice.ColumnMap;
import org.gcube.portlets.user.td.gwtservice.server.trservice.OperationDefinitionMap;
import org.gcube.portlets.user.td.gwtservice.shared.Constants;
import org.gcube.portlets.user.td.gwtservice.shared.OperationsId;
import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTServiceException;
import org.gcube.portlets.user.td.gwtservice.shared.tr.union.UnionSession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Operation Execution for union
*
* @author "Giancarlo Panichi" email: <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class OpExecution4Union extends OpExecutionBuilder {
protected static Logger logger = LoggerFactory
.getLogger(OpExecution4Union.class);
private TabularDataService service;
private UnionSession unionSession;
public OpExecution4Union(
TabularDataService service,
UnionSession unionSession) {
this.service = service;
this.unionSession = unionSession;
}
@Override
public void buildOpEx() throws TDGWTServiceException {
OperationExecution invocation = null;
logger.debug(unionSession.toString());
OperationDefinition operationDefinition;
Map<String, Object> map = new HashMap<String, Object>();
operationDefinition = OperationDefinitionMap.map(
OperationsId.Union.toString(), service);
ColumnMap columnMap = new ColumnMap();
ArrayList<Map<String, Object>> compositeColumnMap = columnMap
.genColumnMap(unionSession);
map.put(Constants.PARAMETER_UNION_COMPOSITE, compositeColumnMap);
invocation = new OperationExecution(
operationDefinition.getOperationId(), map);
operationExecutionSpec.setOp(invocation);
}
}

View File

@ -0,0 +1,105 @@
package org.gcube.portlets.user.td.gwtservice.server.trservice;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import org.gcube.data.analysis.tabulardata.model.column.ColumnLocalId;
import org.gcube.data.analysis.tabulardata.model.column.ColumnReference;
import org.gcube.data.analysis.tabulardata.model.table.TableId;
import org.gcube.portlets.user.td.gwtservice.shared.Constants;
import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTServiceException;
import org.gcube.portlets.user.td.gwtservice.shared.tr.ColumnData;
import org.gcube.portlets.user.td.gwtservice.shared.tr.TabResource;
import org.gcube.portlets.user.td.gwtservice.shared.tr.union.UnionColumnsMapping;
import org.gcube.portlets.user.td.gwtservice.shared.tr.union.UnionSession;
import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
* @author "Giancarlo Panichi" email: <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class ColumnMap {
protected static Logger logger = LoggerFactory.getLogger(ColumnMap.class);
public ColumnMap() {
}
public ArrayList<Map<String, Object>> genColumnMap(UnionSession unionSession)
throws TDGWTServiceException {
try {
ArrayList<Map<String, Object>> composit = new ArrayList<Map<String, Object>>();
logger.debug("UnionSession: " + unionSession);
if (unionSession.getColumnsMatch() == null) {
logger.debug("No columns match present");
return composit;
}
TRId sourceTRId = unionSession.getTrId();
TableId sourceTableId;
if (sourceTRId.isViewTable()) {
sourceTableId = new TableId(new Long(
sourceTRId.getReferenceTargetTableId()));
} else {
sourceTableId = new TableId(new Long(sourceTRId.getTableId()));
}
TabResource unionTR = unionSession.getUnionTabularResource();
TRId targetTRId = unionTR.getTrId();
TableId targetTableId;
if (targetTRId.isViewTable()) {
targetTableId = new TableId(new Long(
targetTRId.getReferenceTargetTableId()));
} else {
targetTableId = new TableId(new Long(targetTRId.getTableId()));
}
ArrayList<UnionColumnsMapping> columnMatch = unionSession
.getColumnsMatch();
ColumnData sourceColumn;
ColumnData targetColumn;
for (UnionColumnsMapping umap : columnMatch) {
sourceColumn = umap.getSourceColumn();
targetColumn = umap.getTargetColumn();
logger.debug("SourceColumn: " + sourceColumn);
logger.debug("TargetColumn: " + targetColumn);
if (sourceColumn != null && targetColumn != null) {
ColumnLocalId sourceColumnId = new ColumnLocalId(
sourceColumn.getColumnId());
ColumnReference sourceColumnRef = new ColumnReference(
sourceTableId, sourceColumnId);
ColumnLocalId targetColumnId = new ColumnLocalId(
targetColumn.getColumnId());
ColumnReference targetColumnRef = new ColumnReference(
targetTableId, targetColumnId);
Map<String, Object> colMap = new HashMap<String, Object>();
colMap.put(Constants.PARAMETER_UNION_COMPOSITE_SOURCE,
sourceColumnRef);
colMap.put(Constants.PARAMETER_UNION_COMPOSITE_TARGET,
targetColumnRef);
composit.add(colMap);
}
}
return composit;
} catch (Throwable e) {
logger.debug("Error in ColumnMap: " + e.getLocalizedMessage());
e.printStackTrace();
throw new TDGWTServiceException("Error in columns map: "
+ e.getLocalizedMessage());
}
}
}

View File

@ -173,4 +173,7 @@ public class ValueMap {
}

View File

@ -41,7 +41,12 @@ public class Constants {
public static final String PARAMETER_REPLACE_BY_EXPRESSION_COLUMN_CONDITION = "condition";
public static final String PARAMETER_REPLACE_BY_EXPRESSION_COLUMN_VALUE = "value";
public static final String PARAMETER_UNION_COMPOSITE_SOURCE = "source";
public static final String PARAMETER_UNION_COMPOSITE_TARGET = "target";
public static final String PARAMETER_UNION_COMPOSITE = "mapping";
public static final String PARAMETER_ADD_ROW_COMPOSITE_FIELD = "field";
public static final String PARAMETER_ADD_ROW_COMPOSITE_TOSETVALUE = "toSetValue";
public static final String PARAMETER_ADD_ROW_COMPOSITE = "mapping";

View File

@ -14,39 +14,41 @@ public class UnionColumnsMapping implements Serializable {
private static final long serialVersionUID = -8971216501310276805L;
protected ColumnData firstColumn;
protected ColumnData secondColumn;
protected ColumnData sourceColumn;
protected ColumnData targetColumn;
public UnionColumnsMapping(){
}
public UnionColumnsMapping(ColumnData firstColumn,ColumnData secondColumn){
this.firstColumn=firstColumn;
this.secondColumn=secondColumn;
public UnionColumnsMapping(ColumnData sourceColumn,ColumnData targetColumn){
this.sourceColumn=sourceColumn;
this.targetColumn=targetColumn;
}
public ColumnData getFirstColumn() {
return firstColumn;
public ColumnData getSourceColumn() {
return sourceColumn;
}
public void setFirstColumn(ColumnData firstColumn) {
this.firstColumn = firstColumn;
public void setSourceColumn(ColumnData sourceColumn) {
this.sourceColumn = sourceColumn;
}
public ColumnData getSecondColumn() {
return secondColumn;
public ColumnData getTargetColumn() {
return targetColumn;
}
public void setSecondColumn(ColumnData secondColumn) {
this.secondColumn = secondColumn;
public void setTargetColumn(ColumnData targetColumn) {
this.targetColumn = targetColumn;
}
@Override
public String toString() {
return "UnionColumnsMapping [firstColumn=" + firstColumn
+ ", secondColumn=" + secondColumn + "]";
return "UnionColumnsMapping [sourceColumn=" + sourceColumn
+ ", targetColumn=" + targetColumn + "]";
}