Changes from code review
This commit is contained in:
parent
4e5ca2ee15
commit
b1ff6cbe37
|
@ -50,7 +50,6 @@ import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.transaction.support.TransactionTemplate;
|
import org.springframework.transaction.support.TransactionTemplate;
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -146,10 +145,15 @@ public class TermDeferredStorageSvcImpl implements ITermDeferredStorageSvc {
|
||||||
ourLog.info("Saving {} deferred concepts...", count);
|
ourLog.info("Saving {} deferred concepts...", count);
|
||||||
while (codeCount < count && myDeferredConcepts.size() > 0) {
|
while (codeCount < count && myDeferredConcepts.size() > 0) {
|
||||||
TermConcept next = myDeferredConcepts.remove(0);
|
TermConcept next = myDeferredConcepts.remove(0);
|
||||||
try {
|
if(myCodeSystemVersionDao.findById(next.getCodeSystemVersion().getPid()).isPresent()) {
|
||||||
codeCount += myCodeSystemStorageSvc.saveConcept(next);
|
try {
|
||||||
} catch (Exception theE) {
|
codeCount += myCodeSystemStorageSvc.saveConcept(next);
|
||||||
ourLog.warn("Unable to save deferred TermConcept {}, possibly because Code System {} version PID {} may have since been replaced.",
|
} 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());
|
next.getCode(), next.getCodeSystemVersion().getCodeSystemDisplayName(), next.getCodeSystemVersion().getPid());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,8 @@ import org.mockito.Mock;
|
||||||
import org.mockito.junit.MockitoJUnitRunner;
|
import org.mockito.junit.MockitoJUnitRunner;
|
||||||
import org.springframework.transaction.PlatformTransactionManager;
|
import org.springframework.transaction.PlatformTransactionManager;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
import static org.mockito.ArgumentMatchers.same;
|
import static org.mockito.ArgumentMatchers.same;
|
||||||
import static org.mockito.Mockito.*;
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
|
@ -50,6 +52,7 @@ public class TermDeferredStorageSvcImplTest {
|
||||||
svc.setCodeSystemStorageSvcForUnitTest(myTermConceptStorageSvc);
|
svc.setCodeSystemStorageSvcForUnitTest(myTermConceptStorageSvc);
|
||||||
svc.setDaoConfigForUnitTest(new DaoConfig());
|
svc.setDaoConfigForUnitTest(new DaoConfig());
|
||||||
|
|
||||||
|
when(myTermCodeSystemVersionDao.findById(anyLong())).thenReturn(Optional.of(myTermCodeSystemVersion));
|
||||||
svc.setCodeSystemVersionDaoForUnitTest(myTermCodeSystemVersionDao);
|
svc.setCodeSystemVersionDaoForUnitTest(myTermCodeSystemVersionDao);
|
||||||
svc.setProcessDeferred(true);
|
svc.setProcessDeferred(true);
|
||||||
svc.addConceptToStorageQueue(concept);
|
svc.addConceptToStorageQueue(concept);
|
||||||
|
@ -65,6 +68,7 @@ public class TermDeferredStorageSvcImplTest {
|
||||||
concept.setCode("CODE_A");
|
concept.setCode("CODE_A");
|
||||||
|
|
||||||
TermCodeSystemVersion myTermCodeSystemVersion = new TermCodeSystemVersion();
|
TermCodeSystemVersion myTermCodeSystemVersion = new TermCodeSystemVersion();
|
||||||
|
myTermCodeSystemVersion.setId(1L);
|
||||||
concept.setCodeSystemVersion(myTermCodeSystemVersion);
|
concept.setCodeSystemVersion(myTermCodeSystemVersion);
|
||||||
|
|
||||||
TermDeferredStorageSvcImpl svc = new TermDeferredStorageSvcImpl();
|
TermDeferredStorageSvcImpl svc = new TermDeferredStorageSvcImpl();
|
||||||
|
@ -72,6 +76,34 @@ public class TermDeferredStorageSvcImplTest {
|
||||||
svc.setCodeSystemStorageSvcForUnitTest(myTermConceptStorageSvc);
|
svc.setCodeSystemStorageSvcForUnitTest(myTermConceptStorageSvc);
|
||||||
svc.setDaoConfigForUnitTest(new DaoConfig());
|
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"));
|
when(myTermConceptStorageSvc.saveConcept(concept)).thenThrow(new RuntimeException("Foreign Constraint Violation"));
|
||||||
svc.setCodeSystemVersionDaoForUnitTest(myTermCodeSystemVersionDao);
|
svc.setCodeSystemVersionDaoForUnitTest(myTermCodeSystemVersionDao);
|
||||||
svc.setProcessDeferred(true);
|
svc.setProcessDeferred(true);
|
||||||
|
|
Loading…
Reference in New Issue