Added Replace Column By Expression
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-gwt-service@99816 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
57f0a7c56b
commit
9e7086cf40
|
@ -45,6 +45,8 @@ public class SessionConstants {
|
|||
|
||||
protected static final String FILTER_COLUMN_SESSION = "FILTER_COLUMN_SESSION";
|
||||
|
||||
protected static final String REPLACE_COLUMN_BY_EXPRESSION_SESSION = "REPLACE_COLUMN_BY_EXPRESSION_SESSION";
|
||||
|
||||
protected static final String EDIT_ROW_SESSION = "EDIT_ROW_SESSION";
|
||||
|
||||
protected static final String TASK_RESUBMIT_SESSION = "TASK_RESUBMIT_SESSION";
|
||||
|
|
|
@ -17,6 +17,7 @@ import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper;
|
|||
import org.gcube.portlets.user.td.gwtservice.server.file.CSVFileUploadSession;
|
||||
import org.gcube.portlets.user.td.gwtservice.server.file.CodelistMappingFileUploadSession;
|
||||
import org.gcube.portlets.user.td.gwtservice.server.trservice.TRTasksManager;
|
||||
import org.gcube.portlets.user.td.gwtservice.shared.Constants;
|
||||
import org.gcube.portlets.user.td.gwtservice.shared.codelisthelper.CodelistMappingSession;
|
||||
import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVExportSession;
|
||||
import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVImportSession;
|
||||
|
@ -39,6 +40,7 @@ import org.gcube.portlets.user.td.gwtservice.shared.tr.column.DeleteColumnSessio
|
|||
import org.gcube.portlets.user.td.gwtservice.shared.tr.column.FilterColumnSession;
|
||||
import org.gcube.portlets.user.td.gwtservice.shared.tr.column.LabelColumnSession;
|
||||
import org.gcube.portlets.user.td.gwtservice.shared.tr.column.MergeColumnSession;
|
||||
import org.gcube.portlets.user.td.gwtservice.shared.tr.column.ReplaceColumnByExpressionSession;
|
||||
import org.gcube.portlets.user.td.gwtservice.shared.tr.column.ReplaceColumnSession;
|
||||
import org.gcube.portlets.user.td.gwtservice.shared.tr.column.SplitColumnSession;
|
||||
import org.gcube.portlets.user.td.gwtservice.shared.tr.column.type.ChangeColumnTypeSession;
|
||||
|
@ -75,10 +77,10 @@ public class SessionUtil {
|
|||
ASLSession session;
|
||||
if (username == null) {
|
||||
logger.warn("no user found in session, using test one");
|
||||
throw new TDGWTSessionExpiredException("Session Expired!");
|
||||
/*throw new TDGWTSessionExpiredException("Session Expired!");*/
|
||||
|
||||
// Remove comment for Test
|
||||
/*
|
||||
|
||||
username = Constants.DEFAULT_USER;
|
||||
String scope = Constants.DEFAULT_SCOPE;
|
||||
|
||||
|
@ -86,7 +88,7 @@ public class SessionUtil {
|
|||
session = SessionManager.getInstance().getASLSession(
|
||||
httpSession.getId(), username);
|
||||
session.setScope(scope);
|
||||
*/
|
||||
|
||||
} else {
|
||||
session = SessionManager.getInstance().getASLSession(
|
||||
httpSession.getId(), username);
|
||||
|
@ -632,7 +634,34 @@ public class SessionUtil {
|
|||
filterColumnSession);
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
public static ReplaceColumnByExpressionSession getReplaceColumnByExpressionSession(
|
||||
HttpSession httpSession) {
|
||||
ReplaceColumnByExpressionSession replaceColumnByExpressionSession = (ReplaceColumnByExpressionSession) httpSession
|
||||
.getAttribute(SessionConstants.REPLACE_COLUMN_BY_EXPRESSION_SESSION);
|
||||
if (replaceColumnByExpressionSession != null) {
|
||||
return replaceColumnByExpressionSession;
|
||||
} else {
|
||||
replaceColumnByExpressionSession = new ReplaceColumnByExpressionSession();
|
||||
httpSession.setAttribute(SessionConstants.REPLACE_COLUMN_BY_EXPRESSION_SESSION,
|
||||
replaceColumnByExpressionSession);
|
||||
return replaceColumnByExpressionSession;
|
||||
}
|
||||
}
|
||||
|
||||
public static void setReplaceColumnByExpressionSession(HttpSession httpSession,
|
||||
ReplaceColumnByExpressionSession replaceColumnByExpressionSession) {
|
||||
ReplaceColumnByExpressionSession rce = (ReplaceColumnByExpressionSession) httpSession
|
||||
.getAttribute(SessionConstants.REPLACE_COLUMN_BY_EXPRESSION_SESSION);
|
||||
if (rce != null) {
|
||||
httpSession.removeAttribute(SessionConstants.REPLACE_COLUMN_BY_EXPRESSION_SESSION);
|
||||
}
|
||||
httpSession.setAttribute(SessionConstants.REPLACE_COLUMN_BY_EXPRESSION_SESSION,
|
||||
replaceColumnByExpressionSession);
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
public static TaskResubmitSession getTaskResubmitSession(
|
||||
HttpSession httpSession) {
|
||||
|
|
|
@ -123,6 +123,7 @@ import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4Merg
|
|||
import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4Normalization;
|
||||
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.OpExecution4ReplaceColumnByExpression;
|
||||
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;
|
||||
|
@ -190,6 +191,7 @@ import org.gcube.portlets.user.td.gwtservice.shared.tr.column.DeleteColumnSessio
|
|||
import org.gcube.portlets.user.td.gwtservice.shared.tr.column.FilterColumnSession;
|
||||
import org.gcube.portlets.user.td.gwtservice.shared.tr.column.LabelColumnSession;
|
||||
import org.gcube.portlets.user.td.gwtservice.shared.tr.column.MergeColumnSession;
|
||||
import org.gcube.portlets.user.td.gwtservice.shared.tr.column.ReplaceColumnByExpressionSession;
|
||||
import org.gcube.portlets.user.td.gwtservice.shared.tr.column.ReplaceColumnSession;
|
||||
import org.gcube.portlets.user.td.gwtservice.shared.tr.column.SplitColumnSession;
|
||||
import org.gcube.portlets.user.td.gwtservice.shared.tr.column.mapping.ColumnMappingData;
|
||||
|
@ -3914,6 +3916,77 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Start Replace Column by Expression
|
||||
*
|
||||
* @param replaceColumnByExpressionSession
|
||||
* @param expression
|
||||
* @param session
|
||||
* @return
|
||||
* @throws TDGWTServiceException
|
||||
*/
|
||||
public String startReplaceColumnByExpression(ReplaceColumnByExpressionSession replaceColumnByExpressionSession,
|
||||
Expression expression, HttpSession session)
|
||||
throws TDGWTServiceException {
|
||||
try {
|
||||
// HttpSession session = this.getThreadLocalRequest().getSession();
|
||||
SessionUtil.setReplaceColumnByExpressionSession(session, replaceColumnByExpressionSession);
|
||||
ASLSession aslSession = SessionUtil.getAslSession(session);
|
||||
if (replaceColumnByExpressionSession == null) {
|
||||
logger.error("ReplaceColumnByExpressionSession is null");
|
||||
throw new TDGWTServiceException(
|
||||
"Error in replace column by expression: ReplaceColumnByExpressionSession is null");
|
||||
}
|
||||
|
||||
logger.debug("StartReplaceColumnByExpression: " + replaceColumnByExpressionSession);
|
||||
AuthorizationProvider.instance.set(new AuthorizationToken(
|
||||
aslSession.getUsername(), aslSession.getScope()));
|
||||
TabularDataService service = TabularDataServiceFactory.getService();
|
||||
checkTabularResourceLocked(service, replaceColumnByExpressionSession.getColumn()
|
||||
.getTrId());
|
||||
|
||||
OpExecution4ReplaceColumnByExpression opEx = new OpExecution4ReplaceColumnByExpression(
|
||||
service, replaceColumnByExpressionSession, expression);
|
||||
OpExecutionDirector director = new OpExecutionDirector();
|
||||
director.setOperationExecutionBuilder(opEx);
|
||||
director.constructOperationExecution();
|
||||
OperationExecution invocation = director
|
||||
.getOperationExecution();
|
||||
|
||||
if (invocation == null) {
|
||||
throw new TDGWTServiceException(
|
||||
"Error in invocation: Operation not supported");
|
||||
}
|
||||
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());
|
||||
|
||||
TaskWrapper taskWrapper = new TaskWrapper(trTask,
|
||||
UIOperationsId.ReplaceByExpression, replaceColumnByExpressionSession
|
||||
.getColumn().getTrId());
|
||||
SessionUtil.setStartedTask(session, taskWrapper);
|
||||
return trTask.getId().getValue();
|
||||
|
||||
} 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 replace column by expression: "
|
||||
+ e.getLocalizedMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
|
@ -0,0 +1,72 @@
|
|||
package org.gcube.portlets.user.td.gwtservice.server.opexecution;
|
||||
|
||||
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.expression.Expression;
|
||||
import org.gcube.data.analysis.tabulardata.service.TabularDataService;
|
||||
import org.gcube.portlets.user.td.gwtservice.server.trservice.ExpressionGenerator;
|
||||
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.column.ReplaceColumnByExpressionSession;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Operation Execution for replace column
|
||||
*
|
||||
* @author "Giancarlo Panichi" email: <a
|
||||
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||
*
|
||||
*/
|
||||
public class OpExecution4ReplaceColumnByExpression extends OpExecutionBuilder {
|
||||
protected static Logger logger = LoggerFactory
|
||||
.getLogger(OpExecution4ReplaceColumnByExpression.class);
|
||||
|
||||
private TabularDataService service;
|
||||
private ReplaceColumnByExpressionSession replaceColumnByExpressionSession;
|
||||
private Expression expression;
|
||||
|
||||
public OpExecution4ReplaceColumnByExpression(TabularDataService service,
|
||||
ReplaceColumnByExpressionSession replaceColumnByExpressionSession,
|
||||
Expression expression) {
|
||||
this.service = service;
|
||||
this.replaceColumnByExpressionSession = replaceColumnByExpressionSession;
|
||||
this.expression=expression;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buildOpEx() throws TDGWTServiceException {
|
||||
|
||||
OperationExecution invocation = null;
|
||||
|
||||
logger.debug(replaceColumnByExpressionSession.toString());
|
||||
OperationDefinition operationDefinition;
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
|
||||
logger.debug("Is a Replace of basic column");
|
||||
|
||||
operationDefinition = OperationDefinitionMap.map(
|
||||
OperationsId.ReplaceColumnByExpression.toString(), service);
|
||||
|
||||
|
||||
Expression value = ExpressionGenerator
|
||||
.genReplaceValueParameterValue(replaceColumnByExpressionSession);
|
||||
|
||||
map.put(Constants.PARAMETER_REPLACE_BY_EXPRESSION_COLUMN_CONDITION,
|
||||
expression);
|
||||
map.put(Constants.PARAMETER_REPLACE_BY_EXPRESSION_COLUMN_VALUE, value);
|
||||
|
||||
invocation = new OperationExecution(replaceColumnByExpressionSession
|
||||
.getColumn().getColumnId(),
|
||||
operationDefinition.getOperationId(), map);
|
||||
|
||||
operationExecutionSpec.setOp(invocation);
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -21,6 +21,7 @@ import org.gcube.portlets.user.td.gwtservice.shared.tr.ColumnData;
|
|||
import org.gcube.portlets.user.td.gwtservice.shared.tr.batch.OccurrencesForReplaceBatchColumnSession;
|
||||
import org.gcube.portlets.user.td.gwtservice.shared.tr.batch.ReplaceBatchColumnSession;
|
||||
import org.gcube.portlets.user.td.gwtservice.shared.tr.batch.ReplaceEntry;
|
||||
import org.gcube.portlets.user.td.gwtservice.shared.tr.column.ReplaceColumnByExpressionSession;
|
||||
import org.gcube.portlets.user.td.gwtservice.shared.tr.column.ReplaceColumnSession;
|
||||
import org.gcube.portlets.user.td.gwtservice.shared.tr.rows.EditRowSession;
|
||||
import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId;
|
||||
|
@ -125,6 +126,26 @@ public class ExpressionGenerator {
|
|||
+ e.getLocalizedMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public static Expression genReplaceValueParameterValue(
|
||||
ReplaceColumnByExpressionSession replaceColumnByExpressionSession)
|
||||
throws TDGWTServiceException {
|
||||
try {
|
||||
TDTypeValue td = TDTypeValueMap.map(replaceColumnByExpressionSession
|
||||
.getColumn().getDataTypeName(),
|
||||
replaceColumnByExpressionSession.getReplaceValue());
|
||||
return td;
|
||||
|
||||
} catch (Throwable e) {
|
||||
logger.debug("Error in genReplaceValueParameterValue: "
|
||||
+ e.getLocalizedMessage());
|
||||
e.printStackTrace();
|
||||
throw new TDGWTServiceException(
|
||||
"Error generating value parameter: "
|
||||
+ e.getLocalizedMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static Expression genReplaceValueParameterCondition(
|
||||
ReplaceBatchColumnSession replaceBatchColumnSession, ReplaceEntry re)
|
||||
|
|
|
@ -85,6 +85,7 @@ public enum UIOperationsId {
|
|||
SplitColumn("Split Column"),
|
||||
Normalize("Normalize"),
|
||||
ReplaceValue("Replace Value"),
|
||||
ReplaceByExpression("Replace By Expression"),
|
||||
ReplaceBatch("Replace Batch"),
|
||||
FilterColumn("Filter Column"),
|
||||
Union("Union"),
|
||||
|
|
|
@ -5,6 +5,12 @@ import java.io.Serializable;
|
|||
import org.gcube.portlets.user.td.gwtservice.shared.tr.ColumnData;
|
||||
import org.gcube.portlets.user.td.widgetcommonevent.shared.expression.C_Expression;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author giancarlo
|
||||
* email: <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||
*
|
||||
*/
|
||||
public class FilterColumnSession implements Serializable{
|
||||
|
||||
private static final long serialVersionUID = -5362632291599472352L;
|
||||
|
|
|
@ -0,0 +1,62 @@
|
|||
package org.gcube.portlets.user.td.gwtservice.shared.tr.column;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.gcube.portlets.user.td.gwtservice.shared.tr.ColumnData;
|
||||
import org.gcube.portlets.user.td.widgetcommonevent.shared.expression.C_Expression;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author giancarlo
|
||||
* email: <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||
*
|
||||
*/
|
||||
public class ReplaceColumnByExpressionSession implements Serializable{
|
||||
|
||||
private static final long serialVersionUID = -3940140817918362233L;
|
||||
protected ColumnData column;
|
||||
protected C_Expression cexpression;
|
||||
protected String replaceValue;
|
||||
|
||||
public ReplaceColumnByExpressionSession(){
|
||||
|
||||
}
|
||||
|
||||
public ReplaceColumnByExpressionSession(ColumnData column, C_Expression cexpression,
|
||||
String replaceValue){
|
||||
this.column=column;
|
||||
this.cexpression=cexpression;
|
||||
this.replaceValue=replaceValue;
|
||||
}
|
||||
|
||||
|
||||
public ColumnData getColumn() {
|
||||
return column;
|
||||
}
|
||||
public void setColumn(ColumnData column) {
|
||||
this.column = column;
|
||||
}
|
||||
public C_Expression getCexpression() {
|
||||
return cexpression;
|
||||
}
|
||||
public void setCexpression(C_Expression cexpression) {
|
||||
this.cexpression = cexpression;
|
||||
}
|
||||
|
||||
public String getReplaceValue() {
|
||||
return replaceValue;
|
||||
}
|
||||
|
||||
public void setReplaceValue(String replaceValue) {
|
||||
this.replaceValue = replaceValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ReplaceColumnByExpressionSession [column=" + column
|
||||
+ ", cexpression=" + cexpression + ", replaceValue="
|
||||
+ replaceValue + "]";
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
package org.gcube.portlets.user.td.gwtservice.client;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.data.analysis.tabulardata.commons.utils.AuthorizationProvider;
|
||||
import org.gcube.data.analysis.tabulardata.commons.utils.AuthorizationToken;
|
||||
import org.gcube.data.analysis.tabulardata.model.column.Column;
|
||||
import org.gcube.data.analysis.tabulardata.model.table.Table;
|
||||
import org.gcube.data.analysis.tabulardata.service.TabularDataService;
|
||||
import org.gcube.data.analysis.tabulardata.service.impl.TabularDataServiceFactory;
|
||||
import org.gcube.data.analysis.tabulardata.service.tabular.TabularResource;
|
||||
import org.gcube.portlets.user.td.gwtservice.shared.Constants;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class TestServiceListTR {
|
||||
|
||||
@Test
|
||||
public void listTR() throws Exception {
|
||||
System.out.println("------------List of Tabular Resources--------------");
|
||||
ScopeProvider.instance.set(Constants.DEFAULT_SCOPE);
|
||||
AuthorizationProvider.instance.set(new AuthorizationToken(Constants.DEFAULT_USER));
|
||||
TabularDataService service = TabularDataServiceFactory.getService();
|
||||
|
||||
List<TabularResource> trs = service.getTabularResources();
|
||||
Assert.assertTrue(trs.size() > 0);
|
||||
|
||||
Table lastTable=null;
|
||||
for (TabularResource tr : trs) {
|
||||
lastTable=service.getLastTable(tr.getId());
|
||||
|
||||
if(lastTable!=null){
|
||||
System.out.println("TabularResource: [ id=" + tr.getId().getValue()+", lastTable=[ id="+lastTable.getId().getValue()+", type="+lastTable.getTableType().getName()+"]]");
|
||||
System.out.println("Last table id="+lastTable.getId()+", name="+lastTable.getName());
|
||||
for(Column col:lastTable.getColumns()){
|
||||
System.out.println("Column: [name:" + col.getName()+", localId:"+col.getLocalId()+", dataType:"+col.getDataType()+"]");
|
||||
|
||||
}
|
||||
System.out.println("---------------------------------");
|
||||
} else {
|
||||
System.out.println("TabularResource: [ id=" + tr.getId().getValue()+", lastTable= "+lastTable+"]");
|
||||
System.out.println("---------------------------------");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue