Search in sources :

Example 1 with PostSubmodelElementByPathResponse

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

the class RequestHandlerManagerTest method testPostSubmodelElementByPathRequest.

@Test
public void testPostSubmodelElementByPathRequest() throws ResourceNotFoundException {
    when(persistence.put(any(), argThat((Reference t) -> true), any())).thenReturn(environment.getSubmodels().get(0).getSubmodelElements().get(0));
    PostSubmodelElementByPathRequest request = new PostSubmodelElementByPathRequest.Builder().id(environment.getSubmodels().get(0).getIdentification()).path(ReferenceHelper.toKeys(SUBMODEL_ELEMENT_REF)).build();
    PostSubmodelElementByPathResponse response = manager.execute(request);
    PostSubmodelElementByPathResponse expected = new PostSubmodelElementByPathResponse.Builder().payload(environment.getSubmodels().get(0).getSubmodelElements().get(0)).statusCode(StatusCode.SuccessCreated).build();
    Assert.assertEquals(expected, response);
}
Also used : PostSubmodelElementByPathResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.PostSubmodelElementByPathResponse) Reference(io.adminshell.aas.v3.model.Reference) DefaultReference(io.adminshell.aas.v3.model.impl.DefaultReference) AtomicReference(java.util.concurrent.atomic.AtomicReference) PostSubmodelElementByPathRequest(de.fraunhofer.iosb.ilt.faaast.service.model.request.PostSubmodelElementByPathRequest) Test(org.junit.Test)

Example 2 with PostSubmodelElementByPathResponse

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

the class PostSubmodelElementByPathRequestHandler method process.

@Override
public PostSubmodelElementByPathResponse process(PostSubmodelElementByPathRequest request) {
    PostSubmodelElementByPathResponse response = new PostSubmodelElementByPathResponse();
    try {
        Reference parentReference = ReferenceHelper.toReference(request.getId(), Submodel.class);
        Reference childReference = AasUtils.toReference(parentReference, request.getSubmodelElement());
        SubmodelElement submodelElement = persistence.put(parentReference, null, request.getSubmodelElement());
        response.setPayload(submodelElement);
        response.setStatusCode(StatusCode.SuccessCreated);
        writeValueToAssetConnection(childReference, ElementValueMapper.toValue(submodelElement));
        publishElementCreateEventMessage(parentReference, submodelElement);
    } catch (ResourceNotFoundException ex) {
        response.setStatusCode(StatusCode.ClientErrorResourceNotFound);
    } catch (Exception ex) {
        response.setStatusCode(StatusCode.ServerInternalError);
    }
    return response;
}
Also used : PostSubmodelElementByPathResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.PostSubmodelElementByPathResponse) SubmodelElement(io.adminshell.aas.v3.model.SubmodelElement) Reference(io.adminshell.aas.v3.model.Reference) ResourceNotFoundException(de.fraunhofer.iosb.ilt.faaast.service.exception.ResourceNotFoundException) ResourceNotFoundException(de.fraunhofer.iosb.ilt.faaast.service.exception.ResourceNotFoundException)

Aggregations

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