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.
This commit is contained in:
parent
e4bb249550
commit
ec0da2601e
3 changed files with 17 additions and 4 deletions
|
|
@ -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);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<ResourceDTO> resources = new ArrayList<ResourceDTO>();
|
||||
resources.add(m1);
|
||||
|
|
|
|||
|
|
@ -25,6 +25,6 @@
|
|||
</criterion-satisfaction-list>
|
||||
</worker>
|
||||
<!-- Missing first name, surname, and nif. -->
|
||||
<worker first-name="" surname="" nif=""/>
|
||||
<worker first-name="" nif=""/>
|
||||
|
||||
</resource-list>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue