Search in sources :

Example 66 with Expression

use of orgomg.cwm.objectmodel.core.Expression in project tdq-studio-se by Talend.

the class ExportFactory method getRelatedValueFromPattern.

private static Map<PatternToExcelEnum, String> getRelatedValueFromPattern(Pattern pattern, IFolder folder) {
    Map<PatternToExcelEnum, String> patternMap = new HashMap<PatternToExcelEnum, String>();
    if (folder != null) {
        IFile file = ResourceFileMap.findCorrespondingFile(pattern);
        // MOD sizhaoliu 2012-5-28 TDQ-5481
        URI parentURI = ResourceManager.getPatternFolder().getLocationURI();
        String relativePath = parentURI.relativize(file.getParent().getLocationURI()).toString();
        // remove Regex or SQL prefix
        relativePath = relativePath.substring(relativePath.indexOf('/') + 1);
        // MOD qiongli 2012-12-18 TDQ-5899, Replace relative path Regex/SQL with empty string.
        if (EResourceConstant.PATTERN_REGEX.getName().equals(relativePath) || EResourceConstant.PATTERN_SQL.getName().equals(relativePath)) {
            relativePath = PluginConstant.EMPTY_STRING;
        }
        // get the basic information
        patternMap.put(PatternToExcelEnum.Label, pattern.getName());
        patternMap.put(PatternToExcelEnum.Purpose, MetadataHelper.getPurpose(pattern));
        patternMap.put(PatternToExcelEnum.Description, MetadataHelper.getDescription(pattern));
        patternMap.put(PatternToExcelEnum.Author, MetadataHelper.getAuthor(pattern));
        patternMap.put(PatternToExcelEnum.RelativePath, relativePath);
        for (PatternLanguageType languagetype : PatternLanguageType.values()) {
            for (PatternComponent component : pattern.getComponents()) {
                Expression expression = ((RegularExpression) component).getExpression();
                if (expression != null && expression.getLanguage().equalsIgnoreCase(languagetype.getLiteral())) {
                    patternMap.put(languagetype.getExcelEnum(), expression.getBody());
                }
            }
            if (!patternMap.containsKey(languagetype.getExcelEnum())) {
                // $NON-NLS-1$
                patternMap.put(languagetype.getExcelEnum(), "");
            }
        }
    }
    return patternMap;
}
Also used : RegularExpression(org.talend.dataquality.domain.pattern.RegularExpression) IFile(org.eclipse.core.resources.IFile) HashMap(java.util.HashMap) TdExpression(org.talend.cwm.relational.TdExpression) RegularExpression(org.talend.dataquality.domain.pattern.RegularExpression) Expression(orgomg.cwm.objectmodel.core.Expression) PatternComponent(org.talend.dataquality.domain.pattern.PatternComponent) URI(java.net.URI)

Example 67 with Expression

use of orgomg.cwm.objectmodel.core.Expression in project tdq-studio-se by Talend.

the class PatternLabelProvider method createIndicatorUnit.

/**
 * DOC xqliu Comment method "createIndicatorUnit".
 *
 * @param pfile
 * @param modelElementIndicator
 * @param analysis
 * @param indicatorDefinition
 * @return
 */
