Search in sources :

Example 1 with PipelineContextList

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

the class PipelineContextServiceImpl method updatePipeline.

@Override
public PipelineContext updatePipeline(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());
    PipelineContextList list = dtoFactory.newDTO(PipelineContextList.class).setData(Arrays.asList(pipelineContext));
    String jsonData = dtoFactory.dtoToJson(list);
    OctaneRequest request = dtoFactory.newDTO(OctaneRequest.class).setMethod(HttpMethod.PUT).setUrl(url).setBody(jsonData).setHeaders(headers);
    OctaneResponse response = octaneRestClient.execute(request);
    validateResponse(HttpStatus.SC_OK, response);
    PipelineContextList resultList = dtoFactory.dtoFromJson(response.getBody(), PipelineContextList.class);
    // we might receive several pipeline context from other workspaces.
    // find updated context by id
    PipelineContext result = resultList.getData().stream().filter(p -> p.getContextEntityId() == pipelineContext.getContextEntityId()).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 2 with PipelineContextList

use of com.hp.octane.integrations.dto.pipelines.PipelineContextList 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 3 with PipelineContextList

use of com.hp.octane.integrations.dto.pipelines.PipelineContextList 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 4 with PipelineContextList

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

the class EntityDTOTests method testParsePipelineContextList.

@Test
public void testParsePipelineContextList() {
    String json = "{\"data\":[{\"contextEntityId\":2014,\"contextEntityName\":\"ss\",\"workspaceId\":1004,\"releaseId\":null,\"ciJob\":{\"ciServer\":{\"id\":2002,\"workspaceId\":1004,\"instanceId\":\"d7cb541b-c22e-4ed5-a566-65854fb7aae1\",\"url\":\"http://localhost:9192/jenkins\",\"type\":\"jenkins\",\"name\":\"local\",\"sendingTime\":null},\"jobId\":2008,\"workspaceId\":1004,\"jobCiId\":\"ss\",\"name\":\"ss\",\"parameters\":[]},\"ignoreTests\":true,\"rootJobCiId\":\"ss\",\"taxonomies\":[{\"id\":1120,\"parent\":{\"id\":1087,\"name\":\"DB\"}}],\"listFields\":{\"test_tool_type\":[],\"test_level\":[{\"id\":1457}],\"test_type\":[],\"test_framework\":[]},\"contextEntityType\":\"pipeline\",\"pipelineRoot\":true},{\"contextEntityId\":1004,\"contextEntityName\":\"ss\",\"workspaceId\":1003,\"releaseId\":1005,\"ciJob\":{\"ciServer\":{\"id\":1002,\"workspaceId\":1003,\"instanceId\":\"d7cb541b-c22e-4ed5-a566-65854fb7aae1\",\"url\":\"http://localhost:9192/jenkins\",\"type\":\"jenkins\",\"name\":\"LOCAL JENKINS\",\"sendingTime\":null},\"jobId\":1003,\"workspaceId\":1003,\"jobCiId\":\"ss\",\"name\":\"ss\",\"parameters\":[]},\"ignoreTests\":false,\"rootJobCiId\":\"ss\",\"taxonomies\":[{\"id\":1075,\"parent\":{\"id\":1044,\"name\":\"Distribution\"}},{\"id\":1078,\"parent\":{\"id\":1046,\"name\":\"DB\"}}],\"listFields\":{\"test_tool_type\":[{\"id\":1280}],\"test_level\":[{\"id\":1266}],\"test_type\":[{\"id\":1271}],\"test_framework\":[{\"id\":1255}]},\"contextEntityType\":\"pipeline\",\"pipelineRoot\":true}]}";
    PipelineContextList serializedList = dtoFactory.dtoFromJson(json, PipelineContextList.class);
    Assert.assertEquals(2, serializedList.getData().size());
}
Also used : PipelineContextList(com.hp.octane.integrations.dto.pipelines.PipelineContextList) Test(org.junit.Test)

Aggregations

PipelineContextList (com.hp.octane.integrations.dto.pipelines.PipelineContextList)4 OctaneRequest (com.hp.octane.integrations.dto.connectivity.OctaneRequest)3 OctaneResponse (com.hp.octane.integrations.dto.connectivity.OctaneResponse)3 OctaneRestClient (com.hp.octane.integrations.services.rest.OctaneRestClient)3 HashMap (java.util.HashMap)3 PipelineContext (com.hp.octane.integrations.dto.pipelines.PipelineContext)2 Test (org.junit.Test)1