use of io.lumeer.engine.api.event.UpdateDocument 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);
}
use of io.lumeer.engine.api.event.UpdateDocument 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.UpdateDocument in project engine by Lumeer.
the class DocumentFacade method fireDocumentUpdate.
private void fireDocumentUpdate(final Document toBeStored, final Document updatedDocument, final Document originalDocument) {
if (updateDocumentEvent != null) {
final Document updatedDocumentWithData = new Document(updatedDocument);
updatedDocumentWithData.setData(toBeStored.getData());
updateDocumentEvent.fire(new UpdateDocument(updatedDocumentWithData, originalDocument));
}
}
use of io.lumeer.engine.api.event.UpdateDocument in project engine by Lumeer.
the class DocumentFacade method updateDocument.
private Document updateDocument(final Collection collection, final Document document, final DataDocument newData) {
final Document originalDocument = new Document(document);
originalDocument.setData(document.getData());
document.setCollectionId(collection.getId());
document.setData(newData);
final var updatedDocument = updateDocument(document, originalDocument);
updatedDocument.setData(newData);
return updatedDocument;
}
use of io.lumeer.engine.api.event.UpdateDocument in project engine by Lumeer.
the class DocumentFacade method patchDocumentData.
public Document patchDocumentData(String collectionId, String documentId, DataDocument data) {
Tuple<Collection, Document> tuple = checkEditDocument(documentId);
final Collection collection = tuple.getFirst();
final Document document = tuple.getSecond();
data = constraintManager.encodeDataTypes(collection, data);
DataDocument originalData = new DataDocument(document.getData());
Set<String> attributesIdsToAdd = new HashSet<>(data.keySet());
attributesIdsToAdd.removeAll(originalData.keySet());
if (!isPatchDifferent(originalData, data)) {
// if there is no difference, just return the document
return document;
}
collectionAdapter.updateCollectionMetadata(collection, attributesIdsToAdd, Collections.emptySet());
DataDocument patchedData = dataDao.patchData(collection.getId(), documentId, data);
final Document updatedDocument = updateDocument(collection, document, patchedData);
updatedDocument.setData(constraintManager.decodeDataTypes(collection, updatedDocument.getData()));
return mapDocumentData(updatedDocument);
}
Aggregations