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;
}
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;
}
}
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;
}
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;
}
Aggregations