Search in sources :

Example 1 with ApiStewardshipType

use of bio.terra.workspace.generated.model.ApiStewardshipType 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)

Example 2 with ApiStewardshipType

use of bio.terra.workspace.generated.model.ApiStewardshipType in project terra-workspace-manager by DataBiosphere.

the class ResourceController method enumerateResources.

@Override
public ResponseEntity<ApiResourceList> enumerateResources(UUID workspaceId, @Valid @RequestParam(value = "offset", required = false, defaultValue = "0") Integer offset, @Valid @RequestParam(value = "limit", required = false, defaultValue = "10") Integer limit, @Valid ApiResourceType resource, @Valid ApiStewardshipType stewardship) {
    AuthenticatedUserRequest userRequest = getAuthenticatedInfo();
    ControllerValidationUtils.validatePaginationParams(offset, limit);
    workspaceService.validateWorkspaceAndAction(userRequest, workspaceId, SamConstants.SamWorkspaceAction.READ);
    List<WsmResource> wsmResources = resourceService.enumerateResources(workspaceId, WsmResourceFamily.fromApiOptional(resource), StewardshipType.fromApiOptional(stewardship), offset, limit, userRequest);
    List<ApiResourceDescription> apiResourceDescriptionList = wsmResources.stream().map(r -> makeApiResourceDescription(r)).collect(Collectors.toList());
    var apiResourceList = new ApiResourceList().resources(apiResourceDescriptionList);
    return new ResponseEntity<>(apiResourceList, HttpStatus.OK);
}
Also used : WsmResource(bio.terra.workspace.service.resource.model.WsmResource) RequestParam(org.springframework.web.bind.annotation.RequestParam) WorkspaceService(bio.terra.workspace.service.workspace.WorkspaceService) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) Controller(org.springframework.stereotype.Controller) AuthenticatedUserRequest(bio.terra.workspace.service.iam.AuthenticatedUserRequest) Valid(javax.validation.Valid) SamConstants(bio.terra.workspace.service.iam.model.SamConstants) ReferencedResourceService(bio.terra.workspace.service.resource.referenced.cloud.gcp.ReferencedResourceService) HttpServletRequest(javax.servlet.http.HttpServletRequest) ApiResourceAttributesUnion(bio.terra.workspace.generated.model.ApiResourceAttributesUnion) StewardshipType(bio.terra.workspace.service.resource.model.StewardshipType) ApiStewardshipType(bio.terra.workspace.generated.model.ApiStewardshipType) ControllerValidationUtils(bio.terra.workspace.common.utils.ControllerValidationUtils) ApiResourceMetadata(bio.terra.workspace.generated.model.ApiResourceMetadata) WsmResource(bio.terra.workspace.service.resource.model.WsmResource) ApiResourceList(bio.terra.workspace.generated.model.ApiResourceList) ApiResourceDescription(bio.terra.workspace.generated.model.ApiResourceDescription) Logger(org.slf4j.Logger) UUID(java.util.UUID) ResourceApi(bio.terra.workspace.generated.controller.ResourceApi) Collectors(java.util.stream.Collectors) WsmResourceService(bio.terra.workspace.service.resource.WsmResourceService) AuthenticatedUserRequestFactory(bio.terra.workspace.service.iam.AuthenticatedUserRequestFactory) HttpStatus(org.springframework.http.HttpStatus) List(java.util.List) WsmResourceFamily(bio.terra.workspace.service.resource.model.WsmResourceFamily) ResponseEntity(org.springframework.http.ResponseEntity) VisibleForTesting(com.google.common.annotations.VisibleForTesting) ApiResourceType(bio.terra.workspace.generated.model.ApiResourceType) ResponseEntity(org.springframework.http.ResponseEntity) ApiResourceDescription(bio.terra.workspace.generated.model.ApiResourceDescription) AuthenticatedUserRequest(bio.terra.workspace.service.iam.AuthenticatedUserRequest) ApiResourceList(bio.terra.workspace.generated.model.ApiResourceList)

Aggregations

ControllerValidationUtils (bio.terra.workspace.common.utils.ControllerValidationUtils)2 ApiResourceType (bio.terra.workspace.generated.model.ApiResourceType)2 ApiStewardshipType (bio.terra.workspace.generated.model.ApiStewardshipType)2 AuthenticatedUserRequest (bio.terra.workspace.service.iam.AuthenticatedUserRequest)2 AuthenticatedUserRequestFactory (bio.terra.workspace.service.iam.AuthenticatedUserRequestFactory)2 StewardshipType (bio.terra.workspace.service.resource.model.StewardshipType)2 WsmResource (bio.terra.workspace.service.resource.model.WsmResource)2 WsmResourceFamily (bio.terra.workspace.service.resource.model.WsmResourceFamily)2 WorkspaceService (bio.terra.workspace.service.workspace.WorkspaceService)2 List (java.util.List)2 UUID (java.util.UUID)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 HttpStatus (org.springframework.http.HttpStatus)2 ResponseEntity (org.springframework.http.ResponseEntity)2 Controller (org.springframework.stereotype.Controller)2 FeatureConfiguration (bio.terra.workspace.app.configuration.external.FeatureConfiguration)1 ErrorReportUtils (bio.terra.workspace.common.utils.ErrorReportUtils)1