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);
}
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)));
}
}
}
}
}
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()));
}
}
}
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)));
}
}
}
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)));
}
}
}
Aggregations