Search in sources :

Example 1 with PutSubmodelResponse

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

the class PutSubmodelRequestHandler method process.

@Override
public PutSubmodelResponse process(PutSubmodelRequest request) {
    PutSubmodelResponse response = new PutSubmodelResponse();
    try {
        // check if resource does exist
        Submodel submodel = (Submodel) persistence.get(request.getSubmodel().getIdentification(), new QueryModifier.Builder().extend(Extend.WithoutBLOBValue).level(Level.Core).build());
        submodel = (Submodel) persistence.put(request.getSubmodel());
        response.setPayload(submodel);
        response.setStatusCode(StatusCode.Success);
        Reference reference = AasUtils.toReference(submodel);
        readValueFromAssetConnectionAndUpdatePersistence(reference, submodel.getSubmodelElements());
        publishElementUpdateEventMessage(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) PutSubmodelResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.PutSubmodelResponse) Reference(io.adminshell.aas.v3.model.Reference) QueryModifier(de.fraunhofer.iosb.ilt.faaast.service.model.api.modifier.QueryModifier) ResourceNotFoundException(de.fraunhofer.iosb.ilt.faaast.service.exception.ResourceNotFoundException) ResourceNotFoundException(de.fraunhofer.iosb.ilt.faaast.service.exception.ResourceNotFoundException)

Example 2 with PutSubmodelResponse

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

the class RequestHandlerManagerTest method testPutSubmodelRequest.

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

Aggregations

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