Search in sources :

Example 1 with WorkspaceStage

use of bio.terra.workspace.service.workspace.model.WorkspaceStage in project terra-workspace-manager by DataBiosphere.

the class WorkspaceApiController method createWorkspace.

@Override
public ResponseEntity<ApiCreatedWorkspace> createWorkspace(@RequestBody ApiCreateWorkspaceRequestBody body) {
    AuthenticatedUserRequest userRequest = getAuthenticatedInfo();
    logger.info("Creating workspace {} for {} subject {}", body.getId(), userRequest.getEmail(), userRequest.getSubjectId());
    // Existing client libraries should not need to know about the stage, as they won't use any of
    // the features it gates. If stage isn't specified in a create request, we default to
    // RAWLS_WORKSPACE.
    ApiWorkspaceStageModel requestStage = body.getStage();
    requestStage = (requestStage == null ? ApiWorkspaceStageModel.RAWLS_WORKSPACE : requestStage);
    WorkspaceStage internalStage = WorkspaceStage.fromApiModel(requestStage);
    Optional<SpendProfileId> spendProfileId = Optional.ofNullable(body.getSpendProfile()).map(SpendProfileId::new);
    Workspace workspace = Workspace.builder().workspaceId(body.getId()).spendProfileId(spendProfileId.orElse(null)).workspaceStage(internalStage).displayName(body.getDisplayName()).description(body.getDescription()).properties(propertyMapFromApi(body.getProperties())).build();
    UUID createdId = workspaceService.createWorkspace(workspace, userRequest);
    ApiCreatedWorkspace responseWorkspace = new ApiCreatedWorkspace().id(createdId);
    logger.info("Created workspace {} for {}", responseWorkspace, userRequest.getEmail());
    return new ResponseEntity<>(responseWorkspace, HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) WorkspaceStage(bio.terra.workspace.service.workspace.model.WorkspaceStage) ApiWorkspaceStageModel(bio.terra.workspace.generated.model.ApiWorkspaceStageModel) ApiCreatedWorkspace(bio.terra.workspace.generated.model.ApiCreatedWorkspace) AuthenticatedUserRequest(bio.terra.workspace.service.iam.AuthenticatedUserRequest) UUID(java.util.UUID) SpendProfileId(bio.terra.workspace.service.spendprofile.SpendProfileId) ApiCreatedWorkspace(bio.terra.workspace.generated.model.ApiCreatedWorkspace) Workspace(bio.terra.workspace.service.workspace.model.Workspace) ApiClonedWorkspace(bio.terra.workspace.generated.model.ApiClonedWorkspace)

Aggregations

ApiClonedWorkspace (bio.terra.workspace.generated.model.ApiClonedWorkspace)1 ApiCreatedWorkspace (bio.terra.workspace.generated.model.ApiCreatedWorkspace)1 ApiWorkspaceStageModel (bio.terra.workspace.generated.model.ApiWorkspaceStageModel)1 AuthenticatedUserRequest (bio.terra.workspace.service.iam.AuthenticatedUserRequest)1 SpendProfileId (bio.terra.workspace.service.spendprofile.SpendProfileId)1 Workspace (bio.terra.workspace.service.workspace.model.Workspace)1 WorkspaceStage (bio.terra.workspace.service.workspace.model.WorkspaceStage)1 UUID (java.util.UUID)1 ResponseEntity (org.springframework.http.ResponseEntity)1