Search in sources :

Example 21 with Pattern

use of org.talend.dataquality.domain.pattern.Pattern in project tdq-studio-se by Talend.

the class RegexpMatchingIndicatorImplTest method testGetRegexFail1NotJavaRegex.

/**
 * Test method for {@link org.talend.dataquality.indicators.impl.RegexpMatchingIndicatorImpl#getJavaRegex()}.
 */
@Test
public void testGetRegexFail1NotJavaRegex() {
    // RegexpMatchingIndicator
    RegexpMatchingIndicator createRegexpMatchingIndicator = IndicatorsFactory.eINSTANCE.createRegexpMatchingIndicator();
    // ~RegexpMatchingIndicator
    // IndicatorParameters
    IndicatorParameters createIndicatorParameters = IndicatorsFactory.eINSTANCE.createIndicatorParameters();
    // ~IndicatorParameters
    // Domain
    Domain createDomain = DomainFactory.eINSTANCE.createDomain();
    EList<Pattern> patterns = createDomain.getPatterns();
    // ~Domain
    // Pattern
    Pattern createJavaPattern = PatternFactory.eINSTANCE.createPattern();
    Pattern createSQLPattern = PatternFactory.eINSTANCE.createPattern();
    Pattern createMSSQLPattern = PatternFactory.eINSTANCE.createPattern();
    patterns.add(createJavaPattern);
    patterns.add(createSQLPattern);
    patterns.add(createMSSQLPattern);
    // ~Pattern
    // init java Pattern data
    RegularExpression createJavaRegularExpression = PatternFactory.eINSTANCE.createRegularExpression();
    TdExpression createJavaTdExpression = RelationalFactory.eINSTANCE.createTdExpression();
    createJavaTdExpression.setBody(JavaRegex);
    createJavaTdExpression.setLanguage("Microsoft SQL Server");
    createJavaRegularExpression.setExpression(createJavaTdExpression);
    createJavaRegularExpression.setExpressionType(ExpressionType.REGEXP.getLiteral());
    EList<PatternComponent> components = createJavaPattern.getComponents();
    components.add(createJavaRegularExpression);
    // ~init java Pattern data
    createIndicatorParameters.setDataValidDomain(createDomain);
    createRegexpMatchingIndicator.setParameters(createIndicatorParameters);
    TdColumn column = RelationalFactory.eINSTANCE.createTdColumn();
    MetadataTable mdColumn = RelationalFactory.eINSTANCE.createTdTable();
    column.setTable(mdColumn);
    createRegexpMatchingIndicator.setAnalyzedElement(column);
    // call getRegex()
    String regexResult = createRegexpMatchingIndicator.getRegex();
    // ~call getRegex()
    Assert.assertTrue(regexResult == null);
}
Also used : Pattern(org.talend.dataquality.domain.pattern.Pattern) RegularExpression(org.talend.dataquality.domain.pattern.RegularExpression) TdColumn(org.talend.cwm.relational.TdColumn) TdExpression(org.talend.cwm.relational.TdExpression) IndicatorParameters(org.talend.dataquality.indicators.IndicatorParameters) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) PatternComponent(org.talend.dataquality.domain.pattern.PatternComponent) RegexpMatchingIndicator(org.talend.dataquality.indicators.RegexpMatchingIndicator) Domain(org.talend.dataquality.domain.Domain) Test(org.junit.Test)

Example 22 with Pattern

use of org.talend.dataquality.domain.pattern.Pattern in project tdq-studio-se by Talend.

the class RegexpMatchingIndicatorImplTest method testGetRegexWithDefaultSQLWhenNoJava.

/**
 * Test method for {@link org.talend.dataquality.indicators.impl.RegexpMatchingIndicatorImpl#getJavaRegex()}.
 */
@Test
public void testGetRegexWithDefaultSQLWhenNoJava() {
    // RegexpMatchingIndicator
    RegexpMatchingIndicator createRegexpMatchingIndicator = IndicatorsFactory.eINSTANCE.createRegexpMatchingIndicator();
    // ~RegexpMatchingIndicator
    // IndicatorParameters
    IndicatorParameters createIndicatorParameters = IndicatorsFactory.eINSTANCE.createIndicatorParameters();
    // ~IndicatorParameters
    // Domain
    Domain createDomain = DomainFactory.eINSTANCE.createDomain();
    EList<Pattern> patterns = createDomain.getPatterns();
    // ~Domain
    // Pattern
    Pattern createSQLPattern = PatternFactory.eINSTANCE.createPattern();
    Pattern createMSSQLPattern = PatternFactory.eINSTANCE.createPattern();
    patterns.add(createSQLPattern);
    patterns.add(createMSSQLPattern);
    // ~Pattern
    // init default:SQL Pattern data
    RegularExpression createDefaultExpression = PatternFactory.eINSTANCE.createRegularExpression();
    TdExpression createDefaultTdExpression = RelationalFactory.eINSTANCE.createTdExpression();
    createDefaultTdExpression.setBody("'sql body'");
    createDefaultTdExpression.setLanguage("SQL");
    createDefaultExpression.setExpression(createDefaultTdExpression);
    createDefaultExpression.setExpressionType(ExpressionType.REGEXP.getLiteral());
    EList<PatternComponent> components = createSQLPattern.getComponents();
    components.add(createDefaultExpression);
    // ~init default Pattern data
    createIndicatorParameters.setDataValidDomain(createDomain);
    createRegexpMatchingIndicator.setParameters(createIndicatorParameters);
    // call getRegex()
    String regexResult = createRegexpMatchingIndicator.getRegex();
    // ~call getRegex()
    Assert.assertTrue("sql body".equalsIgnoreCase(regexResult));
}
Also used : Pattern(org.talend.dataquality.domain.pattern.Pattern) RegularExpression(org.talend.dataquality.domain.pattern.RegularExpression) TdExpression(org.talend.cwm.relational.TdExpression) IndicatorParameters(org.talend.dataquality.indicators.IndicatorParameters) PatternComponent(org.talend.dataquality.domain.pattern.PatternComponent) RegexpMatchingIndicator(org.talend.dataquality.indicators.RegexpMatchingIndicator) Domain(org.talend.dataquality.domain.Domain) Test(org.junit.Test)

Example 23 with Pattern

use of org.talend.dataquality.domain.pattern.Pattern in project tdq-studio-se by Talend.

the class AnalysisColumnNominalIntervalTreeViewer method createTreeMenu.

/**
 * DOC xzhao Comment method "createTreeMenu".
 *
 * @param newTree
 * @param containEdit
 */
private void createTreeMenu(final Tree newTree, boolean containEdit) {
    Menu oldMenu = newTree.getMenu();
    if (oldMenu != null && !oldMenu.isDisposed()) {
        oldMenu.dispose();
    }
    menu = new Menu(newTree);
    MenuItem deleteMenuItem = new MenuItem(menu, SWT.CASCADE);
    // $NON-NLS-1$
    deleteMenuItem.setText(DefaultMessagesImpl.getString("AnalysisColumnTreeViewer.removeElement"));
    deleteMenuItem.setImage(ImageLib.getImage(ImageLib.DELETE_ACTION));
    deleteMenuItem.addSelectionListener(new SelectionAdapter() {

        /*
             * (non-Javadoc)
             * 
             * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse .swt.events.SelectionEvent)
             */
        @Override
        public void widgetSelected(SelectionEvent e) {
            removeSelectedElements(newTree);
        // MOD mzhao 2005-05-05 bug 6587.
        // MOD mzhao 2009-06-8, bug 5887.
        // updateBindConnection(masterPage, tree);
        }
    });
    // ADD 2009-01-07 mzhao for feature:0005664
    MenuItem showMenuItem = new MenuItem(menu, SWT.CASCADE);
    // $NON-NLS-1$
    showMenuItem.setText(DefaultMessagesImpl.getString("AnalysisColumnTreeViewer.showDQElement"));
    showMenuItem.setImage(ImageLib.getImage(ImageLib.EXPLORE_IMAGE));
    showMenuItem.addSelectionListener(new SelectionAdapter() {

        /*
             * (non-Javadoc)
             * 
             * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse .swt.events.SelectionEvent)
             */
        @Override
        public void widgetSelected(SelectionEvent e) {
            TreeItem[] selection = newTree.getSelection();
            if (selection.length > 0) {
                // if DqRepository view is not openning we will not do anything
                DQRespositoryView dqview = CorePlugin.getDefault().findAndOpenRepositoryView();
                if (dqview == null) {
                    return;
                }
                // TdColumn tdColumn = (TdColumn) selection[0].getData(COLUMN_INDICATOR_KEY);
                dqview.showSelectedElements(selection[0].getData(COLUMN_INDICATOR_KEY));
            }
        }
    });
    if (containEdit) {
        editPatternMenuItem = new MenuItem(menu, SWT.CASCADE);
        // $NON-NLS-1$
        editPatternMenuItem.setText(DefaultMessagesImpl.getString("AnalysisColumnTreeViewer.editPattern"));
        editPatternMenuItem.setImage(ImageLib.getImage(ImageLib.PATTERN_REG));
        editPatternMenuItem.addSelectionListener(new SelectionAdapter() {

            /*
                 * (non-Javadoc)
                 * 
                 * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org .eclipse.swt.events.SelectionEvent)
                 */
            @Override
            public void widgetSelected(SelectionEvent e) {
                TreeItem[] selection = tree.getSelection();
                if (selection.length > 0) {
                    TreeItem treeItem = selection[0];
                    IndicatorUnit indicatorUnit = (IndicatorUnit) treeItem.getData(INDICATOR_UNIT_KEY);
                    PatternMatchingIndicator indicator = (PatternMatchingIndicator) indicatorUnit.getIndicator();
                    Pattern pattern = indicator.getParameters().getDataValidDomain().getPatterns().get(0);
                    // MOD mzhao 2009-03-13 Feature 6066 Move all folders
                    // into one project.
                    IFile file = ResourceFileMap.findCorrespondingFile(pattern);
                    IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
                    try {
                        activePage.openEditor(new FileEditorInput(file), // $NON-NLS-1$
                        "org.talend.dataprofiler.core.ui.editor.pattern.PatternEditor");
                    } catch (PartInitException e1) {
                        log.error(e1, e1);
                    }
                }
            }
        });
    }
    newTree.setMenu(menu);
}
Also used : Pattern(org.talend.dataquality.domain.pattern.Pattern) IFile(org.eclipse.core.resources.IFile) TreeItem(org.eclipse.swt.widgets.TreeItem) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) IndicatorUnit(org.talend.dataprofiler.core.ui.editor.preview.IndicatorUnit) MenuItem(org.eclipse.swt.widgets.MenuItem) PatternMatchingIndicator(org.talend.dataquality.indicators.PatternMatchingIndicator) FileEditorInput(org.eclipse.ui.part.FileEditorInput) SelectionEvent(org.eclipse.swt.events.SelectionEvent) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) Menu(org.eclipse.swt.widgets.Menu) PartInitException(org.eclipse.ui.PartInitException) DQRespositoryView(org.talend.dataprofiler.core.ui.views.DQRespositoryView)

Example 24 with Pattern

use of org.talend.dataquality.domain.pattern.Pattern in project tdq-studio-se by Talend.

the class ModelElementTreeMenuProvider method editPattern.

