use of com.qcadoo.mes.orders.controllers.responses.OrderResponse in project mes by qcadoo.
the class DashboardKanbanController method updateOrderState.
@ResponseBody
@RequestMapping(value = "/updateOrderState/{orderId}", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE)
public OrderResponse updateOrderState(@PathVariable final Long orderId) {
Entity order = getOrderDD().get(orderId);
String targetState = OrderState.IN_PROGRESS.getStringValue();
if (OrderState.IN_PROGRESS.getStringValue().equals(order.getStringField(OrderFields.STATE))) {
targetState = OrderState.COMPLETED.getStringValue();
}
StateChangeContext orderStateChangeContext = stateChangeContextBuilder.build(orderStateChangeAspect.getChangeEntityDescriber(), order, targetState);
orderStateChangeAspect.changeState(orderStateChangeContext);
OrderResponse orderResponse = new OrderResponse(dashboardKanbanDataProvider.getOrder(orderId));
List<ErrorMessage> errors = Lists.newArrayList();
if (!orderStateChangeContext.getAllMessages().isEmpty()) {
for (Entity entity : orderStateChangeContext.getAllMessages()) {
errors.add(new ErrorMessage(MessagesUtil.getKey(entity), MessagesUtil.getArgs(entity)));
}
}
if (!errors.isEmpty()) {
String errorMessages = errors.stream().map(errorMessage -> translationService.translate(errorMessage.getMessage(), LocaleContextHolder.getLocale(), errorMessage.getVars())).collect(Collectors.joining(", "));
orderResponse.setMessage(translationService.translate("orders.order.orderStates.error", LocaleContextHolder.getLocale(), errorMessages));
}
return orderResponse;
}
Aggregations