public static TypedReturnCode<IndicatorUnit> createIndicatorUnit(Pattern pattern, ModelElementIndicator modelElementIndicator, Analysis analysis, IndicatorDefinition indicatorDefinition) {
    TypedReturnCode<IndicatorUnit> result = new TypedReturnCode<IndicatorUnit>();
    for (Indicator indicator : modelElementIndicator.getIndicators()) {
        // MOD xwang 2011-08-01 bug TDQ-2730
        if (UDIHelper.getMatchingIndicatorName(indicatorDefinition, pattern).equals(indicator.getName()) && indicator instanceof PatternMatchingIndicator) {
            result.setOk(false);
            // $NON-NLS-1$
            result.setMessage(DefaultMessagesImpl.getString("PatternUtilities.Selected"));
            return result;
        }
    // ~
    }
    // MOD scorreia 2009-01-06: when expression type is not set (version
    // TOP-1.1.x), then it's supposed to be a
    // regexp pattern. This could be false because expression type was not
    // set into SQL pattern neither in TOP-1.1.
    // This means that there could exist the need for a migration task to
    // set the expression type depending on the
    // folder where the pattern is stored. The method
    // DomainHelper.getExpressionType(pattern) tries to find the type
    // of pattern.
    Indicator patternMatchingIndicator = null;
    String expressionType = DomainHelper.getExpressionType(pattern);
    boolean isSQLPattern = (ExpressionType.SQL_LIKE.getLiteral().equals(expressionType));
    if (indicatorDefinition != null) {
        patternMatchingIndicator = UDIFactory.createUserDefIndicator(indicatorDefinition, pattern);
    } else {
        patternMatchingIndicator = isSQLPattern ? PatternIndicatorFactory.createSqlPatternMatchingIndicator(pattern) : PatternIndicatorFactory.createRegexpMatchingIndicator(pattern);
    }
    IEditorPart theEdit = CorePlugin.getDefault().getCurrentActiveEditor();
    if (theEdit != null && theEdit instanceof AnalysisEditor && analysis.getContext().getConnection() == null) {
        theEdit.doSave(null);
    }
    ExecutionLanguage executionLanguage = analysis.getParameters().getExecutionLanguage();
    DbmsLanguage dbmsLanguage = DbmsLanguageFactory.createDbmsLanguage(analysis);
    if (dbmsLanguage.isSql()) {
        // $NON-NLS-1$
        MessageUI.openWarning(DefaultMessagesImpl.getString("PatternUtilities.ConnectionError"));
        result.setOk(false);
        return result;
    }
    boolean isJavaEngin = ExecutionLanguage.JAVA.equals(executionLanguage);
    Expression returnExpression = dbmsLanguage.getRegexp(pattern);
    // MOD gdbu 2011-8-26 bug : TDQ-2169
    if ((ExpressionType.REGEXP.getLiteral().equals(expressionType) || ExpressionType.SQL_LIKE.getLiteral().equals(expressionType)) && returnExpression == null) {
        // ~TDQ-2169
        String executeType = isJavaEngin ? executionLanguage.getName() : dbmsLanguage.getDbmsName();
        boolean openPattern = MessageDialog.openQuestion(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), DefaultMessagesImpl.getString("PatternUtilities.Warning"), // $NON-NLS-1$ //$NON-NLS-2$
        DefaultMessagesImpl.getString("PatternUtilities.NoExpression", executeType, pattern.getName()));
        if (openPattern) {
            RepositoryNode node = RepositoryNodeHelper.recursiveFind(pattern);
            if (RepositoryNodeHelper.canOpenEditor(node)) {
                new OpenItemEditorAction(new IRepositoryNode[] { node }).run();
            }
        }
        result.setOk(false);
        return result;
    }
    // a regular expression for the analyzed
    // database, but we probably test also whether the analyzed database
    // support the regular expressions (=> check
    // DB type, DB number version, existence of UDF)
    DataManager dm = analysis.getContext().getConnection();
    if (dm != null) {
        TypedReturnCode<java.sql.Connection> trc = JavaSqlFactory.createConnection((Connection) dm);
        // MOD qiongli 2011-1-10 feature 16796
        boolean isDelimitedFileConnection = ConnectionUtils.isDelimitedFileConnection((DataProvider) dm);
        if (trc != null) {
            // SoftwareSystem softwareSystem = DatabaseContentRetriever.getSoftwareSystem(conn);
            // MOD sizhaoliu TDQ-6316
            dbmsLanguage = DbmsLanguageFactory.createDbmsLanguage(dm);
        }
        // MOD xqliu 2010-08-12 bug 14601
        if (!(isSQLPattern || DefinitionHandler.getInstance().canRunRegularExpressionMatchingIndicator(dbmsLanguage, isJavaEngin, pattern) || isDelimitedFileConnection)) {
            // MessageDialogWithToggle.openInformation(null,
            // DefaultMessagesImpl.getString("PatternUtilities.Pattern"), DefaultMessagesImpl //$NON-NLS-1$
            // .getString("PatternUtilities.couldnotSetIndicator")); //$NON-NLS-1$
            result.setOk(false);
            // $NON-NLS-1$
            result.setMessage(DefaultMessagesImpl.getString("PatternUtilities.couldnotSetIndicator"));
            return result;
        }
    // ~ 14601
    }
    // when the indicator is created.
    if (indicatorDefinition == null) {
        if (!DefinitionHandler.getInstance().setDefaultIndicatorDefinition(patternMatchingIndicator)) {
            // $NON-NLS-1$
            log.error(DefaultMessagesImpl.getString("PatternUtilities.SetFailed", patternMatchingIndicator.getName()));
        }
    } else {
        patternMatchingIndicator.setIndicatorDefinition(indicatorDefinition);
    }
    IndicatorEnum type = IndicatorEnum.findIndicatorEnum(patternMatchingIndicator.eClass());
    IndicatorUnit addIndicatorUnit = modelElementIndicator.addSpecialIndicator(type, patternMatchingIndicator);
    DependenciesHandler.getInstance().setUsageDependencyOn(analysis, pattern);
    result.setOk(true);
    // $NON-NLS-1$
    result.setMessage(DefaultMessagesImpl.getString("PatternUtilities.OK"));
    result.setObject(addIndicatorUnit);
    return result;
}
Also used : IRepositoryNode(org.talend.repository.model.IRepositoryNode) IndicatorEnum(org.talend.dq.nodes.indicator.type.IndicatorEnum) IndicatorUnit(org.talend.dataprofiler.core.ui.editor.preview.IndicatorUnit) Connection(org.talend.core.model.metadata.builder.connection.Connection) ExecutionLanguage(org.talend.dataquality.analysis.ExecutionLanguage) DataManager(orgomg.cwm.foundation.softwaredeployment.DataManager) IEditorPart(org.eclipse.ui.IEditorPart) RepositoryNode(org.talend.repository.model.RepositoryNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode) OpenItemEditorAction(org.talend.dataprofiler.core.ui.action.actions.OpenItemEditorAction) 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) DbmsLanguage(org.talend.dq.dbms.DbmsLanguage) PatternMatchingIndicator(org.talend.dataquality.indicators.PatternMatchingIndicator) Expression(orgomg.cwm.objectmodel.core.Expression) TypedReturnCode(org.talend.utils.sugars.TypedReturnCode) AnalysisEditor(org.talend.dataprofiler.core.ui.editor.analysis.AnalysisEditor)

Example 68 with Expression

use of orgomg.cwm.objectmodel.core.Expression in project tdq-studio-se by Talend.

the class AnalysisHelper method setStringDataFilter.

/**
 * DOC xqliu Comment method "setStringDataFilter".
 *
 * @param analysis
 * @param datafilterString
 * @param index 0 for DataFilterA, 1 for DataFilterB
 * @return
 */
public static boolean setStringDataFilter(Analysis analysis, String datafilterString, int index) {
    if (index == 1) {
        EList<Domain> dataFilters = analysis.getParameters().getDataFilter();
        int size = dataFilters.size();
        if (size == 0) {
            // $NON-NLS-1$
            dataFilters.add(createDomain(analysis, ""));
            // $NON-NLS-1$
            return dataFilters.add(createDomain(analysis, datafilterString, "1"));
        } else if (size == 1) {
            // $NON-NLS-1$
            return dataFilters.add(createDomain(analysis, datafilterString, "1"));
        } else if (size == 2) {
            Domain domain = dataFilters.get(1);
            EList<RangeRestriction> ranges = domain.getRanges();
            RangeRestriction rangeRestriction = (ranges.isEmpty()) ? DomainHelper.addRangeRestriction(domain) : ranges.get(0);
            BooleanExpressionNode expressions = rangeRestriction.getExpressions();
            if (expressions == null) {
                expressions = BooleanExpressionHelper.createBooleanExpressionNode(datafilterString);
                rangeRestriction.setExpressions(expressions);
            } else {
                Expression expression = expressions.getExpression();
                if (expression == null) {
                    expression = BooleanExpressionHelper.createTdExpression(BooleanExpressionHelper.DEFAULT_LANGUAGE, datafilterString);
                    expressions.setExpression(expression);
                } else {
                    expression.setBody(datafilterString);
                }
            }
            return false;
        } else {
            return false;
        }
    } else {
        return setStringDataFilter(analysis, datafilterString);
    }
}
Also used : Expression(orgomg.cwm.objectmodel.core.Expression) BooleanExpressionNode(org.talend.dataquality.expressions.BooleanExpressionNode) RangeRestriction(org.talend.dataquality.domain.RangeRestriction) Domain(org.talend.dataquality.domain.Domain)

Example 69 with Expression

use of orgomg.cwm.objectmodel.core.Expression in project tdq-studio-se by Talend.

the class AnalysisHelper method getStringDataFilter.

/**
 * DOC xqliu Comment method "getStringDataFilter".
 *
 * @param analysis
 * @param index 0 for DataFilterA, 1 for DataFilterB
 * @return
 */
public static String getStringDataFilter(Analysis analysis, int index) {
    AnalysisParameters parameters = analysis.getParameters();
    if (parameters == null) {
        return null;
    }
    EList<Domain> dataFilters = parameters.getDataFilter();
    // remove existing filters
    if (dataFilters == null || dataFilters.isEmpty()) {
        return null;
    }
    int i = 0;
    for (Domain domain : dataFilters) {
        if (domain == null) {
            continue;
        }
        EList<RangeRestriction> ranges = domain.getRanges();
        for (RangeRestriction rangeRestriction : ranges) {
            BooleanExpressionNode expressions = rangeRestriction.getExpressions();
            if (expressions == null) {
                continue;
            }
            Expression expression = expressions.getExpression();
            if (expression == null) {
                continue;
            }
            if (i == index) {
                // MOD klliu 2011-07-14 bug 23150 solve an NPE
                String body = expression.getBody();
                if (body == null) {
                    continue;
                }
                // ~
                return body.trim();
            } else if (i > index) {
                return null;
            }
        }
        i++;
    }
    return null;
}
Also used : Expression(orgomg.cwm.objectmodel.core.Expression) AnalysisParameters(org.talend.dataquality.analysis.AnalysisParameters) BooleanExpressionNode(org.talend.dataquality.expressions.BooleanExpressionNode) RangeRestriction(org.talend.dataquality.domain.RangeRestriction) Domain(org.talend.dataquality.domain.Domain)

Example 70 with Expression

use of orgomg.cwm.objectmodel.core.Expression in project tdq-studio-se by Talend.

the class AnalysisHelper method setStringDataFilter.

public static boolean setStringDataFilter(Analysis analysis, String datafilterString) {
    EList<Domain> dataFilters = analysis.getParameters().getDataFilter();
    // update existing filters
    if (!dataFilters.isEmpty()) {
        Domain domain = dataFilters.get(0);
        EList<RangeRestriction> ranges = domain.getRanges();
        RangeRestriction rangeRestriction = (ranges.isEmpty()) ? DomainHelper.addRangeRestriction(domain) : ranges.get(0);
        BooleanExpressionNode expressions = rangeRestriction.getExpressions();
        if (expressions == null) {
            expressions = BooleanExpressionHelper.createBooleanExpressionNode(datafilterString);
            rangeRestriction.setExpressions(expressions);
        } else {
            Expression expression = expressions.getExpression();
            if (expression == null) {
                expression = BooleanExpressionHelper.createTdExpression(BooleanExpressionHelper.DEFAULT_LANGUAGE, datafilterString);
                expressions.setExpression(expression);
            } else {
                expression.setBody(datafilterString);
            }
        }
        return false;
    }
    // else
    return dataFilters.add(createDomain(analysis, datafilterString));
}
Also used : Expression(orgomg.cwm.objectmodel.core.Expression) BooleanExpressionNode(org.talend.dataquality.expressions.BooleanExpressionNode) RangeRestriction(org.talend.dataquality.domain.RangeRestriction) Domain(org.talend.dataquality.domain.Domain)

Aggregations

Expression (orgomg.cwm.objectmodel.core.Expression)71 TdExpression (org.talend.cwm.relational.TdExpression)42 RegularExpression (org.talend.dataquality.domain.pattern.RegularExpression)37 Test (org.junit.Test)25 Domain (org.talend.dataquality.domain.Domain)14 ArrayList (java.util.ArrayList)13 TdColumn (org.talend.cwm.relational.TdColumn)11 Pattern (org.talend.dataquality.domain.pattern.Pattern)10 Catalog (orgomg.cwm.resource.relational.Catalog)10 Indicator (org.talend.dataquality.indicators.Indicator)9 IndicatorParameters (org.talend.dataquality.indicators.IndicatorParameters)8 Analysis (org.talend.dataquality.analysis.Analysis)7 PatternMatchingIndicator (org.talend.dataquality.indicators.PatternMatchingIndicator)7 UDIndicatorDefinition (org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition)7 DbmsLanguage (org.talend.dq.dbms.DbmsLanguage)7 Connection (org.talend.core.model.metadata.builder.connection.Connection)6 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)6 AnalysisContext (org.talend.dataquality.analysis.AnalysisContext)6 IndicatorDefinition (org.talend.dataquality.indicators.definition.IndicatorDefinition)6 ChartDataEntity (org.talend.dq.indicators.preview.table.ChartDataEntity)6