From ec0da2601e2ae9a5204d08a38162873c91158173 Mon Sep 17 00:00:00 2001 From: Fernando Bellas Permuy Date: Wed, 30 Dec 2009 10:44:40 +0100 Subject: [PATCH] ItEr41S15CUImportacionRecursosProductivosItEr40S20: Bug fixed when firstName, surname or nif are null in a worker to be imported with the REST service. Bug fixed when firstName, surname or nif are null in a worker to be imported with the REST service. Now, Worker::checkConstraintUniqueFirstName checks if such fields are null. --- .../business/resources/entities/Worker.java | 15 ++++++++++++++- .../ws/resources/api/ResourceServiceTest.java | 4 ++-- scripts/rest-clients/resources-sample.xml | 2 +- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/navalplanner-business/src/main/java/org/navalplanner/business/resources/entities/Worker.java b/navalplanner-business/src/main/java/org/navalplanner/business/resources/entities/Worker.java index fbf81b8e7..4051c2a8f 100644 --- a/navalplanner-business/src/main/java/org/navalplanner/business/resources/entities/Worker.java +++ b/navalplanner-business/src/main/java/org/navalplanner/business/resources/entities/Worker.java @@ -26,6 +26,7 @@ import java.util.List; import org.hibernate.validator.AssertTrue; import org.hibernate.validator.NotEmpty; import org.navalplanner.business.common.Registry; +import org.navalplanner.business.common.StringUtils; /** * This class models a worker. @@ -127,9 +128,13 @@ public class Worker extends Resource { return !isVirtual(); } - @AssertTrue(message = "Worker with the same firstname, surname and nif previously existed") + @AssertTrue(message = "Worker with the same first name, surname and nif previously existed") public boolean checkConstraintUniqueFirstName() { + if (!firstLevelValidationsPassed()) { + return true; + } + if (this instanceof VirtualWorker) { return true; } @@ -146,4 +151,12 @@ public class Worker extends Resource { } + private boolean firstLevelValidationsPassed() { + + return !StringUtils.isEmpty(firstName) && + !StringUtils.isEmpty(surname) && + !StringUtils.isEmpty(nif); + + } + } diff --git a/navalplanner-webapp/src/test/java/org/navalplanner/web/test/ws/resources/api/ResourceServiceTest.java b/navalplanner-webapp/src/test/java/org/navalplanner/web/test/ws/resources/api/ResourceServiceTest.java index 14f5f1159..b27b28c3c 100644 --- a/navalplanner-webapp/src/test/java/org/navalplanner/web/test/ws/resources/api/ResourceServiceTest.java +++ b/navalplanner-webapp/src/test/java/org/navalplanner/web/test/ws/resources/api/ResourceServiceTest.java @@ -94,8 +94,8 @@ public class ResourceServiceTest { // optional). String w1Nif = getUniqueName(); WorkerDTO w1 = new WorkerDTO("w1-first-name", "w1-surname", w1Nif); - WorkerDTO w2 = new WorkerDTO("", "", ""); // Missing first name, - // surname, and nif. + WorkerDTO w2 = new WorkerDTO("", null, ""); // Missing first name, + // surname, and nif. List resources = new ArrayList(); resources.add(m1); diff --git a/scripts/rest-clients/resources-sample.xml b/scripts/rest-clients/resources-sample.xml index aaa157b54..ffeb16b5f 100644 --- a/scripts/rest-clients/resources-sample.xml +++ b/scripts/rest-clients/resources-sample.xml @@ -25,6 +25,6 @@ - +