From 57b90f49f7258e5a7071e180b4c0b1993fa9d93c Mon Sep 17 00:00:00 2001 From: Manuel Rego Casasnovas Date: Tue, 5 Jun 2012 09:43:23 +0200 Subject: [PATCH] Fix problem in work reports web services If the resource was only set in the work-report and not in every line the service returns an error while updating the work report. FEA: ItEr76S04BugFixing --- .../workreports/impl/WorkReportConverter.java | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/libreplan-webapp/src/main/java/org/libreplan/ws/workreports/impl/WorkReportConverter.java b/libreplan-webapp/src/main/java/org/libreplan/ws/workreports/impl/WorkReportConverter.java index 8881e60f1..5a125365d 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/ws/workreports/impl/WorkReportConverter.java +++ b/libreplan-webapp/src/main/java/org/libreplan/ws/workreports/impl/WorkReportConverter.java @@ -52,6 +52,7 @@ import org.libreplan.ws.workreports.api.OneOrderElementPerWorkReportLine; import org.libreplan.ws.workreports.api.WorkReportDTO; import org.libreplan.ws.workreports.api.WorkReportLineDTO; import org.springframework.transaction.annotation.Transactional; +import org.zkoss.lang.Strings; /** * Converter from/to work report related entities to/from DTOs. @@ -103,7 +104,7 @@ public final class WorkReportConverter { } catch (InstanceNotFoundException e) { workReport.setResource(null); throw new ValidationException( - "There is no resource with this ID"); + "There is no resource with this code"); } } @@ -167,7 +168,7 @@ public final class WorkReportConverter { } catch (InstanceNotFoundException e) { workReportLine.setResource(null); throw new ValidationException( - "There is no resource with this ID"); + "There is no resource with this code"); } } @@ -418,14 +419,14 @@ public final class WorkReportConverter { /* Step 4.2: Update the resource. */ String resourceCode = workReportDTO.resource; - if ((resourceCode != null) && (!resourceCode.isEmpty())) { + if (!Strings.isBlank(resourceCode)) { try { Resource resource = Registry.getResourceDAO().findByCode( resourceCode); workReport.setResource(resource); } catch (InstanceNotFoundException e) { throw new ValidationException( - "There is no resource with this ID"); + "There is no resource with this code"); } } @@ -483,12 +484,15 @@ public final class WorkReportConverter { /* Step 3.2: Update the resource. */ String resourceCode = workReportLineDTO.resource; - try { - Resource resource = Registry.getResourceDAO().findByCode( - resourceCode); - workReportLine.setResource(resource); - } catch (InstanceNotFoundException e) { - throw new ValidationException("There is no resource with this ID"); + if (!Strings.isBlank(resourceCode)) { + try { + Resource resource = Registry.getResourceDAO().findByCode( + resourceCode); + workReportLine.setResource(resource); + } catch (InstanceNotFoundException e) { + throw new ValidationException( + "There is no resource with this code"); + } } /* Step 3.3: Update the order element. */