1 package eu.glsgroup.fpcs.soap.util;
3 import eu.glsgroup.fpcs.dto.error.FPCSServiceException;
4 import eu.glsgroup.fpcs.dto.util.DateFormatter;
6 import java.math.BigDecimal;
7 import java.text.ParseException;
8 import java.text.SimpleDateFormat;
13 private static final String DATETIME_FORMAT_STRING =
"yyyy-MM-dd'T'HH:mm:ssXXX";
17 return assumeValidBigDecimal(value,
"");
20 private static BigDecimal assumeValidBigDecimal(String value, String fieldName) {
23 return new BigDecimal(value);
25 catch (NumberFormatException e) {
26 throw new SOAPRequestValidationException(
"Cannot interpret " + value +
" as a valid decimal value.", e);
32 return value.toPlainString();
45 return DateFormatter.getInstance().parseDate(
trimDate(value));
47 catch (FPCSServiceException e) {
53 private static boolean empty(String value) {
55 return value == null || value.isEmpty();
60 String trimmed = value.trim();
61 return trimmed.length() < 11? trimmed : trimmed.substring(0, 10);
69 return DateFormatter.getInstance().formatDate(value);
79 return new SimpleDateFormat(DATETIME_FORMAT_STRING).parse(value);
81 catch (ParseException e) {
83 "Cannot interpret " + value +
" as a valid date. Please submit in format " + DATETIME_FORMAT_STRING);
93 return new SimpleDateFormat(DATETIME_FORMAT_STRING).format(value);