use of com.icthh.xm.ms.entity.projection.XmEntityStateProjection 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 + "]");
}
}
Aggregations