Search in sources :

Example 91 with IndicatorDefinition

use of org.talend.dataquality.indicators.definition.IndicatorDefinition in project tdq-studio-se by Talend.

the class RemoveMDMFromIndicatorsTask method doExecute.

@Override
protected boolean doExecute() throws Exception {
    DefinitionHandler definitionHandler = DefinitionHandler.getInstance();
    // ROW COUNT
    IndicatorDefinition definition = definitionHandler.getDefinitionById(ROW_COUNT_UUID);
    if (definition != null) {
        IndicatorDefinitionFileHelper.removeSqlExpression(definition, LANGUAGE);
        IndicatorDefinitionFileHelper.save(definition);
    }
    definition = definitionHandler.getDefinitionById(NULL_COUNT_UUID);
    if (definition != null) {
        IndicatorDefinitionFileHelper.removeSqlExpression(definition, LANGUAGE);
        IndicatorDefinitionFileHelper.save(definition);
    }
    definition = definitionHandler.getDefinitionById(UNIQUE_COUNT_UUID);
    if (definition != null) {
        IndicatorDefinitionFileHelper.removeSqlExpression(definition, LANGUAGE);
        IndicatorDefinitionFileHelper.save(definition);
    }
    definition = definitionHandler.getDefinitionById(DISTINCT_COUNT_UUID);
    if (definition != null) {
        IndicatorDefinitionFileHelper.removeSqlExpression(definition, LANGUAGE);
        IndicatorDefinitionFileHelper.save(definition);
    }
    definition = definitionHandler.getDefinitionById(DUPLICATE_COUNT_UUID);
    if (definition != null) {
        IndicatorDefinitionFileHelper.removeSqlExpression(definition, LANGUAGE);
        IndicatorDefinitionFileHelper.save(definition);
    }
    return true;
}
Also used : DefinitionHandler(org.talend.dq.indicators.definitions.DefinitionHandler) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition)

Example 92 with IndicatorDefinition

use of org.talend.dataquality.indicators.definition.IndicatorDefinition in project tdq-studio-se by Talend.

the class AnalysisWriter method addDependencies.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.dq.writer.AElementPersistance#addDependencies(orgomg.cwm.objectmodel.core.ModelElement)
     */
@Override
public void addDependencies(ModelElement element) {
    Analysis analysis = (Analysis) element;
    List<IndicatorDefinition> udis = AnalysisHelper.getUserDefinedIndicators(analysis);
    try {
        for (IndicatorDefinition udi : udis) {
            if (udi == null) {
                continue;
            }
            InternalEObject iudi = (InternalEObject) udi;
            if (!iudi.eIsProxy()) {
                DQRepositoryNode recursiveFind = RepositoryNodeHelper.recursiveFind(udi);
                // only do save when the dependency is not reference project node
                if (recursiveFind != null && recursiveFind.getProject().isMainProject()) {
                    TypedReturnCode<Dependency> dependencyReturn = DependenciesHandler.getInstance().setDependencyOn(analysis, udi);
                    if (dependencyReturn.isOk()) {
                        Property property = PropertyHelper.getProperty(udi);
                        if (property != null) {
                            TDQItem udiItem = (TDQItem) property.getItem();
                            if (udiItem instanceof TDQIndicatorDefinitionItem) {
                                ((TDQIndicatorDefinitionItem) udiItem).setIndicatorDefinition(udi);
                            } else if (udiItem instanceof TDQBusinessRuleItem) {
                                ((TDQBusinessRuleItem) udiItem).setDqrule((DQRule) udi);
                            }
                        }
                        ProxyRepositoryFactory.getInstance().getRepositoryFactoryFromProvider().getResourceManager().saveResource(udi.eResource());
                    }
                }
            }
        }
        List<Pattern> patterns = AnalysisHelper.getPatterns(analysis);
        for (Pattern pattern : patterns) {
            InternalEObject iptn = (InternalEObject) pattern;
            if (!iptn.eIsProxy()) {
                DQRepositoryNode recursiveFind = RepositoryNodeHelper.recursiveFind(pattern);
                // only do save when the dependency is not reference project node
                if (recursiveFind != null && recursiveFind.getProject().isMainProject()) {
                    TypedReturnCode<Dependency> dependencyReturn = DependenciesHandler.getInstance().setDependencyOn(analysis, pattern);
                    if (dependencyReturn.isOk()) {
                        Property property = PropertyHelper.getProperty(pattern);
                        if (property != null && property.getItem() instanceof TDQPatternItem) {
                            TDQPatternItem patternItem = (TDQPatternItem) property.getItem();
                            patternItem.setPattern(pattern);
                        }
                        ProxyRepositoryFactory.getInstance().getRepositoryFactoryFromProvider().getResourceManager().saveResource(pattern.eResource());
                    // EMFUtil.saveSingleResource(pattern.eResource());
                    }
                }
            }
        }
    } catch (PersistenceException e) {
        log.error(e, e);
    }
}
Also used : Pattern(org.talend.dataquality.domain.pattern.Pattern) TDQIndicatorDefinitionItem(org.talend.dataquality.properties.TDQIndicatorDefinitionItem) Dependency(orgomg.cwm.objectmodel.core.Dependency) TDQPatternItem(org.talend.dataquality.properties.TDQPatternItem) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition) DQRule(org.talend.dataquality.rules.DQRule) DQRepositoryNode(org.talend.dq.nodes.DQRepositoryNode) Analysis(org.talend.dataquality.analysis.Analysis) PersistenceException(org.talend.commons.exception.PersistenceException) TDQItem(org.talend.core.model.properties.TDQItem) TDQBusinessRuleItem(org.talend.dataquality.properties.TDQBusinessRuleItem) Property(org.talend.core.model.properties.Property) InternalEObject(org.eclipse.emf.ecore.InternalEObject)

