Search in sources :

Example 1 with ReferencedBigQueryDatasetResource

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);
}
Also used : ApiGcpBigQueryDatasetAttributes(bio.terra.workspace.generated.model.ApiGcpBigQueryDatasetAttributes) ApiResourceDescription(bio.terra.workspace.generated.model.ApiResourceDescription) ReferencedBigQueryDatasetResource(bio.terra.workspace.service.resource.referenced.cloud.gcp.bqdataset.ReferencedBigQueryDatasetResource) ApiResourceAttributesUnion(bio.terra.workspace.generated.model.ApiResourceAttributesUnion) BaseUnitTest(bio.terra.workspace.common.BaseUnitTest) Test(org.junit.jupiter.api.Test)

Example 2 with ReferencedBigQueryDatasetResource

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);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) ReferencedBigQueryDatasetResource(bio.terra.workspace.service.resource.referenced.cloud.gcp.bqdataset.ReferencedBigQueryDatasetResource)

Example 3 with ReferencedBigQueryDatasetResource

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);
}
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) ReferencedBigQueryDatasetResource(bio.terra.workspace.service.resource.referenced.cloud.gcp.bqdataset.ReferencedBigQueryDatasetResource) ApiCloneReferencedGcpBigQueryDatasetResourceResult(bio.terra.workspace.generated.model.ApiCloneReferencedGcpBigQueryDatasetResourceResult)

Example 4 with ReferencedBigQueryDatasetResource

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);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) AuthenticatedUserRequest(bio.terra.workspace.service.iam.AuthenticatedUserRequest) ReferencedBigQueryDatasetResource(bio.terra.workspace.service.resource.referenced.cloud.gcp.bqdataset.ReferencedBigQueryDatasetResource)

Example 5 with ReferencedBigQueryDatasetResource

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);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) AuthenticatedUserRequest(bio.terra.workspace.service.iam.AuthenticatedUserRequest) ReferencedBigQueryDatasetResource(bio.terra.workspace.service.resource.referenced.cloud.gcp.bqdataset.ReferencedBigQueryDatasetResource)

Aggregations

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