Search in sources :

Example 1 with LifecycleLepStrategy

use of com.icthh.xm.ms.entity.service.LifecycleLepStrategy in project xm-ms-entity by xm-online.

the class XmEntityServiceImpl method updateState.

@Override
public XmEntity updateState(IdOrKey idOrKey, String stateKey, Map<String, Object> context) {
    XmEntityStateProjection entity = findStateProjectionById(idOrKey).orElseThrow(() -> new EntityNotFoundException("XmEntity with key [" + idOrKey.getKey() + "] not found"));
    List<StateSpec> stateSpecs = xmEntitySpecService.nextStates(entity.getTypeKey(), entity.getStateKey());
    if (stateSpecs.stream().map(StateSpec::getKey).anyMatch(stateKey::equals)) {
        LifecycleLepStrategy lifecycleLepStrategy = lifecycleLepStrategyFactory.getLifecycleLepStrategy();
        return lifecycleLepStrategy.changeState(idOrKey, entity.getTypeKey(), entity.getStateKey(), stateKey, context);
    } else {
        throw new BusinessException(ErrorConstants.ERR_VALIDATION, "Entity " + entity + " can not go from [" + entity.getStateKey() + "] to [" + stateKey + "]");
    }
}
Also used : StateSpec(com.icthh.xm.ms.entity.domain.spec.StateSpec) BusinessException(com.icthh.xm.commons.exceptions.BusinessException) XmEntityStateProjection(com.icthh.xm.ms.entity.projection.XmEntityStateProjection) EntityNotFoundException(com.icthh.xm.commons.exceptions.EntityNotFoundException) LifecycleLepStrategy(com.icthh.xm.ms.entity.service.LifecycleLepStrategy)

Aggregations

BusinessException (com.icthh.xm.commons.exceptions.BusinessException)1 EntityNotFoundException (com.icthh.xm.commons.exceptions.EntityNotFoundException)1 StateSpec (com.icthh.xm.ms.entity.domain.spec.StateSpec)1 XmEntityStateProjection (com.icthh.xm.ms.entity.projection.XmEntityStateProjection)1 LifecycleLepStrategy (com.icthh.xm.ms.entity.service.LifecycleLepStrategy)1