@Test public void getRuleDetailsbyApplicationTest() throws Exception { when( complianceRepository.getRuleDetailsByApplicationFromES( anyString(), anyString(), anyString())).thenReturn( CommonTestUtil.getJsonArray()); when(complianceRepository.getTargetTypeByRuleId(anyString())) .thenReturn(CommonTestUtil.getMapList()); when( complianceRepository.getPatchableAssetsByApplication( anyString(), anyString(), anyString())).thenReturn( CommonTestUtil.getMapLong()); when( complianceRepository.getAllApplicationsAssetCountForTargetType( anyString(), anyString())).thenReturn( CommonTestUtil.getMapLong()); when( complianceRepository.getInstanceCountForQualysByAppsOrEnv( anyString(), anyString(),anyString(), anyString(),anyString())).thenReturn( CommonTestUtil.getMapLong()); assertThat( complianceService.getRuleDetailsbyApplication( "dummyString", "PacMan_cloud-kernel-compliance_version-1_Ec2-Kernel-Compliance-Rule_ec2", "dummyString"), is(notNullValue())); assertThat( complianceService.getRuleDetailsbyApplication( "dummyString", "PacMan_onpremisekernelversion_version-1_onpremKernelVersionRule_onpremserver", "dummyString"), is(notNullValue())); assertThat( complianceService.getRuleDetailsbyApplication( "dummyString", "PacMan_Ec2InstanceScannedByQualys_version-1_Ec2-instance-scanned-by-qualys-API_ec2", "dummyString"), is(notNullValue())); assertThat(complianceService.getRuleDetailsbyApplication("dummyString", "", "dummyString"), is(notNullValue())); }
@SuppressWarnings("unchecked") public List<Map<String, Object>> getRuleDetailsbyApplication(String assetGroup, String ruleId, String searchText) throws ServiceException { Map<String, Long> assetcountbyAplications; List<Map<String, Object>> applicationList = new ArrayList<>(); String targetType = null; JsonArray buckets; try { buckets = repository.getRuleDetailsByApplicationFromES(assetGroup, ruleId, searchText); } catch (DataException e) { logger.error("Error @ getRuleDetailsbyApplication while getting the application by rule from ES", e); throw new ServiceException(e); } Gson googleJson = new Gson(); List<Map<String, Object>> issuesByApplcationList = googleJson.fromJson(buckets, ArrayList.class); Map<String, Long> issuesByApplcationListMap = issuesByApplcationList.parallelStream().collect( Collectors.toMap(issue -> issue.get(KEY).toString(), issue -> (long) Double.parseDouble(issue.get(DOC_COUNT).toString()))); targetType = getTargetTypeByRuleId(ruleId); if (!Strings.isNullOrEmpty(targetType)) { if (ruleId.contains(CLOUD_KERNEL_COMPLIANCE_POLICY)) { try { assetcountbyAplications = repository.getPatchableAssetsByApplication(assetGroup, searchText, targetType); } catch (DataException e) { logger.error("Error @ getRuleDetailsbyApplication while getting the instance count for cloud kernel rule from ES", e); throw new ServiceException(e); } } else if ((ruleId.equalsIgnoreCase(ONPREM_KERNEL_COMPLIANCE_RULE))) { try { assetcountbyAplications = repository.getPatchableAssetsByApplication(assetGroup, searchText, ONPREMSERVER); } catch (DataException e) { logger.error("Error @ getRuleDetailsbyApplication while getting the instance count for onprem kernel rule from ES", e); throw new ServiceException(e); } } else if ((ruleId.contains(CLOUD_QUALYS_POLICY) && qualysEnabled) || ruleId.equalsIgnoreCase(SSM_AGENT_RULE)) { try{ assetcountbyAplications = repository.getInstanceCountForQualysByAppsOrEnv(assetGroup, "policydetailsbyapplication","","",targetType); } catch (DataException e) { logger.error("Error @ getRuleDetailsbyApplication while getting the instance count for qualys from ES", e); throw new ServiceException(e); } }else { assetcountbyAplications = repository.getAllApplicationsAssetCountForTargetType(assetGroup, targetType); } formComplianceDetailsByApplication(applicationList, assetcountbyAplications, issuesByApplcationListMap); } else { throw new ServiceException("No Target Type associated"); } return applicationList; }
ComplianceServiceImpl implements ComplianceService, Constants { @SuppressWarnings("unchecked") public List<Map<String, Object>> getRuleDetailsbyApplication(String assetGroup, String ruleId, String searchText) throws ServiceException { Map<String, Long> assetcountbyAplications; List<Map<String, Object>> applicationList = new ArrayList<>(); String targetType = null; JsonArray buckets; try { buckets = repository.getRuleDetailsByApplicationFromES(assetGroup, ruleId, searchText); } catch (DataException e) { logger.error("Error @ getRuleDetailsbyApplication while getting the application by rule from ES", e); throw new ServiceException(e); } Gson googleJson = new Gson(); List<Map<String, Object>> issuesByApplcationList = googleJson.fromJson(buckets, ArrayList.class); Map<String, Long> issuesByApplcationListMap = issuesByApplcationList.parallelStream().collect( Collectors.toMap(issue -> issue.get(KEY).toString(), issue -> (long) Double.parseDouble(issue.get(DOC_COUNT).toString()))); targetType = getTargetTypeByRuleId(ruleId); if (!Strings.isNullOrEmpty(targetType)) { if (ruleId.contains(CLOUD_KERNEL_COMPLIANCE_POLICY)) { try { assetcountbyAplications = repository.getPatchableAssetsByApplication(assetGroup, searchText, targetType); } catch (DataException e) { logger.error("Error @ getRuleDetailsbyApplication while getting the instance count for cloud kernel rule from ES", e); throw new ServiceException(e); } } else if ((ruleId.equalsIgnoreCase(ONPREM_KERNEL_COMPLIANCE_RULE))) { try { assetcountbyAplications = repository.getPatchableAssetsByApplication(assetGroup, searchText, ONPREMSERVER); } catch (DataException e) { logger.error("Error @ getRuleDetailsbyApplication while getting the instance count for onprem kernel rule from ES", e); throw new ServiceException(e); } } else if ((ruleId.contains(CLOUD_QUALYS_POLICY) && qualysEnabled) || ruleId.equalsIgnoreCase(SSM_AGENT_RULE)) { try{ assetcountbyAplications = repository.getInstanceCountForQualysByAppsOrEnv(assetGroup, "policydetailsbyapplication","","",targetType); } catch (DataException e) { logger.error("Error @ getRuleDetailsbyApplication while getting the instance count for qualys from ES", e); throw new ServiceException(e); } }else { assetcountbyAplications = repository.getAllApplicationsAssetCountForTargetType(assetGroup, targetType); } formComplianceDetailsByApplication(applicationList, assetcountbyAplications, issuesByApplcationListMap); } else { throw new ServiceException("No Target Type associated"); } return applicationList; } }
ComplianceServiceImpl implements ComplianceService, Constants { @SuppressWarnings("unchecked") public List<Map<String, Object>> getRuleDetailsbyApplication(String assetGroup, String ruleId, String searchText) throws ServiceException { Map<String, Long> assetcountbyAplications; List<Map<String, Object>> applicationList = new ArrayList<>(); String targetType = null; JsonArray buckets; try { buckets = repository.getRuleDetailsByApplicationFromES(assetGroup, ruleId, searchText); } catch (DataException e) { logger.error("Error @ getRuleDetailsbyApplication while getting the application by rule from ES", e); throw new ServiceException(e); } Gson googleJson = new Gson(); List<Map<String, Object>> issuesByApplcationList = googleJson.fromJson(buckets, ArrayList.class); Map<String, Long> issuesByApplcationListMap = issuesByApplcationList.parallelStream().collect( Collectors.toMap(issue -> issue.get(KEY).toString(), issue -> (long) Double.parseDouble(issue.get(DOC_COUNT).toString()))); targetType = getTargetTypeByRuleId(ruleId); if (!Strings.isNullOrEmpty(targetType)) { if (ruleId.contains(CLOUD_KERNEL_COMPLIANCE_POLICY)) { try { assetcountbyAplications = repository.getPatchableAssetsByApplication(assetGroup, searchText, targetType); } catch (DataException e) { logger.error("Error @ getRuleDetailsbyApplication while getting the instance count for cloud kernel rule from ES", e); throw new ServiceException(e); } } else if ((ruleId.equalsIgnoreCase(ONPREM_KERNEL_COMPLIANCE_RULE))) { try { assetcountbyAplications = repository.getPatchableAssetsByApplication(assetGroup, searchText, ONPREMSERVER); } catch (DataException e) { logger.error("Error @ getRuleDetailsbyApplication while getting the instance count for onprem kernel rule from ES", e); throw new ServiceException(e); } } else if ((ruleId.contains(CLOUD_QUALYS_POLICY) && qualysEnabled) || ruleId.equalsIgnoreCase(SSM_AGENT_RULE)) { try{ assetcountbyAplications = repository.getInstanceCountForQualysByAppsOrEnv(assetGroup, "policydetailsbyapplication","","",targetType); } catch (DataException e) { logger.error("Error @ getRuleDetailsbyApplication while getting the instance count for qualys from ES", e); throw new ServiceException(e); } }else { assetcountbyAplications = repository.getAllApplicationsAssetCountForTargetType(assetGroup, targetType); } formComplianceDetailsByApplication(applicationList, assetcountbyAplications, issuesByApplcationListMap); } else { throw new ServiceException("No Target Type associated"); } return applicationList; }  }
ComplianceServiceImpl implements ComplianceService, Constants { @SuppressWarnings("unchecked") public List<Map<String, Object>> getRuleDetailsbyApplication(String assetGroup, String ruleId, String searchText) throws ServiceException { Map<String, Long> assetcountbyAplications; List<Map<String, Object>> applicationList = new ArrayList<>(); String targetType = null; JsonArray buckets; try { buckets = repository.getRuleDetailsByApplicationFromES(assetGroup, ruleId, searchText); } catch (DataException e) { logger.error("Error @ getRuleDetailsbyApplication while getting the application by rule from ES", e); throw new ServiceException(e); } Gson googleJson = new Gson(); List<Map<String, Object>> issuesByApplcationList = googleJson.fromJson(buckets, ArrayList.class); Map<String, Long> issuesByApplcationListMap = issuesByApplcationList.parallelStream().collect( Collectors.toMap(issue -> issue.get(KEY).toString(), issue -> (long) Double.parseDouble(issue.get(DOC_COUNT).toString()))); targetType = getTargetTypeByRuleId(ruleId); if (!Strings.isNullOrEmpty(targetType)) { if (ruleId.contains(CLOUD_KERNEL_COMPLIANCE_POLICY)) { try { assetcountbyAplications = repository.getPatchableAssetsByApplication(assetGroup, searchText, targetType); } catch (DataException e) { logger.error("Error @ getRuleDetailsbyApplication while getting the instance count for cloud kernel rule from ES", e); throw new ServiceException(e); } } else if ((ruleId.equalsIgnoreCase(ONPREM_KERNEL_COMPLIANCE_RULE))) { try { assetcountbyAplications = repository.getPatchableAssetsByApplication(assetGroup, searchText, ONPREMSERVER); } catch (DataException e) { logger.error("Error @ getRuleDetailsbyApplication while getting the instance count for onprem kernel rule from ES", e); throw new ServiceException(e); } } else if ((ruleId.contains(CLOUD_QUALYS_POLICY) && qualysEnabled) || ruleId.equalsIgnoreCase(SSM_AGENT_RULE)) { try{ assetcountbyAplications = repository.getInstanceCountForQualysByAppsOrEnv(assetGroup, "policydetailsbyapplication","","",targetType); } catch (DataException e) { logger.error("Error @ getRuleDetailsbyApplication while getting the instance count for qualys from ES", e); throw new ServiceException(e); } }else { assetcountbyAplications = repository.getAllApplicationsAssetCountForTargetType(assetGroup, targetType); } formComplianceDetailsByApplication(applicationList, assetcountbyAplications, issuesByApplcationListMap); } else { throw new ServiceException("No Target Type associated"); } return applicationList; }  @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 { @SuppressWarnings("unchecked") public List<Map<String, Object>> getRuleDetailsbyApplication(String assetGroup, String ruleId, String searchText) throws ServiceException { Map<String, Long> assetcountbyAplications; List<Map<String, Object>> applicationList = new ArrayList<>(); String targetType = null; JsonArray buckets; try { buckets = repository.getRuleDetailsByApplicationFromES(assetGroup, ruleId, searchText); } catch (DataException e) { logger.error("Error @ getRuleDetailsbyApplication while getting the application by rule from ES", e); throw new ServiceException(e); } Gson googleJson = new Gson(); List<Map<String, Object>> issuesByApplcationList = googleJson.fromJson(buckets, ArrayList.class); Map<String, Long> issuesByApplcationListMap = issuesByApplcationList.parallelStream().collect( Collectors.toMap(issue -> issue.get(KEY).toString(), issue -> (long) Double.parseDouble(issue.get(DOC_COUNT).toString()))); targetType = getTargetTypeByRuleId(ruleId); if (!Strings.isNullOrEmpty(targetType)) { if (ruleId.contains(CLOUD_KERNEL_COMPLIANCE_POLICY)) { try { assetcountbyAplications = repository.getPatchableAssetsByApplication(assetGroup, searchText, targetType); } catch (DataException e) { logger.error("Error @ getRuleDetailsbyApplication while getting the instance count for cloud kernel rule from ES", e); throw new ServiceException(e); } } else if ((ruleId.equalsIgnoreCase(ONPREM_KERNEL_COMPLIANCE_RULE))) { try { assetcountbyAplications = repository.getPatchableAssetsByApplication(assetGroup, searchText, ONPREMSERVER); } catch (DataException e) { logger.error("Error @ getRuleDetailsbyApplication while getting the instance count for onprem kernel rule from ES", e); throw new ServiceException(e); } } else if ((ruleId.contains(CLOUD_QUALYS_POLICY) && qualysEnabled) || ruleId.equalsIgnoreCase(SSM_AGENT_RULE)) { try{ assetcountbyAplications = repository.getInstanceCountForQualysByAppsOrEnv(assetGroup, "policydetailsbyapplication","","",targetType); } catch (DataException e) { logger.error("Error @ getRuleDetailsbyApplication while getting the instance count for qualys from ES", e); throw new ServiceException(e); } }else { assetcountbyAplications = repository.getAllApplicationsAssetCountForTargetType(assetGroup, targetType); } formComplianceDetailsByApplication(applicationList, assetcountbyAplications, issuesByApplcationListMap); } else { throw new ServiceException("No Target Type associated"); } return applicationList; }  @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);  }