@Test public void getPolicyViolationDetailsByIssueIdTest() throws Exception { when( complianceRepository.getPolicyViolationDetailsByIssueId( anyString(), anyString())).thenReturn(CommonTestUtil.getMapObject()); when(complianceRepository.getRuleDescriptionFromDb(anyString())) .thenReturn(CommonTestUtil.getMapList()); assertThat(complianceService.getPolicyViolationDetailsByIssueId( "dummyString", "dummyString"), is(notNullValue())); when( complianceRepository.getPolicyViolationDetailsByIssueId( anyString(), anyString())).thenThrow( new DataException()); assertThatThrownBy( () -> complianceService.getPolicyViolationDetailsByIssueId( "dummyString", "dummyString")).isInstanceOf( ServiceException.class); }
public PolicyViolationDetails getPolicyViolationDetailsByIssueId(String assetGroup, String issueId) throws ServiceException { String policyViolated = null; String policyDescription = null; String resourceId = null; String ruleId = null; String issueDetails = null; List<Map<String, Object>> violationList = new ArrayList<>(); Map<String, Object> violation = null; Map<String, Object> policyViolationByIssueId; try { policyViolationByIssueId = repository.getPolicyViolationDetailsByIssueId(assetGroup, issueId); } catch (DataException e) { throw new ServiceException(e); } if (!policyViolationByIssueId.isEmpty()) { ruleId = policyViolationByIssueId.get(RULEID).toString(); resourceId = policyViolationByIssueId.get(RESOURCEID).toString(); policyDescription = (null != getRuleDescription(ruleId).get(RULE_DESC)) ? getRuleDescription(ruleId).get( RULE_DESC).toString() : ""; policyViolated = (null != getRuleDescription(ruleId).get(DISPLAY_NAME)) ? getRuleDescription(ruleId).get( DISPLAY_NAME).toString() : ""; issueDetails = (null != policyViolationByIssueId.get(ISSUE_DETAILS)) ? policyViolationByIssueId.get( ISSUE_DETAILS).toString() : null; if (null != issueDetails) { issueDetails = issueDetails.substring(TWO, issueDetails.length() - TWO); violation = Arrays.stream(issueDetails.trim().split(", ")).map(s -> s.split("=")) .collect(Collectors.toMap(a -> a[0], a -> a[1] )); violation.remove("violationReason"); violationList.add(violation); } return new PolicyViolationDetails(policyViolationByIssueId.get(TARGET_TYPE).toString(), policyViolationByIssueId.get(ISSUE_STATUS).toString(), policyViolationByIssueId.get(SEVERITY) .toString(), policyViolationByIssueId.get(RULE_CATEGORY).toString(), resourceId, policyViolated, policyDescription, policyViolationByIssueId.get(ISSUE_REASON).toString(), policyViolationByIssueId.get(CREATED_DATE).toString(), policyViolationByIssueId.get(MODIFIED_DATE) .toString(), policyViolationByIssueId.get(POLICYID).toString(), ruleId, violationList); } else { throw new ServiceException(NO_DATA_FOUND); } }
ComplianceServiceImpl implements ComplianceService, Constants { public PolicyViolationDetails getPolicyViolationDetailsByIssueId(String assetGroup, String issueId) throws ServiceException { String policyViolated = null; String policyDescription = null; String resourceId = null; String ruleId = null; String issueDetails = null; List<Map<String, Object>> violationList = new ArrayList<>(); Map<String, Object> violation = null; Map<String, Object> policyViolationByIssueId; try { policyViolationByIssueId = repository.getPolicyViolationDetailsByIssueId(assetGroup, issueId); } catch (DataException e) { throw new ServiceException(e); } if (!policyViolationByIssueId.isEmpty()) { ruleId = policyViolationByIssueId.get(RULEID).toString(); resourceId = policyViolationByIssueId.get(RESOURCEID).toString(); policyDescription = (null != getRuleDescription(ruleId).get(RULE_DESC)) ? getRuleDescription(ruleId).get( RULE_DESC).toString() : ""; policyViolated = (null != getRuleDescription(ruleId).get(DISPLAY_NAME)) ? getRuleDescription(ruleId).get( DISPLAY_NAME).toString() : ""; issueDetails = (null != policyViolationByIssueId.get(ISSUE_DETAILS)) ? policyViolationByIssueId.get( ISSUE_DETAILS).toString() : null; if (null != issueDetails) { issueDetails = issueDetails.substring(TWO, issueDetails.length() - TWO); violation = Arrays.stream(issueDetails.trim().split(", ")).map(s -> s.split("=")) .collect(Collectors.toMap(a -> a[0], a -> a[1] )); violation.remove("violationReason"); violationList.add(violation); } return new PolicyViolationDetails(policyViolationByIssueId.get(TARGET_TYPE).toString(), policyViolationByIssueId.get(ISSUE_STATUS).toString(), policyViolationByIssueId.get(SEVERITY) .toString(), policyViolationByIssueId.get(RULE_CATEGORY).toString(), resourceId, policyViolated, policyDescription, policyViolationByIssueId.get(ISSUE_REASON).toString(), policyViolationByIssueId.get(CREATED_DATE).toString(), policyViolationByIssueId.get(MODIFIED_DATE) .toString(), policyViolationByIssueId.get(POLICYID).toString(), ruleId, violationList); } else { throw new ServiceException(NO_DATA_FOUND); } } }
ComplianceServiceImpl implements ComplianceService, Constants { public PolicyViolationDetails getPolicyViolationDetailsByIssueId(String assetGroup, String issueId) throws ServiceException { String policyViolated = null; String policyDescription = null; String resourceId = null; String ruleId = null; String issueDetails = null; List<Map<String, Object>> violationList = new ArrayList<>(); Map<String, Object> violation = null; Map<String, Object> policyViolationByIssueId; try { policyViolationByIssueId = repository.getPolicyViolationDetailsByIssueId(assetGroup, issueId); } catch (DataException e) { throw new ServiceException(e); } if (!policyViolationByIssueId.isEmpty()) { ruleId = policyViolationByIssueId.get(RULEID).toString(); resourceId = policyViolationByIssueId.get(RESOURCEID).toString(); policyDescription = (null != getRuleDescription(ruleId).get(RULE_DESC)) ? getRuleDescription(ruleId).get( RULE_DESC).toString() : ""; policyViolated = (null != getRuleDescription(ruleId).get(DISPLAY_NAME)) ? getRuleDescription(ruleId).get( DISPLAY_NAME).toString() : ""; issueDetails = (null != policyViolationByIssueId.get(ISSUE_DETAILS)) ? policyViolationByIssueId.get( ISSUE_DETAILS).toString() : null; if (null != issueDetails) { issueDetails = issueDetails.substring(TWO, issueDetails.length() - TWO); violation = Arrays.stream(issueDetails.trim().split(", ")).map(s -> s.split("=")) .collect(Collectors.toMap(a -> a[0], a -> a[1] )); violation.remove("violationReason"); violationList.add(violation); } return new PolicyViolationDetails(policyViolationByIssueId.get(TARGET_TYPE).toString(), policyViolationByIssueId.get(ISSUE_STATUS).toString(), policyViolationByIssueId.get(SEVERITY) .toString(), policyViolationByIssueId.get(RULE_CATEGORY).toString(), resourceId, policyViolated, policyDescription, policyViolationByIssueId.get(ISSUE_REASON).toString(), policyViolationByIssueId.get(CREATED_DATE).toString(), policyViolationByIssueId.get(MODIFIED_DATE) .toString(), policyViolationByIssueId.get(POLICYID).toString(), ruleId, violationList); } else { throw new ServiceException(NO_DATA_FOUND); } }  }
ComplianceServiceImpl implements ComplianceService, Constants { public PolicyViolationDetails getPolicyViolationDetailsByIssueId(String assetGroup, String issueId) throws ServiceException { String policyViolated = null; String policyDescription = null; String resourceId = null; String ruleId = null; String issueDetails = null; List<Map<String, Object>> violationList = new ArrayList<>(); Map<String, Object> violation = null; Map<String, Object> policyViolationByIssueId; try { policyViolationByIssueId = repository.getPolicyViolationDetailsByIssueId(assetGroup, issueId); } catch (DataException e) { throw new ServiceException(e); } if (!policyViolationByIssueId.isEmpty()) { ruleId = policyViolationByIssueId.get(RULEID).toString(); resourceId = policyViolationByIssueId.get(RESOURCEID).toString(); policyDescription = (null != getRuleDescription(ruleId).get(RULE_DESC)) ? getRuleDescription(ruleId).get( RULE_DESC).toString() : ""; policyViolated = (null != getRuleDescription(ruleId).get(DISPLAY_NAME)) ? getRuleDescription(ruleId).get( DISPLAY_NAME).toString() : ""; issueDetails = (null != policyViolationByIssueId.get(ISSUE_DETAILS)) ? policyViolationByIssueId.get( ISSUE_DETAILS).toString() : null; if (null != issueDetails) { issueDetails = issueDetails.substring(TWO, issueDetails.length() - TWO); violation = Arrays.stream(issueDetails.trim().split(", ")).map(s -> s.split("=")) .collect(Collectors.toMap(a -> a[0], a -> a[1] )); violation.remove("violationReason"); violationList.add(violation); } return new PolicyViolationDetails(policyViolationByIssueId.get(TARGET_TYPE).toString(), policyViolationByIssueId.get(ISSUE_STATUS).toString(), policyViolationByIssueId.get(SEVERITY) .toString(), policyViolationByIssueId.get(RULE_CATEGORY).toString(), resourceId, policyViolated, policyDescription, policyViolationByIssueId.get(ISSUE_REASON).toString(), policyViolationByIssueId.get(CREATED_DATE).toString(), policyViolationByIssueId.get(MODIFIED_DATE) .toString(), policyViolationByIssueId.get(POLICYID).toString(), ruleId, violationList); } else { throw new ServiceException(NO_DATA_FOUND); } }  @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 PolicyViolationDetails getPolicyViolationDetailsByIssueId(String assetGroup, String issueId) throws ServiceException { String policyViolated = null; String policyDescription = null; String resourceId = null; String ruleId = null; String issueDetails = null; List<Map<String, Object>> violationList = new ArrayList<>(); Map<String, Object> violation = null; Map<String, Object> policyViolationByIssueId; try { policyViolationByIssueId = repository.getPolicyViolationDetailsByIssueId(assetGroup, issueId); } catch (DataException e) { throw new ServiceException(e); } if (!policyViolationByIssueId.isEmpty()) { ruleId = policyViolationByIssueId.get(RULEID).toString(); resourceId = policyViolationByIssueId.get(RESOURCEID).toString(); policyDescription = (null != getRuleDescription(ruleId).get(RULE_DESC)) ? getRuleDescription(ruleId).get( RULE_DESC).toString() : ""; policyViolated = (null != getRuleDescription(ruleId).get(DISPLAY_NAME)) ? getRuleDescription(ruleId).get( DISPLAY_NAME).toString() : ""; issueDetails = (null != policyViolationByIssueId.get(ISSUE_DETAILS)) ? policyViolationByIssueId.get( ISSUE_DETAILS).toString() : null; if (null != issueDetails) { issueDetails = issueDetails.substring(TWO, issueDetails.length() - TWO); violation = Arrays.stream(issueDetails.trim().split(", ")).map(s -> s.split("=")) .collect(Collectors.toMap(a -> a[0], a -> a[1] )); violation.remove("violationReason"); violationList.add(violation); } return new PolicyViolationDetails(policyViolationByIssueId.get(TARGET_TYPE).toString(), policyViolationByIssueId.get(ISSUE_STATUS).toString(), policyViolationByIssueId.get(SEVERITY) .toString(), policyViolationByIssueId.get(RULE_CATEGORY).toString(), resourceId, policyViolated, policyDescription, policyViolationByIssueId.get(ISSUE_REASON).toString(), policyViolationByIssueId.get(CREATED_DATE).toString(), policyViolationByIssueId.get(MODIFIED_DATE) .toString(), policyViolationByIssueId.get(POLICYID).toString(), ruleId, violationList); } else { throw new ServiceException(NO_DATA_FOUND); } }  @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);  }