Search in sources :

Example 41 with TdExpression

use of org.talend.cwm.relational.TdExpression 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 42 with TdExpression

use of org.talend.cwm.relational.TdExpression in project tdq-studio-se by Talend.

the class ModelElementEditonDistance method distance.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.emf.compare.match.eobject.EditionDistance#distance(org.eclipse.emf.compare.Comparison,
     * org.eclipse.emf.ecore.EObject, org.eclipse.emf.ecore.EObject)
     */
@Override
public double distance(Comparison inProgress, EObject a, EObject b) {
    boolean isSame = false;
    if (a instanceof DatabaseConnection) {
        return 0;
    }
    if (a instanceof Catalog && b instanceof Catalog) {
        Catalog catalog1 = (Catalog) a;
        Catalog catalog2 = (Catalog) b;
        isSame = StringUtils.equalsIgnoreCase(catalog1.getName(), catalog2.getName());
        return isSame ? 0 : Double.MAX_VALUE;
    } else if (a instanceof Schema && b instanceof Schema) {
        Schema schema1 = (Schema) a;
        Schema schema2 = (Schema) b;
        isSame = StringUtils.equalsIgnoreCase(schema1.getName(), schema2.getName());
        return isSame ? 0 : Double.MAX_VALUE;
    } else if (a instanceof TdTable && b instanceof TdTable) {
        TdTable tdTable1 = (TdTable) a;
        TdTable tdTable2 = (TdTable) b;
        isSame = StringUtils.equalsIgnoreCase(tdTable1.getName(), tdTable2.getName());
        return isSame ? 0 : Double.MAX_VALUE;
    } else if (a instanceof TdView && b instanceof TdView) {
        TdView tdView1 = (TdView) a;
        TdView tdView2 = (TdView) b;
        isSame = StringUtils.equalsIgnoreCase(tdView1.getName(), tdView2.getName());
        return isSame ? 0 : Double.MAX_VALUE;
    } else if (a instanceof TdColumn && b instanceof TdColumn) {
        TdColumn tdColumn1 = (TdColumn) a;
        TdColumn tdColumn2 = (TdColumn) b;
        isSame = StringUtils.equalsIgnoreCase(tdColumn1.getName(), tdColumn2.getName()) && distance(inProgress, tdColumn1.getSqlDataType(), tdColumn2.getSqlDataType()) == 0;
        return isSame ? 0 : Double.MAX_VALUE;
    } else if (a instanceof TaggedValue && b instanceof TaggedValue) {
        TaggedValue taggedValue1 = (TaggedValue) a;
        TaggedValue taggedValue2 = (TaggedValue) b;
        isSame = StringUtils.equalsIgnoreCase(taggedValue1.getTag(), taggedValue2.getTag()) && StringUtils.equalsIgnoreCase(taggedValue1.getValue(), taggedValue2.getValue());
        return isSame ? 0 : Double.MAX_VALUE;
    } else if (a instanceof TdExpression && b instanceof TdExpression) {
        TdExpression tdExpression1 = (TdExpression) a;
        TdExpression tdExpression2 = (TdExpression) b;
        isSame = StringUtils.equalsIgnoreCase(tdExpression1.getLanguage(), tdExpression2.getLanguage()) && StringUtils.equalsIgnoreCase(tdExpression1.getBody(), tdExpression2.getBody());
        return isSame ? 0 : Double.MAX_VALUE;
    } else if (a instanceof TdSqlDataType && b instanceof TdSqlDataType) {
        TdSqlDataType tdExpression1 = (TdSqlDataType) a;
        TdSqlDataType tdExpression2 = (TdSqlDataType) b;
        isSame = StringUtils.equalsIgnoreCase(tdExpression1.getName(), tdExpression2.getName());
        return isSame ? 0 : Double.MAX_VALUE;
    } else if (a instanceof MetadataColumn && b instanceof MetadataColumn) {
        // Added yyin TDQ-8360
        MetadataColumn metaColumn1 = (MetadataColumn) a;
        MetadataColumn metaColumn2 = (MetadataColumn) b;
        isSame = StringUtils.equalsIgnoreCase(metaColumn1.getLabel(), metaColumn2.getLabel());
        return isSame ? 0 : Double.MAX_VALUE;
    } else if (a instanceof MetadataTable && b instanceof MetadataTable) {
        MetadataTable mTable1 = (MetadataTable) a;
        MetadataTable mTable2 = (MetadataTable) b;
        isSame = StringUtils.equalsIgnoreCase(mTable1.getLabel(), mTable2.getLabel());
        return isSame ? 0 : Double.MAX_VALUE;
    }
    return super.distance(inProgress, a, b);
}
Also used : MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) TdTable(org.talend.cwm.relational.TdTable) TdColumn(org.talend.cwm.relational.TdColumn) TdView(org.talend.cwm.relational.TdView) TdExpression(org.talend.cwm.relational.TdExpression) TaggedValue(orgomg.cwm.objectmodel.core.TaggedValue) Schema(orgomg.cwm.resource.relational.Schema) MetadataTable(org.talend.core.model.metadata.MetadataTable) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) TdSqlDataType(org.talend.cwm.relational.TdSqlDataType) Catalog(orgomg.cwm.resource.relational.Catalog)

