Search in sources :

Example 16 with RangeRestriction

use of org.talend.dataquality.domain.RangeRestriction in project tdq-studio-se by Talend.

the class IndicatorHelper method setDataThreshold.

public static void setDataThreshold(IndicatorParameters parameters, String min, String max) {
    assert parameters != null;
    Domain validDomain = parameters.getDataValidDomain();
    if (validDomain == null) {
        // $NON-NLS-1$
        validDomain = DomainHelper.createDomain("Data threshold");
        parameters.setDataValidDomain(validDomain);
    }
    // remove previous ranges
    assert validDomain.getRanges().size() < 2;
    validDomain.getRanges().clear();
    RangeRestriction rangeRestriction = DomainHelper.createStringRangeRestriction(min, max);
    validDomain.getRanges().add(rangeRestriction);
}
Also used : RangeRestriction(org.talend.dataquality.domain.RangeRestriction) Domain(org.talend.dataquality.domain.Domain)

Example 17 with RangeRestriction

use of org.talend.dataquality.domain.RangeRestriction in project tdq-studio-se by Talend.

the class AnalysisHelper method setStringDataFilter.

/**
 * DOC xqliu Comment method "setStringDataFilter".
 *
 * @param analysis
 * @param datafilterString
 * @param index 0 for DataFilterA, 1 for DataFilterB
 * @return
 */
public static boolean setStringDataFilter(Analysis analysis, String datafilterString, int index) {
    if (index == 1) {
        EList<Domain> dataFilters = analysis.getParameters().getDataFilter();
        int size = dataFilters.size();
        if (size == 0) {
            // $NON-NLS-1$
            dataFilters.add(createDomain(analysis, ""));
            // $NON-NLS-1$
            return dataFilters.add(createDomain(analysis, datafilterString, "1"));
        } else if (size == 1) {
            // $NON-NLS-1$
            return dataFilters.add(createDomain(analysis, datafilterString, "1"));
        } else if (size == 2) {
            Domain domain = dataFilters.get(1);
            EList<RangeRestriction> ranges = domain.getRanges();
            RangeRestriction rangeRestriction = (ranges.isEmpty()) ? DomainHelper.addRangeRestriction(domain) : ranges.get(0);
            BooleanExpressionNode expressions = rangeRestriction.getExpressions();
            if (expressions == null) {
                expressions = BooleanExpressionHelper.createBooleanExpressionNode(datafilterString);
                rangeRestriction.setExpressions(expressions);
            } else {
                Expression expression = expressions.getExpression();
                if (expression == null) {
                    expression = BooleanExpressionHelper.createTdExpression(BooleanExpressionHelper.DEFAULT_LANGUAGE, datafilterString);
                    expressions.setExpression(expression);
                } else {
                    expression.setBody(datafilterString);
                }
            }
            return false;
        } else {
            return false;
        }
    } else {
        return setStringDataFilter(analysis, datafilterString);
    }
}
Also used : Expression(orgomg.cwm.objectmodel.core.Expression) BooleanExpressionNode(org.talend.dataquality.expressions.BooleanExpressionNode) RangeRestriction(org.talend.dataquality.domain.RangeRestriction) Domain(org.talend.dataquality.domain.Domain)

Example 18 with RangeRestriction

use of org.talend.dataquality.domain.RangeRestriction in project tdq-studio-se by Talend.

the class AnalysisHelper method getStringDataFilter.

/**
 * DOC xqliu Comment method "getStringDataFilter".
 *
 * @param analysis
 * @param index 0 for DataFilterA, 1 for DataFilterB
 * @return
 */
public static String getStringDataFilter(Analysis analysis, int index) {
    AnalysisParameters parameters = analysis.getParameters();
    if (parameters == null) {
        return null;
    }
    EList<Domain> dataFilters = parameters.getDataFilter();
    // remove existing filters
    if (dataFilters == null || dataFilters.isEmpty()) {
        return null;
    }
    int i = 0;
    for (Domain domain : dataFilters) {
        if (domain == null) {
            continue;
        }
        EList<RangeRestriction> ranges = domain.getRanges();
        for (RangeRestriction rangeRestriction : ranges) {
            BooleanExpressionNode expressions = rangeRestriction.getExpressions();
            if (expressions == null) {
                continue;
            }
            Expression expression = expressions.getExpression();
            if (expression == null) {
                continue;
            }
            if (i == index) {
                // MOD klliu 2011-07-14 bug 23150 solve an NPE
                String body = expression.getBody();
                if (body == null) {
                    continue;
                }
                // ~
                return body.trim();
            } else if (i > index) {
                return null;
            }
        }
        i++;
    }
    return null;
}
Also used : Expression(orgomg.cwm.objectmodel.core.Expression) AnalysisParameters(org.talend.dataquality.analysis.AnalysisParameters) BooleanExpressionNode(org.talend.dataquality.expressions.BooleanExpressionNode) RangeRestriction(org.talend.dataquality.domain.RangeRestriction) Domain(org.talend.dataquality.domain.Domain)

