Search in sources :

Example 1 with ApiJobStateFilter

use of bio.terra.workspace.generated.model.ApiJobStateFilter 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);
}
Also used : WsmResource(bio.terra.workspace.service.resource.model.WsmResource) WorkspaceService(bio.terra.workspace.service.workspace.WorkspaceService) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) Controller(org.springframework.stereotype.Controller) ApiJobReport(bio.terra.workspace.generated.model.ApiJobReport) AuthenticatedUserRequest(bio.terra.workspace.service.iam.AuthenticatedUserRequest) EnumeratedJob(bio.terra.workspace.service.workspace.model.EnumeratedJob) ArrayList(java.util.ArrayList) HttpServletRequest(javax.servlet.http.HttpServletRequest) JobStateFilter(bio.terra.workspace.service.workspace.model.JobStateFilter) ResourceValidationUtils(bio.terra.workspace.service.resource.ResourceValidationUtils) StewardshipType(bio.terra.workspace.service.resource.model.StewardshipType) ApiStewardshipType(bio.terra.workspace.generated.model.ApiStewardshipType) ApiJobStateFilter(bio.terra.workspace.generated.model.ApiJobStateFilter) ControllerValidationUtils(bio.terra.workspace.common.utils.ControllerValidationUtils) ApiEnumeratedJob(bio.terra.workspace.generated.model.ApiEnumeratedJob) JobService(bio.terra.workspace.service.job.JobService) WsmResource(bio.terra.workspace.service.resource.model.WsmResource) Logger(org.slf4j.Logger) Alpha1Api(bio.terra.workspace.generated.controller.Alpha1Api) UUID(java.util.UUID) SamWorkspaceAction(bio.terra.workspace.service.iam.model.SamConstants.SamWorkspaceAction) AuthenticatedUserRequestFactory(bio.terra.workspace.service.iam.AuthenticatedUserRequestFactory) EnumeratedJobs(bio.terra.workspace.service.workspace.model.EnumeratedJobs) HttpStatus(org.springframework.http.HttpStatus) Alpha1Service(bio.terra.workspace.service.workspace.Alpha1Service) List(java.util.List) ErrorReportUtils(bio.terra.workspace.common.utils.ErrorReportUtils) WsmResourceFamily(bio.terra.workspace.service.resource.model.WsmResourceFamily) Optional(java.util.Optional) ResponseEntity(org.springframework.http.ResponseEntity) FeatureConfiguration(bio.terra.workspace.app.configuration.external.FeatureConfiguration) ApiEnumerateJobsResult(bio.terra.workspace.generated.model.ApiEnumerateJobsResult) ApiResourceType(bio.terra.workspace.generated.model.ApiResourceType) ApiEnumeratedJob(bio.terra.workspace.generated.model.ApiEnumeratedJob) ArrayList(java.util.ArrayList) ErrorReportUtils(bio.terra.workspace.common.utils.ErrorReportUtils) AuthenticatedUserRequest(bio.terra.workspace.service.iam.AuthenticatedUserRequest) EnumeratedJobs(bio.terra.workspace.service.workspace.model.EnumeratedJobs) ApiJobReport(bio.terra.workspace.generated.model.ApiJobReport) ResponseEntity(org.springframework.http.ResponseEntity) ApiEnumerateJobsResult(bio.terra.workspace.generated.model.ApiEnumerateJobsResult) EnumeratedJob(bio.terra.workspace.service.workspace.model.EnumeratedJob) ApiEnumeratedJob(bio.terra.workspace.generated.model.ApiEnumeratedJob)

Aggregations

FeatureConfiguration (bio.terra.workspace.app.configuration.external.FeatureConfiguration)1 ControllerValidationUtils (bio.terra.workspace.common.utils.ControllerValidationUtils)1 ErrorReportUtils (bio.terra.workspace.common.utils.ErrorReportUtils)1 Alpha1Api (bio.terra.workspace.generated.controller.Alpha1Api)1 ApiEnumerateJobsResult (bio.terra.workspace.generated.model.ApiEnumerateJobsResult)1 ApiEnumeratedJob (bio.terra.workspace.generated.model.ApiEnumeratedJob)1 ApiJobReport (bio.terra.workspace.generated.model.ApiJobReport)1 ApiJobStateFilter (bio.terra.workspace.generated.model.ApiJobStateFilter)1 ApiResourceType (bio.terra.workspace.generated.model.ApiResourceType)1 ApiStewardshipType (bio.terra.workspace.generated.model.ApiStewardshipType)1 AuthenticatedUserRequest (bio.terra.workspace.service.iam.AuthenticatedUserRequest)1 AuthenticatedUserRequestFactory (bio.terra.workspace.service.iam.AuthenticatedUserRequestFactory)1 SamWorkspaceAction (bio.terra.workspace.service.iam.model.SamConstants.SamWorkspaceAction)1 JobService (bio.terra.workspace.service.job.JobService)1 ResourceValidationUtils (bio.terra.workspace.service.resource.ResourceValidationUtils)1 StewardshipType (bio.terra.workspace.service.resource.model.StewardshipType)1 WsmResource (bio.terra.workspace.service.resource.model.WsmResource)1 WsmResourceFamily (bio.terra.workspace.service.resource.model.WsmResourceFamily)1 Alpha1Service (bio.terra.workspace.service.workspace.Alpha1Service)1 WorkspaceService (bio.terra.workspace.service.workspace.WorkspaceService)1