Search in sources :

Example 1 with Pattern

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

the class CreatePatternWizard method initCWMResourceBuilder.

public ModelElement initCWMResourceBuilder() {
    patternBuilder = new PatternBuilder();
    boolean patternInitialized = patternBuilder.initializePattern(parameter.getName());
    if (patternInitialized) {
        Pattern pattern = patternBuilder.getPattern();
        String lang = PatternLanguageType.findLanguageByName(parameter.getLanguage());
        String express = parameter.getExpression();
        RegularExpression regularExpr = BooleanExpressionHelper.createRegularExpression(lang, express);
        regularExpr.setExpressionType(type.getLiteral());
        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 2 with Pattern

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

the class CreatePatternWizard method performFinish.

/**
 * mzhao TDQ-4734 refresh the parent node of newly created pattern.
 */
@Override
public boolean performFinish() {
    Boolean ret = super.performFinish();
    if (modelElement instanceof Pattern) {
        RepositoryNode patternNode = RepositoryNodeHelper.recursiveFindPattern((Pattern) modelElement);
        CorePlugin.getDefault().refreshDQView(patternNode.getParent());
    }
    return ret;
}
Also used : Pattern(org.talend.dataquality.domain.pattern.Pattern) IRepositoryNode(org.talend.repository.model.IRepositoryNode) RepositoryNode(org.talend.repository.model.RepositoryNode)

Example 3 with Pattern

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

the class ExportPatternsWizard method performFinish.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.jface.wizard.Wizard#performFinish()
     */
@Override
public boolean performFinish() {
    String targetFile = page.getTargetFile();
    Object[] elements = page.getSelectedPatternsTree().getCheckedElements();
    List<Pattern> seletedPatterns = new ArrayList<Pattern>();
    for (Object element : elements) {
        // MOD klliu 2011-03-08 bug 18657
        if (element instanceof PatternRepNode) {
            PatternRepNode patternNode = (PatternRepNode) element;
            Pattern pattern = patternNode.getPattern();
            seletedPatterns.add(pattern);
        }
    }
    if ("".equals(targetFile)) {
        // $NON-NLS-1$
        MessageDialog.openError(getShell(), DefaultMessagesImpl.getString("ExportPatternsWizard.Error"), // $NON-NLS-1$ //$NON-NLS-2$
        DefaultMessagesImpl.getString("ExportPatternsWizard.SpecifyValidResource"));
        return false;
    } else {
        File resource = new File(targetFile);
        if (isForExchange) {
            ExportFactory.export(resource, folder, seletedPatterns.toArray(new Pattern[seletedPatterns.size()]));
            for (Iterator<Pattern> iterator = seletedPatterns.iterator(); iterator.hasNext(); ) {
                Pattern pattern = iterator.next();
                // $NON-NLS-1$
                File patternFile = new File(resource, ExportFactory.toLocalFileName(pattern.getName() + ".csv"));
                if (patternFile.isFile() && patternFile.exists()) {
                    try {
                        // $NON-NLS-1$
                        FilesUtils.zip(patternFile, patternFile.getPath() + ".zip");
                        patternFile.delete();
                    } catch (Exception e) {
                        log.error(e.getMessage(), e);
                    }
                }
            }
        } else {
            boolean isContinue = true;
            if (resource.exists()) {
                isContinue = MessageDialogWithToggle.openConfirm(null, // $NON-NLS-1$
                DefaultMessagesImpl.getString("ExportPatternsWizard.waring"), // $NON-NLS-1$
                DefaultMessagesImpl.getString("ExportPatternsWizard.fileAlreadyExist"));
            }
            if (!isContinue) {
                return false;
            }
            ExportFactory.export(resource, folder, seletedPatterns.toArray(new Pattern[seletedPatterns.size()]));
        }
        CorePlugin.getDefault().refreshDQView(RepositoryNodeHelper.getLibrariesFolderNode(EResourceConstant.PATTERNS));
        CorePlugin.getDefault().refreshWorkSpace();
        return true;
    }
}
Also used : Pattern(org.talend.dataquality.domain.pattern.Pattern) ArrayList(java.util.ArrayList) File(java.io.File) PatternRepNode(org.talend.dq.nodes.PatternRepNode)

Example 4 with Pattern

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

the class ImportFactory method createAndStorePattern.

private static TypedReturnCode<Object> createAndStorePattern(PatternParameters parameters, IFolder selectionFolder, ExpressionType type) throws TalendInternalPersistenceException {
    Pattern pattern = createPattern(parameters.name, parameters.auther, parameters.description, parameters.purpose, parameters.status);
    for (String key : parameters.regex.keySet()) {
        RegularExpression regularExpr = BooleanExpressionHelper.createRegularExpression(key, parameters.regex.get(key), type);
        pattern.getComponents().add(regularExpr);
    }
    boolean validStatus = PatternUtilities.isPatternValid(pattern);
    TaggedValueHelper.setValidStatus(validStatus, pattern);
    try {
        String relativePath = parameters.relativePath;
        if (EResourceConstant.PATTERN_REGEX.getName().equals(relativePath) || EResourceConstant.PATTERN_SQL.getName().equals(relativePath)) {
            relativePath = PluginConstant.EMPTY_STRING;
        }
        // $NON-NLS-1$
        String[] folderNames = relativePath.split("/");
        for (String folderName : folderNames) {
            IFolder folder = selectionFolder.getFolder(folderName);
            if (!folder.exists()) {
                folder.create(false, true, null);
            }
            selectionFolder = folder;
        }
    } catch (CoreException e) {
        log.error(e, e);
    }
    return ElementWriterFactory.getInstance().createPatternWriter().create(pattern, selectionFolder);
}
Also used : Pattern(org.talend.dataquality.domain.pattern.Pattern) RegularExpression(org.talend.dataquality.domain.pattern.RegularExpression) CoreException(org.eclipse.core.runtime.CoreException) IFolder(org.eclipse.core.resources.IFolder)

Example 5 with Pattern

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

the class ImportFactory method createPattern.

/**
 * DOC qzhang Comment method "createPattern".
 *
 * @param name
 * @param author
 * @param description
 * @param purpose
 * @param status
 * @return
 */
private static Pattern createPattern(String name, String author, String description, String purpose, String status) {
    Pattern pattern = PatternFactory.eINSTANCE.createPattern();
    pattern.setName(name);
    // $NON-NLS-1$
    MetadataHelper.setAuthor(pattern, author == null ? "" : author);
    // $NON-NLS-1$
    MetadataHelper.setDescription(description == null ? "" : description, pattern);
    // $NON-NLS-1$
    MetadataHelper.setPurpose(purpose == null ? "" : purpose, pattern);
    // MOD mzhao feature 7479 2009-10-16
    // $NON-NLS-1$
    MetadataHelper.setDevStatus(pattern, status == null ? "" : status);
    return pattern;
}
Also used : Pattern(org.talend.dataquality.domain.pattern.Pattern)

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