Search in sources :

Example 6 with BusinessException

use of com.icthh.xm.commons.exceptions.BusinessException in project xm-ms-entity by xm-online.

the class XmEntityUtils method getRequiredLinkedTarget.

public static XmEntity getRequiredLinkedTarget(XmEntity xmEntity, String targetTypeKey) {
    Optional<Link> linkOpt = getLink(xmEntity, targetTypeKey);
    XmEntity target = linkOpt.orElseThrow(() -> new BusinessException("Can't find linkOpt with target type key: " + targetTypeKey)).getTarget();
    return Objects.requireNonNull(target, "Target in link with typeKey: " + targetTypeKey + " is null");
}
Also used : BusinessException(com.icthh.xm.commons.exceptions.BusinessException) XmEntity(com.icthh.xm.ms.entity.domain.XmEntity) Link(com.icthh.xm.ms.entity.domain.Link)

Example 7 with BusinessException

use of com.icthh.xm.commons.exceptions.BusinessException 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 8 with BusinessException

use of com.icthh.xm.commons.exceptions.BusinessException in project xm-ms-entity by xm-online.

the class XmEntityKey method ofMatcher.

public static XmEntityKey ofMatcher(String xmKey, Pattern pattern) {
    Objects.requireNonNull(xmKey, "XM entity key can't be null");
    Matcher xmKeyMatcher = pattern.matcher(xmKey);
    if (!xmKeyMatcher.matches()) {
        // add more appropriate exception ...
        throw new BusinessException("XM entity key '" + xmKey + "' doesn't match pattern: " + pattern.pattern());
    }
    int count = xmKeyMatcher.groupCount();
    String[] groups = new String[count];
    for (int i = 0; i < count; i++) {
        groups[i] = xmKeyMatcher.group(i + 1);
    }
    return new XmEntityKey(xmKey, groups);
}
Also used : BusinessException(com.icthh.xm.commons.exceptions.BusinessException) Matcher(java.util.regex.Matcher)

Aggregations

BusinessException (com.icthh.xm.commons.exceptions.BusinessException)8 Link (com.icthh.xm.ms.entity.domain.Link)3 XmEntity (com.icthh.xm.ms.entity.domain.XmEntity)3 EntityNotFoundException (com.icthh.xm.commons.exceptions.EntityNotFoundException)2 Location (com.icthh.xm.ms.entity.domain.Location)2 StateSpec (com.icthh.xm.ms.entity.domain.spec.StateSpec)2 XmEntityStateProjection (com.icthh.xm.ms.entity.projection.XmEntityStateProjection)2 LifecycleLepStrategy (com.icthh.xm.ms.entity.service.LifecycleLepStrategy)2 URI (java.net.URI)2 Timed (com.codahale.metrics.annotation.Timed)1 ErrorConstants (com.icthh.xm.commons.exceptions.ErrorConstants)1 LogicExtensionPoint (com.icthh.xm.commons.lep.LogicExtensionPoint)1 LepService (com.icthh.xm.commons.lep.spring.LepService)1 FindWithPermission (com.icthh.xm.commons.permission.annotation.FindWithPermission)1 XmAuthenticationContextHolder (com.icthh.xm.commons.security.XmAuthenticationContextHolder)1 Constants (com.icthh.xm.ms.entity.config.Constants)1 Attachment (com.icthh.xm.ms.entity.domain.Attachment)1 Calendar (com.icthh.xm.ms.entity.domain.Calendar)1 Comment (com.icthh.xm.ms.entity.domain.Comment)1 FileFormatEnum (com.icthh.xm.ms.entity.domain.FileFormatEnum)1