move transactional method to persistence

This commit is contained in:
Ken Stevens 2020-07-29 17:16:49 -04:00
parent 102f936156
commit 5bfe3ce15f
5 changed files with 23 additions and 41 deletions

View File

@ -51,11 +51,10 @@ import ca.uhn.fhir.jpa.empi.svc.EmpiLinkSvcImpl;
import ca.uhn.fhir.jpa.empi.svc.EmpiLinkUpdaterSvcImpl;
import ca.uhn.fhir.jpa.empi.svc.EmpiMatchFinderSvcImpl;
import ca.uhn.fhir.jpa.empi.svc.EmpiMatchLinkSvc;
import ca.uhn.fhir.jpa.empi.svc.EmpiPersonDeletingSvcImpl;
import ca.uhn.fhir.jpa.empi.svc.EmpiPersonDeletingSvc;
import ca.uhn.fhir.jpa.empi.svc.EmpiPersonMergerSvcImpl;
import ca.uhn.fhir.jpa.empi.svc.EmpiResetSvcImpl;
import ca.uhn.fhir.jpa.empi.svc.EmpiResourceDaoSvc;
import ca.uhn.fhir.jpa.empi.svc.IEmpiPersonDeletingSvc;
import ca.uhn.fhir.jpa.empi.svc.candidate.EmpiCandidateSearchCriteriaBuilderSvc;
import ca.uhn.fhir.jpa.empi.svc.candidate.EmpiCandidateSearchSvc;
import ca.uhn.fhir.jpa.empi.svc.candidate.EmpiPersonFindingSvc;
@ -182,15 +181,10 @@ public class EmpiConsumerConfig {
}
@Bean
IEmpiResetSvc empiResetSvc(EmpiLinkDaoSvc theEmpiLinkDaoSvc, IEmpiPersonDeletingSvc theEmpiPersonDeletingSvcImpl ) {
IEmpiResetSvc empiResetSvc(EmpiLinkDaoSvc theEmpiLinkDaoSvc, EmpiPersonDeletingSvc theEmpiPersonDeletingSvcImpl ) {
return new EmpiResetSvcImpl(theEmpiLinkDaoSvc, theEmpiPersonDeletingSvcImpl);
}
@Bean
IEmpiPersonDeletingSvc empiPersonDeletingSvc() {
return new EmpiPersonDeletingSvcImpl();
}
@Bean
EmpiCandidateSearchSvc empiCandidateSearchSvc() {
return new EmpiCandidateSearchSvc();

View File

@ -24,6 +24,7 @@ import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.empi.rules.config.EmpiRuleValidator;
import ca.uhn.fhir.jpa.dao.empi.EmpiLinkDeleteSvc;
import ca.uhn.fhir.jpa.empi.interceptor.EmpiSubmitterInterceptorLoader;
import ca.uhn.fhir.jpa.empi.svc.EmpiPersonDeletingSvc;
import ca.uhn.fhir.jpa.empi.svc.EmpiSearchParamSvc;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@ -50,4 +51,9 @@ public class EmpiSubmitterConfig {
EmpiLinkDeleteSvc empiLinkDeleteSvc() {
return new EmpiLinkDeleteSvc();
}
@Bean
EmpiPersonDeletingSvc empiPersonDeletingSvc() {
return new EmpiPersonDeletingSvc();
}
}

View File

@ -12,50 +12,42 @@ import org.hl7.fhir.r4.model.IdType;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.support.TransactionTemplate;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import static org.slf4j.LoggerFactory.getLogger;
@Service
public class EmpiPersonDeletingSvcImpl implements IEmpiPersonDeletingSvc {
private static final Logger ourLog = getLogger(EmpiPersonDeletingSvcImpl.class);
public class EmpiPersonDeletingSvc {
private static final Logger ourLog = getLogger(EmpiPersonDeletingSvc.class);
@Autowired
private DaoRegistry myDaoRegistry;
@Autowired
private ExpungeService myExpungeService;
@Autowired
private PlatformTransactionManager myPlatformTransactionManager;
/**
* Function which will delete all resources by their PIDs, and also delete any resources that were undeletable due to
* VersionConflictException
*
* @param theLongs
*/
@Override
@Transactional
public void deleteResourcesAndHandleConflicts(List<Long> theLongs) {
TransactionTemplate txTemplate = new TransactionTemplate(myPlatformTransactionManager);
txTemplate.execute((tx) ->{
DeleteConflictList
deleteConflictList = new DeleteConflictList();
theLongs.stream().forEach(pid -> deleteCascade(pid, deleteConflictList));
DeleteConflictList
deleteConflictList = new DeleteConflictList();
theLongs.stream().forEach(pid -> deleteCascade(pid, deleteConflictList));
IFhirResourceDao personDao = myDaoRegistry.getResourceDao("Person");
while (!deleteConflictList.isEmpty()) {
deleteConflictBatch(deleteConflictList, personDao);
}
return null;
});
IFhirResourceDao personDao = myDaoRegistry.getResourceDao("Person");
while (!deleteConflictList.isEmpty()) {
deleteConflictBatch(deleteConflictList, personDao);
}
}
/**
* Use the expunge service to expunge all historical and current versions of the resources associated to the PIDs.
*/
@Override
public void expungeHistoricalAndCurrentVersionsOfIds(List<Long> theLongs) {
ExpungeOptions options = new ExpungeOptions();
options.setExpungeDeletedResources(true);
@ -76,7 +68,7 @@ public class EmpiPersonDeletingSvcImpl implements IEmpiPersonDeletingSvc {
private void deleteConflictBatch(DeleteConflictList theDcl, IFhirResourceDao<IBaseResource> theDao) {
DeleteConflictList newBatch = new DeleteConflictList();
for (DeleteConflict next: theDcl) {
for (DeleteConflict next : theDcl) {
IdDt nextSource = next.getSourceId();
ourLog.info("Have delete conflict {} - Cascading delete", next);
theDao.delete(nextSource.toVersionless(), newBatch, null, null);

View File

@ -39,10 +39,10 @@ public class EmpiResetSvcImpl implements IEmpiResetSvc {
private static final Logger ourLog = LoggerFactory.getLogger(EmpiResetSvcImpl.class);
final EmpiLinkDaoSvc myEmpiLinkDaoSvc;
final IEmpiPersonDeletingSvc myEmpiPersonDeletingSvcImpl;
final EmpiPersonDeletingSvc myEmpiPersonDeletingSvcImpl;
@Autowired
public EmpiResetSvcImpl(EmpiLinkDaoSvc theEmpiLinkDaoSvc, IEmpiPersonDeletingSvc theEmpiPersonDeletingSvcImpl) {
public EmpiResetSvcImpl(EmpiLinkDaoSvc theEmpiLinkDaoSvc, EmpiPersonDeletingSvc theEmpiPersonDeletingSvcImpl) {
myEmpiLinkDaoSvc = theEmpiLinkDaoSvc;
myEmpiPersonDeletingSvcImpl = theEmpiPersonDeletingSvcImpl;
}

View File

@ -1,10 +0,0 @@
package ca.uhn.fhir.jpa.empi.svc;
import java.util.List;
public interface IEmpiPersonDeletingSvc {
void deleteResourcesAndHandleConflicts(List<Long> theLongs);
void expungeHistoricalAndCurrentVersionsOfIds(List<Long> theLongs);
}