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;
}
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();
}
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();
}
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;
}
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;
}
Aggregations