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:
Ken Stevens 2022-10-22 12:16:27 -04:00 committed by GitHub
parent 929767a09b
commit a824ba263b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 57 additions and 4 deletions

View File

@ -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."

View File

@ -114,7 +114,6 @@ import ca.uhn.fhir.validation.IValidatorModule;
import ca.uhn.fhir.validation.ValidationOptions;
import ca.uhn.fhir.validation.ValidationResult;
import com.google.common.annotations.VisibleForTesting;
import com.google.gson.Gson;
import org.apache.commons.lang3.Validate;
import org.hl7.fhir.instance.model.api.IBaseCoding;
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);
// 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);
} else {
return myTransactionService.execute(theRequest, theTransactionDetails, tx -> doUpdate(theResource, theMatchUrl, thePerformIndexing, theForceUpdateVersion, theRequest, theTransactionDetails), onRollback);

View File

@ -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()) {
SystemRequestDetails requestDetails = newSystemRequestDetails();
return theDao.update(theResource, requestDetails);
} else {
return theDao.update(theResource);
return theDao.update(theResource, new SystemRequestDetails());
}
}

View File

@ -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());
}
}