use of bio.terra.workspace.service.workspace.model.Workspace in project terra-workspace-manager by DataBiosphere.
the class WorkspaceApiController method cloneWorkspace.
/**
* Clone an entire workspace by creating a new workspace and cloning the workspace's resources
* into it.
*
* @param workspaceUuid - ID of source workspace
* @param body - request body
* @return - result structure for the overall clone operation with details for each resource
*/
@Override
public ResponseEntity<ApiCloneWorkspaceResult> cloneWorkspace(UUID workspaceUuid, @Valid ApiCloneWorkspaceRequest body) {
final AuthenticatedUserRequest petRequest = getCloningCredentials(workspaceUuid);
Optional<SpendProfileId> spendProfileId = Optional.ofNullable(body.getSpendProfile()).map(SpendProfileId::new);
final UUID destinationWorkspaceId = UUID.randomUUID();
// ET uses userFacingId; CWB doesn't. Schema enforces that userFacingId must be set. CWB doesn't
// pass userFacingId in request, so use id. Prefix with "a" because userFacingId must start with
// letter.
String destinationUserFacingId = Optional.ofNullable(body.getUserFacingId()).orElse("a-" + destinationWorkspaceId);
ControllerValidationUtils.validateUserFacingId(destinationUserFacingId);
// Construct the target workspace object from the inputs
final Workspace destinationWorkspace = Workspace.builder().workspaceId(destinationWorkspaceId).userFacingId(destinationUserFacingId).spendProfileId(spendProfileId.orElse(null)).workspaceStage(WorkspaceStage.MC_WORKSPACE).displayName(body.getDisplayName()).description(body.getDescription()).properties(propertyMapFromApi(body.getProperties())).build();
final String jobId = workspaceService.cloneWorkspace(workspaceUuid, petRequest, body.getLocation(), destinationWorkspace);
final ApiCloneWorkspaceResult result = fetchCloneWorkspaceResult(jobId, getAuthenticatedInfo());
final ApiClonedWorkspace clonedWorkspaceStub = new ApiClonedWorkspace().destinationWorkspaceId(destinationWorkspaceId).destinationUserFacingId(destinationUserFacingId).sourceWorkspaceId(workspaceUuid);
result.setWorkspace(clonedWorkspaceStub);
return new ResponseEntity<>(result, getAsyncResponseCode(result.getJobReport()));
}
use of bio.terra.workspace.service.workspace.model.Workspace 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);
// ET uses userFacingId; CWB doesn't. Schema enforces that userFacingId must be set. CWB doesn't
// pass userFacingId in request, so use id. Prefix with "a" because userFacingId must start with
// a letter.
String userFacingId = Optional.ofNullable(body.getUserFacingId()).orElse("a-" + body.getId());
ControllerValidationUtils.validateUserFacingId(userFacingId);
Workspace workspace = Workspace.builder().workspaceId(body.getId()).userFacingId(userFacingId).displayName(body.getDisplayName()).description(body.getDescription()).spendProfileId(spendProfileId.orElse(null)).workspaceStage(internalStage).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);
}
use of bio.terra.workspace.service.workspace.model.Workspace in project terra-workspace-manager by DataBiosphere.
the class WorkspaceApiController method getWorkspaceByUserFacingId.
@Override
public ResponseEntity<ApiWorkspaceDescription> getWorkspaceByUserFacingId(@PathVariable("workspaceUserFacingId") String userFacingId) {
AuthenticatedUserRequest userRequest = getAuthenticatedInfo();
logger.info("Getting workspace {} for {}", userFacingId, userRequest.getEmail());
Workspace workspace = workspaceService.getWorkspaceByUserFacingId(userFacingId, userRequest);
ApiWorkspaceDescription desc = buildWorkspaceDescription(workspace);
logger.info("Got workspace {} for {}", desc, userRequest.getEmail());
return new ResponseEntity<>(desc, HttpStatus.OK);
}
use of bio.terra.workspace.service.workspace.model.Workspace in project terra-workspace-manager by DataBiosphere.
the class WorkspaceDao method getWorkspaceIfExists.
@ReadTransaction
public Optional<Workspace> getWorkspaceIfExists(UUID uuid) {
if (uuid == null) {
throw new MissingRequiredFieldException("Valid workspace id is required");
}
String sql = WORKSPACE_SELECT_SQL + " WHERE workspace_id = :id";
MapSqlParameterSource params = new MapSqlParameterSource().addValue("id", uuid.toString());
try {
Workspace result = DataAccessUtils.requiredSingleResult(jdbcTemplate.query(sql, params, WORKSPACE_ROW_MAPPER));
logger.info("Retrieved workspace record {}", result);
return Optional.of(result);
} catch (EmptyResultDataAccessException e) {
return Optional.empty();
}
}
use of bio.terra.workspace.service.workspace.model.Workspace in project terra-workspace-manager by DataBiosphere.
the class WorkspaceDao method getWorkspaceByUserFacingId.
/**
* Retrieves a workspace from database by userFacingId.
*/
public Workspace getWorkspaceByUserFacingId(String userFacingId) {
if (userFacingId == null || userFacingId.isEmpty()) {
throw new MissingRequiredFieldException("userFacingId is required");
}
String sql = WORKSPACE_SELECT_SQL + " WHERE user_facing_id = :user_facing_id";
MapSqlParameterSource params = new MapSqlParameterSource().addValue("user_facing_id", userFacingId);
Workspace result;
try {
result = DataAccessUtils.requiredSingleResult(jdbcTemplate.query(sql, params, WORKSPACE_ROW_MAPPER));
logger.info("Retrieved workspace record {}", result);
return result;
} catch (EmptyResultDataAccessException e) {
throw new WorkspaceNotFoundException(String.format("Workspace %s not found.", userFacingId));
}
}
Aggregations