diff --git a/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/ExpressionWidgetEntry.java b/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/ExpressionWidgetEntry.java index 65072bc..962000d 100644 --- a/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/ExpressionWidgetEntry.java +++ b/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/ExpressionWidgetEntry.java @@ -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.google.gwt.core.client.EntryPoint; @@ -21,8 +21,8 @@ public class ExpressionWidgetEntry implements EntryPoint { public void onModuleLoad() { EventBus eventBus= new SimpleEventBus(); - //TRId trId=new TRId("154","1610"); - //String columnName="zwqvvx"; + TRId trId=new TRId("154","1969"); + String columnName="zwqvvx"; //Column Expression Dialog //ColumnExpressionDialog expressionDialog=new ColumnExpressionDialog("1", ColumnTypeCode.ATTRIBUTE, ColumnDataType.Integer, eventBus); @@ -39,11 +39,12 @@ public class ExpressionWidgetEntry implements EntryPoint { //multiColumnFilterDialog.show(); //Replace Column By Expression Dialog - //ReplaceColumnByExpressionDialog replaceColumnByExpression= new ReplaceColumnByExpressionDialog(trId, columnName, eventBus); - //replaceColumnByExpression.show(); + ReplaceColumnByExpressionDialog replaceColumnByExpression= new ReplaceColumnByExpressionDialog(trId, columnName, eventBus); + replaceColumnByExpression.show(); - HelpReplaceColumnByExpressionDialog help= new HelpReplaceColumnByExpressionDialog(eventBus); - help.show(); + //HelpReplaceColumnByExpressionDialog + //HelpReplaceColumnByExpressionDialog help= new HelpReplaceColumnByExpressionDialog(eventBus); + //help.show(); Log.info("Hello!"); } diff --git a/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/ReplaceColumnByExpressionDialog.java b/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/ReplaceColumnByExpressionDialog.java index f8337bf..84dc986 100644 --- a/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/ReplaceColumnByExpressionDialog.java +++ b/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/ReplaceColumnByExpressionDialog.java @@ -37,7 +37,7 @@ import com.sencha.gxt.widget.core.client.event.SelectEvent.SelectHandler; */ public class ReplaceColumnByExpressionDialog extends Window implements MonitorDialogListener { - protected static final String WIDTH = "710px"; + protected static final String WIDTH = "880px"; protected static final String HEIGHT = "490px"; protected static final String HEIGHT_REDUCE = "404px"; diff --git a/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/ReplaceColumnByExpressionPanel.java b/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/ReplaceColumnByExpressionPanel.java index 1317c18..2976def 100644 --- a/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/ReplaceColumnByExpressionPanel.java +++ b/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/ReplaceColumnByExpressionPanel.java @@ -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.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.gwtservice.shared.tr.ColumnData; 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*$)" + "|(\\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_REDUCE = "368px"; - protected static final String CONDITIONWIDTH = "662px"; + protected static final String CONDITIONWIDTH = "832px"; protected static final String CONDITIONHEIGHT = "120px"; - protected static final String CONDITION_LAYOUT_WIDTH = "662px"; - protected static final String REPLACEWIDTH = "662px"; + protected static final String CONDITION_LAYOUT_WIDTH = "832px"; + protected static final String REPLACEWIDTH = "832px"; 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_ALL_ROWS = "All Rows"; @@ -209,7 +210,7 @@ public class ReplaceColumnByExpressionPanel extends FramedPanel { if (column.getDataTypeName().compareTo( ColumnDataType.Text.toString()) == 0) { replaceWidget = new ReplaceWidget(column, REPLACEWIDTH, - REPLACEHEIGHT); + REPLACEHEIGHT, eventBus); replaceValueFieldSetLayout.add(replaceWidget, new VerticalLayoutData(1, -1)); } else { @@ -323,9 +324,9 @@ public class ReplaceColumnByExpressionPanel extends FramedPanel { "Replace expression is not valid!"); return; } - } catch (Throwable e) { + } catch (ReplaceTypeMapException e) { UtilsGXT3.alert("Attention", - "Replace expression is not valid!"); + e.getLocalizedMessage()); return; } parent.applyReplaceColumnByExpression(cConditionExpression, diff --git a/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/ReplaceWidget.java b/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/ReplaceWidget.java index 060b7ed..446cc00 100644 --- a/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/ReplaceWidget.java +++ b/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/ReplaceWidget.java @@ -1,17 +1,31 @@ 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.ReplaceElementProperties; 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.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.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 com.allen_sauer.gwt.log.client.Log; import com.google.gwt.core.client.GWT; import com.google.gwt.event.logical.shared.SelectionEvent; 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.core.client.dom.ScrollSupport.ScrollMode; import com.sencha.gxt.core.client.util.Margins; @@ -44,22 +58,27 @@ public class ReplaceWidget extends SimpleContainer { private static final String EMPTY_TEXT_INSERT_A_STRING = "insert a string..."; private static final String EMPTY_TEXT_REPLACE_REGEXP = "regexp..."; private static final String EMPTY_TEXT_REPLACE_REPLACING = "replacing..."; - + private ReplaceWidget thisCont; protected static final String HEIGHT = "210px"; - protected static final String WIDTH = "662px"; + protected static final String WIDTH = "832px"; protected static final String COMBO_WIDTH = "170px"; - + + protected EventBus eventBus; + protected TRId trId; + protected ArrayList columns; + protected FieldLabel matchLabel; protected ToggleGroup groupMatch; protected VerticalLayoutContainer vert; - protected ColumnData column; + // protected ColumnData column; protected String readableExpression; private String itemIdComboConcat; private String itemIdComboLeaf; + private String itemIdComboColumns; private String itemIdFirstArg; private String itemIdSecondArg; private String itemIdHoriz; @@ -93,25 +112,36 @@ public class ReplaceWidget extends SimpleContainer { } - public ReplaceWidget(ColumnData column) { + public ReplaceWidget(ColumnData column, EventBus eventBus) { 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(); - create(column, width, height); + create(column.getTrId(), width, height, eventBus); } - protected void create(ColumnData column, String width, String height) { - this.column = column; + public ReplaceWidget(TRId trId, EventBus eventBus) { + 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); setWidth(width); setHeight(height); forceLayoutOnResize = true; thisCont = this; - setup(); addBeforeShowHandler(new BeforeShowEvent.BeforeShowHandler() { @Override @@ -120,15 +150,55 @@ public class ReplaceWidget extends SimpleContainer { } }); + retrieveColumns(); } + protected void retrieveColumns() { + TDGWTServiceAsync.INSTANCE.getColumns(trId, + new AsyncCallback>() { + + 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 result) { + Log.trace("loaded " + result.size() + " ColumnData"); + columns = result; + setup(); + } + + }); + } + protected void setup() { - itemIdComboConcat = "ComboConcat" + column.getName(); - itemIdComboLeaf = "ComboLeaf" + column.getName(); - itemIdFirstArg = "FirstArg" + column.getName(); - itemIdSecondArg = "SecondArg" + column.getName(); - itemIdHoriz = "Horiz" + column.getName(); + itemIdComboConcat = "ComboConcat" + trId.getId(); + itemIdComboLeaf = "ComboLeaf" + trId.getId(); + itemIdComboColumns = "ComboColumns" + trId.getId(); + itemIdFirstArg = "FirstArg" + trId.getId(); + itemIdSecondArg = "SecondArg" + trId.getId(); + itemIdHoriz = "Horiz" + trId.getId(); vert = new VerticalLayoutContainer(); vert.setScrollMode(ScrollMode.AUTO); @@ -143,6 +213,27 @@ public class ReplaceWidget extends SimpleContainer { secondArg.setEmptyText(""); secondArg.setItemId(itemIdSecondArg); + // Combo Column + ColumnDataPropertiesCombo propsColumnData = GWT + .create(ColumnDataPropertiesCombo.class); + ListStore storeColumns = new ListStore( + propsColumnData.id()); + Log.debug("Store Columns: " + storeColumns); + storeColumns.addAll(columns); + + final ComboBox comboColumns = new ComboBox( + 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(); ReplaceElementProperties props = GWT @@ -170,12 +261,16 @@ public class ReplaceWidget extends SimpleContainer { Log.debug("Condition selected:" + re.toString()); switch (re.getReplaceType()) { case Value: + comboColumns.clear(); + comboColumns.setVisible(false); firstArg.setVisible(true); firstArg.setEmptyText(EMPTY_TEXT_INSERT_A_STRING); secondArg.setVisible(false); secondArg.setEmptyText(""); break; case ColumnValue: + comboColumns.clear(); + comboColumns.setVisible(true); firstArg.setVisible(false); firstArg.setEmptyText(""); secondArg.setVisible(false); @@ -184,29 +279,38 @@ public class ReplaceWidget extends SimpleContainer { case Concat: break; case SubstringByRegex: + comboColumns.clear(); + comboColumns.setVisible(true); firstArg.setVisible(true); firstArg.setEmptyText(EMPTY_TEXT_REGEXP); secondArg.setVisible(false); secondArg.setEmptyText(""); break; case SubstringByIndex: + comboColumns.clear(); + comboColumns.setVisible(true); firstArg.setVisible(true); firstArg.setEmptyText(EMPTY_TEXT_FROM_INDEX); secondArg.setVisible(true); secondArg.setEmptyText(EMPTY_TEXT_TO_INDEX); break; case SubstringByCharSeq: + comboColumns.clear(); + comboColumns.setVisible(true); firstArg.setVisible(true); firstArg.setEmptyText(EMPTY_TEXT_FROM_STRING); secondArg.setVisible(true); secondArg.setEmptyText(EMPTY_TEXT_TO_STRING); break; case TextReplaceMatchingRegex: + comboColumns.clear(); + comboColumns.setVisible(true); firstArg.setVisible(true); firstArg.setEmptyText(EMPTY_TEXT_REPLACE_REGEXP); secondArg.setVisible(true); - secondArg.setEmptyText(EMPTY_TEXT_REPLACE_REPLACING); - break; + secondArg + .setEmptyText(EMPTY_TEXT_REPLACE_REPLACING); + break; default: break; } @@ -251,6 +355,8 @@ public class ReplaceWidget extends SimpleContainer { switch (re.getReplaceType()) { case Value: comboReplaceElementsLeaf.setVisible(false); + comboColumns.clear(); + comboColumns.setVisible(false); firstArg.setEmptyText(EMPTY_TEXT_INSERT_A_STRING); firstArg.setVisible(true); secondArg.setVisible(false); @@ -259,6 +365,8 @@ public class ReplaceWidget extends SimpleContainer { break; case ColumnValue: comboReplaceElementsLeaf.setVisible(false); + comboColumns.clear(); + comboColumns.setVisible(true); firstArg.setVisible(false); firstArg.setEmptyText(""); secondArg.setVisible(false); @@ -268,6 +376,8 @@ public class ReplaceWidget extends SimpleContainer { if (!existConcat(source)) { comboReplaceElementsLeaf.clear(); comboReplaceElementsLeaf.setVisible(true); + comboColumns.clear(); + comboColumns.setVisible(false); firstArg.setVisible(false); firstArg.setEmptyText(""); secondArg.setVisible(false); @@ -277,6 +387,8 @@ public class ReplaceWidget extends SimpleContainer { break; case SubstringByRegex: comboReplaceElementsLeaf.setVisible(false); + comboColumns.clear(); + comboColumns.setVisible(true); firstArg.setVisible(true); firstArg.setEmptyText(EMPTY_TEXT_REGEXP); secondArg.setVisible(false); @@ -285,6 +397,8 @@ public class ReplaceWidget extends SimpleContainer { break; case SubstringByIndex: comboReplaceElementsLeaf.setVisible(false); + comboColumns.clear(); + comboColumns.setVisible(true); firstArg.setVisible(true); firstArg.setEmptyText(EMPTY_TEXT_FROM_INDEX); secondArg.setVisible(true); @@ -293,6 +407,8 @@ public class ReplaceWidget extends SimpleContainer { break; case SubstringByCharSeq: comboReplaceElementsLeaf.setVisible(false); + comboColumns.clear(); + comboColumns.setVisible(true); firstArg.setVisible(true); firstArg.setEmptyText(EMPTY_TEXT_FROM_STRING); secondArg.setVisible(true); @@ -301,12 +417,15 @@ public class ReplaceWidget extends SimpleContainer { break; case TextReplaceMatchingRegex: comboReplaceElementsLeaf.setVisible(false); + comboColumns.clear(); + comboColumns.setVisible(true); firstArg.setVisible(true); firstArg.setEmptyText(EMPTY_TEXT_REPLACE_REGEXP); secondArg.setVisible(true); - secondArg.setEmptyText(EMPTY_TEXT_REPLACE_REPLACING); + secondArg + .setEmptyText(EMPTY_TEXT_REPLACE_REPLACING); removeConcat(source); - break; + break; default: break; } @@ -330,6 +449,7 @@ public class ReplaceWidget extends SimpleContainer { // horiz.add(comboReplaceElementsConcat, 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(secondArg, new BoxLayoutData(new Margins(0))); horiz.setItemId(itemIdHoriz); @@ -339,6 +459,7 @@ public class ReplaceWidget extends SimpleContainer { firstArg.setVisible(true); secondArg.setVisible(false); + comboColumns.setVisible(false); comboReplaceElementsLeaf.setVisible(false); comboReplaceElementsConcat.setVisible(true); forceLayout(); @@ -353,6 +474,27 @@ public class ReplaceWidget extends SimpleContainer { final TextField secondArg = new TextField(); secondArg.setItemId(itemIdSecondArg); + // Combo Column + ColumnDataPropertiesCombo propsColumnData = GWT + .create(ColumnDataPropertiesCombo.class); + ListStore storeColumns = new ListStore( + propsColumnData.id()); + Log.debug("Store Columns: " + storeColumns); + storeColumns.addAll(columns); + + final ComboBox comboColumns = new ComboBox( + 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(); ReplaceElementProperties props = GWT @@ -380,12 +522,16 @@ public class ReplaceWidget extends SimpleContainer { Log.debug("Condition selected:" + re.toString()); switch (re.getReplaceType()) { case Value: + comboColumns.clear(); + comboColumns.setVisible(false); firstArg.setVisible(true); firstArg.setEmptyText(EMPTY_TEXT_INSERT_A_STRING); secondArg.setVisible(false); secondArg.setEmptyText(""); break; case ColumnValue: + comboColumns.clear(); + comboColumns.setVisible(true); firstArg.setVisible(false); firstArg.setEmptyText(""); secondArg.setVisible(false); @@ -394,29 +540,38 @@ public class ReplaceWidget extends SimpleContainer { case Concat: break; case SubstringByRegex: + comboColumns.clear(); + comboColumns.setVisible(true); firstArg.setVisible(true); firstArg.setEmptyText(EMPTY_TEXT_REGEXP); secondArg.setVisible(false); secondArg.setEmptyText(""); break; case SubstringByIndex: + comboColumns.clear(); + comboColumns.setVisible(true); firstArg.setVisible(true); firstArg.setEmptyText(EMPTY_TEXT_FROM_INDEX); secondArg.setVisible(true); secondArg.setEmptyText(EMPTY_TEXT_TO_INDEX); break; case SubstringByCharSeq: + comboColumns.clear(); + comboColumns.setVisible(true); firstArg.setVisible(true); firstArg.setEmptyText(EMPTY_TEXT_FROM_STRING); secondArg.setVisible(true); secondArg.setEmptyText(EMPTY_TEXT_TO_STRING); break; case TextReplaceMatchingRegex: + comboColumns.clear(); + comboColumns.setVisible(true); firstArg.setVisible(true); firstArg.setEmptyText(EMPTY_TEXT_REPLACE_REGEXP); secondArg.setVisible(true); - secondArg.setEmptyText(EMPTY_TEXT_REPLACE_REPLACING); - break; + secondArg + .setEmptyText(EMPTY_TEXT_REPLACE_REPLACING); + break; default: break; } @@ -461,6 +616,8 @@ public class ReplaceWidget extends SimpleContainer { switch (re.getReplaceType()) { case Value: comboReplaceElementsLeaf.setVisible(false); + comboColumns.clear(); + comboColumns.setVisible(false); firstArg.setEmptyText(EMPTY_TEXT_INSERT_A_STRING); firstArg.setVisible(true); secondArg.setVisible(false); @@ -469,6 +626,8 @@ public class ReplaceWidget extends SimpleContainer { break; case ColumnValue: comboReplaceElementsLeaf.setVisible(false); + comboColumns.clear(); + comboColumns.setVisible(true); firstArg.setVisible(false); firstArg.setEmptyText(""); secondArg.setVisible(false); @@ -478,6 +637,8 @@ public class ReplaceWidget extends SimpleContainer { if (!existConcat(source)) { comboReplaceElementsLeaf.clear(); comboReplaceElementsLeaf.setVisible(true); + comboColumns.clear(); + comboColumns.setVisible(false); firstArg.setVisible(false); firstArg.setEmptyText(""); secondArg.setVisible(false); @@ -487,6 +648,8 @@ public class ReplaceWidget extends SimpleContainer { break; case SubstringByRegex: comboReplaceElementsLeaf.setVisible(false); + comboColumns.clear(); + comboColumns.setVisible(true); firstArg.setVisible(true); firstArg.setEmptyText(EMPTY_TEXT_REGEXP); secondArg.setVisible(false); @@ -495,6 +658,8 @@ public class ReplaceWidget extends SimpleContainer { break; case SubstringByIndex: comboReplaceElementsLeaf.setVisible(false); + comboColumns.clear(); + comboColumns.setVisible(true); firstArg.setVisible(true); firstArg.setEmptyText(EMPTY_TEXT_FROM_INDEX); secondArg.setVisible(true); @@ -503,6 +668,8 @@ public class ReplaceWidget extends SimpleContainer { break; case SubstringByCharSeq: comboReplaceElementsLeaf.setVisible(false); + comboColumns.clear(); + comboColumns.setVisible(true); firstArg.setVisible(true); firstArg.setEmptyText(EMPTY_TEXT_FROM_STRING); secondArg.setVisible(true); @@ -511,12 +678,15 @@ public class ReplaceWidget extends SimpleContainer { break; case TextReplaceMatchingRegex: comboReplaceElementsLeaf.setVisible(false); + comboColumns.clear(); + comboColumns.setVisible(true); firstArg.setVisible(true); firstArg.setEmptyText(EMPTY_TEXT_REPLACE_REGEXP); secondArg.setVisible(true); - secondArg.setEmptyText(EMPTY_TEXT_REPLACE_REPLACING); + secondArg + .setEmptyText(EMPTY_TEXT_REPLACE_REPLACING); removeConcat(source); - break; + break; default: break; } @@ -541,6 +711,7 @@ public class ReplaceWidget extends SimpleContainer { // horiz.add(comboReplaceElementsConcat, 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(secondArg, new BoxLayoutData(new Margins(0))); horiz.setItemId(itemIdHoriz); @@ -548,6 +719,7 @@ public class ReplaceWidget extends SimpleContainer { firstArg.setVisible(true); secondArg.setVisible(false); + comboColumns.setVisible(false); comboReplaceElementsLeaf.setVisible(false); comboReplaceElementsConcat.setVisible(true); forceLayout(); @@ -578,7 +750,7 @@ public class ReplaceWidget extends SimpleContainer { return exist; } - public C_Expression getExpression() { + public C_Expression getExpression() throws ReplaceTypeMapException { ExpressionContainer expressionContainer = null; readableExpression = new String(); C_Expression expression = null; @@ -591,7 +763,7 @@ public class ReplaceWidget extends SimpleContainer { .getReadableExpression(); expression = expressionContainer.getExpression(); } else { - + } } @@ -604,7 +776,7 @@ public class ReplaceWidget extends SimpleContainer { return readableExpression; } - protected ExpressionContainer calcCExpression(int index) { + protected ExpressionContainer calcCExpression(int index) throws ReplaceTypeMapException { ExpressionContainer expressionContainer = null; ExpressionContainer expContainerConcat = null; C_Expression exp = null; @@ -620,16 +792,22 @@ public class ReplaceWidget extends SimpleContainer { @SuppressWarnings("unchecked") ComboBox comboConcat = (ComboBox) horiz .getItemByItemId(itemIdComboConcat); - Log.debug("combo: " + comboConcat.getCurrentValue().toString()); + Log.debug("combo Concat: " + comboConcat.getCurrentValue()); @SuppressWarnings("unchecked") ComboBox comboLeaf = (ComboBox) horiz .getItemByItemId(itemIdComboLeaf); - Log.debug("combo: " + comboConcat.getCurrentValue().toString()); - + Log.debug("combo Leaf: " + comboLeaf.getCurrentValue()); + + @SuppressWarnings("unchecked") + ComboBox comboColumns = (ComboBox) horiz + .getItemByItemId(itemIdComboColumns); + Log.debug("combo columns: " + comboColumns.getCurrentValue()); + ColumnData column=comboColumns.getCurrentValue(); + firstArg = (TextField) horiz.getItemByItemId(itemIdFirstArg); secondArg = (TextField) horiz.getItemByItemId(itemIdSecondArg); - Log.debug("firstArg: " + firstArg.getCurrentValue() + " secondArg: " - + secondArg.getCurrentValue()); + Log.debug("[column: "+column+", firstArg: " + firstArg.getCurrentValue() + ", secondArg: " + + secondArg.getCurrentValue()+"]"); ReplaceType comboConcatReplaceType = null; ReplaceType comboLeafReplaceType = null; @@ -638,11 +816,11 @@ public class ReplaceWidget extends SimpleContainer { if (index == vert.getWidgetCount() - 1) { exp = mapReplace.map(column, ReplaceType.Null, firstArg == null ? null : firstArg.getCurrentValue(), - secondArg == null ? null : secondArg.getCurrentValue()); + secondArg == null ? null : secondArg.getCurrentValue(), false); readableExp = mapReplace.getReadableExpression(); expressionContainer = new ExpressionContainer(exp, readableExp); } else { - return null; + throw new ReplaceTypeMapException("Fill all field!"); } } else { comboConcatReplaceType = comboConcat.getCurrentValue() @@ -656,7 +834,7 @@ public class ReplaceWidget extends SimpleContainer { firstArg == null ? null : firstArg .getCurrentValue(), secondArg == null ? null : secondArg - .getCurrentValue()); + .getCurrentValue(), false); readableExpLeaf = mapReplace.getReadableExpression(); } else { @@ -668,7 +846,7 @@ public class ReplaceWidget extends SimpleContainer { firstArg == null ? null : firstArg .getCurrentValue(), secondArg == null ? null : secondArg - .getCurrentValue()); + .getCurrentValue(), false); readableExpLeaf = mapReplace.getReadableExpression(); } @@ -684,7 +862,7 @@ public class ReplaceWidget extends SimpleContainer { firstArg == null ? null : firstArg .getCurrentValue(), secondArg == null ? null : secondArg - .getCurrentValue(), expLeaf, + .getCurrentValue(),false, expLeaf, expContainerConcat.getExpression(), readableExpLeaf, expContainerConcat .getReadableExpression()); @@ -699,10 +877,9 @@ public class ReplaceWidget extends SimpleContainer { } else { exp = mapReplace.map(column, comboConcatReplaceType, firstArg == null ? null : firstArg.getCurrentValue(), - secondArg == null ? null : secondArg.getCurrentValue()); + secondArg == null ? null : secondArg.getCurrentValue(),false); readableExp = mapReplace.getReadableExpression(); - expressionContainer = new ExpressionContainer(exp, - readableExp); + expressionContainer = new ExpressionContainer(exp, readableExp); } } diff --git a/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/properties/ColumnDataPropertiesCombo.java b/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/properties/ColumnDataPropertiesCombo.java new file mode 100644 index 0000000..c856304 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/properties/ColumnDataPropertiesCombo.java @@ -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" + * g.panichi@isti.cnr.it + * + */ +public interface ColumnDataPropertiesCombo extends + PropertyAccess { + + @Path("id") + ModelKeyProvider id(); + + LabelProvider label(); + + +} diff --git a/src/main/java/org/gcube/portlets/user/td/expressionwidget/server/C_ExpressionParser.java b/src/main/java/org/gcube/portlets/user/td/expressionwidget/server/C_ExpressionParser.java index 8ee28ef..bb2de96 100644 --- a/src/main/java/org/gcube/portlets/user/td/expressionwidget/server/C_ExpressionParser.java +++ b/src/main/java/org/gcube/portlets/user/td/expressionwidget/server/C_ExpressionParser.java @@ -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.TextMatchSQLRegexp; 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.ConstantList; 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_NotGreater; 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_SubstringByIndex; import org.gcube.portlets.user.td.expressionwidget.shared.model.composite.text.C_SubstringByRegex; @@ -217,6 +219,9 @@ public class C_ExpressionParser { case "ST_Extent": ex = getSTExtent(exp); break; + case "Cast": + ex = getCast(exp); + break; default: break; } @@ -224,7 +229,8 @@ public class C_ExpressionParser { return ex; } - public MultivaluedExpression parseMultivalued(C_MultivaluedExpression exp) throws ExpressionParserException { + public MultivaluedExpression parseMultivalued(C_MultivaluedExpression exp) + throws ExpressionParserException { MultivaluedExpression ex = null; switch (exp.getIdMulti()) { case "ConstantList": @@ -241,7 +247,8 @@ public class C_ExpressionParser { return ex; } - private Expression getValueIsIn(C_Expression exp) throws ExpressionParserException { + private Expression getValueIsIn(C_Expression exp) + throws ExpressionParserException { C_ValueIsIn v = (C_ValueIsIn) exp; MultivaluedExpression multivalued = parseMultivalued(v .getRightArgument()); @@ -263,25 +270,29 @@ public class C_ExpressionParser { return or; } - private Expression getNot(C_Expression exp) throws ExpressionParserException { + private Expression getNot(C_Expression exp) + throws ExpressionParserException { C_Not n = (C_Not) exp; Not not = new Not(parse(n.getArgument())); return not; } - private Expression getIsNull(C_Expression exp) throws ExpressionParserException { + private Expression getIsNull(C_Expression exp) + throws ExpressionParserException { C_IsNull nullIs = (C_IsNull) exp; IsNull isNull = new IsNull(parse(nullIs.getArgument())); return isNull; } - private Expression getIsNotNull(C_Expression exp) throws ExpressionParserException { + private Expression getIsNotNull(C_Expression exp) + throws ExpressionParserException { C_IsNotNull nullNotIs = (C_IsNotNull) exp; IsNotNull isNotNull = new IsNotNull(parse(nullNotIs.getArgument())); return isNotNull; } - private Expression getBetween(C_Expression exp) throws ExpressionParserException { + private Expression getBetween(C_Expression exp) + throws ExpressionParserException { C_Between bet = (C_Between) exp; C_Range crange = bet.getRightArgument(); Range range = new Range(getExpressionValue(crange.getMinimum()), @@ -291,7 +302,8 @@ public class C_ExpressionParser { return between; } - private Expression getAnd(C_Expression exp) throws ExpressionParserException { + private Expression getAnd(C_Expression exp) + throws ExpressionParserException { C_And o = (C_And) exp; List listCExp = o.getArguments(); List listExp = new ArrayList(); @@ -304,7 +316,8 @@ public class C_ExpressionParser { return and; } - private Expression getTextMatchSQLRegexp(C_Expression exp) throws ExpressionParserException { + private Expression getTextMatchSQLRegexp(C_Expression exp) + throws ExpressionParserException { C_TextMatchSQLRegexp reg = (C_TextMatchSQLRegexp) exp; TextMatchSQLRegexp regExp = new TextMatchSQLRegexp( 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; TextEndsWith textEndWith = new TextEndsWith( parse(textEnd.getLeftArgument()), @@ -320,7 +334,8 @@ public class C_ExpressionParser { return textEndWith; } - private Expression getTextContains(C_Expression exp) throws ExpressionParserException { + private Expression getTextContains(C_Expression exp) + throws ExpressionParserException { C_TextContains textContains = (C_TextContains) exp; TextContains textCont = new TextContains( parse(textContains.getLeftArgument()), @@ -328,42 +343,48 @@ public class C_ExpressionParser { return textCont; } - private Expression getTextBeginWith(C_Expression exp) throws ExpressionParserException { + private Expression getTextBeginWith(C_Expression exp) + throws ExpressionParserException { C_TextBeginsWith textB = (C_TextBeginsWith) exp; TextBeginsWith textBegins = new TextBeginsWith( parse(textB.getLeftArgument()), parse(textB.getRightArgument())); return textBegins; } - private Expression getNotLess(C_Expression exp) throws ExpressionParserException { + private Expression getNotLess(C_Expression exp) + throws ExpressionParserException { C_NotLess notL = (C_NotLess) exp; NotLess notLess = new NotLess(parse(notL.getLeftArgument()), parse(notL.getRightArgument())); return notLess; } - private Expression getNotGreater(C_Expression exp) throws ExpressionParserException { + private Expression getNotGreater(C_Expression exp) + throws ExpressionParserException { C_NotGreater notG = (C_NotGreater) exp; NotGreater notGreater = new NotGreater(parse(notG.getLeftArgument()), parse(notG.getRightArgument())); return notGreater; } - private Expression getNotEquals(C_Expression exp) throws ExpressionParserException { + private Expression getNotEquals(C_Expression exp) + throws ExpressionParserException { C_NotEquals notE = (C_NotEquals) exp; NotEquals notEquals = new NotEquals(parse(notE.getLeftArgument()), parse(notE.getRightArgument())); return notEquals; } - private Expression getLessThan(C_Expression exp) throws ExpressionParserException { + private Expression getLessThan(C_Expression exp) + throws ExpressionParserException { C_LessThan lessT = (C_LessThan) exp; LessThan lessThan = new LessThan(parse(lessT.getLeftArgument()), parse(lessT.getRightArgument())); return lessThan; } - private Expression getLessOrEquals(C_Expression exp)throws ExpressionParserException{ + private Expression getLessOrEquals(C_Expression exp) + throws ExpressionParserException { C_LessOrEquals lessOrE = (C_LessOrEquals) exp; LessOrEquals lessOrEquals = new LessOrEquals( parse(lessOrE.getLeftArgument()), @@ -371,7 +392,8 @@ public class C_ExpressionParser { return lessOrEquals; } - private Expression getGreaterThan(C_Expression exp) throws ExpressionParserException{ + private Expression getGreaterThan(C_Expression exp) + throws ExpressionParserException { C_GreaterThan greaterThan = (C_GreaterThan) exp; GreaterThan greater = new GreaterThan( 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; GreaterOrEquals greaterOrEquals = new GreaterOrEquals( 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 l = new ArrayList(); C_ConstantList c = (C_ConstantList) exp; List arguments = c.getArguments(); @@ -495,7 +519,8 @@ public class C_ExpressionParser { return constList; } - protected MultivaluedExpression getConstantlist(C_MultivaluedExpression exp) throws ExpressionParserException { + protected MultivaluedExpression getConstantlist(C_MultivaluedExpression exp) + throws ExpressionParserException { List l = new ArrayList(); C_ConstantList c = (C_ConstantList) exp; List arguments = c.getArguments(); @@ -515,14 +540,16 @@ public class C_ExpressionParser { return col; } - protected Expression getRange(C_Expression exp) throws ExpressionParserException { + protected Expression getRange(C_Expression exp) + throws ExpressionParserException { C_Range c = (C_Range) exp; Range range = new Range(getExpressionValue(c.getMinimum()), getExpressionValue(c.getMaximum())); return range; } - protected MultivaluedExpression getRange(C_MultivaluedExpression exp) throws ExpressionParserException { + protected MultivaluedExpression getRange(C_MultivaluedExpression exp) + throws ExpressionParserException { C_Range c = (C_Range) exp; Range range = new Range(getExpressionValue(c.getMinimum()), getExpressionValue(c.getMaximum())); @@ -545,7 +572,8 @@ public class C_ExpressionParser { return ref; } - protected Expression getEquals(C_Expression exp) throws ExpressionParserException { + protected Expression getEquals(C_Expression exp) + throws ExpressionParserException { C_Equals e = (C_Equals) exp; Expression left = parse(e.getLeftArgument()); Expression right = parse(e.getRightArgument()); @@ -553,14 +581,16 @@ public class C_ExpressionParser { return eq; } - private Expression getConcat(C_Expression exp) throws ExpressionParserException { + private Expression getConcat(C_Expression exp) + throws ExpressionParserException { C_Concat concat = (C_Concat) exp; Concat conc = new Concat(parse(concat.getLeftArgument()), parse(concat.getRightArgument())); return conc; } - private Expression getSubstringByIndex(C_Expression exp) throws ExpressionParserException { + private Expression getSubstringByIndex(C_Expression exp) + throws ExpressionParserException { C_SubstringByIndex subByIndex = (C_SubstringByIndex) exp; SubstringByIndex sByIndex = new SubstringByIndex( parse(subByIndex.getSourceString()), @@ -569,7 +599,8 @@ public class C_ExpressionParser { return sByIndex; } - private Expression getSubstringByRegex(C_Expression exp) throws ExpressionParserException { + private Expression getSubstringByRegex(C_Expression exp) + throws ExpressionParserException { C_SubstringByRegex subByRegex = (C_SubstringByRegex) exp; SubstringByRegex sByRegex = new SubstringByRegex( parse(subByRegex.getSourceString()), @@ -577,7 +608,8 @@ public class C_ExpressionParser { return sByRegex; } - private Expression getSubstringPosition(C_Expression exp) throws ExpressionParserException { + private Expression getSubstringPosition(C_Expression exp) + throws ExpressionParserException { C_SubstringPosition subPosition = (C_SubstringPosition) exp; SubstringPosition sPosition = new SubstringPosition( parse(subPosition.getLeftArgument()), @@ -585,7 +617,8 @@ public class C_ExpressionParser { return sPosition; } - private Expression getTextReplaceMatchingRegex(C_Expression exp) throws ExpressionParserException { + private Expression getTextReplaceMatchingRegex(C_Expression exp) + throws ExpressionParserException { C_TextReplaceMatchingRegex textReplaceMatchingRegex = (C_TextReplaceMatchingRegex) exp; TDText tdRegexp = new TDText(textReplaceMatchingRegex.getRegexp() .getValue()); @@ -598,40 +631,54 @@ public class C_ExpressionParser { return textRepRegex; } - private Expression getAvg(C_Expression exp) throws ExpressionParserException { + private Expression getAvg(C_Expression exp) + throws ExpressionParserException { C_Avg avg = (C_Avg) exp; Avg av = new Avg(parse(avg.getArgument())); return av; } - private Expression getCount(C_Expression exp)throws ExpressionParserException{ + private Expression getCount(C_Expression exp) + throws ExpressionParserException { C_Count count = (C_Count) exp; Count cnt = new Count(parse(count.getArgument())); return cnt; } - private Expression getMax(C_Expression exp) throws ExpressionParserException { + private Expression getMax(C_Expression exp) + throws ExpressionParserException { C_Max max = (C_Max) exp; Max ma = new Max(parse(max.getArgument())); return ma; } - private Expression getMin(C_Expression exp) throws ExpressionParserException { + private Expression getMin(C_Expression exp) + throws ExpressionParserException { C_Min min = (C_Min) exp; Min mi = new Min(parse(min.getArgument())); 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; ST_Extent stEx = new ST_Extent(parse(stExtent.getArgument())); return stEx; } - private Expression getSum(C_Expression exp) throws ExpressionParserException { + private Expression getSum(C_Expression exp) + throws ExpressionParserException { C_Sum sum = (C_Sum) exp; Sum sm = new Sum(parse(sum.getArgument())); 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; + } + } diff --git a/src/main/java/org/gcube/portlets/user/td/expressionwidget/shared/exception/ReplaceTypeMapException.java b/src/main/java/org/gcube/portlets/user/td/expressionwidget/shared/exception/ReplaceTypeMapException.java new file mode 100644 index 0000000..d120609 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/expressionwidget/shared/exception/ReplaceTypeMapException.java @@ -0,0 +1,34 @@ +package org.gcube.portlets.user.td.expressionwidget.shared.exception; + +/** + * + * @author giancarlo + * email: g.panichi@isti.cnr.it + * + */ +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); + } + + +} + diff --git a/src/main/java/org/gcube/portlets/user/td/expressionwidget/shared/model/C_OperatorType.java b/src/main/java/org/gcube/portlets/user/td/expressionwidget/shared/model/C_OperatorType.java index c6eda9f..8a36bd4 100644 --- a/src/main/java/org/gcube/portlets/user/td/expressionwidget/shared/model/C_OperatorType.java +++ b/src/main/java/org/gcube/portlets/user/td/expressionwidget/shared/model/C_OperatorType.java @@ -14,20 +14,21 @@ public enum C_OperatorType { // LOGICAL - ALL, AND, ANY, BETWEEN, NOT_BETWEEN, EXISTS, IN, NOT_IN, - LIKE, NOT_LIKE, NOT, OR, IS_NULL, UNIQUE, IS_NOT_NULL, + ALL, AND, ANY, BETWEEN, NOT_BETWEEN, EXISTS, IN, NOT_IN, LIKE, NOT_LIKE, NOT, OR, IS_NULL, UNIQUE, IS_NOT_NULL, // AGGREGATION AVG, COUNT, MAX, MIN, SUM, ST_EXTENT, - + // STRING BEGINS_WITH, ENDS_WITH, CONTAINS, MATCH_REGEX, - + NOT_BEGINS_WITH, NOT_ENDS_WITH, NOT_CONTAINS, NOT_MATCH_REGEX, - - CONCAT, SUBSTRING_BY_INDEX, SUBSTRING_BY_REGEX, - SUBSTRING_POSITION, TEXT_REPLACE_MATCHING_REGEX, + + CONCAT, SUBSTRING_BY_INDEX, SUBSTRING_BY_REGEX, SUBSTRING_POSITION, TEXT_REPLACE_MATCHING_REGEX, + + // FUNCTIONS + CAST, // COMPLEX diff --git a/src/main/java/org/gcube/portlets/user/td/expressionwidget/shared/model/composite/functions/C_Cast.java b/src/main/java/org/gcube/portlets/user/td/expressionwidget/shared/model/composite/functions/C_Cast.java new file mode 100644 index 0000000..cf19e66 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/expressionwidget/shared/model/composite/functions/C_Cast.java @@ -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" g.panichi@isti.cnr.it + * + */ +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; + } + +} diff --git a/src/main/java/org/gcube/portlets/user/td/expressionwidget/shared/replace/ReplaceTypeMap.java b/src/main/java/org/gcube/portlets/user/td/expressionwidget/shared/replace/ReplaceTypeMap.java index 9a9c5b9..da503e1 100644 --- a/src/main/java/org/gcube/portlets/user/td/expressionwidget/shared/replace/ReplaceTypeMap.java +++ b/src/main/java/org/gcube/portlets/user/td/expressionwidget/shared/replace/ReplaceTypeMap.java @@ -1,5 +1,7 @@ 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_SubstringByIndex; 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, - String firstArg, String secondArg) { - return map(column, replaceType,firstArg, secondArg, null, null, null, null); + String firstArg, String secondArg,boolean template) throws ReplaceTypeMapException { + return map(column, replaceType,firstArg, secondArg, template, null, null, null, null); } public C_Expression map(ColumnData column, ReplaceType replaceType, - String firstArg, String secondArg, C_Expression firstE, - C_Expression secondE, String readableFirstE, String readableSecondE) { + String firstArg, String secondArg, boolean template, C_Expression firstE, + C_Expression secondE, String readableFirstE, String readableSecondE) throws ReplaceTypeMapException { Log.debug("ReplaceTypeMap Map"); C_Expression exp = null; readableExpression = new String(); - if (column.getTrId() == null) { + if (template) { exp = mapPlaceHolder(column, replaceType, firstArg, secondArg, firstE, secondE, readableFirstE,readableSecondE); } else { @@ -52,17 +54,51 @@ public class ReplaceTypeMap { public C_Expression mapPlaceHolder(ColumnData column, 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"); 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()); ColumnDataType dataType = ColumnTypeMap.getColumnDataType(column .getDataTypeName()); Log.debug("Data Type:" + dataType); - C_ColumnReferencePlaceholder placeHolder = new C_ColumnReferencePlaceholder( + 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()+")"; + } else { + placeHolder=placeH; + readablePlaceHolder= column.getColumnId(); + + } Log.debug("placeHolder:" + placeHolder); - String readablePlaceHolder = column.getColumnId(); + TD_Value fArg, sArg; C_Expression posFrom, posTo; @@ -72,7 +108,8 @@ public class ReplaceTypeMap { readableExpression = "Null()"; break; case Value: - exp = new TD_Value(dataType, firstArg); + checkTypeArgument(ColumnDataType.Text,firstArg); + exp = new TD_Value(ColumnDataType.Text, firstArg); readableExpression = "Value(" + firstArg + ")"; break; case ColumnValue: @@ -85,12 +122,15 @@ public class ReplaceTypeMap { + ", " + readableSecondE + ")"; break; case SubstringByRegex: + checkTypeArgument(ColumnDataType.Text,firstArg); fArg = new TD_Value(ColumnDataType.Text, firstArg); exp = new C_SubstringByRegex(placeHolder, fArg); readableExpression = "SubStringByRegex(" + readablePlaceHolder + ", " + firstArg + ")"; 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); exp = new C_SubstringByIndex(placeHolder, fArg, sArg); @@ -98,8 +138,10 @@ public class ReplaceTypeMap { + ", " + firstArg + ", " + secondArg + ")"; break; case SubstringByCharSeq: + checkTypeArgument(ColumnDataType.Text,firstArg); fArg = new TD_Value(ColumnDataType.Text, firstArg); posFrom = new C_SubstringPosition(placeHolder, fArg); + checkTypeArgument(ColumnDataType.Text,secondArg); sArg = new TD_Value(ColumnDataType.Text, secondArg); posTo = new C_SubstringPosition(placeHolder, fArg); exp = new C_SubstringByIndex(placeHolder, posFrom, posTo); @@ -107,6 +149,8 @@ public class ReplaceTypeMap { + ", " + firstArg + ", " + secondArg + ")"; 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); exp = new C_TextReplaceMatchingRegex(placeHolder, fArg, sArg); @@ -121,19 +165,53 @@ public class ReplaceTypeMap { public C_Expression mapTypedColumnReference(ColumnData column, 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"); 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()); ColumnDataType dataType = ColumnTypeMap.getColumnDataType(column .getDataTypeName()); Log.debug("Data Type:" + dataType); - C_TypedColumnReference columnReference = new C_TypedColumnReference( + + C_TypedColumnReference columnRef = new C_TypedColumnReference( column.getTrId(), dataType, column.getColumnId()); - Log.debug("Typed Column Reference:" + columnReference); - String readableColumnReference = column.getLabel(); + + 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); + TD_Value fArg, sArg; C_Expression posFrom, posTo; @@ -143,7 +221,8 @@ public class ReplaceTypeMap { readableExpression = "Null()"; break; case Value: - exp = new TD_Value(dataType, firstArg); + checkTypeArgument(ColumnDataType.Text, firstArg); + exp = new TD_Value(ColumnDataType.Text, firstArg); readableExpression = "Value(" + firstArg + ")"; break; case ColumnValue: @@ -156,12 +235,15 @@ public class ReplaceTypeMap { + ", " + readableSecondE + ")"; break; case SubstringByRegex: + checkTypeArgument(ColumnDataType.Text, firstArg); fArg = new TD_Value(ColumnDataType.Text, firstArg); exp = new C_SubstringByRegex(columnReference, fArg); readableExpression = "SubStringByRegex(" + readableColumnReference + ", " + firstArg + ")"; 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); exp = new C_SubstringByIndex(columnReference, fArg, sArg); @@ -169,8 +251,10 @@ public class ReplaceTypeMap { + ", " + firstArg + ", " + secondArg + ")"; break; case SubstringByCharSeq: + checkTypeArgument(ColumnDataType.Text, firstArg); fArg = new TD_Value(ColumnDataType.Text, firstArg); posFrom = new C_SubstringPosition(columnReference, fArg); + checkTypeArgument(ColumnDataType.Text, secondArg); sArg = new TD_Value(ColumnDataType.Text, secondArg); posTo = new C_SubstringPosition(columnReference, fArg); exp = new C_SubstringByIndex(columnReference, posFrom, posTo); @@ -179,6 +263,8 @@ public class ReplaceTypeMap { + secondArg + ")"; 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); exp = new C_TextReplaceMatchingRegex(columnReference, fArg, sArg); @@ -195,5 +281,59 @@ public class ReplaceTypeMap { public String getReadableExpression() { 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 { + + } + } + } + } + } + + } + } + }