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