Search in sources :

Example 36 with Pattern

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

the class AElementPersistance method createItem.

/**
 * DOC bZhou Comment method "createItem".
 *
 * @param element
 * @return
 */
public Item createItem(ModelElement element) {
    Item item = null;
    // MOD mzhao feature 13114, 2010-05-19 distinguish tdq items.
    if (ModelElementIdentifier.isAnalysis(element)) {
        item = PropertiesFactory.eINSTANCE.createTDQAnalysisItem();
        ((TDQAnalysisItem) item).setAnalysis((Analysis) element);
    } else if (ModelElementIdentifier.isDQRule(element)) {
        item = PropertiesFactory.eINSTANCE.createTDQBusinessRuleItem();
        ((TDQBusinessRuleItem) item).setDqrule((DQRule) element);
    } else if (ModelElementIdentifier.isDataProvider(element)) {
        if (element instanceof DatabaseConnection) {
            item = org.talend.core.model.properties.PropertiesFactory.eINSTANCE.createDatabaseConnectionItem();
            ((ConnectionItem) item).setConnection((DatabaseConnection) element);
        }
        ((ConnectionItem) item).setConnection((Connection) element);
    } else if (ModelElementIdentifier.isMatchRule(element)) {
        // this Condition must before the IndicatorDefinition one because MatchRule instance of it.
        item = PropertiesFactory.eINSTANCE.createTDQMatchRuleItem();
        ((TDQMatchRuleItem) item).setMatchRule((MatchRuleDefinition) element);
    } else if (ModelElementIdentifier.isID(element)) {
        item = PropertiesFactory.eINSTANCE.createTDQIndicatorDefinitionItem();
        ((TDQIndicatorDefinitionItem) item).setIndicatorDefinition((IndicatorDefinition) element);
    } else if (ModelElementIdentifier.isPattern(element)) {
        item = PropertiesFactory.eINSTANCE.createTDQPatternItem();
        ((TDQPatternItem) item).setPattern((Pattern) element);
    } else if (ModelElementIdentifier.isReport(element)) {
        item = PropertiesFactory.eINSTANCE.createTDQReportItem();
        ((TDQReportItem) item).setReport((Report) element);
    } else {
        item = org.talend.core.model.properties.PropertiesFactory.eINSTANCE.createTDQItem();
    }
    ItemState itemState = org.talend.core.model.properties.PropertiesFactory.eINSTANCE.createItemState();
    itemState.setDeleted(false);
    item.setState(itemState);
    if (item instanceof TDQItem) {
        setTDQItemFileName(element, item);
    }
    Resource eResource = element.eResource();
    if (eResource != null) {
        URI uri = eResource.getURI();
        if (uri.isPlatform()) {
            IPath elementPath = new Path(uri.toPlatformString(true)).removeLastSegments(1);
            IPath typedPath = ResourceManager.getRootProject().getFullPath().append(PropertyHelper.getItemTypedPath(item));
            IPath statePath = elementPath.makeRelativeTo(typedPath);
            itemState.setPath(statePath.toString());
        }
    }
    return item;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) Pattern(org.talend.dataquality.domain.pattern.Pattern) TDQIndicatorDefinitionItem(org.talend.dataquality.properties.TDQIndicatorDefinitionItem) IPath(org.eclipse.core.runtime.IPath) ConnectionItem(org.talend.core.model.properties.ConnectionItem) Resource(org.eclipse.emf.ecore.resource.Resource) MatchRuleDefinition(org.talend.dataquality.rules.MatchRuleDefinition) URI(org.eclipse.emf.common.util.URI) DQRule(org.talend.dataquality.rules.DQRule) Item(org.talend.core.model.properties.Item) TDQIndicatorDefinitionItem(org.talend.dataquality.properties.TDQIndicatorDefinitionItem) TDQAnalysisItem(org.talend.dataquality.properties.TDQAnalysisItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) TDQItem(org.talend.core.model.properties.TDQItem) TDQPatternItem(org.talend.dataquality.properties.TDQPatternItem) TDQMatchRuleItem(org.talend.dataquality.properties.TDQMatchRuleItem) TDQBusinessRuleItem(org.talend.dataquality.properties.TDQBusinessRuleItem) TDQReportItem(org.talend.dataquality.properties.TDQReportItem) ItemState(org.talend.core.model.properties.ItemState) TDQItem(org.talend.core.model.properties.TDQItem) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) TDQReportItem(org.talend.dataquality.properties.TDQReportItem) TDQAnalysisItem(org.talend.dataquality.properties.TDQAnalysisItem)

Example 37 with Pattern

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

Example 38 with Pattern

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

the class AddPatternISBN13Task method newPattern.

private Pattern newPattern(String name, String lang, String express) {
    PatternBuilder patternBuilder = new PatternBuilder();
    boolean patternInitialized = patternBuilder.initializePattern(name);
    if (patternInitialized) {
        Pattern pattern = patternBuilder.getPattern();
        RegularExpression regularExpr = BooleanExpressionHelper.createRegularExpression(lang, express);
        // $NON-NLS-1$
        regularExpr.setExpressionType("REGEXP");
        pattern.getComponents().add(regularExpr);
        return pattern;
    }
    return null;
}
Also used : Pattern(org.talend.dataquality.domain.pattern.Pattern) RegularExpression(org.talend.dataquality.domain.pattern.RegularExpression) PatternBuilder(org.talend.dq.pattern.PatternBuilder)

Example 39 with Pattern

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

the class ExportFactory method export.

static void export(File exportFile, IFolder folder, Pattern... patterns) {
    if (exportFile.isDirectory()) {
        for (Pattern pattern : patterns) {
            // $NON-NLS-1$
            File file = new File(exportFile, toLocalFileName(pattern.getName() + ".csv"));
            export(file, folder, pattern);
        }
    }
    String fileExtName = getFileExtName(exportFile);
    if (FileUtils.isCSV(fileExtName)) {
        try {
            CSVWriter out = FileUtils.createCSVWriter(exportFile, FileUtils.TEXT_QUAL, FileUtils.TEXT_QUAL);
            PatternToExcelEnum[] values = PatternToExcelEnum.values();
            String[] temp = new String[values.length];
            Map<PatternToExcelEnum, String> relatedValueMap = null;
            for (int i = 0; i < patterns.length + 1; i++) {
                if (i != 0) {
                    relatedValueMap = getRelatedValueFromPattern(patterns[i - 1], folder);
                }
                for (int j = 0; j < values.length; j++) {
                    if (i == 0) {
                        temp[j] = values[j].getLiteral();
                    } else {
                        if (relatedValueMap == null) {
                            // $NON-NLS-1$
                            throw new NullPointerException(DefaultMessagesImpl.getString("ExportFactory.RelatedValueMapNull"));
                        }
                        temp[j] = relatedValueMap.get(values[j]);
                    }
                }
                out.writeNext(temp);
            }
            out.flush();
            out.close();
        } catch (FileNotFoundException fe) {
            MessageDialogWithToggle.openError(null, DefaultMessagesImpl.getString("ExportFactory.errorOne"), // $NON-NLS-1$ //$NON-NLS-2$
            DefaultMessagesImpl.getString("ExportFactory.notFoundFile"));
        } catch (Exception e) {
            log.error(e.getMessage());
        }
    }
}
Also used : Pattern(org.talend.dataquality.domain.pattern.Pattern) FileNotFoundException(java.io.FileNotFoundException) CSVWriter(com.talend.csv.CSVWriter) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 40 with Pattern

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

the class PatternDefinitionHandler method getPatternById.

public Pattern getPatternById(String definitionId) {
    for (Pattern patDef : this.getPatternDefinitions()) {
        CwmResource resource = (CwmResource) patDef.eResource();
        EObject object = resource.getEObject(definitionId);
        if (object != null && PatternPackage.eINSTANCE.getPattern().equals(object.eClass())) {
            return (Pattern) object;
        }
    }
    return null;
}
Also used : CwmResource(org.talend.model.emf.CwmResource) Pattern(org.talend.dataquality.domain.pattern.Pattern) EObject(org.eclipse.emf.ecore.EObject)

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