Search in sources :

Example 51 with IndicatorDefinition

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

the class TableAnalysisSqlExecutor method getValidStatement.

/**
 * DOC xqliu Comment method "getValidStatement". 2009-10-29 bug 9702
 *
 * @param dataFilterAsString
 * @param indicator
 * @param valid
 * @return
 */
public String getValidStatement(String dataFilterAsString, Indicator indicator, boolean valid) {
    if (!isAnalyzedElementValid(indicator)) {
        return PluginConstant.EMPTY_STRING;
    }
    IndicatorDefinition indicatorDefinition = indicator.getIndicatorDefinition();
    if (!isIndicatorDefinitionValid(indicatorDefinition, AnalysisExecutorHelper.getIndicatorName(indicator))) {
        return PluginConstant.EMPTY_STRING;
    }
    Expression sqlGenericExpression = dbms().getSqlExpression(indicatorDefinition);
    if (!isExpressionValid(sqlGenericExpression, indicator)) {
        return PluginConstant.EMPTY_STRING;
    }
    // --- get indicator parameters and convert them into sql expression
    List<String> whereExpressionAnalysis = new ArrayList<String>();
    if (StringUtils.isNotBlank(dataFilterAsString)) {
        whereExpressionAnalysis.add(dataFilterAsString);
    }
    List<String> whereExpressionDQRule = new ArrayList<String>();
    String setAliasA = PluginConstant.EMPTY_STRING;
    final EList<JoinElement> joinConditions = indicator.getJoinConditions();
    if (RulesPackage.eINSTANCE.getWhereRule().equals(indicatorDefinition.eClass())) {
        WhereRule wr = (WhereRule) indicatorDefinition;
        whereExpressionDQRule.add(wr.getWhereExpression());
        // MOD scorreia 2009-03-13 copy joins conditions into the indicator
        joinConditions.clear();
        if (!isJoinConditionEmpty(indicator)) {
            for (JoinElement joinelt : wr.getJoins()) {
                JoinElement joinCopy = EcoreUtil.copy(joinelt);
                joinConditions.add(joinCopy);
                setAliasA = PluginConstant.EMPTY_STRING.equals(setAliasA) ? joinCopy.getTableAliasA() : setAliasA;
            }
        }
    }
    NamedColumnSet set = SwitchHelpers.NAMED_COLUMN_SET_SWITCH.doSwitch(indicator.getAnalyzedElement());
    String schemaName = getQuotedSchemaName(set);
    // --- normalize table name
    String catalogName = getQuotedCatalogName(set);
    if (catalogName == null && schemaName != null) {
        // try to get catalog above schema
        final Schema parentSchema = SchemaHelper.getParentSchema(set);
        final Catalog parentCatalog = CatalogHelper.getParentCatalog(parentSchema);
        catalogName = parentCatalog != null ? parentCatalog.getName() : null;
    }
    String setName = dbms().toQualifiedName(catalogName, schemaName, quote(set.getName()));
    // ### evaluate SQL Statement depending on indicators ###
    String completedSqlString = null;
    // --- default case
    // allow join
    String joinclause = (!joinConditions.isEmpty()) ? dbms().createJoinConditionAsString(set, joinConditions, catalogName, schemaName) : PluginConstant.EMPTY_STRING;
    String genericSql = sqlGenericExpression.getBody();
    // $NON-NLS-1$//$NON-NLS-2$
    setAliasA = PluginConstant.EMPTY_STRING.equals(setAliasA) ? "*" : setAliasA + ".*";
    // $NON-NLS-1$
    genericSql = genericSql.replace("COUNT(*)", setAliasA);
    completedSqlString = dbms().fillGenericQueryWithJoin(genericSql, setName, joinclause);
    // ~
    completedSqlString = addWhereToSqlStringStatement(whereExpressionAnalysis, whereExpressionDQRule, completedSqlString, valid);
    return completedSqlString;
}
Also used : JoinElement(org.talend.dataquality.rules.JoinElement) WhereRule(org.talend.dataquality.rules.WhereRule) TdExpression(org.talend.cwm.relational.TdExpression) Expression(orgomg.cwm.objectmodel.core.Expression) Schema(orgomg.cwm.resource.relational.Schema) ArrayList(java.util.ArrayList) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition) NamedColumnSet(orgomg.cwm.resource.relational.NamedColumnSet) Catalog(orgomg.cwm.resource.relational.Catalog)

Example 52 with IndicatorDefinition

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

the class CategoryHandler method getShowIndicatorsDefinitions.

/**
 * DOC bZhou Comment method "getShowIndicatorsDefinitions".
 *
 * @return
 */
public static List<IndicatorDefinition> getShowIndicatorsDefinitions() {
    // if (showIndicatorDefinitions == null) {
    ArrayList<IndicatorDefinition> showIndicatorDefinitions = new ArrayList<IndicatorDefinition>();
    List<IndicatorDefinition> indicatorDefinitions = DefinitionHandler.getInstance().getIndicatorsDefinitions();
    for (IndicatorDefinition indicatorDefinition : indicatorDefinitions) {
        if (!indicatorDefinition.getSqlGenericExpression().isEmpty() && !getShouldNotIncludeIndicatorDefinitionUuidList().contains(ResourceHelper.getUUID(indicatorDefinition))) {
            showIndicatorDefinitions.add(indicatorDefinition);
        }
    }
    // }
    return showIndicatorDefinitions;
}
Also used : ArrayList(java.util.ArrayList) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition)

Example 53 with IndicatorDefinition

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

the class FunctionFrequencyStatExplorer method columnNameConvert.

@SuppressWarnings("deprecation")
private String columnNameConvert() {
    String colName = columnName;
    TdColumn column = (TdColumn) indicator.getAnalyzedElement();
    IndicatorDefinition indicatorDefinition;
    String label = indicator.getIndicatorDefinition().getLabel();
    if (label == null || PluginConstant.EMPTY_STRING.equals(label)) {
        indicatorDefinition = indicator.getIndicatorDefinition();
    } else {
        indicatorDefinition = DefinitionHandler.getInstance().getIndicatorDefinition(label);
    }
    if (indicator.eClass().equals(IndicatorsPackage.eINSTANCE.getPatternFreqIndicator()) || indicator.eClass().equals(IndicatorsPackage.eINSTANCE.getPatternLowFreqIndicator())) {
        // MOD zshen for bug 12675 2010-05-12
        if (Java2SqlType.isNumbericInSQL(column.getSqlDataType().getJavaDataType())) {
            colName = addFunctionTypeConvert(colName);
        }
        // ~12675
        final EList<CharactersMapping> charactersMapping = indicatorDefinition.getCharactersMapping();
        colName = dbmsLanguage.getPatternFinderFunction(colName, charactersMapping);
        if (columnName == null) {
            // no replacement found, try the default one
            colName = dbmsLanguage.getPatternFinderDefaultFunction(colName);
        }
    }
    return colName;
}
Also used : CharactersMapping(org.talend.dataquality.indicators.definition.CharactersMapping) TdColumn(org.talend.cwm.relational.TdColumn) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition)

Example 54 with IndicatorDefinition

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

the class DependenciesHandler method getIndicatorDependency.

/**
 * get Indicator Dependency.
 *
 * @return get the list for analysis which use parameter to be a Indicator
 */
public List<IRepositoryViewObject> getIndicatorDependency(IRepositoryViewObject viewObject) {
    Item item = viewObject.getProperty().getItem();
    List<IRepositoryViewObject> listAnalysisViewObject = new ArrayList<IRepositoryViewObject>();
    if (item instanceof TDQIndicatorDefinitionItemImpl) {
        TDQIndicatorDefinitionItemImpl tdqIndicatorItem = (TDQIndicatorDefinitionItemImpl) item;
        IndicatorDefinition newIndicatorDefinition = tdqIndicatorItem.getIndicatorDefinition();
        List<IRepositoryViewObject> allAnaList = new ArrayList<IRepositoryViewObject>();
        try {
            allAnaList.addAll(ProxyRepositoryFactory.getInstance().getAll(ERepositoryObjectType.TDQ_ANALYSIS_ELEMENT, true));
        } catch (PersistenceException e) {
            log.error(e, e);
        }
        for (IRepositoryViewObject theAna : allAnaList) {
            List<Indicator> indicators = IndicatorHelper.getIndicators(((TDQAnalysisItem) theAna.getProperty().getItem()).getAnalysis().getResults());
            for (Indicator indicator : indicators) {
                IndicatorDefinition oldIndicatorDefinition = indicator.getIndicatorDefinition();
                if (ModelElementHelper.compareUUID(oldIndicatorDefinition, newIndicatorDefinition)) {
                    listAnalysisViewObject.add(theAna);
                    break;
                }
            }
        }
    }
    return listAnalysisViewObject;
}
Also used : TDQAnalysisItem(org.talend.dataquality.properties.TDQAnalysisItem) Item(org.talend.core.model.properties.Item) TDQSourceFileItem(org.talend.dataquality.properties.TDQSourceFileItem) TDQFileItem(org.talend.dataquality.properties.TDQFileItem) TDQIndicatorDefinitionItemImpl(org.talend.dataquality.properties.impl.TDQIndicatorDefinitionItemImpl) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) ArrayList(java.util.ArrayList) PersistenceException(org.talend.commons.exception.PersistenceException) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition) Indicator(org.talend.dataquality.indicators.Indicator) TDQAnalysisItem(org.talend.dataquality.properties.TDQAnalysisItem)

Example 55 with IndicatorDefinition

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

the class ResourceViewLabelProvider method decorateImage.

@Override
protected ImageDescriptor decorateImage(ImageDescriptor input, Object element) {
    ImageDescriptor image = super.decorateImage(input, element);
    if (element instanceof IFile) {
        IFile file = (IFile) element;
        String fileExtension = file.getFileExtension();
        // MOD qiongli 2010-9-7,bug 14698,add 'try...catch'
        try {
            if (FactoriesUtil.isPatternFile(fileExtension)) {
                image = ImageLib.getImageDescriptor(ImageLib.PATTERN_REG);
                Pattern pattern = PatternResourceFileHelper.getInstance().findPattern(file);
                if (pattern != null) {
                    if (!TaggedValueHelper.getValidStatus(pattern)) {
                        image = ImageLib.createInvalidIconDes(ImageLib.PATTERN_REG);
                    }
                }
            } else if (FactoriesUtil.isReportFile(fileExtension)) {
                image = ImageLib.getImageDescriptor(ImageLib.REPORT_OBJECT);
            } else if (FactoriesUtil.isUDIFile(fileExtension)) {
                image = ImageLib.getImageDescriptor(ImageLib.IND_DEFINITION);
                IndicatorDefinition udi = IndicatorResourceFileHelper.getInstance().findIndDefinition(file);
                if (udi != null) {
                    boolean validStatus = TaggedValueHelper.getValidStatus(udi) | UDIHelper.isUDIValid(udi);
                    if (!validStatus) {
                        image = ImageLib.createInvalidIconDes(ImageLib.IND_DEFINITION);
                    }
                }
            } else if (FactoriesUtil.isAnalysisFile(fileExtension)) {
                // ADD qiongli 2010-8-9,feature 14252
                Analysis analysis = AnaResourceFileHelper.getInstance().findAnalysis(file);
                if (analysis != null) {
                    AnalysisHandler analysisHandler = new AnalysisHandler();
                    analysisHandler.setAnalysis(analysis);
                    if (analysisHandler.getResultMetadata().getExecutionNumber() != 0) {
                        if (!analysisHandler.getResultMetadata().isLastRunOk()) {
                            image = ImageLib.createErrorIcon(image);
                        } else if (analysisHandler.getResultMetadata().isOutThreshold()) {
                            image = ImageLib.createInvalidIcon(image);
                        }
                    }
                }
            }
        } catch (Exception exc) {
            log.error(exc, exc);
            image = ImageLib.getImageDescriptor(ImageLib.DELETE_ACTION);
        }
        if (FactoriesUtil.isEmfFile(fileExtension)) {
            Property property = PropertyHelper.getProperty(file);
            if (property != null) {
                Item item = property.getItem();
                Boolean lockByOthers = ProxyRepositoryManager.getInstance().isLockByOthers(item);
                Boolean lockByUserOwn = ProxyRepositoryManager.getInstance().isLockByUserOwn(item);
                if (lockByOthers || lockByUserOwn) {
                    // $NON-NLS-1$
                    log.info(property.getLabel() + " is locked");
                    image = ImageLib.createLockedIcon(image);
                }
            }
        }
    } else if (element instanceof IFolder) {
        IFolder folder = (IFolder) element;
        if (ResourceManager.isMetadataFolder(folder)) {
            image = ImageLib.getImageDescriptor(ImageLib.METADATA);
        } else if (ResourceManager.isLibrariesFolder(folder)) {
            image = ImageLib.getImageDescriptor(ImageLib.LIBRARIES);
        } else if (ResourceManager.isDataProfilingFolder(folder)) {
            image = ImageLib.getImageDescriptor(ImageLib.DATA_PROFILING);
        } else if (ResourceManager.isDBConnectionFolder(folder)) {
            image = ImageLib.getImageDescriptor(ImageLib.CONNECTION);
        } else if (ResourceManager.isExchangeFolder(folder)) {
            image = ImageLib.getImageDescriptor(ImageLib.EXCHANGE);
        } else if (ResourceManager.isFileDelimitedFolder(folder)) {
            image = ImageLib.getImageDescriptor(ImageLib.FILE_DELIMITED);
        }
    }
    return image;
}
Also used : Pattern(org.talend.dataquality.domain.pattern.Pattern) AnalysisHandler(org.talend.dq.analysis.AnalysisHandler) IFile(org.eclipse.core.resources.IFile) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition) CoreException(org.eclipse.core.runtime.CoreException) Item(org.talend.core.model.properties.Item) Analysis(org.talend.dataquality.analysis.Analysis) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) Property(org.talend.core.model.properties.Property) IFolder(org.eclipse.core.resources.IFolder)

Aggregations

IndicatorDefinition (org.talend.dataquality.indicators.definition.IndicatorDefinition)141 UDIndicatorDefinition (org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition)37 Test (org.junit.Test)35 ArrayList (java.util.ArrayList)34 TdExpression (org.talend.cwm.relational.TdExpression)31 File (java.io.File)22 Analysis (org.talend.dataquality.analysis.Analysis)16 IFile (org.eclipse.core.resources.IFile)15 Property (org.talend.core.model.properties.Property)14 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)14 TDQIndicatorDefinitionItem (org.talend.dataquality.properties.TDQIndicatorDefinitionItem)14 PersistenceException (org.talend.commons.exception.PersistenceException)13 Indicator (org.talend.dataquality.indicators.Indicator)12 ModelElement (orgomg.cwm.objectmodel.core.ModelElement)12 Path (org.eclipse.core.runtime.Path)10 IFolder (org.eclipse.core.resources.IFolder)9 BasicEList (org.eclipse.emf.common.util.BasicEList)9 TdColumn (org.talend.cwm.relational.TdColumn)9 UserDefIndicator (org.talend.dataquality.indicators.sql.UserDefIndicator)7 TDQAnalysisItem (org.talend.dataquality.properties.TDQAnalysisItem)7