Search in sources :

Example 1 with PostSubmodelResponse

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

the class RequestHandlerManagerTest method testPostSubmodelRequest.

@Test
public void testPostSubmodelRequest() throws ResourceNotFoundException {
    when(persistence.put(environment.getSubmodels().get(0))).thenReturn(environment.getSubmodels().get(0));
    PostSubmodelRequest request = new PostSubmodelRequest.Builder().submodel(environment.getSubmodels().get(0)).build();
    PostSubmodelResponse response = manager.execute(request);
    PostSubmodelResponse expected = new PostSubmodelResponse.Builder().payload(environment.getSubmodels().get(0)).statusCode(StatusCode.SuccessCreated).build();
    Assert.assertEquals(expected, response);
}
Also used : PostSubmodelResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.PostSubmodelResponse) PostSubmodelRequest(de.fraunhofer.iosb.ilt.faaast.service.model.request.PostSubmodelRequest) Test(org.junit.Test)

Example 2 with PostSubmodelResponse

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

the class PostSubmodelRequestHandler method process.

@Override
public PostSubmodelResponse process(PostSubmodelRequest request) {
    PostSubmodelResponse response = new PostSubmodelResponse();
    try {
        Submodel submodel = (Submodel) persistence.put(request.getSubmodel());
        response.setPayload(submodel);
        response.setStatusCode(StatusCode.SuccessCreated);
        Reference reference = AasUtils.toReference(submodel);
        readValueFromAssetConnectionAndUpdatePersistence(reference, submodel.getSubmodelElements());
        publishElementCreateEventMessage(reference, submodel);
    } catch (Exception ex) {
        response.setStatusCode(StatusCode.ServerInternalError);
    }
    return response;
}
Also used : Submodel(io.adminshell.aas.v3.model.Submodel) PostSubmodelResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.PostSubmodelResponse) Reference(io.adminshell.aas.v3.model.Reference)

Aggregations

PostSubmodelResponse (de.fraunhofer.iosb.ilt.faaast.service.model.api.response.PostSubmodelResponse)2 PostSubmodelRequest (de.fraunhofer.iosb.ilt.faaast.service.model.request.PostSubmodelRequest)1 Reference (io.adminshell.aas.v3.model.Reference)1 Submodel (io.adminshell.aas.v3.model.Submodel)1 Test (org.junit.Test)1