Search in sources :

Example 1 with RuleTask

use of io.lumeer.core.task.RuleTask 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 2 with RuleTask

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

the class TaskProcessingFacade method runRule.

public void runRule(final Collection collection, final String ruleName, final Document document, final String actionName) {
    if (collection != null && document != null) {
        Optional<RuleTask> task = createRuleTask(collection, ruleName, null, document);
        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 3 with RuleTask

use of io.lumeer.core.task.RuleTask 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 RuleTask

use of io.lumeer.core.task.RuleTask 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 RuleTask

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

the class CollectionFacade method runRule.

public void runRule(final Collection collection, final String ruleId) {
    if (adapter.getDocumentsCountByCollection(collection.getId()) > 2_000) {
        throw new UnsuccessfulOperationException("Too many documents in the source collection");
    }
    final Rule rule = collection.getRules().get(ruleId);
    if (rule != null && rule.getType() == Rule.RuleType.AUTO_LINK) {
        final AutoLinkRule autoLinkRule = new AutoLinkRule(rule);
        final String otherCollectionId = autoLinkRule.getCollection2().equals(collection.getId()) ? autoLinkRule.getCollection1() : autoLinkRule.getCollection2();
        final String attributeId = autoLinkRule.getCollection1().equals(collection.getId()) ? autoLinkRule.getAttribute1() : autoLinkRule.getAttribute2();
        final Attribute attribute = collection.getAttributes().stream().filter(a -> a.getId().equals(attributeId)).findFirst().orElse(null);
        final Collection otherCollection = getCollection(otherCollectionId);
        final String otherAttributeId = autoLinkRule.getCollection2().equals(collection.getId()) ? autoLinkRule.getAttribute1() : autoLinkRule.getAttribute2();
        final Attribute otherAttribute = otherCollection.getAttributes().stream().filter(a -> a.getId().equals(otherAttributeId)).findFirst().orElse(null);
        final Map<String, AllowedPermissions> permissions = permissionsChecker.getCollectionsPermissions(List.of(collection, otherCollection));
        if (adapter.getDocumentsCountByCollection(otherCollectionId) > 10_000) {
            throw new UnsuccessfulOperationException("Too many documents in the target collection");
        }
        final LinkType linkType = linkTypeDao.getLinkType(autoLinkRule.getLinkType());
        final AutoLinkBatchTask task = taskFactory.getInstance(AutoLinkBatchTask.class);
        task.setupBatch(autoLinkRule, linkType, collection, attribute, otherCollection, otherAttribute, getCurrentUser(), permissions);
        taskExecutor.submitTask(task);
    } else if (rule != null && rule.getType() == Rule.RuleType.CRON) {
        final CronRule cronRule = new CronRule(rule);
        List<Document> documents = new ArrayList<>();
        if (cronRule.getViewId() != null) {
            try {
                final View view = viewDao.getViewById(cronRule.getViewId());
                final User user = AuthenticatedUser.getMachineUser();
                final AllowedPermissions allowedPermissions = AllowedPermissions.allAllowed();
                documents = DocumentUtils.getDocuments(collectionDao, documentDao, dataDao, userDao, groupDao, selectionListDao, getOrganization(), getProject(), view.getQuery(), user, cronRule.getLanguage(), allowedPermissions, null);
                documents = documents.stream().filter(document -> document.getCollectionId().equals(collection.getId())).collect(Collectors.toList());
            } catch (ResourceNotFoundException ignore) {
            }
        }
        RuleTask task = taskFactory.getInstance(RuleTask.class);
        task.setRule(rule.getName(), rule, collection, documents);
        taskExecutor.submitTask(task);
    }
}
Also used : AutoLinkBatchTask(io.lumeer.core.task.AutoLinkBatchTask) TaskExecutor(io.lumeer.core.task.TaskExecutor) CollectionUtil(io.lumeer.api.util.CollectionUtil) ZonedDateTime(java.time.ZonedDateTime) User(io.lumeer.api.model.User) AuthenticatedUser(io.lumeer.core.auth.AuthenticatedUser) LinkTypeDao(io.lumeer.storage.api.dao.LinkTypeDao) AutoLinkRule(io.lumeer.api.model.rule.AutoLinkRule) CollectionDao(io.lumeer.storage.api.dao.CollectionDao) ResourceType(io.lumeer.api.model.ResourceType) DefaultViewConfigDao(io.lumeer.storage.api.dao.DefaultViewConfigDao) Map(java.util.Map) ResourceCommentDao(io.lumeer.storage.api.dao.ResourceCommentDao) CollectionAdapter(io.lumeer.core.adapter.CollectionAdapter) Permission(io.lumeer.api.model.Permission) RoleType(io.lumeer.api.model.RoleType) View(io.lumeer.api.model.View) ResourceNotFoundException(io.lumeer.storage.api.exception.ResourceNotFoundException) Document(io.lumeer.api.model.Document) Set(java.util.Set) NoResourcePermissionException(io.lumeer.core.exception.NoResourcePermissionException) Collectors(java.util.stream.Collectors) LinkType(io.lumeer.api.model.LinkType) Objects(java.util.Objects) AttributesResource(io.lumeer.api.model.common.AttributesResource) List(java.util.List) ResourceUtils(io.lumeer.api.util.ResourceUtils) PostConstruct(javax.annotation.PostConstruct) FavoriteItemDao(io.lumeer.storage.api.dao.FavoriteItemDao) Attribute(io.lumeer.api.model.Attribute) ContextualTaskFactory(io.lumeer.core.task.ContextualTaskFactory) UserDao(io.lumeer.storage.api.dao.UserDao) HashMap(java.util.HashMap) SelectionListDao(io.lumeer.storage.api.dao.SelectionListDao) AllowedPermissions(io.lumeer.api.model.AllowedPermissions) Function(java.util.function.Function) CollectionPurpose(io.lumeer.api.model.CollectionPurpose) GroupDao(io.lumeer.storage.api.dao.GroupDao) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) DataDao(io.lumeer.storage.api.dao.DataDao) ViewDao(io.lumeer.storage.api.dao.ViewDao) CodeGenerator(io.lumeer.core.util.CodeGenerator) Rule(io.lumeer.api.model.Rule) DocumentDao(io.lumeer.storage.api.dao.DocumentDao) Permissions(io.lumeer.api.model.Permissions) ResourceAdapter(io.lumeer.core.adapter.ResourceAdapter) DocumentUtils(io.lumeer.core.util.DocumentUtils) FileAttachment(io.lumeer.api.model.FileAttachment) Project(io.lumeer.api.model.Project) LinkInstanceDao(io.lumeer.storage.api.dao.LinkInstanceDao) UnsuccessfulOperationException(io.lumeer.engine.api.exception.UnsuccessfulOperationException) ConversionFacade(io.lumeer.core.facade.conversion.ConversionFacade) RuleTask(io.lumeer.core.task.RuleTask) RequestScoped(javax.enterprise.context.RequestScoped) CronRule(io.lumeer.api.model.rule.CronRule) AutoLinkBatchTask(io.lumeer.core.task.AutoLinkBatchTask) Collection(io.lumeer.api.model.Collection) User(io.lumeer.api.model.User) AuthenticatedUser(io.lumeer.core.auth.AuthenticatedUser) Attribute(io.lumeer.api.model.Attribute) View(io.lumeer.api.model.View) AllowedPermissions(io.lumeer.api.model.AllowedPermissions) UnsuccessfulOperationException(io.lumeer.engine.api.exception.UnsuccessfulOperationException) Collection(io.lumeer.api.model.Collection) List(java.util.List) ArrayList(java.util.ArrayList) RuleTask(io.lumeer.core.task.RuleTask) AutoLinkRule(io.lumeer.api.model.rule.AutoLinkRule) Rule(io.lumeer.api.model.Rule) CronRule(io.lumeer.api.model.rule.CronRule) LinkType(io.lumeer.api.model.LinkType) ResourceNotFoundException(io.lumeer.storage.api.exception.ResourceNotFoundException) AutoLinkRule(io.lumeer.api.model.rule.AutoLinkRule) CronRule(io.lumeer.api.model.rule.CronRule)

Aggregations

RuleTask (io.lumeer.core.task.RuleTask)11 FunctionTask (io.lumeer.core.task.FunctionTask)10 Collection (io.lumeer.api.model.Collection)6 LinkType (io.lumeer.api.model.LinkType)6 Document (io.lumeer.api.model.Document)5 LinkInstance (io.lumeer.api.model.LinkInstance)4 CreateDocument (io.lumeer.engine.api.event.CreateDocument)4 CreateLinkInstance (io.lumeer.engine.api.event.CreateLinkInstance)4 UpdateDocument (io.lumeer.engine.api.event.UpdateDocument)4 ResourceType (io.lumeer.api.model.ResourceType)3 AutoLinkBatchTask (io.lumeer.core.task.AutoLinkBatchTask)3 TaskExecutor (io.lumeer.core.task.TaskExecutor)3 DocumentUtils (io.lumeer.core.util.DocumentUtils)3 RemoveLinkType (io.lumeer.engine.api.event.RemoveLinkType)3 UpdateLinkInstance (io.lumeer.engine.api.event.UpdateLinkInstance)3 CollectionPurposeType (io.lumeer.api.model.CollectionPurposeType)2 LinkTypeAdapter (io.lumeer.core.adapter.LinkTypeAdapter)2 FunctionFacade (io.lumeer.core.facade.FunctionFacade)2 TaskProcessingFacade (io.lumeer.core.facade.TaskProcessingFacade)2 PurposeChangeProcessor (io.lumeer.core.facade.detector.PurposeChangeProcessor)2