One more bugfix

This commit is contained in:
jamesagnew 2020-04-22 09:08:46 -04:00
parent 8a2b799df0
commit be5f8191dc
5 changed files with 32 additions and 15 deletions

View File

@ -174,7 +174,7 @@ public class JpaServerDemo extends RestfulServer {
DaoRegistry daoRegistry = myAppCtx.getBean(DaoRegistry.class);
IInterceptorBroadcaster interceptorBroadcaster = myAppCtx.getBean(IInterceptorBroadcaster.class);
CascadingDeleteInterceptor cascadingDeleteInterceptor = new CascadingDeleteInterceptor(daoRegistry, interceptorBroadcaster);
CascadingDeleteInterceptor cascadingDeleteInterceptor = new CascadingDeleteInterceptor(ctx, daoRegistry, interceptorBroadcaster);
getInterceptorService().registerInterceptor(cascadingDeleteInterceptor);
}

View File

@ -33,7 +33,6 @@ import ca.uhn.fhir.jpa.api.model.DeleteConflictList;
import ca.uhn.fhir.jpa.delete.DeleteConflictOutcome;
import ca.uhn.fhir.jpa.util.JpaInterceptorBroadcaster;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.rest.api.Constants;
import ca.uhn.fhir.rest.api.DeleteCascadeModeEnum;
import ca.uhn.fhir.rest.api.server.RequestDetails;
import ca.uhn.fhir.rest.api.server.ResponseDetails;
@ -49,10 +48,7 @@ import org.slf4j.LoggerFactory;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.validation.constraints.Null;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import static ca.uhn.fhir.jpa.delete.DeleteConflictService.MAX_RETRY_ATTEMPTS;
@ -80,17 +76,21 @@ public class CascadingDeleteInterceptor {
private final DaoRegistry myDaoRegistry;
private final IInterceptorBroadcaster myInterceptorBroadcaster;
private final FhirContext myFhirContext;
/**
* Constructor
*
* @param theDaoRegistry The DAO registry (must not be null)
*/
public CascadingDeleteInterceptor(DaoRegistry theDaoRegistry, IInterceptorBroadcaster theInterceptorBroadcaster) {
public CascadingDeleteInterceptor(@Nonnull FhirContext theFhirContext, @Nonnull DaoRegistry theDaoRegistry, @Nonnull IInterceptorBroadcaster theInterceptorBroadcaster) {
Validate.notNull(theDaoRegistry, "theDaoRegistry must not be null");
Validate.notNull(theInterceptorBroadcaster, "theInterceptorBroadcaster must not be null");
Validate.notNull(theFhirContext, "theFhirContext must not be null");
myDaoRegistry = theDaoRegistry;
myInterceptorBroadcaster = theInterceptorBroadcaster;
myFhirContext = theFhirContext;
}
@Hook(Pointcut.STORAGE_PRESTORAGE_DELETE_CONFLICTS)
@ -100,15 +100,18 @@ public class CascadingDeleteInterceptor {
if (shouldCascade(theRequest) == DeleteCascadeModeEnum.NONE) {
// Add a message to the response
String message = theRequest.getFhirContext().getLocalizer().getMessage(CascadingDeleteInterceptor.class, "noParam");
theRequest.getUserData().put(CASCADED_DELETES_FAILED_KEY, message);
String message = myFhirContext.getLocalizer().getMessage(CascadingDeleteInterceptor.class, "noParam");
ourLog.trace(message);
if (theRequest != null) {
theRequest.getUserData().put(CASCADED_DELETES_FAILED_KEY, message);
}
return null;
}
List<String> cascadedDeletes = getCascadedDeletesMap(theRequest, true);
for (Iterator<DeleteConflict> iter = theConflictList.iterator(); iter.hasNext(); ) {
DeleteConflict next = iter.next();
for (DeleteConflict next : theConflictList) {
IdDt nextSource = next.getSourceId();
String nextSourceId = nextSource.toUnqualifiedVersionless().getValue();

View File

@ -519,7 +519,7 @@ public class AuthorizationInterceptorResourceProviderR4Test extends BaseResource
@Test
public void testDeleteCascadeBlocked() {
CascadingDeleteInterceptor cascadingDeleteInterceptor = new CascadingDeleteInterceptor(myDaoRegistry, myInterceptorRegistry);
CascadingDeleteInterceptor cascadingDeleteInterceptor = new CascadingDeleteInterceptor(myFhirCtx, myDaoRegistry, myInterceptorRegistry);
ourRestServer.getInterceptorService().registerInterceptor(cascadingDeleteInterceptor);
try {
@ -563,7 +563,7 @@ public class AuthorizationInterceptorResourceProviderR4Test extends BaseResource
@Test
public void testDeleteCascadeAllowed() {
CascadingDeleteInterceptor cascadingDeleteInterceptor = new CascadingDeleteInterceptor(myDaoRegistry, myInterceptorRegistry);
CascadingDeleteInterceptor cascadingDeleteInterceptor = new CascadingDeleteInterceptor(myFhirCtx, myDaoRegistry, myInterceptorRegistry);
ourRestServer.getInterceptorService().registerInterceptor(cascadingDeleteInterceptor);
try {
@ -602,7 +602,7 @@ public class AuthorizationInterceptorResourceProviderR4Test extends BaseResource
@Test
public void testDeleteCascadeAllowed_ButNotOnTargetType() {
CascadingDeleteInterceptor cascadingDeleteInterceptor = new CascadingDeleteInterceptor(myDaoRegistry, myInterceptorRegistry);
CascadingDeleteInterceptor cascadingDeleteInterceptor = new CascadingDeleteInterceptor(myFhirCtx, myDaoRegistry, myInterceptorRegistry);
ourRestServer.getInterceptorService().registerInterceptor(cascadingDeleteInterceptor);
try {

View File

@ -45,7 +45,7 @@ public class CascadingDeleteInterceptorR4Test extends BaseResourceProviderR4Test
public void before() throws Exception {
super.before();
myDeleteInterceptor = new CascadingDeleteInterceptor(myDaoRegistry, myInterceptorBroadcaster);
myDeleteInterceptor = new CascadingDeleteInterceptor(myFhirCtx, myDaoRegistry, myInterceptorBroadcaster);
}
@Override
@ -100,6 +100,20 @@ public class CascadingDeleteInterceptorR4Test extends BaseResourceProviderR4Test
}
}
@Test
public void testDeleteWithNoRequestObject() {
createResources();
myInterceptorRegistry.registerInterceptor(myDeleteInterceptor);
try {
myPatientDao.delete(myPatientId);
fail();
} catch (ResourceVersionConflictException e) {
assertThat(e.getMessage(), containsString("because at least one resource has a reference to this resource"));
}
}
@Test
public void testDeleteWithInterceptorAndConstraints() {
createResources();

View File

@ -256,7 +256,7 @@ public class TestRestfulServer extends RestfulServer {
*/
DaoRegistry daoRegistry = myAppCtx.getBean(DaoRegistry.class);
IInterceptorBroadcaster interceptorBroadcaster = myAppCtx.getBean(IInterceptorBroadcaster.class);
CascadingDeleteInterceptor cascadingDeleteInterceptor = new CascadingDeleteInterceptor(daoRegistry, interceptorBroadcaster);
CascadingDeleteInterceptor cascadingDeleteInterceptor = new CascadingDeleteInterceptor(ctx, daoRegistry, interceptorBroadcaster);
registerInterceptor(cascadingDeleteInterceptor);
/*