Search in sources :

Example 1 with PostSubmodelElementResponse

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

the class RequestHandlerManagerTest method testPostSubmodelElementRequest.

@Test
public void testPostSubmodelElementRequest() throws ResourceNotFoundException {
    Reference reference = ReferenceHelper.toReference(environment.getSubmodels().get(0).getIdentification(), Submodel.class);
    when(persistence.put(reference, (Reference) null, environment.getSubmodels().get(0).getSubmodelElements().get(0))).thenReturn(environment.getSubmodels().get(0).getSubmodelElements().get(0));
    PostSubmodelElementRequest request = new PostSubmodelElementRequest.Builder().id(environment.getSubmodels().get(0).getIdentification()).submodelElement(environment.getSubmodels().get(0).getSubmodelElements().get(0)).build();
    PostSubmodelElementResponse response = manager.execute(request);
    PostSubmodelElementResponse expected = new PostSubmodelElementResponse.Builder().statusCode(StatusCode.SuccessCreated).payload(environment.getSubmodels().get(0).getSubmodelElements().get(0)).build();
    Assert.assertEquals(expected, response);
}
Also used : Reference(io.adminshell.aas.v3.model.Reference) DefaultReference(io.adminshell.aas.v3.model.impl.DefaultReference) AtomicReference(java.util.concurrent.atomic.AtomicReference) PostSubmodelElementRequest(de.fraunhofer.iosb.ilt.faaast.service.model.request.PostSubmodelElementRequest) PostSubmodelElementResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.PostSubmodelElementResponse) Test(org.junit.Test)

Example 2 with PostSubmodelElementResponse

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

the class PostSubmodelElementRequestHandler method process.

@Override
public PostSubmodelElementResponse process(PostSubmodelElementRequest request) {
    PostSubmodelElementResponse response = new PostSubmodelElementResponse();
    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 : SubmodelElement(io.adminshell.aas.v3.model.SubmodelElement) PostSubmodelElementResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.PostSubmodelElementResponse) 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

PostSubmodelElementResponse (de.fraunhofer.iosb.ilt.faaast.service.model.api.response.PostSubmodelElementResponse)2 Reference (io.adminshell.aas.v3.model.Reference)2 ResourceNotFoundException (de.fraunhofer.iosb.ilt.faaast.service.exception.ResourceNotFoundException)1 PostSubmodelElementRequest (de.fraunhofer.iosb.ilt.faaast.service.model.request.PostSubmodelElementRequest)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