From 310978d2b0d9343173f9823399dcf077a50831f7 Mon Sep 17 00:00:00 2001 From: IamMujuziMoses Date: Fri, 29 Mar 2024 23:10:02 +0300 Subject: [PATCH] O3-2454: Queue Module - allow nullable location and service on queue. --- .../org/openmrs/module/queue/model/Queue.java | 4 ++-- .../queue/validators/QueueValidator.java | 13 ++++++------ api/src/main/resources/liquibase.xml | 20 +++++++++++++------ .../queue/validators/QueueValidatorTest.java | 17 ++++++++++++++++ 4 files changed, 39 insertions(+), 15 deletions(-) diff --git a/api/src/main/java/org/openmrs/module/queue/model/Queue.java b/api/src/main/java/org/openmrs/module/queue/model/Queue.java index 6dcc0631..81f9acfa 100644 --- a/api/src/main/java/org/openmrs/module/queue/model/Queue.java +++ b/api/src/main/java/org/openmrs/module/queue/model/Queue.java @@ -50,11 +50,11 @@ public class Queue extends BaseChangeableOpenmrsMetadata { private Integer queueId; @ManyToOne - @JoinColumn(name = "location_id", nullable = false) + @JoinColumn(name = "location_id") private Location location; @ManyToOne - @JoinColumn(name = "service", referencedColumnName = "concept_id", nullable = false) + @JoinColumn(name = "service", referencedColumnName = "concept_id") private Concept service; @ManyToOne diff --git a/api/src/main/java/org/openmrs/module/queue/validators/QueueValidator.java b/api/src/main/java/org/openmrs/module/queue/validators/QueueValidator.java index 32d53290..6ee3b287 100644 --- a/api/src/main/java/org/openmrs/module/queue/validators/QueueValidator.java +++ b/api/src/main/java/org/openmrs/module/queue/validators/QueueValidator.java @@ -39,18 +39,17 @@ public void validate(Object target, Errors errors) { } Queue queue = (Queue) target; ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "queue.name.null", "Queue name can't be null"); - ValidationUtils.rejectIfEmptyOrWhitespace(errors, "location", "queue.location.null", "Location can't be null"); // TODO: Check if the location is tagged as a Queue Location? QueueServicesWrapper queueServices = Context.getRegisteredComponents(QueueServicesWrapper.class).get(0); if (queue.getService() == null) { - errors.rejectValue("service", "QueueEntry.service.null", "The property service should not be null"); - } else { - if (!queueServices.getAllowedServices().contains(queue.getService())) { - errors.rejectValue("service", "Queue.service.invalid", - "The property service should be a member of configured queue service conceptSet."); - } + return; + } + + if (!queueServices.getAllowedServices().contains(queue.getService())) { + errors.rejectValue("service", "Queue.service.invalid", + "The property service should be a member of configured queue service conceptSet."); } } } diff --git a/api/src/main/resources/liquibase.xml b/api/src/main/resources/liquibase.xml index 27e2e7cb..36087217 100644 --- a/api/src/main/resources/liquibase.xml +++ b/api/src/main/resources/liquibase.xml @@ -26,12 +26,8 @@ - - - - - - + + @@ -460,4 +456,16 @@ + + + + + + + Drop Not-Null constraint from columns queue.location_id and queue.service + + + + + diff --git a/integration-tests/src/test/java/org/openmrs/module/queue/validators/QueueValidatorTest.java b/integration-tests/src/test/java/org/openmrs/module/queue/validators/QueueValidatorTest.java index d9de2984..f4f6d5fd 100644 --- a/integration-tests/src/test/java/org/openmrs/module/queue/validators/QueueValidatorTest.java +++ b/integration-tests/src/test/java/org/openmrs/module/queue/validators/QueueValidatorTest.java @@ -10,9 +10,11 @@ package org.openmrs.module.queue.validators; import static org.hamcrest.Matchers.equalTo; +import static org.junit.Assert.assertNull; import static org.junit.Assert.assertThat; import org.junit.Before; +import org.junit.Ignore; import org.junit.Test; import org.openmrs.api.context.Context; import org.openmrs.module.queue.SpringTestConfiguration; @@ -22,6 +24,7 @@ import org.springframework.test.context.ContextConfiguration; import org.springframework.validation.BindException; import org.springframework.validation.Errors; +import org.springframework.validation.FieldError; @ContextConfiguration(classes = SpringTestConfiguration.class, inheritLocations = false) public class QueueValidatorTest extends BaseModuleContextSensitiveTest { @@ -83,6 +86,7 @@ public void shouldSucceedForValidLocation() { } @Test + @Ignore("O3-2454: Allow nullable location and service on queue") public void shouldFailForInvalidLocation() { queue.setName("Test Queue"); queue.setLocation(Context.getLocationService().getLocationByUuid(BAD_LOCATION_UUID)); @@ -90,4 +94,17 @@ public void shouldFailForInvalidLocation() { validator.validate(queue, errors); assertThat(errors.getAllErrors().size(), equalTo(1)); } + + @Test + public void shouldSucceedForNullServiceConceptAndLocation() { + queue.setName("Test Queue"); + queue.setLocation(null); + queue.setService(null); + validator.validate(queue, errors); + + FieldError queueServiceFieldError = errors.getFieldError("service"); + FieldError queueLocationFieldError = errors.getFieldError("location"); + assertNull(queueServiceFieldError); + assertNull(queueLocationFieldError); + } }