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