Search in sources :

Example 1 with PostSubmodelReferenceResponse

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

the class RequestHandlerManagerTest method testPostSubmodelReferenceRequest.

@Test
public void testPostSubmodelReferenceRequest() throws ResourceNotFoundException {
    when(persistence.get(environment.getAssetAdministrationShells().get(0).getIdentification(), new QueryModifier())).thenReturn(environment.getAssetAdministrationShells().get(0));
    when(persistence.put(environment.getSubmodels().get(0))).thenReturn(environment.getSubmodels().get(0));
    PostSubmodelReferenceRequest request = new PostSubmodelReferenceRequest.Builder().id(environment.getAssetAdministrationShells().get(0).getIdentification()).submodelRef(SUBMODEL_ELEMENT_REF).build();
    PostSubmodelReferenceResponse response = manager.execute(request);
    PostSubmodelReferenceResponse expected = new PostSubmodelReferenceResponse.Builder().statusCode(StatusCode.SuccessCreated).payload(SUBMODEL_ELEMENT_REF).build();
    Assert.assertEquals(expected, response);
}
Also used : PostSubmodelReferenceRequest(de.fraunhofer.iosb.ilt.faaast.service.model.request.PostSubmodelReferenceRequest) PostSubmodelReferenceResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.PostSubmodelReferenceResponse) QueryModifier(de.fraunhofer.iosb.ilt.faaast.service.model.api.modifier.QueryModifier) Test(org.junit.Test)

Example 2 with PostSubmodelReferenceResponse

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

the class PostSubmodelReferenceRequestHandler method process.

@Override
public PostSubmodelReferenceResponse process(PostSubmodelReferenceRequest request) {
    PostSubmodelReferenceResponse response = new PostSubmodelReferenceResponse();
    try {
        AssetAdministrationShell aas = (AssetAdministrationShell) persistence.get(request.getId(), new QueryModifier());
        if (!aas.getSubmodels().contains(request.getSubmodelRef())) {
            aas.getSubmodels().add(request.getSubmodelRef());
        }
        persistence.put(aas);
        response.setPayload(request.getSubmodelRef());
        response.setStatusCode(StatusCode.SuccessCreated);
        publishElementUpdateEventMessage(AasUtils.toReference(aas), aas);
    } catch (ResourceNotFoundException ex) {
        response.setStatusCode(StatusCode.ClientErrorResourceNotFound);
    } catch (Exception ex) {
        response.setStatusCode(StatusCode.ServerInternalError);
    }
    return response;
}
Also used : AssetAdministrationShell(io.adminshell.aas.v3.model.AssetAdministrationShell) PostSubmodelReferenceResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.PostSubmodelReferenceResponse) 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)

Aggregations

QueryModifier (de.fraunhofer.iosb.ilt.faaast.service.model.api.modifier.QueryModifier)2 PostSubmodelReferenceResponse (de.fraunhofer.iosb.ilt.faaast.service.model.api.response.PostSubmodelReferenceResponse)2 ResourceNotFoundException (de.fraunhofer.iosb.ilt.faaast.service.exception.ResourceNotFoundException)1 PostSubmodelReferenceRequest (de.fraunhofer.iosb.ilt.faaast.service.model.request.PostSubmodelReferenceRequest)1 AssetAdministrationShell (io.adminshell.aas.v3.model.AssetAdministrationShell)1 Test (org.junit.Test)1