Search in sources :

Example 1 with StateChangeException

use of com.qcadoo.mes.states.exception.StateChangeException 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)

Aggregations

StateChangeContext (com.qcadoo.mes.states.StateChangeContext)1 AnotherChangeInProgressException (com.qcadoo.mes.states.exception.AnotherChangeInProgressException)1 StateChangeException (com.qcadoo.mes.states.exception.StateChangeException)1 StateTransitionNotAlloweException (com.qcadoo.mes.states.exception.StateTransitionNotAlloweException)1