Search in sources :

Example 16 with PatternMatchingIndicator

use of org.talend.dataquality.indicators.PatternMatchingIndicator 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 17 with PatternMatchingIndicator

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

the class AnalysisHelper method getPatterns.

public static List<Pattern> getPatterns(Analysis analysis) {
    List<Pattern> rets = new ArrayList<Pattern>();
    EList<Indicator> indicators = analysis.getResults().getIndicators();
    for (Indicator indicator : indicators) {
        if (indicator instanceof PatternMatchingIndicator) {
            IndicatorParameters parameters = ((PatternMatchingIndicator) indicator).getParameters();
            if (null != parameters && null != parameters.getDataValidDomain()) {
                rets.addAll(parameters.getDataValidDomain().getPatterns());
            }
        }
        // MOD yyi 2010-08-03 14292 Add dependency for children indicator in Column Set analysis
        if (indicator instanceof AllMatchIndicator) {
            EList<RegexpMatchingIndicator> list = ((AllMatchIndicator) indicator).getCompositeRegexMatchingIndicators();
            for (RegexpMatchingIndicator pattern : list) {
                IndicatorParameters parameters = pattern.getParameters();
                if (null != parameters && null != parameters.getDataValidDomain()) {
                    rets.addAll(parameters.getDataValidDomain().getPatterns());
                }
            }
        }
    // ~
    }
    return rets;
}
Also used : Pattern(org.talend.dataquality.domain.pattern.Pattern) PatternMatchingIndicator(org.talend.dataquality.indicators.PatternMatchingIndicator) AllMatchIndicator(org.talend.dataquality.indicators.columnset.AllMatchIndicator) IndicatorParameters(org.talend.dataquality.indicators.IndicatorParameters) ArrayList(java.util.ArrayList) RegexpMatchingIndicator(org.talend.dataquality.indicators.RegexpMatchingIndicator) PatternMatchingIndicator(org.talend.dataquality.indicators.PatternMatchingIndicator) RecordMatchingIndicator(org.talend.dataquality.indicators.columnset.RecordMatchingIndicator) RegexpMatchingIndicator(org.talend.dataquality.indicators.RegexpMatchingIndicator) Indicator(org.talend.dataquality.indicators.Indicator) AllMatchIndicator(org.talend.dataquality.indicators.columnset.AllMatchIndicator) UserDefIndicator(org.talend.dataquality.indicators.sql.UserDefIndicator)

Example 18 with PatternMatchingIndicator

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

the class ModelElementDuplicateHandle method dupAnaWithoutBuiltInPattern.

/**
 * when duplicate an analysis,remove the built-in pattern. or else, the reference pattern will be copied as a built-in
 * pattern.
 *
 * @param oldModelElement
 * @return
 */
private ModelElement dupAnaWithoutBuiltInPattern(ModelElement oldModelElement) {
    ModelElement newModEle = null;
    if (!(oldModelElement instanceof Analysis)) {
        newModEle = (ModelElement) EMFSharedResources.getInstance().copyEObject(oldModelElement);
        return newModEle;
    }
    try {
        Analysis analysis = (Analysis) oldModelElement;
        EList<Indicator> indicators = analysis.getResults().getIndicators();
        List<Indicator> orignalIndicators = new ArrayList<Indicator>();
        orignalIndicators.addAll(indicators);
        Map<Indicator, List<Pattern>> map = new HashMap<Indicator, List<Pattern>>();
        // 2.after copy the analysis without built-in pattern, reset the built for the old analysis.
        for (Indicator indicator : indicators) {
            if (!(indicator instanceof PatternMatchingIndicator)) {
                continue;
            }
            List<Pattern> builtInLs = new ArrayList<Pattern>();
            if (indicator instanceof AllMatchIndicator) {
                EList<RegexpMatchingIndicator> list = ((AllMatchIndicator) indicator).getCompositeRegexMatchingIndicators();
                for (RegexpMatchingIndicator regxIndicator : list) {
                    builtInLs.addAll(regxIndicator.getParameters().getDataValidDomain().getBuiltInPatterns());
                    map.put(regxIndicator, builtInLs);
                    regxIndicator.getParameters().getDataValidDomain().getBuiltInPatterns().clear();
                }
            } else {
                builtInLs.addAll(indicator.getParameters().getDataValidDomain().getBuiltInPatterns());
                map.put(indicator, builtInLs);
                indicator.getParameters().getDataValidDomain().getBuiltInPatterns().clear();
            }
        }
        newModEle = (ModelElement) EMFSharedResources.getInstance().copyEObject(analysis);
        for (Indicator patternInd : map.keySet()) {
            patternInd.getParameters().getDataValidDomain().getBuiltInPatterns().addAll(map.get(patternInd));
        }
        ProxyRepositoryFactory.getInstance().getRepositoryFactoryFromProvider().getResourceManager().saveResource(analysis.eResource());
    } catch (Exception e) {
        LOG.error(e);
    }
    return newModEle;
}
Also used : Pattern(org.talend.dataquality.domain.pattern.Pattern) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PatternMatchingIndicator(org.talend.dataquality.indicators.PatternMatchingIndicator) RegexpMatchingIndicator(org.talend.dataquality.indicators.RegexpMatchingIndicator) Indicator(org.talend.dataquality.indicators.Indicator) AllMatchIndicator(org.talend.dataquality.indicators.columnset.AllMatchIndicator) BusinessException(org.talend.commons.exception.BusinessException) ModelElement(orgomg.cwm.objectmodel.core.ModelElement) PatternMatchingIndicator(org.talend.dataquality.indicators.PatternMatchingIndicator) AllMatchIndicator(org.talend.dataquality.indicators.columnset.AllMatchIndicator) Analysis(org.talend.dataquality.analysis.Analysis) ArrayList(java.util.ArrayList) EList(org.eclipse.emf.common.util.EList) List(java.util.List) RegexpMatchingIndicator(org.talend.dataquality.indicators.RegexpMatchingIndicator)

Aggregations

PatternMatchingIndicator (org.talend.dataquality.indicators.PatternMatchingIndicator)18 Pattern (org.talend.dataquality.domain.pattern.Pattern)12 ArrayList (java.util.ArrayList)8 Analysis (org.talend.dataquality.analysis.Analysis)8 Indicator (org.talend.dataquality.indicators.Indicator)8 IndicatorParameters (org.talend.dataquality.indicators.IndicatorParameters)8 Expression (orgomg.cwm.objectmodel.core.Expression)7 Test (org.junit.Test)6 TdExpression (org.talend.cwm.relational.TdExpression)6 Domain (org.talend.dataquality.domain.Domain)6 RegularExpression (org.talend.dataquality.domain.pattern.RegularExpression)6 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)5 AnalysisContext (org.talend.dataquality.analysis.AnalysisContext)5 ChartDataEntity (org.talend.dq.indicators.preview.table.ChartDataEntity)5 TdColumn (org.talend.cwm.relational.TdColumn)4 TdTable (org.talend.cwm.relational.TdTable)4 IndicatorUnit (org.talend.dataprofiler.core.ui.editor.preview.IndicatorUnit)4 UDIndicatorDefinition (org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition)4 UserDefIndicator (org.talend.dataquality.indicators.sql.UserDefIndicator)4 Catalog (orgomg.cwm.resource.relational.Catalog)4