Skip to content

Package: DefaultGalleryViewController

DefaultGalleryViewController

nameinstructionbranchcomplexitylinemethod
DefaultGalleryViewController(NodeContainerView, SiteNode, RequestLocaleManager, BeanFactory)
M: 22 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
findVirtualSiteNodes()
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
initialize()
M: 50 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 8 C: 0
0%
M: 1 C: 0
0%
lambda$initialize$0(GalleryViewController.GalleryItem)
M: 2 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
static {...}
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

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.gallery;
27:
28: import javax.annotation.Nonnull;
29: import java.util.ArrayList;
30: import java.util.HashMap;
31: import java.util.List;
32: import java.util.Map;
33: import org.springframework.beans.factory.BeanFactory;
34: import it.tidalwave.util.Finder;
35: import it.tidalwave.util.Id;
36: import it.tidalwave.util.spi.HierarchicFinderSupport;
37: import it.tidalwave.northernwind.core.model.RequestLocaleManager;
38: import it.tidalwave.northernwind.core.model.SiteNode;
39: import it.tidalwave.northernwind.frontend.ui.component.gallery.spi.GalleryAdapter;
40: import it.tidalwave.northernwind.frontend.ui.component.gallery.spi.GalleryLoader;
41: import it.tidalwave.northernwind.frontend.ui.component.gallery.spi.loader.SlideShowProPlayerGalleryLoader;
42: import it.tidalwave.northernwind.frontend.ui.component.nodecontainer.DefaultNodeContainerViewController;
43: import it.tidalwave.northernwind.frontend.ui.component.nodecontainer.NodeContainerView;
44: import it.tidalwave.northernwind.frontend.ui.spi.VirtualSiteNode;
45: import lombok.RequiredArgsConstructor;
46: import lombok.extern.slf4j.Slf4j;
47: import static java.util.stream.Collectors.*;
48:
49: /***************************************************************************************************************************************************************
50: *
51: * @author Fabrizio Giudici
52: *
53: **************************************************************************************************************************************************************/
54: @Slf4j
55: public class DefaultGalleryViewController extends DefaultNodeContainerViewController implements GalleryViewController
56: {
57: /***********************************************************************************************************************************************************
58: * A {@link Finder} which returns virtual {@link SiteNode}s representing the multiple contents served by the
59: * {@link SiteNode} associated to this controller. This is typically used to create site maps.
60: **********************************************************************************************************************************************************/
61: @RequiredArgsConstructor
62: private static class VirtualSiteNodeFinder extends HierarchicFinderSupport<SiteNode, VirtualSiteNodeFinder>
63: {
64: private static final long serialVersionUID = 1L;
65:
66: @Nonnull
67: private final transient DefaultGalleryViewController controller;
68:
69: public VirtualSiteNodeFinder (@Nonnull final VirtualSiteNodeFinder other, @Nonnull final Object override)
70: {
71: super(other, override);
72: final var source = getSource(VirtualSiteNodeFinder.class, other, override);
73: this.controller = source.controller;
74: }
75:
76: @Override @Nonnull
77: protected List<SiteNode> computeResults()
78: {
79: final var siteNode = controller.siteNode;
80: final List<SiteNode> result = controller.itemMapById.values().stream()
81: .map(gallery -> createVirtualNode(siteNode, gallery.getId().stringValue()))
82: .collect(toList());
83: result.add(0, createVirtualNode(siteNode, "lightbox"));
84: return result;
85: }
86:
87: @Nonnull
88: private static VirtualSiteNode createVirtualNode (@Nonnull final SiteNode siteNode, final String relativeUri)
89: {
90: return new VirtualSiteNode(siteNode,
91: siteNode.getRelativeUri().appendedWith(relativeUri),
92: siteNode.getProperties());
93: }
94: }
95:
96: @Nonnull
97: private final SiteNode siteNode;
98:
99: @Nonnull
100: private final BeanFactory beanFactory;
101:
102: @Nonnull
103: protected GalleryAdapter galleryAdapter;
104:
105: protected final List<GalleryItem> items = new ArrayList<>();
106:
107: protected final Map<Id, GalleryItem> itemMapById = new HashMap<>();
108:
109: /***********************************************************************************************************************************************************
110: *
111: **********************************************************************************************************************************************************/
112: public DefaultGalleryViewController (@Nonnull final NodeContainerView view,
113: @Nonnull final SiteNode siteNode,
114: @Nonnull final RequestLocaleManager requestLocaleManager,
115: @Nonnull final BeanFactory beanFactory)
116: {
117: super(view, siteNode, requestLocaleManager);
118: this.siteNode = siteNode;
119: this.beanFactory = beanFactory;
120: }
121:
122: /***********************************************************************************************************************************************************
123: * {@inheritDoc}
124: **********************************************************************************************************************************************************/
125: @Override
126: public void initialize()
127: throws Exception
128: {
129: super.initialize();
130: log.info("initialize() - {}", siteNode.getRelativeUri());
131: final var time = System.currentTimeMillis();
132: final GalleryLoader loader = new SlideShowProPlayerGalleryLoader(beanFactory, siteNode.getProperties()); // FIXME: make it configurable
133: items.addAll(loader.loadGallery(siteNode));
134: itemMapById.putAll(items.stream().collect(toMap(GalleryItem::getId, i -> i)));
135: log.info(">>>> {} gallery items loaded in {} msec", items.size(), System.currentTimeMillis() - time);
136: }
137:
138: /***********************************************************************************************************************************************************
139: * {@inheritDoc}
140: **********************************************************************************************************************************************************/
141: @Override @Nonnull
142: public Finder<SiteNode> findVirtualSiteNodes()
143: {
144: return new VirtualSiteNodeFinder(this);
145: }
146: }