private void editPattern(Tree tree) {
    TreeItem[] selection = tree.getSelection();
    if (selection.length > 0) {
        TreeItem treeItem = selection[0];
        IndicatorUnit indicatorUnit = (IndicatorUnit) treeItem.getData(AbstractColumnDropTree.INDICATOR_UNIT_KEY);
        PatternMatchingIndicator indicator = (PatternMatchingIndicator) indicatorUnit.getIndicator();
        Pattern pattern = indicator.getParameters().getDataValidDomain().getPatterns().get(0);
        RepositoryNode patternRecursiveFind = RepositoryNodeHelper.recursiveFind(pattern);
        PatternItemEditorInput patternItemEditorInput = new PatternItemEditorInput(patternRecursiveFind);
        CorePlugin.getDefault().openEditor(patternItemEditorInput, PatternEditor.class.getName());
    }
}
Also used : Pattern(org.talend.dataquality.domain.pattern.Pattern) PatternMatchingIndicator(org.talend.dataquality.indicators.PatternMatchingIndicator) PatternEditor(org.talend.dataprofiler.core.ui.editor.pattern.PatternEditor) TreeItem(org.eclipse.swt.widgets.TreeItem) IndicatorUnit(org.talend.dataprofiler.core.ui.editor.preview.IndicatorUnit) ColumnIndicatorUnit(org.talend.dataprofiler.core.ui.editor.preview.ColumnIndicatorUnit) PatternItemEditorInput(org.talend.dataprofiler.core.ui.editor.pattern.PatternItemEditorInput) RepositoryNode(org.talend.repository.model.RepositoryNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode)

Example 25 with Pattern

use of org.talend.dataquality.domain.pattern.Pattern in project tdq-studio-se by Talend.

the class PatternMasterDetailsPage method getPatternRepNodeFromInput.

/**
 * get PatternRepNode From editorInput
 *
 * @param editorInput
 * @return
 */
private PatternRepNode getPatternRepNodeFromInput(IEditorInput editorInput) {
    if (editorInput instanceof FileEditorInput) {
        FileEditorInput fileEditorInput = (FileEditorInput) editorInput;
        IFile file = fileEditorInput.getFile();
        if (file != null) {
            Pattern pattern = PatternResourceFileHelper.getInstance().findPattern(file);
            pattern = (Pattern) EObjectHelper.resolveObject(pattern);
            return RepositoryNodeHelper.recursiveFindPattern(pattern);
        }
    } else if (editorInput instanceof PatternItemEditorInput) {
        return ((PatternItemEditorInput) editorInput).getRepNode();
    }
    return null;
}
Also used : Pattern(org.talend.dataquality.domain.pattern.Pattern) IFile(org.eclipse.core.resources.IFile) FileEditorInput(org.eclipse.ui.part.FileEditorInput)

Aggregations

Pattern (org.talend.dataquality.domain.pattern.Pattern)75 RegularExpression (org.talend.dataquality.domain.pattern.RegularExpression)27 Test (org.junit.Test)19 TdExpression (org.talend.cwm.relational.TdExpression)18 Domain (org.talend.dataquality.domain.Domain)16 Analysis (org.talend.dataquality.analysis.Analysis)15 PatternComponent (org.talend.dataquality.domain.pattern.PatternComponent)15 IndicatorParameters (org.talend.dataquality.indicators.IndicatorParameters)14 ArrayList (java.util.ArrayList)13 PatternMatchingIndicator (org.talend.dataquality.indicators.PatternMatchingIndicator)13 IFile (org.eclipse.core.resources.IFile)11 TDQPatternItem (org.talend.dataquality.properties.TDQPatternItem)10 Expression (orgomg.cwm.objectmodel.core.Expression)10 IFolder (org.eclipse.core.resources.IFolder)9 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)9 Indicator (org.talend.dataquality.indicators.Indicator)9 Item (org.talend.core.model.properties.Item)7 TdColumn (org.talend.cwm.relational.TdColumn)7 RegexpMatchingIndicator (org.talend.dataquality.indicators.RegexpMatchingIndicator)6 IndicatorDefinition (org.talend.dataquality.indicators.definition.IndicatorDefinition)6