Search in sources :

Example 1 with DeleteSubmodelElementByPathResponse

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);
}
Also used : Submodel(io.adminshell.aas.v3.model.Submodel) Reference(io.adminshell.aas.v3.model.Reference) DefaultReference(io.adminshell.aas.v3.model.impl.DefaultReference) AtomicReference(java.util.concurrent.atomic.AtomicReference) QueryModifier(de.fraunhofer.iosb.ilt.faaast.service.model.api.modifier.QueryModifier) DeleteSubmodelElementByPathResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.DeleteSubmodelElementByPathResponse) DeleteSubmodelElementByPathRequest(de.fraunhofer.iosb.ilt.faaast.service.model.request.DeleteSubmodelElementByPathRequest) Test(org.junit.Test)

Example 2 with DeleteSubmodelElementByPathResponse

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;
}
Also used : SubmodelElement(io.adminshell.aas.v3.model.SubmodelElement) Reference(io.adminshell.aas.v3.model.Reference) DeleteSubmodelElementByPathResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.DeleteSubmodelElementByPathResponse) 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 DeleteSubmodelElementByPathResponse (de.fraunhofer.iosb.ilt.faaast.service.model.api.response.DeleteSubmodelElementByPathResponse)2 Reference (io.adminshell.aas.v3.model.Reference)2 ResourceNotFoundException (de.fraunhofer.iosb.ilt.faaast.service.exception.ResourceNotFoundException)1 DeleteSubmodelElementByPathRequest (de.fraunhofer.iosb.ilt.faaast.service.model.request.DeleteSubmodelElementByPathRequest)1 Submodel (io.adminshell.aas.v3.model.Submodel)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