Search in sources :

Example 1 with OrderResponse

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;
}
Also used : LocaleContextHolder(org.springframework.context.i18n.LocaleContextHolder) PathVariable(org.springframework.web.bind.annotation.PathVariable) DataDefinitionService(com.qcadoo.model.api.DataDefinitionService) DashboardKanbanDataProvider(com.qcadoo.mes.orders.controllers.dataProvider.DashboardKanbanDataProvider) Autowired(org.springframework.beans.factory.annotation.Autowired) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) OrderFields(com.qcadoo.mes.orders.constants.OrderFields) Controller(org.springframework.stereotype.Controller) OrdersConstants(com.qcadoo.mes.orders.constants.OrdersConstants) ErrorMessage(com.qcadoo.model.api.validators.ErrorMessage) Lists(com.google.common.collect.Lists) OrderResponse(com.qcadoo.mes.orders.controllers.responses.OrderResponse) OrderHolder(com.qcadoo.mes.orders.controllers.dto.OrderHolder) MessagesUtil(com.qcadoo.mes.states.messages.util.MessagesUtil) StateChangeContext(com.qcadoo.mes.states.StateChangeContext) OrderState(com.qcadoo.mes.orders.states.constants.OrderState) MediaType(org.springframework.http.MediaType) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) TranslationService(com.qcadoo.localization.api.TranslationService) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) Collectors(java.util.stream.Collectors) DataDefinition(com.qcadoo.model.api.DataDefinition) List(java.util.List) OrderStateChangeAspect(com.qcadoo.mes.orders.states.aop.OrderStateChangeAspect) StateChangeContextBuilder(com.qcadoo.mes.states.service.StateChangeContextBuilder) Entity(com.qcadoo.model.api.Entity) OperationalTaskHolder(com.qcadoo.mes.orders.controllers.dto.OperationalTaskHolder) Entity(com.qcadoo.model.api.Entity) OrderResponse(com.qcadoo.mes.orders.controllers.responses.OrderResponse) StateChangeContext(com.qcadoo.mes.states.StateChangeContext) ErrorMessage(com.qcadoo.model.api.validators.ErrorMessage) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

Lists (com.google.common.collect.Lists)1 TranslationService (com.qcadoo.localization.api.TranslationService)1 OrderFields (com.qcadoo.mes.orders.constants.OrderFields)1 OrdersConstants (com.qcadoo.mes.orders.constants.OrdersConstants)1 DashboardKanbanDataProvider (com.qcadoo.mes.orders.controllers.dataProvider.DashboardKanbanDataProvider)1 OperationalTaskHolder (com.qcadoo.mes.orders.controllers.dto.OperationalTaskHolder)1 OrderHolder (com.qcadoo.mes.orders.controllers.dto.OrderHolder)1 OrderResponse (com.qcadoo.mes.orders.controllers.responses.OrderResponse)1 OrderStateChangeAspect (com.qcadoo.mes.orders.states.aop.OrderStateChangeAspect)1 OrderState (com.qcadoo.mes.orders.states.constants.OrderState)1 StateChangeContext (com.qcadoo.mes.states.StateChangeContext)1 MessagesUtil (com.qcadoo.mes.states.messages.util.MessagesUtil)1 StateChangeContextBuilder (com.qcadoo.mes.states.service.StateChangeContextBuilder)1 DataDefinition (com.qcadoo.model.api.DataDefinition)1 DataDefinitionService (com.qcadoo.model.api.DataDefinitionService)1 Entity (com.qcadoo.model.api.Entity)1 ErrorMessage (com.qcadoo.model.api.validators.ErrorMessage)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1