Search in sources :

Example 1 with RegularExpressionImpl

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

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

the class PatternLabelProvider method isPatternValid.

/**
 * DOC qzhang Comment method "isPatternValid".
 *
 * @param pattern
 * @return
 */
public static boolean isPatternValid(Pattern pattern) {
    boolean valid = false;
    EList<PatternComponent> components = pattern.getComponents();
    for (int i = 0; i < components.size(); i++) {
        RegularExpressionImpl regularExpress = (RegularExpressionImpl) components.get(i);
        String body = regularExpress.getExpression().getBody();
        // $NON-NLS-1$
        valid = ((body != null) && body.matches("'.*'"));
        if (!valid) {
            break;
        }
    }
    return valid;
}
Also used : RegularExpressionImpl(org.talend.dataquality.domain.pattern.impl.RegularExpressionImpl) PatternComponent(org.talend.dataquality.domain.pattern.PatternComponent)

Example 3 with RegularExpressionImpl

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

the class PatternTestView method savePattern.

/**
 * If the pattern is not null, will save it and update the corresponding pattern editor content.
 */
private void savePattern() {
    // If the pattern is not null, will update the pattern editor content.
    if (pattern != null) {
        String expressionLanguage = this.regularExpression.getExpression().getLanguage();
        DbmsLanguage dbmsLanguage = this.getDbmsLanguage();
        // MOD gdbu 2011-6-13 bug : 21695
        if (null != dbmsLanguage) {
            dbmsLanguage.setRegularExpressionFunction(getFunctionName());
        }
        // ~21695
        // ~19119
        // MOD qiongli 2011-1-7 featrue 16799.
        boolean isLanguageMatched = false;
        if (isJavaEngine && expressionLanguage.equals(ExecutionLanguage.JAVA.getLiteral()) || dbmsLanguage != null && (dbmsLanguage.getDbmsName().equalsIgnoreCase(expressionLanguage))) {
            isLanguageMatched = true;
        }
        if (!isLanguageMatched) {
            String messageInfo = DefaultMessagesImpl.getString("PatternTestView.modifiedTheRegularExpression", expressionLanguage, dbmsLanguage.getDbmsName(), expressionLanguage, expressionLanguage, // $NON-NLS-1$
            dbmsLanguage.getDbmsName());
            MessageDialog messageDialog = new MessageDialog(new Shell(), // $NON-NLS-1$
            DefaultMessagesImpl.getString("PatternTestView.warning"), // $NON-NLS-1$
            null, // $NON-NLS-1$
            messageInfo, // $NON-NLS-1$
            MessageDialog.WARNING, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0);
            int result = messageDialog.open();
            if (result == MessageDialog.OK) {
                regularExpression.getExpression().setBody(regularText.getText());
            } else {
                EList<PatternComponent> components = this.pattern.getComponents();
                boolean isContainLanguage = false;
                for (int i = 0; i < components.size(); i++) {
                    RegularExpressionImpl regularExpress = (RegularExpressionImpl) components.get(i);
                    // expression
                    if (dbmsLanguage.getDbmsName().equalsIgnoreCase(regularExpress.getExpression().getLanguage())) {
                        regularExpress.getExpression().setBody(regularText.getText());
                        isContainLanguage = true;
                        break;
                    }
                }
                // expression.
                if (!isContainLanguage) {
                    RegularExpression newRegularExpress = BooleanExpressionHelper.createRegularExpression(dbmsLanguage.getDbmsName(), regularText.getText());
                    this.pattern.getComponents().add(newRegularExpress);
                }
            }
        } else {
            regularExpression.getExpression().setBody(regularText.getText());
        }
        EMFUtil.saveSingleResource(pattern.eResource());
        editorPage.updatePatternDefinitonSection();
        // MessageDialog.openInformation(new Shell(), "Success",
        // "Success to save the pattern '" +
        // pattern.getName()
        // + "'");
        saveButton.setEnabled(false);
    }
}
Also used : DbmsLanguage(org.talend.dq.dbms.DbmsLanguage) RegularExpression(org.talend.dataquality.domain.pattern.RegularExpression) Shell(org.eclipse.swt.widgets.Shell) RegularExpressionImpl(org.talend.dataquality.domain.pattern.impl.RegularExpressionImpl) PatternComponent(org.talend.dataquality.domain.pattern.PatternComponent) MessageDialog(org.eclipse.jface.dialogs.MessageDialog)

Example 4 with RegularExpressionImpl

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

the class PatternMasterDetailsPage method savePattern.

