Skip to content

Commit

Permalink
TRUNK-6223 - RequiredDataAdvice should validate after save handlers e…
Browse files Browse the repository at this point in the history
…xecute (#4559)
  • Loading branch information
mseaton authored Feb 15, 2024
1 parent 4388021 commit 50a61b5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
6 changes: 2 additions & 4 deletions api/src/main/java/org/openmrs/aop/RequiredDataAdvice.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,8 @@ public void before(Method method, Object[] args, Object target) throws Throwable
other = (String) args[1];
}

ValidateUtil.validate(mainArgument);

recursivelyHandle(SaveHandler.class, (OpenmrsObject) mainArgument, other);
ValidateUtil.validate(mainArgument);
}
// if the first argument is a list of openmrs objects, handle them all now
else if (Reflect.isCollection(mainArgument) && isOpenmrsObjectCollection(mainArgument)) {
Expand All @@ -145,9 +144,8 @@ else if (Reflect.isCollection(mainArgument) && isOpenmrsObjectCollection(mainArg
Collection<OpenmrsObject> openmrsObjects = (Collection<OpenmrsObject>) mainArgument;

for (OpenmrsObject object : openmrsObjects) {
ValidateUtil.validate(object);

recursivelyHandle(SaveHandler.class, object, other);
ValidateUtil.validate(object);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@
*/
package org.openmrs.api.handler;

import static org.junit.jupiter.api.Assertions.assertThrows;

import java.util.Date;

import org.junit.jupiter.api.Test;
import org.openmrs.Encounter;
import org.openmrs.Patient;
import org.openmrs.Person;
import org.openmrs.PersonAddress;
import org.openmrs.User;
import org.openmrs.Voidable;
import org.openmrs.api.APIException;
import org.openmrs.api.context.Context;
import org.openmrs.test.jupiter.BaseContextSensitiveTest;

import java.util.Date;

import static org.junit.jupiter.api.Assertions.assertThrows;

/**
* Tests for the {@link RequireVoidReasonSaveHandler} class.
*/
Expand Down Expand Up @@ -77,10 +77,9 @@ public void handle_shouldNotThrowExceptionIfVoidReasonIsNotBlank() {
*/
@Test
public void handle_shouldNotThrowExceptionIfVoidReasonIsNullForUnsupportedTypes() {
Person p = Context.getPersonService().getPerson(1);
p.setVoided(true);
p.setVoidReason(null);
p.setVoidReason("voidReason");
Context.getPersonService().savePerson(p);
PersonAddress pa = Context.getPersonService().getPersonAddressByUuid("3350d0b5-821c-4e5e-ad1d-a9bce331e118");
pa.setVoided(true);
pa.setVoidReason(null);
Context.getPersonService().savePersonAddress(pa);
}
}

0 comments on commit 50a61b5

Please sign in to comment.