Search in sources :

Example 1 with CxPreset

use of com.checkmarx.sdk.dto.cx.CxPreset in project checkmarx-spring-boot-java-sdk by checkmarx-ltd.

the class ScanSettingsClientImpl method getPresetId.

@Override
public int getPresetId(String presetName) throws CheckmarxException {
    HttpEntity<Void> httpEntity = new HttpEntity<>(authClient.createAuthHeaders());
    int defaultPresetId = Constants.UNKNOWN_INT;
    try {
        log.info("Retrieving Cx presets");
        ResponseEntity<CxPreset[]> response = restTemplate.exchange(cxProperties.getUrl().concat(PRESETS), HttpMethod.GET, httpEntity, CxPreset[].class);
        CxPreset[] cxPresets = response.getBody();
        if (cxPresets == null) {
            throw new CheckmarxException("Error obtaining Team Id");
        }
        for (CxPreset cxPreset : cxPresets) {
            String currentPresetName = cxPreset.getName();
            int presetId = cxPreset.getId();
            if (currentPresetName.equalsIgnoreCase(presetName)) {
                log.info("Found preset '{}' with ID {}", presetName, presetId);
                return cxPreset.getId();
            }
            if (currentPresetName.equalsIgnoreCase(Constants.CX_DEFAULT_PRESET)) {
                defaultPresetId = presetId;
            }
        }
        log.warn("No Preset was found for '{}'", presetName);
        log.warn("Default Preset {} with ID {} will be used instead", Constants.CX_DEFAULT_PRESET, defaultPresetId);
        return defaultPresetId;
    } catch (HttpStatusCodeException e) {
        log.error("Error occurred while retrieving presets");
        log.error(ExceptionUtils.getStackTrace(e));
        throw new CheckmarxException("Error obtaining Preset Id");
    }
}
Also used : CxPreset(com.checkmarx.sdk.dto.cx.CxPreset) HttpEntity(org.springframework.http.HttpEntity) CheckmarxException(com.checkmarx.sdk.exception.CheckmarxException) HttpStatusCodeException(org.springframework.web.client.HttpStatusCodeException)

Aggregations

CxPreset (com.checkmarx.sdk.dto.cx.CxPreset)1 CheckmarxException (com.checkmarx.sdk.exception.CheckmarxException)1 HttpEntity (org.springframework.http.HttpEntity)1 HttpStatusCodeException (org.springframework.web.client.HttpStatusCodeException)1