Search in sources :

Example 1 with DocumentChanges

use of de.metas.ui.web.window.model.DocumentChanges in project metasfresh-webui-api by metasfresh.

the class JSONDocument method ofEvents.

public static List<JSONDocument> ofEvents(final IDocumentChangesCollector documentChangesCollector, final JSONOptions jsonOpts) {
    final int MAX_SIZE = 100;
    final List<JSONDocument> jsonChanges = documentChangesCollector.streamOrderedDocumentChanges().map(documentChanges -> ofEventOrNull(documentChanges, jsonOpts)).filter(jsonDocument -> jsonDocument != null).limit(MAX_SIZE + 1).collect(ImmutableList.toImmutableList());
    // Prevent sending more then MAX_SIZE events because that will freeze the frontend application.
    if (jsonChanges.size() > MAX_SIZE) {
        throw new AdempiereException("Events count exceeded").setParameter("maxSize", MAX_SIZE).setParameter("documentChangesCollector", documentChangesCollector).setParameter("first events", jsonChanges);
    }
    return jsonChanges;
}
Also used : JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) DocumentPath(de.metas.ui.web.window.datatypes.DocumentPath) DocumentValidStatus(de.metas.ui.web.window.model.DocumentValidStatus) DocumentId(de.metas.ui.web.window.datatypes.DocumentId) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IIncludedDocumentsCollection(de.metas.ui.web.window.model.IIncludedDocumentsCollection) DocumentChanges(de.metas.ui.web.window.model.DocumentChanges) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) JsonIgnore(com.fasterxml.jackson.annotation.JsonIgnore) ToString(lombok.ToString) DocumentStandardAction(de.metas.ui.web.window.model.DocumentStandardAction) ImmutableSet(com.google.common.collect.ImmutableSet) WindowConstants(de.metas.ui.web.window.WindowConstants) Collection(java.util.Collection) LogicExpressionResult(org.adempiere.ad.expression.api.LogicExpressionResult) Set(java.util.Set) WindowId(de.metas.ui.web.window.datatypes.WindowId) Collectors(java.util.stream.Collectors) DocumentSaveStatus(de.metas.ui.web.window.model.DocumentSaveStatus) List(java.util.List) AdempiereException(org.adempiere.exceptions.AdempiereException) IDocumentChangesCollector(de.metas.ui.web.window.model.IDocumentChangesCollector) JsonInclude(com.fasterxml.jackson.annotation.JsonInclude) WebSocketConfig(de.metas.ui.web.websocket.WebSocketConfig) Document(de.metas.ui.web.window.model.Document) AdempiereException(org.adempiere.exceptions.AdempiereException)

Example 2 with DocumentChanges

use of de.metas.ui.web.window.model.DocumentChanges in project metasfresh-webui-api by metasfresh.

the class JSONDocument method ofEventOrNull.

