@Test public void patchProgByExSponsorTest() throws Exception { Map<String, Object> targetTypesMap = new HashMap<>(); targetTypesMap.put("week", "1"); targetTypesMap.put("projection", "500"); targetTypesMap.put("appTag", "500"); targetTypesMap.put("executiveSponsor", "abc"); List<Map<String, Object>> maintargetTypesList = new ArrayList<>(); maintargetTypesList.add(targetTypesMap); List<LocalDate> lastDayOfEachWeek =new ArrayList<>(); lastDayOfEachWeek.add(LocalDate.now()); Map<Integer, Long> patchingSnapshotMap = new HashMap<>(); patchingSnapshotMap.put(1, 0l); Map<String, Long> assetMap = new HashMap<>(); assetMap.put("total_instances", 100l); ReflectionTestUtils.setField(projectionServiceImpl, "projectionAssetgroups", "onprem-vm"); String targetTypes = "'onpremserver','ec2','s3','volume'"; when(complainceRepository.getTargetTypeForAG(anyString(), anyString())) .thenReturn(targetTypes); when(repository.getAssetDetailsByApplication(anyString(),anyString())) .thenReturn(assetMap); when(patchingRepository.getNonCompliantNumberForAgAndResourceType(anyString(), anyString())) .thenReturn(assetMap); when(repository.getAppsDetails(anyString())) .thenReturn(maintargetTypesList); when(complianceService.getPatching(anyString(),anyString(),anyString())) .thenReturn(assetMap); assertThat(projectionServiceImpl.patchProgByExSponsor("onprem-vm"), is(notNullValue())); assertThatThrownBy(() -> projectionServiceImpl.patchProgByExSponsor("dummy")).isInstanceOf(ServiceException.class); }
@Override public PatchingProgressResponse patchProgByExSponsor(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>> patchingProgressByExecutorsList = new ArrayList<>(); String targetTypes = complianceRepository.getTargetTypeForAG( assetGroup, null); List<String> targetTypesList = new ArrayList<>( Arrays.asList(targetTypes.split(","))); Map<String, Map<String, Object>> executorsListMap = new ConcurrentHashMap<>(); for (String resourceType : targetTypesList) { resourceType = resourceType.replaceAll("\'", ""); if (resourceType.equalsIgnoreCase(ONPREMSERVER)) { if (targetType.length() > 0) { targetType.append(",").append(resourceType); } else { targetType.append(resourceType); } try { 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; executorsListMap = getDirectorsOrExecutorsPatchingProgress( EXCUTIVE_SPONSOR, quarterScope, resourceType, onpremAssetsByApplicationMap, appsDetails, onpremUnPatchedCountByApplicationMap, executorsListMap, patchingProgressByExecutorsList); } } catch (DataException e) { logger.error("Error @ patchProgByExSponsor", e); throw new ServiceException(e); } } else if (resourceType.equalsIgnoreCase(EC2)) { if (targetType.length() > 0) { targetType.append(",").append(resourceType); } else { targetType.append(resourceType); } try { 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; executorsListMap = getDirectorsOrExecutorsPatchingProgress( EXCUTIVE_SPONSOR, quarterScope, resourceType, ec2AssetsByApplicationMap, appsDetails, ec2UnPatchedCountByApplicationMap, executorsListMap, patchingProgressByExecutorsList); } } catch (DataException e) { logger.error("Error @ patchProgByExSponsor", e); throw new ServiceException(e); } } } for (Map.Entry<String, Map<String, Object>> entry : executorsListMap .entrySet()) { Map<String, Object> executorsMap = entry.getValue(); if (null != executorsMap) { patchingProgressByExecutorsList.add(executorsMap); } } Comparator<Map<String, Object>> comp = (m1, m2) -> Integer.compare( new Integer(m2.get(quarterScope).toString()), new Integer( m1.get(quarterScope).toString())); Collections.sort(patchingProgressByExecutorsList, comp); return new PatchingProgressResponse(assetGroup, targetType.toString(), totalAssets, year, quarter, patchingProgressByExecutorsList); } else { throw new ServiceException( NOT_ELIGIBLE_PROJECTIONS); } }
ProjectionServiceImpl implements ProjectionService, Constants { @Override public PatchingProgressResponse patchProgByExSponsor(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>> patchingProgressByExecutorsList = new ArrayList<>(); String targetTypes = complianceRepository.getTargetTypeForAG( assetGroup, null); List<String> targetTypesList = new ArrayList<>( Arrays.asList(targetTypes.split(","))); Map<String, Map<String, Object>> executorsListMap = new ConcurrentHashMap<>(); for (String resourceType : targetTypesList) { resourceType = resourceType.replaceAll("\'", ""); if (resourceType.equalsIgnoreCase(ONPREMSERVER)) { if (targetType.length() > 0) { targetType.append(",").append(resourceType); } else { targetType.append(resourceType); } try { 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; executorsListMap = getDirectorsOrExecutorsPatchingProgress( EXCUTIVE_SPONSOR, quarterScope, resourceType, onpremAssetsByApplicationMap, appsDetails, onpremUnPatchedCountByApplicationMap, executorsListMap, patchingProgressByExecutorsList); } } catch (DataException e) { logger.error("Error @ patchProgByExSponsor", e); throw new ServiceException(e); } } else if (resourceType.equalsIgnoreCase(EC2)) { if (targetType.length() > 0) { targetType.append(",").append(resourceType); } else { targetType.append(resourceType); } try { 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; executorsListMap = getDirectorsOrExecutorsPatchingProgress( EXCUTIVE_SPONSOR, quarterScope, resourceType, ec2AssetsByApplicationMap, appsDetails, ec2UnPatchedCountByApplicationMap, executorsListMap, patchingProgressByExecutorsList); } } catch (DataException e) { logger.error("Error @ patchProgByExSponsor", e); throw new ServiceException(e); } } } for (Map.Entry<String, Map<String, Object>> entry : executorsListMap .entrySet()) { Map<String, Object> executorsMap = entry.getValue(); if (null != executorsMap) { patchingProgressByExecutorsList.add(executorsMap); } } Comparator<Map<String, Object>> comp = (m1, m2) -> Integer.compare( new Integer(m2.get(quarterScope).toString()), new Integer( m1.get(quarterScope).toString())); Collections.sort(patchingProgressByExecutorsList, comp); return new PatchingProgressResponse(assetGroup, targetType.toString(), totalAssets, year, quarter, patchingProgressByExecutorsList); } else { throw new ServiceException( NOT_ELIGIBLE_PROJECTIONS); } } }
ProjectionServiceImpl implements ProjectionService, Constants { @Override public PatchingProgressResponse patchProgByExSponsor(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>> patchingProgressByExecutorsList = new ArrayList<>(); String targetTypes = complianceRepository.getTargetTypeForAG( assetGroup, null); List<String> targetTypesList = new ArrayList<>( Arrays.asList(targetTypes.split(","))); Map<String, Map<String, Object>> executorsListMap = new ConcurrentHashMap<>(); for (String resourceType : targetTypesList) { resourceType = resourceType.replaceAll("\'", ""); if (resourceType.equalsIgnoreCase(ONPREMSERVER)) { if (targetType.length() > 0) { targetType.append(",").append(resourceType); } else { targetType.append(resourceType); } try { 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; executorsListMap = getDirectorsOrExecutorsPatchingProgress( EXCUTIVE_SPONSOR, quarterScope, resourceType, onpremAssetsByApplicationMap, appsDetails, onpremUnPatchedCountByApplicationMap, executorsListMap, patchingProgressByExecutorsList); } } catch (DataException e) { logger.error("Error @ patchProgByExSponsor", e); throw new ServiceException(e); } } else if (resourceType.equalsIgnoreCase(EC2)) { if (targetType.length() > 0) { targetType.append(",").append(resourceType); } else { targetType.append(resourceType); } try { 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; executorsListMap = getDirectorsOrExecutorsPatchingProgress( EXCUTIVE_SPONSOR, quarterScope, resourceType, ec2AssetsByApplicationMap, appsDetails, ec2UnPatchedCountByApplicationMap, executorsListMap, patchingProgressByExecutorsList); } } catch (DataException e) { logger.error("Error @ patchProgByExSponsor", e); throw new ServiceException(e); } } } for (Map.Entry<String, Map<String, Object>> entry : executorsListMap .entrySet()) { Map<String, Object> executorsMap = entry.getValue(); if (null != executorsMap) { patchingProgressByExecutorsList.add(executorsMap); } } Comparator<Map<String, Object>> comp = (m1, m2) -> Integer.compare( new Integer(m2.get(quarterScope).toString()), new Integer( m1.get(quarterScope).toString())); Collections.sort(patchingProgressByExecutorsList, comp); return new PatchingProgressResponse(assetGroup, targetType.toString(), totalAssets, year, quarter, patchingProgressByExecutorsList); } else { throw new ServiceException( NOT_ELIGIBLE_PROJECTIONS); } }  }
ProjectionServiceImpl implements ProjectionService, Constants { @Override public PatchingProgressResponse patchProgByExSponsor(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>> patchingProgressByExecutorsList = new ArrayList<>(); String targetTypes = complianceRepository.getTargetTypeForAG( assetGroup, null); List<String> targetTypesList = new ArrayList<>( Arrays.asList(targetTypes.split(","))); Map<String, Map<String, Object>> executorsListMap = new ConcurrentHashMap<>(); for (String resourceType : targetTypesList) { resourceType = resourceType.replaceAll("\'", ""); if (resourceType.equalsIgnoreCase(ONPREMSERVER)) { if (targetType.length() > 0) { targetType.append(",").append(resourceType); } else { targetType.append(resourceType); } try { 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; executorsListMap = getDirectorsOrExecutorsPatchingProgress( EXCUTIVE_SPONSOR, quarterScope, resourceType, onpremAssetsByApplicationMap, appsDetails, onpremUnPatchedCountByApplicationMap, executorsListMap, patchingProgressByExecutorsList); } } catch (DataException e) { logger.error("Error @ patchProgByExSponsor", e); throw new ServiceException(e); } } else if (resourceType.equalsIgnoreCase(EC2)) { if (targetType.length() > 0) { targetType.append(",").append(resourceType); } else { targetType.append(resourceType); } try { 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; executorsListMap = getDirectorsOrExecutorsPatchingProgress( EXCUTIVE_SPONSOR, quarterScope, resourceType, ec2AssetsByApplicationMap, appsDetails, ec2UnPatchedCountByApplicationMap, executorsListMap, patchingProgressByExecutorsList); } } catch (DataException e) { logger.error("Error @ patchProgByExSponsor", e); throw new ServiceException(e); } } } for (Map.Entry<String, Map<String, Object>> entry : executorsListMap .entrySet()) { Map<String, Object> executorsMap = entry.getValue(); if (null != executorsMap) { patchingProgressByExecutorsList.add(executorsMap); } } Comparator<Map<String, Object>> comp = (m1, m2) -> Integer.compare( new Integer(m2.get(quarterScope).toString()), new Integer( m1.get(quarterScope).toString())); Collections.sort(patchingProgressByExecutorsList, comp); return new PatchingProgressResponse(assetGroup, targetType.toString(), totalAssets, year, quarter, patchingProgressByExecutorsList); } else { throw new ServiceException( NOT_ELIGIBLE_PROJECTIONS); } }  @Override Boolean updateProjection(ProjectionRequest projectionRequest); @Override ProjectionResponse getProjection(String resourceType, int year,
            int quarter); Long getTotalAsseCountByTargetType(String targetType); @Override ProjectionResponse getPatchingAndProjectionByWeek(String assetGroup); @Override PatchingProgressResponse getPatchingProgressByDirector(
            String assetGroup); @Override PatchingProgressResponse patchProgByExSponsor(String assetGroup); }
