@Test public void revokeAndUpdateIssueDetailsTest() throws Exception { List<Map<String, Object>> issueDetails = new ArrayList<>(); Map<String, Object> issueDetailMap = new HashMap<>(); issueDetailMap.put("resourceType", "ec2"); issueDetailMap.put("status", "open"); issueDetailMap.put("severity", "high"); issueDetailMap.put(PAC_DS, AWS); issueDetailMap.put(PAC_DS, AWS); issueDetailMap.put(TYPE, "issue"); issueDetailMap.put(ES_DOC_ROUTING_KEY, "12345"); issueDetailMap.put(ES_DOC_PARENT_KEY, "ec2"); issueDetailMap.put(ES_DOC_ID_KEY, "678"); issueDetails.add(issueDetailMap); IssueResponse issueReason = new IssueResponse(); issueReason.setExceptionReason("exempted"); issueReason.setIssueId("1234"); RuleDetails ruleDetails = new RuleDetails(); ruleDetails.setRuleId("Kernel Compliance Rule"); ruleDetails.setReason("kernel Version Non-Compliant"); when( elasticSearchRepository.getSortedDataFromES(anyString(), anyString(), anyObject(), anyObject(), anyObject(), anyObject(), anyObject(), anyObject())).thenReturn(issueDetails); when(complianceRepositoryImpl.getExemptedIssueDetails(issueReason.getIssueId())).thenReturn(issueDetails); when( elasticSearchRepository.updatePartialDataToES(anyString(), anyString(), anyString(), anyString(), anyString(), anyObject())).thenReturn(true); ReflectionTestUtils.setField(complianceRepositoryImpl, "esUrl", "dummyEsURL"); complianceRepositoryImpl.revokeAndUpdateIssueDetails("1234"); }
@Override public Boolean revokeAndUpdateIssueDetails(String issueId) throws DataException { try { List<Map<String, Object>> issueDetails = getExemptedIssueDetails(issueId); Boolean isUpdated = false; if (!issueDetails.isEmpty()) { Map<String, Object> issueDetail = issueDetails.get(0); Map<String, Object> issueExceptionDetails = Maps.newHashMap(); issueExceptionDetails.put(TARGET_TYPE, String.valueOf(issueDetail.get(TARGET_TYPE))); issueExceptionDetails.put("source", "issueException"); String dataSource = issueDetail.get(PAC_DS) + "_" + issueDetail.get(TARGET_TYPE); String targetType = issueDetail.get(TYPE) + "_" + issueDetail.get(TARGET_TYPE); String id = String.valueOf(issueDetail.get(ES_DOC_ID_KEY)); String routing = String.valueOf(issueDetail.get(ES_DOC_ROUTING_KEY)); String parent = String.valueOf(issueDetail.get(ES_DOC_PARENT_KEY)); Map<String, Object> partialDocument = Maps.newHashMap(); partialDocument.put(ISSUE_STATUS, OPEN); SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT, Locale.US); sdf.setTimeZone(TimeZone.getTimeZone("UTC")); partialDocument.put(MODIFIED_DATE, sdf.format(new Date())); partialDocument.put(STATUS, "revoked"); isUpdated = elasticSearchRepository.updatePartialDataToES(dataSource, targetType, id, routing, parent, partialDocument); if (isUpdated) { try { List<Map<String, Object>> exceptionDetails = getIssueDetails(issueId, null); Map<String, Object> exceptionDetail = exceptionDetails.get(0); String exceptionId = String.valueOf(exceptionDetail.get(ES_DOC_ID_KEY)); StringBuilder esQueryUrl = new StringBuilder(esUrl); esQueryUrl.append("/").append(dataSource).append("/" + targetType).append("_exception/") .append(exceptionId).append("?routing=" + routing); HttpClient client = HttpClientBuilder.create().build(); HttpDelete httpdelete = new HttpDelete(esQueryUrl.toString()); httpdelete.setHeader("Content-Type", ContentType.APPLICATION_JSON.toString()); client.execute(httpdelete); } catch (Exception exception) { logger.info("No Issue Exception found!!!" + exception); } return isUpdated; } } return false; } catch (Exception e) { throw new DataException(e); } }
ComplianceRepositoryImpl implements ComplianceRepository, Constants { @Override public Boolean revokeAndUpdateIssueDetails(String issueId) throws DataException { try { List<Map<String, Object>> issueDetails = getExemptedIssueDetails(issueId); Boolean isUpdated = false; if (!issueDetails.isEmpty()) { Map<String, Object> issueDetail = issueDetails.get(0); Map<String, Object> issueExceptionDetails = Maps.newHashMap(); issueExceptionDetails.put(TARGET_TYPE, String.valueOf(issueDetail.get(TARGET_TYPE))); issueExceptionDetails.put("source", "issueException"); String dataSource = issueDetail.get(PAC_DS) + "_" + issueDetail.get(TARGET_TYPE); String targetType = issueDetail.get(TYPE) + "_" + issueDetail.get(TARGET_TYPE); String id = String.valueOf(issueDetail.get(ES_DOC_ID_KEY)); String routing = String.valueOf(issueDetail.get(ES_DOC_ROUTING_KEY)); String parent = String.valueOf(issueDetail.get(ES_DOC_PARENT_KEY)); Map<String, Object> partialDocument = Maps.newHashMap(); partialDocument.put(ISSUE_STATUS, OPEN); SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT, Locale.US); sdf.setTimeZone(TimeZone.getTimeZone("UTC")); partialDocument.put(MODIFIED_DATE, sdf.format(new Date())); partialDocument.put(STATUS, "revoked"); isUpdated = elasticSearchRepository.updatePartialDataToES(dataSource, targetType, id, routing, parent, partialDocument); if (isUpdated) { try { List<Map<String, Object>> exceptionDetails = getIssueDetails(issueId, null); Map<String, Object> exceptionDetail = exceptionDetails.get(0); String exceptionId = String.valueOf(exceptionDetail.get(ES_DOC_ID_KEY)); StringBuilder esQueryUrl = new StringBuilder(esUrl); esQueryUrl.append("/").append(dataSource).append("/" + targetType).append("_exception/") .append(exceptionId).append("?routing=" + routing); HttpClient client = HttpClientBuilder.create().build(); HttpDelete httpdelete = new HttpDelete(esQueryUrl.toString()); httpdelete.setHeader("Content-Type", ContentType.APPLICATION_JSON.toString()); client.execute(httpdelete); } catch (Exception exception) { logger.info("No Issue Exception found!!!" + exception); } return isUpdated; } } return false; } catch (Exception e) { throw new DataException(e); } } }
ComplianceRepositoryImpl implements ComplianceRepository, Constants { @Override public Boolean revokeAndUpdateIssueDetails(String issueId) throws DataException { try { List<Map<String, Object>> issueDetails = getExemptedIssueDetails(issueId); Boolean isUpdated = false; if (!issueDetails.isEmpty()) { Map<String, Object> issueDetail = issueDetails.get(0); Map<String, Object> issueExceptionDetails = Maps.newHashMap(); issueExceptionDetails.put(TARGET_TYPE, String.valueOf(issueDetail.get(TARGET_TYPE))); issueExceptionDetails.put("source", "issueException"); String dataSource = issueDetail.get(PAC_DS) + "_" + issueDetail.get(TARGET_TYPE); String targetType = issueDetail.get(TYPE) + "_" + issueDetail.get(TARGET_TYPE); String id = String.valueOf(issueDetail.get(ES_DOC_ID_KEY)); String routing = String.valueOf(issueDetail.get(ES_DOC_ROUTING_KEY)); String parent = String.valueOf(issueDetail.get(ES_DOC_PARENT_KEY)); Map<String, Object> partialDocument = Maps.newHashMap(); partialDocument.put(ISSUE_STATUS, OPEN); SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT, Locale.US); sdf.setTimeZone(TimeZone.getTimeZone("UTC")); partialDocument.put(MODIFIED_DATE, sdf.format(new Date())); partialDocument.put(STATUS, "revoked"); isUpdated = elasticSearchRepository.updatePartialDataToES(dataSource, targetType, id, routing, parent, partialDocument); if (isUpdated) { try { List<Map<String, Object>> exceptionDetails = getIssueDetails(issueId, null); Map<String, Object> exceptionDetail = exceptionDetails.get(0); String exceptionId = String.valueOf(exceptionDetail.get(ES_DOC_ID_KEY)); StringBuilder esQueryUrl = new StringBuilder(esUrl); esQueryUrl.append("/").append(dataSource).append("/" + targetType).append("_exception/") .append(exceptionId).append("?routing=" + routing); HttpClient client = HttpClientBuilder.create().build(); HttpDelete httpdelete = new HttpDelete(esQueryUrl.toString()); httpdelete.setHeader("Content-Type", ContentType.APPLICATION_JSON.toString()); client.execute(httpdelete); } catch (Exception exception) { logger.info("No Issue Exception found!!!" + exception); } return isUpdated; } } return false; } catch (Exception e) { throw new DataException(e); } }  }
ComplianceRepositoryImpl implements ComplianceRepository, Constants { @Override public Boolean revokeAndUpdateIssueDetails(String issueId) throws DataException { try { List<Map<String, Object>> issueDetails = getExemptedIssueDetails(issueId); Boolean isUpdated = false; if (!issueDetails.isEmpty()) { Map<String, Object> issueDetail = issueDetails.get(0); Map<String, Object> issueExceptionDetails = Maps.newHashMap(); issueExceptionDetails.put(TARGET_TYPE, String.valueOf(issueDetail.get(TARGET_TYPE))); issueExceptionDetails.put("source", "issueException"); String dataSource = issueDetail.get(PAC_DS) + "_" + issueDetail.get(TARGET_TYPE); String targetType = issueDetail.get(TYPE) + "_" + issueDetail.get(TARGET_TYPE); String id = String.valueOf(issueDetail.get(ES_DOC_ID_KEY)); String routing = String.valueOf(issueDetail.get(ES_DOC_ROUTING_KEY)); String parent = String.valueOf(issueDetail.get(ES_DOC_PARENT_KEY)); Map<String, Object> partialDocument = Maps.newHashMap(); partialDocument.put(ISSUE_STATUS, OPEN); SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT, Locale.US); sdf.setTimeZone(TimeZone.getTimeZone("UTC")); partialDocument.put(MODIFIED_DATE, sdf.format(new Date())); partialDocument.put(STATUS, "revoked"); isUpdated = elasticSearchRepository.updatePartialDataToES(dataSource, targetType, id, routing, parent, partialDocument); if (isUpdated) { try { List<Map<String, Object>> exceptionDetails = getIssueDetails(issueId, null); Map<String, Object> exceptionDetail = exceptionDetails.get(0); String exceptionId = String.valueOf(exceptionDetail.get(ES_DOC_ID_KEY)); StringBuilder esQueryUrl = new StringBuilder(esUrl); esQueryUrl.append("/").append(dataSource).append("/" + targetType).append("_exception/") .append(exceptionId).append("?routing=" + routing); HttpClient client = HttpClientBuilder.create().build(); HttpDelete httpdelete = new HttpDelete(esQueryUrl.toString()); httpdelete.setHeader("Content-Type", ContentType.APPLICATION_JSON.toString()); client.execute(httpdelete); } catch (Exception exception) { logger.info("No Issue Exception found!!!" + exception); } return isUpdated; } } return false; } catch (Exception e) { throw new DataException(e); } }  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 { @Override public Boolean revokeAndUpdateIssueDetails(String issueId) throws DataException { try { List<Map<String, Object>> issueDetails = getExemptedIssueDetails(issueId); Boolean isUpdated = false; if (!issueDetails.isEmpty()) { Map<String, Object> issueDetail = issueDetails.get(0); Map<String, Object> issueExceptionDetails = Maps.newHashMap(); issueExceptionDetails.put(TARGET_TYPE, String.valueOf(issueDetail.get(TARGET_TYPE))); issueExceptionDetails.put("source", "issueException"); String dataSource = issueDetail.get(PAC_DS) + "_" + issueDetail.get(TARGET_TYPE); String targetType = issueDetail.get(TYPE) + "_" + issueDetail.get(TARGET_TYPE); String id = String.valueOf(issueDetail.get(ES_DOC_ID_KEY)); String routing = String.valueOf(issueDetail.get(ES_DOC_ROUTING_KEY)); String parent = String.valueOf(issueDetail.get(ES_DOC_PARENT_KEY)); Map<String, Object> partialDocument = Maps.newHashMap(); partialDocument.put(ISSUE_STATUS, OPEN); SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT, Locale.US); sdf.setTimeZone(TimeZone.getTimeZone("UTC")); partialDocument.put(MODIFIED_DATE, sdf.format(new Date())); partialDocument.put(STATUS, "revoked"); isUpdated = elasticSearchRepository.updatePartialDataToES(dataSource, targetType, id, routing, parent, partialDocument); if (isUpdated) { try { List<Map<String, Object>> exceptionDetails = getIssueDetails(issueId, null); Map<String, Object> exceptionDetail = exceptionDetails.get(0); String exceptionId = String.valueOf(exceptionDetail.get(ES_DOC_ID_KEY)); StringBuilder esQueryUrl = new StringBuilder(esUrl); esQueryUrl.append("/").append(dataSource).append("/" + targetType).append("_exception/") .append(exceptionId).append("?routing=" + routing); HttpClient client = HttpClientBuilder.create().build(); HttpDelete httpdelete = new HttpDelete(esQueryUrl.toString()); httpdelete.setHeader("Content-Type", ContentType.APPLICATION_JSON.toString()); client.execute(httpdelete); } catch (Exception exception) { logger.info("No Issue Exception found!!!" + exception); } return isUpdated; } } return false; } catch (Exception e) { throw new DataException(e); } }  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);  }