Skip to content

Commit

Permalink
feat: synchronize all methods in class using the same lock
Browse files Browse the repository at this point in the history
OCD-4688
  • Loading branch information
tmy1313 committed Nov 7, 2024
1 parent 97f3e95 commit b6241bb
Showing 1 changed file with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@
import gov.healthit.chpl.search.domain.ListingSearchResult;
import gov.healthit.chpl.search.domain.NonConformitySearchOptions;
import gov.healthit.chpl.search.domain.SearchRequest;
import lombok.Synchronized;
import lombok.extern.log4j.Log4j2;

@Log4j2
@Component
public class SurveillanceReportsService {
private final Object lock = new Object();

private SummaryStatisticsDAO summaryStatisticsDAO;
private ListingSearchService listingSearchService;
Expand All @@ -35,6 +37,7 @@ public SurveillanceReportsService(SummaryStatisticsDAO summaryStatisticsDAO, Lis
this.listingSearchService = listingSearchService;
}

@Synchronized("lock")
public SurveillanceActivityCounts getSurveiilanceActivityCounts() {
StatisticsSnapshot stats = getStatistics();
return SurveillanceActivityCounts.builder()
Expand All @@ -47,10 +50,12 @@ public SurveillanceActivityCounts getSurveiilanceActivityCounts() {
.build();
}

@Synchronized("lock")
public List<CertificationBodyStatistic> getOpenSurveillanceActivityCountsByAcb() {
return getStatistics().getSurveillanceOpenStatus().getAcbStatistics();
}

@Synchronized("lock")
public List<ListingSearchResult> getListingsWithOpenSurveillance() {
try {
return listingSearchService.getAllPagesOfSearchResults(
Expand All @@ -68,6 +73,7 @@ public List<ListingSearchResult> getListingsWithOpenSurveillance() {
}
}

@Synchronized("lock")
public NonconformityCounts getNonconformityCounts() {
StatisticsSnapshot stats = getStatistics();
return NonconformityCounts.builder()
Expand All @@ -83,10 +89,12 @@ public NonconformityCounts getNonconformityCounts() {
.build();
}

@Synchronized("lock")
public List<CertificationBodyStatistic> getOpenNonconformityCountsByAcb() {
return getStatistics().getNonConfStatusOpen().getAcbStatistics();
}

@Synchronized("lock")
public List<ListingSearchResult> getListingsWithOpenNonconformity() {
try {
return listingSearchService.getAllPagesOfSearchResults(
Expand All @@ -104,6 +112,7 @@ public List<ListingSearchResult> getListingsWithOpenNonconformity() {
}
}

@Synchronized("lock")
public CapCounts getCapCounts() {
StatisticsSnapshot stats = getStatistics();
Long openCaps = stats.getNonConfCAPStatusOpen().stream().collect(Collectors.summingLong(s -> s.getCount()));
Expand All @@ -115,14 +124,17 @@ public CapCounts getCapCounts() {
.build();
}

@Synchronized("lock")
public List<CertificationBodyStatistic> getOpenCapCountsByAcb() {
return getStatistics().getNonConfCAPStatusOpen();
}

@Synchronized("lock")
public List<CertificationBodyStatistic> getClosedCapCountsByAcb() {
return getStatistics().getNonConfCAPStatusClosed();
}

@Synchronized("lock")
public List<ListingSearchResult> getListingsWithOpenCap() {
try {
return listingSearchService.getAllPagesOfSearchResults(
Expand All @@ -148,6 +160,7 @@ public List<ListingSearchResult> getListingsWithOpenCap() {
}
}

@Synchronized("lock")
public List<ListingSearchResult> getListingsWithClosedCap() {
try {
return listingSearchService.getAllPagesOfSearchResults(
Expand Down

0 comments on commit b6241bb

Please sign in to comment.