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