use of de.fraunhofer.iosb.ilt.faaast.service.model.api.response.PostSubmodelElementResponse in project FAAAST-Service by FraunhoferIOSB.
the class RequestHandlerManagerTest method testPostSubmodelElementRequest.
@Test
public void testPostSubmodelElementRequest() throws ResourceNotFoundException {
Reference reference = ReferenceHelper.toReference(environment.getSubmodels().get(0).getIdentification(), Submodel.class);
when(persistence.put(reference, (Reference) null, environment.getSubmodels().get(0).getSubmodelElements().get(0))).thenReturn(environment.getSubmodels().get(0).getSubmodelElements().get(0));
PostSubmodelElementRequest request = new PostSubmodelElementRequest.Builder().id(environment.getSubmodels().get(0).getIdentification()).submodelElement(environment.getSubmodels().get(0).getSubmodelElements().get(0)).build();
PostSubmodelElementResponse response = manager.execute(request);
PostSubmodelElementResponse expected = new PostSubmodelElementResponse.Builder().statusCode(StatusCode.SuccessCreated).payload(environment.getSubmodels().get(0).getSubmodelElements().get(0)).build();
Assert.assertEquals(expected, response);
}
use of de.fraunhofer.iosb.ilt.faaast.service.model.api.response.PostSubmodelElementResponse in project FAAAST-Service by FraunhoferIOSB.
the class PostSubmodelElementRequestHandler method process.
@Override
public PostSubmodelElementResponse process(PostSubmodelElementRequest request) {
PostSubmodelElementResponse response = new PostSubmodelElementResponse();
try {
Reference parentReference = ReferenceHelper.toReference(request.getId(), Submodel.class);
Reference childReference = AasUtils.toReference(parentReference, request.getSubmodelElement());
SubmodelElement submodelElement = persistence.put(parentReference, null, request.getSubmodelElement());
response.setPayload(submodelElement);
response.setStatusCode(StatusCode.SuccessCreated);
writeValueToAssetConnection(childReference, ElementValueMapper.toValue(submodelElement));
publishElementCreateEventMessage(parentReference, submodelElement);
} catch (ResourceNotFoundException ex) {
response.setStatusCode(StatusCode.ClientErrorResourceNotFound);
} catch (Exception ex) {
response.setStatusCode(StatusCode.ServerInternalError);
}
return response;
}
Aggregations