Search in sources :

Example 51 with ModelElementIndicator

use of org.talend.dataprofiler.core.model.ModelElementIndicator in project tdq-studio-se by Talend.

the class AbstractColumnDropTree method createOneUnit.

/**
 * DOC qzhang Comment method "createOneUnit".
 *
 * @param treeItem
 * @param indicatorUnit
 */
public void createOneUnit(final TreeItem treeItem, IndicatorUnit indicatorUnit) {
    final TreeItem indicatorItem = new TreeItem(treeItem, SWT.NONE);
    final IndicatorUnit unit = indicatorUnit;
    IndicatorEnum indicatorType = indicatorUnit.getType();
    indicatorItem.setData(MODELELEMENT_INDICATOR_KEY, treeItem.getData(MODELELEMENT_INDICATOR_KEY));
    indicatorItem.setData(INDICATOR_UNIT_KEY, unit);
    indicatorItem.setData(viewKey, this);
    indicatorItem.setImage(0, getIndicatorImage(unit));
    String indicatorName = getIndicatorName(indicatorUnit);
    // $NON-NLS-1$
    String label = indicatorName == null ? "unknown indicator" : indicatorName;
    indicatorItem.setText(0, label);
    TreeEditor optionEditor = new TreeEditor(tree);
    // $NON-NLS-1$
    final Label optionLabel = createTreeItemLabel(tree, ImageLib.OPTION, "AnalysisColumnTreeViewer.options");
    optionLabel.setData(indicatorUnit);
    optionLabel.addMouseListener(new MouseAdapter() {

        /*
             * (non-Javadoc)
             * 
             * @see org.eclipse.swt.events.MouseAdapter#mouseDown(org.eclipse.swt .events.MouseEvent)
             */
        @Override
        public void mouseDown(MouseEvent e) {
            boolean hasIndicatorParameters = openIndicatorOptionDialog(Display.getCurrent().getActiveShell(), indicatorItem);
            if (hasIndicatorParameters) {
                optionLabel.setImage(ImageLib.getImage(ImageLib.INDICATOR_OPTION_CHECKED));
            }
        }
    });
    optionEditor.minimumWidth = optionLabel.getImage().getBounds().width;
    optionEditor.horizontalAlignment = SWT.CENTER;
    optionEditor.setEditor(optionLabel, indicatorItem, 1);
    // }
    TreeEditor delEditor = new TreeEditor(tree);
    // $NON-NLS-1$
    Label delLabel = createTreeItemLabel(tree, ImageLib.DELETE_ACTION, "AnalysisColumnTreeViewer.delete");
    delLabel.addMouseListener(new MouseAdapter() {

        /*
             * (non-Javadoc)
             * 
             * @see org.eclipse.swt.events.MouseAdapter#mouseDown(org.eclipse.swt .events.MouseEvent)
             */
        @Override
        public void mouseDown(MouseEvent e) {
            // current delLabel is behind of one indicator item.
            ModelElementIndicator meIndicator = (ModelElementIndicator) treeItem.getData(MODELELEMENT_INDICATOR_KEY);
            deleteIndicatorItems(meIndicator, unit);
            if (indicatorItem.getParentItem() != null && indicatorItem.getParentItem().getData(INDICATOR_UNIT_KEY) != null) {
                setElements(modelElementIndicators);
            } else {
                removeItemBranch(indicatorItem);
            }
        }
    });
    delEditor.minimumWidth = delLabel.getImage().getBounds().width;
    delEditor.horizontalAlignment = SWT.CENTER;
    // MOD mzhao feature 13040, column analysis have 5 columns, whereas columnset have 4 columns.
    if (AnalysisColumnTreeViewer.VIEWER_KEY.equals(viewKey)) {
        delEditor.setEditor(delLabel, indicatorItem, 4);
    } else if (AnalysisColumnSetTreeViewer.VIEWER_KEY.equals(viewKey)) {
        delEditor.setEditor(delLabel, indicatorItem, 3);
    }
    indicatorItem.setData(ITEM_EDITOR_KEY, new TreeEditor[] { optionEditor, delEditor });
    if (indicatorType.hasChildren()) {
        indicatorItem.setData(treeItem.getData(MODELELEMENT_INDICATOR_KEY));
        createIndicatorItems(indicatorItem, indicatorUnit.getChildren());
    }
    if (hasIndicatorParameters(indicatorUnit)) {
        optionLabel.setImage(ImageLib.getImage(ImageLib.INDICATOR_OPTION_CHECKED));
    }
}
Also used : MouseEvent(org.eclipse.swt.events.MouseEvent) IndicatorEnum(org.talend.dq.nodes.indicator.type.IndicatorEnum) TreeEditor(org.eclipse.swt.custom.TreeEditor) TreeItem(org.eclipse.swt.widgets.TreeItem) IndicatorUnit(org.talend.dataprofiler.core.ui.editor.preview.IndicatorUnit) Label(org.eclipse.swt.widgets.Label) MouseAdapter(org.eclipse.swt.events.MouseAdapter) ModelElementIndicator(org.talend.dataprofiler.core.model.ModelElementIndicator)

Example 52 with ModelElementIndicator

use of org.talend.dataprofiler.core.model.ModelElementIndicator in project tdq-studio-se by Talend.

the class AbstractPredefinedAnalysisAction method composePredefinedColumnIndicator.

protected ModelElementIndicator[] composePredefinedColumnIndicator(IndicatorEnum[] allowedEnum) {
    IRepositoryNode[] columns = getColumns();
    ModelElementIndicator[] predefinedColumnIndicator = new ModelElementIndicator[columns.length];
    ExecutionLanguage language = ExecutionLanguage.get(getMasterPage().getExecCombo().getText());
    for (int i = 0; i < columns.length; i++) {
        IRepositoryNode columnNode = columns[i];
        ModelElementIndicator columnIndicator = ModelElementIndicatorHelper.createModelElementIndicator(columnNode);
        for (IndicatorEnum oneEnum : allowedEnum) {
            columnIndicator.addTempIndicatorEnum(oneEnum);
            if (oneEnum.getChildren() != null) {
                for (IndicatorEnum childEnum : oneEnum.getChildren()) {
                    // MOD by zshen:need language to decide DatePatternFrequencyIndicator whether can be choose by
                    // user.
                    IRepositoryViewObject object = columnNode.getObject();
                    ModelElement element = null;
                    if (object instanceof MetadataColumnRepositoryObject) {
                        element = ((MetadataColumnRepositoryObject) object).getTdColumn();
                    } else if (object instanceof MetadataXmlElementTypeRepositoryObject) {
                        element = ((MetadataXmlElementTypeRepositoryObject) object).getModelElement();
                    }
                    if (element != null && ModelElementIndicatorRule.patternRule(childEnum, element, language)) {
                        columnIndicator.addTempIndicatorEnum(childEnum);
                    }
                }
            }
        }
        columnIndicator.storeTempIndicator();
        predefinedColumnIndicator[i] = columnIndicator;
    }
    return predefinedColumnIndicator;
}
Also used : ModelElement(orgomg.cwm.objectmodel.core.ModelElement) IRepositoryNode(org.talend.repository.model.IRepositoryNode) IndicatorEnum(org.talend.dq.nodes.indicator.type.IndicatorEnum) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) ExecutionLanguage(org.talend.dataquality.analysis.ExecutionLanguage) MetadataColumnRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataColumnRepositoryObject) MetadataXmlElementTypeRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataXmlElementTypeRepositoryObject) ModelElementIndicator(org.talend.dataprofiler.core.model.ModelElementIndicator)

Example 53 with ModelElementIndicator

use of org.talend.dataprofiler.core.model.ModelElementIndicator in project tdq-studio-se by Talend.

the class PatternLabelProvider method createIndicatorUnit.

/**
 * DOC xqliu Comment method "createIndicatorUnit".
 *
 * @param pfile
 * @param modelElementIndicator
 * @param analysis
 * @param indicatorDefinition
 * @return
 */
public static TypedReturnCode<IndicatorUnit> createIndicatorUnit(Pattern pattern, ModelElementIndicator modelElementIndicator, Analysis analysis, IndicatorDefinition indicatorDefinition) {
    TypedReturnCode<IndicatorUnit> result = new TypedReturnCode<IndicatorUnit>();
    for (Indicator indicator : modelElementIndicator.getIndicators()) {
        // MOD xwang 2011-08-01 bug TDQ-2730
        if (UDIHelper.getMatchingIndicatorName(indicatorDefinition, pattern).equals(indicator.getName()) && indicator instanceof PatternMatchingIndicator) {
            result.setOk(false);
            // $NON-NLS-1$
            result.setMessage(DefaultMessagesImpl.getString("PatternUtilities.Selected"));
            return result;
        }
    // ~
    }
    // MOD scorreia 2009-01-06: when expression type is not set (version
    // TOP-1.1.x), then it's supposed to be a
    // regexp pattern. This could be false because expression type was not
    // set into SQL pattern neither in TOP-1.1.
    // This means that there could exist the need for a migration task to
    // set the expression type depending on the
    // folder where the pattern is stored. The method
    // DomainHelper.getExpressionType(pattern) tries to find the type
    // of pattern.
    Indicator patternMatchingIndicator = null;
    String expressionType = DomainHelper.getExpressionType(pattern);
    boolean isSQLPattern = (ExpressionType.SQL_LIKE.getLiteral().equals(expressionType));
    if (indicatorDefinition != null) {
        patternMatchingIndicator = UDIFactory.createUserDefIndicator(indicatorDefinition, pattern);
    } else {
        patternMatchingIndicator = isSQLPattern ? PatternIndicatorFactory.createSqlPatternMatchingIndicator(pattern) : PatternIndicatorFactory.createRegexpMatchingIndicator(pattern);
    }
    IEditorPart theEdit = CorePlugin.getDefault().getCurrentActiveEditor();
    if (theEdit != null && theEdit instanceof AnalysisEditor && analysis.getContext().getConnection() == null) {
        theEdit.doSave(null);
    }
    ExecutionLanguage executionLanguage = analysis.getParameters().getExecutionLanguage();
    DbmsLanguage dbmsLanguage = DbmsLanguageFactory.createDbmsLanguage(analysis);
    if (dbmsLanguage.isSql()) {
        // $NON-NLS-1$
        MessageUI.openWarning(DefaultMessagesImpl.getString("PatternUtilities.ConnectionError"));
        result.setOk(false);
        return result;
    }
    boolean isJavaEngin = ExecutionLanguage.JAVA.equals(executionLanguage);
    Expression returnExpression = dbmsLanguage.getRegexp(pattern);
    // MOD gdbu 2011-8-26 bug : TDQ-2169
    if ((ExpressionType.REGEXP.getLiteral().equals(expressionType) || ExpressionType.SQL_LIKE.getLiteral().equals(expressionType)) && returnExpression == null) {
        // ~TDQ-2169
        String executeType = isJavaEngin ? executionLanguage.getName() : dbmsLanguage.getDbmsName();
        boolean openPattern = MessageDialog.openQuestion(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), DefaultMessagesImpl.getString("PatternUtilities.Warning"), // $NON-NLS-1$ //$NON-NLS-2$
        DefaultMessagesImpl.getString("PatternUtilities.NoExpression", executeType, pattern.getName()));
        if (openPattern) {
            RepositoryNode node = RepositoryNodeHelper.recursiveFind(pattern);
            if (RepositoryNodeHelper.canOpenEditor(node)) {
                new OpenItemEditorAction(new IRepositoryNode[] { node }).run();
            }
        }
        result.setOk(false);
        return result;
    }
    // a regular expression for the analyzed
    // database, but we probably test also whether the analyzed database
    // support the regular expressions (=> check
    // DB type, DB number version, existence of UDF)
    DataManager dm = analysis.getContext().getConnection();
    if (dm != null) {
        TypedReturnCode<java.sql.Connection> trc = JavaSqlFactory.createConnection((Connection) dm);
        // MOD qiongli 2011-1-10 feature 16796
        boolean isDelimitedFileConnection = ConnectionUtils.isDelimitedFileConnection((DataProvider) dm);
        if (trc != null) {
            // SoftwareSystem softwareSystem = DatabaseContentRetriever.getSoftwareSystem(conn);
            // MOD sizhaoliu TDQ-6316
            dbmsLanguage = DbmsLanguageFactory.createDbmsLanguage(dm);
        }
        // MOD xqliu 2010-08-12 bug 14601
        if (!(isSQLPattern || DefinitionHandler.getInstance().canRunRegularExpressionMatchingIndicator(dbmsLanguage, isJavaEngin, pattern) || isDelimitedFileConnection)) {
            // MessageDialogWithToggle.openInformation(null,
            // DefaultMessagesImpl.getString("PatternUtilities.Pattern"), DefaultMessagesImpl //$NON-NLS-1$
            // .getString("PatternUtilities.couldnotSetIndicator")); //$NON-NLS-1$
            result.setOk(false);
            // $NON-NLS-1$
            result.setMessage(DefaultMessagesImpl.getString("PatternUtilities.couldnotSetIndicator"));
            return result;
        }
    // ~ 14601
    }
    // when the indicator is created.
    if (indicatorDefinition == null) {
        if (!DefinitionHandler.getInstance().setDefaultIndicatorDefinition(patternMatchingIndicator)) {
            // $NON-NLS-1$
            log.error(DefaultMessagesImpl.getString("PatternUtilities.SetFailed", patternMatchingIndicator.getName()));
        }
    } else {
        patternMatchingIndicator.setIndicatorDefinition(indicatorDefinition);
    }
    IndicatorEnum type = IndicatorEnum.findIndicatorEnum(patternMatchingIndicator.eClass());
    IndicatorUnit addIndicatorUnit = modelElementIndicator.addSpecialIndicator(type, patternMatchingIndicator);
    DependenciesHandler.getInstance().setUsageDependencyOn(analysis, pattern);
    result.setOk(true);
    // $NON-NLS-1$
    result.setMessage(DefaultMessagesImpl.getString("PatternUtilities.OK"));
    result.setObject(addIndicatorUnit);
    return result;
}
Also used : IRepositoryNode(org.talend.repository.model.IRepositoryNode) IndicatorEnum(org.talend.dq.nodes.indicator.type.IndicatorEnum) IndicatorUnit(org.talend.dataprofiler.core.ui.editor.preview.IndicatorUnit) Connection(org.talend.core.model.metadata.builder.connection.Connection) ExecutionLanguage(org.talend.dataquality.analysis.ExecutionLanguage) DataManager(orgomg.cwm.foundation.softwaredeployment.DataManager) IEditorPart(org.eclipse.ui.IEditorPart) RepositoryNode(org.talend.repository.model.RepositoryNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode) OpenItemEditorAction(org.talend.dataprofiler.core.ui.action.actions.OpenItemEditorAction) ColumnIndicator(org.talend.dataprofiler.core.model.ColumnIndicator) ModelElementIndicator(org.talend.dataprofiler.core.model.ModelElementIndicator) PatternMatchingIndicator(org.talend.dataquality.indicators.PatternMatchingIndicator) Indicator(org.talend.dataquality.indicators.Indicator) DbmsLanguage(org.talend.dq.dbms.DbmsLanguage) PatternMatchingIndicator(org.talend.dataquality.indicators.PatternMatchingIndicator) Expression(orgomg.cwm.objectmodel.core.Expression) TypedReturnCode(org.talend.utils.sugars.TypedReturnCode) AnalysisEditor(org.talend.dataprofiler.core.ui.editor.analysis.AnalysisEditor)

Example 54 with ModelElementIndicator

use of org.talend.dataprofiler.core.model.ModelElementIndicator in project tdq-studio-se by Talend.

the class PatternLabelProvider method getPatternRepNodesByIndicator.

/**
 * get the repository nodes corresponding to the indicator.
 *
 * @param meIndicator
 * @return
 */
public static Object[] getPatternRepNodesByIndicator(ModelElementIndicator meIndicator) {
    List<IRepositoryNode> patternRepNodes = RepositoryNodeHelper.getPatternsRepositoryNodes(false);
    ArrayList<Object> ret = new ArrayList<Object>();
    for (Indicator indicator : meIndicator.getPatternIndicators()) {
        Pattern patternInAnalysis = IndicatorHelper.getPattern(indicator);
        for (IRepositoryNode patternRepNode : patternRepNodes) {
            Pattern pattern = ((PatternRepNode) patternRepNode).getPattern();
            if (StringUtils.equals(ResourceHelper.getUUID(patternInAnalysis), ResourceHelper.getUUID(pattern))) {
                ret.add(patternRepNode);
            }
        }
    }
    return ret.toArray();
}
Also used : Pattern(org.talend.dataquality.domain.pattern.Pattern) IRepositoryNode(org.talend.repository.model.IRepositoryNode) ArrayList(java.util.ArrayList) ColumnIndicator(org.talend.dataprofiler.core.model.ColumnIndicator) ModelElementIndicator(org.talend.dataprofiler.core.model.ModelElementIndicator) PatternMatchingIndicator(org.talend.dataquality.indicators.PatternMatchingIndicator) Indicator(org.talend.dataquality.indicators.Indicator) PatternRepNode(org.talend.dq.nodes.PatternRepNode)

