Search in sources :

Example 1 with RemoveDocument

use of io.lumeer.engine.api.event.RemoveDocument 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 2 with RemoveDocument

use of io.lumeer.engine.api.event.RemoveDocument in project engine by Lumeer.

the class DueDateChangeDetector method detectChanges.

@Override
public void detectChanges(final DocumentEvent documentEvent, final Collection collection) {
    final CollectionPurpose purpose = collection.getPurpose();
    final String dueDateAttr = purpose.getDueDateAttributeId();
    if (StringUtils.isNotEmpty(dueDateAttr) && isAttributeChanged(documentEvent, dueDateAttr)) {
        if (!(documentEvent instanceof CreateDocument)) {
            // delete previous due date events on the document
            delayedActionDao.deleteScheduledActions(getResourcePath(documentEvent), Set.of(NotificationType.DUE_DATE_SOON, NotificationType.PAST_DUE_DATE, NotificationType.DUE_DATE_CHANGED));
        }
        if (!(documentEvent instanceof RemoveDocument) && !isDoneState(documentEvent, collection)) {
            // create new due date events on the document
            final ZonedDateTime dueDate = getDueDate(documentEvent, collection);
            final String assigneeAttr = purpose.getAssigneeAttributeId();
            // due date has changed - but it goes with the assignee change message, so send it only if the assignee did not change
            if (isAttributeChanged(documentEvent, dueDateAttr) && !isAttributeChanged(documentEvent, assigneeAttr)) {
                delayedActionDao.scheduleActions(getDelayedActions(documentEvent, collection, NotificationType.DUE_DATE_CHANGED, nowPlus()));
            }
            // if it is not unset, then schedule past due and due date soon
            if (dueDate != null) {
                delayedActionDao.scheduleActions(getDelayedActions(documentEvent, collection, NotificationType.PAST_DUE_DATE, dueDate));
                if (dueDate.minus(DUE_DATE_SOON_DAYS, ChronoUnit.DAYS).isAfter(ZonedDateTime.now())) {
                    delayedActionDao.scheduleActions(getDelayedActions(documentEvent, collection, NotificationType.DUE_DATE_SOON, dueDate.minus(DUE_DATE_SOON_DAYS, ChronoUnit.DAYS)));
                }
            }
        }
    }
}
Also used : RemoveDocument(io.lumeer.engine.api.event.RemoveDocument) ZonedDateTime(java.time.ZonedDateTime) CreateDocument(io.lumeer.engine.api.event.CreateDocument) CollectionPurpose(io.lumeer.api.model.CollectionPurpose)

Example 3 with RemoveDocument

use of io.lumeer.engine.api.event.RemoveDocument in project engine by Lumeer.

the class StateChangeDetector method detectChanges.

