use of de.metas.ui.web.window.model.DocumentReference in project metasfresh-webui-api by metasfresh.
the class WindowRestController method getDocumentReferences.
@GetMapping(value = "/{windowId}/{documentId}/{tabId}/{rowId}/references")
public JSONDocumentReferencesGroup getDocumentReferences(@PathVariable("windowId") final String windowIdStr, @PathVariable("documentId") final String documentIdStr, @PathVariable("tabId") final String tabIdStr, @PathVariable("rowId") final String rowIdStr) {
userSession.assertLoggedIn();
// Get document references
final WindowId windowId = WindowId.fromJson(windowIdStr);
final DocumentPath documentPath = DocumentPath.includedDocumentPath(windowId, documentIdStr, tabIdStr, rowIdStr);
final List<DocumentReference> documentReferences = documentReferencesService.getDocumentReferences(documentPath);
final JSONOptions jsonOpts = newJSONOptions().build();
return JSONDocumentReferencesGroup.builder().caption("References").references(JSONDocumentReference.ofList(documentReferences, jsonOpts)).build();
}
use of de.metas.ui.web.window.model.DocumentReference in project metasfresh-webui-api by metasfresh.
the class JSONDocumentReferencesGroupList method of.
public static //
JSONDocumentReferencesGroupList of(//
final Collection<DocumentReference> documentReferences, //
final MenuTree menuTree, //
final String othersMenuCaption, //
final JSONOptions jsonOpts) {
if (documentReferences.isEmpty()) {
return EMPTY;
}
final Map<String, JSONDocumentReferencesGroupBuilder> groupsBuilders = new HashMap<>();
final String othersGroupId = "_others_" + UUID.randomUUID();
for (final DocumentReference documentReference : documentReferences) {
final JSONDocumentReference jsonDocumentReference = JSONDocumentReference.of(documentReference, jsonOpts);
if (jsonDocumentReference == null) {
continue;
}
final MenuNode topLevelMenuGroup = menuTree.getTopLevelMenuGroupOrNull(documentReference.getWindowId());
final String topLevelMenuGroupId = topLevelMenuGroup != null ? topLevelMenuGroup.getId() : othersGroupId;
final JSONDocumentReferencesGroupBuilder groupBuilder = groupsBuilders.computeIfAbsent(topLevelMenuGroupId, k -> {
final boolean isMiscGroup = topLevelMenuGroup == null;
final String caption = topLevelMenuGroup != null ? topLevelMenuGroup.getCaption() : othersMenuCaption;
return JSONDocumentReferencesGroup.builder().caption(caption).isMiscGroup(isMiscGroup);
});
groupBuilder.reference(jsonDocumentReference);
}
// Sort by Caption, but keep the "misc group" last
Comparator<JSONDocumentReferencesGroup> sorting = Comparator.<JSONDocumentReferencesGroup>comparingInt(group -> group.isMiscGroup() ? 1 : 0).thenComparing(JSONDocumentReferencesGroup::getCaption);
final List<JSONDocumentReferencesGroup> groups = groupsBuilders.values().stream().map(groupBuilder -> groupBuilder.build()).filter(group -> !group.isEmpty()).sorted(sorting).collect(ImmutableList.toImmutableList());
return new JSONDocumentReferencesGroupList(groups);
}
Aggregations