Example 55 with ModelElementIndicator

use of org.talend.dataprofiler.core.model.ModelElementIndicator in project tdq-studio-se by Talend.

the class IndicatorThresholdsForm method isContainRowCountIndicator.

private boolean isContainRowCountIndicator() {
    IEditorPart editor = CorePlugin.getDefault().getCurrentActiveEditor();
    if (editor == null) {
        return false;
    }
    AbstractAnalysisMetadataPage masterPage = ((AnalysisEditor) editor).getMasterPage();
    if (masterPage == null) {
        return false;
    }
    // if the analysis type is TABLE Analysis, just return true
    if (AnalysisType.TABLE.equals(masterPage.getAnalysisHandler().getAnalysis().getParameters().getAnalysisType())) {
        return true;
    }
    ModelElementIndicator[] currentModelElementIndicators = masterPage.getCurrentModelElementIndicators();
    if (currentModelElementIndicators == null) {
        return false;
    }
    for (ModelElementIndicator meIndicator : currentModelElementIndicators) {
        if (meIndicator != null && meIndicator.getIndicators() != null) {
            for (Indicator indicator : meIndicator.getIndicators()) {
                if (IndicatorsPackage.eINSTANCE.getRowCountIndicator().equals(indicator.eClass())) {
                    return true;
                }
                if (IndicatorsPackage.eINSTANCE.getCountsIndicator().equals(indicator.eClass())) {
                    CountsIndicator cInd = (CountsIndicator) indicator;
                    if (cInd.getRowCountIndicator() != null) {
                        return true;
                    }
                }
                if (ColumnsetPackage.eINSTANCE.getSimpleStatIndicator().equals(indicator.eClass())) {
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : CountsIndicator(org.talend.dataquality.indicators.CountsIndicator) AbstractAnalysisMetadataPage(org.talend.dataprofiler.core.ui.editor.analysis.AbstractAnalysisMetadataPage) IEditorPart(org.eclipse.ui.IEditorPart) AnalysisEditor(org.talend.dataprofiler.core.ui.editor.analysis.AnalysisEditor) CountsIndicator(org.talend.dataquality.indicators.CountsIndicator) Indicator(org.talend.dataquality.indicators.Indicator) ModelElementIndicator(org.talend.dataprofiler.core.model.ModelElementIndicator) ModelElementIndicator(org.talend.dataprofiler.core.model.ModelElementIndicator)

Aggregations

ModelElementIndicator (org.talend.dataprofiler.core.model.ModelElementIndicator)58 IRepositoryNode (org.talend.repository.model.IRepositoryNode)22 ArrayList (java.util.ArrayList)16 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)16 ModelElement (orgomg.cwm.objectmodel.core.ModelElement)16 MetadataColumnRepositoryObject (org.talend.core.repository.model.repositoryObject.MetadataColumnRepositoryObject)15 Indicator (org.talend.dataquality.indicators.Indicator)13 IndicatorUnit (org.talend.dataprofiler.core.ui.editor.preview.IndicatorUnit)12 TreeItem (org.eclipse.swt.widgets.TreeItem)11 RepositoryNode (org.talend.repository.model.RepositoryNode)10 IndicatorEnum (org.talend.dq.nodes.indicator.type.IndicatorEnum)9 MetadataXmlElementTypeRepositoryObject (org.talend.core.repository.model.repositoryObject.MetadataXmlElementTypeRepositoryObject)7 Connection (org.talend.core.model.metadata.builder.connection.Connection)6 CompositeIndicator (org.talend.dataquality.indicators.CompositeIndicator)6 MetadataTableRepositoryObject (org.talend.core.repository.model.repositoryObject.MetadataTableRepositoryObject)5 TreeEditor (org.eclipse.swt.custom.TreeEditor)4 MouseAdapter (org.eclipse.swt.events.MouseAdapter)4 MouseEvent (org.eclipse.swt.events.MouseEvent)4 Composite (org.eclipse.swt.widgets.Composite)4 Label (org.eclipse.swt.widgets.Label)4