Search in sources :

Example 56 with TdExpression

use of org.talend.cwm.relational.TdExpression 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 57 with TdExpression

use of org.talend.cwm.relational.TdExpression in project tdq-studio-se by Talend.

the class DefinitionHandler method updateRegex.

public boolean updateRegex(String dbmsName, String regexpFunction) {
    boolean ok = true;
    boolean replaced = false;
    IndicatorDefinition regexIndDef = this.getIndicatorDefinition(REGULAR_EXPRESSION_MATCHING);
    EList<TdExpression> sqlGenericExpression = regexIndDef.getSqlGenericExpression();
    for (Expression expression : sqlGenericExpression) {
        // MOD qiongli 2011-4-18,bug 16723.data cleansing.
        if (DbmsLanguageFactory.compareDbmsLanguage(dbmsName, expression.getLanguage())) {
            replaced = replaceBodyWith(expression, regexpFunction);
        }
    }
    if (!replaced) {
        // add new expression
        String genericSQL = getGenericSQL(dbmsName, regexpFunction);
        TdExpression createdExpression = BooleanExpressionHelper.createTdExpression(dbmsName, genericSQL);
        sqlGenericExpression.add(createdExpression);
    }
    return ok;
}
Also used : TdExpression(org.talend.cwm.relational.TdExpression) TdExpression(org.talend.cwm.relational.TdExpression) RegularExpression(org.talend.dataquality.domain.pattern.RegularExpression) Expression(orgomg.cwm.objectmodel.core.Expression) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition) UDIndicatorDefinition(org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition)

Example 58 with TdExpression

use of org.talend.cwm.relational.TdExpression in project tdq-studio-se by Talend.

the class RegularExpressionImpl method basicSetExpression.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public NotificationChain basicSetExpression(TdExpression newExpression, NotificationChain msgs) {
    TdExpression oldExpression = expression;
    expression = newExpression;
    if (eNotificationRequired()) {
        ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, PatternPackage.REGULAR_EXPRESSION__EXPRESSION, oldExpression, newExpression);
        if (msgs == null)
            msgs = notification;
        else
            msgs.add(notification);
    }
    return msgs;
}
Also used : TdExpression(org.talend.cwm.relational.TdExpression) ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl)

Example 59 with TdExpression

use of org.talend.cwm.relational.TdExpression in project tdq-studio-se by Talend.

the class TOPRepositoryService method getPaserRulesFromRules.

public List<Map<String, String>> getPaserRulesFromRules(Object parser) {
    if (parser != null && parser instanceof ParserRule) {
        List<Map<String, String>> ruleValues = new ArrayList<Map<String, String>>();
        for (TdExpression exp : ((ParserRule) parser).getExpression()) {
            Map<String, String> pr = new HashMap<String, String>();
            // MOD yyi 2011-08-12 TDQ-1698:avoid importing null value
            pr.put(RULE_NAME, null == exp.getName() ? StringUtils.EMPTY : exp.getName());
            pr.put(RULE_VALUE, null == exp.getBody() ? StringUtils.EMPTY : exp.getBody());
            pr.put(RULE_TYPE, null == exp.getLanguage() ? StringUtils.EMPTY : exp.getLanguage().toUpperCase());
            ruleValues.add(pr);
        }
        return ruleValues;
    }
    return null;
}
Also used : ParserRule(org.talend.dataquality.rules.ParserRule) TdExpression(org.talend.cwm.relational.TdExpression) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap)

Example 60 with TdExpression

use of org.talend.cwm.relational.TdExpression in project tdq-studio-se by Talend.

the class ExportFactory method export.

public static void export(File exportFile, IFolder folder, ParserRule... parserRules) {
    if (exportFile.isDirectory()) {
        for (ParserRule pr : parserRules) {
            // $NON-NLS-1$
            File file = new File(exportFile, pr.getName() + ".csv");
            export(file, folder, pr);
        }
    }
    String fileExtName = getFileExtName(exportFile);
    if (FileUtils.isCSV(fileExtName)) {
        try {
            CSVWriter out = FileUtils.createCSVWriter(exportFile, FileUtils.TEXT_QUAL, FileUtils.TEXT_QUAL);
            List<TdExpression> expressions = parserRules[0].getExpression();
            ParserRuleToExcelEnum[] values = getParserRuleEnumValues();
            String[] temp = new String[values.length];
            for (int i = 0; i < expressions.toArray().length + 1; i++) {
                for (int j = 0; j < values.length; j++) {
                    if (i == 0) {
                        temp[j] = values[j].getLiteral();
                    } else {
                        Map<ParserRuleToExcelEnum, String> relatedValueFromParserRule = getRelatedValueFromParserRule(parserRules[0], folder, expressions.get(i - 1));
                        temp[j] = relatedValueFromParserRule.get(values[j]);
                    }
                }
                out.writeNext(temp);
            }
            out.flush();
            out.close();
        } catch (FileNotFoundException fe) {
            MessageDialogWithToggle.openError(null, DefaultMessagesImpl.getString("ExportFactory.errorOne"), // $NON-NLS-1$ //$NON-NLS-2$
            DefaultMessagesImpl.getString("ExportFactory.notFoundFile"));
        } catch (Exception e) {
            log.error(e.getMessage());
        }
    }
}
Also used : ParserRule(org.talend.dataquality.rules.ParserRule) TdExpression(org.talend.cwm.relational.TdExpression) FileNotFoundException(java.io.FileNotFoundException) CSVWriter(com.talend.csv.CSVWriter) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) ParserRuleToExcelEnum(org.talend.dataprofiler.core.ui.wizard.parserrule.ParserRuleToExcelEnum) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Aggregations

TdExpression (org.talend.cwm.relational.TdExpression)121 Test (org.junit.Test)51 IndicatorDefinition (org.talend.dataquality.indicators.definition.IndicatorDefinition)30 UDIndicatorDefinition (org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition)29 ArrayList (java.util.ArrayList)19 RegularExpression (org.talend.dataquality.domain.pattern.RegularExpression)19 Pattern (org.talend.dataquality.domain.pattern.Pattern)16 TdColumn (org.talend.cwm.relational.TdColumn)12 Expression (orgomg.cwm.objectmodel.core.Expression)12 BasicEList (org.eclipse.emf.common.util.BasicEList)11 IndicatorParameters (org.talend.dataquality.indicators.IndicatorParameters)11 Domain (org.talend.dataquality.domain.Domain)10 TdTable (org.talend.cwm.relational.TdTable)9 ProductVersion (org.talend.utils.ProductVersion)9 Analysis (org.talend.dataquality.analysis.Analysis)8 PatternComponent (org.talend.dataquality.domain.pattern.PatternComponent)8 ChartDataEntity (org.talend.dq.indicators.preview.table.ChartDataEntity)8 File (java.io.File)7 IFile (org.eclipse.core.resources.IFile)6 IFolder (org.eclipse.core.resources.IFolder)6