use of de.fraunhofer.iosb.ilt.faaast.service.model.api.response.PostSubmodelReferenceResponse in project FAAAST-Service by FraunhoferIOSB.
the class RequestHandlerManagerTest method testPostSubmodelReferenceRequest.
@Test
public void testPostSubmodelReferenceRequest() throws ResourceNotFoundException {
when(persistence.get(environment.getAssetAdministrationShells().get(0).getIdentification(), new QueryModifier())).thenReturn(environment.getAssetAdministrationShells().get(0));
when(persistence.put(environment.getSubmodels().get(0))).thenReturn(environment.getSubmodels().get(0));
PostSubmodelReferenceRequest request = new PostSubmodelReferenceRequest.Builder().id(environment.getAssetAdministrationShells().get(0).getIdentification()).submodelRef(SUBMODEL_ELEMENT_REF).build();
PostSubmodelReferenceResponse response = manager.execute(request);
PostSubmodelReferenceResponse expected = new PostSubmodelReferenceResponse.Builder().statusCode(StatusCode.SuccessCreated).payload(SUBMODEL_ELEMENT_REF).build();
Assert.assertEquals(expected, response);
}
use of de.fraunhofer.iosb.ilt.faaast.service.model.api.response.PostSubmodelReferenceResponse in project FAAAST-Service by FraunhoferIOSB.
the class PostSubmodelReferenceRequestHandler method process.
@Override
public PostSubmodelReferenceResponse process(PostSubmodelReferenceRequest request) {
PostSubmodelReferenceResponse response = new PostSubmodelReferenceResponse();
try {
AssetAdministrationShell aas = (AssetAdministrationShell) persistence.get(request.getId(), new QueryModifier());
if (!aas.getSubmodels().contains(request.getSubmodelRef())) {
aas.getSubmodels().add(request.getSubmodelRef());
}
persistence.put(aas);
response.setPayload(request.getSubmodelRef());
response.setStatusCode(StatusCode.SuccessCreated);
publishElementUpdateEventMessage(AasUtils.toReference(aas), aas);
} catch (ResourceNotFoundException ex) {
response.setStatusCode(StatusCode.ClientErrorResourceNotFound);
} catch (Exception ex) {
response.setStatusCode(StatusCode.ServerInternalError);
}
return response;
}
Aggregations