Search in sources :

Example 1 with FunctionTask

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

the class FunctionFacadeIT method testCreateLinkTaskToCollection.

@Test
public void testCreateLinkTaskToCollection() {
    createTestData();
    // L12(a1) = C2(a2) + C2(a3); C2(a2) = L23(a1) + L23(a2); L23(a1) = C3(a3) + C3(a4)
    LinkType l12 = getLinkType(c1, c2);
    LinkType l23 = getLinkType(c2, c3);
    FunctionRow row1 = FunctionRow.createForLink(l12.getId(), "a1", c2.getId(), l12.getId(), "a2");
    FunctionRow row2 = FunctionRow.createForLink(l12.getId(), "a1", c2.getId(), l12.getId(), "a3");
    FunctionRow row3 = FunctionRow.createForCollection(c2.getId(), "a2", c3.getId(), l23.getId(), "a1");
    FunctionRow row4 = FunctionRow.createForCollection(c2.getId(), "a2", c3.getId(), l23.getId(), "a2");
    FunctionRow row5 = FunctionRow.createForLink(l23.getId(), "a1", c3.getId(), l23.getId(), "a3");
    FunctionRow row6 = FunctionRow.createForLink(l23.getId(), "a1", c3.getId(), l23.getId(), "a4");
    functionDao.createRows(Arrays.asList(row1, row2, row3, row4, row5, row6));
    List<Document> c1Documents = getDocuments(c1).subList(0, 2);
    List<Document> c2Documents = getDocuments(c2).subList(0, 2);
    List<Document> c3Documents = getDocuments(c3).subList(0, 2);
    createLinks(l12, c1Documents, c2Documents);
    List<LinkInstance> l23Links = createLinks(l23, c2Documents, c3Documents);
    Deque<FunctionFacade.FunctionParameterDocuments> queue = functionFacade.createQueueForLinkChanged(l23.getId(), Collections.singletonList("a1"), l23Links.get(0).getId());
    assertThat(queue).hasSize(2);
    assertThat(queue.getFirst().getResourceId()).isEqualTo(c2.getId());
    assertThat(queue.getLast().getResourceId()).isEqualTo(l12.getId());
    FunctionTask task = functionFacade.convertQueueToTask(queue);
    assertThat(task.getCollection().getId()).isEqualTo(c2.getId());
    assertThat(task.getDocuments()).hasSize(1);
    assertThat(task.getParent()).isNotNull();
    task = (FunctionTask) task.getParent();
    assertThat(task.getLinkType().getId()).isEqualTo(l12.getId());
    assertThat(task.getLinkInstances()).hasSize(2);
    assertThat(task.getParent()).isNull();
}
Also used : FunctionRow(io.lumeer.api.model.function.FunctionRow) FunctionTask(io.lumeer.core.task.FunctionTask) LinkInstance(io.lumeer.api.model.LinkInstance) LinkType(io.lumeer.api.model.LinkType) DataDocument(io.lumeer.engine.api.data.DataDocument) Document(io.lumeer.api.model.Document) Test(org.junit.Test)

Example 2 with FunctionTask

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

the class TaskProcessingFacade method onDocumentUpdate.

public void onDocumentUpdate(final UpdateDocument updateDocument, final String skipTask) {
    final Collection collection = getCollectionForEvent(updateDocument);
    if (collection == null) {
        return;
    }
    FunctionTask functionTask = functionFacade.createTaskForUpdateDocument(collection, new Document(updateDocument.getOriginalDocument()), new Document(updateDocument.getDocument()));
    List<RuleTask> tasks = createDocumentUpdateRuleTasks(collection, updateDocument, skipTask);
    RuleTask ruleTask = createOrderedRuleTask(tasks);
    processTasks(functionTask, ruleTask);
}
Also used : Collection(io.lumeer.api.model.Collection) FunctionTask(io.lumeer.core.task.FunctionTask) RuleTask(io.lumeer.core.task.RuleTask) Document(io.lumeer.api.model.Document) RemoveDocument(io.lumeer.engine.api.event.RemoveDocument) CreateDocument(io.lumeer.engine.api.event.CreateDocument) UpdateDocument(io.lumeer.engine.api.event.UpdateDocument)

