Search in sources :

Example 16 with StateChangeContext

use of com.qcadoo.mes.states.StateChangeContext in project mes by qcadoo.

the class StateChangeContextBuilderTest method shouldBuildStateChangeContextBasedOnStateChangeEntity.

@Test
public final void shouldBuildStateChangeContextBasedOnStateChangeEntity() {
    // given
    stubSearchCriteria(Lists.<Entity>newArrayList());
    // when
    final StateChangeContext stateChangeContext = stateChangeContextBuilder.build(describer, stateChangeEntity);
    // then
    assertNotNull(stateChangeContext);
    assertEquals(stateChangeEntity, stateChangeContext.getStateChangeEntity());
    assertEquals(owner, stateChangeContext.getOwner());
}
Also used : StateChangeContext(com.qcadoo.mes.states.StateChangeContext) StateChangeTest(com.qcadoo.mes.states.StateChangeTest) Test(org.junit.Test)

Example 17 with StateChangeContext

use of com.qcadoo.mes.states.StateChangeContext in project mes by qcadoo.

the class AbstractStateChangeViewClient method changeState.

@Override
public final void changeState(final ViewContextHolder viewContext, final String targetState, final Entity entity) {
    try {
        LOG.info(String.format("Change state. Entity name : %S id : %d. Target state : %S", entity.getDataDefinition().getName(), entity.getId(), targetState));
        StateChangeContext stateChangeContext = stateChangeContextBuilder.build(getStateChangeService().getChangeEntityDescriber(), entity, targetState);
        getStateChangeService().changeState(stateChangeContext);
        viewClientUtil.refreshComponent(viewContext);
        showMessages(viewContext, stateChangeContext);
        stateChangeContext = null;
    } catch (AnotherChangeInProgressException e) {
        viewContext.getMessagesConsumer().addMessage("states.messages.change.failure.anotherChangeInProgress", MessageType.FAILURE);
        LOG.info(String.format("Another state change in progress. Entity name : %S id : %d. Target state : %S", entity.getDataDefinition().getName(), entity.getId(), targetState));
    } catch (StateTransitionNotAlloweException e) {
        viewContext.getMessagesConsumer().addMessage("states.messages.change.failure.transitionNotAllowed", MessageType.FAILURE);
        LOG.info(String.format("State change - transition not allowed. Entity name : %S id : %d. Target state : %S", entity.getDataDefinition().getName(), entity.getId(), targetState));
    } catch (Exception e) {
        throw new StateChangeException(e);
    }
}
Also used : AnotherChangeInProgressException(com.qcadoo.mes.states.exception.AnotherChangeInProgressException) StateTransitionNotAlloweException(com.qcadoo.mes.states.exception.StateTransitionNotAlloweException) StateChangeException(com.qcadoo.mes.states.exception.StateChangeException) StateChangeContext(com.qcadoo.mes.states.StateChangeContext) AnotherChangeInProgressException(com.qcadoo.mes.states.exception.AnotherChangeInProgressException) StateTransitionNotAlloweException(com.qcadoo.mes.states.exception.StateTransitionNotAlloweException) StateChangeException(com.qcadoo.mes.states.exception.StateChangeException)

Example 18 with StateChangeContext

use of com.qcadoo.mes.states.StateChangeContext in project mes by qcadoo.

the class StateChangeSamplesClientImpl method resumeStateChange.

@Override
public void resumeStateChange(final Entity entity, final Entity stateChangeEntity) {
    entity.getDataDefinition().save(entity);
    final StateChangeService stateChangeService = stateChangeServiceResolver.get(entity.getDataDefinition());
    if (stateChangeService != null) {
        final StateChangeEntityDescriber describer = stateChangeService.getChangeEntityDescriber();
        final StateChangeContext stateChangeContext = stateChangeContextBuilder.build(describer, stateChangeEntity);
        stateChangeContext.setStatus(StateChangeStatus.IN_PROGRESS);
        stateChangeService.changeState(stateChangeContext);
        checkResults(stateChangeContext);
    }
}
Also used : StateChangeEntityDescriber(com.qcadoo.mes.states.StateChangeEntityDescriber) StateChangeService(com.qcadoo.mes.states.service.StateChangeService) StateChangeContext(com.qcadoo.mes.states.StateChangeContext)

Example 19 with StateChangeContext

use of com.qcadoo.mes.states.StateChangeContext in project mes by qcadoo.

the class MaintenanceEventToPlannedEventListeners method cancelStateChange.

public void cancelStateChange(final ViewDefinitionState view, final ComponentState form, final String[] args) {
    final Entity stateChangeEntity = ((FormComponent) form).getEntity();
    final StateChangeContext stateContext = stateChangeContextBuilder.build(maintenanceEventStateChangeAspect.getChangeEntityDescriber(), stateChangeEntity);
    stateContext.setStatus(StateChangeStatus.CANCELED);
    stateContext.save();
    maintenanceEventStateChangeViewClient.showMessages(new ViewContextHolder(view, form), stateContext);
}
Also used : Entity(com.qcadoo.model.api.Entity) FormComponent(com.qcadoo.view.api.components.FormComponent) ViewContextHolder(com.qcadoo.mes.states.service.client.util.ViewContextHolder) StateChangeContext(com.qcadoo.mes.states.StateChangeContext)

Example 20 with StateChangeContext

use of com.qcadoo.mes.states.StateChangeContext 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

StateChangeContext (com.qcadoo.mes.states.StateChangeContext)25 Entity (com.qcadoo.model.api.Entity)20 FormComponent (com.qcadoo.view.api.components.FormComponent)10 ViewContextHolder (com.qcadoo.mes.states.service.client.util.ViewContextHolder)8 Lists (com.google.common.collect.Lists)7 List (java.util.List)7 Autowired (org.springframework.beans.factory.annotation.Autowired)7 Service (org.springframework.stereotype.Service)6 TranslationService (com.qcadoo.localization.api.TranslationService)5 DataDefinition (com.qcadoo.model.api.DataDefinition)5 DataDefinitionService (com.qcadoo.model.api.DataDefinitionService)5 Collectors (java.util.stream.Collectors)5 Sets (com.google.common.collect.Sets)4 ProductFields (com.qcadoo.mes.basic.constants.ProductFields)4 ErrorMessage (com.qcadoo.model.api.validators.ErrorMessage)4 ProductFamilyElementType (com.qcadoo.mes.basic.constants.ProductFamilyElementType)3 OrderFields (com.qcadoo.mes.orders.constants.OrderFields)3 OrdersConstants (com.qcadoo.mes.orders.constants.OrdersConstants)3 StateMessageType (com.qcadoo.mes.states.messages.constants.StateMessageType)3 BigDecimal (java.math.BigDecimal)3