ProjectionServiceImpl implements ProjectionService, Constants { @Override public PatchingProgressResponse patchProgByExSponsor(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>> patchingProgressByExecutorsList = new ArrayList<>(); String targetTypes = complianceRepository.getTargetTypeForAG( assetGroup, null); List<String> targetTypesList = new ArrayList<>( Arrays.asList(targetTypes.split(","))); Map<String, Map<String, Object>> executorsListMap = new ConcurrentHashMap<>(); for (String resourceType : targetTypesList) { resourceType = resourceType.replaceAll("\'", ""); if (resourceType.equalsIgnoreCase(ONPREMSERVER)) { if (targetType.length() > 0) { targetType.append(",").append(resourceType); } else { targetType.append(resourceType); } try { 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; executorsListMap = getDirectorsOrExecutorsPatchingProgress( EXCUTIVE_SPONSOR, quarterScope, resourceType, onpremAssetsByApplicationMap, appsDetails, onpremUnPatchedCountByApplicationMap, executorsListMap, patchingProgressByExecutorsList); } } catch (DataException e) { logger.error("Error @ patchProgByExSponsor", e); throw new ServiceException(e); } } else if (resourceType.equalsIgnoreCase(EC2)) { if (targetType.length() > 0) { targetType.append(",").append(resourceType); } else { targetType.append(resourceType); } try { 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; executorsListMap = getDirectorsOrExecutorsPatchingProgress( EXCUTIVE_SPONSOR, quarterScope, resourceType, ec2AssetsByApplicationMap, appsDetails, ec2UnPatchedCountByApplicationMap, executorsListMap, patchingProgressByExecutorsList); } } catch (DataException e) { logger.error("Error @ patchProgByExSponsor", e); throw new ServiceException(e); } } } for (Map.Entry<String, Map<String, Object>> entry : executorsListMap .entrySet()) { Map<String, Object> executorsMap = entry.getValue(); if (null != executorsMap) { patchingProgressByExecutorsList.add(executorsMap); } } Comparator<Map<String, Object>> comp = (m1, m2) -> Integer.compare( new Integer(m2.get(quarterScope).toString()), new Integer( m1.get(quarterScope).toString())); Collections.sort(patchingProgressByExecutorsList, comp); return new PatchingProgressResponse(assetGroup, targetType.toString(), totalAssets, year, quarter, patchingProgressByExecutorsList); } else { throw new ServiceException( NOT_ELIGIBLE_PROJECTIONS); } }  @Override Boolean updateProjection(ProjectionRequest projectionRequest); @Override ProjectionResponse getProjection(String resourceType, int year,
            int quarter); Long getTotalAsseCountByTargetType(String targetType); @Override ProjectionResponse getPatchingAndProjectionByWeek(String assetGroup); @Override PatchingProgressResponse getPatchingProgressByDirector(
            String assetGroup); @Override PatchingProgressResponse patchProgByExSponsor(String assetGroup);  }