Search in sources :

Example 1 with EntityNotFoundException

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 + "]");
    }
}
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)

Example 2 with EntityNotFoundException

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;
}
Also used : XmAuthenticationContext(com.icthh.xm.commons.security.XmAuthenticationContext) EntityNotFoundException(com.icthh.xm.commons.exceptions.EntityNotFoundException) Profile(com.icthh.xm.ms.entity.domain.Profile) LogicExtensionPoint(com.icthh.xm.commons.lep.LogicExtensionPoint) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

EntityNotFoundException (com.icthh.xm.commons.exceptions.EntityNotFoundException)2 BusinessException (com.icthh.xm.commons.exceptions.BusinessException)1 LogicExtensionPoint (com.icthh.xm.commons.lep.LogicExtensionPoint)1 XmAuthenticationContext (com.icthh.xm.commons.security.XmAuthenticationContext)1 Profile (com.icthh.xm.ms.entity.domain.Profile)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 Transactional (org.springframework.transaction.annotation.Transactional)1