Search in sources :

Example 71 with Pattern

use of org.talend.dataquality.domain.pattern.Pattern in project tdq-studio-se by Talend.

the class DomainHelper method createPattern.

/**
 * Method "createPattern".
 *
 * @param language
 * @param regexp
 * @return a new pattern from the given regular expression
 */
public static Pattern createPattern(String language, String regexp) {
    Pattern pattern = PatternFactory.eINSTANCE.createPattern();
    pattern.getComponents().add(BooleanExpressionHelper.createRegularExpression(language, regexp));
    return pattern;
}
Also used : Pattern(org.talend.dataquality.domain.pattern.Pattern)

Example 72 with Pattern

use of org.talend.dataquality.domain.pattern.Pattern 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 73 with Pattern

use of org.talend.dataquality.domain.pattern.Pattern in project tdq-studio-se by Talend.

the class DomainHelper method getPattern.

private static String getPattern(final Collection<Domain> dataFilters, DomainType domainType, PatternType patternType) {
    if (dataFilters == null) {
        return null;
    }
    for (Domain domain : dataFilters) {
        if (!domainType.label.equals(domain.getName())) {
            continue;
        }
        EList<Pattern> patterns = domain.getPatterns();
        for (Pattern pattern : patterns) {
            if (patternType.label.equals(pattern.getName())) {
                PatternComponent next = pattern.getComponents().iterator().next();
                if (next == null) {
                    continue;
                } else {
                    RegularExpression regexp = (RegularExpression) next;
                    Expression expression = regexp.getExpression();
                    if (expression != null) {
                        return expression.getBody();
                    }
                }
            }
        }
    }
    return null;
}
Also used : Pattern(org.talend.dataquality.domain.pattern.Pattern) RegularExpression(org.talend.dataquality.domain.pattern.RegularExpression) RegularExpression(org.talend.dataquality.domain.pattern.RegularExpression) Expression(orgomg.cwm.objectmodel.core.Expression) PatternComponent(org.talend.dataquality.domain.pattern.PatternComponent) Domain(org.talend.dataquality.domain.Domain)

Example 74 with Pattern

use of org.talend.dataquality.domain.pattern.Pattern 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)

Example 75 with Pattern

use of org.talend.dataquality.domain.pattern.Pattern in project tdq-studio-se by Talend.

the class TDQPatternItemImpl method setPattern.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public void setPattern(Pattern newPattern) {
    Pattern oldPattern = pattern;
    pattern = newPattern;
    if (eNotificationRequired())
        eNotify(new ENotificationImpl(this, Notification.SET, PropertiesPackage.TDQ_PATTERN_ITEM__PATTERN, oldPattern, pattern));
}
Also used : Pattern(org.talend.dataquality.domain.pattern.Pattern) ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl)

Aggregations

Pattern (org.talend.dataquality.domain.pattern.Pattern)75 RegularExpression (org.talend.dataquality.domain.pattern.RegularExpression)27 Test (org.junit.Test)19 TdExpression (org.talend.cwm.relational.TdExpression)18 Domain (org.talend.dataquality.domain.Domain)16 Analysis (org.talend.dataquality.analysis.Analysis)15 PatternComponent (org.talend.dataquality.domain.pattern.PatternComponent)15 IndicatorParameters (org.talend.dataquality.indicators.IndicatorParameters)14 ArrayList (java.util.ArrayList)13 PatternMatchingIndicator (org.talend.dataquality.indicators.PatternMatchingIndicator)13 IFile (org.eclipse.core.resources.IFile)11 TDQPatternItem (org.talend.dataquality.properties.TDQPatternItem)10 Expression (orgomg.cwm.objectmodel.core.Expression)10 IFolder (org.eclipse.core.resources.IFolder)9 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)9 Indicator (org.talend.dataquality.indicators.Indicator)9 Item (org.talend.core.model.properties.Item)7 TdColumn (org.talend.cwm.relational.TdColumn)7 RegexpMatchingIndicator (org.talend.dataquality.indicators.RegexpMatchingIndicator)6 IndicatorDefinition (org.talend.dataquality.indicators.definition.IndicatorDefinition)6