Search in sources :

Example 36 with RegularExpression

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

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

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

the class BooleanExpressionHelper method createRegularExpression.

/**
 * Method "createRegularExpression".
 *
 * @param language
 * @param expression
 * @return a regular expression (no type is set. The caller should set the correct type)
 */
public static RegularExpression createRegularExpression(String language, String expression) {
    RegularExpression regexp = PatternFactory.eINSTANCE.createRegularExpression();
    regexp.setExpression(createTdExpression(language, expression));
    return regexp;
}
Also used : RegularExpression(org.talend.dataquality.domain.pattern.RegularExpression)

Example 39 with RegularExpression

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

RegularExpression (org.talend.dataquality.domain.pattern.RegularExpression)39 Pattern (org.talend.dataquality.domain.pattern.Pattern)26 TdExpression (org.talend.cwm.relational.TdExpression)18 PatternComponent (org.talend.dataquality.domain.pattern.PatternComponent)17 Test (org.junit.Test)12 Domain (org.talend.dataquality.domain.Domain)12 Expression (orgomg.cwm.objectmodel.core.Expression)10 IndicatorParameters (org.talend.dataquality.indicators.IndicatorParameters)9 TdColumn (org.talend.cwm.relational.TdColumn)7 ArrayList (java.util.ArrayList)6 Analysis (org.talend.dataquality.analysis.Analysis)6 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)5 TdTable (org.talend.cwm.relational.TdTable)5 AnalysisContext (org.talend.dataquality.analysis.AnalysisContext)5 PatternMatchingIndicator (org.talend.dataquality.indicators.PatternMatchingIndicator)5 ChartDataEntity (org.talend.dq.indicators.preview.table.ChartDataEntity)5 Catalog (orgomg.cwm.resource.relational.Catalog)5 UDIndicatorDefinition (org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition)4 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)3 PatternBuilder (org.talend.dq.pattern.PatternBuilder)3