Skip to content

Package: DefaultMenuViewController

DefaultMenuViewController

nameinstructionbranchcomplexitylinemethod
lambda$renderView$0(Site, ResourcePath)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
lambda$renderView$1(Site, String)
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
lambda$renderView$2(Site, SiteNode)
M: 0 C: 14
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
renderView(RenderContext)
M: 0 C: 50
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 10
100%
M: 0 C: 1
100%
static {...}
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%

Coverage

1: /*
2: * *************************************************************************************************************************************************************
3: *
4: * NorthernWind - lightweight CMS
5: * http://tidalwave.it/projects/northernwind
6: *
7: * Copyright (C) 2011 - 2025 Tidalwave s.a.s. (http://tidalwave.it)
8: *
9: * *************************************************************************************************************************************************************
10: *
11: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
12: * You may obtain a copy of the License at
13: *
14: * http://www.apache.org/licenses/LICENSE-2.0
15: *
16: * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
17: * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
18: *
19: * *************************************************************************************************************************************************************
20: *
21: * git clone https://bitbucket.org/tidalwave/northernwind-src
22: * git clone https://github.com/tidalwave-it/northernwind-src
23: *
24: * *************************************************************************************************************************************************************
25: */
26: package it.tidalwave.northernwind.frontend.ui.component.menu;
27:
28: import javax.annotation.Nonnull;
29: import org.springframework.context.annotation.Scope;
30: import it.tidalwave.northernwind.core.model.SiteNode;
31: import it.tidalwave.northernwind.frontend.ui.RenderContext;
32: import lombok.RequiredArgsConstructor;
33: import lombok.extern.slf4j.Slf4j;
34: import static java.util.Collections.emptyList;
35: import static it.tidalwave.northernwind.core.model.Content.P_TITLE;
36: import static it.tidalwave.northernwind.core.model.SiteNode.*;
37: import static it.tidalwave.northernwind.frontend.ui.component.Properties.P_TEMPLATE_PATH;
38:
39: /***************************************************************************************************************************************************************
40: *
41: * The default implementation of {@link MenuViewController}.
42: *
43: * @author Fabrizio Giudici
44: *
45: **************************************************************************************************************************************************************/
46: @RequiredArgsConstructor @Scope("session") @Slf4j
47: public class DefaultMenuViewController implements MenuViewController
48: {
49: @Nonnull
50: protected final MenuView view;
51:
52: @Nonnull
53: protected final SiteNode siteNode;
54:
55: /***********************************************************************************************************************************************************
56: * {@inheritDoc}
57: **********************************************************************************************************************************************************/
58: @Override
59: public void renderView (@Nonnull final RenderContext context)
60: {
61: final var site = siteNode.getSite();
62: final var viewProperties = siteNode.getPropertyGroup(view.getId());
63: viewProperties.getProperty(P_TITLE).ifPresent(view::setTitle);
64: viewProperties.getProperty(P_TEMPLATE_PATH).flatMap(p -> site.getTemplate(getClass(), p))
65: .ifPresent(view::setTemplate);
66:
67: viewProperties.getProperty(P_LINKS).orElse(emptyList())
68: .stream()
69: .flatMap(path -> site.find(_SiteNode_).withRelativePath(path).stream())
70: .forEach(node -> view.addLink(node.getProperty(P_NAVIGATION_LABEL).orElse("no nav. label"), // FIXME
71: site.createLink(node.getRelativeUri())));
72: }
73: }