Search in sources :

Example 56 with Pattern

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

the class RespositoryDetailView method createFileDetail.

private boolean createFileDetail(boolean is, IRepositoryViewObject reposViewObj) {
    // MOD klliu 2001-02-28 bug 19154
    if (reposViewObj.getProperty() != null) {
        Item item = reposViewObj.getProperty().getItem();
        if (item instanceof ConnectionItem) {
            Connection conn = ((ConnectionItem) item).getConnection();
            createDataProviderDetail(conn);
            is = false;
        }
        if (item instanceof TDQAnalysisItem) {
            Analysis analysis = ((TDQAnalysisItem) item).getAnalysis();
            createAnaysisDetail(analysis);
            is = false;
        }
        if (item instanceof TDQPatternItem) {
            Pattern pattern = ((TDQPatternItem) item).getPattern();
            createPatternDetail(pattern);
            is = false;
        }
        if (item instanceof TDQReportItem) {
            Report report = ((TDQReportItem) item).getReport();
            createReportDetail(report);
            is = false;
        }
    }
    return is;
}
Also used : ContextItem(org.talend.core.model.properties.ContextItem) Item(org.talend.core.model.properties.Item) TDQAnalysisItem(org.talend.dataquality.properties.TDQAnalysisItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) TDQPatternItem(org.talend.dataquality.properties.TDQPatternItem) TDQReportItem(org.talend.dataquality.properties.TDQReportItem) Pattern(org.talend.dataquality.domain.pattern.Pattern) Report(orgomg.cwmx.analysis.informationreporting.Report) TdReport(org.talend.dataquality.reports.TdReport) ConnectionItem(org.talend.core.model.properties.ConnectionItem) Analysis(org.talend.dataquality.analysis.Analysis) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) DelimitedFileConnection(org.talend.core.model.metadata.builder.connection.DelimitedFileConnection) FileConnection(org.talend.core.model.metadata.builder.connection.FileConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) TDQPatternItem(org.talend.dataquality.properties.TDQPatternItem) TDQReportItem(org.talend.dataquality.properties.TDQReportItem) TDQAnalysisItem(org.talend.dataquality.properties.TDQAnalysisItem)

Example 57 with Pattern

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

the class FileSystemImportWriter method mergePattern.

/**
 * when imported pattern is from lower version, even if it is modified, the "modify date" is still null, so, even if
 * the modify date is null ,still do the comparation. [for Pattern matadata(Purpose, Description, Author, Status):
 * 1) will replace old value with new value if new value is not blank; 2) will keep old value if new value is blank]
 *
 * @param record
 * @param patternItem
 */
protected void mergePattern(ItemRecord record, TDQPatternItem patternItem) {
    // only when the Si is modified, do the save
    boolean isModified = false;
    // old objects
    Pattern pattern = patternItem.getPattern();
    Property patternProp = patternItem.getProperty();
    // new objects
    Pattern recordPattern = (Pattern) record.getElement();
    Property recordProp = record.getProperty();
    // get expression list from record
    EList<PatternComponent> importComponents = recordPattern.getComponents();
    // for each expression:
    for (PatternComponent component : importComponents) {
        // if the modify date ==null, maybe it is from lower version, still do the compare
        TdExpression importEx = ((RegularExpression) component).getExpression();
        PatternComponent replaced = null;
        for (PatternComponent pComp : pattern.getComponents()) {
            TdExpression pex = ((RegularExpression) pComp).getExpression();
            if (importEx.getLanguage().equals(pex.getLanguage())) {
                replaced = pComp;
                break;
            }
        }
        // if new, add to SI
        if (replaced == null) {
            pattern.getComponents().add(createPatternComponent(component));
            isModified = true;
        } else {
            // if the expression are different: compare the modify date, make the SI keep the new one
            if (replaceExpression(((RegularExpression) replaced).getExpression(), importEx)) {
                pattern.getComponents().remove(replaced);
                pattern.getComponents().add(createPatternComponent(component));
                isModified = true;
            }
        }
    }
    // for Pattern Metadata
    if (patternProp != null && recordProp != null) {
        if (!StringUtils.isBlank(recordProp.getPurpose())) {
            patternProp.setPurpose(recordProp.getPurpose());
        }
        if (!StringUtils.isBlank(recordProp.getDescription())) {
            patternProp.setDescription(recordProp.getDescription());
        }
        patternProp.setAuthor(recordProp.getAuthor());
        patternProp.setStatusCode(recordProp.getStatusCode());
        isModified = true;
    }
    if (isModified) {
        ElementWriterFactory.getInstance().createPatternWriter().save(patternItem, false);
    }
}
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) Property(org.talend.core.model.properties.Property)

