fixed bug (#2824)
This commit is contained in:
parent
91bbebad27
commit
92ec113775
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
type: fix
|
||||||
|
issue: 2823
|
||||||
|
title: "Mdm failed to load if any mdm subscription had been deleted, e.g. if $expunge expungeEverything had been run
|
||||||
|
on the server. This has been corrected."
|
|
@ -22,14 +22,15 @@ package ca.uhn.fhir.jpa.mdm.config;
|
||||||
|
|
||||||
import ca.uhn.fhir.context.ConfigurationException;
|
import ca.uhn.fhir.context.ConfigurationException;
|
||||||
import ca.uhn.fhir.context.FhirContext;
|
import ca.uhn.fhir.context.FhirContext;
|
||||||
import ca.uhn.fhir.mdm.api.MdmConstants;
|
|
||||||
import ca.uhn.fhir.mdm.api.IMdmSettings;
|
|
||||||
import ca.uhn.fhir.mdm.log.Logs;
|
|
||||||
import ca.uhn.fhir.jpa.api.dao.DaoRegistry;
|
import ca.uhn.fhir.jpa.api.dao.DaoRegistry;
|
||||||
import ca.uhn.fhir.jpa.api.dao.IFhirResourceDao;
|
import ca.uhn.fhir.jpa.api.dao.IFhirResourceDao;
|
||||||
import ca.uhn.fhir.jpa.dao.index.IdHelperService;
|
import ca.uhn.fhir.jpa.dao.index.IdHelperService;
|
||||||
import ca.uhn.fhir.jpa.subscription.channel.api.ChannelProducerSettings;
|
import ca.uhn.fhir.jpa.subscription.channel.api.ChannelProducerSettings;
|
||||||
import ca.uhn.fhir.jpa.subscription.channel.subscription.IChannelNamer;
|
import ca.uhn.fhir.jpa.subscription.channel.subscription.IChannelNamer;
|
||||||
|
import ca.uhn.fhir.mdm.api.IMdmSettings;
|
||||||
|
import ca.uhn.fhir.mdm.api.MdmConstants;
|
||||||
|
import ca.uhn.fhir.mdm.log.Logs;
|
||||||
|
import ca.uhn.fhir.rest.server.exceptions.ResourceGoneException;
|
||||||
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
|
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
|
||||||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||||
import org.hl7.fhir.r4.model.Subscription;
|
import org.hl7.fhir.r4.model.Subscription;
|
||||||
|
@ -86,10 +87,10 @@ public class MdmSubscriptionLoader {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized void updateIfNotPresent(IBaseResource theSubscription) {
|
synchronized void updateIfNotPresent(IBaseResource theSubscription) {
|
||||||
try {
|
try {
|
||||||
mySubscriptionDao.read(theSubscription.getIdElement());
|
mySubscriptionDao.read(theSubscription.getIdElement());
|
||||||
} catch (ResourceNotFoundException e) {
|
} catch (ResourceNotFoundException | ResourceGoneException e) {
|
||||||
ourLog.info("Creating subsription " + theSubscription.getIdElement());
|
ourLog.info("Creating subsription " + theSubscription.getIdElement());
|
||||||
mySubscriptionDao.update(theSubscription);
|
mySubscriptionDao.update(theSubscription);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,64 @@
|
||||||
|
package ca.uhn.fhir.jpa.mdm.config;
|
||||||
|
|
||||||
|
import ca.uhn.fhir.jpa.api.dao.IFhirResourceDao;
|
||||||
|
import ca.uhn.fhir.rest.server.exceptions.ResourceGoneException;
|
||||||
|
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
|
||||||
|
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||||
|
import org.hl7.fhir.r4.model.IdType;
|
||||||
|
import org.hl7.fhir.r4.model.Subscription;
|
||||||
|
import org.junit.jupiter.api.AfterEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
|
import org.mockito.InjectMocks;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
|
|
||||||
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
|
import static org.mockito.Mockito.never;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
@ExtendWith(MockitoExtension.class)
|
||||||
|
class MdmSubscriptionLoaderTest {
|
||||||
|
@Mock
|
||||||
|
IFhirResourceDao<IBaseResource> mySubscriptionDao;
|
||||||
|
|
||||||
|
@InjectMocks
|
||||||
|
MdmSubscriptionLoader mySvc = new MdmSubscriptionLoader();
|
||||||
|
|
||||||
|
@AfterEach
|
||||||
|
public void after() {
|
||||||
|
verifyNoMoreInteractions(mySubscriptionDao);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void updateIfNotPresent_createSubscriptionIfItWasDeleted() {
|
||||||
|
Subscription subscription = new Subscription();
|
||||||
|
IdType id = new IdType("2401");
|
||||||
|
subscription.setIdElement(id);
|
||||||
|
when(mySubscriptionDao.read(id)).thenThrow(new ResourceGoneException(""));
|
||||||
|
mySvc.updateIfNotPresent(subscription);
|
||||||
|
verify(mySubscriptionDao).update(subscription);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void updateIfNotPresent_createSubscriptionIfItDoesNotExist() {
|
||||||
|
Subscription subscription = new Subscription();
|
||||||
|
IdType id = new IdType("2401");
|
||||||
|
subscription.setIdElement(id);
|
||||||
|
when(mySubscriptionDao.read(id)).thenThrow(new ResourceNotFoundException(""));
|
||||||
|
mySvc.updateIfNotPresent(subscription);
|
||||||
|
verify(mySubscriptionDao).update(subscription);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void updateIfNotPresent_createSubscriptionExists() {
|
||||||
|
Subscription subscription = new Subscription();
|
||||||
|
IdType id = new IdType("2401");
|
||||||
|
subscription.setIdElement(id);
|
||||||
|
when(mySubscriptionDao.read(id)).thenReturn(subscription);
|
||||||
|
mySvc.updateIfNotPresent(subscription);
|
||||||
|
verify(mySubscriptionDao, never()).update(any());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue