class PatchingServiceImpl implements PatchingService, Constants {

    @Override
    public List<Map<String, Object>> getNonCompliantExecsForAG(String assetGroup)
            throws ServiceException {
        List<Map<String, Long>> appComplianceMapList =new ArrayList<>();
        List<Map<String, Object>> appComplianceList = new ArrayList<>();

        // Invoking ES

        try{
            AssetCountDTO[] targetTypes = filterRepository.getListOfTargetTypes(
                    assetGroup, null);
            for (AssetCountDTO targettype : targetTypes) {
                if (StringUtils.isNotBlank(targettype.getType())) {
                    appComplianceMapList.add(repository.getNonCompliantNumberForAgAndResourceType(assetGroup, targettype.getType()));
                }
                }
          } catch (DataException e) {
              throw new ServiceException(e);
          }
        for (Map<String, Long> appComplianceMap : appComplianceMapList) {
            for (Map.Entry<String, Long> entry : appComplianceMap.entrySet()) {
                Map<String, Object> createdMap = new HashMap<>();
                if (StringUtils.isNotBlank(entry.getKey())) {
                    long currentNumber = entry.getValue();
                    long previousNumber = 0;
                    String execName = fetchAppExec(entry.getKey());
                    boolean sponsorDataOverwritten = false;
                    // One exec sponsor can have more than one application. If
                    // so,
                    // the number for each applications are to be summed up and
                    // the
                    // total number should be shown against the sponsors name
                    for (Map<String, Object> existingSponsorData : appComplianceList) {
                        if (execName.equals(existingSponsorData
                                .get("Executive Sponsor"))) {
                            previousNumber = (long) existingSponsorData
                                    .get(NON_COMPLIANT_NUMBER);
                            // Add the current number to the existing total of
                            // the
                            // sponsor, to get the updated total for the sponsor
                            long updatedNumber = currentNumber + previousNumber;
                            existingSponsorData.put(NON_COMPLIANT_NUMBER,
                                    updatedNumber);
                            sponsorDataOverwritten = true;
                            break;
                        }
                    }

                    // If this is a fresh sponsor, add it to the map. If
                    // existing
                    // one, we would have already updated the numbers above, so
                    // no
                    // need to add fresh
                    if (!sponsorDataOverwritten) {
                        createdMap.put(NON_COMPLIANT_NUMBER, currentNumber);
                        createdMap.put("Executive Sponsor", execName);
                        appComplianceList.add(createdMap);
                    }

                }
            }
        }

        // Sort the list by the number of nonCompliantNumber in descending order
        Comparator<Map<String, Object>> comp = (m1, m2) -> Integer.compare(
                new Integer(m2.get(NON_COMPLIANT_NUMBER).toString()),
                new Integer(m1.get(NON_COMPLIANT_NUMBER).toString()));
        Collections.sort(appComplianceList, comp);
        if (appComplianceList.isEmpty()) {
            throw new ServiceException(NO_DATA_FOUND);
        }
        return appComplianceList;
    }

}