Search in sources :

Example 11 with FunctionTask

use of io.lumeer.core.task.FunctionTask in project engine by Lumeer.

the class FunctionFacadeIT method testCreateCollectionQueueLinkedCollection.

@Test
public void testCreateCollectionQueueLinkedCollection() {
    createTestData();
    // C1(a1) = C2(a2) + C3(a3); C2(a2) = C4(a4) + C5(a5); C2(a3) = C2(a2) + C2(a4);
    LinkType l12 = getLinkType(c1, c2);
    LinkType l13 = getLinkType(c1, c3);
    LinkType l24 = getLinkType(c2, c4);
    LinkType l25 = getLinkType(c2, c5);
    FunctionRow row1 = FunctionRow.createForCollection(c1.getId(), "a1", c2.getId(), l12.getId(), "a2");
    FunctionRow row2 = FunctionRow.createForCollection(c1.getId(), "a1", c3.getId(), l13.getId(), "a3");
    FunctionRow row3 = FunctionRow.createForCollection(c2.getId(), "a2", c4.getId(), l24.getId(), "a4");
    FunctionRow row4 = FunctionRow.createForCollection(c2.getId(), "a2", c5.getId(), l25.getId(), "a5");
    FunctionRow row5 = FunctionRow.createForCollection(c2.getId(), "a3", c2.getId(), null, "a2");
    FunctionRow row6 = FunctionRow.createForCollection(c2.getId(), "a3", c2.getId(), null, "a4");
    functionDao.createRows(Arrays.asList(row1, row2, row3, row4, row5, row6));
    Document c4Document = getAnyDocument(c4);
    List<Document> c2Documents = getDocuments(c2).subList(0, 2);
    List<Document> c1Documents = getDocuments(c1).subList(0, 2);
    createLinks(l24, Collections.singletonList(c4Document), c2Documents);
    createLinks(l12, c2Documents, c1Documents);
    Deque<FunctionFacade.FunctionParameterDocuments> queue = functionFacade.createQueueForDocumentChanged(c4.getId(), Collections.singletonList("a4"), c4Document.getId());
    assertThat(queue).hasSize(3);
    assertThat(queue.getFirst().getResourceId()).isEqualTo(c2.getId());
    assertThat(queue.getFirst().getAttributeId()).isEqualTo("a2");
    FunctionTask task = functionFacade.convertQueueToTask(queue);
    assertThat(task).isNotNull();
    assertThat(task.getCollection().getId()).isEqualTo(c2.getId());
    assertThat(task.getAttribute().getId()).isEqualTo("a2");
    assertThat(task.getDocuments()).hasSize(2);
    assertThat(task.getParent()).isNotNull();
    assertThat(task.getParent().getParent()).isNotNull();
    assertThat(task.getParent().getParent().getParent()).isNull();
}
Also used : FunctionRow(io.lumeer.api.model.function.FunctionRow) FunctionTask(io.lumeer.core.task.FunctionTask) LinkType(io.lumeer.api.model.LinkType) DataDocument(io.lumeer.engine.api.data.DataDocument) Document(io.lumeer.api.model.Document) Test(org.junit.Test)

Example 12 with FunctionTask

use of io.lumeer.core.task.FunctionTask in project engine by Lumeer.

the class FunctionFacadeIT method testCreateCollectionQueueWithCycle.

@Test
public void testCreateCollectionQueueWithCycle() {
    createTestData();
    // C1(a1) = C2(a2) + C3(a3); C2(a2) = C4(a4) + C5(a5); C4(a4) = C1(a1) + C1(a2)
    LinkType l12 = getLinkType(c1, c2);
    LinkType l13 = getLinkType(c1, c3);
    LinkType l24 = getLinkType(c2, c4);
    LinkType l25 = getLinkType(c2, c5);
    LinkType l41 = getLinkType(c4, c1);
    FunctionRow row1 = FunctionRow.createForCollection(c1.getId(), "a1", c2.getId(), l12.getId(), "a2");
    FunctionRow row2 = FunctionRow.createForCollection(c1.getId(), "a1", c3.getId(), l13.getId(), "a3");
    FunctionRow row3 = FunctionRow.createForCollection(c2.getId(), "a2", c4.getId(), l24.getId(), "a4");
    FunctionRow row4 = FunctionRow.createForCollection(c2.getId(), "a2", c5.getId(), l25.getId(), "a5");
    FunctionRow row5 = FunctionRow.createForCollection(c4.getId(), "a4", c1.getId(), l41.getId(), "a1");
    FunctionRow row6 = FunctionRow.createForCollection(c4.getId(), "a4", c1.getId(), l41.getId(), "a2");
    functionDao.createRows(Arrays.asList(row1, row2, row3, row4, row5, row6));
    List<Document> c4Documents = getDocuments(c4).subList(0, 2);
    List<Document> c2Documents = getDocuments(c2).subList(0, 2);
    List<Document> c1Documents = getDocuments(c1).subList(0, 2);
    createLinks(l12, c2Documents, c1Documents);
    createLinks(l24, c4Documents, c2Documents);
    createLinks(l41, c4Documents, c1Documents);
    Deque<FunctionFacade.FunctionParameterDocuments> queue = functionFacade.createQueueForDocumentChanged(c1.getId(), Collections.singletonList("a2"), c1Documents.get(0).getId());
    assertThat(queue).hasSize(3);
    assertThat(queue).extracting(FunctionFacade.FunctionParameterDocuments::getResourceId).contains(c4.getId(), c2.getId(), c1.getId());
    FunctionTask task = functionFacade.convertQueueToTask(queue);
    assertThat(task).isNotNull();
    assertThat(task.getParent()).isNotNull();
    assertThat(task.getParent().getParent()).isNotNull();
    assertThat(task.getParent().getParent().getParent()).isNull();
}
Also used : FunctionRow(io.lumeer.api.model.function.FunctionRow) FunctionTask(io.lumeer.core.task.FunctionTask) LinkType(io.lumeer.api.model.LinkType) DataDocument(io.lumeer.engine.api.data.DataDocument) Document(io.lumeer.api.model.Document) Test(org.junit.Test)

Aggregations

FunctionTask (io.lumeer.core.task.FunctionTask)12 LinkType (io.lumeer.api.model.LinkType)9 Document (io.lumeer.api.model.Document)8 RuleTask (io.lumeer.core.task.RuleTask)8 Collection (io.lumeer.api.model.Collection)6 LinkInstance (io.lumeer.api.model.LinkInstance)6 DataDocument (io.lumeer.engine.api.data.DataDocument)6 FunctionRow (io.lumeer.api.model.function.FunctionRow)4 CreateDocument (io.lumeer.engine.api.event.CreateDocument)4 CreateLinkInstance (io.lumeer.engine.api.event.CreateLinkInstance)4 UpdateLinkInstance (io.lumeer.engine.api.event.UpdateLinkInstance)4 LinkTypeAdapter (io.lumeer.core.adapter.LinkTypeAdapter)3 Utils (io.lumeer.core.util.Utils)3 RemoveLinkType (io.lumeer.engine.api.event.RemoveLinkType)3 CollectionPurposeType (io.lumeer.api.model.CollectionPurposeType)2 ResourceType (io.lumeer.api.model.ResourceType)2 FunctionFacade (io.lumeer.core.facade.FunctionFacade)2 TaskProcessingFacade (io.lumeer.core.facade.TaskProcessingFacade)2 PurposeChangeProcessor (io.lumeer.core.facade.detector.PurposeChangeProcessor)2 AutoLinkBatchTask (io.lumeer.core.task.AutoLinkBatchTask)2