Search in sources :

Example 21 with PatternComponent

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

the class ExportFactory method getRelatedValueFromPattern.

private static Map<PatternToExcelEnum, String> getRelatedValueFromPattern(Pattern pattern, IFolder folder) {
    Map<PatternToExcelEnum, String> patternMap = new HashMap<PatternToExcelEnum, String>();
    if (folder != null) {
        IFile file = ResourceFileMap.findCorrespondingFile(pattern);
        // MOD sizhaoliu 2012-5-28 TDQ-5481
        URI parentURI = ResourceManager.getPatternFolder().getLocationURI();
        String relativePath = parentURI.relativize(file.getParent().getLocationURI()).toString();
        // remove Regex or SQL prefix
        relativePath = relativePath.substring(relativePath.indexOf('/') + 1);
        // MOD qiongli 2012-12-18 TDQ-5899, Replace relative path Regex/SQL with empty string.
        if (EResourceConstant.PATTERN_REGEX.getName().equals(relativePath) || EResourceConstant.PATTERN_SQL.getName().equals(relativePath)) {
            relativePath = PluginConstant.EMPTY_STRING;
        }
        // get the basic information
        patternMap.put(PatternToExcelEnum.Label, pattern.getName());
        patternMap.put(PatternToExcelEnum.Purpose, MetadataHelper.getPurpose(pattern));
        patternMap.put(PatternToExcelEnum.Description, MetadataHelper.getDescription(pattern));
        patternMap.put(PatternToExcelEnum.Author, MetadataHelper.getAuthor(pattern));
        patternMap.put(PatternToExcelEnum.RelativePath, relativePath);
        for (PatternLanguageType languagetype : PatternLanguageType.values()) {
            for (PatternComponent component : pattern.getComponents()) {
                Expression expression = ((RegularExpression) component).getExpression();
                if (expression != null && expression.getLanguage().equalsIgnoreCase(languagetype.getLiteral())) {
                    patternMap.put(languagetype.getExcelEnum(), expression.getBody());
                }
            }
            if (!patternMap.containsKey(languagetype.getExcelEnum())) {
                // $NON-NLS-1$
                patternMap.put(languagetype.getExcelEnum(), "");
            }
        }
    }
    return patternMap;
}
Also used : RegularExpression(org.talend.dataquality.domain.pattern.RegularExpression) IFile(org.eclipse.core.resources.IFile) HashMap(java.util.HashMap) TdExpression(org.talend.cwm.relational.TdExpression) RegularExpression(org.talend.dataquality.domain.pattern.RegularExpression) Expression(orgomg.cwm.objectmodel.core.Expression) PatternComponent(org.talend.dataquality.domain.pattern.PatternComponent) URI(java.net.URI)

Example 22 with PatternComponent

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

the class UpdateStartWithBlankPatternTask method doExecute.

/*
     * (non-Jsdoc) update the regular express for java
     */
@Override
protected boolean doExecute() throws Exception {
    IPath realtivePath = // $NON-NLS-1$
    ResourceManager.getPatternRegexFolder().getFullPath().append("/text").makeRelativeTo(ResourceManager.getRootProject().getFullPath());
    RootContainer<String, IRepositoryViewObject> tdqViewObjects = ProxyRepositoryFactory.getInstance().getTdqRepositoryViewObjects(ERepositoryObjectType.TDQ_PATTERN_REGEX, realtivePath.toString());
    for (IRepositoryViewObject viewObject : tdqViewObjects.getMembers()) {
        Item item = viewObject.getProperty().getItem();
        Pattern pattern = null;
        if (item != null && item instanceof TDQPatternItem) {
            TDQPatternItem patternItem = (TDQPatternItem) item;
            pattern = patternItem.getPattern();
            boolean isFound = false;
            if (PATTERN_NAME.equals(pattern.getName())) {
                EList<PatternComponent> components = pattern.getComponents();
                for (PatternComponent pComponet : components) {
                    RegularExpressionImpl regularExpress = (RegularExpressionImpl) pComponet;
                    if (JAVA_LANGUAGE.equals(regularExpress.getExpression().getLanguage())) {
                        regularExpress.getExpression().setBody(JAVA_REGULAR_EXPRESSION);
                        patternItem.setPattern(pattern);
                        // MOD yyi 2012-02-08 TDQ-4621:Explicitly set true for updating dependencies.
                        ElementWriterFactory.getInstance().createPatternWriter().save(patternItem, true);
                        isFound = true;
                        break;
                    }
                }
            }
            if (isFound) {
                break;
            }
        }
    }
    return true;
}
Also used : Item(org.talend.core.model.properties.Item) TDQPatternItem(org.talend.dataquality.properties.TDQPatternItem) Pattern(org.talend.dataquality.domain.pattern.Pattern) IPath(org.eclipse.core.runtime.IPath) RegularExpressionImpl(org.talend.dataquality.domain.pattern.impl.RegularExpressionImpl) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PatternComponent(org.talend.dataquality.domain.pattern.PatternComponent) TDQPatternItem(org.talend.dataquality.properties.TDQPatternItem)

Example 23 with PatternComponent

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

the class UpdateSomePatternToMatchMysql method doExecute.

@Override
protected boolean doExecute() throws Exception {
    if (updateFile == null) {
        updateFile = getWorkspacePath().append(UPDATE_FILE_NAME).toFile();
    }
    if (!updateFile.exists()) {
        // if International_phone_number.pattern don't exsit.
        return true;
    }
    URI uri = URI.createFileURI(updateFile.getAbsolutePath());
    Resource patternResource = EMFSharedResources.getInstance().reloadResource(uri);
    if (patternResource != null) {
        Pattern thePattern = retirePattern(patternResource);
        for (PatternComponent currentExpression : thePattern.getComponents()) {
            if (currentExpression instanceof RegularExpression) {
                if (PatternLanguageType.MYSQL.getLiteral().equals(((RegularExpression) currentExpression).getExpression().getLanguage())) {
                    // if the case of Mysql has been added.
                    return true;
                }
            }
        }
        String language = PatternLanguageType.MYSQL.getLiteral();
        RegularExpression newRegularExpress = BooleanExpressionHelper.createRegularExpression(language, EXPRESSIONBODY);
        String expressionType = DomainHelper.getExpressionType(thePattern);
        newRegularExpress.setExpressionType(expressionType);
        List<PatternComponent> componentsList = new ArrayList<PatternComponent>();
        componentsList.add(newRegularExpress);
        componentsList.addAll(thePattern.getComponents());
        thePattern.getComponents().clear();
        thePattern.getComponents().addAll(componentsList);
        ReturnCode rc = PatternResourceFileHelper.getInstance().save(thePattern);
        uri = URI.createFileURI(updateFile.getAbsolutePath());
        EMFSharedResources.getInstance().reloadResource(uri);
        return rc.isOk();
    } else {
        // $NON-NLS-1$
        log.error(DefaultMessagesImpl.getString("UpdateSomePatternToMatchMysql_logErr", patternResource));
        return false;
    }
}
Also used : Pattern(org.talend.dataquality.domain.pattern.Pattern) RegularExpression(org.talend.dataquality.domain.pattern.RegularExpression) ReturnCode(org.talend.utils.sugars.ReturnCode) Resource(org.eclipse.emf.ecore.resource.Resource) ArrayList(java.util.ArrayList) PatternComponent(org.talend.dataquality.domain.pattern.PatternComponent) URI(org.eclipse.emf.common.util.URI)

Example 24 with PatternComponent

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

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