Example 93 with IndicatorDefinition

use of org.talend.dataquality.indicators.definition.IndicatorDefinition in project tdq-studio-se by Talend.

the class AddBenfordLaw4RedshiftTask method doExecute.

@Override
protected boolean doExecute() throws Exception {
    definitionHandler = DefinitionHandler.getInstance();
    IndicatorDefinition regexPatternDefinition = definitionHandler.getDefinitionById(BENFORD_LAW_UUID);
    if (regexPatternDefinition != null) {
        if (!IndicatorDefinitionFileHelper.isExistSqlExprWithLanguage(regexPatternDefinition, Redshift)) {
            IndicatorDefinitionFileHelper.addSqlExpression(regexPatternDefinition, Redshift, // $NON-NLS-1$
            "SELECT SUBSTRING(<%=__COLUMN_NAMES__%>,1,1), COUNT(*)  FROM <%=__TABLE_NAME__%> t <%=__WHERE_CLAUSE__%> GROUP BY 1 order by 1");
        } else {
            IndicatorDefinitionFileHelper.updateSqlExpression(regexPatternDefinition, Redshift, // $NON-NLS-1$
            "SELECT SUBSTRING(<%=__COLUMN_NAMES__%>,1,1), COUNT(*)  FROM <%=__TABLE_NAME__%> t <%=__WHERE_CLAUSE__%> GROUP BY 1 order by 1");
        }
        IndicatorDefinitionFileHelper.save(regexPatternDefinition);
        DefinitionHandler.getInstance().reloadIndicatorsDefinitions();
    }
    return true;
}
Also used : IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition)

Example 94 with IndicatorDefinition

use of org.talend.dataquality.indicators.definition.IndicatorDefinition in project tdq-studio-se by Talend.

the class AddExasolRegularExpressionMatchingTask method doExecute.

@Override
protected boolean doExecute() throws Exception {
    definitionHandler = DefinitionHandler.getInstance();
    IndicatorDefinition regexPatternDefinition = definitionHandler.getDefinitionById(REGEXPATTERNMATCH_UUID);
    if (regexPatternDefinition != null && !IndicatorDefinitionFileHelper.isExistSqlExprWithLanguage(regexPatternDefinition, EXASolution)) {
        IndicatorDefinitionFileHelper.addSqlExpression(regexPatternDefinition, EXASolution, // $NON-NLS-1$
        "SELECT COUNT(CASE WHEN <%=__COLUMN_NAMES__%> REGEXP_LIKE <%=__PATTERN_EXPR__%> THEN 1 END), COUNT(*) FROM <%=__TABLE_NAME__%> <%=__WHERE_CLAUSE__%>");
        IndicatorDefinitionFileHelper.save(regexPatternDefinition);
        DefinitionHandler.getInstance().reloadIndicatorsDefinitions();
    }
    return true;
}
Also used : IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition)

