use of org.talend.dataquality.domain.pattern.RegularExpression in project tdq-studio-se by Talend.
the class RespositoryDetailView method selectionChanged.
/*
* (non-Javadoc)
*
* @seeorg.eclipse.ui.ISelectionListener#selectionChanged(org.eclipse.ui. IWorkbenchPart,
* org.eclipse.jface.viewers.ISelection)
*/
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
clearContainer();
boolean isNeedcreateDefault = true;
try {
if (part instanceof DQRespositoryView) {
StructuredSelection sel = (StructuredSelection) selection;
// MOD by zshen for bug 15750 TODO 39(13) make Detail View can be used.
Object fe = sel.getFirstElement();
// MOD klliu 2011-02-24 if choose diffirent node ,that will load diffirent child ,so that not use up.
if (fe instanceof AnalysisRepNode || fe instanceof ReportRepNode || fe instanceof SysIndicatorDefinitionRepNode || fe instanceof PatternRepNode || fe instanceof RuleRepNode) {
fe = ((IRepositoryNode) fe).getObject();
}
if (fe instanceof IFile) {
IFile fe2 = (IFile) fe;
isNeedcreateDefault = createFileDetail(isNeedcreateDefault, fe2);
} else if (fe instanceof IRepositoryViewObject) {
isNeedcreateDefault = createFileDetail(isNeedcreateDefault, (IRepositoryViewObject) fe);
} else if (fe instanceof DBConnectionRepNode) {
DBConnectionRepNode connNode = (DBConnectionRepNode) fe;
// MOD sizhaoliu TDQ-6316
ConnectionItem connectionItem = (ConnectionItem) connNode.getObject().getProperty().getItem();
createDataProviderDetail(connectionItem);
isNeedcreateDefault = false;
} else if (fe instanceof DBCatalogRepNode) {
DBCatalogRepNode catalogNode = (DBCatalogRepNode) fe;
Catalog catalog = catalogNode.getCatalog();
createTdCatalogDetail(catalog);
isNeedcreateDefault = false;
} else if (fe instanceof DBSchemaRepNode) {
DBSchemaRepNode schemaNode = (DBSchemaRepNode) fe;
Schema schema = schemaNode.getSchema();
createTdSchemaDetail(schema);
isNeedcreateDefault = false;
} else if (fe instanceof DBTableRepNode) {
DBTableRepNode tableNode = (DBTableRepNode) fe;
// MOD gdbu 2011-9-14 TDQ-3243
if (!DQRepositoryNode.isOnFilterring()) {
tableNode.getChildren().get(0).getChildren();
}
// ~TDQ-3243
TdTable tdTable = tableNode.getTdTable();
createTableDetail(tdTable);
isNeedcreateDefault = false;
} else if (fe instanceof DBViewRepNode) {
DBViewRepNode viewNode = (DBViewRepNode) fe;
// MOD gdbu 2011-9-14 TDQ-3243
if (!DQRepositoryNode.isOnFilterring()) {
viewNode.getChildren().get(0).getChildren();
}
// ~TDQ-3243
createNameCommentDetail(viewNode.getTdView());
isNeedcreateDefault = false;
} else if (fe instanceof DBColumnRepNode) {
DBColumnRepNode columnNode = (DBColumnRepNode) fe;
TdColumn column = columnNode.getTdColumn();
createTdColumn(column);
isNeedcreateDefault = false;
} else if (fe instanceof IEcosComponent) {
IEcosComponent component = (IEcosComponent) fe;
createEcosComponent(component);
isNeedcreateDefault = false;
} else if (fe instanceof RegularExpression) {
// MOD mzhao 2009-04-20,Bug 6349.
RegularExpression regularExpression = (RegularExpression) fe;
createRegularExpression(regularExpression);
isNeedcreateDefault = false;
} else if (fe instanceof PatternLanguageRepNode) {
// MOD mzhao 2012-08-15,feature TDQ-4037.
PatternLanguageRepNode pattLangNode = (PatternLanguageRepNode) fe;
createRegularExpression(pattLangNode.getRegularExpression());
isNeedcreateDefault = false;
} else if (fe instanceof SourceFileRepNode) {
// MOD klliu 2001-02-28 bug 19154
IPath filePath = WorkbenchUtils.getFilePath((SourceFileRepNode) fe);
DQRepositoryNode node = (DQRepositoryNode) fe;
IFile file = ResourceManager.getRoot().getProject(node.getProject().getTechnicalLabel()).getFile(filePath);
createSqlFileDetail(file);
} else if (fe instanceof ExchangeComponentRepNode) {
// MOD klliu 2001-02-28 bug 19154
IEcosComponent ecosComponent = ((ExchangeComponentRepNode) fe).getEcosComponent();
IEcosComponent component = ecosComponent;
createEcosComponent(component);
isNeedcreateDefault = false;
// ADD by msjian 2011-5-12 21186: don't check whether the selected object is "MDMConnectionRepNode"
} else if (fe instanceof DFConnectionRepNode) {
DFConnectionRepNode dfNode = (DFConnectionRepNode) fe;
DelimitedFileConnection dfConnection = dfNode.getDfConnection();
createDFconnectionName(dfNode.getObject().getLabel());
createDataProviderDetail(dfConnection);
isNeedcreateDefault = false;
}
if (PluginChecker.isTDQLoaded()) {
if (fe instanceof EObject) {
createTechnicalDetail((EObject) fe);
} else if (fe instanceof IFile) {
createTechnicalDetail((IFile) fe);
} else if (fe instanceof IRepositoryViewObject) {
createTechnicalDetail((IRepositoryViewObject) fe);
} else {
createExtDefault();
}
}
if (!scomp.isDisposed()) {
scomp.setMinSize(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
composite.layout();
}
} else if (part instanceof CommonFormEditor) {
CommonFormEditor editor = (CommonFormEditor) part;
IEditorInput editorInput = editor.getEditorInput();
if (editorInput instanceof IFileEditorInput) {
IFileEditorInput input = (IFileEditorInput) editorInput;
IFile file = input.getFile();
isNeedcreateDefault = createFileDetail(isNeedcreateDefault, file);
}
}
if (isNeedcreateDefault) {
createDefault();
}
// feature 19053
if (!gContainer.isDisposed()) {
gContainer.layout();
if (tContainer != null) {
tContainer.layout();
}
}
} catch (MissingDriverException e) {
if (PluginChecker.isOnlyTopLoaded()) {
MessageDialog.openWarning(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), // $NON-NLS-1$
DefaultMessagesImpl.getString("RespositoryDetailView.warning"), e.getErrorMessage());
} else {
log.error(e, e);
}
}
}
use of org.talend.dataquality.domain.pattern.RegularExpression 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.RegularExpression in project tdq-studio-se by Talend.
the class AnalysisHandleTest method setUp.
/**
* DOC yyin Comment method "setUp".
*
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
// init the analysis
// $NON-NLS-1$
oldAnalysis = AnalysisHelper.createAnalysis("Analysis Data Filter");
AnalysisParameters parameters = AnalysisFactory.eINSTANCE.createAnalysisParameters();
oldAnalysis.setParameters(parameters);
// add two filters which type is ranges
// $NON-NLS-1$
AnalysisHelper.setStringDataFilter(oldAnalysis, "filter1", 0);
// $NON-NLS-1$
AnalysisHelper.setStringDataFilter(oldAnalysis, "filter2", 1);
// add one filter which type is pattern and contains two patterns
EList<Domain> dataFilters = oldAnalysis.getParameters().getDataFilter();
RegularExpression tablePattern = BooleanExpressionHelper.createRegularExpression(null, TABLE_PATTERN_FILTER);
// $NON-NLS-1$
addPatternToDomain(dataFilters.get(0), tablePattern, "Table Pattern");
RegularExpression viewPattern = BooleanExpressionHelper.createRegularExpression(null, VIEW_PATTERN_FILTER);
// $NON-NLS-1$
addPatternToDomain(dataFilters.get(0), viewPattern, "View Pattern");
// create a handle
IRepositoryNode node = mock(IRepositoryNode.class);
IRepositoryViewObject object = mock(IRepositoryViewObject.class);
when(node.getObject()).thenReturn(object);
Property pro = mock(Property.class);
when(object.getProperty()).thenReturn(pro);
IPath itemPath = mock(IPath.class);
PowerMockito.mockStatic(WorkbenchUtils.class);
when(WorkbenchUtils.getFilePath(node)).thenReturn(itemPath);
PowerMockito.mockStatic(ResourceManager.class);
IWorkspaceRoot root = mock(IWorkspaceRoot.class);
when(ResourceManager.getRoot()).thenReturn(root);
when(root.getFile(itemPath)).thenReturn(null);
PowerMockito.mockStatic(RepositoryNodeHelper.class);
when(RepositoryNodeHelper.getModelElementFromRepositoryNode(node)).thenReturn(oldAnalysis);
handle = new AnalysisDuplicateHandle();
}
use of org.talend.dataquality.domain.pattern.RegularExpression in project tdq-studio-se by Talend.
the class PatternMasterDetailsPage method creatNewExpressLine.
private void creatNewExpressLine(RegularExpression regularExpress) {
final Composite expressComp = new Composite(componentsComp, SWT.NONE);
expressComp.setLayout(new GridLayout(10, false));
final CCombo combo = new CCombo(expressComp, SWT.BORDER);
combo.setEditable(false);
combo.setItems(remainDBTypeList.toArray(new String[remainDBTypeList.size()]));
final RegularExpression finalRegExpress = regularExpress;
String language = regularExpress.getExpression().getLanguage();
String body = regularExpress.getExpression().getBody();
if (language == null) {
combo.setText(remainDBTypeList.get(0));
} else {
combo.setText(PatternLanguageType.findNameByLanguage(language));
}
GridDataFactory.fillDefaults().span(2, 1).grab(false, false).applyTo(combo);
combo.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
String lang = combo.getText();
finalRegExpress.getExpression().setLanguage(PatternLanguageType.findLanguageByName(lang));
// added yyin 20120815 TDQ-5982
finalRegExpress.getExpression().setModificationDate(getCurrentDateTime());
setDirty(true);
}
});
final Text patternText = new Text(expressComp, SWT.BORDER);
patternText.setText(body == null ? PluginConstant.EMPTY_STRING : body);
GridDataFactory.fillDefaults().span(6, 1).grab(true, true).applyTo(patternText);
// TDQ-10804, if the content is too long, the below "add" button will be disapper.set widthHint to '0' so that
// the Text width isn't adaptive width.
((GridData) patternText.getLayoutData()).widthHint = 0;
patternText.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
finalRegExpress.getExpression().setBody(patternText.getText());
// added yyin 20120815 TDQ-5982
finalRegExpress.getExpression().setModificationDate(getCurrentDateTime());
setDirty(true);
}
});
Button delButton = new Button(expressComp, SWT.NONE);
delButton.setImage(ImageLib.getImage(ImageLib.DELETE_ACTION));
// $NON-NLS-1$
delButton.setToolTipText(DefaultMessagesImpl.getString("PatternMasterDetailsPage.delete"));
GridDataFactory.fillDefaults().span(1, 1).grab(false, false).applyTo(delButton);
delButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
tempPatternComponents.remove(finalRegExpress);
expressComp.dispose();
patternDefinitionSection.setExpanded(true);
setDirty(true);
}
});
// MOD scorreia 2008-12-15 do not display button when pattern is "SQL Like"
if (!ExpressionType.SQL_LIKE.getLiteral().equals(expressionType)) {
Button testPatternButton = new Button(expressComp, SWT.NONE);
// testPatternButton.setImage(ImageLib.getImage(ImageLib.));
// $NON-NLS-1$
testPatternButton.setText(DefaultMessagesImpl.getString("PatternMasterDetailsPage.test"));
// $NON-NLS-1$
testPatternButton.setToolTipText(DefaultMessagesImpl.getString("PatternMasterDetailsPage.patternTest"));
GridDataFactory.fillDefaults().span(1, 1).grab(false, false).applyTo(testPatternButton);
testPatternButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
// Open test pattern viewer
PatternTestView patternTestView = CorePlugin.getDefault().getPatternTestView();
patternTestView.setPatternExpression(PatternMasterDetailsPage.this, getCurrentModelElement(), finalRegExpress);
}
});
}
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, false).applyTo(expressComp);
}
use of org.talend.dataquality.domain.pattern.RegularExpression 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