private static JSONDocument ofEventOrNull(final DocumentChanges documentChangedEvents, final JSONOptions jsonOpts) {
    if (documentChangedEvents.isEmpty()) {
        return null;
    }
    final DocumentPath documentPath = documentChangedEvents.getDocumentPath();
    final JSONDocument jsonDocument = new JSONDocument(documentPath);
    // If the document was deleted, we just need to export that flag. All the other changes are not relevant.
    if (documentChangedEvents.isDeleted()) {
        jsonDocument.setDeleted();
        return jsonDocument;
    }
    // 
    // Fields
    {
        final List<JSONDocumentField> jsonFields = new ArrayList<>();
        documentChangedEvents.getFieldChangesList().stream().filter(jsonOpts.documentFieldChangeFilter()).forEach((field) -> {
            // Add the pseudo-field "ID" first
            if (field.isKey()) {
                jsonFields.add(0, JSONDocumentField.idField(field.getValueAsJsonObject()));
            }
            // Append the other fields
            final JSONDocumentField jsonField = JSONDocumentField.ofDocumentFieldChangedEvent(field, jsonOpts);
            // apply permissions
            jsonOpts.getDocumentPermissions().apply(documentPath, jsonField);
            jsonFields.add(jsonField);
        });
        jsonDocument.setFields(jsonFields);
    }
    // 
    // Valid status
    final DocumentValidStatus documentValidStatus = documentChangedEvents.getDocumentValidStatus();
    if (documentValidStatus != null) {
        jsonDocument.setValidStatus(documentValidStatus);
    }
    // 
    // Save status
    final DocumentSaveStatus documentSaveStatus = documentChangedEvents.getDocumentSaveStatus();
    if (documentSaveStatus != null) {
        jsonDocument.setSaveStatus(documentSaveStatus);
    }
    // 
    // Included tabs info
    documentChangedEvents.getIncludedDetailInfos().stream().map(JSONDocument::createIncludedTabInfo).peek(jsonIncludedTabInfo -> jsonOpts.getDocumentPermissions().apply(documentPath, jsonIncludedTabInfo)).forEach(jsonDocument::addIncludedTabInfo);
    return jsonDocument;
}
Also used : JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) DocumentPath(de.metas.ui.web.window.datatypes.DocumentPath) DocumentValidStatus(de.metas.ui.web.window.model.DocumentValidStatus) DocumentId(de.metas.ui.web.window.datatypes.DocumentId) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IIncludedDocumentsCollection(de.metas.ui.web.window.model.IIncludedDocumentsCollection) DocumentChanges(de.metas.ui.web.window.model.DocumentChanges) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) JsonIgnore(com.fasterxml.jackson.annotation.JsonIgnore) ToString(lombok.ToString) DocumentStandardAction(de.metas.ui.web.window.model.DocumentStandardAction) ImmutableSet(com.google.common.collect.ImmutableSet) WindowConstants(de.metas.ui.web.window.WindowConstants) Collection(java.util.Collection) LogicExpressionResult(org.adempiere.ad.expression.api.LogicExpressionResult) Set(java.util.Set) WindowId(de.metas.ui.web.window.datatypes.WindowId) Collectors(java.util.stream.Collectors) DocumentSaveStatus(de.metas.ui.web.window.model.DocumentSaveStatus) List(java.util.List) AdempiereException(org.adempiere.exceptions.AdempiereException) IDocumentChangesCollector(de.metas.ui.web.window.model.IDocumentChangesCollector) JsonInclude(com.fasterxml.jackson.annotation.JsonInclude) WebSocketConfig(de.metas.ui.web.websocket.WebSocketConfig) Document(de.metas.ui.web.window.model.Document) DocumentSaveStatus(de.metas.ui.web.window.model.DocumentSaveStatus) DocumentPath(de.metas.ui.web.window.datatypes.DocumentPath) DocumentValidStatus(de.metas.ui.web.window.model.DocumentValidStatus) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List)

Aggregations

JsonIgnore (com.fasterxml.jackson.annotation.JsonIgnore)2 JsonInclude (com.fasterxml.jackson.annotation.JsonInclude)2 JsonProperty (com.fasterxml.jackson.annotation.JsonProperty)2 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 WebSocketConfig (de.metas.ui.web.websocket.WebSocketConfig)2 WindowConstants (de.metas.ui.web.window.WindowConstants)2 DocumentId (de.metas.ui.web.window.datatypes.DocumentId)2 DocumentPath (de.metas.ui.web.window.datatypes.DocumentPath)2 WindowId (de.metas.ui.web.window.datatypes.WindowId)2 Document (de.metas.ui.web.window.model.Document)2 DocumentChanges (de.metas.ui.web.window.model.DocumentChanges)2 DocumentSaveStatus (de.metas.ui.web.window.model.DocumentSaveStatus)2 DocumentStandardAction (de.metas.ui.web.window.model.DocumentStandardAction)2 DocumentValidStatus (de.metas.ui.web.window.model.DocumentValidStatus)2 IDocumentChangesCollector (de.metas.ui.web.window.model.IDocumentChangesCollector)2 IIncludedDocumentsCollection (de.metas.ui.web.window.model.IIncludedDocumentsCollection)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2