Search in sources :

Example 11 with RangeRestriction

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

the class ColumnAnalysisSqlExecutor method getBinsAsGenericString.

/**
 * DOC scorreia Comment method "getBinsAsString".
 *
 * @param ranges
 * @return
 */
private List<String> getBinsAsGenericString(EList<RangeRestriction> ranges, String colName) {
    List<String> bins = new ArrayList<String>();
    for (RangeRestriction rangeRestriction : ranges) {
        String bin = colName + dbms().greaterOrEqual() + DomainHelper.getMinValue(rangeRestriction) + dbms().and() + colName + dbms().less() + DomainHelper.getMaxValue(rangeRestriction);
        // set the name of the RangeRestriction here
        // TODO range name should be set at the construction (in the bins designer wizard)
        rangeRestriction.setName(this.unquote(bin));
        bins.add(bin);
    }
    return bins;
}
Also used : ArrayList(java.util.ArrayList) RangeRestriction(org.talend.dataquality.domain.RangeRestriction)

Example 12 with RangeRestriction

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

the class FrequencyStatisticsExplorer method getFreqRowsStatement.

protected String getFreqRowsStatement() {
    IndicatorDefinition indicatorDefinition = this.indicator.getIndicatorDefinition();
    if (indicatorDefinition instanceof UDIndicatorDefinition) {
        return getQueryForUDIndicator(indicatorDefinition);
    }
    String clause = PluginConstant.EMPTY_STRING;
    TdColumn column = (TdColumn) indicator.getAnalyzedElement();
    int javaType = column.getSqlDataType().getJavaDataType();
    if (Java2SqlType.isTextInSQL(javaType)) {
        clause = getInstantiatedClause();
    } else if (Java2SqlType.isDateInSQL(javaType)) {
        // MOD scorreia 2009-09-22 first check whether the value is null
        if (entity.isLabelNull()) {
            clause = getInstantiatedClause();
        } else {
            IndicatorParameters parameters = indicator.getParameters();
            if (parameters != null) {
                DateParameters dateParameters = parameters.getDateParameters();
                if (dateParameters != null) {
                    DateGrain dateGrain = dateParameters.getDateAggregationType();
                    clause = entity.isLabelNull() ? getInstantiatedClause() : getClauseWithDate(dateGrain, clause);
                } else {
                    clause = getInstantiatedClause();
                }
            } else {
                clause = getInstantiatedClause();
            }
        }
    } else if (Java2SqlType.isNumbericInSQL(javaType)) {
        IndicatorParameters parameters = indicator.getParameters();
        if (parameters != null) {
            // handle bins
            Domain bins = parameters.getBins();
            if (bins != null) {
                // rangeStrings = getBinsAsGenericString(bins.getRanges());
                final EList<RangeRestriction> ranges = bins.getRanges();
                for (RangeRestriction rangeRestriction : ranges) {
                    // find the rangeLabel
                    if (entity.getLabel() != null && entity.getLabel().equals(rangeRestriction.getName())) {
                        clause = createWhereClause(rangeRestriction);
                        break;
                    }
                }
            } else {
                // MOD hcheng 2009-05-18.Bug 7377,Frequency indicator,when bins is null,handle as textual data
                clause = getInstantiatedClause();
            }
        } else {
            // MOD scorreia 2009-05-13. Bug 7235
            // no parameter set: handle as textual data
            clause = getInstantiatedClause();
        }
    } else {
        // no quote here
        clause = getDefaultQuotedStatement(PluginConstant.EMPTY_STRING);
    }
    return // $NON-NLS-1$
    "SELECT * FROM " + getFullyQualifiedTableName(column) + dbmsLanguage.where() + inBrackets(clause) + andDataFilterClause();
}
Also used : TdColumn(org.talend.cwm.relational.TdColumn) DateGrain(org.talend.dataquality.indicators.DateGrain) UDIndicatorDefinition(org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition) IndicatorParameters(org.talend.dataquality.indicators.IndicatorParameters) DateParameters(org.talend.dataquality.indicators.DateParameters) RangeRestriction(org.talend.dataquality.domain.RangeRestriction) Domain(org.talend.dataquality.domain.Domain) UDIndicatorDefinition(org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition)

Example 13 with RangeRestriction

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

