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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations