Search in sources :

Example 1 with UpdateDocument

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);
}
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 UpdateDocument

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();
}
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 3 with UpdateDocument

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));
    }
}
Also used : UpdateDocument(io.lumeer.engine.api.event.UpdateDocument) 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 4 with UpdateDocument

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;
}
Also used : 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 5 with UpdateDocument

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);
}
Also used : DataDocument(io.lumeer.engine.api.data.DataDocument) 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) HashSet(java.util.HashSet)

Aggregations

UpdateDocument (io.lumeer.engine.api.event.UpdateDocument)14 CreateDocument (io.lumeer.engine.api.event.CreateDocument)13 Document (io.lumeer.api.model.Document)10 DataDocument (io.lumeer.engine.api.data.DataDocument)9 Collection (io.lumeer.api.model.Collection)6 HashSet (java.util.HashSet)5 ZonedDateTime (java.time.ZonedDateTime)3 Attribute (io.lumeer.api.model.Attribute)2 CollectionPurpose (io.lumeer.api.model.CollectionPurpose)2 ResourceUtils.findAttribute (io.lumeer.api.util.ResourceUtils.findAttribute)2 FunctionTask (io.lumeer.core.task.FunctionTask)2 RuleTask (io.lumeer.core.task.RuleTask)2 RemoveDocument (io.lumeer.engine.api.event.RemoveDocument)2 CollectionPurposeType (io.lumeer.api.model.CollectionPurposeType)1 LinkInstance (io.lumeer.api.model.LinkInstance)1 LinkType (io.lumeer.api.model.LinkType)1 ResourceType (io.lumeer.api.model.ResourceType)1 LinkTypeAdapter (io.lumeer.core.adapter.LinkTypeAdapter)1 FunctionFacade (io.lumeer.core.facade.FunctionFacade)1 TaskProcessingFacade (io.lumeer.core.facade.TaskProcessingFacade)1