use of de.fraunhofer.iosb.ilt.faaast.service.model.api.response.PutSubmodelByIdResponse in project FAAAST-Service by FraunhoferIOSB.
the class RequestHandlerManagerTest method testPutSubmodelByIdRequest.
@Test
public void testPutSubmodelByIdRequest() throws ResourceNotFoundException {
when(persistence.put(environment.getSubmodels().get(0))).thenReturn(environment.getSubmodels().get(0));
PutSubmodelByIdRequest request = new PutSubmodelByIdRequest.Builder().id(environment.getSubmodels().get(0).getIdentification()).submodel(environment.getSubmodels().get(0)).build();
PutSubmodelByIdResponse response = manager.execute(request);
PutSubmodelByIdResponse expected = new PutSubmodelByIdResponse.Builder().payload(environment.getSubmodels().get(0)).statusCode(StatusCode.Success).build();
Assert.assertEquals(expected, response);
}
use of de.fraunhofer.iosb.ilt.faaast.service.model.api.response.PutSubmodelByIdResponse in project FAAAST-Service by FraunhoferIOSB.
the class PutSubmodelByIdRequestHandler method process.
@Override
public PutSubmodelByIdResponse process(PutSubmodelByIdRequest request) {
PutSubmodelByIdResponse response = new PutSubmodelByIdResponse();
try {
// check if resource does exist
Submodel submodel = (Submodel) persistence.get(request.getSubmodel().getIdentification(), new QueryModifier.Builder().extend(Extend.WithoutBLOBValue).level(Level.Core).build());
submodel = (Submodel) persistence.put(request.getSubmodel());
response.setPayload(submodel);
response.setStatusCode(StatusCode.Success);
Reference reference = AasUtils.toReference(submodel);
readValueFromAssetConnectionAndUpdatePersistence(reference, submodel.getSubmodelElements());
publishElementUpdateEventMessage(reference, submodel);
} catch (ResourceNotFoundException ex) {
response.setStatusCode(StatusCode.ClientErrorResourceNotFound);
} catch (Exception ex) {
response.setStatusCode(StatusCode.ServerInternalError);
}
return response;
}
Aggregations