the class BinsDesignerForm method addFieldsListeners.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.dataprofiler.core.ui.utils.AbstractForm#addFieldsListeners()
     */
@Override
protected void addFieldsListeners() {
    // MOD hcheng for 7377,only when minValue,maxValue,numbOfBins are set, the wizard can finish
    minValue.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            String mintxt = minValue.getText();
            String maxtxt = maxValue.getText();
            String bintxt = numbOfBins.getText();
            if (mintxt != "") {
                // $NON-NLS-1$
                if (!CheckValueUtils.isRealNumberValue(mintxt)) {
                    updateStatus(IStatus.ERROR, MSG_ONLY_REAL_NUMBER);
                } else if (!maxtxt.equals("") && CheckValueUtils.isAoverB(mintxt, maxtxt)) {
                    // $NON-NLS-1$
                    updateStatus(IStatus.ERROR, UIMessages.MSG_LOWER_LESS_HIGHER);
                } else if (!maxtxt.equals("") && !bintxt.equals("")) {
                    // $NON-NLS-1$ //$NON-NLS-2$
                    updateStatus(IStatus.OK, MSG_OK);
                } else {
                    updateStatus(IStatus.ERROR, MSG_EMPTY);
                }
            } else {
                if (!maxtxt.equals("") || !bintxt.equals("")) {
                    // $NON-NLS-1$ //$NON-NLS-2$
                    updateStatus(IStatus.ERROR, MSG_EMPTY);
                } else {
                    updateStatus(IStatus.OK, UIMessages.MSG_INDICATOR_WIZARD);
                }
            }
        }
    });
    maxValue.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            String mintxt = minValue.getText();
            String maxtxt = maxValue.getText();
            String bintxt = numbOfBins.getText();
            if (maxtxt != "") {
                // $NON-NLS-1$
                if (!CheckValueUtils.isRealNumberValue(maxtxt)) {
                    updateStatus(IStatus.ERROR, MSG_ONLY_REAL_NUMBER);
                } else if (!mintxt.equals("") && CheckValueUtils.isAoverB(mintxt, maxtxt)) {
                    // $NON-NLS-1$
                    updateStatus(IStatus.ERROR, UIMessages.MSG_LOWER_LESS_HIGHER);
                } else if (!mintxt.equals("") && !bintxt.equals("")) {
                    // $NON-NLS-1$ //$NON-NLS-2$
                    updateStatus(IStatus.OK, MSG_OK);
                } else {
                    updateStatus(IStatus.ERROR, MSG_EMPTY);
                }
            } else {
                if (!mintxt.equals("") || !bintxt.equals("")) {
                    // $NON-NLS-1$ //$NON-NLS-2$
                    updateStatus(IStatus.ERROR, MSG_EMPTY);
                } else {
                    updateStatus(IStatus.OK, UIMessages.MSG_INDICATOR_WIZARD);
                }
            }
        }
    });
    numbOfBins.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            String mintxt = minValue.getText();
            String maxtxt = maxValue.getText();
            String numbtxt = numbOfBins.getText();
            if (numbtxt != "") {
                // $NON-NLS-1$
                if (!CheckValueUtils.isNumberValue(numbtxt)) {
                    updateStatus(IStatus.ERROR, MSG_ONLY_NUMBER);
                } else if (!mintxt.equals("") && !maxtxt.equals("")) {
                    // $NON-NLS-1$ //$NON-NLS-2$
                    updateStatus(IStatus.OK, MSG_OK);
                } else {
                    updateStatus(IStatus.ERROR, MSG_EMPTY);
                }
            } else {
                if (!mintxt.equals("") || !maxtxt.equals("")) {
                    // $NON-NLS-1$ //$NON-NLS-2$
                    updateStatus(IStatus.ERROR, MSG_EMPTY);
                } else {
                    updateStatus(IStatus.OK, UIMessages.MSG_INDICATOR_WIZARD);
                }
            }
        }
    });
    isSetRange.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            boolean flag = ((Button) e.getSource()).getSelection();
            boolean validSelect = !CheckValueUtils.isEmpty(numbOfBins.getText(), minValue.getText(), maxValue.getText());
            if (flag && validSelect) {
                addSlice.setEnabled(true);
                delSlice.setEnabled(true);
                minValue.setEnabled(false);
                maxValue.setEnabled(false);
                numbOfBins.setEnabled(false);
                int numb = Integer.parseInt(numbOfBins.getText());
                double min = Double.parseDouble(minValue.getText());
                double max = Double.parseDouble(maxValue.getText());
                // $NON-NLS-1$
                Domain customerDomin = DomainHelper.createContiguousClosedBinsIntoDomain("", numb, min, max);
                tableViewer.setInput(customerDomin.getRanges());
            } else {
                addSlice.setEnabled(false);
                delSlice.setEnabled(false);
                minValue.setEnabled(true);
                maxValue.setEnabled(true);
                numbOfBins.setEnabled(true);
                // $NON-NLS-1$
                tableViewer.setInput("");
            }
        }
    });
    addSlice.addSelectionListener(new SelectionAdapter() {

        @SuppressWarnings("unchecked")
        @Override
        public void widgetSelected(SelectionEvent e) {
            if (tableViewer.getInput() instanceof List) {
                List<RangeRestriction> inputList = (List<RangeRestriction>) tableViewer.getInput();
                // create a default range restriction, the min = 0, the max = 0
                RangeRestriction newRange = DomainHelper.createRealRangeRestriction(0, 0);
                inputList.add(newRange);
                tableViewer.setInput(inputList);
            }
        }
    });
    delSlice.addSelectionListener(new SelectionAdapter() {

        @SuppressWarnings("unchecked")
        @Override
        public void widgetSelected(SelectionEvent e) {
            boolean flag = !tableViewer.getSelection().isEmpty();
            if (flag) {
                IStructuredSelection selection = (IStructuredSelection) tableViewer.getSelection();
                RangeRestriction range = (RangeRestriction) selection.getFirstElement();
                if (tableViewer.getInput() instanceof List) {
                    List<RangeRestriction> inputList = (List<RangeRestriction>) tableViewer.getInput();
                    inputList.remove(range);
                    tableViewer.setInput(inputList);
                }
            }
        }
    });
}
Also used : ModifyEvent(org.eclipse.swt.events.ModifyEvent) ModifyListener(org.eclipse.swt.events.ModifyListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) EList(org.eclipse.emf.common.util.EList) List(java.util.List) RangeRestriction(org.talend.dataquality.domain.RangeRestriction) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Domain(org.talend.dataquality.domain.Domain)

