use of org.talend.dataquality.domain.pattern.PatternComponent in project tdq-studio-se by Talend.
the class PatternTestView method savePattern.
/**
* If the pattern is not null, will save it and update the corresponding pattern editor content.
*/
private void savePattern() {
// If the pattern is not null, will update the pattern editor content.
if (pattern != null) {
String expressionLanguage = this.regularExpression.getExpression().getLanguage();
DbmsLanguage dbmsLanguage = this.getDbmsLanguage();
// MOD gdbu 2011-6-13 bug : 21695
if (null != dbmsLanguage) {
dbmsLanguage.setRegularExpressionFunction(getFunctionName());
}
// ~21695
// ~19119
// MOD qiongli 2011-1-7 featrue 16799.
boolean isLanguageMatched = false;
if (isJavaEngine && expressionLanguage.equals(ExecutionLanguage.JAVA.getLiteral()) || dbmsLanguage != null && (dbmsLanguage.getDbmsName().equalsIgnoreCase(expressionLanguage))) {
isLanguageMatched = true;
}
if (!isLanguageMatched) {
String messageInfo = DefaultMessagesImpl.getString("PatternTestView.modifiedTheRegularExpression", expressionLanguage, dbmsLanguage.getDbmsName(), expressionLanguage, expressionLanguage, // $NON-NLS-1$
dbmsLanguage.getDbmsName());
MessageDialog messageDialog = new MessageDialog(new Shell(), // $NON-NLS-1$
DefaultMessagesImpl.getString("PatternTestView.warning"), // $NON-NLS-1$
null, // $NON-NLS-1$
messageInfo, // $NON-NLS-1$
MessageDialog.WARNING, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0);
int result = messageDialog.open();
if (result == MessageDialog.OK) {
regularExpression.getExpression().setBody(regularText.getText());
} else {
EList<PatternComponent> components = this.pattern.getComponents();
boolean isContainLanguage = false;
for (int i = 0; i < components.size(); i++) {
RegularExpressionImpl regularExpress = (RegularExpressionImpl) components.get(i);
// expression
if (dbmsLanguage.getDbmsName().equalsIgnoreCase(regularExpress.getExpression().getLanguage())) {
regularExpress.getExpression().setBody(regularText.getText());
isContainLanguage = true;
break;
}
}
// expression.
if (!isContainLanguage) {
RegularExpression newRegularExpress = BooleanExpressionHelper.createRegularExpression(dbmsLanguage.getDbmsName(), regularText.getText());
this.pattern.getComponents().add(newRegularExpress);
}
}
} else {
regularExpression.getExpression().setBody(regularText.getText());
}
EMFUtil.saveSingleResource(pattern.eResource());
editorPage.updatePatternDefinitonSection();
// MessageDialog.openInformation(new Shell(), "Success",
// "Success to save the pattern '" +
// pattern.getName()
// + "'");
saveButton.setEnabled(false);
}
}
use of org.talend.dataquality.domain.pattern.PatternComponent in project tdq-studio-se by Talend.
the class RespositoryDetailView method createPatternDetail.
private void createPatternDetail(Pattern pattern) {
createName(pattern);
createPurpose(pattern);
createDescription(pattern);
EList<PatternComponent> components = pattern.getComponents();
StringBuilder description = new StringBuilder();
for (PatternComponent poc : components) {
if (poc instanceof RegularExpression) {
RegularExpression expression = (RegularExpression) poc;
// $NON-NLS-1$
description.append(" ").append(expression.getExpression().getLanguage());
}
}
// $NON-NLS-1$
newLabelAndText(gContainer, DefaultMessagesImpl.getString("RespositoryDetailView.type"), description.toString().trim());
}
use of org.talend.dataquality.domain.pattern.PatternComponent in project tdq-studio-se by Talend.
the class FileSystemImportWriter method mergePattern.
/**
* when imported pattern is from lower version, even if it is modified, the "modify date" is still null, so, even if
* the modify date is null ,still do the comparation. [for Pattern matadata(Purpose, Description, Author, Status):
* 1) will replace old value with new value if new value is not blank; 2) will keep old value if new value is blank]
*
* @param record
* @param patternItem
*/
protected void mergePattern(ItemRecord record, TDQPatternItem patternItem) {
// only when the Si is modified, do the save
boolean isModified = false;
// old objects
Pattern pattern = patternItem.getPattern();
Property patternProp = patternItem.getProperty();
// new objects
Pattern recordPattern = (Pattern) record.getElement();
Property recordProp = record.getProperty();
// get expression list from record
EList<PatternComponent> importComponents = recordPattern.getComponents();
// for each expression:
for (PatternComponent component : importComponents) {
// if the modify date ==null, maybe it is from lower version, still do the compare
TdExpression importEx = ((RegularExpression) component).getExpression();
PatternComponent replaced = null;
for (PatternComponent pComp : pattern.getComponents()) {
TdExpression pex = ((RegularExpression) pComp).getExpression();
if (importEx.getLanguage().equals(pex.getLanguage())) {
replaced = pComp;
break;
}
}
// if new, add to SI
if (replaced == null) {
pattern.getComponents().add(createPatternComponent(component));
isModified = true;
} else {
// if the expression are different: compare the modify date, make the SI keep the new one
if (replaceExpression(((RegularExpression) replaced).getExpression(), importEx)) {
pattern.getComponents().remove(replaced);
pattern.getComponents().add(createPatternComponent(component));
isModified = true;
}
}
}
// for Pattern Metadata
if (patternProp != null && recordProp != null) {
if (!StringUtils.isBlank(recordProp.getPurpose())) {
patternProp.setPurpose(recordProp.getPurpose());
}
if (!StringUtils.isBlank(recordProp.getDescription())) {
patternProp.setDescription(recordProp.getDescription());
}
patternProp.setAuthor(recordProp.getAuthor());
patternProp.setStatusCode(recordProp.getStatusCode());
isModified = true;
}
if (isModified) {
ElementWriterFactory.getInstance().createPatternWriter().save(patternItem, false);
}
}
use of org.talend.dataquality.domain.pattern.PatternComponent in project tdq-studio-se by Talend.
the class PatternMasterDetailsPage method savePattern.
private boolean savePattern() {
if (tempPatternComponents.isEmpty()) {
MessageDialog.openError(null, DefaultMessagesImpl.getString("PatternMasterDetailsPage.error"), // $NON-NLS-1$ //$NON-NLS-2$
DefaultMessagesImpl.getString("PatternMasterDetailsPage.cannotSave", getCurrentModelElement().getName()));
return false;
}
getCurrentModelElement().getComponents().clear();
getCurrentModelElement().getComponents().addAll(tempPatternComponents);
// PTODO fixed bug 4296: set the Pattern is valid
TaggedValueHelper.setValidStatus(true, getCurrentModelElement());
EList<PatternComponent> components = getCurrentModelElement().getComponents();
List<String> existLanguage = new ArrayList<String>();
for (int i = 0; i < components.size(); i++) {
RegularExpressionImpl regularExpress = (RegularExpressionImpl) components.get(i);
String language = regularExpress.getExpression().getLanguage();
if ((regularExpress.getExpression().getBody() == null) || (!regularExpress.getExpression().getBody().matches("'.*'"))) {
// $NON-NLS-1$
MessageDialog.openWarning(null, DefaultMessagesImpl.getString("PatternMasterDetailsPage.warning"), // $NON-NLS-1$ //$NON-NLS-2$
DefaultMessagesImpl.getString("PatternMasterDetailsPage.patternExpressions", language));
return false;
}
if (existLanguage.contains(language)) {
MessageDialog.openError(null, DefaultMessagesImpl.getString("PatternMasterDetailsPage.error"), // $NON-NLS-1$ //$NON-NLS-2$
DefaultMessagesImpl.getString("PatternMasterDetailsPage.languageType", language));
return false;
} else {
existLanguage.add(language);
}
}
TDQPatternItem patternItem = (TDQPatternItem) this.patternRepNode.getObject().getProperty().getItem();
// Added TDQ-14249 rename udi, 20170920
patternRepNode.getObject().getProperty().setDisplayName(patternItem.getPattern().getName());
// MOD yyi 2012-02-08 TDQ-4621:Explicitly set true for updating dependencies.
ElementWriterFactory.getInstance().createPatternWriter().save(patternItem, true);
// TDQ-13498 : SQL pattern should not pop up modify jobs' dialog.
if (!ExpressionType.SQL_LIKE.getLiteral().equals(expressionType)) {
// TDQ-11688
RepositoryUpdateManager.updateDQPattern(patternItem);
}
return true;
}
use of org.talend.dataquality.domain.pattern.PatternComponent in project tdq-studio-se by Talend.
the class PatternMasterDetailsPage method createPatternDefinitionComp.
/**
* DOC rli Comment method "ceatePatternDefinitionComp".
*
* @param form
* @param section
*/
private Composite createPatternDefinitionComp() {
Composite newComp = toolkit.createComposite(patternDefinitionSection);
newComp.setLayout(new GridLayout());
componentsComp = new Composite(newComp, SWT.NONE);
componentsComp.setLayout(new GridLayout());
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(componentsComp);
EList<PatternComponent> components = getCurrentModelElement().getComponents();
for (int i = 0; i < components.size(); i++) {
RegularExpression regularExpress = (RegularExpression) components.get(i);
// RegularExpressionImpl newRegularExpress = (RegularExpressionImpl)
// PatternFactory.eINSTANCE.createRegularExpression();
// Expression newExpression = CoreFactory.eINSTANCE.createExpression();
// newExpression.setBody(regularExpress.getExpression().getBody());
// newExpression.setLanguage(regularExpress.getExpression().getLanguage());
// newRegularExpress.setExpression(newExpression);
tempPatternComponents.add(regularExpress);
creatNewExpressLine(regularExpress);
}
createAddButton(newComp);
patternDefinitionSection.setClient(newComp);
return newComp;
}
Aggregations