diff --git a/metasfresh-webui-api/src/main/java/de/metas/ui/web/handlingunits/HUDocumentViewSelection.java b/metasfresh-webui-api/src/main/java/de/metas/ui/web/handlingunits/HUDocumentViewSelection.java index 5079c1f96..949081818 100644 --- a/metasfresh-webui-api/src/main/java/de/metas/ui/web/handlingunits/HUDocumentViewSelection.java +++ b/metasfresh-webui-api/src/main/java/de/metas/ui/web/handlingunits/HUDocumentViewSelection.java @@ -248,30 +248,29 @@ private void invalidateAllNoNotify() _recordsSupplier.forget(); documentViewsLoader.getAttributesProvider().invalidateAll(); } - + public void addHUsAndInvalidate(final Collection husToAdd) { - if(husToAdd.isEmpty()) + if (husToAdd.isEmpty()) { return; } - + documentViewsLoader.addHUs(husToAdd); invalidateAll(); } - + public void addHUAndInvalidate(final I_M_HU hu) { - if(hu == null) + if (hu == null) { return; } - + documentViewsLoader.addHUs(ImmutableSet.of(hu)); invalidateAll(); } - @Override public void notifyRecordsChanged(final Set recordRefs) { @@ -285,7 +284,7 @@ public void notifyRecordsChanged(final Set recordRefs) .filter(recordRef -> I_M_HU.Table_Name.equals(recordRef.getTableName())) .map(recordRef -> DocumentId.of(recordRef.getRecord_ID())) .anyMatch(records::contains); - if(!containsSomeRecords) + if (!containsSomeRecords) { return; } @@ -356,6 +355,22 @@ public Stream stream() return records.stream(); } + public Stream streamRecursive() + { + return records.stream() + .map(row -> streamRecursive(row)) + .reduce(Stream::concat) + .orElse(Stream.of()); + } + + private Stream streamRecursive(HUDocumentView row) + { + return row.getIncludedDocuments() + .stream() + .map(includedRow -> streamRecursive(includedRow)) + .reduce(Stream.of(row), Stream::concat); + } + public long size() { return records.size(); @@ -468,6 +483,18 @@ public Stream streamByIds(final Collection documentI return getRecords().streamByIds(documentIds); } + /** @return top level rows stream */ + public Stream streamAll() + { + return getRecords().stream(); + } + + /** @return top level rows and included rows recursive stream */ + public Stream streamAllRecursive() + { + return getRecords().streamRecursive(); + } + @Override public List retrieveModelsByIds(final Collection documentIds, final Class modelClass) {