Example 14 with RangeRestriction

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

the class IndicatorHelper method getDataThreshold.

/**
 * Method "getDataThreshold".
 *
 * @param parameters
 * @return an array with two elements. returns null when no threshold has been found. One element of the array can
 * be null but not both. In this case, it means that there is only one defined threshold, either the upper or the
 * lower threshold.
 */
public static String[] getDataThreshold(IndicatorParameters parameters) {
    Domain validDomain = parameters.getDataValidDomain();
    if (validDomain == null) {
        return null;
    }
    EList<RangeRestriction> ranges = validDomain.getRanges();
    if (ranges.size() != 1) {
        // log.warn("Data threshold contain too many ranges (or no range): " + ranges.size() + " range(s).");
        return null;
    }
    RangeRestriction rangeRestriction = ranges.get(0);
    if (rangeRestriction == null) {
        return new String[] { null, null };
    }
    return new String[] { DomainHelper.getMinValue(rangeRestriction), DomainHelper.getMaxValue(rangeRestriction) };
}
Also used : RangeRestriction(org.talend.dataquality.domain.RangeRestriction) Domain(org.talend.dataquality.domain.Domain)

Example 15 with RangeRestriction

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

the class IndicatorHelper method getIndicatorThreshold.

private static String[] getIndicatorThreshold(IndicatorParameters parameters, ThresholdType thresholdType) {
    Domain validDomain = parameters.getIndicatorValidDomain();
    if (validDomain == null) {
        return null;
    }
    EList<RangeRestriction> ranges = validDomain.getRanges();
    for (RangeRestriction rangeRestriction : ranges) {
        if (thresholdType.getLabel().equals(rangeRestriction.getName())) {
            return new String[] { DomainHelper.getMinValue(rangeRestriction), DomainHelper.getMaxValue(rangeRestriction) };
        }
    }
    return null;
}
Also used : RangeRestriction(org.talend.dataquality.domain.RangeRestriction) Domain(org.talend.dataquality.domain.Domain)

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