@Test public void getPatchingTest() throws Exception { when(filterRepository.getListOfTargetTypes(anyString(), anyString())) .thenReturn(CommonTestUtil.getAssetCountByApps()); when( complianceRepository.getPatchabeAssetsCount(anyString(), anyString(),anyString(),anyString(),anyString())).thenReturn(1000l); when( complianceRepository.getUnpatchedAssetsCount(anyString(), anyString(),anyString())).thenReturn(1000l); assertThat(complianceService.getPatching("test", "",""), is(notNullValue())); assertThat(complianceService.getPatching("test", "test",""), is(notNullValue())); }
@Override public Map<String, Long> getPatching(String assetGroup, String targetType, String application) throws ServiceException { logger.info("input value for getPatching are {} {} {}",assetGroup,targetType,application); Long totalPatched; Long totalUnpatched = 0l; Long totalAssets = 0l; double patchingPercentage; Map<String, Long> patching = new HashMap<>(); AssetCountDTO[] targetTypes; try { if (StringUtils.isEmpty(targetType)) { targetTypes = filterRepository.getListOfTargetTypes(assetGroup, null); } else { AssetCountDTO apiName = new AssetCountDTO(); apiName.setType(targetType); targetTypes = new AssetCountDTO[] { apiName }; } for (AssetCountDTO targettype : targetTypes) { String type = targettype.getType(); if (EC2.equalsIgnoreCase(type) || VIRTUALMACHINE.equalsIgnoreCase(type)) { totalAssets += repository.getPatchabeAssetsCount(assetGroup, targettype.getType(),application,null,null); totalUnpatched += repository.getUnpatchedAssetsCount(assetGroup, targettype.getType(),application); } } } catch (DataException e) { logger.error("Error @ getPatching ", e); throw new ServiceException(e); } if(totalUnpatched > totalAssets){ totalUnpatched = totalAssets; } totalPatched = totalAssets - totalUnpatched; if (totalAssets > 0) { patchingPercentage = (totalPatched * HUNDRED) / totalAssets; patchingPercentage = Math.floor(patchingPercentage); } else { patchingPercentage = HUNDRED; } patching.put("unpatched_instances", totalUnpatched); patching.put("total_instances", totalAssets); patching.put("patched_instances", totalPatched); patching.put("patching_percentage", (long) patchingPercentage); if (patching.isEmpty()) { throw new ServiceException(NO_DATA_FOUND); } return patching; }
ComplianceServiceImpl implements ComplianceService, Constants { @Override public Map<String, Long> getPatching(String assetGroup, String targetType, String application) throws ServiceException { logger.info("input value for getPatching are {} {} {}",assetGroup,targetType,application); Long totalPatched; Long totalUnpatched = 0l; Long totalAssets = 0l; double patchingPercentage; Map<String, Long> patching = new HashMap<>(); AssetCountDTO[] targetTypes; try { if (StringUtils.isEmpty(targetType)) { targetTypes = filterRepository.getListOfTargetTypes(assetGroup, null); } else { AssetCountDTO apiName = new AssetCountDTO(); apiName.setType(targetType); targetTypes = new AssetCountDTO[] { apiName }; } for (AssetCountDTO targettype : targetTypes) { String type = targettype.getType(); if (EC2.equalsIgnoreCase(type) || VIRTUALMACHINE.equalsIgnoreCase(type)) { totalAssets += repository.getPatchabeAssetsCount(assetGroup, targettype.getType(),application,null,null); totalUnpatched += repository.getUnpatchedAssetsCount(assetGroup, targettype.getType(),application); } } } catch (DataException e) { logger.error("Error @ getPatching ", e); throw new ServiceException(e); } if(totalUnpatched > totalAssets){ totalUnpatched = totalAssets; } totalPatched = totalAssets - totalUnpatched; if (totalAssets > 0) { patchingPercentage = (totalPatched * HUNDRED) / totalAssets; patchingPercentage = Math.floor(patchingPercentage); } else { patchingPercentage = HUNDRED; } patching.put("unpatched_instances", totalUnpatched); patching.put("total_instances", totalAssets); patching.put("patched_instances", totalPatched); patching.put("patching_percentage", (long) patchingPercentage); if (patching.isEmpty()) { throw new ServiceException(NO_DATA_FOUND); } return patching; } }
ComplianceServiceImpl implements ComplianceService, Constants { @Override public Map<String, Long> getPatching(String assetGroup, String targetType, String application) throws ServiceException { logger.info("input value for getPatching are {} {} {}",assetGroup,targetType,application); Long totalPatched; Long totalUnpatched = 0l; Long totalAssets = 0l; double patchingPercentage; Map<String, Long> patching = new HashMap<>(); AssetCountDTO[] targetTypes; try { if (StringUtils.isEmpty(targetType)) { targetTypes = filterRepository.getListOfTargetTypes(assetGroup, null); } else { AssetCountDTO apiName = new AssetCountDTO(); apiName.setType(targetType); targetTypes = new AssetCountDTO[] { apiName }; } for (AssetCountDTO targettype : targetTypes) { String type = targettype.getType(); if (EC2.equalsIgnoreCase(type) || VIRTUALMACHINE.equalsIgnoreCase(type)) { totalAssets += repository.getPatchabeAssetsCount(assetGroup, targettype.getType(),application,null,null); totalUnpatched += repository.getUnpatchedAssetsCount(assetGroup, targettype.getType(),application); } } } catch (DataException e) { logger.error("Error @ getPatching ", e); throw new ServiceException(e); } if(totalUnpatched > totalAssets){ totalUnpatched = totalAssets; } totalPatched = totalAssets - totalUnpatched; if (totalAssets > 0) { patchingPercentage = (totalPatched * HUNDRED) / totalAssets; patchingPercentage = Math.floor(patchingPercentage); } else { patchingPercentage = HUNDRED; } patching.put("unpatched_instances", totalUnpatched); patching.put("total_instances", totalAssets); patching.put("patched_instances", totalPatched); patching.put("patching_percentage", (long) patchingPercentage); if (patching.isEmpty()) { throw new ServiceException(NO_DATA_FOUND); } return patching; }  }
ComplianceServiceImpl implements ComplianceService, Constants { @Override public Map<String, Long> getPatching(String assetGroup, String targetType, String application) throws ServiceException { logger.info("input value for getPatching are {} {} {}",assetGroup,targetType,application); Long totalPatched; Long totalUnpatched = 0l; Long totalAssets = 0l; double patchingPercentage; Map<String, Long> patching = new HashMap<>(); AssetCountDTO[] targetTypes; try { if (StringUtils.isEmpty(targetType)) { targetTypes = filterRepository.getListOfTargetTypes(assetGroup, null); } else { AssetCountDTO apiName = new AssetCountDTO(); apiName.setType(targetType); targetTypes = new AssetCountDTO[] { apiName }; } for (AssetCountDTO targettype : targetTypes) { String type = targettype.getType(); if (EC2.equalsIgnoreCase(type) || VIRTUALMACHINE.equalsIgnoreCase(type)) { totalAssets += repository.getPatchabeAssetsCount(assetGroup, targettype.getType(),application,null,null); totalUnpatched += repository.getUnpatchedAssetsCount(assetGroup, targettype.getType(),application); } } } catch (DataException e) { logger.error("Error @ getPatching ", e); throw new ServiceException(e); } if(totalUnpatched > totalAssets){ totalUnpatched = totalAssets; } totalPatched = totalAssets - totalUnpatched; if (totalAssets > 0) { patchingPercentage = (totalPatched * HUNDRED) / totalAssets; patchingPercentage = Math.floor(patchingPercentage); } else { patchingPercentage = HUNDRED; } patching.put("unpatched_instances", totalUnpatched); patching.put("total_instances", totalAssets); patching.put("patched_instances", totalPatched); patching.put("patching_percentage", (long) patchingPercentage); if (patching.isEmpty()) { throw new ServiceException(NO_DATA_FOUND); } return patching; }  @Override long getIssuesCount(String assetGroup, String ruleId, String domain); @Override ResponseWithOrder getIssues(Request request); @Override Map<String, Object> getDistribution(String assetGroup, String domain); @Override Map<String, Long> getTagging(String assetGroup, String targetType); @Override Map<String, Long> getCertificates(String assetGroup); @Override Map<String, Long> getPatching(String assetGroup, String targetType, String application); List<Map<String, Object>> getRecommendations(String assetGroup, String targetType); ResponseWithOrder getIssueAuditLog(String annotationId, String targetType, int from, int size,
            String searchText); List<Map<String, Object>> getResourceDetails(String assetGroup, String resourceId); @Override Boolean addIssueException(final IssueResponse issueException); @SuppressWarnings("rawtypes") ResponseWithOrder getRulecompliance(Request request); @Override Map<String, Object> closeIssuesByRule(final RuleDetails ruleDetails); JsonArray getRuleDetailsByApplicationFromES(String assetGroup, String ruleId, String searchText); List<Map<String, Object>> getRuleDetailsbyEnvironment(String assetGroup, String ruleId, String application,
            String searchText); Map<String, Object> getRuleDescription(String ruleId); @Override Boolean revokeIssueException(final String issueId); @Override Map<String, Object> getKernelComplianceByInstanceIdFromDb(String instanceId); @Override Map<String, Object> updateKernelVersion(final KernelVersion kernelVersion); @Override Map<String, Object> getOverallComplianceByDomain(String assetGroup, String domain); @Override List<String> getResourceType(String assetgroup, String domain); @SuppressWarnings("serial") @Override List<Map<String, Object>> getRuleSevCatDetails(List<Map<String, Object>> ruleDetails); PolicyViolationDetails getPolicyViolationDetailsByIssueId(String assetGroup, String issueId); ResponseEntity<Object> formatException(ServiceException e); @Override Map<String, String> getCurrentKernelVersions(); @Override IssueExceptionResponse addMultipleIssueException(IssuesException issuesException); @Override IssueExceptionResponse revokeMultipleIssueException(List<String> issueIds); @SuppressWarnings("unchecked") List<Map<String, Object>> getRuleDetailsbyApplication(String assetGroup, String ruleId, String searchText); }
ComplianceServiceImpl implements ComplianceService, Constants { @Override public Map<String, Long> getPatching(String assetGroup, String targetType, String application) throws ServiceException { logger.info("input value for getPatching are {} {} {}",assetGroup,targetType,application); Long totalPatched; Long totalUnpatched = 0l; Long totalAssets = 0l; double patchingPercentage; Map<String, Long> patching = new HashMap<>(); AssetCountDTO[] targetTypes; try { if (StringUtils.isEmpty(targetType)) { targetTypes = filterRepository.getListOfTargetTypes(assetGroup, null); } else { AssetCountDTO apiName = new AssetCountDTO(); apiName.setType(targetType); targetTypes = new AssetCountDTO[] { apiName }; } for (AssetCountDTO targettype : targetTypes) { String type = targettype.getType(); if (EC2.equalsIgnoreCase(type) || VIRTUALMACHINE.equalsIgnoreCase(type)) { totalAssets += repository.getPatchabeAssetsCount(assetGroup, targettype.getType(),application,null,null); totalUnpatched += repository.getUnpatchedAssetsCount(assetGroup, targettype.getType(),application); } } } catch (DataException e) { logger.error("Error @ getPatching ", e); throw new ServiceException(e); } if(totalUnpatched > totalAssets){ totalUnpatched = totalAssets; } totalPatched = totalAssets - totalUnpatched; if (totalAssets > 0) { patchingPercentage = (totalPatched * HUNDRED) / totalAssets; patchingPercentage = Math.floor(patchingPercentage); } else { patchingPercentage = HUNDRED; } patching.put("unpatched_instances", totalUnpatched); patching.put("total_instances", totalAssets); patching.put("patched_instances", totalPatched); patching.put("patching_percentage", (long) patchingPercentage); if (patching.isEmpty()) { throw new ServiceException(NO_DATA_FOUND); } return patching; }  @Override long getIssuesCount(String assetGroup, String ruleId, String domain); @Override ResponseWithOrder getIssues(Request request); @Override Map<String, Object> getDistribution(String assetGroup, String domain); @Override Map<String, Long> getTagging(String assetGroup, String targetType); @Override Map<String, Long> getCertificates(String assetGroup); @Override Map<String, Long> getPatching(String assetGroup, String targetType, String application); List<Map<String, Object>> getRecommendations(String assetGroup, String targetType); ResponseWithOrder getIssueAuditLog(String annotationId, String targetType, int from, int size,
            String searchText); List<Map<String, Object>> getResourceDetails(String assetGroup, String resourceId); @Override Boolean addIssueException(final IssueResponse issueException); @SuppressWarnings("rawtypes") ResponseWithOrder getRulecompliance(Request request); @Override Map<String, Object> closeIssuesByRule(final RuleDetails ruleDetails); JsonArray getRuleDetailsByApplicationFromES(String assetGroup, String ruleId, String searchText); List<Map<String, Object>> getRuleDetailsbyEnvironment(String assetGroup, String ruleId, String application,
            String searchText); Map<String, Object> getRuleDescription(String ruleId); @Override Boolean revokeIssueException(final String issueId); @Override Map<String, Object> getKernelComplianceByInstanceIdFromDb(String instanceId); @Override Map<String, Object> updateKernelVersion(final KernelVersion kernelVersion); @Override Map<String, Object> getOverallComplianceByDomain(String assetGroup, String domain); @Override List<String> getResourceType(String assetgroup, String domain); @SuppressWarnings("serial") @Override List<Map<String, Object>> getRuleSevCatDetails(List<Map<String, Object>> ruleDetails); PolicyViolationDetails getPolicyViolationDetailsByIssueId(String assetGroup, String issueId); ResponseEntity<Object> formatException(ServiceException e); @Override Map<String, String> getCurrentKernelVersions(); @Override IssueExceptionResponse addMultipleIssueException(IssuesException issuesException); @Override IssueExceptionResponse revokeMultipleIssueException(List<String> issueIds); @SuppressWarnings("unchecked") List<Map<String, Object>> getRuleDetailsbyApplication(String assetGroup, String ruleId, String searchText);  }