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;
}
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();
}
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;
}
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;
}
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);
}
Aggregations