Search in sources :

Example 11 with PatternComponent

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

the class AddPatternISBN13Task method doExecute.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.dataprofiler.migration.AMigrationTask#doExecute()
     */
@Override
protected boolean doExecute() throws Exception {
    parameter = new PatternParameter();
    ReturnCode rc1 = new ReturnCode(true), rc2 = new ReturnCode(true), rc3 = new ReturnCode(true);
    // number folder
    // $NON-NLS-1$
    IFolder folder = ResourceManager.getPatternRegexFolder().getFolder("number");
    if (folder.exists()) {
        // only create ISBN 13 Checker when not found.
        if (!folder.getFile("ISBN_13_Checker_0.1.pattern").exists()) {
            Pattern pattern = newPattern(// $NON-NLS-1$ //$NON-NLS-2$
            "ISBN 13 Checker", // $NON-NLS-1$ //$NON-NLS-2$
            "Java", // $NON-NLS-1$
            "'^ISBN(?:-13)?:?\\ *(97(?:8|9)([ -]?)(?=[0-9]{1,5}\\2?[0-9]{1,7}\\2?[0-9]{1,6}\\2?[0-9])(?:[0-9]\\2*){9}[0-9])$'");
            if (pattern != null) {
                setTagValue(// $NON-NLS-1$
                pattern, // $NON-NLS-1$
                "ISBN-13: 978-2711791415 | ISBN 978-2711791415 |  ISBN: 978-2711791415", // $NON-NLS-1$
                "International Standard Book Number 13 digits");
                rc1 = ElementWriterFactory.getInstance().createPatternWriter().create(pattern, folder);
            }
        }
    }
    // Update IPv6 Address.pattern.
    // $NON-NLS-1$
    IFile file = ResourceManager.getPatternRegexFolder().getFolder("internet").getFile("IPv6_Address_0.1.pattern");
    if (file.exists()) {
        Pattern ipv6Pattern = PatternResourceFileHelper.getInstance().findPattern(file);
        if (ipv6Pattern != null) {
            List<PatternComponent> componentLs = new ArrayList<PatternComponent>();
            // $NON-NLS-1$
            componentLs.add(BooleanExpressionHelper.createRegularExpression("Java", REGEX_BODY, ExpressionType.REGEXP));
            // $NON-NLS-1$
            componentLs.add(BooleanExpressionHelper.createRegularExpression("MySQL", REGEX_BODY, ExpressionType.REGEXP));
            // $NON-NLS-1$
            componentLs.add(BooleanExpressionHelper.createRegularExpression("PostgreSQL", REGEX_BODY, ExpressionType.REGEXP));
            ipv6Pattern.getComponents().clear();
            ipv6Pattern.getComponents().addAll(componentLs);
            rc2 = PatternResourceFileHelper.getInstance().save(ipv6Pattern);
        }
    }
    // Update EN Month.pattern. for expresstion add ()
    // $NON-NLS-1$ //$NON-NLS-2$
    IFile file2 = ResourceManager.getPatternRegexFolder().getFolder("date").getFile("EN_Month_0.1.pattern");
    if (file2.exists()) {
        Pattern enMonthPattern = PatternResourceFileHelper.getInstance().findPattern(file2);
        if (enMonthPattern != null) {
            List<PatternComponent> componentLs = new ArrayList<PatternComponent>();
            // $NON-NLS-1$
            String regexBody = "'^(January|June|July|February|March|May|April|August|September|October|November|December)$'";
            // $NON-NLS-1$
            componentLs.add(BooleanExpressionHelper.createRegularExpression("SQL", regexBody, ExpressionType.REGEXP));
            enMonthPattern.getComponents().clear();
            enMonthPattern.getComponents().addAll(componentLs);
            rc3 = PatternResourceFileHelper.getInstance().save(enMonthPattern);
        }
    }
    return rc1.isOk() && rc2.isOk() && rc3.isOk();
}
Also used : Pattern(org.talend.dataquality.domain.pattern.Pattern) ReturnCode(org.talend.utils.sugars.ReturnCode) IFile(org.eclipse.core.resources.IFile) ArrayList(java.util.ArrayList) PatternComponent(org.talend.dataquality.domain.pattern.PatternComponent) PatternParameter(org.talend.dq.analysis.parameters.PatternParameter) IFolder(org.eclipse.core.resources.IFolder)

