Skip to content

Commit

Permalink
Fixes the self-proxying and avoids using an empty applicaiton context (
Browse files Browse the repository at this point in the history
…#924)

Co-authored-by: Sven F. <[email protected]>
  • Loading branch information
KochTobi and sven1103 authored Nov 26, 2024
1 parent 13123da commit 1617648
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import life.qbic.projectmanagement.domain.service.BatchDomainService;
import life.qbic.projectmanagement.domain.service.SampleDomainService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand All @@ -29,7 +29,7 @@
@Service
public class DeletionService {

private ApplicationContext context;
private DeletionService selfProxy;

private final ProjectInformationService projectInformationService;
private final ExperimentInformationService experimentInformationService;
Expand All @@ -41,7 +41,8 @@ public class DeletionService {
public DeletionService(ProjectInformationService projectInformationService,
ExperimentInformationService experimentInformationService,
SampleInformationService sampleInformationService, BatchDomainService batchDomainService,
SampleDomainService sampleDomainService, ApplicationContext context) {
SampleDomainService sampleDomainService,
@Lazy DeletionService selfProxy) {
this.projectInformationService = requireNonNull(projectInformationService,
"experimentInformationService must not be null");
this.experimentInformationService = requireNonNull(experimentInformationService,
Expand All @@ -52,6 +53,7 @@ public DeletionService(ProjectInformationService projectInformationService,
BatchDomainService.class.getSimpleName() + " must not be null");
this.sampleDomainService = requireNonNull(sampleDomainService,
SampleDomainService.class.getSimpleName() + " must not be null");
this.selfProxy = selfProxy;
}

/**
Expand Down Expand Up @@ -88,7 +90,7 @@ public BatchId deleteBatch(ProjectId projectId, BatchId batchId) {
});
// We need to get the proxy Spring has wrapped around the service, otherwise calling
// the @transaction annotated method has no effect
context.getBean(DeletionService.class).deleteSamples(projectId, batchId, samples);
selfProxy.deleteSamples(projectId, batchId, samples);
return deletedBatchId.getValue();
}

Expand Down

0 comments on commit 1617648

Please sign in to comment.