Example 95 with IndicatorDefinition

use of org.talend.dataquality.indicators.definition.IndicatorDefinition in project tdq-studio-se by Talend.

the class DQRespositoryView method createPartControl.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.ui.navigator.CommonNavigator#createPartControl(org.eclipse .swt.widgets.Composite)
     */
@Override
public void createPartControl(Composite parent) {
    parent.setLayout(new BorderLayout());
    Composite topComp = new Composite(parent, SWT.NONE);
    topComp.setFont(parent.getFont());
    topComp.setLayoutData(BorderLayout.NORTH);
    Composite bottomComp = new Composite(parent, SWT.NONE);
    bottomComp.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
    bottomComp.setFont(parent.getFont());
    bottomComp.setLayoutData(BorderLayout.CENTER);
    topComp.setLayout(new BorderLayout());
    FillLayout bottomLayout = new FillLayout(SWT.VERTICAL);
    bottomComp.setLayout(bottomLayout);
    createTreeFilter(topComp);
    super.createPartControl(bottomComp);
    // For removing the popup menu of DQRepositoryView.
    // $NON-NLS-1$
    MenuManager menuMgr = new MenuManager("org.talend.dataprofiler.core.ui.views.DQRespositoryView");
    menuMgr.setRemoveAllWhenShown(true);
    menuMgr.addMenuListener(new IMenuListener() {

        public void menuAboutToShow(IMenuManager menuManager) {
            ISelection selection = getCommonViewer().getSelection();
            getNavigatorActionService().setContext(new ActionContext(selection));
            getNavigatorActionService().fillContextMenu(menuManager);
        }
    });
    Menu menu = menuMgr.createContextMenu(getCommonViewer().getTree());
    getCommonViewer().getTree().setMenu(menu);
    this.addViewerFilter(EMFObjFilter.FILTER_ID);
    this.addViewerFilter(ReportingFilter.FILTER_ID);
    this.addViewerFilter(FolderObjFilter.FILTER_ID);
    adjustFilter();
    activateContext();
    getCommonViewer().setSorter(null);
    getCommonViewer().getTree().addTreeListener(new TreeAdapter() {

        @Override
        public void treeExpanded(TreeEvent e) {
            TreeItem item = (TreeItem) e.item;
            if (!item.getText().endsWith(")")) {
                // $NON-NLS-1$
                Object obj = item.getData();
                if (obj instanceof TableFolderNode || obj instanceof ViewFolderNode || obj instanceof ColumnFolderNode) {
                    // $NON-NLS-1$ //$NON-NLS-2$
                    item.setText(item.getText() + "(" + item.getItemCount() + ")");
                }
            }
            super.treeExpanded(e);
        }
    });
    getCommonViewer().getTree().addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDoubleClick(MouseEvent e) {
            boolean superDoubleClick = true;
            Tree tree = (Tree) e.getSource();
            Point point = new Point(e.x, e.y);
            final TreeItem item = tree.getItem(point);
            if (item != null) {
                Object obj = item.getData();
                if (obj instanceof AbstractFolderNode) {
                    AbstractFolderNode node = (AbstractFolderNode) obj;
                    node.loadChildren();
                    Object[] children = node.getChildren();
                    if (children != null) {
                        if (item.getText().indexOf("(") > 0) {
                            // $NON-NLS-1$
                            item.setText(// $NON-NLS-1$ //$NON-NLS-2$
                            item.getText().substring(0, item.getText().indexOf("(")) + "(" + children.length + // $NON-NLS-1$
                            ")");
                        } else {
                            // $NON-NLS-1$ //$NON-NLS-2$
                            item.setText(item.getText() + "(" + children.length + ")");
                        }
                    }
                }
                if (obj instanceof IndicatorDefinition) {
                    IndicatorDefinition indicatorDefinition = (IndicatorDefinition) obj;
                    // reload object
                    indicatorDefinition = DefinitionHandler.getInstance().getIndicatorDefinition(indicatorDefinition.getLabel());
                    IndicatorEditorInput input = new IndicatorEditorInput(indicatorDefinition);
                    try {
                        CorePlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(input, IndicatorEditor.class.getName());
                    } catch (PartInitException e1) {
                        log.error(e1, e1);
                    }
                }
                if (obj instanceof DQRepositoryNode) {
                    if (obj instanceof ReportFileRepNode) {
                        new OpenItemEditorAction(new IRepositoryNode[] { (IRepositoryNode) obj }).run();
                    } else if (obj instanceof DFConnectionRepNode) {
                        new EditFileDelimitedAction((IRepositoryNode) obj).run();
                    } else if (obj instanceof HadoopClusterConnectionRepNode && HadoopClusterUtils.getDefault().isServiceInstalled()) {
                        new EditHadoopClusterAction((IRepositoryNode) obj).run();
                    } else if (obj instanceof HDFSOfHCConnectionNode && HadoopClusterUtils.getDefault().isServiceInstalled()) {
                        new EditHDFSConnectionAction((IRepositoryNode) obj).run();
                    } else if (obj instanceof DFTableRepNode) {
                        new EditDFTableAction((IRepositoryNode) obj).run();
                    } else if (obj instanceof ContextRepNode) {
                        new DQEditContextAction((ContextRepNode) obj, false).run();
                    } else {
                        DQRepositoryNode repoNode = (DQRepositoryNode) obj;
                        if (RepositoryNodeHelper.canOpenEditor(repoNode)) {
                            OpenItemEditorAction openItemEditorAction = new OpenItemEditorAction(new IRepositoryNode[] { repoNode });
                            openItemEditorAction.run();
                        }
                        if (repoNode instanceof AnalysisRepNode || repoNode instanceof ReportRepNode || repoNode instanceof SysIndicatorDefinitionRepNode || repoNode instanceof PatternRepNode || repoNode instanceof RuleRepNode) {
                            superDoubleClick = false;
                        }
                    }
                }
            }
            if (superDoubleClick) {
                super.mouseDoubleClick(e);
            }
        }
    });
    getCommonViewer().getTree().addKeyListener(new KeyListener() {

        public void keyPressed(KeyEvent e) {
            if (e.keyCode == SWT.CR || e.keyCode == SWT.KEYPAD_CR) {
                Tree tree = (Tree) e.getSource();
                TreeItem[] selection = tree.getSelection();
                for (TreeItem item : selection) {
                    Object data = item.getData();
                    DQRepositoryNode repoNode = (DQRepositoryNode) data;
                    if (RepositoryNodeHelper.canOpenEditor(repoNode)) {
                        OpenItemEditorAction openItemEditorAction = new OpenItemEditorAction(new IRepositoryNode[] { repoNode });
                        openItemEditorAction.run();
                    }
                }
            }
        }

        public void keyReleased(KeyEvent e) {
        // do nothing here until now
        }
    });
    // ~ADD mzhao for feature 6233 Load columns when selecting a table (or
    // view) in DQ Repository view
    getCommonViewer().addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            TreeSelection selection = (TreeSelection) event.getSelection();
            Iterator<?> iterator = selection.iterator();
            while (iterator.hasNext()) {
                Object selectedElement = iterator.next();
                if (selectedElement instanceof DBTableRepNode || selectedElement instanceof DBViewRepNode) {
                    ((RepositoryNode) selectedElement).getChildren().get(0).getChildren();
                }
            }
        }
    });
    // MOD mzhao 2011-03-10 bug 19147: filter MDM entries.
    getCommonViewer().addFilter(new ViewerFilter() {

        @Override
        public boolean select(Viewer viewer, Object parentElement, Object element) {
            if (element instanceof IProject) {
                return false;
            }
            return true;
        }
    });
