From 0d1d8c0e78734fc09cb94e6b57ce070d5e7e77dc Mon Sep 17 00:00:00 2001 From: Giancarlo Panichi Date: Thu, 18 Sep 2014 15:46:32 +0000 Subject: [PATCH] Updated Replace by Expression git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-expression-widget@100026 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../shared/model/OperatorTypeMap.java | 484 ++++++++---------- 1 file changed, 219 insertions(+), 265 deletions(-) diff --git a/src/main/java/org/gcube/portlets/user/td/expressionwidget/shared/model/OperatorTypeMap.java b/src/main/java/org/gcube/portlets/user/td/expressionwidget/shared/model/OperatorTypeMap.java index b51f3ca..80653b1 100644 --- a/src/main/java/org/gcube/portlets/user/td/expressionwidget/shared/model/OperatorTypeMap.java +++ b/src/main/java/org/gcube/portlets/user/td/expressionwidget/shared/model/OperatorTypeMap.java @@ -1,6 +1,5 @@ package org.gcube.portlets.user.td.expressionwidget.shared.model; -import java.util.ArrayList; import java.util.List; import org.gcube.portlets.user.td.expressionwidget.shared.model.composite.comparable.C_Equals; @@ -16,7 +15,6 @@ import org.gcube.portlets.user.td.expressionwidget.shared.model.composite.text.C import org.gcube.portlets.user.td.expressionwidget.shared.model.composite.text.C_TextEndsWith; import org.gcube.portlets.user.td.expressionwidget.shared.model.composite.text.C_TextMatchSQLRegexp; import org.gcube.portlets.user.td.expressionwidget.shared.model.leaf.C_ColumnReferencePlaceholder; -import org.gcube.portlets.user.td.expressionwidget.shared.model.leaf.C_ConstantList; import org.gcube.portlets.user.td.expressionwidget.shared.model.leaf.C_Range; import org.gcube.portlets.user.td.expressionwidget.shared.model.leaf.C_TypedColumnReference; import org.gcube.portlets.user.td.expressionwidget.shared.model.leaf.TD_Value; @@ -33,51 +31,51 @@ import org.gcube.portlets.user.td.widgetcommonevent.shared.tr.column.ColumnTypeM import com.allen_sauer.gwt.log.client.Log; - - /** * OperatorTypeMap creates a C_Expression usable client-side * - * @author "Giancarlo Panichi" - * g.panichi@isti.cnr.it - * + * @author "Giancarlo Panichi" g.panichi@isti.cnr.it + * */ public class OperatorTypeMap { private String readableExpression; - - public OperatorTypeMap(){ - + + public OperatorTypeMap() { + } - - public C_Expression map(ColumnData column,C_OperatorType operatorType, String firstArg, String secondArg){ + + public C_Expression map(ColumnData column, C_OperatorType operatorType, + String firstArg, String secondArg) { Log.debug("OperatorTypeMap Map"); - C_Expression exp=null; - readableExpression=new String(); - if(column.getTrId()==null){ - exp=mapPlaceHolder(column,operatorType,firstArg,secondArg); + C_Expression exp = null; + readableExpression = new String(); + if (column.getTrId() == null) { + exp = mapPlaceHolder(column, operatorType, firstArg, secondArg); } else { - exp=mapTypedColumnReference(column,operatorType,firstArg,secondArg); + exp = mapTypedColumnReference(column, operatorType, firstArg, + secondArg); } return exp; } - - public C_Expression mapPlaceHolder(ColumnData column,C_OperatorType operatorType, String firstArg, String secondArg){ + + public C_Expression mapPlaceHolder(ColumnData column, + C_OperatorType operatorType, String firstArg, String secondArg) { Log.debug("OperatorTypeMap Map Place Holder"); C_Expression exp = null; - Log.debug("Column Data Type Name:"+column.getDataTypeName()); - ColumnDataType dataType=ColumnTypeMap.getColumnDataType(column.getDataTypeName()); - Log.debug("Data Type:"+dataType); - C_ColumnReferencePlaceholder placeHolder=new C_ColumnReferencePlaceholder(dataType - , column.getColumnId()); - Log.debug("placeHolder:"+placeHolder); - String readablePlaceHolder=column.getColumnId(); - - List arguments=new ArrayList(); + Log.debug("Column Data Type Name:" + column.getDataTypeName()); + ColumnDataType dataType = ColumnTypeMap.getColumnDataType(column + .getDataTypeName()); + Log.debug("Data Type:" + dataType); + C_ColumnReferencePlaceholder placeHolder = new C_ColumnReferencePlaceholder( + dataType, column.getColumnId()); + Log.debug("placeHolder:" + placeHolder); + String readablePlaceHolder = column.getColumnId(); + TD_Value fArg; TD_Value sArg; C_Range range; - int separator; - + switch (operatorType) { case ADDITION: break; @@ -88,90 +86,81 @@ public class OperatorTypeMap { case ANY: break; case BEGINS_WITH: - exp=new C_TextBeginsWith(placeHolder,new TD_Value(dataType,firstArg)); - readableExpression="Begins("+readablePlaceHolder+", "+firstArg+")"; + exp = new C_TextBeginsWith(placeHolder, new TD_Value(dataType, + firstArg)); + readableExpression = "Begins(" + readablePlaceHolder + ", " + + firstArg + ")"; break; case BETWEEN: - fArg=new TD_Value(dataType,firstArg); - sArg=new TD_Value(dataType,secondArg); - range=new C_Range(fArg,sArg); - exp=new C_Between(placeHolder,range); - readableExpression="Between("+readablePlaceHolder+", Range("+firstArg+", "+secondArg+"))"; + fArg = new TD_Value(dataType, firstArg); + sArg = new TD_Value(dataType, secondArg); + range = new C_Range(fArg, sArg); + exp = new C_Between(placeHolder, range); + readableExpression = "Between(" + readablePlaceHolder + ", Range(" + + firstArg + ", " + secondArg + "))"; break; case CONTAINS: - separator=firstArg.indexOf(","); - if(separator==-1|| firstArg.length()==1){ - arguments.add(new TD_Value(dataType,firstArg)); - } else { - String arg; - boolean end=false; - while(!end){ - arg=firstArg.substring(0, separator); - arguments.add(new TD_Value(dataType,arg)); - separator++; - if(separator arguments=new ArrayList(); + + Log.debug("Column Data Type Name:" + column.getDataTypeName()); + ColumnDataType dataType = ColumnTypeMap.getColumnDataType(column + .getDataTypeName()); + Log.debug("Data Type:" + dataType); + C_TypedColumnReference columnReference = new C_TypedColumnReference( + column.getTrId(), dataType, column.getColumnId()); + Log.debug("Typed Column Reference:" + columnReference); + String readableColumnReference = column.getLabel(); + TD_Value fArg; TD_Value sArg; C_Range range; - int separator; - + switch (operatorType) { case ADDITION: break; @@ -295,90 +268,83 @@ public class OperatorTypeMap { case ANY: break; case BEGINS_WITH: - exp=new C_TextBeginsWith(columnReference,new TD_Value(dataType,firstArg)); - readableExpression="TextBeginsWith("+readableColumnReference+","+firstArg+")"; + exp = new C_TextBeginsWith(columnReference, new TD_Value(dataType, + firstArg)); + readableExpression = "TextBeginsWith(" + readableColumnReference + + "," + firstArg + ")"; break; case BETWEEN: - fArg=new TD_Value(dataType,firstArg); - sArg=new TD_Value(dataType,secondArg); - range=new C_Range(fArg,sArg); - exp=new C_Between(columnReference,range); - readableExpression="Between("+readableColumnReference+", Range("+firstArg+", "+secondArg+"))"; + fArg = new TD_Value(dataType, firstArg); + sArg = new TD_Value(dataType, secondArg); + range = new C_Range(fArg, sArg); + exp = new C_Between(columnReference, range); + readableExpression = "Between(" + readableColumnReference + + ", Range(" + firstArg + ", " + secondArg + "))"; break; case CONTAINS: - separator=firstArg.indexOf(","); - if(separator==-1|| firstArg.length()==1){ - arguments.add(new TD_Value(dataType,firstArg)); - } else { - String arg; - boolean end=false; - while(!end){ - arg=firstArg.substring(0, separator); - arguments.add(new TD_Value(dataType,arg)); - separator++; - if(separator arguments){ - C_Or or=new C_Or(arguments); + + public C_Expression createC_Or(List arguments) { + C_Or or = new C_Or(arguments); return or; } - - public C_Expression createC_And(List arguments){ - C_And or=new C_And(arguments); + + public C_Expression createC_And(List arguments) { + C_And or = new C_And(arguments); return or; } - + public String getReadableExpression() { return readableExpression; } - }