Search in sources :

Example 1 with ConstraintType

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;
}
Also used : ResourceUtils.findAttribute(io.lumeer.api.util.ResourceUtils.findAttribute) Attribute(io.lumeer.api.model.Attribute) Constraint(io.lumeer.api.model.Constraint) ConstraintType(io.lumeer.api.model.ConstraintType) List(java.util.List)

Example 2 with ConstraintType

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);
}
Also used : Constraint(io.lumeer.api.model.Constraint) ConstraintType(io.lumeer.api.model.ConstraintType)

Example 3 with ConstraintType

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;
}
Also used : ConstraintType(io.lumeer.api.model.ConstraintType)

Aggregations

ConstraintType (io.lumeer.api.model.ConstraintType)3 Constraint (io.lumeer.api.model.Constraint)2 Attribute (io.lumeer.api.model.Attribute)1 ResourceUtils.findAttribute (io.lumeer.api.util.ResourceUtils.findAttribute)1 List (java.util.List)1