Example 19 with RangeRestriction

use of org.talend.dataquality.domain.RangeRestriction in project tdq-studio-se by Talend.

the class AnalysisHelper method setStringDataFilter.

public static boolean setStringDataFilter(Analysis analysis, String datafilterString) {
    EList<Domain> dataFilters = analysis.getParameters().getDataFilter();
    // update existing filters
    if (!dataFilters.isEmpty()) {
        Domain domain = dataFilters.get(0);
        EList<RangeRestriction> ranges = domain.getRanges();
        RangeRestriction rangeRestriction = (ranges.isEmpty()) ? DomainHelper.addRangeRestriction(domain) : ranges.get(0);
        BooleanExpressionNode expressions = rangeRestriction.getExpressions();
        if (expressions == null) {
            expressions = BooleanExpressionHelper.createBooleanExpressionNode(datafilterString);
            rangeRestriction.setExpressions(expressions);
        } else {
            Expression expression = expressions.getExpression();
            if (expression == null) {
                expression = BooleanExpressionHelper.createTdExpression(BooleanExpressionHelper.DEFAULT_LANGUAGE, datafilterString);
                expressions.setExpression(expression);
            } else {
                expression.setBody(datafilterString);
            }
        }
        return false;
    }
    // else
    return dataFilters.add(createDomain(analysis, datafilterString));
}
Also used : Expression(orgomg.cwm.objectmodel.core.Expression) BooleanExpressionNode(org.talend.dataquality.expressions.BooleanExpressionNode) RangeRestriction(org.talend.dataquality.domain.RangeRestriction) Domain(org.talend.dataquality.domain.Domain)

Example 20 with RangeRestriction

use of org.talend.dataquality.domain.RangeRestriction in project tdq-studio-se by Talend.

the class DomainHelper method getMaxBinValue.

/**
 * Method "getMaxBinValue".
 *
 * @param domain
 * @return the higher value of the last bin.
 * @throws IllegalArgumentException
 */
public static double getMaxBinValue(Domain domain) {
    EList<RangeRestriction> ranges = domain.getRanges();
    if (ranges.isEmpty()) {
        // $NON-NLS-1$
        throw new IllegalArgumentException(Messages.getString("DomainHelper.NoRangeMax", domain.getName()));
    }
    int lastIdx = ranges.size() - 1;
    RangeRestriction r1 = ranges.get(lastIdx);
    if (r1 == null) {
        // $NON-NLS-1$
        throw new IllegalArgumentException(Messages.getString("DomainHelper.LastRangeMax", domain.getName()));
    }
    return getRealValue(r1.getUpperValue());
}
Also used : RangeRestriction(org.talend.dataquality.domain.RangeRestriction)

Aggregations

RangeRestriction (org.talend.dataquality.domain.RangeRestriction)22 Domain (org.talend.dataquality.domain.Domain)13 BooleanExpressionNode (org.talend.dataquality.expressions.BooleanExpressionNode)4 Expression (orgomg.cwm.objectmodel.core.Expression)3 ArrayList (java.util.ArrayList)1 List (java.util.List)1 EList (org.eclipse.emf.common.util.EList)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 ModifyEvent (org.eclipse.swt.events.ModifyEvent)1 ModifyListener (org.eclipse.swt.events.ModifyListener)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 TdColumn (org.talend.cwm.relational.TdColumn)1 AnalysisParameters (org.talend.dataquality.analysis.AnalysisParameters)1 DateGrain (org.talend.dataquality.indicators.DateGrain)1 DateParameters (org.talend.dataquality.indicators.DateParameters)1 IndicatorParameters (org.talend.dataquality.indicators.IndicatorParameters)1 IndicatorDefinition (org.talend.dataquality.indicators.definition.IndicatorDefinition)1 UDIndicatorDefinition (org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition)1