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 a1cdd3c..b77cadc 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 @@ -250,7 +250,7 @@ public class ColumnExpressionPanel extends FramedPanel { conditionsField.add(conditionWidget); btnApply = new TextButton("Save"); - btnApply.setIcon(ExpressionResources.INSTANCE.rule()); + btnApply.setIcon(ExpressionResources.INSTANCE.ruleColumnAdd()); btnApply.setIconAlign(IconAlign.RIGHT); btnApply.setToolTip("Save rule"); btnApply.addSelectHandler(new SelectHandler() { 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 9820860..d1574f2 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 @@ -69,7 +69,7 @@ public class RuleDialog extends Window implements setClosable(true); setModal(true); forceLayoutOnResize = true; - getHeader().setIcon(ExpressionResources.INSTANCE.rule()); + getHeader().setIcon(ExpressionResources.INSTANCE.ruleColumnAdd()); } diff --git a/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/TemplateColumnExpressionDialog.java b/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/TemplateColumnExpressionDialog.java index 2364604..4e4ee42 100644 --- a/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/TemplateColumnExpressionDialog.java +++ b/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/TemplateColumnExpressionDialog.java @@ -88,7 +88,7 @@ public class TemplateColumnExpressionDialog extends Window implements setClosable(true); setModal(true); forceLayoutOnResize = true; - getHeader().setIcon(ExpressionResources.INSTANCE.rule()); + getHeader().setIcon(ExpressionResources.INSTANCE.ruleAdd()); } diff --git a/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/resources/ExpressionResources.java b/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/resources/ExpressionResources.java index 65f54fb..e6ee3db 100644 --- a/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/resources/ExpressionResources.java +++ b/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/resources/ExpressionResources.java @@ -30,7 +30,16 @@ public interface ExpressionResources extends ClientBundle { ImageResource close(); @Source("rule-add.png") - ImageResource rule(); + ImageResource ruleAdd(); + + @Source("rule-add_32.png") + ImageResource ruleAdd32(); + + @Source("rule-column-add.png") + ImageResource ruleColumnAdd(); + + @Source("rule-column-add_32.png") + ImageResource ruleColumnAdd32(); @Source("wrench-go.png") ImageResource apply(); diff --git a/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/resources/rule-add.png b/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/resources/rule-add.png index 17bcae1..b3ee5c2 100644 Binary files a/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/resources/rule-add.png and b/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/resources/rule-add.png differ diff --git a/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/resources/rule-column-add.png b/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/resources/rule-column-add.png new file mode 100644 index 0000000..15e8736 Binary files /dev/null and b/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/resources/rule-column-add.png differ diff --git a/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/resources/rule-column-add_32.png b/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/resources/rule-column-add_32.png new file mode 100644 index 0000000..230cb1b Binary files /dev/null and b/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/resources/rule-column-add_32.png differ 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 80ea970..d89a092 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 @@ -6,12 +6,14 @@ package org.gcube.portlets.user.td.expressionwidget.client.rpc; 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.RuleDescriptionData; import org.gcube.portlets.user.td.gwtservice.shared.rule.RuleScopeType; import org.gcube.portlets.user.td.gwtservice.shared.rule.ApplyColumnRulesSession; 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; +import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId; import org.gcube.portlets.user.td.widgetcommonevent.shared.tr.column.ColumnData; import com.google.gwt.user.client.rpc.RemoteService; @@ -67,4 +69,8 @@ public interface ExpressionService extends RemoteService { public String startApplyColumnRules(ApplyColumnRulesSession ruleOnColumnApplySession) throws TDGWTServiceException; + + public AppliedRulesResponseData getAppliedRulesByTabularResourceId(TRId trId) + 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 9c87122..ec5b1a0 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 @@ -5,12 +5,14 @@ package org.gcube.portlets.user.td.expressionwidget.client.rpc; import java.util.ArrayList; +import org.gcube.portlets.user.td.gwtservice.shared.rule.AppliedRulesResponseData; +import org.gcube.portlets.user.td.gwtservice.shared.rule.ApplyColumnRulesSession; 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.ApplyColumnRulesSession; 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; +import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId; import org.gcube.portlets.user.td.widgetcommonevent.shared.tr.column.ColumnData; import com.google.gwt.core.client.GWT; @@ -55,5 +57,8 @@ public interface ExpressionServiceAsync { void startApplyColumnRules( ApplyColumnRulesSession ruleOnColumnApplySession, AsyncCallback callback); + + void getAppliedRulesByTabularResourceId(TRId trId, + 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 7779966..4dd741e 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 @@ -19,14 +19,17 @@ import org.gcube.data.analysis.tabulardata.service.impl.TabularDataServiceFactor 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.shared.exception.ExpressionParserException; import org.gcube.portlets.user.td.expressionwidget.shared.exception.ExpressionServiceException; import org.gcube.portlets.user.td.gwtservice.server.SessionUtil; import org.gcube.portlets.user.td.gwtservice.server.TDGWTServiceImpl; import org.gcube.portlets.user.td.gwtservice.server.trservice.ColumnDataTypeMap; -import org.gcube.portlets.user.td.gwtservice.server.trservice.rule.RuleColumnTypeMap; -import org.gcube.portlets.user.td.gwtservice.server.trservice.rule.RuleScopeMap; 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.RuleScopeType; import org.gcube.portlets.user.td.gwtservice.shared.rule.ApplyColumnRulesSession; @@ -272,8 +275,7 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements } } - - + /** * * {@inheritDoc} @@ -308,7 +310,7 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements ruleDescription.getOwner(), RuleScopeMap.map(ruleDescription.getScope()), tdRuleColumnType, cexp); - logger.info("Rule: "+ruleData); + logger.info("Rule: " + ruleData); rulesDes.add(ruleData); } @@ -335,7 +337,7 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements * * {@inheritDoc} */ - @Override + @Override public ArrayList getApplicableBaseColumnRules( ColumnData columnData) throws TDGWTServiceException { try { @@ -361,29 +363,20 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements List rules = service .getApplicableBaseColumnRules(dataType); - if(rules==null){ + if (rules == null) { logger.error("Invalid applicable base column rules from service: null"); - throw new TDGWTServiceException("Error retrieving the rules: invalid applicable base column rules from service(null)"); + throw new TDGWTServiceException( + "Error retrieving the rules: invalid applicable base column rules from service(null)"); } else { - logger.debug("Applicable Base Column Rules: "+rules.size()); + logger.debug("Applicable Base Column Rules: " + rules.size()); } ArrayList rulesDes = new ArrayList(); - C_ExpressionParser parser = new C_ExpressionParser(); - for (RuleDescription ruleDescription : rules) { - Expression serviceExpression = ruleDescription.getRule(); - C_Expression cexp = parser.parse(serviceExpression); - TDRuleColumnType tdRuleColumnType = RuleColumnTypeMap - .map(ruleDescription.getRuleColumnType()); - RuleDescriptionData ruleData = new RuleDescriptionData( - ruleDescription.getId(), ruleDescription.getName(), - ruleDescription.getDescription(), - ruleDescription.getOwner(), - RuleScopeMap.map(ruleDescription.getScope()), - tdRuleColumnType, cexp); + RuleDescriptionData ruleData = RuleDescriptionMap + .map(ruleDescription); rulesDes.add(ruleData); - logger.info("Rule:"+ruleData); + logger.info("Rule:" + ruleData); } @@ -397,91 +390,71 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements e.printStackTrace(); throw e; } catch (Throwable e) { - logger.error("Error in getApplicableBaseColumnRules(): " + e.getLocalizedMessage()); + logger.error("Error in getApplicableBaseColumnRules(): " + + e.getLocalizedMessage()); e.printStackTrace(); throw new TDGWTServiceException("Error retrieving the rules: " + e.getLocalizedMessage()); } } - - - public ArrayList getAppliedRulesByTabularResourceId( - TRId trId) throws TDGWTServiceException { - try { - HttpSession session = this.getThreadLocalRequest().getSession(); - ASLSession aslSession = SessionUtil.getAslSession(session); + + /** + * + * {@inheritDoc} + */ + @Override + public AppliedRulesResponseData getAppliedRulesByTabularResourceId(TRId trId) + throws TDGWTServiceException { + try { + HttpSession session = this.getThreadLocalRequest().getSession(); + ASLSession aslSession = SessionUtil.getAslSession(session); - logger.debug("GetAppliedRulesByTabularResourceId(): " + trId); - AuthorizationProvider.instance.set(new AuthorizationToken( - aslSession.getUsername(), aslSession.getScope())); - TabularDataService service = TabularDataServiceFactory.getService(); + logger.debug("GetAppliedRulesByTabularResourceId(): " + trId); + AuthorizationProvider.instance.set(new AuthorizationToken( + aslSession.getUsername(), aslSession.getScope())); + TabularDataService service = TabularDataServiceFactory.getService(); - if (trId == null || trId.getId()==null || trId.getId().isEmpty()) { - logger.error("Error in getAppliedRulesByTabularResourceId(): No valid tabular resource id!"); - throw new TDGWTServiceException( - "Error in get applied rules: invalid tabular resource id!"); - } + if (trId == null || trId.getId() == null || trId.getId().isEmpty()) { + logger.error("Error in getAppliedRulesByTabularResourceId(): No valid tabular resource id!"); + throw new TDGWTServiceException( + "Error in get applied rules: invalid tabular resource id!"); + } - TabularResourceId tabularResourceId=new TabularResourceId(Long.valueOf(trId.getId())); - - AppliedRulesResponse appliedRulesResponse = service - .getAppliedRulesByTabularResourceId(tabularResourceId); - if(appliedRulesResponse==null){ - logger.error("Invalid applied rules response from service: null"); - throw new TDGWTServiceException("Invalid applied rules response from service: null"); - } else { - logger.debug("Applied Rules Response: "+appliedRulesResponse); - } - - //List appliedRulesResponse.getTableRules(); - - - - /* - - ArrayList rulesDes = new ArrayList(); + TabularResourceId tabularResourceId = new TabularResourceId( + Long.valueOf(trId.getId())); - C_ExpressionParser parser = new C_ExpressionParser(); + AppliedRulesResponse appliedRulesResponse = service + .getAppliedRulesByTabularResourceId(tabularResourceId); + if (appliedRulesResponse == null) { + logger.error("Invalid applied rules response from service: null"); + throw new TDGWTServiceException( + "Invalid applied rules response from service: null"); + } else { + logger.debug("Applied Rules Response: " + appliedRulesResponse); + } - for (RuleDescription ruleDescription : rules) { - Expression serviceExpression = ruleDescription.getRule(); - C_Expression cexp = parser.parse(serviceExpression); - TDRuleColumnType tdRuleColumnType = RuleColumnTypeMap - .map(ruleDescription.getRuleColumnType()); - RuleDescriptionData ruleData = new RuleDescriptionData( - ruleDescription.getId(), ruleDescription.getName(), - ruleDescription.getDescription(), - ruleDescription.getOwner(), - RuleScopeMap.map(ruleDescription.getScope()), - tdRuleColumnType, cexp); - rulesDes.add(ruleData); - logger.info("Rule:"+ruleData); + AppliedRulesResponseData appliedRulesResponseData = AppliedRulesResponseMap + .map(appliedRulesResponse); - } - - return rulesDes; - */ - - return null; - } 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 getApplicableBaseColumnRules(): " + e.getLocalizedMessage()); - e.printStackTrace(); - throw new TDGWTServiceException("Error retrieving the rules: " - + e.getLocalizedMessage()); - } + return appliedRulesResponseData; + } 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 getAppliedRulesByTabularResourceId(): " + + e.getLocalizedMessage()); + e.printStackTrace(); + throw new TDGWTServiceException("Error retrieving applied rules: " + + e.getLocalizedMessage()); + } - } - - + } /** * @@ -514,11 +487,12 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements RuleColumnType ruleColumnType = RuleColumnTypeMap .map(ruleDescriptionData.getTdRuleColumnType()); - if(ruleColumnType==null){ + if (ruleColumnType == null) { logger.debug("Error saving rule: rule column type is null!"); - throw new TDGWTServiceException("Error saving rule: rule column type is null!"); + throw new TDGWTServiceException( + "Error saving rule: rule column type is null!"); } - + RuleId ruleId = service.saveColumnRule( ruleDescriptionData.getName(), ruleDescriptionData.getDescription(), conditionExpression, @@ -592,9 +566,6 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements } } - - - /** * diff --git a/src/main/java/org/gcube/portlets/user/td/expressionwidget/server/service/rule/AppliedRulesResponseMap.java b/src/main/java/org/gcube/portlets/user/td/expressionwidget/server/service/rule/AppliedRulesResponseMap.java new file mode 100644 index 0000000..669c4a0 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/expressionwidget/server/service/rule/AppliedRulesResponseMap.java @@ -0,0 +1,84 @@ +package org.gcube.portlets.user.td.expressionwidget.server.service.rule; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.gcube.data.analysis.tabulardata.commons.webservice.types.AppliedRulesResponse; +import org.gcube.data.analysis.tabulardata.commons.webservice.types.RuleDescription; +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.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * + * @author "Giancarlo Panichi" g.panichi@isti.cnr.it + * + */ +public class AppliedRulesResponseMap { + private static Logger logger = LoggerFactory + .getLogger(AppliedRulesResponseMap.class); + + public static AppliedRulesResponseData map( + AppliedRulesResponse appliedRulesResponse) + throws TDGWTServiceException, ExpressionParserException { + AppliedRulesResponseData appliedRulesResponseData = null; + if (appliedRulesResponse == null) { + logger.debug("Applied Rules: " + appliedRulesResponse); + throw new TDGWTServiceException("Applied Rules Response is null!"); + } + + ArrayList tableRulesData = new ArrayList(); + List tableRules = appliedRulesResponse.getTableRules(); + if (tableRules != null && tableRules.size() > 0) { + for (RuleDescription ruleDescription : tableRules) { + RuleDescriptionData ruleDescriptionData = RuleDescriptionMap + .map(ruleDescription); + if (ruleDescriptionData != null) { + tableRulesData.add(ruleDescriptionData); + } else { + logger.error("Invalid Rule Description(Rule is discarded): " + + ruleDescription); + + } + + } + } + + HashMap> columnRuleMappingData = new HashMap>(); + Map> columnRuleMapping = appliedRulesResponse + .getColumnRuleMapping(); + if (columnRuleMapping != null && columnRuleMapping.size() > 0) { + for (Map.Entry> entry : columnRuleMapping + .entrySet()) { + ArrayList columnRules = new ArrayList(); + for (RuleDescription ruleDescription : entry.getValue()) { + RuleDescriptionData ruleDescriptionData = RuleDescriptionMap + .map(ruleDescription); + if (ruleDescriptionData != null) { + columnRules.add(ruleDescriptionData); + } else { + logger.error("Invalid Rule Description(Rule is discarded): " + + ruleDescription); + + } + } + columnRuleMappingData.put(entry.getKey(), columnRules); + + } + } + + appliedRulesResponseData = new AppliedRulesResponseData(tableRulesData, + columnRuleMappingData); + + logger.debug("Applied Rules: " + appliedRulesResponseData); + return appliedRulesResponseData; + + } + +} diff --git a/src/main/java/org/gcube/portlets/user/td/expressionwidget/server/service/rule/RuleColumnTypeMap.java b/src/main/java/org/gcube/portlets/user/td/expressionwidget/server/service/rule/RuleColumnTypeMap.java new file mode 100644 index 0000000..6f529bd --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/expressionwidget/server/service/rule/RuleColumnTypeMap.java @@ -0,0 +1,95 @@ +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: g.panichi@isti.cnr.it + * + */ +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; + + } + + +} diff --git a/src/main/java/org/gcube/portlets/user/td/expressionwidget/server/service/rule/RuleDescriptionMap.java b/src/main/java/org/gcube/portlets/user/td/expressionwidget/server/service/rule/RuleDescriptionMap.java new file mode 100644 index 0000000..4b4a715 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/expressionwidget/server/service/rule/RuleDescriptionMap.java @@ -0,0 +1,86 @@ +package org.gcube.portlets.user.td.expressionwidget.server.service.rule; + + + +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.widgetcommonevent.shared.expression.C_Expression; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * + * @author "Giancarlo Panichi" + * g.panichi@isti.cnr.it + * + */ +public class RuleDescriptionMap { + private static Logger logger = LoggerFactory + .getLogger(RuleDescriptionMap.class); + + + public static RuleDescriptionData map(RuleDescription ruleDescription) + throws TDGWTServiceException, ExpressionParserException { + RuleDescriptionData ruleDescriptionData=null; + if(ruleDescription==null){ + logger.error("Rule description is null"); + throw new TDGWTServiceException("Rule description is null"); + + } + + + if(ruleDescription.getScope()==null){ + logger.error("Rule description has scope null"); + throw new TDGWTServiceException("Rule description has scope null"); + } + + + switch (ruleDescription.getScope()) { + case COLUMN: + ruleDescriptionData=createColumnRule(ruleDescription); + break; + case TABLE: + ruleDescriptionData=createTableRule(ruleDescription); + break; + default: + break; + } + + return ruleDescriptionData; + + } + + + private static RuleDescriptionData createTableRule( + RuleDescription ruleDescription) { + return null; + } + + + private static RuleDescriptionData createColumnRule( + RuleDescription ruleDescription) throws ExpressionParserException { + + Expression serviceExpression = ruleDescription.getRule(); + + C_ExpressionParser parser = new C_ExpressionParser(); + + C_Expression cexp = parser.parse(serviceExpression); + TDRuleColumnType tdRuleColumnType = RuleColumnTypeMap + .map(ruleDescription.getRuleColumnType()); + RuleDescriptionData ruleData = new RuleDescriptionData( + ruleDescription.getId(), ruleDescription.getName(), + ruleDescription.getDescription(), + ruleDescription.getOwner(), + RuleScopeMap.map(ruleDescription.getScope()), + tdRuleColumnType, cexp); + + return ruleData; + } + +} diff --git a/src/main/java/org/gcube/portlets/user/td/expressionwidget/server/service/rule/RuleScopeMap.java b/src/main/java/org/gcube/portlets/user/td/expressionwidget/server/service/rule/RuleScopeMap.java new file mode 100644 index 0000000..e497bf1 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/expressionwidget/server/service/rule/RuleScopeMap.java @@ -0,0 +1,46 @@ +package org.gcube.portlets.user.td.expressionwidget.server.service.rule; + +import org.gcube.data.analysis.tabulardata.commons.rules.RuleScope; +import org.gcube.portlets.user.td.gwtservice.shared.rule.RuleScopeType; + + +/** + * + * @author "Giancarlo Panichi" + * g.panichi@isti.cnr.it + * + */ +public class RuleScopeMap { + public static RuleScopeType map(RuleScope ruleScope) { + if(ruleScope==null){ + return null; + } + + switch (ruleScope) { + case COLUMN: + return RuleScopeType.COLUMN; + case TABLE: + return RuleScopeType.TABLE; + default: + return null; + + } + } + + public static RuleScope map(RuleScopeType ruleScopeType) { + if(ruleScopeType==null){ + return null; + } + + switch (ruleScopeType) { + case COLUMN: + return RuleScope.COLUMN; + case TABLE: + return RuleScope.TABLE; + default: + return null; + + } + } + +} diff --git a/src/main/resources/org/gcube/portlets/user/td/expressionwidget/client/resources/rule-add.png b/src/main/resources/org/gcube/portlets/user/td/expressionwidget/client/resources/rule-add.png index 17bcae1..b3ee5c2 100644 Binary files a/src/main/resources/org/gcube/portlets/user/td/expressionwidget/client/resources/rule-add.png and b/src/main/resources/org/gcube/portlets/user/td/expressionwidget/client/resources/rule-add.png differ diff --git a/src/main/resources/org/gcube/portlets/user/td/expressionwidget/client/resources/rule-column-add.png b/src/main/resources/org/gcube/portlets/user/td/expressionwidget/client/resources/rule-column-add.png new file mode 100644 index 0000000..15e8736 Binary files /dev/null and b/src/main/resources/org/gcube/portlets/user/td/expressionwidget/client/resources/rule-column-add.png differ diff --git a/src/main/resources/org/gcube/portlets/user/td/expressionwidget/client/resources/rule-column-add_32.png b/src/main/resources/org/gcube/portlets/user/td/expressionwidget/client/resources/rule-column-add_32.png new file mode 100644 index 0000000..230cb1b Binary files /dev/null and b/src/main/resources/org/gcube/portlets/user/td/expressionwidget/client/resources/rule-column-add_32.png differ