Search in sources :

Example 1 with DocumentReference

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();
}
Also used : JSONOptions(de.metas.ui.web.window.datatypes.json.JSONOptions) WindowId(de.metas.ui.web.window.datatypes.WindowId) DocumentPath(de.metas.ui.web.window.datatypes.DocumentPath) JSONDocumentPath(de.metas.ui.web.window.datatypes.json.JSONDocumentPath) DocumentReference(de.metas.ui.web.window.model.DocumentReference) JSONDocumentReference(de.metas.ui.web.window.datatypes.json.JSONDocumentReference) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 2 with DocumentReference

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);
}
Also used : JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) MenuNode(de.metas.ui.web.menu.MenuNode) JSONDocumentReferencesGroupBuilder(de.metas.ui.web.window.datatypes.json.JSONDocumentReferencesGroup.JSONDocumentReferencesGroupBuilder) Collection(java.util.Collection) Visibility(com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility) MoreObjects(com.google.common.base.MoreObjects) HashMap(java.util.HashMap) UUID(java.util.UUID) JsonAutoDetect(com.fasterxml.jackson.annotation.JsonAutoDetect) MenuTree(de.metas.ui.web.menu.MenuTree) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) JsonCreator(com.fasterxml.jackson.annotation.JsonCreator) DocumentReference(de.metas.ui.web.window.model.DocumentReference) Comparator(java.util.Comparator) HashMap(java.util.HashMap) JSONDocumentReferencesGroupBuilder(de.metas.ui.web.window.datatypes.json.JSONDocumentReferencesGroup.JSONDocumentReferencesGroupBuilder) MenuNode(de.metas.ui.web.menu.MenuNode) DocumentReference(de.metas.ui.web.window.model.DocumentReference)

Aggregations

DocumentReference (de.metas.ui.web.window.model.DocumentReference)2 JsonAutoDetect (com.fasterxml.jackson.annotation.JsonAutoDetect)1 Visibility (com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility)1 JsonCreator (com.fasterxml.jackson.annotation.JsonCreator)1 JsonProperty (com.fasterxml.jackson.annotation.JsonProperty)1 MoreObjects (com.google.common.base.MoreObjects)1 ImmutableList (com.google.common.collect.ImmutableList)1 MenuNode (de.metas.ui.web.menu.MenuNode)1 MenuTree (de.metas.ui.web.menu.MenuTree)1 DocumentPath (de.metas.ui.web.window.datatypes.DocumentPath)1 WindowId (de.metas.ui.web.window.datatypes.WindowId)1 JSONDocumentPath (de.metas.ui.web.window.datatypes.json.JSONDocumentPath)1 JSONDocumentReference (de.metas.ui.web.window.datatypes.json.JSONDocumentReference)1 JSONDocumentReferencesGroupBuilder (de.metas.ui.web.window.datatypes.json.JSONDocumentReferencesGroup.JSONDocumentReferencesGroupBuilder)1 JSONOptions (de.metas.ui.web.window.datatypes.json.JSONOptions)1 Collection (java.util.Collection)1 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1