Search in sources :

Example 1 with ReferencedGcsObjectResource

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

the class ReferencedGcpResourceController method createGcsObjectReference.

// -- GCS Bucket object -- //
@Override
public ResponseEntity<ApiGcpGcsObjectResource> createGcsObjectReference(UUID workspaceId, @Valid ApiCreateGcpGcsObjectReferenceRequestBody body) {
    // Construct a ReferenceGcsBucketResource object from the API input
    var resource = ReferencedGcsObjectResource.builder().workspaceId(workspaceId).name(body.getMetadata().getName()).description(body.getMetadata().getDescription()).cloningInstructions(CloningInstructions.fromApiModel(body.getMetadata().getCloningInstructions())).bucketName(body.getFile().getBucketName()).fileName(body.getFile().getFileName()).build();
    ReferencedGcsObjectResource referencedResource = referenceResourceService.createReferenceResource(resource, getAuthenticatedInfo()).castByEnum(WsmResourceType.REFERENCED_GCP_GCS_OBJECT);
    return new ResponseEntity<>(referencedResource.toApiResource(), HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) ReferencedGcsObjectResource(bio.terra.workspace.service.resource.referenced.cloud.gcp.gcsobject.ReferencedGcsObjectResource)

Example 2 with ReferencedGcsObjectResource

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

the class ReferencedGcpResourceController method getGcsObjectReferenceByName.

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

Example 3 with ReferencedGcsObjectResource

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

the class ReferencedGcpResourceController method updateBucketObjectReferenceResource.

@Override
public ResponseEntity<Void> updateBucketObjectReferenceResource(UUID workspaceId, UUID referenceId, ApiUpdateGcsBucketObjectReferenceRequestBody body) {
    AuthenticatedUserRequest userRequest = getAuthenticatedInfo();
    String bucketName = body.getBucketName();
    String objectName = body.getObjectName();
    if (StringUtils.isEmpty(bucketName) && StringUtils.isEmpty(objectName)) {
        referenceResourceService.updateReferenceResource(workspaceId, referenceId, body.getName(), body.getDescription(), userRequest);
    } else {
        ReferencedGcsObjectResource referencedResource = referenceResourceService.getReferenceResource(workspaceId, referenceId, userRequest).castByEnum(WsmResourceType.REFERENCED_GCP_GCS_OBJECT);
        ReferencedGcsObjectResource.Builder updateBucketObjectResourceBuilder = referencedResource.toBuilder();
        if (!StringUtils.isEmpty(bucketName)) {
            updateBucketObjectResourceBuilder.bucketName(bucketName);
        }
        if (!StringUtils.isEmpty(objectName)) {
            updateBucketObjectResourceBuilder.fileName(objectName);
        }
        referenceResourceService.updateReferenceResource(workspaceId, referenceId, body.getName(), body.getDescription(), updateBucketObjectResourceBuilder.build(), userRequest);
    }
    return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) AuthenticatedUserRequest(bio.terra.workspace.service.iam.AuthenticatedUserRequest) ReferencedGcsObjectResource(bio.terra.workspace.service.resource.referenced.cloud.gcp.gcsobject.ReferencedGcsObjectResource)

Example 4 with ReferencedGcsObjectResource

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

the class ReferencedGcpResourceController method cloneGcpGcsObjectReference.

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

Example 5 with ReferencedGcsObjectResource

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

the class ReferencedGcpResourceController method getGcsObjectReference.

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

Aggregations

ReferencedGcsObjectResource (bio.terra.workspace.service.resource.referenced.cloud.gcp.gcsobject.ReferencedGcsObjectResource)5 ResponseEntity (org.springframework.http.ResponseEntity)5 AuthenticatedUserRequest (bio.terra.workspace.service.iam.AuthenticatedUserRequest)4 ApiCloneReferencedGcpGcsObjectResourceResult (bio.terra.workspace.generated.model.ApiCloneReferencedGcpGcsObjectResourceResult)1 CloningInstructions (bio.terra.workspace.service.resource.model.CloningInstructions)1 ReferencedResource (bio.terra.workspace.service.resource.referenced.cloud.gcp.ReferencedResource)1