Updated C_ExpressionParser

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-expression-widget@113948 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2015-04-10 17:07:27 +00:00
parent 1315884dfd
commit aa855309eb
49 changed files with 1285 additions and 65 deletions

View File

@ -62,3 +62,67 @@ Compiling...
Compilation completed in 0.00 seconds Compilation completed in 0.00 seconds
Removing invalidated units Removing invalidated units
Finding entry point classes Finding entry point classes
Public resources found in...
Translatable source found in...
Found 0 cached/archived units. Used 0 / 2737 units from cache.
Compiling...
10% complete (ETR: 24 seconds)
10% complete (ETR: 24 seconds)
20% complete (ETR: 22 seconds)
30% complete (ETR: 17 seconds)
40% complete (ETR: 12 seconds)
50% complete (ETR: 9 seconds)
60% complete (ETR: 6 seconds)
70% complete (ETR: 4 seconds)
80% complete (ETR: 3 seconds)
90% complete (ETR: 1 seconds)
100% complete (ETR: 0 seconds)
Compilation completed in 27.69 seconds
Removing invalidated units
Finding entry point classes
Public resources found in...
Translatable source found in...
Found 2737 cached/archived units. Used 2737 / 2737 units from cache.
Compiling...
Compilation completed in 0.00 seconds
Removing invalidated units
Finding entry point classes
Public resources found in...
Translatable source found in...
Found 2737 cached/archived units. Used 2737 / 2737 units from cache.
Compiling...
Compilation completed in 0.00 seconds
Removing invalidated units
Finding entry point classes
Public resources found in...
Translatable source found in...
Found 0 cached/archived units. Used 0 / 2737 units from cache.
Compiling...
40% complete (ETR: 7 seconds)
40% complete (ETR: 7 seconds)
40% complete (ETR: 7 seconds)
40% complete (ETR: 7 seconds)
40% complete (ETR: 7 seconds)
50% complete (ETR: 6 seconds)
60% complete (ETR: 4 seconds)
70% complete (ETR: 3 seconds)
80% complete (ETR: 2 seconds)
90% complete (ETR: 1 seconds)
100% complete (ETR: 0 seconds)
Compilation completed in 20.49 seconds
Removing invalidated units
Finding entry point classes
Public resources found in...
Translatable source found in...
Found 2737 cached/archived units. Used 2737 / 2737 units from cache.
Compiling...
Compilation completed in 0.00 seconds
Removing invalidated units
Finding entry point classes
Public resources found in...
Translatable source found in...
Found 2737 cached/archived units. Used 2737 / 2737 units from cache.
Compiling...
Compilation completed in 0.00 seconds
Removing invalidated units
Finding entry point classes

View File

@ -8,6 +8,7 @@ import java.util.List;
import org.gcube.data.analysis.tabulardata.expression.Expression; import org.gcube.data.analysis.tabulardata.expression.Expression;
import org.gcube.data.analysis.tabulardata.expression.MultivaluedExpression; import org.gcube.data.analysis.tabulardata.expression.MultivaluedExpression;
import org.gcube.data.analysis.tabulardata.expression.composite.ExternalReferenceExpression;
import org.gcube.data.analysis.tabulardata.expression.composite.aggregation.Avg; import org.gcube.data.analysis.tabulardata.expression.composite.aggregation.Avg;
import org.gcube.data.analysis.tabulardata.expression.composite.aggregation.Count; import org.gcube.data.analysis.tabulardata.expression.composite.aggregation.Count;
import org.gcube.data.analysis.tabulardata.expression.composite.aggregation.Max; import org.gcube.data.analysis.tabulardata.expression.composite.aggregation.Max;
@ -16,6 +17,7 @@ import org.gcube.data.analysis.tabulardata.expression.composite.aggregation.ST_E
import org.gcube.data.analysis.tabulardata.expression.composite.aggregation.Sum; import org.gcube.data.analysis.tabulardata.expression.composite.aggregation.Sum;
import org.gcube.data.analysis.tabulardata.expression.composite.arithmetic.Addition; import org.gcube.data.analysis.tabulardata.expression.composite.arithmetic.Addition;
import org.gcube.data.analysis.tabulardata.expression.composite.arithmetic.Division; import org.gcube.data.analysis.tabulardata.expression.composite.arithmetic.Division;
import org.gcube.data.analysis.tabulardata.expression.composite.arithmetic.Exponentiation;
import org.gcube.data.analysis.tabulardata.expression.composite.arithmetic.Modulus; import org.gcube.data.analysis.tabulardata.expression.composite.arithmetic.Modulus;
import org.gcube.data.analysis.tabulardata.expression.composite.arithmetic.Multiplication; import org.gcube.data.analysis.tabulardata.expression.composite.arithmetic.Multiplication;
import org.gcube.data.analysis.tabulardata.expression.composite.arithmetic.Subtraction; import org.gcube.data.analysis.tabulardata.expression.composite.arithmetic.Subtraction;
@ -27,10 +29,13 @@ import org.gcube.data.analysis.tabulardata.expression.composite.comparable.LessT
import org.gcube.data.analysis.tabulardata.expression.composite.comparable.NotEquals; import org.gcube.data.analysis.tabulardata.expression.composite.comparable.NotEquals;
import org.gcube.data.analysis.tabulardata.expression.composite.comparable.NotGreater; import org.gcube.data.analysis.tabulardata.expression.composite.comparable.NotGreater;
import org.gcube.data.analysis.tabulardata.expression.composite.comparable.NotLess; import org.gcube.data.analysis.tabulardata.expression.composite.comparable.NotLess;
import org.gcube.data.analysis.tabulardata.expression.composite.condtional.Case;
import org.gcube.data.analysis.tabulardata.expression.composite.text.Concat; import org.gcube.data.analysis.tabulardata.expression.composite.text.Concat;
import org.gcube.data.analysis.tabulardata.expression.composite.text.Length;
import org.gcube.data.analysis.tabulardata.expression.composite.text.Levenshtein; import org.gcube.data.analysis.tabulardata.expression.composite.text.Levenshtein;
import org.gcube.data.analysis.tabulardata.expression.composite.text.Lower; import org.gcube.data.analysis.tabulardata.expression.composite.text.Lower;
import org.gcube.data.analysis.tabulardata.expression.composite.text.MD5; import org.gcube.data.analysis.tabulardata.expression.composite.text.MD5;
import org.gcube.data.analysis.tabulardata.expression.composite.text.RepeatText;
import org.gcube.data.analysis.tabulardata.expression.composite.text.Similarity; import org.gcube.data.analysis.tabulardata.expression.composite.text.Similarity;
import org.gcube.data.analysis.tabulardata.expression.composite.text.Soundex; import org.gcube.data.analysis.tabulardata.expression.composite.text.Soundex;
import org.gcube.data.analysis.tabulardata.expression.composite.text.SubstringByIndex; import org.gcube.data.analysis.tabulardata.expression.composite.text.SubstringByIndex;
@ -39,6 +44,7 @@ import org.gcube.data.analysis.tabulardata.expression.composite.text.SubstringPo
import org.gcube.data.analysis.tabulardata.expression.composite.text.TextBeginsWith; import org.gcube.data.analysis.tabulardata.expression.composite.text.TextBeginsWith;
import org.gcube.data.analysis.tabulardata.expression.composite.text.TextContains; import org.gcube.data.analysis.tabulardata.expression.composite.text.TextContains;
import org.gcube.data.analysis.tabulardata.expression.composite.text.TextEndsWith; import org.gcube.data.analysis.tabulardata.expression.composite.text.TextEndsWith;
import org.gcube.data.analysis.tabulardata.expression.composite.text.TextMatchPosixRegexp;
import org.gcube.data.analysis.tabulardata.expression.composite.text.TextMatchSQLRegexp; import org.gcube.data.analysis.tabulardata.expression.composite.text.TextMatchSQLRegexp;
import org.gcube.data.analysis.tabulardata.expression.composite.text.TextReplaceMatchingRegex; import org.gcube.data.analysis.tabulardata.expression.composite.text.TextReplaceMatchingRegex;
import org.gcube.data.analysis.tabulardata.expression.composite.text.Trim; import org.gcube.data.analysis.tabulardata.expression.composite.text.Trim;
@ -121,17 +127,826 @@ 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_Not;
import org.gcube.portlets.user.td.expressionwidget.shared.model.logical.C_Or; 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.expressionwidget.shared.model.logical.C_ValueIsIn;
import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId;
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;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
public class C_ExpressionParser { public class C_ExpressionParser {
protected static Logger logger = LoggerFactory private static Logger logger = LoggerFactory
.getLogger(C_ExpressionParser.class); .getLogger(C_ExpressionParser.class);
protected SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
/**
*
* @param exp
* @return
* @throws ExpressionParserException
*/
public C_Expression parse(Expression exp) throws ExpressionParserException {
logger.debug("Parse: " + exp);
C_Expression ex = null;
if (exp == null) {
return ex;
}
if (exp instanceof Addition) {
return getAddition(exp);
}
if (exp instanceof Division) {
return getDivision(exp);
}
if (exp instanceof Exponentiation) {
//TODO
return ex;
}
if (exp instanceof Equals) {
return getEquals(exp);
}
if (exp instanceof GreaterOrEquals) {
return getGreaterOrEquals(exp);
}
if (exp instanceof GreaterThan) {
return getGreaterThan(exp);
}
if (exp instanceof LessOrEquals) {
return getLessOrEquals(exp);
}
if (exp instanceof LessThan) {
return getLessThan(exp);
}
if (exp instanceof Modulus) {
return getModulus(exp);
}
if (exp instanceof Multiplication) {
return getMultiplication(exp);
}
if (exp instanceof NotEquals) {
return getNotEquals(exp);
}
if (exp instanceof NotGreater) {
return getNotGreater(exp);
}
if (exp instanceof NotLess) {
return getNotLess(exp);
}
if (exp instanceof Subtraction) {
return getSubtraction(exp);
}
if (exp instanceof TextBeginsWith) {
return getTextBeginWith(exp);
}
if (exp instanceof TextContains) {
return getTextContains(exp);
}
if (exp instanceof TextEndsWith) {
return getTextEndWith(exp);
}
if (exp instanceof TextMatchSQLRegexp) {
return getTextMatchSQLRegexp(exp);
}
if (exp instanceof TextMatchPosixRegexp) {
//TODO
return ex;
}
if (exp instanceof TextReplaceMatchingRegex) {
return getTextReplaceMatchingRegex(exp);
}
if (exp instanceof SubstringByRegex) {
return getSubstringByRegex(exp);
}
if (exp instanceof SubstringByIndex) {
return getSubstringByIndex(exp);
}
if (exp instanceof SubstringPosition) {
return getSubstringPosition(exp);
}
if (exp instanceof RepeatText) {
//TODO
return ex;
}
if (exp instanceof Trim) {
return getTrim(exp);
}
if (exp instanceof Length) {
//TODO
return ex;
}
if (exp instanceof Upper) {
return getUpper(exp);
}
if (exp instanceof Lower) {
return getLower(exp);
}
if (exp instanceof Concat) {
return getConcat(exp);
}
if (exp instanceof MD5) {
return getMD5(exp);
}
if (exp instanceof Soundex) {
return getSoundex(exp);
}
if (exp instanceof Similarity) {
return getSimilarity(exp);
}
if (exp instanceof Levenshtein) {
return getLevenshtein(exp);
}
if (exp instanceof ValueIsIn) {
return getValueIsIn(exp);
}
if (exp instanceof ExternalReferenceExpression) {
//TODO
return ex;
}
if (exp instanceof Between) {
return getBetween(exp);
}
// Multiple
if (exp instanceof And) {
return getAnd(exp);
}
if (exp instanceof Or) {
return getOr(exp);
}
if (exp instanceof Case) {
//TODO
return ex;
}
// Unary
if (exp instanceof IsNotNull) {
return getIsNotNull(exp);
}
if (exp instanceof IsNull) {
return getIsNull(exp);
}
if (exp instanceof Not) {
return getNot(exp);
}
// Leaf
if (exp instanceof ColumnReference) {
return getColumnReference(exp);
}
if (exp instanceof Range) {
return getRange(exp);
}
if (exp instanceof ConstantList) {
return getConstantList(exp);
}
// TypedColumnReference.class,
if (exp instanceof ColumnReferencePlaceholder) {
return getColumnReferencePlaceholder(exp);
}
// TDTypeValue
if (exp instanceof TDBoolean) {
return getExpressionValue((TDBoolean)exp);
}
if (exp instanceof TDDate) {
return getExpressionValue((TDDate)exp);
}
if (exp instanceof TDInteger) {
return getExpressionValue((TDInteger)exp);
}
if (exp instanceof TDNumeric) {
return getExpressionValue((TDNumeric)exp);
}
if (exp instanceof TDText) {
return getExpressionValue((TDText)exp);
}
if (exp instanceof TDGeometry) {
return getExpressionValue((TDGeometry)exp);
}
if (exp instanceof Cast) {
return getCast(exp);
}
// Aggregation
if (exp instanceof Avg) {
return getAvg(exp);
}
if (exp instanceof Count) {
return getCount(exp);
}
if (exp instanceof Max) {
return getMax(exp);
}
if (exp instanceof Min) {
return getMin(exp);
}
if (exp instanceof Sum) {
return getSum(exp);
}
if (exp instanceof ST_Extent) {
return getSTExtent(exp);
}
ex = new C_Expression();
return ex;
}
public C_MultivaluedExpression parseMultivalued(Expression exp)
throws ExpressionParserException {
if (exp instanceof ConstantList) {
return getConstantList((ConstantList) exp);
}
if (exp instanceof Range) {
return getRange((Range)exp);
}
if (exp instanceof ExternalReferenceExpression) {
return null;
}
return null;
}
private C_Expression getValueIsIn(Expression exp)
throws ExpressionParserException {
ValueIsIn v = (ValueIsIn) exp;
C_MultivaluedExpression multivalued = parseMultivalued(v
.getRightArgument());
C_ValueIsIn valueIsIn = new C_ValueIsIn(parse(v.getLeftArgument()),
multivalued);
return valueIsIn;
}
private C_Expression getOr(Expression exp) throws ExpressionParserException {
Or o = (Or) exp;
List<Expression> listExp = o.getArguments();
List<C_Expression> listCExp = new ArrayList<C_Expression>();
C_Expression ex;
for (Expression serviceExp : listExp) {
ex = parse(serviceExp);
listCExp.add(ex);
}
C_Or or = new C_Or(listCExp);
return or;
}
private C_Expression getNot(Expression exp)
throws ExpressionParserException {
Not n = (Not) exp;
C_Not not = new C_Not(parse(n.getArgument()));
return not;
}
private C_Expression getIsNull(Expression exp)
throws ExpressionParserException {
IsNull nullIs = (IsNull) exp;
C_IsNull isNull = new C_IsNull(parse(nullIs.getArgument()));
return isNull;
}
private C_Expression getIsNotNull(Expression exp)
throws ExpressionParserException {
IsNotNull nullNotIs = (IsNotNull) exp;
C_IsNotNull isNotNull = new C_IsNotNull(parse(nullNotIs.getArgument()));
return isNotNull;
}
private C_Expression getBetween(Expression exp)
throws ExpressionParserException {
Between bet = (Between) exp;
C_Expression crange = parse(bet.getRightArgument());
C_Between between = null;
if (crange instanceof C_Range) {
C_Range range = (C_Range) crange;
between = new C_Between(parse(bet.getLeftArgument()), range);
}
return between;
}
private C_Expression getAnd(Expression exp)
throws ExpressionParserException {
And o = (And) exp;
List<Expression> listExp = o.getArguments();
List<C_Expression> listCExp = new ArrayList<C_Expression>();
C_Expression ex;
for (Expression serviceExp : listExp) {
ex = parse(serviceExp);
listCExp.add(ex);
}
C_And and = new C_And(listCExp);
return and;
}
private C_Expression getTextMatchSQLRegexp(Expression exp)
throws ExpressionParserException {
TextMatchSQLRegexp reg = (TextMatchSQLRegexp) exp;
C_TextMatchSQLRegexp regExp = new C_TextMatchSQLRegexp(
parse(reg.getLeftArgument()), parse(reg.getRightArgument()));
return regExp;
}
private C_Expression getTextEndWith(Expression exp)
throws ExpressionParserException {
TextEndsWith textEnd = (TextEndsWith) exp;
C_TextEndsWith textEndWith = new C_TextEndsWith(
parse(textEnd.getLeftArgument()),
parse(textEnd.getRightArgument()));
return textEndWith;
}
private C_Expression getTextContains(Expression exp)
throws ExpressionParserException {
TextContains textContains = (TextContains) exp;
C_TextContains textCont = new C_TextContains(
parse(textContains.getLeftArgument()),
parse(textContains.getRightArgument()));
return textCont;
}
private C_Expression getTextBeginWith(Expression exp)
throws ExpressionParserException {
TextBeginsWith textB = (TextBeginsWith) exp;
C_TextBeginsWith textBegins = new C_TextBeginsWith(
parse(textB.getLeftArgument()), parse(textB.getRightArgument()));
return textBegins;
}
private C_Expression getNotLess(Expression exp)
throws ExpressionParserException {
NotLess notL = (NotLess) exp;
C_NotLess notLess = new C_NotLess(parse(notL.getLeftArgument()),
parse(notL.getRightArgument()));
return notLess;
}
private C_Expression getNotGreater(Expression exp)
throws ExpressionParserException {
NotGreater notG = (NotGreater) exp;
C_NotGreater notGreater = new C_NotGreater(
parse(notG.getLeftArgument()), parse(notG.getRightArgument()));
return notGreater;
}
private C_Expression getNotEquals(Expression exp)
throws ExpressionParserException {
NotEquals notE = (NotEquals) exp;
C_NotEquals notEquals = new C_NotEquals(parse(notE.getLeftArgument()),
parse(notE.getRightArgument()));
return notEquals;
}
private C_Expression getLessThan(Expression exp)
throws ExpressionParserException {
LessThan lessT = (LessThan) exp;
C_LessThan lessThan = new C_LessThan(parse(lessT.getLeftArgument()),
parse(lessT.getRightArgument()));
return lessThan;
}
private C_Expression getLessOrEquals(Expression exp)
throws ExpressionParserException {
LessOrEquals lessOrE = (LessOrEquals) exp;
C_LessOrEquals lessOrEquals = new C_LessOrEquals(
parse(lessOrE.getLeftArgument()),
parse(lessOrE.getRightArgument()));
return lessOrEquals;
}
private C_Expression getGreaterThan(Expression exp)
throws ExpressionParserException {
GreaterThan greaterThan = (GreaterThan) exp;
C_GreaterThan greater = new C_GreaterThan(
parse(greaterThan.getLeftArgument()),
parse(greaterThan.getRightArgument()));
return greater;
}
private C_Expression getGreaterOrEquals(Expression exp)
throws ExpressionParserException {
GreaterOrEquals greaterOrEq = (GreaterOrEquals) exp;
C_GreaterOrEquals greaterOrEquals = new C_GreaterOrEquals(
parse(greaterOrEq.getLeftArgument()),
parse(greaterOrEq.getRightArgument()));
return greaterOrEquals;
}
private TD_Value getExpressionValue(TDTypeValue value)
throws ExpressionParserException {
try {
if (value instanceof TDBoolean) {
TDBoolean tdboolean = (TDBoolean) value;
return new TD_Value(ColumnDataType.Boolean,
String.valueOf(tdboolean.getValue()));
}
if (value instanceof TDDate) {
TDDate tddate = (TDDate) value;
return new TD_Value(ColumnDataType.Date, sdf.format(tddate
.getValue()));
}
if (value instanceof TDGeometry) {
TDGeometry tdgeometry = (TDGeometry) value;
return new TD_Value(ColumnDataType.Geometry,
tdgeometry.getValue());
}
if (value instanceof TDInteger) {
TDInteger tdinteger = (TDInteger) value;
return new TD_Value(ColumnDataType.Integer,
String.valueOf(tdinteger.getValue()));
}
if (value instanceof TDNumeric) {
TDNumeric tdnumeric = (TDNumeric) value;
return new TD_Value(ColumnDataType.Numeric,
String.valueOf(tdnumeric.getValue()));
}
if (value instanceof TDText) {
TDText tdtext = (TDText) value;
return new TD_Value(ColumnDataType.Text, String.valueOf(tdtext
.getValue()));
}
} catch (Throwable e) {
logger.error("type error parsing value " + value + " "
+ e.getLocalizedMessage());
}
return null;
}
private ColumnDataType mapColumnDataType(DataType columnDataType) {
if (columnDataType instanceof IntegerType) {
return ColumnDataType.Integer;
} else {
if (columnDataType instanceof NumericType) {
return ColumnDataType.Numeric;
} else {
if (columnDataType instanceof BooleanType) {
return ColumnDataType.Boolean;
} else {
if (columnDataType instanceof GeometryType) {
return ColumnDataType.Geometry;
} else {
if (columnDataType instanceof TextType) {
return ColumnDataType.Text;
} else {
if (columnDataType instanceof DateType) {
return ColumnDataType.Date;
} else {
return null;
}
}
}
}
}
}
}
private C_Expression getConstantList(Expression exp)
throws ExpressionParserException {
List<TD_Value> l = new ArrayList<TD_Value>();
ConstantList c = (ConstantList) exp;
List<TDTypeValue> arguments = c.getArguments();
TD_Value tdv;
for (TDTypeValue value : arguments) {
tdv = getExpressionValue(value);
l.add(tdv);
}
C_ConstantList constList = new C_ConstantList(l);
return constList;
}
private C_MultivaluedExpression getConstantList(ConstantList c)
throws ExpressionParserException {
List<TD_Value> l = new ArrayList<TD_Value>();
List<TDTypeValue> arguments = c.getArguments();
TD_Value tdv;
for (TDTypeValue value : arguments) {
tdv = getExpressionValue(value);
l.add(tdv);
}
C_ConstantList constList = new C_ConstantList(l);
return constList;
}
private C_Expression getColumnReferencePlaceholder(Expression exp) {
ColumnReferencePlaceholder c = (ColumnReferencePlaceholder) exp;
C_ColumnReferencePlaceholder col = new C_ColumnReferencePlaceholder(
mapColumnDataType(c.getDatatype()), c.getId());
return col;
}
private C_Expression getRange(Expression exp)
throws ExpressionParserException {
Range c = (Range) exp;
C_Range range = new C_Range(getExpressionValue(c.getMinimum()),
getExpressionValue(c.getMaximum()));
return range;
}
private C_MultivaluedExpression getRange(Range range)
throws ExpressionParserException {
C_Range r = new C_Range(getExpressionValue(range.getMinimum()),
getExpressionValue(range.getMaximum()));
return r;
}
private C_Expression getColumnReference(Expression exp) {
ColumnReference c = (ColumnReference) exp;
String tableId = String.valueOf(c.getTableId().getValue());
String columnId = c.getColumnId().getValue();
ColumnDataType columnDataType = mapColumnDataType(c.getType());
TRId trId = new TRId();
trId.setTableId(tableId);
trId.setViewTable(false);
C_ColumnReference ref = new C_ColumnReference(trId, columnDataType,
columnId);
return ref;
}
private C_Expression getUpper(Expression exp)
throws ExpressionParserException {
Upper e = (Upper) exp;
C_Expression arg = parse(e.getArgument());
C_Upper upper = new C_Upper(arg);
return upper;
}
private C_Expression getLower(Expression exp)
throws ExpressionParserException {
Lower e = (Lower) exp;
C_Expression arg = parse(e.getArgument());
C_Lower lower = new C_Lower(arg);
return lower;
}
private C_Expression getTrim(Expression exp)
throws ExpressionParserException {
Trim e = (Trim) exp;
C_Expression arg = parse(e.getArgument());
C_Trim trim = new C_Trim(arg);
return trim;
}
private C_Expression getMD5(Expression exp)
throws ExpressionParserException {
MD5 e = (MD5) exp;
C_Expression arg = parse(e.getArgument());
C_MD5 md5 = new C_MD5(arg);
return md5;
}
private C_Expression getSoundex(Expression exp)
throws ExpressionParserException {
Soundex e = (Soundex) exp;
C_Expression arg = parse(e.getArgument());
C_Soundex soundex = new C_Soundex(arg);
return soundex;
}
private C_Expression getLevenshtein(Expression exp)
throws ExpressionParserException {
Levenshtein e = (Levenshtein) exp;
C_Expression left = parse(e.getLeftArgument());
C_Expression right = parse(e.getRightArgument());
C_Levenshtein levenshtein = new C_Levenshtein(left, right);
return levenshtein;
}
private C_Expression getSimilarity(Expression exp)
throws ExpressionParserException {
Similarity e = (Similarity) exp;
C_Expression left = parse(e.getLeftArgument());
C_Expression right = parse(e.getRightArgument());
C_Similarity similarity = new C_Similarity(left, right);
return similarity;
}
private C_Expression getEquals(Expression exp)
throws ExpressionParserException {
Equals e = (Equals) exp;
C_Expression left = parse(e.getLeftArgument());
C_Expression right = parse(e.getRightArgument());
C_Equals eq = new C_Equals(left, right);
return eq;
}
private C_Expression getConcat(Expression exp)
throws ExpressionParserException {
Concat concat = (Concat) exp;
C_Concat conc = new C_Concat(parse(concat.getLeftArgument()),
parse(concat.getRightArgument()));
return conc;
}
private C_Expression getSubstringByIndex(Expression exp)
throws ExpressionParserException {
SubstringByIndex subByIndex = (SubstringByIndex) exp;
C_SubstringByIndex sByIndex = new C_SubstringByIndex(
parse(subByIndex.getSourceString()),
parse(subByIndex.getFromIndex()),
parse(subByIndex.getToIndex()));
return sByIndex;
}
private C_Expression getSubstringByRegex(Expression exp)
throws ExpressionParserException {
SubstringByRegex subByRegex = (SubstringByRegex) exp;
C_SubstringByRegex sByRegex = new C_SubstringByRegex(
parse(subByRegex.getLeftArgument()),
parse(subByRegex.getRightArgument()));
return sByRegex;
}
private C_Expression getSubstringPosition(Expression exp)
throws ExpressionParserException {
SubstringPosition subPosition = (SubstringPosition) exp;
C_SubstringPosition sPosition = new C_SubstringPosition(
parse(subPosition.getLeftArgument()),
parse(subPosition.getRightArgument()));
return sPosition;
}
private C_Expression getTextReplaceMatchingRegex(Expression exp)
throws ExpressionParserException {
TextReplaceMatchingRegex textReplaceMatchingRegex = (TextReplaceMatchingRegex) exp;
TD_Value replacing = getExpressionValue(textReplaceMatchingRegex
.getReplacingValue());
TD_Value regexp = getExpressionValue(textReplaceMatchingRegex
.getRegexp());
C_Expression toCheckText = parse(textReplaceMatchingRegex
.getToCheckText());
C_TextReplaceMatchingRegex textRepRegex = new C_TextReplaceMatchingRegex(
toCheckText, regexp, replacing);
return textRepRegex;
}
private C_Expression getAvg(Expression exp)
throws ExpressionParserException {
Avg avg = (Avg) exp;
C_Avg av = new C_Avg(parse(avg.getArgument()));
return av;
}
private C_Expression getCount(Expression exp)
throws ExpressionParserException {
Count count = (Count) exp;
C_Count cnt = new C_Count(parse(count.getArgument()));
return cnt;
}
private C_Expression getMax(Expression exp)
throws ExpressionParserException {
Max max = (Max) exp;
C_Max ma = new C_Max(parse(max.getArgument()));
return ma;
}
private C_Expression getMin(Expression exp)
throws ExpressionParserException {
Min min = (Min) exp;
C_Min mi = new C_Min(parse(min.getArgument()));
return mi;
}
private C_Expression getSTExtent(Expression exp)
throws ExpressionParserException {
ST_Extent stExtent = (ST_Extent) exp;
C_ST_Extent stEx = new C_ST_Extent(parse(stExtent.getArgument()));
return stEx;
}
private C_Expression getSum(Expression exp)
throws ExpressionParserException {
Sum sum = (Sum) exp;
C_Sum sm = new C_Sum(parse(sum.getArgument()));
return sm;
}
private C_Expression getCast(Expression exp)
throws ExpressionParserException {
Cast castExp = (Cast) exp;
C_Cast sm = new C_Cast(parse(castExp.getArgument()),
mapColumnDataType(castExp.getCastToType()));
return sm;
}
private C_Expression getAddition(Expression exp)
throws ExpressionParserException {
Addition addition = (Addition) exp;
C_Addition add = new C_Addition(parse(addition.getLeftArgument()),
parse(addition.getRightArgument()));
return add;
}
private C_Expression getSubtraction(Expression exp)
throws ExpressionParserException {
Subtraction subtraction = (Subtraction) exp;
C_Subtraction sub = new C_Subtraction(
parse(subtraction.getLeftArgument()),
parse(subtraction.getRightArgument()));
return sub;
}
private C_Expression getModulus(Expression exp)
throws ExpressionParserException {
Modulus modulus = (Modulus) exp;
C_Modulus modu = new C_Modulus(parse(modulus.getLeftArgument()),
parse(modulus.getRightArgument()));
return modu;
}
private C_Expression getMultiplication(Expression exp)
throws ExpressionParserException {
Multiplication multiplication = (Multiplication) exp;
C_Multiplication multi = new C_Multiplication(
parse(multiplication.getLeftArgument()),
parse(multiplication.getRightArgument()));
return multi;
}
private C_Expression getDivision(Expression exp)
throws ExpressionParserException {
Division division = (Division) exp;
C_Division divi = new C_Division(parse(division.getLeftArgument()),
parse(division.getRightArgument()));
return divi;
}
/**
*
* @param exp
* @return
* @throws ExpressionParserException
*/
public Expression parse(C_Expression exp) throws ExpressionParserException { public Expression parse(C_Expression exp) throws ExpressionParserException {
logger.debug("Parse: " + exp); logger.debug("Parse: " + exp);
Expression ex = null; Expression ex = null;
@ -472,7 +1287,7 @@ public class C_ExpressionParser {
} }
protected TDTypeValue getExpressionValue(TD_Value value) private TDTypeValue getExpressionValue(TD_Value value)
throws ExpressionParserException { throws ExpressionParserException {
TDTypeValue ex = null; TDTypeValue ex = null;
@ -537,7 +1352,7 @@ public class C_ExpressionParser {
return ex; return ex;
} }
protected DataType mapColumnDataType(ColumnDataType columnDataType) { private DataType mapColumnDataType(ColumnDataType columnDataType) {
if (columnDataType == ColumnDataType.Integer) { if (columnDataType == ColumnDataType.Integer) {
return new IntegerType(); return new IntegerType();
} else { } else {
@ -565,7 +1380,7 @@ public class C_ExpressionParser {
} }
} }
protected Expression getConstantlist(C_Expression exp) private Expression getConstantlist(C_Expression exp)
throws ExpressionParserException { throws ExpressionParserException {
List<TDTypeValue> l = new ArrayList<TDTypeValue>(); List<TDTypeValue> l = new ArrayList<TDTypeValue>();
C_ConstantList c = (C_ConstantList) exp; C_ConstantList c = (C_ConstantList) exp;
@ -579,7 +1394,7 @@ public class C_ExpressionParser {
return constList; return constList;
} }
protected MultivaluedExpression getConstantlist(C_MultivaluedExpression exp) private MultivaluedExpression getConstantlist(C_MultivaluedExpression exp)
throws ExpressionParserException { throws ExpressionParserException {
List<TDTypeValue> l = new ArrayList<TDTypeValue>(); List<TDTypeValue> l = new ArrayList<TDTypeValue>();
C_ConstantList c = (C_ConstantList) exp; C_ConstantList c = (C_ConstantList) exp;
@ -593,14 +1408,14 @@ public class C_ExpressionParser {
return constList; return constList;
} }
protected Expression getColumnReferencePlaceholder(C_Expression exp) { private Expression getColumnReferencePlaceholder(C_Expression exp) {
C_ColumnReferencePlaceholder c = (C_ColumnReferencePlaceholder) exp; C_ColumnReferencePlaceholder c = (C_ColumnReferencePlaceholder) exp;
ColumnReferencePlaceholder col = new ColumnReferencePlaceholder( ColumnReferencePlaceholder col = new ColumnReferencePlaceholder(
mapColumnDataType(c.getDataType()), c.getColumnId()); mapColumnDataType(c.getDataType()), c.getColumnId());
return col; return col;
} }
protected Expression getRange(C_Expression exp) private Expression getRange(C_Expression exp)
throws ExpressionParserException { throws ExpressionParserException {
C_Range c = (C_Range) exp; C_Range c = (C_Range) exp;
Range range = new Range(getExpressionValue(c.getMinimum()), Range range = new Range(getExpressionValue(c.getMinimum()),
@ -608,7 +1423,7 @@ public class C_ExpressionParser {
return range; return range;
} }
protected MultivaluedExpression getRange(C_MultivaluedExpression exp) private MultivaluedExpression getRange(C_MultivaluedExpression exp)
throws ExpressionParserException { throws ExpressionParserException {
C_Range c = (C_Range) exp; C_Range c = (C_Range) exp;
Range range = new Range(getExpressionValue(c.getMinimum()), Range range = new Range(getExpressionValue(c.getMinimum()),
@ -616,7 +1431,7 @@ public class C_ExpressionParser {
return range; return range;
} }
protected Expression getColumnReference(C_Expression exp) { private Expression getColumnReference(C_Expression exp) {
C_ColumnReference c = (C_ColumnReference) exp; C_ColumnReference c = (C_ColumnReference) exp;
String tableIdS = null; String tableIdS = null;
if (c.getTrId().isViewTable()) { if (c.getTrId().isViewTable()) {
@ -632,7 +1447,7 @@ public class C_ExpressionParser {
return ref; return ref;
} }
protected Expression getUpper(C_Expression exp) private Expression getUpper(C_Expression exp)
throws ExpressionParserException { throws ExpressionParserException {
C_Upper e = (C_Upper) exp; C_Upper e = (C_Upper) exp;
Expression arg = parse(e.getArgument()); Expression arg = parse(e.getArgument());
@ -640,7 +1455,7 @@ public class C_ExpressionParser {
return upper; return upper;
} }
protected Expression getLower(C_Expression exp) private Expression getLower(C_Expression exp)
throws ExpressionParserException { throws ExpressionParserException {
C_Lower e = (C_Lower) exp; C_Lower e = (C_Lower) exp;
Expression arg = parse(e.getArgument()); Expression arg = parse(e.getArgument());
@ -648,7 +1463,7 @@ public class C_ExpressionParser {
return lower; return lower;
} }
protected Expression getTrim(C_Expression exp) private Expression getTrim(C_Expression exp)
throws ExpressionParserException { throws ExpressionParserException {
C_Trim e = (C_Trim) exp; C_Trim e = (C_Trim) exp;
Expression arg = parse(e.getArgument()); Expression arg = parse(e.getArgument());
@ -656,7 +1471,7 @@ public class C_ExpressionParser {
return trim; return trim;
} }
protected Expression getMD5(C_Expression exp) private Expression getMD5(C_Expression exp)
throws ExpressionParserException { throws ExpressionParserException {
C_MD5 e = (C_MD5) exp; C_MD5 e = (C_MD5) exp;
Expression arg = parse(e.getArgument()); Expression arg = parse(e.getArgument());
@ -664,7 +1479,7 @@ public class C_ExpressionParser {
return md5; return md5;
} }
protected Expression getSoundex(C_Expression exp) private Expression getSoundex(C_Expression exp)
throws ExpressionParserException { throws ExpressionParserException {
C_Soundex e = (C_Soundex) exp; C_Soundex e = (C_Soundex) exp;
Expression arg = parse(e.getArgument()); Expression arg = parse(e.getArgument());
@ -672,7 +1487,7 @@ public class C_ExpressionParser {
return soundex; return soundex;
} }
protected Expression getLevenshtein(C_Expression exp) private Expression getLevenshtein(C_Expression exp)
throws ExpressionParserException { throws ExpressionParserException {
C_Levenshtein e = (C_Levenshtein) exp; C_Levenshtein e = (C_Levenshtein) exp;
Expression left = parse(e.getLeftArgument()); Expression left = parse(e.getLeftArgument());
@ -682,7 +1497,7 @@ public class C_ExpressionParser {
return levenshtein; return levenshtein;
} }
protected Expression getSimilarity(C_Expression exp) private Expression getSimilarity(C_Expression exp)
throws ExpressionParserException { throws ExpressionParserException {
C_Similarity e = (C_Similarity) exp; C_Similarity e = (C_Similarity) exp;
Expression left = parse(e.getLeftArgument()); Expression left = parse(e.getLeftArgument());
@ -692,9 +1507,7 @@ public class C_ExpressionParser {
return similarity; return similarity;
} }
private Expression getEquals(C_Expression exp)
protected Expression getEquals(C_Expression exp)
throws ExpressionParserException { throws ExpressionParserException {
C_Equals e = (C_Equals) exp; C_Equals e = (C_Equals) exp;
Expression left = parse(e.getLeftArgument()); Expression left = parse(e.getLeftArgument());

View File

@ -1,12 +1,15 @@
package org.gcube.portlets.user.td.expressionwidget.server; package org.gcube.portlets.user.td.expressionwidget.server;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpSession; import javax.servlet.http.HttpSession;
import org.gcube.application.framework.core.session.ASLSession; import org.gcube.application.framework.core.session.ASLSession;
import org.gcube.data.analysis.tabulardata.commons.utils.AuthorizationProvider; import org.gcube.data.analysis.tabulardata.commons.utils.AuthorizationProvider;
import org.gcube.data.analysis.tabulardata.commons.utils.AuthorizationToken; import org.gcube.data.analysis.tabulardata.commons.utils.AuthorizationToken;
import org.gcube.data.analysis.tabulardata.commons.webservice.types.RuleDescription;
import org.gcube.data.analysis.tabulardata.expression.Expression; import org.gcube.data.analysis.tabulardata.expression.Expression;
import org.gcube.data.analysis.tabulardata.model.metadata.table.DatasetViewTableMetadata; import org.gcube.data.analysis.tabulardata.model.metadata.table.DatasetViewTableMetadata;
import org.gcube.data.analysis.tabulardata.model.table.Table; import org.gcube.data.analysis.tabulardata.model.table.Table;
@ -15,8 +18,11 @@ 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.TabularResource;
import org.gcube.data.analysis.tabulardata.service.tabular.TabularResourceId; 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.client.rpc.ExpressionService;
import org.gcube.portlets.user.td.expressionwidget.server.service.RuleScopeMap;
import org.gcube.portlets.user.td.expressionwidget.shared.exception.ExpressionParserException; 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.expressionwidget.shared.exception.ExpressionServiceException;
import org.gcube.portlets.user.td.expressionwidget.shared.rule.RuleDescriptionData;
import org.gcube.portlets.user.td.expressionwidget.shared.rule.RuleScopeType;
import org.gcube.portlets.user.td.gwtservice.server.SessionUtil; import org.gcube.portlets.user.td.gwtservice.server.SessionUtil;
import org.gcube.portlets.user.td.gwtservice.server.TDGWTServiceImpl; import org.gcube.portlets.user.td.gwtservice.server.TDGWTServiceImpl;
import org.gcube.portlets.user.td.gwtservice.server.trservice.TabularResourceTypeMap; import org.gcube.portlets.user.td.gwtservice.server.trservice.TabularResourceTypeMap;
@ -26,6 +32,7 @@ import org.gcube.portlets.user.td.gwtservice.shared.tr.column.AddColumnSession;
import org.gcube.portlets.user.td.gwtservice.shared.tr.column.FilterColumnSession; import org.gcube.portlets.user.td.gwtservice.shared.tr.column.FilterColumnSession;
import org.gcube.portlets.user.td.gwtservice.shared.tr.column.ReplaceColumnByExpressionSession; import org.gcube.portlets.user.td.gwtservice.shared.tr.column.ReplaceColumnByExpressionSession;
import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId; import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId;
import org.gcube.portlets.user.td.widgetcommonevent.shared.expression.C_Expression;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -206,6 +213,57 @@ public class ExpressionServiceImpl extends RemoteServiceServlet implements
} }
} }
//TODO
public ArrayList<RuleDescriptionData> getRule(RuleScopeType scope) throws TDGWTServiceException {
try {
HttpSession session = this.getThreadLocalRequest().getSession();
ASLSession aslSession = SessionUtil.getAslSession(session);
logger.debug("GetRule()");
AuthorizationProvider.instance.set(new AuthorizationToken(
aslSession.getUsername(), aslSession.getScope()));
TabularDataService service = TabularDataServiceFactory.getService();
service.getRules();
List<RuleDescription> rules=service.getRulesByScope(RuleScopeMap.map(scope));
ArrayList<RuleDescriptionData> rulesDes=new ArrayList<RuleDescriptionData>();
C_ExpressionParser parser = new C_ExpressionParser();
for(RuleDescription ruleDescription: rules){
Expression serviceExpression=ruleDescription.getRule();
C_Expression cexp=parser.parse(serviceExpression);
RuleDescriptionData ruleData=new RuleDescriptionData(ruleDescription.getId(),
ruleDescription.getName(), ruleDescription.getDescription(),
RuleScopeMap.map(ruleDescription.getScope()),
cexp);
rulesDes.add(ruleData);
}
return rulesDes;
} catch (TDGWTServiceException e) {
logger.error(e.getLocalizedMessage(),e);
throw e;
} catch (SecurityException e) {
logger.error(e.getLocalizedMessage(),e);
throw e;
} catch (Throwable e) {
logger.error(
"Error in getRule(): " + e.getLocalizedMessage(),
e);
throw new TDGWTServiceException("Error retrieving the rules: "
+ e.getLocalizedMessage());
}
}
/** /**
* Retrieve and set Tabular Resource Type * Retrieve and set Tabular Resource Type
* *

View File

@ -0,0 +1,46 @@
package org.gcube.portlets.user.td.expressionwidget.server.service;
import org.gcube.data.analysis.tabulardata.commons.rules.RuleScope;
import org.gcube.portlets.user.td.expressionwidget.shared.rule.RuleScopeType;
/**
*
* @author "Giancarlo Panichi"
* <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class RuleScopeMap {
public static RuleScopeType map(RuleScope ruleScope) {
if(ruleScope==null){
return null;
}
switch (ruleScope) {
case COLUMN:
return RuleScopeType.COLUMN;
case TABLE:
return RuleScopeType.TABLE;
default:
return null;
}
}
public static RuleScope map(RuleScopeType ruleScopeType) {
if(ruleScopeType==null){
return null;
}
switch (ruleScopeType) {
case COLUMN:
return RuleScope.COLUMN;
case TABLE:
return RuleScope.TABLE;
default:
return null;
}
}
}

View File

@ -1,11 +1,11 @@
package org.gcube.portlets.user.td.expressionwidget.shared.model.composite; package org.gcube.portlets.user.td.expressionwidget.shared.model.composite;
import org.gcube.portlets.user.td.expressionwidget.shared.expression.C_MultivaluedExpression; import org.gcube.portlets.user.td.expressionwidget.shared.expression.C_MultivaluedExpression;
import org.gcube.portlets.user.td.expressionwidget.shared.model.leaf.C_Leaf; import org.gcube.portlets.user.td.expressionwidget.shared.model.leaf.C_Leaf;
import org.gcube.portlets.user.td.widgetcommonevent.shared.expression.C_Expression; import org.gcube.portlets.user.td.widgetcommonevent.shared.expression.C_Expression;
public class C_ExternalReferenceExpression extends C_Expression implements C_MultivaluedExpression{ public class C_ExternalReferenceExpression extends C_Expression implements
C_MultivaluedExpression {
private static final long serialVersionUID = 1260894239836974010L; private static final long serialVersionUID = 1260894239836974010L;
protected C_Leaf leftArgument; protected C_Leaf leftArgument;
@ -13,17 +13,19 @@ public class C_ExternalReferenceExpression extends C_Expression implements C_Mul
protected String id = "ExternalReferenceExpression"; protected String id = "ExternalReferenceExpression";
public C_ExternalReferenceExpression() { public C_ExternalReferenceExpression() {
} }
public C_ExternalReferenceExpression(C_Leaf leftArgument, C_Expression rightArgument) { public C_ExternalReferenceExpression(C_Leaf leftArgument,
C_Expression rightArgument) {
this.leftArgument = leftArgument; this.leftArgument = leftArgument;
this.rightArgument = rightArgument; this.rightArgument = rightArgument;
this.readableExpression = "ExternalReferenceExpression("
+ leftArgument.getReadableExpression() + ","
+ rightArgument.getReadableExpression() + ")";
} }
@Override @Override
public String getId() { public String getId() {
return id; return id;
@ -52,12 +54,8 @@ public class C_ExternalReferenceExpression extends C_Expression implements C_Mul
@Override @Override
public String toString() { public String toString() {
return "ExternalReferenceExpression [ id=" + id+", leftArgument=" + leftArgument return "ExternalReferenceExpression [ id=" + id + ", leftArgument="
+ ", rightArgument=" + rightArgument + "]"; + leftArgument + ", rightArgument=" + rightArgument + "]";
} }
} }

View File

@ -22,6 +22,9 @@ public class C_AggregationExpression extends C_Expression {
public C_AggregationExpression(C_Expression argument) { public C_AggregationExpression(C_Expression argument) {
this.argument = argument; this.argument = argument;
this.readableExpression = "AggregationExpression("
+ argument.getReadableExpression() + ")";
} }
@Override @Override

View File

@ -24,6 +24,8 @@ public class C_Avg extends C_AggregationExpression {
*/ */
public C_Avg(C_Expression argument) { public C_Avg(C_Expression argument) {
this.argument = argument; this.argument = argument;
this.readableExpression = "AVG("
+ argument.getReadableExpression() + ")";
} }

View File

@ -24,7 +24,8 @@ public class C_Count extends C_AggregationExpression {
*/ */
public C_Count(C_Expression argument) { public C_Count(C_Expression argument) {
this.argument = argument; this.argument = argument;
this.readableExpression = "Count("
+ argument.getReadableExpression() + ")";
} }
public C_OperatorType getOperator() { public C_OperatorType getOperator() {

View File

@ -24,7 +24,8 @@ public class C_Max extends C_AggregationExpression {
*/ */
public C_Max(C_Expression argument) { public C_Max(C_Expression argument) {
this.argument = argument; this.argument = argument;
this.readableExpression = "Max("
+ argument.getReadableExpression() + ")";
} }
public C_OperatorType getOperator() { public C_OperatorType getOperator() {

View File

@ -24,7 +24,8 @@ public class C_Min extends C_AggregationExpression {
*/ */
public C_Min(C_Expression argument) { public C_Min(C_Expression argument) {
this.argument = argument; this.argument = argument;
this.readableExpression = "Min("
+ argument.getReadableExpression() + ")";
} }
public C_OperatorType getOperator() { public C_OperatorType getOperator() {

View File

@ -23,6 +23,8 @@ public class C_ST_Extent extends C_AggregationExpression {
*/ */
public C_ST_Extent(C_Expression argument) { public C_ST_Extent(C_Expression argument) {
this.argument = argument; this.argument = argument;
this.readableExpression = "ST_Extent("
+ argument.getReadableExpression() + ")";
} }
public C_OperatorType getOperator() { public C_OperatorType getOperator() {

View File

@ -24,7 +24,8 @@ public class C_Sum extends C_AggregationExpression {
*/ */
public C_Sum(C_Expression argument) { public C_Sum(C_Expression argument) {
this.argument = argument; this.argument = argument;
this.readableExpression = "Sum("
+ argument.getReadableExpression() + ")";
} }
public C_OperatorType getOperator() { public C_OperatorType getOperator() {

View File

@ -23,6 +23,9 @@ public class C_Addition extends C_ArithmeticExpression {
public C_Addition(C_Expression leftArgument, C_Expression rightArgument) { public C_Addition(C_Expression leftArgument, C_Expression rightArgument) {
this.leftArgument = leftArgument; this.leftArgument = leftArgument;
this.rightArgument = rightArgument; this.rightArgument = rightArgument;
this.readableExpression = "Addition("
+ leftArgument.getReadableExpression() + ","
+ rightArgument.getReadableExpression() + ")";
} }
public C_OperatorType getOperator() { public C_OperatorType getOperator() {

View File

@ -30,6 +30,9 @@ public class C_ArithmeticExpression extends C_Expression {
C_Expression rightArgument) { C_Expression rightArgument) {
this.leftArgument = leftArgument; this.leftArgument = leftArgument;
this.rightArgument = rightArgument; this.rightArgument = rightArgument;
this.readableExpression = "ArithmeticExpression("
+ leftArgument.getReadableExpression() + ","
+ rightArgument.getReadableExpression() + ")";
} }
static { static {

View File

@ -22,6 +22,9 @@ public class C_Division extends C_ArithmeticExpression {
public C_Division(C_Expression leftArgument, C_Expression rightArgument) { public C_Division(C_Expression leftArgument, C_Expression rightArgument) {
this.leftArgument = leftArgument; this.leftArgument = leftArgument;
this.rightArgument = rightArgument; this.rightArgument = rightArgument;
this.readableExpression = "Division("
+ leftArgument.getReadableExpression() + ","
+ rightArgument.getReadableExpression() + ")";
} }
public C_OperatorType getOperator() { public C_OperatorType getOperator() {

View File

@ -27,6 +27,9 @@ public class C_Exponentiation extends C_ArithmeticExpression {
public C_Exponentiation(C_Expression leftArgument, C_Expression rightArgument) { public C_Exponentiation(C_Expression leftArgument, C_Expression rightArgument) {
this.leftArgument = leftArgument; this.leftArgument = leftArgument;
this.rightArgument = rightArgument; this.rightArgument = rightArgument;
this.readableExpression = "Exponentiation("
+ leftArgument.getReadableExpression() + ","
+ rightArgument.getReadableExpression() + ")";
} }

View File

@ -22,6 +22,9 @@ public class C_Modulus extends C_ArithmeticExpression {
public C_Modulus(C_Expression leftArgument, C_Expression rightArgument) { public C_Modulus(C_Expression leftArgument, C_Expression rightArgument) {
this.leftArgument = leftArgument; this.leftArgument = leftArgument;
this.rightArgument = rightArgument; this.rightArgument = rightArgument;
this.readableExpression = "Modulus("
+ leftArgument.getReadableExpression() + ","
+ rightArgument.getReadableExpression() + ")";
} }
public C_OperatorType getOperator() { public C_OperatorType getOperator() {

View File

@ -22,6 +22,9 @@ public class C_Multiplication extends C_ArithmeticExpression {
public C_Multiplication(C_Expression leftArgument, C_Expression rightArgument) { public C_Multiplication(C_Expression leftArgument, C_Expression rightArgument) {
this.leftArgument = leftArgument; this.leftArgument = leftArgument;
this.rightArgument = rightArgument; this.rightArgument = rightArgument;
this.readableExpression = "Multiplication("
+ leftArgument.getReadableExpression() + ","
+ rightArgument.getReadableExpression() + ")";
} }
public C_OperatorType getOperator() { public C_OperatorType getOperator() {

View File

@ -23,6 +23,9 @@ public class C_Subtraction extends C_ArithmeticExpression {
public C_Subtraction(C_Expression leftArgument, C_Expression rightArgument) { public C_Subtraction(C_Expression leftArgument, C_Expression rightArgument) {
this.leftArgument = leftArgument; this.leftArgument = leftArgument;
this.rightArgument = rightArgument; this.rightArgument = rightArgument;
this.readableExpression = "Subtraction("
+ leftArgument.getReadableExpression() + ","
+ rightArgument.getReadableExpression() + ")";
} }
public C_OperatorType getOperator() { public C_OperatorType getOperator() {

View File

@ -23,6 +23,9 @@ public class C_Equals extends C_Expression {
public C_Equals(C_Expression leftArgument, C_Expression rightArgument) { public C_Equals(C_Expression leftArgument, C_Expression rightArgument) {
this.leftArgument = leftArgument; this.leftArgument = leftArgument;
this.rightArgument = rightArgument; this.rightArgument = rightArgument;
this.readableExpression = "Equals("
+ leftArgument.getReadableExpression() + ","
+ rightArgument.getReadableExpression() + ")";
} }
public C_OperatorType getOperator() { public C_OperatorType getOperator() {

View File

@ -24,6 +24,9 @@ public class C_GreaterOrEquals extends C_Expression {
C_Expression rightArgument) { C_Expression rightArgument) {
this.leftArgument = leftArgument; this.leftArgument = leftArgument;
this.rightArgument = rightArgument; this.rightArgument = rightArgument;
this.readableExpression = "GreaterOrEquals("
+ leftArgument.getReadableExpression() + ","
+ rightArgument.getReadableExpression() + ")";
} }
public C_OperatorType getOperator() { public C_OperatorType getOperator() {

View File

@ -22,6 +22,9 @@ public class C_GreaterThan extends C_Expression {
public C_GreaterThan(C_Expression leftArgument, C_Expression rightArgument) { public C_GreaterThan(C_Expression leftArgument, C_Expression rightArgument) {
this.leftArgument = leftArgument; this.leftArgument = leftArgument;
this.rightArgument = rightArgument; this.rightArgument = rightArgument;
this.readableExpression = "GreaterThan("
+ leftArgument.getReadableExpression() + ","
+ rightArgument.getReadableExpression() + ")";
} }
public C_OperatorType getOperator() { public C_OperatorType getOperator() {

View File

@ -22,6 +22,9 @@ public class C_LessOrEquals extends C_Expression {
public C_LessOrEquals(C_Expression leftArgument, C_Expression rightArgument) { public C_LessOrEquals(C_Expression leftArgument, C_Expression rightArgument) {
this.leftArgument = leftArgument; this.leftArgument = leftArgument;
this.rightArgument = rightArgument; this.rightArgument = rightArgument;
this.readableExpression = "LessOrEquals("
+ leftArgument.getReadableExpression() + ","
+ rightArgument.getReadableExpression() + ")";
} }
public C_OperatorType getOperator() { public C_OperatorType getOperator() {

View File

@ -22,6 +22,9 @@ public class C_LessThan extends C_Expression {
public C_LessThan(C_Expression leftArgument, C_Expression rightArgument) { public C_LessThan(C_Expression leftArgument, C_Expression rightArgument) {
this.leftArgument = leftArgument; this.leftArgument = leftArgument;
this.rightArgument = rightArgument; this.rightArgument = rightArgument;
this.readableExpression = "LessThan("
+ leftArgument.getReadableExpression() + ","
+ rightArgument.getReadableExpression() + ")";
} }
public C_OperatorType getOperator() { public C_OperatorType getOperator() {

View File

@ -22,6 +22,9 @@ public class C_NotEquals extends C_Expression {
public C_NotEquals(C_Expression leftArgument, C_Expression rightArgument) { public C_NotEquals(C_Expression leftArgument, C_Expression rightArgument) {
this.leftArgument = leftArgument; this.leftArgument = leftArgument;
this.rightArgument = rightArgument; this.rightArgument = rightArgument;
this.readableExpression = "NotEquals("
+ leftArgument.getReadableExpression() + ","
+ rightArgument.getReadableExpression() + ")";
} }
public C_OperatorType getOperator() { public C_OperatorType getOperator() {

View File

@ -22,6 +22,9 @@ public class C_NotGreater extends C_Expression {
public C_NotGreater(C_Expression leftArgument, C_Expression rightArgument) { public C_NotGreater(C_Expression leftArgument, C_Expression rightArgument) {
this.leftArgument = leftArgument; this.leftArgument = leftArgument;
this.rightArgument = rightArgument; this.rightArgument = rightArgument;
this.readableExpression = "NotGreater("
+ leftArgument.getReadableExpression() + ","
+ rightArgument.getReadableExpression() + ")";
} }
public C_OperatorType getOperator() { public C_OperatorType getOperator() {

View File

@ -22,6 +22,9 @@ public class C_NotLess extends C_Expression {
public C_NotLess(C_Expression leftArgument, C_Expression rightArgument) { public C_NotLess(C_Expression leftArgument, C_Expression rightArgument) {
this.leftArgument = leftArgument; this.leftArgument = leftArgument;
this.rightArgument = rightArgument; this.rightArgument = rightArgument;
this.readableExpression = "NotLess("
+ leftArgument.getReadableExpression() + ","
+ rightArgument.getReadableExpression() + ")";
} }
public C_OperatorType getOperator() { public C_OperatorType getOperator() {

View File

@ -27,6 +27,9 @@ public class C_Cast extends C_Expression {
super(); super();
this.leftArgument = leftArgument; this.leftArgument = leftArgument;
this.rightArgument = rightArgument; this.rightArgument = rightArgument;
this.readableExpression = "Cast("
+ leftArgument.getReadableExpression() + ","
+ rightArgument.getColumnDataTypeLabel() + ")";
} }
public C_OperatorType getOperator() { public C_OperatorType getOperator() {

View File

@ -26,6 +26,9 @@ public class C_Concat extends C_Expression {
super(); super();
this.leftArgument = leftArgument; this.leftArgument = leftArgument;
this.rightArgument = rightArgument; this.rightArgument = rightArgument;
this.readableExpression = "Concat("
+ leftArgument.getReadableExpression() + ","
+ rightArgument.getReadableExpression() + ")";
} }
public C_OperatorType getOperator() { public C_OperatorType getOperator() {

View File

@ -20,6 +20,8 @@ public class C_Lenght extends C_Expression {
public C_Lenght(C_Expression argument) { public C_Lenght(C_Expression argument) {
this.argument=argument; this.argument=argument;
this.readableExpression = "Lenght("
+ argument.getReadableExpression() + ")";
} }

View File

@ -25,6 +25,9 @@ public class C_Levenshtein extends C_Expression {
C_Expression rightArgument) { C_Expression rightArgument) {
this.leftArgument = leftArgument; this.leftArgument = leftArgument;
this.rightArgument = rightArgument; this.rightArgument = rightArgument;
this.readableExpression = "Levenshtein("
+ leftArgument.getReadableExpression() + ","
+ rightArgument.getReadableExpression() + ")";
} }
public C_OperatorType getOperator() { public C_OperatorType getOperator() {

View File

@ -20,6 +20,8 @@ public class C_Lower extends C_Expression {
public C_Lower(C_Expression argument) { public C_Lower(C_Expression argument) {
this.argument=argument; this.argument=argument;
this.readableExpression = "Lower("
+ argument.getReadableExpression() + ")";
} }

View File

@ -20,6 +20,8 @@ public class C_MD5 extends C_Expression {
public C_MD5(C_Expression argument) { public C_MD5(C_Expression argument) {
this.argument=argument; this.argument=argument;
this.readableExpression = "MD5("
+ argument.getReadableExpression() + ")";
} }

View File

@ -25,6 +25,9 @@ public class C_Similarity extends C_Expression {
C_Expression rightArgument) { C_Expression rightArgument) {
this.leftArgument = leftArgument; this.leftArgument = leftArgument;
this.rightArgument = rightArgument; this.rightArgument = rightArgument;
this.readableExpression = "Similarity("
+ leftArgument.getReadableExpression() + ","
+ rightArgument.getReadableExpression() + ")";
} }
public C_OperatorType getOperator() { public C_OperatorType getOperator() {

View File

@ -20,6 +20,8 @@ public class C_Soundex extends C_Expression {
public C_Soundex(C_Expression argument) { public C_Soundex(C_Expression argument) {
this.argument=argument; this.argument=argument;
this.readableExpression = "Soundex("
+ argument.getReadableExpression() + ")";
} }

View File

@ -28,6 +28,13 @@ public class C_SubstringByIndex extends C_Expression {
this.sourceString = sourceString; this.sourceString = sourceString;
this.fromIndex=fromIndex; this.fromIndex=fromIndex;
this.toIndex=toIndex; this.toIndex=toIndex;
this.readableExpression = "SubstringByIndex("
+ sourceString.getReadableExpression() + ","
+ fromIndex.getReadableExpression() + ","
+ toIndex.getReadableExpression() + ")";
} }
public C_OperatorType getOperator() { public C_OperatorType getOperator() {

View File

@ -26,6 +26,10 @@ public class C_SubstringByRegex extends C_Expression {
super(); super();
this.sourceString = sourceString; this.sourceString = sourceString;
this.regex = regex; this.regex = regex;
this.readableExpression = "SubstringByRegex("
+ sourceString.getReadableExpression() + ","
+ regex.getReadableExpression() + ")";
} }
public C_OperatorType getOperator() { public C_OperatorType getOperator() {

View File

@ -27,6 +27,9 @@ public class C_SubstringPosition extends C_Expression {
super(); super();
this.leftArgument = leftArgument; this.leftArgument = leftArgument;
this.rightArgument = rightArgument; this.rightArgument = rightArgument;
this.readableExpression = "SubstringPosition("
+ leftArgument.getReadableExpression() + ","
+ rightArgument.getReadableExpression() + ")";
} }

View File

@ -25,6 +25,9 @@ public class C_TextBeginsWith extends C_Expression {
C_Expression rightArgument) { C_Expression rightArgument) {
this.leftArgument = leftArgument; this.leftArgument = leftArgument;
this.rightArgument = rightArgument; this.rightArgument = rightArgument;
this.readableExpression = "TextBeginsWith("
+ leftArgument.getReadableExpression() + ","
+ rightArgument.getReadableExpression() + ")";
} }
public C_OperatorType getOperator() { public C_OperatorType getOperator() {

View File

@ -22,6 +22,9 @@ public class C_TextContains extends C_Expression {
public C_TextContains(C_Expression leftArgument, C_Expression rightArgument) { public C_TextContains(C_Expression leftArgument, C_Expression rightArgument) {
this.leftArgument = leftArgument; this.leftArgument = leftArgument;
this.rightArgument = rightArgument; this.rightArgument = rightArgument;
this.readableExpression = "TextContains("
+ leftArgument.getReadableExpression() + ","
+ rightArgument.getReadableExpression() + ")";
} }
public C_OperatorType getOperator() { public C_OperatorType getOperator() {

View File

@ -22,6 +22,9 @@ public class C_TextEndsWith extends C_Expression {
public C_TextEndsWith(C_Expression leftArgument, C_Expression rightArgument) { public C_TextEndsWith(C_Expression leftArgument, C_Expression rightArgument) {
this.leftArgument = leftArgument; this.leftArgument = leftArgument;
this.rightArgument = rightArgument; this.rightArgument = rightArgument;
this.readableExpression = "TextEndsWith("
+ leftArgument.getReadableExpression() + ","
+ rightArgument.getReadableExpression() + ")";
} }
public C_OperatorType getOperator() { public C_OperatorType getOperator() {

View File

@ -23,6 +23,9 @@ public class C_TextMatchSQLRegexp extends C_Expression {
C_Expression rightArgument) { C_Expression rightArgument) {
this.leftArgument = leftArgument; this.leftArgument = leftArgument;
this.rightArgument = rightArgument; this.rightArgument = rightArgument;
this.readableExpression = "TextMatchSQLRegexp("
+ leftArgument.getReadableExpression() + ","
+ rightArgument.getReadableExpression() + ")";
} }
public C_OperatorType getOperator() { public C_OperatorType getOperator() {

View File

@ -30,6 +30,11 @@ public class C_TextReplaceMatchingRegex extends C_Expression {
this.toCheckText = toCheckText; this.toCheckText = toCheckText;
this.regexp = regexp; this.regexp = regexp;
this.replacing = replacing; this.replacing = replacing;
this.readableExpression = "TextReplaceMatchingRegex("
+ toCheckText.getReadableExpression() + ","
+ regexp.getReadableExpression() + ","
+ replacing.getReadableExpression() + ")";
} }
public C_OperatorType getOperator() { public C_OperatorType getOperator() {

View File

@ -20,6 +20,8 @@ public class C_Trim extends C_Expression {
public C_Trim(C_Expression argument) { public C_Trim(C_Expression argument) {
this.argument=argument; this.argument=argument;
this.readableExpression = "Trim("
+ argument.getReadableExpression() + ")";
} }

View File

@ -20,6 +20,8 @@ public class C_Upper extends C_Expression {
public C_Upper(C_Expression argument) { public C_Upper(C_Expression argument) {
this.argument=argument; this.argument=argument;
this.readableExpression = "Upper("
+ argument.getReadableExpression() + ")";
} }

View File

@ -20,6 +20,18 @@ public class C_ColumnReference extends C_Leaf {
this.trId = trId; this.trId = trId;
this.dataType = dataType; this.dataType = dataType;
this.columnId = columnId; this.columnId = columnId;
String tableId = "";
if (trId != null) {
if (trId.isViewTable()) {
tableId = trId.getReferenceTargetTableId();
} else {
tableId = trId.getTableId();
}
}
this.readableExpression = "ColumnReference(" + tableId + ","
+ dataType.getColumnDataTypeLabel() + "," + columnId + ")";
} }
@Override @Override
@ -27,7 +39,6 @@ public class C_ColumnReference extends C_Leaf {
return id; return id;
} }
public TRId getTrId() { public TRId getTrId() {
return trId; return trId;
} }
@ -58,7 +69,4 @@ public class C_ColumnReference extends C_Leaf {
+ ", columnId=" + columnId + ", dataType=" + dataType + "]"; + ", columnId=" + columnId + ", dataType=" + dataType + "]";
} }
} }

View File

@ -26,6 +26,8 @@ public class C_Between extends C_Expression {
this.rightArgument = rightArgument; this.rightArgument = rightArgument;
} }
public C_OperatorType getOperator() { public C_OperatorType getOperator() {
return C_OperatorType.BETWEEN; return C_OperatorType.BETWEEN;
} }

View File

@ -0,0 +1,83 @@
package org.gcube.portlets.user.td.expressionwidget.shared.rule;
import java.io.Serializable;
import org.gcube.portlets.user.td.widgetcommonevent.shared.expression.C_Expression;
/**
*
* @author "Giancarlo Panichi" <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class RuleDescriptionData implements Serializable {
private static final long serialVersionUID = 2238695825091799598L;
private long id;
private String name;
private String description;
private RuleScopeType scope;
private C_Expression expression;
public RuleDescriptionData() {
super();
}
public RuleDescriptionData(long id, String name, String description,
RuleScopeType scope, C_Expression expression) {
super();
this.id = id;
this.name = name;
this.description = description;
this.scope = scope;
this.expression = expression;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public RuleScopeType getScope() {
return scope;
}
public void setScope(RuleScopeType scope) {
this.scope = scope;
}
public C_Expression getExpression() {
return expression;
}
public void setExpression(C_Expression expression) {
this.expression = expression;
}
@Override
public String toString() {
return "RuleDescriptionData [id=" + id + ", name=" + name
+ ", description=" + description + ", scope=" + scope
+ ", expression=" + expression + "]";
}
}

View File

@ -0,0 +1,37 @@
package org.gcube.portlets.user.td.expressionwidget.shared.rule;
/**
*
* @author giancarlo email: <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public enum RuleScopeType {
TABLE("Table"), COLUMN("Column");
/**
* @param text
*/
private RuleScopeType(final String id) {
this.id = id;
}
private final String id;
@Override
public String toString() {
return id;
}
public static RuleScopeType get(String ruleScopeType) {
for(RuleScopeType ws:values()){
if(ws.id.compareTo(ruleScopeType)==0){
return ws;
}
}
return null;
}
}