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