use of bio.terra.workspace.service.resource.referenced.cloud.gcp.bqdataset.ReferencedBigQueryDatasetResource in project terra-workspace-manager by DataBiosphere.
the class MakeApiResourceDescriptionTest method mapReferencedBigQueryDatasetTest.
@Test
public void mapReferencedBigQueryDatasetTest() throws Exception {
String projectId = RandomStringUtils.randomAlphabetic(12);
String datasetName = RandomStringUtils.randomAlphabetic(12);
var resource = new ReferencedBigQueryDatasetResource(workspaceId, resourceId, resourceName, description, cloning, projectId, datasetName);
ApiResourceDescription resourceDescription = resourceController.makeApiResourceDescription(resource);
validateWsmResource(resourceDescription);
ApiResourceAttributesUnion union = resourceDescription.getResourceAttributes();
ApiGcpBigQueryDatasetAttributes attributes = union.getGcpBqDataset();
assertThat(attributes, is(notNullValue()));
assertEquals(attributes.getDatasetId(), datasetName);
assertEquals(attributes.getProjectId(), projectId);
}
use of bio.terra.workspace.service.resource.referenced.cloud.gcp.bqdataset.ReferencedBigQueryDatasetResource in project terra-workspace-manager by DataBiosphere.
the class ReferencedGcpResourceController method createBigQueryDatasetReference.
// -- Big Query Dataset -- //
@Override
public ResponseEntity<ApiGcpBigQueryDatasetResource> createBigQueryDatasetReference(UUID id, @Valid ApiCreateGcpBigQueryDatasetReferenceRequestBody body) {
// Construct a ReferenceBigQueryResource object from the API input
var resource = ReferencedBigQueryDatasetResource.builder().workspaceId(id).name(body.getMetadata().getName()).description(body.getMetadata().getDescription()).cloningInstructions(CloningInstructions.fromApiModel(body.getMetadata().getCloningInstructions())).projectId(body.getDataset().getProjectId()).datasetName(body.getDataset().getDatasetId()).build();
ReferencedBigQueryDatasetResource referenceResource = referenceResourceService.createReferenceResource(resource, getAuthenticatedInfo()).castByEnum(WsmResourceType.REFERENCED_GCP_BIG_QUERY_DATASET);
return new ResponseEntity<>(referenceResource.toApiResource(), HttpStatus.OK);
}
use of bio.terra.workspace.service.resource.referenced.cloud.gcp.bqdataset.ReferencedBigQueryDatasetResource in project terra-workspace-manager by DataBiosphere.
the class ReferencedGcpResourceController method cloneGcpBigQueryDatasetReference.
@Override
public ResponseEntity<ApiCloneReferencedGcpBigQueryDatasetResourceResult> cloneGcpBigQueryDatasetReference(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 ApiCloneReferencedGcpBigQueryDatasetResourceResult().effectiveCloningInstructions(effectiveCloningInstructions.toApiModel()).sourceResourceId(sourceReferencedResource.getResourceId()).sourceWorkspaceId(sourceReferencedResource.getWorkspaceId()).resource(null);
return new ResponseEntity<>(emptyResult, HttpStatus.OK);
}
// Clone the reference
final ReferencedBigQueryDatasetResource clonedReferencedResource = referenceResourceService.cloneReferencedResource(sourceReferencedResource, body.getDestinationWorkspaceId(), body.getName(), body.getDescription(), petRequest).castByEnum(WsmResourceType.REFERENCED_GCP_BIG_QUERY_DATASET);
// Build the correct response type
final var result = new ApiCloneReferencedGcpBigQueryDatasetResourceResult().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.bqdataset.ReferencedBigQueryDatasetResource in project terra-workspace-manager by DataBiosphere.
the class ReferencedGcpResourceController method getBigQueryDatasetReference.
@Override
public ResponseEntity<ApiGcpBigQueryDatasetResource> getBigQueryDatasetReference(UUID id, UUID referenceId) {
AuthenticatedUserRequest userRequest = getAuthenticatedInfo();
ReferencedBigQueryDatasetResource referenceResource = referenceResourceService.getReferenceResource(id, referenceId, userRequest).castByEnum(WsmResourceType.REFERENCED_GCP_BIG_QUERY_DATASET);
return new ResponseEntity<>(referenceResource.toApiResource(), HttpStatus.OK);
}
use of bio.terra.workspace.service.resource.referenced.cloud.gcp.bqdataset.ReferencedBigQueryDatasetResource in project terra-workspace-manager by DataBiosphere.
the class ReferencedGcpResourceController method updateBigQueryDatasetReferenceResource.
@Override
public ResponseEntity<Void> updateBigQueryDatasetReferenceResource(UUID workspaceId, UUID resourceId, ApiUpdateBigQueryDatasetReferenceRequestBody body) {
AuthenticatedUserRequest userRequest = getAuthenticatedInfo();
String updatedDatasetId = body.getDatasetId();
String updatedProjectId = body.getProjectId();
if (StringUtils.isEmpty(updatedDatasetId) && StringUtils.isEmpty(updatedProjectId)) {
referenceResourceService.updateReferenceResource(workspaceId, resourceId, body.getName(), body.getDescription(), userRequest);
} else {
ReferencedBigQueryDatasetResource referenceResource = referenceResourceService.getReferenceResource(workspaceId, resourceId, userRequest).castByEnum(WsmResourceType.REFERENCED_GCP_BIG_QUERY_DATASET);
ReferencedBigQueryDatasetResource.Builder updatedBqDatasetResourceBuilder = referenceResource.toBuilder();
if (!StringUtils.isEmpty(updatedProjectId)) {
updatedBqDatasetResourceBuilder.projectId(updatedProjectId);
}
if (!StringUtils.isEmpty(updatedDatasetId)) {
updatedBqDatasetResourceBuilder.datasetName(updatedDatasetId);
}
referenceResourceService.updateReferenceResource(workspaceId, resourceId, body.getName(), body.getDescription(), updatedBqDatasetResourceBuilder.build(), userRequest);
}
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
Aggregations