Search in sources :

Example 6 with PatternComponent

use of org.talend.dataquality.domain.pattern.PatternComponent 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 7 with PatternComponent

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

the class PatternMasterDetailsPage method createAddButton.

private void createAddButton(Composite parent) {
    final Button addButton = new Button(parent, SWT.NONE);
    addButton.setImage(ImageLib.getImage(ImageLib.ADD_ACTION));
    // $NON-NLS-1$
    addButton.setToolTipText(DefaultMessagesImpl.getString("PatternMasterDetailsPage.add"));
    GridData labelGd = new GridData();
    labelGd.horizontalAlignment = SWT.CENTER;
    labelGd.widthHint = 65;
    addButton.setLayoutData(labelGd);
    addButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            remainDBTypeList.clear();
            remainDBTypeList.addAll(allDBTypeList);
            for (PatternComponent patternComponent : tempPatternComponents) {
                String language = ((RegularExpressionImpl) patternComponent).getExpression().getLanguage();
                String languageName = PatternLanguageType.findNameByLanguage(language);
                remainDBTypeList.remove(languageName);
            }
            if (remainDBTypeList.isEmpty()) {
                MessageDialog.openWarning(null, DefaultMessagesImpl.getString("PatternMasterDetailsPage.warning"), // $NON-NLS-1$ //$NON-NLS-2$
                DefaultMessagesImpl.getString("PatternMasterDetailsPage.patternExpression"));
                return;
            }
            String language = PatternLanguageType.findLanguageByName(remainDBTypeList.get(0));
            RegularExpression newRegularExpress = BooleanExpressionHelper.createRegularExpression(language, null);
            newRegularExpress.setExpressionType(expressionType);
            creatNewExpressLine(newRegularExpress);
            tempPatternComponents.add(newRegularExpress);
            patternDefinitionSection.setExpanded(true);
            setDirty(true);
        }
    });
}
Also used : RegularExpression(org.talend.dataquality.domain.pattern.RegularExpression) RegularExpressionImpl(org.talend.dataquality.domain.pattern.impl.RegularExpressionImpl) Button(org.eclipse.swt.widgets.Button) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) PatternComponent(org.talend.dataquality.domain.pattern.PatternComponent)

Example 8 with PatternComponent

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

the class DbmsLanguage method getRegexp.

/**
 * Method "getRegexp".
 *
 * When in SQL engine, retrieve the regex with the matching Dbms Language. If null, return the regex with default
 * SQL (even if it's null)
 *
 * @param pattern a pattern
 * @return the body of the regular expression applicable to this dbms or null
 */
public Expression getRegexp(Pattern pattern) {
    // MOD by zhsne for bug 17172 2010.12.10
    Expression expression = null;
    Expression defaultExpression = null;
    EList<PatternComponent> components = pattern.getComponents();
    for (PatternComponent patternComponent : components) {
        if (patternComponent != null) {
            expression = this.getExpression(patternComponent);
            if (expression != null && DbmsLanguageFactory.compareDbmsLanguage(this.dbmsName, expression.getLanguage())) {
                // return this db's expression
                return expression;
            } else if (expression != null && DbmsLanguageFactory.compareDbmsLanguage(ExecutionLanguage.SQL.getName(), expression.getLanguage())) {
                // remember the default expression
                defaultExpression = expression;
            }
        }
    }
    // if can not find itself, return the default one.
    return defaultExpression;
}
Also used : TdExpression(org.talend.cwm.relational.TdExpression) RegularExpression(org.talend.dataquality.domain.pattern.RegularExpression) Expression(orgomg.cwm.objectmodel.core.Expression) PatternComponent(org.talend.dataquality.domain.pattern.PatternComponent)

Example 9 with PatternComponent

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

the class PatternRepNode method getChildren.

@Override
public List<IRepositoryNode> getChildren() {
    List<IRepositoryNode> languageElement = new ArrayList<IRepositoryNode>();
    IRepositoryViewObject object = this.getObject();
    TDQPatternItem patternItem = (TDQPatternItem) object.getProperty().getItem();
    Pattern pattern = patternItem.getPattern();
    EList<PatternComponent> components = pattern.getComponents();
    for (PatternComponent component : components) {
        RegularExpression re = (RegularExpression) component;
        Expression expression = re.getExpression();
        String language = expression.getLanguage();
        PatternLanguageRepNode plrn = new PatternLanguageRepNode(this, ENodeType.TDQ_REPOSITORY_ELEMENT, getProject());
        plrn.setRegularExpression(re);
        plrn.setId(language);
        plrn.setLabel(language);
        languageElement.add(plrn);
    }
    // MOD gdbu 2011-7-11 bug : 22204
    return filterResultsIfAny(languageElement);
// ~22204
}
Also used : Pattern(org.talend.dataquality.domain.pattern.Pattern) RegularExpression(org.talend.dataquality.domain.pattern.RegularExpression) IRepositoryNode(org.talend.repository.model.IRepositoryNode) Expression(orgomg.cwm.objectmodel.core.Expression) RegularExpression(org.talend.dataquality.domain.pattern.RegularExpression) ArrayList(java.util.ArrayList) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PatternComponent(org.talend.dataquality.domain.pattern.PatternComponent) TDQPatternItem(org.talend.dataquality.properties.TDQPatternItem)

Example 10 with PatternComponent

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

the class ComponentReferenceImpl method setReferencedComponent.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public void setReferencedComponent(PatternComponent newReferencedComponent) {
    PatternComponent oldReferencedComponent = referencedComponent;
    referencedComponent = newReferencedComponent;
    if (eNotificationRequired())
        eNotify(new ENotificationImpl(this, Notification.SET, PatternPackage.COMPONENT_REFERENCE__REFERENCED_COMPONENT, oldReferencedComponent, referencedComponent));
}
Also used : ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl) PatternComponent(org.talend.dataquality.domain.pattern.PatternComponent)

Aggregations

PatternComponent (org.talend.dataquality.domain.pattern.PatternComponent)24 RegularExpression (org.talend.dataquality.domain.pattern.RegularExpression)18 Pattern (org.talend.dataquality.domain.pattern.Pattern)15 TdExpression (org.talend.cwm.relational.TdExpression)10 Test (org.junit.Test)9 RegularExpressionImpl (org.talend.dataquality.domain.pattern.impl.RegularExpressionImpl)5 ArrayList (java.util.ArrayList)4 Domain (org.talend.dataquality.domain.Domain)4 TDQPatternItem (org.talend.dataquality.properties.TDQPatternItem)4 Expression (orgomg.cwm.objectmodel.core.Expression)4 IndicatorParameters (org.talend.dataquality.indicators.IndicatorParameters)3 RegexpMatchingIndicator (org.talend.dataquality.indicators.RegexpMatchingIndicator)3 IFile (org.eclipse.core.resources.IFile)2 URI (org.eclipse.emf.common.util.URI)2 Resource (org.eclipse.emf.ecore.resource.Resource)2 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)2 ReturnCode (org.talend.utils.sugars.ReturnCode)2 File (java.io.File)1 URI (java.net.URI)1 HashMap (java.util.HashMap)1