use of de.fraunhofer.iosb.ilt.faaast.service.model.request.InvokeOperationSyncRequest in project FAAAST-Service by FraunhoferIOSB.
the class OpcUaEndpoint method callOperation.
/**
* Calls the desired operation in the service.
*
* @param operation The desired operation
* @param inputVariables The input arguments
* @param submodel The corresponding submodel
* @param refElement The reference to the SubmodelElement
* @return The OutputArguments The output arguments returned from the operation call
* @throws StatusException If the operation fails
*/
public List<OperationVariable> callOperation(Operation operation, List<OperationVariable> inputVariables, Submodel submodel, Reference refElement) throws StatusException {
List<OperationVariable> outputArguments;
try {
InvokeOperationSyncRequest request = new InvokeOperationSyncRequest();
List<Key> path = new ArrayList<>();
path.addAll(refElement.getKeys());
request.setId(submodel.getIdentification());
request.setPath(path);
request.setInputArguments(inputVariables);
request.setContent(Content.Normal);
requestCounter++;
request.setRequestId(Integer.toString(requestCounter));
// execute method
InvokeOperationSyncResponse response = (InvokeOperationSyncResponse) service.execute(request);
if (isSuccess(response.getStatusCode())) {
logger.info("callOperation: Operation " + operation.getIdShort() + " executed successfully");
} else if (response.getStatusCode() == StatusCode.ClientMethodNotAllowed) {
logger.warn("callOperation: Operation " + operation.getIdShort() + " error executing operation: " + response.getStatusCode());
throw new StatusException(StatusCodes.Bad_NotExecutable);
} else {
logger.warn("callOperation: Operation " + operation.getIdShort() + " error executing operation: " + response.getStatusCode());
throw new StatusException(StatusCodes.Bad_UnexpectedError);
}
outputArguments = response.getPayload().getOutputArguments();
} catch (Exception ex) {
logger.error("callOperation error", ex);
throw ex;
}
return outputArguments;
}
use of de.fraunhofer.iosb.ilt.faaast.service.model.request.InvokeOperationSyncRequest in project FAAAST-Service by FraunhoferIOSB.
the class RequestHandlerManagerTest method testInvokeOperationSyncRequest.
@Test
public void testInvokeOperationSyncRequest() {
CoreConfig coreConfig = CoreConfig.builder().build();
Persistence persistence = mock(Persistence.class);
MessageBus messageBus = mock(MessageBus.class);
AssetConnectionManager assetConnectionManager = mock(AssetConnectionManager.class);
when(assetConnectionManager.hasOperationProvider(any())).thenReturn(true);
when(assetConnectionManager.getOperationProvider(any())).thenReturn(new CustomAssetOperationProvider());
RequestHandlerManager manager = new RequestHandlerManager(coreConfig, persistence, messageBus, assetConnectionManager);
Operation operation = getTestOperation();
InvokeOperationSyncRequest invokeOperationSyncRequest = new InvokeOperationSyncRequest.Builder().requestId("1").inoutputArguments(operation.getInoutputVariables()).inputArguments(operation.getInputVariables()).id(new DefaultIdentifier.Builder().idType(IdentifierType.IRI).identifier("http://example.org").build()).build();
InvokeOperationSyncResponse actualResponse = manager.execute(invokeOperationSyncRequest);
InvokeOperationSyncResponse expectedResponse = new InvokeOperationSyncResponse.Builder().statusCode(StatusCode.Success).payload(new OperationResult.Builder().requestId("1").inoutputArguments(List.of(new DefaultOperationVariable.Builder().value(new DefaultProperty.Builder().idShort("TestProp").value("TestOutput").build()).build())).outputArguments(operation.getInputVariables()).executionState(ExecutionState.Completed).build()).build();
Assert.assertEquals(expectedResponse, actualResponse);
}
Aggregations