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);
}
Aggregations