class PatchingServiceImpl implements PatchingService, Constants {

    @Override
    public List<Map<String, Object>> getNonCompliantNumberForAG(
            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())) {

                    createdMap.put("app", entry.getKey());
                    createdMap.put(NON_COMPLIANT_NUMBER, entry.getValue());
                    createdMap
                            .put("Director", fetchAppDirector(entry.getKey()));
                    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;
    }

}