Search in sources :

Example 6 with RegexpMatchingIndicator

use of org.talend.dataquality.indicators.RegexpMatchingIndicator in project tdq-studio-se by Talend.

the class FileSystemImportWriter method updatePatternInAnaParams.

/**
 * if there is a same name pattern in current workspace,update the pattern in imported analysis IndicatorParameters.
 *
 * @param systemSupplyModelElement
 * @param analysis
 */
private void updatePatternInAnaParams(ModelElement systemSupplyModelElement, Analysis analysis) {
    if (analysis.getResults() != null) {
        EList<Indicator> indicators = analysis.getResults().getIndicators();
        IndicatorParameters parameters = null;
        for (Indicator indicator : indicators) {
            // AllMatchIndicator is in column set analysis.
            if (indicator instanceof AllMatchIndicator) {
                EList<RegexpMatchingIndicator> list = ((AllMatchIndicator) indicator).getCompositeRegexMatchingIndicators();
                for (RegexpMatchingIndicator regMatchIndicator : list) {
                    parameters = regMatchIndicator.getParameters();
                    removOldAddSysPatternInAnaParams(parameters, (Pattern) systemSupplyModelElement, analysis);
                }
            } else if (indicator instanceof PatternMatchingIndicator) {
                parameters = ((PatternMatchingIndicator) indicator).getParameters();
                removOldAddSysPatternInAnaParams(parameters, (Pattern) systemSupplyModelElement, analysis);
            }
        }
    }
}
Also used : Pattern(org.talend.dataquality.domain.pattern.Pattern) PatternMatchingIndicator(org.talend.dataquality.indicators.PatternMatchingIndicator) AllMatchIndicator(org.talend.dataquality.indicators.columnset.AllMatchIndicator) IndicatorParameters(org.talend.dataquality.indicators.IndicatorParameters) RegexpMatchingIndicator(org.talend.dataquality.indicators.RegexpMatchingIndicator) Indicator(org.talend.dataquality.indicators.Indicator) RegexpMatchingIndicator(org.talend.dataquality.indicators.RegexpMatchingIndicator) AllMatchIndicator(org.talend.dataquality.indicators.columnset.AllMatchIndicator) PatternMatchingIndicator(org.talend.dataquality.indicators.PatternMatchingIndicator)

Example 7 with RegexpMatchingIndicator

use of org.talend.dataquality.indicators.RegexpMatchingIndicator in project tdq-studio-se by Talend.

the class PatternIndicatorFactory method createRegexpMatchingIndicator.

/**
 * Method "createRegexpMatchingIndicator".
 *
 * @param pattern the pattern from which the RegexpMatchingIndicator is created
 * @return the new RegexpMatchingIndicator with the same name as the pattern
 */
public static RegexpMatchingIndicator createRegexpMatchingIndicator(Pattern pattern) {
    RegexpMatchingIndicator patternMatchingIndicator = IndicatorsFactory.eINSTANCE.createRegexpMatchingIndicator();
    IndicatorParameters indicParams = IndicatorsFactory.eINSTANCE.createIndicatorParameters();
    Domain validData = DomainFactory.eINSTANCE.createDomain();
    validData.getPatterns().add(pattern);
    indicParams.setDataValidDomain(validData);
    patternMatchingIndicator.setParameters(indicParams);
    patternMatchingIndicator.setName(pattern.getName());
    return patternMatchingIndicator;
}
Also used : IndicatorParameters(org.talend.dataquality.indicators.IndicatorParameters) RegexpMatchingIndicator(org.talend.dataquality.indicators.RegexpMatchingIndicator) Domain(org.talend.dataquality.domain.Domain)

Example 8 with RegexpMatchingIndicator

use of org.talend.dataquality.indicators.RegexpMatchingIndicator in project tdq-studio-se by Talend.

the class AllMatchIndicatorImpl method instantiatePatterns.

