Search in sources :

Example 1 with StateChangeContextImpl

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

the class StateChangeContextBuilderImpl method build.

@Override
@Transactional
public StateChangeContext build(final StateChangeEntityDescriber describer, final Entity owner, final String targetStateString) {
    final Entity persistedOwner = owner.getDataDefinition().save(owner);
    final DataDefinition stateChangeDataDefinition = describer.getDataDefinition();
    final StateEnum sourceState = describer.parseStateEnum(owner.getStringField(describer.getOwnerStateFieldName()));
    final StateEnum targetState = describer.parseStateEnum(targetStateString);
    if (sourceState != null && !sourceState.canChangeTo(targetState)) {
        throw new StateTransitionNotAlloweException(sourceState, targetState);
    }
    final Entity stateChangeEntity = stateChangeEntityBuilder.build(describer, persistedOwner, targetState);
    checkForUnfinishedStateChange(describer, persistedOwner);
    return new StateChangeContextImpl(stateChangeDataDefinition.save(stateChangeEntity), describer, messageService);
}
Also used : Entity(com.qcadoo.model.api.Entity) StateEnum(com.qcadoo.mes.states.StateEnum) StateTransitionNotAlloweException(com.qcadoo.mes.states.exception.StateTransitionNotAlloweException) StateChangeContextImpl(com.qcadoo.mes.states.StateChangeContextImpl) DataDefinition(com.qcadoo.model.api.DataDefinition) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

StateChangeContextImpl (com.qcadoo.mes.states.StateChangeContextImpl)1 StateEnum (com.qcadoo.mes.states.StateEnum)1 StateTransitionNotAlloweException (com.qcadoo.mes.states.exception.StateTransitionNotAlloweException)1 DataDefinition (com.qcadoo.model.api.DataDefinition)1 Entity (com.qcadoo.model.api.Entity)1 Transactional (org.springframework.transaction.annotation.Transactional)1