Search in sources :

Example 11 with MatchKeyDefinition

use of org.talend.dataquality.rules.MatchKeyDefinition in project tdq-studio-se by Talend.

the class MatchingKeySection method checkAndRemoveEmptyMatchRule.

/**
 * check and remove empty match rule
 */
protected void checkAndRemoveEmptyMatchRule(CTabItem theTab) {
    MatchRuleTableComposite matchRuleTableComp = (MatchRuleTableComposite) getMatchRuleComposite(theTab);
    EList<MatchKeyDefinition> matchKeys = matchRuleTableComp.getMatchRule().getMatchKeys();
    if (matchKeys.size() <= 0) {
        getMatchRuleList().remove(matchRuleTableComp.getMatchRule());
    }
}
Also used : MatchRuleTableComposite(org.talend.dataquality.record.linkage.ui.composite.MatchRuleTableComposite) MatchKeyDefinition(org.talend.dataquality.rules.MatchKeyDefinition)

Example 12 with MatchKeyDefinition

use of org.talend.dataquality.rules.MatchKeyDefinition in project tdq-studio-se by Talend.

the class MatchingKeySection method removeTableItem.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.dataquality.record.linkage.ui.section.AbstractMatchAnaysisTableSection#removeTableItem()
     */
@Override
public void removeTableItem() {
    boolean success = false;
    ISelection selectItems = getCurrentMatchRuleTableComposite().getSelectItems();
    if (selectItems instanceof StructuredSelection) {
        Iterator<MatchKeyDefinition> iterator = ((StructuredSelection) selectItems).iterator();
        while (iterator.hasNext()) {
            MatchKeyDefinition next = iterator.next();
            removeMatchKeyFromCurrentMatchRule(next);
            success = true;
        }
        if (success) {
            listeners.firePropertyChange(MatchAnalysisConstant.ISDIRTY_PROPERTY, true, false);
            listeners.firePropertyChange(MatchAnalysisConstant.MATCH_RULE_TAB_SWITCH, true, false);
        }
    }
}
Also used : ISelection(org.eclipse.jface.viewers.ISelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) MatchKeyDefinition(org.talend.dataquality.rules.MatchKeyDefinition)

Example 13 with MatchKeyDefinition

use of org.talend.dataquality.rules.MatchKeyDefinition in project tdq-studio-se by Talend.

the class MatchingKeySection method checkResultStatus.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.dataquality.record.linkage.ui.section.AbstractMatchAnaysisTableSection#checkResultStatus()
     */
@Override
public ReturnCode checkResultStatus() {
    ReturnCode returnCode = new ReturnCode(false);
    if (!hasMatchKey(false)) {
        // $NON-NLS-1$
        returnCode.setMessage(DefaultMessagesImpl.getString("MatchMasterDetailsPage.NoMatchKey"));
        return returnCode;
    }
    List<String> uniqueNameList = new ArrayList<String>();
    for (MatchRule currentRule : getMatchRuleList()) {
        EList<MatchKeyDefinition> matchKeys = currentRule.getMatchKeys();
        for (MatchKeyDefinition mdk : matchKeys) {
            String currentName = mdk.getName();
            if (currentName.equals(StringUtils.EMPTY)) {
                returnCode.setMessage(DefaultMessagesImpl.getString("BlockingKeySection.emptyKeys.message", // $NON-NLS-1$ //$NON-NLS-2$
                getSectionName() + " , " + currentRule.getName()));
                return returnCode;
            }
            if (uniqueNameList.contains(currentName)) {
                returnCode.setMessage(DefaultMessagesImpl.getString("BlockingKeySection.duplicateKeys.message", // $NON-NLS-1$ //$NON-NLS-2$
                getSectionName() + "--" + currentName));
                return returnCode;
            }
            uniqueNameList.add(currentName);
            if (checkColumnNameIsEmpty(mdk)) {
                returnCode.setMessage(DefaultMessagesImpl.getString("BlockingKeySection.emptyColumn.message", // $NON-NLS-1$ //$NON-NLS-2$
                getSectionName() + " , " + currentRule.getName()));
                return returnCode;
            }
            if (// $NON-NLS-1$
            "CUSTOM".equals(mdk.getAlgorithm().getAlgorithmType()) && StringUtils.EMPTY.equals(mdk.getAlgorithm().getAlgorithmParameters().trim())) {
                returnCode.setMessage(DefaultMessagesImpl.getString("BlockingKeySection.invalidCustomAlgorithmError", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                getSectionName() + " , " + currentRule.getName() + " , " + currentName));
                return returnCode;
            }
            if (mdk.getConfidenceWeight() <= 0) {
                returnCode.setMessage(DefaultMessagesImpl.getString("BlockingKeySection.invalidConfidenceWeight.message", // $NON-NLS-1$
                getSectionName()));
                return returnCode;
            }
            ReturnCode checkSurvivorshipFunction = checkSurvivorshipFunction(mdk, this.getMatchRuleDefinition());
            if (!checkSurvivorshipFunction.isOk()) {
                returnCode.setMessage(// $NON-NLS-1$
                DefaultMessagesImpl.getString(// $NON-NLS-1$
                "MatchingKeySection.invalidSurvivorshipFunction", getSectionName(), checkSurvivorshipFunction.getMessage()));
                return returnCode;
            }
        }
    }
    returnCode.setOk(true);
    return returnCode;
}
Also used : TypedReturnCode(org.talend.utils.sugars.TypedReturnCode) ReturnCode(org.talend.utils.sugars.ReturnCode) ArrayList(java.util.ArrayList) MatchKeyDefinition(org.talend.dataquality.rules.MatchKeyDefinition) MatchRule(org.talend.dataquality.rules.MatchRule)

