Search in sources :

Example 1 with GetSubmodelByIdResponse

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

the class GetSubmodelByIdRequestHandler method process.

@Override
public GetSubmodelByIdResponse process(GetSubmodelByIdRequest request) {
    GetSubmodelByIdResponse response = new GetSubmodelByIdResponse();
    try {
        Submodel submodel = (Submodel) persistence.get(request.getId(), request.getOutputModifier());
        response.setPayload(submodel);
        response.setStatusCode(StatusCode.Success);
        Reference reference = AasUtils.toReference(submodel);
        readValueFromAssetConnectionAndUpdatePersistence(reference, submodel.getSubmodelElements());
        publishElementReadEventMessage(reference, submodel);
    } catch (ResourceNotFoundException ex) {
        response.setStatusCode(StatusCode.ClientErrorResourceNotFound);
    } catch (Exception ex) {
        response.setStatusCode(StatusCode.ServerInternalError);
    }
    return response;
}
Also used : Submodel(io.adminshell.aas.v3.model.Submodel) Reference(io.adminshell.aas.v3.model.Reference) GetSubmodelByIdResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.GetSubmodelByIdResponse) ResourceNotFoundException(de.fraunhofer.iosb.ilt.faaast.service.exception.ResourceNotFoundException) ResourceNotFoundException(de.fraunhofer.iosb.ilt.faaast.service.exception.ResourceNotFoundException)

Example 2 with GetSubmodelByIdResponse

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

the class RequestHandlerManagerTest method testGetSubmodelByIdRequest.

@Test
public void testGetSubmodelByIdRequest() throws ResourceNotFoundException {
    when(persistence.get(environment.getSubmodels().get(0).getIdentification(), new OutputModifier())).thenReturn(environment.getSubmodels().get(0));
    GetSubmodelByIdRequest request = new GetSubmodelByIdRequest.Builder().id(environment.getSubmodels().get(0).getIdentification()).outputModifier(new OutputModifier()).build();
    GetSubmodelByIdResponse response = manager.execute(request);
    GetSubmodelByIdResponse expected = new GetSubmodelByIdResponse.Builder().payload(environment.getSubmodels().get(0)).statusCode(StatusCode.Success).build();
    Assert.assertEquals(expected, response);
}
Also used : OutputModifier(de.fraunhofer.iosb.ilt.faaast.service.model.api.modifier.OutputModifier) GetSubmodelByIdResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.GetSubmodelByIdResponse) GetSubmodelByIdRequest(de.fraunhofer.iosb.ilt.faaast.service.model.request.GetSubmodelByIdRequest) Test(org.junit.Test)

Aggregations

GetSubmodelByIdResponse (de.fraunhofer.iosb.ilt.faaast.service.model.api.response.GetSubmodelByIdResponse)2 ResourceNotFoundException (de.fraunhofer.iosb.ilt.faaast.service.exception.ResourceNotFoundException)1 OutputModifier (de.fraunhofer.iosb.ilt.faaast.service.model.api.modifier.OutputModifier)1 GetSubmodelByIdRequest (de.fraunhofer.iosb.ilt.faaast.service.model.request.GetSubmodelByIdRequest)1 Reference (io.adminshell.aas.v3.model.Reference)1 Submodel (io.adminshell.aas.v3.model.Submodel)1 Test (org.junit.Test)1