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);
}
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;
}
Aggregations