@Test public void getRuleDetailsbyEnvironmentTest() throws Exception { when( complianceRepository.getRuleDetailsByEnvironmentFromES( anyString(), anyString(), anyString(), anyString(), anyString())) .thenReturn(CommonTestUtil.getJsonArray()); when(complianceRepository.getTargetTypeByRuleId(anyString())) .thenReturn(CommonTestUtil.getMapList()); when( complianceRepository.getTotalAssetCountByEnvironment( anyString(), anyString(), anyString())) .thenReturn(CommonTestUtil.getMapLong()); when( complianceRepository.getInstanceCountForQualys( anyString(), anyString(),anyString(), anyString(),anyString())).thenReturn(5000l); assertThat( complianceService.getRuleDetailsbyEnvironment( "dummyString", "PacMan_cloud-kernel-compliance_version-1_Ec2-Kernel-Compliance-Rule_ec2", "", "dummyString"), is(notNullValue())); assertThat( complianceService.getRuleDetailsbyEnvironment( "dummyString", "PacMan_onpremisekernelversion_version-1_onpremKernelVersionRule_onpremserver", "", "dummyString"), is(notNullValue())); assertThat(complianceService.getRuleDetailsbyEnvironment("dummyString", "", "", "dummyString"), is(notNullValue())); assertThat( complianceService.getRuleDetailsbyEnvironment( "dummyString", "PacMan_Ec2InstanceScannedByQualys_version-1_Ec2-instance-scanned-by-qualys-API_ec2", "dummyString",""), is(notNullValue())); assertThat(complianceService.getRuleDetailsbyEnvironment("dummyString", "", "","dummyString"), is(notNullValue())); }
public List<Map<String, Object>> getRuleDetailsbyEnvironment(String assetGroup, String ruleId, String application, String searchText) throws ServiceException { List<Map<String, Object>> environmentList = new ArrayList<>(); String targetType = getTargetTypeByRuleId(ruleId); JsonArray buckets; try { buckets = repository.getRuleDetailsByEnvironmentFromES(assetGroup, ruleId, application, searchText,targetType); } catch (DataException e) { logger.error("Error @ getRuleDetailsbyEnvironment while getting the env by rule and application from ES", e); throw new ServiceException(e); } Gson googleJson = new Gson(); List<Map<String, Object>> issuesForApplcationByEnvList = googleJson.fromJson(buckets, ArrayList.class); Map<String, Long> issuesByApplcationListMap = issuesForApplcationByEnvList.parallelStream().collect( Collectors.toMap(issue -> issue.get(KEY).toString(), issue -> (long) Double.parseDouble(issue.get(DOC_COUNT).toString()))); Map<String,Long> assetCountByEnv = repository.getTotalAssetCountByEnvironment(assetGroup, application, targetType); formComplianceDetailsForApplicationByEnvironment(ruleId, assetCountByEnv, issuesByApplcationListMap,assetGroup,application,environmentList,targetType,searchText); return environmentList; }
ComplianceServiceImpl implements ComplianceService, Constants { public List<Map<String, Object>> getRuleDetailsbyEnvironment(String assetGroup, String ruleId, String application, String searchText) throws ServiceException { List<Map<String, Object>> environmentList = new ArrayList<>(); String targetType = getTargetTypeByRuleId(ruleId); JsonArray buckets; try { buckets = repository.getRuleDetailsByEnvironmentFromES(assetGroup, ruleId, application, searchText,targetType); } catch (DataException e) { logger.error("Error @ getRuleDetailsbyEnvironment while getting the env by rule and application from ES", e); throw new ServiceException(e); } Gson googleJson = new Gson(); List<Map<String, Object>> issuesForApplcationByEnvList = googleJson.fromJson(buckets, ArrayList.class); Map<String, Long> issuesByApplcationListMap = issuesForApplcationByEnvList.parallelStream().collect( Collectors.toMap(issue -> issue.get(KEY).toString(), issue -> (long) Double.parseDouble(issue.get(DOC_COUNT).toString()))); Map<String,Long> assetCountByEnv = repository.getTotalAssetCountByEnvironment(assetGroup, application, targetType); formComplianceDetailsForApplicationByEnvironment(ruleId, assetCountByEnv, issuesByApplcationListMap,assetGroup,application,environmentList,targetType,searchText); return environmentList; } }
ComplianceServiceImpl implements ComplianceService, Constants { public List<Map<String, Object>> getRuleDetailsbyEnvironment(String assetGroup, String ruleId, String application, String searchText) throws ServiceException { List<Map<String, Object>> environmentList = new ArrayList<>(); String targetType = getTargetTypeByRuleId(ruleId); JsonArray buckets; try { buckets = repository.getRuleDetailsByEnvironmentFromES(assetGroup, ruleId, application, searchText,targetType); } catch (DataException e) { logger.error("Error @ getRuleDetailsbyEnvironment while getting the env by rule and application from ES", e); throw new ServiceException(e); } Gson googleJson = new Gson(); List<Map<String, Object>> issuesForApplcationByEnvList = googleJson.fromJson(buckets, ArrayList.class); Map<String, Long> issuesByApplcationListMap = issuesForApplcationByEnvList.parallelStream().collect( Collectors.toMap(issue -> issue.get(KEY).toString(), issue -> (long) Double.parseDouble(issue.get(DOC_COUNT).toString()))); Map<String,Long> assetCountByEnv = repository.getTotalAssetCountByEnvironment(assetGroup, application, targetType); formComplianceDetailsForApplicationByEnvironment(ruleId, assetCountByEnv, issuesByApplcationListMap,assetGroup,application,environmentList,targetType,searchText); return environmentList; }  }
ComplianceServiceImpl implements ComplianceService, Constants { public List<Map<String, Object>> getRuleDetailsbyEnvironment(String assetGroup, String ruleId, String application, String searchText) throws ServiceException { List<Map<String, Object>> environmentList = new ArrayList<>(); String targetType = getTargetTypeByRuleId(ruleId); JsonArray buckets; try { buckets = repository.getRuleDetailsByEnvironmentFromES(assetGroup, ruleId, application, searchText,targetType); } catch (DataException e) { logger.error("Error @ getRuleDetailsbyEnvironment while getting the env by rule and application from ES", e); throw new ServiceException(e); } Gson googleJson = new Gson(); List<Map<String, Object>> issuesForApplcationByEnvList = googleJson.fromJson(buckets, ArrayList.class); Map<String, Long> issuesByApplcationListMap = issuesForApplcationByEnvList.parallelStream().collect( Collectors.toMap(issue -> issue.get(KEY).toString(), issue -> (long) Double.parseDouble(issue.get(DOC_COUNT).toString()))); Map<String,Long> assetCountByEnv = repository.getTotalAssetCountByEnvironment(assetGroup, application, targetType); formComplianceDetailsForApplicationByEnvironment(ruleId, assetCountByEnv, issuesByApplcationListMap,assetGroup,application,environmentList,targetType,searchText); return environmentList; }  @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 { public List<Map<String, Object>> getRuleDetailsbyEnvironment(String assetGroup, String ruleId, String application, String searchText) throws ServiceException { List<Map<String, Object>> environmentList = new ArrayList<>(); String targetType = getTargetTypeByRuleId(ruleId); JsonArray buckets; try { buckets = repository.getRuleDetailsByEnvironmentFromES(assetGroup, ruleId, application, searchText,targetType); } catch (DataException e) { logger.error("Error @ getRuleDetailsbyEnvironment while getting the env by rule and application from ES", e); throw new ServiceException(e); } Gson googleJson = new Gson(); List<Map<String, Object>> issuesForApplcationByEnvList = googleJson.fromJson(buckets, ArrayList.class); Map<String, Long> issuesByApplcationListMap = issuesForApplcationByEnvList.parallelStream().collect( Collectors.toMap(issue -> issue.get(KEY).toString(), issue -> (long) Double.parseDouble(issue.get(DOC_COUNT).toString()))); Map<String,Long> assetCountByEnv = repository.getTotalAssetCountByEnvironment(assetGroup, application, targetType); formComplianceDetailsForApplicationByEnvironment(ruleId, assetCountByEnv, issuesByApplcationListMap,assetGroup,application,environmentList,targetType,searchText); return environmentList; }  @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);  }