@Test public void getComplianceTrendProgressTest() throws Exception { String targetTypes = "'ec2','s3','volume'"; when(complainceRepository.getTargetTypeForAG(anyString(), anyString())) .thenReturn(targetTypes); when(complainceRepository.getRuleIdWithDisplayNameQuery(anyString())) .thenReturn(CommonTestUtil.getListMapObject()); when(complianceService.getRuleSevCatDetails(anyObject())) .thenReturn(CommonTestUtil.getListMapObject()); when(repository.getComplianceTrendProgress(anyString(),anyObject(),anyString(),anyObject())) .thenReturn(CommonTestUtil.getListMapObject()); when(complianceService.getOverallComplianceByDomain(anyString(),anyString())) .thenReturn(CommonTestUtil.getMapObject()); assertThat(issueTrendServiceImpl.getComplianceTrendProgress("ansString", LocalDate.now(),"compliance"), is(notNullValue())); }
@Override public Map<String, Object> getComplianceTrendProgress(String assetGroup, LocalDate fromDate, String domain) throws ServiceException { Map<String, Object> parentMap = new HashMap<>(); parentMap.put("ag", assetGroup); String ttypes = complianceRepository.getTargetTypeForAG(assetGroup, domain); List<Map<String, Object>> ruleDetails = null; List<Map<String, Object>> inputList; List<Map<String, Object>> complianceInfoList; if (!Strings.isNullOrEmpty(ttypes)) { try { ruleDetails = complianceRepository .getRuleIdWithDisplayNameQuery(ttypes); } catch (DataException e) { throw new ServiceException(e); } } Set<String> ruleCat = new HashSet<>(); List<Map<String, Object>> ruleSevCatDetails; ruleSevCatDetails = complianceService .getRuleSevCatDetails(ruleDetails); Map<String, Object> ruleCatDetails = ruleSevCatDetails.parallelStream() .collect( Collectors.toMap(c -> c.get(RULEID).toString(), c -> c.get(RULE_CATEGORY), (oldvalue, newValue) -> newValue)); ruleCatDetails.entrySet().parallelStream() .forEach(entry -> ruleCat.add(entry.getValue().toString())); complianceInfoList = new ArrayList<>(); try { inputList = repository .getComplianceTrendProgress(assetGroup, fromDate, domain, ruleCat); } catch (DataException e) { throw new ServiceException(e); } if (!inputList.isEmpty()) { Comparator<Map<String, Object>> comp = (m1, m2) -> LocalDate.parse( m1.get("date").toString(), DateTimeFormatter.ISO_DATE) .compareTo( LocalDate.parse(m2.get("date").toString(), DateTimeFormatter.ISO_DATE)); Collections.sort(inputList, comp); useRealTimeDataForLatestDate(inputList, assetGroup, COMPLIANCE_PERCENTAGE, null, domain); inputList.forEach(inputMap -> { Map<String, Object> outputMap = new HashMap<>(); inputMap.forEach((key, value) -> { if ((!Strings.isNullOrEmpty(key)) && !("_id".equalsIgnoreCase(key))) { outputMap.put(key, value); } }); complianceInfoList.add(outputMap); }); Collections.sort(complianceInfoList, comp); } parentMap.put("compliance_info", complianceInfoList); return parentMap; }
IssueTrendServiceImpl implements IssueTrendService, Constants { @Override public Map<String, Object> getComplianceTrendProgress(String assetGroup, LocalDate fromDate, String domain) throws ServiceException { Map<String, Object> parentMap = new HashMap<>(); parentMap.put("ag", assetGroup); String ttypes = complianceRepository.getTargetTypeForAG(assetGroup, domain); List<Map<String, Object>> ruleDetails = null; List<Map<String, Object>> inputList; List<Map<String, Object>> complianceInfoList; if (!Strings.isNullOrEmpty(ttypes)) { try { ruleDetails = complianceRepository .getRuleIdWithDisplayNameQuery(ttypes); } catch (DataException e) { throw new ServiceException(e); } } Set<String> ruleCat = new HashSet<>(); List<Map<String, Object>> ruleSevCatDetails; ruleSevCatDetails = complianceService .getRuleSevCatDetails(ruleDetails); Map<String, Object> ruleCatDetails = ruleSevCatDetails.parallelStream() .collect( Collectors.toMap(c -> c.get(RULEID).toString(), c -> c.get(RULE_CATEGORY), (oldvalue, newValue) -> newValue)); ruleCatDetails.entrySet().parallelStream() .forEach(entry -> ruleCat.add(entry.getValue().toString())); complianceInfoList = new ArrayList<>(); try { inputList = repository .getComplianceTrendProgress(assetGroup, fromDate, domain, ruleCat); } catch (DataException e) { throw new ServiceException(e); } if (!inputList.isEmpty()) { Comparator<Map<String, Object>> comp = (m1, m2) -> LocalDate.parse( m1.get("date").toString(), DateTimeFormatter.ISO_DATE) .compareTo( LocalDate.parse(m2.get("date").toString(), DateTimeFormatter.ISO_DATE)); Collections.sort(inputList, comp); useRealTimeDataForLatestDate(inputList, assetGroup, COMPLIANCE_PERCENTAGE, null, domain); inputList.forEach(inputMap -> { Map<String, Object> outputMap = new HashMap<>(); inputMap.forEach((key, value) -> { if ((!Strings.isNullOrEmpty(key)) && !("_id".equalsIgnoreCase(key))) { outputMap.put(key, value); } }); complianceInfoList.add(outputMap); }); Collections.sort(complianceInfoList, comp); } parentMap.put("compliance_info", complianceInfoList); return parentMap; } }
IssueTrendServiceImpl implements IssueTrendService, Constants { @Override public Map<String, Object> getComplianceTrendProgress(String assetGroup, LocalDate fromDate, String domain) throws ServiceException { Map<String, Object> parentMap = new HashMap<>(); parentMap.put("ag", assetGroup); String ttypes = complianceRepository.getTargetTypeForAG(assetGroup, domain); List<Map<String, Object>> ruleDetails = null; List<Map<String, Object>> inputList; List<Map<String, Object>> complianceInfoList; if (!Strings.isNullOrEmpty(ttypes)) { try { ruleDetails = complianceRepository .getRuleIdWithDisplayNameQuery(ttypes); } catch (DataException e) { throw new ServiceException(e); } } Set<String> ruleCat = new HashSet<>(); List<Map<String, Object>> ruleSevCatDetails; ruleSevCatDetails = complianceService .getRuleSevCatDetails(ruleDetails); Map<String, Object> ruleCatDetails = ruleSevCatDetails.parallelStream() .collect( Collectors.toMap(c -> c.get(RULEID).toString(), c -> c.get(RULE_CATEGORY), (oldvalue, newValue) -> newValue)); ruleCatDetails.entrySet().parallelStream() .forEach(entry -> ruleCat.add(entry.getValue().toString())); complianceInfoList = new ArrayList<>(); try { inputList = repository .getComplianceTrendProgress(assetGroup, fromDate, domain, ruleCat); } catch (DataException e) { throw new ServiceException(e); } if (!inputList.isEmpty()) { Comparator<Map<String, Object>> comp = (m1, m2) -> LocalDate.parse( m1.get("date").toString(), DateTimeFormatter.ISO_DATE) .compareTo( LocalDate.parse(m2.get("date").toString(), DateTimeFormatter.ISO_DATE)); Collections.sort(inputList, comp); useRealTimeDataForLatestDate(inputList, assetGroup, COMPLIANCE_PERCENTAGE, null, domain); inputList.forEach(inputMap -> { Map<String, Object> outputMap = new HashMap<>(); inputMap.forEach((key, value) -> { if ((!Strings.isNullOrEmpty(key)) && !("_id".equalsIgnoreCase(key))) { outputMap.put(key, value); } }); complianceInfoList.add(outputMap); }); Collections.sort(complianceInfoList, comp); } parentMap.put("compliance_info", complianceInfoList); return parentMap; }  }
IssueTrendServiceImpl implements IssueTrendService, Constants { @Override public Map<String, Object> getComplianceTrendProgress(String assetGroup, LocalDate fromDate, String domain) throws ServiceException { Map<String, Object> parentMap = new HashMap<>(); parentMap.put("ag", assetGroup); String ttypes = complianceRepository.getTargetTypeForAG(assetGroup, domain); List<Map<String, Object>> ruleDetails = null; List<Map<String, Object>> inputList; List<Map<String, Object>> complianceInfoList; if (!Strings.isNullOrEmpty(ttypes)) { try { ruleDetails = complianceRepository .getRuleIdWithDisplayNameQuery(ttypes); } catch (DataException e) { throw new ServiceException(e); } } Set<String> ruleCat = new HashSet<>(); List<Map<String, Object>> ruleSevCatDetails; ruleSevCatDetails = complianceService .getRuleSevCatDetails(ruleDetails); Map<String, Object> ruleCatDetails = ruleSevCatDetails.parallelStream() .collect( Collectors.toMap(c -> c.get(RULEID).toString(), c -> c.get(RULE_CATEGORY), (oldvalue, newValue) -> newValue)); ruleCatDetails.entrySet().parallelStream() .forEach(entry -> ruleCat.add(entry.getValue().toString())); complianceInfoList = new ArrayList<>(); try { inputList = repository .getComplianceTrendProgress(assetGroup, fromDate, domain, ruleCat); } catch (DataException e) { throw new ServiceException(e); } if (!inputList.isEmpty()) { Comparator<Map<String, Object>> comp = (m1, m2) -> LocalDate.parse( m1.get("date").toString(), DateTimeFormatter.ISO_DATE) .compareTo( LocalDate.parse(m2.get("date").toString(), DateTimeFormatter.ISO_DATE)); Collections.sort(inputList, comp); useRealTimeDataForLatestDate(inputList, assetGroup, COMPLIANCE_PERCENTAGE, null, domain); inputList.forEach(inputMap -> { Map<String, Object> outputMap = new HashMap<>(); inputMap.forEach((key, value) -> { if ((!Strings.isNullOrEmpty(key)) && !("_id".equalsIgnoreCase(key))) { outputMap.put(key, value); } }); complianceInfoList.add(outputMap); }); Collections.sort(complianceInfoList, comp); } parentMap.put("compliance_info", complianceInfoList); return parentMap; }  Asset finfindByName(String accountName); @Override Map<String, Long> getTrendForIssues(String assetGroup,
            String fromDate, String toDate, String severity, String ruleId,
            String policyId, String app, String env); @Override Map<String, Object> getComplianceTrendProgress(String assetGroup,
            LocalDate fromDate, String domain); @Override Map<String, Object> getTrendProgress(String assetGroup,
            String ruleId, LocalDate startDate, LocalDate endDate,
            String trendCategory); @Override void useRealTimeDataForLatestDate(
            List<Map<String, Object>> trendList, String ag,
            String trendCategory, String ruleId, String domain); @Override Map<String, Object> getTrendIssues(String assetGroup,
            LocalDate from, LocalDate to, Map<String, String> filter,
            String domain); }
