use of org.talend.dataquality.domain.pattern.Pattern in project tdq-studio-se by Talend.
the class AElementPersistance method createItem.
/**
* DOC bZhou Comment method "createItem".
*
* @param element
* @return
*/
public Item createItem(ModelElement element) {
Item item = null;
// MOD mzhao feature 13114, 2010-05-19 distinguish tdq items.
if (ModelElementIdentifier.isAnalysis(element)) {
item = PropertiesFactory.eINSTANCE.createTDQAnalysisItem();
((TDQAnalysisItem) item).setAnalysis((Analysis) element);
} else if (ModelElementIdentifier.isDQRule(element)) {
item = PropertiesFactory.eINSTANCE.createTDQBusinessRuleItem();
((TDQBusinessRuleItem) item).setDqrule((DQRule) element);
} else if (ModelElementIdentifier.isDataProvider(element)) {
if (element instanceof DatabaseConnection) {
item = org.talend.core.model.properties.PropertiesFactory.eINSTANCE.createDatabaseConnectionItem();
((ConnectionItem) item).setConnection((DatabaseConnection) element);
}
((ConnectionItem) item).setConnection((Connection) element);
} else if (ModelElementIdentifier.isMatchRule(element)) {
// this Condition must before the IndicatorDefinition one because MatchRule instance of it.
item = PropertiesFactory.eINSTANCE.createTDQMatchRuleItem();
((TDQMatchRuleItem) item).setMatchRule((MatchRuleDefinition) element);
} else if (ModelElementIdentifier.isID(element)) {
item = PropertiesFactory.eINSTANCE.createTDQIndicatorDefinitionItem();
((TDQIndicatorDefinitionItem) item).setIndicatorDefinition((IndicatorDefinition) element);
} else if (ModelElementIdentifier.isPattern(element)) {
item = PropertiesFactory.eINSTANCE.createTDQPatternItem();
((TDQPatternItem) item).setPattern((Pattern) element);
} else if (ModelElementIdentifier.isReport(element)) {
item = PropertiesFactory.eINSTANCE.createTDQReportItem();
((TDQReportItem) item).setReport((Report) element);
} else {
item = org.talend.core.model.properties.PropertiesFactory.eINSTANCE.createTDQItem();
}
ItemState itemState = org.talend.core.model.properties.PropertiesFactory.eINSTANCE.createItemState();
itemState.setDeleted(false);
item.setState(itemState);
if (item instanceof TDQItem) {
setTDQItemFileName(element, item);
}
Resource eResource = element.eResource();
if (eResource != null) {
URI uri = eResource.getURI();
if (uri.isPlatform()) {
IPath elementPath = new Path(uri.toPlatformString(true)).removeLastSegments(1);
IPath typedPath = ResourceManager.getRootProject().getFullPath().append(PropertyHelper.getItemTypedPath(item));
IPath statePath = elementPath.makeRelativeTo(typedPath);
itemState.setPath(statePath.toString());
}
}
return item;
}
use of org.talend.dataquality.domain.pattern.Pattern in project tdq-studio-se by Talend.
the class AddPatternISBN13Task method doExecute.
/*
* (non-Javadoc)
*
* @see org.talend.dataprofiler.migration.AMigrationTask#doExecute()
*/
@Override
protected boolean doExecute() throws Exception {
parameter = new PatternParameter();
ReturnCode rc1 = new ReturnCode(true), rc2 = new ReturnCode(true), rc3 = new ReturnCode(true);
// number folder
// $NON-NLS-1$
IFolder folder = ResourceManager.getPatternRegexFolder().getFolder("number");
if (folder.exists()) {
// only create ISBN 13 Checker when not found.
if (!folder.getFile("ISBN_13_Checker_0.1.pattern").exists()) {
Pattern pattern = newPattern(// $NON-NLS-1$ //$NON-NLS-2$
"ISBN 13 Checker", // $NON-NLS-1$ //$NON-NLS-2$
"Java", // $NON-NLS-1$
"'^ISBN(?:-13)?:?\\ *(97(?:8|9)([ -]?)(?=[0-9]{1,5}\\2?[0-9]{1,7}\\2?[0-9]{1,6}\\2?[0-9])(?:[0-9]\\2*){9}[0-9])$'");
if (pattern != null) {
setTagValue(// $NON-NLS-1$
pattern, // $NON-NLS-1$
"ISBN-13: 978-2711791415 | ISBN 978-2711791415 | ISBN: 978-2711791415", // $NON-NLS-1$
"International Standard Book Number 13 digits");
rc1 = ElementWriterFactory.getInstance().createPatternWriter().create(pattern, folder);
}
}
}
// Update IPv6 Address.pattern.
// $NON-NLS-1$
IFile file = ResourceManager.getPatternRegexFolder().getFolder("internet").getFile("IPv6_Address_0.1.pattern");
if (file.exists()) {
Pattern ipv6Pattern = PatternResourceFileHelper.getInstance().findPattern(file);
if (ipv6Pattern != null) {
List<PatternComponent> componentLs = new ArrayList<PatternComponent>();
// $NON-NLS-1$
componentLs.add(BooleanExpressionHelper.createRegularExpression("Java", REGEX_BODY, ExpressionType.REGEXP));
// $NON-NLS-1$
componentLs.add(BooleanExpressionHelper.createRegularExpression("MySQL", REGEX_BODY, ExpressionType.REGEXP));
// $NON-NLS-1$
componentLs.add(BooleanExpressionHelper.createRegularExpression("PostgreSQL", REGEX_BODY, ExpressionType.REGEXP));
ipv6Pattern.getComponents().clear();
ipv6Pattern.getComponents().addAll(componentLs);
rc2 = PatternResourceFileHelper.getInstance().save(ipv6Pattern);
}
}
// Update EN Month.pattern. for expresstion add ()
// $NON-NLS-1$ //$NON-NLS-2$
IFile file2 = ResourceManager.getPatternRegexFolder().getFolder("date").getFile("EN_Month_0.1.pattern");
if (file2.exists()) {
Pattern enMonthPattern = PatternResourceFileHelper.getInstance().findPattern(file2);
if (enMonthPattern != null) {
List<PatternComponent> componentLs = new ArrayList<PatternComponent>();
// $NON-NLS-1$
String regexBody = "'^(January|June|July|February|March|May|April|August|September|October|November|December)$'";
// $NON-NLS-1$
componentLs.add(BooleanExpressionHelper.createRegularExpression("SQL", regexBody, ExpressionType.REGEXP));
enMonthPattern.getComponents().clear();
enMonthPattern.getComponents().addAll(componentLs);
rc3 = PatternResourceFileHelper.getInstance().save(enMonthPattern);
}
}
return rc1.isOk() && rc2.isOk() && rc3.isOk();
}
use of org.talend.dataquality.domain.pattern.Pattern in project tdq-studio-se by Talend.
the class AddPatternISBN13Task method newPattern.
private Pattern newPattern(String name, String lang, String express) {
PatternBuilder patternBuilder = new PatternBuilder();
boolean patternInitialized = patternBuilder.initializePattern(name);
if (patternInitialized) {
Pattern pattern = patternBuilder.getPattern();
RegularExpression regularExpr = BooleanExpressionHelper.createRegularExpression(lang, express);
// $NON-NLS-1$
regularExpr.setExpressionType("REGEXP");
pattern.getComponents().add(regularExpr);
return pattern;
}
return null;
}
use of org.talend.dataquality.domain.pattern.Pattern in project tdq-studio-se by Talend.
the class ExportFactory method export.
static void export(File exportFile, IFolder folder, Pattern... patterns) {
if (exportFile.isDirectory()) {
for (Pattern pattern : patterns) {
// $NON-NLS-1$
File file = new File(exportFile, toLocalFileName(pattern.getName() + ".csv"));
export(file, folder, pattern);
}
}
String fileExtName = getFileExtName(exportFile);
if (FileUtils.isCSV(fileExtName)) {
try {
CSVWriter out = FileUtils.createCSVWriter(exportFile, FileUtils.TEXT_QUAL, FileUtils.TEXT_QUAL);
PatternToExcelEnum[] values = PatternToExcelEnum.values();
String[] temp = new String[values.length];
Map<PatternToExcelEnum, String> relatedValueMap = null;
for (int i = 0; i < patterns.length + 1; i++) {
if (i != 0) {
relatedValueMap = getRelatedValueFromPattern(patterns[i - 1], folder);
}
for (int j = 0; j < values.length; j++) {
if (i == 0) {
temp[j] = values[j].getLiteral();
} else {
if (relatedValueMap == null) {
// $NON-NLS-1$
throw new NullPointerException(DefaultMessagesImpl.getString("ExportFactory.RelatedValueMapNull"));
}
temp[j] = relatedValueMap.get(values[j]);
}
}
out.writeNext(temp);
}
out.flush();
out.close();
} catch (FileNotFoundException fe) {
MessageDialogWithToggle.openError(null, DefaultMessagesImpl.getString("ExportFactory.errorOne"), // $NON-NLS-1$ //$NON-NLS-2$
DefaultMessagesImpl.getString("ExportFactory.notFoundFile"));
} catch (Exception e) {
log.error(e.getMessage());
}
}
}
use of org.talend.dataquality.domain.pattern.Pattern in project tdq-studio-se by Talend.
the class PatternDefinitionHandler method getPatternById.
public Pattern getPatternById(String definitionId) {
for (Pattern patDef : this.getPatternDefinitions()) {
CwmResource resource = (CwmResource) patDef.eResource();
EObject object = resource.getEObject(definitionId);
if (object != null && PatternPackage.eINSTANCE.getPattern().equals(object.eClass())) {
return (Pattern) object;
}
}
return null;
}
Aggregations