use of com.google.api.services.container.v1beta1.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);
}
}
use of com.google.api.services.container.v1beta1.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);
}
use of com.google.api.services.container.v1beta1.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!");
}
}
}
use of com.google.api.services.container.v1beta1.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;
}
use of com.google.api.services.container.v1beta1.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;
}
Aggregations