use of org.supercsv.cellprocessor.ParseDate in project apex-malhar by apache.
the class CellProcessorBuilder method getDateCellProcessor.
/**
* Method to get cellprocessor for Date with constraints. These constraints
* are evaluated against the Date field for which this cellprocessor is
* defined.
*
* @param constraints
* map of constraints applicable to Date
* @return CellProcessor
*/
private static CellProcessor getDateCellProcessor(Map<String, Object> constraints) {
Boolean required = constraints.get(DelimitedSchema.REQUIRED) == null ? null : Boolean.parseBoolean((String) constraints.get(DelimitedSchema.REQUIRED));
String format = constraints.get(DelimitedSchema.DATE_FORMAT) == null ? null : (String) constraints.get(DelimitedSchema.DATE_FORMAT);
CellProcessor cellProcessor = null;
String fmt = StringUtils.isNotBlank(format) ? format : "dd/MM/yyyy";
cellProcessor = new ParseDate(fmt, false);
if (required == null || !required) {
cellProcessor = addOptional(cellProcessor);
}
return cellProcessor;
}
use of org.supercsv.cellprocessor.ParseDate in project apex-malhar by apache.
the class AbstractCsvParser method initialise.
// Initialise the properties and processors.
public void initialise(String[] properties, CellProcessor[] processors) {
for (int i = 0; i < getFields().size(); i++) {
FIELD_TYPE type = getFields().get(i).type;
properties[i] = getFields().get(i).name;
if (type == FIELD_TYPE.DOUBLE) {
processors[i] = new Optional(new ParseDouble());
} else if (type == FIELD_TYPE.INTEGER) {
processors[i] = new Optional(new ParseInt());
} else if (type == FIELD_TYPE.FLOAT) {
processors[i] = new Optional(new ParseDouble());
} else if (type == FIELD_TYPE.LONG) {
processors[i] = new Optional(new ParseLong());
} else if (type == FIELD_TYPE.SHORT) {
processors[i] = new Optional(new ParseInt());
} else if (type == FIELD_TYPE.STRING) {
processors[i] = new Optional();
} else if (type == FIELD_TYPE.CHARACTER) {
processors[i] = new Optional(new ParseChar());
} else if (type == FIELD_TYPE.BOOLEAN) {
processors[i] = new Optional(new ParseChar());
} else if (type == FIELD_TYPE.DATE) {
processors[i] = new Optional(new ParseDate("dd/MM/yyyy"));
}
}
}
Aggregations