private static ExpenseSheetLineDTO toDTO(ExpenseSheetLine line) {
if (line != null) {
String code = line.getCode();
if (StringUtils.isBlank(code)) {
throw new ValidationException(
"missing code in the expense sheet line");
}
BigDecimal value = line.getValue();
if (value == null || value.compareTo(BigDecimal.ZERO) < 0) {
value = BigDecimal.ZERO;
}
String resourceCode = null;
if (line.getResource() != null) {
resourceCode = line.getResource().getCode();
}
String orderElementCode = null;
if (line.getOrderElement() != null) {
orderElementCode = line.getOrderElement().getCode();
} else {
throw new ValidationException(
"missing order element code in a expense sheet line");
}
XMLGregorianCalendar date = null;
if (line.getDate() != null) {
date = DateConverter.toXMLGregorianCalendar(line.getDate());
} else {
throw new ValidationException(
"missing date in a expense sheet line");
}
return new ExpenseSheetLineDTO(code, line.getConcept(), value,
resourceCode, orderElementCode, date);
} else {
throw new ValidationException(
"the expense sheet line is not initialized");
}
}