class 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);
                            }
                        }

                    });
            // Sort the list by the date in ascending order
            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;
    }

}