use of de.fraunhofer.iosb.ilt.faaast.service.model.api.response.DeleteSubmodelElementByPathResponse in project FAAAST-Service by FraunhoferIOSB.
the class RequestHandlerManagerTest method testDeleteSubmodelElementByPathRequest.
@Test
public void testDeleteSubmodelElementByPathRequest() throws ResourceNotFoundException {
Submodel submodel = environment.getSubmodels().get(0);
Reference reference = ReferenceHelper.toReference(ReferenceHelper.toKeys(SUBMODEL_ELEMENT_REF), submodel.getIdentification(), Submodel.class);
when(persistence.get(reference, new QueryModifier())).thenReturn(environment.getSubmodels().get(0).getSubmodelElements().get(0));
DeleteSubmodelElementByPathRequest request = new DeleteSubmodelElementByPathRequest.Builder().id(submodel.getIdentification()).path(ReferenceHelper.toKeys(SUBMODEL_ELEMENT_REF)).build();
DeleteSubmodelElementByPathResponse response = manager.execute(request);
DeleteSubmodelElementByPathResponse expected = new DeleteSubmodelElementByPathResponse.Builder().statusCode(StatusCode.Success).build();
Assert.assertEquals(expected, response);
verify(persistence).remove(reference);
}
use of de.fraunhofer.iosb.ilt.faaast.service.model.api.response.DeleteSubmodelElementByPathResponse in project FAAAST-Service by FraunhoferIOSB.
the class DeleteSubmodelElementByPathRequestHandler method process.
@Override
public DeleteSubmodelElementByPathResponse process(DeleteSubmodelElementByPathRequest request) {
DeleteSubmodelElementByPathResponse response = new DeleteSubmodelElementByPathResponse();
try {
Reference reference = ReferenceHelper.toReference(request.getPath(), request.getId(), Submodel.class);
SubmodelElement submodelElement = persistence.get(reference, new QueryModifier());
persistence.remove(reference);
response.setStatusCode(StatusCode.Success);
publishElementDeleteEventMessage(reference, submodelElement);
} catch (ResourceNotFoundException ex) {
response.setStatusCode(StatusCode.ClientErrorResourceNotFound);
} catch (Exception ex) {
response.setStatusCode(StatusCode.ServerInternalError);
}
return response;
}
Aggregations