Search in sources :

Example 6 with IndicatorCategory

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

the class UDIUtils method createDefaultDrillDownList.

/**
 * create Default Drill Down List for UDI.
 *
 * @param indiDefinition
 * @return
 */
public static UDIndicatorDefinition createDefaultDrillDownList(UDIndicatorDefinition indiDefinition) {
    IndicatorCategory category = IndicatorCategoryHelper.getCategory(indiDefinition);
    if (IndicatorCategoryHelper.isUserDefMatching(category)) {
        // set default value from templates
        EList<TdExpression> viewValidRowsList = indiDefinition.getViewValidRowsExpression();
        EList<TdExpression> viewInvalidRowsList = indiDefinition.getViewInvalidRowsExpression();
        EList<TdExpression> viewValidValuesList = indiDefinition.getViewValidValuesExpression();
        EList<TdExpression> viewInvalidValuesList = indiDefinition.getViewInvalidValuesExpression();
        EList<TdExpression> sqlGenericExpression = indiDefinition.getSqlGenericExpression();
        if (sqlGenericExpression != null) {
            for (TdExpression tdExp : sqlGenericExpression) {
                String language = tdExp.getLanguage();
                String version = tdExp.getVersion();
                // if not exist, add one.(when do migration more than one time, will add one)
                if (!UDIUtils.checkExistInList(viewValidRowsList, language, version)) {
                    // for match is View Valid Rows template
                    String body = UDIHelper.getQueryFromTemplates(2, language, category);
                    viewValidRowsList.add(UDIUtils.createNewTdExpression(language, version, replaceQueryForMatchUDI(body)));
                }
                if (!UDIUtils.checkExistInList(viewInvalidRowsList, language, version)) {
                    // for match is View Invalid Rows Template
                    String body = UDIHelper.getQueryFromTemplates(3, language, category);
                    viewInvalidRowsList.add(UDIUtils.createNewTdExpression(language, version, replaceQueryForMatchUDI(body)));
                }
                if (!UDIUtils.checkExistInList(viewValidValuesList, language, version)) {
                    // for match is View Valid Values Template
                    String body = UDIHelper.getQueryFromTemplates(4, language, category);
                    viewValidValuesList.add(UDIUtils.createNewTdExpression(language, version, replaceQueryForMatchUDI(body)));
                }
                if (!UDIUtils.checkExistInList(viewInvalidValuesList, language, version)) {
                    // for match is View Invalid Values Template
                    String body = UDIHelper.getQueryFromTemplates(5, language, category);
                    viewInvalidValuesList.add(UDIUtils.createNewTdExpression(language, version, replaceQueryForMatchUDI(body)));
                }
            }
        }
    } else {
        // for others is view rows template
        EList<TdExpression> viewRowsList = indiDefinition.getViewRowsExpression();
        EList<TdExpression> sqlGenericExpression = indiDefinition.getSqlGenericExpression();
        if (sqlGenericExpression != null) {
            for (TdExpression tdExp : sqlGenericExpression) {
                String language = tdExp.getLanguage();
                String version = tdExp.getVersion();
                // if not exist, add one.(when do migration more than one time, will add one)
                if (!UDIUtils.checkExistInList(viewRowsList, language, version)) {
                    String body = UDIHelper.getQueryFromTemplates(2, language, category);
                    GenericSQLHandler genericSQLHandler = new GenericSQLHandler(body);
                    if (IndicatorCategoryHelper.isUserDefRealValue(category)) {
                        // replace <COLUMN_EXPRESSION_TEXT_FIELD>
                        genericSQLHandler.replaceUDIColumn(PluginConstant.EMPTY_STRING);
                    } else if (IndicatorCategoryHelper.isUserDefFrequency(category)) {
                        // replace <FIRST_COLUMN_EXPRESSION_TEXT_FIELD>
                        // replace <SECOND_COLUMN_EXPRESSION_TEXT_FIELD>
                        genericSQLHandler.replaceUDIFirstColumn(PluginConstant.EMPTY_STRING).replaceUDISecondColumn(PluginConstant.EMPTY_STRING);
                    }
                    viewRowsList.add(UDIUtils.createNewTdExpression(language, version, genericSQLHandler.replaceUDIQueryToMatch().getSqlString()));
                }
            }
        }
    }
    return indiDefinition;
}
Also used : TdExpression(org.talend.cwm.relational.TdExpression) IndicatorCategory(org.talend.dataquality.indicators.definition.IndicatorCategory) GenericSQLHandler(org.talend.dq.dbms.GenericSQLHandler)

Example 7 with IndicatorCategory

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

the class FileSystemImportWriter method mergeSystemIndicator.

/**
 * Added: (20120808 yyin, TDQ-4189) The system indicators are not read-only because the user may want to write his
 * own SQL template. so this task deals with the modified SI from imported one, and merge them with the current
 * studio. 1)only when the user select the"Overwrite existing items" on the import wizard(and the modifydate is
 * newer than the current studio's SI), the conflict modification in imported SI will overwrite the ones in current
 * studio, otherwise, the SI in current studio will keep. 2)If a language does not exist in the system indicator but
 * exists in the user modified indicator, then we add it 3)if a language exists in the system indicator but has been
 * removed in the user modified indicator, then we keep the system indicator definition. [for Indicator
 * matadata(Purpose, Description, Author, Status): 1) will replace old value with new value if new value is not
 * blank; 2) will keep old value if new value is blank][for IndicatorDefinitionParameter: 1) will replace the same
 * name old parameter with new parameter; 2) will keep the old parameter if new one don't include the same name
 * parameter ]
 *
 * @param record imported modified system indicator
 * @param siDef the system indicator in the current studio
 */
protected void mergeSystemIndicator(ItemRecord record, TDQIndicatorDefinitionItem siDefItem) {
    // only when the Si is modified, do the save
    boolean isModified = false;
    // old object
    IndicatorDefinition siDef = siDefItem.getIndicatorDefinition();
    Property siProp = siDefItem.getProperty();
    // new object
    IndicatorDefinition indDef = (IndicatorDefinition) record.getElement();
    Property indDefProp = record.getProperty();
    // get expression list from record
    EList<TdExpression> importedExs = indDef.getSqlGenericExpression();
    // for each expression:
    for (TdExpression importedEx : importedExs) {
        // if the modify date ==null, means it is not modified, do nothing
        if (importedEx.getModificationDate() == null) {
            continue;
        }
        // find the related template in system indicator(with same language)
        TdExpression systemExpression = null;
        for (TdExpression ex : siDef.getSqlGenericExpression()) {
            if (ex.getLanguage().equals(importedEx.getLanguage())) {
                systemExpression = ex;
                break;
            }
        }
        // if new, add to SI
        if (systemExpression == null) {
            IndicatorDefinitionFileHelper.addSqlExpression(siDef, importedEx.getLanguage(), importedEx.getBody(), importedEx.getModificationDate());
            isModified = true;
        } else {
            // if the expression are different: compare the modify date, make the SI keep the new one
            if (replaceExpression(systemExpression, importedEx)) {
                IndicatorDefinitionFileHelper.removeSqlExpression(siDef, importedEx.getLanguage());
                IndicatorDefinitionFileHelper.addSqlExpression(siDef, importedEx.getLanguage(), importedEx.getBody(), importedEx.getModificationDate());
                isModified = true;
            }
        }
    }
    // handle the category
    IndicatorCategory siDefCategory = IndicatorCategoryHelper.getCategory(siDef);
    IndicatorCategory indDefCategory = IndicatorCategoryHelper.getCategory(indDef);
    siDefCategory = (IndicatorCategory) EObjectHelper.resolveObject(siDefCategory);
    indDefCategory = (IndicatorCategory) EObjectHelper.resolveObject(indDefCategory);
    if (!ModelElementHelper.compareUUID(siDefCategory, indDefCategory)) {
        // use the imported one
        IndicatorCategoryHelper.setCategory(siDef, indDefCategory);
        isModified = true;
    } else {
        // if the uuid is the same, but the label is different
        if (siDefCategory != null && indDefCategory != null && !siDefCategory.eIsProxy()) {
            if (!indDefCategory.equals(siDefCategory)) {
                // especially: "Pattern Finder" is changed by us
                if (!indDefCategory.getLabel().equals(RenamePatternFinderFolderTask.PATTERN_FINDER)) {
                    IndicatorCategoryHelper.setCategory(siDef, indDefCategory);
                    isModified = true;
                }
            }
        }
    }
    // for Indicator Metadata
    if (siProp != null && indDefProp != null) {
        if (!StringUtils.isBlank(indDefProp.getPurpose())) {
            siProp.setPurpose(indDefProp.getPurpose());
        }
        if (!StringUtils.isBlank(indDefProp.getDescription())) {
            siProp.setDescription(indDefProp.getDescription());
        }
        siProp.setAuthor(indDefProp.getAuthor());
        siProp.setStatusCode(indDefProp.getStatusCode());
        isModified = true;
    }
    // for judi's jar file information
    String jarFilePath = TaggedValueHelper.getJarFilePath(indDef);
    if (!StringUtils.isBlank(jarFilePath)) {
        TaggedValueHelper.setJarFilePath(jarFilePath, siDef);
        isModified = true;
    }
    String classNameText = TaggedValueHelper.getClassNameText(indDef);
    if (!StringUtils.isBlank(classNameText)) {
        TaggedValueHelper.setClassNameText(classNameText, siDef);
        isModified = true;
    }
    // for IndicatorDefinintionParameter
    EList<IndicatorDefinitionParameter> siParameter = siDef.getIndicatorDefinitionParameter();
    EList<IndicatorDefinitionParameter> indDefParameter = indDef.getIndicatorDefinitionParameter();
    List<IndicatorDefinitionParameter> tempParameter = new ArrayList<IndicatorDefinitionParameter>();
    for (IndicatorDefinitionParameter indDefPara : indDefParameter) {
        boolean include = false;
        String key = indDefPara.getKey();
        for (IndicatorDefinitionParameter siPara : siParameter) {
            if (key.equals(siPara.getKey())) {
                include = true;
                siPara.setValue(indDefPara.getValue());
                isModified = true;
            }
        }
        if (!include) {
            tempParameter.add(indDefPara);
            isModified = true;
        }
    }
    if (isModified && !tempParameter.isEmpty()) {
        siParameter.addAll(tempParameter);
    }
    if (isModified) {
        try {
            ElementWriterFactory.getInstance().createIndicatorDefinitionWriter().save(siDefItem, false);
        } catch (Exception e) {
            log.error(e);
        }
    }
}
Also used : TdExpression(org.talend.cwm.relational.TdExpression) IndicatorCategory(org.talend.dataquality.indicators.definition.IndicatorCategory) ArrayList(java.util.ArrayList) IndicatorDefinitionParameter(org.talend.dataquality.indicators.definition.IndicatorDefinitionParameter) UDIndicatorDefinition(org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition) Property(org.talend.core.model.properties.Property) CoreException(org.eclipse.core.runtime.CoreException) LoginException(org.talend.commons.exception.LoginException) IOException(java.io.IOException) PersistenceException(org.talend.commons.exception.PersistenceException)

Example 8 with IndicatorCategory

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

the class NewDQRulesWizard method createAndSaveCWMFile.

public TypedReturnCode<Object> createAndSaveCWMFile(ModelElement cwmElement) {
    WhereRule whereRule = (WhereRule) cwmElement;
    TaggedValueHelper.setValidStatus(true, whereRule);
    whereRule.setWhereExpression(parameter.getWhereClause());
    whereRule.setCriticalityLevel(CRITICALITY_LEVEL_DEFAULT);
    whereRule.getSqlGenericExpression().add(getExpression());
    // MOD scorreia 2009-04-29 bug 7151: add the category
    IndicatorCategory ruleIndicatorCategory = DefinitionHandler.getInstance().getDQRuleIndicatorCategory();
    if (ruleIndicatorCategory != null && !whereRule.getCategories().contains(ruleIndicatorCategory)) {
        whereRule.getCategories().add(ruleIndicatorCategory);
    }
    IFolder folder = parameter.getFolderProvider().getFolderResource();
    return ElementWriterFactory.getInstance().createdRuleWriter().create(whereRule, folder);
}
Also used : WhereRule(org.talend.dataquality.rules.WhereRule) IndicatorCategory(org.talend.dataquality.indicators.definition.IndicatorCategory) IFolder(org.eclipse.core.resources.IFolder)

Example 9 with IndicatorCategory

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

the class DefinitionHandler method getUserDefinedIndicatorCategoryMap.

public Map<String, IndicatorCategory> getUserDefinedIndicatorCategoryMap() {
    // FIXME lazy initialization of a static field
    if (userDefinedIndicatorCategoryMap == null) {
        userDefinedIndicatorCategoryMap = new HashMap<String, IndicatorCategory>();
        // init user defined indicator categories
        List<IndicatorCategory> categoryList = new ArrayList<IndicatorCategory>();
        categoryList.add(getUserDefinedCountIndicatorCategory());
        categoryList.add(getUserDefinedFrequencyIndicatorCategory());
        categoryList.add(getUserDefinedMatchIndicatorCategory());
        categoryList.add(getUserDefinedRealValueIndicatorCategory());
        for (IndicatorCategory category : categoryList) {
            userDefinedIndicatorCategoryMap.put(InternationalizationUtil.getCategoryInternationalizationLabel(category.getLabel()), category);
        }
        categoryList = null;
    }
    return userDefinedIndicatorCategoryMap;
}
Also used : IndicatorCategory(org.talend.dataquality.indicators.definition.IndicatorCategory) ArrayList(java.util.ArrayList)

Example 10 with IndicatorCategory

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

the class UDIndicatorBuilder method initializeUDIndicatorBuilder.

public boolean initializeUDIndicatorBuilder(String udiName) {
    if (initialized) {
        // $NON-NLS-1$
        log.warn("User Defined Indicator already initialized. ");
        return false;
    }
    this.indicatorDefinition = UserdefineFactoryImpl.eINSTANCE.createUDIndicatorDefinition();
    indicatorDefinition.setName(udiName);
    indicatorDefinition.setLabel(udiName);
    IndicatorCategory udiCategory = DefinitionHandler.getInstance().getUserDefinedCountIndicatorCategory();
    if (udiCategory != null && !indicatorDefinition.getCategories().contains(udiCategory)) {
        indicatorDefinition.getCategories().add(udiCategory);
    }
    return true;
}
Also used : IndicatorCategory(org.talend.dataquality.indicators.definition.IndicatorCategory)

Aggregations

IndicatorCategory (org.talend.dataquality.indicators.definition.IndicatorCategory)17 TdExpression (org.talend.cwm.relational.TdExpression)5 ArrayList (java.util.ArrayList)4 IFolder (org.eclipse.core.resources.IFolder)3 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)2 IndicatorDefinition (org.talend.dataquality.indicators.definition.IndicatorDefinition)2 UDIndicatorDefinition (org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition)2 ParserRule (org.talend.dataquality.rules.ParserRule)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 List (java.util.List)1 CoreException (org.eclipse.core.runtime.CoreException)1 EList (org.eclipse.emf.common.util.EList)1 LoginException (org.talend.commons.exception.LoginException)1 PersistenceException (org.talend.commons.exception.PersistenceException)1 Property (org.talend.core.model.properties.Property)1 Folder (org.talend.core.model.repository.Folder)1 BusinessRuleItemEditorInput (org.talend.dataprofiler.core.ui.editor.dqrules.BusinessRuleItemEditorInput)1 DQRuleEditor (org.talend.dataprofiler.core.ui.editor.dqrules.DQRuleEditor)1 AverageLengthIndicator (org.talend.dataquality.indicators.AverageLengthIndicator)1