Search in sources :

Example 1 with ReferencedBigQueryDataTableResource

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

the class ReferencedGcpResourceController method getBigQueryDataTableReferenceByName.

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

Example 2 with ReferencedBigQueryDataTableResource

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

the class ReferencedGcpResourceController method getBigQueryDataTableReference.

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

Example 3 with ReferencedBigQueryDataTableResource

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

the class ReferencedGcpResourceController method createBigQueryDataTableReference.

// -- BigQuery DataTable -- //
@Override
public ResponseEntity<ApiGcpBigQueryDataTableResource> createBigQueryDataTableReference(UUID id, @Valid ApiCreateGcpBigQueryDataTableReferenceRequestBody body) {
    var resource = ReferencedBigQueryDataTableResource.builder().workspaceId(id).name(body.getMetadata().getName()).description(body.getMetadata().getDescription()).cloningInstructions(CloningInstructions.fromApiModel(body.getMetadata().getCloningInstructions())).projectId(body.getDataTable().getProjectId()).datasetId(body.getDataTable().getDatasetId()).dataTableId(body.getDataTable().getDataTableId()).build();
    ReferencedBigQueryDataTableResource referenceResource = referenceResourceService.createReferenceResource(resource, getAuthenticatedInfo()).castByEnum(WsmResourceType.REFERENCED_GCP_BIG_QUERY_DATA_TABLE);
    return new ResponseEntity<>(referenceResource.toApiResource(), HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) ReferencedBigQueryDataTableResource(bio.terra.workspace.service.resource.referenced.cloud.gcp.bqdatatable.ReferencedBigQueryDataTableResource)

Example 4 with ReferencedBigQueryDataTableResource

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

the class MakeApiResourceDescriptionTest method mapReferencedBigQueryDataTableTest.

@Test
public void mapReferencedBigQueryDataTableTest() throws Exception {
    String projectId = RandomStringUtils.randomAlphabetic(12);
    String datasetName = RandomStringUtils.randomAlphabetic(12);
    String datatableName = RandomStringUtils.randomAlphabetic(12);
    var resource = new ReferencedBigQueryDataTableResource(workspaceId, resourceId, resourceName, description, cloning, projectId, datasetName, datatableName);
    ApiResourceDescription resourceDescription = resourceController.makeApiResourceDescription(resource);
    validateWsmResource(resourceDescription);
    ApiResourceAttributesUnion union = resourceDescription.getResourceAttributes();
    ApiGcpBigQueryDataTableAttributes attributes = union.getGcpBqDataTable();
    assertThat(attributes, is(notNullValue()));
    assertEquals(attributes.getDatasetId(), datasetName);
    assertEquals(attributes.getProjectId(), projectId);
    assertEquals(attributes.getDataTableId(), datatableName);
}
Also used : ApiGcpBigQueryDataTableAttributes(bio.terra.workspace.generated.model.ApiGcpBigQueryDataTableAttributes) ApiResourceDescription(bio.terra.workspace.generated.model.ApiResourceDescription) ApiResourceAttributesUnion(bio.terra.workspace.generated.model.ApiResourceAttributesUnion) ReferencedBigQueryDataTableResource(bio.terra.workspace.service.resource.referenced.cloud.gcp.bqdatatable.ReferencedBigQueryDataTableResource) BaseUnitTest(bio.terra.workspace.common.BaseUnitTest) Test(org.junit.jupiter.api.Test)

Example 5 with ReferencedBigQueryDataTableResource

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

the class ReferencedGcpResourceController method cloneGcpBigQueryDataTableReference.

@Override
public ResponseEntity<ApiCloneReferencedGcpBigQueryDataTableResourceResult> cloneGcpBigQueryDataTableReference(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 ApiCloneReferencedGcpBigQueryDataTableResourceResult().effectiveCloningInstructions(effectiveCloningInstructions.toApiModel()).sourceResourceId(sourceReferencedResource.getResourceId()).sourceWorkspaceId(sourceReferencedResource.getWorkspaceId()).resource(null);
        return new ResponseEntity<>(emptyResult, HttpStatus.OK);
    }
    // Clone the reference
    final ReferencedBigQueryDataTableResource clonedReferencedResource = referenceResourceService.cloneReferencedResource(sourceReferencedResource, body.getDestinationWorkspaceId(), body.getName(), body.getDescription(), userRequest).castByEnum(WsmResourceType.REFERENCED_GCP_BIG_QUERY_DATA_TABLE);
    // Build the correct response type
    final var result = new ApiCloneReferencedGcpBigQueryDataTableResourceResult().resource(clonedReferencedResource.toApiResource()).sourceWorkspaceId(sourceReferencedResource.getWorkspaceId()).sourceResourceId(sourceReferencedResource.getResourceId()).effectiveCloningInstructions(effectiveCloningInstructions.toApiModel());
    return new ResponseEntity<>(result, HttpStatus.OK);
}
Also used : ApiCloneReferencedGcpBigQueryDataTableResourceResult(bio.terra.workspace.generated.model.ApiCloneReferencedGcpBigQueryDataTableResourceResult) 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) ReferencedBigQueryDataTableResource(bio.terra.workspace.service.resource.referenced.cloud.gcp.bqdatatable.ReferencedBigQueryDataTableResource)

Aggregations

ReferencedBigQueryDataTableResource (bio.terra.workspace.service.resource.referenced.cloud.gcp.bqdatatable.ReferencedBigQueryDataTableResource)6 ResponseEntity (org.springframework.http.ResponseEntity)5 AuthenticatedUserRequest (bio.terra.workspace.service.iam.AuthenticatedUserRequest)4 BaseUnitTest (bio.terra.workspace.common.BaseUnitTest)1 ApiCloneReferencedGcpBigQueryDataTableResourceResult (bio.terra.workspace.generated.model.ApiCloneReferencedGcpBigQueryDataTableResourceResult)1 ApiGcpBigQueryDataTableAttributes (bio.terra.workspace.generated.model.ApiGcpBigQueryDataTableAttributes)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