Example 14 with MatchKeyDefinition

use of org.talend.dataquality.rules.MatchKeyDefinition in project tdq-studio-se by Talend.

the class MatchingKeySection method importMatchRule.

/**
 * if overwrite: need to delete all current tabs, and create the tab according to the parameter:matchRule else: only
 * add the tab in the parameter matchrule, to the current matchrule.
 *
 * @param matchRuleDefinition
 * @param overwrite
 */
public void importMatchRule(MatchRuleDefinition matchRuleDefinition, boolean overwrite) {
    if (overwrite) {
        // delete all tab in UI
        CTabItem[] tabItems = ruleFolder.getItems();
        if (tabItems != null && tabItems.length > 0) {
            for (CTabItem oneTab : tabItems) {
                @SuppressWarnings("rawtypes") AbsMatchAnalysisTableComposite matchRuleTableComp = getMatchRuleComposite(oneTab);
                matchRuleTableComp.dispose();
                oneTab.dispose();
            }
        }
        // clear all survivorship keys
        getMatchRuleDefinition().getSurvivorshipKeys().clear();
        // clear all match rules in matchrule definition
        getMatchRuleDefinition().getMatchRules().clear();
        // overwrite the threshold
        groupQualityThresholdText.setText(String.valueOf(matchRuleDefinition.getMatchGroupQualityThreshold()));
    }
    // import survivorship keys
    for (SurvivorshipKeyDefinition skd : matchRuleDefinition.getSurvivorshipKeys()) {
        SurvivorshipKeyDefinition survivorshipKeyDefinition = EcoreUtil.copy(skd);
        setColumnValueIfMatch(survivorshipKeyDefinition);
        getMatchRuleDefinition().getSurvivorshipKeys().add(survivorshipKeyDefinition);
    }
    // create the tab from the parameter:matchRule
    for (MatchRule oneMatchRule : matchRuleDefinition.getMatchRules()) {
        MatchRule matchRule2 = createMatchRuleByCopy(oneMatchRule);
        // MOD msjian TDQ-8484: set the name of the match rule by the old name
        matchRule2.setName(oneMatchRule.getName());
        // if the key name= some column name, set the column to this key
        for (MatchKeyDefinition key : matchRule2.getMatchKeys()) {
            setColumnValueIfMatch(key);
        }
        // auto add the tab name order
        addRuleTab(false, matchRule2);
        getMatchRuleDefinition().getMatchRules().add(matchRule2);
    }
}
Also used : AbsMatchAnalysisTableComposite(org.talend.dataquality.record.linkage.ui.composite.AbsMatchAnalysisTableComposite) SurvivorshipKeyDefinition(org.talend.dataquality.rules.SurvivorshipKeyDefinition) MatchKeyDefinition(org.talend.dataquality.rules.MatchKeyDefinition) MatchRule(org.talend.dataquality.rules.MatchRule) CTabItem(org.eclipse.swt.custom.CTabItem)

Example 15 with MatchKeyDefinition

use of org.talend.dataquality.rules.MatchKeyDefinition in project tdq-studio-se by Talend.

the class MatchRuleCellModifier method modify.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.jface.viewers.ICellModifier#modify(java.lang.Object, java.lang.String, java.lang.Object)
     */
