From b4e626cfc44ce97f458d3cc8944f9fa76d674b61 Mon Sep 17 00:00:00 2001 From: Giancarlo Panichi Date: Tue, 14 Apr 2015 13:13:58 +0000 Subject: [PATCH] Updated Rule git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-expression-widget@114026 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../client/ColumnExpressionPanel.java | 331 +++++++++++------- .../expressionwidget/client/RuleDialog.java | 6 +- .../client/rpc/ExpressionService.java | 9 + .../client/rpc/ExpressionServiceAsync.java | 9 + .../server/ExpressionServiceImpl.java | 146 +++++--- .../shared/rule/RuleDescriptionData.java | 9 + .../rule/RuleDescriptionDataProperties.java | 29 ++ 7 files changed, 363 insertions(+), 176 deletions(-) create mode 100644 src/main/java/org/gcube/portlets/user/td/expressionwidget/shared/rule/RuleDescriptionDataProperties.java diff --git a/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/ColumnExpressionPanel.java b/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/ColumnExpressionPanel.java index aca85c6..3a8a340 100644 --- a/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/ColumnExpressionPanel.java +++ b/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/ColumnExpressionPanel.java @@ -14,6 +14,8 @@ import org.gcube.portlets.user.td.expressionwidget.client.store.ColumnTypeCodeSt import org.gcube.portlets.user.td.expressionwidget.client.store.LocaleTypeElement; 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.expressionwidget.shared.rule.RuleDescriptionData; +import org.gcube.portlets.user.td.expressionwidget.shared.rule.RuleScopeType; 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; @@ -36,8 +38,6 @@ import com.google.gwt.core.client.Scheduler; import com.google.gwt.core.client.Scheduler.ScheduledCommand; import com.google.gwt.event.logical.shared.SelectionEvent; import com.google.gwt.event.logical.shared.SelectionHandler; -import com.google.gwt.event.logical.shared.ValueChangeEvent; -import com.google.gwt.event.logical.shared.ValueChangeHandler; import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.ui.HTML; import com.google.web.bindery.event.shared.EventBus; @@ -69,6 +69,8 @@ import com.sencha.gxt.widget.core.client.info.Info; * */ public class ColumnExpressionPanel extends FramedPanel { + private static final String RULE_PLACE_HOLDER_ID = "RulePlaceHolderId"; + private enum ColumnExpressionPanelType { MultiColumnFilter, ColumnFilter, RowDeleteByExpression, Template, Rule; } @@ -98,7 +100,9 @@ public class ColumnExpressionPanel extends FramedPanel { private ComboBox comboCols; private RuleDialog parentRuleDialog; - private TextField columnTag; + private TextField ruleName; + private TextField ruleDescription; + private ComboBox comboColumnTypeCode; private ComboBox comboMeasureType; private ComboBox comboAttributeType; @@ -108,7 +112,6 @@ public class ColumnExpressionPanel extends FramedPanel { private FieldLabel comboLocaleTypeLabel; private FieldLabel comboAttributeTypeLabel; private FieldLabel comboMeasureTypeLabel; - /** * @@ -291,20 +294,14 @@ public class ColumnExpressionPanel extends FramedPanel { // TODO private void createColumnMockUp(VerticalLayoutContainer propertiesLayout) { - columnTag = new TextField(); - columnTag.setToolTip("Column Label"); - columnTag.addValueChangeHandler(new ValueChangeHandler() { - - @Override - public void onValueChange(ValueChangeEvent event) { - updateColumnTag(event.getValue()); - - } + ruleName = new TextField(); + ruleName.setToolTip("Rule Name"); + FieldLabel ruleNameLabel = new FieldLabel(ruleName, "Rule Name"); - - }); - - FieldLabel columnLabel = new FieldLabel(columnTag, "Column Label"); + ruleDescription = new TextField(); + ruleDescription.setToolTip("Rule Description"); + FieldLabel ruleDescriptionLabel = new FieldLabel(ruleDescription, + "Rule Description"); // combo TypeCode ColumnTypeCodeProperties propsColumnTypeCode = GWT @@ -324,9 +321,10 @@ public class ColumnExpressionPanel extends FramedPanel { comboColumnTypeCode.setWidth(191); comboColumnTypeCode.setTypeAhead(true); comboColumnTypeCode.setTriggerAction(TriggerAction.ALL); - - comboColumnTypeCodeLabel=new FieldLabel(comboColumnTypeCode, "Column Type"); - + + comboColumnTypeCodeLabel = new FieldLabel(comboColumnTypeCode, + "Column Type"); + // comboMeasureType ColumnDataTypeProperties propsMeasureType = GWT .create(ColumnDataTypeProperties.class); @@ -397,11 +395,12 @@ public class ColumnExpressionPanel extends FramedPanel { comboLocaleTypeLabel = new FieldLabel(comboLocaleType, "Locale"); - propertiesLayout.add(columnLabel, new VerticalLayoutData(1, -1, + propertiesLayout.add(ruleNameLabel, new VerticalLayoutData(1, -1, new Margins(0))); - propertiesLayout.add( - comboColumnTypeCodeLabel, - new VerticalLayoutData(1, -1, new Margins(0))); + propertiesLayout.add(ruleDescriptionLabel, new VerticalLayoutData(1, + -1, new Margins(0))); + propertiesLayout.add(comboColumnTypeCodeLabel, new VerticalLayoutData( + 1, -1, new Margins(0))); propertiesLayout.add(comboLocaleTypeLabel, new VerticalLayoutData(1, -1, new Margins(0))); propertiesLayout.add(comboMeasureTypeLabel, new VerticalLayoutData(1, @@ -409,7 +408,6 @@ public class ColumnExpressionPanel extends FramedPanel { propertiesLayout.add(comboAttributeTypeLabel, new VerticalLayoutData(1, -1, new Margins(0))); - comboColumnTypeCodeLabel.setVisible(false); comboMeasureTypeLabel.setVisible(false); comboAttributeTypeLabel.setVisible(false); comboLocaleTypeLabel.setVisible(false); @@ -506,31 +504,6 @@ public class ColumnExpressionPanel extends FramedPanel { }); } - - protected void updateColumnTag(String value) { - if(value==null|| value.isEmpty()){ - comboColumnTypeCodeLabel.setVisible(false); - comboMeasureTypeLabel.setVisible(false); - comboAttributeTypeLabel.setVisible(false); - comboLocaleTypeLabel.setVisible(false); - - } else { - comboColumnTypeCodeLabel.setVisible(true); - comboMeasureTypeLabel.setVisible(false); - comboAttributeTypeLabel.setVisible(false); - comboLocaleTypeLabel.setVisible(false); - - } - - comboColumnTypeCode.reset(); - comboMeasureType.reset(); - comboAttributeType.reset(); - comboLocaleType.reset(); - updateCondition(); - forceLayout(); - - } - protected void updateColumnType(ColumnTypeCode type) { Log.debug("Update ColumnTypeCode " + type.toString()); @@ -558,7 +531,7 @@ public class ColumnExpressionPanel extends FramedPanel { comboAttributeTypeLabel.setVisible(false); break; } - + updateCondition(); forceLayout(); } @@ -582,88 +555,197 @@ public class ColumnExpressionPanel extends FramedPanel { protected ColumnMockUp retrieveColumnMockUp() { ColumnMockUp columnMockUp = null; - String labelS = columnTag.getCurrentValue(); - - if (labelS != null && !labelS.isEmpty()) { - ColumnTypeCodeElement columnTypeCodeElement = comboColumnTypeCode - .getCurrentValue(); - if (columnTypeCodeElement != null) { - ColumnTypeCode type = columnTypeCodeElement.getCode(); - ColumnDataTypeElement columnDataTypeElement; - switch (type) { - case MEASURE: - columnDataTypeElement = comboMeasureType.getCurrentValue(); - if (columnDataTypeElement != null) { - ColumnDataType dataType = columnDataTypeElement - .getType(); - if (dataType != null) { - columnMockUp = new ColumnMockUp(null, labelS, - labelS, type, dataType, ""); - } else { - - } - + ColumnTypeCodeElement columnTypeCodeElement = comboColumnTypeCode + .getCurrentValue(); + if (columnTypeCodeElement != null) { + ColumnTypeCode type = columnTypeCodeElement.getCode(); + ColumnDataTypeElement columnDataTypeElement; + switch (type) { + case MEASURE: + columnDataTypeElement = comboMeasureType.getCurrentValue(); + if (columnDataTypeElement != null) { + ColumnDataType dataType = columnDataTypeElement.getType(); + if (dataType != null) { + columnMockUp = new ColumnMockUp(null, + RULE_PLACE_HOLDER_ID, RULE_PLACE_HOLDER_ID, + type, dataType, ""); } else { - - } - break; - case ATTRIBUTE: - columnDataTypeElement = comboAttributeType - .getCurrentValue(); - if (columnDataTypeElement != null) { - ColumnDataType dataType = columnDataTypeElement - .getType(); - if (dataType != null) { - columnMockUp = new ColumnMockUp(null, labelS, - labelS, type, dataType, ""); - } else { - } - } else { - } - break; - case CODE: - case CODEDESCRIPTION: - case ANNOTATION: - columnMockUp = new ColumnMockUp(null, labelS, labelS, type, - ""); - break; - case CODENAME: - LocaleTypeElement locale = comboLocaleType - .getCurrentValue(); - if (locale != null) { - columnMockUp = new ColumnMockUp(null, labelS, labelS, - type, locale.getLocaleName(), ""); + } else { - } else { - - } - break; - default: - break; } - } else { - + break; + case ATTRIBUTE: + columnDataTypeElement = comboAttributeType.getCurrentValue(); + if (columnDataTypeElement != null) { + ColumnDataType dataType = columnDataTypeElement.getType(); + if (dataType != null) { + columnMockUp = new ColumnMockUp(null, + RULE_PLACE_HOLDER_ID, RULE_PLACE_HOLDER_ID, + type, dataType, ""); + + } else { + } + } else { + + } + break; + case CODE: + case CODEDESCRIPTION: + case ANNOTATION: + columnMockUp = new ColumnMockUp(null, RULE_PLACE_HOLDER_ID, + RULE_PLACE_HOLDER_ID, type, ""); + break; + + case CODENAME: + LocaleTypeElement locale = comboLocaleType.getCurrentValue(); + if (locale != null) { + columnMockUp = new ColumnMockUp(null, RULE_PLACE_HOLDER_ID, + RULE_PLACE_HOLDER_ID, type, locale.getLocaleName(), + ""); + + } else { + + } + break; + default: + break; } } else { - + } return columnMockUp; } + protected ColumnMockUp checkEnterData() { + ColumnMockUp columnMockUp = null; + + String ruleNameS = ruleName.getCurrentValue(); + + if (ruleNameS != null && !ruleNameS.isEmpty()) { + + String ruleDescriptionS = ruleDescription.getCurrentValue(); + + if (ruleDescriptionS != null && !ruleDescriptionS.isEmpty()) { + ColumnTypeCodeElement columnTypeCodeElement = comboColumnTypeCode + .getCurrentValue(); + if (columnTypeCodeElement != null) { + ColumnTypeCode type = columnTypeCodeElement.getCode(); + ColumnDataTypeElement columnDataTypeElement; + switch (type) { + case MEASURE: + columnDataTypeElement = comboMeasureType + .getCurrentValue(); + if (columnDataTypeElement != null) { + ColumnDataType dataType = columnDataTypeElement + .getType(); + if (dataType != null) { + columnMockUp = new ColumnMockUp(null, + RULE_PLACE_HOLDER_ID, + RULE_PLACE_HOLDER_ID, type, dataType, + ""); + } else { + UtilsGXT3.alert("Attention", + "Column data type not selected!"); + } + + } else { + UtilsGXT3.alert("Attention", + "Column data type not selected!"); + } + break; + case ATTRIBUTE: + columnDataTypeElement = comboAttributeType + .getCurrentValue(); + if (columnDataTypeElement != null) { + ColumnDataType dataType = columnDataTypeElement + .getType(); + if (dataType != null) { + columnMockUp = new ColumnMockUp(null, + RULE_PLACE_HOLDER_ID, + RULE_PLACE_HOLDER_ID, type, dataType, + ""); + + } else { + UtilsGXT3.alert("Attention", + "Column data type not selected!"); + } + } else { + UtilsGXT3.alert("Attention", + "Column data type not selected!"); + } + break; + case CODE: + case CODEDESCRIPTION: + case ANNOTATION: + columnMockUp = new ColumnMockUp(null, + RULE_PLACE_HOLDER_ID, RULE_PLACE_HOLDER_ID, + type, ""); + break; + + case CODENAME: + LocaleTypeElement locale = comboLocaleType + .getCurrentValue(); + if (locale != null) { + columnMockUp = new ColumnMockUp(null, + RULE_PLACE_HOLDER_ID, RULE_PLACE_HOLDER_ID, + type, locale.getLocaleName(), ""); + + } else { + UtilsGXT3.alert("Attention", "No locale selected!"); + } + break; + + default: + UtilsGXT3.alert("Attention", + "This column type is not supported now!"); + break; + } + } else { + UtilsGXT3.alert("Attention", "Select a column type!"); + } + } else { + UtilsGXT3.alert("Attention", + "Enter a valid description for the rule!"); + } + } else { + UtilsGXT3.alert("Attention", "Enter a valid name for the rule!"); + } + return columnMockUp; + + } + + protected RuleDescriptionData retrieveRuleDescriptionData(C_Expression exp) { + ColumnMockUp columnMockUp = checkEnterData(); + if (columnMockUp != null) { + if(exp!=null){ + + String ruleNameS = ruleName.getCurrentValue(); + String ruleDescriptionS = ruleDescription.getCurrentValue(); + RuleDescriptionData ruleDescriptionData = new RuleDescriptionData( + 0, ruleNameS, ruleDescriptionS, RuleScopeType.COLUMN, exp); + return ruleDescriptionData; + } else { + UtilsGXT3.alert("Attention", "Enter a valid condition!"); + return null; + } + } else { + return null; + } + } + protected void updateMeasureType(ColumnDataType type) { Log.debug("Update ColumnTypeCode " + type); updateCondition(); - + } protected void updateAttributeType(ColumnDataType type) { Log.debug("Update ColumnTypeCode " + type); updateCondition(); - } @@ -1164,25 +1246,15 @@ public class ColumnExpressionPanel extends FramedPanel { parentTemplateDialog.hide(); eventBus.fireEvent(expressionEvent); break; + case Rule: + RuleDescriptionData ruleDescriptionData = retrieveRuleDescriptionData(exp); + if (ruleDescriptionData != null) { + parentRuleDialog.addRule(ruleDescriptionData); + } + break; case ColumnFilter: parentFilterDialog.applyFilter(column, exp); break; - - case Rule: - ColumnMockUp columnMockUp = new ColumnMockUp(); - column = new ColumnData(); - column.setColumnId(columnMockUp.getColumnId()); - column.setLabel(columnMockUp.getLabel()); - column.setDataTypeName(columnMockUp.getColumnDataType().toString()); - column.setTypeCode(columnMockUp.getColumnType().toString()); - condContainer = new C_ExpressionContainer(); - condContainer.setId(C_ExpressionContainer.Contains.C_Expression); - condContainer.setExp(exp); - condContainer.setReadableExpression(conditionWidget - .getReadableExpression()); - exWrapper = new ExpressionWrapper(null, column, condContainer); - parentRuleDialog.addRule(exWrapper); - break; case RowDeleteByExpression: C_Expression notExp = new C_Not(exp); parentRowsDeleteByExpressionDialog.deleteRowsByExpression(column, @@ -1208,12 +1280,15 @@ public class ColumnExpressionPanel extends FramedPanel { parentTemplateDialog.hide(); eventBus.fireEvent(expressionEvent); break; + case Rule: + parentRuleDialog.close(); case ColumnFilter: parentFilterDialog.close(); break; case RowDeleteByExpression: parentRowsDeleteByExpressionDialog.close(); break; + case MultiColumnFilter: break; default: diff --git a/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/RuleDialog.java b/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/RuleDialog.java index 36e5afd..3d58623 100644 --- a/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/RuleDialog.java +++ b/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/RuleDialog.java @@ -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.widgetcommonevent.client.expression.ExpressionWrapper; +import org.gcube.portlets.user.td.expressionwidget.shared.rule.RuleDescriptionData; import com.allen_sauer.gwt.log.client.Log; import com.google.web.bindery.event.shared.EventBus; @@ -87,8 +87,8 @@ public class RuleDialog extends Window { } - public void addRule(ExpressionWrapper exWrapper) { - Log.debug("ExpressionWrapper: "+exWrapper); + public void addRule(RuleDescriptionData ruleDescriptionData) { + Log.debug("RuleDescriptionData: "+ruleDescriptionData); close(); } diff --git a/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/rpc/ExpressionService.java b/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/rpc/ExpressionService.java index afca76f..0f76c7b 100644 --- a/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/rpc/ExpressionService.java +++ b/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/rpc/ExpressionService.java @@ -3,6 +3,10 @@ */ package org.gcube.portlets.user.td.expressionwidget.client.rpc; +import java.util.ArrayList; + +import org.gcube.portlets.user.td.expressionwidget.shared.rule.RuleDescriptionData; +import org.gcube.portlets.user.td.expressionwidget.shared.rule.RuleScopeType; import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTServiceException; import org.gcube.portlets.user.td.gwtservice.shared.tr.column.AddColumnSession; import org.gcube.portlets.user.td.gwtservice.shared.tr.column.FilterColumnSession; @@ -44,5 +48,10 @@ public interface ExpressionService extends RemoteService { public String startAddColumn(AddColumnSession addColumnSession) throws TDGWTServiceException; + + public ArrayList getRules() + throws TDGWTServiceException; + public ArrayList getRules(RuleScopeType scope) + throws TDGWTServiceException; } diff --git a/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/rpc/ExpressionServiceAsync.java b/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/rpc/ExpressionServiceAsync.java index bf8036d..359583b 100644 --- a/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/rpc/ExpressionServiceAsync.java +++ b/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/rpc/ExpressionServiceAsync.java @@ -3,6 +3,10 @@ */ package org.gcube.portlets.user.td.expressionwidget.client.rpc; +import java.util.ArrayList; + +import org.gcube.portlets.user.td.expressionwidget.shared.rule.RuleDescriptionData; +import org.gcube.portlets.user.td.expressionwidget.shared.rule.RuleScopeType; 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; @@ -32,4 +36,9 @@ public interface ExpressionServiceAsync { void startAddColumn(AddColumnSession addColumnSession, AsyncCallback callback); + void getRules(AsyncCallback> callback); + + void getRules(RuleScopeType scope, + AsyncCallback> callback); + } diff --git a/src/main/java/org/gcube/portlets/user/td/expressionwidget/server/ExpressionServiceImpl.java b/src/main/java/org/gcube/portlets/user/td/expressionwidget/server/ExpressionServiceImpl.java index 2e3c55f..52cd85e 100644 --- a/src/main/java/org/gcube/portlets/user/td/expressionwidget/server/ExpressionServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/td/expressionwidget/server/ExpressionServiceImpl.java @@ -213,54 +213,110 @@ public class ExpressionServiceImpl extends RemoteServiceServlet implements } } - //TODO - public ArrayList getRule(RuleScopeType scope) throws TDGWTServiceException { - try { - HttpSession session = this.getThreadLocalRequest().getSession(); - ASLSession aslSession = SessionUtil.getAslSession(session); + + /** + * + * {@inheritDoc} + */ + @Override + public ArrayList getRules(RuleScopeType scope) + throws TDGWTServiceException { + try { + HttpSession session = this.getThreadLocalRequest().getSession(); + ASLSession aslSession = SessionUtil.getAslSession(session); - logger.debug("GetRule()"); - AuthorizationProvider.instance.set(new AuthorizationToken( - aslSession.getUsername(), aslSession.getScope())); - TabularDataService service = TabularDataServiceFactory.getService(); - service.getRules(); - - List rules=service.getRulesByScope(RuleScopeMap.map(scope)); - - ArrayList rulesDes=new ArrayList(); - - C_ExpressionParser parser = new C_ExpressionParser(); - - for(RuleDescription ruleDescription: rules){ - Expression serviceExpression=ruleDescription.getRule(); - C_Expression cexp=parser.parse(serviceExpression); - RuleDescriptionData ruleData=new RuleDescriptionData(ruleDescription.getId(), - ruleDescription.getName(), ruleDescription.getDescription(), - RuleScopeMap.map(ruleDescription.getScope()), - cexp); - rulesDes.add(ruleData); - - - } - - return rulesDes; - - } catch (TDGWTServiceException e) { - logger.error(e.getLocalizedMessage(),e); - throw e; - } catch (SecurityException e) { - logger.error(e.getLocalizedMessage(),e); - throw e; - } catch (Throwable e) { - logger.error( - "Error in getRule(): " + e.getLocalizedMessage(), - e); - throw new TDGWTServiceException("Error retrieving the rules: " - + e.getLocalizedMessage()); - } + logger.debug("GetRule()"); + AuthorizationProvider.instance.set(new AuthorizationToken( + aslSession.getUsername(), aslSession.getScope())); + TabularDataService service = TabularDataServiceFactory.getService(); + List rules = service.getRulesByScope(RuleScopeMap + .map(scope)); + + ArrayList rulesDes = new ArrayList(); + + C_ExpressionParser parser = new C_ExpressionParser(); + + for (RuleDescription ruleDescription : rules) { + Expression serviceExpression = ruleDescription.getRule(); + C_Expression cexp = parser.parse(serviceExpression); + RuleDescriptionData ruleData = new RuleDescriptionData( + ruleDescription.getId(), ruleDescription.getName(), + ruleDescription.getDescription(), + RuleScopeMap.map(ruleDescription.getScope()), cexp); + rulesDes.add(ruleData); + + } + + return rulesDes; + + } catch (TDGWTServiceException e) { + logger.error(e.getLocalizedMessage()); + throw e; + } catch (SecurityException e) { + logger.error(e.getLocalizedMessage()); + e.printStackTrace(); + throw e; + } catch (Throwable e) { + logger.error("Error in getRule(): " + e.getLocalizedMessage()); + e.printStackTrace(); + throw new TDGWTServiceException("Error retrieving the rules: " + + e.getLocalizedMessage()); } - + + } + + + /** + * + * {@inheritDoc} + */ + @Override + public ArrayList getRules() + throws TDGWTServiceException { + try { + HttpSession session = this.getThreadLocalRequest().getSession(); + ASLSession aslSession = SessionUtil.getAslSession(session); + + logger.debug("GetRule()"); + AuthorizationProvider.instance.set(new AuthorizationToken( + aslSession.getUsername(), aslSession.getScope())); + TabularDataService service = TabularDataServiceFactory.getService(); + + List rules = service.getRules(); + + ArrayList rulesDes = new ArrayList(); + + C_ExpressionParser parser = new C_ExpressionParser(); + + for (RuleDescription ruleDescription : rules) { + Expression serviceExpression = ruleDescription.getRule(); + C_Expression cexp = parser.parse(serviceExpression); + RuleDescriptionData ruleData = new RuleDescriptionData( + ruleDescription.getId(), ruleDescription.getName(), + ruleDescription.getDescription(), + RuleScopeMap.map(ruleDescription.getScope()), cexp); + rulesDes.add(ruleData); + + } + + return rulesDes; + + } catch (TDGWTServiceException e) { + logger.error(e.getLocalizedMessage()); + throw e; + } catch (SecurityException e) { + logger.error(e.getLocalizedMessage()); + e.printStackTrace(); + throw e; + } catch (Throwable e) { + logger.error("Error in getRule(): " + e.getLocalizedMessage()); + e.printStackTrace(); + throw new TDGWTServiceException("Error retrieving the rules: " + + e.getLocalizedMessage()); + } + + } diff --git a/src/main/java/org/gcube/portlets/user/td/expressionwidget/shared/rule/RuleDescriptionData.java b/src/main/java/org/gcube/portlets/user/td/expressionwidget/shared/rule/RuleDescriptionData.java index 9317527..fefb9ff 100644 --- a/src/main/java/org/gcube/portlets/user/td/expressionwidget/shared/rule/RuleDescriptionData.java +++ b/src/main/java/org/gcube/portlets/user/td/expressionwidget/shared/rule/RuleDescriptionData.java @@ -72,6 +72,15 @@ public class RuleDescriptionData implements Serializable { public void setExpression(C_Expression expression) { this.expression = expression; } + + public String getReadableExpression(){ + if(expression!=null){ + return expression.getReadableExpression(); + } else { + return ""; + } + } + @Override public String toString() { diff --git a/src/main/java/org/gcube/portlets/user/td/expressionwidget/shared/rule/RuleDescriptionDataProperties.java b/src/main/java/org/gcube/portlets/user/td/expressionwidget/shared/rule/RuleDescriptionDataProperties.java new file mode 100644 index 0000000..4714ce2 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/expressionwidget/shared/rule/RuleDescriptionDataProperties.java @@ -0,0 +1,29 @@ +package org.gcube.portlets.user.td.expressionwidget.shared.rule; + + + + + +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 + * email: g.panichi@isti.cnr.it + * + */ +public interface RuleDescriptionDataProperties extends PropertyAccess { + + @Path("id") + ModelKeyProvider id(); + + ValueProvider name(); + ValueProvider description(); + ValueProvider readableExpression(); + + +} +