use of bio.terra.workspace.common.utils.ErrorReportUtils in project terra-workspace-manager by DataBiosphere.
the class Alpha1ApiController method enumerateJobs.
@Override
public ResponseEntity<ApiEnumerateJobsResult> enumerateJobs(UUID workspaceId, Integer limit, String pageToken, ApiResourceType resource, ApiStewardshipType stewardship, String name, ApiJobStateFilter jobState) {
// Make sure Alpha1 is enabled
features.alpha1EnabledCheck();
// Prepare the inputs
final AuthenticatedUserRequest userRequest = getAuthenticatedInfo();
ControllerValidationUtils.validatePaginationParams(0, limit);
ResourceValidationUtils.validateOptionalResourceName(name);
// Make sure the caller has read access to the workspace
workspaceService.validateWorkspaceAndAction(userRequest, workspaceId, SamWorkspaceAction.READ);
// Do the enumeration
EnumeratedJobs enumeratedJobs = alpha1Service.enumerateJobs(workspaceId, userRequest, limit, pageToken, WsmResourceFamily.fromApiOptional(resource), StewardshipType.fromApiOptional(stewardship), name, JobStateFilter.fromApi(jobState));
// Convert the result to API-speak
List<ApiEnumeratedJob> apiJobList = new ArrayList<>();
for (EnumeratedJob enumeratedJob : enumeratedJobs.getResults()) {
ApiJobReport jobReport = jobService.mapFlightStateToApiJobReport(enumeratedJob.getFlightState());
Optional<WsmResource> optResource = enumeratedJob.getResource();
ApiEnumeratedJob apiJob = new ApiEnumeratedJob().jobReport(jobReport).errorReport(enumeratedJob.getFlightState().getException().map(ErrorReportUtils::buildApiErrorReport).orElse(null)).jobDescription(enumeratedJob.getJobDescription()).operationType(enumeratedJob.getOperationType().toApiModel()).resourceType(optResource.map(r -> r.getResourceType().toApiModel()).orElse(null)).resource(optResource.map(WsmResource::toApiResourceUnion).orElse(null));
apiJobList.add(apiJob);
}
ApiEnumerateJobsResult result = new ApiEnumerateJobsResult().pageToken(enumeratedJobs.getPageToken()).totalResults(enumeratedJobs.getTotalResults()).results(apiJobList);
return new ResponseEntity<>(result, HttpStatus.OK);
}
Aggregations