use of com.icthh.xm.commons.exceptions.EntityNotFoundException 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 + "]");
}
}
use of com.icthh.xm.commons.exceptions.EntityNotFoundException in project xm-ms-entity by xm-online.
the class ProfileService method getSelfProfile.
@LogicExtensionPoint("GetSelfProfile")
@Transactional(readOnly = true)
public Profile getSelfProfile() {
XmAuthenticationContext context = authContextHolder.getContext();
if (!context.isFullyAuthenticated()) {
throw new EntityNotFoundException("Can't get profile for not fully authenticated user");
}
String userKey = context.getRequiredUserKey();
log.debug("Get profile for user key {}", userKey);
Profile profile = getProfile(userKey);
if (profile == null) {
throw new IllegalArgumentException("Profile not found for user key " + userKey);
}
return profile;
}
Aggregations