Search in sources :

Example 1 with Incident

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

the class ServiceNowTracker method updateIncidentFromIssue.

/**
 * Update Incident from Issue.
 *
 * @param issue
 * @param resultIssue
 * @return Incident object.
 */
private Incident updateIncidentFromIssue(Issue issue, ScanResults.XIssue resultIssue) {
    Incident incident = new Incident();
    incident.setSysId(issue.getId());
    incident.setSeverity(getSeverityId(resultIssue.getSeverity()));
    incident.setState(TRANSITION_OPEN);
    incident.setIncidentState(TRANSITION_OPEN);
    return incident;
}
Also used : Incident(com.checkmarx.flow.dto.servicenow.Incident)

Example 2 with Incident

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

the class ServiceNowTracker method getCloseIncident.

/**
 * Create Service Now object out of the Issue/ScanRequest for close issue.
 * @return Incident object
 */
private Incident getCloseIncident() {
    Incident incident = new Incident();
    incident.setState(TRANSITION_CLOSE);
    incident.setIncidentState(TRANSITION_CLOSE);
    incident.setCloseNotes(String.format("Closing reason: %s", CLOSING_NOTE));
    incident.setCloseCode(CLOSE_CODE);
    return incident;
}
Also used : Incident(com.checkmarx.flow.dto.servicenow.Incident)

Example 3 with Incident

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

the class ServiceNowTracker method updateIssue.

@Override
public Issue updateIssue(Issue issue, ScanResults.XIssue resultIssue, ScanRequest request) throws MachinaException {
    log.info("Executing updateIssue Service Now API call");
    Incident incident = updateIncidentFromIssue(issue, resultIssue);
    try {
        String query = String.format("%s%s/%s", properties.getApiUrl(), INCIDENTS, issue.getId());
        this.addComment(incident, resultIssue.getLink(), "Issue still exists.");
        restOperations.put(query, incident);
        return getIssues(request).stream().findFirst().orElseThrow(() -> new MachinaException("Incident record hasn't been found."));
    } catch (HttpClientErrorException e) {
        log.error("Error updating issue.");
        throw new MachinaRuntimeException();
    }
}
Also used : HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) MachinaRuntimeException(com.checkmarx.flow.exception.MachinaRuntimeException) MachinaException(com.checkmarx.flow.exception.MachinaException) Incident(com.checkmarx.flow.dto.servicenow.Incident)

Example 4 with Incident

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

the class ServiceNowTracker method getCreateIncident.

/**
 * Create Service Now object out of the Issue/ScanRequest for a new/update issue.
 * @param resultIssue
 * @param request
 * @return Incident object
 */
private Incident getCreateIncident(ScanResults.XIssue resultIssue, ScanRequest request) {
    String tag = createServiceNowTag(request);
    String title = HTMLHelper.getScanRequestIssueKeyWithDefaultProductValue(request, this, resultIssue);
    String body = HTMLHelper.getTextBody(resultIssue, request, flowProperties);
    Incident incident = new Incident();
    incident.setShortDescription(title);
    incident.setDescription(convertToText(body));
    incident.setSeverity(getSeverityId(resultIssue.getSeverity()));
    incident.setComments(tag);
    incident.setWorkNotes(request.getAdditionalMetadata("tagsList"));
    incident.setState(TRANSITION_OPEN);
    incident.setIncidentState(TRANSITION_OPEN);
    return incident;
}
Also used : Incident(com.checkmarx.flow.dto.servicenow.Incident)

Example 5 with Incident

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

the class ServiceNowTracker method closeIssue.

@Override
public void closeIssue(Issue issue, ScanRequest request) throws MachinaException {
    log.info("Executing closeIssue Service Now API call");
    Incident incident = getCloseIncident();
    try {
        String query = String.format("%s%s/%s", properties.getApiUrl(), INCIDENTS, issue.getId());
        log.debug("ServiceNow Close Issues URL: {}", query);
        restOperations.put(query, incident);
    } catch (HttpClientErrorException e) {
        log.error("Error closing issue.Details are:" + e.getMessage());
        throw new MachinaRuntimeException(e);
    }
}
Also used : HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) MachinaRuntimeException(com.checkmarx.flow.exception.MachinaRuntimeException) Incident(com.checkmarx.flow.dto.servicenow.Incident)

Aggregations

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