Search in sources :

Example 66 with Pattern

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

the class PatternLabelProvider method getPatternRepNodesByIndicator.

/**
 * get the repository nodes corresponding to the indicator.
 *
 * @param meIndicator
 * @return
 */
public static Object[] getPatternRepNodesByIndicator(ModelElementIndicator meIndicator) {
    List<IRepositoryNode> patternRepNodes = RepositoryNodeHelper.getPatternsRepositoryNodes(false);
    ArrayList<Object> ret = new ArrayList<Object>();
    for (Indicator indicator : meIndicator.getPatternIndicators()) {
        Pattern patternInAnalysis = IndicatorHelper.getPattern(indicator);
        for (IRepositoryNode patternRepNode : patternRepNodes) {
            Pattern pattern = ((PatternRepNode) patternRepNode).getPattern();
            if (StringUtils.equals(ResourceHelper.getUUID(patternInAnalysis), ResourceHelper.getUUID(pattern))) {
                ret.add(patternRepNode);
            }
        }
    }
    return ret.toArray();
}
Also used : Pattern(org.talend.dataquality.domain.pattern.Pattern) IRepositoryNode(org.talend.repository.model.IRepositoryNode) ArrayList(java.util.ArrayList) ColumnIndicator(org.talend.dataprofiler.core.model.ColumnIndicator) ModelElementIndicator(org.talend.dataprofiler.core.model.ModelElementIndicator) PatternMatchingIndicator(org.talend.dataquality.indicators.PatternMatchingIndicator) Indicator(org.talend.dataquality.indicators.Indicator) PatternRepNode(org.talend.dq.nodes.PatternRepNode)

Example 67 with Pattern

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

the class PatternLabelProvider method createPatternCheckedTreeSelectionDialog.

/**
 * create CheckedTreeSelectionDialog for patterns.
 *
 * @param node Pattern root RepositoryNode.
 * @return
 */
public static CheckedTreeSelectionDialog createPatternCheckedTreeSelectionDialog(IRepositoryNode node) {
    CheckedTreeSelectionDialog dialog = new CheckedTreeSelectionDialog(null, new DQRepositoryViewLabelProvider(), new ResourceViewContentProvider());
    dialog.setInput(node);
    dialog.setValidator(new ISelectionStatusValidator() {

        public IStatus validate(Object[] selection) {
            for (Object patte : selection) {
                if (patte instanceof PatternRepNode) {
                    PatternRepNode patternNode = (PatternRepNode) patte;
                    Pattern findPattern = patternNode.getPattern();
                    boolean validStatus = TaggedValueHelper.getValidStatus(findPattern);
                    if (!validStatus) {
                        return new Status(IStatus.ERROR, CorePlugin.PLUGIN_ID, DefaultMessagesImpl.getString(// $NON-NLS-1$
                        "AnalysisColumnTreeViewer.chooseValidPatterns"));
                    }
                }
            }
            return new // $NON-NLS-1$
            Status(// $NON-NLS-1$
            IStatus.OK, // $NON-NLS-1$
            PlatformUI.PLUGIN_ID, // $NON-NLS-1$
            IStatus.OK, // $NON-NLS-1$
            "", null);
        }
    });
    dialog.setContainerMode(true);
    // $NON-NLS-1$
    dialog.setTitle(DefaultMessagesImpl.getString("AnalysisColumnTreeViewer.patternSelector"));
    // $NON-NLS-1$
    dialog.setMessage(DefaultMessagesImpl.getString("AnalysisColumnTreeViewer.patterns"));
    dialog.setSize(80, 30);
    return dialog;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) Pattern(org.talend.dataquality.domain.pattern.Pattern) IStatus(org.eclipse.core.runtime.IStatus) CheckedTreeSelectionDialog(org.eclipse.ui.dialogs.CheckedTreeSelectionDialog) ResourceViewContentProvider(org.talend.dataprofiler.core.ui.views.provider.ResourceViewContentProvider) ISelectionStatusValidator(org.eclipse.ui.dialogs.ISelectionStatusValidator) DQRepositoryViewLabelProvider(org.talend.dataprofiler.core.ui.views.provider.DQRepositoryViewLabelProvider) PatternRepNode(org.talend.dq.nodes.PatternRepNode)

Example 68 with Pattern

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

the class PatternLabelProvider method getText.

@Override
public String getText(Object element) {
    if (element instanceof IFile) {
        IFile file = (IFile) element;
        Pattern pattern = PatternResourceFileHelper.getInstance().findPattern(file);
        if (pattern != null) {
            return pattern.getName();
        }
    }
    if (element instanceof IFolder) {
        return ((IFolder) element).getName();
    }
    // $NON-NLS-1$
    return "";
}
Also used : Pattern(org.talend.dataquality.domain.pattern.Pattern) IFile(org.eclipse.core.resources.IFile) IFolder(org.eclipse.core.resources.IFolder)

Example 69 with Pattern

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

Example 70 with Pattern

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

the class UpdateSomePatternToMatchMysql method doExecute.

@Override
protected boolean doExecute() throws Exception {
    if (updateFile == null) {
        updateFile = getWorkspacePath().append(UPDATE_FILE_NAME).toFile();
    }
    if (!updateFile.exists()) {
        // if International_phone_number.pattern don't exsit.
        return true;
    }
    URI uri = URI.createFileURI(updateFile.getAbsolutePath());
    Resource patternResource = EMFSharedResources.getInstance().reloadResource(uri);
    if (patternResource != null) {
        Pattern thePattern = retirePattern(patternResource);
        for (PatternComponent currentExpression : thePattern.getComponents()) {
            if (currentExpression instanceof RegularExpression) {
                if (PatternLanguageType.MYSQL.getLiteral().equals(((RegularExpression) currentExpression).getExpression().getLanguage())) {
                    // if the case of Mysql has been added.
                    return true;
                }
            }
        }
        String language = PatternLanguageType.MYSQL.getLiteral();
        RegularExpression newRegularExpress = BooleanExpressionHelper.createRegularExpression(language, EXPRESSIONBODY);
        String expressionType = DomainHelper.getExpressionType(thePattern);
        newRegularExpress.setExpressionType(expressionType);
        List<PatternComponent> componentsList = new ArrayList<PatternComponent>();
        componentsList.add(newRegularExpress);
        componentsList.addAll(thePattern.getComponents());
        thePattern.getComponents().clear();
        thePattern.getComponents().addAll(componentsList);
        ReturnCode rc = PatternResourceFileHelper.getInstance().save(thePattern);
        uri = URI.createFileURI(updateFile.getAbsolutePath());
        EMFSharedResources.getInstance().reloadResource(uri);
        return rc.isOk();
    } else {
        // $NON-NLS-1$
        log.error(DefaultMessagesImpl.getString("UpdateSomePatternToMatchMysql_logErr", patternResource));
        return false;
    }
}
Also used : Pattern(org.talend.dataquality.domain.pattern.Pattern) RegularExpression(org.talend.dataquality.domain.pattern.RegularExpression) ReturnCode(org.talend.utils.sugars.ReturnCode) Resource(org.eclipse.emf.ecore.resource.Resource) ArrayList(java.util.ArrayList) PatternComponent(org.talend.dataquality.domain.pattern.PatternComponent) URI(org.eclipse.emf.common.util.URI)

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