.getInstance();
public static WorkReport toEntity(WorkReportDTO workReportDTO)
throws InstanceNotFoundException {
WorkReport workReport = WorkReport.create();
// Mandatory fields
workReport.setCode(workReportDTO.code);
try {
WorkReportType workReportType = Registry.getWorkReportTypeDAO()
.findUniqueByCode(workReportDTO.workReportType);
workReport.setWorkReportType(workReportType);
} catch (InstanceNotFoundException e) {
throw new ValidationException(
"There is no type of work report with this code");
}
for (WorkReportLineDTO workReportLineDTO : workReportDTO.workReportLines) {
workReport
.addWorkReportLine(toEntity(workReportLineDTO, workReport));
}
// Optional fields
if (workReportDTO.date != null) {
workReport.setDate(DateConverter.toDate(workReportDTO.date));
}
bindingStrategy.assignOrderElementsToWorkReportLine(workReport,
bindingStrategy.getOrderElementsBound(workReportDTO));
if (workReportDTO.resource != null) {
try {
Resource resource = Registry.getResourceDAO().findByCode(
workReportDTO.resource);
workReport.setResource(resource);
} catch (InstanceNotFoundException e) {
workReport.setResource(null);
throw new ValidationException(
"There is no resource with this code");
}
}
if (workReportDTO.labels != null && !workReportDTO.labels.isEmpty()) {
try {
workReport.setLabels(LabelReferenceConverter
.toEntity(workReportDTO.labels));
} catch (InstanceNotFoundException e) {
throw new ValidationException(MessageFormat.format(
"There is no label with this code ",
(String) e.getKey()));
}
}
if (workReportDTO.descriptionValues != null
&& !workReportDTO.descriptionValues.isEmpty()) {
workReport
.setDescriptionValues(toEntity(workReportDTO.descriptionValues));
}
return workReport;
}