Fix to the issue (#3723)

This commit is contained in:
Qingyixia 2022-06-21 12:29:35 -04:00 committed by GitHub
parent 48c28997e6
commit dce330eb01
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 33 additions and 3 deletions

View File

@ -0,0 +1,5 @@
---
type: fix
issue: 3722
jira: SMILE-2323
title: "Fixed the $expunge operation that expunge everything response will return the correct number of dropped resources."

View File

@ -106,6 +106,8 @@ public class ExpungeEverythingService implements IExpungeEverythingService {
@Autowired
private MemoryCacheService myMemoryCacheService;
private int deletedResourceEntityCount;
@PostConstruct
public void initTxTemplate() {
myTxTemplate = new TransactionTemplate(myPlatformTransactionManager);
@ -177,8 +179,12 @@ public class ExpungeEverythingService implements IExpungeEverythingService {
counter.addAndGet(expungeEverythingByTypeWithoutPurging(TagDefinition.class));
counter.addAndGet(expungeEverythingByTypeWithoutPurging(ResourceHistoryProvenanceEntity.class));
counter.addAndGet(expungeEverythingByTypeWithoutPurging(ResourceHistoryTable.class));
int counterBefore = counter.get();
counter.addAndGet(expungeEverythingByTypeWithoutPurging(ResourceTable.class));
counter.addAndGet(expungeEverythingByTypeWithoutPurging(PartitionEntity.class));
deletedResourceEntityCount = counter.get() - counterBefore;
myTxTemplate.execute(t -> {
counter.addAndGet(doExpungeEverythingQuery("DELETE from " + Search.class.getSimpleName() + " d"));
return null;
@ -189,7 +195,12 @@ public class ExpungeEverythingService implements IExpungeEverythingService {
ourLog.info("COMPLETED GLOBAL $expunge - Deleted {} rows", counter.get());
}
private void purgeAllCaches() {
@Override
public int getExpungeDeletedEntityCount() {
return deletedResourceEntityCount;
}
private void purgeAllCaches() {
myTxTemplate.execute(t -> {
myMemoryCacheService.invalidateAllCaches();
return null;

View File

@ -4,6 +4,7 @@ import ca.uhn.fhir.i18n.Msg;
import ca.uhn.fhir.jpa.api.config.DaoConfig;
import ca.uhn.fhir.jpa.api.dao.IFhirResourceDao;
import ca.uhn.fhir.jpa.api.model.ExpungeOptions;
import ca.uhn.fhir.jpa.api.model.ExpungeOutcome;
import ca.uhn.fhir.jpa.dao.data.ISearchDao;
import ca.uhn.fhir.jpa.dao.data.ISearchResultDao;
import ca.uhn.fhir.jpa.interceptor.CascadingDeleteInterceptor;
@ -30,7 +31,6 @@ import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IIdType;
import org.hl7.fhir.r4.model.BooleanType;
import org.hl7.fhir.r4.model.CodeableConcept;
import org.hl7.fhir.r4.model.ContactPoint;
import org.hl7.fhir.r4.model.DateType;
import org.hl7.fhir.r4.model.DecimalType;
import org.hl7.fhir.r4.model.Enumerations;
@ -523,6 +523,17 @@ public class ExpungeR4Test extends BaseResourceProviderR4Test {
assertExpunged(myDeletedObservationId);
}
@Test
public void testExpungeSystemEverythingDeletedResourceCount() {
createStandardPatients();
ExpungeOutcome outcome = mySystemDao.expunge(new ExpungeOptions()
.setExpungeEverything(true), null);
// Make sure the deleted resource entities count is correct
assertEquals(8, outcome.getDeletedCount());
}
@Test
public void testExpungeTypeOldVersionsAndDeleted() {
createStandardPatients();

View File

@ -49,6 +49,7 @@ public class ExpungeService {
public ExpungeOutcome expunge(String theResourceName, ResourcePersistentId theResourceId, ExpungeOptions theExpungeOptions, RequestDetails theRequest) {
ourLog.info("Expunge: ResourceName[{}] Id[{}] Version[{}] Options[{}]", theResourceName, theResourceId != null ? theResourceId.getId() : null, theResourceId != null ? theResourceId.getVersion() : null, theExpungeOptions);
ExpungeOperation expungeOperation = getExpungeOperation(theResourceName, theResourceId, theExpungeOptions, theRequest);
if (theExpungeOptions.getLimit() < 1) {
throw new InvalidRequestException(Msg.code(1087) + "Expunge limit may not be less than 1. Received expunge limit " + theExpungeOptions.getLimit() + ".");
@ -57,10 +58,10 @@ public class ExpungeService {
if (theResourceName == null && (theResourceId == null || (theResourceId.getId() == null && theResourceId.getVersion() == null))) {
if (theExpungeOptions.isExpungeEverything()) {
myExpungeEverythingService.expungeEverything(theRequest);
return new ExpungeOutcome().setDeletedCount(myExpungeEverythingService.getExpungeDeletedEntityCount());
}
}
ExpungeOperation expungeOperation = getExpungeOperation(theResourceName, theResourceId, theExpungeOptions, theRequest);
return expungeOperation.call();
}

View File

@ -26,4 +26,6 @@ import javax.annotation.Nullable;
public interface IExpungeEverythingService {
void expungeEverything(@Nullable RequestDetails theRequest);
int getExpungeDeletedEntityCount();
}