Search in sources :

Example 1 with ReferencedGcsBucketResource

use of bio.terra.workspace.service.resource.referenced.cloud.gcp.gcsbucket.ReferencedGcsBucketResource in project terra-workspace-manager by DataBiosphere.

the class MakeApiResourceDescriptionTest method mapReferencedGcsBucketTest.

@Test
public void mapReferencedGcsBucketTest() throws Exception {
    String bucketName = RandomStringUtils.randomAlphabetic(5).toLowerCase();
    var resource = new ReferencedGcsBucketResource(workspaceId, resourceId, resourceName, description, cloning, bucketName);
    ApiResourceDescription resourceDescription = resourceController.makeApiResourceDescription(resource);
    validateWsmResource(resourceDescription);
    ApiResourceAttributesUnion union = resourceDescription.getResourceAttributes();
    ApiGcpGcsBucketAttributes attributes = union.getGcpGcsBucket();
    assertThat(attributes, is(notNullValue()));
    assertEquals(attributes.getBucketName(), bucketName);
}
Also used : ReferencedGcsBucketResource(bio.terra.workspace.service.resource.referenced.cloud.gcp.gcsbucket.ReferencedGcsBucketResource) ApiResourceDescription(bio.terra.workspace.generated.model.ApiResourceDescription) ApiResourceAttributesUnion(bio.terra.workspace.generated.model.ApiResourceAttributesUnion) ApiGcpGcsBucketAttributes(bio.terra.workspace.generated.model.ApiGcpGcsBucketAttributes) BaseUnitTest(bio.terra.workspace.common.BaseUnitTest) Test(org.junit.jupiter.api.Test)

Example 2 with ReferencedGcsBucketResource

use of bio.terra.workspace.service.resource.referenced.cloud.gcp.gcsbucket.ReferencedGcsBucketResource in project terra-workspace-manager by DataBiosphere.

the class ReferencedGcpResourceController method cloneGcpGcsBucketReference.

@Override
public ResponseEntity<ApiCloneReferencedGcpGcsBucketResourceResult> cloneGcpGcsBucketReference(UUID workspaceId, UUID resourceId, @Valid ApiCloneReferencedResourceRequestBody body) {
    final AuthenticatedUserRequest petRequest = getCloningCredentials(workspaceId);
    final ReferencedResource sourceReferencedResource = referenceResourceService.getReferenceResource(workspaceId, resourceId, petRequest);
    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 ApiCloneReferencedGcpGcsBucketResourceResult().effectiveCloningInstructions(effectiveCloningInstructions.toApiModel()).sourceResourceId(sourceReferencedResource.getResourceId()).sourceWorkspaceId(sourceReferencedResource.getWorkspaceId()).resource(null);
        return new ResponseEntity<>(emptyResult, HttpStatus.OK);
    }
    // Clone the reference
    final ReferencedGcsBucketResource clonedReferencedResource = referenceResourceService.cloneReferencedResource(sourceReferencedResource, body.getDestinationWorkspaceId(), body.getName(), body.getDescription(), petRequest).castByEnum(WsmResourceType.REFERENCED_GCP_GCS_BUCKET);
    // Build the correct response type
    final var result = new ApiCloneReferencedGcpGcsBucketResourceResult().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) ReferencedGcsBucketResource(bio.terra.workspace.service.resource.referenced.cloud.gcp.gcsbucket.ReferencedGcsBucketResource) ApiCloneReferencedGcpGcsBucketResourceResult(bio.terra.workspace.generated.model.ApiCloneReferencedGcpGcsBucketResourceResult) AuthenticatedUserRequest(bio.terra.workspace.service.iam.AuthenticatedUserRequest)

Example 3 with ReferencedGcsBucketResource

use of bio.terra.workspace.service.resource.referenced.cloud.gcp.gcsbucket.ReferencedGcsBucketResource in project terra-workspace-manager by DataBiosphere.

the class ReferencedGcpResourceController method getBucketReference.

