use of de.fraunhofer.iosb.ilt.faaast.service.model.api.response.InvokeOperationSyncResponse 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 de.fraunhofer.iosb.ilt.faaast.service.model.api.response.InvokeOperationSyncResponse 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.api.response.InvokeOperationSyncResponse 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