call delete expunge hook for pid list within delete expunge batch job (#3252)
* call delete expunge hook for pid list within delete expunge batch job * review feedback
This commit is contained in:
parent
a078306a7d
commit
a41d79ed22
|
@ -20,6 +20,10 @@ package ca.uhn.fhir.jpa.delete.job;
|
||||||
* #L%
|
* #L%
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import ca.uhn.fhir.context.FhirContext;
|
||||||
|
import ca.uhn.fhir.interceptor.api.HookParams;
|
||||||
|
import ca.uhn.fhir.interceptor.api.IInterceptorService;
|
||||||
|
import ca.uhn.fhir.interceptor.api.Pointcut;
|
||||||
import ca.uhn.fhir.jpa.api.config.DaoConfig;
|
import ca.uhn.fhir.jpa.api.config.DaoConfig;
|
||||||
import ca.uhn.fhir.jpa.dao.data.IResourceLinkDao;
|
import ca.uhn.fhir.jpa.dao.data.IResourceLinkDao;
|
||||||
import ca.uhn.fhir.jpa.dao.expunge.PartitionRunner;
|
import ca.uhn.fhir.jpa.dao.expunge.PartitionRunner;
|
||||||
|
@ -27,8 +31,11 @@ import ca.uhn.fhir.jpa.dao.expunge.ResourceForeignKey;
|
||||||
import ca.uhn.fhir.jpa.dao.expunge.ResourceTableFKProvider;
|
import ca.uhn.fhir.jpa.dao.expunge.ResourceTableFKProvider;
|
||||||
import ca.uhn.fhir.jpa.dao.index.IdHelperService;
|
import ca.uhn.fhir.jpa.dao.index.IdHelperService;
|
||||||
import ca.uhn.fhir.jpa.model.entity.ResourceLink;
|
import ca.uhn.fhir.jpa.model.entity.ResourceLink;
|
||||||
|
import ca.uhn.fhir.jpa.partition.SystemRequestDetails;
|
||||||
|
import ca.uhn.fhir.rest.api.server.RequestDetails;
|
||||||
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
|
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails;
|
||||||
|
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||||
import org.hl7.fhir.instance.model.api.IIdType;
|
import org.hl7.fhir.instance.model.api.IIdType;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -40,6 +47,8 @@ import org.springframework.data.domain.SliceImpl;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -60,6 +69,8 @@ public class DeleteExpungeProcessor implements ItemProcessor<List<Long>, List<St
|
||||||
IdHelperService myIdHelper;
|
IdHelperService myIdHelper;
|
||||||
@Autowired
|
@Autowired
|
||||||
IResourceLinkDao myResourceLinkDao;
|
IResourceLinkDao myResourceLinkDao;
|
||||||
|
@Autowired
|
||||||
|
IInterceptorService myInterceptorService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> process(List<Long> thePids) throws Exception {
|
public List<String> process(List<Long> thePids) throws Exception {
|
||||||
|
@ -67,13 +78,16 @@ public class DeleteExpungeProcessor implements ItemProcessor<List<Long>, List<St
|
||||||
|
|
||||||
List<String> retval = new ArrayList<>();
|
List<String> retval = new ArrayList<>();
|
||||||
|
|
||||||
String pidListString = "(" + thePids.stream().map(Object::toString).collect(Collectors.joining(",")) + ")";
|
String pidListString = "(" + thePids.stream().map(Object::toString).collect(Collectors.joining(",")) + ")";
|
||||||
|
|
||||||
//Given the first pid in the last, grab the resource type so we can filter out which FKs we care about.
|
//Given the first pid in the last, grab the resource type so we can filter out which FKs we care about.
|
||||||
//TODO GGG should we pass this down the pipe?
|
//TODO GGG should we pass this down the pipe?
|
||||||
IIdType iIdType = myIdHelper.resourceIdFromPidOrThrowException(thePids.get(0));
|
IIdType iIdType = myIdHelper.resourceIdFromPidOrThrowException(thePids.get(0));
|
||||||
|
|
||||||
List<ResourceForeignKey> resourceForeignKeys = myResourceTableFKProvider.getResourceForeignKeysByResourceType(iIdType.getResourceType());
|
|
||||||
|
String resourceType = iIdType.getResourceType();
|
||||||
|
callHooks(thePids, resourceType);
|
||||||
|
List<ResourceForeignKey> resourceForeignKeys = myResourceTableFKProvider.getResourceForeignKeysByResourceType(resourceType);
|
||||||
|
|
||||||
for (ResourceForeignKey resourceForeignKey : resourceForeignKeys) {
|
for (ResourceForeignKey resourceForeignKey : resourceForeignKeys) {
|
||||||
retval.add(deleteRecordsByColumnSql(pidListString, resourceForeignKey));
|
retval.add(deleteRecordsByColumnSql(pidListString, resourceForeignKey));
|
||||||
|
@ -85,6 +99,16 @@ public class DeleteExpungeProcessor implements ItemProcessor<List<Long>, List<St
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void callHooks(List<Long> thePids, String theResourceType) {
|
||||||
|
HookParams params = new HookParams()
|
||||||
|
.add(String.class, theResourceType)
|
||||||
|
.add(List.class, thePids)
|
||||||
|
.add(AtomicLong.class, new AtomicLong())
|
||||||
|
.add(RequestDetails.class, new SystemRequestDetails())
|
||||||
|
.add(ServletRequestDetails.class, new ServletRequestDetails());
|
||||||
|
myInterceptorService.callHooks(Pointcut.STORAGE_PRE_DELETE_EXPUNGE_PID_LIST, params);
|
||||||
|
}
|
||||||
|
|
||||||
public void validateOkToDeleteAndExpunge(Slice<Long> thePids) {
|
public void validateOkToDeleteAndExpunge(Slice<Long> thePids) {
|
||||||
if (!myDaoConfig.isEnforceReferentialIntegrityOnDelete()) {
|
if (!myDaoConfig.isEnforceReferentialIntegrityOnDelete()) {
|
||||||
ourLog.info("Referential integrity on delete disabled. Skipping referential integrity check.");
|
ourLog.info("Referential integrity on delete disabled. Skipping referential integrity check.");
|
||||||
|
|
Loading…
Reference in New Issue