Search in sources :

Example 1 with PatternParameter

use of org.talend.dq.analysis.parameters.PatternParameter in project tdq-studio-se by Talend.

the class CreatePatternWizardPage2 method createControl.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
     */
public void createControl(Composite parent) {
    Composite container = new Composite(parent, SWT.NONE);
    GridLayout gdLayout = new GridLayout(2, false);
    container.setLayout(gdLayout);
    // $NON-NLS-1$
    String s = "Regular expression:";
    // Name
    Label nameLab = new Label(container, SWT.NONE);
    if (type != null) {
        switch(type) {
            case SQL_LIKE:
                // $NON-NLS-1$
                s = "SQL Like expression:";
            // $FALL-THROUGH$
            default:
        }
    }
    nameLab.setText(s);
    expressionText = new Text(container, SWT.BORDER);
    expressionText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    setControl(container);
    expressionText.setText(expression == null ? PluginConstant.EMPTY_STRING : expression);
    nameLab = new Label(container, SWT.NONE);
    // $NON-NLS-1$
    nameLab.setText(DefaultMessagesImpl.getString("CreatePatternWizardPage2.languageSelection"));
    String[] types = PatternLanguageType.getAllLanguageTypes();
    comboLang = new Combo(container, SWT.BORDER);
    comboLang.setItems(types);
    comboLang.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    if (types.length > 0 && language == null) {
        language = PatternLanguageType.Default.getName();
    }
    comboLang.setText(language);
    PatternParameter parameter = (PatternParameter) getParameter();
    parameter.setLanguage(language);
    parameter.setExpression(expression);
    addHelpSurpport();
    addListeners();
    if (!checkFieldsValue()) {
        this.setPageComplete(false);
    }
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) Composite(org.eclipse.swt.widgets.Composite) Label(org.eclipse.swt.widgets.Label) GridData(org.eclipse.swt.layout.GridData) Text(org.eclipse.swt.widgets.Text) Combo(org.eclipse.swt.widgets.Combo) PatternParameter(org.talend.dq.analysis.parameters.PatternParameter)

Example 2 with PatternParameter

use of org.talend.dq.analysis.parameters.PatternParameter in project tdq-studio-se by Talend.

the class CreatePatternWizardPage2 method addListeners.

private void addListeners() {
    expressionText.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            checkFieldsValue();
            if (isStatusOnValid()) {
                PatternParameter parameter = (PatternParameter) getParameter();
                parameter.setExpression(expressionText.getText());
                setPageComplete(true);
            }
        }
    });
    comboLang.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            PatternParameter parameter = (PatternParameter) getParameter();
            parameter.setLanguage(comboLang.getText());
        }
    });
}
Also used : ModifyEvent(org.eclipse.swt.events.ModifyEvent) ModifyListener(org.eclipse.swt.events.ModifyListener) PatternParameter(org.talend.dq.analysis.parameters.PatternParameter)

Example 3 with PatternParameter

use of org.talend.dq.analysis.parameters.PatternParameter in project tdq-studio-se by Talend.

the class CreatePatternsMigratorTask method setTagValue.

private void setTagValue(Pattern pattern, String purpose, String decription) {
    TaggedValueHelper.setTaggedValue(pattern, TaggedValueHelper.DESCRIPTION, decription);
    TaggedValueHelper.setTaggedValue(pattern, TaggedValueHelper.PURPOSE, purpose);
    TaggedValueHelper.setTaggedValue(pattern, TaggedValueHelper.VALID_STATUS, String.valueOf(true));
    if (parameter == null) {
        parameter = new PatternParameter();
    }
    MetadataHelper.setDevStatus(pattern, parameter.getStatus());
    MetadataHelper.setAuthor(pattern, parameter.getAuthor());
    MetadataHelper.setVersion(parameter.getVersion(), pattern);
}
Also used : PatternParameter(org.talend.dq.analysis.parameters.PatternParameter)

Example 4 with PatternParameter

use of org.talend.dq.analysis.parameters.PatternParameter in project tdq-studio-se by Talend.

the class CreatePatternsMigratorTask method doExecute.

@Override
protected boolean doExecute() throws Exception {
    parameter = new PatternParameter();
    // FR Insee Code
    IFolder folder = ResourceManager.getPatternRegexFolder().getFolder(PATH_ADDRESS);
    if (folder.exists()) {
        if (!folder.getFile("FR_Insee_Code_0.1.pattern").exists()) {
            // $NON-NLS-1$ //$NON-NLS-2$
            Pattern pattern = newPattern("FR Insee Code", SQLLanguage, "'^(F-|FRA?(-| ))?((2[A|B])|[0-9]{2})[0-9]{3}$'");
            if (pattern != null) {
                setTagValue(// $NON-NLS-1$
                pattern, // $NON-NLS-1$
                " FRA-2A235 |   F-2B128 |  FRA 2B356", // $NON-NLS-1$
                "French Insee code of cities with Corsica and colonies");
                ElementWriterFactory.getInstance().createPatternWriter().create(pattern, folder);
            }
        }
    }
    // SEDOL
    folder = ResourceManager.getPatternRegexFolder().getFolder(PATH_CUSTOMER);
    if (folder.exists()) {
        if (!folder.getFile("SEDOL_0.1.pattern").exists()) {
            // $NON-NLS-1$ //$NON-NLS-2$
            Pattern pattern = newPattern("SEDOL", SQLLanguage, "'^([B-Db-dF-Hf-hJ-Nj-nP-Tp-tV-Xv-xYyZz0-9]{6}[0-9])$'");
            if (pattern != null) {
                // $NON-NLS-1$ //$NON-NLS-2$
                setTagValue(pattern, "B01HL06 | 4155586", "Stock Exchange Daily Official List ");
                ElementWriterFactory.getInstance().createPatternWriter().create(pattern, folder);
            }
        }
    }
    // IPV6 MAC Address
    folder = ResourceManager.getPatternRegexFolder().getFolder(PATH_INTERNET);
    if (folder.exists()) {
        if (!folder.getFile("IPv6_Address_0.1.pattern").exists()) {
            Pattern pattern = newPattern(// $NON-NLS-1$
            "IPv6 Address", SQLLanguage, // $NON-NLS-1$
            "'^((([0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}:[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){5}:([0-9A-Fa-f]{1,4}:)?[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){4}:([0-9A-Fa-f]{1,4}:){0,2}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){3}:([0-9A-Fa-f]{1,4}:){0,3}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){2}:([0-9A-Fa-f]{1,4}:){0,4}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}((\\b((25[0-5])|(1\\d{2})|(2[0-4]\\d)|(\\d{1,2}))\\b)\\.){3}(\\b((25[0-5])|(1\\d{2})|(2[0-4]\\d)|(\\d{1,2}))\\b))|(([0-9A-Fa-f]{1,4}:){0,5}:((\\b((25[0-5])|(1\\d{2})|(2[0-4]\\d)|(\\d{1,2}))\\b)\\.){3}(\\b((25[0-5])|(1\\d{2})|(2[0-4]\\d)|(\\d{1,2}))\\b))|(::([0-9A-Fa-f]{1,4}:){0,5}((\\b((25[0-5])|(1\\d{2})|(2[0-4]\\d)|(\\d{1,2}))\\b)\\.){3}(\\b((25[0-5])|(1\\d{2})|(2[0-4]\\d)|(\\d{1,2}))\\b))|([0-9A-Fa-f]{1,4}::([0-9A-Fa-f]{1,4}:){0,5}[0-9A-Fa-f]{1,4})|(::([0-9A-Fa-f]{1,4}:){0,6}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){1,7}:))$'");
            if (pattern != null) {
                // $NON-NLS-1$ //$NON-NLS-2$
                setTagValue(pattern, "Check if it is a IPv6 address", "IPv6 address");
                ElementWriterFactory.getInstance().createPatternWriter().create(pattern, folder);
            }
        }
        if (!folder.getFile("MAC_Address_0.1.pattern").exists()) {
            Pattern pattern = newPattern("MAC Address", SQLLanguage, // $NON-NLS-1$ //$NON-NLS-2$
            "'^([0-9a-fA-F][0-9a-fA-F]:){5}([0-9a-fA-F][0-9a-fA-F])$'");
            if (pattern != null) {
                // $NON-NLS-1$ //$NON-NLS-2$
                setTagValue(pattern, "A4:4E:31:B9:C5:B4", "Match MAC Address");
                ElementWriterFactory.getInstance().createPatternWriter().create(pattern, folder);
            }
        }
    }
    // GPS Coordinate ,ISBN 13,UK SSN
    folder = ResourceManager.getPatternRegexFolder().getFolder(PATH_NUMBER);
    if (folder.exists()) {
        if (!folder.getFile("GPS_Coordinate_0.1.pattern").exists()) {
            Pattern pattern = newPattern(// $NON-NLS-1$
            "GPS Coordinate", // $NON-NLS-1$
            SQLLanguage, // $NON-NLS-1$
            "'^([0-9]{1,3}[\\.][0-9]*)[, ]+-?([0-9]{1,3}[\\.][0-9]*)$'");
            if (pattern != null) {
                // $NON-NLS-1$ //$NON-NLS-2$
                setTagValue(pattern, "40.7127837,-74.00594130000002", "Google Maps style GPS Decimal format");
                ElementWriterFactory.getInstance().createPatternWriter().create(pattern, folder);
            }
        }
        if (!folder.getFile("UK_SSN_0.1.pattern").exists()) {
            Pattern pattern = newPattern(// $NON-NLS-1$
            "UK SSN", // $NON-NLS-1$
            SQLLanguage, // $NON-NLS-1$
            "'^[A-CEGHJ-PR-TW-Z]{1}[A-CEGHJ-NPR-TW-Z]{1}([0-9]{6}|( [0-9]{2}){3} )[A-DFM]{0,1}$'");
            if (pattern != null) {
                setTagValue(// $NON-NLS-1$
                pattern, // $NON-NLS-1$
                "AB123456C | AB 12 34 56 C", // $NON-NLS-1$
                "National identification number, national identity number, or national insurance number generally called an NI Number (NINO)");
                ElementWriterFactory.getInstance().createPatternWriter().create(pattern, folder);
            }
        }
    }
    // EN Amount Money ,FR Amount Money
    folder = ResourceManager.getPatternRegexFolder().getFolder(PATH_MONEY);
    if (!folder.exists()) {
        folder.create(true, true, null);
    }
    if (folder.exists()) {
        if (!folder.getFile("EN_Amount_Money_0.1.pattern").exists()) {
            Pattern pattern = newPattern(// $NON-NLS-1$
            "EN Amount Money", // $NON-NLS-1$
            SQLLanguage, // $NON-NLS-1$
            "'^((US|CA)?\\$|\\£|\\€|\\¥)(([1-9][0-9]{0,2}(\\,[0-9]{3})*)|([1-9][0-9]*)|(0))(\\.[0-9]{2}|k|M|G|T)?$'");
            if (pattern != null) {
                RegularExpression regularExpr = BooleanExpressionHelper.createRegularExpression(// $NON-NLS-1$
                "MySQL", // $NON-NLS-1$
                "'^((US|CA)?\\\\$|\\£|\\€|\\¥)(([1-9][0-9]{0,2}(\\,[0-9]{3})*)|([1-9][0-9]*)|(0))(\\.[0-9]{2}|k|M|G|T)?$'");
                // $NON-NLS-1$
                regularExpr.setExpressionType("REGEXP");
                pattern.getComponents().add(regularExpr);
                // $NON-NLS-1$ //$NON-NLS-2$
                setTagValue(pattern, "$3,000 || CA$3000", "Amount of money in English format");
                ElementWriterFactory.getInstance().createPatternWriter().create(pattern, folder);
            }
        }
        if (!folder.getFile("FR_Amount_Money_0.1.pattern").exists()) {
            Pattern pattern = newPattern(// $NON-NLS-1$
            "FR Amount Money", // $NON-NLS-1$
            SQLLanguage, // $NON-NLS-1$
            "'^(([1-9][0-9]{0,2}( [0-9]{3})*)|([1-9][0-9]*)|0)((,[0-9]{2} | (k|M|G|T))?| )(\\$( (US|CA))?|\\£|\\€|\\¥)$'");
            if (pattern != null) {
                // $NON-NLS-1$ //$NON-NLS-2$
                setTagValue(pattern, "3000 € | 35 k€ | 35 054 T€", "Amount of money in French format");
                ElementWriterFactory.getInstance().createPatternWriter().create(pattern, folder);
            }
        }
    }
    // EN_Month_Abbrev,EN_Month
    folder = ResourceManager.getPatternRegexFolder().getFolder(PATH_DATE);
    if (folder.exists()) {
        if (!folder.getFile("EN_Month_Abbrev_0.1.pattern").exists()) {
            Pattern pattern = newPattern("EN_Month_Abbrev", SQLLanguage, // $NON-NLS-1$ //$NON-NLS-2$
            "'^(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)$'");
            if (pattern != null) {
                // $NON-NLS-1$ //$NON-NLS-2$
                setTagValue(pattern, "Jan | Feb ", "Month English abbreviation");
                ElementWriterFactory.getInstance().createPatternWriter().create(pattern, folder);
            }
        }
        if (!folder.getFile("EN_Month_0.1.pattern").exists()) {
            Pattern pattern = newPattern(// $NON-NLS-1$
            "EN_Month", // $NON-NLS-1$
            SQLLanguage, // $NON-NLS-1$
            "'^(January|June|July|February|March|May|April|August|September|October|November|December)$'");
            if (pattern != null) {
                // $NON-NLS-1$ //$NON-NLS-2$
                setTagValue(pattern, "January | February ", "Month in English");
                ElementWriterFactory.getInstance().createPatternWriter().create(pattern, folder);
            }
        }
    }
    return true;
}
Also used : Pattern(org.talend.dataquality.domain.pattern.Pattern) RegularExpression(org.talend.dataquality.domain.pattern.RegularExpression) PatternParameter(org.talend.dq.analysis.parameters.PatternParameter) IFolder(org.eclipse.core.resources.IFolder)

Example 5 with PatternParameter

use of org.talend.dq.analysis.parameters.PatternParameter in project tdq-studio-se by Talend.

the class AddPatternISBN13Task method doExecute.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.dataprofiler.migration.AMigrationTask#doExecute()
     */
@Override
protected boolean doExecute() throws Exception {
    parameter = new PatternParameter();
    ReturnCode rc1 = new ReturnCode(true), rc2 = new ReturnCode(true), rc3 = new ReturnCode(true);
    // number folder
    // $NON-NLS-1$
    IFolder folder = ResourceManager.getPatternRegexFolder().getFolder("number");
    if (folder.exists()) {
        // only create ISBN 13 Checker when not found.
        if (!folder.getFile("ISBN_13_Checker_0.1.pattern").exists()) {
            Pattern pattern = newPattern(// $NON-NLS-1$ //$NON-NLS-2$
            "ISBN 13 Checker", // $NON-NLS-1$ //$NON-NLS-2$
            "Java", // $NON-NLS-1$
            "'^ISBN(?:-13)?:?\\ *(97(?:8|9)([ -]?)(?=[0-9]{1,5}\\2?[0-9]{1,7}\\2?[0-9]{1,6}\\2?[0-9])(?:[0-9]\\2*){9}[0-9])$'");
            if (pattern != null) {
                setTagValue(// $NON-NLS-1$
                pattern, // $NON-NLS-1$
                "ISBN-13: 978-2711791415 | ISBN 978-2711791415 |  ISBN: 978-2711791415", // $NON-NLS-1$
                "International Standard Book Number 13 digits");
                rc1 = ElementWriterFactory.getInstance().createPatternWriter().create(pattern, folder);
            }
        }
    }
    // Update IPv6 Address.pattern.
    // $NON-NLS-1$
    IFile file = ResourceManager.getPatternRegexFolder().getFolder("internet").getFile("IPv6_Address_0.1.pattern");
    if (file.exists()) {
        Pattern ipv6Pattern = PatternResourceFileHelper.getInstance().findPattern(file);
        if (ipv6Pattern != null) {
            List<PatternComponent> componentLs = new ArrayList<PatternComponent>();
            // $NON-NLS-1$
            componentLs.add(BooleanExpressionHelper.createRegularExpression("Java", REGEX_BODY, ExpressionType.REGEXP));
            // $NON-NLS-1$
            componentLs.add(BooleanExpressionHelper.createRegularExpression("MySQL", REGEX_BODY, ExpressionType.REGEXP));
            // $NON-NLS-1$
            componentLs.add(BooleanExpressionHelper.createRegularExpression("PostgreSQL", REGEX_BODY, ExpressionType.REGEXP));
            ipv6Pattern.getComponents().clear();
            ipv6Pattern.getComponents().addAll(componentLs);
            rc2 = PatternResourceFileHelper.getInstance().save(ipv6Pattern);
        }
    }
    // Update EN Month.pattern. for expresstion add ()
    // $NON-NLS-1$ //$NON-NLS-2$
    IFile file2 = ResourceManager.getPatternRegexFolder().getFolder("date").getFile("EN_Month_0.1.pattern");
    if (file2.exists()) {
        Pattern enMonthPattern = PatternResourceFileHelper.getInstance().findPattern(file2);
        if (enMonthPattern != null) {
            List<PatternComponent> componentLs = new ArrayList<PatternComponent>();
            // $NON-NLS-1$
            String regexBody = "'^(January|June|July|February|March|May|April|August|September|October|November|December)$'";
            // $NON-NLS-1$
            componentLs.add(BooleanExpressionHelper.createRegularExpression("SQL", regexBody, ExpressionType.REGEXP));
            enMonthPattern.getComponents().clear();
            enMonthPattern.getComponents().addAll(componentLs);
            rc3 = PatternResourceFileHelper.getInstance().save(enMonthPattern);
        }
    }
    return rc1.isOk() && rc2.isOk() && rc3.isOk();
}
Also used : Pattern(org.talend.dataquality.domain.pattern.Pattern) ReturnCode(org.talend.utils.sugars.ReturnCode) IFile(org.eclipse.core.resources.IFile) ArrayList(java.util.ArrayList) PatternComponent(org.talend.dataquality.domain.pattern.PatternComponent) PatternParameter(org.talend.dq.analysis.parameters.PatternParameter) IFolder(org.eclipse.core.resources.IFolder)

Aggregations

PatternParameter (org.talend.dq.analysis.parameters.PatternParameter)7 IFolder (org.eclipse.core.resources.IFolder)2 Pattern (org.talend.dataquality.domain.pattern.Pattern)2 ArrayList (java.util.ArrayList)1 IFile (org.eclipse.core.resources.IFile)1 IContext (org.eclipse.help.IContext)1 IHelpResource (org.eclipse.help.IHelpResource)1 WizardDialog (org.eclipse.jface.wizard.WizardDialog)1 ModifyEvent (org.eclipse.swt.events.ModifyEvent)1 ModifyListener (org.eclipse.swt.events.ModifyListener)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Combo (org.eclipse.swt.widgets.Combo)1 Composite (org.eclipse.swt.widgets.Composite)1 Label (org.eclipse.swt.widgets.Label)1 Text (org.eclipse.swt.widgets.Text)1 FolderProvider (org.talend.cwm.management.api.FolderProvider)1 CreatePatternWizard (org.talend.dataprofiler.core.pattern.CreatePatternWizard)1 OpeningHelpWizardDialog (org.talend.dataprofiler.core.ui.utils.OpeningHelpWizardDialog)1 PatternComponent (org.talend.dataquality.domain.pattern.PatternComponent)1