Example 58 with Pattern

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

the class USStateCodesPatternRegexTest method setUpBeforeClass.

@BeforeClass
public static void setUpBeforeClass() throws Exception {
    DQStructureManager.getInstance().createDQStructure();
    IFolder patternRegexFolder = ResourceManager.getPatternRegexFolder();
    // $NON-NLS-1$
    IFolder folder = patternRegexFolder.getFolder("address");
    // $NON-NLS-1$
    IFile file = folder.getFile("US_State_Codes_0.1.pattern");
    Assert.assertTrue(file.exists());
    ModelElement modelElement = PatternResourceFileHelper.getInstance().getModelElement(file);
    if (Pattern.class.isInstance(modelElement)) {
        regexp = DomainHelper.getRegexp((Pattern) modelElement, DbmsLanguage.SQL);
        if (regexp.charAt(0) == '\'') {
            regexp = regexp.substring(1);
        }
        if (regexp.charAt(regexp.length() - 1) == '\'') {
            regexp = regexp.substring(0, regexp.length() - 2);
        }
    }
}
Also used : ModelElement(orgomg.cwm.objectmodel.core.ModelElement) Pattern(org.talend.dataquality.domain.pattern.Pattern) IFile(org.eclipse.core.resources.IFile) IFolder(org.eclipse.core.resources.IFolder) BeforeClass(org.junit.BeforeClass)

Example 59 with Pattern

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

the class AnalysisHandleTest method addPatternToDomain.

private static void addPatternToDomain(Domain domain, RegularExpression filter, String patternName) {
    Pattern pattern = PatternFactory.eINSTANCE.createPattern();
    pattern.setName(patternName);
    pattern.getComponents().add(filter);
    domain.getPatterns().add(pattern);
    domain.getOwnedElement().add(pattern);
}
Also used : Pattern(org.talend.dataquality.domain.pattern.Pattern)

Example 60 with Pattern

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

the class IndicatorHelperTest method testGetPattern_1.

/**
 * Test method for get pattern based on indicator.
 */
@Test
public void testGetPattern_1() {
    Indicator indicator = IndicatorsFactory.eINSTANCE.createRegexpMatchingIndicator();
    IndicatorParameters parameters = IndicatorsFactory.eINSTANCE.createIndicatorParameters();
    Domain validData = DomainFactory.eINSTANCE.createDomain();
    Pattern pattern = PatternFactory.eINSTANCE.createPattern();
    // $NON-NLS-1$
    pattern.setName("Blank Text");
    validData.getPatterns().add(pattern);
    parameters.setDataValidDomain(validData);
    indicator.setParameters(parameters);
    Pattern pattern2 = IndicatorHelper.getPattern(indicator);
    assert (pattern2 != null);
    assert (pattern2.equals(pattern));
}
Also used : Pattern(org.talend.dataquality.domain.pattern.Pattern) IndicatorParameters(org.talend.dataquality.indicators.IndicatorParameters) Domain(org.talend.dataquality.domain.Domain) NullCountIndicator(org.talend.dataquality.indicators.NullCountIndicator) Indicator(org.talend.dataquality.indicators.Indicator) RowCountIndicator(org.talend.dataquality.indicators.RowCountIndicator) Test(org.junit.Test)

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