Skip to content

Commit

Permalink
feat: chage the structore of the response to be more efficient
Browse files Browse the repository at this point in the history
OCD-4513
  • Loading branch information
tmy1313 committed Nov 7, 2024
1 parent 9dfc322 commit 3a7734b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package gov.healthit.chpl.report.product;

import gov.healthit.chpl.domain.CertificationBody;
import gov.healthit.chpl.domain.Product;
import gov.healthit.chpl.domain.IdNamePair;
import gov.healthit.chpl.search.domain.ListingSearchResult.DeveloperSearchResult;
import lombok.Builder;
import lombok.Data;

@Data
@Builder
public class ProductByAcb {
private Product product;
private CertificationBody acb;
private IdNamePair product;
private IdNamePair acb;
private DeveloperSearchResult developer;
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,8 @@

import gov.healthit.chpl.dao.CertificationStatusDAO;
import gov.healthit.chpl.dao.statistics.SummaryStatisticsDAO;
import gov.healthit.chpl.domain.CertificationBody;
import gov.healthit.chpl.domain.Product;
import gov.healthit.chpl.entity.statistics.SummaryStatisticsEntity;
import gov.healthit.chpl.exception.EntityRetrievalException;
import gov.healthit.chpl.exception.ValidationException;
import gov.healthit.chpl.manager.CertificationBodyManager;
import gov.healthit.chpl.manager.ProductManager;
import gov.healthit.chpl.scheduler.job.summarystatistics.data.CertificationBodyStatistic;
import gov.healthit.chpl.scheduler.job.summarystatistics.data.StatisticsSnapshot;
import gov.healthit.chpl.scheduler.job.summarystatistics.email.CertificationStatusIdHelper;
Expand All @@ -34,17 +29,12 @@ public class ProductReportsService {
private SummaryStatisticsDAO summaryStatisticsDAO;
private CertificationStatusIdHelper statusIdHelper;
private ListingSearchService listingSearchService;
private ProductManager productManager;
private CertificationBodyManager certificationBodyManager;

@Autowired
public ProductReportsService(SummaryStatisticsDAO summaryStatisticsDAO, CertificationStatusDAO certificationStatusDao, ListingSearchService listingSearchService,
ProductManager productManager, CertificationBodyManager certificationBodyManager) {
public ProductReportsService(SummaryStatisticsDAO summaryStatisticsDAO, CertificationStatusDAO certificationStatusDao, ListingSearchService listingSearchService) {
this.summaryStatisticsDAO = summaryStatisticsDAO;
this.statusIdHelper = new CertificationStatusIdHelper(certificationStatusDao);
this.listingSearchService = listingSearchService;
this.productManager = productManager;
this.certificationBodyManager = certificationBodyManager;
}

public UniqueProductCount getUniqueProductCount() {
Expand Down Expand Up @@ -98,23 +88,15 @@ private List<ProductByAcb> getProdutsAndAcbByStatuses(Set<String> statusNames) {
.certificationStatuses(statusNames)
.build());

Set<ProductByAcb> x = results.stream()
.map(searchResult -> {
try {
Product product = productManager.getById(searchResult.getProduct().getId());
CertificationBody acb = certificationBodyManager.getById(searchResult.getCertificationBody().getId());
return ProductByAcb.builder()
.product(product)
.acb(acb)
.build();
} catch (EntityRetrievalException e) {
LOGGER.error("Could not locate productId: {}", searchResult.getProduct().getId());
return null;
}
})
Set<ProductByAcb> productsByAcbs = results.stream()
.map(searchResult -> ProductByAcb.builder()
.product(searchResult.getProduct())
.acb(searchResult.getCertificationBody())
.developer(searchResult.getDeveloper())
.build())
.collect(Collectors.toSet());

return new ArrayList<ProductByAcb>(x);
return new ArrayList<ProductByAcb>(productsByAcbs);
} catch (ValidationException e) {
LOGGER.error("Error validating SearchRequest: {}", e.getMessage(), e);
return List.of();
Expand Down

0 comments on commit 3a7734b

Please sign in to comment.