Added Replace on Arithmetic value

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-expression-widget@111724 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2015-02-05 12:06:15 +00:00
parent b22d4598fc
commit 21e6656ffe
14 changed files with 1771 additions and 39 deletions

View File

@ -1,7 +1,7 @@
package org.gcube.portlets.user.td.expressionwidget.client; package org.gcube.portlets.user.td.expressionwidget.client;
import org.gcube.portlets.user.td.expressionwidget.client.resources.ExpressionResources; import org.gcube.portlets.user.td.expressionwidget.client.resources.ExpressionResources;
import org.gcube.portlets.user.td.expressionwidget.shared.exception.OperatorTypeMapException; import org.gcube.portlets.user.td.expressionwidget.shared.exception.ConditionTypeMapException;
import org.gcube.portlets.user.td.gwtservice.shared.tr.ColumnData; import org.gcube.portlets.user.td.gwtservice.shared.tr.ColumnData;
import org.gcube.portlets.user.td.monitorwidget.client.utils.UtilsGXT3; import org.gcube.portlets.user.td.monitorwidget.client.utils.UtilsGXT3;
import org.gcube.portlets.user.td.widgetcommonevent.client.event.ExpressionEvent; import org.gcube.portlets.user.td.widgetcommonevent.client.event.ExpressionEvent;
@ -326,7 +326,7 @@ public class ColumnExpressionPanel extends FramedPanel {
C_Expression exp; C_Expression exp;
try { try {
exp = conditionWidget.getExpression(); exp = conditionWidget.getExpression();
} catch (OperatorTypeMapException e) { } catch (ConditionTypeMapException e) {
Log.debug(e.getLocalizedMessage()); Log.debug(e.getLocalizedMessage());
UtilsGXT3.alert("Attention", e.getLocalizedMessage()); UtilsGXT3.alert("Attention", e.getLocalizedMessage());
return; return;

View File

@ -10,8 +10,8 @@ import org.gcube.portlets.user.td.expressionwidget.client.operation.Operation;
import org.gcube.portlets.user.td.expressionwidget.client.operation.OperationProperties; import org.gcube.portlets.user.td.expressionwidget.client.operation.OperationProperties;
import org.gcube.portlets.user.td.expressionwidget.client.operation.OperationsStore; import org.gcube.portlets.user.td.expressionwidget.client.operation.OperationsStore;
import org.gcube.portlets.user.td.expressionwidget.client.resources.ExpressionResources; import org.gcube.portlets.user.td.expressionwidget.client.resources.ExpressionResources;
import org.gcube.portlets.user.td.expressionwidget.shared.exception.OperatorTypeMapException; import org.gcube.portlets.user.td.expressionwidget.shared.condition.ConditionTypeMap;
import org.gcube.portlets.user.td.expressionwidget.shared.model.OperatorTypeMap; import org.gcube.portlets.user.td.expressionwidget.shared.exception.ConditionTypeMapException;
import org.gcube.portlets.user.td.gwtservice.shared.tr.ColumnData; import org.gcube.portlets.user.td.gwtservice.shared.tr.ColumnData;
import org.gcube.portlets.user.td.widgetcommonevent.shared.expression.C_Expression; import org.gcube.portlets.user.td.widgetcommonevent.shared.expression.C_Expression;
import org.gcube.portlets.user.td.widgetcommonevent.shared.tr.column.ColumnDataType; import org.gcube.portlets.user.td.widgetcommonevent.shared.tr.column.ColumnDataType;
@ -488,7 +488,7 @@ public class ConditionWidget extends SimpleContainer {
} }
public C_Expression getExpression() throws OperatorTypeMapException { public C_Expression getExpression() throws ConditionTypeMapException {
C_Expression exp = null; C_Expression exp = null;
readableExpression = new String(); readableExpression = new String();
List<C_Expression> arguments = new ArrayList<C_Expression>(); List<C_Expression> arguments = new ArrayList<C_Expression>();
@ -501,7 +501,7 @@ public class ConditionWidget extends SimpleContainer {
DateTimeFormat sdf = DateTimeFormat.getFormat("yyyy-MM-dd"); DateTimeFormat sdf = DateTimeFormat.getFormat("yyyy-MM-dd");
OperatorTypeMap mapOp = new OperatorTypeMap(); ConditionTypeMap mapOp = new ConditionTypeMap();
Iterator<Widget> iteratorVert = vert.iterator(); Iterator<Widget> iteratorVert = vert.iterator();
HBoxLayoutContainer horiz; HBoxLayoutContainer horiz;
while (iteratorVert.hasNext()) { while (iteratorVert.hasNext()) {

View File

@ -5,7 +5,7 @@ import java.util.Date;
import org.gcube.portlets.user.td.expressionwidget.client.resources.ExpressionResources; import org.gcube.portlets.user.td.expressionwidget.client.resources.ExpressionResources;
import org.gcube.portlets.user.td.expressionwidget.client.type.ReplaceColumnByExpressionType; import org.gcube.portlets.user.td.expressionwidget.client.type.ReplaceColumnByExpressionType;
import org.gcube.portlets.user.td.expressionwidget.shared.exception.OperatorTypeMapException; import org.gcube.portlets.user.td.expressionwidget.shared.exception.ConditionTypeMapException;
import org.gcube.portlets.user.td.expressionwidget.shared.exception.ReplaceTypeMapException; import org.gcube.portlets.user.td.expressionwidget.shared.exception.ReplaceTypeMapException;
import org.gcube.portlets.user.td.expressionwidget.shared.model.leaf.TD_Value; import org.gcube.portlets.user.td.expressionwidget.shared.model.leaf.TD_Value;
import org.gcube.portlets.user.td.gwtservice.shared.tr.ColumnData; import org.gcube.portlets.user.td.gwtservice.shared.tr.ColumnData;
@ -328,7 +328,7 @@ public class ReplaceColumnByExpressionPanel extends FramedPanel {
try { try {
cConditionExpression = conditionWidget.getExpression(); cConditionExpression = conditionWidget.getExpression();
} catch (OperatorTypeMapException e) { } catch (ConditionTypeMapException e) {
Log.debug(e.getLocalizedMessage()); Log.debug(e.getLocalizedMessage());
UtilsGXT3.alert("Attention", e.getLocalizedMessage()); UtilsGXT3.alert("Attention", e.getLocalizedMessage());
return; return;

View File

@ -0,0 +1,57 @@
package org.gcube.portlets.user.td.expressionwidget.client.properties;
import java.io.Serializable;
import org.gcube.portlets.user.td.expressionwidget.shared.replace.ReplaceArithmeticType;
/**
*
* @author giancarlo email: <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class ReplaceArithmeticElement implements Serializable {
private static final long serialVersionUID = 3187480746998044539L;
private Integer id;
private ReplaceArithmeticType replaceArithmeticType;
public ReplaceArithmeticElement() {
super();
}
public ReplaceArithmeticElement(Integer id, ReplaceArithmeticType replaceArithmeticType) {
super();
this.id = id;
this.replaceArithmeticType = replaceArithmeticType;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getLabel() {
return replaceArithmeticType.toString();
}
public ReplaceArithmeticType getReplaceArithmeticType() {
return replaceArithmeticType;
}
public void setReplaceArithmeticType(ReplaceArithmeticType replaceArithmeticType) {
this.replaceArithmeticType = replaceArithmeticType;
}
@Override
public String toString() {
return "ReplaceArithmeticElement [id=" + id
+ ", replaceArithmeticType=" + replaceArithmeticType + "]";
}
}

View File

@ -0,0 +1,21 @@
package org.gcube.portlets.user.td.expressionwidget.client.properties;
import com.google.gwt.editor.client.Editor.Path;
import com.sencha.gxt.data.shared.LabelProvider;
import com.sencha.gxt.data.shared.ModelKeyProvider;
import com.sencha.gxt.data.shared.PropertyAccess;
/**
*
* @author "Giancarlo Panichi"
* <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public interface ReplaceArithmeticElementProperties extends PropertyAccess<ReplaceArithmeticElement> {
@Path("id")
ModelKeyProvider<ReplaceArithmeticElement> id();
LabelProvider<ReplaceArithmeticElement> label();
}

View File

@ -0,0 +1,48 @@
package org.gcube.portlets.user.td.expressionwidget.client.properties;
import java.util.ArrayList;
import org.gcube.portlets.user.td.expressionwidget.shared.replace.ReplaceArithmeticType;
/**
*
* @author "Giancarlo Panichi" <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class ReplaceArithmeticElementStore {
public ArrayList<ReplaceArithmeticElement> replaceArithmeticElementsOperators = new ArrayList<ReplaceArithmeticElement>() {
private static final long serialVersionUID = 7803379977670393398L;
{
add(new ReplaceArithmeticElement(1, ReplaceArithmeticType.Value));
add(new ReplaceArithmeticElement(2, ReplaceArithmeticType.ColumnValue));
add(new ReplaceArithmeticElement(3, ReplaceArithmeticType.SubstringByRegex));
add(new ReplaceArithmeticElement(4, ReplaceArithmeticType.SubstringByIndex));
add(new ReplaceArithmeticElement(5, ReplaceArithmeticType.SubstringByCharSeq));
add(new ReplaceArithmeticElement(6, ReplaceArithmeticType.TextReplaceMatchingRegex));
add(new ReplaceArithmeticElement(7, ReplaceArithmeticType.Addition));
add(new ReplaceArithmeticElement(8, ReplaceArithmeticType.Subtraction));
add(new ReplaceArithmeticElement(9, ReplaceArithmeticType.Modulus));
add(new ReplaceArithmeticElement(10, ReplaceArithmeticType.Multiplication));
add(new ReplaceArithmeticElement(11, ReplaceArithmeticType.Division));
}
};
public ArrayList<ReplaceArithmeticElement> replaceArithmeticElements = new ArrayList<ReplaceArithmeticElement>() {
private static final long serialVersionUID = 7803379977670393398L;
{
add(new ReplaceArithmeticElement(1, ReplaceArithmeticType.Value));
add(new ReplaceArithmeticElement(2, ReplaceArithmeticType.ColumnValue));
add(new ReplaceArithmeticElement(3, ReplaceArithmeticType.SubstringByRegex));
add(new ReplaceArithmeticElement(4, ReplaceArithmeticType.SubstringByIndex));
add(new ReplaceArithmeticElement(5, ReplaceArithmeticType.SubstringByCharSeq));
add(new ReplaceArithmeticElement(6, ReplaceArithmeticType.TextReplaceMatchingRegex));
}
};
}

View File

@ -1,9 +1,10 @@
package org.gcube.portlets.user.td.expressionwidget.shared.model; package org.gcube.portlets.user.td.expressionwidget.shared.condition;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.gcube.portlets.user.td.expressionwidget.shared.exception.OperatorTypeMapException; import org.gcube.portlets.user.td.expressionwidget.shared.exception.ConditionTypeMapException;
import org.gcube.portlets.user.td.expressionwidget.shared.model.C_OperatorType;
import org.gcube.portlets.user.td.expressionwidget.shared.model.composite.comparable.C_Equals; import org.gcube.portlets.user.td.expressionwidget.shared.model.composite.comparable.C_Equals;
import org.gcube.portlets.user.td.expressionwidget.shared.model.composite.comparable.C_GreaterOrEquals; import org.gcube.portlets.user.td.expressionwidget.shared.model.composite.comparable.C_GreaterOrEquals;
import org.gcube.portlets.user.td.expressionwidget.shared.model.composite.comparable.C_GreaterThan; import org.gcube.portlets.user.td.expressionwidget.shared.model.composite.comparable.C_GreaterThan;
@ -36,22 +37,22 @@ import org.gcube.portlets.user.td.widgetcommonevent.shared.tr.column.ColumnTypeM
import com.allen_sauer.gwt.log.client.Log; import com.allen_sauer.gwt.log.client.Log;
/** /**
* OperatorTypeMap creates a C_Expression usable client-side * ConditionTypeMap creates a C_Expression usable client-side
* *
* @author "Giancarlo Panichi" <a * @author "Giancarlo Panichi" <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a> * href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
* *
*/ */
public class OperatorTypeMap { public class ConditionTypeMap {
private String readableExpression; private String readableExpression;
public OperatorTypeMap() { public ConditionTypeMap() {
} }
public C_Expression map(ColumnData column, C_OperatorType operatorType, public C_Expression map(ColumnData column, C_OperatorType operatorType,
String firstArg, String secondArg) throws OperatorTypeMapException { String firstArg, String secondArg) throws ConditionTypeMapException {
Log.debug("OperatorTypeMap Map"); Log.debug("ConditionTypeMap Map");
C_Expression exp = null; C_Expression exp = null;
readableExpression = new String(); readableExpression = new String();
if (column.getTrId() == null) { if (column.getTrId() == null) {
@ -65,8 +66,8 @@ public class OperatorTypeMap {
public C_Expression mapPlaceHolder(ColumnData column, public C_Expression mapPlaceHolder(ColumnData column,
C_OperatorType operatorType, String firstArg, String secondArg) C_OperatorType operatorType, String firstArg, String secondArg)
throws OperatorTypeMapException { throws ConditionTypeMapException {
Log.debug("OperatorTypeMap Map Place Holder"); Log.debug("ConditionTypeMap Map Place Holder");
C_Expression exp = null; C_Expression exp = null;
Log.debug("Column Data Type Name:" + column.getDataTypeName()); Log.debug("Column Data Type Name:" + column.getDataTypeName());
ColumnDataType dataType = ColumnTypeMap.getColumnDataType(column ColumnDataType dataType = ColumnTypeMap.getColumnDataType(column
@ -336,8 +337,8 @@ public class OperatorTypeMap {
public C_Expression mapTypedColumnReference(ColumnData column, public C_Expression mapTypedColumnReference(ColumnData column,
C_OperatorType operatorType, String firstArg, String secondArg) C_OperatorType operatorType, String firstArg, String secondArg)
throws OperatorTypeMapException { throws ConditionTypeMapException {
Log.debug("OperatorTypeMap Map Typed Column Reference"); Log.debug("ConditionTypeMap Map Typed Column Reference");
C_Expression exp = null; C_Expression exp = null;
Log.debug("Column Data Type Name:" + column.getDataTypeName()); Log.debug("Column Data Type Name:" + column.getDataTypeName());
@ -626,7 +627,7 @@ public class OperatorTypeMap {
} }
protected void checkTypeArgument(ColumnData column, String arg) protected void checkTypeArgument(ColumnData column, String arg)
throws OperatorTypeMapException { throws ConditionTypeMapException {
if (column.getDataTypeName().compareTo(ColumnDataType.Text.toString()) == 0) { if (column.getDataTypeName().compareTo(ColumnDataType.Text.toString()) == 0) {
if (arg == null) { if (arg == null) {
arg = ""; arg = "";
@ -635,7 +636,7 @@ public class OperatorTypeMap {
if (column.getDataTypeName().compareTo( if (column.getDataTypeName().compareTo(
ColumnDataType.Boolean.toString()) == 0) { ColumnDataType.Boolean.toString()) == 0) {
if(arg==null){ if(arg==null){
throw new OperatorTypeMapException( throw new ConditionTypeMapException(
"Insert a valid Boolean(ex: true, false)!"); "Insert a valid Boolean(ex: true, false)!");
} }
} else { } else {
@ -650,27 +651,27 @@ public class OperatorTypeMap {
if (column.getDataTypeName().compareTo( if (column.getDataTypeName().compareTo(
ColumnDataType.Integer.toString()) == 0) { ColumnDataType.Integer.toString()) == 0) {
if(arg==null){ if(arg==null){
throw new OperatorTypeMapException( throw new ConditionTypeMapException(
"Insert a valid Integer(ex: -1, 0, 1, 2)!"); "Insert a valid Integer(ex: -1, 0, 1, 2)!");
} }
try { try {
Integer.parseInt(arg); Integer.parseInt(arg);
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
throw new OperatorTypeMapException(arg throw new ConditionTypeMapException(arg
+ " is not valid Integer(ex: -1, 0, 1, 2)!"); + " is not valid Integer(ex: -1, 0, 1, 2)!");
} }
} else { } else {
if (column.getDataTypeName().compareTo( if (column.getDataTypeName().compareTo(
ColumnDataType.Numeric.toString()) == 0) { ColumnDataType.Numeric.toString()) == 0) {
if(arg==null){ if(arg==null){
throw new OperatorTypeMapException( throw new ConditionTypeMapException(
"Insert a valid Numeric(ex: -1.2, 0, 1, 2.4)!"); "Insert a valid Numeric(ex: -1.2, 0, 1, 2.4)!");
} }
try { try {
Float.parseFloat(arg); Float.parseFloat(arg);
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
throw new OperatorTypeMapException(arg throw new ConditionTypeMapException(arg
+ " is not valid Numeric(ex: -1.2, 0, 1, 2.4)!"); + " is not valid Numeric(ex: -1.2, 0, 1, 2.4)!");
} }
} else { } else {

View File

@ -6,26 +6,26 @@ package org.gcube.portlets.user.td.expressionwidget.shared.exception;
* email: <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a> * email: <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
* *
*/ */
public class OperatorTypeMapException extends Exception { public class ConditionTypeMapException extends Exception {
private static final long serialVersionUID = -9066034060104406559L; private static final long serialVersionUID = -9066034060104406559L;
/** /**
* *
*/ */
public OperatorTypeMapException() { public ConditionTypeMapException() {
super(); super();
} }
/** /**
* @param message * @param message
*/ */
public OperatorTypeMapException(String message) { public ConditionTypeMapException(String message) {
super(message); super(message);
} }
public OperatorTypeMapException(String message,Throwable t) { public ConditionTypeMapException(String message,Throwable t) {
super(message,t); super(message,t);
} }

View File

@ -18,7 +18,7 @@ public class C_ArithmeticExpression extends C_Expression {
private String id="ArithmeticExpression"; private String id="ArithmeticExpression";
protected static final ArrayList<ColumnDataType> ACCEPTED_DATA_TYPES=new ArrayList<ColumnDataType>(); public static final ArrayList<ColumnDataType> acceptedDataTypes=new ArrayList<ColumnDataType>();
protected C_Expression leftArgument; protected C_Expression leftArgument;
protected C_Expression rightArgument; protected C_Expression rightArgument;
@ -34,10 +34,10 @@ public class C_ArithmeticExpression extends C_Expression {
static { static {
ACCEPTED_DATA_TYPES.add(ColumnDataType.Numeric); acceptedDataTypes.add(ColumnDataType.Numeric);
ACCEPTED_DATA_TYPES.add(ColumnDataType.Integer); acceptedDataTypes.add(ColumnDataType.Integer);
ACCEPTED_DATA_TYPES.add(ColumnDataType.Date); acceptedDataTypes.add(ColumnDataType.Date);
ACCEPTED_DATA_TYPES.add(ColumnDataType.Geometry); acceptedDataTypes.add(ColumnDataType.Geometry);
} }
@ -46,11 +46,11 @@ public class C_ArithmeticExpression extends C_Expression {
} }
public ArrayList<ColumnDataType> allowedLeftDataTypes() { public ArrayList<ColumnDataType> allowedLeftDataTypes() {
return ACCEPTED_DATA_TYPES; return acceptedDataTypes;
} }
public ArrayList<ColumnDataType> allowedRightDataTypes() { public ArrayList<ColumnDataType> allowedRightDataTypes() {
return ACCEPTED_DATA_TYPES; return acceptedDataTypes;
} }

View File

@ -0,0 +1,36 @@
package org.gcube.portlets.user.td.expressionwidget.shared.replace;
/**
*
* @author giancarlo
* email: <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public enum ReplaceArithmeticType {
Value("Value"),
ColumnValue("Column Value"),
SubstringByRegex("Substring by Regex"),
SubstringByIndex("Substring by Index"),
SubstringByCharSeq("Substring by Char Seq."),
TextReplaceMatchingRegex("Replace Matching Regex"),
Addition("Addition"),
Subtraction("Substring by Index"),
Modulus("Substring by Char Seq."),
Multiplication("Replace Matching Regex"),
Division("Replace Matching Regex");
/**
* @param text
*/
private ReplaceArithmeticType(final String id) {
this.id = id;
}
private final String id;
@Override
public String toString() {
return id;
}
}

View File

@ -0,0 +1,536 @@
package org.gcube.portlets.user.td.expressionwidget.shared.replace;
import org.gcube.portlets.user.td.expressionwidget.shared.exception.ReplaceTypeMapException;
import org.gcube.portlets.user.td.expressionwidget.shared.model.composite.arithmetic.C_Addition;
import org.gcube.portlets.user.td.expressionwidget.shared.model.composite.arithmetic.C_ArithmeticExpression;
import org.gcube.portlets.user.td.expressionwidget.shared.model.composite.arithmetic.C_Division;
import org.gcube.portlets.user.td.expressionwidget.shared.model.composite.arithmetic.C_Modulus;
import org.gcube.portlets.user.td.expressionwidget.shared.model.composite.arithmetic.C_Multiplication;
import org.gcube.portlets.user.td.expressionwidget.shared.model.composite.arithmetic.C_Subtraction;
import org.gcube.portlets.user.td.expressionwidget.shared.model.composite.functions.C_Cast;
import org.gcube.portlets.user.td.expressionwidget.shared.model.composite.text.C_SubstringByIndex;
import org.gcube.portlets.user.td.expressionwidget.shared.model.composite.text.C_SubstringByRegex;
import org.gcube.portlets.user.td.expressionwidget.shared.model.composite.text.C_SubstringPosition;
import org.gcube.portlets.user.td.expressionwidget.shared.model.composite.text.C_TextReplaceMatchingRegex;
import org.gcube.portlets.user.td.expressionwidget.shared.model.leaf.C_ColumnReference;
import org.gcube.portlets.user.td.expressionwidget.shared.model.leaf.C_ColumnReferencePlaceholder;
import org.gcube.portlets.user.td.expressionwidget.shared.model.leaf.TD_Value;
import org.gcube.portlets.user.td.gwtservice.shared.tr.ColumnData;
import org.gcube.portlets.user.td.widgetcommonevent.shared.expression.C_Expression;
import org.gcube.portlets.user.td.widgetcommonevent.shared.tr.column.ColumnDataType;
import org.gcube.portlets.user.td.widgetcommonevent.shared.tr.column.ColumnTypeMap;
import com.allen_sauer.gwt.log.client.Log;
/**
* ReplaceArithmeticTypeMap creates a C_Expression usable client-side
*
* @author "Giancarlo Panichi" <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class ReplaceArithmeticTypeMap {
private String readableExpression;
public ReplaceArithmeticTypeMap() {
}
public C_Expression map(ColumnData column,
ColumnDataType targetColumnDataType,
ReplaceArithmeticType replaceType, String firstArg,
String secondArg, boolean template) throws ReplaceTypeMapException {
return map(column, targetColumnDataType, replaceType, firstArg,
secondArg, template, null, null, null, null);
}
public C_Expression map(ColumnData column,
ColumnDataType targetColumnDataType,
ReplaceArithmeticType replaceType, String firstArg,
String secondArg, boolean template, C_Expression firstE,
C_Expression secondE, String readableFirstE, String readableSecondE)
throws ReplaceTypeMapException {
Log.debug("ReplaceArithmeticTypeMap Map");
C_Expression exp = null;
readableExpression = new String();
if (template) {
exp = mapPlaceHolder(column, targetColumnDataType, replaceType,
firstArg, secondArg, firstE, secondE, readableFirstE,
readableSecondE);
} else {
exp = mapColumnReference(column, targetColumnDataType, replaceType,
firstArg, secondArg, firstE, secondE, readableFirstE,
readableSecondE);
}
return exp;
}
public C_Expression mapPlaceHolder(ColumnData column,
ColumnDataType targetColumnDataType,
ReplaceArithmeticType replaceType, String firstArg,
String secondArg, C_Expression firstE, C_Expression secondE,
String readableFirstE, String readableSecondE)
throws ReplaceTypeMapException {
Log.debug("ReplaceArithmeticTypeMap Map Place Holder");
C_Expression exp = null;
if (column == null) {
switch (replaceType) {
case Value:
checkArithmeticTypeArgument(targetColumnDataType, firstArg);
exp = new TD_Value(targetColumnDataType, firstArg);
readableExpression = "Value(" + firstArg + ")";
break;
case Addition:
exp = new C_Addition(firstE, secondE);
readableExpression = "Addition(" + readableFirstE + ", "
+ readableSecondE + ")";
break;
case Subtraction:
exp = new C_Subtraction(firstE, secondE);
readableExpression = "Subtraction(" + readableFirstE + ", "
+ readableSecondE + ")";
break;
case Modulus:
exp = new C_Modulus(firstE, secondE);
readableExpression = "Modulus(" + readableFirstE + ", "
+ readableSecondE + ")";
break;
case Multiplication:
exp = new C_Multiplication(firstE, secondE);
readableExpression = "Multiplication(" + readableFirstE + ", "
+ readableSecondE + ")";
break;
case Division:
exp = new C_Division(firstE, secondE);
readableExpression = "Division(" + readableFirstE + ", "
+ readableSecondE + ")";
break;
default:
throw new ReplaceTypeMapException("No valid column selected");
}
return exp;
}
Log.debug("Column Data Type Name:" + column.getDataTypeName());
ColumnDataType dataType = ColumnTypeMap.getColumnDataType(column
.getDataTypeName());
Log.debug("Data Type:" + dataType);
C_ColumnReferencePlaceholder placeH = new C_ColumnReferencePlaceholder(
dataType, column.getColumnId());
C_Expression placeHolder;
String readablePlaceHolder;
if (dataType != targetColumnDataType) {
placeHolder = new C_Cast(placeH, targetColumnDataType);
readablePlaceHolder = "Cast(" + column.getColumnId() + ","
+ targetColumnDataType + ")";
} else {
placeHolder = placeH;
readablePlaceHolder = column.getColumnId();
}
C_Expression placeHolderForStringExp;
String readablePlaceHolderForStringExp;
if (dataType != ColumnDataType.Text) {
placeHolderForStringExp = new C_Cast(placeH, ColumnDataType.Text);
readablePlaceHolderForStringExp = "Cast(" + column.getColumnId()
+ "," + ColumnDataType.Text + ")";
} else {
placeHolderForStringExp = placeH;
readablePlaceHolderForStringExp = column.getColumnId();
}
Log.debug("placeHolder:" + placeHolder);
TD_Value fArg, sArg;
C_Expression posFrom, posTo;
switch (replaceType) {
case Value:
checkArithmeticTypeArgument(targetColumnDataType, firstArg);
exp = new TD_Value(targetColumnDataType, firstArg);
readableExpression = "Value(" + firstArg + ")";
break;
case ColumnValue:
exp = placeHolder;
readableExpression = "ColumnValue(" + readablePlaceHolder + ")";
break;
case Addition:
exp = new C_Addition(firstE, secondE);
readableExpression = "Addition(" + readableFirstE + ", "
+ readableSecondE + ")";
break;
case Subtraction:
exp = new C_Subtraction(firstE, secondE);
readableExpression = "Subtraction(" + readableFirstE + ", "
+ readableSecondE + ")";
break;
case Modulus:
exp = new C_Modulus(firstE, secondE);
readableExpression = "Modulus(" + readableFirstE + ", "
+ readableSecondE + ")";
break;
case Multiplication:
exp = new C_Multiplication(firstE, secondE);
readableExpression = "Multiplication(" + readableFirstE + ", "
+ readableSecondE + ")";
break;
case Division:
exp = new C_Division(firstE, secondE);
readableExpression = "Division(" + readableFirstE + ", "
+ readableSecondE + ")";
break;
case SubstringByRegex:
checkTypeArgument(ColumnDataType.Text, firstArg);
fArg = new TD_Value(ColumnDataType.Text, firstArg);
C_SubstringByRegex substringByRegex = new C_SubstringByRegex(
placeHolderForStringExp, fArg);
exp = new C_Cast(substringByRegex, targetColumnDataType);
readableExpression = "Cast(SubstringByRegex("
+ readablePlaceHolderForStringExp + ", " + firstArg + "),"
+ targetColumnDataType + ")";
break;
case SubstringByIndex:
checkTypeArgument(ColumnDataType.Integer, firstArg);
checkTypeArgument(ColumnDataType.Integer, secondArg);
fArg = new TD_Value(ColumnDataType.Integer, firstArg);
sArg = new TD_Value(ColumnDataType.Integer, secondArg);
C_SubstringByIndex substringByIndex = new C_SubstringByIndex(
placeHolderForStringExp, fArg, sArg);
exp = new C_Cast(substringByIndex, targetColumnDataType);
readableExpression = "Cast(SubstringByIndex("
+ readablePlaceHolderForStringExp + ", " + firstArg + ", "
+ secondArg + ")," + targetColumnDataType + ")";
break;
case SubstringByCharSeq:
checkTypeArgument(ColumnDataType.Text, firstArg);
fArg = new TD_Value(ColumnDataType.Text, firstArg);
posFrom = new C_SubstringPosition(placeHolderForStringExp, fArg);
checkTypeArgument(ColumnDataType.Text, secondArg);
sArg = new TD_Value(ColumnDataType.Text, secondArg);
posTo = new C_SubstringPosition(placeHolderForStringExp, fArg);
C_SubstringByIndex substringByCharSeq = new C_SubstringByIndex(
placeHolderForStringExp, posFrom, posTo);
exp = new C_Cast(substringByCharSeq, targetColumnDataType);
readableExpression = "Cast(SubstringByCharSeq("
+ readablePlaceHolderForStringExp + ", " + firstArg + ", "
+ secondArg + ")," + targetColumnDataType + ")";
break;
case TextReplaceMatchingRegex:
checkTypeArgument(ColumnDataType.Text, firstArg);
checkTypeArgument(ColumnDataType.Text, secondArg);
fArg = new TD_Value(ColumnDataType.Text, firstArg);
sArg = new TD_Value(ColumnDataType.Text, secondArg);
C_TextReplaceMatchingRegex textReplaceMatchingRegex = new C_TextReplaceMatchingRegex(
placeHolderForStringExp, fArg, sArg);
exp = new C_Cast(textReplaceMatchingRegex, targetColumnDataType);
readableExpression = "Cast(TextReplaceMatchingRegex("
+ readablePlaceHolderForStringExp + ", " + firstArg + ", "
+ secondArg + ")," + targetColumnDataType + ")";
break;
default:
break;
}
return exp;
}
public C_Expression mapColumnReference(ColumnData column,
ColumnDataType targetColumnDataType,
ReplaceArithmeticType replaceType, String firstArg,
String secondArg, C_Expression firstE, C_Expression secondE,
String readableFirstE, String readableSecondE)
throws ReplaceTypeMapException {
Log.debug("ReplaceArithmeticTypeMap Map Typed Column Reference");
C_Expression exp = null;
if (column == null) {
switch (replaceType) {
case Value:
checkArithmeticTypeArgument(targetColumnDataType, firstArg);
exp = new TD_Value(targetColumnDataType, firstArg);
readableExpression = "Value(" + firstArg + ")";
break;
case Addition:
exp = new C_Addition(firstE, secondE);
readableExpression = "Addition(" + readableFirstE + ", "
+ readableSecondE + ")";
break;
case Subtraction:
exp = new C_Subtraction(firstE, secondE);
readableExpression = "Subtraction(" + readableFirstE + ", "
+ readableSecondE + ")";
break;
case Modulus:
exp = new C_Modulus(firstE, secondE);
readableExpression = "Modulus(" + readableFirstE + ", "
+ readableSecondE + ")";
break;
case Multiplication:
exp = new C_Multiplication(firstE, secondE);
readableExpression = "Multiplication(" + readableFirstE + ", "
+ readableSecondE + ")";
break;
case Division:
exp = new C_Division(firstE, secondE);
readableExpression = "Division(" + readableFirstE + ", "
+ readableSecondE + ")";
break;
default:
throw new ReplaceTypeMapException("No valid column selected");
}
return exp;
}
Log.debug("Column Data Type Name:" + column.getDataTypeName());
ColumnDataType dataType = ColumnTypeMap.getColumnDataType(column
.getDataTypeName());
Log.debug("Data Type:" + dataType);
C_ColumnReference columnRef = new C_ColumnReference(column.getTrId(),
dataType, column.getColumnId());
C_Expression columnReference;
String readableColumnReference;
if (dataType != targetColumnDataType) {
columnReference = new C_Cast(columnRef, targetColumnDataType);
readableColumnReference = "Cast(" + column.getColumnId() + ","
+ targetColumnDataType + ")";
} else {
columnReference = columnRef;
readableColumnReference = column.getColumnId();
}
C_Expression columnReferenceForStringExp;
String readableColumnReferenceForStringExp;
if (dataType != ColumnDataType.Text) {
columnReferenceForStringExp = new C_Cast(columnRef,
ColumnDataType.Text);
readableColumnReferenceForStringExp = "Cast("
+ column.getColumnId() + "," + ColumnDataType.Text + ")";
} else {
columnReferenceForStringExp = columnRef;
readableColumnReferenceForStringExp = column.getColumnId();
}
Log.debug("Typed Column Reference:" + columnReference);
TD_Value fArg, sArg;
C_Expression posFrom, posTo;
switch (replaceType) {
case Value:
checkArithmeticTypeArgument(targetColumnDataType, firstArg);
exp = new TD_Value(targetColumnDataType, firstArg);
readableExpression = "Value(" + firstArg + ")";
break;
case ColumnValue:
exp = columnReference;
readableExpression = "ColumnValue(" + readableColumnReference + ")";
break;
case Addition:
exp = new C_Addition(firstE, secondE);
readableExpression = "Addition(" + readableFirstE + ", "
+ readableSecondE + ")";
break;
case Subtraction:
exp = new C_Subtraction(firstE, secondE);
readableExpression = "Subtraction(" + readableFirstE + ", "
+ readableSecondE + ")";
break;
case Modulus:
exp = new C_Modulus(firstE, secondE);
readableExpression = "Modulus(" + readableFirstE + ", "
+ readableSecondE + ")";
break;
case Multiplication:
exp = new C_Multiplication(firstE, secondE);
readableExpression = "Multiplication(" + readableFirstE + ", "
+ readableSecondE + ")";
break;
case Division:
exp = new C_Division(firstE, secondE);
readableExpression = "Division(" + readableFirstE + ", "
+ readableSecondE + ")";
break;
case SubstringByRegex:
checkTypeArgument(ColumnDataType.Text, firstArg);
fArg = new TD_Value(ColumnDataType.Text, firstArg);
C_SubstringByRegex substringByRegex = new C_SubstringByRegex(
columnReferenceForStringExp, fArg);
exp = new C_Cast(substringByRegex, targetColumnDataType);
readableExpression = "Cast(SubStringByRegex("
+ readableColumnReferenceForStringExp + ", " + firstArg
+ ")," + targetColumnDataType + ")";
break;
case SubstringByIndex:
checkTypeArgument(ColumnDataType.Integer, firstArg);
checkTypeArgument(ColumnDataType.Integer, secondArg);
fArg = new TD_Value(ColumnDataType.Integer, firstArg);
sArg = new TD_Value(ColumnDataType.Integer, secondArg);
C_SubstringByIndex substringByIndex = new C_SubstringByIndex(
columnReferenceForStringExp, fArg, sArg);
exp = new C_Cast(substringByIndex, targetColumnDataType);
readableExpression = "Cast(SubstringByIndex("
+ readableColumnReferenceForStringExp + ", " + firstArg
+ ", " + secondArg + ")," + targetColumnDataType + ")";
break;
case SubstringByCharSeq:
checkTypeArgument(ColumnDataType.Text, firstArg);
fArg = new TD_Value(ColumnDataType.Text, firstArg);
posFrom = new C_SubstringPosition(columnReferenceForStringExp, fArg);
checkTypeArgument(ColumnDataType.Text, secondArg);
sArg = new TD_Value(ColumnDataType.Text, secondArg);
posTo = new C_SubstringPosition(columnReferenceForStringExp, fArg);
C_SubstringByIndex substringByCharSeq = new C_SubstringByIndex(
columnReferenceForStringExp, posFrom, posTo);
exp = new C_Cast(substringByCharSeq, targetColumnDataType);
readableExpression = "Cast(SubstringByCharSeq("
+ readableColumnReferenceForStringExp + ", " + firstArg
+ ", " + secondArg + ")," + targetColumnDataType + ")";
break;
case TextReplaceMatchingRegex:
checkTypeArgument(ColumnDataType.Text, firstArg);
checkTypeArgument(ColumnDataType.Text, secondArg);
fArg = new TD_Value(ColumnDataType.Text, firstArg);
sArg = new TD_Value(ColumnDataType.Text, secondArg);
C_TextReplaceMatchingRegex textReplaceMatchingRegex = new C_TextReplaceMatchingRegex(
columnReferenceForStringExp, fArg, sArg);
exp = new C_Cast(textReplaceMatchingRegex, targetColumnDataType);
readableExpression = "Cast(TextReplaceMatchingRegex("
+ readableColumnReferenceForStringExp + ", " + firstArg
+ ", " + secondArg + ")," + targetColumnDataType + ")";
break;
default:
break;
}
return exp;
}
public String getReadableExpression() {
return readableExpression;
}
protected void checkArithmeticTypeArgument(ColumnDataType columnDataType,
String arg) throws ReplaceTypeMapException {
boolean accepted = false;
for (ColumnDataType acceptedColumnDataType : C_ArithmeticExpression.acceptedDataTypes) {
if (acceptedColumnDataType.compareTo(columnDataType) == 0) {
accepted = true;
break;
}
}
if (!accepted) {
throw new ReplaceTypeMapException("Attention, " + columnDataType
+ " is not a valid arithmetic type!");
}
if (columnDataType == ColumnDataType.Date) {
if (arg == null || arg.isEmpty()) {
throw new ReplaceTypeMapException(
"Insert a valid Date (ex: 2015-01-10)!");
}
} else {
if (columnDataType == ColumnDataType.Geometry) {
if (arg == null || arg.isEmpty()) {
throw new ReplaceTypeMapException(
"Insert a valid Geometry (ex: POINT(10 10))!");
}
} else {
if (columnDataType == ColumnDataType.Integer) {
if (arg == null) {
throw new ReplaceTypeMapException(
"Insert a valid Integer(ex: -1, 0, 1, 2)!");
}
try {
Integer.parseInt(arg);
} catch (NumberFormatException e) {
throw new ReplaceTypeMapException(arg
+ " is not valid Integer(ex: -1, 0, 1, 2)!");
}
} else {
if (columnDataType == ColumnDataType.Numeric) {
if (arg == null) {
throw new ReplaceTypeMapException(
"Insert a valid Numeric(ex: -1.2, 0, 1, 2.4)!");
}
try {
Float.parseFloat(arg);
} catch (NumberFormatException e) {
throw new ReplaceTypeMapException(
arg
+ " is not valid Numeric(ex: -1.2, 0, 1, 2.4)!");
}
} else {
}
}
}
}
}
protected void checkTypeArgument(ColumnDataType columnDataType, String arg)
throws ReplaceTypeMapException {
if (columnDataType == ColumnDataType.Text) {
if (arg == null) {
arg = "";
}
} else {
if (columnDataType == ColumnDataType.Boolean) {
if (arg == null) {
throw new ReplaceTypeMapException(
"Insert a valid Boolean(ex: true, false)!");
}
} else {
if (columnDataType == ColumnDataType.Date) {
} else {
if (columnDataType == ColumnDataType.Geometry) {
} else {
if (columnDataType == ColumnDataType.Integer) {
if (arg == null) {
throw new ReplaceTypeMapException(
"Insert a valid Integer(ex: -1, 0, 1, 2)!");
}
try {
Integer.parseInt(arg);
} catch (NumberFormatException e) {
throw new ReplaceTypeMapException(
arg
+ " is not valid Integer(ex: -1, 0, 1, 2)!");
}
} else {
if (columnDataType == ColumnDataType.Numeric) {
if (arg == null) {
throw new ReplaceTypeMapException(
"Insert a valid Numeric(ex: -1.2, 0, 1, 2.4)!");
}
try {
Float.parseFloat(arg);
} catch (NumberFormatException e) {
throw new ReplaceTypeMapException(
arg
+ " is not valid Numeric(ex: -1.2, 0, 1, 2.4)!");
}
} else {
}
}
}
}
}
}
}
}

View File

@ -1,5 +1,11 @@
package org.gcube.portlets.user.td.expressionwidget.shared.replace; package org.gcube.portlets.user.td.expressionwidget.shared.replace;
/**
*
* @author giancarlo
* email: <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public enum ReplaceType { public enum ReplaceType {
Null("Null"), Null("Null"),
Value("Value"), Value("Value"),

View File

@ -18,7 +18,7 @@ import org.gcube.portlets.user.td.widgetcommonevent.shared.tr.column.ColumnTypeM
import com.allen_sauer.gwt.log.client.Log; import com.allen_sauer.gwt.log.client.Log;
/** /**
* OperatorTypeMap creates a C_Expression usable client-side * ReplaceTypeMap creates a C_Expression usable client-side
* *
* @author "Giancarlo Panichi" <a * @author "Giancarlo Panichi" <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a> * href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
@ -55,7 +55,7 @@ public class ReplaceTypeMap {
public C_Expression mapPlaceHolder(ColumnData column, public C_Expression mapPlaceHolder(ColumnData column,
ReplaceType replaceType, String firstArg, String secondArg, ReplaceType replaceType, String firstArg, String secondArg,
C_Expression firstE, C_Expression secondE,String readableFirstE, String readableSecondE) throws ReplaceTypeMapException { C_Expression firstE, C_Expression secondE,String readableFirstE, String readableSecondE) throws ReplaceTypeMapException {
Log.debug("OperatorTypeMap Map Place Holder"); Log.debug("ReplaceTypeMap Map Place Holder");
C_Expression exp = null; C_Expression exp = null;
if(column==null){ if(column==null){
@ -166,7 +166,7 @@ public class ReplaceTypeMap {
public C_Expression mapColumnReference(ColumnData column, public C_Expression mapColumnReference(ColumnData column,
ReplaceType replaceType, String firstArg, String secondArg, ReplaceType replaceType, String firstArg, String secondArg,
C_Expression firstE, C_Expression secondE, String readableFirstE, String readableSecondE) throws ReplaceTypeMapException { C_Expression firstE, C_Expression secondE, String readableFirstE, String readableSecondE) throws ReplaceTypeMapException {
Log.debug("OperatorTypeMap Map Typed Column Reference"); Log.debug("ReplaceTypeMap Map Typed Column Reference");
C_Expression exp = null; C_Expression exp = null;
if(column==null){ if(column==null){