@SuppressWarnings("unchecked")
private boolean instantiatePatterns() {
    boolean noErrors = true;
    EList<ModelElement> columns = this.getAnalyzedColumns();
    this.patterns = new List[columns.size()];
    EList<RegexpMatchingIndicator> indicators = this.getCompositeRegexMatchingIndicators();
    for (int i = 0; i < columns.size(); i++) {
        for (RegexpMatchingIndicator rmi : indicators) {
            if (rmi.getAnalyzedElement() == columns.get(i)) {
                if (null == this.patterns[i]) {
                    this.patterns[i] = new ArrayList<java.util.regex.Pattern>();
                }
                String regex = rmi.getRegex();
                // MOD TDQ-8388 20150530 yyin, should check all patterns, and log the errors
                if (null == regex) {
                    continue;
                }
                try {
                    this.patterns[i].add(java.util.regex.Pattern.compile(regex));
                } catch (java.util.regex.PatternSyntaxException e) {
                    log.error(Messages.getString("Using_regular_expression", rmi.getName(), regex), e);
                    noErrors = false;
                    continue;
                }
            }
        }
    }
    return noErrors;
}
Also used : ModelElement(orgomg.cwm.objectmodel.core.ModelElement) RegexpMatchingIndicator(org.talend.dataquality.indicators.RegexpMatchingIndicator)

Example 9 with RegexpMatchingIndicator

use of org.talend.dataquality.indicators.RegexpMatchingIndicator in project tdq-studio-se by Talend.

the class RegexpMatchingIndicatorImplTest method testGetRegexsuccess.

/**
 * Test method for {@link org.talend.dataquality.indicators.impl.RegexpMatchingIndicatorImpl#getJavaRegex()}.
 */
@Test
public void testGetRegexsuccess() {
    // RegexpMatchingIndicator
    RegexpMatchingIndicator createRegexpMatchingIndicator = IndicatorsFactory.eINSTANCE.createRegexpMatchingIndicator();
    // ~RegexpMatchingIndicator
    // IndicatorParameters
    IndicatorParameters createIndicatorParameters = IndicatorsFactory.eINSTANCE.createIndicatorParameters();
    // ~IndicatorParameters
    // Domain
    Domain createDomain = DomainFactory.eINSTANCE.createDomain();
    EList<Pattern> patterns = createDomain.getPatterns();
    // ~Domain
    // Pattern
    Pattern createJavaPattern = PatternFactory.eINSTANCE.createPattern();
    Pattern createSQLPattern = PatternFactory.eINSTANCE.createPattern();
    Pattern createMSSQLPattern = PatternFactory.eINSTANCE.createPattern();
    patterns.add(createJavaPattern);
    patterns.add(createSQLPattern);
    patterns.add(createMSSQLPattern);
    // ~Pattern
    // init java Pattern data
    RegularExpression createJavaRegularExpression = PatternFactory.eINSTANCE.createRegularExpression();
    TdExpression createJavaTdExpression = RelationalFactory.eINSTANCE.createTdExpression();
    createJavaTdExpression.setBody(JavaRegex);
    createJavaTdExpression.setLanguage("Java");
    createJavaRegularExpression.setExpression(createJavaTdExpression);
    createJavaRegularExpression.setExpressionType(ExpressionType.REGEXP.getLiteral());
    EList<PatternComponent> components = createJavaPattern.getComponents();
    components.add(createJavaRegularExpression);
    // ~init java Pattern data
    createIndicatorParameters.setDataValidDomain(createDomain);
    createRegexpMatchingIndicator.setParameters(createIndicatorParameters);
    // call getRegex()
    String regexResult = createRegexpMatchingIndicator.getRegex();
    String JavaRegex2 = JavaRegex.substring(1, JavaRegex.length() - 1);
    // ~call getRegex()
    Assert.assertTrue(JavaRegex2.equalsIgnoreCase(regexResult));
}
Also used : Pattern(org.talend.dataquality.domain.pattern.Pattern) RegularExpression(org.talend.dataquality.domain.pattern.RegularExpression) TdExpression(org.talend.cwm.relational.TdExpression) IndicatorParameters(org.talend.dataquality.indicators.IndicatorParameters) PatternComponent(org.talend.dataquality.domain.pattern.PatternComponent) RegexpMatchingIndicator(org.talend.dataquality.indicators.RegexpMatchingIndicator) Domain(org.talend.dataquality.domain.Domain) Test(org.junit.Test)

Example 10 with RegexpMatchingIndicator

use of org.talend.dataquality.indicators.RegexpMatchingIndicator in project tdq-studio-se by Talend.

the class ColumnSetAnalysisDetailsPage method saveAnalysis.

/**
 * @param outputFolder
 * @throws DataprofilerCoreException
 */
@Override
public void saveAnalysis() throws DataprofilerCoreException {
    columnSetAnalysisHandler.changeDefaultRowLoaded(rowLoadedText.getText());
    columnSetAnalysisHandler.changeSampleDataShowWay(sampleDataShowWayCombo.getText());
    // columnSetAnalysisHandler.setName(columnSetAnalysisHandler.getName().replace(" ", ""));
    for (Domain domain : getCurrentModelElement().getParameters().getDataFilter()) {
        domain.setName(getCurrentModelElement().getName());
    }
    // ~
    columnSetAnalysisHandler.clearAnalysis();
    simpleStatIndicator.getAnalyzedColumns().clear();
    allMatchIndicator.getAnalyzedColumns().clear();
    // set execute engine
    Analysis analysis = columnSetAnalysisHandler.getAnalysis();
    analysis.getParameters().setExecutionLanguage(ExecutionLanguage.get(execLang));
    // set data filter
    columnSetAnalysisHandler.setStringDataFilter(dataFilterComp.getDataFilterString());
    // save analysis
    List<IRepositoryNode> repositoryNodes = treeViewer.getColumnSetMultiValueList();
    Connection tdProvider = null;
    IRepositoryViewObject reposObject = null;
    if (repositoryNodes != null && repositoryNodes.size() != 0) {
        ConnectionItem item = (ConnectionItem) repositoryNodes.get(0).getObject().getProperty().getItem();
        tdProvider = item.getConnection();
        if (tdProvider.eIsProxy()) {
            // Resolve the connection again
            tdProvider = (Connection) EObjectHelper.resolveObject(tdProvider);
        }
        analysis.getContext().setConnection(tdProvider);
        List<ModelElement> columnList = new ArrayList<ModelElement>();
        for (IRepositoryNode rd : repositoryNodes) {
            reposObject = rd.getObject();
            columnList.add(((MetadataColumnRepositoryObject) reposObject).getTdColumn());
        }
        simpleStatIndicator.getAnalyzedColumns().addAll(columnList);
        columnSetAnalysisHandler.addIndicator(columnList, simpleStatIndicator);
        // ~ MOD mzhao feature 13040. 2010-05-21
        allMatchIndicator.getCompositeRegexMatchingIndicators().clear();
        ModelElementIndicator[] modelElementIndicator = treeViewer.getModelElementIndicator();
        if (modelElementIndicator != null) {
            for (ModelElementIndicator modelElementInd : modelElementIndicator) {
                Indicator[] inds = modelElementInd.getPatternIndicators();
                for (Indicator ind : inds) {
                    if (ind instanceof RegexpMatchingIndicator) {
                        // MOD yyi 2011-06-15 22419:column set pattern for MDM
                        IRepositoryViewObject obj = modelElementInd.getModelElementRepositoryNode().getObject();
                        ModelElement analyzedElt = ((MetadataColumnRepositoryObject) obj).getTdColumn();
                        ind.setAnalyzedElement(analyzedElt);
                        allMatchIndicator.getCompositeRegexMatchingIndicators().add((RegexpMatchingIndicator) ind);
                    }
                }
            }
        }
        if (allMatchIndicator.getCompositeRegexMatchingIndicators().size() > 0) {
            allMatchIndicator.getAnalyzedColumns().addAll(columnList);
            columnSetAnalysisHandler.addIndicator(columnList, allMatchIndicator);
        }
    // ~
    } else {
        analysis.getContext().setConnection(null);
    }
    TaggedValueHelper.setTaggedValue(getCurrentModelElement(), TaggedValueHelper.IS_USE_SAMPLE_DATA, isRunWithSampleData.toString());
    // save the number of connections per analysis
    this.saveNumberOfConnectionsPerAnalysis();
    // 2011.1.12 MOD by zhsne to unify anlysis and connection id when saving.
    this.nameText.setText(columnSetAnalysisHandler.getName());
    // TDQ-5581,if has removed emlements(patten),should remove dependency each other before saving.
    // MOD yyi 2012-02-08 TDQ-4621:Explicitly set true for updating dependencies.
    ReturnCode saved = ElementWriterFactory.getInstance().createAnalysisWrite().save(getCurrentRepNode().getObject().getProperty().getItem(), true);
    // MOD yyi 2012-02-03 TDQ-3602:Avoid to rewriting all analyzes after saving, no reason to update all analyzes
    // which is depended in the referred connection.
    // Extract saving log function.
    // @see org.talend.dataprofiler.core.ui.editor.analysis.AbstractAnalysisMetadataPage#logSaved(ReturnCode)
    logSaved(saved);
    treeViewer.setDirty(false);
    dataFilterComp.setDirty(false);
}
Also used : ReturnCode(org.talend.utils.sugars.ReturnCode) IRepositoryNode(org.talend.repository.model.IRepositoryNode) ConnectionItem(org.talend.core.model.properties.ConnectionItem) FileConnection(org.talend.core.model.metadata.builder.connection.FileConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) ArrayList(java.util.ArrayList) RegexpMatchingIndicator(org.talend.dataquality.indicators.RegexpMatchingIndicator) AllMatchIndicator(org.talend.dataquality.indicators.columnset.AllMatchIndicator) ModelElementIndicator(org.talend.dataprofiler.core.model.ModelElementIndicator) Indicator(org.talend.dataquality.indicators.Indicator) CompositeIndicator(org.talend.dataquality.indicators.CompositeIndicator) SimpleStatIndicator(org.talend.dataquality.indicators.columnset.SimpleStatIndicator) ModelElement(orgomg.cwm.objectmodel.core.ModelElement) Analysis(org.talend.dataquality.analysis.Analysis) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) RegexpMatchingIndicator(org.talend.dataquality.indicators.RegexpMatchingIndicator) MetadataColumnRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataColumnRepositoryObject) Domain(org.talend.dataquality.domain.Domain) ModelElementIndicator(org.talend.dataprofiler.core.model.ModelElementIndicator)

Aggregations

RegexpMatchingIndicator (org.talend.dataquality.indicators.RegexpMatchingIndicator)18 IndicatorParameters (org.talend.dataquality.indicators.IndicatorParameters)7 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)6 Pattern (org.talend.dataquality.domain.pattern.Pattern)6 Domain (org.talend.dataquality.domain.Domain)5 Indicator (org.talend.dataquality.indicators.Indicator)5 AllMatchIndicator (org.talend.dataquality.indicators.columnset.AllMatchIndicator)5 ModelElement (orgomg.cwm.objectmodel.core.ModelElement)4 TdExpression (org.talend.cwm.relational.TdExpression)3 PatternComponent (org.talend.dataquality.domain.pattern.PatternComponent)3 RegularExpression (org.talend.dataquality.domain.pattern.RegularExpression)3 PatternMatchingIndicator (org.talend.dataquality.indicators.PatternMatchingIndicator)3 HashMap (java.util.HashMap)2 Matcher (java.util.regex.Matcher)2 Pattern (java.util.regex.Pattern)2 ModelElementIndicator (org.talend.dataprofiler.core.model.ModelElementIndicator)2 Analysis (org.talend.dataquality.analysis.Analysis)2 CompositeIndicator (org.talend.dataquality.indicators.CompositeIndicator)2 SimpleStatIndicator (org.talend.dataquality.indicators.columnset.SimpleStatIndicator)2