Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public QueueEntry transitionQueueEntry(QueueEntryTransition queueEntryTransition
queueEntryToStop.setEndedAt(queueEntryTransition.getTransitionDate());
boolean updated = dao.updateIfUnmodified(queueEntryToStop, expectedDateChanged);
if (!updated) {
throw new IllegalStateException("Queue entry was modified by another transaction");
throw new APIException("queue.entry.error.concurrentModification", new Object[0]);
}

dao.flushSession();
Expand All @@ -139,8 +139,6 @@ public QueueEntry transitionQueueEntry(QueueEntryTransition queueEntryTransition
*/
@Override
public QueueEntry undoTransition(@NotNull QueueEntry queueEntry) {
// TODO: Exceptions should be translatable and human readable on the frontend.
// See: https://openmrs.atlassian.net/browse/O3-2988
if (queueEntry.getId() == null) {
throw new IllegalArgumentException("Cannot undo transition on a queue entry that has not been saved");
}
Comment thread
sanks011 marked this conversation as resolved.
Expand All @@ -167,7 +165,7 @@ public QueueEntry undoTransition(@NotNull QueueEntry queueEntry) {
prevQueueEntry.setEndedAt(null);
boolean updated = dao.updateIfUnmodified(prevQueueEntry, expectedDateChanged);
if (!updated) {
throw new IllegalStateException("Previous queue entry was modified by another transaction");
throw new APIException("queue.entry.error.concurrentModification", new Object[0]);
}

getProxiedQueueEntryService().voidQueueEntry(queueEntry, "Transition undone");
Expand Down Expand Up @@ -290,8 +288,6 @@ public QueueEntry getPreviousQueueEntry(@NotNull QueueEntry queueEntry) {
if (prevQueueEntries.size() == 1) {
return prevQueueEntries.get(0);
} else if (prevQueueEntries.size() > 1) {
// TODO: Exceptions should be translatable and human readable on the frontend.
// See: https://openmrs.atlassian.net/browse/O3-2988
throw new IllegalStateException("Multiple previous queue entries found");
} else {
return null;
Expand Down
1 change: 1 addition & 0 deletions api/src/main/resources/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ queue.entry.duplicate.patient=Patient already in the queue
queue.entry.error.cannotStartBeforeVisitStartDate=Queue entry cannot start before the visit start date
queue.entry.error.cannotStartAfterVisitStopDate=Queue entry cannot start after the visit stop date
queue.entry.error.cannotEndAfterVisitStopDate=Queue entry cannot end after the visit stop date
queue.entry.error.concurrentModification=Queue entry was modified by another transaction. Please refresh and try again.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.openmrs.User;
import org.openmrs.Visit;
import org.openmrs.VisitAttributeType;
import org.openmrs.api.APIException;
import org.openmrs.api.VisitService;
import org.openmrs.api.context.Context;
import org.openmrs.api.context.UserContext;
Expand Down Expand Up @@ -402,7 +403,7 @@ public void shouldThrowWhenUndoingTransitionOnEndedEntry() {
queueEntryService.undoTransition(endedEntry);
}

@Test(expected = IllegalStateException.class)
@Test(expected = APIException.class)
public void shouldThrowWhenTransitioningConcurrentlyModifiedEntry() {
QueueEntry queueEntry = new QueueEntry();
queueEntry.setQueueEntryId(1);
Expand All @@ -420,7 +421,7 @@ public void shouldThrowWhenTransitioningConcurrentlyModifiedEntry() {
queueEntryService.transitionQueueEntry(transition);
}

@Test(expected = IllegalStateException.class)
@Test(expected = APIException.class)
public void shouldThrowWhenUndoingTransitionOnConcurrentlyModifiedPreviousEntry() {
Queue queue1 = new Queue();
Patient patient1 = new Patient();
Expand Down