Example 3 with FunctionTask

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

the class TaskProcessingFacade method onUpdateLink.

public void onUpdateLink(final UpdateLinkInstance updateLinkEvent, final String skipTask) {
    LinkType linkType = getLinkTypeForEvent(updateLinkEvent);
    if (linkType == null) {
        return;
    }
    FunctionTask functionTask = functionFacade.creatTaskForChangedLink(linkType, new LinkInstance(updateLinkEvent.getOriginalLinkInstance()), new LinkInstance(updateLinkEvent.getLinkInstance()));
    List<RuleTask> tasks = createLinkInstanceUpdateRuleTasks(linkType, updateLinkEvent, skipTask);
    RuleTask ruleTask = createOrderedRuleTask(tasks);
    processTasks(functionTask, ruleTask);
}
Also used : FunctionTask(io.lumeer.core.task.FunctionTask) RuleTask(io.lumeer.core.task.RuleTask) CreateLinkInstance(io.lumeer.engine.api.event.CreateLinkInstance) LinkInstance(io.lumeer.api.model.LinkInstance) RemoveLinkInstance(io.lumeer.engine.api.event.RemoveLinkInstance) UpdateLinkInstance(io.lumeer.engine.api.event.UpdateLinkInstance) RemoveLinkType(io.lumeer.engine.api.event.RemoveLinkType) LinkType(io.lumeer.api.model.LinkType) UpdateLinkType(io.lumeer.engine.api.event.UpdateLinkType)

Example 4 with FunctionTask

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

the class TaskProcessingFacade method onRemoveDocument.

public void onRemoveDocument(@Observes final RemoveDocument removeDocument) {
    final Collection collection = getCollectionForEvent(removeDocument);
    if (collection == null) {
        return;
    }
    FunctionTask functionTask = functionFacade.createTaskForRemovedDocument(collection, new Document(removeDocument.getDocument()));
    List<RuleTask> tasks = createDocumentRemoveRuleTasks(collection, removeDocument.getDocument());
    RuleTask ruleTask = createOrderedRuleTask(tasks);
    processTasks(functionTask, ruleTask);
}
Also used : Collection(io.lumeer.api.model.Collection) FunctionTask(io.lumeer.core.task.FunctionTask) RuleTask(io.lumeer.core.task.RuleTask) Document(io.lumeer.api.model.Document) RemoveDocument(io.lumeer.engine.api.event.RemoveDocument) CreateDocument(io.lumeer.engine.api.event.CreateDocument) UpdateDocument(io.lumeer.engine.api.event.UpdateDocument)

Example 5 with FunctionTask

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

the class FunctionFacade method convertQueueToTask.

