Search in sources :

Example 1 with ColumnsCompareIndicator

use of org.talend.dataquality.indicators.columnset.ColumnsCompareIndicator in project tdq-studio-se by Talend.

the class ChangeConnectionAction method synAnalyzedElements.

private boolean synAnalyzedElements(AnalyzedElementSynDialog anaEleSynDialog, Analysis synAnalysis, Connection oldDataProvider, Connection newDataProv) {
    // Change connection uuid.
    Map<ModelElement, ModelElement> synEleMap = anaEleSynDialog == null ? null : anaEleSynDialog.getSynedEleMap();
    AnalysisBuilder anaBuilder = new AnalysisBuilder();
    anaBuilder.setAnalysis(synAnalysis);
    // Remove old dependencies.
    boolean isRemovedDependency = DependenciesHandler.getInstance().removeConnDependencyAndSave(analysisItem);
    if (!isRemovedDependency) {
        return false;
    }
    synAnalysis.getContext().setConnection(newDataProv);
    // Synchronize analysis result.
    EList<Indicator> indcList = synAnalysis.getResults().getIndicators();
    Indicator[] copiedIndArray = new Indicator[indcList.size()];
    System.arraycopy(indcList.toArray(), 0, copiedIndArray, 0, indcList.size());
    // MOD qiongli 2010-6-13,bug 12766:To column analysis, which has same
    // construct connection with before and maybe have not indicator
    boolean isExistSynedElement = false;
    AnalysisType analysisType = synAnalysis.getParameters().getAnalysisType();
    if (analysisType == AnalysisType.MULTIPLE_COLUMN) {
        EList<ModelElement> meLs = synAnalysis.getContext().getAnalysedElements();
        ModelElement[] mes = new ModelElement[meLs.size()];
        System.arraycopy(meLs.toArray(), 0, mes, 0, meLs.size());
        synAnalysis.getContext().getAnalysedElements().clear();
        for (ModelElement me : mes) {
            if (synEleMap != null && synEleMap.get(me) != null) {
                TdColumn newColumn = (TdColumn) synEleMap.get(me);
                synAnalysis.getContext().getAnalysedElements().add(newColumn);
                isExistSynedElement = true;
            }
        }
    }
    if (!isExistSynedElement) {
        synAnalysis.getContext().getAnalysedElements().clear();
    }
    // ~
    synAnalysis.getResults().getIndicators().clear();
    for (Indicator indicator : copiedIndArray) {
        // connection.
        if (indicator instanceof ColumnSetMultiValueIndicator) {
            ColumnSetMultiValueIndicator compositeInd = (ColumnSetMultiValueIndicator) indicator;
            ModelElement[] mes = new ModelElement[compositeInd.getAnalyzedColumns().size()];
            ((ColumnSetMultiValueIndicator) indicator).getAnalyzedColumns().toArray(mes);
            compositeInd.getAnalyzedColumns().clear();
            for (ModelElement me : mes) {
                if (synEleMap != null && synEleMap.get(me) != null) {
                    TdColumn newColumn = (TdColumn) synEleMap.get(me);
                    DataminingType dataminingType = MetadataHelper.getDataminingType((TdColumn) me);
                    if (dataminingType == null) {
                        dataminingType = MetadataHelper.getDefaultDataminingType(((TdColumn) me).getSqlDataType().getJavaDataType());
                    }
                    MetadataHelper.setDataminingType(dataminingType, newColumn);
                    compositeInd.getAnalyzedColumns().add(newColumn);
                    anaBuilder.addElementToAnalyze(newColumn, indicator);
                    isExistSynedElement = true;
                }
            }
        } else if (indicator instanceof ColumnsCompareIndicator) {
            // Correlation compare
            ColumnsCompareIndicator compInd = (ColumnsCompareIndicator) indicator;
            if ((compInd.getColumnSetA() == null || compInd.getColumnSetA().size() == 0) || (compInd.getColumnSetB() == null || compInd.getColumnSetB().size() == 0)) {
                return false;
            }
            // Column set(Columns)
            ModelElement[] mesA = new ModelElement[compInd.getColumnSetA().size()];
            compInd.getColumnSetA().toArray(mesA);
            compInd.getColumnSetA().clear();
            for (ModelElement me : mesA) {
                if (synEleMap != null && synEleMap.get(me) != null) {
                    TdColumn newColumn = (TdColumn) synEleMap.get(me);
                    compInd.getColumnSetA().add(newColumn);
                    anaBuilder.addElementToAnalyze(newColumn, indicator);
                    isExistSynedElement = true;
                }
            }
            ModelElement[] mesB = new ModelElement[compInd.getColumnSetB().size()];
            compInd.getColumnSetB().toArray(mesB);
            compInd.getColumnSetB().clear();
            for (ModelElement me : mesB) {
                if (synEleMap != null && synEleMap.get(me) != null) {
                    TdColumn newColumn = (TdColumn) synEleMap.get(me);
                    compInd.getColumnSetB().add(newColumn);
                    anaBuilder.addElementToAnalyze(newColumn, indicator);
                    isExistSynedElement = true;
                }
            }
            // Analyzed element(Table)
            ModelElement oldAnaEle = compInd.getAnalyzedElement();
            compInd.setAnalyzedElement(null);
            ColumnSet oldColSetA = ColumnHelper.getColumnOwnerAsColumnSet(mesA[0]);
            ColumnSet oldColSetB = ColumnHelper.getColumnOwnerAsColumnSet(mesB[0]);
            if (oldColSetA == oldAnaEle) {
                if (synEleMap != null && synEleMap.get(mesA[0]) != null) {
                    compInd.setAnalyzedElement(ColumnHelper.getColumnOwnerAsColumnSet(synEleMap.get(mesA[0])));
                }
            }
            if (oldColSetB == oldAnaEle) {
                if (synEleMap != null && synEleMap.get(mesB[0]) != null) {
                    compInd.setAnalyzedElement(ColumnHelper.getColumnOwnerAsColumnSet(synEleMap.get(mesB[0])));
                }
            }
        } else if (indicator instanceof ColumnDependencyIndicator) {
            // ADD qiongli bug 0012766
            // Functional Dependency indicator
            ColumnDependencyIndicator funDepInd = (ColumnDependencyIndicator) indicator;
            if (funDepInd.getColumnA() == null || funDepInd.getColumnB() == null) {
                return false;
            }
            // Column A
            if (synEleMap != null && synEleMap.get(funDepInd.getColumnA()) != null) {
                TdColumn newColumn = (TdColumn) synEleMap.get(funDepInd.getColumnA());
                funDepInd.setColumnA(newColumn);
                anaBuilder.addElementToAnalyze(newColumn, indicator);
                isExistSynedElement = true;
            }
            // Column B
            if (synEleMap != null && synEleMap.get(funDepInd.getColumnB()) != null) {
                TdColumn newColumn = (TdColumn) synEleMap.get(funDepInd.getColumnB());
                funDepInd.setColumnB(newColumn);
                anaBuilder.addElementToAnalyze(newColumn, indicator);
                isExistSynedElement = true;
            }
            // Analyzed element(Table)
            ModelElement oldAnaEle = funDepInd.getAnalyzedElement();
            funDepInd.setAnalyzedElement(null);
            ColumnSet oldColSetA = ColumnHelper.getColumnOwnerAsColumnSet(funDepInd.getColumnA());
            ColumnSet oldColSetB = ColumnHelper.getColumnOwnerAsColumnSet(funDepInd.getColumnB());
            if (oldColSetA == oldAnaEle) {
                if (synEleMap != null && synEleMap.get(funDepInd.getColumnA()) != null) {
                    funDepInd.setAnalyzedElement(ColumnHelper.getColumnOwnerAsColumnSet(synEleMap.get(funDepInd.getColumnA())));
                }
            }
            if (oldColSetB == oldAnaEle) {
                if (synEleMap != null && synEleMap.get(funDepInd.getColumnB()) != null) {
                    funDepInd.setAnalyzedElement(ColumnHelper.getColumnOwnerAsColumnSet(synEleMap.get(funDepInd.getColumnB())));
                }
            }
        } else {
            ModelElement me = indicator.getAnalyzedElement();
            if (synEleMap != null && synEleMap.get(me) != null) {
                indicator.setAnalyzedElement(synEleMap.get(me));
                if (analysisType == AnalysisType.MULTIPLE_COLUMN) {
                    synAnalysis.getResults().getIndicators().add(indicator);
                } else {
                    anaBuilder.addElementToAnalyze(synEleMap.get(me), indicator);
                }
                isExistSynedElement = true;
            }
        }
    }
    return isExistSynedElement;
}
Also used : AnalysisType(org.talend.dataquality.analysis.AnalysisType) ColumnDependencyIndicator(org.talend.dataquality.indicators.columnset.ColumnDependencyIndicator) ColumnSet(orgomg.cwm.resource.relational.ColumnSet) ColumnSetMultiValueIndicator(org.talend.dataquality.indicators.columnset.ColumnSetMultiValueIndicator) ColumnSetMultiValueIndicator(org.talend.dataquality.indicators.columnset.ColumnSetMultiValueIndicator) ColumnsCompareIndicator(org.talend.dataquality.indicators.columnset.ColumnsCompareIndicator) Indicator(org.talend.dataquality.indicators.Indicator) ColumnDependencyIndicator(org.talend.dataquality.indicators.columnset.ColumnDependencyIndicator) DataminingType(org.talend.dataquality.indicators.DataminingType) ModelElement(orgomg.cwm.objectmodel.core.ModelElement) TdColumn(org.talend.cwm.relational.TdColumn) ColumnsCompareIndicator(org.talend.dataquality.indicators.columnset.ColumnsCompareIndicator) AnalysisBuilder(org.talend.dq.analysis.AnalysisBuilder)

Aggregations

TdColumn (org.talend.cwm.relational.TdColumn)1 AnalysisType (org.talend.dataquality.analysis.AnalysisType)1 DataminingType (org.talend.dataquality.indicators.DataminingType)1 Indicator (org.talend.dataquality.indicators.Indicator)1 ColumnDependencyIndicator (org.talend.dataquality.indicators.columnset.ColumnDependencyIndicator)1 ColumnSetMultiValueIndicator (org.talend.dataquality.indicators.columnset.ColumnSetMultiValueIndicator)1 ColumnsCompareIndicator (org.talend.dataquality.indicators.columnset.ColumnsCompareIndicator)1 AnalysisBuilder (org.talend.dq.analysis.AnalysisBuilder)1 ModelElement (orgomg.cwm.objectmodel.core.ModelElement)1 ColumnSet (orgomg.cwm.resource.relational.ColumnSet)1