use of io.lumeer.api.model.ConstraintType in project engine by Lumeer.
the class CollectionPurposeUtils method isDoneState.
public static boolean isDoneState(final DataDocument data, final Collection collection) {
final String stateAttributeId = collection.getPurpose().getStateAttributeId();
final List<Object> finalStates = collection.getPurpose().getFinalStatesList();
if (finalStates != null && data != null) {
Attribute stateAttribute = findAttribute(collection.getAttributes(), stateAttributeId);
if (stateAttribute != null) {
final Object states = data.getObject(stateAttributeId);
ConstraintType constraintType = Utils.computeIfNotNull(stateAttribute.getConstraint(), Constraint::getType);
if (constraintType == ConstraintType.Boolean) {
var finalState = finalStates.isEmpty() ? null : finalStates.get(0);
return toBoolean(finalState) == toBoolean(states);
} else if (states instanceof List) {
final List<Object> stringStates = data.getArrayList(stateAttributeId);
return stringStates.stream().anyMatch(finalStates::contains);
} else {
return finalStates.contains(states);
}
}
}
return false;
}
use of io.lumeer.api.model.ConstraintType in project engine by Lumeer.
the class ConstraintCodec method convertFromDocument.
public static Constraint convertFromDocument(final Document document) {
if (document == null) {
return null;
}
ConstraintType type = ConstraintType.valueOf(document.getString(TYPE));
Object config = document.get(CONFIG);
return new Constraint(type, config);
}
use of io.lumeer.api.model.ConstraintType in project engine by Lumeer.
the class ConstraintConverterFactory method getConstraintConverter.
public ConstraintConverter getConstraintConverter(final Attribute fromAttribute, final Attribute toAttribute) {
final ConstraintType fromType = fromAttribute != null && fromAttribute.getConstraint() != null ? fromAttribute.getConstraint().getType() : ConstraintType.None;
final ConstraintType toType = toAttribute != null && toAttribute.getConstraint() != null ? toAttribute.getConstraint().getType() : ConstraintType.None;
final ConstraintConverter converter = converters.stream().filter(c -> c.getFromTypes().contains(fromType) && c.getToTypes().contains(toType)).findFirst().orElse(null);
if (converter != null) {
converter.init(constraintManager, userLocale, fromAttribute, toAttribute);
}
return converter;
}
Aggregations