issue-2901 removing cruft and cleaning up

This commit is contained in:
leif stawnyczy 2021-09-02 11:07:06 -04:00
parent 1a7b101d03
commit cbfcc02a92
8 changed files with 54 additions and 14 deletions

View File

@ -18,7 +18,7 @@ public class AutoVersioningServiceImpl implements IAutoVersioningService {
private DaoRegistry myDaoRegistry;
@Override
public Map<IIdType, ResourcePersistentId> getAutoversionsForIds(Collection<IIdType> theIds) {
public Map<IIdType, ResourcePersistentId> getExistingAutoversionsForIds(Collection<IIdType> theIds) {
HashMap<IIdType, ResourcePersistentId> idToPID = new HashMap<>();
HashMap<String, List<IIdType>> resourceTypeToIds = new HashMap<>();

View File

@ -209,7 +209,7 @@ public abstract class BaseStorageDao {
IIdType referenceElement = nextReference.getReferenceElement();
if (!referenceElement.hasBaseUrl()) {
Map<IIdType, ResourcePersistentId> idToPID = myAutoVersioningService.getAutoversionsForIds(
Map<IIdType, ResourcePersistentId> idToPID = myAutoVersioningService.getExistingAutoversionsForIds(
Collections.singletonList(referenceElement)
);

View File

@ -117,7 +117,6 @@ import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.TreeSet;
import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
@ -1269,7 +1268,7 @@ public abstract class BaseTransactionProcessor {
} else {
// get a map of
// existing ids -> PID (for resources that exist in the DB)
Map<IIdType, ResourcePersistentId> idToPID = myAutoVersioningService.getAutoversionsForIds(theReferencesToAutoVersion.stream()
Map<IIdType, ResourcePersistentId> idToPID = myAutoVersioningService.getExistingAutoversionsForIds(theReferencesToAutoVersion.stream()
.map(ref -> ref.getReferenceElement()).collect(Collectors.toList()));
for (IBaseReference baseRef : theReferencesToAutoVersion) {

View File

@ -19,5 +19,5 @@ public interface IAutoVersioningService {
* @param theIds
* @return
*/
Map<IIdType, ResourcePersistentId> getAutoversionsForIds(Collection<IIdType> theIds);
Map<IIdType, ResourcePersistentId> getExistingAutoversionsForIds(Collection<IIdType> theIds);
}

View File

@ -111,6 +111,15 @@ public interface IForcedIdDao extends JpaRepository<ForcedId, Long> {
"WHERE f.myResourceType = :resource_type AND f.myForcedId IN ( :forced_id )")
Collection<Object[]> findAndResolveByForcedIdWithNoType(@Param("resource_type") String theResourceType, @Param("forced_id") Collection<String> theForcedIds);
/**
* This method returns a collection where eah row is an element in the collection.
* Each element in the collection is an object array where order matters.
* The returned order of each object array element is:
* ResourceType (Patient, etc - String), ForcedId (String), ResourcePID (Long), Version (Long)
* @param theResourceType
* @param theForcedIds
* @return
*/
@Query("" +
"SELECT " +
" f.myResourceType, f.myForcedId, f.myResourcePid, t.myVersion " +

View File

@ -13,7 +13,7 @@ import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.jupiter.MockitoExtension;
import java.util.Collection;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@ -38,8 +38,10 @@ public class AutoVersioningServiceImplTests {
IFhirResourceDao daoMock = Mockito.mock(IFhirResourceDao.class);
Mockito.when(daoMock.getIdsOfExistingResources(Mockito.anyList()))
.thenReturn(map);
Mockito.when(daoRegistry.getResourceDao(Mockito.anyString()))
.thenReturn(daoMock);
Map<IIdType, ResourcePersistentId> retMap = myAutoversioningService.getAutoversionsForIds(Collections.singletonList(type));
Map<IIdType, ResourcePersistentId> retMap = myAutoversioningService.getExistingAutoversionsForIds(Collections.singletonList(type));
Assertions.assertTrue(retMap.containsKey(type));
Assertions.assertEquals(pid.getVersion(), map.get(type).getVersion());
@ -52,11 +54,38 @@ public class AutoVersioningServiceImplTests {
IFhirResourceDao daoMock = Mockito.mock(IFhirResourceDao.class);
Mockito.when(daoMock.getIdsOfExistingResources(Mockito.anyList()))
.thenReturn(new HashMap<>());
Mockito.when(daoRegistry.getResourceDao(Mockito.anyString()))
.thenReturn(daoMock);
Map<IIdType, ResourcePersistentId> retMap = myAutoversioningService.getAutoversionsForIds(Collections.singletonList(type));
Map<IIdType, ResourcePersistentId> retMap = myAutoversioningService.getExistingAutoversionsForIds(Collections.singletonList(type));
Assertions.assertTrue(retMap.isEmpty());
}
@Test
public void getAutoversionsForIds_whenSomeResourcesDoNotExist_returnsOnlyExistingElements() {
IIdType type = new IdDt("Patient/RED");
ResourcePersistentId pid = new ResourcePersistentId(1);
pid.setVersion(2L);
HashMap<IIdType, ResourcePersistentId> map = new HashMap<>();
map.put(type, pid);
IIdType type2 = new IdDt("Patient/BLUE");
// when
IFhirResourceDao daoMock = Mockito.mock(IFhirResourceDao.class);
Mockito.when(daoMock.getIdsOfExistingResources(Mockito.anyList()))
.thenReturn(map);
Mockito.when(daoRegistry.getResourceDao(Mockito.anyString()))
.thenReturn(daoMock);
// test
Map<IIdType, ResourcePersistentId> retMap = myAutoversioningService.getExistingAutoversionsForIds(
Arrays.asList(type, type2)
);
// verify
Assertions.assertEquals(map.size(), retMap.size());
Assertions.assertTrue(retMap.containsKey(type));
Assertions.assertFalse(retMap.containsKey(type2));
}
}

View File

@ -34,6 +34,7 @@ import static org.junit.jupiter.api.Assertions.fail;
@ExtendWith(MockitoExtension.class)
class BaseHapiFhirResourceDaoTest {
// our simple concrete test class for BaseHapiFhirResourceDao
private class SimpleTestDao extends BaseHapiFhirResourceDao<Patient> {
public SimpleTestDao() {
super();
@ -58,6 +59,14 @@ class BaseHapiFhirResourceDaoTest {
//TODO - all other dependency mocks
/**
* Creates a match entry to be returned by myIForcedIdDao.
* This ordering matters (see IForcedIdDao)
* @param theId
* @param thePID
* @param theResourceVersion
* @return
*/
private Object[] createMatchEntryForGetIdsOfExistingResources(IIdType theId, long thePID, long theResourceVersion) {
Object[] arr = new Object[] {
theId.getResourceType(),

View File

@ -25,7 +25,6 @@ import org.hl7.fhir.r4.model.Reference;
import org.hl7.fhir.r4.model.Task;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import java.util.List;
@ -598,9 +597,7 @@ public class FhirResourceDaoCreatePlaceholdersR4Test extends BaseJpaR4Test {
// create
Patient patient = new Patient();
// patient.setId(patientId);
patient.setIdElement(new IdType(patientId));
// patient.setActive(true);
myPatientDao.update(patient);
// update
@ -624,7 +621,4 @@ public class FhirResourceDaoCreatePlaceholdersR4Test extends BaseJpaR4Test {
Observation retObservation = myObservationDao.read(obs.getIdElement());
Assertions.assertTrue(retObservation != null);
}
// always work with the put
// conditional create (replace put with conditional create?)
}