Updated Replace by Expression

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-expression-widget@99999 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2014-09-17 16:45:15 +00:00
parent e6ba70d77b
commit a6704a4ecc
10 changed files with 154 additions and 8 deletions

View File

@ -42,11 +42,15 @@ public class ReplaceWidget extends SimpleContainer {
private static final String EMPTY_TEXT_FROM_INDEX = "from index...";
private static final String EMPTY_TEXT_REGEXP = "regexp...";
private static final String EMPTY_TEXT_INSERT_A_STRING = "insert a string...";
private static final String EMPTY_TEXT_REPLACE_REGEXP = "regexp...";
private static final String EMPTY_TEXT_REPLACE_REPLACING = "replacing...";
private ReplaceWidget thisCont;
protected static final String HEIGHT = "210px";
protected static final String WIDTH = "612px";
protected static final String COMBO_WIDTH = "150px";
protected FieldLabel matchLabel;
protected ToggleGroup groupMatch;
@ -197,6 +201,12 @@ public class ReplaceWidget extends SimpleContainer {
secondArg.setVisible(true);
secondArg.setEmptyText(EMPTY_TEXT_TO_STRING);
break;
case TextReplaceMatchingRegex:
firstArg.setVisible(true);
firstArg.setEmptyText(EMPTY_TEXT_REPLACE_REGEXP);
secondArg.setVisible(true);
secondArg.setEmptyText(EMPTY_TEXT_REPLACE_REPLACING);
break;
default:
break;
}
@ -288,6 +298,14 @@ public class ReplaceWidget extends SimpleContainer {
secondArg.setEmptyText(EMPTY_TEXT_TO_STRING);
removeConcat(source);
break;
case TextReplaceMatchingRegex:
comboReplaceElementsLeaf.setVisible(false);
firstArg.setVisible(true);
firstArg.setEmptyText(EMPTY_TEXT_REPLACE_REGEXP);
secondArg.setVisible(true);
secondArg.setEmptyText(EMPTY_TEXT_REPLACE_REPLACING);
removeConcat(source);
break;
default:
break;
}
@ -392,6 +410,12 @@ public class ReplaceWidget extends SimpleContainer {
secondArg.setVisible(true);
secondArg.setEmptyText(EMPTY_TEXT_TO_STRING);
break;
case TextReplaceMatchingRegex:
firstArg.setVisible(true);
firstArg.setEmptyText(EMPTY_TEXT_REPLACE_REGEXP);
secondArg.setVisible(true);
secondArg.setEmptyText(EMPTY_TEXT_REPLACE_REPLACING);
break;
default:
break;
}
@ -483,6 +507,14 @@ public class ReplaceWidget extends SimpleContainer {
secondArg.setEmptyText(EMPTY_TEXT_TO_STRING);
removeConcat(source);
break;
case TextReplaceMatchingRegex:
comboReplaceElementsLeaf.setVisible(false);
firstArg.setVisible(true);
firstArg.setEmptyText(EMPTY_TEXT_REPLACE_REGEXP);
secondArg.setVisible(true);
secondArg.setEmptyText(EMPTY_TEXT_REPLACE_REPLACING);
removeConcat(source);
break;
default:
break;
}

View File

@ -22,10 +22,11 @@ public class ReplaceElementStore {
add(new ReplaceElement(3, ReplaceType.SubstringByRegex));
add(new ReplaceElement(4, ReplaceType.SubstringByIndex));
add(new ReplaceElement(5, ReplaceType.SubstringByCharSeq));
add(new ReplaceElement(6, ReplaceType.Concat));
add(new ReplaceElement(6, ReplaceType.TextReplaceMatchingRegex));
add(new ReplaceElement(7, ReplaceType.Concat));
}
};
public ArrayList<ReplaceElement> replaceElements = new ArrayList<ReplaceElement>() {
private static final long serialVersionUID = 1690916203781730778L;
@ -36,9 +37,9 @@ public class ReplaceElementStore {
add(new ReplaceElement(3, ReplaceType.SubstringByRegex));
add(new ReplaceElement(4, ReplaceType.SubstringByIndex));
add(new ReplaceElement(5, ReplaceType.SubstringByCharSeq));
add(new ReplaceElement(5, ReplaceType.TextReplaceMatchingRegex));
}
};
}

View File

@ -24,6 +24,7 @@ import org.gcube.data.analysis.tabulardata.expression.composite.text.TextBeginsW
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.TextMatchSQLRegexp;
import org.gcube.data.analysis.tabulardata.expression.composite.text.TextReplaceMatchingRegex;
import org.gcube.data.analysis.tabulardata.expression.leaf.ColumnReferencePlaceholder;
import org.gcube.data.analysis.tabulardata.expression.leaf.ConstantList;
import org.gcube.data.analysis.tabulardata.expression.leaf.Range;
@ -67,6 +68,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_TextContains;
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.composite.text.C_TextReplaceMatchingRegex;
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;
@ -180,6 +182,8 @@ public class C_ExpressionParser {
case "SubstringPosition":
ex =getSubstringPosition(exp);
break;
case "TextReplaceMatchingRegex":
ex =getTextReplaceMatchingRegex(exp);
default:
break;
}
@ -517,5 +521,18 @@ public class C_ExpressionParser {
return sPosition;
}
private Expression getTextReplaceMatchingRegex(C_Expression exp) {
C_TextReplaceMatchingRegex textReplaceMatchingRegex = (C_TextReplaceMatchingRegex) exp;
TDText tdRegexp=new TDText(textReplaceMatchingRegex.getRegexp().getValue());
TDText tdReplacing=new TDText(textReplaceMatchingRegex.getReplacing().getValue());
TextReplaceMatchingRegex textRepRegex = new TextReplaceMatchingRegex(
parse(textReplaceMatchingRegex.getToCheckText()),
tdRegexp,
tdReplacing);
return textRepRegex;
}
}

View File

@ -23,7 +23,8 @@ public enum C_OperatorType {
NOT_BEGINS_WITH, NOT_ENDS_WITH, NOT_CONTAINS, NOT_MATCH_REGEX,
CONCAT, SUBSTRINGBYINDEX, SUBSTRINGBYREGEX, SUBSTRINGPOSITION,
CONCAT, SUBSTRING_BY_INDEX, SUBSTRING_BY_REGEX,
SUBSTRING_POSITION, TEXT_REPLACE_MATCHING_REGEX,
// COMPLEX

View File

@ -31,7 +31,7 @@ public class C_SubstringByIndex extends C_Expression {
}
public C_OperatorType getOperator() {
return C_OperatorType.SUBSTRINGBYINDEX;
return C_OperatorType.SUBSTRING_BY_INDEX;
}
public String getReturnedDataType() {

View File

@ -29,7 +29,7 @@ public class C_SubstringByRegex extends C_Expression {
}
public C_OperatorType getOperator() {
return C_OperatorType.SUBSTRINGBYREGEX;
return C_OperatorType.SUBSTRING_BY_REGEX;
}
public String getReturnedDataType() {

View File

@ -32,7 +32,7 @@ public class C_SubstringPosition extends C_Expression {
public C_OperatorType getOperator() {
return C_OperatorType.SUBSTRINGBYREGEX;
return C_OperatorType.SUBSTRING_BY_REGEX;
}
public String getReturnedDataType() {

View File

@ -0,0 +1,79 @@
package org.gcube.portlets.user.td.expressionwidget.shared.model.composite.text;
import org.gcube.portlets.user.td.expressionwidget.shared.model.C_OperatorType;
import org.gcube.portlets.user.td.expressionwidget.shared.model.leaf.TD_Value;
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 C_TextReplaceMatchingRegex extends C_Expression {
private static final long serialVersionUID = -5827586649543147576L;
protected String id = "TextReplaceMatchingRegex";
private C_Expression toCheckText;
private TD_Value regexp;
private TD_Value replacing;
public C_TextReplaceMatchingRegex() {
super();
}
public C_TextReplaceMatchingRegex(C_Expression toCheckText,
TD_Value regexp, TD_Value replacing) {
super();
this.toCheckText = toCheckText;
this.regexp = regexp;
this.replacing = replacing;
}
public C_OperatorType getOperator() {
return C_OperatorType.TEXT_REPLACE_MATCHING_REGEX;
}
public String getReturnedDataType() {
return "Text";
}
@Override
public String getId() {
return id;
}
public C_Expression getToCheckText() {
return toCheckText;
}
public void setToCheckText(C_Expression toCheckText) {
this.toCheckText = toCheckText;
}
public TD_Value getRegexp() {
return regexp;
}
public void setRegexp(TD_Value regexp) {
this.regexp = regexp;
}
public TD_Value getReplacing() {
return replacing;
}
public void setReplacing(TD_Value replacing) {
this.replacing = replacing;
}
@Override
public String toString() {
return "C_TextReplaceMatchingRegex [id=" + id + ", toCheckText="
+ toCheckText + ", regexp=" + regexp + ", replacing="
+ replacing + "]";
}
}

View File

@ -7,6 +7,7 @@ public enum ReplaceType {
SubstringByRegex("Substring by Regex"),
SubstringByIndex("Substring by Index"),
SubstringByCharSeq("Substring by Char Seq."),
TextReplaceMatchingRegex("Replace Matching Regex"),
Concat("Concat");
/**

View File

@ -4,6 +4,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_SubstringByIndex;
import org.gcube.portlets.user.td.expressionwidget.shared.model.composite.text.C_SubstringByRegex;
import org.gcube.portlets.user.td.expressionwidget.shared.model.composite.text.C_SubstringPosition;
import org.gcube.portlets.user.td.expressionwidget.shared.model.composite.text.C_TextReplaceMatchingRegex;
import org.gcube.portlets.user.td.expressionwidget.shared.model.leaf.C_ColumnReferencePlaceholder;
import org.gcube.portlets.user.td.expressionwidget.shared.model.leaf.C_TypedColumnReference;
import org.gcube.portlets.user.td.expressionwidget.shared.model.leaf.TD_Value;
@ -105,6 +106,13 @@ public class ReplaceTypeMap {
readableExpression = "SubstringByCharSeq(" + readablePlaceHolder
+ ", " + firstArg + ", " + secondArg + ")";
break;
case TextReplaceMatchingRegex:
fArg = new TD_Value(ColumnDataType.Text, firstArg);
sArg = new TD_Value(ColumnDataType.Text, secondArg);
exp = new C_TextReplaceMatchingRegex(placeHolder, fArg, sArg);
readableExpression = "TextReplaceMatchingRegex(" + readablePlaceHolder
+ ", " + firstArg + ", " + secondArg + ")";
break;
default:
break;
}
@ -170,6 +178,13 @@ public class ReplaceTypeMap {
+ readableColumnReference + ", " + firstArg + ", "
+ secondArg + ")";
break;
case TextReplaceMatchingRegex:
fArg = new TD_Value(ColumnDataType.Text, firstArg);
sArg = new TD_Value(ColumnDataType.Text, secondArg);
exp = new C_TextReplaceMatchingRegex(columnReference, fArg, sArg);
readableExpression = "TextReplaceMatchingRegex(" + readableColumnReference
+ ", " + firstArg + ", " + secondArg + ")";
break;
default:
break;
}