Search in sources :

Example 41 with Pattern

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

the class TreeMessageInfoDialog method getLabelProvider.

protected ILabelProvider getLabelProvider() {
    if (labelProvider == null) {
        labelProvider = new LabelProvider() {

            @Override
            public String getText(Object obj) {
                if (obj == null) {
                    // $NON-NLS-1$
                    return "";
                }
                if (obj instanceof ImpactNode) {
                    return ((ImpactNode) obj).toString();
                } else if (obj instanceof IFile) {
                    IFile file = (IFile) obj;
                    ModelElement modelElement = ModelElementFileFactory.getModelElement(file);
                    // MOD msjian TDQ-5909: modify to displayName
                    return modelElement != null ? PropertyHelper.getProperty(modelElement).getDisplayName() : file.getName();
                } else if (obj instanceof RepositoryViewObject) {
                    // Added 20130226 TDQ-6899 show the name for Jrxml object (which has no related ModelElement)
                    return ((IRepositoryViewObject) obj).getLabel();
                } else if (obj instanceof MetadataTable) {
                    // ADD TDQ-7146: for all type's connection table/view node
                    return ((ModelElement) obj).getName();
                }
                Property property = PropertyHelper.getProperty((ModelElement) obj);
                return property == null ? ((ModelElement) obj).getName() : property.getDisplayName();
            }

            @Override
            public Image getImage(Object obj) {
                ModelElement modelElement = null;
                if (obj instanceof ModelElement) {
                    modelElement = (ModelElement) obj;
                } else if (obj instanceof ImpactNode) {
                    modelElement = ((ImpactNode) obj).getNodeElement();
                } else if (obj instanceof IFile) {
                    modelElement = ModelElementFileFactory.getModelElement((IFile) obj);
                } else if (obj instanceof RepositoryViewObject) {
                    // Added 20130226 TDQ-6899 show the name for Jrxml object (which has no related ModelElement)
                    return ImageLib.getImage(ImageLib.JRXML_ICON);
                }
                // ~
                if (modelElement == null) {
                    if (((ImpactNode) obj).getNode() != null) {
                        return ImageLib.getImage(ImageLib.JRXML_ICON);
                    }
                    return super.getImage(obj);
                }
                Image modelElementImage = null;
                String imgName = null;
                if (modelElement instanceof Analysis) {
                    imgName = ImageLib.ANALYSIS_OBJECT;
                } else if (modelElement instanceof TdReport) {
                    imgName = ImageLib.REPORT_OBJECT;
                } else if (modelElement instanceof DatabaseConnection) {
                    imgName = ImageLib.CONNECTION;
                } else if (modelElement instanceof DelimitedFileConnection) {
                    imgName = ImageLib.FILE_DELIMITED;
                } else if (modelElement instanceof Pattern) {
                    imgName = ImageLib.PATTERN_REG;
                } else if (modelElement instanceof IndicatorDefinition) {
                    // IndicatorDefinition
                    if (modelElement instanceof DQRule) {
                        imgName = ImageLib.DQ_RULE;
                    } else if (modelElement instanceof MatchRuleDefinition) {
                        imgName = ImageLib.MATCH_RULE_ICON;
                    } else {
                        imgName = ImageLib.IND_DEFINITION;
                    }
                // TDQ-8550~
                } else if (modelElement instanceof MetadataTable) {
                    imgName = ImageLib.TABLE;
                }
                if (imgName != null) {
                    modelElementImage = ImageLib.getImage(imgName);
                }
                // add lock icon on the image
                if (modelElementImage != null) {
                    if (modelElement != null) {
                        Property property = PropertyHelper.getProperty(modelElement);
                        if (property != null) {
                            Item item = property.getItem();
                            if (item != null) {
                                if (ProxyRepositoryManager.getInstance().isLockByUserOwn(item)) {
                                    modelElementImage = ImageLib.createLockedByOwnIcon(imgName);
                                } else if (ProxyRepositoryManager.getInstance().isLockByOthers(item)) {
                                    modelElementImage = ImageLib.createLockedByOtherIcon(imgName);
                                }
                            }
                        }
                    }
                    return modelElementImage;
                }
                return super.getImage(obj);
            }
        };
    }
    return labelProvider;
}
Also used : Pattern(org.talend.dataquality.domain.pattern.Pattern) IFile(org.eclipse.core.resources.IFile) ImpactNode(org.talend.dataprofiler.core.ui.dialog.message.DeleteModelElementConfirmDialog.ImpactNode) TdReport(org.talend.dataquality.reports.TdReport) DelimitedFileConnection(org.talend.core.model.metadata.builder.connection.DelimitedFileConnection) MatchRuleDefinition(org.talend.dataquality.rules.MatchRuleDefinition) Image(org.eclipse.swt.graphics.Image) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition) DQRule(org.talend.dataquality.rules.DQRule) ModelElement(orgomg.cwm.objectmodel.core.ModelElement) Item(org.talend.core.model.properties.Item) Analysis(org.talend.dataquality.analysis.Analysis) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) RepositoryViewObject(org.talend.core.model.repository.RepositoryViewObject) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) ILabelProvider(org.eclipse.jface.viewers.ILabelProvider) LabelProvider(org.eclipse.jface.viewers.LabelProvider) Property(org.talend.core.model.properties.Property) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) RepositoryViewObject(org.talend.core.model.repository.RepositoryViewObject)

