use of io.lumeer.api.model.Constraint in project engine by Lumeer.
the class SearchFacadeIT method createTaskCollectionWithAttributes.
private Collection createTaskCollectionWithAttributes(String name) {
var options = Arrays.asList(new DataDocument("option", "a"), new DataDocument("option", "b"), new DataDocument("option", "c"), new DataDocument("option", "d"));
Constraint stateConstraint = new Constraint(ConstraintType.Select, new DataDocument("multi", true).append("options", options));
Attribute stateAttribute = new Attribute("a1", "a1", null, stateConstraint, null, null, 1, null);
var stateAttributeId = stateAttribute.getId();
Constraint assigneeConstraint = new Constraint(ConstraintType.User, new DataDocument());
Attribute assigneeAttribute = new Attribute("a2", "a2", null, assigneeConstraint, null, null, 1, null);
var assigneeAttributeId = assigneeAttribute.getId();
var purposeMetadata = new DataDocument(CollectionPurpose.META_STATE_ATTRIBUTE_ID, stateAttributeId).append(CollectionPurpose.META_ASSIGNEE_ATTRIBUTE_ID, assigneeAttributeId).append(CollectionPurpose.META_FINAL_STATES_LIST, Arrays.asList("c", "d"));
CollectionPurpose purpose = new CollectionPurpose(CollectionPurposeType.Tasks, purposeMetadata);
Constraint numberConstraint = new Constraint(ConstraintType.Number, new DataDocument());
Attribute otherAttribute = new Attribute("a3", "a3", null, numberConstraint, null, null, 3, null);
return createTaskCollection(name, purpose, stateAttribute, assigneeAttribute, otherAttribute);
}
use of io.lumeer.api.model.Constraint in project engine by Lumeer.
the class SearchFacadeIT method testUserConstraint.
@Test
public void testUserConstraint() {
Constraint constraint = new Constraint(ConstraintType.User, new DataDocument("multi", true));
Attribute attribute = new Attribute(DOCUMENT_KEY, DOCUMENT_KEY, null, constraint, null, null, 3, null);
String collectionId = createCollection("userCollection", attribute).getId();
String id1 = createDocument(collectionId, Collections.singletonList(USER)).getId();
String id2 = createDocument(collectionId, Arrays.asList(USER1, USER2)).getId();
String id3 = createDocument(collectionId, Arrays.asList(USER, USER1)).getId();
String id4 = createDocument(collectionId, Collections.singletonList(USER1)).getId();
Query query = createSimpleQueryWithAttributeFilter(collectionId, CollectionAttributeFilter.createFromTypes(collectionId, DOCUMENT_KEY, ConditionType.HAS_SOME, ConditionValueType.CURRENT_USER.getValue()));
List<Document> documents = searchFacade.searchDocuments(query, true);
assertThat(documents).extracting(Document::getId).containsOnly(id1, id3);
query = createSimpleQueryWithAttributeFilter(collectionId, CollectionAttributeFilter.createFromValues(collectionId, DOCUMENT_KEY, ConditionType.HAS_NONE_OF, USER2));
documents = searchFacade.searchDocuments(query, true);
assertThat(documents).extracting(Document::getId).containsOnly(id1, id3, id4);
}
use of io.lumeer.api.model.Constraint in project engine by Lumeer.
the class SearchFacadeIT method testDurationConstraint.
@Test
public void testDurationConstraint() {
Constraint constraint = new Constraint(ConstraintType.Duration, new DataDocument("type", "Work"));
Attribute attribute = new Attribute(DOCUMENT_KEY, DOCUMENT_KEY, null, constraint, null, null, 3, null);
String collectionId = createCollection("durationCollection", attribute).getId();
String id1 = createDocument(collectionId, "5w3d").getId();
String id2 = createDocument(collectionId, "3d4h").getId();
String id3 = createDocument(collectionId, "2d12h").getId();
String id4 = createDocument(collectionId, "3d2h5s").getId();
String id5 = createDocument(collectionId, "ddhmms").getId();
Query query = createSimpleQueryWithAttributeFilter(collectionId, CollectionAttributeFilter.createFromValues(collectionId, DOCUMENT_KEY, ConditionType.EQUALS, "28h"));
List<Document> documents = searchFacade.searchDocuments(query, true);
assertThat(documents).extracting(Document::getId).containsOnly(id2, id3);
query = createSimpleQueryWithAttributeFilter(collectionId, CollectionAttributeFilter.createFromValues(collectionId, DOCUMENT_KEY, ConditionType.NOT_EQUALS, "dh19h"));
documents = searchFacade.searchDocuments(query, true);
assertThat(documents).extracting(Document::getId).containsOnly(id1, id4, id5);
query = createSimpleQueryWithAttributeFilter(collectionId, CollectionAttributeFilter.createFromValues(collectionId, DOCUMENT_KEY, ConditionType.EQUALS, "5tddd"));
searchFacade.setLanguage(Language.CS);
documents = searchFacade.searchDocuments(query, true);
assertThat(documents).extracting(Document::getId).containsOnly(id1);
}
use of io.lumeer.api.model.Constraint in project engine by Lumeer.
the class SearchFacadeIT method testSearchFulltextDocumentsByNumberConstraint.
@Test
public void testSearchFulltextDocumentsByNumberConstraint() {
Constraint constraint = new Constraint(ConstraintType.Number, new DataDocument("currency", "sk-SK"));
Attribute attribute = new Attribute(DOCUMENT_KEY, DOCUMENT_KEY, null, constraint, null, null, 3, null);
String collectionId = createCollection("numberCollection2", attribute).getId();
String id1 = createDocument(collectionId, "20.3").getId();
String id2 = createDocument(collectionId, "40.1").getId();
String id3 = createDocument(collectionId, "60").getId();
Query query = createSimpleQueryWithFulltext("20");
List<Document> documents = searchFacade.searchDocuments(query, true);
assertThat(documents).extracting(Document::getId).containsOnly(id1);
query = createSimpleQueryWithFulltext("€");
documents = searchFacade.searchDocuments(query, true);
assertThat(documents).extracting(Document::getId).containsOnly(id1, id2, id3);
query = createSimpleQueryWithFulltext("60 €");
documents = searchFacade.searchDocuments(query, true);
assertThat(documents).extracting(Document::getId).containsOnly(id3);
}
use of io.lumeer.api.model.Constraint in project engine by Lumeer.
the class DocumentFacade method runRule.
@SuppressWarnings("unchecked")
public void runRule(final String collectionId, String documentId, String attributeId, final String actionName) {
Collection collection = collectionDao.getCollectionById(collectionId);
Constraint constraint = ResourceUtils.findConstraint(collection.getAttributes(), attributeId);
if (constraint != null) {
var config = (Map<String, Object>) constraint.getConfig();
var rule = config.get("rule").toString();
if (!collection.getRules().containsKey(rule)) {
throw new IllegalStateException("Rule not found");
}
var document = checkReadDocument(collection, documentId);
taskProcessingFacade.runRule(collection, rule, document, actionName);
}
}
Aggregations