// ~
}
Also used : TreeItem(org.eclipse.swt.widgets.TreeItem) HDFSOfHCConnectionNode(org.talend.dq.nodes.hadoopcluster.HDFSOfHCConnectionNode) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) ColumnViewer(org.eclipse.jface.viewers.ColumnViewer) Viewer(org.eclipse.jface.viewers.Viewer) TreeAdapter(org.eclipse.swt.events.TreeAdapter) TableFolderNode(org.talend.dataprofiler.core.model.nodes.foldernode.TableFolderNode) TreeEvent(org.eclipse.swt.events.TreeEvent) IndicatorEditorInput(org.talend.dataprofiler.core.ui.editor.indicator.IndicatorEditorInput) ReportFileRepNode(org.talend.dq.nodes.ReportFileRepNode) BorderLayout(org.talend.dataprofiler.core.ui.views.layout.BorderLayout) ReportRepNode(org.talend.dq.nodes.ReportRepNode) TreeSelection(org.eclipse.jface.viewers.TreeSelection) Tree(org.eclipse.swt.widgets.Tree) PatternRepNode(org.talend.dq.nodes.PatternRepNode) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) FillLayout(org.eclipse.swt.layout.FillLayout) OpenItemEditorAction(org.talend.dataprofiler.core.ui.action.actions.OpenItemEditorAction) ViewFolderNode(org.talend.dataprofiler.core.model.nodes.foldernode.ViewFolderNode) DQEditContextAction(org.talend.dataprofiler.core.ui.action.actions.DQEditContextAction) MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) ColumnFolderNode(org.talend.dataprofiler.core.model.nodes.foldernode.ColumnFolderNode) EditDFTableAction(org.talend.dataprofiler.core.ui.action.actions.EditDFTableAction) AbstractViewerFilter(org.talend.dataprofiler.core.ui.filters.AbstractViewerFilter) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) AbstractFolderNode(org.talend.dq.nodes.foldernode.AbstractFolderNode) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition) KeyEvent(org.eclipse.swt.events.KeyEvent) DQRepositoryNode(org.talend.dq.nodes.DQRepositoryNode) ISelection(org.eclipse.jface.viewers.ISelection) EditHDFSConnectionAction(org.talend.dataprofiler.core.ui.action.actions.EditHDFSConnectionAction) SysIndicatorDefinitionRepNode(org.talend.dq.nodes.SysIndicatorDefinitionRepNode) Iterator(java.util.Iterator) DFTableRepNode(org.talend.dq.nodes.DFTableRepNode) Menu(org.eclipse.swt.widgets.Menu) PartInitException(org.eclipse.ui.PartInitException) DBViewRepNode(org.talend.dq.nodes.DBViewRepNode) MouseEvent(org.eclipse.swt.events.MouseEvent) Composite(org.eclipse.swt.widgets.Composite) IRepositoryNode(org.talend.repository.model.IRepositoryNode) MouseAdapter(org.eclipse.swt.events.MouseAdapter) Point(org.eclipse.swt.graphics.Point) ActionContext(org.eclipse.ui.actions.ActionContext) RuleRepNode(org.talend.dq.nodes.RuleRepNode) IMenuListener(org.eclipse.jface.action.IMenuListener) IProject(org.eclipse.core.resources.IProject) EditFileDelimitedAction(org.talend.dataprofiler.core.ui.action.actions.EditFileDelimitedAction) DBTableRepNode(org.talend.dq.nodes.DBTableRepNode) AnalysisRepNode(org.talend.dq.nodes.AnalysisRepNode) DFConnectionRepNode(org.talend.dq.nodes.DFConnectionRepNode) EditHadoopClusterAction(org.talend.dataprofiler.core.ui.action.actions.EditHadoopClusterAction) KeyListener(org.eclipse.swt.events.KeyListener) IMenuManager(org.eclipse.jface.action.IMenuManager) HadoopClusterConnectionRepNode(org.talend.dq.nodes.hadoopcluster.HadoopClusterConnectionRepNode) ContextRepNode(org.talend.dq.nodes.ContextRepNode)

Aggregations

IndicatorDefinition (org.talend.dataquality.indicators.definition.IndicatorDefinition)141 UDIndicatorDefinition (org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition)37 Test (org.junit.Test)35 ArrayList (java.util.ArrayList)34 TdExpression (org.talend.cwm.relational.TdExpression)31 File (java.io.File)22 Analysis (org.talend.dataquality.analysis.Analysis)16 IFile (org.eclipse.core.resources.IFile)15 Property (org.talend.core.model.properties.Property)14 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)14 TDQIndicatorDefinitionItem (org.talend.dataquality.properties.TDQIndicatorDefinitionItem)14 PersistenceException (org.talend.commons.exception.PersistenceException)13 Indicator (org.talend.dataquality.indicators.Indicator)12 ModelElement (orgomg.cwm.objectmodel.core.ModelElement)12 Path (org.eclipse.core.runtime.Path)10 IFolder (org.eclipse.core.resources.IFolder)9 BasicEList (org.eclipse.emf.common.util.BasicEList)9 TdColumn (org.talend.cwm.relational.TdColumn)9 UserDefIndicator (org.talend.dataquality.indicators.sql.UserDefIndicator)7 TDQAnalysisItem (org.talend.dataquality.properties.TDQAnalysisItem)7