81: Allow the creation and use of expressions on multi column in TDM portlet

Task-Url: https://support.d4science.org/issues/81

Updated Rule on Table Creation

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-expression-widget@114806 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2015-05-19 16:53:26 +00:00
parent 1a1d110a35
commit 21cfb22d0c
16 changed files with 546 additions and 331 deletions

View File

@ -1,6 +1,7 @@
package org.gcube.portlets.user.td.expressionwidget.client;
import java.util.ArrayList;
import java.util.Date;
import org.gcube.portlets.user.td.expressionwidget.client.expression.ConditionWidget;
import org.gcube.portlets.user.td.expressionwidget.client.notification.ExpressionWrapperNotification;
@ -11,10 +12,10 @@ import org.gcube.portlets.user.td.expressionwidget.client.store.ColumnDataTypeEl
import org.gcube.portlets.user.td.expressionwidget.client.store.ColumnDataTypeStore;
import org.gcube.portlets.user.td.expressionwidget.shared.exception.ConditionTypeMapException;
import org.gcube.portlets.user.td.expressionwidget.shared.model.logical.C_Not;
import org.gcube.portlets.user.td.gwtservice.shared.rule.RuleDescriptionData;
import org.gcube.portlets.user.td.gwtservice.shared.rule.RuleScopeType;
import org.gcube.portlets.user.td.gwtservice.shared.rule.description.RuleDescriptionData;
import org.gcube.portlets.user.td.gwtservice.shared.rule.type.TDBaseColumnRuleType;
import org.gcube.portlets.user.td.gwtservice.shared.rule.type.TDRuleColumnType;
import org.gcube.portlets.user.td.gwtservice.shared.rule.type.TDRuleType;
import org.gcube.portlets.user.td.monitorwidget.client.utils.UtilsGXT3;
import org.gcube.portlets.user.td.widgetcommonevent.client.expression.C_ExpressionContainer;
import org.gcube.portlets.user.td.widgetcommonevent.client.expression.ExpressionWrapper;
@ -28,6 +29,7 @@ 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.i18n.client.DateTimeFormat;
import com.google.gwt.user.client.ui.HTML;
import com.google.web.bindery.event.shared.EventBus;
import com.sencha.gxt.cell.core.client.ButtonCell.IconAlign;
@ -61,14 +63,14 @@ import com.sencha.gxt.widget.core.client.info.Info;
public class ColumnExpressionPanel extends FramedPanel {
private static final String RULE_DESCRIPTION_HEIGHT = "44px";
private static final String RULE_PLACE_HOLDER_ID = "Column";
private enum ColumnExpressionPanelType {
ColumnFilter, RowDeleteByExpression, Template, Rule;
}
private static final String WIDTH = "658px";
private static final String HEIGHT = "364px";
private static final String RULE_HEIGHT = "388px";
private DateTimeFormat sdf = DateTimeFormat.getFormat("yyyy-MM-dd HH:mm");
private enum ColumnExpressionPanelType {
ColumnFilter, RowDeleteByExpression, Template, RuleOnColumn;
}
private ColumnExpressionPanelType type;
@ -85,7 +87,7 @@ public class ColumnExpressionPanel extends FramedPanel {
private FieldSet conditionsField;
private ConditionWidget conditionWidget;
private ComboBox<ColumnData> comboCols;
private RuleDialog parentRuleDialog;
private RuleOnColumnCreateDialog parentRuleOnColumnCreateDialog;
private RuleDescriptionData initialRuleDescriptionData;
@ -96,9 +98,6 @@ public class ColumnExpressionPanel extends FramedPanel {
private FieldLabel comboDataTypeLabel;
/**
*
* @param parentFilterDialog
@ -163,30 +162,16 @@ public class ColumnExpressionPanel extends FramedPanel {
/**
*
* @param parentRuleDialog
* @param parent
* @param eventBus
*/
public ColumnExpressionPanel(RuleDialog parentRuleDialog, EventBus eventBus) {
public ColumnExpressionPanel(RuleOnColumnCreateDialog parent,
EventBus eventBus) {
super();
setWidth(WIDTH);
setHeight(HEIGHT);
type = ColumnExpressionPanelType.Rule;
this.parentRuleDialog = parentRuleDialog;
this.column = null;
this.columns = null;
Log.debug("Column:" + column);
createOnRule();
}
public ColumnExpressionPanel(RuleDialog parentRuleDialog,
RuleDescriptionData ruleDescriptionData, EventBus eventBus) {
super();
setWidth(WIDTH);
setHeight(HEIGHT);
type = ColumnExpressionPanelType.Rule;
this.parentRuleDialog = parentRuleDialog;
this.initialRuleDescriptionData = ruleDescriptionData;
type = ColumnExpressionPanelType.RuleOnColumn;
this.parentRuleOnColumnCreateDialog = parent;
this.column = null;
this.columns = null;
Log.debug("Column:" + column);
@ -290,7 +275,6 @@ public class ColumnExpressionPanel extends FramedPanel {
FieldLabel ruleDescriptionLabel = new FieldLabel(ruleDescription,
"Rule Description");
// comboDataType
ColumnDataTypeProperties propsDataType = GWT
.create(ColumnDataTypeProperties.class);
@ -298,8 +282,8 @@ public class ColumnExpressionPanel extends FramedPanel {
propsDataType.id());
storeComboDataType.addAll(ColumnDataTypeStore.getAttributeType());
comboDataType = new ComboBox<ColumnDataTypeElement>(
storeComboDataType, propsDataType.label());
comboDataType = new ComboBox<ColumnDataTypeElement>(storeComboDataType,
propsDataType.label());
Log.trace("ComboDataType created");
addHandlersForComboAttributeType(propsDataType.label());
@ -326,24 +310,21 @@ public class ColumnExpressionPanel extends FramedPanel {
}
}
comboDataTypeLabel = new FieldLabel(comboDataType,
"Data Type");
comboDataTypeLabel = new FieldLabel(comboDataType, "Data Type");
propertiesLayout.add(ruleNameLabel, new VerticalLayoutData(1, -1,
new Margins(0)));
propertiesLayout.add(ruleDescriptionLabel, new VerticalLayoutData(1,
-1, new Margins(0)));
propertiesLayout.add(comboDataTypeLabel, new VerticalLayoutData(1,
-1, new Margins(0)));
propertiesLayout.add(comboDataTypeLabel, new VerticalLayoutData(1, -1,
new Margins(0)));
}
private ColumnDataType retrieveColumnDataType() {
TDRuleColumnType tdRuleColumnType = initialRuleDescriptionData
.getTdRuleColumnType();
TDRuleType tdRuleColumnType = initialRuleDescriptionData
.getTdRuleType();
if (tdRuleColumnType instanceof TDBaseColumnRuleType) {
TDBaseColumnRuleType tdBaseColumnRuleType = (TDBaseColumnRuleType) tdRuleColumnType;
return tdBaseColumnRuleType.getColumnDataType();
@ -353,7 +334,6 @@ public class ColumnExpressionPanel extends FramedPanel {
}
protected void addHandlersForComboAttributeType(
final LabelProvider<ColumnDataTypeElement> labelProvider) {
comboDataType
@ -377,7 +357,6 @@ public class ColumnExpressionPanel extends FramedPanel {
});
}
protected void updateCondition() {
ColumnMockUp columnMockUp = retrieveColumnMockUp();
if (columnMockUp != null) {
@ -394,8 +373,6 @@ public class ColumnExpressionPanel extends FramedPanel {
forceLayout();
}
protected ColumnMockUp retrieveColumnMockUp() {
ColumnMockUp columnMockUp = null;
@ -466,8 +443,8 @@ public class ColumnExpressionPanel extends FramedPanel {
columnMockUp.getColumnDataType());
RuleDescriptionData ruleDescriptionData = new RuleDescriptionData(
0, ruleNameS, ruleDescriptionS, null, null,
RuleScopeType.COLUMN, tdBaseColumnRule, exp);
0, ruleNameS, ruleDescriptionS, sdf.format(new Date()),
null, null, RuleScopeType.COLUMN, exp, tdBaseColumnRule);
return ruleDescriptionData;
} else {
UtilsGXT3.alert("Attention", "Enter a valid condition!");
@ -478,8 +455,6 @@ public class ColumnExpressionPanel extends FramedPanel {
}
}
protected void updateDataType(ColumnDataType type) {
Log.debug("Update ColumnDataType: " + type);
updateCondition();
@ -930,7 +905,7 @@ public class ColumnExpressionPanel extends FramedPanel {
Log.debug("Notification: " + expressionWrapperNotification);
parentTemplateDialog.onExpression(expressionWrapperNotification);
break;
case Rule:
case RuleOnColumn:
if (!conditionWidget.isEnabled()) {
UtilsGXT3.alert("Attention", "Fill all field!");
return;
@ -944,7 +919,7 @@ public class ColumnExpressionPanel extends FramedPanel {
}
RuleDescriptionData ruleDescriptionData = retrieveRuleDescriptionData(exp);
if (ruleDescriptionData != null) {
parentRuleDialog.addRule(ruleDescriptionData);
parentRuleOnColumnCreateDialog.addRule(ruleDescriptionData);
}
break;
case ColumnFilter:
@ -970,7 +945,7 @@ public class ColumnExpressionPanel extends FramedPanel {
notExp);
break;
default:
break;
}
@ -982,8 +957,8 @@ public class ColumnExpressionPanel extends FramedPanel {
case Template:
parentTemplateDialog.close();
break;
case Rule:
parentRuleDialog.close();
case RuleOnColumn:
parentRuleOnColumnCreateDialog.close();
break;
case ColumnFilter:
parentFilterDialog.close();

View File

@ -1,6 +1,7 @@
package org.gcube.portlets.user.td.expressionwidget.client;
import java.util.ArrayList;
import java.util.Date;
import org.gcube.portlets.user.td.expressionwidget.client.expression.ConditionOnMultiColumnWidget;
import org.gcube.portlets.user.td.expressionwidget.client.notification.ExpressionWrapperNotification;
@ -10,10 +11,9 @@ import org.gcube.portlets.user.td.expressionwidget.client.store.ColumnDataTypeEl
import org.gcube.portlets.user.td.expressionwidget.client.store.ColumnDataTypeStore;
import org.gcube.portlets.user.td.expressionwidget.shared.exception.ConditionTypeMapException;
import org.gcube.portlets.user.td.expressionwidget.shared.model.logical.C_Not;
import org.gcube.portlets.user.td.gwtservice.shared.rule.RuleDescriptionData;
import org.gcube.portlets.user.td.gwtservice.shared.rule.RuleScopeType;
import org.gcube.portlets.user.td.gwtservice.shared.rule.type.TDBaseColumnRuleType;
import org.gcube.portlets.user.td.gwtservice.shared.rule.type.TDRuleColumnType;
import org.gcube.portlets.user.td.gwtservice.shared.rule.description.RuleDescriptionData;
import org.gcube.portlets.user.td.gwtservice.shared.rule.type.TDRuleType;
import org.gcube.portlets.user.td.monitorwidget.client.utils.UtilsGXT3;
import org.gcube.portlets.user.td.widgetcommonevent.client.expression.C_ExpressionContainer;
import org.gcube.portlets.user.td.widgetcommonevent.client.expression.ExpressionWrapper;
@ -27,6 +27,7 @@ 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.i18n.client.DateTimeFormat;
import com.google.gwt.user.client.ui.HTML;
import com.google.web.bindery.event.shared.EventBus;
import com.sencha.gxt.cell.core.client.ButtonCell.IconAlign;
@ -64,8 +65,10 @@ public class MultiColumnExpressionPanel extends FramedPanel {
private static final String RULE_DESCRIPTION_HEIGHT = "44px";
private static final String RULE_PLACE_HOLDER_ID = "Column";
private DateTimeFormat sdf = DateTimeFormat.getFormat("yyyy-MM-dd HH:mm");
private enum MultiColumnExpressionPanelType {
ColumnFilter, RowDeleteByExpression, Template, Rule;
ColumnFilter, RowDeleteByExpression, Template, RuleOnTable;
}
@ -85,7 +88,7 @@ public class MultiColumnExpressionPanel extends FramedPanel {
private FieldSet conditionsField;
private ConditionOnMultiColumnWidget conditionWidget;
private ComboBox<ColumnData> comboCols;
private RuleDialog parentRuleDialog;
private RuleOnTableCreateDialog parentRuleOnTableCreateDialog;
private RuleDescriptionData initialRuleDescriptionData;
@ -95,6 +98,7 @@ public class MultiColumnExpressionPanel extends FramedPanel {
private ComboBox<ColumnDataTypeElement> comboDataType;
private FieldLabel comboDataTypeLabel;
//private RuleDescriptionData ruleDescriptionData;
@ -102,7 +106,7 @@ public class MultiColumnExpressionPanel extends FramedPanel {
/**
*
* @param parent
* @param column
* @param columncreateOnRule
* @param columns
* @param eventBus
*/
@ -159,30 +163,17 @@ public class MultiColumnExpressionPanel extends FramedPanel {
* @param parent
* @param eventBus
*/
public MultiColumnExpressionPanel(RuleDialog parent, EventBus eventBus) {
public MultiColumnExpressionPanel(RuleOnTableCreateDialog parent, RuleDescriptionData initialRuleDescriptionData, EventBus eventBus) {
super();
setWidth(WIDTH);
setHeight(HEIGHT);
type = MultiColumnExpressionPanelType.Rule;
this.parentRuleDialog = parent;
type = MultiColumnExpressionPanelType.RuleOnTable;
this.parentRuleOnTableCreateDialog = parent;
this.initialRuleDescriptionData=initialRuleDescriptionData;
this.columns = null;
createOnRule();
}
public MultiColumnExpressionPanel(RuleDialog parentRuleDialog,
RuleDescriptionData ruleDescriptionData, EventBus eventBus) {
super();
setWidth(WIDTH);
setHeight(HEIGHT);
type = MultiColumnExpressionPanelType.Rule;
this.parentRuleDialog = parentRuleDialog;
this.initialRuleDescriptionData = ruleDescriptionData;
this.column = null;
this.columns = null;
Log.debug("Column:" + column);
createOnRule();
}
protected void createOnRule() {
forceLayoutOnResize = true;
@ -320,13 +311,9 @@ public class MultiColumnExpressionPanel extends FramedPanel {
}
private ColumnDataType retrieveColumnDataType() {
TDRuleColumnType tdRuleColumnType = initialRuleDescriptionData
.getTdRuleColumnType();
if (tdRuleColumnType instanceof TDBaseColumnRuleType) {
TDBaseColumnRuleType tdBaseColumnRuleType = (TDBaseColumnRuleType) tdRuleColumnType;
return tdBaseColumnRuleType.getColumnDataType();
}
TDRuleType tdRuleTableType = initialRuleDescriptionData
.getTdRuleType();
return null;
}
@ -440,12 +427,10 @@ public class MultiColumnExpressionPanel extends FramedPanel {
if (exp != null) {
String ruleNameS = ruleName.getCurrentValue();
String ruleDescriptionS = ruleDescription.getCurrentValue();
TDBaseColumnRuleType tdBaseColumnRule = new TDBaseColumnRuleType(
columnMockUp.getColumnDataType());
//TODO
RuleDescriptionData ruleDescriptionData = new RuleDescriptionData(
0, ruleNameS, ruleDescriptionS, null, null,
RuleScopeType.COLUMN, tdBaseColumnRule, exp);
0, ruleNameS, ruleDescriptionS, sdf.format(new Date()), null, null,
RuleScopeType.TABLE, exp,initialRuleDescriptionData.getTdRuleType());
return ruleDescriptionData;
} else {
UtilsGXT3.alert("Attention", "Enter a valid condition!");
@ -740,7 +725,7 @@ public class MultiColumnExpressionPanel extends FramedPanel {
Log.debug("Apply: "+expressionWrapperNotification);
parentTemplateDialog.onExpression(expressionWrapperNotification);
break;
case Rule:
case RuleOnTable:
if (!conditionWidget.isEnabled()) {
UtilsGXT3.alert("Attention", "Fill all field!");
return;
@ -754,7 +739,7 @@ public class MultiColumnExpressionPanel extends FramedPanel {
}
RuleDescriptionData ruleDescriptionData = retrieveRuleDescriptionData(exp);
if (ruleDescriptionData != null) {
parentRuleDialog.addRule(ruleDescriptionData);
parentRuleOnTableCreateDialog.addRule(ruleDescriptionData);
}
break;
case ColumnFilter:
@ -794,8 +779,8 @@ public class MultiColumnExpressionPanel extends FramedPanel {
case Template:
parentTemplateDialog.close();
break;
case Rule:
parentRuleDialog.close();
case RuleOnTable:
parentRuleOnTableCreateDialog.close();
break;
case ColumnFilter:
parentMultiFilterDialog.close();

View File

@ -9,7 +9,7 @@ import org.gcube.portlets.user.td.expressionwidget.client.resources.ExpressionRe
import org.gcube.portlets.user.td.expressionwidget.client.rpc.ExpressionServiceAsync;
import org.gcube.portlets.user.td.expressionwidget.client.utils.UtilsGXT3;
import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTSessionExpiredException;
import org.gcube.portlets.user.td.gwtservice.shared.rule.RuleDescriptionData;
import org.gcube.portlets.user.td.gwtservice.shared.rule.description.RuleDescriptionData;
import org.gcube.portlets.user.td.widgetcommonevent.client.event.SessionExpiredEvent;
import org.gcube.portlets.user.td.widgetcommonevent.client.type.SessionExpiredType;

View File

@ -2,7 +2,7 @@ package org.gcube.portlets.user.td.expressionwidget.client;
import org.gcube.portlets.user.td.expressionwidget.client.resources.ExpressionResources;
import org.gcube.portlets.user.td.expressionwidget.client.utils.UtilsGXT3;
import org.gcube.portlets.user.td.gwtservice.shared.rule.RuleDescriptionData;
import org.gcube.portlets.user.td.gwtservice.shared.rule.description.RuleDescriptionData;
import com.allen_sauer.gwt.log.client.Log;
import com.google.web.bindery.event.shared.EventBus;

View File

@ -9,7 +9,7 @@ import org.gcube.portlets.user.td.expressionwidget.client.resources.ExpressionRe
import org.gcube.portlets.user.td.expressionwidget.client.rpc.ExpressionServiceAsync;
import org.gcube.portlets.user.td.expressionwidget.client.utils.UtilsGXT3;
import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTSessionExpiredException;
import org.gcube.portlets.user.td.gwtservice.shared.rule.RuleDescriptionData;
import org.gcube.portlets.user.td.gwtservice.shared.rule.description.RuleDescriptionData;
import org.gcube.portlets.user.td.widgetcommonevent.client.event.SessionExpiredEvent;
import org.gcube.portlets.user.td.widgetcommonevent.client.type.SessionExpiredType;
@ -26,7 +26,7 @@ import com.sencha.gxt.widget.core.client.event.SelectEvent.SelectHandler;
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class RuleDialog extends Window implements
public class RuleOnColumnCreateDialog extends Window implements
HasRuleDialogNotificationListener {
private static final String WIDTH = "670px";
private static final String HEIGHT = "460px";
@ -40,7 +40,7 @@ public class RuleDialog extends Window implements
* @param columnMockUp
* @param eventBus
*/
public RuleDialog(EventBus eventBus) {
public RuleOnColumnCreateDialog(EventBus eventBus) {
listeners = new ArrayList<RuleDialogNotificationListener>();
initWindow();
this.eventBus = eventBus;
@ -49,17 +49,6 @@ public class RuleDialog extends Window implements
}
public RuleDialog(RuleDescriptionData ruleDescriptionData, EventBus eventBus) {
listeners = new ArrayList<RuleDialogNotificationListener>();
initWindow();
this.eventBus = eventBus;
this.initialRuleDescriptionData = ruleDescriptionData;
columnExpressionPanel = new ColumnExpressionPanel(this,
ruleDescriptionData, eventBus);
add(columnExpressionPanel);
}
protected void initWindow() {
setWidth(WIDTH);
setHeight(HEIGHT);
@ -103,8 +92,8 @@ public class RuleDialog extends Window implements
}
public void saveColumnRule(RuleDescriptionData ruleDescriptionData) {
ExpressionServiceAsync.INSTANCE.saveColumnRule(ruleDescriptionData,
ExpressionServiceAsync.INSTANCE.saveRule(ruleDescriptionData,
new AsyncCallback<String>() {
@Override
@ -121,10 +110,10 @@ public class RuleDialog extends Window implements
eventBus.fireEvent(new SessionExpiredEvent(
SessionExpiredType.EXPIREDONSERVER));
} else {
Log.error("Error saving column rule: "
Log.error("Error saving rule on column: "
+ caught.getLocalizedMessage());
caught.printStackTrace();
UtilsGXT3.alert("Error saving column rule",
UtilsGXT3.alert("Error saving rule on column",
caught.getLocalizedMessage());
fireFailed(caught);

View File

@ -0,0 +1,174 @@
package org.gcube.portlets.user.td.expressionwidget.client;
import java.util.ArrayList;
import org.gcube.portlets.user.td.expressionwidget.client.notification.RuleDialogNotification;
import org.gcube.portlets.user.td.expressionwidget.client.notification.RuleDialogNotification.HasRuleDialogNotificationListener;
import org.gcube.portlets.user.td.expressionwidget.client.notification.RuleDialogNotification.RuleDialogNotificationListener;
import org.gcube.portlets.user.td.expressionwidget.client.resources.ExpressionResources;
import org.gcube.portlets.user.td.expressionwidget.client.rpc.ExpressionServiceAsync;
import org.gcube.portlets.user.td.expressionwidget.client.utils.UtilsGXT3;
import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTSessionExpiredException;
import org.gcube.portlets.user.td.gwtservice.shared.rule.description.RuleDescriptionData;
import org.gcube.portlets.user.td.widgetcommonevent.client.event.SessionExpiredEvent;
import org.gcube.portlets.user.td.widgetcommonevent.client.type.SessionExpiredType;
import com.allen_sauer.gwt.log.client.Log;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.web.bindery.event.shared.EventBus;
import com.sencha.gxt.widget.core.client.Window;
import com.sencha.gxt.widget.core.client.event.SelectEvent;
import com.sencha.gxt.widget.core.client.event.SelectEvent.SelectHandler;
/**
*
* @author "Giancarlo Panichi" <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class RuleOnTableCreateDialog extends Window implements
HasRuleDialogNotificationListener {
private static final String WIDTH = "940px";
private static final String HEIGHT = "388px";
private MultiColumnExpressionPanel multiColumnExpressionPanel;
private EventBus eventBus;
private ArrayList<RuleDialogNotificationListener> listeners;
private Object initialRuleDescriptionData;
/**
*
* @param columnMockUp
* @param eventBus
*/
public RuleOnTableCreateDialog(RuleDescriptionData ruleDescriptionData, EventBus eventBus) {
listeners = new ArrayList<RuleDialogNotificationListener>();
initWindow();
this.eventBus = eventBus;
this.initialRuleDescriptionData=ruleDescriptionData;
multiColumnExpressionPanel = new MultiColumnExpressionPanel(this, ruleDescriptionData,eventBus);
add(multiColumnExpressionPanel);
}
protected void initWindow() {
setWidth(WIDTH);
setHeight(HEIGHT);
setBodyBorder(false);
setResizable(false);
setHeadingText("New Rule On Column");
setClosable(true);
setModal(true);
forceLayoutOnResize = true;
getHeader().setIcon(ExpressionResources.INSTANCE.ruleColumnAdd());
}
/**
* {@inheritDoc}
*/
@Override
protected void initTools() {
super.initTools();
closeBtn.addSelectHandler(new SelectHandler() {
public void onSelect(SelectEvent event) {
close();
}
});
}
protected void close() {
fireAborted();
}
public void addRule(RuleDescriptionData ruleDescriptionData) {
Log.debug("RuleDescriptionData: " + ruleDescriptionData);
if (initialRuleDescriptionData == null) {
saveColumnRule(ruleDescriptionData);
} else {
updateColumnRule(ruleDescriptionData);
}
}
public void saveColumnRule(RuleDescriptionData ruleDescriptionData) {
ExpressionServiceAsync.INSTANCE.saveRule(ruleDescriptionData,
new AsyncCallback<String>() {
@Override
public void onSuccess(String ruleId) {
Log.debug("Saved Rule: " + ruleId);
UtilsGXT3.info("Save Rule", "The rule is saved!");
fireNotification(ruleId);
}
@Override
public void onFailure(Throwable caught) {
if (caught instanceof TDGWTSessionExpiredException) {
eventBus.fireEvent(new SessionExpiredEvent(
SessionExpiredType.EXPIREDONSERVER));
} else {
Log.error("Error saving column rule: "
+ caught.getLocalizedMessage());
caught.printStackTrace();
UtilsGXT3.alert("Error saving column rule",
caught.getLocalizedMessage());
fireFailed(caught);
}
}
});
}
private void updateColumnRule(RuleDescriptionData ruleDescriptionData) {
fireAborted();
}
@Override
public void addRuleDialogNotificationListener(
RuleDialogNotificationListener handler) {
listeners.add(handler);
}
@Override
public void removeRuleDialogNotificationListener(
RuleDialogNotificationListener handler) {
listeners.remove(handler);
}
private void fireNotification(String ruleId) {
if (listeners != null) {
for (RuleDialogNotificationListener listener : listeners) {
listener.onNotification(new RuleDialogNotification(ruleId));
}
}
hide();
}
private void fireAborted() {
if (listeners != null) {
for (RuleDialogNotificationListener listener : listeners) {
listener.aborted();
}
}
hide();
}
private void fireFailed(Throwable caught) {
if (listeners != null) {
for (RuleDialogNotificationListener listener : listeners) {
listener.failed(caught);
}
}
hide();
}
}

View File

@ -0,0 +1,28 @@
package org.gcube.portlets.user.td.expressionwidget.client.properties;
import org.gcube.portlets.user.td.gwtservice.shared.rule.RuleColumnPlaceHolderDescriptor;
import org.gcube.portlets.user.td.widgetcommonevent.shared.tr.column.ColumnDataType;
import com.google.gwt.editor.client.Editor.Path;
import com.sencha.gxt.core.client.ValueProvider;
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 RuleColumnPlaceHolderDescriptorProperties extends
PropertyAccess<RuleColumnPlaceHolderDescriptor> {
@Path("id")
ModelKeyProvider<RuleColumnPlaceHolderDescriptor> id();
ValueProvider<RuleColumnPlaceHolderDescriptor,String> label();
ValueProvider<RuleColumnPlaceHolderDescriptor,ColumnDataType> columnDataType();
}

View File

@ -8,9 +8,9 @@ import java.util.ArrayList;
import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTServiceException;
import org.gcube.portlets.user.td.gwtservice.shared.rule.AppliedRulesResponseData;
import org.gcube.portlets.user.td.gwtservice.shared.rule.DetachColumnRulesSession;
import org.gcube.portlets.user.td.gwtservice.shared.rule.RuleDescriptionData;
import org.gcube.portlets.user.td.gwtservice.shared.rule.RuleScopeType;
import org.gcube.portlets.user.td.gwtservice.shared.rule.ApplyAndDetachColumnRulesSession;
import org.gcube.portlets.user.td.gwtservice.shared.rule.description.RuleDescriptionData;
import org.gcube.portlets.user.td.gwtservice.shared.tr.column.AddColumnSession;
import org.gcube.portlets.user.td.gwtservice.shared.tr.column.FilterColumnSession;
import org.gcube.portlets.user.td.gwtservice.shared.tr.column.ReplaceColumnByExpressionSession;
@ -63,9 +63,9 @@ public interface ExpressionService extends RemoteService {
public ArrayList<RuleDescriptionData> getApplicableBaseColumnRules(
ColumnData columnData) throws TDGWTServiceException;
public String saveColumnRule(RuleDescriptionData ruleDescriptionData)
public String saveRule(RuleDescriptionData ruleDescriptionData)
throws TDGWTServiceException;
public void updateColumnRule(RuleDescriptionData ruleDescriptionData)
throws TDGWTServiceException;

View File

@ -8,8 +8,8 @@ import java.util.ArrayList;
import org.gcube.portlets.user.td.gwtservice.shared.rule.AppliedRulesResponseData;
import org.gcube.portlets.user.td.gwtservice.shared.rule.ApplyAndDetachColumnRulesSession;
import org.gcube.portlets.user.td.gwtservice.shared.rule.DetachColumnRulesSession;
import org.gcube.portlets.user.td.gwtservice.shared.rule.RuleDescriptionData;
import org.gcube.portlets.user.td.gwtservice.shared.rule.RuleScopeType;
import org.gcube.portlets.user.td.gwtservice.shared.rule.description.RuleDescriptionData;
import org.gcube.portlets.user.td.gwtservice.shared.tr.column.AddColumnSession;
import org.gcube.portlets.user.td.gwtservice.shared.tr.column.FilterColumnSession;
import org.gcube.portlets.user.td.gwtservice.shared.tr.column.ReplaceColumnByExpressionSession;
@ -49,9 +49,10 @@ public interface ExpressionServiceAsync {
void getApplicableBaseColumnRules(ColumnData columnData,
AsyncCallback<ArrayList<RuleDescriptionData>> callback);
void saveColumnRule(RuleDescriptionData ruleDescriptionData,
void saveRule(RuleDescriptionData ruleDescriptionData,
AsyncCallback<String> callback);
void updateColumnRule(RuleDescriptionData ruleDescriptionData,
AsyncCallback<Void> callback);

View File

@ -7,6 +7,7 @@ import javax.servlet.http.HttpSession;
import org.gcube.application.framework.core.session.ASLSession;
import org.gcube.data.analysis.tabulardata.commons.rules.types.RuleColumnType;
import org.gcube.data.analysis.tabulardata.commons.rules.types.RuleType;
import org.gcube.data.analysis.tabulardata.commons.utils.AuthorizationProvider;
import org.gcube.data.analysis.tabulardata.commons.utils.AuthorizationToken;
import org.gcube.data.analysis.tabulardata.commons.webservice.types.AppliedRulesResponse;
@ -19,9 +20,9 @@ import org.gcube.data.analysis.tabulardata.service.rules.RuleId;
import org.gcube.data.analysis.tabulardata.service.tabular.TabularResourceId;
import org.gcube.portlets.user.td.expressionwidget.client.rpc.ExpressionService;
import org.gcube.portlets.user.td.expressionwidget.server.service.rule.AppliedRulesResponseMap;
import org.gcube.portlets.user.td.expressionwidget.server.service.rule.RuleColumnTypeMap;
import org.gcube.portlets.user.td.expressionwidget.server.service.rule.RuleDescriptionMap;
import org.gcube.portlets.user.td.expressionwidget.server.service.rule.RuleScopeMap;
import org.gcube.portlets.user.td.expressionwidget.server.service.rule.RuleTypeMap;
import org.gcube.portlets.user.td.expressionwidget.shared.exception.ExpressionParserException;
import org.gcube.portlets.user.td.expressionwidget.shared.exception.ExpressionServiceException;
import org.gcube.portlets.user.td.gwtservice.server.SessionUtil;
@ -31,8 +32,8 @@ import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTServiceExcept
import org.gcube.portlets.user.td.gwtservice.shared.rule.AppliedRulesResponseData;
import org.gcube.portlets.user.td.gwtservice.shared.rule.ApplyAndDetachColumnRulesSession;
import org.gcube.portlets.user.td.gwtservice.shared.rule.DetachColumnRulesSession;
import org.gcube.portlets.user.td.gwtservice.shared.rule.RuleDescriptionData;
import org.gcube.portlets.user.td.gwtservice.shared.rule.RuleScopeType;
import org.gcube.portlets.user.td.gwtservice.shared.rule.description.RuleDescriptionData;
import org.gcube.portlets.user.td.gwtservice.shared.tr.column.AddColumnSession;
import org.gcube.portlets.user.td.gwtservice.shared.tr.column.FilterColumnSession;
import org.gcube.portlets.user.td.gwtservice.shared.tr.column.ReplaceColumnByExpressionSession;
@ -56,12 +57,11 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements
private static final long serialVersionUID = 4632292751581364137L;
private static Logger logger = LoggerFactory
.getLogger(ExpressionServiceImpl.class);
//private static SimpleDateFormat sdf = new SimpleDateFormat(
// "yyyy-MM-dd HH:mm");
// private static SimpleDateFormat sdf = new SimpleDateFormat(
// "yyyy-MM-dd HH:mm");
/**
*
@ -237,8 +237,9 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements
TabularDataService service = TabularDataServiceFactory.getService();
List<RuleDescription> rules = service.getRules();
logger.debug("Service Rules: "+((rules==null)?"null":rules.size()));
logger.debug("Service Rules: "
+ ((rules == null) ? "null" : rules.size()));
ArrayList<RuleDescriptionData> rulesDes = new ArrayList<RuleDescriptionData>();
for (RuleDescription ruleDescription : rules) {
@ -247,8 +248,8 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements
logger.debug("Rule: " + ruleData);
rulesDes.add(ruleData);
}
logger.debug("Rules: "+rulesDes.size());
logger.debug("Rules: " + rulesDes.size());
return rulesDes;
} catch (TDGWTServiceException e) {
@ -266,9 +267,7 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements
}
}
/**
*
* {@inheritDoc}
@ -280,15 +279,16 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements
HttpSession session = this.getThreadLocalRequest().getSession();
ASLSession aslSession = SessionUtil.getAslSession(session);
logger.debug("GetRules(): "+scope);
logger.debug("GetRules(): " + scope);
AuthorizationProvider.instance.set(new AuthorizationToken(
aslSession.getUsername(), aslSession.getScope()));
TabularDataService service = TabularDataServiceFactory.getService();
List<RuleDescription> rules = service.getRulesByScope(RuleScopeMap
.map(scope));
logger.debug("Service Rules: "+((rules==null)?"null":rules.size()));
logger.debug("Service Rules: "
+ ((rules == null) ? "null" : rules.size()));
ArrayList<RuleDescriptionData> rulesDes = new ArrayList<RuleDescriptionData>();
for (RuleDescription ruleDescription : rules) {
@ -298,7 +298,7 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements
rulesDes.add(ruleData);
}
logger.debug("Rules: "+rulesDes.size());
logger.debug("Rules: " + rulesDes.size());
return rulesDes;
} catch (TDGWTServiceException e) {
@ -363,7 +363,7 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements
rulesDes.add(ruleData);
}
logger.debug("Rules: "+rulesDes.size());
logger.debug("Rules: " + rulesDes.size());
return rulesDes;
} catch (TDGWTServiceException e) {
@ -382,8 +382,7 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements
}
}
/**
*
* {@inheritDoc}
@ -445,13 +444,14 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements
* {@inheritDoc}
*/
@Override
public String saveColumnRule(RuleDescriptionData ruleDescriptionData)
public String saveRule(
RuleDescriptionData ruleDescriptionData)
throws TDGWTServiceException {
try {
HttpSession session = this.getThreadLocalRequest().getSession();
ASLSession aslSession = SessionUtil.getAslSession(session);
logger.debug("SaveColumnRule() :" + ruleDescriptionData);
logger.debug("SaveRule() :" + ruleDescriptionData);
AuthorizationProvider.instance.set(new AuthorizationToken(
aslSession.getUsername(), aslSession.getScope()));
TabularDataService service = TabularDataServiceFactory.getService();
@ -469,25 +469,32 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements
logger.debug("Service Condition Expression:" + conditionExpression);
RuleColumnType ruleColumnType = RuleColumnTypeMap
.map(ruleDescriptionData.getTdRuleColumnType());
if (ruleColumnType == null) {
logger.debug("Error saving rule: rule column type is null!");
RuleType ruleType = RuleTypeMap
.map(ruleDescriptionData.getTdRuleType());
if (ruleType == null) {
throw new TDGWTServiceException(
"Error saving rule: rule column type is null!");
"Error saving rule, rule type is null!");
}
RuleId ruleId = service.saveColumnRule(
if (!(RuleColumnType.class.isAssignableFrom(ruleType.getClass()))){
throw new TDGWTServiceException(
"Error saving rule, rule type is not RuleColumnType!");
}
//TODO
/*RuleId ruleId = null;
service.saveRule(
ruleDescriptionData.getName(),
ruleDescriptionData.getDescription(), conditionExpression,
ruleColumnType);
ruleDescriptionData.getDescription(),
conditionExpression, ruleType);
logger.debug("RuleId: " + ruleId);
*/
String ruleIdent = null;
if (ruleId != null) {
/*if (ruleId != null) {
ruleIdent = String.valueOf(ruleId.getValue());
}
}*/
return ruleIdent;
@ -499,15 +506,16 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements
e.printStackTrace();
throw e;
} catch (Throwable e) {
logger.error("Error in getRule(): " + e.getLocalizedMessage());
logger.error("Error in save rule: "
+ e.getLocalizedMessage());
e.printStackTrace();
throw new TDGWTServiceException("Error retrieving the rules: "
throw new TDGWTServiceException("Error in save rule: "
+ e.getLocalizedMessage());
}
}
/**
*
* {@inheritDoc}
@ -523,16 +531,17 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements
AuthorizationProvider.instance.set(new AuthorizationToken(
aslSession.getUsername(), aslSession.getScope()));
TabularDataService service = TabularDataServiceFactory.getService();
RuleDescription ruleDescription=RuleDescriptionMap.map(ruleDescriptionData);
if(ruleDescription==null){
RuleDescription ruleDescription = RuleDescriptionMap
.map(ruleDescriptionData);
if (ruleDescription == null) {
logger.error("Error in rule description: null!");
throw new TDGWTServiceException("Error in rule description: null!");
throw new TDGWTServiceException(
"Error in rule description: null!");
}
service.updateColumnRule(
ruleDescription);
service.updateColumnRule(ruleDescription);
logger.debug("Rule updated");
@ -554,8 +563,6 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements
}
/**
*
* {@inheritDoc}
@ -610,8 +617,8 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements
throws TDGWTServiceException {
try {
HttpSession session = this.getThreadLocalRequest().getSession();
String taskId = startApplyAndDetachColumnnRules(applyAndDetachColumnRulesSession,
session);
String taskId = startApplyAndDetachColumnnRules(
applyAndDetachColumnRulesSession, session);
return taskId;
} catch (TDGWTServiceException e) {
@ -622,7 +629,7 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements
}
}
/**
*
* {@inheritDoc}
@ -633,10 +640,9 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements
throws TDGWTServiceException {
try {
HttpSession session = this.getThreadLocalRequest().getSession();
setDetachColumnnRules(detachColumnRulesSession,
session);
setDetachColumnnRules(detachColumnRulesSession, session);
return;
} catch (TDGWTServiceException e) {
throw e;
} catch (Throwable e) {
@ -645,9 +651,5 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements
}
}
}

View File

@ -10,7 +10,7 @@ import org.gcube.data.analysis.tabulardata.commons.webservice.types.RuleDescript
import org.gcube.portlets.user.td.expressionwidget.shared.exception.ExpressionParserException;
import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTServiceException;
import org.gcube.portlets.user.td.gwtservice.shared.rule.AppliedRulesResponseData;
import org.gcube.portlets.user.td.gwtservice.shared.rule.RuleDescriptionData;
import org.gcube.portlets.user.td.gwtservice.shared.rule.description.RuleDescriptionData;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

View File

@ -1,95 +0,0 @@
package org.gcube.portlets.user.td.expressionwidget.server.service.rule;
import org.gcube.data.analysis.tabulardata.commons.rules.types.BaseColumnRuleType;
import org.gcube.data.analysis.tabulardata.commons.rules.types.DimensionColumnRuleType;
import org.gcube.data.analysis.tabulardata.commons.rules.types.RuleColumnType;
import org.gcube.data.analysis.tabulardata.commons.utils.DimensionReference;
import org.gcube.data.analysis.tabulardata.model.column.ColumnLocalId;
import org.gcube.data.analysis.tabulardata.model.table.TableId;
import org.gcube.portlets.user.td.gwtservice.server.trservice.ColumnDataTypeMap;
import org.gcube.portlets.user.td.gwtservice.shared.rule.type.TDBaseColumnRuleType;
import org.gcube.portlets.user.td.gwtservice.shared.rule.type.TDDimensionColumnRuleType;
import org.gcube.portlets.user.td.gwtservice.shared.rule.type.TDRuleColumnType;
import org.gcube.portlets.user.td.widgetcommonevent.shared.tr.column.DimensionReferenceData;
/**
*
* @author giancarlo
* email: <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class RuleColumnTypeMap {
public static RuleColumnType map(TDRuleColumnType tdRuleColumnType) {
if (tdRuleColumnType == null) {
return null;
}
if (tdRuleColumnType instanceof TDBaseColumnRuleType) {
TDBaseColumnRuleType tdBaseColumnRuleType = (TDBaseColumnRuleType) tdRuleColumnType;
BaseColumnRuleType baseColumnRuleType = new BaseColumnRuleType(
ColumnDataTypeMap.map(tdBaseColumnRuleType
.getColumnDataType()));
return baseColumnRuleType;
}
if (tdRuleColumnType instanceof TDDimensionColumnRuleType) {
TDDimensionColumnRuleType tdDimensionColumnRuleType = (TDDimensionColumnRuleType) tdRuleColumnType;
TableId tableId = new TableId(
Long.valueOf(tdDimensionColumnRuleType
.getDimensionReferenceData().getTableId()));
ColumnLocalId columnId = new ColumnLocalId(
tdDimensionColumnRuleType.getDimensionReferenceData()
.getColumnId());
DimensionReference dimensionReference = new DimensionReference(
tableId, columnId);
DimensionColumnRuleType dimensionColumnRuleType = new DimensionColumnRuleType(
dimensionReference);
return dimensionColumnRuleType;
}
return null;
}
public static TDRuleColumnType map(RuleColumnType ruleColumnType) {
if (ruleColumnType == null) {
return null;
}
if (ruleColumnType instanceof BaseColumnRuleType) {
BaseColumnRuleType baseColumnRuleType = (BaseColumnRuleType) ruleColumnType;
TDBaseColumnRuleType tdBaseColumnRuleType = new TDBaseColumnRuleType(
ColumnDataTypeMap.map(baseColumnRuleType
.getInternalType()));
return tdBaseColumnRuleType;
}
if (ruleColumnType instanceof DimensionColumnRuleType) {
DimensionColumnRuleType dimensionColumnRuleType = (DimensionColumnRuleType) ruleColumnType;
DimensionReference dimensionReference=(DimensionReference)dimensionColumnRuleType.getInternalType();
DimensionReferenceData dimensionReferenceData = new DimensionReferenceData(
String.valueOf(dimensionReference.getTableId().getValue()), dimensionReference.getColumnId().getValue());
TDDimensionColumnRuleType tdDimensionColumnRuleType = new TDDimensionColumnRuleType(
dimensionReferenceData);
return tdDimensionColumnRuleType;
}
return null;
}
}

View File

@ -1,16 +1,20 @@
package org.gcube.portlets.user.td.expressionwidget.server.service.rule;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
import org.gcube.data.analysis.tabulardata.commons.rules.types.RuleColumnType;
import org.gcube.data.analysis.tabulardata.commons.rules.types.RuleType;
import org.gcube.data.analysis.tabulardata.commons.webservice.types.RuleDescription;
import org.gcube.data.analysis.tabulardata.expression.Expression;
import org.gcube.portlets.user.td.expressionwidget.server.C_ExpressionParser;
import org.gcube.portlets.user.td.expressionwidget.shared.exception.ExpressionParserException;
import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTServiceException;
import org.gcube.portlets.user.td.gwtservice.shared.rule.RuleDescriptionData;
import org.gcube.portlets.user.td.gwtservice.shared.rule.type.TDRuleColumnType;
import org.gcube.portlets.user.td.gwtservice.shared.rule.description.RuleDescriptionData;
import org.gcube.portlets.user.td.gwtservice.shared.rule.type.TDRuleType;
import org.gcube.portlets.user.td.gwtservice.shared.share.Contacts;
import org.gcube.portlets.user.td.widgetcommonevent.shared.expression.C_Expression;
import org.slf4j.Logger;
@ -26,6 +30,9 @@ public class RuleDescriptionMap {
private static final Logger logger = LoggerFactory
.getLogger(RuleDescriptionMap.class);
private static SimpleDateFormat sdf = new SimpleDateFormat(
"yyyy-MM-dd HH:mm");
private static final String SECURITY_EXCEPTION_RIGHTS = "Security exception, you don't have the required rights!";
public static RuleDescriptionData map(RuleDescription ruleDescription)
@ -42,27 +49,14 @@ public class RuleDescriptionMap {
throw new TDGWTServiceException("Rule description has scope null");
}
switch (ruleDescription.getScope()) {
case COLUMN:
ruleDescriptionData = createColumnRuleDescriptionData(ruleDescription);
break;
case TABLE:
ruleDescriptionData = createTableRuleDescriptionData(ruleDescription);
break;
default:
break;
}
ruleDescriptionData = createRuleDescriptionData(ruleDescription);
return ruleDescriptionData;
}
private static RuleDescriptionData createTableRuleDescriptionData(
RuleDescription ruleDescription) {
return null;
}
private static RuleDescriptionData createColumnRuleDescriptionData(
private static RuleDescriptionData createRuleDescriptionData(
RuleDescription ruleDescription) throws ExpressionParserException,
TDGWTServiceException {
@ -71,17 +65,27 @@ public class RuleDescriptionMap {
C_ExpressionParser parser = new C_ExpressionParser();
C_Expression cexp = parser.parse(serviceExpression);
TDRuleColumnType tdRuleColumnType = RuleColumnTypeMap
.map(ruleDescription.getRuleColumnType());
RuleType ruleType = ruleDescription.getRuleType();
TDRuleType tdRuleType = RuleTypeMap.map(ruleType);
Contacts owner = new Contacts("", ruleDescription.getOwner(), false);
ArrayList<Contacts> contacts = retrieveRuleShareInfo(ruleDescription);
String creationDate="";
try{
creationDate = sdf.format(ruleDescription.getCreationDate());
} catch(IllegalArgumentException e){
logger.error("Error in rule description, creation date is not valid!"+
ruleDescription.getCreationDate());
throw new TDGWTServiceException(
"Error in rule description, creation date is not valid!");
}
RuleDescriptionData ruleData = new RuleDescriptionData(
ruleDescription.getId(), ruleDescription.getName(),
ruleDescription.getDescription(), owner, contacts,
RuleScopeMap.map(ruleDescription.getScope()), tdRuleColumnType,
cexp);
ruleDescription.getDescription(), creationDate, owner,
contacts, RuleScopeMap.map(ruleDescription.getScope()), cexp,
tdRuleType);
return ruleData;
}
@ -135,21 +139,12 @@ public class RuleDescriptionMap {
throw new TDGWTServiceException("Rule description has scope null");
}
switch (ruleDescriptionData.getScope()) {
case COLUMN:
ruleDescription = createColumnRuleDescription(ruleDescriptionData);
break;
case TABLE:
ruleDescription = createTableRuleDescription(ruleDescriptionData);
break;
default:
break;
}
ruleDescription = createRuleDescription(ruleDescriptionData);
return ruleDescription;
}
private static RuleDescription createColumnRuleDescription(
private static RuleDescription createRuleDescription(
RuleDescriptionData ruleDescriptionData)
throws TDGWTServiceException {
@ -160,34 +155,43 @@ public class RuleDescriptionMap {
conditionExpression = parser.parse(ruleDescriptionData
.getExpression());
} catch (ExpressionParserException e) {
logger.debug(e.getLocalizedMessage());
logger.error(e.getLocalizedMessage());
throw new TDGWTServiceException(e.getLocalizedMessage());
}
logger.debug("Service Condition Expression:" + conditionExpression);
RuleColumnType ruleColumnType = RuleColumnTypeMap
.map(ruleDescriptionData.getTdRuleColumnType());
if (ruleColumnType == null) {
logger.debug("Error saving rule: rule column type is null!");
RuleType ruleType = RuleTypeMap
.map(ruleDescriptionData.getTdRuleType());
if (ruleType == null) {
logger.error("Error saving rule, rule column type is null!");
throw new TDGWTServiceException(
"Error saving rule: rule column type is null!");
"Error saving rule, rule column type is null!");
}
RuleDescription ruleDescription=new RuleDescription(ruleDescriptionData.getId(),
ruleDescriptionData.getName(),
ruleDescriptionData.getDescription(), conditionExpression,RuleScopeMap.map(ruleDescriptionData.getScope()),
ruleDescriptionData.getOwnerLogin(),
ruleColumnType,
ruleDescriptionData.getContactsAsStringList());
Date cDate;
try {
cDate = sdf.parse(ruleDescriptionData.getCreationDate());
} catch (ParseException e) {
logger.error("Error saving rule, creation date is not valid: "
+ ruleDescriptionData.getCreationDate());
throw new TDGWTServiceException(
"Error saving rule, creation date is not valid: "
+ ruleDescriptionData.getCreationDate());
}
GregorianCalendar creationDate = new GregorianCalendar();
creationDate.setTime(cDate);
RuleDescription ruleDescription = new RuleDescription(
ruleDescriptionData.getId(), ruleDescriptionData.getName(),
ruleDescriptionData.getDescription(), creationDate,
conditionExpression, RuleScopeMap.map(ruleDescriptionData
.getScope()), ruleDescriptionData.getOwnerLogin(),
ruleType, ruleDescriptionData.getContactsAsStringList());
return ruleDescription;
}
private static RuleDescription createTableRuleDescription(
RuleDescriptionData ruleDescriptionData) {
return null;
}
}

View File

@ -0,0 +1,152 @@
package org.gcube.portlets.user.td.expressionwidget.server.service.rule;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import org.gcube.data.analysis.tabulardata.commons.rules.types.BaseColumnRuleType;
import org.gcube.data.analysis.tabulardata.commons.rules.types.DimensionColumnRuleType;
import org.gcube.data.analysis.tabulardata.commons.rules.types.RuleColumnType;
import org.gcube.data.analysis.tabulardata.commons.rules.types.RuleTableType;
import org.gcube.data.analysis.tabulardata.commons.rules.types.RuleType;
import org.gcube.data.analysis.tabulardata.commons.utils.DimensionReference;
import org.gcube.data.analysis.tabulardata.model.column.ColumnLocalId;
import org.gcube.data.analysis.tabulardata.model.datatype.DataType;
import org.gcube.data.analysis.tabulardata.model.table.TableId;
import org.gcube.portlets.user.td.gwtservice.server.trservice.ColumnDataTypeMap;
import org.gcube.portlets.user.td.gwtservice.shared.rule.RuleColumnPlaceHolderDescriptor;
import org.gcube.portlets.user.td.gwtservice.shared.rule.type.TDBaseColumnRuleType;
import org.gcube.portlets.user.td.gwtservice.shared.rule.type.TDDimensionColumnRuleType;
import org.gcube.portlets.user.td.gwtservice.shared.rule.type.TDRuleColumnType;
import org.gcube.portlets.user.td.gwtservice.shared.rule.type.TDRuleTableType;
import org.gcube.portlets.user.td.gwtservice.shared.rule.type.TDRuleType;
import org.gcube.portlets.user.td.widgetcommonevent.shared.tr.column.ColumnDataType;
import org.gcube.portlets.user.td.widgetcommonevent.shared.tr.column.DimensionReferenceData;
/**
*
* @author giancarlo email: <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class RuleTypeMap {
public static RuleType map(TDRuleType tdRuleType) {
if (tdRuleType == null) {
return null;
}
if (TDRuleColumnType.class.isAssignableFrom(tdRuleType.getClass())) {
if (tdRuleType instanceof TDBaseColumnRuleType) {
TDBaseColumnRuleType tdBaseColumnRuleType = (TDBaseColumnRuleType) tdRuleType;
BaseColumnRuleType baseColumnRuleType = new BaseColumnRuleType(
ColumnDataTypeMap.map(tdBaseColumnRuleType
.getColumnDataType()));
return baseColumnRuleType;
}
if (tdRuleType instanceof TDDimensionColumnRuleType) {
TDDimensionColumnRuleType tdDimensionColumnRuleType = (TDDimensionColumnRuleType) tdRuleType;
TableId tableId = new TableId(
Long.valueOf(tdDimensionColumnRuleType
.getDimensionReferenceData().getTableId()));
ColumnLocalId columnId = new ColumnLocalId(
tdDimensionColumnRuleType.getDimensionReferenceData()
.getColumnId());
DimensionReference dimensionReference = new DimensionReference(
tableId, columnId);
DimensionColumnRuleType dimensionColumnRuleType = new DimensionColumnRuleType(
dimensionReference);
return dimensionColumnRuleType;
}
} else {
if (tdRuleType instanceof TDRuleTableType) {
TDRuleTableType tdRuleTableType = (TDRuleTableType) tdRuleType;
Map<String, Class<? extends DataType>> ruleColumnPlaceHolderDescriptorMap =
new HashMap<String, Class<? extends DataType>>();
ArrayList<RuleColumnPlaceHolderDescriptor> descriptors = tdRuleTableType.getRuleColumnPlaceHolderDescriptors();
for (RuleColumnPlaceHolderDescriptor ruleColumnPlaceHolderDescriptor:descriptors) {
Class<? extends DataType> dataType=ColumnDataTypeMap.mapToDataTypeClass(ruleColumnPlaceHolderDescriptor.getColumnDataType());
ruleColumnPlaceHolderDescriptorMap.put(ruleColumnPlaceHolderDescriptor.getId(), dataType);
}
RuleTableType ruleTableType = new RuleTableType(
ruleColumnPlaceHolderDescriptorMap);
return ruleTableType;
}
}
return null;
}
public static TDRuleType map(RuleType ruleType) {
if (ruleType == null) {
return null;
}
if (RuleColumnType.class.isAssignableFrom(ruleType.getClass())) {
if (ruleType instanceof BaseColumnRuleType) {
BaseColumnRuleType baseColumnRuleType = (BaseColumnRuleType) ruleType;
TDBaseColumnRuleType tdBaseColumnRuleType = new TDBaseColumnRuleType(
ColumnDataTypeMap.map(baseColumnRuleType
.getInternalType()));
return tdBaseColumnRuleType;
}
if (ruleType instanceof DimensionColumnRuleType) {
DimensionColumnRuleType dimensionColumnRuleType = (DimensionColumnRuleType) ruleType;
DimensionReference dimensionReference = (DimensionReference) dimensionColumnRuleType
.getInternalType();
DimensionReferenceData dimensionReferenceData = new DimensionReferenceData(
String.valueOf(dimensionReference.getTableId()
.getValue()), dimensionReference.getColumnId()
.getValue());
TDDimensionColumnRuleType tdDimensionColumnRuleType = new TDDimensionColumnRuleType(
dimensionReferenceData);
return tdDimensionColumnRuleType;
}
} else {
if (ruleType instanceof RuleTableType) {
RuleTableType ruleTableType = (RuleTableType) ruleType;
Map<String, Class<? extends DataType>> ruleColumnPlaceHolderDescriptorMap = ruleTableType
.getInternalType();
ArrayList<RuleColumnPlaceHolderDescriptor> descriptors = new ArrayList<RuleColumnPlaceHolderDescriptor>();
for (Map.Entry<String, Class<? extends DataType>> entry : ruleColumnPlaceHolderDescriptorMap
.entrySet()) {
String id = entry.getKey();
Class<? extends DataType> dataType = entry.getValue();
ColumnDataType columnDataType = ColumnDataTypeMap
.mapFromDataTypeClass(dataType);
RuleColumnPlaceHolderDescriptor ruleColumnPlaceHolderDescriptor = new RuleColumnPlaceHolderDescriptor(
id, columnDataType);
descriptors.add(ruleColumnPlaceHolderDescriptor);
}
TDRuleTableType tdRuleTableType = new TDRuleTableType(
descriptors);
return tdRuleTableType;
}
}
return null;
}
}

View File

@ -4,7 +4,7 @@ package org.gcube.portlets.user.td.expressionwidget.shared.rule;
import org.gcube.portlets.user.td.gwtservice.shared.rule.RuleDescriptionData;
import org.gcube.portlets.user.td.gwtservice.shared.rule.description.RuleDescriptionData;
import com.google.gwt.editor.client.Editor.Path;
import com.sencha.gxt.core.client.ValueProvider;

View File

@ -1,6 +1,6 @@
package org.gcube.portlets.user.td.expressionwidget.shared.rule;
import org.gcube.portlets.user.td.gwtservice.shared.rule.RuleDescriptionData;
import org.gcube.portlets.user.td.gwtservice.shared.rule.description.RuleDescriptionData;
import com.google.gwt.editor.client.Editor.Path;
import com.sencha.gxt.core.client.ValueProvider;