Merge pull request #1960 from jamesagnew/im_20200630_code_system_load
Accidentally merged pull request before pushing changes from code review
This commit is contained in:
commit
e23e222f80
|
@ -146,7 +146,12 @@ public class TermDeferredStorageSvcImpl implements ITermDeferredStorageSvc {
|
|||
while (codeCount < count && myDeferredConcepts.size() > 0) {
|
||||
TermConcept next = myDeferredConcepts.remove(0);
|
||||
if(myCodeSystemVersionDao.findById(next.getCodeSystemVersion().getPid()).isPresent()) {
|
||||
codeCount += myCodeSystemStorageSvc.saveConcept(next);
|
||||
try {
|
||||
codeCount += myCodeSystemStorageSvc.saveConcept(next);
|
||||
} catch (Exception theE) {
|
||||
ourLog.error("Exception thrown when attempting to save TermConcept {} in Code System {}",
|
||||
next.getCode(), next.getCodeSystemVersion().getCodeSystemDisplayName(), theE);
|
||||
}
|
||||
} else {
|
||||
ourLog.warn("Unable to save deferred TermConcept {} because Code System {} version PID {} is no longer valid. Code system may have since been replaced.",
|
||||
next.getCode(), next.getCodeSystemVersion().getCodeSystemDisplayName(), next.getCodeSystemVersion().getPid());
|
||||
|
|
|
@ -12,6 +12,28 @@ public class TermCodeSystemStorageSvcTest extends BaseJpaR4Test {
|
|||
|
||||
public static final String URL_MY_CODE_SYSTEM = "http://example.com/my_code_system";
|
||||
|
||||
@Test
|
||||
public void testStoreNewCodeSystemVersionForExistingCodeSystem() {
|
||||
CodeSystem upload = createCodeSystemWithMoreThan100Concepts();
|
||||
|
||||
// Create CodeSystem resource
|
||||
ResourceTable codeSystemResourceEntity = (ResourceTable)myCodeSystemDao.create(upload, mySrd).getEntity();
|
||||
|
||||
// Update the CodeSystem resource
|
||||
runInTransaction(() -> myTermCodeSystemStorageSvc.storeNewCodeSystemVersionIfNeeded(upload, codeSystemResourceEntity));
|
||||
|
||||
/*
|
||||
Because there are more than 100 concepts in the code system, the first 100 will be persisted immediately and
|
||||
the remaining 25 concepts will be queued up for "deferred save".
|
||||
|
||||
As the CodeSystem was persisted twice, the extra 25 term concepts will be queued twice, each with a different
|
||||
CodeSystem version PID. Only one set of the term concepts should be persisted (i.e. 125 term concepts in total).
|
||||
*/
|
||||
myTerminologyDeferredStorageSvc.setProcessDeferred(true);
|
||||
myTerminologyDeferredStorageSvc.saveDeferred();
|
||||
assertEquals(125, myTermConceptDao.count());
|
||||
}
|
||||
|
||||
private CodeSystem createCodeSystemWithMoreThan100Concepts() {
|
||||
CodeSystem codeSystem = new CodeSystem();
|
||||
codeSystem.setUrl(URL_MY_CODE_SYSTEM);
|
||||
|
@ -25,20 +47,5 @@ public class TermCodeSystemStorageSvcTest extends BaseJpaR4Test {
|
|||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStoreNewCodeSystemVersionForExistingCodeSystem() {
|
||||
CodeSystem upload = createCodeSystemWithMoreThan100Concepts();
|
||||
|
||||
ResourceTable codeSystemResourceEntity = (ResourceTable)myCodeSystemDao.create(upload, mySrd).getEntity();
|
||||
|
||||
runInTransaction(() -> myTermCodeSystemStorageSvc.storeNewCodeSystemVersionIfNeeded(upload, codeSystemResourceEntity));
|
||||
|
||||
myTerminologyDeferredStorageSvc.setProcessDeferred(true);
|
||||
myTerminologyDeferredStorageSvc.saveDeferred();
|
||||
myTerminologyDeferredStorageSvc.saveDeferred();
|
||||
|
||||
assertEquals(125, myTermConceptDao.count());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -21,7 +21,6 @@ import static org.mockito.Mockito.*;
|
|||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class TermDeferredStorageSvcImplTest {
|
||||
|
||||
|
||||
@Mock
|
||||
private PlatformTransactionManager myTxManager;
|
||||
@Mock
|
||||
|
@ -69,6 +68,7 @@ public class TermDeferredStorageSvcImplTest {
|
|||
concept.setCode("CODE_A");
|
||||
|
||||
TermCodeSystemVersion myTermCodeSystemVersion = new TermCodeSystemVersion();
|
||||
myTermCodeSystemVersion.setId(1L);
|
||||
concept.setCodeSystemVersion(myTermCodeSystemVersion);
|
||||
|
||||
TermDeferredStorageSvcImpl svc = new TermDeferredStorageSvcImpl();
|
||||
|
@ -76,15 +76,45 @@ public class TermDeferredStorageSvcImplTest {
|
|||
svc.setCodeSystemStorageSvcForUnitTest(myTermConceptStorageSvc);
|
||||
svc.setDaoConfigForUnitTest(new DaoConfig());
|
||||
|
||||
when(myTermCodeSystemVersionDao.findById(anyLong())).thenReturn(Optional.empty());
|
||||
svc.setCodeSystemVersionDaoForUnitTest(myTermCodeSystemVersionDao);
|
||||
svc.setProcessDeferred(true);
|
||||
svc.addConceptToStorageQueue(concept);
|
||||
svc.saveDeferred();
|
||||
|
||||
verify(myTermConceptStorageSvc, times(0)).saveConcept(same(concept));
|
||||
verifyNoMoreInteractions(myTermConceptStorageSvc);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSaveDeferred_Concept_Exception() {
|
||||
// There is a small
|
||||
TermConcept concept = new TermConcept();
|
||||
concept.setCode("CODE_A");
|
||||
|
||||
TermCodeSystemVersion myTermCodeSystemVersion = new TermCodeSystemVersion();
|
||||
myTermCodeSystemVersion.setId(1L);
|
||||
concept.setCodeSystemVersion(myTermCodeSystemVersion);
|
||||
|
||||
TermDeferredStorageSvcImpl svc = new TermDeferredStorageSvcImpl();
|
||||
svc.setTransactionManagerForUnitTest(myTxManager);
|
||||
svc.setCodeSystemStorageSvcForUnitTest(myTermConceptStorageSvc);
|
||||
svc.setDaoConfigForUnitTest(new DaoConfig());
|
||||
|
||||
// Simulate the case where an exception is thrown despite a valid code system version.
|
||||
when(myTermCodeSystemVersionDao.findById(anyLong())).thenReturn(Optional.of(myTermCodeSystemVersion));
|
||||
when(myTermConceptStorageSvc.saveConcept(concept)).thenThrow(new RuntimeException("Foreign Constraint Violation"));
|
||||
svc.setCodeSystemVersionDaoForUnitTest(myTermCodeSystemVersionDao);
|
||||
svc.setProcessDeferred(true);
|
||||
svc.addConceptToStorageQueue(concept);
|
||||
svc.saveDeferred();
|
||||
|
||||
verify(myTermConceptStorageSvc, times(1)).saveConcept(same(concept));
|
||||
verifyNoMoreInteractions(myTermConceptStorageSvc);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSaveDeferred_ConceptParentChildLink_ConceptsMissing() {
|
||||
TermConceptParentChildLink conceptLink = new TermConceptParentChildLink();
|
||||
|
|
Loading…
Reference in New Issue