private boolean savePattern() {
    if (tempPatternComponents.isEmpty()) {
        MessageDialog.openError(null, DefaultMessagesImpl.getString("PatternMasterDetailsPage.error"), // $NON-NLS-1$ //$NON-NLS-2$
        DefaultMessagesImpl.getString("PatternMasterDetailsPage.cannotSave", getCurrentModelElement().getName()));
        return false;
    }
    getCurrentModelElement().getComponents().clear();
    getCurrentModelElement().getComponents().addAll(tempPatternComponents);
    // PTODO fixed bug 4296: set the Pattern is valid
    TaggedValueHelper.setValidStatus(true, getCurrentModelElement());
    EList<PatternComponent> components = getCurrentModelElement().getComponents();
    List<String> existLanguage = new ArrayList<String>();
    for (int i = 0; i < components.size(); i++) {
        RegularExpressionImpl regularExpress = (RegularExpressionImpl) components.get(i);
        String language = regularExpress.getExpression().getLanguage();
        if ((regularExpress.getExpression().getBody() == null) || (!regularExpress.getExpression().getBody().matches("'.*'"))) {
            // $NON-NLS-1$
            MessageDialog.openWarning(null, DefaultMessagesImpl.getString("PatternMasterDetailsPage.warning"), // $NON-NLS-1$ //$NON-NLS-2$
            DefaultMessagesImpl.getString("PatternMasterDetailsPage.patternExpressions", language));
            return false;
        }
        if (existLanguage.contains(language)) {
            MessageDialog.openError(null, DefaultMessagesImpl.getString("PatternMasterDetailsPage.error"), // $NON-NLS-1$ //$NON-NLS-2$
            DefaultMessagesImpl.getString("PatternMasterDetailsPage.languageType", language));
            return false;
        } else {
            existLanguage.add(language);
        }
    }
    TDQPatternItem patternItem = (TDQPatternItem) this.patternRepNode.getObject().getProperty().getItem();
    // Added TDQ-14249 rename udi, 20170920
    patternRepNode.getObject().getProperty().setDisplayName(patternItem.getPattern().getName());
    // MOD yyi 2012-02-08 TDQ-4621:Explicitly set true for updating dependencies.
    ElementWriterFactory.getInstance().createPatternWriter().save(patternItem, true);
    // TDQ-13498 : SQL pattern should not pop up modify jobs' dialog.
    if (!ExpressionType.SQL_LIKE.getLiteral().equals(expressionType)) {
        // TDQ-11688
        RepositoryUpdateManager.updateDQPattern(patternItem);
    }
    return true;
}
Also used : RegularExpressionImpl(org.talend.dataquality.domain.pattern.impl.RegularExpressionImpl) ArrayList(java.util.ArrayList) PatternComponent(org.talend.dataquality.domain.pattern.PatternComponent) TDQPatternItem(org.talend.dataquality.properties.TDQPatternItem)

Example 5 with RegularExpressionImpl

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

the class UpdateStartWithBlankPatternTask method doExecute.

/*
     * (non-Jsdoc) update the regular express for java
     */
@Override
protected boolean doExecute() throws Exception {
    IPath realtivePath = // $NON-NLS-1$
    ResourceManager.getPatternRegexFolder().getFullPath().append("/text").makeRelativeTo(ResourceManager.getRootProject().getFullPath());
    RootContainer<String, IRepositoryViewObject> tdqViewObjects = ProxyRepositoryFactory.getInstance().getTdqRepositoryViewObjects(ERepositoryObjectType.TDQ_PATTERN_REGEX, realtivePath.toString());
    for (IRepositoryViewObject viewObject : tdqViewObjects.getMembers()) {
        Item item = viewObject.getProperty().getItem();
        Pattern pattern = null;
        if (item != null && item instanceof TDQPatternItem) {
            TDQPatternItem patternItem = (TDQPatternItem) item;
            pattern = patternItem.getPattern();
            boolean isFound = false;
            if (PATTERN_NAME.equals(pattern.getName())) {
                EList<PatternComponent> components = pattern.getComponents();
                for (PatternComponent pComponet : components) {
                    RegularExpressionImpl regularExpress = (RegularExpressionImpl) pComponet;
                    if (JAVA_LANGUAGE.equals(regularExpress.getExpression().getLanguage())) {
                        regularExpress.getExpression().setBody(JAVA_REGULAR_EXPRESSION);
                        patternItem.setPattern(pattern);
                        // MOD yyi 2012-02-08 TDQ-4621:Explicitly set true for updating dependencies.
                        ElementWriterFactory.getInstance().createPatternWriter().save(patternItem, true);
                        isFound = true;
                        break;
                    }
                }
            }
            if (isFound) {
                break;
            }
        }
    }
    return true;
}
Also used : Item(org.talend.core.model.properties.Item) TDQPatternItem(org.talend.dataquality.properties.TDQPatternItem) Pattern(org.talend.dataquality.domain.pattern.Pattern) IPath(org.eclipse.core.runtime.IPath) RegularExpressionImpl(org.talend.dataquality.domain.pattern.impl.RegularExpressionImpl) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PatternComponent(org.talend.dataquality.domain.pattern.PatternComponent) TDQPatternItem(org.talend.dataquality.properties.TDQPatternItem)

Aggregations

PatternComponent (org.talend.dataquality.domain.pattern.PatternComponent)5 RegularExpressionImpl (org.talend.dataquality.domain.pattern.impl.RegularExpressionImpl)5 RegularExpression (org.talend.dataquality.domain.pattern.RegularExpression)2 TDQPatternItem (org.talend.dataquality.properties.TDQPatternItem)2 ArrayList (java.util.ArrayList)1 IPath (org.eclipse.core.runtime.IPath)1 MessageDialog (org.eclipse.jface.dialogs.MessageDialog)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 GridData (org.eclipse.swt.layout.GridData)1 Button (org.eclipse.swt.widgets.Button)1 Shell (org.eclipse.swt.widgets.Shell)1 Item (org.talend.core.model.properties.Item)1 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)1 Pattern (org.talend.dataquality.domain.pattern.Pattern)1 DbmsLanguage (org.talend.dq.dbms.DbmsLanguage)1