Search in sources :

Example 1 with Result

use of com.checkmarx.flow.dto.servicenow.Result in project cx-flow by checkmarx-ltd.

the class ServiceNowTracker method getIssues.

/**
 * Get Incidents/Issues from Service Now.
 * @param request
 * @return issues collection of data.
 * @throws MachinaException
 */
@Override
public List<Issue> getIssues(ScanRequest request) throws MachinaException {
    log.debug("Executing getIssues Service Now API call");
    try {
        String apiRequest = createServiceNowRequest(request);
        URI apiRequestUri = URI.create(apiRequest);
        Optional<Result> res = Optional.ofNullable(restOperations.getForObject(apiRequestUri, Result.class));
        if (res.isPresent()) {
            List results = res.get().getIncidents().stream().map(i -> mapToIssue(i)).collect(Collectors.toList());
            log.debug("Found {} issues in ServiceNow for this project.", results != null ? results.size() : 0);
            return results;
        }
    } catch (RestClientException e) {
        log.error("Error occurred while fetching ServiceNow Issues");
        log.error(ExceptionUtils.getStackTrace(e));
        throw new MachinaRuntimeException();
    }
    return Lists.newArrayList();
}
Also used : Issue(com.checkmarx.flow.dto.Issue) ScanRequest(com.checkmarx.flow.dto.ScanRequest) ScanResults(com.checkmarx.sdk.dto.ScanResults) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) FlowProperties(com.checkmarx.flow.config.FlowProperties) HTMLHelper(com.checkmarx.flow.utils.HTMLHelper) Lists(com.google.common.collect.Lists) Service(org.springframework.stereotype.Service) Locale(java.util.Locale) URI(java.net.URI) RestClientException(org.springframework.web.client.RestClientException) Result(com.checkmarx.flow.dto.servicenow.Result) Logger(org.slf4j.Logger) RestOperations(org.springframework.web.client.RestOperations) RestTemplateBuilder(org.springframework.boot.web.client.RestTemplateBuilder) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) ServiceNowProperties(com.checkmarx.flow.config.ServiceNowProperties) HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) URLEncoder(java.net.URLEncoder) List(java.util.List) Incident(com.checkmarx.flow.dto.servicenow.Incident) MachinaRuntimeException(com.checkmarx.flow.exception.MachinaRuntimeException) ScanUtils(com.checkmarx.flow.utils.ScanUtils) Optional(java.util.Optional) MachinaException(com.checkmarx.flow.exception.MachinaException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) JSONArray(org.json.JSONArray) ExceptionUtils(org.apache.commons.lang3.exception.ExceptionUtils) MachinaRuntimeException(com.checkmarx.flow.exception.MachinaRuntimeException) RestClientException(org.springframework.web.client.RestClientException) List(java.util.List) URI(java.net.URI) Result(com.checkmarx.flow.dto.servicenow.Result)

Example 2 with Result

use of com.checkmarx.flow.dto.servicenow.Result in project cx-flow by checkmarx-ltd.

the class ServiceNowTracker method getIncidentByIDConvertToIssue.

/**
 * Find Incident By Sys ID and convert into Issue
 * @return Issue object.
 */
private Optional<Issue> getIncidentByIDConvertToIssue(String sysId) {
    log.debug("Executing getIncidentByIDConvertToIssue");
    try {
        String apiRequest = String.format("%s%s?sys_id=%s", properties.getApiUrl(), INCIDENTS, sysId);
        Optional<Result> res = Optional.ofNullable(restOperations.getForObject(apiRequest, Result.class));
        if (res.isPresent()) {
            return res.get().getIncidents().stream().map(i -> this.mapToIssue(i)).findFirst();
        }
    } catch (RestClientException e) {
        log.error("Error occurred while fetching ServiceNow Issue");
        log.error(ExceptionUtils.getStackTrace(e));
        throw new MachinaRuntimeException();
    }
    return Optional.empty();
}
Also used : Issue(com.checkmarx.flow.dto.Issue) ScanRequest(com.checkmarx.flow.dto.ScanRequest) ScanResults(com.checkmarx.sdk.dto.ScanResults) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) FlowProperties(com.checkmarx.flow.config.FlowProperties) HTMLHelper(com.checkmarx.flow.utils.HTMLHelper) Lists(com.google.common.collect.Lists) Service(org.springframework.stereotype.Service) Locale(java.util.Locale) URI(java.net.URI) RestClientException(org.springframework.web.client.RestClientException) Result(com.checkmarx.flow.dto.servicenow.Result) Logger(org.slf4j.Logger) RestOperations(org.springframework.web.client.RestOperations) RestTemplateBuilder(org.springframework.boot.web.client.RestTemplateBuilder) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) ServiceNowProperties(com.checkmarx.flow.config.ServiceNowProperties) HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) URLEncoder(java.net.URLEncoder) List(java.util.List) Incident(com.checkmarx.flow.dto.servicenow.Incident) MachinaRuntimeException(com.checkmarx.flow.exception.MachinaRuntimeException) ScanUtils(com.checkmarx.flow.utils.ScanUtils) Optional(java.util.Optional) MachinaException(com.checkmarx.flow.exception.MachinaException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) JSONArray(org.json.JSONArray) ExceptionUtils(org.apache.commons.lang3.exception.ExceptionUtils) MachinaRuntimeException(com.checkmarx.flow.exception.MachinaRuntimeException) RestClientException(org.springframework.web.client.RestClientException) Result(com.checkmarx.flow.dto.servicenow.Result)

Aggregations

FlowProperties (com.checkmarx.flow.config.FlowProperties)2 ServiceNowProperties (com.checkmarx.flow.config.ServiceNowProperties)2 Issue (com.checkmarx.flow.dto.Issue)2 ScanRequest (com.checkmarx.flow.dto.ScanRequest)2 Incident (com.checkmarx.flow.dto.servicenow.Incident)2 Result (com.checkmarx.flow.dto.servicenow.Result)2 MachinaException (com.checkmarx.flow.exception.MachinaException)2 MachinaRuntimeException (com.checkmarx.flow.exception.MachinaRuntimeException)2 HTMLHelper (com.checkmarx.flow.utils.HTMLHelper)2 ScanUtils (com.checkmarx.flow.utils.ScanUtils)2 ScanResults (com.checkmarx.sdk.dto.ScanResults)2 Lists (com.google.common.collect.Lists)2 Maps (com.google.common.collect.Maps)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 URI (java.net.URI)2 URLEncoder (java.net.URLEncoder)2 StandardCharsets (java.nio.charset.StandardCharsets)2 List (java.util.List)2 Locale (java.util.Locale)2 Optional (java.util.Optional)2