Search in sources :

Example 6 with UserDefIndicator

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

the class ItemRecord method getSystemIndicaotrOfAnalysis.

/**
 * get Analysis Dependency (for indicator only).
 *
 * @return get the list of indicator which in use by the analysis
 */
private List<File> getSystemIndicaotrOfAnalysis(ModelElement mElement) {
    List<File> listFile = new ArrayList<File>();
    if (mElement instanceof Analysis) {
        Analysis anaElement = (Analysis) mElement;
        List<Indicator> indicators = IndicatorHelper.getIndicators(anaElement.getResults());
        for (Indicator indicator : indicators) {
            if (indicator instanceof UserDefIndicator) {
                // whereRuleIndicator or UDIIndicator
                continue;
            }
            boolean isContain = false;
            IndicatorDefinition newIndicatorDefinition = indicator.getIndicatorDefinition();
            // MOD qiongli 2012-5-11 TDQ-5256
            if (newIndicatorDefinition == null) {
                continue;
            }
            for (File lf : listFile) {
                ModelElement me = getElement(lf);
                if (me != null && me instanceof IndicatorDefinition) {
                    IndicatorDefinition oldIndicatorDefinition = (IndicatorDefinition) me;
                    if (ModelElementHelper.compareUUID(oldIndicatorDefinition, newIndicatorDefinition)) {
                        isContain = true;
                        break;
                    }
                }
            }
            if (!isContain) {
                File depFile = EObjectHelper.modelElement2File(newIndicatorDefinition);
                if (depFile != null) {
                    FILE_ELEMENT_MAP.put(depFile, newIndicatorDefinition);
                    listFile.add(depFile);
                }
            }
        }
    }
    return listFile;
}
Also used : ModelElement(orgomg.cwm.objectmodel.core.ModelElement) Analysis(org.talend.dataquality.analysis.Analysis) ArrayList(java.util.ArrayList) File(java.io.File) UserDefIndicator(org.talend.dataquality.indicators.sql.UserDefIndicator) UDIndicatorDefinition(org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition) UserDefIndicator(org.talend.dataquality.indicators.sql.UserDefIndicator) RecordMatchingIndicator(org.talend.dataquality.indicators.columnset.RecordMatchingIndicator) Indicator(org.talend.dataquality.indicators.Indicator)

Example 7 with UserDefIndicator

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

the class IndicatorCommonUtil method handleMatchingValue.

/**
 * DOC xqliu Comment method "handleMatchingValue".
 *
 * @param indicator
 * @return
 */
public static PatternMatchingExt handleMatchingValue(Indicator indicator) {
    PatternMatchingExt patternExt = new PatternMatchingExt();
    if (UDIHelper.isUDI(indicator)) {
        UserDefIndicator udi = (UserDefIndicator) indicator;
        if (udi.getMatchingValueCount() != null) {
            patternExt.setMatchingValueCount(udi.getMatchingValueCount());
        }
        if (udi.getNotMatchingValueCount() != null) {
            patternExt.setNotMatchingValueCount(udi.getNotMatchingValueCount());
        }
    } else {
        // TDQ-12282 msjian : fix a NPE
        Long matchingValueCount = ((PatternMatchingIndicator) indicator).getMatchingValueCount();
        patternExt.setMatchingValueCount(matchingValueCount == null ? 0l : matchingValueCount);
        Long notMatchingValueCount = ((PatternMatchingIndicator) indicator).getNotMatchingValueCount();
        patternExt.setNotMatchingValueCount(notMatchingValueCount == null ? 0l : notMatchingValueCount);
    }
    return patternExt;
}
Also used : PatternMatchingIndicator(org.talend.dataquality.indicators.PatternMatchingIndicator) PatternMatchingExt(org.talend.dq.indicators.ext.PatternMatchingExt) UserDefIndicator(org.talend.dataquality.indicators.sql.UserDefIndicator)

Example 8 with UserDefIndicator

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

the class IndicatorHelper method getIndicatorValue.

/**
 * DOC bZhou Comment method "getIndicatorValue".
 *
 * @param indicator
 * @return
 */
public static String getIndicatorValue(Indicator indicator) {
    IndicatorsSwitch<String> mySwitch = new IndicatorsSwitch<String>() {

        @Override
        public String caseAverageLengthIndicator(AverageLengthIndicator object) {
            return createStandardNumber(object.getAverageLength());
        }

        @Override
        public String caseBlankCountIndicator(BlankCountIndicator object) {
            return String.valueOf(object.getBlankCount());
        }

        @Override
        public String caseDefValueCountIndicator(DefValueCountIndicator object) {
            return String.valueOf(object.getDefaultValCount());
        }

        @Override
        public String caseDistinctCountIndicator(DistinctCountIndicator object) {
            return String.valueOf(object.getDistinctValueCount());
        }

        @Override
        public String caseDuplicateCountIndicator(DuplicateCountIndicator object) {
            return String.valueOf(object.getDuplicateValueCount());
        }

        @Override
        public String caseMaxLengthIndicator(MaxLengthIndicator object) {
            return String.valueOf(object.getLength());
        }

        @Override
        public String caseMeanIndicator(MeanIndicator object) {
            return createStandardNumber(object.getMean());
        }

        @Override
        public String caseMedianIndicator(MedianIndicator object) {
            return createStandardNumber(object.getMedian());
        }

        @Override
        public String caseMinLengthIndicator(MinLengthIndicator object) {
            return String.valueOf(object.getLength());
        }

        @Override
        public String caseModeIndicator(ModeIndicator object) {
            return String.valueOf(object.getMode());
        }

        @Override
        public String caseNullCountIndicator(NullCountIndicator object) {
            return String.valueOf(object.getNullCount());
        }

        @Override
        public String casePatternMatchingIndicator(PatternMatchingIndicator object) {
            return String.valueOf(object.getMatchingValueCount());
        }

        @Override
        public String caseRowCountIndicator(RowCountIndicator object) {
            return String.valueOf(object.getCount());
        }

        @Override
        public String caseUniqueCountIndicator(UniqueCountIndicator object) {
            return String.valueOf(object.getUniqueValueCount());
        }

        @Override
        public String caseValueIndicator(ValueIndicator object) {
            return object.getValue();
        }

        @Override
        public String caseValidPhoneCountIndicator(ValidPhoneCountIndicator object) {
            return String.valueOf(object.getValidPhoneNumCount());
        }

        @Override
        public String casePossiblePhoneCountIndicator(PossiblePhoneCountIndicator object) {
            return String.valueOf(object.getPossiblePhoneCount());
        }

        @Override
        public String caseValidRegCodeCountIndicator(ValidRegCodeCountIndicator object) {
            return String.valueOf(object.getValidRegCount());
        }

        @Override
        public String caseInvalidRegCodeCountIndicator(InvalidRegCodeCountIndicator object) {
            return String.valueOf(object.getInvalidRegCount());
        }

        @Override
        public String caseWellFormE164PhoneCountIndicator(WellFormE164PhoneCountIndicator object) {
            return String.valueOf(object.getWellFormE164PhoneCount());
        }

        @Override
        public String caseWellFormIntePhoneCountIndicator(WellFormIntePhoneCountIndicator object) {
            return String.valueOf(object.getWellFormIntePhoneCount());
        }

        @Override
        public String caseWellFormNationalPhoneCountIndicator(WellFormNationalPhoneCountIndicator object) {
            return String.valueOf(object.getWellFormNatiPhoneCount());
        }
    };
    // TDQ-11114: consider the UDI type
    IndicatorSqlSwitch<String> sqlSwitch = new IndicatorSqlSwitch<String>() {

        @Override
        public String caseWhereRuleIndicator(WhereRuleIndicator object) {
            return String.valueOf(object.getUserCount());
        }

        @Override
        public String caseUserDefIndicator(UserDefIndicator object) {
            // TDQ-11114: get the correct value for user define realvalue indicator
            if (object instanceof UserDefIndicator) {
                UserDefIndicator userDefineIndicator = object;
                IndicatorCategory category = IndicatorCategoryHelper.getCategory(userDefineIndicator.getIndicatorDefinition());
                if (IndicatorCategoryHelper.isUserDefRealValue(category)) {
                    return String.valueOf(userDefineIndicator.getRealValue());
                }
            }
            // TDQ-11485: fix the match udi get result value error
            return String.valueOf(object.getIntegerValue());
        }

        @Override
        public String caseJavaUserDefIndicator(JavaUserDefIndicator object) {
            return String.valueOf(object.getUserCount());
        }
    };
    String result = mySwitch.doSwitch(indicator);
    return result == null ? sqlSwitch.doSwitch(indicator) : result;
}
Also used : BlankCountIndicator(org.talend.dataquality.indicators.BlankCountIndicator) MedianIndicator(org.talend.dataquality.indicators.MedianIndicator) UniqueCountIndicator(org.talend.dataquality.indicators.UniqueCountIndicator) ModeIndicator(org.talend.dataquality.indicators.ModeIndicator) NullCountIndicator(org.talend.dataquality.indicators.NullCountIndicator) DistinctCountIndicator(org.talend.dataquality.indicators.DistinctCountIndicator) WellFormIntePhoneCountIndicator(org.talend.dataquality.indicators.WellFormIntePhoneCountIndicator) PatternMatchingIndicator(org.talend.dataquality.indicators.PatternMatchingIndicator) WhereRuleIndicator(org.talend.dataquality.indicators.sql.WhereRuleIndicator) IndicatorCategory(org.talend.dataquality.indicators.definition.IndicatorCategory) IndicatorsSwitch(org.talend.dataquality.indicators.util.IndicatorsSwitch) RowCountIndicator(org.talend.dataquality.indicators.RowCountIndicator) MeanIndicator(org.talend.dataquality.indicators.MeanIndicator) JavaUserDefIndicator(org.talend.dataquality.indicators.sql.JavaUserDefIndicator) UserDefIndicator(org.talend.dataquality.indicators.sql.UserDefIndicator) IndicatorSqlSwitch(org.talend.dataquality.indicators.sql.util.IndicatorSqlSwitch) PossiblePhoneCountIndicator(org.talend.dataquality.indicators.PossiblePhoneCountIndicator) WellFormE164PhoneCountIndicator(org.talend.dataquality.indicators.WellFormE164PhoneCountIndicator) ValidPhoneCountIndicator(org.talend.dataquality.indicators.ValidPhoneCountIndicator) DuplicateCountIndicator(org.talend.dataquality.indicators.DuplicateCountIndicator) MaxLengthIndicator(org.talend.dataquality.indicators.MaxLengthIndicator) MaxValueIndicator(org.talend.dataquality.indicators.MaxValueIndicator) MinValueIndicator(org.talend.dataquality.indicators.MinValueIndicator) ValueIndicator(org.talend.dataquality.indicators.ValueIndicator) ValidRegCodeCountIndicator(org.talend.dataquality.indicators.ValidRegCodeCountIndicator) MinLengthIndicator(org.talend.dataquality.indicators.MinLengthIndicator) InvalidRegCodeCountIndicator(org.talend.dataquality.indicators.InvalidRegCodeCountIndicator) JavaUserDefIndicator(org.talend.dataquality.indicators.sql.JavaUserDefIndicator) DefValueCountIndicator(org.talend.dataquality.indicators.DefValueCountIndicator) AverageLengthIndicator(org.talend.dataquality.indicators.AverageLengthIndicator) WellFormNationalPhoneCountIndicator(org.talend.dataquality.indicators.WellFormNationalPhoneCountIndicator)

Example 9 with UserDefIndicator

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

the class AnalysisHelper method getUserDefinedIndicators.

public static List<IndicatorDefinition> getUserDefinedIndicators(Analysis analysis) {
    List<IndicatorDefinition> rets = new ArrayList<IndicatorDefinition>();
    EList<Indicator> indicators = analysis.getResults().getIndicators();
    for (Indicator indicator : indicators) {
        if (indicator instanceof UserDefIndicator) {
            rets.add(indicator.getIndicatorDefinition());
        }
    }
    return rets;
}
Also used : ArrayList(java.util.ArrayList) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition) UserDefIndicator(org.talend.dataquality.indicators.sql.UserDefIndicator) PatternMatchingIndicator(org.talend.dataquality.indicators.PatternMatchingIndicator) RecordMatchingIndicator(org.talend.dataquality.indicators.columnset.RecordMatchingIndicator) RegexpMatchingIndicator(org.talend.dataquality.indicators.RegexpMatchingIndicator) Indicator(org.talend.dataquality.indicators.Indicator) AllMatchIndicator(org.talend.dataquality.indicators.columnset.AllMatchIndicator) UserDefIndicator(org.talend.dataquality.indicators.sql.UserDefIndicator)

Example 10 with UserDefIndicator

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

the class UDIHelper method adaptToJavaUDI.