@Override
public ResponseEntity<ApiGcpGcsBucketResource> getBucketReference(UUID id, UUID referenceId) {
    AuthenticatedUserRequest userRequest = getAuthenticatedInfo();
    ReferencedGcsBucketResource referenceResource = referenceResourceService.getReferenceResource(id, referenceId, userRequest).castByEnum(WsmResourceType.REFERENCED_GCP_GCS_BUCKET);
    return new ResponseEntity<>(referenceResource.toApiResource(), HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) ReferencedGcsBucketResource(bio.terra.workspace.service.resource.referenced.cloud.gcp.gcsbucket.ReferencedGcsBucketResource) AuthenticatedUserRequest(bio.terra.workspace.service.iam.AuthenticatedUserRequest)

Example 4 with ReferencedGcsBucketResource

use of bio.terra.workspace.service.resource.referenced.cloud.gcp.gcsbucket.ReferencedGcsBucketResource in project terra-workspace-manager by DataBiosphere.

the class ReferencedGcpResourceController method createBucketReference.

// -- GCS Bucket -- //
@Override
public ResponseEntity<ApiGcpGcsBucketResource> createBucketReference(UUID id, @Valid ApiCreateGcpGcsBucketReferenceRequestBody body) {
    // Construct a ReferenceGcsBucketResource object from the API input
    var resource = ReferencedGcsBucketResource.builder().workspaceId(id).name(body.getMetadata().getName()).description(body.getMetadata().getDescription()).cloningInstructions(CloningInstructions.fromApiModel(body.getMetadata().getCloningInstructions())).bucketName(body.getBucket().getBucketName()).build();
    ReferencedGcsBucketResource referenceResource = referenceResourceService.createReferenceResource(resource, getAuthenticatedInfo()).castByEnum(WsmResourceType.REFERENCED_GCP_GCS_BUCKET);
    return new ResponseEntity<>(referenceResource.toApiResource(), HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) ReferencedGcsBucketResource(bio.terra.workspace.service.resource.referenced.cloud.gcp.gcsbucket.ReferencedGcsBucketResource)

Example 5 with ReferencedGcsBucketResource

use of bio.terra.workspace.service.resource.referenced.cloud.gcp.gcsbucket.ReferencedGcsBucketResource in project terra-workspace-manager by DataBiosphere.

the class ReferencedGcpResourceController method getBucketReferenceByName.

@Override
public ResponseEntity<ApiGcpGcsBucketResource> getBucketReferenceByName(UUID id, String name) {
    AuthenticatedUserRequest userRequest = getAuthenticatedInfo();
    ReferencedGcsBucketResource referenceResource = referenceResourceService.getReferenceResourceByName(id, name, userRequest).castByEnum(WsmResourceType.REFERENCED_GCP_GCS_BUCKET);
    return new ResponseEntity<>(referenceResource.toApiResource(), HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) ReferencedGcsBucketResource(bio.terra.workspace.service.resource.referenced.cloud.gcp.gcsbucket.ReferencedGcsBucketResource) AuthenticatedUserRequest(bio.terra.workspace.service.iam.AuthenticatedUserRequest)

Aggregations

ReferencedGcsBucketResource (bio.terra.workspace.service.resource.referenced.cloud.gcp.gcsbucket.ReferencedGcsBucketResource)6 ResponseEntity (org.springframework.http.ResponseEntity)5 AuthenticatedUserRequest (bio.terra.workspace.service.iam.AuthenticatedUserRequest)4 BaseUnitTest (bio.terra.workspace.common.BaseUnitTest)1 ApiCloneReferencedGcpGcsBucketResourceResult (bio.terra.workspace.generated.model.ApiCloneReferencedGcpGcsBucketResourceResult)1 ApiGcpGcsBucketAttributes (bio.terra.workspace.generated.model.ApiGcpGcsBucketAttributes)1 ApiResourceAttributesUnion (bio.terra.workspace.generated.model.ApiResourceAttributesUnion)1 ApiResourceDescription (bio.terra.workspace.generated.model.ApiResourceDescription)1 CloningInstructions (bio.terra.workspace.service.resource.model.CloningInstructions)1 ReferencedResource (bio.terra.workspace.service.resource.referenced.cloud.gcp.ReferencedResource)1 Test (org.junit.jupiter.api.Test)1