class ProjectionServiceImpl implements ProjectionService, Constants {

    @Override
    public PatchingProgressResponse getPatchingProgressByDirector(
            String assetGroup) throws ServiceException {
        if (projectionAssetgroups.contains(assetGroup)) {
            LocalDate todayDate = LocalDate.now();
            int year = todayDate.getYear();
            int quarter = todayDate.get(IsoFields.QUARTER_OF_YEAR);
            Long totalAssets = 0l;
            StringBuilder targetType = new StringBuilder();
            String quarterScope = "q" + quarter + " scope";
            List<Map<String, Object>> patchingProgressByDirectorList = new ArrayList<>();
            String targetTypes = complianceRepository.getTargetTypeForAG(
                    assetGroup, null);
            List<String> targetTypesList = new ArrayList<>(
                    Arrays.asList(targetTypes.split(",")));
            Map<String, Map<String, Object>> directorListMap = new ConcurrentHashMap<>();
            for (String resourceType : targetTypesList) {
                try {
                    resourceType = resourceType.replaceAll("\'", "");
                    if (resourceType.equalsIgnoreCase(ONPREMSERVER)) {
                        if (targetType.length() > 0) {
                            targetType.append(",").append(resourceType);
                        } else {
                            targetType.append(resourceType);
                        }
                        Map<String, Long> onpremAssetsByApplicationMap = repository
                                .getAssetDetailsByApplication(assetGroup,
                                        resourceType);
                        Map<String, Long> onpremUnPatchedCountByApplicationMap = patchingRepository
                                .getNonCompliantNumberForAgAndResourceType(
                                        assetGroup, resourceType);

                        List<Map<String, Object>> appsDetails = repository.getAppsDetails("OnPrem");

                        if (!appsDetails.isEmpty()) {
                           Long onpremTotalAssets = complianceService.getPatching(
                                    assetGroup, resourceType, null).get(
                                    TOTAL_INSTANCES);
                            totalAssets += onpremTotalAssets;
                            directorListMap = getDirectorsOrExecutorsPatchingProgress(
                                    DIRECTOR, quarterScope, resourceType,
                                    onpremAssetsByApplicationMap, appsDetails,
                                    onpremUnPatchedCountByApplicationMap,
                                    directorListMap,
                                    patchingProgressByDirectorList);
                        }
                    } else if (resourceType.equalsIgnoreCase(EC2)) {
                        if (targetType.length() > 0) {
                            targetType.append(",").append(resourceType);
                        } else {
                            targetType.append(resourceType);
                        }
                        Map<String, Long> ec2AssetsByApplicationMap = repository
                                .getAssetDetailsByApplication(assetGroup,
                                        resourceType);
                        Map<String, Long> ec2UnPatchedCountByApplicationMap = patchingRepository
                                .getNonCompliantNumberForAgAndResourceType(
                                        assetGroup, resourceType);

                        List<Map<String, Object>> appsDetails = repository.getAppsDetails("Cloud");
                        if (!appsDetails.isEmpty()) {
                           Long ec2TotalAssets = complianceService.getPatching(
                                    assetGroup, resourceType, null).get(
                                    TOTAL_INSTANCES);
                            totalAssets += ec2TotalAssets;
                            directorListMap = getDirectorsOrExecutorsPatchingProgress(
                                    DIRECTOR, quarterScope, resourceType,
                                    ec2AssetsByApplicationMap, appsDetails,
                                    ec2UnPatchedCountByApplicationMap,
                                    directorListMap,
                                    patchingProgressByDirectorList);
                        }
                    }
                } catch (DataException e) {
                	logger.error("Error @ getPatchingProgressByDirector", e);
                    throw new ServiceException(e);
                }
            }

            for (Map.Entry<String, Map<String, Object>> entry : directorListMap
                    .entrySet()) {
                Map<String, Object> directorMap = entry.getValue();
                if (null != directorMap) {
                    patchingProgressByDirectorList.add(directorMap);
                }
            }
            Comparator<Map<String, Object>> comp = (m1, m2) -> Integer.compare(
                    new Integer(m2.get(quarterScope).toString()), new Integer(
                            m1.get(quarterScope).toString()));
            Collections.sort(patchingProgressByDirectorList, comp);

            return new PatchingProgressResponse(assetGroup,
                    targetType.toString(), totalAssets, year, quarter,
                    patchingProgressByDirectorList);
        } else {
            throw new ServiceException(
                    NOT_ELIGIBLE_PROJECTIONS);
        }
    }

}