Search in sources :

Example 6 with Operation

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

the class FhirStoreExport method fhirStoreExport.

public static void fhirStoreExport(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 will be exported too.
    GoogleCloudHealthcareV1FhirGcsDestination gcsDestination = new GoogleCloudHealthcareV1FhirGcsDestination().setUriPrefix(gcsUri);
    ExportResourcesRequest exportRequest = new ExportResourcesRequest().setGcsDestination(gcsDestination);
    // Create request and configure any parameters.
    FhirStores.Export request = client.projects().locations().datasets().fhirStores().export(fhirStoreName, 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("Fhir store export 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) CloudHealthcare(com.google.api.services.healthcare.v1.CloudHealthcare) ExportResourcesRequest(com.google.api.services.healthcare.v1.model.ExportResourcesRequest) Operation(com.google.api.services.healthcare.v1.model.Operation) GoogleCloudHealthcareV1FhirGcsDestination(com.google.api.services.healthcare.v1.model.GoogleCloudHealthcareV1FhirGcsDestination) IOException(java.io.IOException)

Example 7 with Operation

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

the class RequestHandlerManagerTest method testInvokeOperationAsyncRequest.

@Test
public void testInvokeOperationAsyncRequest() {
    CoreConfig coreConfig = CoreConfig.builder().build();
    Persistence persistence = mock(Persistence.class);
    MessageBus messageBus = mock(MessageBus.class);
    AssetConnectionManager assetConnectionManager = mock(AssetConnectionManager.class);
    AssetOperationProvider assetOperationProvider = mock(AssetOperationProvider.class);
    RequestHandlerManager manager = new RequestHandlerManager(coreConfig, persistence, messageBus, assetConnectionManager);
    Operation operation = getTestOperation();
    OperationHandle expectedOperationHandle = new OperationHandle.Builder().handleId("1").requestId("1").build();
    when(persistence.putOperationContext(any(), any(), any())).thenReturn(expectedOperationHandle);
    when(persistence.getOperationResult(any())).thenReturn(new OperationResult.Builder().requestId("1").build());
    when(assetConnectionManager.hasOperationProvider(any())).thenReturn(true);
    when(assetConnectionManager.getOperationProvider(any())).thenReturn(assetOperationProvider);
    InvokeOperationAsyncRequest invokeOperationAsyncRequest = new InvokeOperationAsyncRequest.Builder().requestId("1").id(new DefaultIdentifier.Builder().idType(IdentifierType.IRI).identifier("http://example.org").build()).inoutputArguments(operation.getInoutputVariables()).inputArguments(operation.getInputVariables()).build();
    InvokeOperationAsyncResponse response = manager.execute(invokeOperationAsyncRequest);
    OperationHandle actualOperationHandle = response.getPayload();
    Assert.assertEquals(expectedOperationHandle, actualOperationHandle);
}
Also used : CoreConfig(de.fraunhofer.iosb.ilt.faaast.service.config.CoreConfig) OperationResult(de.fraunhofer.iosb.ilt.faaast.service.model.api.operation.OperationResult) Operation(io.adminshell.aas.v3.model.Operation) DefaultOperation(io.adminshell.aas.v3.model.impl.DefaultOperation) OperationHandle(de.fraunhofer.iosb.ilt.faaast.service.model.api.operation.OperationHandle) Persistence(de.fraunhofer.iosb.ilt.faaast.service.persistence.Persistence) MessageBus(de.fraunhofer.iosb.ilt.faaast.service.messagebus.MessageBus) AssetConnectionManager(de.fraunhofer.iosb.ilt.faaast.service.assetconnection.AssetConnectionManager) RequestHandlerManager(de.fraunhofer.iosb.ilt.faaast.service.request.RequestHandlerManager) InvokeOperationAsyncRequest(de.fraunhofer.iosb.ilt.faaast.service.model.request.InvokeOperationAsyncRequest) AssetOperationProvider(de.fraunhofer.iosb.ilt.faaast.service.assetconnection.AssetOperationProvider) DefaultIdentifier(io.adminshell.aas.v3.model.impl.DefaultIdentifier) InvokeOperationAsyncResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.InvokeOperationAsyncResponse) Test(org.junit.Test)

Example 8 with Operation

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

the class ReferenceHelper method completeReferenceWithProperKeyElements.

/**
 * Browse the keys of a reference and try to find the referenced element in the
 * asset administration shell environment to set the right {@link io.adminshell.aas.v3.model.KeyElements}
 * of the key.
 * All key types must be null or SUBMODEL_ELEMENT.
 *
 * @param reference with keys which should be completed
 * @param env the asset administration shell environment which contains the referenced elements
 * @throws ResourceNotFoundException if an element referenced by a key could not be found
 */
public static void completeReferenceWithProperKeyElements(Reference reference, AssetAdministrationShellEnvironment env) throws ResourceNotFoundException {
    if (reference == null) {
        return;
    }
    List<Key> keys = reference.getKeys();
    if (keys.stream().allMatch(x -> x.getType() != null && x.getType() != KeyElements.SUBMODEL_ELEMENT)) {
        return;
    }
    final Referable[] parent = { null };
    for (Key k : keys) {
        if (env.getAssetAdministrationShells().stream().anyMatch(x -> x.getIdentification().getIdentifier().equalsIgnoreCase(k.getValue()) || x.getIdShort().equalsIgnoreCase(k.getValue()))) {
            k.setType(KeyElements.ASSET_ADMINISTRATION_SHELL);
            continue;
        }
        env.getSubmodels().forEach(x -> {
            if (x.getIdentification().getIdentifier().equalsIgnoreCase(k.getValue()) || x.getIdShort().equalsIgnoreCase(k.getValue())) {
                k.setType(KeyElements.SUBMODEL);
                parent[0] = x;
            }
        });
        if (k.getType() != null && k.getType() != KeyElements.SUBMODEL_ELEMENT) {
            continue;
        }
        if (env.getConceptDescriptions().stream().anyMatch(x -> x.getIdentification().getIdentifier().equalsIgnoreCase(k.getValue()) || x.getIdShort().equalsIgnoreCase(k.getValue()))) {
            k.setType(KeyElements.CONCEPT_DESCRIPTION);
            continue;
        }
        if (env.getAssets().stream().anyMatch(x -> x.getIdentification().getIdentifier().equalsIgnoreCase(k.getValue()) || x.getIdShort().equalsIgnoreCase(k.getValue()))) {
            k.setType(KeyElements.ASSET);
            continue;
        }
        if (parent[0] != null && Submodel.class.isAssignableFrom(parent[0].getClass())) {
            Submodel submodel = (Submodel) parent[0];
            submodel.getSubmodelElements().forEach(y -> {
                if (y.getIdShort().equalsIgnoreCase(k.getValue())) {
                    k.setType(AasUtils.referableToKeyType(y));
                    parent[0] = y;
                }
            });
        } else if (SubmodelElementCollection.class.isAssignableFrom(parent[0].getClass())) {
            ((SubmodelElementCollection) parent[0]).getValues().forEach(x -> {
                if (x.getIdShort().equalsIgnoreCase(k.getValue())) {
                    k.setType(AasUtils.referableToKeyType(x));
                    parent[0] = x;
                }
            });
        } else if (Operation.class.isAssignableFrom(parent[0].getClass())) {
            Operation operation = (Operation) parent[0];
            Stream.concat(Stream.concat(operation.getInoutputVariables().stream(), operation.getInputVariables().stream()), operation.getOutputVariables().stream()).forEach(x -> {
                if (x.getValue().getIdShort().equalsIgnoreCase(k.getValue())) {
                    k.setType(AasUtils.referableToKeyType(x.getValue()));
                    parent[0] = x.getValue();
                }
            });
        }
        if (k.getType() == null) {
            throw new ResourceNotFoundException("Resource with ID " + k.getValue() + " was not found!");
        }
    }
}
Also used : Submodel(io.adminshell.aas.v3.model.Submodel) KeyElements(io.adminshell.aas.v3.model.KeyElements) Operation(io.adminshell.aas.v3.model.Operation) SubmodelElement(io.adminshell.aas.v3.model.SubmodelElement) Reference(io.adminshell.aas.v3.model.Reference) AssetAdministrationShellEnvironment(io.adminshell.aas.v3.model.AssetAdministrationShellEnvironment) SubmodelElementCollection(io.adminshell.aas.v3.model.SubmodelElementCollection) Collectors(java.util.stream.Collectors) AasUtils(io.adminshell.aas.v3.dataformat.core.util.AasUtils) Identifier(io.adminshell.aas.v3.model.Identifier) ArrayList(java.util.ArrayList) ReflectionHelper(io.adminshell.aas.v3.dataformat.core.ReflectionHelper) Key(io.adminshell.aas.v3.model.Key) List(java.util.List) Stream(java.util.stream.Stream) ResourceNotFoundException(de.fraunhofer.iosb.ilt.faaast.service.exception.ResourceNotFoundException) Referable(io.adminshell.aas.v3.model.Referable) DefaultReference(io.adminshell.aas.v3.model.impl.DefaultReference) KeyType(io.adminshell.aas.v3.model.KeyType) DefaultKey(io.adminshell.aas.v3.model.impl.DefaultKey) Submodel(io.adminshell.aas.v3.model.Submodel) Referable(io.adminshell.aas.v3.model.Referable) SubmodelElementCollection(io.adminshell.aas.v3.model.SubmodelElementCollection) Operation(io.adminshell.aas.v3.model.Operation) ResourceNotFoundException(de.fraunhofer.iosb.ilt.faaast.service.exception.ResourceNotFoundException) Key(io.adminshell.aas.v3.model.Key) DefaultKey(io.adminshell.aas.v3.model.impl.DefaultKey)

Example 9 with Operation

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

the class InvokeOperationSyncRequestHandler method process.

@Override
public InvokeOperationSyncResponse process(InvokeOperationSyncRequest request) {
    Reference reference = ReferenceHelper.toReference(request.getPath(), request.getId(), Submodel.class);
    InvokeOperationSyncResponse response = new InvokeOperationSyncResponse();
    try {
        // Check if submodelelement does exist
        Operation operation = (Operation) persistence.get(reference, new OutputModifier());
        publishOperationInvokeEventMessage(reference, toValues(request.getInputArguments()), toValues(request.getInoutputArguments()));
        OperationResult operationResult = executeOperationSync(reference, request);
        response.setPayload(operationResult);
        response.setStatusCode(StatusCode.Success);
    } catch (ResourceNotFoundException ex) {
        response.setStatusCode(StatusCode.ClientErrorResourceNotFound);
    } catch (Exception ex) {
        response.setStatusCode(StatusCode.ServerInternalError);
    }
    publishOperationFinishEventMessage(reference, toValues(response.getPayload().getOutputArguments()), toValues(response.getPayload().getInoutputArguments()));
    return response;
}
Also used : OutputModifier(de.fraunhofer.iosb.ilt.faaast.service.model.api.modifier.OutputModifier) Reference(io.adminshell.aas.v3.model.Reference) InvokeOperationSyncResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.InvokeOperationSyncResponse) OperationResult(de.fraunhofer.iosb.ilt.faaast.service.model.api.operation.OperationResult) Operation(io.adminshell.aas.v3.model.Operation) ResourceNotFoundException(de.fraunhofer.iosb.ilt.faaast.service.exception.ResourceNotFoundException) TimeoutException(java.util.concurrent.TimeoutException) ResourceNotFoundException(de.fraunhofer.iosb.ilt.faaast.service.exception.ResourceNotFoundException)

Example 10 with Operation

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

the class AasServiceMethodManagerListener method onCall.

/**
 * Callback method when a method was called
 *
 * @param serviceContext the current service context
 * @param objectId the ID of the node whose method is being called
 * @param object the object node whose method is being called, if available
 * @param methodId the ID of the method being called
 * @param method the method node being called, if available
 * @param inputArguments input argument values
 * @param inputArgumentResults argument errors. If errors in the values are
 *            encountered.
 * @param inputArgumentDiagnosticInfos diagnostic info, in case of errors.
 * @param outputs output values. The array is pre-created, just fill in the
 *            values.
 * @return true if you handle the call, which prevents any other handler
 *         being called.
 * @throws StatusException if there are errors in the method handling. For
 *             example, if you set inputArgumentResults, you should throw a
 *             StatusException with StatusCodes.Bad_InvalidArgument
 */
@Override
public boolean onCall(ServiceContext serviceContext, NodeId objectId, UaNode object, NodeId methodId, UaMethod method, Variant[] inputArguments, StatusCode[] inputArgumentResults, DiagnosticInfo[] inputArgumentDiagnosticInfos, Variant[] outputs) throws StatusException {
    boolean retval = false;
    // Handle method calls
    // Note that the outputs array is already allocated
    logger.info("onCall: method " + methodId.toString() + ": called. InputArguments: " + Arrays.toString(inputArguments));
    try {
        if (endpoint == null) {
            logger.warn("onCall: no Endpoint available");
        } else {
            SubmodelElementData data = nodeManager.getAasData(objectId);
            Operation aasOper = (Operation) data.getSubmodelElement();
            if (aasOper != null) {
                List<OperationVariable> inputVariables = aasOper.getInputVariables();
                ValueConverter.setOperationValues(inputVariables, inputArguments);
                List<OperationVariable> outputVariables = endpoint.callOperation(aasOper, inputVariables, data.getSubmodel(), data.getReference());
                ValueConverter.setOutputArguments(outputVariables, outputs);
                retval = true;
            } else {
                logger.info("onCall: Property for " + objectId.toString() + " not found");
            }
        }
    } catch (StatusException se) {
        logger.error("onCall StatusException", se);
        throw se;
    } catch (Throwable ex) {
        logger.error("onCall Exception", ex);
        throw new StatusException(ex.getMessage(), StatusCodes.Bad_UnexpectedError);
    }
    return retval;
}
Also used : StatusException(com.prosysopc.ua.StatusException) OperationVariable(io.adminshell.aas.v3.model.OperationVariable) Operation(io.adminshell.aas.v3.model.Operation) SubmodelElementData(de.fraunhofer.iosb.ilt.faaast.service.endpoint.opcua.data.SubmodelElementData)

Aggregations

IOException (java.io.IOException)13 Operation (io.adminshell.aas.v3.model.Operation)8 CloudHealthcare (com.google.api.services.healthcare.v1.CloudHealthcare)6 Operation (com.google.api.services.healthcare.v1.model.Operation)6 GoogleJsonResponseException (com.google.api.client.googleapis.json.GoogleJsonResponseException)5 Operation (com.google.api.services.notebooks.v1.model.Operation)5 Reference (io.adminshell.aas.v3.model.Reference)5 StepResult (bio.terra.stairway.StepResult)4 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 Status (com.google.api.services.appengine.v1.model.Status)3 Project (com.google.api.services.cloudresourcemanager.v3.model.Project)3 SystemException (bio.terra.cli.exception.SystemException)2