Search in sources :

Example 1 with GetSubmodelElementByPathResponse

use of de.fraunhofer.iosb.ilt.faaast.service.model.api.response.GetSubmodelElementByPathResponse in project FAAAST-Service by FraunhoferIOSB.

the class GetSubmodelElementByPathRequestHandler method process.

@Override
public GetSubmodelElementByPathResponse process(GetSubmodelElementByPathRequest request) {
    GetSubmodelElementByPathResponse response = new GetSubmodelElementByPathResponse();
    try {
        Reference reference = ReferenceHelper.toReference(request.getPath(), request.getId(), Submodel.class);
        SubmodelElement submodelElement = persistence.get(reference, request.getOutputModifier());
        ElementValue oldValue = ElementValueMapper.toValue(submodelElement);
        // read value from AssetConnection if one exist
        // and update value in persistence if differs
        ElementValue valueFromAssetConnection = readDataElementValueFromAssetConnection(reference);
        if (valueFromAssetConnection != null && !Objects.equals(valueFromAssetConnection, oldValue)) {
            submodelElement = ElementValueMapper.setValue(submodelElement, valueFromAssetConnection);
            persistence.put(null, reference, submodelElement);
            // TODO @Jens
            // better publishValueChangeEventMessage(reference, oldValue, oldValue) ???
            publishElementUpdateEventMessage(reference, submodelElement);
        }
        response.setPayload(submodelElement);
        response.setStatusCode(StatusCode.Success);
        publishElementReadEventMessage(reference, submodelElement);
    } catch (ResourceNotFoundException ex) {
        response.setStatusCode(StatusCode.ClientErrorResourceNotFound);
    } catch (Exception ex) {
        response.setStatusCode(StatusCode.ServerInternalError);
    }
    return response;
}
Also used : SubmodelElement(io.adminshell.aas.v3.model.SubmodelElement) Reference(io.adminshell.aas.v3.model.Reference) GetSubmodelElementByPathResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.GetSubmodelElementByPathResponse) 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 GetSubmodelElementByPathResponse

use of de.fraunhofer.iosb.ilt.faaast.service.model.api.response.GetSubmodelElementByPathResponse in project FAAAST-Service by FraunhoferIOSB.

the class RequestHandlerManagerTest method testGetSubmodelElementByPathRequest.

@Test
public void testGetSubmodelElementByPathRequest() throws ResourceNotFoundException, AssetConnectionException {
    Submodel submodel = environment.getSubmodels().get(0);
    SubmodelElement cur_submodelElement = new DefaultProperty.Builder().idShort("testIdShort").value("testValue").build();
    PropertyValue propertyValue = new PropertyValue.Builder().value(new StringValue("test")).build();
    when(persistence.get(argThat((Reference t) -> true), eq(new OutputModifier()))).thenReturn(cur_submodelElement);
    when(assetConnectionManager.hasValueProvider(any())).thenReturn(true);
    when(assetValueProvider.getValue()).thenReturn(propertyValue);
    GetSubmodelElementByPathRequest request = new GetSubmodelElementByPathRequest.Builder().id(submodel.getIdentification()).outputModifier(new OutputModifier()).path(ReferenceHelper.toKeys(SUBMODEL_ELEMENT_REF)).build();
    GetSubmodelElementByPathResponse response = manager.execute(request);
    SubmodelElement expected_submodelElement = new DefaultProperty.Builder().idShort("testIdShort").value("test").valueType("string").build();
    GetSubmodelElementByPathResponse expected = new GetSubmodelElementByPathResponse.Builder().payload(expected_submodelElement).statusCode(StatusCode.Success).build();
    Assert.assertEquals(expected, response);
}
Also used : Submodel(io.adminshell.aas.v3.model.Submodel) SubmodelElement(io.adminshell.aas.v3.model.SubmodelElement) GetSubmodelElementByPathRequest(de.fraunhofer.iosb.ilt.faaast.service.model.request.GetSubmodelElementByPathRequest) OutputModifier(de.fraunhofer.iosb.ilt.faaast.service.model.api.modifier.OutputModifier) Reference(io.adminshell.aas.v3.model.Reference) DefaultReference(io.adminshell.aas.v3.model.impl.DefaultReference) AtomicReference(java.util.concurrent.atomic.AtomicReference) PropertyValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.PropertyValue) GetSubmodelElementByPathResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.GetSubmodelElementByPathResponse) StringValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.primitive.StringValue) DefaultProperty(io.adminshell.aas.v3.model.impl.DefaultProperty) Test(org.junit.Test)

Aggregations

GetSubmodelElementByPathResponse (de.fraunhofer.iosb.ilt.faaast.service.model.api.response.GetSubmodelElementByPathResponse)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 OutputModifier (de.fraunhofer.iosb.ilt.faaast.service.model.api.modifier.OutputModifier)1 GetSubmodelElementByPathRequest (de.fraunhofer.iosb.ilt.faaast.service.model.request.GetSubmodelElementByPathRequest)1 ElementValue (de.fraunhofer.iosb.ilt.faaast.service.model.value.ElementValue)1 PropertyValue (de.fraunhofer.iosb.ilt.faaast.service.model.value.PropertyValue)1 StringValue (de.fraunhofer.iosb.ilt.faaast.service.model.value.primitive.StringValue)1 Submodel (io.adminshell.aas.v3.model.Submodel)1 DefaultProperty (io.adminshell.aas.v3.model.impl.DefaultProperty)1 DefaultReference (io.adminshell.aas.v3.model.impl.DefaultReference)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Test (org.junit.Test)1