Updated Rules
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-expression-widget@114299 82a268e6-3cf1-43bd-a215-b396298e98cf
|
@ -250,7 +250,7 @@ public class ColumnExpressionPanel extends FramedPanel {
|
||||||
conditionsField.add(conditionWidget);
|
conditionsField.add(conditionWidget);
|
||||||
|
|
||||||
btnApply = new TextButton("Save");
|
btnApply = new TextButton("Save");
|
||||||
btnApply.setIcon(ExpressionResources.INSTANCE.rule());
|
btnApply.setIcon(ExpressionResources.INSTANCE.ruleColumnAdd());
|
||||||
btnApply.setIconAlign(IconAlign.RIGHT);
|
btnApply.setIconAlign(IconAlign.RIGHT);
|
||||||
btnApply.setToolTip("Save rule");
|
btnApply.setToolTip("Save rule");
|
||||||
btnApply.addSelectHandler(new SelectHandler() {
|
btnApply.addSelectHandler(new SelectHandler() {
|
||||||
|
|
|
@ -69,7 +69,7 @@ public class RuleDialog extends Window implements
|
||||||
setClosable(true);
|
setClosable(true);
|
||||||
setModal(true);
|
setModal(true);
|
||||||
forceLayoutOnResize = true;
|
forceLayoutOnResize = true;
|
||||||
getHeader().setIcon(ExpressionResources.INSTANCE.rule());
|
getHeader().setIcon(ExpressionResources.INSTANCE.ruleColumnAdd());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -88,7 +88,7 @@ public class TemplateColumnExpressionDialog extends Window implements
|
||||||
setClosable(true);
|
setClosable(true);
|
||||||
setModal(true);
|
setModal(true);
|
||||||
forceLayoutOnResize = true;
|
forceLayoutOnResize = true;
|
||||||
getHeader().setIcon(ExpressionResources.INSTANCE.rule());
|
getHeader().setIcon(ExpressionResources.INSTANCE.ruleAdd());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,16 @@ public interface ExpressionResources extends ClientBundle {
|
||||||
ImageResource close();
|
ImageResource close();
|
||||||
|
|
||||||
@Source("rule-add.png")
|
@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")
|
@Source("wrench-go.png")
|
||||||
ImageResource apply();
|
ImageResource apply();
|
||||||
|
|
Before Width: | Height: | Size: 922 B After Width: | Height: | Size: 1.6 KiB |
After Width: | Height: | Size: 882 B |
After Width: | Height: | Size: 2.0 KiB |
|
@ -6,12 +6,14 @@ package org.gcube.portlets.user.td.expressionwidget.client.rpc;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTServiceException;
|
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.RuleDescriptionData;
|
||||||
import org.gcube.portlets.user.td.gwtservice.shared.rule.RuleScopeType;
|
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.rule.ApplyColumnRulesSession;
|
||||||
import org.gcube.portlets.user.td.gwtservice.shared.tr.column.AddColumnSession;
|
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.FilterColumnSession;
|
||||||
import org.gcube.portlets.user.td.gwtservice.shared.tr.column.ReplaceColumnByExpressionSession;
|
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 org.gcube.portlets.user.td.widgetcommonevent.shared.tr.column.ColumnData;
|
||||||
|
|
||||||
import com.google.gwt.user.client.rpc.RemoteService;
|
import com.google.gwt.user.client.rpc.RemoteService;
|
||||||
|
@ -67,4 +69,8 @@ public interface ExpressionService extends RemoteService {
|
||||||
|
|
||||||
public String startApplyColumnRules(ApplyColumnRulesSession ruleOnColumnApplySession)
|
public String startApplyColumnRules(ApplyColumnRulesSession ruleOnColumnApplySession)
|
||||||
throws TDGWTServiceException;
|
throws TDGWTServiceException;
|
||||||
|
|
||||||
|
public AppliedRulesResponseData getAppliedRulesByTabularResourceId(TRId trId)
|
||||||
|
throws TDGWTServiceException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,12 +5,14 @@ package org.gcube.portlets.user.td.expressionwidget.client.rpc;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
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.RuleDescriptionData;
|
||||||
import org.gcube.portlets.user.td.gwtservice.shared.rule.RuleScopeType;
|
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.AddColumnSession;
|
||||||
import org.gcube.portlets.user.td.gwtservice.shared.tr.column.FilterColumnSession;
|
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.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 org.gcube.portlets.user.td.widgetcommonevent.shared.tr.column.ColumnData;
|
||||||
|
|
||||||
import com.google.gwt.core.client.GWT;
|
import com.google.gwt.core.client.GWT;
|
||||||
|
@ -56,4 +58,7 @@ public interface ExpressionServiceAsync {
|
||||||
ApplyColumnRulesSession ruleOnColumnApplySession,
|
ApplyColumnRulesSession ruleOnColumnApplySession,
|
||||||
AsyncCallback<String> callback);
|
AsyncCallback<String> callback);
|
||||||
|
|
||||||
|
void getAppliedRulesByTabularResourceId(TRId trId,
|
||||||
|
AsyncCallback<AppliedRulesResponseData> callback);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.rules.RuleId;
|
||||||
import org.gcube.data.analysis.tabulardata.service.tabular.TabularResourceId;
|
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.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.ExpressionParserException;
|
||||||
import org.gcube.portlets.user.td.expressionwidget.shared.exception.ExpressionServiceException;
|
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.SessionUtil;
|
||||||
import org.gcube.portlets.user.td.gwtservice.server.TDGWTServiceImpl;
|
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.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.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.RuleDescriptionData;
|
||||||
import org.gcube.portlets.user.td.gwtservice.shared.rule.RuleScopeType;
|
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.rule.ApplyColumnRulesSession;
|
||||||
|
@ -273,7 +276,6 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
|
@ -308,7 +310,7 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements
|
||||||
ruleDescription.getOwner(),
|
ruleDescription.getOwner(),
|
||||||
RuleScopeMap.map(ruleDescription.getScope()),
|
RuleScopeMap.map(ruleDescription.getScope()),
|
||||||
tdRuleColumnType, cexp);
|
tdRuleColumnType, cexp);
|
||||||
logger.info("Rule: "+ruleData);
|
logger.info("Rule: " + ruleData);
|
||||||
rulesDes.add(ruleData);
|
rulesDes.add(ruleData);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -361,29 +363,20 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements
|
||||||
|
|
||||||
List<RuleDescription> rules = service
|
List<RuleDescription> rules = service
|
||||||
.getApplicableBaseColumnRules(dataType);
|
.getApplicableBaseColumnRules(dataType);
|
||||||
if(rules==null){
|
if (rules == null) {
|
||||||
logger.error("Invalid applicable base column rules from service: 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 {
|
} else {
|
||||||
logger.debug("Applicable Base Column Rules: "+rules.size());
|
logger.debug("Applicable Base Column Rules: " + rules.size());
|
||||||
}
|
}
|
||||||
ArrayList<RuleDescriptionData> rulesDes = new ArrayList<RuleDescriptionData>();
|
ArrayList<RuleDescriptionData> rulesDes = new ArrayList<RuleDescriptionData>();
|
||||||
|
|
||||||
C_ExpressionParser parser = new C_ExpressionParser();
|
|
||||||
|
|
||||||
for (RuleDescription ruleDescription : rules) {
|
for (RuleDescription ruleDescription : rules) {
|
||||||
Expression serviceExpression = ruleDescription.getRule();
|
RuleDescriptionData ruleData = RuleDescriptionMap
|
||||||
C_Expression cexp = parser.parse(serviceExpression);
|
.map(ruleDescription);
|
||||||
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);
|
rulesDes.add(ruleData);
|
||||||
logger.info("Rule:"+ruleData);
|
logger.info("Rule:" + ruleData);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -397,7 +390,8 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
throw e;
|
throw e;
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
logger.error("Error in getApplicableBaseColumnRules(): " + e.getLocalizedMessage());
|
logger.error("Error in getApplicableBaseColumnRules(): "
|
||||||
|
+ e.getLocalizedMessage());
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
throw new TDGWTServiceException("Error retrieving the rules: "
|
throw new TDGWTServiceException("Error retrieving the rules: "
|
||||||
+ e.getLocalizedMessage());
|
+ e.getLocalizedMessage());
|
||||||
|
@ -406,9 +400,13 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
public ArrayList<RuleDescriptionData> getAppliedRulesByTabularResourceId(
|
*
|
||||||
TRId trId) throws TDGWTServiceException {
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public AppliedRulesResponseData getAppliedRulesByTabularResourceId(TRId trId)
|
||||||
|
throws TDGWTServiceException {
|
||||||
try {
|
try {
|
||||||
HttpSession session = this.getThreadLocalRequest().getSession();
|
HttpSession session = this.getThreadLocalRequest().getSession();
|
||||||
ASLSession aslSession = SessionUtil.getAslSession(session);
|
ASLSession aslSession = SessionUtil.getAslSession(session);
|
||||||
|
@ -418,53 +416,29 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements
|
||||||
aslSession.getUsername(), aslSession.getScope()));
|
aslSession.getUsername(), aslSession.getScope()));
|
||||||
TabularDataService service = TabularDataServiceFactory.getService();
|
TabularDataService service = TabularDataServiceFactory.getService();
|
||||||
|
|
||||||
if (trId == null || trId.getId()==null || trId.getId().isEmpty()) {
|
if (trId == null || trId.getId() == null || trId.getId().isEmpty()) {
|
||||||
logger.error("Error in getAppliedRulesByTabularResourceId(): No valid tabular resource id!");
|
logger.error("Error in getAppliedRulesByTabularResourceId(): No valid tabular resource id!");
|
||||||
throw new TDGWTServiceException(
|
throw new TDGWTServiceException(
|
||||||
"Error in get applied rules: invalid tabular resource id!");
|
"Error in get applied rules: invalid tabular resource id!");
|
||||||
}
|
}
|
||||||
|
|
||||||
TabularResourceId tabularResourceId=new TabularResourceId(Long.valueOf(trId.getId()));
|
TabularResourceId tabularResourceId = new TabularResourceId(
|
||||||
|
Long.valueOf(trId.getId()));
|
||||||
|
|
||||||
AppliedRulesResponse appliedRulesResponse = service
|
AppliedRulesResponse appliedRulesResponse = service
|
||||||
.getAppliedRulesByTabularResourceId(tabularResourceId);
|
.getAppliedRulesByTabularResourceId(tabularResourceId);
|
||||||
if(appliedRulesResponse==null){
|
if (appliedRulesResponse == null) {
|
||||||
logger.error("Invalid applied rules response from service: null");
|
logger.error("Invalid applied rules response from service: null");
|
||||||
throw new TDGWTServiceException("Invalid applied rules response from service: null");
|
throw new TDGWTServiceException(
|
||||||
|
"Invalid applied rules response from service: null");
|
||||||
} else {
|
} else {
|
||||||
logger.debug("Applied Rules Response: "+appliedRulesResponse);
|
logger.debug("Applied Rules Response: " + appliedRulesResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
//List<RuleDescription> appliedRulesResponse.getTableRules();
|
AppliedRulesResponseData appliedRulesResponseData = AppliedRulesResponseMap
|
||||||
|
.map(appliedRulesResponse);
|
||||||
|
|
||||||
|
return appliedRulesResponseData;
|
||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
ArrayList<RuleDescriptionData> rulesDes = new ArrayList<RuleDescriptionData>();
|
|
||||||
|
|
||||||
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);
|
|
||||||
rulesDes.add(ruleData);
|
|
||||||
logger.info("Rule:"+ruleData);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return rulesDes;
|
|
||||||
*/
|
|
||||||
|
|
||||||
return null;
|
|
||||||
} catch (TDGWTServiceException e) {
|
} catch (TDGWTServiceException e) {
|
||||||
logger.error(e.getLocalizedMessage());
|
logger.error(e.getLocalizedMessage());
|
||||||
throw e;
|
throw e;
|
||||||
|
@ -473,16 +447,15 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
throw e;
|
throw e;
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
logger.error("Error in getApplicableBaseColumnRules(): " + e.getLocalizedMessage());
|
logger.error("Error in getAppliedRulesByTabularResourceId(): "
|
||||||
|
+ e.getLocalizedMessage());
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
throw new TDGWTServiceException("Error retrieving the rules: "
|
throw new TDGWTServiceException("Error retrieving applied rules: "
|
||||||
+ e.getLocalizedMessage());
|
+ e.getLocalizedMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
|
@ -514,9 +487,10 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements
|
||||||
|
|
||||||
RuleColumnType ruleColumnType = RuleColumnTypeMap
|
RuleColumnType ruleColumnType = RuleColumnTypeMap
|
||||||
.map(ruleDescriptionData.getTdRuleColumnType());
|
.map(ruleDescriptionData.getTdRuleColumnType());
|
||||||
if(ruleColumnType==null){
|
if (ruleColumnType == null) {
|
||||||
logger.debug("Error saving rule: rule column type is 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(
|
RuleId ruleId = service.saveColumnRule(
|
||||||
|
@ -593,9 +567,6 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
|
|
|
@ -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" <a
|
||||||
|
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
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<RuleDescriptionData> tableRulesData = new ArrayList<RuleDescriptionData>();
|
||||||
|
List<RuleDescription> 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<String, ArrayList<RuleDescriptionData>> columnRuleMappingData = new HashMap<String, ArrayList<RuleDescriptionData>>();
|
||||||
|
Map<String, List<RuleDescription>> columnRuleMapping = appliedRulesResponse
|
||||||
|
.getColumnRuleMapping();
|
||||||
|
if (columnRuleMapping != null && columnRuleMapping.size() > 0) {
|
||||||
|
for (Map.Entry<String, List<RuleDescription>> entry : columnRuleMapping
|
||||||
|
.entrySet()) {
|
||||||
|
ArrayList<RuleDescriptionData> columnRules = new ArrayList<RuleDescriptionData>();
|
||||||
|
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;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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: <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;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -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"
|
||||||
|
* <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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"
|
||||||
|
* <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
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;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Before Width: | Height: | Size: 922 B After Width: | Height: | Size: 1.6 KiB |
After Width: | Height: | Size: 882 B |
After Width: | Height: | Size: 2.0 KiB |