Search in sources :

Example 21 with OctaneResponse

use of com.hp.octane.integrations.dto.connectivity.OctaneResponse in project octane-ci-java-sdk by MicroFocus.

the class EntitiesServiceImpl method getPagedEntities.

@Override
public ResponseEntityList getPagedEntities(String url) {
    OctaneRestClient octaneRestClient = restService.obtainOctaneRestClient();
    Map<String, String> headers = new HashMap<>();
    headers.put(ACCEPT_HEADER, ContentType.APPLICATION_JSON.getMimeType());
    headers.put(OctaneRestClient.CLIENT_TYPE_HEADER, OctaneRestClient.CLIENT_TYPE_VALUE);
    OctaneRequest request = dtoFactory.newDTO(OctaneRequest.class).setMethod(HttpMethod.GET).setUrl(url).setHeaders(headers);
    OctaneResponse response = executeRequest(octaneRestClient, request);
    ResponseEntityList pagedEntityList = parseBody(HttpStatus.SC_OK, response);
    return pagedEntityList;
}
Also used : OctaneResponse(com.hp.octane.integrations.dto.connectivity.OctaneResponse) OctaneRequest(com.hp.octane.integrations.dto.connectivity.OctaneRequest) OctaneRestClient(com.hp.octane.integrations.services.rest.OctaneRestClient)

Example 22 with OctaneResponse

use of com.hp.octane.integrations.dto.connectivity.OctaneResponse in project octane-ci-java-sdk by MicroFocus.

the class EntitiesServiceImpl method postEntities.

@Override
public List<Entity> postEntities(Long workspaceId, String entityCollectionName, String jsonData, Collection<String> fields, Map<String, String> serviceArgument) {
    OctaneRestClient octaneRestClient = restService.obtainOctaneRestClient();
    Map<String, String> headers = new HashMap<>();
    headers.put(ACCEPT_HEADER, ContentType.APPLICATION_JSON.getMimeType());
    headers.put(CONTENT_TYPE_HEADER, ContentType.APPLICATION_JSON.getMimeType());
    headers.put(OctaneRestClient.CLIENT_TYPE_HEADER, OctaneRestClient.CLIENT_TYPE_VALUE);
    String url = buildEntityUrl(workspaceId, entityCollectionName, null, fields, null, null, null, serviceArgument);
    OctaneRequest request = dtoFactory.newDTO(OctaneRequest.class).setMethod(HttpMethod.POST).setUrl(url).setBody(jsonData).setHeaders(headers);
    OctaneResponse response = executeRequest(octaneRestClient, request);
    ResponseEntityList responseEntityList = parseBody(HttpStatus.SC_CREATED, response);
    return responseEntityList.getData();
}
Also used : OctaneResponse(com.hp.octane.integrations.dto.connectivity.OctaneResponse) OctaneRequest(com.hp.octane.integrations.dto.connectivity.OctaneRequest) OctaneRestClient(com.hp.octane.integrations.services.rest.OctaneRestClient)

Example 23 with OctaneResponse

use of com.hp.octane.integrations.dto.connectivity.OctaneResponse in project octane-ci-java-sdk by MicroFocus.

the class PipelineContextServiceImpl method createPipeline.

@Override
public PipelineContext createPipeline(String serverIdentity, String jobName, PipelineContext pipelineContext) throws IOException {
    String url = getConfigurationUrl(serverIdentity, jobName);
    validateReleaseAndMilestone(pipelineContext);
    OctaneRestClient octaneRestClient = restService.obtainOctaneRestClient();
    Map<String, String> headers = new HashMap<>();
    headers.put(ACCEPT_HEADER, ContentType.APPLICATION_JSON.getMimeType());
    headers.put(CONTENT_TYPE_HEADER, ContentType.APPLICATION_JSON.getMimeType());
    String jsonData = dtoFactory.dtoToJson(pipelineContext);
    OctaneRequest request = dtoFactory.newDTO(OctaneRequest.class).setMethod(HttpMethod.POST).setUrl(url).setBody(jsonData).setHeaders(headers);
    OctaneResponse response = octaneRestClient.execute(request);
    validateResponse(HttpStatus.SC_CREATED, response);
    PipelineContextList list = dtoFactory.dtoFromJson(response.getBody(), PipelineContextList.class);
    // we might receive several pipeline context from other workspaces.
    // find updated context by workspace id
    PipelineContext result = list.getData().stream().filter(p -> p.getWorkspaceId() == pipelineContext.getWorkspaceId()).findFirst().get();
    return result;
}
Also used : HashMap(java.util.HashMap) PipelineContext(com.hp.octane.integrations.dto.pipelines.PipelineContext) PipelineContextList(com.hp.octane.integrations.dto.pipelines.PipelineContextList) OctaneResponse(com.hp.octane.integrations.dto.connectivity.OctaneResponse) OctaneRequest(com.hp.octane.integrations.dto.connectivity.OctaneRequest) OctaneRestClient(com.hp.octane.integrations.services.rest.OctaneRestClient)

Example 24 with OctaneResponse

use of com.hp.octane.integrations.dto.connectivity.OctaneResponse in project octane-ci-java-sdk by MicroFocus.

the class PipelineContextServiceImpl method getJobConfiguration.

@Override
public PipelineContextList getJobConfiguration(String serverIdentity, String jobName) throws IOException {
    String url = getConfigurationUrl(serverIdentity, jobName);
    OctaneRestClient octaneRestClient = restService.obtainOctaneRestClient();
    Map<String, String> headers = new HashMap<>();
    headers.put(ACCEPT_HEADER, ContentType.APPLICATION_JSON.getMimeType());
    OctaneRequest request = dtoFactory.newDTO(OctaneRequest.class).setMethod(HttpMethod.GET).setUrl(url).setHeaders(headers);
    OctaneResponse response = octaneRestClient.execute(request);
    validateResponse(HttpStatus.SC_OK, response);
    PipelineContextList result = dtoFactory.dtoFromJson(response.getBody(), PipelineContextList.class);
    return result;
}
Also used : HashMap(java.util.HashMap) PipelineContextList(com.hp.octane.integrations.dto.pipelines.PipelineContextList) OctaneResponse(com.hp.octane.integrations.dto.connectivity.OctaneResponse) OctaneRequest(com.hp.octane.integrations.dto.connectivity.OctaneRequest) OctaneRestClient(com.hp.octane.integrations.services.rest.OctaneRestClient)

Example 25 with OctaneResponse

use of com.hp.octane.integrations.dto.connectivity.OctaneResponse in project octane-ci-java-sdk by MicroFocus.

the class PullRequestAndBranchServiceImpl method sendPullRequests.

@Override
public void sendPullRequests(List<PullRequest> pullRequests, String workspaceId, PullRequestFetchParameters pullRequestFetchParameters, Consumer<String> logConsumer) throws IOException {
    Map<String, String> headers = new LinkedHashMap<>();
    headers.put(RestService.CONTENT_TYPE_HEADER, ContentType.APPLICATION_JSON.getMimeType());
    String url = configurer.octaneConfiguration.getUrl() + RestService.SHARED_SPACE_API_PATH_PART + configurer.octaneConfiguration.getSharedSpace() + "/workspaces/" + workspaceId + RestService.ANALYTICS_CI_PATH_PART + "pull-requests/";
    int sentCounter = 0;
    List<List<PullRequest>> subSets = ListUtils.partition(pullRequests, 200);
    for (List<PullRequest> list : subSets) {
        String json = dtoFactory.dtoCollectionToJson(list);
        OctaneRequest octaneRequest = dtoFactory.newDTO(OctaneRequest.class).setMethod(HttpMethod.PUT).setUrl(url).setHeaders(headers).setBody(json);
        OctaneResponse octaneResponse = restService.obtainOctaneRestClient().execute(octaneRequest);
        if (octaneResponse.getStatus() != HttpStatus.SC_OK) {
            if (octaneResponse.getStatus() == HttpStatus.SC_NOT_FOUND) {
                throw new ResourceNotFoundException("Failed to sendPullRequests : received 404 status. Validate that you use correct workspace id and ALM Octane version is greater than " + PullRequestAndBranchService.BRANCH_COLLECTION_SUPPORTED_VERSION);
            } else {
                throw new RuntimeException("Failed to sendPullRequests : (" + octaneResponse.getStatus() + ")" + octaneResponse.getBody());
            }
        } else {
            sentCounter += list.size();
            logConsumer.accept(String.format("Sent %s/%s pull requests.", sentCounter, pullRequests.size()));
        }
    }
    long lastUpdateTime = pullRequests.stream().map(PullRequest::getUpdatedTime).max(Comparator.naturalOrder()).orElse(0L);
    savePullRequestLastUpdateTime(workspaceId, pullRequestFetchParameters.getRepoUrl(), lastUpdateTime);
    logConsumer.accept("Last update time set to " + lastUpdateTime);
}
Also used : PullRequest(com.hp.octane.integrations.dto.scm.PullRequest) OctaneRequest(com.hp.octane.integrations.dto.connectivity.OctaneRequest) OctaneResponse(com.hp.octane.integrations.dto.connectivity.OctaneResponse) ResourceNotFoundException(com.hp.octane.integrations.exceptions.ResourceNotFoundException)

Aggregations

OctaneResponse (com.hp.octane.integrations.dto.connectivity.OctaneResponse)36 OctaneRequest (com.hp.octane.integrations.dto.connectivity.OctaneRequest)27 IOException (java.io.IOException)14 PermanentException (com.hp.octane.integrations.exceptions.PermanentException)10 TemporaryException (com.hp.octane.integrations.exceptions.TemporaryException)10 OctaneRestClient (com.hp.octane.integrations.services.rest.OctaneRestClient)10 HashMap (java.util.HashMap)7 InputStream (java.io.InputStream)4 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)3 PipelineContextList (com.hp.octane.integrations.dto.pipelines.PipelineContextList)3 RequestTimeoutException (com.hp.octane.integrations.exceptions.RequestTimeoutException)3 ResourceNotFoundException (com.hp.octane.integrations.exceptions.ResourceNotFoundException)3 InterruptedIOException (java.io.InterruptedIOException)3 HttpResponse (org.apache.http.HttpResponse)3 HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)3 HttpClientContext (org.apache.http.client.protocol.HttpClientContext)3 OctaneConfiguration (com.hp.octane.integrations.OctaneConfiguration)2 PipelineContext (com.hp.octane.integrations.dto.pipelines.PipelineContext)2 OctaneConnectivityException (com.hp.octane.integrations.exceptions.OctaneConnectivityException)2 Header (org.apache.http.Header)2