Skip to content

Package: HtmlTemplateCalendarViewController

HtmlTemplateCalendarViewController

nameinstructionbranchcomplexitylinemethod
HtmlTemplateCalendarViewController(HtmlTemplateCalendarView, SiteNode, RequestLocaleManager, CalendarDao, TimeProvider)
M: 0 C: 11
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
lambda$render$0(int, int)
M: 0 C: 10
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
lambda$render$1(DefaultCalendarViewController.Entry)
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%
lambda$render$2(SortedMap, int)
M: 0 C: 15
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
lambda$toAggregate$3(String)
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
render(Optional, int, int, int, SortedMap, int)
M: 0 C: 51
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 11
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%
toAggregate(DefaultCalendarViewController.Entry)
M: 0 C: 15
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
toAggregate(int, boolean)
M: 0 C: 16
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 2
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.calendar.htmltemplate;
27:
28: import javax.annotation.Nonnegative;
29: import javax.annotation.Nonnull;
30: import java.text.DateFormatSymbols;
31: import java.util.List;
32: import java.util.Map;
33: import java.util.Optional;
34: import java.util.SortedMap;
35: import java.util.function.IntFunction;
36: import java.util.stream.IntStream;
37: import it.tidalwave.util.TimeProvider;
38: import it.tidalwave.northernwind.core.model.RequestLocaleManager;
39: import it.tidalwave.northernwind.core.model.SiteNode;
40: import it.tidalwave.northernwind.core.model.Template.Aggregate;
41: import it.tidalwave.northernwind.frontend.ui.component.calendar.CalendarViewController;
42: import it.tidalwave.northernwind.frontend.ui.component.calendar.DefaultCalendarViewController;
43: import it.tidalwave.northernwind.frontend.ui.component.calendar.spi.CalendarDao;
44: import lombok.extern.slf4j.Slf4j;
45: import static java.util.Collections.emptyList;
46: import static java.util.stream.Collectors.*;
47: import static it.tidalwave.util.Pair.*;
48: import static it.tidalwave.northernwind.core.model.Template.Aggregates.toAggregates;
49: import static it.tidalwave.northernwind.frontend.ui.component.Properties.P_TEMPLATE_PATH;
50:
51: /***************************************************************************************************************************************************************
52: *
53: * <p>An implementation of {@link CalendarViewController} based on HTML templates.</p>
54: *
55: * <p>The template for rendering the page can be specified by means of the property {@code P_TEMPLATE_PATH}.</p>
56: *
57: * @see HtmlTemplateCalendarView
58: * @author Fabrizio Giudici
59: *
60: **************************************************************************************************************************************************************/
61: @Slf4j
62: public class HtmlTemplateCalendarViewController extends DefaultCalendarViewController
63: {
64: @Nonnull
65: private final HtmlTemplateCalendarView view;
66:
67: /***********************************************************************************************************************************************************
68: *
69: **********************************************************************************************************************************************************/
70: public HtmlTemplateCalendarViewController (@Nonnull final HtmlTemplateCalendarView view,
71: @Nonnull final SiteNode siteNode,
72: @Nonnull final RequestLocaleManager requestLocaleManager,
73: @Nonnull final CalendarDao dao,
74: @Nonnull final TimeProvider timeProvider)
75: {
76: super(view, siteNode, requestLocaleManager, dao, timeProvider);
77: this.view = view;
78: }
79:
80: /***********************************************************************************************************************************************************
81: * {@inheritDoc}
82: **********************************************************************************************************************************************************/
83: @Override
84: protected void render (@Nonnull final Optional<String> title,
85: @Nonnegative final int year,
86: @Nonnegative final int firstYear,
87: @Nonnegative final int lastYear,
88: @Nonnull final SortedMap<Integer, List<Entry>> byMonth,
89: @Nonnegative final int columns)
90: {
91: final var years = IntStream.rangeClosed(firstYear, lastYear)
92:• .mapToObj(y -> toAggregate(y, y == year))
93: .collect(toAggregates("years"));
94:
95: final var monthNames = DateFormatSymbols.getInstance(requestLocaleManager.getLocales().get(0)).getMonths();
96: final IntFunction<List<Map<String, Object>>> entriesByMonth =
97: m -> byMonth.getOrDefault(m + 1, emptyList()).stream().map(x -> toAggregate(x).getMap()).collect(toList());
98: view.render(title,
99: getViewProperties().getProperty(P_TEMPLATE_PATH),
100: indexedPairStream(monthNames, BASE_1).collect(pairsToMap()),
101: Integer.toString(year),
102: years,
103: indexedPairStream(0, 12, entriesByMonth, BASE_1).collect(pairsToMap()),
104: columns);
105: }
106:
107: /***********************************************************************************************************************************************************
108: *
109: **********************************************************************************************************************************************************/
110: @Nonnull
111: private static Aggregate toAggregate (@Nonnull final Entry entry)
112: {
113: return Aggregate.of( "label", entry.name)
114: .with("link", entry.link)
115: .with("class", entry.type.map(s -> "nw-calendar-table-link-" + s));
116: }
117:
118: /***********************************************************************************************************************************************************
119: *
120: **********************************************************************************************************************************************************/
121: @Nonnull
122: private Aggregate toAggregate (final int year, final boolean withLink)
123: {
124: final var a = Aggregate.of("number", year);
125:• return withLink ? a : a.with("link", createYearLink(year));
126: }
127: }