@Test public void getOverallComplianceByDomainTest() throws Exception { when(complianceRepository.getTargetTypeForAG(anyString(), anyString())) .thenReturn(CommonTestUtil.getTargetTypes()); when(complianceRepository.getRuleIds(anyString())).thenReturn( CommonTestUtil.getRules()); when(complianceRepository.getRuleCategoryWeightagefromDB(anyString())) .thenReturn(CommonTestUtil.getMapObject()); getRulecomplianceTest(); assertThat( complianceService.getOverallComplianceByDomain("test", "test"), is(notNullValue())); }
@Override public Map<String, Object> getOverallComplianceByDomain(String assetGroup, String domain) throws ServiceException { double numerator = 0; double denominator = 0; double overallcompliance = 0; List<Object> rules = getRules(repository.getTargetTypeForAG(assetGroup, domain)); List<LinkedHashMap<String, Object>> complainceByRules = getComplainceByRules(domain, assetGroup, rules); Map<String, Map<String, Double>> rulesComplianceByCategory = getRulesComplianceByCategory(complainceByRules, assetGroup); int totalCategories = rulesComplianceByCategory.entrySet().size(); LinkedHashMap<String, Object> ruleCatWeightage = getRuleCategoryBWeightage(domain, totalCategories, rulesComplianceByCategory); int ruleCategoryWeightage = 1; int totalWeightage = 0; LinkedHashMap<String, Object> ruleCatDistributionWithOverall = new LinkedHashMap<>(); for (Map.Entry<String, Object> entry : ruleCatWeightage.entrySet()) { for (Map.Entry<String, Map<String, Double>> categoryDistribution : rulesComplianceByCategory.entrySet()) { if (entry.getKey().equals(categoryDistribution.getKey())) { ruleCategoryWeightage = (null != ruleCatWeightage.get(categoryDistribution.getKey())) ? Integer .valueOf(ruleCatWeightage.get(categoryDistribution.getKey()).toString()) : 1; totalWeightage += ruleCategoryWeightage; denominator = (categoryDistribution.getValue().get(DENOMINATOR)); numerator = (categoryDistribution.getValue().get(NUMERATOR)); double issueCompliance = calculateIssueCompliance(numerator, denominator); ruleCatDistributionWithOverall.put(categoryDistribution.getKey(), issueCompliance); overallcompliance += (ruleCategoryWeightage * issueCompliance); if (totalCategories == 1) { overallcompliance = overallcompliance / totalWeightage; overallcompliance = Math.floor(overallcompliance); ruleCatDistributionWithOverall.put("overall", overallcompliance); } totalCategories -= 1; } } } if (ruleCatDistributionWithOverall.isEmpty()) { throw new ServiceException(NO_DATA_FOUND); } return ruleCatDistributionWithOverall; }
ComplianceServiceImpl implements ComplianceService, Constants { @Override public Map<String, Object> getOverallComplianceByDomain(String assetGroup, String domain) throws ServiceException { double numerator = 0; double denominator = 0; double overallcompliance = 0; List<Object> rules = getRules(repository.getTargetTypeForAG(assetGroup, domain)); List<LinkedHashMap<String, Object>> complainceByRules = getComplainceByRules(domain, assetGroup, rules); Map<String, Map<String, Double>> rulesComplianceByCategory = getRulesComplianceByCategory(complainceByRules, assetGroup); int totalCategories = rulesComplianceByCategory.entrySet().size(); LinkedHashMap<String, Object> ruleCatWeightage = getRuleCategoryBWeightage(domain, totalCategories, rulesComplianceByCategory); int ruleCategoryWeightage = 1; int totalWeightage = 0; LinkedHashMap<String, Object> ruleCatDistributionWithOverall = new LinkedHashMap<>(); for (Map.Entry<String, Object> entry : ruleCatWeightage.entrySet()) { for (Map.Entry<String, Map<String, Double>> categoryDistribution : rulesComplianceByCategory.entrySet()) { if (entry.getKey().equals(categoryDistribution.getKey())) { ruleCategoryWeightage = (null != ruleCatWeightage.get(categoryDistribution.getKey())) ? Integer .valueOf(ruleCatWeightage.get(categoryDistribution.getKey()).toString()) : 1; totalWeightage += ruleCategoryWeightage; denominator = (categoryDistribution.getValue().get(DENOMINATOR)); numerator = (categoryDistribution.getValue().get(NUMERATOR)); double issueCompliance = calculateIssueCompliance(numerator, denominator); ruleCatDistributionWithOverall.put(categoryDistribution.getKey(), issueCompliance); overallcompliance += (ruleCategoryWeightage * issueCompliance); if (totalCategories == 1) { overallcompliance = overallcompliance / totalWeightage; overallcompliance = Math.floor(overallcompliance); ruleCatDistributionWithOverall.put("overall", overallcompliance); } totalCategories -= 1; } } } if (ruleCatDistributionWithOverall.isEmpty()) { throw new ServiceException(NO_DATA_FOUND); } return ruleCatDistributionWithOverall; } }
ComplianceServiceImpl implements ComplianceService, Constants { @Override public Map<String, Object> getOverallComplianceByDomain(String assetGroup, String domain) throws ServiceException { double numerator = 0; double denominator = 0; double overallcompliance = 0; List<Object> rules = getRules(repository.getTargetTypeForAG(assetGroup, domain)); List<LinkedHashMap<String, Object>> complainceByRules = getComplainceByRules(domain, assetGroup, rules); Map<String, Map<String, Double>> rulesComplianceByCategory = getRulesComplianceByCategory(complainceByRules, assetGroup); int totalCategories = rulesComplianceByCategory.entrySet().size(); LinkedHashMap<String, Object> ruleCatWeightage = getRuleCategoryBWeightage(domain, totalCategories, rulesComplianceByCategory); int ruleCategoryWeightage = 1; int totalWeightage = 0; LinkedHashMap<String, Object> ruleCatDistributionWithOverall = new LinkedHashMap<>(); for (Map.Entry<String, Object> entry : ruleCatWeightage.entrySet()) { for (Map.Entry<String, Map<String, Double>> categoryDistribution : rulesComplianceByCategory.entrySet()) { if (entry.getKey().equals(categoryDistribution.getKey())) { ruleCategoryWeightage = (null != ruleCatWeightage.get(categoryDistribution.getKey())) ? Integer .valueOf(ruleCatWeightage.get(categoryDistribution.getKey()).toString()) : 1; totalWeightage += ruleCategoryWeightage; denominator = (categoryDistribution.getValue().get(DENOMINATOR)); numerator = (categoryDistribution.getValue().get(NUMERATOR)); double issueCompliance = calculateIssueCompliance(numerator, denominator); ruleCatDistributionWithOverall.put(categoryDistribution.getKey(), issueCompliance); overallcompliance += (ruleCategoryWeightage * issueCompliance); if (totalCategories == 1) { overallcompliance = overallcompliance / totalWeightage; overallcompliance = Math.floor(overallcompliance); ruleCatDistributionWithOverall.put("overall", overallcompliance); } totalCategories -= 1; } } } if (ruleCatDistributionWithOverall.isEmpty()) { throw new ServiceException(NO_DATA_FOUND); } return ruleCatDistributionWithOverall; }  }
ComplianceServiceImpl implements ComplianceService, Constants { @Override public Map<String, Object> getOverallComplianceByDomain(String assetGroup, String domain) throws ServiceException { double numerator = 0; double denominator = 0; double overallcompliance = 0; List<Object> rules = getRules(repository.getTargetTypeForAG(assetGroup, domain)); List<LinkedHashMap<String, Object>> complainceByRules = getComplainceByRules(domain, assetGroup, rules); Map<String, Map<String, Double>> rulesComplianceByCategory = getRulesComplianceByCategory(complainceByRules, assetGroup); int totalCategories = rulesComplianceByCategory.entrySet().size(); LinkedHashMap<String, Object> ruleCatWeightage = getRuleCategoryBWeightage(domain, totalCategories, rulesComplianceByCategory); int ruleCategoryWeightage = 1; int totalWeightage = 0; LinkedHashMap<String, Object> ruleCatDistributionWithOverall = new LinkedHashMap<>(); for (Map.Entry<String, Object> entry : ruleCatWeightage.entrySet()) { for (Map.Entry<String, Map<String, Double>> categoryDistribution : rulesComplianceByCategory.entrySet()) { if (entry.getKey().equals(categoryDistribution.getKey())) { ruleCategoryWeightage = (null != ruleCatWeightage.get(categoryDistribution.getKey())) ? Integer .valueOf(ruleCatWeightage.get(categoryDistribution.getKey()).toString()) : 1; totalWeightage += ruleCategoryWeightage; denominator = (categoryDistribution.getValue().get(DENOMINATOR)); numerator = (categoryDistribution.getValue().get(NUMERATOR)); double issueCompliance = calculateIssueCompliance(numerator, denominator); ruleCatDistributionWithOverall.put(categoryDistribution.getKey(), issueCompliance); overallcompliance += (ruleCategoryWeightage * issueCompliance); if (totalCategories == 1) { overallcompliance = overallcompliance / totalWeightage; overallcompliance = Math.floor(overallcompliance); ruleCatDistributionWithOverall.put("overall", overallcompliance); } totalCategories -= 1; } } } if (ruleCatDistributionWithOverall.isEmpty()) { throw new ServiceException(NO_DATA_FOUND); } return ruleCatDistributionWithOverall; }  @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, Object> getOverallComplianceByDomain(String assetGroup, String domain) throws ServiceException { double numerator = 0; double denominator = 0; double overallcompliance = 0; List<Object> rules = getRules(repository.getTargetTypeForAG(assetGroup, domain)); List<LinkedHashMap<String, Object>> complainceByRules = getComplainceByRules(domain, assetGroup, rules); Map<String, Map<String, Double>> rulesComplianceByCategory = getRulesComplianceByCategory(complainceByRules, assetGroup); int totalCategories = rulesComplianceByCategory.entrySet().size(); LinkedHashMap<String, Object> ruleCatWeightage = getRuleCategoryBWeightage(domain, totalCategories, rulesComplianceByCategory); int ruleCategoryWeightage = 1; int totalWeightage = 0; LinkedHashMap<String, Object> ruleCatDistributionWithOverall = new LinkedHashMap<>(); for (Map.Entry<String, Object> entry : ruleCatWeightage.entrySet()) { for (Map.Entry<String, Map<String, Double>> categoryDistribution : rulesComplianceByCategory.entrySet()) { if (entry.getKey().equals(categoryDistribution.getKey())) { ruleCategoryWeightage = (null != ruleCatWeightage.get(categoryDistribution.getKey())) ? Integer .valueOf(ruleCatWeightage.get(categoryDistribution.getKey()).toString()) : 1; totalWeightage += ruleCategoryWeightage; denominator = (categoryDistribution.getValue().get(DENOMINATOR)); numerator = (categoryDistribution.getValue().get(NUMERATOR)); double issueCompliance = calculateIssueCompliance(numerator, denominator); ruleCatDistributionWithOverall.put(categoryDistribution.getKey(), issueCompliance); overallcompliance += (ruleCategoryWeightage * issueCompliance); if (totalCategories == 1) { overallcompliance = overallcompliance / totalWeightage; overallcompliance = Math.floor(overallcompliance); ruleCatDistributionWithOverall.put("overall", overallcompliance); } totalCategories -= 1; } } } if (ruleCatDistributionWithOverall.isEmpty()) { throw new ServiceException(NO_DATA_FOUND); } return ruleCatDistributionWithOverall; }  @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);  }