use of de.fraunhofer.iosb.ilt.faaast.service.model.api.response.PutSubmodelElementByPathResponse in project FAAAST-Service by FraunhoferIOSB.
the class PutSubmodelElementByPathRequestHandler method process.
@Override
public PutSubmodelElementByPathResponse process(PutSubmodelElementByPathRequest request) {
PutSubmodelElementByPathResponse response = new PutSubmodelElementByPathResponse();
try {
Reference reference = ReferenceHelper.toReference(request.getPath(), request.getId(), Submodel.class);
// Check if submodelelement does exist
SubmodelElement currentSubmodelElement = persistence.get(reference, new QueryModifier.Builder().extend(Extend.WithoutBLOBValue).level(Level.Core).build());
SubmodelElement newSubmodelElement = request.getSubmodelElement();
ElementValue oldValue = ElementValueMapper.toValue(currentSubmodelElement);
ElementValue newValue = ElementValueMapper.toValue(newSubmodelElement);
currentSubmodelElement = persistence.put(null, reference, newSubmodelElement);
response.setPayload(currentSubmodelElement);
response.setStatusCode(StatusCode.Success);
if (!Objects.equals(oldValue, newValue)) {
writeValueToAssetConnection(reference, ElementValueMapper.toValue(currentSubmodelElement));
}
publishElementUpdateEventMessage(reference, currentSubmodelElement);
} catch (ResourceNotFoundException ex) {
response.setStatusCode(StatusCode.ClientErrorResourceNotFound);
} catch (Exception ex) {
response.setStatusCode(StatusCode.ServerInternalError);
}
return response;
}
use of de.fraunhofer.iosb.ilt.faaast.service.model.api.response.PutSubmodelElementByPathResponse in project FAAAST-Service by FraunhoferIOSB.
the class RequestHandlerManagerTest method testPutSubmodelElementByPathRequest.
@Test
public void testPutSubmodelElementByPathRequest() throws ResourceNotFoundException, AssetConnectionException {
SubmodelElement currentSubmodelElement = new DefaultProperty.Builder().idShort("TestIdshort").valueType("string").value("TestValue").build();
SubmodelElement newSubmodelElement = new DefaultProperty.Builder().idShort("TestIdshort").valueType("string").value("NewTestValue").build();
when(persistence.get(argThat((Reference t) -> true), any())).thenReturn(currentSubmodelElement);
when(persistence.put(any(), argThat((Reference t) -> true), any())).thenReturn(newSubmodelElement);
when(assetConnectionManager.hasValueProvider(any())).thenReturn(true);
PutSubmodelElementByPathRequest request = new PutSubmodelElementByPathRequest.Builder().id(environment.getSubmodels().get(0).getIdentification()).submodelElement(newSubmodelElement).build();
PutSubmodelElementByPathResponse response = manager.execute(request);
PutSubmodelElementByPathResponse expected = new PutSubmodelElementByPathResponse.Builder().payload(newSubmodelElement).statusCode(StatusCode.Success).build();
Assert.assertEquals(expected, response);
verify(assetValueProvider).setValue(ElementValueMapper.toValue(newSubmodelElement));
}
Aggregations