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