Search in sources :

Example 16 with TdColumn

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

the class DatePatternFreqIndicatorImpl method reset.

@Override
public boolean reset() {
    boolean flag = super.reset();
    // set date pattern only for delimited file
    MetadataColumn mdColumn = SwitchHelpers.METADATA_COLUMN_SWITCH.doSwitch(this.getAnalyzedElement());
    TdColumn tdColumn = SwitchHelpers.COLUMN_SWITCH.doSwitch(this.getAnalyzedElement());
    if (tdColumn == null && mdColumn != null && "id_Date".equals(mdColumn.getTalendType())) {
        // get date pattern from the column
        String pattern = mdColumn.getPattern();
        if (StringUtils.isEmpty(pattern)) {
            pattern = "yyyy-MM-dd";
        } else {
            pattern = StringUtils.replace(pattern, "\"", StringUtils.EMPTY);
        }
        // the datePattern only for DelimitedFile connection in DatePatternFreqIndicator.
        this.datePattern = pattern;
    }
    return flag;
}
Also used : MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) TdColumn(org.talend.cwm.relational.TdColumn)

Example 17 with TdColumn

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

the class DefValueCountIndicatorImpl method prepare.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.dataquality.indicators.impl.IndicatorImpl#prepare()
     * 
     * ADD yyi 2009-09-02 prepare()
     */
@Override
public boolean prepare() {
    TdColumn tdColumn = SwitchHelpers.COLUMN_SWITCH.doSwitch(this.getAnalyzedElement());
    this.defValue = ColumnHelper.getDefaultValue(tdColumn);
    // MOD qiongli 2011-5-31 bug 21655,if it is oracle db,need to handel the default value.
    Connection connection = ConnectionHelper.getConnection(tdColumn);
    if (SwitchHelpers.DATABASECONNECTION_SWITCH.doSwitch(connection) != null) {
        String databaseType = ((DatabaseConnection) connection).getDatabaseType();
        if (databaseType != null && databaseType.contains("Oracle")) {
            // $NON-NLS-1$
            isOracle = true;
        }
    }
    // this indicator.
    if (defValue != null) {
        if (isOracle) {
            getDefValueForOracle(tdColumn);
        } else if (Java2SqlType.isDateInSQL(tdColumn.getSqlDataType().getJavaDataType())) {
            String defTmp = defValue.toString();
            try {
                if (StringUtils.contains(defTmp, ":")) {
                    // $NON-NLS-1$
                    defValue = DateFormat.getDateTimeInstance().parse(defTmp);
                } else {
                    defValue = DateFormat.getDateInstance().parse(defTmp);
                }
            } catch (ParseException exc) {
                // if parse fail,reset defValue to String
                defValue = defTmp;
                log.warn("Parse default value failure!");
            }
        }
    }
    return super.prepare();
}
Also used : TdColumn(org.talend.cwm.relational.TdColumn) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) ParseException(java.text.ParseException)

Example 18 with TdColumn

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

the class RegexpMatchingIndicatorImpl method prepare.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.dataquality.indicators.impl.IndicatorImpl#prepare()
     */
@Override
public boolean prepare() {
    // the same with in DatePatternFreqIndicatorImpl
    // TDQ-14467: set date pattern only for delimited file.
    MetadataColumn mdColumn = SwitchHelpers.METADATA_COLUMN_SWITCH.doSwitch(this.getAnalyzedElement());
    TdColumn tdColumn = SwitchHelpers.COLUMN_SWITCH.doSwitch(this.getAnalyzedElement());
    if (tdColumn == null && mdColumn != null && "id_Date".equals(mdColumn.getTalendType())) {
        // get date pattern from the column
        String pattern = mdColumn.getPattern();
        if (StringUtils.isEmpty(pattern)) {
            pattern = "yyyy-MM-dd";
        } else {
            pattern = StringUtils.replace(pattern, "\"", StringUtils.EMPTY);
        }
        // the datePattern only for DelimitedFile connection.
        this.datePattern = pattern;
    }
    // TDQ-14467~
    this.regex = getRegex();
    if (regex == null) {
        return false;
    }
    // MOD klliu 2010-06-12 bug 13695
    if (regex.equals(this.getJavaPatternMessage())) {
        return false;
    }
    try {
        pattern = java.util.regex.Pattern.compile(regex);
    } catch (java.util.regex.PatternSyntaxException e) {
        log.error(Messages.getString("Using_regular_expression", this.getName(), regex), e);
        return false;
    }
    if (log.isInfoEnabled()) {
        log.info(Messages.getString("Using_regular_expression", this.getName(), regex));
    }
    return super.prepare();
}
Also used : MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) TdColumn(org.talend.cwm.relational.TdColumn)

Example 19 with TdColumn

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

the class IndicatorImpl method getColumnType.

/**
 * Method "getColumnType".
 *
 * @return the column type of the analyzed object (when the analyzed object is a column). Otherwise, it returns
 * Types.JAVA_OBJECT.
 */
protected int getColumnType() {
    // default type
    int javaType = Types.JAVA_OBJECT;
    ModelElement elt = this.getAnalyzedElement();
    if (elt != null) {
        TdColumn col = SwitchHelpers.COLUMN_SWITCH.doSwitch(elt);
        if (col != null) {
            javaType = col.getSqlDataType().getJavaDataType();
            return javaType;
        }
        MetadataColumn mdCol = SwitchHelpers.METADATA_COLUMN_SWITCH.doSwitch(elt);
        if (mdCol != null) {
            javaType = Java2SqlType.getJavaTypeBySqlType(TalendTypeConvert.convertToJavaType(mdCol.getTalendType()));
        }
    }
    return javaType;
}
Also used : ModelElement(orgomg.cwm.objectmodel.core.ModelElement) MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) TdColumn(org.talend.cwm.relational.TdColumn)

Example 20 with TdColumn

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

the class ValueIndicatorImpl method isDateValue.

/**
 * Method "isDateValue".
 *
 * @return true if the analyzed column is of date type.
 */
protected boolean isDateValue() {
    // MOD scorreia handle date: bug 5938
    final ModelElement elt = getAnalyzedElement();
    if (elt != null) {
        final TdColumn col = SwitchHelpers.COLUMN_SWITCH.doSwitch(elt);
        if (col != null && (Java2SqlType.isDateInSQL(col.getSqlDataType().getJavaDataType()) || Java2SqlType.isDateTimeSQL(col.getSqlDataType().getJavaDataType()))) {
            return true;
        }
        MetadataColumn metadataColumn = SwitchHelpers.METADATA_COLUMN_SWITCH.doSwitch(elt);
        if (metadataColumn != null && metadataColumn.getTalendType().equals("id_Date")) {
            // get date pattern from the column
            String pattern = metadataColumn.getPattern();
            if (StringUtils.isEmpty(pattern)) {
                pattern = "yyyy-MM-dd";
            } else {
                pattern = StringUtils.replace(pattern, "\"", StringUtils.EMPTY);
            }
            // the datePattern only for DelimitedFile connection in current or sub-class indicators.
            this.datePattern = pattern;
            return true;
        }
    }
    return false;
}
Also used : ModelElement(orgomg.cwm.objectmodel.core.ModelElement) MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) TdColumn(org.talend.cwm.relational.TdColumn)

Aggregations

TdColumn (org.talend.cwm.relational.TdColumn)177 TdTable (org.talend.cwm.relational.TdTable)47 ArrayList (java.util.ArrayList)45 ModelElement (orgomg.cwm.objectmodel.core.ModelElement)40 Test (org.junit.Test)37 ColumnSet (orgomg.cwm.resource.relational.ColumnSet)35 MetadataColumn (org.talend.core.model.metadata.builder.connection.MetadataColumn)26 RepositoryNode (org.talend.repository.model.RepositoryNode)26 IRepositoryNode (org.talend.repository.model.IRepositoryNode)23 Indicator (org.talend.dataquality.indicators.Indicator)20 Connection (org.talend.core.model.metadata.builder.connection.Connection)17 Catalog (orgomg.cwm.resource.relational.Catalog)17 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)16 TdSqlDataType (org.talend.cwm.relational.TdSqlDataType)16 Analysis (org.talend.dataquality.analysis.Analysis)16 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)15 IndicatorParameters (org.talend.dataquality.indicators.IndicatorParameters)14 DBColumnRepNode (org.talend.dq.nodes.DBColumnRepNode)14 Package (orgomg.cwm.objectmodel.core.Package)14 MetadataColumnRepositoryObject (org.talend.core.repository.model.repositoryObject.MetadataColumnRepositoryObject)13