Search in sources :

Example 1 with GetAllSubmodelElementsResponse

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

the class RequestHandlerManagerTest method testGetAllSubmodelElementsRequest.

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

Example 2 with GetAllSubmodelElementsResponse

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

the class GetAllSubmodelElementsRequestHandler method process.

@Override
public GetAllSubmodelElementsResponse process(GetAllSubmodelElementsRequest request) {
    GetAllSubmodelElementsResponse response = new GetAllSubmodelElementsResponse();
    try {
        Reference reference = ReferenceHelper.toReference(request.getId(), Submodel.class);
        List<SubmodelElement> submodelElements = persistence.getSubmodelElements(reference, null, request.getOutputModifier());
        readValueFromAssetConnectionAndUpdatePersistence(reference, submodelElements);
        response.setPayload(submodelElements);
        response.setStatusCode(StatusCode.Success);
        if (submodelElements != null) {
            submodelElements.forEach(x -> publishElementReadEventMessage(AasUtils.toReference(reference, x), x));
        }
    } 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) Reference(io.adminshell.aas.v3.model.Reference) ResourceNotFoundException(de.fraunhofer.iosb.ilt.faaast.service.exception.ResourceNotFoundException) GetAllSubmodelElementsResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.GetAllSubmodelElementsResponse) ResourceNotFoundException(de.fraunhofer.iosb.ilt.faaast.service.exception.ResourceNotFoundException)

Aggregations

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