Search in sources :

Example 21 with Operation

use of com.google.api.services.storagetransfer.v1.model.Operation in project java-docs-samples by GoogleCloudPlatform.

the class DicomStoreExport method dicomStoreExport.

public static void dicomStoreExport(String dicomStoreName, String gcsUri) throws IOException {
    // String dicomStoreName =
    // String.format(
    // DICOM_NAME, "your-project-id", "your-region-id", "your-dataset-id", "your-dicom-id");
    // String gcsUri = "gs://your-bucket-id/path/to/destination/dir"
    // Initialize the client, which will be used to interact with the service.
    CloudHealthcare client = createClient();
    // Configure where the store will be exported too.
    GoogleCloudHealthcareV1DicomGcsDestination gcsDestination = new GoogleCloudHealthcareV1DicomGcsDestination().setUriPrefix(gcsUri);
    ExportDicomDataRequest exportRequest = new ExportDicomDataRequest().setGcsDestination(gcsDestination);
    // Create request and configure any parameters.
    DicomStores.Export request = client.projects().locations().datasets().dicomStores().export(dicomStoreName, exportRequest);
    // Execute the request, wait for the operation to complete, and process the results.
    try {
        Operation operation = request.execute();
        while (operation.getDone() == null || !operation.getDone()) {
            // Update the status of the operation with another request.
            // Pause for 500ms between requests.
            Thread.sleep(500);
            operation = client.projects().locations().datasets().operations().get(operation.getName()).execute();
        }
        System.out.println("DICOM store export complete." + operation.getResponse());
    } catch (Exception ex) {
        System.out.printf("Error during request execution: %s", ex.toString());
        ex.printStackTrace(System.out);
    }
}
Also used : DicomStores(com.google.api.services.healthcare.v1.CloudHealthcare.Projects.Locations.Datasets.DicomStores) CloudHealthcare(com.google.api.services.healthcare.v1.CloudHealthcare) GoogleCloudHealthcareV1DicomGcsDestination(com.google.api.services.healthcare.v1.model.GoogleCloudHealthcareV1DicomGcsDestination) Operation(com.google.api.services.healthcare.v1.model.Operation) ExportDicomDataRequest(com.google.api.services.healthcare.v1.model.ExportDicomDataRequest) IOException(java.io.IOException)

Example 22 with Operation

use of com.google.api.services.storagetransfer.v1.model.Operation in project java-docs-samples by GoogleCloudPlatform.

the class FhirStoreImport method fhirStoreImport.

public static void fhirStoreImport(String fhirStoreName, String gcsUri) throws IOException {
    // String fhirStoreName =
    // String.format(
    // FHIR_NAME, "your-project-id", "your-region-id", "your-dataset-id", "your-fhir-id");
    // String gcsUri = "gs://your-bucket-id/path/to/destination/dir"
    // Initialize the client, which will be used to interact with the service.
    CloudHealthcare client = createClient();
    // Configure where the store should be imported from.
    GoogleCloudHealthcareV1FhirGcsSource gcsSource = new GoogleCloudHealthcareV1FhirGcsSource().setUri(gcsUri);
    ImportResourcesRequest importRequest = new ImportResourcesRequest().setGcsSource(gcsSource);
    // Create request and configure any parameters.
    FhirStores.CloudHealthcareImport request = client.projects().locations().datasets().fhirStores().healthcareImport(fhirStoreName, importRequest);
    // Execute the request, wait for the operation to complete, and process the results.
    try {
        Operation operation = request.execute();
        while (operation.getDone() == null || !operation.getDone()) {
            // Update the status of the operation with another request.
            // Pause for 500ms between requests.
            Thread.sleep(500);
            operation = client.projects().locations().datasets().operations().get(operation.getName()).execute();
        }
        System.out.println("FHIR store import complete: " + operation.getResponse());
    } catch (Exception ex) {
        System.out.printf("Error during request execution: %s", ex.toString());
        ex.printStackTrace(System.out);
    }
}
Also used : FhirStores(com.google.api.services.healthcare.v1.CloudHealthcare.Projects.Locations.Datasets.FhirStores) ImportResourcesRequest(com.google.api.services.healthcare.v1.model.ImportResourcesRequest) CloudHealthcare(com.google.api.services.healthcare.v1.CloudHealthcare) Operation(com.google.api.services.healthcare.v1.model.Operation) GoogleCloudHealthcareV1FhirGcsSource(com.google.api.services.healthcare.v1.model.GoogleCloudHealthcareV1FhirGcsSource) IOException(java.io.IOException)

Example 23 with Operation

use of com.google.api.services.storagetransfer.v1.model.Operation in project java-docs-samples by GoogleCloudPlatform.

the class DatasetDeIdentify method datasetDeIdentify.

