Updated ReplaceWidet added external columns

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-expression-widget@100335 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2014-10-01 16:30:59 +00:00
parent 9ed273a01e
commit 3f651e7132
10 changed files with 619 additions and 112 deletions

View File

@ -2,7 +2,7 @@ package org.gcube.portlets.user.td.expressionwidget.client;
import org.gcube.portlets.user.td.expressionwidget.client.help.HelpReplaceColumnByExpressionDialog; import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId;
import com.allen_sauer.gwt.log.client.Log; import com.allen_sauer.gwt.log.client.Log;
import com.google.gwt.core.client.EntryPoint; import com.google.gwt.core.client.EntryPoint;
@ -21,8 +21,8 @@ public class ExpressionWidgetEntry implements EntryPoint {
public void onModuleLoad() { public void onModuleLoad() {
EventBus eventBus= new SimpleEventBus(); EventBus eventBus= new SimpleEventBus();
//TRId trId=new TRId("154","1610"); TRId trId=new TRId("154","1969");
//String columnName="zwqvvx"; String columnName="zwqvvx";
//Column Expression Dialog //Column Expression Dialog
//ColumnExpressionDialog expressionDialog=new ColumnExpressionDialog("1", ColumnTypeCode.ATTRIBUTE, ColumnDataType.Integer, eventBus); //ColumnExpressionDialog expressionDialog=new ColumnExpressionDialog("1", ColumnTypeCode.ATTRIBUTE, ColumnDataType.Integer, eventBus);
@ -39,11 +39,12 @@ public class ExpressionWidgetEntry implements EntryPoint {
//multiColumnFilterDialog.show(); //multiColumnFilterDialog.show();
//Replace Column By Expression Dialog //Replace Column By Expression Dialog
//ReplaceColumnByExpressionDialog replaceColumnByExpression= new ReplaceColumnByExpressionDialog(trId, columnName, eventBus); ReplaceColumnByExpressionDialog replaceColumnByExpression= new ReplaceColumnByExpressionDialog(trId, columnName, eventBus);
//replaceColumnByExpression.show(); replaceColumnByExpression.show();
HelpReplaceColumnByExpressionDialog help= new HelpReplaceColumnByExpressionDialog(eventBus); //HelpReplaceColumnByExpressionDialog
help.show(); //HelpReplaceColumnByExpressionDialog help= new HelpReplaceColumnByExpressionDialog(eventBus);
//help.show();
Log.info("Hello!"); Log.info("Hello!");
} }

View File

@ -37,7 +37,7 @@ import com.sencha.gxt.widget.core.client.event.SelectEvent.SelectHandler;
*/ */
public class ReplaceColumnByExpressionDialog extends Window implements public class ReplaceColumnByExpressionDialog extends Window implements
MonitorDialogListener { MonitorDialogListener {
protected static final String WIDTH = "710px"; protected static final String WIDTH = "880px";
protected static final String HEIGHT = "490px"; protected static final String HEIGHT = "490px";
protected static final String HEIGHT_REDUCE = "404px"; protected static final String HEIGHT_REDUCE = "404px";

View File

@ -4,6 +4,7 @@ import java.util.Date;
import org.gcube.portlets.user.td.expressionwidget.client.resources.ExpressionResources; import org.gcube.portlets.user.td.expressionwidget.client.resources.ExpressionResources;
import org.gcube.portlets.user.td.expressionwidget.shared.exception.OperatorTypeMapException; import org.gcube.portlets.user.td.expressionwidget.shared.exception.OperatorTypeMapException;
import org.gcube.portlets.user.td.expressionwidget.shared.exception.ReplaceTypeMapException;
import org.gcube.portlets.user.td.expressionwidget.shared.model.leaf.TD_Value; import org.gcube.portlets.user.td.expressionwidget.shared.model.leaf.TD_Value;
import org.gcube.portlets.user.td.gwtservice.shared.tr.ColumnData; import org.gcube.portlets.user.td.gwtservice.shared.tr.ColumnData;
import org.gcube.portlets.user.td.monitorwidget.client.utils.UtilsGXT3; import org.gcube.portlets.user.td.monitorwidget.client.utils.UtilsGXT3;
@ -51,16 +52,16 @@ public class ReplaceColumnByExpressionPanel extends FramedPanel {
private static final String GEOMETRY_REGEXPR = "(\\s*POINT\\s*\\(\\s*(-)?\\d+(\\.\\d+)?\\s+(-)?\\d+(\\.\\d+)?\\s*\\)\\s*$)" private static final String GEOMETRY_REGEXPR = "(\\s*POINT\\s*\\(\\s*(-)?\\d+(\\.\\d+)?\\s+(-)?\\d+(\\.\\d+)?\\s*\\)\\s*$)"
+ "|(\\s*LINESTRING\\s*\\((\\s*(-)?\\d+(\\.\\d+)?\\s+(-)?\\d+(\\.\\d+)?\\s*,)+\\s*((-)?\\d+(\\.\\d+)?\\s+(-)?\\d+(\\.\\d+)?\\s*)\\)\\s*$)"; + "|(\\s*LINESTRING\\s*\\((\\s*(-)?\\d+(\\.\\d+)?\\s+(-)?\\d+(\\.\\d+)?\\s*,)+\\s*((-)?\\d+(\\.\\d+)?\\s+(-)?\\d+(\\.\\d+)?\\s*)\\)\\s*$)";
protected static final String WIDTH = "698px"; protected static final String WIDTH = "868px";
protected static final String HEIGHT = "454px"; protected static final String HEIGHT = "454px";
protected static final String HEIGHT_REDUCE = "368px"; protected static final String HEIGHT_REDUCE = "368px";
protected static final String CONDITIONWIDTH = "662px"; protected static final String CONDITIONWIDTH = "832px";
protected static final String CONDITIONHEIGHT = "120px"; protected static final String CONDITIONHEIGHT = "120px";
protected static final String CONDITION_LAYOUT_WIDTH = "662px"; protected static final String CONDITION_LAYOUT_WIDTH = "832px";
protected static final String REPLACEWIDTH = "662px"; protected static final String REPLACEWIDTH = "832px";
protected static final String REPLACEHEIGHT = "120px"; protected static final String REPLACEHEIGHT = "120px";
protected static final String ALL_ROWS_FIELD_WIDTH = "662px"; protected static final String ALL_ROWS_FIELD_WIDTH = "832px";
protected static final String RADIO_LABEL_BY_CONDITION = "By Condition"; protected static final String RADIO_LABEL_BY_CONDITION = "By Condition";
protected static final String RADIO_LABEL_ALL_ROWS = "All Rows"; protected static final String RADIO_LABEL_ALL_ROWS = "All Rows";
@ -209,7 +210,7 @@ public class ReplaceColumnByExpressionPanel extends FramedPanel {
if (column.getDataTypeName().compareTo( if (column.getDataTypeName().compareTo(
ColumnDataType.Text.toString()) == 0) { ColumnDataType.Text.toString()) == 0) {
replaceWidget = new ReplaceWidget(column, REPLACEWIDTH, replaceWidget = new ReplaceWidget(column, REPLACEWIDTH,
REPLACEHEIGHT); REPLACEHEIGHT, eventBus);
replaceValueFieldSetLayout.add(replaceWidget, replaceValueFieldSetLayout.add(replaceWidget,
new VerticalLayoutData(1, -1)); new VerticalLayoutData(1, -1));
} else { } else {
@ -323,9 +324,9 @@ public class ReplaceColumnByExpressionPanel extends FramedPanel {
"Replace expression is not valid!"); "Replace expression is not valid!");
return; return;
} }
} catch (Throwable e) { } catch (ReplaceTypeMapException e) {
UtilsGXT3.alert("Attention", UtilsGXT3.alert("Attention",
"Replace expression is not valid!"); e.getLocalizedMessage());
return; return;
} }
parent.applyReplaceColumnByExpression(cConditionExpression, parent.applyReplaceColumnByExpression(cConditionExpression,

View File

@ -1,17 +1,31 @@
package org.gcube.portlets.user.td.expressionwidget.client; package org.gcube.portlets.user.td.expressionwidget.client;
import java.util.ArrayList;
import org.gcube.portlets.user.td.expressionwidget.client.properties.ColumnDataPropertiesCombo;
import org.gcube.portlets.user.td.expressionwidget.client.properties.ReplaceElement; import org.gcube.portlets.user.td.expressionwidget.client.properties.ReplaceElement;
import org.gcube.portlets.user.td.expressionwidget.client.properties.ReplaceElementProperties; import org.gcube.portlets.user.td.expressionwidget.client.properties.ReplaceElementProperties;
import org.gcube.portlets.user.td.expressionwidget.client.properties.ReplaceElementStore; import org.gcube.portlets.user.td.expressionwidget.client.properties.ReplaceElementStore;
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.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.shared.exception.TDGWTIsFinalException;
import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTIsLockedException;
import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTSessionExpiredException;
import org.gcube.portlets.user.td.gwtservice.shared.tr.ColumnData; import org.gcube.portlets.user.td.gwtservice.shared.tr.ColumnData;
import org.gcube.portlets.user.td.widgetcommonevent.client.event.SessionExpiredEvent;
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.expression.C_Expression; import org.gcube.portlets.user.td.widgetcommonevent.shared.expression.C_Expression;
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;
import com.google.gwt.event.logical.shared.SelectionEvent; import com.google.gwt.event.logical.shared.SelectionEvent;
import com.google.gwt.event.logical.shared.SelectionHandler; import com.google.gwt.event.logical.shared.SelectionHandler;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.web.bindery.event.shared.EventBus;
import com.sencha.gxt.cell.core.client.form.ComboBoxCell.TriggerAction; import com.sencha.gxt.cell.core.client.form.ComboBoxCell.TriggerAction;
import com.sencha.gxt.core.client.dom.ScrollSupport.ScrollMode; import com.sencha.gxt.core.client.dom.ScrollSupport.ScrollMode;
import com.sencha.gxt.core.client.util.Margins; import com.sencha.gxt.core.client.util.Margins;
@ -48,18 +62,23 @@ public class ReplaceWidget extends SimpleContainer {
private ReplaceWidget thisCont; private ReplaceWidget thisCont;
protected static final String HEIGHT = "210px"; protected static final String HEIGHT = "210px";
protected static final String WIDTH = "662px"; protected static final String WIDTH = "832px";
protected static final String COMBO_WIDTH = "170px"; protected static final String COMBO_WIDTH = "170px";
protected EventBus eventBus;
protected TRId trId;
protected ArrayList<ColumnData> columns;
protected FieldLabel matchLabel; protected FieldLabel matchLabel;
protected ToggleGroup groupMatch; protected ToggleGroup groupMatch;
protected VerticalLayoutContainer vert; protected VerticalLayoutContainer vert;
protected ColumnData column; // protected ColumnData column;
protected String readableExpression; protected String readableExpression;
private String itemIdComboConcat; private String itemIdComboConcat;
private String itemIdComboLeaf; private String itemIdComboLeaf;
private String itemIdComboColumns;
private String itemIdFirstArg; private String itemIdFirstArg;
private String itemIdSecondArg; private String itemIdSecondArg;
private String itemIdHoriz; private String itemIdHoriz;
@ -93,25 +112,36 @@ public class ReplaceWidget extends SimpleContainer {
} }
public ReplaceWidget(ColumnData column) { public ReplaceWidget(ColumnData column, EventBus eventBus) {
super(); super();
create(column, WIDTH, HEIGHT); create(column.getTrId(), WIDTH, HEIGHT, eventBus);
} }
public ReplaceWidget(ColumnData column, String width, String height) { public ReplaceWidget(ColumnData column, String width, String height,
EventBus eventBus) {
super(); super();
create(column, width, height); create(column.getTrId(), width, height, eventBus);
} }
protected void create(ColumnData column, String width, String height) { public ReplaceWidget(TRId trId, EventBus eventBus) {
this.column = column; create(trId, WIDTH, HEIGHT, eventBus);
}
public ReplaceWidget(TRId trId, String width, String height,
EventBus eventBus) {
super();
create(trId, width, height, eventBus);
}
protected void create(TRId trId, String width, String height,
EventBus eventBus) {
this.trId = trId;
setBorders(true); setBorders(true);
setWidth(width); setWidth(width);
setHeight(height); setHeight(height);
forceLayoutOnResize = true; forceLayoutOnResize = true;
thisCont = this; thisCont = this;
setup();
addBeforeShowHandler(new BeforeShowEvent.BeforeShowHandler() { addBeforeShowHandler(new BeforeShowEvent.BeforeShowHandler() {
@Override @Override
@ -120,15 +150,55 @@ public class ReplaceWidget extends SimpleContainer {
} }
}); });
retrieveColumns();
} }
protected void retrieveColumns() {
TDGWTServiceAsync.INSTANCE.getColumns(trId,
new AsyncCallback<ArrayList<ColumnData>>() {
public void onFailure(Throwable caught) {
if (caught instanceof TDGWTSessionExpiredException) {
eventBus.fireEvent(new SessionExpiredEvent(
SessionExpiredType.EXPIREDONSERVER));
} else {
if (caught instanceof TDGWTIsLockedException) {
Log.error(caught.getLocalizedMessage());
UtilsGXT3.alert("Error Locked",
caught.getLocalizedMessage());
} else {
if (caught instanceof TDGWTIsFinalException) {
Log.error(caught.getLocalizedMessage());
UtilsGXT3.alert("Error Final",
caught.getLocalizedMessage());
} else {
Log.error("load combo failure:"
+ caught.getLocalizedMessage());
UtilsGXT3.alert("Error",
"Error retrieving columns of tabular resource:"
+ trId.getId());
}
}
}
}
public void onSuccess(ArrayList<ColumnData> result) {
Log.trace("loaded " + result.size() + " ColumnData");
columns = result;
setup();
}
});
}
protected void setup() { protected void setup() {
itemIdComboConcat = "ComboConcat" + column.getName(); itemIdComboConcat = "ComboConcat" + trId.getId();
itemIdComboLeaf = "ComboLeaf" + column.getName(); itemIdComboLeaf = "ComboLeaf" + trId.getId();
itemIdFirstArg = "FirstArg" + column.getName(); itemIdComboColumns = "ComboColumns" + trId.getId();
itemIdSecondArg = "SecondArg" + column.getName(); itemIdFirstArg = "FirstArg" + trId.getId();
itemIdHoriz = "Horiz" + column.getName(); itemIdSecondArg = "SecondArg" + trId.getId();
itemIdHoriz = "Horiz" + trId.getId();
vert = new VerticalLayoutContainer(); vert = new VerticalLayoutContainer();
vert.setScrollMode(ScrollMode.AUTO); vert.setScrollMode(ScrollMode.AUTO);
@ -143,6 +213,27 @@ public class ReplaceWidget extends SimpleContainer {
secondArg.setEmptyText(""); secondArg.setEmptyText("");
secondArg.setItemId(itemIdSecondArg); secondArg.setItemId(itemIdSecondArg);
// Combo Column
ColumnDataPropertiesCombo propsColumnData = GWT
.create(ColumnDataPropertiesCombo.class);
ListStore<ColumnData> storeColumns = new ListStore<ColumnData>(
propsColumnData.id());
Log.debug("Store Columns: " + storeColumns);
storeColumns.addAll(columns);
final ComboBox<ColumnData> comboColumns = new ComboBox<ColumnData>(
storeColumns, propsColumnData.label());
Log.debug("Combo Columns created");
comboColumns.setEmptyText("Select Column...");
comboColumns.setItemId(itemIdComboColumns);
comboColumns.setWidth(COMBO_WIDTH);
comboColumns.setEditable(false);
comboColumns.setTriggerAction(TriggerAction.ALL);
// Replace Elemet Store
ReplaceElementStore factory = new ReplaceElementStore(); ReplaceElementStore factory = new ReplaceElementStore();
ReplaceElementProperties props = GWT ReplaceElementProperties props = GWT
@ -170,12 +261,16 @@ public class ReplaceWidget extends SimpleContainer {
Log.debug("Condition selected:" + re.toString()); Log.debug("Condition selected:" + re.toString());
switch (re.getReplaceType()) { switch (re.getReplaceType()) {
case Value: case Value:
comboColumns.clear();
comboColumns.setVisible(false);
firstArg.setVisible(true); firstArg.setVisible(true);
firstArg.setEmptyText(EMPTY_TEXT_INSERT_A_STRING); firstArg.setEmptyText(EMPTY_TEXT_INSERT_A_STRING);
secondArg.setVisible(false); secondArg.setVisible(false);
secondArg.setEmptyText(""); secondArg.setEmptyText("");
break; break;
case ColumnValue: case ColumnValue:
comboColumns.clear();
comboColumns.setVisible(true);
firstArg.setVisible(false); firstArg.setVisible(false);
firstArg.setEmptyText(""); firstArg.setEmptyText("");
secondArg.setVisible(false); secondArg.setVisible(false);
@ -184,28 +279,37 @@ public class ReplaceWidget extends SimpleContainer {
case Concat: case Concat:
break; break;
case SubstringByRegex: case SubstringByRegex:
comboColumns.clear();
comboColumns.setVisible(true);
firstArg.setVisible(true); firstArg.setVisible(true);
firstArg.setEmptyText(EMPTY_TEXT_REGEXP); firstArg.setEmptyText(EMPTY_TEXT_REGEXP);
secondArg.setVisible(false); secondArg.setVisible(false);
secondArg.setEmptyText(""); secondArg.setEmptyText("");
break; break;
case SubstringByIndex: case SubstringByIndex:
comboColumns.clear();
comboColumns.setVisible(true);
firstArg.setVisible(true); firstArg.setVisible(true);
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);
break; break;
case SubstringByCharSeq: case SubstringByCharSeq:
comboColumns.clear();
comboColumns.setVisible(true);
firstArg.setVisible(true); firstArg.setVisible(true);
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);
break; break;
case TextReplaceMatchingRegex: case TextReplaceMatchingRegex:
comboColumns.clear();
comboColumns.setVisible(true);
firstArg.setVisible(true); firstArg.setVisible(true);
firstArg.setEmptyText(EMPTY_TEXT_REPLACE_REGEXP); firstArg.setEmptyText(EMPTY_TEXT_REPLACE_REGEXP);
secondArg.setVisible(true); secondArg.setVisible(true);
secondArg.setEmptyText(EMPTY_TEXT_REPLACE_REPLACING); secondArg
.setEmptyText(EMPTY_TEXT_REPLACE_REPLACING);
break; break;
default: default:
break; break;
@ -251,6 +355,8 @@ public class ReplaceWidget extends SimpleContainer {
switch (re.getReplaceType()) { switch (re.getReplaceType()) {
case Value: case Value:
comboReplaceElementsLeaf.setVisible(false); comboReplaceElementsLeaf.setVisible(false);
comboColumns.clear();
comboColumns.setVisible(false);
firstArg.setEmptyText(EMPTY_TEXT_INSERT_A_STRING); firstArg.setEmptyText(EMPTY_TEXT_INSERT_A_STRING);
firstArg.setVisible(true); firstArg.setVisible(true);
secondArg.setVisible(false); secondArg.setVisible(false);
@ -259,6 +365,8 @@ public class ReplaceWidget extends SimpleContainer {
break; break;
case ColumnValue: case ColumnValue:
comboReplaceElementsLeaf.setVisible(false); comboReplaceElementsLeaf.setVisible(false);
comboColumns.clear();
comboColumns.setVisible(true);
firstArg.setVisible(false); firstArg.setVisible(false);
firstArg.setEmptyText(""); firstArg.setEmptyText("");
secondArg.setVisible(false); secondArg.setVisible(false);
@ -268,6 +376,8 @@ public class ReplaceWidget extends SimpleContainer {
if (!existConcat(source)) { if (!existConcat(source)) {
comboReplaceElementsLeaf.clear(); comboReplaceElementsLeaf.clear();
comboReplaceElementsLeaf.setVisible(true); comboReplaceElementsLeaf.setVisible(true);
comboColumns.clear();
comboColumns.setVisible(false);
firstArg.setVisible(false); firstArg.setVisible(false);
firstArg.setEmptyText(""); firstArg.setEmptyText("");
secondArg.setVisible(false); secondArg.setVisible(false);
@ -277,6 +387,8 @@ public class ReplaceWidget extends SimpleContainer {
break; break;
case SubstringByRegex: case SubstringByRegex:
comboReplaceElementsLeaf.setVisible(false); comboReplaceElementsLeaf.setVisible(false);
comboColumns.clear();
comboColumns.setVisible(true);
firstArg.setVisible(true); firstArg.setVisible(true);
firstArg.setEmptyText(EMPTY_TEXT_REGEXP); firstArg.setEmptyText(EMPTY_TEXT_REGEXP);
secondArg.setVisible(false); secondArg.setVisible(false);
@ -285,6 +397,8 @@ public class ReplaceWidget extends SimpleContainer {
break; break;
case SubstringByIndex: case SubstringByIndex:
comboReplaceElementsLeaf.setVisible(false); comboReplaceElementsLeaf.setVisible(false);
comboColumns.clear();
comboColumns.setVisible(true);
firstArg.setVisible(true); firstArg.setVisible(true);
firstArg.setEmptyText(EMPTY_TEXT_FROM_INDEX); firstArg.setEmptyText(EMPTY_TEXT_FROM_INDEX);
secondArg.setVisible(true); secondArg.setVisible(true);
@ -293,6 +407,8 @@ public class ReplaceWidget extends SimpleContainer {
break; break;
case SubstringByCharSeq: case SubstringByCharSeq:
comboReplaceElementsLeaf.setVisible(false); comboReplaceElementsLeaf.setVisible(false);
comboColumns.clear();
comboColumns.setVisible(true);
firstArg.setVisible(true); firstArg.setVisible(true);
firstArg.setEmptyText(EMPTY_TEXT_FROM_STRING); firstArg.setEmptyText(EMPTY_TEXT_FROM_STRING);
secondArg.setVisible(true); secondArg.setVisible(true);
@ -301,10 +417,13 @@ public class ReplaceWidget extends SimpleContainer {
break; break;
case TextReplaceMatchingRegex: case TextReplaceMatchingRegex:
comboReplaceElementsLeaf.setVisible(false); comboReplaceElementsLeaf.setVisible(false);
comboColumns.clear();
comboColumns.setVisible(true);
firstArg.setVisible(true); firstArg.setVisible(true);
firstArg.setEmptyText(EMPTY_TEXT_REPLACE_REGEXP); firstArg.setEmptyText(EMPTY_TEXT_REPLACE_REGEXP);
secondArg.setVisible(true); secondArg.setVisible(true);
secondArg.setEmptyText(EMPTY_TEXT_REPLACE_REPLACING); secondArg
.setEmptyText(EMPTY_TEXT_REPLACE_REPLACING);
removeConcat(source); removeConcat(source);
break; break;
default: default:
@ -330,6 +449,7 @@ public class ReplaceWidget extends SimpleContainer {
// //
horiz.add(comboReplaceElementsConcat, new BoxLayoutData(new Margins(0))); horiz.add(comboReplaceElementsConcat, 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(firstArg, new BoxLayoutData(new Margins(0))); horiz.add(firstArg, new BoxLayoutData(new Margins(0)));
horiz.add(secondArg, new BoxLayoutData(new Margins(0))); horiz.add(secondArg, new BoxLayoutData(new Margins(0)));
horiz.setItemId(itemIdHoriz); horiz.setItemId(itemIdHoriz);
@ -339,6 +459,7 @@ public class ReplaceWidget extends SimpleContainer {
firstArg.setVisible(true); firstArg.setVisible(true);
secondArg.setVisible(false); secondArg.setVisible(false);
comboColumns.setVisible(false);
comboReplaceElementsLeaf.setVisible(false); comboReplaceElementsLeaf.setVisible(false);
comboReplaceElementsConcat.setVisible(true); comboReplaceElementsConcat.setVisible(true);
forceLayout(); forceLayout();
@ -353,6 +474,27 @@ public class ReplaceWidget extends SimpleContainer {
final TextField secondArg = new TextField(); final TextField secondArg = new TextField();
secondArg.setItemId(itemIdSecondArg); secondArg.setItemId(itemIdSecondArg);
// Combo Column
ColumnDataPropertiesCombo propsColumnData = GWT
.create(ColumnDataPropertiesCombo.class);
ListStore<ColumnData> storeColumns = new ListStore<ColumnData>(
propsColumnData.id());
Log.debug("Store Columns: " + storeColumns);
storeColumns.addAll(columns);
final ComboBox<ColumnData> comboColumns = new ComboBox<ColumnData>(
storeColumns, propsColumnData.label());
Log.debug("Combo Columns created");
comboColumns.setEmptyText("Select Column...");
comboColumns.setItemId(itemIdComboColumns);
comboColumns.setWidth(COMBO_WIDTH);
comboColumns.setEditable(false);
comboColumns.setTriggerAction(TriggerAction.ALL);
//
ReplaceElementStore factory = new ReplaceElementStore(); ReplaceElementStore factory = new ReplaceElementStore();
ReplaceElementProperties props = GWT ReplaceElementProperties props = GWT
@ -380,12 +522,16 @@ public class ReplaceWidget extends SimpleContainer {
Log.debug("Condition selected:" + re.toString()); Log.debug("Condition selected:" + re.toString());
switch (re.getReplaceType()) { switch (re.getReplaceType()) {
case Value: case Value:
comboColumns.clear();
comboColumns.setVisible(false);
firstArg.setVisible(true); firstArg.setVisible(true);
firstArg.setEmptyText(EMPTY_TEXT_INSERT_A_STRING); firstArg.setEmptyText(EMPTY_TEXT_INSERT_A_STRING);
secondArg.setVisible(false); secondArg.setVisible(false);
secondArg.setEmptyText(""); secondArg.setEmptyText("");
break; break;
case ColumnValue: case ColumnValue:
comboColumns.clear();
comboColumns.setVisible(true);
firstArg.setVisible(false); firstArg.setVisible(false);
firstArg.setEmptyText(""); firstArg.setEmptyText("");
secondArg.setVisible(false); secondArg.setVisible(false);
@ -394,28 +540,37 @@ public class ReplaceWidget extends SimpleContainer {
case Concat: case Concat:
break; break;
case SubstringByRegex: case SubstringByRegex:
comboColumns.clear();
comboColumns.setVisible(true);
firstArg.setVisible(true); firstArg.setVisible(true);
firstArg.setEmptyText(EMPTY_TEXT_REGEXP); firstArg.setEmptyText(EMPTY_TEXT_REGEXP);
secondArg.setVisible(false); secondArg.setVisible(false);
secondArg.setEmptyText(""); secondArg.setEmptyText("");
break; break;
case SubstringByIndex: case SubstringByIndex:
comboColumns.clear();
comboColumns.setVisible(true);
firstArg.setVisible(true); firstArg.setVisible(true);
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);
break; break;
case SubstringByCharSeq: case SubstringByCharSeq:
comboColumns.clear();
comboColumns.setVisible(true);
firstArg.setVisible(true); firstArg.setVisible(true);
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);
break; break;
case TextReplaceMatchingRegex: case TextReplaceMatchingRegex:
comboColumns.clear();
comboColumns.setVisible(true);
firstArg.setVisible(true); firstArg.setVisible(true);
firstArg.setEmptyText(EMPTY_TEXT_REPLACE_REGEXP); firstArg.setEmptyText(EMPTY_TEXT_REPLACE_REGEXP);
secondArg.setVisible(true); secondArg.setVisible(true);
secondArg.setEmptyText(EMPTY_TEXT_REPLACE_REPLACING); secondArg
.setEmptyText(EMPTY_TEXT_REPLACE_REPLACING);
break; break;
default: default:
break; break;
@ -461,6 +616,8 @@ public class ReplaceWidget extends SimpleContainer {
switch (re.getReplaceType()) { switch (re.getReplaceType()) {
case Value: case Value:
comboReplaceElementsLeaf.setVisible(false); comboReplaceElementsLeaf.setVisible(false);
comboColumns.clear();
comboColumns.setVisible(false);
firstArg.setEmptyText(EMPTY_TEXT_INSERT_A_STRING); firstArg.setEmptyText(EMPTY_TEXT_INSERT_A_STRING);
firstArg.setVisible(true); firstArg.setVisible(true);
secondArg.setVisible(false); secondArg.setVisible(false);
@ -469,6 +626,8 @@ public class ReplaceWidget extends SimpleContainer {
break; break;
case ColumnValue: case ColumnValue:
comboReplaceElementsLeaf.setVisible(false); comboReplaceElementsLeaf.setVisible(false);
comboColumns.clear();
comboColumns.setVisible(true);
firstArg.setVisible(false); firstArg.setVisible(false);
firstArg.setEmptyText(""); firstArg.setEmptyText("");
secondArg.setVisible(false); secondArg.setVisible(false);
@ -478,6 +637,8 @@ public class ReplaceWidget extends SimpleContainer {
if (!existConcat(source)) { if (!existConcat(source)) {
comboReplaceElementsLeaf.clear(); comboReplaceElementsLeaf.clear();
comboReplaceElementsLeaf.setVisible(true); comboReplaceElementsLeaf.setVisible(true);
comboColumns.clear();
comboColumns.setVisible(false);
firstArg.setVisible(false); firstArg.setVisible(false);
firstArg.setEmptyText(""); firstArg.setEmptyText("");
secondArg.setVisible(false); secondArg.setVisible(false);
@ -487,6 +648,8 @@ public class ReplaceWidget extends SimpleContainer {
break; break;
case SubstringByRegex: case SubstringByRegex:
comboReplaceElementsLeaf.setVisible(false); comboReplaceElementsLeaf.setVisible(false);
comboColumns.clear();
comboColumns.setVisible(true);
firstArg.setVisible(true); firstArg.setVisible(true);
firstArg.setEmptyText(EMPTY_TEXT_REGEXP); firstArg.setEmptyText(EMPTY_TEXT_REGEXP);
secondArg.setVisible(false); secondArg.setVisible(false);
@ -495,6 +658,8 @@ public class ReplaceWidget extends SimpleContainer {
break; break;
case SubstringByIndex: case SubstringByIndex:
comboReplaceElementsLeaf.setVisible(false); comboReplaceElementsLeaf.setVisible(false);
comboColumns.clear();
comboColumns.setVisible(true);
firstArg.setVisible(true); firstArg.setVisible(true);
firstArg.setEmptyText(EMPTY_TEXT_FROM_INDEX); firstArg.setEmptyText(EMPTY_TEXT_FROM_INDEX);
secondArg.setVisible(true); secondArg.setVisible(true);
@ -503,6 +668,8 @@ public class ReplaceWidget extends SimpleContainer {
break; break;
case SubstringByCharSeq: case SubstringByCharSeq:
comboReplaceElementsLeaf.setVisible(false); comboReplaceElementsLeaf.setVisible(false);
comboColumns.clear();
comboColumns.setVisible(true);
firstArg.setVisible(true); firstArg.setVisible(true);
firstArg.setEmptyText(EMPTY_TEXT_FROM_STRING); firstArg.setEmptyText(EMPTY_TEXT_FROM_STRING);
secondArg.setVisible(true); secondArg.setVisible(true);
@ -511,10 +678,13 @@ public class ReplaceWidget extends SimpleContainer {
break; break;
case TextReplaceMatchingRegex: case TextReplaceMatchingRegex:
comboReplaceElementsLeaf.setVisible(false); comboReplaceElementsLeaf.setVisible(false);
comboColumns.clear();
comboColumns.setVisible(true);
firstArg.setVisible(true); firstArg.setVisible(true);
firstArg.setEmptyText(EMPTY_TEXT_REPLACE_REGEXP); firstArg.setEmptyText(EMPTY_TEXT_REPLACE_REGEXP);
secondArg.setVisible(true); secondArg.setVisible(true);
secondArg.setEmptyText(EMPTY_TEXT_REPLACE_REPLACING); secondArg
.setEmptyText(EMPTY_TEXT_REPLACE_REPLACING);
removeConcat(source); removeConcat(source);
break; break;
default: default:
@ -541,6 +711,7 @@ public class ReplaceWidget extends SimpleContainer {
// //
horiz.add(comboReplaceElementsConcat, new BoxLayoutData(new Margins(0))); horiz.add(comboReplaceElementsConcat, 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(firstArg, new BoxLayoutData(new Margins(0))); horiz.add(firstArg, new BoxLayoutData(new Margins(0)));
horiz.add(secondArg, new BoxLayoutData(new Margins(0))); horiz.add(secondArg, new BoxLayoutData(new Margins(0)));
horiz.setItemId(itemIdHoriz); horiz.setItemId(itemIdHoriz);
@ -548,6 +719,7 @@ public class ReplaceWidget extends SimpleContainer {
firstArg.setVisible(true); firstArg.setVisible(true);
secondArg.setVisible(false); secondArg.setVisible(false);
comboColumns.setVisible(false);
comboReplaceElementsLeaf.setVisible(false); comboReplaceElementsLeaf.setVisible(false);
comboReplaceElementsConcat.setVisible(true); comboReplaceElementsConcat.setVisible(true);
forceLayout(); forceLayout();
@ -578,7 +750,7 @@ public class ReplaceWidget extends SimpleContainer {
return exist; return exist;
} }
public C_Expression getExpression() { public C_Expression getExpression() throws ReplaceTypeMapException {
ExpressionContainer expressionContainer = null; ExpressionContainer expressionContainer = null;
readableExpression = new String(); readableExpression = new String();
C_Expression expression = null; C_Expression expression = null;
@ -604,7 +776,7 @@ public class ReplaceWidget extends SimpleContainer {
return readableExpression; return readableExpression;
} }
protected ExpressionContainer calcCExpression(int index) { protected ExpressionContainer calcCExpression(int index) throws ReplaceTypeMapException {
ExpressionContainer expressionContainer = null; ExpressionContainer expressionContainer = null;
ExpressionContainer expContainerConcat = null; ExpressionContainer expContainerConcat = null;
C_Expression exp = null; C_Expression exp = null;
@ -620,16 +792,22 @@ public class ReplaceWidget extends SimpleContainer {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
ComboBox<ReplaceElement> comboConcat = (ComboBox<ReplaceElement>) horiz ComboBox<ReplaceElement> comboConcat = (ComboBox<ReplaceElement>) horiz
.getItemByItemId(itemIdComboConcat); .getItemByItemId(itemIdComboConcat);
Log.debug("combo: " + comboConcat.getCurrentValue().toString()); Log.debug("combo Concat: " + comboConcat.getCurrentValue());
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
ComboBox<ReplaceElement> comboLeaf = (ComboBox<ReplaceElement>) horiz ComboBox<ReplaceElement> comboLeaf = (ComboBox<ReplaceElement>) horiz
.getItemByItemId(itemIdComboLeaf); .getItemByItemId(itemIdComboLeaf);
Log.debug("combo: " + comboConcat.getCurrentValue().toString()); Log.debug("combo Leaf: " + comboLeaf.getCurrentValue());
@SuppressWarnings("unchecked")
ComboBox<ColumnData> comboColumns = (ComboBox<ColumnData>) horiz
.getItemByItemId(itemIdComboColumns);
Log.debug("combo columns: " + comboColumns.getCurrentValue());
ColumnData column=comboColumns.getCurrentValue();
firstArg = (TextField) horiz.getItemByItemId(itemIdFirstArg); firstArg = (TextField) horiz.getItemByItemId(itemIdFirstArg);
secondArg = (TextField) horiz.getItemByItemId(itemIdSecondArg); secondArg = (TextField) horiz.getItemByItemId(itemIdSecondArg);
Log.debug("firstArg: " + firstArg.getCurrentValue() + " secondArg: " Log.debug("[column: "+column+", firstArg: " + firstArg.getCurrentValue() + ", secondArg: "
+ secondArg.getCurrentValue()); + secondArg.getCurrentValue()+"]");
ReplaceType comboConcatReplaceType = null; ReplaceType comboConcatReplaceType = null;
ReplaceType comboLeafReplaceType = null; ReplaceType comboLeafReplaceType = null;
@ -638,11 +816,11 @@ public class ReplaceWidget extends SimpleContainer {
if (index == vert.getWidgetCount() - 1) { if (index == vert.getWidgetCount() - 1) {
exp = mapReplace.map(column, ReplaceType.Null, exp = mapReplace.map(column, ReplaceType.Null,
firstArg == null ? null : firstArg.getCurrentValue(), firstArg == null ? null : firstArg.getCurrentValue(),
secondArg == null ? null : secondArg.getCurrentValue()); secondArg == null ? null : secondArg.getCurrentValue(), false);
readableExp = mapReplace.getReadableExpression(); readableExp = mapReplace.getReadableExpression();
expressionContainer = new ExpressionContainer(exp, readableExp); expressionContainer = new ExpressionContainer(exp, readableExp);
} else { } else {
return null; throw new ReplaceTypeMapException("Fill all field!");
} }
} else { } else {
comboConcatReplaceType = comboConcat.getCurrentValue() comboConcatReplaceType = comboConcat.getCurrentValue()
@ -656,7 +834,7 @@ public class ReplaceWidget extends SimpleContainer {
firstArg == null ? null : firstArg firstArg == null ? null : firstArg
.getCurrentValue(), .getCurrentValue(),
secondArg == null ? null : secondArg secondArg == null ? null : secondArg
.getCurrentValue()); .getCurrentValue(), false);
readableExpLeaf = mapReplace.getReadableExpression(); readableExpLeaf = mapReplace.getReadableExpression();
} else { } else {
@ -668,7 +846,7 @@ public class ReplaceWidget extends SimpleContainer {
firstArg == null ? null : firstArg firstArg == null ? null : firstArg
.getCurrentValue(), .getCurrentValue(),
secondArg == null ? null : secondArg secondArg == null ? null : secondArg
.getCurrentValue()); .getCurrentValue(), false);
readableExpLeaf = mapReplace.getReadableExpression(); readableExpLeaf = mapReplace.getReadableExpression();
} }
@ -684,7 +862,7 @@ public class ReplaceWidget extends SimpleContainer {
firstArg == null ? null : firstArg firstArg == null ? null : firstArg
.getCurrentValue(), .getCurrentValue(),
secondArg == null ? null : secondArg secondArg == null ? null : secondArg
.getCurrentValue(), expLeaf, .getCurrentValue(),false, expLeaf,
expContainerConcat.getExpression(), expContainerConcat.getExpression(),
readableExpLeaf, expContainerConcat readableExpLeaf, expContainerConcat
.getReadableExpression()); .getReadableExpression());
@ -699,10 +877,9 @@ public class ReplaceWidget extends SimpleContainer {
} else { } else {
exp = mapReplace.map(column, comboConcatReplaceType, exp = mapReplace.map(column, comboConcatReplaceType,
firstArg == null ? null : firstArg.getCurrentValue(), firstArg == null ? null : firstArg.getCurrentValue(),
secondArg == null ? null : secondArg.getCurrentValue()); secondArg == null ? null : secondArg.getCurrentValue(),false);
readableExp = mapReplace.getReadableExpression(); readableExp = mapReplace.getReadableExpression();
expressionContainer = new ExpressionContainer(exp, expressionContainer = new ExpressionContainer(exp, readableExp);
readableExp);
} }
} }

View File

@ -0,0 +1,25 @@
package org.gcube.portlets.user.td.expressionwidget.client.properties;
import org.gcube.portlets.user.td.gwtservice.shared.tr.ColumnData;
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 ColumnDataPropertiesCombo extends
PropertyAccess<ColumnData> {
@Path("id")
ModelKeyProvider<ColumnData> id();
LabelProvider<ColumnData> label();
}

View File

@ -31,6 +31,7 @@ import org.gcube.data.analysis.tabulardata.expression.composite.text.TextContain
import org.gcube.data.analysis.tabulardata.expression.composite.text.TextEndsWith; import org.gcube.data.analysis.tabulardata.expression.composite.text.TextEndsWith;
import org.gcube.data.analysis.tabulardata.expression.composite.text.TextMatchSQLRegexp; import org.gcube.data.analysis.tabulardata.expression.composite.text.TextMatchSQLRegexp;
import org.gcube.data.analysis.tabulardata.expression.composite.text.TextReplaceMatchingRegex; import org.gcube.data.analysis.tabulardata.expression.composite.text.TextReplaceMatchingRegex;
import org.gcube.data.analysis.tabulardata.expression.functions.Cast;
import org.gcube.data.analysis.tabulardata.expression.leaf.ColumnReferencePlaceholder; import org.gcube.data.analysis.tabulardata.expression.leaf.ColumnReferencePlaceholder;
import org.gcube.data.analysis.tabulardata.expression.leaf.ConstantList; import org.gcube.data.analysis.tabulardata.expression.leaf.ConstantList;
import org.gcube.data.analysis.tabulardata.expression.leaf.Range; import org.gcube.data.analysis.tabulardata.expression.leaf.Range;
@ -74,6 +75,7 @@ import org.gcube.portlets.user.td.expressionwidget.shared.model.composite.compar
import org.gcube.portlets.user.td.expressionwidget.shared.model.composite.comparable.C_NotEquals; import org.gcube.portlets.user.td.expressionwidget.shared.model.composite.comparable.C_NotEquals;
import org.gcube.portlets.user.td.expressionwidget.shared.model.composite.comparable.C_NotGreater; import org.gcube.portlets.user.td.expressionwidget.shared.model.composite.comparable.C_NotGreater;
import org.gcube.portlets.user.td.expressionwidget.shared.model.composite.comparable.C_NotLess; import org.gcube.portlets.user.td.expressionwidget.shared.model.composite.comparable.C_NotLess;
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;
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_SubstringByRegex;
@ -217,6 +219,9 @@ public class C_ExpressionParser {
case "ST_Extent": case "ST_Extent":
ex = getSTExtent(exp); ex = getSTExtent(exp);
break; break;
case "Cast":
ex = getCast(exp);
break;
default: default:
break; break;
} }
@ -224,7 +229,8 @@ public class C_ExpressionParser {
return ex; return ex;
} }
public MultivaluedExpression parseMultivalued(C_MultivaluedExpression exp) throws ExpressionParserException { public MultivaluedExpression parseMultivalued(C_MultivaluedExpression exp)
throws ExpressionParserException {
MultivaluedExpression ex = null; MultivaluedExpression ex = null;
switch (exp.getIdMulti()) { switch (exp.getIdMulti()) {
case "ConstantList": case "ConstantList":
@ -241,7 +247,8 @@ public class C_ExpressionParser {
return ex; return ex;
} }
private Expression getValueIsIn(C_Expression exp) throws ExpressionParserException { private Expression getValueIsIn(C_Expression exp)
throws ExpressionParserException {
C_ValueIsIn v = (C_ValueIsIn) exp; C_ValueIsIn v = (C_ValueIsIn) exp;
MultivaluedExpression multivalued = parseMultivalued(v MultivaluedExpression multivalued = parseMultivalued(v
.getRightArgument()); .getRightArgument());
@ -263,25 +270,29 @@ public class C_ExpressionParser {
return or; return or;
} }
private Expression getNot(C_Expression exp) throws ExpressionParserException { private Expression getNot(C_Expression exp)
throws ExpressionParserException {
C_Not n = (C_Not) exp; C_Not n = (C_Not) exp;
Not not = new Not(parse(n.getArgument())); Not not = new Not(parse(n.getArgument()));
return not; return not;
} }
private Expression getIsNull(C_Expression exp) throws ExpressionParserException { private Expression getIsNull(C_Expression exp)
throws ExpressionParserException {
C_IsNull nullIs = (C_IsNull) exp; C_IsNull nullIs = (C_IsNull) exp;
IsNull isNull = new IsNull(parse(nullIs.getArgument())); IsNull isNull = new IsNull(parse(nullIs.getArgument()));
return isNull; return isNull;
} }
private Expression getIsNotNull(C_Expression exp) throws ExpressionParserException { private Expression getIsNotNull(C_Expression exp)
throws ExpressionParserException {
C_IsNotNull nullNotIs = (C_IsNotNull) exp; C_IsNotNull nullNotIs = (C_IsNotNull) exp;
IsNotNull isNotNull = new IsNotNull(parse(nullNotIs.getArgument())); IsNotNull isNotNull = new IsNotNull(parse(nullNotIs.getArgument()));
return isNotNull; return isNotNull;
} }
private Expression getBetween(C_Expression exp) throws ExpressionParserException { private Expression getBetween(C_Expression exp)
throws ExpressionParserException {
C_Between bet = (C_Between) exp; C_Between bet = (C_Between) exp;
C_Range crange = bet.getRightArgument(); C_Range crange = bet.getRightArgument();
Range range = new Range(getExpressionValue(crange.getMinimum()), Range range = new Range(getExpressionValue(crange.getMinimum()),
@ -291,7 +302,8 @@ public class C_ExpressionParser {
return between; return between;
} }
private Expression getAnd(C_Expression exp) throws ExpressionParserException { private Expression getAnd(C_Expression exp)
throws ExpressionParserException {
C_And o = (C_And) exp; C_And o = (C_And) exp;
List<C_Expression> listCExp = o.getArguments(); List<C_Expression> listCExp = o.getArguments();
List<Expression> listExp = new ArrayList<Expression>(); List<Expression> listExp = new ArrayList<Expression>();
@ -304,7 +316,8 @@ public class C_ExpressionParser {
return and; return and;
} }
private Expression getTextMatchSQLRegexp(C_Expression exp) throws ExpressionParserException { private Expression getTextMatchSQLRegexp(C_Expression exp)
throws ExpressionParserException {
C_TextMatchSQLRegexp reg = (C_TextMatchSQLRegexp) exp; C_TextMatchSQLRegexp reg = (C_TextMatchSQLRegexp) exp;
TextMatchSQLRegexp regExp = new TextMatchSQLRegexp( TextMatchSQLRegexp regExp = new TextMatchSQLRegexp(
parse(reg.getLeftArgument()), parse(reg.getRightArgument())); parse(reg.getLeftArgument()), parse(reg.getRightArgument()));
@ -312,7 +325,8 @@ public class C_ExpressionParser {
} }
private Expression getTextEndWith(C_Expression exp) throws ExpressionParserException { private Expression getTextEndWith(C_Expression exp)
throws ExpressionParserException {
C_TextEndsWith textEnd = (C_TextEndsWith) exp; C_TextEndsWith textEnd = (C_TextEndsWith) exp;
TextEndsWith textEndWith = new TextEndsWith( TextEndsWith textEndWith = new TextEndsWith(
parse(textEnd.getLeftArgument()), parse(textEnd.getLeftArgument()),
@ -320,7 +334,8 @@ public class C_ExpressionParser {
return textEndWith; return textEndWith;
} }
private Expression getTextContains(C_Expression exp) throws ExpressionParserException { private Expression getTextContains(C_Expression exp)
throws ExpressionParserException {
C_TextContains textContains = (C_TextContains) exp; C_TextContains textContains = (C_TextContains) exp;
TextContains textCont = new TextContains( TextContains textCont = new TextContains(
parse(textContains.getLeftArgument()), parse(textContains.getLeftArgument()),
@ -328,42 +343,48 @@ public class C_ExpressionParser {
return textCont; return textCont;
} }
private Expression getTextBeginWith(C_Expression exp) throws ExpressionParserException { private Expression getTextBeginWith(C_Expression exp)
throws ExpressionParserException {
C_TextBeginsWith textB = (C_TextBeginsWith) exp; C_TextBeginsWith textB = (C_TextBeginsWith) exp;
TextBeginsWith textBegins = new TextBeginsWith( TextBeginsWith textBegins = new TextBeginsWith(
parse(textB.getLeftArgument()), parse(textB.getRightArgument())); parse(textB.getLeftArgument()), parse(textB.getRightArgument()));
return textBegins; return textBegins;
} }
private Expression getNotLess(C_Expression exp) throws ExpressionParserException { private Expression getNotLess(C_Expression exp)
throws ExpressionParserException {
C_NotLess notL = (C_NotLess) exp; C_NotLess notL = (C_NotLess) exp;
NotLess notLess = new NotLess(parse(notL.getLeftArgument()), NotLess notLess = new NotLess(parse(notL.getLeftArgument()),
parse(notL.getRightArgument())); parse(notL.getRightArgument()));
return notLess; return notLess;
} }
private Expression getNotGreater(C_Expression exp) throws ExpressionParserException { private Expression getNotGreater(C_Expression exp)
throws ExpressionParserException {
C_NotGreater notG = (C_NotGreater) exp; C_NotGreater notG = (C_NotGreater) exp;
NotGreater notGreater = new NotGreater(parse(notG.getLeftArgument()), NotGreater notGreater = new NotGreater(parse(notG.getLeftArgument()),
parse(notG.getRightArgument())); parse(notG.getRightArgument()));
return notGreater; return notGreater;
} }
private Expression getNotEquals(C_Expression exp) throws ExpressionParserException { private Expression getNotEquals(C_Expression exp)
throws ExpressionParserException {
C_NotEquals notE = (C_NotEquals) exp; C_NotEquals notE = (C_NotEquals) exp;
NotEquals notEquals = new NotEquals(parse(notE.getLeftArgument()), NotEquals notEquals = new NotEquals(parse(notE.getLeftArgument()),
parse(notE.getRightArgument())); parse(notE.getRightArgument()));
return notEquals; return notEquals;
} }
private Expression getLessThan(C_Expression exp) throws ExpressionParserException { private Expression getLessThan(C_Expression exp)
throws ExpressionParserException {
C_LessThan lessT = (C_LessThan) exp; C_LessThan lessT = (C_LessThan) exp;
LessThan lessThan = new LessThan(parse(lessT.getLeftArgument()), LessThan lessThan = new LessThan(parse(lessT.getLeftArgument()),
parse(lessT.getRightArgument())); parse(lessT.getRightArgument()));
return lessThan; return lessThan;
} }
private Expression getLessOrEquals(C_Expression exp)throws ExpressionParserException{ private Expression getLessOrEquals(C_Expression exp)
throws ExpressionParserException {
C_LessOrEquals lessOrE = (C_LessOrEquals) exp; C_LessOrEquals lessOrE = (C_LessOrEquals) exp;
LessOrEquals lessOrEquals = new LessOrEquals( LessOrEquals lessOrEquals = new LessOrEquals(
parse(lessOrE.getLeftArgument()), parse(lessOrE.getLeftArgument()),
@ -371,7 +392,8 @@ public class C_ExpressionParser {
return lessOrEquals; return lessOrEquals;
} }
private Expression getGreaterThan(C_Expression exp) throws ExpressionParserException{ private Expression getGreaterThan(C_Expression exp)
throws ExpressionParserException {
C_GreaterThan greaterThan = (C_GreaterThan) exp; C_GreaterThan greaterThan = (C_GreaterThan) exp;
GreaterThan greater = new GreaterThan( GreaterThan greater = new GreaterThan(
parse(greaterThan.getLeftArgument()), parse(greaterThan.getLeftArgument()),
@ -380,7 +402,8 @@ public class C_ExpressionParser {
} }
private Expression getGreaterOrEquals(C_Expression exp) throws ExpressionParserException{ private Expression getGreaterOrEquals(C_Expression exp)
throws ExpressionParserException {
C_GreaterOrEquals greaterOrEq = (C_GreaterOrEquals) exp; C_GreaterOrEquals greaterOrEq = (C_GreaterOrEquals) exp;
GreaterOrEquals greaterOrEquals = new GreaterOrEquals( GreaterOrEquals greaterOrEquals = new GreaterOrEquals(
parse(greaterOrEq.getLeftArgument()), parse(greaterOrEq.getLeftArgument()),
@ -482,7 +505,8 @@ public class C_ExpressionParser {
} }
} }
protected Expression getConstantlist(C_Expression exp) throws ExpressionParserException { protected Expression getConstantlist(C_Expression exp)
throws ExpressionParserException {
List<TDTypeValue> l = new ArrayList<TDTypeValue>(); List<TDTypeValue> l = new ArrayList<TDTypeValue>();
C_ConstantList c = (C_ConstantList) exp; C_ConstantList c = (C_ConstantList) exp;
List<TD_Value> arguments = c.getArguments(); List<TD_Value> arguments = c.getArguments();
@ -495,7 +519,8 @@ public class C_ExpressionParser {
return constList; return constList;
} }
protected MultivaluedExpression getConstantlist(C_MultivaluedExpression exp) throws ExpressionParserException { protected MultivaluedExpression getConstantlist(C_MultivaluedExpression exp)
throws ExpressionParserException {
List<TDTypeValue> l = new ArrayList<TDTypeValue>(); List<TDTypeValue> l = new ArrayList<TDTypeValue>();
C_ConstantList c = (C_ConstantList) exp; C_ConstantList c = (C_ConstantList) exp;
List<TD_Value> arguments = c.getArguments(); List<TD_Value> arguments = c.getArguments();
@ -515,14 +540,16 @@ public class C_ExpressionParser {
return col; return col;
} }
protected Expression getRange(C_Expression exp) throws ExpressionParserException { protected Expression getRange(C_Expression exp)
throws ExpressionParserException {
C_Range c = (C_Range) exp; C_Range c = (C_Range) exp;
Range range = new Range(getExpressionValue(c.getMinimum()), Range range = new Range(getExpressionValue(c.getMinimum()),
getExpressionValue(c.getMaximum())); getExpressionValue(c.getMaximum()));
return range; return range;
} }
protected MultivaluedExpression getRange(C_MultivaluedExpression exp) throws ExpressionParserException { protected MultivaluedExpression getRange(C_MultivaluedExpression exp)
throws ExpressionParserException {
C_Range c = (C_Range) exp; C_Range c = (C_Range) exp;
Range range = new Range(getExpressionValue(c.getMinimum()), Range range = new Range(getExpressionValue(c.getMinimum()),
getExpressionValue(c.getMaximum())); getExpressionValue(c.getMaximum()));
@ -545,7 +572,8 @@ public class C_ExpressionParser {
return ref; return ref;
} }
protected Expression getEquals(C_Expression exp) throws ExpressionParserException { protected Expression getEquals(C_Expression exp)
throws ExpressionParserException {
C_Equals e = (C_Equals) exp; C_Equals e = (C_Equals) exp;
Expression left = parse(e.getLeftArgument()); Expression left = parse(e.getLeftArgument());
Expression right = parse(e.getRightArgument()); Expression right = parse(e.getRightArgument());
@ -553,14 +581,16 @@ public class C_ExpressionParser {
return eq; return eq;
} }
private Expression getConcat(C_Expression exp) throws ExpressionParserException { private Expression getConcat(C_Expression exp)
throws ExpressionParserException {
C_Concat concat = (C_Concat) exp; C_Concat concat = (C_Concat) exp;
Concat conc = new Concat(parse(concat.getLeftArgument()), Concat conc = new Concat(parse(concat.getLeftArgument()),
parse(concat.getRightArgument())); parse(concat.getRightArgument()));
return conc; return conc;
} }
private Expression getSubstringByIndex(C_Expression exp) throws ExpressionParserException { private Expression getSubstringByIndex(C_Expression exp)
throws ExpressionParserException {
C_SubstringByIndex subByIndex = (C_SubstringByIndex) exp; C_SubstringByIndex subByIndex = (C_SubstringByIndex) exp;
SubstringByIndex sByIndex = new SubstringByIndex( SubstringByIndex sByIndex = new SubstringByIndex(
parse(subByIndex.getSourceString()), parse(subByIndex.getSourceString()),
@ -569,7 +599,8 @@ public class C_ExpressionParser {
return sByIndex; return sByIndex;
} }
private Expression getSubstringByRegex(C_Expression exp) throws ExpressionParserException { private Expression getSubstringByRegex(C_Expression exp)
throws ExpressionParserException {
C_SubstringByRegex subByRegex = (C_SubstringByRegex) exp; C_SubstringByRegex subByRegex = (C_SubstringByRegex) exp;
SubstringByRegex sByRegex = new SubstringByRegex( SubstringByRegex sByRegex = new SubstringByRegex(
parse(subByRegex.getSourceString()), parse(subByRegex.getSourceString()),
@ -577,7 +608,8 @@ public class C_ExpressionParser {
return sByRegex; return sByRegex;
} }
private Expression getSubstringPosition(C_Expression exp) throws ExpressionParserException { private Expression getSubstringPosition(C_Expression exp)
throws ExpressionParserException {
C_SubstringPosition subPosition = (C_SubstringPosition) exp; C_SubstringPosition subPosition = (C_SubstringPosition) exp;
SubstringPosition sPosition = new SubstringPosition( SubstringPosition sPosition = new SubstringPosition(
parse(subPosition.getLeftArgument()), parse(subPosition.getLeftArgument()),
@ -585,7 +617,8 @@ public class C_ExpressionParser {
return sPosition; return sPosition;
} }
private Expression getTextReplaceMatchingRegex(C_Expression exp) throws ExpressionParserException { private Expression getTextReplaceMatchingRegex(C_Expression exp)
throws ExpressionParserException {
C_TextReplaceMatchingRegex textReplaceMatchingRegex = (C_TextReplaceMatchingRegex) exp; C_TextReplaceMatchingRegex textReplaceMatchingRegex = (C_TextReplaceMatchingRegex) exp;
TDText tdRegexp = new TDText(textReplaceMatchingRegex.getRegexp() TDText tdRegexp = new TDText(textReplaceMatchingRegex.getRegexp()
.getValue()); .getValue());
@ -598,40 +631,54 @@ public class C_ExpressionParser {
return textRepRegex; return textRepRegex;
} }
private Expression getAvg(C_Expression exp) throws ExpressionParserException { private Expression getAvg(C_Expression exp)
throws ExpressionParserException {
C_Avg avg = (C_Avg) exp; C_Avg avg = (C_Avg) exp;
Avg av = new Avg(parse(avg.getArgument())); Avg av = new Avg(parse(avg.getArgument()));
return av; return av;
} }
private Expression getCount(C_Expression exp)throws ExpressionParserException{ private Expression getCount(C_Expression exp)
throws ExpressionParserException {
C_Count count = (C_Count) exp; C_Count count = (C_Count) exp;
Count cnt = new Count(parse(count.getArgument())); Count cnt = new Count(parse(count.getArgument()));
return cnt; return cnt;
} }
private Expression getMax(C_Expression exp) throws ExpressionParserException { private Expression getMax(C_Expression exp)
throws ExpressionParserException {
C_Max max = (C_Max) exp; C_Max max = (C_Max) exp;
Max ma = new Max(parse(max.getArgument())); Max ma = new Max(parse(max.getArgument()));
return ma; return ma;
} }
private Expression getMin(C_Expression exp) throws ExpressionParserException { private Expression getMin(C_Expression exp)
throws ExpressionParserException {
C_Min min = (C_Min) exp; C_Min min = (C_Min) exp;
Min mi = new Min(parse(min.getArgument())); Min mi = new Min(parse(min.getArgument()));
return mi; return mi;
} }
private Expression getSTExtent(C_Expression exp) throws ExpressionParserException { private Expression getSTExtent(C_Expression exp)
throws ExpressionParserException {
C_ST_Extent stExtent = (C_ST_Extent) exp; C_ST_Extent stExtent = (C_ST_Extent) exp;
ST_Extent stEx = new ST_Extent(parse(stExtent.getArgument())); ST_Extent stEx = new ST_Extent(parse(stExtent.getArgument()));
return stEx; return stEx;
} }
private Expression getSum(C_Expression exp) throws ExpressionParserException { private Expression getSum(C_Expression exp)
throws ExpressionParserException {
C_Sum sum = (C_Sum) exp; C_Sum sum = (C_Sum) exp;
Sum sm = new Sum(parse(sum.getArgument())); Sum sm = new Sum(parse(sum.getArgument()));
return sm; return sm;
} }
private Expression getCast(C_Expression exp)
throws ExpressionParserException {
C_Cast castExp = (C_Cast) exp;
Cast sm = new Cast(parse(castExp.getLeftArgument()),
mapColumnDataType(castExp.getRightArgument()));
return sm;
}
} }

View File

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

View File

@ -14,8 +14,7 @@ public enum C_OperatorType {
// LOGICAL // LOGICAL
ALL, AND, ANY, BETWEEN, NOT_BETWEEN, EXISTS, IN, NOT_IN, ALL, AND, ANY, BETWEEN, NOT_BETWEEN, EXISTS, IN, NOT_IN, LIKE, NOT_LIKE, NOT, OR, IS_NULL, UNIQUE, IS_NOT_NULL,
LIKE, NOT_LIKE, NOT, OR, IS_NULL, UNIQUE, IS_NOT_NULL,
// AGGREGATION // AGGREGATION
AVG, COUNT, MAX, MIN, SUM, ST_EXTENT, AVG, COUNT, MAX, MIN, SUM, ST_EXTENT,
@ -26,8 +25,10 @@ public enum C_OperatorType {
NOT_BEGINS_WITH, NOT_ENDS_WITH, NOT_CONTAINS, NOT_MATCH_REGEX, NOT_BEGINS_WITH, NOT_ENDS_WITH, NOT_CONTAINS, NOT_MATCH_REGEX,
CONCAT, SUBSTRING_BY_INDEX, SUBSTRING_BY_REGEX, CONCAT, SUBSTRING_BY_INDEX, SUBSTRING_BY_REGEX, SUBSTRING_POSITION, TEXT_REPLACE_MATCHING_REGEX,
SUBSTRING_POSITION, TEXT_REPLACE_MATCHING_REGEX,
// FUNCTIONS
CAST,
// COMPLEX // COMPLEX

View File

@ -0,0 +1,81 @@
package org.gcube.portlets.user.td.expressionwidget.shared.model.composite.functions;
import org.gcube.portlets.user.td.expressionwidget.shared.model.C_OperatorType;
import org.gcube.portlets.user.td.widgetcommonevent.shared.expression.C_Expression;
import org.gcube.portlets.user.td.widgetcommonevent.shared.tr.column.ColumnDataType;
/**
*
* @author "Giancarlo Panichi" <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class C_Cast extends C_Expression {
private static final long serialVersionUID = 5871179766613405166L;
protected String id = "Cast";
protected C_Expression leftArgument;
protected ColumnDataType rightArgument;
public C_Cast(){
super();
}
public C_Cast(C_Expression leftArgument,
ColumnDataType rightArgument) {
super();
this.leftArgument = leftArgument;
this.rightArgument = rightArgument;
}
public C_OperatorType getOperator() {
return C_OperatorType.CAST;
}
public ColumnDataType getReturnedDataType() {
return rightArgument;
}
@Override
public String getId() {
return id;
}
public C_Expression getLeftArgument() {
return leftArgument;
}
public void setLeftArgument(C_Expression leftArgument) {
this.leftArgument = leftArgument;
}
public ColumnDataType getRightArgument() {
return rightArgument;
}
public void setRightArgument(ColumnDataType rightArgument) {
this.rightArgument = rightArgument;
}
@Override
public String toString() {
return "C_Cast [id=" + id + ", leftArgument=" + leftArgument
+ ", rightArgument=" + rightArgument + "]";
}
public boolean isCastSupported(ColumnDataType sourceType,ColumnDataType targetType){
// from / to text
if(targetType==ColumnDataType.Text||sourceType==ColumnDataType.Text) return true;
// same class
if(sourceType==targetType) return true;
// integer <--> numeric
if((sourceType==ColumnDataType.Integer && targetType==ColumnDataType.Numeric)
|| (sourceType==ColumnDataType.Numeric && targetType==ColumnDataType.Integer))return true;
return false;
}
}

View File

@ -1,5 +1,7 @@
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.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;
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_SubstringByRegex;
@ -30,17 +32,17 @@ public class ReplaceTypeMap {
} }
public C_Expression map(ColumnData column, ReplaceType replaceType, public C_Expression map(ColumnData column, ReplaceType replaceType,
String firstArg, String secondArg) { String firstArg, String secondArg,boolean template) throws ReplaceTypeMapException {
return map(column, replaceType,firstArg, secondArg, null, null, null, null); return map(column, replaceType,firstArg, secondArg, template, null, null, null, null);
} }
public C_Expression map(ColumnData column, ReplaceType replaceType, public C_Expression map(ColumnData column, ReplaceType replaceType,
String firstArg, String secondArg, C_Expression firstE, String firstArg, String secondArg, boolean template, C_Expression firstE,
C_Expression secondE, String readableFirstE, String readableSecondE) { 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 (column.getTrId() == null) { if (template) {
exp = mapPlaceHolder(column, replaceType, firstArg, secondArg, exp = mapPlaceHolder(column, replaceType, firstArg, secondArg,
firstE, secondE, readableFirstE,readableSecondE); firstE, secondE, readableFirstE,readableSecondE);
} else { } else {
@ -52,17 +54,51 @@ public class ReplaceTypeMap {
public C_Expression mapPlaceHolder(ColumnData column, public C_Expression mapPlaceHolder(ColumnData column,
ReplaceType replaceType, String firstArg, String secondArg, ReplaceType replaceType, String firstArg, String secondArg,
C_Expression firstE, C_Expression secondE,String readableFirstE, String readableSecondE) { C_Expression firstE, C_Expression secondE,String readableFirstE, String readableSecondE) throws ReplaceTypeMapException {
Log.debug("OperatorTypeMap Map Place Holder"); Log.debug("OperatorTypeMap Map Place Holder");
C_Expression exp = null; C_Expression exp = null;
if(column==null){
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 Concat:
exp = new C_Concat(firstE, secondE);
readableExpression = "Concat(" + readableFirstE
+ ", " + readableSecondE + ")";
break;
default:
throw new ReplaceTypeMapException("No valid column selected");
}
return exp;
}
Log.debug("Column Data Type Name:" + column.getDataTypeName()); Log.debug("Column Data Type Name:" + column.getDataTypeName());
ColumnDataType dataType = ColumnTypeMap.getColumnDataType(column ColumnDataType dataType = ColumnTypeMap.getColumnDataType(column
.getDataTypeName()); .getDataTypeName());
Log.debug("Data Type:" + dataType); Log.debug("Data Type:" + dataType);
C_ColumnReferencePlaceholder placeHolder = new C_ColumnReferencePlaceholder( C_ColumnReferencePlaceholder placeH = new C_ColumnReferencePlaceholder(
dataType, column.getColumnId()); dataType, column.getColumnId());
C_Expression placeHolder;
String readablePlaceHolder;
if(dataType!=ColumnDataType.Text){
placeHolder=new C_Cast(placeH,ColumnDataType.Text);
readablePlaceHolder= "Cast("+column.getColumnId()+")";
} else {
placeHolder=placeH;
readablePlaceHolder= column.getColumnId();
}
Log.debug("placeHolder:" + placeHolder); Log.debug("placeHolder:" + placeHolder);
String readablePlaceHolder = column.getColumnId();
TD_Value fArg, sArg; TD_Value fArg, sArg;
C_Expression posFrom, posTo; C_Expression posFrom, posTo;
@ -72,7 +108,8 @@ public class ReplaceTypeMap {
readableExpression = "Null()"; readableExpression = "Null()";
break; break;
case Value: case Value:
exp = new TD_Value(dataType, firstArg); checkTypeArgument(ColumnDataType.Text,firstArg);
exp = new TD_Value(ColumnDataType.Text, firstArg);
readableExpression = "Value(" + firstArg + ")"; readableExpression = "Value(" + firstArg + ")";
break; break;
case ColumnValue: case ColumnValue:
@ -85,12 +122,15 @@ public class ReplaceTypeMap {
+ ", " + readableSecondE + ")"; + ", " + readableSecondE + ")";
break; break;
case SubstringByRegex: case SubstringByRegex:
checkTypeArgument(ColumnDataType.Text,firstArg);
fArg = new TD_Value(ColumnDataType.Text, firstArg); fArg = new TD_Value(ColumnDataType.Text, firstArg);
exp = new C_SubstringByRegex(placeHolder, fArg); exp = new C_SubstringByRegex(placeHolder, fArg);
readableExpression = "SubStringByRegex(" + readablePlaceHolder readableExpression = "SubStringByRegex(" + readablePlaceHolder
+ ", " + firstArg + ")"; + ", " + firstArg + ")";
break; break;
case SubstringByIndex: case SubstringByIndex:
checkTypeArgument(ColumnDataType.Integer,firstArg);
checkTypeArgument(ColumnDataType.Integer,secondArg);
fArg = new TD_Value(ColumnDataType.Integer, firstArg); fArg = new TD_Value(ColumnDataType.Integer, firstArg);
sArg = new TD_Value(ColumnDataType.Integer, secondArg); sArg = new TD_Value(ColumnDataType.Integer, secondArg);
exp = new C_SubstringByIndex(placeHolder, fArg, sArg); exp = new C_SubstringByIndex(placeHolder, fArg, sArg);
@ -98,8 +138,10 @@ public class ReplaceTypeMap {
+ ", " + firstArg + ", " + secondArg + ")"; + ", " + firstArg + ", " + secondArg + ")";
break; break;
case SubstringByCharSeq: case SubstringByCharSeq:
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);
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); exp = new C_SubstringByIndex(placeHolder, posFrom, posTo);
@ -107,6 +149,8 @@ public class ReplaceTypeMap {
+ ", " + firstArg + ", " + secondArg + ")"; + ", " + firstArg + ", " + secondArg + ")";
break; break;
case TextReplaceMatchingRegex: case TextReplaceMatchingRegex:
checkTypeArgument(ColumnDataType.Text,firstArg);
checkTypeArgument(ColumnDataType.Text,secondArg);
fArg = new TD_Value(ColumnDataType.Text, firstArg); fArg = new TD_Value(ColumnDataType.Text, firstArg);
sArg = new TD_Value(ColumnDataType.Text, secondArg); sArg = new TD_Value(ColumnDataType.Text, secondArg);
exp = new C_TextReplaceMatchingRegex(placeHolder, fArg, sArg); exp = new C_TextReplaceMatchingRegex(placeHolder, fArg, sArg);
@ -121,18 +165,52 @@ public class ReplaceTypeMap {
public C_Expression mapTypedColumnReference(ColumnData column, public C_Expression mapTypedColumnReference(ColumnData column,
ReplaceType replaceType, String firstArg, String secondArg, ReplaceType replaceType, String firstArg, String secondArg,
C_Expression firstE, C_Expression secondE, String readableFirstE, String readableSecondE) { C_Expression firstE, C_Expression secondE, String readableFirstE, String readableSecondE) throws ReplaceTypeMapException {
Log.debug("OperatorTypeMap Map Typed Column Reference"); Log.debug("OperatorTypeMap Map Typed Column Reference");
C_Expression exp = null; C_Expression exp = null;
if(column==null){
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 Concat:
exp = new C_Concat(firstE, secondE);
readableExpression = "Concat(" + readableFirstE
+ ", " + readableSecondE + ")";
break;
default:
throw new ReplaceTypeMapException("No valid column selected");
}
return exp;
}
Log.debug("Column Data Type Name:" + column.getDataTypeName()); Log.debug("Column Data Type Name:" + column.getDataTypeName());
ColumnDataType dataType = ColumnTypeMap.getColumnDataType(column ColumnDataType dataType = ColumnTypeMap.getColumnDataType(column
.getDataTypeName()); .getDataTypeName());
Log.debug("Data Type:" + dataType); Log.debug("Data Type:" + dataType);
C_TypedColumnReference columnReference = new C_TypedColumnReference(
C_TypedColumnReference columnRef = new C_TypedColumnReference(
column.getTrId(), dataType, column.getColumnId()); 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()+")";
} else {
columnReference=columnRef;
readableColumnReference= column.getColumnId();
}
Log.debug("Typed Column Reference:" + columnReference); Log.debug("Typed Column Reference:" + columnReference);
String readableColumnReference = column.getLabel();
TD_Value fArg, sArg; TD_Value fArg, sArg;
C_Expression posFrom, posTo; C_Expression posFrom, posTo;
@ -143,7 +221,8 @@ public class ReplaceTypeMap {
readableExpression = "Null()"; readableExpression = "Null()";
break; break;
case Value: case Value:
exp = new TD_Value(dataType, firstArg); checkTypeArgument(ColumnDataType.Text, firstArg);
exp = new TD_Value(ColumnDataType.Text, firstArg);
readableExpression = "Value(" + firstArg + ")"; readableExpression = "Value(" + firstArg + ")";
break; break;
case ColumnValue: case ColumnValue:
@ -156,12 +235,15 @@ public class ReplaceTypeMap {
+ ", " + readableSecondE + ")"; + ", " + readableSecondE + ")";
break; break;
case SubstringByRegex: case SubstringByRegex:
checkTypeArgument(ColumnDataType.Text, firstArg);
fArg = new TD_Value(ColumnDataType.Text, firstArg); fArg = new TD_Value(ColumnDataType.Text, firstArg);
exp = new C_SubstringByRegex(columnReference, fArg); exp = new C_SubstringByRegex(columnReference, fArg);
readableExpression = "SubStringByRegex(" + readableColumnReference readableExpression = "SubStringByRegex(" + readableColumnReference
+ ", " + firstArg + ")"; + ", " + firstArg + ")";
break; break;
case SubstringByIndex: case SubstringByIndex:
checkTypeArgument(ColumnDataType.Integer, firstArg);
checkTypeArgument(ColumnDataType.Integer, secondArg);
fArg = new TD_Value(ColumnDataType.Integer, firstArg); fArg = new TD_Value(ColumnDataType.Integer, firstArg);
sArg = new TD_Value(ColumnDataType.Integer, secondArg); sArg = new TD_Value(ColumnDataType.Integer, secondArg);
exp = new C_SubstringByIndex(columnReference, fArg, sArg); exp = new C_SubstringByIndex(columnReference, fArg, sArg);
@ -169,8 +251,10 @@ public class ReplaceTypeMap {
+ ", " + firstArg + ", " + secondArg + ")"; + ", " + firstArg + ", " + secondArg + ")";
break; break;
case SubstringByCharSeq: case SubstringByCharSeq:
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);
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); exp = new C_SubstringByIndex(columnReference, posFrom, posTo);
@ -179,6 +263,8 @@ public class ReplaceTypeMap {
+ secondArg + ")"; + secondArg + ")";
break; break;
case TextReplaceMatchingRegex: case TextReplaceMatchingRegex:
checkTypeArgument(ColumnDataType.Text, firstArg);
checkTypeArgument(ColumnDataType.Text, secondArg);
fArg = new TD_Value(ColumnDataType.Text, firstArg); fArg = new TD_Value(ColumnDataType.Text, firstArg);
sArg = new TD_Value(ColumnDataType.Text, secondArg); sArg = new TD_Value(ColumnDataType.Text, secondArg);
exp = new C_TextReplaceMatchingRegex(columnReference, fArg, sArg); exp = new C_TextReplaceMatchingRegex(columnReference, fArg, sArg);
@ -196,4 +282,58 @@ public class ReplaceTypeMap {
return readableExpression; return readableExpression;
} }
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 {
}
}
}
}
}
}
}
} }