Example 43 with TdExpression

use of org.talend.cwm.relational.TdExpression in project tdq-studio-se by Talend.

the class ParserRuleMasterDetailsPage method createButtons.

/**
 * DOC klliu Comment method "createButtons".
 *
 * @param parent
 */
private void createButtons(Composite parent, final ParserRuleTableViewer parserRuleTableViewer) {
    boolean isNeedTestButton = false;
    if (GlobalServiceRegister.getDefault().isServiceRegistered(IAntlrEditorUIService.class)) {
        isNeedTestButton = true;
    }
    Composite buttonsComposite = new Composite(parent, SWT.NONE);
    buttonsComposite.setLayout(new GridLayout(7, true));
    GridData labelGd = new GridData();
    labelGd.horizontalAlignment = SWT.LEFT;
    labelGd.widthHint = 30;
    final Button addButton = new Button(buttonsComposite, SWT.NONE);
    // $NON-NLS-1$
    addButton.setToolTipText("Add New Item");
    addButton.setImage(ImageLib.getImage(ImageLib.ADD_ACTION));
    addButton.setLayoutData(labelGd);
    addButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            parserRuleTableViewer.addTdExpression();
        }
    });
    final Button delButton = new Button(buttonsComposite, SWT.NONE);
    // $NON-NLS-1$
    delButton.setToolTipText("Delete Selcetion Item");
    delButton.setImage(ImageLib.getImage(ImageLib.DELETE_ACTION));
    delButton.setLayoutData(labelGd);
    delButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            TdExpression tdExpression = (TdExpression) ((IStructuredSelection) parserRuleTableViewer.getSelection()).getFirstElement();
            if (tdExpression != null) {
                parserRuleTableViewer.removeTdExpression(tdExpression);
            }
        }
    });
    final Button upButton = new Button(buttonsComposite, SWT.NONE);
    // $NON-NLS-1$
    upButton.setToolTipText("Move Item Up");
    upButton.setImage(ImageLib.getImage(ImageLib.UP_ACTION));
    upButton.setLayoutData(labelGd);
    upButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            TdExpression tdExpression = (TdExpression) ((IStructuredSelection) parserRuleTableViewer.getSelection()).getFirstElement();
            if (tdExpression != null) {
                parserRuleTableViewer.moveTdExpression(tdExpression, 1);
            }
        }
    });
    final Button downButton = new Button(buttonsComposite, SWT.NONE);
    // $NON-NLS-1$
    downButton.setToolTipText("Move Item Down");
    downButton.setImage(ImageLib.getImage(ImageLib.DOWN_ACTION));
    downButton.setLayoutData(labelGd);
    downButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            TdExpression tdExpression = (TdExpression) ((IStructuredSelection) parserRuleTableViewer.getSelection()).getFirstElement();
            if (tdExpression != null) {
                parserRuleTableViewer.moveTdExpression(tdExpression, -1);
            }
        }
    });
    final Button copyButton = new Button(buttonsComposite, SWT.NONE);
    // $NON-NLS-1$
    copyButton.setToolTipText("Copy Selcetion Item");
    copyButton.setImage(ImageLib.getImage(ImageLib.COPY_ACTION));
    copyButton.setLayoutData(labelGd);
    copyButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            List<TdExpression> listTdExpression = ((IStructuredSelection) parserRuleTableViewer.getSelection()).toList();
            parserRuleTableViewer.copyTdExpression(listTdExpression);
        }
    });
    final Button pasteButton = new Button(buttonsComposite, SWT.NONE);
    // $NON-NLS-1$
    pasteButton.setToolTipText("Paste Selcetion Item");
    pasteButton.setImage(ImageLib.getImage(ImageLib.PASTE_ACTION));
    pasteButton.setLayoutData(labelGd);
    pasteButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            parserRuleTableViewer.pasteTdExpression();
        }
    });
    if (isNeedTestButton) {
        final Button testButton = new Button(buttonsComposite, SWT.NONE);
        testButton.setImage(ImageLib.getImage(ImageLib.RULE_TEST));
        // $NON-NLS-1$
        testButton.setToolTipText(DefaultMessagesImpl.getString("ParserRuleMasterDetailsPage.testRule"));
        testButton.setLayoutData(labelGd);
        testButton.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                if (GlobalServiceRegister.getDefault().isServiceRegistered(IAntlrEditorUIService.class)) {
                    IAntlrEditorUIService antlrEditorUIService = (IAntlrEditorUIService) GlobalServiceRegister.getDefault().getService(IAntlrEditorUIService.class);
                    antlrEditorUIService.runTestRuleAction(getCurrentModelElement(), ParserRuleMasterDetailsPage.this.getEditor());
                }
            }
        });
    }
}
Also used : IAntlrEditorUIService(org.talend.dataprofiler.core.service.IAntlrEditorUIService) GridLayout(org.eclipse.swt.layout.GridLayout) Composite(org.eclipse.swt.widgets.Composite) Button(org.eclipse.swt.widgets.Button) TdExpression(org.talend.cwm.relational.TdExpression) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) List(java.util.List) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 44 with TdExpression

use of org.talend.cwm.relational.TdExpression in project tdq-studio-se by Talend.

the class ParserRuleTableViewer method pasteTdExpression.

public void pasteTdExpression() {
    if (copyTdExpression != null) {
        for (TdExpression tdExpression : copyTdExpression) {
            TdExpression newExpresstion = org.talend.cwm.relational.RelationalFactory.eINSTANCE.createTdExpression();
            newExpresstion.setBody(tdExpression.getBody());
            newExpresstion.setLanguage(tdExpression.getLanguage());
            newExpresstion.setName(tdExpression.getName());
            TdExpressionContentProvider contentProvider = (TdExpressionContentProvider) parserRuleTableViewer.getContentProvider();
            List<TdExpression> movedElements = contentProvider.getMovedElements();
            movedElements.add(newExpresstion);
            parserRuleTableViewer.setInput(movedElements);
            this.parserRuleTdExpression.add(newExpresstion);
        }
        setDirty(true);
        this.parserRuleTableViewer.refresh();
    }
}
Also used : TdExpression(org.talend.cwm.relational.TdExpression)

Example 45 with TdExpression

use of org.talend.cwm.relational.TdExpression in project tdq-studio-se by Talend.

the class IndicatorDefinitionMaterPage method checkCorrectForExpression.

/**
 * DOC talend Comment method "checkDuplicateLanguage".
 *
 * @param rc
 * @return
 */
private ReturnCode checkCorrectForExpression() {
    ReturnCode rc = new ReturnCode();
    Map<String, Integer> languageVersionCountMap = new HashMap<String, Integer>();
    Iterator<CCombo> it = tempExpressionMap.keySet().iterator();
    while (it.hasNext()) {
        CCombo cb = it.next();
        TdExpression expression = tempExpressionMap.get(cb);
        String language = expression.getLanguage();
        String version = expression.getVersion();
        if (!language.equals(PatternLanguageType.JAVA.getLiteral())) {
            String body = expression.getBody();
            if (null == body || body.length() + 1 < UDIHelper.MIN_EXPRESSION_LENGTH) {
                rc.setOk(false);
                // $NON-NLS-1$
                rc.setMessage(DefaultMessagesImpl.getString("IndicatorDefinition.validateTooShort"));
                return rc;
            }
        }
        if (version != null && !PluginConstant.EMPTY_STRING.equals(version)) {
            // $NON-NLS-1$
            language = language + " V" + expression.getVersion();
        }
        Integer integer = languageVersionCountMap.get(language);
        if (integer == null) {
            languageVersionCountMap.put(language, 1);
        } else {
            languageVersionCountMap.put(language, integer + 1);
        }
    }
    Iterator<String> iterator = languageVersionCountMap.keySet().iterator();
    while (iterator.hasNext()) {
        String key = iterator.next();
        Integer integer = languageVersionCountMap.get(key);
        if (integer > 1) {
            rc.setOk(false);
            // $NON-NLS-1$
            rc.setMessage(DefaultMessagesImpl.getString("IndicatorDefinitionMaterPage.isRepeatedExp", key));
            return rc;
        }
    }
    return rc;
}
Also used : ReturnCode(org.talend.utils.sugars.ReturnCode) CCombo(org.eclipse.swt.custom.CCombo) HashMap(java.util.HashMap) TdExpression(org.talend.cwm.relational.TdExpression)

Aggregations

TdExpression (org.talend.cwm.relational.TdExpression)121 Test (org.junit.Test)51 IndicatorDefinition (org.talend.dataquality.indicators.definition.IndicatorDefinition)30 UDIndicatorDefinition (org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition)29 ArrayList (java.util.ArrayList)19 RegularExpression (org.talend.dataquality.domain.pattern.RegularExpression)19 Pattern (org.talend.dataquality.domain.pattern.Pattern)16 TdColumn (org.talend.cwm.relational.TdColumn)12 Expression (orgomg.cwm.objectmodel.core.Expression)12 BasicEList (org.eclipse.emf.common.util.BasicEList)11 IndicatorParameters (org.talend.dataquality.indicators.IndicatorParameters)11 Domain (org.talend.dataquality.domain.Domain)10 TdTable (org.talend.cwm.relational.TdTable)9 ProductVersion (org.talend.utils.ProductVersion)9 Analysis (org.talend.dataquality.analysis.Analysis)8 PatternComponent (org.talend.dataquality.domain.pattern.PatternComponent)8 ChartDataEntity (org.talend.dq.indicators.preview.table.ChartDataEntity)8 File (java.io.File)7 IFile (org.eclipse.core.resources.IFile)6 IFolder (org.eclipse.core.resources.IFolder)6