Updated Replace By Expression

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-expression-widget@111786 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2015-02-06 17:26:57 +00:00
parent 4612e0e2ba
commit ba8e135c1e
13 changed files with 973 additions and 2178 deletions

View File

@ -137,7 +137,7 @@ public class ReplaceColumnByExpressionDialog extends Window implements
||column.getDataTypeName().compareTo(ColumnDataType.Integer.toString()) == 0 ||column.getDataTypeName().compareTo(ColumnDataType.Integer.toString()) == 0
||column.getDataTypeName().compareTo(ColumnDataType.Numeric.toString()) == 0 ||column.getDataTypeName().compareTo(ColumnDataType.Numeric.toString()) == 0
||column.getDataTypeName().compareTo(ColumnDataType.Geometry.toString()) == 0 ||column.getDataTypeName().compareTo(ColumnDataType.Geometry.toString()) == 0
||column.getDataTypeName().compareTo(ColumnDataType.Date.toString()) == 0) { ) {
setHeight(HEIGHT); setHeight(HEIGHT);
} else { } else {
setHeight(HEIGHT_REDUCE); setHeight(HEIGHT_REDUCE);

View File

@ -1,6 +1,7 @@
package org.gcube.portlets.user.td.expressionwidget.client; package org.gcube.portlets.user.td.expressionwidget.client;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date;
import org.gcube.portlets.user.td.expressionwidget.client.resources.ExpressionResources; import org.gcube.portlets.user.td.expressionwidget.client.resources.ExpressionResources;
import org.gcube.portlets.user.td.expressionwidget.client.type.ReplaceColumnByExpressionType; import org.gcube.portlets.user.td.expressionwidget.client.type.ReplaceColumnByExpressionType;
@ -18,6 +19,7 @@ import org.gcube.portlets.user.td.widgetcommonevent.shared.tr.column.ColumnDataT
import com.allen_sauer.gwt.log.client.Log; import com.allen_sauer.gwt.log.client.Log;
import com.google.gwt.event.logical.shared.ValueChangeEvent; import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler; import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.regexp.shared.MatchResult; import com.google.gwt.regexp.shared.MatchResult;
import com.google.gwt.regexp.shared.RegExp; import com.google.gwt.regexp.shared.RegExp;
import com.google.gwt.user.client.ui.HasHorizontalAlignment; import com.google.gwt.user.client.ui.HasHorizontalAlignment;
@ -37,6 +39,7 @@ import com.sencha.gxt.widget.core.client.container.VerticalLayoutContainer;
import com.sencha.gxt.widget.core.client.container.VerticalLayoutContainer.VerticalLayoutData; import com.sencha.gxt.widget.core.client.container.VerticalLayoutContainer.VerticalLayoutData;
import com.sencha.gxt.widget.core.client.event.SelectEvent; import com.sencha.gxt.widget.core.client.event.SelectEvent;
import com.sencha.gxt.widget.core.client.event.SelectEvent.SelectHandler; import com.sencha.gxt.widget.core.client.event.SelectEvent.SelectHandler;
import com.sencha.gxt.widget.core.client.form.DateField;
import com.sencha.gxt.widget.core.client.form.FieldLabel; import com.sencha.gxt.widget.core.client.form.FieldLabel;
import com.sencha.gxt.widget.core.client.form.FieldSet; import com.sencha.gxt.widget.core.client.form.FieldSet;
import com.sencha.gxt.widget.core.client.form.Radio; import com.sencha.gxt.widget.core.client.form.Radio;
@ -75,7 +78,7 @@ public class ReplaceColumnByExpressionPanel extends FramedPanel {
private ReplaceColumnByExpressionType replaceColumnByExpressionType; private ReplaceColumnByExpressionType replaceColumnByExpressionType;
// private DateTimeFormat sdf = DateTimeFormat.getFormat("yyyy-MM-dd"); private DateTimeFormat sdf = DateTimeFormat.getFormat("yyyy-MM-dd");
private TextButton btnApply; private TextButton btnApply;
private TextButton btnClose; private TextButton btnClose;
@ -84,9 +87,8 @@ public class ReplaceColumnByExpressionPanel extends FramedPanel {
private ConditionWidget conditionWidget; private ConditionWidget conditionWidget;
private ReplaceWidget replaceWidget; private ReplaceWidget replaceWidget;
private ReplaceArithmeticWidget replaceArithmeticWidget;
private TextField replaceValue; private TextField replaceValue;
// private DateField replaceValueDate; private DateField replaceValueDate;
private VerticalLayoutContainer conditionsVerticalLayout; private VerticalLayoutContainer conditionsVerticalLayout;
private FieldLabel allRowsField; private FieldLabel allRowsField;
@ -130,9 +132,7 @@ public class ReplaceColumnByExpressionPanel extends FramedPanel {
|| column.getDataTypeName().compareTo( || column.getDataTypeName().compareTo(
ColumnDataType.Numeric.toString()) == 0 ColumnDataType.Numeric.toString()) == 0
|| column.getDataTypeName().compareTo( || column.getDataTypeName().compareTo(
ColumnDataType.Geometry.toString()) == 0 || column ColumnDataType.Geometry.toString()) == 0)) {
.getDataTypeName().compareTo(
ColumnDataType.Date.toString()) == 0)) {
setHeight(HEIGHT); setHeight(HEIGHT);
} else { } else {
setHeight(HEIGHT_REDUCE); setHeight(HEIGHT_REDUCE);
@ -229,46 +229,21 @@ public class ReplaceColumnByExpressionPanel extends FramedPanel {
VerticalLayoutContainer replaceValueFieldSetLayout = new VerticalLayoutContainer(); VerticalLayoutContainer replaceValueFieldSetLayout = new VerticalLayoutContainer();
replaceValueFieldSet.add(replaceValueFieldSetLayout); replaceValueFieldSet.add(replaceValueFieldSetLayout);
if (column.getDataTypeName().compareTo(ColumnDataType.Date.toString()) == 0) {
replaceValueDate = new DateField();
replaceValueDate.setToolTip("Replace Value");
replaceValueFieldSetLayout.add(new FieldLabel(replaceValueDate,
"Replace Value"), new VerticalLayoutData(1, -1));
} else {
if (column.getDataTypeName().compareTo( if (column.getDataTypeName().compareTo(
ColumnDataType.Text.toString()) == 0
|| column.getDataTypeName().compareTo(
ColumnDataType.Integer.toString()) == 0 ColumnDataType.Integer.toString()) == 0
|| column.getDataTypeName().compareTo( || column.getDataTypeName().compareTo(
ColumnDataType.Numeric.toString()) == 0 ColumnDataType.Numeric.toString()) == 0
|| column.getDataTypeName().compareTo( || column.getDataTypeName().compareTo(
ColumnDataType.Geometry.toString()) == 0 ColumnDataType.Geometry.toString()) == 0) {
|| column.getDataTypeName().compareTo(
ColumnDataType.Date.toString()) == 0) {
switch (replaceColumnByExpressionType) {
case Replace:
replaceArithmeticWidget = new ReplaceArithmeticWidget(column,
REPLACEWIDTH, REPLACEHEIGHT, eventBus);
break;
case Template:
replaceArithmeticWidget = new ReplaceArithmeticWidget(column,
columns, REPLACEWIDTH, REPLACEHEIGHT, eventBus);
break;
default:
Log.debug("Attention Replace Widget have not a valid type");
UtilsGXT3.alert("Attention",
"Attention Replace Widget have not a valid type");
if (parent != null) {
parent.hide();
}
return;
}
replaceValueFieldSetLayout.add(replaceArithmeticWidget,
new VerticalLayoutData(1, -1));
/*
* replaceValueDate = new DateField();
* replaceValueDate.setToolTip("Replace Value");
* replaceValueFieldSetLayout.add(new FieldLabel(replaceValueDate,
* "Replace Value"), new VerticalLayoutData(1, -1));
*/
} else {
if (column.getDataTypeName().compareTo(
ColumnDataType.Text.toString()) == 0) {
switch (replaceColumnByExpressionType) { switch (replaceColumnByExpressionType) {
case Replace: case Replace:
replaceWidget = new ReplaceWidget(column, REPLACEWIDTH, replaceWidget = new ReplaceWidget(column, REPLACEWIDTH,
@ -371,44 +346,33 @@ public class ReplaceColumnByExpressionPanel extends FramedPanel {
} }
String value = null; String value = null;
if (column.getDataTypeName().compareTo(ColumnDataType.Date.toString()) == 0) {
Date valueDate = replaceValueDate.getCurrentValue();
if (valueDate == null) {
UtilsGXT3.alert("Error replace value",
"Select a valid date as replace value!");
return;
} else {
try {
value = sdf.format(valueDate);
} catch (Throwable e) {
UtilsGXT3.alert("Error replace value",
"Select a valid date as replace value!");
return;
}
callApplyReplaceColumnByExpression(cConditionExpression, value);
}
} else {
if (column.getDataTypeName().compareTo( if (column.getDataTypeName().compareTo(
ColumnDataType.Text.toString()) == 0|| column.getDataTypeName().compareTo(
ColumnDataType.Integer.toString()) == 0 ColumnDataType.Integer.toString()) == 0
|| column.getDataTypeName().compareTo( || column.getDataTypeName().compareTo(
ColumnDataType.Numeric.toString()) == 0 ColumnDataType.Numeric.toString()) == 0
|| column.getDataTypeName().compareTo( || column.getDataTypeName().compareTo(
ColumnDataType.Geometry.toString()) == 0 ColumnDataType.Geometry.toString()) == 0) {
|| column.getDataTypeName().compareTo(
ColumnDataType.Date.toString()) == 0) {
C_Expression cReplaceExpression = null;
try {
cReplaceExpression = replaceArithmeticWidget.getExpression();
if (cReplaceExpression == null) {
UtilsGXT3.alert("Attention",
"Replace expression is not valid!");
return;
}
} catch (ReplaceTypeMapException e) {
UtilsGXT3.alert("Attention", e.getLocalizedMessage());
return;
}
callApplyReplaceColumnByExpression(cConditionExpression,
cReplaceExpression);
/*
* Date valueDate = replaceValueDate.getCurrentValue(); if
* (valueDate == null) { UtilsGXT3.alert("Error replace value",
* "Select a valid date as replace value!"); return; } else { try {
* value = sdf.format(valueDate); } catch (Throwable e) {
* UtilsGXT3.alert("Error replace value",
* "Select a valid date as replace value!"); return; }
* callApplyReplaceColumnByExpression(cConditionExpression, value);
*
* }
*/
} else {
if (column.getDataTypeName().compareTo(
ColumnDataType.Text.toString()) == 0) {
C_Expression cReplaceExpression = null; C_Expression cReplaceExpression = null;
try { try {
cReplaceExpression = replaceWidget.getExpression(); cReplaceExpression = replaceWidget.getExpression();
@ -484,7 +448,7 @@ public class ReplaceColumnByExpressionPanel extends FramedPanel {
cReplaceExpression, replaceWidget.getReadableExpression()); cReplaceExpression, replaceWidget.getReadableExpression());
expressionEvent expressionEvent
.setC_ReplaceExpressionContainer(replaceExpressionContainer); .setC_ReplaceExpressionContainer(replaceExpressionContainer);
;
expressionEvent.setTrId(column.getTrId()); expressionEvent.setTrId(column.getTrId());
expressionEvent.setColumnId(column.getColumnId()); expressionEvent.setColumnId(column.getColumnId());
expressionEvent.setColumnName(column.getName()); expressionEvent.setColumnName(column.getName());
@ -504,7 +468,7 @@ public class ReplaceColumnByExpressionPanel extends FramedPanel {
private boolean checkValue(String value) { private boolean checkValue(String value) {
try { try {
boolean ok = false; boolean ok = false;
ColumnDataType columnDataType =ColumnDataType ColumnDataType columnDataType = ColumnDataType
.getColumnDataTypeFromId(column.getDataTypeName()); .getColumnDataTypeFromId(column.getDataTypeName());
switch (columnDataType) { switch (columnDataType) {
case Boolean: case Boolean:

View File

@ -9,6 +9,7 @@ import org.gcube.portlets.user.td.expressionwidget.client.properties.ReplaceElem
import org.gcube.portlets.user.td.expressionwidget.client.type.ReplaceColumnByExpressionType; import org.gcube.portlets.user.td.expressionwidget.client.type.ReplaceColumnByExpressionType;
import org.gcube.portlets.user.td.expressionwidget.client.utils.UtilsGXT3; import org.gcube.portlets.user.td.expressionwidget.client.utils.UtilsGXT3;
import org.gcube.portlets.user.td.expressionwidget.shared.exception.ReplaceTypeMapException; import org.gcube.portlets.user.td.expressionwidget.shared.exception.ReplaceTypeMapException;
import org.gcube.portlets.user.td.expressionwidget.shared.model.composite.arithmetic.C_ArithmeticExpression;
import org.gcube.portlets.user.td.expressionwidget.shared.replace.ReplaceType; import org.gcube.portlets.user.td.expressionwidget.shared.replace.ReplaceType;
import org.gcube.portlets.user.td.expressionwidget.shared.replace.ReplaceTypeMap; import org.gcube.portlets.user.td.expressionwidget.shared.replace.ReplaceTypeMap;
import org.gcube.portlets.user.td.gwtservice.client.rpc.TDGWTServiceAsync; import org.gcube.portlets.user.td.gwtservice.client.rpc.TDGWTServiceAsync;
@ -20,6 +21,7 @@ import org.gcube.portlets.user.td.widgetcommonevent.client.event.SessionExpiredE
import org.gcube.portlets.user.td.widgetcommonevent.client.type.SessionExpiredType; import org.gcube.portlets.user.td.widgetcommonevent.client.type.SessionExpiredType;
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.gcube.portlets.user.td.widgetcommonevent.shared.expression.C_Expression;
import org.gcube.portlets.user.td.widgetcommonevent.shared.tr.column.ColumnDataType;
import com.allen_sauer.gwt.log.client.Log; import com.allen_sauer.gwt.log.client.Log;
import com.google.gwt.core.client.GWT; import com.google.gwt.core.client.GWT;
@ -66,6 +68,7 @@ public class ReplaceWidget extends SimpleContainer {
private EventBus eventBus; private EventBus eventBus;
private TRId trId; private TRId trId;
private ArrayList<ColumnData> columns; private ArrayList<ColumnData> columns;
private ArrayList<ColumnData> arithmeticColumns;
// private FieldLabel matchLabel; // private FieldLabel matchLabel;
// private ToggleGroup groupMatch; // private ToggleGroup groupMatch;
@ -81,6 +84,7 @@ public class ReplaceWidget extends SimpleContainer {
private String itemIdSecondArg; private String itemIdSecondArg;
private String itemIdHoriz; private String itemIdHoriz;
private ReplaceColumnByExpressionType replaceColumnByExpressionType; private ReplaceColumnByExpressionType replaceColumnByExpressionType;
private ColumnDataType targetColumnType;
protected class ExpressionContainer { protected class ExpressionContainer {
private C_Expression expression; private C_Expression expression;
@ -114,7 +118,9 @@ public class ReplaceWidget extends SimpleContainer {
public ReplaceWidget(ColumnData column, EventBus eventBus) { public ReplaceWidget(ColumnData column, EventBus eventBus) {
super(); super();
replaceColumnByExpressionType = ReplaceColumnByExpressionType.Replace; replaceColumnByExpressionType = ReplaceColumnByExpressionType.Replace;
create(column.getTrId(), WIDTH, HEIGHT, eventBus); ColumnDataType targetType = ColumnDataType
.getColumnDataTypeFromId(column.getDataTypeName());
create(column.getTrId(), targetType, WIDTH, HEIGHT, eventBus);
retrieveColumns(); retrieveColumns();
} }
@ -122,7 +128,9 @@ public class ReplaceWidget extends SimpleContainer {
EventBus eventBus) { EventBus eventBus) {
super(); super();
replaceColumnByExpressionType = ReplaceColumnByExpressionType.Replace; replaceColumnByExpressionType = ReplaceColumnByExpressionType.Replace;
create(column.getTrId(), width, height, eventBus); ColumnDataType targetType = ColumnDataType
.getColumnDataTypeFromId(column.getDataTypeName());
create(column.getTrId(), targetType, width, height, eventBus);
retrieveColumns(); retrieveColumns();
} }
@ -131,7 +139,9 @@ public class ReplaceWidget extends SimpleContainer {
super(); super();
replaceColumnByExpressionType = ReplaceColumnByExpressionType.Template; replaceColumnByExpressionType = ReplaceColumnByExpressionType.Template;
this.columns = columns; this.columns = columns;
create(column.getTrId(), WIDTH, HEIGHT, eventBus); ColumnDataType targetType = ColumnDataType
.getColumnDataTypeFromId(column.getDataTypeName());
create(column.getTrId(), targetType, WIDTH, HEIGHT, eventBus);
setup(); setup();
} }
@ -140,13 +150,16 @@ public class ReplaceWidget extends SimpleContainer {
super(); super();
replaceColumnByExpressionType = ReplaceColumnByExpressionType.Template; replaceColumnByExpressionType = ReplaceColumnByExpressionType.Template;
this.columns = columns; this.columns = columns;
create(column.getTrId(), width, height, eventBus); ColumnDataType targetType = ColumnDataType
.getColumnDataTypeFromId(column.getDataTypeName());
create(column.getTrId(), targetType, width, height, eventBus);
setup(); setup();
} }
protected void create(TRId trId, String width, String height, protected void create(TRId trId, ColumnDataType targetColumnType,
EventBus eventBus) { String width, String height, EventBus eventBus) {
this.trId = trId; this.trId = trId;
this.targetColumnType = targetColumnType;
setBorders(true); setBorders(true);
setWidth(width); setWidth(width);
setHeight(height); setHeight(height);
@ -196,6 +209,16 @@ public class ReplaceWidget extends SimpleContainer {
public void onSuccess(ArrayList<ColumnData> result) { public void onSuccess(ArrayList<ColumnData> result) {
Log.trace("loaded " + result.size() + " ColumnData"); Log.trace("loaded " + result.size() + " ColumnData");
columns = result; columns = result;
arithmeticColumns = new ArrayList<ColumnData>();
for (ColumnData col : result) {
ColumnDataType colDataType = ColumnDataType
.getColumnDataTypeFromId(col
.getDataTypeName());
if (C_ArithmeticExpression.isAccepted(colDataType)) {
arithmeticColumns.add(col);
}
}
setup(); setup();
} }
@ -211,7 +234,7 @@ public class ReplaceWidget extends SimpleContainer {
itemIdHoriz = "Horiz" + trId.getId(); itemIdHoriz = "Horiz" + trId.getId();
vert = new VerticalLayoutContainer(); vert = new VerticalLayoutContainer();
//vert.setScrollMode(ScrollMode.AUTO); Set in GXT 3.0.1 // vert.setScrollMode(ScrollMode.AUTO); Set in GXT 3.0.1
final HBoxLayoutContainer horiz = new HBoxLayoutContainer(); final HBoxLayoutContainer horiz = new HBoxLayoutContainer();
@ -244,7 +267,7 @@ public class ReplaceWidget extends SimpleContainer {
comboColumns.setTriggerAction(TriggerAction.ALL); comboColumns.setTriggerAction(TriggerAction.ALL);
// Replace Elemet Store // Replace Elemet Store
ReplaceElementStore factory = new ReplaceElementStore(); final ReplaceElementStore factory = new ReplaceElementStore();
ReplaceElementProperties props = GWT ReplaceElementProperties props = GWT
.create(ReplaceElementProperties.class); .create(ReplaceElementProperties.class);
@ -287,6 +310,11 @@ public class ReplaceWidget extends SimpleContainer {
secondArg.setEmptyText(""); secondArg.setEmptyText("");
break; break;
case Concat: case Concat:
case Addition:
case Subtraction:
case Modulus:
case Multiplication:
case Division:
break; break;
case SubstringByRegex: case SubstringByRegex:
comboColumns.clear(); comboColumns.clear();
@ -340,19 +368,20 @@ public class ReplaceWidget extends SimpleContainer {
comboReplaceElementsLeaf.setTriggerAction(TriggerAction.ALL); comboReplaceElementsLeaf.setTriggerAction(TriggerAction.ALL);
// ComboConcat // ComboOperations
ListStore<ReplaceElement> storeReplaceElementsConcat = new ListStore<ReplaceElement>( ListStore<ReplaceElement> storeReplaceElementsOperations = new ListStore<ReplaceElement>(
props.id()); props.id());
Log.debug("Store Concat: " + storeReplaceElementsConcat); Log.debug("Store Operations: " + storeReplaceElementsOperations);
storeReplaceElementsConcat.addAll(factory.replaceElementsConcat); storeReplaceElementsOperations
.addAll(factory.replaceElementsOperations);
Log.debug("Store created"); Log.debug("Store created");
final ComboBox<ReplaceElement> comboReplaceElementsConcat = new ComboBox<ReplaceElement>( final ComboBox<ReplaceElement> comboReplaceElementsOperations = new ComboBox<ReplaceElement>(
storeReplaceElementsConcat, props.label()); storeReplaceElementsOperations, props.label());
Log.debug("Combo created"); Log.debug("Combo created");
comboReplaceElementsConcat comboReplaceElementsOperations
.addSelectionHandler(new SelectionHandler<ReplaceElement>() { .addSelectionHandler(new SelectionHandler<ReplaceElement>() {
public void onSelection(SelectionEvent<ReplaceElement> event) { public void onSelection(SelectionEvent<ReplaceElement> event) {
@ -371,7 +400,7 @@ public class ReplaceWidget extends SimpleContainer {
firstArg.setVisible(true); firstArg.setVisible(true);
secondArg.setVisible(false); secondArg.setVisible(false);
secondArg.setEmptyText(""); secondArg.setEmptyText("");
removeConcat(source); removeOperation(source);
break; break;
case ColumnValue: case ColumnValue:
comboReplaceElementsLeaf.setVisible(false); comboReplaceElementsLeaf.setVisible(false);
@ -381,19 +410,49 @@ public class ReplaceWidget extends SimpleContainer {
firstArg.setEmptyText(""); firstArg.setEmptyText("");
secondArg.setVisible(false); secondArg.setVisible(false);
secondArg.setEmptyText(""); secondArg.setEmptyText("");
removeConcat(source); removeOperation(source);
break; break;
case Concat: case Concat:
if (!existConcat(source)) {
comboReplaceElementsLeaf.clear(); comboReplaceElementsLeaf.clear();
comboReplaceElementsLeaf.reset();
comboReplaceElementsLeaf.getStore().clear();
comboReplaceElementsLeaf.getStore()
.addAll(factory.replaceElements);
comboReplaceElementsLeaf.getStore().commitChanges();
comboReplaceElementsLeaf.setVisible(true); comboReplaceElementsLeaf.setVisible(true);
comboReplaceElementsLeaf.redraw();
if (!existOperation(source)) {
comboColumns.clear(); comboColumns.clear();
comboColumns.setVisible(false); comboColumns.setVisible(false);
firstArg.setVisible(false); firstArg.setVisible(false);
firstArg.setEmptyText(""); firstArg.setEmptyText("");
secondArg.setVisible(false); secondArg.setVisible(false);
secondArg.setEmptyText(""); secondArg.setEmptyText("");
addConcat(); addOperation();
}
break;
case Addition:
case Subtraction:
case Modulus:
case Multiplication:
case Division:
comboReplaceElementsLeaf.clear();
comboReplaceElementsLeaf.reset();
comboReplaceElementsLeaf.getStore().clear();
comboReplaceElementsLeaf.getStore()
.addAll(factory.replaceElementsArithmetic);
comboReplaceElementsLeaf.getStore().commitChanges();
comboReplaceElementsLeaf.setVisible(true);
comboReplaceElementsLeaf.redraw();
if (!existOperation(source)) {
comboColumns.clear();
comboColumns.setVisible(false);
firstArg.setVisible(false);
firstArg.setEmptyText("");
secondArg.setVisible(false);
secondArg.setEmptyText("");
addOperation();
} }
break; break;
case SubstringByRegex: case SubstringByRegex:
@ -404,7 +463,7 @@ public class ReplaceWidget extends SimpleContainer {
firstArg.setEmptyText(EMPTY_TEXT_REGEXP); firstArg.setEmptyText(EMPTY_TEXT_REGEXP);
secondArg.setVisible(false); secondArg.setVisible(false);
secondArg.setEmptyText(""); secondArg.setEmptyText("");
removeConcat(source); removeOperation(source);
break; break;
case SubstringByIndex: case SubstringByIndex:
comboReplaceElementsLeaf.setVisible(false); comboReplaceElementsLeaf.setVisible(false);
@ -414,7 +473,7 @@ public class ReplaceWidget extends SimpleContainer {
firstArg.setEmptyText(EMPTY_TEXT_FROM_INDEX); firstArg.setEmptyText(EMPTY_TEXT_FROM_INDEX);
secondArg.setVisible(true); secondArg.setVisible(true);
secondArg.setEmptyText(EMPTY_TEXT_TO_INDEX); secondArg.setEmptyText(EMPTY_TEXT_TO_INDEX);
removeConcat(source); removeOperation(source);
break; break;
case SubstringByCharSeq: case SubstringByCharSeq:
comboReplaceElementsLeaf.setVisible(false); comboReplaceElementsLeaf.setVisible(false);
@ -424,7 +483,7 @@ public class ReplaceWidget extends SimpleContainer {
firstArg.setEmptyText(EMPTY_TEXT_FROM_STRING); firstArg.setEmptyText(EMPTY_TEXT_FROM_STRING);
secondArg.setVisible(true); secondArg.setVisible(true);
secondArg.setEmptyText(EMPTY_TEXT_TO_STRING); secondArg.setEmptyText(EMPTY_TEXT_TO_STRING);
removeConcat(source); removeOperation(source);
break; break;
case TextReplaceMatchingRegex: case TextReplaceMatchingRegex:
comboReplaceElementsLeaf.setVisible(false); comboReplaceElementsLeaf.setVisible(false);
@ -435,7 +494,7 @@ public class ReplaceWidget extends SimpleContainer {
secondArg.setVisible(true); secondArg.setVisible(true);
secondArg secondArg
.setEmptyText(EMPTY_TEXT_REPLACE_REPLACING); .setEmptyText(EMPTY_TEXT_REPLACE_REPLACING);
removeConcat(source); removeOperation(source);
break; break;
default: default:
break; break;
@ -448,17 +507,18 @@ public class ReplaceWidget extends SimpleContainer {
}); });
comboReplaceElementsConcat.setEmptyText("Select..."); comboReplaceElementsOperations.setEmptyText("Select...");
comboReplaceElementsConcat.setItemId(itemIdComboConcat); comboReplaceElementsOperations.setItemId(itemIdComboConcat);
comboReplaceElementsConcat.setWidth(COMBO_WIDTH); comboReplaceElementsOperations.setWidth(COMBO_WIDTH);
comboReplaceElementsConcat.setEditable(false); comboReplaceElementsOperations.setEditable(false);
comboReplaceElementsConcat.setTriggerAction(TriggerAction.ALL); comboReplaceElementsOperations.setTriggerAction(TriggerAction.ALL);
comboReplaceElementsConcat.setValue(storeReplaceElementsConcat.get(0), comboReplaceElementsOperations.setValue(
true); storeReplaceElementsOperations.get(0), true);
// //
horiz.add(comboReplaceElementsConcat, new BoxLayoutData(new Margins(0))); horiz.add(comboReplaceElementsOperations, new BoxLayoutData(
new Margins(0)));
horiz.add(comboReplaceElementsLeaf, new BoxLayoutData(new Margins(0))); horiz.add(comboReplaceElementsLeaf, new BoxLayoutData(new Margins(0)));
horiz.add(comboColumns, new BoxLayoutData(new Margins(0))); horiz.add(comboColumns, new BoxLayoutData(new Margins(0)));
horiz.add(firstArg, new BoxLayoutData(new Margins(0))); horiz.add(firstArg, new BoxLayoutData(new Margins(0)));
@ -472,11 +532,11 @@ public class ReplaceWidget extends SimpleContainer {
secondArg.setVisible(false); secondArg.setVisible(false);
comboColumns.setVisible(false); comboColumns.setVisible(false);
comboReplaceElementsLeaf.setVisible(false); comboReplaceElementsLeaf.setVisible(false);
comboReplaceElementsConcat.setVisible(true); comboReplaceElementsOperations.setVisible(true);
forceLayout(); forceLayout();
} }
protected void addConcat() { protected void addOperation() {
final HBoxLayoutContainer horiz = new HBoxLayoutContainer(); final HBoxLayoutContainer horiz = new HBoxLayoutContainer();
final TextField firstArg = new TextField(); final TextField firstArg = new TextField();
@ -506,7 +566,7 @@ public class ReplaceWidget extends SimpleContainer {
comboColumns.setTriggerAction(TriggerAction.ALL); comboColumns.setTriggerAction(TriggerAction.ALL);
// //
ReplaceElementStore factory = new ReplaceElementStore(); final ReplaceElementStore factory = new ReplaceElementStore();
ReplaceElementProperties props = GWT ReplaceElementProperties props = GWT
.create(ReplaceElementProperties.class); .create(ReplaceElementProperties.class);
@ -549,6 +609,11 @@ public class ReplaceWidget extends SimpleContainer {
secondArg.setEmptyText(""); secondArg.setEmptyText("");
break; break;
case Concat: case Concat:
case Addition:
case Subtraction:
case Modulus:
case Multiplication:
case Division:
break; break;
case SubstringByRegex: case SubstringByRegex:
comboColumns.clear(); comboColumns.clear();
@ -601,19 +666,20 @@ public class ReplaceWidget extends SimpleContainer {
comboReplaceElementsLeaf.setTriggerAction(TriggerAction.ALL); comboReplaceElementsLeaf.setTriggerAction(TriggerAction.ALL);
// ComboConcat // ComboOperations
ListStore<ReplaceElement> storeReplaceElementsConcat = new ListStore<ReplaceElement>( ListStore<ReplaceElement> storeReplaceElementsOperations = new ListStore<ReplaceElement>(
props.id()); props.id());
Log.debug("Store Concat: " + storeReplaceElementsConcat); Log.debug("Store Concat: " + storeReplaceElementsOperations);
storeReplaceElementsConcat.addAll(factory.replaceElementsConcat); storeReplaceElementsOperations
.addAll(factory.replaceElementsOperations);
Log.debug("Store created"); Log.debug("Store created");
final ComboBox<ReplaceElement> comboReplaceElementsConcat = new ComboBox<ReplaceElement>( final ComboBox<ReplaceElement> comboReplaceElementsOperations = new ComboBox<ReplaceElement>(
storeReplaceElementsConcat, props.label()); storeReplaceElementsOperations, props.label());
Log.debug("Combo created"); Log.debug("Combo created");
comboReplaceElementsConcat comboReplaceElementsOperations
.addSelectionHandler(new SelectionHandler<ReplaceElement>() { .addSelectionHandler(new SelectionHandler<ReplaceElement>() {
public void onSelection(SelectionEvent<ReplaceElement> event) { public void onSelection(SelectionEvent<ReplaceElement> event) {
@ -633,7 +699,7 @@ public class ReplaceWidget extends SimpleContainer {
firstArg.setVisible(true); firstArg.setVisible(true);
secondArg.setVisible(false); secondArg.setVisible(false);
secondArg.setEmptyText(""); secondArg.setEmptyText("");
removeConcat(source); removeOperation(source);
break; break;
case ColumnValue: case ColumnValue:
comboReplaceElementsLeaf.setVisible(false); comboReplaceElementsLeaf.setVisible(false);
@ -643,19 +709,48 @@ public class ReplaceWidget extends SimpleContainer {
firstArg.setEmptyText(""); firstArg.setEmptyText("");
secondArg.setVisible(false); secondArg.setVisible(false);
secondArg.setEmptyText(""); secondArg.setEmptyText("");
removeConcat(source); removeOperation(source);
break; break;
case Concat: case Concat:
if (!existConcat(source)) {
comboReplaceElementsLeaf.clear(); comboReplaceElementsLeaf.clear();
comboReplaceElementsLeaf.reset();
comboReplaceElementsLeaf.getStore().clear();
comboReplaceElementsLeaf.getStore()
.addAll(factory.replaceElements);
comboReplaceElementsLeaf.getStore().commitChanges();
comboReplaceElementsLeaf.setVisible(true); comboReplaceElementsLeaf.setVisible(true);
comboReplaceElementsLeaf.redraw();
if (!existOperation(source)) {
comboColumns.clear(); comboColumns.clear();
comboColumns.setVisible(false); comboColumns.setVisible(false);
firstArg.setVisible(false); firstArg.setVisible(false);
firstArg.setEmptyText(""); firstArg.setEmptyText("");
secondArg.setVisible(false); secondArg.setVisible(false);
secondArg.setEmptyText(""); secondArg.setEmptyText("");
addConcat(); addOperation();
}
break;
case Addition:
case Subtraction:
case Modulus:
case Multiplication:
case Division:
comboReplaceElementsLeaf.clear();
comboReplaceElementsLeaf.reset();
comboReplaceElementsLeaf.getStore().clear();
comboReplaceElementsLeaf.getStore()
.addAll(factory.replaceElementsArithmetic);
comboReplaceElementsLeaf.getStore().commitChanges();
comboReplaceElementsLeaf.setVisible(true);
comboReplaceElementsLeaf.redraw();
if (!existOperation(source)) {
comboColumns.clear();
comboColumns.setVisible(false);
firstArg.setVisible(false);
firstArg.setEmptyText("");
secondArg.setVisible(false);
secondArg.setEmptyText("");
addOperation();
} }
break; break;
case SubstringByRegex: case SubstringByRegex:
@ -666,7 +761,7 @@ public class ReplaceWidget extends SimpleContainer {
firstArg.setEmptyText(EMPTY_TEXT_REGEXP); firstArg.setEmptyText(EMPTY_TEXT_REGEXP);
secondArg.setVisible(false); secondArg.setVisible(false);
secondArg.setEmptyText(""); secondArg.setEmptyText("");
removeConcat(source); removeOperation(source);
break; break;
case SubstringByIndex: case SubstringByIndex:
comboReplaceElementsLeaf.setVisible(false); comboReplaceElementsLeaf.setVisible(false);
@ -676,7 +771,7 @@ public class ReplaceWidget extends SimpleContainer {
firstArg.setEmptyText(EMPTY_TEXT_FROM_INDEX); firstArg.setEmptyText(EMPTY_TEXT_FROM_INDEX);
secondArg.setVisible(true); secondArg.setVisible(true);
secondArg.setEmptyText(EMPTY_TEXT_TO_INDEX); secondArg.setEmptyText(EMPTY_TEXT_TO_INDEX);
removeConcat(source); removeOperation(source);
break; break;
case SubstringByCharSeq: case SubstringByCharSeq:
comboReplaceElementsLeaf.setVisible(false); comboReplaceElementsLeaf.setVisible(false);
@ -686,7 +781,7 @@ public class ReplaceWidget extends SimpleContainer {
firstArg.setEmptyText(EMPTY_TEXT_FROM_STRING); firstArg.setEmptyText(EMPTY_TEXT_FROM_STRING);
secondArg.setVisible(true); secondArg.setVisible(true);
secondArg.setEmptyText(EMPTY_TEXT_TO_STRING); secondArg.setEmptyText(EMPTY_TEXT_TO_STRING);
removeConcat(source); removeOperation(source);
break; break;
case TextReplaceMatchingRegex: case TextReplaceMatchingRegex:
comboReplaceElementsLeaf.setVisible(false); comboReplaceElementsLeaf.setVisible(false);
@ -697,7 +792,7 @@ public class ReplaceWidget extends SimpleContainer {
secondArg.setVisible(true); secondArg.setVisible(true);
secondArg secondArg
.setEmptyText(EMPTY_TEXT_REPLACE_REPLACING); .setEmptyText(EMPTY_TEXT_REPLACE_REPLACING);
removeConcat(source); removeOperation(source);
break; break;
default: default:
break; break;
@ -711,17 +806,18 @@ public class ReplaceWidget extends SimpleContainer {
}); });
comboReplaceElementsConcat.setEmptyText("Select..."); comboReplaceElementsOperations.setEmptyText("Select...");
comboReplaceElementsConcat.setItemId(itemIdComboConcat); comboReplaceElementsOperations.setItemId(itemIdComboConcat);
comboReplaceElementsConcat.setWidth(COMBO_WIDTH); comboReplaceElementsOperations.setWidth(COMBO_WIDTH);
comboReplaceElementsConcat.setEditable(false); comboReplaceElementsOperations.setEditable(false);
comboReplaceElementsConcat.setTriggerAction(TriggerAction.ALL); comboReplaceElementsOperations.setTriggerAction(TriggerAction.ALL);
comboReplaceElementsConcat.setValue(storeReplaceElementsConcat.get(0), comboReplaceElementsOperations.setValue(
true); storeReplaceElementsOperations.get(0), true);
// //
horiz.add(comboReplaceElementsConcat, new BoxLayoutData(new Margins(0))); horiz.add(comboReplaceElementsOperations, new BoxLayoutData(
new Margins(0)));
horiz.add(comboReplaceElementsLeaf, new BoxLayoutData(new Margins(0))); horiz.add(comboReplaceElementsLeaf, new BoxLayoutData(new Margins(0)));
horiz.add(comboColumns, new BoxLayoutData(new Margins(0))); horiz.add(comboColumns, new BoxLayoutData(new Margins(0)));
horiz.add(firstArg, new BoxLayoutData(new Margins(0))); horiz.add(firstArg, new BoxLayoutData(new Margins(0)));
@ -733,11 +829,11 @@ public class ReplaceWidget extends SimpleContainer {
secondArg.setVisible(false); secondArg.setVisible(false);
comboColumns.setVisible(false); comboColumns.setVisible(false);
comboReplaceElementsLeaf.setVisible(false); comboReplaceElementsLeaf.setVisible(false);
comboReplaceElementsConcat.setVisible(true); comboReplaceElementsOperations.setVisible(true);
forceLayout(); forceLayout();
} }
private void removeConcat(ComboBox<ReplaceElement> source) { private void removeOperation(ComboBox<ReplaceElement> source) {
HBoxLayoutContainer horiz = (HBoxLayoutContainer) source.getParent(); HBoxLayoutContainer horiz = (HBoxLayoutContainer) source.getParent();
int index = vert.getWidgetIndex(horiz); int index = vert.getWidgetIndex(horiz);
Log.debug("No concat for index: " + index); Log.debug("No concat for index: " + index);
@ -748,7 +844,7 @@ public class ReplaceWidget extends SimpleContainer {
} }
} }
private boolean existConcat(ComboBox<ReplaceElement> source) { private boolean existOperation(ComboBox<ReplaceElement> source) {
boolean exist = false; boolean exist = false;
HBoxLayoutContainer horiz = (HBoxLayoutContainer) source.getParent(); HBoxLayoutContainer horiz = (HBoxLayoutContainer) source.getParent();
int index = vert.getWidgetIndex(horiz); int index = vert.getWidgetIndex(horiz);
@ -769,7 +865,8 @@ public class ReplaceWidget extends SimpleContainer {
if (vert.getWidgetCount() > 0) { if (vert.getWidgetCount() > 0) {
int index = 0; int index = 0;
expressionContainer = calcCExpression(index); ColumnDataType targetType = targetColumnType;
expressionContainer = calcCExpression(index, targetType);
if (expressionContainer != null) { if (expressionContainer != null) {
readableExpression = expressionContainer readableExpression = expressionContainer
.getReadableExpression(); .getReadableExpression();
@ -788,10 +885,10 @@ public class ReplaceWidget extends SimpleContainer {
return readableExpression; return readableExpression;
} }
protected ExpressionContainer calcCExpression(int index) protected ExpressionContainer calcCExpression(int index,
throws ReplaceTypeMapException { ColumnDataType targetType) throws ReplaceTypeMapException {
ExpressionContainer expressionContainer = null; ExpressionContainer expressionContainer = null;
ExpressionContainer expContainerConcat = null; ExpressionContainer expContainerOperation = null;
C_Expression exp = null; C_Expression exp = null;
C_Expression expLeaf = null; C_Expression expLeaf = null;
String readableExp = ""; String readableExp = "";
@ -803,9 +900,9 @@ public class ReplaceWidget extends SimpleContainer {
horiz = (HBoxLayoutContainer) vert.getWidget(index); horiz = (HBoxLayoutContainer) vert.getWidget(index);
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
ComboBox<ReplaceElement> comboConcat = (ComboBox<ReplaceElement>) horiz ComboBox<ReplaceElement> comboOperations = (ComboBox<ReplaceElement>) horiz
.getItemByItemId(itemIdComboConcat); .getItemByItemId(itemIdComboConcat);
Log.debug("combo Concat: " + comboConcat.getCurrentValue()); Log.debug("combo Concat: " + comboOperations.getCurrentValue());
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
ComboBox<ReplaceElement> comboLeaf = (ComboBox<ReplaceElement>) horiz ComboBox<ReplaceElement> comboLeaf = (ComboBox<ReplaceElement>) horiz
.getItemByItemId(itemIdComboLeaf); .getItemByItemId(itemIdComboLeaf);
@ -823,93 +920,29 @@ public class ReplaceWidget extends SimpleContainer {
+ firstArg.getCurrentValue() + ", secondArg: " + firstArg.getCurrentValue() + ", secondArg: "
+ secondArg.getCurrentValue() + "]"); + secondArg.getCurrentValue() + "]");
ReplaceType comboConcatReplaceType = null; ReplaceType comboOperationsReplaceType = null;
ReplaceType comboLeafReplaceType = null; ReplaceType comboLeafReplaceType = null;
if (comboConcat.getCurrentValue() == null) { if (comboOperations.getCurrentValue() == null) {
if (index == vert.getWidgetCount() - 1) {
switch (replaceColumnByExpressionType) {
case Replace:
exp = mapReplace.map(
column,
ReplaceType.Null,
firstArg == null ? null : firstArg
.getCurrentValue(),
secondArg == null ? null : secondArg
.getCurrentValue(), false);
break;
case Template:
exp = mapReplace.map(
column,
ReplaceType.Null,
firstArg == null ? null : firstArg
.getCurrentValue(),
secondArg == null ? null : secondArg
.getCurrentValue(), true);
break;
default:
exp = mapReplace.map(
column,
ReplaceType.Null,
firstArg == null ? null : firstArg
.getCurrentValue(),
secondArg == null ? null : secondArg
.getCurrentValue(), false);
break;
}
readableExp = mapReplace.getReadableExpression();
expressionContainer = new ExpressionContainer(exp, readableExp);
} else {
throw new ReplaceTypeMapException("Fill all field!"); throw new ReplaceTypeMapException("Fill all field!");
}
} else { } else {
comboConcatReplaceType = comboConcat.getCurrentValue() comboOperationsReplaceType = comboOperations.getCurrentValue()
.getReplaceType(); .getReplaceType();
if (comboConcatReplaceType.compareTo(ReplaceType.Concat) == 0) { if (comboOperationsReplaceType.compareTo(ReplaceType.Concat) == 0) {
if (comboLeaf.getCurrentValue() == null) { if (comboLeaf.getCurrentValue() == null) {
switch (replaceColumnByExpressionType) { throw new ReplaceTypeMapException("Fill all field!");
case Replace:
expLeaf = mapReplace.map(
column,
ReplaceType.Null,
firstArg == null ? null : firstArg
.getCurrentValue(),
secondArg == null ? null : secondArg
.getCurrentValue(), false);
break;
case Template:
expLeaf = mapReplace.map(
column,
ReplaceType.Null,
firstArg == null ? null : firstArg
.getCurrentValue(),
secondArg == null ? null : secondArg
.getCurrentValue(), true);
break;
default:
expLeaf = mapReplace.map(
column,
ReplaceType.Null,
firstArg == null ? null : firstArg
.getCurrentValue(),
secondArg == null ? null : secondArg
.getCurrentValue(), false);
break;
}
readableExpLeaf = mapReplace.getReadableExpression();
} else { } else {
comboLeafReplaceType = comboLeaf.getCurrentValue() comboLeafReplaceType = comboLeaf.getCurrentValue()
.getReplaceType(); .getReplaceType();
/*
* ColumnDataType cType = ColumnDataType
* .getColumnDataTypeFromId(column.getDataTypeName());
*/
switch (replaceColumnByExpressionType) { switch (replaceColumnByExpressionType) {
case Replace: case Replace:
expLeaf = mapReplace.map( expLeaf = mapReplace.map(
column, column,
ColumnDataType.Text,
comboLeafReplaceType, comboLeafReplaceType,
firstArg == null ? null : firstArg firstArg == null ? null : firstArg
.getCurrentValue(), .getCurrentValue(),
@ -919,6 +952,7 @@ public class ReplaceWidget extends SimpleContainer {
case Template: case Template:
expLeaf = mapReplace.map( expLeaf = mapReplace.map(
column, column,
ColumnDataType.Text,
comboLeafReplaceType, comboLeafReplaceType,
firstArg == null ? null : firstArg firstArg == null ? null : firstArg
.getCurrentValue(), .getCurrentValue(),
@ -928,6 +962,7 @@ public class ReplaceWidget extends SimpleContainer {
default: default:
expLeaf = mapReplace.map( expLeaf = mapReplace.map(
column, column,
ColumnDataType.Text,
comboLeafReplaceType, comboLeafReplaceType,
firstArg == null ? null : firstArg firstArg == null ? null : firstArg
.getCurrentValue(), .getCurrentValue(),
@ -942,45 +977,167 @@ public class ReplaceWidget extends SimpleContainer {
index++; index++;
if (index < vert.getWidgetCount()) { if (index < vert.getWidgetCount()) {
expContainerConcat = calcCExpression(index); expContainerOperation = calcCExpression(index,
if (expContainerConcat == null) { ColumnDataType.Text);
if (expContainerOperation == null) {
return null; return null;
} else { } else {
switch (replaceColumnByExpressionType) { switch (replaceColumnByExpressionType) {
case Replace: case Replace:
exp = mapReplace.map( exp = mapReplace.map(
column, column,
comboConcatReplaceType, targetType,
comboOperationsReplaceType,
firstArg == null ? null : firstArg firstArg == null ? null : firstArg
.getCurrentValue(), .getCurrentValue(),
secondArg == null ? null : secondArg secondArg == null ? null : secondArg
.getCurrentValue(), false, expLeaf, .getCurrentValue(), false, expLeaf,
expContainerConcat.getExpression(), expContainerOperation.getExpression(),
readableExpLeaf, expContainerConcat readableExpLeaf, expContainerOperation
.getReadableExpression()); .getReadableExpression());
break; break;
case Template: case Template:
exp = mapReplace.map( exp = mapReplace.map(
column, column,
comboConcatReplaceType, targetType,
comboOperationsReplaceType,
firstArg == null ? null : firstArg firstArg == null ? null : firstArg
.getCurrentValue(), .getCurrentValue(),
secondArg == null ? null : secondArg secondArg == null ? null : secondArg
.getCurrentValue(), true, expLeaf, .getCurrentValue(), true, expLeaf,
expContainerConcat.getExpression(), expContainerOperation.getExpression(),
readableExpLeaf, expContainerConcat readableExpLeaf, expContainerOperation
.getReadableExpression()); .getReadableExpression());
break; break;
default: default:
exp = mapReplace.map( exp = mapReplace.map(
column, column,
comboConcatReplaceType, targetType,
comboOperationsReplaceType,
firstArg == null ? null : firstArg firstArg == null ? null : firstArg
.getCurrentValue(), .getCurrentValue(),
secondArg == null ? null : secondArg secondArg == null ? null : secondArg
.getCurrentValue(), false, expLeaf, .getCurrentValue(), false, expLeaf,
expContainerConcat.getExpression(), expContainerOperation.getExpression(),
readableExpLeaf, expContainerConcat readableExpLeaf, expContainerOperation
.getReadableExpression());
break;
}
readableExp = mapReplace.getReadableExpression();
expressionContainer = new ExpressionContainer(exp,
readableExp);
}
} else {
return null;
}
} else {
if (comboOperationsReplaceType.compareTo(ReplaceType.Addition) == 0
|| comboOperationsReplaceType
.compareTo(ReplaceType.Subtraction) == 0
|| comboOperationsReplaceType
.compareTo(ReplaceType.Modulus) == 0
|| comboOperationsReplaceType
.compareTo(ReplaceType.Multiplication) == 0
|| comboOperationsReplaceType
.compareTo(ReplaceType.Division) == 0) {
ColumnDataType cType;
if (comboLeaf.getCurrentValue() == null) {
throw new ReplaceTypeMapException("Fill all field!");
} else {
comboLeafReplaceType = comboLeaf.getCurrentValue()
.getReplaceType();
cType = ColumnDataType
.getColumnDataTypeFromId(column
.getDataTypeName());
switch (replaceColumnByExpressionType) {
case Replace:
expLeaf = mapReplace.map(
column,
cType,
comboLeafReplaceType,
firstArg == null ? null : firstArg
.getCurrentValue(),
secondArg == null ? null : secondArg
.getCurrentValue(), false);
break;
case Template:
expLeaf = mapReplace.map(
column,
cType,
comboLeafReplaceType,
firstArg == null ? null : firstArg
.getCurrentValue(),
secondArg == null ? null : secondArg
.getCurrentValue(), true);
break;
default:
expLeaf = mapReplace.map(
column,
cType,
comboLeafReplaceType,
firstArg == null ? null : firstArg
.getCurrentValue(),
secondArg == null ? null : secondArg
.getCurrentValue(), false);
break;
}
readableExpLeaf = mapReplace.getReadableExpression();
}
index++;
if (index < vert.getWidgetCount()) {
expContainerOperation = calcCExpression(index,
cType);
if (expContainerOperation == null) {
return null;
} else {
switch (replaceColumnByExpressionType) {
case Replace:
exp = mapReplace.map(
column,
targetType,
comboOperationsReplaceType,
firstArg == null ? null : firstArg
.getCurrentValue(),
secondArg == null ? null : secondArg
.getCurrentValue(), false,
expLeaf, expContainerOperation
.getExpression(),
readableExpLeaf, expContainerOperation
.getReadableExpression());
break;
case Template:
exp = mapReplace.map(
column,
targetType,
comboOperationsReplaceType,
firstArg == null ? null : firstArg
.getCurrentValue(),
secondArg == null ? null : secondArg
.getCurrentValue(), true,
expLeaf, expContainerOperation
.getExpression(),
readableExpLeaf, expContainerOperation
.getReadableExpression());
break;
default:
exp = mapReplace.map(
column,
targetType,
comboOperationsReplaceType,
firstArg == null ? null : firstArg
.getCurrentValue(),
secondArg == null ? null : secondArg
.getCurrentValue(), false,
expLeaf, expContainerOperation
.getExpression(),
readableExpLeaf, expContainerOperation
.getReadableExpression()); .getReadableExpression());
break; break;
@ -996,28 +1153,41 @@ public class ReplaceWidget extends SimpleContainer {
} else { } else {
switch (replaceColumnByExpressionType) { switch (replaceColumnByExpressionType) {
case Replace: case Replace:
exp = mapReplace.map(column, comboConcatReplaceType, exp = mapReplace.map(
firstArg == null ? null : firstArg.getCurrentValue(), column,
secondArg == null ? null : secondArg.getCurrentValue(), targetType,
false); comboOperationsReplaceType,
firstArg == null ? null : firstArg
.getCurrentValue(),
secondArg == null ? null : secondArg
.getCurrentValue(), false);
break; break;
case Template: case Template:
exp = mapReplace.map(column, comboConcatReplaceType, exp = mapReplace.map(
firstArg == null ? null : firstArg.getCurrentValue(), column,
secondArg == null ? null : secondArg.getCurrentValue(), targetType,
true); comboOperationsReplaceType,
firstArg == null ? null : firstArg
.getCurrentValue(),
secondArg == null ? null : secondArg
.getCurrentValue(), true);
break; break;
default: default:
exp = mapReplace.map(column, comboConcatReplaceType, exp = mapReplace.map(
firstArg == null ? null : firstArg.getCurrentValue(), column,
secondArg == null ? null : secondArg.getCurrentValue(), targetType,
false); comboOperationsReplaceType,
firstArg == null ? null : firstArg
.getCurrentValue(),
secondArg == null ? null : secondArg
.getCurrentValue(), false);
break; break;
} }
readableExp = mapReplace.getReadableExpression(); readableExp = mapReplace.getReadableExpression();
expressionContainer = new ExpressionContainer(exp, readableExp); expressionContainer = new ExpressionContainer(exp,
readableExp);
}
} }
} }
return expressionContainer; return expressionContainer;

View File

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

View File

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

View File

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

View File

@ -12,7 +12,7 @@ import org.gcube.portlets.user.td.expressionwidget.shared.replace.ReplaceType;
*/ */
public class ReplaceElementStore { public class ReplaceElementStore {
public ArrayList<ReplaceElement> replaceElementsConcat = new ArrayList<ReplaceElement>() { public ArrayList<ReplaceElement> replaceElementsOperations = new ArrayList<ReplaceElement>() {
private static final long serialVersionUID = 1690916203781730778L; private static final long serialVersionUID = 1690916203781730778L;
@ -24,6 +24,11 @@ public class ReplaceElementStore {
add(new ReplaceElement(5, ReplaceType.SubstringByCharSeq)); add(new ReplaceElement(5, ReplaceType.SubstringByCharSeq));
add(new ReplaceElement(6, ReplaceType.TextReplaceMatchingRegex)); add(new ReplaceElement(6, ReplaceType.TextReplaceMatchingRegex));
add(new ReplaceElement(7, ReplaceType.Concat)); add(new ReplaceElement(7, ReplaceType.Concat));
add(new ReplaceElement(8, ReplaceType.Addition));
add(new ReplaceElement(9, ReplaceType.Subtraction));
add(new ReplaceElement(10, ReplaceType.Modulus));
add(new ReplaceElement(11, ReplaceType.Multiplication));
add(new ReplaceElement(12, ReplaceType.Division));
} }
}; };
@ -42,4 +47,15 @@ public class ReplaceElementStore {
} }
}; };
public ArrayList<ReplaceElement> replaceElementsArithmetic = new ArrayList<ReplaceElement>() {
private static final long serialVersionUID = 1690916203781730778L;
{
add(new ReplaceElement(1, ReplaceType.ColumnValue));
}
};
} }

View File

@ -7,18 +7,17 @@ import org.gcube.portlets.user.td.widgetcommonevent.shared.tr.column.ColumnDataT
/** /**
* *
* @author giancarlo * @author giancarlo email: <a
* email: <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a> * href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
* *
*/ */
public class C_ArithmeticExpression extends C_Expression { public class C_ArithmeticExpression extends C_Expression {
private static final long serialVersionUID = 897961910530874376L; private static final long serialVersionUID = 897961910530874376L;
private String id = "ArithmeticExpression";
private String id="ArithmeticExpression"; public static final ArrayList<ColumnDataType> acceptedDataTypes = new ArrayList<ColumnDataType>();
public static final ArrayList<ColumnDataType> acceptedDataTypes=new ArrayList<ColumnDataType>();
protected C_Expression leftArgument; protected C_Expression leftArgument;
protected C_Expression rightArgument; protected C_Expression rightArgument;
@ -27,12 +26,12 @@ public class C_ArithmeticExpression extends C_Expression {
} }
public C_ArithmeticExpression(C_Expression leftArgument, C_Expression rightArgument) { public C_ArithmeticExpression(C_Expression leftArgument,
C_Expression rightArgument) {
this.leftArgument = leftArgument; this.leftArgument = leftArgument;
this.rightArgument = rightArgument; this.rightArgument = rightArgument;
} }
static { static {
acceptedDataTypes.add(ColumnDataType.Numeric); acceptedDataTypes.add(ColumnDataType.Numeric);
acceptedDataTypes.add(ColumnDataType.Integer); acceptedDataTypes.add(ColumnDataType.Integer);
@ -40,7 +39,6 @@ public class C_ArithmeticExpression extends C_Expression {
acceptedDataTypes.add(ColumnDataType.Geometry); acceptedDataTypes.add(ColumnDataType.Geometry);
} }
public String getReturnedDataType() { public String getReturnedDataType() {
return "DataType"; return "DataType";
} }
@ -53,13 +51,20 @@ public class C_ArithmeticExpression extends C_Expression {
return acceptedDataTypes; return acceptedDataTypes;
} }
public static boolean isAccepted(ColumnDataType columnDataType) {
for (ColumnDataType c : acceptedDataTypes) {
if (c.compareTo(columnDataType) == 0) {
return true;
}
}
return false;
}
@Override @Override
public String getId() { public String getId() {
return id; return id;
} }
public C_Expression getLeftArgument() { public C_Expression getLeftArgument() {
return leftArgument; return leftArgument;
} }
@ -82,7 +87,4 @@ public class C_ArithmeticExpression extends C_Expression {
+ leftArgument + ", rightArgument=" + rightArgument + "]"; + leftArgument + ", rightArgument=" + rightArgument + "]";
} }
} }

View File

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

View File

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

View File

@ -7,14 +7,20 @@ package org.gcube.portlets.user.td.expressionwidget.shared.replace;
* *
*/ */
public enum ReplaceType { public enum ReplaceType {
Null("Null"),
Value("Value"), Value("Value"),
ColumnValue("Column Value"), ColumnValue("Column Value"),
SubstringByRegex("Substring by Regex"), SubstringByRegex("Substring by Regex"),
SubstringByIndex("Substring by Index"), SubstringByIndex("Substring by Index"),
SubstringByCharSeq("Substring by Char Seq."), SubstringByCharSeq("Substring by Char Seq."),
TextReplaceMatchingRegex("Replace Matching Regex"), TextReplaceMatchingRegex("Replace Matching Regex"),
Concat("Concat"); Concat("Concat"),
Addition("Addition"),
Subtraction("Subtraction"),
Modulus("Modulus"),
Multiplication("Multiplication"),
Division("Division");
/** /**
* @param text * @param text

View File

@ -1,6 +1,11 @@
package org.gcube.portlets.user.td.expressionwidget.shared.replace; package org.gcube.portlets.user.td.expressionwidget.shared.replace;
import org.gcube.portlets.user.td.expressionwidget.shared.exception.ReplaceTypeMapException; import org.gcube.portlets.user.td.expressionwidget.shared.exception.ReplaceTypeMapException;
import org.gcube.portlets.user.td.expressionwidget.shared.model.composite.arithmetic.C_Addition;
import org.gcube.portlets.user.td.expressionwidget.shared.model.composite.arithmetic.C_Division;
import org.gcube.portlets.user.td.expressionwidget.shared.model.composite.arithmetic.C_Modulus;
import org.gcube.portlets.user.td.expressionwidget.shared.model.composite.arithmetic.C_Multiplication;
import org.gcube.portlets.user.td.expressionwidget.shared.model.composite.arithmetic.C_Subtraction;
import org.gcube.portlets.user.td.expressionwidget.shared.model.composite.functions.C_Cast; import org.gcube.portlets.user.td.expressionwidget.shared.model.composite.functions.C_Cast;
import org.gcube.portlets.user.td.expressionwidget.shared.model.composite.text.C_Concat; import org.gcube.portlets.user.td.expressionwidget.shared.model.composite.text.C_Concat;
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_SubstringByIndex;
@ -30,28 +35,28 @@ public class ReplaceTypeMap {
} }
public C_Expression map(ColumnData column, ReplaceType replaceType, public C_Expression map(ColumnData column, ColumnDataType targetType, ReplaceType replaceType,
String firstArg, String secondArg,boolean template) throws ReplaceTypeMapException { String firstArg, String secondArg,boolean template) throws ReplaceTypeMapException {
return map(column, replaceType,firstArg, secondArg, template, null, null, null, null); return map(column, targetType, replaceType,firstArg, secondArg, template, null, null, null, null);
} }
public C_Expression map(ColumnData column, ReplaceType replaceType, public C_Expression map(ColumnData column, ColumnDataType targetType, ReplaceType replaceType,
String firstArg, String secondArg, boolean template, C_Expression firstE, String firstArg, String secondArg, boolean template, C_Expression firstE,
C_Expression secondE, String readableFirstE, String readableSecondE) throws ReplaceTypeMapException { C_Expression secondE, String readableFirstE, String readableSecondE) throws ReplaceTypeMapException {
Log.debug("ReplaceTypeMap Map"); Log.debug("ReplaceTypeMap Map");
C_Expression exp = null; C_Expression exp = null;
readableExpression = new String(); readableExpression = new String();
if (template) { if (template) {
exp = mapPlaceHolder(column, replaceType, firstArg, secondArg, exp = mapPlaceHolder(column, targetType, replaceType, firstArg, secondArg,
firstE, secondE, readableFirstE,readableSecondE); firstE, secondE, readableFirstE,readableSecondE);
} else { } else {
exp = mapColumnReference(column, replaceType, firstArg, exp = mapColumnReference(column, targetType, replaceType, firstArg,
secondArg, firstE, secondE,readableFirstE,readableSecondE); secondArg, firstE, secondE,readableFirstE,readableSecondE);
} }
return exp; return exp;
} }
public C_Expression mapPlaceHolder(ColumnData column, public C_Expression mapPlaceHolder(ColumnData column,ColumnDataType targetType,
ReplaceType replaceType, String firstArg, String secondArg, ReplaceType replaceType, String firstArg, String secondArg,
C_Expression firstE, C_Expression secondE,String readableFirstE, String readableSecondE) throws ReplaceTypeMapException { C_Expression firstE, C_Expression secondE,String readableFirstE, String readableSecondE) throws ReplaceTypeMapException {
Log.debug("ReplaceTypeMap Map Place Holder"); Log.debug("ReplaceTypeMap Map Place Holder");
@ -59,19 +64,47 @@ public class ReplaceTypeMap {
if(column==null){ if(column==null){
switch (replaceType) { switch (replaceType) {
case Null:
exp = new TD_Value(ColumnDataType.Text, "");
readableExpression = "Null()";
break;
case Value: case Value:
checkTypeArgument(ColumnDataType.Text,firstArg); checkTypeArgument(targetType,firstArg);
exp = new TD_Value(ColumnDataType.Text, firstArg); exp = new TD_Value(targetType, firstArg);
readableExpression = "Value(" + firstArg + ")"; readableExpression = "Value(" + firstArg + ")";
break; break;
case Concat: case Concat:
exp = new C_Concat(firstE, secondE); C_Concat concat = new C_Concat(firstE, secondE);
readableExpression = "Concat(" + readableFirstE exp= new C_Cast(concat,targetType);
+ ", " + readableSecondE + ")"; readableExpression = "Cast(Concat(" + readableFirstE
+ ", " + readableSecondE + "),"+targetType+")";
break;
case Addition:
C_Addition add = new C_Addition(firstE, secondE);
exp= new C_Cast(add, targetType);
readableExpression = "Cast(Addition(" + readableFirstE + ", "
+ readableSecondE + "),"+targetType+")";
break;
case Subtraction:
C_Subtraction sub = new C_Subtraction(firstE, secondE);
exp= new C_Cast(sub,targetType);
readableExpression = "Cast(Subtraction(" + readableFirstE + ", "
+ readableSecondE + "),"+targetType+")";
break;
case Modulus:
C_Modulus modu = new C_Modulus(firstE, secondE);
exp=new C_Cast(modu,targetType);
readableExpression = "Cast(Modulus(" + readableFirstE + ", "
+ readableSecondE + "),"+targetType+")";
break;
case Multiplication:
C_Multiplication multi = new C_Multiplication(firstE, secondE);
exp=new C_Cast(multi,targetType);
readableExpression = "Cast(Multiplication(" + readableFirstE + ", "
+ readableSecondE + "),"+targetType+")";
break;
case Division:
C_Division divi = new C_Division(firstE, secondE);
exp=new C_Cast(divi,targetType);
readableExpression = "Cast(Division(" + readableFirstE + ", "
+ readableSecondE + "),"+targetType+")";
break; break;
default: default:
throw new ReplaceTypeMapException("No valid column selected"); throw new ReplaceTypeMapException("No valid column selected");
@ -79,7 +112,79 @@ public class ReplaceTypeMap {
return exp; return exp;
} }
switch (replaceType) {
case Value:
checkTypeArgument(targetType,firstArg);
exp = new TD_Value(targetType, firstArg);
readableExpression = "Value(" + firstArg + ")";
break;
case ColumnValue:
exp = columnValuePlaceHolder(column, targetType);
break;
case Concat:
C_Concat concat = new C_Concat(firstE, secondE);
exp= new C_Cast(concat,targetType);
readableExpression = "Cast(Concat(" + readableFirstE
+ ", " + readableSecondE + "),"+targetType+")";
break;
case Addition:
C_Addition add = new C_Addition(firstE, secondE);
exp= new C_Cast(add, targetType);
readableExpression = "Cast(Addition(" + readableFirstE + ", "
+ readableSecondE + "),"+targetType+")";
break;
case Subtraction:
C_Subtraction sub = new C_Subtraction(firstE, secondE);
exp= new C_Cast(sub,targetType);
readableExpression = "Cast(Subtraction(" + readableFirstE + ", "
+ readableSecondE + "),"+targetType+")";
break;
case Modulus:
C_Modulus modu = new C_Modulus(firstE, secondE);
exp=new C_Cast(modu,targetType);
readableExpression = "Cast(Modulus(" + readableFirstE + ", "
+ readableSecondE + "),"+targetType+")";
break;
case Multiplication:
C_Multiplication multi = new C_Multiplication(firstE, secondE);
exp=new C_Cast(multi,targetType);
readableExpression = "Cast(Multiplication(" + readableFirstE + ", "
+ readableSecondE + "),"+targetType+")";
break;
case Division:
C_Division divi = new C_Division(firstE, secondE);
exp=new C_Cast(divi,targetType);
readableExpression = "Cast(Division(" + readableFirstE + ", "
+ readableSecondE + "),"+targetType+")";
break;
case SubstringByRegex:
exp = substringByRegexPlaceHolder(column, targetType, firstArg);
break;
case SubstringByIndex:
exp = substringByIndexPlaceHolder(column, targetType, firstArg,
secondArg);
break;
case SubstringByCharSeq:
exp = substringByCharSeqPlaceHolder(column, targetType, firstArg,
secondArg);
break;
case TextReplaceMatchingRegex:
exp = textReplaceMatchingRegexPlaceHolder(column, targetType,
firstArg, secondArg);
break;
default:
break;
}
return exp;
}
private C_Expression textReplaceMatchingRegexPlaceHolder(ColumnData column,
ColumnDataType targetType, String firstArg, String secondArg)
throws ReplaceTypeMapException {
C_Expression exp;
TD_Value fArg;
TD_Value sArg;
Log.debug("Column Data Type Name:" + column.getDataTypeName()); Log.debug("Column Data Type Name:" + column.getDataTypeName());
ColumnDataType dataType = ColumnDataType ColumnDataType dataType = ColumnDataType
.getColumnDataTypeFromId(column .getColumnDataTypeFromId(column
@ -90,8 +195,8 @@ public class ReplaceTypeMap {
C_Expression placeHolder; C_Expression placeHolder;
String readablePlaceHolder; String readablePlaceHolder;
if(dataType!=ColumnDataType.Text){ if(dataType!=ColumnDataType.Text){
placeHolder=new C_Cast(placeH,ColumnDataType.Text); placeHolder=new C_Cast(placeH, ColumnDataType.Text);
readablePlaceHolder= "Cast("+column.getColumnId()+")"; readablePlaceHolder= "Cast("+column.getColumnId()+","+ColumnDataType.Text+")";
} else { } else {
placeHolder=placeH; placeHolder=placeH;
readablePlaceHolder= column.getColumnId(); readablePlaceHolder= column.getColumnId();
@ -99,71 +204,157 @@ public class ReplaceTypeMap {
} }
Log.debug("placeHolder:" + placeHolder); Log.debug("placeHolder:" + placeHolder);
TD_Value fArg, sArg;
C_Expression posFrom, posTo;
switch (replaceType) {
case Null:
exp = new TD_Value(ColumnDataType.Text, "");
readableExpression = "Null()";
break;
case Value:
checkTypeArgument(ColumnDataType.Text,firstArg);
exp = new TD_Value(ColumnDataType.Text, firstArg);
readableExpression = "Value(" + firstArg + ")";
break;
case ColumnValue:
exp = placeHolder;
readableExpression = "ColumnValue(" + readablePlaceHolder + ")";
break;
case Concat:
exp = new C_Concat(firstE, secondE);
readableExpression = "Concat(" + readableFirstE
+ ", " + readableSecondE + ")";
break;
case SubstringByRegex:
checkTypeArgument(ColumnDataType.Text,firstArg); checkTypeArgument(ColumnDataType.Text,firstArg);
checkTypeArgument(ColumnDataType.Text,secondArg);
fArg = new TD_Value(ColumnDataType.Text, firstArg); fArg = new TD_Value(ColumnDataType.Text, firstArg);
exp = new C_SubstringByRegex(placeHolder, fArg); sArg = new TD_Value(ColumnDataType.Text, secondArg);
readableExpression = "SubStringByRegex(" + readablePlaceHolder C_TextReplaceMatchingRegex substring = new C_TextReplaceMatchingRegex(placeHolder, fArg, sArg);
+ ", " + firstArg + ")"; exp=new C_Cast(substring, targetType);
break; readableExpression = "Cast(TextReplaceMatchingRegex(" + readablePlaceHolder
case SubstringByIndex: + ", " + firstArg + ", " + secondArg + "),"+targetType+")";
checkTypeArgument(ColumnDataType.Integer,firstArg); return exp;
checkTypeArgument(ColumnDataType.Integer,secondArg); }
fArg = new TD_Value(ColumnDataType.Integer, firstArg);
sArg = new TD_Value(ColumnDataType.Integer, secondArg); private C_Expression substringByCharSeqPlaceHolder(ColumnData column,
exp = new C_SubstringByIndex(placeHolder, fArg, sArg); ColumnDataType targetType, String firstArg, String secondArg)
readableExpression = "SubstringByIndex(" + readablePlaceHolder throws ReplaceTypeMapException {
+ ", " + firstArg + ", " + secondArg + ")"; C_Expression exp;
break; TD_Value fArg;
case SubstringByCharSeq: //TD_Value sArg;
C_Expression posFrom;
C_Expression posTo;
Log.debug("Column Data Type Name:" + column.getDataTypeName());
ColumnDataType dataType = ColumnDataType
.getColumnDataTypeFromId(column
.getDataTypeName());
Log.debug("Data Type:" + dataType);
C_ColumnReferencePlaceholder placeH = new C_ColumnReferencePlaceholder(
dataType, column.getColumnId());
C_Expression placeHolder;
String readablePlaceHolder;
if(dataType!=ColumnDataType.Text){
placeHolder=new C_Cast(placeH, ColumnDataType.Text);
readablePlaceHolder= "Cast("+column.getColumnId()+","+ColumnDataType.Text+")";
} else {
placeHolder=placeH;
readablePlaceHolder= column.getColumnId();
}
Log.debug("placeHolder:" + placeHolder);
checkTypeArgument(ColumnDataType.Text,firstArg); checkTypeArgument(ColumnDataType.Text,firstArg);
fArg = new TD_Value(ColumnDataType.Text, firstArg); fArg = new TD_Value(ColumnDataType.Text, firstArg);
posFrom = new C_SubstringPosition(placeHolder, fArg); posFrom = new C_SubstringPosition(placeHolder, fArg);
checkTypeArgument(ColumnDataType.Text,secondArg); checkTypeArgument(ColumnDataType.Text,secondArg);
sArg = new TD_Value(ColumnDataType.Text, secondArg); //sArg = new TD_Value(ColumnDataType.Text, secondArg);
posTo = new C_SubstringPosition(placeHolder, fArg); posTo = new C_SubstringPosition(placeHolder, fArg);
exp = new C_SubstringByIndex(placeHolder, posFrom, posTo); C_SubstringByIndex substring = new C_SubstringByIndex(placeHolder, posFrom, posTo);
readableExpression = "SubstringByCharSeq(" + readablePlaceHolder exp=new C_Cast(substring, targetType);
+ ", " + firstArg + ", " + secondArg + ")"; readableExpression = "Cast(SubstringByCharSeq(" + readablePlaceHolder
break; + ", " + firstArg + ", " + secondArg + "),"+targetType+")";
case TextReplaceMatchingRegex:
checkTypeArgument(ColumnDataType.Text,firstArg);
checkTypeArgument(ColumnDataType.Text,secondArg);
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;
}
return exp; return exp;
} }
public C_Expression mapColumnReference(ColumnData column, private C_Expression substringByIndexPlaceHolder(ColumnData column,
ColumnDataType targetType, String firstArg, String secondArg)
throws ReplaceTypeMapException {
C_Expression exp;
TD_Value fArg;
TD_Value sArg;
Log.debug("Column Data Type Name:" + column.getDataTypeName());
ColumnDataType dataType = ColumnDataType
.getColumnDataTypeFromId(column
.getDataTypeName());
Log.debug("Data Type:" + dataType);
C_ColumnReferencePlaceholder placeH = new C_ColumnReferencePlaceholder(
dataType, column.getColumnId());
C_Expression placeHolder;
String readablePlaceHolder;
if(dataType!=ColumnDataType.Text){
placeHolder=new C_Cast(placeH, ColumnDataType.Text);
readablePlaceHolder= "Cast("+column.getColumnId()+","+ColumnDataType.Text+")";
} else {
placeHolder=placeH;
readablePlaceHolder= column.getColumnId();
}
Log.debug("placeHolder:" + placeHolder);
checkTypeArgument(ColumnDataType.Integer,firstArg);
checkTypeArgument(ColumnDataType.Integer,secondArg);
fArg = new TD_Value(ColumnDataType.Integer, firstArg);
sArg = new TD_Value(ColumnDataType.Integer, secondArg);
C_SubstringByIndex substring = new C_SubstringByIndex(placeHolder, fArg, sArg);
exp=new C_Cast(substring, targetType);
readableExpression = "Cast(SubstringByIndex(" + readablePlaceHolder
+ ", " + firstArg + ", " + secondArg + "),"+targetType+")";
return exp;
}
private C_Expression substringByRegexPlaceHolder(ColumnData column,
ColumnDataType targetType, String firstArg)
throws ReplaceTypeMapException {
C_Expression exp;
TD_Value fArg;
Log.debug("Column Data Type Name:" + column.getDataTypeName());
ColumnDataType dataType = ColumnDataType
.getColumnDataTypeFromId(column
.getDataTypeName());
Log.debug("Data Type:" + dataType);
C_ColumnReferencePlaceholder placeH = new C_ColumnReferencePlaceholder(
dataType, column.getColumnId());
C_Expression placeHolder;
String readablePlaceHolder;
if(dataType!=ColumnDataType.Text){
placeHolder=new C_Cast(placeH, ColumnDataType.Text);
readablePlaceHolder= "Cast("+column.getColumnId()+","+ColumnDataType.Text+")";
} else {
placeHolder=placeH;
readablePlaceHolder= column.getColumnId();
}
Log.debug("placeHolder:" + placeHolder);
checkTypeArgument(ColumnDataType.Text,firstArg);
fArg = new TD_Value(ColumnDataType.Text, firstArg);
C_SubstringByRegex substring = new C_SubstringByRegex(placeHolder, fArg);
exp=new C_Cast(substring, targetType);
readableExpression = "Cast(SubStringByRegex(" + readablePlaceHolder
+ ", " + firstArg + "),"+targetType+")";
return exp;
}
private C_Expression columnValuePlaceHolder(ColumnData column,
ColumnDataType targetType) {
C_Expression exp;
Log.debug("Column Data Type Name:" + column.getDataTypeName());
ColumnDataType dataType = ColumnDataType
.getColumnDataTypeFromId(column
.getDataTypeName());
Log.debug("Data Type:" + dataType);
C_ColumnReferencePlaceholder placeH = new C_ColumnReferencePlaceholder(
dataType, column.getColumnId());
C_Expression placeHolder;
String readablePlaceHolder;
if(dataType!=targetType){
placeHolder=new C_Cast(placeH, targetType);
readablePlaceHolder= "Cast("+column.getColumnId()+","+targetType+")";
} else {
placeHolder=placeH;
readablePlaceHolder= column.getColumnId();
}
Log.debug("placeHolder:" + placeHolder);
exp = placeHolder;
readableExpression = "ColumnValue(" + readablePlaceHolder + ")";
return exp;
}
public C_Expression mapColumnReference(ColumnData column,ColumnDataType targetType,
ReplaceType replaceType, String firstArg, String secondArg, ReplaceType replaceType, String firstArg, String secondArg,
C_Expression firstE, C_Expression secondE, String readableFirstE, String readableSecondE) throws ReplaceTypeMapException { C_Expression firstE, C_Expression secondE, String readableFirstE, String readableSecondE) throws ReplaceTypeMapException {
Log.debug("ReplaceTypeMap Map Typed Column Reference"); Log.debug("ReplaceTypeMap Map Typed Column Reference");
@ -171,19 +362,47 @@ public class ReplaceTypeMap {
if(column==null){ if(column==null){
switch (replaceType) { switch (replaceType) {
case Null:
exp = new TD_Value(ColumnDataType.Text, "");
readableExpression = "Null()";
break;
case Value: case Value:
checkTypeArgument(ColumnDataType.Text,firstArg); checkTypeArgument(targetType,firstArg);
exp = new TD_Value(ColumnDataType.Text, firstArg); exp = new TD_Value(targetType, firstArg);
readableExpression = "Value(" + firstArg + ")"; readableExpression = "Value(" + firstArg + ")";
break; break;
case Concat: case Concat:
exp = new C_Concat(firstE, secondE); C_Concat concat = new C_Concat(firstE, secondE);
readableExpression = "Concat(" + readableFirstE exp= new C_Cast(concat,targetType);
+ ", " + readableSecondE + ")"; readableExpression = "Cast(Concat(" + readableFirstE
+ ", " + readableSecondE + "),"+targetType+")";
break;
case Addition:
C_Addition add = new C_Addition(firstE, secondE);
exp= new C_Cast(add, targetType);
readableExpression = "Cast(Addition(" + readableFirstE + ", "
+ readableSecondE + "),"+targetType+")";
break;
case Subtraction:
C_Subtraction sub = new C_Subtraction(firstE, secondE);
exp= new C_Cast(sub,targetType);
readableExpression = "Cast(Subtraction(" + readableFirstE + ", "
+ readableSecondE + "),"+targetType+")";
break;
case Modulus:
C_Modulus modu = new C_Modulus(firstE, secondE);
exp=new C_Cast(modu,targetType);
readableExpression = "Cast(Modulus(" + readableFirstE + ", "
+ readableSecondE + "),"+targetType+")";
break;
case Multiplication:
C_Multiplication multi = new C_Multiplication(firstE, secondE);
exp=new C_Cast(multi,targetType);
readableExpression = "Cast(Multiplication(" + readableFirstE + ", "
+ readableSecondE + "),"+targetType+")";
break;
case Division:
C_Division divi = new C_Division(firstE, secondE);
exp=new C_Cast(divi,targetType);
readableExpression = "Cast(Division(" + readableFirstE + ", "
+ readableSecondE + "),"+targetType+")";
break; break;
default: default:
throw new ReplaceTypeMapException("No valid column selected"); throw new ReplaceTypeMapException("No valid column selected");
@ -192,6 +411,79 @@ public class ReplaceTypeMap {
} }
switch (replaceType) {
case Value:
checkTypeArgument(targetType, firstArg);
exp = new TD_Value(targetType, firstArg);
readableExpression = "Value(" + firstArg + ")";
break;
case ColumnValue:
exp = columnValueReference(column, targetType);
break;
case Concat:
C_Concat concat = new C_Concat(firstE, secondE);
exp= new C_Cast(concat,targetType);
readableExpression = "Cast(Concat(" + readableFirstE
+ ", " + readableSecondE + "),"+targetType+")";
break;
case Addition:
C_Addition add = new C_Addition(firstE, secondE);
exp= new C_Cast(add, targetType);
readableExpression = "Cast(Addition(" + readableFirstE + ", "
+ readableSecondE + "),"+targetType+")";
break;
case Subtraction:
C_Subtraction sub = new C_Subtraction(firstE, secondE);
exp= new C_Cast(sub,targetType);
readableExpression = "Cast(Subtraction(" + readableFirstE + ", "
+ readableSecondE + "),"+targetType+")";
break;
case Modulus:
C_Modulus modu = new C_Modulus(firstE, secondE);
exp=new C_Cast(modu,targetType);
readableExpression = "Cast(Modulus(" + readableFirstE + ", "
+ readableSecondE + "),"+targetType+")";
break;
case Multiplication:
C_Multiplication multi = new C_Multiplication(firstE, secondE);
exp=new C_Cast(multi,targetType);
readableExpression = "Cast(Multiplication(" + readableFirstE + ", "
+ readableSecondE + "),"+targetType+")";
break;
case Division:
C_Division divi = new C_Division(firstE, secondE);
exp=new C_Cast(divi,targetType);
readableExpression = "Cast(Division(" + readableFirstE + ", "
+ readableSecondE + "),"+targetType+")";
break;
case SubstringByRegex:
exp = SubstringByRegexReference(column, targetType, firstArg);
break;
case SubstringByIndex:
exp = substringByIndexReference(column, targetType, firstArg,
secondArg);
break;
case SubstringByCharSeq:
exp = substringByCharSeq(column, targetType, firstArg, secondArg);
break;
case TextReplaceMatchingRegex:
exp = textReplaceMatchingRegexReference(column, targetType,
firstArg, secondArg);
break;
default:
break;
}
return exp;
}
private C_Expression textReplaceMatchingRegexReference(ColumnData column,
ColumnDataType targetType, String firstArg, String secondArg)
throws ReplaceTypeMapException {
C_Expression exp;
TD_Value fArg;
TD_Value sArg;
Log.debug("Column Data Type Name:" + column.getDataTypeName()); Log.debug("Column Data Type Name:" + column.getDataTypeName());
ColumnDataType dataType = ColumnDataType ColumnDataType dataType = ColumnDataType
.getColumnDataTypeFromId(column .getColumnDataTypeFromId(column
@ -205,7 +497,7 @@ public class ReplaceTypeMap {
String readableColumnReference; String readableColumnReference;
if(dataType!=ColumnDataType.Text){ if(dataType!=ColumnDataType.Text){
columnReference=new C_Cast(columnRef,ColumnDataType.Text); columnReference=new C_Cast(columnRef,ColumnDataType.Text);
readableColumnReference= "Cast("+column.getColumnId()+")"; readableColumnReference= "Cast("+column.getColumnId()+","+ColumnDataType.Text+")";
} else { } else {
columnReference=columnRef; columnReference=columnRef;
readableColumnReference= column.getColumnId(); readableColumnReference= column.getColumnId();
@ -213,69 +505,158 @@ public class ReplaceTypeMap {
} }
Log.debug("Typed Column Reference:" + columnReference); Log.debug("Typed Column Reference:" + columnReference);
TD_Value fArg, sArg;
C_Expression posFrom, posTo;
switch (replaceType) {
case Null:
exp = new TD_Value(ColumnDataType.Text, "");
readableExpression = "Null()";
break;
case Value:
checkTypeArgument(ColumnDataType.Text, firstArg);
exp = new TD_Value(ColumnDataType.Text, firstArg);
readableExpression = "Value(" + firstArg + ")";
break;
case ColumnValue:
exp = columnReference;
readableExpression = "ColumnValue(" + readableColumnReference + ")";
break;
case Concat:
exp = new C_Concat(firstE, secondE);
readableExpression = "Concat(" + readableFirstE
+ ", " + readableSecondE + ")";
break;
case SubstringByRegex:
checkTypeArgument(ColumnDataType.Text, firstArg); checkTypeArgument(ColumnDataType.Text, firstArg);
checkTypeArgument(ColumnDataType.Text, secondArg);
fArg = new TD_Value(ColumnDataType.Text, firstArg); fArg = new TD_Value(ColumnDataType.Text, firstArg);
exp = new C_SubstringByRegex(columnReference, fArg); sArg = new TD_Value(ColumnDataType.Text, secondArg);
readableExpression = "SubStringByRegex(" + readableColumnReference C_TextReplaceMatchingRegex substring = new C_TextReplaceMatchingRegex(columnReference, fArg, sArg);
+ ", " + firstArg + ")"; exp=new C_Cast(substring, targetType);
break; readableExpression = "Cast(TextReplaceMatchingRegex(" + readableColumnReference
case SubstringByIndex: + ", " + firstArg + ", " + secondArg + "),"+targetType+")";
checkTypeArgument(ColumnDataType.Integer, firstArg); return exp;
checkTypeArgument(ColumnDataType.Integer, secondArg); }
fArg = new TD_Value(ColumnDataType.Integer, firstArg);
sArg = new TD_Value(ColumnDataType.Integer, secondArg); private C_Expression substringByCharSeq(ColumnData column,
exp = new C_SubstringByIndex(columnReference, fArg, sArg); ColumnDataType targetType, String firstArg, String secondArg)
readableExpression = "SubstringByIndex(" + readableColumnReference throws ReplaceTypeMapException {
+ ", " + firstArg + ", " + secondArg + ")"; C_Expression exp;
break; TD_Value fArg;
case SubstringByCharSeq: C_Expression posFrom;
C_Expression posTo;
Log.debug("Column Data Type Name:" + column.getDataTypeName());
ColumnDataType dataType = ColumnDataType
.getColumnDataTypeFromId(column
.getDataTypeName());
Log.debug("Data Type:" + dataType);
C_ColumnReference columnRef = new C_ColumnReference(
column.getTrId(), dataType, column.getColumnId());
C_Expression columnReference;
String readableColumnReference;
if(dataType!=ColumnDataType.Text){
columnReference=new C_Cast(columnRef,ColumnDataType.Text);
readableColumnReference= "Cast("+column.getColumnId()+","+ColumnDataType.Text+")";
} else {
columnReference=columnRef;
readableColumnReference= column.getColumnId();
}
Log.debug("Typed Column Reference:" + columnReference);
checkTypeArgument(ColumnDataType.Text, firstArg); checkTypeArgument(ColumnDataType.Text, firstArg);
fArg = new TD_Value(ColumnDataType.Text, firstArg); fArg = new TD_Value(ColumnDataType.Text, firstArg);
posFrom = new C_SubstringPosition(columnReference, fArg); posFrom = new C_SubstringPosition(columnReference, fArg);
checkTypeArgument(ColumnDataType.Text, secondArg); checkTypeArgument(ColumnDataType.Text, secondArg);
sArg = new TD_Value(ColumnDataType.Text, secondArg); //sArg = new TD_Value(ColumnDataType.Text, secondArg);
posTo = new C_SubstringPosition(columnReference, fArg); posTo = new C_SubstringPosition(columnReference, fArg);
exp = new C_SubstringByIndex(columnReference, posFrom, posTo); C_SubstringByIndex substring = new C_SubstringByIndex(columnReference, posFrom, posTo);
readableExpression = "SubstringByCharSeq(" exp=new C_Cast(substring, targetType);
readableExpression = "Cast(SubstringByCharSeq("
+ readableColumnReference + ", " + firstArg + ", " + readableColumnReference + ", " + firstArg + ", "
+ secondArg + ")"; + secondArg + "),"+targetType+")";
break; return exp;
case TextReplaceMatchingRegex:
checkTypeArgument(ColumnDataType.Text, firstArg);
checkTypeArgument(ColumnDataType.Text, secondArg);
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;
} }
private C_Expression substringByIndexReference(ColumnData column,
ColumnDataType targetType, String firstArg, String secondArg)
throws ReplaceTypeMapException {
C_Expression exp;
TD_Value fArg;
TD_Value sArg;
Log.debug("Column Data Type Name:" + column.getDataTypeName());
ColumnDataType dataType = ColumnDataType
.getColumnDataTypeFromId(column
.getDataTypeName());
Log.debug("Data Type:" + dataType);
C_ColumnReference columnRef = new C_ColumnReference(
column.getTrId(), dataType, column.getColumnId());
C_Expression columnReference;
String readableColumnReference;
if(dataType!=ColumnDataType.Text){
columnReference=new C_Cast(columnRef,ColumnDataType.Text);
readableColumnReference= "Cast("+column.getColumnId()+","+ColumnDataType.Text+")";
} else {
columnReference=columnRef;
readableColumnReference= column.getColumnId();
}
Log.debug("Typed Column Reference:" + columnReference);
checkTypeArgument(ColumnDataType.Integer, firstArg);
checkTypeArgument(ColumnDataType.Integer, secondArg);
fArg = new TD_Value(ColumnDataType.Integer, firstArg);
sArg = new TD_Value(ColumnDataType.Integer, secondArg);
C_SubstringByIndex substring = new C_SubstringByIndex(columnReference, fArg, sArg);
exp=new C_Cast(substring,targetType);
readableExpression = "Cast(SubstringByIndex(" + readableColumnReference
+ ", " + firstArg + ", " + secondArg + "),"+targetType+")";
return exp;
}
private C_Expression SubstringByRegexReference(ColumnData column,
ColumnDataType targetType, String firstArg)
throws ReplaceTypeMapException {
C_Expression exp;
TD_Value fArg;
Log.debug("Column Data Type Name:" + column.getDataTypeName());
ColumnDataType dataType = ColumnDataType
.getColumnDataTypeFromId(column
.getDataTypeName());
Log.debug("Data Type:" + dataType);
C_ColumnReference columnRef = new C_ColumnReference(
column.getTrId(), dataType, column.getColumnId());
C_Expression columnReference;
String readableColumnReference;
if(dataType!=ColumnDataType.Text){
columnReference=new C_Cast(columnRef,ColumnDataType.Text);
readableColumnReference= "Cast("+column.getColumnId()+","+ColumnDataType.Text+")";
} else {
columnReference=columnRef;
readableColumnReference= column.getColumnId();
}
Log.debug("Typed Column Reference:" + columnReference);
checkTypeArgument(ColumnDataType.Text, firstArg);
fArg = new TD_Value(ColumnDataType.Text, firstArg);
C_SubstringByRegex substring= new C_SubstringByRegex(columnReference, fArg);
exp=new C_Cast(substring, targetType);
readableExpression = "Cast(SubStringByRegex(" + readableColumnReference
+ ", " + firstArg + "),"+targetType+")";
return exp;
}
private C_Expression columnValueReference(ColumnData column,
ColumnDataType targetType) {
C_Expression exp;
Log.debug("Column Data Type Name:" + column.getDataTypeName());
ColumnDataType dataType = ColumnDataType
.getColumnDataTypeFromId(column
.getDataTypeName());
Log.debug("Data Type:" + dataType);
C_ColumnReference columnRef = new C_ColumnReference(
column.getTrId(), dataType, column.getColumnId());
C_Expression columnReference;
String readableColumnReference;
if(dataType!=targetType){
columnReference=new C_Cast(columnRef,targetType);
readableColumnReference= "Cast("+column.getColumnId()+","+targetType+")";
} else {
columnReference=columnRef;
readableColumnReference= column.getColumnId();
}
Log.debug("Typed Column Reference:" + columnReference);
exp = columnReference;
readableExpression = "ColumnValue(" + readableColumnReference + ")";
return exp; return exp;
} }