Skip to content

Commit

Permalink
O3-2454: Queue Module - allow nullable location and service on queue.
Browse files Browse the repository at this point in the history
  • Loading branch information
IamMujuziMoses committed Mar 29, 2024
1 parent 21c98ae commit a7ebb37
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 16 deletions.
4 changes: 2 additions & 2 deletions api/src/main/java/org/openmrs/module/queue/model/Queue.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,13 @@ 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.");
}
if (queue.getService() != null && !queueServices.getAllowedServices().contains(queue.getService())) {
errors.rejectValue("service", "Queue.service.invalid",
"The property service should be a member of configured queue service conceptSet.");
}
}
}
20 changes: 14 additions & 6 deletions api/src/main/resources/liquibase.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,8 @@
<constraints nullable="false"/>
</column>
<column name="description" type="varchar(255)"/>
<column name="location_id" type="int">
<constraints nullable="false"/>
</column>
<column name="service" type="int">
<constraints nullable="false"/>
</column>
<column name="location_id" type="int"/>
<column name="service" type="int"/>
<column name="creator" type="int">
<constraints nullable="false"/>
</column>
Expand Down Expand Up @@ -460,4 +456,16 @@
</sql>
</changeSet>

<changeSet id="nullable_location_and_service_on_queue_20240329" author="mujuzi">
<preConditions onFail="MARK_RAN">
<columnExists tableName="queue" columnName="location_id"/>
<columnExists tableName="queue" columnName="service"/>
</preConditions>
<comment>
Drop Not-Null constraint from columns queue.location_id and queue.service
</comment>
<dropNotNullConstraint tableName="queue" columnName="location_id" columnDataType="int"/>
<dropNotNullConstraint tableName="queue" columnName="service" columnDataType="int"/>
</changeSet>

</databaseChangeLog>
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -83,11 +86,25 @@ 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));
queue.setService(Context.getConceptService().getConceptByUuid(VALID_SERVICE_CONCEPT));
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);
}
}

0 comments on commit a7ebb37

Please sign in to comment.