Search in sources :

Example 1 with CreateDocument

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

the class AbstractPurposeChangeDetector method getAddedAssignees.

protected Set<Assignee> getAddedAssignees(final DocumentEvent documentEvent, final Collection collection) {
    final String assigneeAttributeId = collection.getPurpose().getAssigneeAttributeId();
    if (StringUtils.isNotEmpty(assigneeAttributeId)) {
        final Attribute assigneeAttribute = findAttribute(collection.getAttributes(), assigneeAttributeId);
        if (assigneeAttribute != null) {
            if (documentEvent instanceof UpdateDocument) {
                final Set<Assignee> originalUsers = DocumentUtils.getUsersList(((UpdateDocument) documentEvent).getOriginalDocument(), assigneeAttribute, getTeams(), getUsers());
                final Set<Assignee> newUsers = new HashSet<>(DocumentUtils.getUsersList(documentEvent.getDocument(), assigneeAttribute, getTeams(), getUsers()));
                originalUsers.forEach(assignee -> {
                    newUsers.remove(new Assignee(assignee.getEmail(), true));
                    newUsers.remove(new Assignee(assignee.getEmail(), false));
                });
                return newUsers;
            } else if (documentEvent instanceof CreateDocument) {
                return DocumentUtils.getUsersList(documentEvent.getDocument(), assigneeAttribute, getTeams(), getUsers());
            }
        }
    }
    return Set.of();
}
Also used : ResourceUtils.findAttribute(io.lumeer.api.util.ResourceUtils.findAttribute) Attribute(io.lumeer.api.model.Attribute) UpdateDocument(io.lumeer.engine.api.event.UpdateDocument) CreateDocument(io.lumeer.engine.api.event.CreateDocument) HashSet(java.util.HashSet)

Example 2 with CreateDocument

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

the class DocumentFacade method createDocument.

public Document createDocument(String collectionId, Document document) {
    Collection collection = checkCreateDocuments(collectionId);
    permissionsChecker.checkDocumentLimits(document);
    final Tuple<Document, Document> documentTuple = createDocument(collection, document);
    if (createDocumentEvent != null) {
        createDocumentEvent.fire(new CreateDocument(documentTuple.getFirst()));
    }
    return documentTuple.getSecond();
}
Also used : CreateDocument(io.lumeer.engine.api.event.CreateDocument) Collection(io.lumeer.api.model.Collection) DataDocument(io.lumeer.engine.api.data.DataDocument) Document(io.lumeer.api.model.Document) CreateDocument(io.lumeer.engine.api.event.CreateDocument) UpdateDocument(io.lumeer.engine.api.event.UpdateDocument)

Example 3 with CreateDocument

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

the class DocumentFacade method createDocument.

private Tuple<Document, Document> createDocument(Collection collection, Document document) {
    DataDocument data = document.getData();
    data = constraintManager.encodeDataTypes(collection, data);
    Document storedDocument = createDocument(collection, document, new DataDocument(data));
    DataDocument storedData = dataDao.createData(collection.getId(), storedDocument.getId(), data);
    storedDocument.setData(storedData);
    Document storedDocumentCopy = new Document(storedDocument);
    collectionAdapter.updateCollectionMetadata(collection, data.keySet(), Collections.emptySet());
    storedDocument.setData(constraintManager.decodeDataTypes(collection, storedData));
    return new Tuple<>(storedDocumentCopy, storedDocument);
}
Also used : DataDocument(io.lumeer.engine.api.data.DataDocument) DataDocument(io.lumeer.engine.api.data.DataDocument) Document(io.lumeer.api.model.Document) CreateDocument(io.lumeer.engine.api.event.CreateDocument) UpdateDocument(io.lumeer.engine.api.event.UpdateDocument) Tuple(io.lumeer.core.util.Tuple)

Example 4 with CreateDocument

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

use of io.lumeer.engine.api.event.CreateDocument 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)

Aggregations

CreateDocument (io.lumeer.engine.api.event.CreateDocument)10 UpdateDocument (io.lumeer.engine.api.event.UpdateDocument)8 Document (io.lumeer.api.model.Document)5 RemoveDocument (io.lumeer.engine.api.event.RemoveDocument)5 ZonedDateTime (java.time.ZonedDateTime)5 CollectionPurpose (io.lumeer.api.model.CollectionPurpose)4 DataDocument (io.lumeer.engine.api.data.DataDocument)4 HashSet (java.util.HashSet)4 Collection (io.lumeer.api.model.Collection)3 LinkInstance (io.lumeer.api.model.LinkInstance)2 LinkType (io.lumeer.api.model.LinkType)2 ResourceType (io.lumeer.api.model.ResourceType)2 FunctionTask (io.lumeer.core.task.FunctionTask)2 RuleTask (io.lumeer.core.task.RuleTask)2 DocumentUtils (io.lumeer.core.util.DocumentUtils)2 Utils (io.lumeer.core.util.Utils)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2