package loader npe (#4186)
* begin with failing test * fixed * change log * change log Co-authored-by: Ken Stevens <ken@smilecdr.com>
This commit is contained in:
parent
929767a09b
commit
a824ba263b
|
@ -0,0 +1,6 @@
|
||||||
|
---
|
||||||
|
type: fix
|
||||||
|
issue: 4185
|
||||||
|
jira: SMILE-5340
|
||||||
|
title: "When DaoConfig UpdateWithHistoryRewriteEnabled is enabled, the package loader throws a NullPointerException.
|
||||||
|
This has been corrected."
|
|
@ -114,7 +114,6 @@ import ca.uhn.fhir.validation.IValidatorModule;
|
||||||
import ca.uhn.fhir.validation.ValidationOptions;
|
import ca.uhn.fhir.validation.ValidationOptions;
|
||||||
import ca.uhn.fhir.validation.ValidationResult;
|
import ca.uhn.fhir.validation.ValidationResult;
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
import com.google.gson.Gson;
|
|
||||||
import org.apache.commons.lang3.Validate;
|
import org.apache.commons.lang3.Validate;
|
||||||
import org.hl7.fhir.instance.model.api.IBaseCoding;
|
import org.hl7.fhir.instance.model.api.IBaseCoding;
|
||||||
import org.hl7.fhir.instance.model.api.IBaseMetaType;
|
import org.hl7.fhir.instance.model.api.IBaseMetaType;
|
||||||
|
@ -1686,7 +1685,7 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
|
||||||
Runnable onRollback = () -> theResource.getIdElement().setValue(id);
|
Runnable onRollback = () -> theResource.getIdElement().setValue(id);
|
||||||
|
|
||||||
// Execute the update in a retryable transaction
|
// Execute the update in a retryable transaction
|
||||||
if (myDaoConfig.isUpdateWithHistoryRewriteEnabled() && theRequest.isRewriteHistory()) {
|
if (myDaoConfig.isUpdateWithHistoryRewriteEnabled() && theRequest != null && theRequest.isRewriteHistory()) {
|
||||||
return myTransactionService.execute(theRequest, theTransactionDetails, tx -> doUpdateWithHistoryRewrite(theResource, theRequest, theTransactionDetails), onRollback);
|
return myTransactionService.execute(theRequest, theTransactionDetails, tx -> doUpdateWithHistoryRewrite(theResource, theRequest, theTransactionDetails), onRollback);
|
||||||
} else {
|
} else {
|
||||||
return myTransactionService.execute(theRequest, theTransactionDetails, tx -> doUpdate(theResource, theMatchUrl, thePerformIndexing, theForceUpdateVersion, theRequest, theTransactionDetails), onRollback);
|
return myTransactionService.execute(theRequest, theTransactionDetails, tx -> doUpdate(theResource, theMatchUrl, thePerformIndexing, theForceUpdateVersion, theRequest, theTransactionDetails), onRollback);
|
||||||
|
|
|
@ -393,12 +393,12 @@ public class PackageInstallerSvcImpl implements IPackageInstallerSvc {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private DaoMethodOutcome updateResource(IFhirResourceDao theDao, IBaseResource theResource) {
|
DaoMethodOutcome updateResource(IFhirResourceDao theDao, IBaseResource theResource) {
|
||||||
if (myPartitionSettings.isPartitioningEnabled()) {
|
if (myPartitionSettings.isPartitioningEnabled()) {
|
||||||
SystemRequestDetails requestDetails = newSystemRequestDetails();
|
SystemRequestDetails requestDetails = newSystemRequestDetails();
|
||||||
return theDao.update(theResource, requestDetails);
|
return theDao.update(theResource, requestDetails);
|
||||||
} else {
|
} else {
|
||||||
return theDao.update(theResource);
|
return theDao.update(theResource, new SystemRequestDetails());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,48 @@
|
||||||
|
package ca.uhn.fhir.jpa.packages;
|
||||||
|
|
||||||
|
import ca.uhn.fhir.jpa.test.BaseJpaR4Test;
|
||||||
|
import ca.uhn.fhir.model.primitive.IdDt;
|
||||||
|
import org.hl7.fhir.instance.model.api.IIdType;
|
||||||
|
import org.hl7.fhir.r4.model.ConceptMap;
|
||||||
|
import org.junit.jupiter.api.AfterEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
|
||||||
|
public class PackageInstallerSvcImplRewriteHistoryTest extends BaseJpaR4Test {
|
||||||
|
public static final IIdType CONCEPT_MAP_TEST_ID = new IdDt("ConceptMap/PackageInstallerSvcImplRewriteHistoryTest");
|
||||||
|
@Autowired
|
||||||
|
PackageInstallerSvcImpl mySvc;
|
||||||
|
|
||||||
|
|
||||||
|
@AfterEach
|
||||||
|
void after() {
|
||||||
|
myDaoConfig.setUpdateWithHistoryRewriteEnabled(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void svc_notnull() {
|
||||||
|
assertNotNull(mySvc);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void updateWithHistoryRewriteEnabled() {
|
||||||
|
// setup
|
||||||
|
myDaoConfig.setUpdateWithHistoryRewriteEnabled(true);
|
||||||
|
|
||||||
|
ConceptMap conceptMap = new ConceptMap();
|
||||||
|
conceptMap.setId(CONCEPT_MAP_TEST_ID);
|
||||||
|
conceptMap.setUrl("http://example.com/ConceptMap/testcm");
|
||||||
|
|
||||||
|
// execute
|
||||||
|
// red-green this threw a NPE before the fix
|
||||||
|
mySvc.updateResource(myConceptMapDao, conceptMap);
|
||||||
|
|
||||||
|
// verify
|
||||||
|
ConceptMap readConceptMap = myConceptMapDao.read(CONCEPT_MAP_TEST_ID);
|
||||||
|
assertEquals(CONCEPT_MAP_TEST_ID.toString(), readConceptMap.getIdElement().toVersionless().toString());
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue