Search in sources :

Example 16 with AnalysisRepNode

use of org.talend.dq.nodes.AnalysisRepNode in project tdq-studio-se by Talend.

the class CreateDuplicatesAnalysisAction method run.

@Override
public void run() {
    ReturnCode success = new ReturnCode(true);
    if (this.getColumnsMap() == null || this.getColumnsMap().isEmpty() || this.getConnection() == null) {
        return;
    }
    try {
        Set<ColumnSet> keySet = this.getColumnsMap().keySet();
        for (ColumnSet cs : keySet) {
            List<TdColumn> columns = this.getColumnsMap().get(cs);
            // create the analysis
            Analysis analysis = null;
            AnalysisBuilder analysisBuilder = new AnalysisBuilder();
            boolean analysisInitialized = analysisBuilder.initializeAnalysis(getAnalysisName(cs), AnalysisType.MULTIPLE_COLUMN);
            if (analysisInitialized) {
                analysis = analysisBuilder.getAnalysis();
            }
            fillMetadataToAnalysis(analysis, createDefaultAnalysisParameter(cs));
            // add Connection into the Analysis Context
            analysis.getContext().setConnection(this.getConnection());
            for (TdColumn theColumn : columns) {
                // add TdColumn into the Analysis Context
                analysis.getContext().getAnalysedElements().add(theColumn);
                // create Row Count Indicator
                RowCountIndicator rcIndicator = IndicatorsFactory.eINSTANCE.createRowCountIndicator();
                rcIndicator.setAnalyzedElement(theColumn);
                DefinitionHandler.getInstance().setDefaultIndicatorDefinition(rcIndicator);
                analysis.getResults().getIndicators().add(rcIndicator);
                // create Duplicate Count Indicator
                DuplicateCountIndicator dcIndicator = IndicatorsFactory.eINSTANCE.createDuplicateCountIndicator();
                dcIndicator.setAnalyzedElement(theColumn);
                DefinitionHandler.getInstance().setDefaultIndicatorDefinition(dcIndicator);
                analysis.getResults().getIndicators().add(dcIndicator);
            }
            // create dependencies
            DependenciesHandler.getInstance().setDependencyOn(analysis, this.getConnection());
            // set the domain
            for (Domain domain : analysis.getParameters().getDataFilter()) {
                domain.setName(analysis.getName());
            }
            // set execution language
            analysis.getParameters().setExecutionLanguage(ExecutionLanguage.SQL);
            // save the analysis
            RepositoryNode analysisRepNode = (RepositoryNode) RepositoryNodeHelper.getDataProfilingFolderNode(EResourceConstant.ANALYSIS);
            IFolder folder = WorkbenchUtils.getFolder(analysisRepNode);
            AnalysisWriter analysisWriter = ElementWriterFactory.getInstance().createAnalysisWrite();
            TypedReturnCode<Object> create = analysisWriter.create(analysis, folder);
            if (create.isOk()) {
                // refresh the RepositoryView
                CorePlugin.getDefault().refreshDQView(analysisRepNode);
                // open the editor
                AnalysisRepNode anaRepNode = RepositoryNodeHelper.recursiveFindAnalysis(analysis);
                AnalysisItemEditorInput analysisEditorInput = new AnalysisItemEditorInput(anaRepNode);
                IRepositoryNode connectionRepNode = RepositoryNodeHelper.recursiveFind(this.getConnection());
                analysisEditorInput.setConnectionNode(connectionRepNode);
                CorePlugin.getDefault().openEditor(analysisEditorInput, AnalysisEditor.class.getName());
            } else {
                success.setOk(false);
                success.setMessage(create.getMessage());
            }
        }
    // for
    } catch (Exception e) {
        success.setOk(false);
        success.setMessage(e.getMessage());
    }
    if (!success.isOk()) {
        MessageUI.openError(success.getMessage());
    }
}
Also used : DuplicateCountIndicator(org.talend.dataquality.indicators.DuplicateCountIndicator) TypedReturnCode(org.talend.utils.sugars.TypedReturnCode) ReturnCode(org.talend.utils.sugars.ReturnCode) IRepositoryNode(org.talend.repository.model.IRepositoryNode) ColumnSet(orgomg.cwm.resource.relational.ColumnSet) RepositoryNode(org.talend.repository.model.RepositoryNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode) TdColumn(org.talend.cwm.relational.TdColumn) AnalysisRepNode(org.talend.dq.nodes.AnalysisRepNode) Analysis(org.talend.dataquality.analysis.Analysis) AnalysisBuilder(org.talend.dq.analysis.AnalysisBuilder) RowCountIndicator(org.talend.dataquality.indicators.RowCountIndicator) AnalysisItemEditorInput(org.talend.dataprofiler.core.ui.editor.analysis.AnalysisItemEditorInput) Domain(org.talend.dataquality.domain.Domain) AnalysisEditor(org.talend.dataprofiler.core.ui.editor.analysis.AnalysisEditor) AnalysisWriter(org.talend.dq.writer.impl.AnalysisWriter) IFolder(org.eclipse.core.resources.IFolder)

Example 17 with AnalysisRepNode

use of org.talend.dq.nodes.AnalysisRepNode in project tdq-studio-se by Talend.

the class DuplicateAction method selectAndReveal.

/**
 * DOC bZhou Comment method "selectAndReveal".
 *
 * Selects and reveals the newly added resource in all parts of the active workbench window's active page.
 *
 * @param newLabel
 *
 * @param duplicateObject
 * @throws BusinessException
 */
private void selectAndReveal(String newLabel, Item duplicateItem) throws BusinessException {
    IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    IWorkbenchPage page = workbenchWindow.getActivePage();
    IWorkbenchPart activePart = page.getActivePart();
    RepositoryNode recursiveFind = null;
    recursiveFind = getSelctionNode(newLabel, duplicateItem.getProperty());
    if (recursiveFind != null) {
        if (recursiveFind instanceof AnalysisRepNode || recursiveFind instanceof AnalysisSubFolderRepNode || recursiveFind instanceof ReportRepNode || recursiveFind instanceof ReportSubFolderRepNode) {
            CorePlugin.getDefault().refreshDQView(RepositoryNodeHelper.findNearestSystemFolderNode(recursiveFind));
        } else {
            CorePlugin.getDefault().refreshDQView(recursiveFind.getParent());
            refreshHiveConnectionParent(recursiveFind);
        }
        // MOD qiongli TDQ-5391 Avoid 'recursiveFind' to casue NPE .
        if (activePart instanceof ISetSelectionTarget) {
            ISelection selection = new StructuredSelection(recursiveFind);
            ((ISetSelectionTarget) activePart).selectReveal(selection);
        }
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) AnalysisRepNode(org.talend.dq.nodes.AnalysisRepNode) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) ReportRepNode(org.talend.dq.nodes.ReportRepNode) ISelection(org.eclipse.jface.viewers.ISelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) ISetSelectionTarget(org.eclipse.ui.part.ISetSelectionTarget) RepositoryNode(org.talend.repository.model.RepositoryNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode) ReportSubFolderRepNode(org.talend.dq.nodes.ReportSubFolderRepNode) AnalysisSubFolderRepNode(org.talend.dq.nodes.AnalysisSubFolderRepNode)

Aggregations

AnalysisRepNode (org.talend.dq.nodes.AnalysisRepNode)17 IRepositoryNode (org.talend.repository.model.IRepositoryNode)10 ReportAnalysisRepNode (org.talend.dq.nodes.ReportAnalysisRepNode)8 ReportRepNode (org.talend.dq.nodes.ReportRepNode)6 RepositoryNode (org.talend.repository.model.RepositoryNode)6 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)5 Analysis (org.talend.dataquality.analysis.Analysis)5 PatternRepNode (org.talend.dq.nodes.PatternRepNode)5 DBTableRepNode (org.talend.dq.nodes.DBTableRepNode)4 DBViewRepNode (org.talend.dq.nodes.DBViewRepNode)4 DFConnectionRepNode (org.talend.dq.nodes.DFConnectionRepNode)4 DQRepositoryNode (org.talend.dq.nodes.DQRepositoryNode)4 RuleRepNode (org.talend.dq.nodes.RuleRepNode)4 SysIndicatorDefinitionRepNode (org.talend.dq.nodes.SysIndicatorDefinitionRepNode)4 ENodeType (org.talend.repository.model.IRepositoryNode.ENodeType)4 IPath (org.eclipse.core.runtime.IPath)3 PersistenceException (org.talend.commons.exception.PersistenceException)3 ExchangeComponentRepNode (org.talend.dataprofiler.core.ui.exchange.ExchangeComponentRepNode)3 TDQAnalysisItem (org.talend.dataquality.properties.TDQAnalysisItem)3 DBCatalogRepNode (org.talend.dq.nodes.DBCatalogRepNode)3