Search in sources :

Example 1 with MatchRuleElementTreeSelectionDialog

use of org.talend.dataprofiler.core.ui.dialog.MatchRuleElementTreeSelectionDialog in project tdq-studio-se by Talend.

the class ImportMatchRuleAction method run.

@Override
public void run() {
    MatchRuleElementTreeSelectionDialog dialog = new MatchRuleElementTreeSelectionDialog(null, new DQRepositoryViewLabelProvider(), new ResourceViewContentProvider(), MatchRuleElementTreeSelectionDialog.MATCH_ANALYSIS_TYPE);
    List<String> inputColumnNames = new ArrayList<String>();
    Map<String, String> columnName2Type = new HashMap<String, String>();
    Analysis analysis = masterPage.getCurrentModelElement();
    EList<ModelElement> elements = analysis.getContext().getAnalysedElements();
    for (ModelElement me : elements) {
        inputColumnNames.add(me.getName());
        if (me instanceof MetadataColumn) {
            columnName2Type.put(me.getName(), ((MetadataColumn) me).getTalendType());
        }
    }
    dialog.setInputColumnNames(inputColumnNames);
    dialog.setColumnName2Type(columnName2Type);
    AnalysisResult anaResults = analysis.getResults();
    if (anaResults != null) {
        for (Indicator ind : anaResults.getIndicators()) {
            if (ind != null && ind instanceof RecordMatchingIndicator) {
                RecordMatchingIndicator rmInd = (RecordMatchingIndicator) ind;
                MatchRuleDefinition builtInMatchRuleDefinition = rmInd.getBuiltInMatchRuleDefinition();
                if (builtInMatchRuleDefinition != null) {
                    if (builtInMatchRuleDefinition.getBlockKeys() != null && builtInMatchRuleDefinition.getBlockKeys().size() > 0) {
                        List<String> blockKeyName = new ArrayList<String>();
                        for (BlockKeyDefinition blockKey : builtInMatchRuleDefinition.getBlockKeys()) {
                            blockKeyName.add(blockKey.getName());
                        }
                        dialog.setCurrentAnaBlockKeys(blockKeyName);
                    }
                    List<String> matchKeysName = new ArrayList<String>();
                    for (MatchRule matchRule : builtInMatchRuleDefinition.getMatchRules()) {
                        EList<MatchKeyDefinition> matchKeys = matchRule.getMatchKeys();
                        for (MatchKeyDefinition mkd : matchKeys) {
                            // same
                            if (!matchKeysName.contains(mkd.getName())) {
                                matchKeysName.add(mkd.getName());
                            }
                        }
                    }
                    dialog.setAnalysisCurrentMatchKeys(matchKeysName);
                    List<String> pdsdKeysName = new ArrayList<String>();
                    for (ParticularDefaultSurvivorshipDefinitions pdsd : builtInMatchRuleDefinition.getParticularDefaultSurvivorshipDefinitions()) {
                        pdsdKeysName.add(pdsd.getColumn());
                    }
                    dialog.setAnalysisCurrentParticularColumns(pdsdKeysName);
                }
            }
        }
    }
    dialog.create();
    if (dialog.open() == Window.OK) {
        Object[] results = dialog.getResult();
        for (Object obj : results) {
            if (obj instanceof RuleRepNode) {
                RuleRepNode node = (RuleRepNode) obj;
                MatchRuleDefinition matchRule = (MatchRuleDefinition) node.getRule();
                if (matchRule != null) {
                    updateMatchRule(matchRule, dialog.isOverwrite());
                }
            }
        }
    }
}
Also used : ParticularDefaultSurvivorshipDefinitions(org.talend.dataquality.rules.ParticularDefaultSurvivorshipDefinitions) HashMap(java.util.HashMap) MatchRuleElementTreeSelectionDialog(org.talend.dataprofiler.core.ui.dialog.MatchRuleElementTreeSelectionDialog) ResourceViewContentProvider(org.talend.dataprofiler.core.ui.views.provider.ResourceViewContentProvider) ArrayList(java.util.ArrayList) MatchRuleDefinition(org.talend.dataquality.rules.MatchRuleDefinition) MatchRule(org.talend.dataquality.rules.MatchRule) RecordMatchingIndicator(org.talend.dataquality.indicators.columnset.RecordMatchingIndicator) RuleRepNode(org.talend.dq.nodes.RuleRepNode) AnalysisResult(org.talend.dataquality.analysis.AnalysisResult) RecordMatchingIndicator(org.talend.dataquality.indicators.columnset.RecordMatchingIndicator) Indicator(org.talend.dataquality.indicators.Indicator) ModelElement(orgomg.cwm.objectmodel.core.ModelElement) MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) Analysis(org.talend.dataquality.analysis.Analysis) BlockKeyDefinition(org.talend.dataquality.rules.BlockKeyDefinition) MatchKeyDefinition(org.talend.dataquality.rules.MatchKeyDefinition) DQRepositoryViewLabelProvider(org.talend.dataprofiler.core.ui.views.provider.DQRepositoryViewLabelProvider)

Aggregations

ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 MetadataColumn (org.talend.core.model.metadata.builder.connection.MetadataColumn)1 MatchRuleElementTreeSelectionDialog (org.talend.dataprofiler.core.ui.dialog.MatchRuleElementTreeSelectionDialog)1 DQRepositoryViewLabelProvider (org.talend.dataprofiler.core.ui.views.provider.DQRepositoryViewLabelProvider)1 ResourceViewContentProvider (org.talend.dataprofiler.core.ui.views.provider.ResourceViewContentProvider)1 Analysis (org.talend.dataquality.analysis.Analysis)1 AnalysisResult (org.talend.dataquality.analysis.AnalysisResult)1 Indicator (org.talend.dataquality.indicators.Indicator)1 RecordMatchingIndicator (org.talend.dataquality.indicators.columnset.RecordMatchingIndicator)1 BlockKeyDefinition (org.talend.dataquality.rules.BlockKeyDefinition)1 MatchKeyDefinition (org.talend.dataquality.rules.MatchKeyDefinition)1 MatchRule (org.talend.dataquality.rules.MatchRule)1 MatchRuleDefinition (org.talend.dataquality.rules.MatchRuleDefinition)1 ParticularDefaultSurvivorshipDefinitions (org.talend.dataquality.rules.ParticularDefaultSurvivorshipDefinitions)1 RuleRepNode (org.talend.dq.nodes.RuleRepNode)1 ModelElement (orgomg.cwm.objectmodel.core.ModelElement)1