public static void datasetDeIdentify(String srcDatasetName, String destDatasetName) throws IOException {
    // String srcDatasetName =
    // String.format(DATASET_NAME, "your-project-id", "your-region-id", "your-src-dataset-id");
    // String destDatasetName =
    // String.format(DATASET_NAME, "your-project-id", "your-region-id", "your-dest-dataset-id");
    // Initialize the client, which will be used to interact with the service.
    CloudHealthcare client = createClient();
    // Configure what information needs to be De-Identified.
    // For more information on de-identifying using tags, please see the following:
    // https://cloud.google.com/healthcare/docs/how-tos/dicom-deidentify#de-identification_using_tags
    TagFilterList tags = new TagFilterList().setTags(Arrays.asList("PatientID"));
    DicomConfig dicomConfig = new DicomConfig().setKeepList(tags);
    DeidentifyConfig config = new DeidentifyConfig().setDicom(dicomConfig);
    // Create the de-identify request and configure any parameters.
    DeidentifyDatasetRequest deidentifyRequest = new DeidentifyDatasetRequest().setDestinationDataset(destDatasetName).setConfig(config);
    Datasets.Deidentify request = client.projects().locations().datasets().deidentify(srcDatasetName, deidentifyRequest);
    // Execute the request, wait for the operation to complete, and process the results.
    try {
        Operation operation = request.execute();
        while (operation.getDone() == null || !operation.getDone()) {
            // Update the status of the operation with another request.
            // Pause for 500ms between requests.
            Thread.sleep(500);
            operation = client.projects().locations().datasets().operations().get(operation.getName()).execute();
        }
        System.out.println("De-identified Dataset created. Response content: " + operation.getResponse());
    } catch (Exception ex) {
        System.out.printf("Error during request execution: %s", ex.toString());
        ex.printStackTrace(System.out);
    }
}
Also used : Datasets(com.google.api.services.healthcare.v1.CloudHealthcare.Projects.Locations.Datasets) DeidentifyDatasetRequest(com.google.api.services.healthcare.v1.model.DeidentifyDatasetRequest) DeidentifyConfig(com.google.api.services.healthcare.v1.model.DeidentifyConfig) CloudHealthcare(com.google.api.services.healthcare.v1.CloudHealthcare) Operation(com.google.api.services.healthcare.v1.model.Operation) DicomConfig(com.google.api.services.healthcare.v1.model.DicomConfig) TagFilterList(com.google.api.services.healthcare.v1.model.TagFilterList) IOException(java.io.IOException)

Example 24 with Operation

use of com.google.api.services.storagetransfer.v1.model.Operation in project FAAAST-Service by FraunhoferIOSB.

the class InvokeOperationAsyncRequestHandler method executeOperationAsync.

public OperationHandle executeOperationAsync(Reference reference, InvokeOperationAsyncRequest request) {
    if (assetConnectionManager.hasOperationProvider(reference)) {
        OperationHandle operationHandle = this.persistence.putOperationContext(null, request.getRequestId(), new OperationResult.Builder().requestId(request.getRequestId()).inoutputArguments(request.getInoutputArguments()).executionState(ExecutionState.Running).build());
        BiConsumer<OperationVariable[], OperationVariable[]> callback = (x, y) -> {
            OperationResult operationResult = persistence.getOperationResult(operationHandle.getHandleId());
            operationResult.setExecutionState(ExecutionState.Completed);
            operationResult.setOutputArguments(Arrays.asList(x));
            operationResult.setInoutputArguments(Arrays.asList(y));
            persistence.putOperationContext(operationHandle.getHandleId(), operationHandle.getRequestId(), operationResult);
            publishOperationFinishEventMessage(reference, toValues(Arrays.asList(x)), toValues(Arrays.asList(y)));
        };
        AssetOperationProvider assetOperationProvider = assetConnectionManager.getOperationProvider(reference);
        try {
            assetOperationProvider.invokeAsync(request.getInputArguments().toArray(new OperationVariable[0]), request.getInoutputArguments().toArray(new OperationVariable[0]), callback);
        } catch (AssetConnectionException ex) {
            OperationResult operationResult = persistence.getOperationResult(operationHandle.getHandleId());
            operationResult.setExecutionState(ExecutionState.Failed);
            operationResult.setInoutputArguments(request.getInoutputArguments());
            persistence.putOperationContext(operationHandle.getHandleId(), operationHandle.getRequestId(), operationResult);
            publishOperationFinishEventMessage(reference, List.of(), toValues(operationResult.getInoutputArguments()));
        }
        return operationHandle;
    } else {
        throw new RuntimeException("No assetconnection available for running operation with request id" + request.getRequestId());
    }
}
Also used : MessageBus(de.fraunhofer.iosb.ilt.faaast.service.messagebus.MessageBus) Operation(io.adminshell.aas.v3.model.Operation) Arrays(java.util.Arrays) OperationVariable(io.adminshell.aas.v3.model.OperationVariable) Reference(io.adminshell.aas.v3.model.Reference) OutputModifier(de.fraunhofer.iosb.ilt.faaast.service.model.api.modifier.OutputModifier) AssetConnectionManager(de.fraunhofer.iosb.ilt.faaast.service.assetconnection.AssetConnectionManager) Persistence(de.fraunhofer.iosb.ilt.faaast.service.persistence.Persistence) AssetConnectionException(de.fraunhofer.iosb.ilt.faaast.service.assetconnection.AssetConnectionException) ReferenceHelper(de.fraunhofer.iosb.ilt.faaast.service.util.ReferenceHelper) OperationHandle(de.fraunhofer.iosb.ilt.faaast.service.model.api.operation.OperationHandle) List(java.util.List) StatusCode(de.fraunhofer.iosb.ilt.faaast.service.model.api.StatusCode) ExecutionState(de.fraunhofer.iosb.ilt.faaast.service.model.api.operation.ExecutionState) ResourceNotFoundException(de.fraunhofer.iosb.ilt.faaast.service.exception.ResourceNotFoundException) BiConsumer(java.util.function.BiConsumer) InvokeOperationAsyncRequest(de.fraunhofer.iosb.ilt.faaast.service.model.request.InvokeOperationAsyncRequest) InvokeOperationAsyncResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.InvokeOperationAsyncResponse) OperationResult(de.fraunhofer.iosb.ilt.faaast.service.model.api.operation.OperationResult) AssetOperationProvider(de.fraunhofer.iosb.ilt.faaast.service.assetconnection.AssetOperationProvider) Submodel(io.adminshell.aas.v3.model.Submodel) OperationVariable(io.adminshell.aas.v3.model.OperationVariable) OperationResult(de.fraunhofer.iosb.ilt.faaast.service.model.api.operation.OperationResult) AssetOperationProvider(de.fraunhofer.iosb.ilt.faaast.service.assetconnection.AssetOperationProvider) AssetConnectionException(de.fraunhofer.iosb.ilt.faaast.service.assetconnection.AssetConnectionException) OperationHandle(de.fraunhofer.iosb.ilt.faaast.service.model.api.operation.OperationHandle)

Example 25 with Operation

use of com.google.api.services.storagetransfer.v1.model.Operation in project FAAAST-Service by FraunhoferIOSB.

the class InvokeOperationAsyncRequestHandler method process.

@Override
public InvokeOperationAsyncResponse process(InvokeOperationAsyncRequest request) {
    InvokeOperationAsyncResponse response = new InvokeOperationAsyncResponse();
    try {
        Reference reference = ReferenceHelper.toReference(request.getPath(), request.getId(), Submodel.class);
        // Check if submodelelement does exist
        Operation operation = (Operation) persistence.get(reference, new OutputModifier());
        OperationHandle operationHandle = executeOperationAsync(reference, request);
        response.setPayload(operationHandle);
        response.setStatusCode(StatusCode.Success);
        publishOperationInvokeEventMessage(reference, toValues(request.getInputArguments()), toValues(request.getInoutputArguments()));
    } catch (ResourceNotFoundException ex) {
        response.setStatusCode(StatusCode.ClientErrorResourceNotFound);
    } catch (Exception ex) {
        response.setStatusCode(StatusCode.ServerInternalError);
    }
    return response;
}
Also used : OutputModifier(de.fraunhofer.iosb.ilt.faaast.service.model.api.modifier.OutputModifier) Reference(io.adminshell.aas.v3.model.Reference) Operation(io.adminshell.aas.v3.model.Operation) ResourceNotFoundException(de.fraunhofer.iosb.ilt.faaast.service.exception.ResourceNotFoundException) InvokeOperationAsyncResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.InvokeOperationAsyncResponse) OperationHandle(de.fraunhofer.iosb.ilt.faaast.service.model.api.operation.OperationHandle) AssetConnectionException(de.fraunhofer.iosb.ilt.faaast.service.assetconnection.AssetConnectionException) ResourceNotFoundException(de.fraunhofer.iosb.ilt.faaast.service.exception.ResourceNotFoundException)

Aggregations

IOException (java.io.IOException)15 Operation (io.adminshell.aas.v3.model.Operation)8 StepResult (bio.terra.stairway.StepResult)6 GoogleJsonResponseException (com.google.api.client.googleapis.json.GoogleJsonResponseException)6 CloudHealthcare (com.google.api.services.healthcare.v1.CloudHealthcare)6 Operation (com.google.api.services.healthcare.v1.model.Operation)6 Operation (com.google.api.services.notebooks.v1.model.Operation)5 Reference (io.adminshell.aas.v3.model.Reference)5 Operation (com.google.api.services.appengine.v1.model.Operation)4 ResourceNotFoundException (de.fraunhofer.iosb.ilt.faaast.service.exception.ResourceNotFoundException)4 MessageBus (de.fraunhofer.iosb.ilt.faaast.service.messagebus.MessageBus)4 OperationResult (de.fraunhofer.iosb.ilt.faaast.service.model.api.operation.OperationResult)4 List (java.util.List)4 Test (org.junit.Test)4 AIPlatformNotebooksCow (bio.terra.cloudres.google.notebooks.AIPlatformNotebooksCow)3 InstanceName (bio.terra.cloudres.google.notebooks.InstanceName)3 GcpCloudContext (bio.terra.workspace.service.workspace.model.GcpCloudContext)3 Storagetransfer (com.google.api.services.storagetransfer.v1.Storagetransfer)3 SystemException (bio.terra.cli.exception.SystemException)2 RetryException (bio.terra.stairway.exception.RetryException)2