use of com.hp.octane.integrations.exceptions.ResourceNotFoundException 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);
}
use of com.hp.octane.integrations.exceptions.ResourceNotFoundException in project octane-ci-java-sdk by MicroFocus.
the class GithubV3FetchHandler method getEntity.
private <T extends Entity> T getEntity(String url, Class<T> entityType, RateLimitationInfo rateLimitationInfo) {
try {
OctaneRequest request = dtoFactory.newDTO(OctaneRequest.class).setUrl(url).setMethod(HttpMethod.GET);
OctaneResponse response = restClient.executeRequest(request);
if (response.getStatus() == HttpStatus.SC_NOT_FOUND) {
throw new ResourceNotFoundException(String.format("URL %s not found", url));
}
if (rateLimitationInfo != null) {
fillRateLimitationInfo(response, rateLimitationInfo);
}
return JsonConverter.convert(response.getBody(), entityType);
} catch (ResourceNotFoundException notFoundException) {
throw notFoundException;
} catch (Exception e) {
throw new RuntimeException("Failed to getEntity : " + e.getMessage(), e);
}
}
Aggregations