Example 42 with Pattern

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

the class DomainHelper method addPatternToDomain.

/**
 * Method "addPatternToDomain" creates a Pattern object with the given expression and stores it in the given domain.
 * Beware that it is also added to the owned elements of the Domain. This means that is contained in the domain and
 * cannot be shared among several domains.
 *
 * @param domain
 * @param tableFilter
 * @param tablePattern
 */
private static void addPatternToDomain(Domain domain, RegularExpression tableFilter, String tablePattern, PatternType type) {
    Pattern pattern = PatternFactory.eINSTANCE.createPattern();
    pattern.setName(type.label);
    pattern.getComponents().add(tableFilter);
    domain.getPatterns().add(pattern);
    domain.getOwnedElement().add(pattern);
}
Also used : Pattern(org.talend.dataquality.domain.pattern.Pattern)

Example 43 with Pattern

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

the class DomainHelper method setDataFilterPattern.

/**
 * Method "setDataFilterPattern".
 *
 * @param dataFilters a list of data filters
 * @param type
 * @param domainName
 * @param filterPattern
 * @return
 */
private static Domain setDataFilterPattern(final Collection<Domain> dataFilters, PatternType type, DomainType domainName, String filterPattern) {
    RegularExpression filterExpr = BooleanExpressionHelper.createRegularExpression(null, filterPattern);
    for (Domain domain : dataFilters) {
        if (!domainName.label.equals(domain.getName())) {
            continue;
        }
        boolean exists = false;
        EList<Pattern> patterns = domain.getPatterns();
        for (Pattern pattern : patterns) {
            if (type.label.equals(pattern.getName())) {
                exists = true;
                // remove previous expressions
                pattern.getComponents().clear();
                pattern.getComponents().add(filterExpr);
            }
        }
        if (!exists) {
            // create pattern and set into the data filter
            addPatternToDomain(domain, filterExpr, filterPattern, type);
        }
        return domain;
    }
    // no data filter has not been set yet
    Domain domain = DomainFactory.eINSTANCE.createDomain();
    dataFilters.add(domain);
    domain.setName(domainName.label);
    addPatternToDomain(domain, filterExpr, filterPattern, type);
    return domain;
}
Also used : RegularExpression(org.talend.dataquality.domain.pattern.RegularExpression) Pattern(org.talend.dataquality.domain.pattern.Pattern) Domain(org.talend.dataquality.domain.Domain)

Example 44 with Pattern

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

the class AnalysisExecutorHelper method hotCopyPatterns.

/**
 * DOC zhao Comment method "hotCopyPatterns".
 *
 * @param indicator
 * @param patterns
 */
private static void hotCopyPatterns(Indicator indicator, List<Pattern> patterns) {
    Set<Pattern> deepCopiedPatterns = new HashSet<Pattern>();
    for (Pattern pattern : patterns) {
        Pattern deepCopiedPattern = EObjectHelper.deepCopy(pattern);
        deepCopiedPattern.getSupplierDependency().clear();
        deepCopiedPatterns.add(deepCopiedPattern);
    }
    indicator.getParameters().getDataValidDomain().getBuiltInPatterns().clear();
    indicator.getParameters().getDataValidDomain().getBuiltInPatterns().addAll(deepCopiedPatterns);
    EMFUtil.saveResource(indicator.eResource());
}
Also used : Pattern(org.talend.dataquality.domain.pattern.Pattern) HashSet(java.util.HashSet)

Example 45 with Pattern

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

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