Updated type-checking for ConditionWidget
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-expression-widget@100299 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
11a6c4e54a
commit
2f52a3c34d
|
@ -1,7 +1,9 @@
|
|||
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.shared.exception.OperatorTypeMapException;
|
||||
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.widgetcommonevent.client.event.ExpressionEvent;
|
||||
import org.gcube.portlets.user.td.widgetcommonevent.client.type.ExpressionType;
|
||||
import org.gcube.portlets.user.td.widgetcommonevent.shared.expression.C_Expression;
|
||||
|
@ -322,10 +324,15 @@ public class ColumnExpressionPanel extends FramedPanel {
|
|||
}
|
||||
|
||||
protected void applyRule() {
|
||||
C_Expression exp = conditionWidget.getExpression();
|
||||
if(exp==null){
|
||||
C_Expression exp;
|
||||
try {
|
||||
exp = conditionWidget.getExpression();
|
||||
} catch (OperatorTypeMapException e) {
|
||||
Log.debug(e.getLocalizedMessage());
|
||||
UtilsGXT3.alert("Attention", e.getLocalizedMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
switch (type) {
|
||||
case ColumnRule:
|
||||
parentRuleDialog.setExpression(exp);
|
||||
|
|
|
@ -10,6 +10,7 @@ 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.OperationsStore;
|
||||
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.model.OperatorTypeMap;
|
||||
import org.gcube.portlets.user.td.gwtservice.shared.tr.ColumnData;
|
||||
import org.gcube.portlets.user.td.widgetcommonevent.shared.expression.C_Expression;
|
||||
|
@ -319,7 +320,6 @@ public class ConditionWidget extends SimpleContainer {
|
|||
protected void addCondition() {
|
||||
final HBoxLayoutContainer horiz = new HBoxLayoutContainer();
|
||||
|
||||
|
||||
final TextField firstArg = new TextField();
|
||||
firstArg.setItemId(itemIdFirstArg);
|
||||
firstArg.setVisible(false);
|
||||
|
@ -328,7 +328,6 @@ public class ConditionWidget extends SimpleContainer {
|
|||
firstArgDate.setItemId(itemIdFirstArgDate);
|
||||
firstArgDate.setVisible(false);
|
||||
|
||||
|
||||
final HTML andText = new HTML(
|
||||
"<div style='vertical-align:middle; margin-left:2px;margin-right:2px;margin-top:4px;'>and</div>");
|
||||
andText.setVisible(false);
|
||||
|
@ -490,7 +489,7 @@ public class ConditionWidget extends SimpleContainer {
|
|||
|
||||
}
|
||||
|
||||
public C_Expression getExpression() {
|
||||
public C_Expression getExpression() throws OperatorTypeMapException {
|
||||
C_Expression exp = null;
|
||||
readableExpression = new String();
|
||||
List<C_Expression> arguments = new ArrayList<C_Expression>();
|
||||
|
@ -500,9 +499,9 @@ public class ConditionWidget extends SimpleContainer {
|
|||
DateField firstArgDate;
|
||||
DateField secondArgDate;
|
||||
C_Expression expression;
|
||||
|
||||
|
||||
DateTimeFormat sdf = DateTimeFormat.getFormat("yyyy-MM-dd");
|
||||
|
||||
|
||||
OperatorTypeMap mapOp = new OperatorTypeMap();
|
||||
Iterator<Widget> iteratorVert = vert.iterator();
|
||||
HBoxLayoutContainer horiz;
|
||||
|
@ -513,27 +512,28 @@ public class ConditionWidget extends SimpleContainer {
|
|||
.getItemByItemId(itemIdCombo);
|
||||
Log.debug("combo: " + comboOp.getCurrentValue().toString());
|
||||
|
||||
if (column.getDataTypeName().compareTo(ColumnDataType.Date.toString()) == 0) {
|
||||
if (column.getDataTypeName().compareTo(
|
||||
ColumnDataType.Date.toString()) == 0) {
|
||||
firstArgDate = (DateField) horiz
|
||||
.getItemByItemId(itemIdFirstArgDate);
|
||||
secondArgDate = (DateField) horiz
|
||||
.getItemByItemId(itemIdSecondArgDate);
|
||||
Log.debug("argLeft: " + firstArgDate + " argRight:"
|
||||
+ secondArgDate);
|
||||
Date firstDate=firstArgDate.getCurrentValue();
|
||||
Date secondDate=secondArgDate.getCurrentValue();
|
||||
expression = mapOp.map(
|
||||
column,
|
||||
comboOp.getCurrentValue().getOperatorType(),
|
||||
+ secondArgDate);
|
||||
Date firstDate = firstArgDate.getCurrentValue();
|
||||
Date secondDate = secondArgDate.getCurrentValue();
|
||||
|
||||
expression = mapOp.map(column, comboOp.getCurrentValue()
|
||||
.getOperatorType(),
|
||||
firstDate == null ? null : sdf.format(firstDate),
|
||||
secondDate == null ? null : sdf.format(secondDate));
|
||||
} else {
|
||||
|
||||
firstArg = (TextField) horiz.getItemByItemId(itemIdFirstArg);
|
||||
secondArg = (TextField) horiz.getItemByItemId(itemIdSecondArg);
|
||||
Log.debug("argLeft: " + firstArg.getCurrentValue() + " argRight: " + secondArg.getCurrentValue());
|
||||
|
||||
|
||||
Log.debug("argLeft: " + firstArg.getCurrentValue()
|
||||
+ " argRight: " + secondArg.getCurrentValue());
|
||||
|
||||
expression = mapOp.map(column, comboOp.getCurrentValue()
|
||||
.getOperatorType(),
|
||||
firstArg == null ? null : firstArg.getCurrentValue(),
|
||||
|
@ -588,7 +588,6 @@ public class ConditionWidget extends SimpleContainer {
|
|||
return exp;
|
||||
}
|
||||
|
||||
|
||||
public String getReadableExpression() {
|
||||
return readableExpression;
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package org.gcube.portlets.user.td.expressionwidget.client;
|
|||
import java.util.Date;
|
||||
|
||||
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.model.leaf.TD_Value;
|
||||
import org.gcube.portlets.user.td.gwtservice.shared.tr.ColumnData;
|
||||
import org.gcube.portlets.user.td.monitorwidget.client.utils.UtilsGXT3;
|
||||
|
@ -281,7 +282,15 @@ public class ReplaceColumnByExpressionPanel extends FramedPanel {
|
|||
if (allRows) {
|
||||
cConditionExpression = new TD_Value(ColumnDataType.Boolean, "true");
|
||||
} else {
|
||||
cConditionExpression = conditionWidget.getExpression();
|
||||
|
||||
try {
|
||||
cConditionExpression = conditionWidget.getExpression();
|
||||
} catch (OperatorTypeMapException e) {
|
||||
Log.debug(e.getLocalizedMessage());
|
||||
UtilsGXT3.alert("Attention", e.getLocalizedMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
String value = null;
|
||||
if (column.getDataTypeName().compareTo(ColumnDataType.Date.toString()) == 0) {
|
||||
|
|
|
@ -14,6 +14,7 @@ import javax.servlet.http.HttpServletResponse;
|
|||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import org.gcube.data.analysis.tabulardata.expression.Expression;
|
||||
import org.gcube.portlets.user.td.expressionwidget.shared.exception.ExpressionParserException;
|
||||
import org.gcube.portlets.user.td.widgetcommonevent.shared.expression.C_Expression;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -71,7 +72,14 @@ public class CExpressionMapServlet extends HttpServlet {
|
|||
|
||||
}
|
||||
|
||||
Expression expression = parse(exp);
|
||||
Expression expression=null;
|
||||
try {
|
||||
expression = parse(exp);
|
||||
} catch (ExpressionParserException e) {
|
||||
logger.error(e.getLocalizedMessage());
|
||||
response.sendError(HttpServletResponse.SC_BAD_REQUEST,
|
||||
"ERROR-Error parsing expression: "+e.getLocalizedMessage());
|
||||
}
|
||||
logger.trace("Expression: " + expression.toString());
|
||||
|
||||
response.setContentType("Content-Type: application/java-object");
|
||||
|
@ -85,7 +93,7 @@ public class CExpressionMapServlet extends HttpServlet {
|
|||
logger.trace("Response in " + (System.currentTimeMillis() - startTime));
|
||||
}
|
||||
|
||||
protected Expression parse(C_Expression exp) {
|
||||
protected Expression parse(C_Expression exp) throws ExpressionParserException {
|
||||
C_ExpressionParser parser=new C_ExpressionParser();
|
||||
return parser.parse(exp);
|
||||
}
|
||||
|
|
|
@ -58,6 +58,7 @@ import org.gcube.data.analysis.tabulardata.model.datatype.value.TDNumeric;
|
|||
import org.gcube.data.analysis.tabulardata.model.datatype.value.TDText;
|
||||
import org.gcube.data.analysis.tabulardata.model.datatype.value.TDTypeValue;
|
||||
import org.gcube.data.analysis.tabulardata.model.table.TableId;
|
||||
import org.gcube.portlets.user.td.expressionwidget.shared.exception.ExpressionParserException;
|
||||
import org.gcube.portlets.user.td.expressionwidget.shared.expression.C_MultivaluedExpression;
|
||||
import org.gcube.portlets.user.td.expressionwidget.shared.model.composite.aggregation.C_Avg;
|
||||
import org.gcube.portlets.user.td.expressionwidget.shared.model.composite.aggregation.C_Count;
|
||||
|
@ -105,7 +106,7 @@ public class C_ExpressionParser {
|
|||
|
||||
protected SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||||
|
||||
public Expression parse(C_Expression exp) {
|
||||
public Expression parse(C_Expression exp) throws ExpressionParserException {
|
||||
logger.debug("Parse: " + exp);
|
||||
Expression ex = null;
|
||||
|
||||
|
@ -199,23 +200,23 @@ public class C_ExpressionParser {
|
|||
ex = getTextReplaceMatchingRegex(exp);
|
||||
break;
|
||||
case "Avg":
|
||||
ex = getAvg(exp);
|
||||
ex = getAvg(exp);
|
||||
break;
|
||||
case "Count":
|
||||
ex = getCount(exp);
|
||||
ex = getCount(exp);
|
||||
break;
|
||||
case "Max":
|
||||
ex = getMax(exp);
|
||||
break;
|
||||
ex = getMax(exp);
|
||||
break;
|
||||
case "Min":
|
||||
ex = getMin(exp);
|
||||
ex = getMin(exp);
|
||||
break;
|
||||
case "Sum":
|
||||
ex = getSum(exp);
|
||||
ex = getSum(exp);
|
||||
break;
|
||||
case "ST_Extent":
|
||||
ex = getSTExtent(exp);
|
||||
break;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -223,7 +224,7 @@ public class C_ExpressionParser {
|
|||
return ex;
|
||||
}
|
||||
|
||||
public MultivaluedExpression parseMultivalued(C_MultivaluedExpression exp) {
|
||||
public MultivaluedExpression parseMultivalued(C_MultivaluedExpression exp) throws ExpressionParserException {
|
||||
MultivaluedExpression ex = null;
|
||||
switch (exp.getIdMulti()) {
|
||||
case "ConstantList":
|
||||
|
@ -240,7 +241,7 @@ public class C_ExpressionParser {
|
|||
return ex;
|
||||
}
|
||||
|
||||
private Expression getValueIsIn(C_Expression exp) {
|
||||
private Expression getValueIsIn(C_Expression exp) throws ExpressionParserException {
|
||||
C_ValueIsIn v = (C_ValueIsIn) exp;
|
||||
MultivaluedExpression multivalued = parseMultivalued(v
|
||||
.getRightArgument());
|
||||
|
@ -249,7 +250,7 @@ public class C_ExpressionParser {
|
|||
return valueIsIn;
|
||||
}
|
||||
|
||||
private Expression getOr(C_Expression exp) {
|
||||
private Expression getOr(C_Expression exp) throws ExpressionParserException {
|
||||
C_Or o = (C_Or) exp;
|
||||
List<C_Expression> listCExp = o.getArguments();
|
||||
List<Expression> listExp = new ArrayList<Expression>();
|
||||
|
@ -262,25 +263,25 @@ public class C_ExpressionParser {
|
|||
return or;
|
||||
}
|
||||
|
||||
private Expression getNot(C_Expression exp) {
|
||||
private Expression getNot(C_Expression exp) throws ExpressionParserException {
|
||||
C_Not n = (C_Not) exp;
|
||||
Not not = new Not(parse(n.getArgument()));
|
||||
return not;
|
||||
}
|
||||
|
||||
private Expression getIsNull(C_Expression exp) {
|
||||
private Expression getIsNull(C_Expression exp) throws ExpressionParserException {
|
||||
C_IsNull nullIs = (C_IsNull) exp;
|
||||
IsNull isNull = new IsNull(parse(nullIs.getArgument()));
|
||||
return isNull;
|
||||
}
|
||||
|
||||
private Expression getIsNotNull(C_Expression exp) {
|
||||
private Expression getIsNotNull(C_Expression exp) throws ExpressionParserException {
|
||||
C_IsNotNull nullNotIs = (C_IsNotNull) exp;
|
||||
IsNotNull isNotNull = new IsNotNull(parse(nullNotIs.getArgument()));
|
||||
return isNotNull;
|
||||
}
|
||||
|
||||
private Expression getBetween(C_Expression exp) {
|
||||
private Expression getBetween(C_Expression exp) throws ExpressionParserException {
|
||||
C_Between bet = (C_Between) exp;
|
||||
C_Range crange = bet.getRightArgument();
|
||||
Range range = new Range(getExpressionValue(crange.getMinimum()),
|
||||
|
@ -290,7 +291,7 @@ public class C_ExpressionParser {
|
|||
return between;
|
||||
}
|
||||
|
||||
private Expression getAnd(C_Expression exp) {
|
||||
private Expression getAnd(C_Expression exp) throws ExpressionParserException {
|
||||
C_And o = (C_And) exp;
|
||||
List<C_Expression> listCExp = o.getArguments();
|
||||
List<Expression> listExp = new ArrayList<Expression>();
|
||||
|
@ -303,7 +304,7 @@ public class C_ExpressionParser {
|
|||
return and;
|
||||
}
|
||||
|
||||
private Expression getTextMatchSQLRegexp(C_Expression exp) {
|
||||
private Expression getTextMatchSQLRegexp(C_Expression exp) throws ExpressionParserException {
|
||||
C_TextMatchSQLRegexp reg = (C_TextMatchSQLRegexp) exp;
|
||||
TextMatchSQLRegexp regExp = new TextMatchSQLRegexp(
|
||||
parse(reg.getLeftArgument()), parse(reg.getRightArgument()));
|
||||
|
@ -311,7 +312,7 @@ public class C_ExpressionParser {
|
|||
|
||||
}
|
||||
|
||||
private Expression getTextEndWith(C_Expression exp) {
|
||||
private Expression getTextEndWith(C_Expression exp) throws ExpressionParserException {
|
||||
C_TextEndsWith textEnd = (C_TextEndsWith) exp;
|
||||
TextEndsWith textEndWith = new TextEndsWith(
|
||||
parse(textEnd.getLeftArgument()),
|
||||
|
@ -319,7 +320,7 @@ public class C_ExpressionParser {
|
|||
return textEndWith;
|
||||
}
|
||||
|
||||
private Expression getTextContains(C_Expression exp) {
|
||||
private Expression getTextContains(C_Expression exp) throws ExpressionParserException {
|
||||
C_TextContains textContains = (C_TextContains) exp;
|
||||
TextContains textCont = new TextContains(
|
||||
parse(textContains.getLeftArgument()),
|
||||
|
@ -327,42 +328,42 @@ public class C_ExpressionParser {
|
|||
return textCont;
|
||||
}
|
||||
|
||||
private Expression getTextBeginWith(C_Expression exp) {
|
||||
private Expression getTextBeginWith(C_Expression exp) throws ExpressionParserException {
|
||||
C_TextBeginsWith textB = (C_TextBeginsWith) exp;
|
||||
TextBeginsWith textBegins = new TextBeginsWith(
|
||||
parse(textB.getLeftArgument()), parse(textB.getRightArgument()));
|
||||
return textBegins;
|
||||
}
|
||||
|
||||
private Expression getNotLess(C_Expression exp) {
|
||||
private Expression getNotLess(C_Expression exp) throws ExpressionParserException {
|
||||
C_NotLess notL = (C_NotLess) exp;
|
||||
NotLess notLess = new NotLess(parse(notL.getLeftArgument()),
|
||||
parse(notL.getRightArgument()));
|
||||
return notLess;
|
||||
}
|
||||
|
||||
private Expression getNotGreater(C_Expression exp) {
|
||||
private Expression getNotGreater(C_Expression exp) throws ExpressionParserException {
|
||||
C_NotGreater notG = (C_NotGreater) exp;
|
||||
NotGreater notGreater = new NotGreater(parse(notG.getLeftArgument()),
|
||||
parse(notG.getRightArgument()));
|
||||
return notGreater;
|
||||
}
|
||||
|
||||
private Expression getNotEquals(C_Expression exp) {
|
||||
private Expression getNotEquals(C_Expression exp) throws ExpressionParserException {
|
||||
C_NotEquals notE = (C_NotEquals) exp;
|
||||
NotEquals notEquals = new NotEquals(parse(notE.getLeftArgument()),
|
||||
parse(notE.getRightArgument()));
|
||||
return notEquals;
|
||||
}
|
||||
|
||||
private Expression getLessThan(C_Expression exp) {
|
||||
private Expression getLessThan(C_Expression exp) throws ExpressionParserException {
|
||||
C_LessThan lessT = (C_LessThan) exp;
|
||||
LessThan lessThan = new LessThan(parse(lessT.getLeftArgument()),
|
||||
parse(lessT.getRightArgument()));
|
||||
return lessThan;
|
||||
}
|
||||
|
||||
private Expression getLessOrEquals(C_Expression exp) {
|
||||
private Expression getLessOrEquals(C_Expression exp)throws ExpressionParserException{
|
||||
C_LessOrEquals lessOrE = (C_LessOrEquals) exp;
|
||||
LessOrEquals lessOrEquals = new LessOrEquals(
|
||||
parse(lessOrE.getLeftArgument()),
|
||||
|
@ -370,7 +371,7 @@ public class C_ExpressionParser {
|
|||
return lessOrEquals;
|
||||
}
|
||||
|
||||
private Expression getGreaterThan(C_Expression exp) {
|
||||
private Expression getGreaterThan(C_Expression exp) throws ExpressionParserException{
|
||||
C_GreaterThan greaterThan = (C_GreaterThan) exp;
|
||||
GreaterThan greater = new GreaterThan(
|
||||
parse(greaterThan.getLeftArgument()),
|
||||
|
@ -379,7 +380,7 @@ public class C_ExpressionParser {
|
|||
|
||||
}
|
||||
|
||||
private Expression getGreaterOrEquals(C_Expression exp) {
|
||||
private Expression getGreaterOrEquals(C_Expression exp) throws ExpressionParserException{
|
||||
C_GreaterOrEquals greaterOrEq = (C_GreaterOrEquals) exp;
|
||||
GreaterOrEquals greaterOrEquals = new GreaterOrEquals(
|
||||
parse(greaterOrEq.getLeftArgument()),
|
||||
|
@ -388,7 +389,8 @@ public class C_ExpressionParser {
|
|||
|
||||
}
|
||||
|
||||
protected TDTypeValue getExpressionValue(TD_Value value) {
|
||||
protected TDTypeValue getExpressionValue(TD_Value value)
|
||||
throws ExpressionParserException {
|
||||
|
||||
TDTypeValue ex = null;
|
||||
try {
|
||||
|
@ -402,7 +404,8 @@ public class C_ExpressionParser {
|
|||
d = sdf.parse(value.getValue());
|
||||
} catch (ParseException e) {
|
||||
logger.error("Unparseable using " + sdf);
|
||||
return null;
|
||||
throw new ExpressionParserException(value.getValue()
|
||||
+ " is not valid Date type");
|
||||
}
|
||||
ex = new TDDate(d);
|
||||
break;
|
||||
|
@ -410,23 +413,43 @@ public class C_ExpressionParser {
|
|||
if (TDGeometry.validateGeometry(value.getValue())) {
|
||||
ex = new TDGeometry(value.getValue());
|
||||
} else {
|
||||
ex = null;
|
||||
throw new ExpressionParserException(value.getValue()
|
||||
+ " is not valid Geometry type");
|
||||
}
|
||||
break;
|
||||
case Integer:
|
||||
ex = new TDInteger(Integer.valueOf(value.getValue()));
|
||||
Integer vInteger;
|
||||
try {
|
||||
vInteger = Integer.valueOf(value.getValue());
|
||||
} catch (NumberFormatException e) {
|
||||
throw new ExpressionParserException(value.getValue()
|
||||
+ " is not valid Integer type");
|
||||
}
|
||||
ex = new TDInteger(vInteger);
|
||||
break;
|
||||
case Numeric:
|
||||
ex = new TDNumeric(Float.valueOf(value.getValue()));
|
||||
Float vNumeric;
|
||||
try {
|
||||
vNumeric = Float.valueOf(value.getValue());
|
||||
} catch (NumberFormatException e) {
|
||||
throw new ExpressionParserException(value.getValue()
|
||||
+ " is not valid Float type");
|
||||
}
|
||||
ex = new TDNumeric(vNumeric);
|
||||
break;
|
||||
case Text:
|
||||
ex = new TDText(value.getValue());
|
||||
if (value.getValue() == null) {
|
||||
ex = new TDText("");
|
||||
} else {
|
||||
ex = new TDText(value.getValue());
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
logger.error("type error parsing value " + value+" "+ e.getLocalizedMessage());
|
||||
logger.error("type error parsing value " + value + " "
|
||||
+ e.getLocalizedMessage());
|
||||
}
|
||||
return ex;
|
||||
}
|
||||
|
@ -459,7 +482,7 @@ public class C_ExpressionParser {
|
|||
}
|
||||
}
|
||||
|
||||
protected Expression getConstantlist(C_Expression exp) {
|
||||
protected Expression getConstantlist(C_Expression exp) throws ExpressionParserException {
|
||||
List<TDTypeValue> l = new ArrayList<TDTypeValue>();
|
||||
C_ConstantList c = (C_ConstantList) exp;
|
||||
List<TD_Value> arguments = c.getArguments();
|
||||
|
@ -472,7 +495,7 @@ public class C_ExpressionParser {
|
|||
return constList;
|
||||
}
|
||||
|
||||
protected MultivaluedExpression getConstantlist(C_MultivaluedExpression exp) {
|
||||
protected MultivaluedExpression getConstantlist(C_MultivaluedExpression exp) throws ExpressionParserException {
|
||||
List<TDTypeValue> l = new ArrayList<TDTypeValue>();
|
||||
C_ConstantList c = (C_ConstantList) exp;
|
||||
List<TD_Value> arguments = c.getArguments();
|
||||
|
@ -492,14 +515,14 @@ public class C_ExpressionParser {
|
|||
return col;
|
||||
}
|
||||
|
||||
protected Expression getRange(C_Expression exp) {
|
||||
protected Expression getRange(C_Expression exp) throws ExpressionParserException {
|
||||
C_Range c = (C_Range) exp;
|
||||
Range range = new Range(getExpressionValue(c.getMinimum()),
|
||||
getExpressionValue(c.getMaximum()));
|
||||
return range;
|
||||
}
|
||||
|
||||
protected MultivaluedExpression getRange(C_MultivaluedExpression exp) {
|
||||
protected MultivaluedExpression getRange(C_MultivaluedExpression exp) throws ExpressionParserException {
|
||||
C_Range c = (C_Range) exp;
|
||||
Range range = new Range(getExpressionValue(c.getMinimum()),
|
||||
getExpressionValue(c.getMaximum()));
|
||||
|
@ -522,7 +545,7 @@ public class C_ExpressionParser {
|
|||
return ref;
|
||||
}
|
||||
|
||||
protected Expression getEquals(C_Expression exp) {
|
||||
protected Expression getEquals(C_Expression exp) throws ExpressionParserException {
|
||||
C_Equals e = (C_Equals) exp;
|
||||
Expression left = parse(e.getLeftArgument());
|
||||
Expression right = parse(e.getRightArgument());
|
||||
|
@ -530,14 +553,14 @@ public class C_ExpressionParser {
|
|||
return eq;
|
||||
}
|
||||
|
||||
private Expression getConcat(C_Expression exp) {
|
||||
private Expression getConcat(C_Expression exp) throws ExpressionParserException {
|
||||
C_Concat concat = (C_Concat) exp;
|
||||
Concat conc = new Concat(parse(concat.getLeftArgument()),
|
||||
parse(concat.getRightArgument()));
|
||||
return conc;
|
||||
}
|
||||
|
||||
private Expression getSubstringByIndex(C_Expression exp) {
|
||||
private Expression getSubstringByIndex(C_Expression exp) throws ExpressionParserException {
|
||||
C_SubstringByIndex subByIndex = (C_SubstringByIndex) exp;
|
||||
SubstringByIndex sByIndex = new SubstringByIndex(
|
||||
parse(subByIndex.getSourceString()),
|
||||
|
@ -546,7 +569,7 @@ public class C_ExpressionParser {
|
|||
return sByIndex;
|
||||
}
|
||||
|
||||
private Expression getSubstringByRegex(C_Expression exp) {
|
||||
private Expression getSubstringByRegex(C_Expression exp) throws ExpressionParserException {
|
||||
C_SubstringByRegex subByRegex = (C_SubstringByRegex) exp;
|
||||
SubstringByRegex sByRegex = new SubstringByRegex(
|
||||
parse(subByRegex.getSourceString()),
|
||||
|
@ -554,7 +577,7 @@ public class C_ExpressionParser {
|
|||
return sByRegex;
|
||||
}
|
||||
|
||||
private Expression getSubstringPosition(C_Expression exp) {
|
||||
private Expression getSubstringPosition(C_Expression exp) throws ExpressionParserException {
|
||||
C_SubstringPosition subPosition = (C_SubstringPosition) exp;
|
||||
SubstringPosition sPosition = new SubstringPosition(
|
||||
parse(subPosition.getLeftArgument()),
|
||||
|
@ -562,7 +585,7 @@ public class C_ExpressionParser {
|
|||
return sPosition;
|
||||
}
|
||||
|
||||
private Expression getTextReplaceMatchingRegex(C_Expression exp) {
|
||||
private Expression getTextReplaceMatchingRegex(C_Expression exp) throws ExpressionParserException {
|
||||
C_TextReplaceMatchingRegex textReplaceMatchingRegex = (C_TextReplaceMatchingRegex) exp;
|
||||
TDText tdRegexp = new TDText(textReplaceMatchingRegex.getRegexp()
|
||||
.getValue());
|
||||
|
@ -574,52 +597,41 @@ public class C_ExpressionParser {
|
|||
tdReplacing);
|
||||
return textRepRegex;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private Expression getAvg(C_Expression exp) {
|
||||
|
||||
private Expression getAvg(C_Expression exp) throws ExpressionParserException {
|
||||
C_Avg avg = (C_Avg) exp;
|
||||
Avg av = new Avg(
|
||||
parse(avg.getArgument()));
|
||||
Avg av = new Avg(parse(avg.getArgument()));
|
||||
return av;
|
||||
}
|
||||
|
||||
private Expression getCount(C_Expression exp) {
|
||||
|
||||
private Expression getCount(C_Expression exp)throws ExpressionParserException{
|
||||
C_Count count = (C_Count) exp;
|
||||
Count cnt = new Count(
|
||||
parse(count.getArgument()));
|
||||
Count cnt = new Count(parse(count.getArgument()));
|
||||
return cnt;
|
||||
}
|
||||
|
||||
|
||||
private Expression getMax(C_Expression exp) {
|
||||
|
||||
private Expression getMax(C_Expression exp) throws ExpressionParserException {
|
||||
C_Max max = (C_Max) exp;
|
||||
Max ma = new Max(
|
||||
parse(max.getArgument()));
|
||||
Max ma = new Max(parse(max.getArgument()));
|
||||
return ma;
|
||||
}
|
||||
|
||||
private Expression getMin(C_Expression exp) {
|
||||
|
||||
private Expression getMin(C_Expression exp) throws ExpressionParserException {
|
||||
C_Min min = (C_Min) exp;
|
||||
Min mi = new Min(
|
||||
parse(min.getArgument()));
|
||||
Min mi = new Min(parse(min.getArgument()));
|
||||
return mi;
|
||||
}
|
||||
|
||||
private Expression getSTExtent(C_Expression exp) {
|
||||
|
||||
private Expression getSTExtent(C_Expression exp) throws ExpressionParserException {
|
||||
C_ST_Extent stExtent = (C_ST_Extent) exp;
|
||||
ST_Extent stEx = new ST_Extent(
|
||||
parse(stExtent.getArgument()));
|
||||
ST_Extent stEx = new ST_Extent(parse(stExtent.getArgument()));
|
||||
return stEx;
|
||||
}
|
||||
|
||||
private Expression getSum(C_Expression exp) {
|
||||
|
||||
private Expression getSum(C_Expression exp) throws ExpressionParserException {
|
||||
C_Sum sum = (C_Sum) exp;
|
||||
Sum sm = new Sum(
|
||||
parse(sum.getArgument()));
|
||||
Sum sm = new Sum(parse(sum.getArgument()));
|
||||
return sm;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ import org.gcube.data.analysis.tabulardata.service.impl.TabularDataServiceFactor
|
|||
import org.gcube.data.analysis.tabulardata.service.tabular.TabularResource;
|
||||
import org.gcube.data.analysis.tabulardata.service.tabular.TabularResourceId;
|
||||
import org.gcube.portlets.user.td.expressionwidget.client.rpc.ExpressionService;
|
||||
import org.gcube.portlets.user.td.expressionwidget.shared.exception.ExpressionParserException;
|
||||
import org.gcube.portlets.user.td.expressionwidget.shared.exception.ExpressionServiceException;
|
||||
import org.gcube.portlets.user.td.gwtservice.server.SessionUtil;
|
||||
import org.gcube.portlets.user.td.gwtservice.server.TDGWTServiceImpl;
|
||||
|
@ -59,8 +60,13 @@ public class ExpressionServiceImpl extends RemoteServiceServlet implements
|
|||
filterColumnSession);
|
||||
|
||||
C_ExpressionParser parser = new C_ExpressionParser();
|
||||
Expression expression = parser.parse(filterColumnSession
|
||||
.getCexpression());
|
||||
Expression expression;
|
||||
try {
|
||||
expression = parser.parse(filterColumnSession.getCexpression());
|
||||
} catch (ExpressionParserException e) {
|
||||
logger.debug(e.getLocalizedMessage());
|
||||
throw new TDGWTServiceException(e.getLocalizedMessage());
|
||||
}
|
||||
logger.debug("Service Expression:" + expression);
|
||||
|
||||
TDGWTServiceImpl gwtService = new TDGWTServiceImpl();
|
||||
|
@ -102,9 +108,16 @@ public class ExpressionServiceImpl extends RemoteServiceServlet implements
|
|||
replaceColumnByExpressionSession);
|
||||
|
||||
C_ExpressionParser parser = new C_ExpressionParser();
|
||||
Expression conditionExpression = parser
|
||||
.parse(replaceColumnByExpressionSession
|
||||
.getcConditionExpression());
|
||||
Expression conditionExpression;
|
||||
try {
|
||||
conditionExpression = parser
|
||||
.parse(replaceColumnByExpressionSession
|
||||
.getcConditionExpression());
|
||||
} catch (ExpressionParserException e) {
|
||||
logger.debug(e.getLocalizedMessage());
|
||||
throw new TDGWTServiceException(e.getLocalizedMessage());
|
||||
}
|
||||
|
||||
logger.debug("Service Condition Expression:" + conditionExpression);
|
||||
|
||||
Expression replaceExpression = null;
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
package org.gcube.portlets.user.td.expressionwidget.shared.exception;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author giancarlo
|
||||
* email: <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||
*
|
||||
*/
|
||||
public class ExpressionParserException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = 8823457309498708839L;
|
||||
|
||||
public ExpressionParserException() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param message
|
||||
*/
|
||||
public ExpressionParserException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public ExpressionParserException(String message, Throwable t) {
|
||||
super(message, t);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,6 +1,11 @@
|
|||
package org.gcube.portlets.user.td.expressionwidget.shared.exception;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author giancarlo
|
||||
* email: <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||
*
|
||||
*/
|
||||
public class ExpressionServiceException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = -9066034060104406559L;
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
package org.gcube.portlets.user.td.expressionwidget.shared.exception;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author giancarlo
|
||||
* email: <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||
*
|
||||
*/
|
||||
public class OperatorTypeMapException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = -9066034060104406559L;
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
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.exception.OperatorTypeMapException;
|
||||
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_GreaterThan;
|
||||
|
@ -15,6 +17,7 @@ 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;
|
||||
|
@ -24,6 +27,7 @@ import org.gcube.portlets.user.td.expressionwidget.shared.model.logical.C_IsNotN
|
|||
import org.gcube.portlets.user.td.expressionwidget.shared.model.logical.C_IsNull;
|
||||
import org.gcube.portlets.user.td.expressionwidget.shared.model.logical.C_Not;
|
||||
import org.gcube.portlets.user.td.expressionwidget.shared.model.logical.C_Or;
|
||||
import org.gcube.portlets.user.td.expressionwidget.shared.model.logical.C_ValueIsIn;
|
||||
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;
|
||||
|
@ -46,7 +50,7 @@ public class OperatorTypeMap {
|
|||
}
|
||||
|
||||
public C_Expression map(ColumnData column, C_OperatorType operatorType,
|
||||
String firstArg, String secondArg) {
|
||||
String firstArg, String secondArg) throws OperatorTypeMapException {
|
||||
Log.debug("OperatorTypeMap Map");
|
||||
C_Expression exp = null;
|
||||
readableExpression = new String();
|
||||
|
@ -60,7 +64,8 @@ public class OperatorTypeMap {
|
|||
}
|
||||
|
||||
public C_Expression mapPlaceHolder(ColumnData column,
|
||||
C_OperatorType operatorType, String firstArg, String secondArg) {
|
||||
C_OperatorType operatorType, String firstArg, String secondArg)
|
||||
throws OperatorTypeMapException {
|
||||
Log.debug("OperatorTypeMap Map Place Holder");
|
||||
C_Expression exp = null;
|
||||
Log.debug("Column Data Type Name:" + column.getDataTypeName());
|
||||
|
@ -76,6 +81,9 @@ public class OperatorTypeMap {
|
|||
TD_Value sArg;
|
||||
C_Range range;
|
||||
|
||||
List<TD_Value> arguments = new ArrayList<TD_Value>();
|
||||
int separator;
|
||||
|
||||
switch (operatorType) {
|
||||
case ADDITION:
|
||||
break;
|
||||
|
@ -86,17 +94,15 @@ public class OperatorTypeMap {
|
|||
case ANY:
|
||||
break;
|
||||
case BEGINS_WITH:
|
||||
if(column.getDataTypeName().compareTo(ColumnDataType.Text.toString())==0){
|
||||
if(firstArg==null){
|
||||
firstArg="";
|
||||
}
|
||||
}
|
||||
checkTypeArgument(column, firstArg);
|
||||
exp = new C_TextBeginsWith(placeHolder, new TD_Value(dataType,
|
||||
firstArg));
|
||||
readableExpression = "Begins(" + readablePlaceHolder + ", "
|
||||
+ firstArg + ")";
|
||||
break;
|
||||
case BETWEEN:
|
||||
checkTypeArgument(column, firstArg);
|
||||
checkTypeArgument(column, secondArg);
|
||||
fArg = new TD_Value(dataType, firstArg);
|
||||
sArg = new TD_Value(dataType, secondArg);
|
||||
range = new C_Range(fArg, sArg);
|
||||
|
@ -105,11 +111,7 @@ public class OperatorTypeMap {
|
|||
+ firstArg + ", " + secondArg + "))";
|
||||
break;
|
||||
case CONTAINS:
|
||||
if(column.getDataTypeName().compareTo(ColumnDataType.Text.toString())==0){
|
||||
if(firstArg==null){
|
||||
firstArg="";
|
||||
}
|
||||
}
|
||||
checkTypeArgument(column, firstArg);
|
||||
fArg = new TD_Value(dataType, firstArg);
|
||||
exp = new C_TextContains(placeHolder, fArg);
|
||||
readableExpression = "Contains(" + readablePlaceHolder + ", "
|
||||
|
@ -118,22 +120,14 @@ public class OperatorTypeMap {
|
|||
case DIVISION:
|
||||
break;
|
||||
case ENDS_WITH:
|
||||
if(column.getDataTypeName().compareTo(ColumnDataType.Text.toString())==0){
|
||||
if(firstArg==null){
|
||||
firstArg="";
|
||||
}
|
||||
}
|
||||
checkTypeArgument(column, firstArg);
|
||||
exp = new C_TextEndsWith(placeHolder, new TD_Value(dataType,
|
||||
firstArg));
|
||||
readableExpression = "TextEndsWith(" + readablePlaceHolder + ","
|
||||
+ firstArg + ")";
|
||||
break;
|
||||
case EQUALS:
|
||||
if(column.getDataTypeName().compareTo(ColumnDataType.Text.toString())==0){
|
||||
if(firstArg==null){
|
||||
firstArg="";
|
||||
}
|
||||
}
|
||||
checkTypeArgument(column, firstArg);
|
||||
exp = new C_Equals(placeHolder, new TD_Value(dataType, firstArg));
|
||||
readableExpression = "Equals(" + readablePlaceHolder + ","
|
||||
+ firstArg + ")";
|
||||
|
@ -142,18 +136,52 @@ public class OperatorTypeMap {
|
|||
// exp=new C_Exi(placeHolder,new C_ConstantList(arguments));
|
||||
break;
|
||||
case GREATER:
|
||||
checkTypeArgument(column, firstArg);
|
||||
exp = new C_GreaterThan(placeHolder, new TD_Value(dataType,
|
||||
firstArg));
|
||||
readableExpression = "GreaterThan(" + readablePlaceHolder + ","
|
||||
+ firstArg + ")";
|
||||
break;
|
||||
case GREATER_OR_EQUALS:
|
||||
checkTypeArgument(column, firstArg);
|
||||
exp = new C_GreaterOrEquals(placeHolder, new TD_Value(dataType,
|
||||
firstArg));
|
||||
readableExpression = "GreaterOrEquals(" + readablePlaceHolder + ","
|
||||
+ firstArg + ")";
|
||||
break;
|
||||
case IN:
|
||||
separator = firstArg.indexOf(",");
|
||||
if (separator == -1 || firstArg.length() == 1) {
|
||||
checkTypeArgument(column, firstArg);
|
||||
arguments.add(new TD_Value(dataType, firstArg));
|
||||
} else {
|
||||
String arg;
|
||||
boolean end = false;
|
||||
while (!end) {
|
||||
arg = firstArg.substring(0, separator);
|
||||
checkTypeArgument(column, arg);
|
||||
arguments.add(new TD_Value(dataType, arg));
|
||||
separator++;
|
||||
if (separator < firstArg.length()) {
|
||||
firstArg = firstArg.substring(separator,
|
||||
firstArg.length());
|
||||
separator = firstArg.indexOf(",");
|
||||
if (separator == -1) {
|
||||
checkTypeArgument(column, firstArg);
|
||||
arguments.add(new TD_Value(dataType, firstArg));
|
||||
end = true;
|
||||
}
|
||||
} else {
|
||||
end = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
exp = new C_ValueIsIn(placeHolder, new C_ConstantList(arguments));
|
||||
readableExpression = "ValueIsIn(" + readablePlaceHolder;
|
||||
for (TD_Value v : arguments) {
|
||||
readableExpression += ", " + v.getValue();
|
||||
}
|
||||
readableExpression += ")";
|
||||
break;
|
||||
case IS_NOT_NULL:
|
||||
exp = new C_IsNotNull(placeHolder);
|
||||
|
@ -164,11 +192,13 @@ public class OperatorTypeMap {
|
|||
readableExpression = "IsNull(" + readablePlaceHolder + ")";
|
||||
break;
|
||||
case LESSER:
|
||||
checkTypeArgument(column, firstArg);
|
||||
exp = new C_LessThan(placeHolder, new TD_Value(dataType, firstArg));
|
||||
readableExpression = "LessThan(" + readablePlaceHolder + ","
|
||||
+ firstArg + ")";
|
||||
break;
|
||||
case LESSER_OR_EQUALS:
|
||||
checkTypeArgument(column, firstArg);
|
||||
exp = new C_LessOrEquals(placeHolder, new TD_Value(dataType,
|
||||
firstArg));
|
||||
readableExpression = "LessOrEquals(" + readablePlaceHolder + ","
|
||||
|
@ -177,11 +207,7 @@ public class OperatorTypeMap {
|
|||
case LIKE:
|
||||
break;
|
||||
case MATCH_REGEX:
|
||||
if(column.getDataTypeName().compareTo(ColumnDataType.Text.toString())==0){
|
||||
if(firstArg==null){
|
||||
firstArg="";
|
||||
}
|
||||
}
|
||||
checkTypeArgument(column, firstArg);
|
||||
exp = new C_TextMatchSQLRegexp(placeHolder, new TD_Value(dataType,
|
||||
firstArg));
|
||||
readableExpression = "TextMatchSQLRegexp(" + readablePlaceHolder
|
||||
|
@ -194,11 +220,7 @@ public class OperatorTypeMap {
|
|||
case NOT:
|
||||
break;
|
||||
case NOT_BEGINS_WITH:
|
||||
if(column.getDataTypeName().compareTo(ColumnDataType.Text.toString())==0){
|
||||
if(firstArg==null){
|
||||
firstArg="";
|
||||
}
|
||||
}
|
||||
checkTypeArgument(column, firstArg);
|
||||
exp = new C_TextBeginsWith(placeHolder, new TD_Value(dataType,
|
||||
firstArg));
|
||||
exp = new C_Not(exp);
|
||||
|
@ -206,6 +228,9 @@ public class OperatorTypeMap {
|
|||
+ "," + firstArg + "))";
|
||||
break;
|
||||
case NOT_BETWEEN:
|
||||
checkTypeArgument(column, firstArg);
|
||||
checkTypeArgument(column, secondArg);
|
||||
|
||||
fArg = new TD_Value(dataType, firstArg);
|
||||
sArg = new TD_Value(dataType, secondArg);
|
||||
range = new C_Range(fArg, sArg);
|
||||
|
@ -215,11 +240,7 @@ public class OperatorTypeMap {
|
|||
+ ", Range(" + firstArg + ", " + secondArg + ")))";
|
||||
break;
|
||||
case NOT_CONTAINS:
|
||||
if(column.getDataTypeName().compareTo(ColumnDataType.Text.toString())==0){
|
||||
if(firstArg==null){
|
||||
firstArg="";
|
||||
}
|
||||
}
|
||||
checkTypeArgument(column, firstArg);
|
||||
fArg = new TD_Value(dataType, firstArg);
|
||||
exp = new C_TextContains(placeHolder, fArg);
|
||||
exp = new C_Not(exp);
|
||||
|
@ -227,11 +248,7 @@ public class OperatorTypeMap {
|
|||
+ firstArg + "))";
|
||||
break;
|
||||
case NOT_ENDS_WITH:
|
||||
if(column.getDataTypeName().compareTo(ColumnDataType.Text.toString())==0){
|
||||
if(firstArg==null){
|
||||
firstArg="";
|
||||
}
|
||||
}
|
||||
checkTypeArgument(column, firstArg);
|
||||
exp = new C_TextEndsWith(placeHolder, new TD_Value(dataType,
|
||||
firstArg));
|
||||
exp = new C_Not(exp);
|
||||
|
@ -239,24 +256,55 @@ public class OperatorTypeMap {
|
|||
+ "," + firstArg + "))";
|
||||
break;
|
||||
case NOT_EQUALS:
|
||||
if(column.getDataTypeName().compareTo(ColumnDataType.Text.toString())==0){
|
||||
if(firstArg==null){
|
||||
firstArg="";
|
||||
}
|
||||
}
|
||||
checkTypeArgument(column, firstArg);
|
||||
exp = new C_NotEquals(placeHolder, new TD_Value(dataType, firstArg));
|
||||
readableExpression = "NotEquals(" + readablePlaceHolder + ","
|
||||
+ firstArg + ")";
|
||||
break;
|
||||
case NOT_GREATER:
|
||||
checkTypeArgument(column, firstArg);
|
||||
exp = new C_NotGreater(placeHolder,
|
||||
new TD_Value(dataType, firstArg));
|
||||
readableExpression = "NotGreater(" + readablePlaceHolder + ","
|
||||
+ firstArg + ")";
|
||||
break;
|
||||
case NOT_IN:
|
||||
separator = firstArg.indexOf(",");
|
||||
if (separator == -1 || firstArg.length() == 1) {
|
||||
checkTypeArgument(column, firstArg);
|
||||
arguments.add(new TD_Value(dataType, firstArg));
|
||||
} else {
|
||||
String arg;
|
||||
boolean end = false;
|
||||
while (!end) {
|
||||
arg = firstArg.substring(0, separator);
|
||||
checkTypeArgument(column, arg);
|
||||
arguments.add(new TD_Value(dataType, arg));
|
||||
separator++;
|
||||
if (separator < firstArg.length()) {
|
||||
firstArg = firstArg.substring(separator,
|
||||
firstArg.length());
|
||||
separator = firstArg.indexOf(",");
|
||||
if (separator == -1) {
|
||||
checkTypeArgument(column, firstArg);
|
||||
arguments.add(new TD_Value(dataType, firstArg));
|
||||
end = true;
|
||||
}
|
||||
} else {
|
||||
end = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
exp = new C_ValueIsIn(placeHolder, new C_ConstantList(arguments));
|
||||
exp = new C_Not(exp);
|
||||
readableExpression = "Not(ValueIsIn(" + readablePlaceHolder;
|
||||
for (TD_Value v : arguments) {
|
||||
readableExpression += ", " + v.getValue();
|
||||
}
|
||||
readableExpression += "))";
|
||||
break;
|
||||
case NOT_LESSER:
|
||||
checkTypeArgument(column, firstArg);
|
||||
exp = new C_NotLess(placeHolder, new TD_Value(dataType, firstArg));
|
||||
readableExpression = "NotLess(" + readablePlaceHolder + ","
|
||||
+ firstArg + ")";
|
||||
|
@ -264,11 +312,7 @@ public class OperatorTypeMap {
|
|||
case NOT_LIKE:
|
||||
break;
|
||||
case NOT_MATCH_REGEX:
|
||||
if(column.getDataTypeName().compareTo(ColumnDataType.Text.toString())==0){
|
||||
if(firstArg==null){
|
||||
firstArg="";
|
||||
}
|
||||
}
|
||||
checkTypeArgument(column, firstArg);
|
||||
exp = new C_TextMatchSQLRegexp(placeHolder, new TD_Value(dataType,
|
||||
firstArg));
|
||||
exp = new C_Not(exp);
|
||||
|
@ -291,7 +335,8 @@ public class OperatorTypeMap {
|
|||
}
|
||||
|
||||
public C_Expression mapTypedColumnReference(ColumnData column,
|
||||
C_OperatorType operatorType, String firstArg, String secondArg) {
|
||||
C_OperatorType operatorType, String firstArg, String secondArg)
|
||||
throws OperatorTypeMapException {
|
||||
Log.debug("OperatorTypeMap Map Typed Column Reference");
|
||||
C_Expression exp = null;
|
||||
|
||||
|
@ -308,6 +353,9 @@ public class OperatorTypeMap {
|
|||
TD_Value sArg;
|
||||
C_Range range;
|
||||
|
||||
List<TD_Value> arguments = new ArrayList<TD_Value>();
|
||||
int separator;
|
||||
|
||||
switch (operatorType) {
|
||||
case ADDITION:
|
||||
break;
|
||||
|
@ -318,17 +366,15 @@ public class OperatorTypeMap {
|
|||
case ANY:
|
||||
break;
|
||||
case BEGINS_WITH:
|
||||
if(column.getDataTypeName().compareTo(ColumnDataType.Text.toString())==0){
|
||||
if(firstArg==null){
|
||||
firstArg="";
|
||||
}
|
||||
}
|
||||
checkTypeArgument(column, firstArg);
|
||||
exp = new C_TextBeginsWith(columnReference, new TD_Value(dataType,
|
||||
firstArg));
|
||||
readableExpression = "TextBeginsWith(" + readableColumnReference
|
||||
+ "," + firstArg + ")";
|
||||
break;
|
||||
case BETWEEN:
|
||||
checkTypeArgument(column, firstArg);
|
||||
checkTypeArgument(column, secondArg);
|
||||
fArg = new TD_Value(dataType, firstArg);
|
||||
sArg = new TD_Value(dataType, secondArg);
|
||||
range = new C_Range(fArg, sArg);
|
||||
|
@ -337,11 +383,7 @@ public class OperatorTypeMap {
|
|||
+ ", Range(" + firstArg + ", " + secondArg + "))";
|
||||
break;
|
||||
case CONTAINS:
|
||||
if(column.getDataTypeName().compareTo(ColumnDataType.Text.toString())==0){
|
||||
if(firstArg==null){
|
||||
firstArg="";
|
||||
}
|
||||
}
|
||||
checkTypeArgument(column, firstArg);
|
||||
fArg = new TD_Value(dataType, firstArg);
|
||||
exp = new C_TextContains(columnReference, fArg);
|
||||
readableExpression = "Contains(" + columnReference + ", "
|
||||
|
@ -350,22 +392,14 @@ public class OperatorTypeMap {
|
|||
case DIVISION:
|
||||
break;
|
||||
case ENDS_WITH:
|
||||
if(column.getDataTypeName().compareTo(ColumnDataType.Text.toString())==0){
|
||||
if(firstArg==null){
|
||||
firstArg="";
|
||||
}
|
||||
}
|
||||
checkTypeArgument(column, firstArg);
|
||||
exp = new C_TextEndsWith(columnReference, new TD_Value(dataType,
|
||||
firstArg));
|
||||
readableExpression = "TextEndsWith(" + readableColumnReference
|
||||
+ ", " + firstArg + ")";
|
||||
break;
|
||||
case EQUALS:
|
||||
if(column.getDataTypeName().compareTo(ColumnDataType.Text.toString())==0){
|
||||
if(firstArg==null){
|
||||
firstArg="";
|
||||
}
|
||||
}
|
||||
checkTypeArgument(column, firstArg);
|
||||
exp = new C_Equals(columnReference,
|
||||
new TD_Value(dataType, firstArg));
|
||||
readableExpression = "Equals(" + readableColumnReference + ", "
|
||||
|
@ -375,18 +409,53 @@ public class OperatorTypeMap {
|
|||
// exp=new C_Exi(placeHolder,new C_ConstantList(arguments));
|
||||
break;
|
||||
case GREATER:
|
||||
checkTypeArgument(column, firstArg);
|
||||
exp = new C_GreaterThan(columnReference, new TD_Value(dataType,
|
||||
firstArg));
|
||||
readableExpression = "GreaterThan(" + readableColumnReference
|
||||
+ ", " + firstArg + ")";
|
||||
break;
|
||||
case GREATER_OR_EQUALS:
|
||||
checkTypeArgument(column, firstArg);
|
||||
exp = new C_GreaterOrEquals(columnReference, new TD_Value(dataType,
|
||||
firstArg));
|
||||
readableExpression = "GreaterOrEquals(" + readableColumnReference
|
||||
+ ", " + firstArg + ")";
|
||||
break;
|
||||
case IN:
|
||||
separator = firstArg.indexOf(",");
|
||||
if (separator == -1 || firstArg.length() == 1) {
|
||||
checkTypeArgument(column, firstArg);
|
||||
arguments.add(new TD_Value(dataType, firstArg));
|
||||
} else {
|
||||
String arg;
|
||||
boolean end = false;
|
||||
while (!end) {
|
||||
arg = firstArg.substring(0, separator);
|
||||
checkTypeArgument(column, arg);
|
||||
arguments.add(new TD_Value(dataType, arg));
|
||||
separator++;
|
||||
if (separator < firstArg.length()) {
|
||||
firstArg = firstArg.substring(separator,
|
||||
firstArg.length());
|
||||
separator = firstArg.indexOf(",");
|
||||
if (separator == -1) {
|
||||
checkTypeArgument(column, firstArg);
|
||||
arguments.add(new TD_Value(dataType, firstArg));
|
||||
end = true;
|
||||
}
|
||||
} else {
|
||||
end = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
exp = new C_ValueIsIn(columnReference,
|
||||
new C_ConstantList(arguments));
|
||||
readableExpression = "ValueIsIn(" + readableColumnReference;
|
||||
for (TD_Value v : arguments) {
|
||||
readableExpression += ", " + v.getValue();
|
||||
}
|
||||
readableExpression += ")";
|
||||
break;
|
||||
case IS_NOT_NULL:
|
||||
exp = new C_IsNotNull(columnReference);
|
||||
|
@ -397,12 +466,14 @@ public class OperatorTypeMap {
|
|||
readableExpression = "IsNull(" + readableColumnReference + ")";
|
||||
break;
|
||||
case LESSER:
|
||||
checkTypeArgument(column, firstArg);
|
||||
exp = new C_LessThan(columnReference, new TD_Value(dataType,
|
||||
firstArg));
|
||||
readableExpression = "LessThan(" + readableColumnReference + ", "
|
||||
+ firstArg + ")";
|
||||
break;
|
||||
case LESSER_OR_EQUALS:
|
||||
checkTypeArgument(column, firstArg);
|
||||
exp = new C_LessOrEquals(columnReference, new TD_Value(dataType,
|
||||
firstArg));
|
||||
readableExpression = "LessOrEquals(" + readableColumnReference
|
||||
|
@ -411,11 +482,7 @@ public class OperatorTypeMap {
|
|||
case LIKE:
|
||||
break;
|
||||
case MATCH_REGEX:
|
||||
if(column.getDataTypeName().compareTo(ColumnDataType.Text.toString())==0){
|
||||
if(firstArg==null){
|
||||
firstArg="";
|
||||
}
|
||||
}
|
||||
checkTypeArgument(column, firstArg);
|
||||
exp = new C_TextMatchSQLRegexp(columnReference, new TD_Value(
|
||||
dataType, firstArg));
|
||||
readableExpression = "TextMatchSQLRegexp("
|
||||
|
@ -428,11 +495,7 @@ public class OperatorTypeMap {
|
|||
case NOT:
|
||||
break;
|
||||
case NOT_BEGINS_WITH:
|
||||
if(column.getDataTypeName().compareTo(ColumnDataType.Text.toString())==0){
|
||||
if(firstArg==null){
|
||||
firstArg="";
|
||||
}
|
||||
}
|
||||
checkTypeArgument(column, firstArg);
|
||||
exp = new C_TextBeginsWith(columnReference, new TD_Value(dataType,
|
||||
firstArg));
|
||||
exp = new C_Not(exp);
|
||||
|
@ -440,6 +503,8 @@ public class OperatorTypeMap {
|
|||
+ readableColumnReference + ", " + firstArg + "))";
|
||||
break;
|
||||
case NOT_BETWEEN:
|
||||
checkTypeArgument(column, firstArg);
|
||||
checkTypeArgument(column, secondArg);
|
||||
fArg = new TD_Value(dataType, firstArg);
|
||||
sArg = new TD_Value(dataType, secondArg);
|
||||
range = new C_Range(fArg, sArg);
|
||||
|
@ -449,11 +514,7 @@ public class OperatorTypeMap {
|
|||
+ ", Range(" + firstArg + ", " + secondArg + ")))";
|
||||
break;
|
||||
case NOT_CONTAINS:
|
||||
if(column.getDataTypeName().compareTo(ColumnDataType.Text.toString())==0){
|
||||
if(firstArg==null){
|
||||
firstArg="";
|
||||
}
|
||||
}
|
||||
checkTypeArgument(column, firstArg);
|
||||
fArg = new TD_Value(dataType, firstArg);
|
||||
exp = new C_TextContains(columnReference, fArg);
|
||||
exp = new C_Not(exp);
|
||||
|
@ -461,11 +522,7 @@ public class OperatorTypeMap {
|
|||
+ firstArg + "))";
|
||||
break;
|
||||
case NOT_ENDS_WITH:
|
||||
if(column.getDataTypeName().compareTo(ColumnDataType.Text.toString())==0){
|
||||
if(firstArg==null){
|
||||
firstArg="";
|
||||
}
|
||||
}
|
||||
checkTypeArgument(column, firstArg);
|
||||
exp = new C_TextEndsWith(columnReference, new TD_Value(dataType,
|
||||
firstArg));
|
||||
exp = new C_Not(exp);
|
||||
|
@ -473,25 +530,57 @@ public class OperatorTypeMap {
|
|||
+ "," + firstArg + "))";
|
||||
break;
|
||||
case NOT_EQUALS:
|
||||
if(column.getDataTypeName().compareTo(ColumnDataType.Text.toString())==0){
|
||||
if(firstArg==null){
|
||||
firstArg="";
|
||||
}
|
||||
}
|
||||
checkTypeArgument(column, firstArg);
|
||||
exp = new C_NotEquals(columnReference, new TD_Value(dataType,
|
||||
firstArg));
|
||||
readableExpression = "NotEquals(" + readableColumnReference + ","
|
||||
+ firstArg + ")";
|
||||
break;
|
||||
case NOT_GREATER:
|
||||
checkTypeArgument(column, firstArg);
|
||||
exp = new C_NotGreater(columnReference, new TD_Value(dataType,
|
||||
firstArg));
|
||||
readableExpression = "NotGreater(" + readableColumnReference + ","
|
||||
+ firstArg + ")";
|
||||
break;
|
||||
case NOT_IN:
|
||||
separator = firstArg.indexOf(",");
|
||||
if (separator == -1 || firstArg.length() == 1) {
|
||||
checkTypeArgument(column, firstArg);
|
||||
arguments.add(new TD_Value(dataType, firstArg));
|
||||
} else {
|
||||
String arg;
|
||||
boolean end = false;
|
||||
while (!end) {
|
||||
arg = firstArg.substring(0, separator);
|
||||
checkTypeArgument(column, arg);
|
||||
arguments.add(new TD_Value(dataType, arg));
|
||||
separator++;
|
||||
if (separator < firstArg.length()) {
|
||||
firstArg = firstArg.substring(separator,
|
||||
firstArg.length());
|
||||
separator = firstArg.indexOf(",");
|
||||
if (separator == -1) {
|
||||
checkTypeArgument(column, firstArg);
|
||||
arguments.add(new TD_Value(dataType, firstArg));
|
||||
end = true;
|
||||
}
|
||||
} else {
|
||||
end = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
exp = new C_ValueIsIn(columnReference,
|
||||
new C_ConstantList(arguments));
|
||||
exp = new C_Not(exp);
|
||||
readableExpression = "Not(ValueIsIn(" + readableColumnReference;
|
||||
for (TD_Value v : arguments) {
|
||||
readableExpression += ", " + v.getValue();
|
||||
}
|
||||
readableExpression += "))";
|
||||
break;
|
||||
case NOT_LESSER:
|
||||
checkTypeArgument(column, firstArg);
|
||||
exp = new C_NotLess(columnReference, new TD_Value(dataType,
|
||||
firstArg));
|
||||
readableExpression = "NotLess(" + readableColumnReference + ","
|
||||
|
@ -500,11 +589,7 @@ public class OperatorTypeMap {
|
|||
case NOT_LIKE:
|
||||
break;
|
||||
case NOT_MATCH_REGEX:
|
||||
if(column.getDataTypeName().compareTo(ColumnDataType.Text.toString())==0){
|
||||
if(firstArg==null){
|
||||
firstArg="";
|
||||
}
|
||||
}
|
||||
checkTypeArgument(column, firstArg);
|
||||
exp = new C_TextMatchSQLRegexp(columnReference, new TD_Value(
|
||||
dataType, firstArg));
|
||||
exp = new C_Not(exp);
|
||||
|
@ -540,4 +625,63 @@ public class OperatorTypeMap {
|
|||
return readableExpression;
|
||||
}
|
||||
|
||||
protected void checkTypeArgument(ColumnData column, String arg)
|
||||
throws OperatorTypeMapException {
|
||||
if (column.getDataTypeName().compareTo(ColumnDataType.Text.toString()) == 0) {
|
||||
if (arg == null) {
|
||||
arg = "";
|
||||
}
|
||||
} else {
|
||||
if (column.getDataTypeName().compareTo(
|
||||
ColumnDataType.Boolean.toString()) == 0) {
|
||||
if(arg==null){
|
||||
throw new OperatorTypeMapException(
|
||||
"Insert a valid Boolean(ex: true, false)!");
|
||||
}
|
||||
} else {
|
||||
if (column.getDataTypeName().compareTo(
|
||||
ColumnDataType.Date.toString()) == 0) {
|
||||
|
||||
} else {
|
||||
if (column.getDataTypeName().compareTo(
|
||||
ColumnDataType.Geometry.toString()) == 0) {
|
||||
|
||||
} else {
|
||||
if (column.getDataTypeName().compareTo(
|
||||
ColumnDataType.Integer.toString()) == 0) {
|
||||
if(arg==null){
|
||||
throw new OperatorTypeMapException(
|
||||
"Insert a valid Integer(ex: -1, 0, 1, 2)!");
|
||||
}
|
||||
|
||||
try {
|
||||
Integer.parseInt(arg);
|
||||
} catch (NumberFormatException e) {
|
||||
throw new OperatorTypeMapException(arg
|
||||
+ " is not valid Integer(ex: -1, 0, 1, 2)!");
|
||||
}
|
||||
} else {
|
||||
if (column.getDataTypeName().compareTo(
|
||||
ColumnDataType.Numeric.toString()) == 0) {
|
||||
if(arg==null){
|
||||
throw new OperatorTypeMapException(
|
||||
"Insert a valid Numeric(ex: -1.2, 0, 1, 2.4)!");
|
||||
}
|
||||
try {
|
||||
Float.parseFloat(arg);
|
||||
} catch (NumberFormatException e) {
|
||||
throw new OperatorTypeMapException(arg
|
||||
+ " is not valid Numeric(ex: -1.2, 0, 1, 2.4)!");
|
||||
}
|
||||
} else {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue