use of org.supercsv.cellprocessor.constraint.Strlen in project apex-malhar by apache.
the class CellProcessorBuilder method getStringCellProcessor.
/**
* Method to get cellprocessor for String with constraints. These constraints
* are evaluated against the String field for which this cellprocessor is
* defined.
*
* @param constraints
* map of constraints applicable to String
* @return CellProcessor
*/
private static CellProcessor getStringCellProcessor(Map<String, Object> constraints) {
Boolean required = constraints.get(DelimitedSchema.REQUIRED) == null ? null : Boolean.parseBoolean((String) constraints.get(DelimitedSchema.REQUIRED));
Integer strLen = constraints.get(DelimitedSchema.LENGTH) == null ? null : Integer.parseInt((String) constraints.get(DelimitedSchema.LENGTH));
Integer minLength = constraints.get(DelimitedSchema.MIN_LENGTH) == null ? null : Integer.parseInt((String) constraints.get(DelimitedSchema.MIN_LENGTH));
Integer maxLength = constraints.get(DelimitedSchema.MAX_LENGTH) == null ? null : Integer.parseInt((String) constraints.get(DelimitedSchema.MAX_LENGTH));
String equals = constraints.get(DelimitedSchema.EQUALS) == null ? null : (String) constraints.get(DelimitedSchema.EQUALS);
String pattern = constraints.get(DelimitedSchema.REGEX_PATTERN) == null ? null : (String) constraints.get(DelimitedSchema.REGEX_PATTERN);
CellProcessor cellProcessor = null;
if (StringUtils.isNotBlank(equals)) {
cellProcessor = new Equals(equals);
} else if (StringUtils.isNotBlank(pattern)) {
cellProcessor = new StrRegEx(pattern);
} else if (strLen != null) {
cellProcessor = new Strlen(strLen);
} else if (maxLength != null || minLength != null) {
Long min = minLength == null ? 0L : minLength;
Long max = maxLength == null ? LMinMax.MAX_LONG : maxLength;
cellProcessor = new StrMinMax(min, max);
}
if (required == null || !required) {
cellProcessor = addOptional(cellProcessor);
}
return cellProcessor;
}
Aggregations