Search in sources :

Example 6 with Constraint

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);
}
Also used : DataDocument(io.lumeer.engine.api.data.DataDocument) Constraint(io.lumeer.api.model.Constraint) Attribute(io.lumeer.api.model.Attribute) CollectionPurpose(io.lumeer.api.model.CollectionPurpose)

Example 7 with Constraint

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);
}
Also used : DataDocument(io.lumeer.engine.api.data.DataDocument) Query(io.lumeer.api.model.Query) Constraint(io.lumeer.api.model.Constraint) Attribute(io.lumeer.api.model.Attribute) DataDocument(io.lumeer.engine.api.data.DataDocument) Document(io.lumeer.api.model.Document) Test(org.junit.Test)

Example 8 with Constraint

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);
}
Also used : DataDocument(io.lumeer.engine.api.data.DataDocument) Query(io.lumeer.api.model.Query) Constraint(io.lumeer.api.model.Constraint) Attribute(io.lumeer.api.model.Attribute) DataDocument(io.lumeer.engine.api.data.DataDocument) Document(io.lumeer.api.model.Document) Test(org.junit.Test)

Example 9 with Constraint

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);
}
Also used : DataDocument(io.lumeer.engine.api.data.DataDocument) Query(io.lumeer.api.model.Query) Constraint(io.lumeer.api.model.Constraint) Attribute(io.lumeer.api.model.Attribute) DataDocument(io.lumeer.engine.api.data.DataDocument) Document(io.lumeer.api.model.Document) Test(org.junit.Test)

Example 10 with Constraint

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);
    }
}
Also used : Constraint(io.lumeer.api.model.Constraint) Collection(io.lumeer.api.model.Collection) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

Constraint (io.lumeer.api.model.Constraint)25 Attribute (io.lumeer.api.model.Attribute)17 Test (org.junit.Test)17 DataDocument (io.lumeer.engine.api.data.DataDocument)15 Document (io.lumeer.api.model.Document)13 Query (io.lumeer.api.model.Query)9 Collection (io.lumeer.api.model.Collection)8 HashMap (java.util.HashMap)5 BigDecimal (java.math.BigDecimal)4 ConstraintType (io.lumeer.api.model.ConstraintType)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 Point (com.mongodb.client.model.geojson.Point)2 Position (com.mongodb.client.model.geojson.Position)2 CollectionPurpose (io.lumeer.api.model.CollectionPurpose)2 LinkType (io.lumeer.api.model.LinkType)2 NumberFormat (java.text.NumberFormat)2 ZonedDateTime (java.time.ZonedDateTime)2 Date (java.util.Date)2 List (java.util.List)2 Map (java.util.Map)2