@Transactional
public static Result updateOrderState(int id) {
try {
String requestBody = request().body().asJson().toString();
Order order = DaoManager.getOrderDao().findById(id);
if (order == null) {
return notFound(Utilities.getJsonErrorNode("can't find order with id " + id));
}
Logger.debug("Update order state request body: " + requestBody);
OrderStateChangeDto dto = new ObjectMapper().readValue(requestBody, OrderStateChangeDto.class);
OrderStateChange stateChange = new OrderStateChange();
dto.mapBack(stateChange);
stateChange.setPerformedOn(Calendar.getInstance().getTime());
stateChange.setChanger(SecurityController.getUser());
stateChange.setAlteredOrder(order);
order.setState(stateChange.getNewState());
DaoManager.getOrderStateChangeDao().persist(stateChange);
} catch (DataAccessException e) {
Logger.error("failed to update order state", e);
return badRequest(Utilities.getJsonErrorNode("failed to update order state"));
} catch (IOException e) {