Example 12 with PatternComponent

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

the class PatternLabelProvider method isPatternValid.

/**
 * DOC qzhang Comment method "isPatternValid".
 *
 * @param pattern
 * @return
 */
public static boolean isPatternValid(Pattern pattern) {
    boolean valid = false;
    EList<PatternComponent> components = pattern.getComponents();
    for (int i = 0; i < components.size(); i++) {
        RegularExpressionImpl regularExpress = (RegularExpressionImpl) components.get(i);
        String body = regularExpress.getExpression().getBody();
        // $NON-NLS-1$
        valid = ((body != null) && body.matches("'.*'"));
        if (!valid) {
            break;
        }
    }
    return valid;
}
Also used : RegularExpressionImpl(org.talend.dataquality.domain.pattern.impl.RegularExpressionImpl) PatternComponent(org.talend.dataquality.domain.pattern.PatternComponent)

Example 13 with PatternComponent

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

the class RegexpMatchingIndicatorImplTest method testGetRegexsuccess.

/**
 * Test method for {@link org.talend.dataquality.indicators.impl.RegexpMatchingIndicatorImpl#getJavaRegex()}.
 */
@Test
public void testGetRegexsuccess() {
    // RegexpMatchingIndicator
    RegexpMatchingIndicator createRegexpMatchingIndicator = IndicatorsFactory.eINSTANCE.createRegexpMatchingIndicator();
    // ~RegexpMatchingIndicator
    // IndicatorParameters
    IndicatorParameters createIndicatorParameters = IndicatorsFactory.eINSTANCE.createIndicatorParameters();
    // ~IndicatorParameters
    // Domain
    Domain createDomain = DomainFactory.eINSTANCE.createDomain();
    EList<Pattern> patterns = createDomain.getPatterns();
    // ~Domain
    // Pattern
    Pattern createJavaPattern = PatternFactory.eINSTANCE.createPattern();
    Pattern createSQLPattern = PatternFactory.eINSTANCE.createPattern();
    Pattern createMSSQLPattern = PatternFactory.eINSTANCE.createPattern();
    patterns.add(createJavaPattern);
    patterns.add(createSQLPattern);
    patterns.add(createMSSQLPattern);
    // ~Pattern
    // init java Pattern data
    RegularExpression createJavaRegularExpression = PatternFactory.eINSTANCE.createRegularExpression();
    TdExpression createJavaTdExpression = RelationalFactory.eINSTANCE.createTdExpression();
    createJavaTdExpression.setBody(JavaRegex);
    createJavaTdExpression.setLanguage("Java");
    createJavaRegularExpression.setExpression(createJavaTdExpression);
    createJavaRegularExpression.setExpressionType(ExpressionType.REGEXP.getLiteral());
    EList<PatternComponent> components = createJavaPattern.getComponents();
    components.add(createJavaRegularExpression);
    // ~init java Pattern data
    createIndicatorParameters.setDataValidDomain(createDomain);
    createRegexpMatchingIndicator.setParameters(createIndicatorParameters);
    // call getRegex()
    String regexResult = createRegexpMatchingIndicator.getRegex();
    String JavaRegex2 = JavaRegex.substring(1, JavaRegex.length() - 1);
    // ~call getRegex()
    Assert.assertTrue(JavaRegex2.equalsIgnoreCase(regexResult));
}
Also used : Pattern(org.talend.dataquality.domain.pattern.Pattern) RegularExpression(org.talend.dataquality.domain.pattern.RegularExpression) TdExpression(org.talend.cwm.relational.TdExpression) IndicatorParameters(org.talend.dataquality.indicators.IndicatorParameters) PatternComponent(org.talend.dataquality.domain.pattern.PatternComponent) RegexpMatchingIndicator(org.talend.dataquality.indicators.RegexpMatchingIndicator) Domain(org.talend.dataquality.domain.Domain) Test(org.junit.Test)

Example 14 with PatternComponent

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

the class DbmsLanguageTest method testGetRegexpGetMssqlFromContainDefaultAndWithoutMssql.

/**
 * Test method for
 * {@link org.talend.dq.dbms.DbmsLanguage#getRegexp(org.talend.dataquality.domain.pattern.Pattern, boolean)}.
 */
@Test
public void testGetRegexpGetMssqlFromContainDefaultAndWithoutMssql() {
    // Pattern
    Pattern createPattern = PatternFactory.eINSTANCE.createPattern();
    // ~Pattern
    // init sql Expression data
    RegularExpression createSqlRegularExpression = PatternFactory.eINSTANCE.createRegularExpression();
    TdExpression createSqlTdExpression = RelationalFactory.eINSTANCE.createTdExpression();
    createSqlTdExpression.setBody(SqlRegex);
    createSqlTdExpression.setLanguage(ExecutionLanguage.SQL.getName());
    createSqlRegularExpression.setExpression(createSqlTdExpression);
    createSqlRegularExpression.setExpressionType(ExpressionType.REGEXP.getLiteral());
    EList<PatternComponent> components = createPattern.getComponents();
    components.add(createSqlRegularExpression);
    // ~init sql Expression data
    // init java Expression data
    RegularExpression createJavaRegularExpression = PatternFactory.eINSTANCE.createRegularExpression();
    TdExpression createJavaTdExpression = RelationalFactory.eINSTANCE.createTdExpression();
    createJavaTdExpression.setBody(JavaRegex);
    createJavaTdExpression.setLanguage(SupportDBUrlType.JAVADEFAULTURL.getLanguage());
    createJavaRegularExpression.setExpression(createJavaTdExpression);
    createJavaRegularExpression.setExpressionType(ExpressionType.REGEXP.getLiteral());
    components = createPattern.getComponents();
    components.add(createJavaRegularExpression);
    try {
        DbmsLanguage dbms = DbmsLanguageFactory.createDbmsLanguage(SupportDBUrlType.MSSQLDEFAULTURL);
        Assert.assertTrue(SqlRegex.equalsIgnoreCase(dbms.getRegexp(createPattern).getBody()));
    } catch (Exception e) {
        fail(e.getMessage());
    }
}
Also used : Pattern(org.talend.dataquality.domain.pattern.Pattern) RegularExpression(org.talend.dataquality.domain.pattern.RegularExpression) TdExpression(org.talend.cwm.relational.TdExpression) PatternComponent(org.talend.dataquality.domain.pattern.PatternComponent) Test(org.junit.Test)

Example 15 with PatternComponent

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

the class DbmsLanguageTest method testGetExpressionPatternComponent.

/**
 * Test method for
 * {@link org.talend.dq.dbms.DbmsLanguage#getExpression(org.talend.dataquality.domain.pattern.PatternComponent)}.
 */
@Test
public void testGetExpressionPatternComponent() {
    try {
        Pattern createPattern = createPattern();
        EList<PatternComponent> components = createPattern.getComponents();
        DbmsLanguage dbms = getMysqlDbmsLanguage();
        Assert.assertNotNull(dbms.getExpression(components.get(0)));
    } catch (Exception e) {
        fail(e.getMessage());
    }
}
Also used : Pattern(org.talend.dataquality.domain.pattern.Pattern) PatternComponent(org.talend.dataquality.domain.pattern.PatternComponent) Test(org.junit.Test)

Aggregations

PatternComponent (org.talend.dataquality.domain.pattern.PatternComponent)24 RegularExpression (org.talend.dataquality.domain.pattern.RegularExpression)18 Pattern (org.talend.dataquality.domain.pattern.Pattern)15 TdExpression (org.talend.cwm.relational.TdExpression)10 Test (org.junit.Test)9 RegularExpressionImpl (org.talend.dataquality.domain.pattern.impl.RegularExpressionImpl)5 ArrayList (java.util.ArrayList)4 Domain (org.talend.dataquality.domain.Domain)4 TDQPatternItem (org.talend.dataquality.properties.TDQPatternItem)4 Expression (orgomg.cwm.objectmodel.core.Expression)4 IndicatorParameters (org.talend.dataquality.indicators.IndicatorParameters)3 RegexpMatchingIndicator (org.talend.dataquality.indicators.RegexpMatchingIndicator)3 IFile (org.eclipse.core.resources.IFile)2 URI (org.eclipse.emf.common.util.URI)2 Resource (org.eclipse.emf.ecore.resource.Resource)2 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)2 ReturnCode (org.talend.utils.sugars.ReturnCode)2 File (java.io.File)1 URI (java.net.URI)1 HashMap (java.util.HashMap)1