Search in sources :

Example 6 with Task

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

the class TaskProcessingFacade method runRule.

public void runRule(final LinkType linkType, final String ruleName, final LinkInstance linkInstance, final String actionName) {
    if (linkType != null && linkInstance != null) {
        Optional<RuleTask> task = createRuleTask(linkType, ruleName, null, linkInstance);
        Task t = task.orElse(null);
        while (t != null) {
            if (t instanceof RuleTask) {
                ((RuleTask) t).setActionName(actionName);
            }
            t = t.getParent();
        }
        task.ifPresent(this::processTasks);
    }
}
Also used : FunctionTask(io.lumeer.core.task.FunctionTask) Task(io.lumeer.core.task.Task) RuleTask(io.lumeer.core.task.RuleTask) RuleTask(io.lumeer.core.task.RuleTask)

Example 7 with Task

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

the class TaskProcessingFacade method onUpdateCollection.

public void onUpdateCollection(@Observes final UpdateResource updateResource) {
    if (updateResource.getResource() == null || updateResource.getOriginalResource() == null || !(updateResource.getResource() instanceof Collection)) {
        return;
    }
    List<Task> tasks = new ArrayList<>();
    Collection original = (Collection) updateResource.getOriginalResource();
    Collection current = (Collection) updateResource.getResource();
    AttributesDiff attributesDiff = checkAttributesDiff(original.getAttributes(), current.getAttributes());
    attributesDiff.getRemovedIds().forEach(removedAttributeId -> functionFacade.onDeleteCollectionAttribute(original.getId(), removedAttributeId));
    attributesDiff.getRemovedFunction().forEach(removedAttributeId -> functionFacade.onDeleteCollectionFunction(original.getId(), removedAttributeId));
    attributesDiff.getCreatedFunction().forEach(attribute -> tasks.add(functionFacade.createTaskForCreatedFunction(current, attribute)));
    attributesDiff.getUpdatedFunction().forEach(attribute -> tasks.add(functionFacade.createTaskForUpdatedFunction(current, attribute)));
    processTasks(tasks.toArray(new Task[0]));
}
Also used : FunctionTask(io.lumeer.core.task.FunctionTask) Task(io.lumeer.core.task.Task) RuleTask(io.lumeer.core.task.RuleTask) ArrayList(java.util.ArrayList) Collection(io.lumeer.api.model.Collection) AttributeUtil.checkAttributesDiff(io.lumeer.api.util.AttributeUtil.checkAttributesDiff) AttributesDiff(io.lumeer.api.util.AttributesDiff)

Aggregations

FunctionTask (io.lumeer.core.task.FunctionTask)7 RuleTask (io.lumeer.core.task.RuleTask)7 Task (io.lumeer.core.task.Task)7 AttributeUtil.checkAttributesDiff (io.lumeer.api.util.AttributeUtil.checkAttributesDiff)2 AttributesDiff (io.lumeer.api.util.AttributesDiff)2 ArrayList (java.util.ArrayList)2 Collection (io.lumeer.api.model.Collection)1 Document (io.lumeer.api.model.Document)1 LinkInstance (io.lumeer.api.model.LinkInstance)1 CreateDocument (io.lumeer.engine.api.event.CreateDocument)1 CreateLinkInstance (io.lumeer.engine.api.event.CreateLinkInstance)1 RemoveDocument (io.lumeer.engine.api.event.RemoveDocument)1 RemoveLinkInstance (io.lumeer.engine.api.event.RemoveLinkInstance)1 UpdateDocument (io.lumeer.engine.api.event.UpdateDocument)1 UpdateLinkInstance (io.lumeer.engine.api.event.UpdateLinkInstance)1