@Override
public void detectChanges(final DocumentEvent documentEvent, final Collection collection) {
    final CollectionPurpose purpose = collection.getPurpose();
    final String stateAttr = purpose.getStateAttributeId();
    if (StringUtils.isNotEmpty(stateAttr) && isAttributeChanged(documentEvent, stateAttr)) {
        final boolean doneState = isDoneState(documentEvent, collection);
        if (!(documentEvent instanceof CreateDocument)) {
            // delete previous due date and assignee events on the document
            if (documentEvent instanceof RemoveDocument || doneState) {
                delayedActionDao.deleteScheduledActions(getResourcePath(documentEvent), Set.of(NotificationType.DUE_DATE_SOON, NotificationType.PAST_DUE_DATE, NotificationType.TASK_ASSIGNED, NotificationType.TASK_REOPENED, NotificationType.STATE_UPDATE, NotificationType.DUE_DATE_CHANGED));
            }
        }
        if (documentEvent instanceof UpdateDocument) {
            // switched back to non-final state, reschedule due dates and assignees
            if (wasDoneState(documentEvent, collection) && !doneState) {
                // create new due date events on the document
                final ZonedDateTime dueDate = getDueDate(documentEvent, collection);
                if (dueDate != null) {
                    delayedActionDao.scheduleActions(getDelayedActions(documentEvent, collection, NotificationType.PAST_DUE_DATE, dueDate));
                    if (dueDate.minus(DUE_DATE_SOON_DAYS, ChronoUnit.DAYS).isAfter(ZonedDateTime.now())) {
                        delayedActionDao.scheduleActions(getDelayedActions(documentEvent, collection, NotificationType.DUE_DATE_SOON, dueDate.minus(DUE_DATE_SOON_DAYS, ChronoUnit.DAYS)));
                    }
                }
                delayedActionDao.scheduleActions(getDelayedActions(documentEvent, collection, NotificationType.TASK_REOPENED, nowPlus()));
            }
        }
        if (!(documentEvent instanceof RemoveDocument)) {
            // create new due date events on the document
            delayedActionDao.scheduleActions(getDelayedActions(documentEvent, collection, NotificationType.STATE_UPDATE, nowPlus()));
        }
    }
}
Also used : RemoveDocument(io.lumeer.engine.api.event.RemoveDocument) UpdateDocument(io.lumeer.engine.api.event.UpdateDocument) ZonedDateTime(java.time.ZonedDateTime) CreateDocument(io.lumeer.engine.api.event.CreateDocument) CollectionPurpose(io.lumeer.api.model.CollectionPurpose)

Example 4 with RemoveDocument

use of io.lumeer.engine.api.event.RemoveDocument in project engine by Lumeer.

the class AssigneeChangeDetector method detectChanges.

@Override
public void detectChanges(final DocumentEvent documentEvent, final Collection collection) {
    final CollectionPurpose purpose = collection.getPurpose();
    final String assigneeAttr = purpose.getAssigneeAttributeId();
    final boolean doneState = isDoneState(documentEvent, collection);
    if (StringUtils.isNotEmpty(assigneeAttr) && isAttributeChanged(documentEvent, assigneeAttr)) {
        if (!(documentEvent instanceof CreateDocument)) {
            // delete previous due date and assignee events on the document
            delayedActionDao.deleteScheduledActions(getResourcePath(documentEvent), Set.of(NotificationType.DUE_DATE_SOON, NotificationType.PAST_DUE_DATE, NotificationType.TASK_ASSIGNED, NotificationType.TASK_REOPENED, NotificationType.DUE_DATE_CHANGED));
            if (!(documentEvent instanceof RemoveDocument) && !doneState) {
                final ZonedDateTime dueDate = getDueDate(documentEvent, collection);
                if (dueDate != null) {
                    delayedActionDao.scheduleActions(getDelayedActions(documentEvent, collection, NotificationType.PAST_DUE_DATE, dueDate));
                    if (dueDate.minus(DUE_DATE_SOON_DAYS, ChronoUnit.DAYS).isAfter(ZonedDateTime.now())) {
                        delayedActionDao.scheduleActions(getDelayedActions(documentEvent, collection, NotificationType.DUE_DATE_SOON, dueDate.minus(DUE_DATE_SOON_DAYS, ChronoUnit.DAYS)));
                    }
                }
            }
        }
        if (documentEvent instanceof UpdateDocument) {
            delayedActionDao.scheduleActions(getDelayedActions(documentEvent, collection, NotificationType.TASK_UNASSIGNED, nowPlus(), getRemovedAssignees(documentEvent, collection)));
        }
        if (!(documentEvent instanceof RemoveDocument) && !doneState) {
            // create new due date events on the document
            delayedActionDao.scheduleActions(getDelayedActions(documentEvent, collection, NotificationType.TASK_ASSIGNED, nowPlus(), getAddedAssignees(documentEvent, collection)));
        }
    }
}
Also used : RemoveDocument(io.lumeer.engine.api.event.RemoveDocument) ZonedDateTime(java.time.ZonedDateTime) UpdateDocument(io.lumeer.engine.api.event.UpdateDocument) CreateDocument(io.lumeer.engine.api.event.CreateDocument) CollectionPurpose(io.lumeer.api.model.CollectionPurpose)

Example 5 with RemoveDocument

use of io.lumeer.engine.api.event.RemoveDocument in project engine by Lumeer.

the class TaskUpdateChangeDetector method detectChanges.

@Override
public void detectChanges(final DocumentEvent documentEvent, final Collection collection) {
    final CollectionPurpose purpose = collection.getPurpose();
    final boolean doneState = isDoneState(documentEvent, collection);
    if (!(documentEvent instanceof CreateDocument) && !(documentEvent instanceof RemoveDocument)) {
        // delete previous due date and assignee events on the document
        delayedActionDao.deleteScheduledActions(getResourcePath(documentEvent), Set.of(NotificationType.TASK_UPDATED));
        if (!doneState) {
            final Set<Assignee> observers = getObservers(documentEvent, collection);
            delayedActionDao.scheduleActions(getDelayedActions(documentEvent, collection, NotificationType.TASK_UPDATED, nowPlus(), observers));
            // assignee != initiator, initiator != observer, no change in due date, state, nor assignee => send task update
            final String assigneeAttr = purpose.getAssigneeAttributeId();
            final String dueDateAttr = purpose.getDueDateAttributeId();
            final String stateAttr = purpose.getStateAttributeId();
            if (!isAttributeChanged(documentEvent, assigneeAttr) && !isAttributeChanged(documentEvent, dueDateAttr) && !isAttributeChanged(documentEvent, stateAttr)) {
                if (observers != null) {
                    // prevent double notification when assignee is also an observer
                    final Set<Assignee> assignees = new HashSet<>(getAssignees(documentEvent, collection));
                    observers.forEach(assignee -> {
                        assignees.remove(new Assignee(assignee.getEmail(), true));
                        assignees.remove(new Assignee(assignee.getEmail(), false));
                    });
                    delayedActionDao.scheduleActions(getDelayedActions(documentEvent, collection, NotificationType.TASK_UPDATED, nowPlus(), assignees));
                } else {
                    delayedActionDao.scheduleActions(getDelayedActions(documentEvent, collection, NotificationType.TASK_UPDATED, nowPlus()));
                }
            }
        }
    }
    if (documentEvent instanceof RemoveDocument) {
        // create new due date events on the document
        if (!doneState) {
            delayedActionDao.scheduleActions(getDelayedActions(documentEvent, collection, NotificationType.TASK_REMOVED, nowPlus()));
            delayedActionDao.scheduleActions(getDelayedActions(documentEvent, collection, NotificationType.TASK_REMOVED, nowPlus(), getObservers(documentEvent, collection)));
        }
    }
}
Also used : RemoveDocument(io.lumeer.engine.api.event.RemoveDocument) CreateDocument(io.lumeer.engine.api.event.CreateDocument) CollectionPurpose(io.lumeer.api.model.CollectionPurpose) HashSet(java.util.HashSet)

Aggregations

RemoveDocument (io.lumeer.engine.api.event.RemoveDocument)6 CreateDocument (io.lumeer.engine.api.event.CreateDocument)5 CollectionPurpose (io.lumeer.api.model.CollectionPurpose)4 UpdateDocument (io.lumeer.engine.api.event.UpdateDocument)3 ZonedDateTime (java.time.ZonedDateTime)3 Document (io.lumeer.api.model.Document)2 Collection (io.lumeer.api.model.Collection)1 ResourceComment (io.lumeer.api.model.ResourceComment)1 Role (io.lumeer.api.model.Role)1 FunctionTask (io.lumeer.core.task.FunctionTask)1 RuleTask (io.lumeer.core.task.RuleTask)1 DataDocument (io.lumeer.engine.api.data.DataDocument)1 HashSet (java.util.HashSet)1 Test (org.junit.Test)1