Search in sources :

Example 6 with SurvivorShipAlgorithmEnum

use of org.talend.dataquality.record.linkage.utils.SurvivorShipAlgorithmEnum in project tdq-studio-se by Talend.

the class FunctionEditingSupport method getValue.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.jface.viewers.EditingSupport#getValue(java.lang.Object)
     */
@Override
protected Object getValue(Object element) {
    String talendDataType = ((ParticularDefaultSurvivorshipDefinitions) element).getDataType();
    String[] allShowTypes = getAllFunctionByDataTypes(talendDataType);
    SurvivorShipAlgorithmEnum typeBySavedValue = SurvivorShipAlgorithmEnum.getTypeBySavedValue(((ParticularDefaultSurvivorshipDefinitions) element).getFunction().getAlgorithmType());
    for (int index = 0; index < allShowTypes.length; index++) {
        if (typeBySavedValue.getValue().equals(allShowTypes[index])) {
            return index;
        }
    }
    return -1;
}
Also used : ParticularDefaultSurvivorshipDefinitions(org.talend.dataquality.rules.ParticularDefaultSurvivorshipDefinitions) SurvivorShipAlgorithmEnum(org.talend.dataquality.record.linkage.utils.SurvivorShipAlgorithmEnum)

Example 7 with SurvivorShipAlgorithmEnum

use of org.talend.dataquality.record.linkage.utils.SurvivorShipAlgorithmEnum in project tdq-studio-se by Talend.

the class FunctionEditingSupport method findEnumValue.

/**
 * Find enum value by data type of talend and index of function
 *
 * @param talendDataType like id_String or id_Boolean
 * @param functionTypeIndex the index of function which want to choose -1 mean that no funncion be choosed
 *
 * @return value of SurvivorShipAlgorithmEnum which choose else return default one(MostCommon)
 */
private SurvivorShipAlgorithmEnum findEnumValue(String talendDataType, int functionTypeIndex) {
    // One case about this issue is imported matchRule choose error functionType
    if (functionTypeIndex == -1) {
        return SurvivorShipAlgorithmEnum.MOST_COMMON;
    }
    String[] allFunctionByDataTypes = getAllFunctionByDataTypes(talendDataType);
    if (allFunctionByDataTypes.length == 0) {
        return SurvivorShipAlgorithmEnum.MOST_COMMON;
    }
    SurvivorShipAlgorithmEnum valueByIndex = SurvivorShipAlgorithmEnum.getTypeByValue(allFunctionByDataTypes[functionTypeIndex]);
    return valueByIndex;
}
Also used : SurvivorShipAlgorithmEnum(org.talend.dataquality.record.linkage.utils.SurvivorShipAlgorithmEnum)

Example 8 with SurvivorShipAlgorithmEnum

use of org.talend.dataquality.record.linkage.utils.SurvivorShipAlgorithmEnum in project tdq-studio-se by Talend.

the class FunctionEditingSupport method setValue.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.jface.viewers.EditingSupport#setValue(java.lang.Object, java.lang.Object)
     */
@Override
protected void setValue(Object element, Object value) {
    ParticularDefaultSurvivorshipDefinitions pdskd = ((ParticularDefaultSurvivorshipDefinitions) element);
    String talendDataType = ((ParticularDefaultSurvivorshipDefinitions) element).getDataType();
    int functionTypeIndex = Integer.valueOf(value.toString()).intValue();
    SurvivorShipAlgorithmEnum valueByIndex = findEnumValue(talendDataType, functionTypeIndex);
    if (StringUtils.equals(pdskd.getFunction().getAlgorithmType(), valueByIndex.getComponentValueName())) {
        return;
    }
    pdskd.getFunction().setAlgorithmType(valueByIndex.getComponentValueName());
    if (!(isSurvivorShipAlgorithm(pdskd, SurvivorShipAlgorithmEnum.MOST_TRUSTED_SOURCE) || isSurvivorShipAlgorithm(pdskd, SurvivorShipAlgorithmEnum.CONCATENATE))) {
        pdskd.getFunction().setAlgorithmParameters(StringUtils.EMPTY);
        CellEditor[] cellEditors = this.getViewer().getCellEditors();
        if (cellEditors.length == 3) {
            cellEditors[2].setValue(StringUtils.EMPTY);
        }
    }
    this.getViewer().update(element, null);
}
Also used : ParticularDefaultSurvivorshipDefinitions(org.talend.dataquality.rules.ParticularDefaultSurvivorshipDefinitions) CellEditor(org.eclipse.jface.viewers.CellEditor) ComboBoxCellEditor(org.eclipse.jface.viewers.ComboBoxCellEditor) SurvivorShipAlgorithmEnum(org.talend.dataquality.record.linkage.utils.SurvivorShipAlgorithmEnum)

Example 9 with SurvivorShipAlgorithmEnum

use of org.talend.dataquality.record.linkage.utils.SurvivorShipAlgorithmEnum in project tdq-studio-se by Talend.

the class MatchAndSurvivorCellModifer 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) {
        MatchKeyAndSurvivorDefinition mkd = (MatchKeyAndSurvivorDefinition) ((TableItem) element).getData();
        String newValue = String.valueOf(value);
        MatchKeyDefinition matchKey = mkd.getMatchKey();
        if (MatchAnalysisConstant.HANDLE_NULL.equalsIgnoreCase(property)) {
            HandleNullEnum valueByIndex = HandleNullEnum.values()[Integer.valueOf(newValue)];
            if (StringUtils.equals(matchKey.getHandleNull(), valueByIndex.getValue())) {
                return;
            }
            matchKey.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(matchKey.getAlgorithm().getAlgorithmType(), valueByIndex.name())) {
                return;
            }
            matchKey.getAlgorithm().setAlgorithmType(valueByIndex.name());
            matchKey.getAlgorithm().setAlgorithmParameters(StringUtils.EMPTY);
            if (isMatcherType(mkd, AttributeMatcherType.EXACT)) {
                matchKey.setThreshold(1.0d);
            }
        } else if (MatchAnalysisConstant.CUSTOM_MATCHER.equalsIgnoreCase(property)) {
            if (StringUtils.equals(matchKey.getAlgorithm().getAlgorithmParameters(), newValue)) {
                return;
            }
            matchKey.getAlgorithm().setAlgorithmParameters(String.valueOf(value));
        } else if (MatchAnalysisConstant.CONFIDENCE_WEIGHT.equalsIgnoreCase(property)) {
            if (!org.apache.commons.lang.math.NumberUtils.isDigits(newValue)) {
                return;
            }
            if (matchKey.getConfidenceWeight() == Integer.valueOf(newValue).intValue()) {
                return;
            }
            matchKey.setConfidenceWeight(Integer.valueOf(newValue).intValue());
        } else if (MatchAnalysisConstant.MATCH_KEY_NAME.equalsIgnoreCase(property)) {
            if (StringUtils.equals(matchKey.getName(), newValue)) {
                return;
            }
            matchKey.setName(newValue);
            mkd.getSurvivorShipKey().setName(newValue);
        } else if (MatchAnalysisConstant.INPUT_COLUMN.equalsIgnoreCase(property)) {
            int idx = Integer.valueOf(newValue);
            if (columnList == null || columnList.isEmpty()) {
                return;
            }
            MetadataColumn metaColumn = columnList.get(idx);
            if (metaColumn == null) {
                return;
            }
            if (StringUtils.equals(metaColumn.getName(), newValue)) {
                return;
            }
            matchKey.setColumn(metaColumn.getName());
            mkd.getSurvivorShipKey().setColumn(metaColumn.getName());
            // added TDQ-9296, nodify the change to let the upper layer know this
            tableViewer.noticeColumnSelectChange();
        } else if (MatchAnalysisConstant.THRESHOLD.equalsIgnoreCase(property)) {
            if (!org.apache.commons.lang.math.NumberUtils.isNumber(newValue)) {
                return;
            }
            if (matchKey.getThreshold() == Double.parseDouble(newValue)) {
                return;
            }
            try {
                matchKey.setThreshold(Double.parseDouble(newValue));
            } catch (NumberFormatException e) {
            // revert user change at here so don't need do anything
            }
        } else if (MatchAnalysisConstant.FUNCTION.equalsIgnoreCase(property)) {
            SurvivorShipAlgorithmEnum valueByIndex = SurvivorShipAlgorithmEnum.getTypeByIndex(Integer.valueOf(newValue).intValue());
            if (StringUtils.equals(mkd.getSurvivorShipKey().getFunction().getAlgorithmType(), valueByIndex.getComponentValueName())) {
                return;
            }
            mkd.getSurvivorShipKey().getFunction().setAlgorithmType(valueByIndex.getComponentValueName());
            if (!(isSurvivorShipAlgorithm(mkd, SurvivorShipAlgorithmEnum.MOST_TRUSTED_SOURCE) | (isSurvivorShipAlgorithm(mkd, SurvivorShipAlgorithmEnum.CONCATENATE)))) {
                mkd.getSurvivorShipKey().getFunction().setAlgorithmParameters(StringUtils.EMPTY);
            // MOD mzhao 2014-7-22 there will be an exception here, when switching the surv functions. Confirmed
            // with haibo (MDM team), removed this code.
            // CellEditor[] cellEditors = tableViewer.getCellEditors();
            // if (cellEditors.length == 9) {
            // cellEditors[7].setValue(StringUtils.EMPTY);
            // }
            }
        } else if (MatchAnalysisConstant.PARAMETER.equalsIgnoreCase(property)) {
            mkd.getSurvivorShipKey().getFunction().setAlgorithmParameters(newValue);
        } else if (MatchAnalysisConstant.TOKENIZATION_TYPE.equalsIgnoreCase(property)) {
            TokenizedResolutionMethod valueByIndex = TokenizedResolutionMethod.values()[Integer.valueOf(newValue)];
            if (StringUtils.equals(mkd.getMatchKey().getTokenizationType(), valueByIndex.getComponentValue())) {
                return;
            }
            mkd.getMatchKey().setTokenizationType(valueByIndex.getComponentValue());
        } else {
            return;
        }
        tableViewer.update(mkd, null);
    }
}
Also used : MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) 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) SurvivorShipAlgorithmEnum(org.talend.dataquality.record.linkage.utils.SurvivorShipAlgorithmEnum) MatchKeyAndSurvivorDefinition(org.talend.dataquality.record.linkage.ui.composite.tableviewer.definition.MatchKeyAndSurvivorDefinition) HandleNullEnum(org.talend.dataquality.record.linkage.utils.HandleNullEnum)

Aggregations

SurvivorShipAlgorithmEnum (org.talend.dataquality.record.linkage.utils.SurvivorShipAlgorithmEnum)9 TableItem (org.eclipse.swt.widgets.TableItem)4 DefaultSurvivorShipDataTypeEnum (org.talend.dataquality.record.linkage.utils.DefaultSurvivorShipDataTypeEnum)3 ParticularDefaultSurvivorshipDefinitions (org.talend.dataquality.rules.ParticularDefaultSurvivorshipDefinitions)3 MetadataColumn (org.talend.core.model.metadata.builder.connection.MetadataColumn)2 CellEditor (org.eclipse.jface.viewers.CellEditor)1 ComboBoxCellEditor (org.eclipse.jface.viewers.ComboBoxCellEditor)1 AttributeMatcherType (org.talend.dataquality.record.linkage.constant.AttributeMatcherType)1 TokenizedResolutionMethod (org.talend.dataquality.record.linkage.constant.TokenizedResolutionMethod)1 MatchKeyAndSurvivorDefinition (org.talend.dataquality.record.linkage.ui.composite.tableviewer.definition.MatchKeyAndSurvivorDefinition)1 HandleNullEnum (org.talend.dataquality.record.linkage.utils.HandleNullEnum)1 AlgorithmDefinition (org.talend.dataquality.rules.AlgorithmDefinition)1 DefaultSurvivorshipDefinition (org.talend.dataquality.rules.DefaultSurvivorshipDefinition)1 MatchKeyDefinition (org.talend.dataquality.rules.MatchKeyDefinition)1 SurvivorshipKeyDefinition (org.talend.dataquality.rules.SurvivorshipKeyDefinition)1