in SdmxDataParser/src/main/java/org/sdmxsource/sdmx/dataparser/engine/impl/DeepDataValidationEngine.java [250:329]
private List<String> validateTextFormat(ComponentSuperBean componentSb, String value, List<String> errorMessages) {
TextFormatBean textFormat = componentSb.getTextFormat();
if (textFormat == null) {
return errorMessages;
}
ComponentBean component = componentSb.getBuiltFrom();
if (textFormat.getTextType() != null) {
errorMessages = validateTextType(component, textFormat.getTextType(), value, errorMessages);
}
if (textFormat.getDecimals() != null) {
try {
Double valAsDouble = Double.parseDouble(value);
int num = getNumberOfDecimalPlace(valAsDouble);
if (num > textFormat.getDecimals().intValue()) {
errorMessages = addErrorMessage(component, value, "' exceeds the number of allowed decimal places of " + textFormat.getDecimals().toString(), errorMessages);
}
} catch (NumberFormatException e) {
errorMessages = addErrorMessage(component, value, "' is expected to be numerical", errorMessages);
}
}
if (textFormat.getMinLength() != null) {
if (value.length() < textFormat.getMinLength().intValue()) {
errorMessages = addErrorMessage(component, value, "' is shorter then the minimum allowed length of '" + textFormat.getMinLength().toString() + "'", errorMessages);
}
}
if (textFormat.getMaxLength() != null) {
if (value.length() > textFormat.getMaxLength().intValue()) {
errorMessages = addErrorMessage(component, value, "' is greater then the maximum allowed length of '" + textFormat.getMaxLength().toString() + "'", errorMessages);
}
}
if (textFormat.getStartValue() != null) {
BigDecimal valueAsDecimal = parseBigDecimal(value);
if (valueAsDecimal.compareTo(textFormat.getStartValue()) < 0) {
errorMessages = addErrorMessage(component, value, "' is less then the specified start value of " + textFormat.getStartValue().toPlainString(), errorMessages);
}
if (textFormat.getInterval() != null) {
if (valueAsDecimal.subtract(textFormat.getStartValue()).remainder(textFormat.getInterval()).compareTo(BigDecimal.ZERO) != 0) {
errorMessages = addErrorMessage(component, value, "' do not fit the allowed intervals starting from " + textFormat.getStartValue().toPlainString() + " and increasing by " + textFormat.getInterval().toPlainString(), errorMessages);
}
}
}
if (textFormat.getEndValue() != null) {
if (parseBigDecimal(value).compareTo(textFormat.getEndValue()) > 0) {
errorMessages = addErrorMessage(component, value, "' is greater then the specified end value of " + textFormat.getEndValue().toPlainString(), errorMessages);
}
}
if (textFormat.getMinValue() != null) {
if (parseBigDecimal(value).compareTo(textFormat.getMinValue()) < 0) {
errorMessages = addErrorMessage(component, value, "' is less then the specified min value of " + textFormat.getMinValue().toPlainString(), errorMessages);
}
}
if (textFormat.getMaxValue() != null) {
if (parseBigDecimal(value).compareTo(textFormat.getMaxValue()) > 0) {
errorMessages = addErrorMessage(component, value, "' is greater then the specified end value of " + textFormat.getMaxValue().toPlainString(), errorMessages);
}
}
if (textFormat.getStartTime() != null) {
try {
Date dte = DateUtil.formatDate(value, true);
if (dte.before(textFormat.getStartTime().getDate())) {
errorMessages = addErrorMessage(component, value, "' is before the allowed start time of " + textFormat.getStartTime().getDateInSdmxFormat(), errorMessages);
}
} catch (NumberFormatException e) {
errorMessages = addErrorMessage(component, value, "' is not of expected type 'Date'", errorMessages);
}
}
if (textFormat.getEndTime() != null) {
try {
Date dte = DateUtil.formatDate(value, true);
if (dte.after(textFormat.getEndTime().getDate())) {
errorMessages = addErrorMessage(component, value, "' is after the allowed start time of " + textFormat.getStartTime().getDateInSdmxFormat(), errorMessages);
}
} catch (NumberFormatException e) {
errorMessages = addErrorMessage(component, value, "' is not of expected type 'Date'", errorMessages);
}
}
return errorMessages;
}