Search in sources :

Example 1 with ApiCloneReferencedGcpDataRepoSnapshotResourceResult

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

the class ReferencedGcpResourceController method cloneGcpDataRepoSnapshotReference.

@Override
public ResponseEntity<ApiCloneReferencedGcpDataRepoSnapshotResourceResult> cloneGcpDataRepoSnapshotReference(UUID workspaceId, UUID resourceId, @Valid ApiCloneReferencedResourceRequestBody body) {
    final AuthenticatedUserRequest userRequest = getAuthenticatedInfo();
    final ReferencedResource sourceReferencedResource = referenceResourceService.getReferenceResource(workspaceId, resourceId, userRequest);
    final CloningInstructions effectiveCloningInstructions = Optional.ofNullable(body.getCloningInstructions()).map(CloningInstructions::fromApiModel).orElse(sourceReferencedResource.getCloningInstructions());
    if (CloningInstructions.COPY_REFERENCE != effectiveCloningInstructions) {
        // Nothing to clone here
        final var emptyResult = new ApiCloneReferencedGcpDataRepoSnapshotResourceResult().effectiveCloningInstructions(effectiveCloningInstructions.toApiModel()).sourceResourceId(sourceReferencedResource.getResourceId()).sourceWorkspaceId(sourceReferencedResource.getWorkspaceId()).resource(null);
        return new ResponseEntity<>(emptyResult, HttpStatus.OK);
    }
    // Clone the reference
    final ReferencedDataRepoSnapshotResource clonedReferencedResource = referenceResourceService.cloneReferencedResource(sourceReferencedResource, body.getDestinationWorkspaceId(), body.getName(), body.getDescription(), userRequest).castByEnum(WsmResourceType.REFERENCED_ANY_DATA_REPO_SNAPSHOT);
    // Build the correct response type
    final var result = new ApiCloneReferencedGcpDataRepoSnapshotResourceResult().resource(clonedReferencedResource.toApiResource()).sourceWorkspaceId(sourceReferencedResource.getWorkspaceId()).sourceResourceId(sourceReferencedResource.getResourceId()).effectiveCloningInstructions(effectiveCloningInstructions.toApiModel());
    return new ResponseEntity<>(result, HttpStatus.OK);
}
Also used : ReferencedResource(bio.terra.workspace.service.resource.referenced.cloud.gcp.ReferencedResource) ResponseEntity(org.springframework.http.ResponseEntity) CloningInstructions(bio.terra.workspace.service.resource.model.CloningInstructions) ApiCloneReferencedGcpDataRepoSnapshotResourceResult(bio.terra.workspace.generated.model.ApiCloneReferencedGcpDataRepoSnapshotResourceResult) AuthenticatedUserRequest(bio.terra.workspace.service.iam.AuthenticatedUserRequest) ReferencedDataRepoSnapshotResource(bio.terra.workspace.service.resource.referenced.cloud.gcp.datareposnapshot.ReferencedDataRepoSnapshotResource)

Aggregations

ApiCloneReferencedGcpDataRepoSnapshotResourceResult (bio.terra.workspace.generated.model.ApiCloneReferencedGcpDataRepoSnapshotResourceResult)1 AuthenticatedUserRequest (bio.terra.workspace.service.iam.AuthenticatedUserRequest)1 CloningInstructions (bio.terra.workspace.service.resource.model.CloningInstructions)1 ReferencedResource (bio.terra.workspace.service.resource.referenced.cloud.gcp.ReferencedResource)1 ReferencedDataRepoSnapshotResource (bio.terra.workspace.service.resource.referenced.cloud.gcp.datareposnapshot.ReferencedDataRepoSnapshotResource)1 ResponseEntity (org.springframework.http.ResponseEntity)1