public FunctionTask convertQueueToTask(final Deque<FunctionParameterDocuments> queue) {
    Set<String> collectionIds = queue.stream().filter(q -> q.getType() == FunctionResourceType.COLLECTION && q.getCollection() == null).map(FunctionParameter::getResourceId).collect(Collectors.toSet());
    Set<String> linkTypeIds = queue.stream().filter(q -> q.getType() == FunctionResourceType.LINK && q.getLinkType() == null).map(FunctionParameter::getResourceId).collect(Collectors.toSet());
    Map<String, Collection> collectionMap = collectionIds.size() > 0 ? collectionDao.getCollectionsByIds(collectionIds).stream().collect(Collectors.toMap(Resource::getId, c -> c)) : new HashMap<>();
    List<LinkType> linkTypes = linkTypeIds.size() > 0 ? linkTypeAdapter.mapLinkTypesComputedProperties(linkTypeDao.getLinkTypesByIds(linkTypeIds)) : new ArrayList<>();
    Map<String, LinkType> linkTypeMap = linkTypes.stream().collect(Collectors.toMap(LinkType::getId, c -> c));
    FunctionTask task = null;
    final Iterator<FunctionParameterDocuments> iterator = queue.descendingIterator();
    while (iterator.hasNext()) {
        final FunctionParameterDocuments parameter = iterator.next();
        if (parameter.getType() == FunctionResourceType.COLLECTION) {
            Collection collection = parameter.getCollection() != null ? parameter.getCollection() : collectionMap.get(parameter.getResourceId());
            Attribute attribute = parameter.getAttribute() != null ? parameter.getAttribute() : findAttributeInCollection(collection, parameter.getAttributeId());
            if (collection != null && attribute != null) {
                FunctionTask functionTask = contextualTaskFactory.getInstance(FunctionTask.class);
                functionTask.setFunctionTask(attribute, collection, parameter.getDocuments(), task);
                task = functionTask;
            }
        } else if (parameter.getType() == FunctionResourceType.LINK) {
            LinkType linkType = parameter.getLinkType() != null ? parameter.getLinkType() : linkTypeMap.get(parameter.getResourceId());
            Attribute attribute = parameter.getAttribute() != null ? parameter.getAttribute() : findAttributeInLinkType(linkType, parameter.getAttributeId());
            if (linkType != null && attribute != null) {
                FunctionTask functionTask = contextualTaskFactory.getInstance(FunctionTask.class);
                functionTask.setFunctionTask(attribute, linkType, parameter.getLinkInstances(), task);
                task = functionTask;
            }
        }
    }
    return task;
}
Also used : ContextualTaskFactory(io.lumeer.core.task.ContextualTaskFactory) FunctionOrder(io.lumeer.core.util.FunctionOrder) LinkTypeDao(io.lumeer.storage.api.dao.LinkTypeDao) HashMap(java.util.HashMap) Deque(java.util.Deque) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) CollectionDao(io.lumeer.storage.api.dao.CollectionDao) Resource(io.lumeer.api.model.common.Resource) Map(java.util.Map) FunctionResourceType(io.lumeer.api.model.function.FunctionResourceType) FunctionTask(io.lumeer.core.task.FunctionTask) LinkedList(java.util.LinkedList) DocumentDao(io.lumeer.storage.api.dao.DocumentDao) DataDocument(io.lumeer.engine.api.data.DataDocument) Iterator(java.util.Iterator) FunctionXmlParser(io.lumeer.core.util.FunctionXmlParser) Document(io.lumeer.api.model.Document) Set(java.util.Set) FunctionRow(io.lumeer.api.model.function.FunctionRow) Collectors(java.util.stream.Collectors) LinkInstance(io.lumeer.api.model.LinkInstance) LinkTypeAdapter(io.lumeer.core.adapter.LinkTypeAdapter) LinkType(io.lumeer.api.model.LinkType) Objects(java.util.Objects) LinkInstanceDao(io.lumeer.storage.api.dao.LinkInstanceDao) List(java.util.List) ResourceUtils(io.lumeer.api.util.ResourceUtils) RequestScoped(javax.enterprise.context.RequestScoped) PostConstruct(javax.annotation.PostConstruct) FunctionDao(io.lumeer.storage.api.dao.FunctionDao) Optional(java.util.Optional) Attribute(io.lumeer.api.model.Attribute) FunctionParameter(io.lumeer.api.model.function.FunctionParameter) Utils(io.lumeer.core.util.Utils) Collections(java.util.Collections) Collection(io.lumeer.api.model.Collection) Attribute(io.lumeer.api.model.Attribute) Resource(io.lumeer.api.model.common.Resource) FunctionTask(io.lumeer.core.task.FunctionTask) Collection(io.lumeer.api.model.Collection) LinkType(io.lumeer.api.model.LinkType)

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