use of io.lumeer.api.model.Constraint in project engine by Lumeer.
the class LinkInstanceFacade method runRule.
@SuppressWarnings("unchecked")
public void runRule(final String linkTypeId, String linkInstanceId, String attributeId, final String actionName) {
LinkType linkType = linkTypeDao.getLinkType(linkTypeId);
Constraint constraint = ResourceUtils.findConstraint(linkType.getAttributes(), attributeId);
if (constraint != null) {
var config = (Map<String, Object>) constraint.getConfig();
var rule = config.get("rule").toString();
if (!linkType.getRules().containsKey(rule)) {
throw new IllegalStateException("Rule not found");
}
var linkInstance = checkReadLink(linkType, linkInstanceId);
taskProcessingFacade.runRule(linkType, rule, linkInstance, actionName);
}
}
use of io.lumeer.api.model.Constraint 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.Constraint in project engine by Lumeer.
the class AttributeCodec method convertFromDocument.
public static Attribute convertFromDocument(final Document document) {
String id = document.getString(ID);
String name = document.getString(NAME);
String description = document.getString(DESCRIPTION);
Constraint constraint = ConstraintCodec.convertFromDocument(document.get(CONSTRAINT, Document.class));
AttributeLock lock = AttributeLockCodec.convertFromDocument(document.get(LOCK, Document.class));
Function function = FunctionCodec.convertFromDocument(document.get(FUNCTION, Document.class));
Integer usageCount = document.getInteger(USAGE_COUNT);
Boolean suggestValues = document.getBoolean(SUGGEST_VALUES);
return new Attribute(id, name, description, constraint, lock, function, usageCount, suggestValues);
}
use of io.lumeer.api.model.Constraint in project engine by Lumeer.
the class ConstraintManagerTest method testCoordinatesConstraint.
@Test
public void testCoordinatesConstraint() {
final Constraint coordinatesConstraint = new Constraint(ConstraintType.Coordinates, null);
final ConstraintManager cm = new ConstraintManager();
cm.setLocale(l);
Object encoded = cm.encode("40.123, -74.123", coordinatesConstraint);
assertThat(encoded).isEqualTo(new Point(NamedCoordinateReferenceSystem.EPSG_4326, new Position(40.123, -74.123)));
encoded = cm.encode("40.123°N 74.123°W", coordinatesConstraint);
assertThat(encoded).isEqualTo(new Point(NamedCoordinateReferenceSystem.EPSG_4326, new Position(40.123, -74.123)));
encoded = cm.encode("40°7´22.8\"N 74°7´22.8\"W", coordinatesConstraint);
assertThat(encoded).isEqualTo(new Point(NamedCoordinateReferenceSystem.EPSG_4326, new Position(40.123, -74.123)));
encoded = cm.encode("40°7.38'N, 74°7.38'W", coordinatesConstraint);
assertThat(encoded).isEqualTo(new Point(NamedCoordinateReferenceSystem.EPSG_4326, new Position(40.123, -74.123)));
encoded = cm.encode("N40°7’22.8, W74°7’22.8\"", coordinatesConstraint);
assertThat(encoded).isEqualTo(new Point(NamedCoordinateReferenceSystem.EPSG_4326, new Position(40.123, -74.123)));
encoded = cm.encode("40 7 22.8, W74 7 22.8", coordinatesConstraint);
assertThat(encoded).isEqualTo(new Point(NamedCoordinateReferenceSystem.EPSG_4326, new Position(40.123, -74.123)));
encoded = cm.encode("40.123N 74.123W", coordinatesConstraint);
assertThat(encoded).isEqualTo(new Point(NamedCoordinateReferenceSystem.EPSG_4326, new Position(40.123, -74.123)));
}
use of io.lumeer.api.model.Constraint in project engine by Lumeer.
the class ConstraintManagerTest method testBooleanConstraint.
@Test
public void testBooleanConstraint() {
final Constraint booleanConstraint = new Constraint(ConstraintType.Boolean, null);
final ConstraintManager cm = new ConstraintManager();
cm.setLocale(l);
Object encoded = cm.encode("true", booleanConstraint);
assertThat(encoded).isEqualTo(Boolean.TRUE);
encoded = cm.encode("yes", booleanConstraint);
assertThat(encoded).isEqualTo("yes");
encoded = cm.encode(" fAlse ", booleanConstraint);
assertThat(encoded).isEqualTo(Boolean.FALSE);
}
Aggregations