All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.synopsys.integration.blackduck.service.request.BlackDuckRequest Maven / Gradle / Ivy

Go to download

A library for using various capabilities of Black Duck, notably the REST API and signature scanning.

There is a newer version: 66.2.19
Show newest version
/*
 * blackduck-common
 *
 * Copyright (c) 2023 Synopsys, Inc.
 *
 * Use subject to the terms and conditions of the Synopsys End User Software License and Maintenance Agreement. All rights reserved worldwide.
 */
package com.synopsys.integration.blackduck.service.request;

import com.synopsys.integration.blackduck.api.core.BlackDuckResponse;
import com.synopsys.integration.blackduck.api.core.response.UrlMultipleResponses;
import com.synopsys.integration.blackduck.api.core.response.UrlResponse;
import com.synopsys.integration.blackduck.api.core.response.UrlSingleResponse;
import com.synopsys.integration.blackduck.api.generated.discovery.BlackDuckMediaTypeDiscovery;
import com.synopsys.integration.blackduck.http.BlackDuckRequestBuilder;
import com.synopsys.integration.rest.HttpMethod;
import com.synopsys.integration.rest.HttpUrl;
import com.synopsys.integration.rest.request.Request;

/**
 * The total picture of a Black Duck interaction. Intended to be an immutable,
 * valid packaging of an HTTP request to Black Duck and how to consider and
 * handle the response.
 */
public class BlackDuckRequest> {
    private static final PagingDefaultsEditor DEFAULT_PAGING_DEFAULTS_EDITOR = new PagingDefaultsEditor();
    private static final AcceptHeaderEditor DEFAULT_ACCEPT_HEADER_EDITOR = new AcceptHeaderEditor(new BlackDuckMediaTypeDiscovery());

    private final BlackDuckRequestBuilder blackDuckRequestBuilder;
    private final U urlResponse;

    public static  BlackDuckRequest> createSingleRequest(BlackDuckRequestBuilder blackDuckRequestBuilder, HttpUrl url, Class responseClass) {
        return new BlackDuckSingleRequest(blackDuckRequestBuilder, new UrlSingleResponse(url, responseClass));
    }

    public static  BlackDuckMultipleRequest createMultipleRequest(BlackDuckRequestBuilder blackDuckRequestBuilder, HttpUrl url, Class responseClass) {
        return new BlackDuckMultipleRequest(blackDuckRequestBuilder, new UrlMultipleResponses(url, responseClass));
    }

    public BlackDuckRequest(BlackDuckRequestBuilder blackDuckRequestBuilder, U urlResponse) {
        this(blackDuckRequestBuilder, urlResponse, DEFAULT_PAGING_DEFAULTS_EDITOR, DEFAULT_ACCEPT_HEADER_EDITOR);
    }

    public BlackDuckRequest(BlackDuckRequestBuilder blackDuckRequestBuilder, U urlResponse, PagingDefaultsEditor pagingDefaultsEditor, AcceptHeaderEditor acceptHeaderEditor) {
        this.blackDuckRequestBuilder = blackDuckRequestBuilder.url(urlResponse.getUrl());
        this.urlResponse = urlResponse;

        blackDuckRequestBuilder.apply(acceptHeaderEditor);

        if (HttpMethod.GET == blackDuckRequestBuilder.getMethod()) {
            blackDuckRequestBuilder.apply(pagingDefaultsEditor);
        }
    }

    public Request getRequest() {
        return blackDuckRequestBuilder.build();
    }

    public U getUrlResponse() {
        return urlResponse;
    }

    public HttpUrl getUrl() {
        return urlResponse.getUrl();
    }

    public Class getResponseClass() {
        return urlResponse.getResponseClass();
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy