Search in sources :

Example 21 with UserDefIndicator

use of org.talend.dataquality.indicators.sql.UserDefIndicator in project tdq-studio-se by Talend.

the class AnalysisColumnTreeViewer method addColumnUdi.

/**
 * DOC xqliu Comment method "addColumnUdi". ADD xqliu 2010-02-23 feature 11617
 *
 * @param treeItem
 * @param meIndicator
 * @param columnIndex
 * @return
 */
private TreeEditor addColumnUdi(final TreeItem treeItem, final ModelElementIndicator meIndicator, int columnIndex) {
    TreeEditor addUdiEditor = new TreeEditor(tree);
    // $NON-NLS-1$
    Label addUdiLabl = createTreeItemLabel(tree, ImageLib.ADD_IND_DEFINITION, "AnalysisColumnTreeViewer.addUdi");
    addUdiLabl.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDown(MouseEvent e) {
            DataManager dm = getAnalysis().getContext().getConnection();
            if (dm == null) {
                masterPage.doSave(null);
            }
            CheckedTreeSelectionDialog dialog = UDIUtils.createUdiCheckedTreeSelectionDialog(meIndicator);
            if (dialog.open() == Window.OK) {
                // MOD qiongli 2012-10-24 TDQ-6308,just remove some deselected indicatorUnit then set dirty to
                // true,just create new indicatorUnit for some new added UDI then set dirty to true.
                List<IndicatorDefinition> allSelectedIndicatorDefinitions = new ArrayList<IndicatorDefinition>();
                Set<String> allSelectedIndNames = new HashSet<String>();
                for (Object obj : dialog.getResult()) {
                    if (obj instanceof SysIndicatorDefinitionRepNode) {
                        IndicatorDefinition udid = ((SysIndicatorDefinitionRepNode) obj).getIndicatorDefinition();
                        allSelectedIndicatorDefinitions.add(udid);
                        if (udid != null) {
                            allSelectedIndNames.add(udid.getName());
                        }
                    }
                }
                Set<String> oldSelectedIndNames = new HashSet<String>();
                for (IndicatorUnit indicatorUnit : meIndicator.getIndicatorUnits()) {
                    Indicator indicator = indicatorUnit.getIndicator();
                    if (indicator instanceof UserDefIndicator) {
                        if (allSelectedIndNames.contains(indicator.getName())) {
                            oldSelectedIndNames.add(indicator.getName());
                        } else {
                            // remove the UDI from UI need to insert this UDI into removeList
                            deleteIndicatorItems(meIndicator, indicatorUnit);
                            if (!isDirty()) {
                                setDirty(true);
                            }
                        }
                    }
                }
                treeItem.removeAll();
                for (IndicatorDefinition udid : allSelectedIndicatorDefinitions) {
                    if (udid != null && oldSelectedIndNames.contains(udid.getName())) {
                        continue;
                    }
                    IndicatorUnit[] addIndicatorUnits = null;
                    try {
                        addIndicatorUnits = UDIUtils.createIndicatorUnit(udid, meIndicator, getAnalysis());
                    } catch (Throwable e1) {
                        log.warn(e1, e1);
                    }
                    if (addIndicatorUnits != null && addIndicatorUnits.length > 0) {
                        for (IndicatorUnit unit : addIndicatorUnits) {
                            createOneUnit(treeItem, unit);
                        }
                        if (!isDirty()) {
                            setDirty(true);
                        }
                    }
                }
                treeItem.setExpanded(true);
                masterPage.refreshTheTree(masterPage.getCurrentModelElementIndicators());
            }
        }
    });
    addUdiEditor.minimumWidth = addUdiLabl.getImage().getBounds().width;
    addUdiEditor.setEditor(addUdiLabl, treeItem, columnIndex);
    return addUdiEditor;
}
Also used : MouseEvent(org.eclipse.swt.events.MouseEvent) Set(java.util.Set) HashSet(java.util.HashSet) TreeEditor(org.eclipse.swt.custom.TreeEditor) CheckedTreeSelectionDialog(org.eclipse.ui.dialogs.CheckedTreeSelectionDialog) Label(org.eclipse.swt.widgets.Label) MouseAdapter(org.eclipse.swt.events.MouseAdapter) IndicatorUnit(org.talend.dataprofiler.core.ui.editor.preview.IndicatorUnit) DataManager(orgomg.cwm.foundation.softwaredeployment.DataManager) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition) DelimitedFileIndicator(org.talend.dataprofiler.core.model.DelimitedFileIndicator) ModelElementIndicator(org.talend.dataprofiler.core.model.ModelElementIndicator) UserDefIndicator(org.talend.dataquality.indicators.sql.UserDefIndicator) Indicator(org.talend.dataquality.indicators.Indicator) CompositeIndicator(org.talend.dataquality.indicators.CompositeIndicator) SysIndicatorDefinitionRepNode(org.talend.dq.nodes.SysIndicatorDefinitionRepNode) List(java.util.List) ArrayList(java.util.ArrayList) MetadataTableRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataTableRepositoryObject) MetadataColumnRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataColumnRepositoryObject) MetadataXmlElementTypeRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataXmlElementTypeRepositoryObject) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) UserDefIndicator(org.talend.dataquality.indicators.sql.UserDefIndicator)

Example 22 with UserDefIndicator

use of org.talend.dataquality.indicators.sql.UserDefIndicator in project tdq-studio-se by Talend.

the class ModelElementTreeMenuProvider method editUDIndicator.

/**
 * DOC yyi Comment method "editUDIndicator" 2009-09-04.
 *
 * @param tree
 */
private void editUDIndicator(Tree tree) {
    TreeItem[] selection = tree.getSelection();
    if (selection.length > 0) {
        TreeItem treeItem = selection[0];
        IndicatorUnit indicatorUnit = (IndicatorUnit) treeItem.getData(AbstractColumnDropTree.INDICATOR_UNIT_KEY);
        UserDefIndicator indicator = (UserDefIndicator) indicatorUnit.getIndicator();
        IFile file = ResourceFileMap.findCorrespondingFile(indicator.getIndicatorDefinition());
        IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
        try {
            activePage.openEditor(new FileEditorInput(file), // $NON-NLS-1$
            "org.talend.dataprofiler.core.ui.editor.indicator.IndicatorEditor");
        } catch (PartInitException e1) {
            log.error(e1, e1);
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) TreeItem(org.eclipse.swt.widgets.TreeItem) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IndicatorUnit(org.talend.dataprofiler.core.ui.editor.preview.IndicatorUnit) ColumnIndicatorUnit(org.talend.dataprofiler.core.ui.editor.preview.ColumnIndicatorUnit) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) PartInitException(org.eclipse.ui.PartInitException) UserDefIndicator(org.talend.dataquality.indicators.sql.UserDefIndicator)

Example 23 with UserDefIndicator

use of org.talend.dataquality.indicators.sql.UserDefIndicator in project tdq-studio-se by Talend.

the class IndicatorEvaluator method getMessageForInvalidJUDIs.

/**
 * check each UDI if has realted java expression(class) for Java Engine,remove it from elementToIndicators(no need
 * to compute),then populate the message
 *
 * @param analysis
 * @return
 */
protected ReturnCode getMessageForInvalidJUDIs() {
    ReturnCode ret = new ReturnCode(Boolean.TRUE);
    Set<String> invalidUdiNames = new HashSet<String>();
    Set<String> columns = elementToIndicators.keySet();
    Iterator<String> colIt = columns.iterator();
    while (colIt.hasNext()) {
        String nextCol = colIt.next();
        List<Indicator> indicators = elementToIndicators.get(nextCol);
        List<Indicator> needRemovedInds = new ArrayList<Indicator>();
        for (Indicator ind : indicators) {
            if (ind instanceof UserDefIndicator && UDIHelper.isJavaUDI(ind) && !UDIHelper.isJUDIValid(ind.getIndicatorDefinition())) {
                invalidUdiNames.add(ind.getName());
                needRemovedInds.add(ind);
            }
        }
        if (!needRemovedInds.isEmpty()) {
            indicators.removeAll(needRemovedInds);
            allIndicators.removeAll(needRemovedInds);
        }
    }
    if (!invalidUdiNames.isEmpty()) {
        String message = invalidUdiNames.toString();
        // $NON-NLS-1$
        ret.setReturnCode(Messages.getString("IndicatorEvaluator.NoExpressionFound", message), false);
    }
    return ret;
}
Also used : ReturnCode(org.talend.utils.sugars.ReturnCode) ArrayList(java.util.ArrayList) UserDefIndicator(org.talend.dataquality.indicators.sql.UserDefIndicator) UniqueCountIndicator(org.talend.dataquality.indicators.UniqueCountIndicator) FrequencyIndicator(org.talend.dataquality.indicators.FrequencyIndicator) FormatFreqPieIndicator(org.talend.dataquality.indicators.FormatFreqPieIndicator) MaxLengthIndicator(org.talend.dataquality.indicators.MaxLengthIndicator) Indicator(org.talend.dataquality.indicators.Indicator) MinLengthIndicator(org.talend.dataquality.indicators.MinLengthIndicator) PatternLowFreqIndicator(org.talend.dataquality.indicators.PatternLowFreqIndicator) PatternFreqIndicator(org.talend.dataquality.indicators.PatternFreqIndicator) DuplicateCountIndicator(org.talend.dataquality.indicators.DuplicateCountIndicator) UserDefIndicator(org.talend.dataquality.indicators.sql.UserDefIndicator) HashSet(java.util.HashSet)

Aggregations

UserDefIndicator (org.talend.dataquality.indicators.sql.UserDefIndicator)23 Test (org.junit.Test)9 TdExpression (org.talend.cwm.relational.TdExpression)7 IndicatorDefinition (org.talend.dataquality.indicators.definition.IndicatorDefinition)7 ArrayList (java.util.ArrayList)6 Indicator (org.talend.dataquality.indicators.Indicator)6 UDIndicatorDefinition (org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition)6 Analysis (org.talend.dataquality.analysis.Analysis)5 AnalysisResult (org.talend.dataquality.analysis.AnalysisResult)5 IndicatorParameters (org.talend.dataquality.indicators.IndicatorParameters)5 PatternMatchingIndicator (org.talend.dataquality.indicators.PatternMatchingIndicator)4 Expression (orgomg.cwm.objectmodel.core.Expression)4 Path (org.eclipse.core.runtime.Path)3 PersistenceException (org.talend.commons.exception.PersistenceException)3 ItemState (org.talend.core.model.properties.ItemState)3 Property (org.talend.core.model.properties.Property)3 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)3 IndicatorUnit (org.talend.dataprofiler.core.ui.editor.preview.IndicatorUnit)3 RegularExpression (org.talend.dataquality.domain.pattern.RegularExpression)3 TDQAnalysisItem (org.talend.dataquality.properties.TDQAnalysisItem)3