Search in sources :

Example 1 with PutSubmodelElementByPathResponse

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;
}
Also used : PutSubmodelElementByPathResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.PutSubmodelElementByPathResponse) SubmodelElement(io.adminshell.aas.v3.model.SubmodelElement) Reference(io.adminshell.aas.v3.model.Reference) ElementValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.ElementValue) ResourceNotFoundException(de.fraunhofer.iosb.ilt.faaast.service.exception.ResourceNotFoundException) ResourceNotFoundException(de.fraunhofer.iosb.ilt.faaast.service.exception.ResourceNotFoundException)

Example 2 with PutSubmodelElementByPathResponse

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));
}
Also used : PutSubmodelElementByPathResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.PutSubmodelElementByPathResponse) SubmodelElement(io.adminshell.aas.v3.model.SubmodelElement) PutSubmodelElementByPathRequest(de.fraunhofer.iosb.ilt.faaast.service.model.request.PutSubmodelElementByPathRequest) Reference(io.adminshell.aas.v3.model.Reference) DefaultReference(io.adminshell.aas.v3.model.impl.DefaultReference) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.Test)

Aggregations

PutSubmodelElementByPathResponse (de.fraunhofer.iosb.ilt.faaast.service.model.api.response.PutSubmodelElementByPathResponse)2 Reference (io.adminshell.aas.v3.model.Reference)2 SubmodelElement (io.adminshell.aas.v3.model.SubmodelElement)2 ResourceNotFoundException (de.fraunhofer.iosb.ilt.faaast.service.exception.ResourceNotFoundException)1 PutSubmodelElementByPathRequest (de.fraunhofer.iosb.ilt.faaast.service.model.request.PutSubmodelElementByPathRequest)1 ElementValue (de.fraunhofer.iosb.ilt.faaast.service.model.value.ElementValue)1 DefaultReference (io.adminshell.aas.v3.model.impl.DefaultReference)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Test (org.junit.Test)1