Untitled
unknown
plain_text
a year ago
3.4 kB
5
Indexable
public List<CMSInsuranceProduct> getInsuranceProducts() throws ApplicationException { log.info("getInsuranceProducts for the entity {} and language {}" , ThreadLocalUtility.getEntity(), ThreadLocalUtility.getLanguage()); List<CMSInsuranceProduct> cmsInsProdList = new ArrayList<>(); try{ cmsInsProdList = cacheConfigService.getInsuranceProducts(ThreadLocalUtility.getLanguage(), ThreadLocalUtility.getEntity()); }catch (ApplicationException e){ log.error("Error fetching insurance products from cms:{}", e); throw new ApplicationException(GenericErrorEnum.ERR_INSURANCE_PRODUCTS_NOT_FOUND); } if (ObjectUtils.isEmpty(cmsInsProdList)) { throw new ApplicationException(GenericErrorEnum.ERR_INSURANCE_PRODUCTS_NOT_FOUND); } return getFilteredInsuranceProducts(cmsInsProdList); } private List<String> getActiveInsuranceProducts() throws ApplicationException { Set<String> insuranceProduct = new HashSet<>(); log.info("calling product master for active product listing"); ProductMasterResponse productMasterResponse = productMasterService.getInsuranceProductMasterDetails(0, 0); log.info("got response from product master status: {}, current page: {}, last page: {}, data: {}" , productMasterResponse.getStatusCode(), productMasterResponse.getCurrentPage(), productMasterResponse.getLastPage(), productMasterResponse.getData()); populateActiveInsuranceProductList(productMasterResponse, insuranceProduct); log.info("data populated in the map: {}", insuranceProduct); while (productMasterResponse.getCurrentPage() < productMasterResponse.getLastPage()) { int offset = productMasterResponse.getCurrentPage() + 1; log.info("calling product master for {}", offset); productMasterResponse = productMasterService.getInsuranceProductMasterDetails(offset, 0); populateActiveInsuranceProductList(productMasterResponse, insuranceProduct); } log.info("final data:{}", insuranceProduct); return new ArrayList<>(insuranceProduct); } private void populateActiveInsuranceProductList(ProductMasterResponse productMasterResponse, Set<String> insuranceProduct) { productMasterResponse .getData() .stream() .filter(productData -> Constants.ACTIVE.equalsIgnoreCase(productData.getStatus())) .map(ProductData::getCode) .forEach(insuranceProduct::add); } private List<CMSInsuranceProduct> getFilteredInsuranceProducts(List<CMSInsuranceProduct> cmsInsProdList) throws ApplicationException { log.info("Filtering insurance products for the entity {} and language {}", ThreadLocalUtility.getEntity(), ThreadLocalUtility.getLanguage()); List<String> activeInsuranceProductList = getActiveInsuranceProducts(); List<CMSInsuranceProduct> cmsProductList = new ArrayList<>(); if (!activeInsuranceProductList.isEmpty()) { activeInsuranceProductList.forEach(s -> cmsProductList.addAll( cmsInsProdList .stream() .filter(insProd -> s.equalsIgnoreCase(insProd.getProductId()) && (!StringUtils.hasText(insProd.getCifs()) || (StringUtils.hasText(insProd.getCifs()) && insProd.getCifs().contains(ThreadLocalUtility.getCifId())))) .toList())); } log.info("Filtered insurance product list- fetched from CMS Entity: {} and size: {}", ThreadLocalUtility.getEntity(), cmsProductList.size()); return cmsProductList; }
Editor is loading...
Leave a Comment