Search in sources :

Example 31 with RegularExpression

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);
        }
    }
}
Also used : DBConnectionRepNode(org.talend.dq.nodes.DBConnectionRepNode) IFile(org.eclipse.core.resources.IFile) ConnectionItem(org.talend.core.model.properties.ConnectionItem) Schema(orgomg.cwm.resource.relational.Schema) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) PatternLanguageRepNode(org.talend.dq.nodes.PatternLanguageRepNode) DBColumnRepNode(org.talend.dq.nodes.DBColumnRepNode) SourceFileRepNode(org.talend.dq.nodes.SourceFileRepNode) DQRepositoryNode(org.talend.dq.nodes.DQRepositoryNode) DBCatalogRepNode(org.talend.dq.nodes.DBCatalogRepNode) ReportRepNode(org.talend.dq.nodes.ReportRepNode) ExchangeComponentRepNode(org.talend.dataprofiler.core.ui.exchange.ExchangeComponentRepNode) IFileEditorInput(org.eclipse.ui.IFileEditorInput) EObject(org.eclipse.emf.ecore.EObject) SysIndicatorDefinitionRepNode(org.talend.dq.nodes.SysIndicatorDefinitionRepNode) DBViewRepNode(org.talend.dq.nodes.DBViewRepNode) PatternRepNode(org.talend.dq.nodes.PatternRepNode) RegularExpression(org.talend.dataquality.domain.pattern.RegularExpression) DBSchemaRepNode(org.talend.dq.nodes.DBSchemaRepNode) TdTable(org.talend.cwm.relational.TdTable) IPath(org.eclipse.core.runtime.IPath) DelimitedFileConnection(org.talend.core.model.metadata.builder.connection.DelimitedFileConnection) RuleRepNode(org.talend.dq.nodes.RuleRepNode) Catalog(orgomg.cwm.resource.relational.Catalog) CommonFormEditor(org.talend.dataprofiler.core.ui.editor.CommonFormEditor) DBTableRepNode(org.talend.dq.nodes.DBTableRepNode) MissingDriverException(org.talend.utils.exceptions.MissingDriverException) AnalysisRepNode(org.talend.dq.nodes.AnalysisRepNode) TdColumn(org.talend.cwm.relational.TdColumn) DFConnectionRepNode(org.talend.dq.nodes.DFConnectionRepNode) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) IEcosComponent(org.talend.dataprofiler.ecos.model.IEcosComponent) EObject(org.eclipse.emf.ecore.EObject) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) IEditorInput(org.eclipse.ui.IEditorInput)

Example 32 with RegularExpression

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);
    }
}
Also used : Pattern(org.talend.dataquality.domain.pattern.Pattern) RegularExpression(org.talend.dataquality.domain.pattern.RegularExpression) TdExpression(org.talend.cwm.relational.TdExpression) PatternComponent(org.talend.dataquality.domain.pattern.PatternComponent) Property(org.talend.core.model.properties.Property)

Example 33 with RegularExpression

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();
}
Also used : RegularExpression(org.talend.dataquality.domain.pattern.RegularExpression) IRepositoryNode(org.talend.repository.model.IRepositoryNode) IPath(org.eclipse.core.runtime.IPath) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) AnalysisParameters(org.talend.dataquality.analysis.AnalysisParameters) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) Domain(org.talend.dataquality.domain.Domain) Property(org.talend.core.model.properties.Property) Before(org.junit.Before)

Example 34 with RegularExpression

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);
}
Also used : RegularExpression(org.talend.dataquality.domain.pattern.RegularExpression) Composite(org.eclipse.swt.widgets.Composite) ModifyListener(org.eclipse.swt.events.ModifyListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) PatternTestView(org.talend.dataprofiler.core.ui.views.PatternTestView) Text(org.eclipse.swt.widgets.Text) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) CCombo(org.eclipse.swt.custom.CCombo) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent)

Example 35 with RegularExpression

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;
}
Also used : RegularExpression(org.talend.dataquality.domain.pattern.RegularExpression) GridLayout(org.eclipse.swt.layout.GridLayout) Composite(org.eclipse.swt.widgets.Composite) PatternComponent(org.talend.dataquality.domain.pattern.PatternComponent)

Aggregations

RegularExpression (org.talend.dataquality.domain.pattern.RegularExpression)39 Pattern (org.talend.dataquality.domain.pattern.Pattern)26 TdExpression (org.talend.cwm.relational.TdExpression)18 PatternComponent (org.talend.dataquality.domain.pattern.PatternComponent)17 Test (org.junit.Test)12 Domain (org.talend.dataquality.domain.Domain)12 Expression (orgomg.cwm.objectmodel.core.Expression)10 IndicatorParameters (org.talend.dataquality.indicators.IndicatorParameters)9 TdColumn (org.talend.cwm.relational.TdColumn)7 ArrayList (java.util.ArrayList)6 Analysis (org.talend.dataquality.analysis.Analysis)6 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)5 TdTable (org.talend.cwm.relational.TdTable)5 AnalysisContext (org.talend.dataquality.analysis.AnalysisContext)5 PatternMatchingIndicator (org.talend.dataquality.indicators.PatternMatchingIndicator)5 ChartDataEntity (org.talend.dq.indicators.preview.table.ChartDataEntity)5 Catalog (orgomg.cwm.resource.relational.Catalog)5 UDIndicatorDefinition (org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition)4 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)3 PatternBuilder (org.talend.dq.pattern.PatternBuilder)3