@Test public void getPatchableAssetsByApplicationTest() throws Exception { Map<String, Long> patchableassetsByApp = new HashMap<>(); patchableassetsByApp.put("app1", 200l); when( elasticSearchRepository.getTotalDistributionForIndexAndType(anyString(), anyString(), anyObject(), anyObject(), anyObject(), anyObject(), anyInt(), anyObject())).thenReturn(patchableassetsByApp); complianceRepositoryImpl.getPatchableAssetsByApplication("test", null, "ec2"); complianceRepositoryImpl.getPatchableAssetsByApplication("test", "app1", "ec2"); complianceRepositoryImpl.getPatchableAssetsByApplication("test", null, ONPREMSERVER); complianceRepositoryImpl.getPatchableAssetsByApplication("test", null, "s3"); }
public Map<String, Long> getPatchableAssetsByApplication(String assetGroup, String application, String resourceType) throws DataException { Map<String, Object> mustFilter = new HashMap<>(); Map<String, Object> mustNotFilter = new HashMap<>(); Map<String, Long> patchableassetsByApp = null; mustFilter.put(LATEST, true); String aggsFilter = "tags.Application.keyword"; if (!Strings.isNullOrEmpty(application)) { mustFilter.put(TAGS_APPLICATION, application); } try { if ("ec2".equals(resourceType)) { mustFilter.put(STATE_NAME, RUNNING); mustNotFilter.put(PLATFORM, WINDOWS); patchableassetsByApp = elasticSearchRepository.getTotalDistributionForIndexAndType(assetGroup, "ec2", mustFilter, mustNotFilter, null, aggsFilter, 1000, null); } else if (ONPREMSERVER.equals(resourceType)) { mustFilter.put(INSCOPE, true); patchableassetsByApp = elasticSearchRepository.getTotalDistributionForIndexAndType(assetGroup, ONPREMSERVER, mustFilter, null, null, aggsFilter, 5000, null); } } catch (Exception e) { throw new DataException(e); } if (null != patchableassetsByApp && patchableassetsByApp.isEmpty()) { throw new DataException(NO_DATA_FOUND); } return patchableassetsByApp; }
ComplianceRepositoryImpl implements ComplianceRepository, Constants { public Map<String, Long> getPatchableAssetsByApplication(String assetGroup, String application, String resourceType) throws DataException { Map<String, Object> mustFilter = new HashMap<>(); Map<String, Object> mustNotFilter = new HashMap<>(); Map<String, Long> patchableassetsByApp = null; mustFilter.put(LATEST, true); String aggsFilter = "tags.Application.keyword"; if (!Strings.isNullOrEmpty(application)) { mustFilter.put(TAGS_APPLICATION, application); } try { if ("ec2".equals(resourceType)) { mustFilter.put(STATE_NAME, RUNNING); mustNotFilter.put(PLATFORM, WINDOWS); patchableassetsByApp = elasticSearchRepository.getTotalDistributionForIndexAndType(assetGroup, "ec2", mustFilter, mustNotFilter, null, aggsFilter, 1000, null); } else if (ONPREMSERVER.equals(resourceType)) { mustFilter.put(INSCOPE, true); patchableassetsByApp = elasticSearchRepository.getTotalDistributionForIndexAndType(assetGroup, ONPREMSERVER, mustFilter, null, null, aggsFilter, 5000, null); } } catch (Exception e) { throw new DataException(e); } if (null != patchableassetsByApp && patchableassetsByApp.isEmpty()) { throw new DataException(NO_DATA_FOUND); } return patchableassetsByApp; } }
ComplianceRepositoryImpl implements ComplianceRepository, Constants { public Map<String, Long> getPatchableAssetsByApplication(String assetGroup, String application, String resourceType) throws DataException { Map<String, Object> mustFilter = new HashMap<>(); Map<String, Object> mustNotFilter = new HashMap<>(); Map<String, Long> patchableassetsByApp = null; mustFilter.put(LATEST, true); String aggsFilter = "tags.Application.keyword"; if (!Strings.isNullOrEmpty(application)) { mustFilter.put(TAGS_APPLICATION, application); } try { if ("ec2".equals(resourceType)) { mustFilter.put(STATE_NAME, RUNNING); mustNotFilter.put(PLATFORM, WINDOWS); patchableassetsByApp = elasticSearchRepository.getTotalDistributionForIndexAndType(assetGroup, "ec2", mustFilter, mustNotFilter, null, aggsFilter, 1000, null); } else if (ONPREMSERVER.equals(resourceType)) { mustFilter.put(INSCOPE, true); patchableassetsByApp = elasticSearchRepository.getTotalDistributionForIndexAndType(assetGroup, ONPREMSERVER, mustFilter, null, null, aggsFilter, 5000, null); } } catch (Exception e) { throw new DataException(e); } if (null != patchableassetsByApp && patchableassetsByApp.isEmpty()) { throw new DataException(NO_DATA_FOUND); } return patchableassetsByApp; }  }
ComplianceRepositoryImpl implements ComplianceRepository, Constants { public Map<String, Long> getPatchableAssetsByApplication(String assetGroup, String application, String resourceType) throws DataException { Map<String, Object> mustFilter = new HashMap<>(); Map<String, Object> mustNotFilter = new HashMap<>(); Map<String, Long> patchableassetsByApp = null; mustFilter.put(LATEST, true); String aggsFilter = "tags.Application.keyword"; if (!Strings.isNullOrEmpty(application)) { mustFilter.put(TAGS_APPLICATION, application); } try { if ("ec2".equals(resourceType)) { mustFilter.put(STATE_NAME, RUNNING); mustNotFilter.put(PLATFORM, WINDOWS); patchableassetsByApp = elasticSearchRepository.getTotalDistributionForIndexAndType(assetGroup, "ec2", mustFilter, mustNotFilter, null, aggsFilter, 1000, null); } else if (ONPREMSERVER.equals(resourceType)) { mustFilter.put(INSCOPE, true); patchableassetsByApp = elasticSearchRepository.getTotalDistributionForIndexAndType(assetGroup, ONPREMSERVER, mustFilter, null, null, aggsFilter, 5000, null); } } catch (Exception e) { throw new DataException(e); } if (null != patchableassetsByApp && patchableassetsByApp.isEmpty()) { throw new DataException(NO_DATA_FOUND); } return patchableassetsByApp; }  long getIssuesCount(String assetGroup, String ruleId, String domain); @SuppressWarnings("rawtypes") ResponseWithOrder getIssuesFromES(Request request); @SuppressWarnings("rawtypes") Map<String, Long> getTagging(String assetGroup, String targetType); Map<String, Long> getCertificates(String assetGroup); @SuppressWarnings("rawtypes") List<Map<String, Object>> getRecommendations(String assetGroup, String targetType); Long getTotalAssetCountForAnytargetType(String assetGroup, String targetType); List<Map<String, Object>> getResourceDetailsFromES(String assetGroup, String resourceId); List<LinkedHashMap<String, Object>> getIssueAuditLog(String annotationId, String targetType, int from,
            int size, String searchText); Long getIssueAuditLogCount(String annotationId, String targetType); Map<String, Long> getRulesFromES(String assetGroup); @Override Boolean exemptAndUpdateIssueDetails(IssueResponse issueException); @Override Boolean closeIssuesByRule(RuleDetails ruleDetails); @Override Boolean revokeAndUpdateIssueDetails(String issueId); @Override List<Map<String, Object>> getExemptedIssueDetails(String issueId); @Override List<Map<String, Object>> getOpenIssueDetails(final String issueId); List<Map<String, Object>> getRuleIdWithDisplayNameQuery(String targetType); List<Map<String, Object>> getRuleIDsForTargetType(String targetType); List<Map<String, Object>> getRuleIdDetails(String ruleId); @Override List<Object> getRuleIds(String targetType); @SuppressWarnings("rawtypes") Map<String, Long> getNonCompliancePolicyByEsWithAssetGroup(String assetGroup, String searchText,
            Map<String, String> filters, int from, int size, String targetTypes); String getTargetTypeForAG(String assetGroup, String domain); List<Map<String, Object>> getRulesLastScanDate(); String getScanDate(String ruleId, Map<String, String> rulidwithScanDate); String getRuleCategory(Object ruleId, Map<String, String> ruleIdwithruleParamsMap); JsonArray getRuleDetailsByApplicationFromES(String assetGroup, String ruleId, String searchText); Map<String, Long> getAllApplicationsAssetCountForTargetType(String assetGroup, String targetType); List<Map<String, Object>> getTargetTypeByRuleId(String ruleId); Long getTotalAssetCountForEnvironment(String assetGroup, String application, String environment,
            String targetType); JsonArray getRuleDetailsByEnvironmentFromES(String assetGroup, String ruleId, String application,
            String searchText,String targetType); JsonArray getEventsProcessedFromEs(); List<Map<String, Object>> getRuleDescriptionFromDb(String ruleId); List<Map<String, Object>> getKernelComplianceByInstanceIdFromDb(String instanceId); String fetchSystemConfiguration(final String keyname); @SuppressWarnings("unchecked") @Override Map<String, Object> updateKernelVersion(final KernelVersion kernelVersion); Map<String, Object> getRuleCategoryWeightagefromDB(String domain); @SuppressWarnings("rawtypes") Map<String, Object> getTaggingByAG(String assetGroup, String targetTypes, String application); @SuppressWarnings("rawtypes") Map<String, Object> getPolicyViolationDetailsByIssueId(String assetGroup, String issueId); Map<String, Long> getPatchableAssetsByApplication(String assetGroup, String application, String resourceType); List<Map<String, Object>> getRuleIdWithDisplayNameWithRuleCategoryQuery(String targetType,
            String ruleCategory); Long getPatchabeAssetsCount(String assetGroup, String targetType); Long getUnpatchedAssetsCount(String assetGroup, String targetType, String application); Map<String, Object> formatUnpatchedMustFilter(String targetType, String ruleId); Map<String, Long> getRulesDistribution(String assetGroup, String domain, List<Object> rules,
            String aggsFiltername); Map<String, Object> getRuleCategoryPercentage(Map<String, Long> ruleCategoryDistribution, Long totalIssues); Long getInstanceCountForQualys(String assetGroup, String apiType, String application, String environment,
			String resourceType); Map<String, Long> getInstanceCountForQualysByAppsOrEnv(String assetGroup, String apiType, String application,
			String environment, String resourceType); @Override IssueExceptionResponse exemptAndUpdateMultipleIssueDetails(IssuesException issuesException); @Override IssueExceptionResponse revokeAndUpdateMultipleIssueDetails(List<String> issueIds); String createESDoc(Map<String, ?> doc); Response invokeAPI(String method, String endpoint, String payLoad); Map<String,Long> getTotalAssetCountByEnvironment(String assetGroup, String application,String targetType); List<Map<String, String>> getDataSourceForTargetTypeForAG(String assetGroup, String domain,
			String targetType); Map<String, Long> getTotalAssetCount(String assetGroup, String domain, String application, String type); @Override Map<String, Integer> getExemptedAssetsCountByRule(String assetGroup, String application, String type); Long getPatchabeAssetsCount(String assetGroup, String targetType, String application, String environment,
			String searchText); }
ComplianceRepositoryImpl implements ComplianceRepository, Constants { public Map<String, Long> getPatchableAssetsByApplication(String assetGroup, String application, String resourceType) throws DataException { Map<String, Object> mustFilter = new HashMap<>(); Map<String, Object> mustNotFilter = new HashMap<>(); Map<String, Long> patchableassetsByApp = null; mustFilter.put(LATEST, true); String aggsFilter = "tags.Application.keyword"; if (!Strings.isNullOrEmpty(application)) { mustFilter.put(TAGS_APPLICATION, application); } try { if ("ec2".equals(resourceType)) { mustFilter.put(STATE_NAME, RUNNING); mustNotFilter.put(PLATFORM, WINDOWS); patchableassetsByApp = elasticSearchRepository.getTotalDistributionForIndexAndType(assetGroup, "ec2", mustFilter, mustNotFilter, null, aggsFilter, 1000, null); } else if (ONPREMSERVER.equals(resourceType)) { mustFilter.put(INSCOPE, true); patchableassetsByApp = elasticSearchRepository.getTotalDistributionForIndexAndType(assetGroup, ONPREMSERVER, mustFilter, null, null, aggsFilter, 5000, null); } } catch (Exception e) { throw new DataException(e); } if (null != patchableassetsByApp && patchableassetsByApp.isEmpty()) { throw new DataException(NO_DATA_FOUND); } return patchableassetsByApp; }  long getIssuesCount(String assetGroup, String ruleId, String domain); @SuppressWarnings("rawtypes") ResponseWithOrder getIssuesFromES(Request request); @SuppressWarnings("rawtypes") Map<String, Long> getTagging(String assetGroup, String targetType); Map<String, Long> getCertificates(String assetGroup); @SuppressWarnings("rawtypes") List<Map<String, Object>> getRecommendations(String assetGroup, String targetType); Long getTotalAssetCountForAnytargetType(String assetGroup, String targetType); List<Map<String, Object>> getResourceDetailsFromES(String assetGroup, String resourceId); List<LinkedHashMap<String, Object>> getIssueAuditLog(String annotationId, String targetType, int from,
            int size, String searchText); Long getIssueAuditLogCount(String annotationId, String targetType); Map<String, Long> getRulesFromES(String assetGroup); @Override Boolean exemptAndUpdateIssueDetails(IssueResponse issueException); @Override Boolean closeIssuesByRule(RuleDetails ruleDetails); @Override Boolean revokeAndUpdateIssueDetails(String issueId); @Override List<Map<String, Object>> getExemptedIssueDetails(String issueId); @Override List<Map<String, Object>> getOpenIssueDetails(final String issueId); List<Map<String, Object>> getRuleIdWithDisplayNameQuery(String targetType); List<Map<String, Object>> getRuleIDsForTargetType(String targetType); List<Map<String, Object>> getRuleIdDetails(String ruleId); @Override List<Object> getRuleIds(String targetType); @SuppressWarnings("rawtypes") Map<String, Long> getNonCompliancePolicyByEsWithAssetGroup(String assetGroup, String searchText,
            Map<String, String> filters, int from, int size, String targetTypes); String getTargetTypeForAG(String assetGroup, String domain); List<Map<String, Object>> getRulesLastScanDate(); String getScanDate(String ruleId, Map<String, String> rulidwithScanDate); String getRuleCategory(Object ruleId, Map<String, String> ruleIdwithruleParamsMap); JsonArray getRuleDetailsByApplicationFromES(String assetGroup, String ruleId, String searchText); Map<String, Long> getAllApplicationsAssetCountForTargetType(String assetGroup, String targetType); List<Map<String, Object>> getTargetTypeByRuleId(String ruleId); Long getTotalAssetCountForEnvironment(String assetGroup, String application, String environment,
            String targetType); JsonArray getRuleDetailsByEnvironmentFromES(String assetGroup, String ruleId, String application,
            String searchText,String targetType); JsonArray getEventsProcessedFromEs(); List<Map<String, Object>> getRuleDescriptionFromDb(String ruleId); List<Map<String, Object>> getKernelComplianceByInstanceIdFromDb(String instanceId); String fetchSystemConfiguration(final String keyname); @SuppressWarnings("unchecked") @Override Map<String, Object> updateKernelVersion(final KernelVersion kernelVersion); Map<String, Object> getRuleCategoryWeightagefromDB(String domain); @SuppressWarnings("rawtypes") Map<String, Object> getTaggingByAG(String assetGroup, String targetTypes, String application); @SuppressWarnings("rawtypes") Map<String, Object> getPolicyViolationDetailsByIssueId(String assetGroup, String issueId); Map<String, Long> getPatchableAssetsByApplication(String assetGroup, String application, String resourceType); List<Map<String, Object>> getRuleIdWithDisplayNameWithRuleCategoryQuery(String targetType,
            String ruleCategory); Long getPatchabeAssetsCount(String assetGroup, String targetType); Long getUnpatchedAssetsCount(String assetGroup, String targetType, String application); Map<String, Object> formatUnpatchedMustFilter(String targetType, String ruleId); Map<String, Long> getRulesDistribution(String assetGroup, String domain, List<Object> rules,
            String aggsFiltername); Map<String, Object> getRuleCategoryPercentage(Map<String, Long> ruleCategoryDistribution, Long totalIssues); Long getInstanceCountForQualys(String assetGroup, String apiType, String application, String environment,
			String resourceType); Map<String, Long> getInstanceCountForQualysByAppsOrEnv(String assetGroup, String apiType, String application,
			String environment, String resourceType); @Override IssueExceptionResponse exemptAndUpdateMultipleIssueDetails(IssuesException issuesException); @Override IssueExceptionResponse revokeAndUpdateMultipleIssueDetails(List<String> issueIds); String createESDoc(Map<String, ?> doc); Response invokeAPI(String method, String endpoint, String payLoad); Map<String,Long> getTotalAssetCountByEnvironment(String assetGroup, String application,String targetType); List<Map<String, String>> getDataSourceForTargetTypeForAG(String assetGroup, String domain,
			String targetType); Map<String, Long> getTotalAssetCount(String assetGroup, String domain, String application, String type); @Override Map<String, Integer> getExemptedAssetsCountByRule(String assetGroup, String application, String type); Long getPatchabeAssetsCount(String assetGroup, String targetType, String application, String environment,
			String searchText);  }