IssueTrendServiceImpl implements IssueTrendService, Constants { @Override public Map<String, Object> getComplianceTrendProgress(String assetGroup, LocalDate fromDate, String domain) throws ServiceException { Map<String, Object> parentMap = new HashMap<>(); parentMap.put("ag", assetGroup); String ttypes = complianceRepository.getTargetTypeForAG(assetGroup, domain); List<Map<String, Object>> ruleDetails = null; List<Map<String, Object>> inputList; List<Map<String, Object>> complianceInfoList; if (!Strings.isNullOrEmpty(ttypes)) { try { ruleDetails = complianceRepository .getRuleIdWithDisplayNameQuery(ttypes); } catch (DataException e) { throw new ServiceException(e); } } Set<String> ruleCat = new HashSet<>(); List<Map<String, Object>> ruleSevCatDetails; ruleSevCatDetails = complianceService .getRuleSevCatDetails(ruleDetails); Map<String, Object> ruleCatDetails = ruleSevCatDetails.parallelStream() .collect( Collectors.toMap(c -> c.get(RULEID).toString(), c -> c.get(RULE_CATEGORY), (oldvalue, newValue) -> newValue)); ruleCatDetails.entrySet().parallelStream() .forEach(entry -> ruleCat.add(entry.getValue().toString())); complianceInfoList = new ArrayList<>(); try { inputList = repository .getComplianceTrendProgress(assetGroup, fromDate, domain, ruleCat); } catch (DataException e) { throw new ServiceException(e); } if (!inputList.isEmpty()) { Comparator<Map<String, Object>> comp = (m1, m2) -> LocalDate.parse( m1.get("date").toString(), DateTimeFormatter.ISO_DATE) .compareTo( LocalDate.parse(m2.get("date").toString(), DateTimeFormatter.ISO_DATE)); Collections.sort(inputList, comp); useRealTimeDataForLatestDate(inputList, assetGroup, COMPLIANCE_PERCENTAGE, null, domain); inputList.forEach(inputMap -> { Map<String, Object> outputMap = new HashMap<>(); inputMap.forEach((key, value) -> { if ((!Strings.isNullOrEmpty(key)) && !("_id".equalsIgnoreCase(key))) { outputMap.put(key, value); } }); complianceInfoList.add(outputMap); }); Collections.sort(complianceInfoList, comp); } parentMap.put("compliance_info", complianceInfoList); return parentMap; }  Asset finfindByName(String accountName); @Override Map<String, Long> getTrendForIssues(String assetGroup,
            String fromDate, String toDate, String severity, String ruleId,
            String policyId, String app, String env); @Override Map<String, Object> getComplianceTrendProgress(String assetGroup,
            LocalDate fromDate, String domain); @Override Map<String, Object> getTrendProgress(String assetGroup,
            String ruleId, LocalDate startDate, LocalDate endDate,
            String trendCategory); @Override void useRealTimeDataForLatestDate(
            List<Map<String, Object>> trendList, String ag,
            String trendCategory, String ruleId, String domain); @Override Map<String, Object> getTrendIssues(String assetGroup,
            LocalDate from, LocalDate to, Map<String, String> filter,
            String domain);  }