/**
 * DOC mzhao feature 11128, If the execute engine and by the same time Java User Defined Indicator is also defined,
 * then compute via Java UDI, here convert common udi to a Java UDI.
 *
 * @param udi
 * @return
 * @throws Exception
 */
public static Indicator adaptToJavaUDI(Indicator indicator) throws Throwable {
    Indicator returnIndicator = getUDIFromMap(indicator);
    if (returnIndicator != null) {
        return returnIndicator;
    }
    UserDefIndicator adaptedUDI = null;
    if (userDefIndSwitch.doSwitch(indicator) != null) {
        EList<TaggedValue> taggedValues = indicator.getIndicatorDefinition().getTaggedValue();
        String userJavaClassName = null;
        String jarPath = null;
        for (TaggedValue tv : taggedValues) {
            if (tv.getTag().equals(TaggedValueHelper.CLASS_NAME_TEXT)) {
                userJavaClassName = tv.getValue();
                continue;
            }
            if (tv.getTag().equals(TaggedValueHelper.JAR_FILE_PATH)) {
                jarPath = tv.getValue();
            }
        }
        // MOD by zshen for feature 18724
        if (validateJavaUDI(userJavaClassName, jarPath)) {
            List<URL> jarUrls = new ArrayList<URL>();
            for (File file : getContainJarFile(jarPath)) {
                jarUrls.add(file.toURI().toURL());
            }
            TalendURLClassLoader cl;
            // Note that the 2nd parameter (classloader) is needed to load class UserDefinitionIndicator from
            // org.talend.dataquality plugin.
            cl = new TalendURLClassLoader(jarUrls.toArray(new URL[jarUrls.size()]), UDIHelper.class.getClassLoader());
            Class<?> clazz = null;
            clazz = cl.findClass(userJavaClassName);
            if (clazz != null) {
                // MOD yyin 20121012 TDQ-6259
                UserDefIndicator judi = (UserDefIndicator) clazz.newInstance();
                // judi.setIndicatorDefinition(indicator.getIndicatorDefinition());
                PropertyUtils.copyProperties(judi, indicator);
                // judi.setAnalyzedElement(indicator.getAnalyzedElement());
                adaptedUDI = judi;
                JAVAUDIMAP.put(indicator, adaptedUDI);
            }
        }
    }
    return adaptedUDI;
}
Also used : TaggedValue(orgomg.cwm.objectmodel.core.TaggedValue) ArrayList(java.util.ArrayList) UserDefIndicator(org.talend.dataquality.indicators.sql.UserDefIndicator) IFile(org.eclipse.core.resources.IFile) File(java.io.File) Indicator(org.talend.dataquality.indicators.Indicator) UserDefIndicator(org.talend.dataquality.indicators.sql.UserDefIndicator) URL(java.net.URL) TalendURLClassLoader(org.talend.utils.classloader.TalendURLClassLoader)

Aggregations

UserDefIndicator (org.talend.dataquality.indicators.sql.UserDefIndicator)23 Test (org.junit.Test)9 TdExpression (org.talend.cwm.relational.TdExpression)7 IndicatorDefinition (org.talend.dataquality.indicators.definition.IndicatorDefinition)7 ArrayList (java.util.ArrayList)6 Indicator (org.talend.dataquality.indicators.Indicator)6 UDIndicatorDefinition (org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition)6 Analysis (org.talend.dataquality.analysis.Analysis)5 AnalysisResult (org.talend.dataquality.analysis.AnalysisResult)5 IndicatorParameters (org.talend.dataquality.indicators.IndicatorParameters)5 PatternMatchingIndicator (org.talend.dataquality.indicators.PatternMatchingIndicator)4 Expression (orgomg.cwm.objectmodel.core.Expression)4 Path (org.eclipse.core.runtime.Path)3 PersistenceException (org.talend.commons.exception.PersistenceException)3 ItemState (org.talend.core.model.properties.ItemState)3 Property (org.talend.core.model.properties.Property)3 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)3 IndicatorUnit (org.talend.dataprofiler.core.ui.editor.preview.IndicatorUnit)3 RegularExpression (org.talend.dataquality.domain.pattern.RegularExpression)3 TDQAnalysisItem (org.talend.dataquality.properties.TDQAnalysisItem)3