@Override
public void modify(Object element, String property, Object value) {
    if (element instanceof TableItem) {
        MatchKeyDefinition mkd = (MatchKeyDefinition) ((TableItem) element).getData();
        String newValue = String.valueOf(value);
        if (MatchAnalysisConstant.HANDLE_NULL.equalsIgnoreCase(property)) {
            HandleNullEnum valueByIndex = HandleNullEnum.values()[Integer.valueOf(newValue)];
            if (StringUtils.equals(mkd.getHandleNull(), valueByIndex.getValue())) {
                return;
            }
            mkd.setHandleNull(valueByIndex.getValue());
        } else if (MatchAnalysisConstant.MATCHING_TYPE.equalsIgnoreCase(property)) {
            int idx = Integer.valueOf(newValue);
            if (idx == AttributeMatcherType.DUMMY.ordinal()) {
                // The DUMMY algorithm is internal and does not exist in the combo lists of
                idx += 1;
            // MatchRuleItemEditor or MatchRuleAnalysisEditor. So we increment the index by 1 in order
            // to get the correct Matcher.
            }
            AttributeMatcherType valueByIndex = AttributeMatcherType.values()[idx];
            if (StringUtils.equals(mkd.getAlgorithm().getAlgorithmType(), valueByIndex.name())) {
                return;
            }
            mkd.getAlgorithm().setAlgorithmType(valueByIndex.name());
            mkd.getAlgorithm().setAlgorithmParameters(StringUtils.EMPTY);
        } else if (MatchAnalysisConstant.CUSTOM_MATCHER.equalsIgnoreCase(property)) {
            if (StringUtils.equals(mkd.getAlgorithm().getAlgorithmParameters(), newValue)) {
                return;
            }
            mkd.getAlgorithm().setAlgorithmParameters(String.valueOf(value));
        } else if (MatchAnalysisConstant.INPUT_COLUMN.equalsIgnoreCase(property)) {
            if (Integer.parseInt(newValue) == -1) {
                return;
            }
            String columnName = columnList.get(Integer.parseInt(newValue)).getName();
            if (StringUtils.equals(mkd.getColumn(), columnName)) {
                return;
            }
            mkd.setColumn(columnName);
            tableViewer.noticeColumnSelectChange();
        } else if (MatchAnalysisConstant.CONFIDENCE_WEIGHT.equalsIgnoreCase(property)) {
            if (!validIntegerType(newValue)) {
                return;
            }
            if (mkd.getConfidenceWeight() == Integer.valueOf(newValue).intValue()) {
                return;
            }
            mkd.setConfidenceWeight(Integer.valueOf(newValue).intValue());
        } else if (MatchAnalysisConstant.MATCH_KEY_NAME.equalsIgnoreCase(property)) {
            if (StringUtils.equals(mkd.getName(), newValue)) {
                return;
            }
            mkd.setName(newValue);
        } else if (MatchAnalysisConstant.THRESHOLD.equalsIgnoreCase(property)) {
            if (mkd.getThreshold() == Double.parseDouble(newValue)) {
                return;
            }
            try {
                mkd.setThreshold(Double.parseDouble(newValue));
            } catch (NumberFormatException e) {
            // revert user change at here so don't need do anything
            }
        } else if (MatchAnalysisConstant.TOKENIZATION_TYPE.equalsIgnoreCase(property)) {
            TokenizedResolutionMethod valueByIndex = TokenizedResolutionMethod.values()[Integer.valueOf(newValue)];
            if (StringUtils.equals(mkd.getTokenizationType(), valueByIndex.getComponentValue())) {
                return;
            }
            mkd.setTokenizationType(valueByIndex.getComponentValue());
        } else {
            return;
        }
        tableViewer.update(mkd, null);
    }
}
Also used : AttributeMatcherType(org.talend.dataquality.record.linkage.constant.AttributeMatcherType) TokenizedResolutionMethod(org.talend.dataquality.record.linkage.constant.TokenizedResolutionMethod) TableItem(org.eclipse.swt.widgets.TableItem) MatchKeyDefinition(org.talend.dataquality.rules.MatchKeyDefinition) HandleNullEnum(org.talend.dataquality.record.linkage.utils.HandleNullEnum)

Aggregations

MatchKeyDefinition (org.talend.dataquality.rules.MatchKeyDefinition)19 MatchRule (org.talend.dataquality.rules.MatchRule)12 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)7 AlgorithmDefinition (org.talend.dataquality.rules.AlgorithmDefinition)7 MetadataColumn (org.talend.core.model.metadata.builder.connection.MetadataColumn)6 MatchRuleDefinition (org.talend.dataquality.rules.MatchRuleDefinition)6 RecordMatchingIndicator (org.talend.dataquality.indicators.columnset.RecordMatchingIndicator)5 Test (org.junit.Test)4 BlockKeyIndicator (org.talend.dataquality.indicators.columnset.BlockKeyIndicator)4 MatchGroupResultConsumer (org.talend.dataquality.record.linkage.grouping.MatchGroupResultConsumer)4 BlockKeyDefinition (org.talend.dataquality.rules.BlockKeyDefinition)4 ExecuteMatchRuleHandler (org.talend.dq.analysis.match.ExecuteMatchRuleHandler)4 Map (java.util.Map)2 TableItem (org.eclipse.swt.widgets.TableItem)2 AttributeMatcherType (org.talend.dataquality.record.linkage.constant.AttributeMatcherType)2 TokenizedResolutionMethod (org.talend.dataquality.record.linkage.constant.TokenizedResolutionMethod)2 MatchKeyAndSurvivorDefinition (org.talend.dataquality.record.linkage.ui.composite.tableviewer.definition.MatchKeyAndSurvivorDefinition)2 HandleNullEnum (org.talend.dataquality.record.linkage.utils.HandleNullEnum)2 SurvivorshipKeyDefinition (org.talend.dataquality.rules.SurvivorshipKeyDefinition)2