@Test public void getTrendIssuesTest() 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.getTrendIssues(anyString(),anyObject(),anyObject(),anyObject(),anyObject())) .thenReturn(CommonTestUtil.getListMapObject()); when(complianceService.getDistribution(anyString(),anyString())) .thenReturn(CommonTestUtil.getMapObject()); assertThat(issueTrendServiceImpl.getTrendIssues("ansString", LocalDate.now(),LocalDate.now(),new HashMap<>(),"issues"), is(notNullValue())); }
@Override public Map<String, Object> getTrendIssues(String assetGroup, LocalDate from, LocalDate to, Map<String, String> filter, String domain) throws ServiceException { Map<String, Object> parentMap = new HashMap<>(); parentMap.put("ag", assetGroup); String ttypes = complianceRepository.getTargetTypeForAG(assetGroup, filter.get(DOMAIN)); List<Map<String, Object>> ruleDetails = null; if (!Strings.isNullOrEmpty(ttypes)) { try{ ruleDetails = complianceRepository .getRuleIdWithDisplayNameQuery(ttypes); }catch(DataException e){ throw new ServiceException(e); } } Set<String> ruleSev = new HashSet<>(); List<Map<String, Object>> ruleSevCatDetails; ruleSevCatDetails = complianceService .getRuleSevCatDetails(ruleDetails); Map<String, Object> ruleSevDetails = ruleSevCatDetails.parallelStream() .collect( Collectors.toMap(r -> r.get(RULEID).toString(), r -> r.get(SEVERITY), (oldvalue, newValue) -> newValue)); ruleSevDetails.entrySet().parallelStream() .forEach(entry -> ruleSev.add(entry.getValue().toString())); List<Map<String, Object>> issueInfoList; try { issueInfoList = repository.getTrendIssues( assetGroup, from, to, filter, ruleSev); } catch (DataException e) { throw new ServiceException(e); } if (!issueInfoList.isEmpty()) { issueInfoList.parallelStream().forEach( issuemap -> { issuemap.remove("_id"); double total = Double.parseDouble(issuemap.get(TOTAL) .toString()); if (total == 0) { for (Map.Entry<String, Object> issue : issuemap .entrySet()) { if (!"date".equals(issue.getKey())) { issuemap.put(issue.getKey(), 0); } } } else { for (Map.Entry<String, Object> issue : issuemap .entrySet()) { if (issuemap.get(issue.getKey()) == null) issuemap.put(issue.getKey(), 0); } } }); 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(issueInfoList, comp); useRealTimeDataForLatestDate(issueInfoList, assetGroup, "issues", null, domain); parentMap.put("issues_info", issueInfoList); } return parentMap; }
IssueTrendServiceImpl implements IssueTrendService, Constants { @Override public Map<String, Object> getTrendIssues(String assetGroup, LocalDate from, LocalDate to, Map<String, String> filter, String domain) throws ServiceException { Map<String, Object> parentMap = new HashMap<>(); parentMap.put("ag", assetGroup); String ttypes = complianceRepository.getTargetTypeForAG(assetGroup, filter.get(DOMAIN)); List<Map<String, Object>> ruleDetails = null; if (!Strings.isNullOrEmpty(ttypes)) { try{ ruleDetails = complianceRepository .getRuleIdWithDisplayNameQuery(ttypes); }catch(DataException e){ throw new ServiceException(e); } } Set<String> ruleSev = new HashSet<>(); List<Map<String, Object>> ruleSevCatDetails; ruleSevCatDetails = complianceService .getRuleSevCatDetails(ruleDetails); Map<String, Object> ruleSevDetails = ruleSevCatDetails.parallelStream() .collect( Collectors.toMap(r -> r.get(RULEID).toString(), r -> r.get(SEVERITY), (oldvalue, newValue) -> newValue)); ruleSevDetails.entrySet().parallelStream() .forEach(entry -> ruleSev.add(entry.getValue().toString())); List<Map<String, Object>> issueInfoList; try { issueInfoList = repository.getTrendIssues( assetGroup, from, to, filter, ruleSev); } catch (DataException e) { throw new ServiceException(e); } if (!issueInfoList.isEmpty()) { issueInfoList.parallelStream().forEach( issuemap -> { issuemap.remove("_id"); double total = Double.parseDouble(issuemap.get(TOTAL) .toString()); if (total == 0) { for (Map.Entry<String, Object> issue : issuemap .entrySet()) { if (!"date".equals(issue.getKey())) { issuemap.put(issue.getKey(), 0); } } } else { for (Map.Entry<String, Object> issue : issuemap .entrySet()) { if (issuemap.get(issue.getKey()) == null) issuemap.put(issue.getKey(), 0); } } }); 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(issueInfoList, comp); useRealTimeDataForLatestDate(issueInfoList, assetGroup, "issues", null, domain); parentMap.put("issues_info", issueInfoList); } return parentMap; } }
IssueTrendServiceImpl implements IssueTrendService, Constants { @Override public Map<String, Object> getTrendIssues(String assetGroup, LocalDate from, LocalDate to, Map<String, String> filter, String domain) throws ServiceException { Map<String, Object> parentMap = new HashMap<>(); parentMap.put("ag", assetGroup); String ttypes = complianceRepository.getTargetTypeForAG(assetGroup, filter.get(DOMAIN)); List<Map<String, Object>> ruleDetails = null; if (!Strings.isNullOrEmpty(ttypes)) { try{ ruleDetails = complianceRepository .getRuleIdWithDisplayNameQuery(ttypes); }catch(DataException e){ throw new ServiceException(e); } } Set<String> ruleSev = new HashSet<>(); List<Map<String, Object>> ruleSevCatDetails; ruleSevCatDetails = complianceService .getRuleSevCatDetails(ruleDetails); Map<String, Object> ruleSevDetails = ruleSevCatDetails.parallelStream() .collect( Collectors.toMap(r -> r.get(RULEID).toString(), r -> r.get(SEVERITY), (oldvalue, newValue) -> newValue)); ruleSevDetails.entrySet().parallelStream() .forEach(entry -> ruleSev.add(entry.getValue().toString())); List<Map<String, Object>> issueInfoList; try { issueInfoList = repository.getTrendIssues( assetGroup, from, to, filter, ruleSev); } catch (DataException e) { throw new ServiceException(e); } if (!issueInfoList.isEmpty()) { issueInfoList.parallelStream().forEach( issuemap -> { issuemap.remove("_id"); double total = Double.parseDouble(issuemap.get(TOTAL) .toString()); if (total == 0) { for (Map.Entry<String, Object> issue : issuemap .entrySet()) { if (!"date".equals(issue.getKey())) { issuemap.put(issue.getKey(), 0); } } } else { for (Map.Entry<String, Object> issue : issuemap .entrySet()) { if (issuemap.get(issue.getKey()) == null) issuemap.put(issue.getKey(), 0); } } }); 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(issueInfoList, comp); useRealTimeDataForLatestDate(issueInfoList, assetGroup, "issues", null, domain); parentMap.put("issues_info", issueInfoList); } return parentMap; }  }
IssueTrendServiceImpl implements IssueTrendService, Constants { @Override public Map<String, Object> getTrendIssues(String assetGroup, LocalDate from, LocalDate to, Map<String, String> filter, String domain) throws ServiceException { Map<String, Object> parentMap = new HashMap<>(); parentMap.put("ag", assetGroup); String ttypes = complianceRepository.getTargetTypeForAG(assetGroup, filter.get(DOMAIN)); List<Map<String, Object>> ruleDetails = null; if (!Strings.isNullOrEmpty(ttypes)) { try{ ruleDetails = complianceRepository .getRuleIdWithDisplayNameQuery(ttypes); }catch(DataException e){ throw new ServiceException(e); } } Set<String> ruleSev = new HashSet<>(); List<Map<String, Object>> ruleSevCatDetails; ruleSevCatDetails = complianceService .getRuleSevCatDetails(ruleDetails); Map<String, Object> ruleSevDetails = ruleSevCatDetails.parallelStream() .collect( Collectors.toMap(r -> r.get(RULEID).toString(), r -> r.get(SEVERITY), (oldvalue, newValue) -> newValue)); ruleSevDetails.entrySet().parallelStream() .forEach(entry -> ruleSev.add(entry.getValue().toString())); List<Map<String, Object>> issueInfoList; try { issueInfoList = repository.getTrendIssues( assetGroup, from, to, filter, ruleSev); } catch (DataException e) { throw new ServiceException(e); } if (!issueInfoList.isEmpty()) { issueInfoList.parallelStream().forEach( issuemap -> { issuemap.remove("_id"); double total = Double.parseDouble(issuemap.get(TOTAL) .toString()); if (total == 0) { for (Map.Entry<String, Object> issue : issuemap .entrySet()) { if (!"date".equals(issue.getKey())) { issuemap.put(issue.getKey(), 0); } } } else { for (Map.Entry<String, Object> issue : issuemap .entrySet()) { if (issuemap.get(issue.getKey()) == null) issuemap.put(issue.getKey(), 0); } } }); 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(issueInfoList, comp); useRealTimeDataForLatestDate(issueInfoList, assetGroup, "issues", null, domain); parentMap.put("issues_info", issueInfoList); } 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> getTrendIssues(String assetGroup, LocalDate from, LocalDate to, Map<String, String> filter, String domain) throws ServiceException { Map<String, Object> parentMap = new HashMap<>(); parentMap.put("ag", assetGroup); String ttypes = complianceRepository.getTargetTypeForAG(assetGroup, filter.get(DOMAIN)); List<Map<String, Object>> ruleDetails = null; if (!Strings.isNullOrEmpty(ttypes)) { try{ ruleDetails = complianceRepository .getRuleIdWithDisplayNameQuery(ttypes); }catch(DataException e){ throw new ServiceException(e); } } Set<String> ruleSev = new HashSet<>(); List<Map<String, Object>> ruleSevCatDetails; ruleSevCatDetails = complianceService .getRuleSevCatDetails(ruleDetails); Map<String, Object> ruleSevDetails = ruleSevCatDetails.parallelStream() .collect( Collectors.toMap(r -> r.get(RULEID).toString(), r -> r.get(SEVERITY), (oldvalue, newValue) -> newValue)); ruleSevDetails.entrySet().parallelStream() .forEach(entry -> ruleSev.add(entry.getValue().toString())); List<Map<String, Object>> issueInfoList; try { issueInfoList = repository.getTrendIssues( assetGroup, from, to, filter, ruleSev); } catch (DataException e) { throw new ServiceException(e); } if (!issueInfoList.isEmpty()) { issueInfoList.parallelStream().forEach( issuemap -> { issuemap.remove("_id"); double total = Double.parseDouble(issuemap.get(TOTAL) .toString()); if (total == 0) { for (Map.Entry<String, Object> issue : issuemap .entrySet()) { if (!"date".equals(issue.getKey())) { issuemap.put(issue.getKey(), 0); } } } else { for (Map.Entry<String, Object> issue : issuemap .entrySet()) { if (issuemap.get(issue.getKey()) == null) issuemap.put(issue.getKey(), 0); } } }); 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(issueInfoList, comp); useRealTimeDataForLatestDate(issueInfoList, assetGroup, "issues", null, domain); parentMap.put("issues_info", issueInfoList); } 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);  }