Package: DefaultGalleryViewController
DefaultGalleryViewController
name | instruction | branch | complexity | line | method | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
DefaultGalleryViewController(NodeContainerView, SiteNode, RequestLocaleManager, BeanFactory) |
|
|
|
|
|
||||||||||||||||||||
findVirtualSiteNodes() |
|
|
|
|
|
||||||||||||||||||||
initialize() |
|
|
|
|
|
||||||||||||||||||||
lambda$initialize$0(GalleryViewController.GalleryItem) |
|
|
|
|
|
||||||||||||||||||||
static {...} |
|
|
|
|
|
Coverage
1: /*
2: * #%L
3: * *********************************************************************************************************************
4: *
5: * NorthernWind - lightweight CMS
6: * http://northernwind.tidalwave.it - git clone https://bitbucket.org/tidalwave/northernwind-src.git
7: * %%
8: * Copyright (C) 2011 - 2023 Tidalwave s.a.s. (http://tidalwave.it)
9: * %%
10: * *********************************************************************************************************************
11: *
12: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
13: * the License. You may obtain a copy of the License at
14: *
15: * http://www.apache.org/licenses/LICENSE-2.0
16: *
17: * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
18: * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
19: * specific language governing permissions and limitations under the License.
20: *
21: * *********************************************************************************************************************
22: *
23: *
24: * *********************************************************************************************************************
25: * #L%
26: */
27: package it.tidalwave.northernwind.frontend.ui.component.gallery;
28:
29: import javax.annotation.Nonnull;
30: import java.util.ArrayList;
31: import java.util.HashMap;
32: import java.util.List;
33: import java.util.Map;
34: import org.springframework.beans.factory.BeanFactory;
35: import it.tidalwave.util.Finder;
36: import it.tidalwave.util.Id;
37: import it.tidalwave.util.spi.HierarchicFinderSupport;
38: import it.tidalwave.northernwind.core.model.RequestLocaleManager;
39: import it.tidalwave.northernwind.core.model.SiteNode;
40: import it.tidalwave.northernwind.frontend.ui.component.gallery.spi.GalleryAdapter;
41: import it.tidalwave.northernwind.frontend.ui.component.gallery.spi.GalleryLoader;
42: import it.tidalwave.northernwind.frontend.ui.component.gallery.spi.loader.SlideShowProPlayerGalleryLoader;
43: import it.tidalwave.northernwind.frontend.ui.component.nodecontainer.DefaultNodeContainerViewController;
44: import it.tidalwave.northernwind.frontend.ui.component.nodecontainer.NodeContainerView;
45: import it.tidalwave.northernwind.frontend.ui.spi.VirtualSiteNode;
46: import lombok.RequiredArgsConstructor;
47: import lombok.extern.slf4j.Slf4j;
48: import static java.util.stream.Collectors.*;
49:
50: /***********************************************************************************************************************
51: *
52: * @author Fabrizio Giudici
53: *
54: **********************************************************************************************************************/
55: @Slf4j
56: public class DefaultGalleryViewController extends DefaultNodeContainerViewController implements GalleryViewController
57: {
58: /*******************************************************************************************************************
59: *
60: * A {@link Finder} which returns virtual {@link SiteNode}s representing the multiple contents served by the
61: * {@link SiteNode} associated to this controller. This is typically used to create site maps.
62: *
63: ******************************************************************************************************************/
64: @RequiredArgsConstructor
65: private static class VirtualSiteNodeFinder extends HierarchicFinderSupport<SiteNode, VirtualSiteNodeFinder>
66: {
67: private static final long serialVersionUID = 1L;
68:
69: @Nonnull
70: private final transient DefaultGalleryViewController controller;
71:
72: public VirtualSiteNodeFinder (@Nonnull final VirtualSiteNodeFinder other, @Nonnull final Object override)
73: {
74: super(other, override);
75: final var source = getSource(VirtualSiteNodeFinder.class, other, override);
76: this.controller = source.controller;
77: }
78:
79: @Override @Nonnull
80: protected List<SiteNode> computeResults()
81: {
82: final var siteNode = controller.siteNode;
83: final List<SiteNode> result = controller.itemMapById.values().stream()
84: .map(gallery -> createVirtualNode(siteNode, gallery.getId().stringValue()))
85: .collect(toList());
86: result.add(0, createVirtualNode(siteNode, "lightbox"));
87: return result;
88: }
89:
90: @Nonnull
91: private static VirtualSiteNode createVirtualNode (@Nonnull final SiteNode siteNode, final String relativeUri)
92: {
93: return new VirtualSiteNode(siteNode,
94: siteNode.getRelativeUri().appendedWith(relativeUri),
95: siteNode.getProperties());
96: }
97: }
98:
99: @Nonnull
100: private final SiteNode siteNode;
101:
102: @Nonnull
103: private final BeanFactory beanFactory;
104:
105: @Nonnull
106: protected GalleryAdapter galleryAdapter;
107:
108: protected final List<GalleryItem> items = new ArrayList<>();
109:
110: protected final Map<Id, GalleryItem> itemMapById = new HashMap<>();
111:
112: /*******************************************************************************************************************
113: *
114: *
115: ******************************************************************************************************************/
116: public DefaultGalleryViewController (@Nonnull final NodeContainerView view,
117: @Nonnull final SiteNode siteNode,
118: @Nonnull final RequestLocaleManager requestLocaleManager,
119: @Nonnull final BeanFactory beanFactory)
120: {
121: super(view, siteNode, requestLocaleManager);
122: this.siteNode = siteNode;
123: this.beanFactory = beanFactory;
124: }
125:
126: /*******************************************************************************************************************
127: *
128: * {@inheritDoc}
129: *
130: ******************************************************************************************************************/
131: @Override
132: public void initialize()
133: throws Exception
134: {
135: super.initialize();
136: log.info("initialize() - {}", siteNode.getRelativeUri());
137: final var time = System.currentTimeMillis();
138: final GalleryLoader loader = new SlideShowProPlayerGalleryLoader(beanFactory, siteNode.getProperties()); // FIXME: make it configurable
139: items.addAll(loader.loadGallery(siteNode));
140: itemMapById.putAll(items.stream().collect(toMap(GalleryItem::getId, i -> i)));
141: log.info(">>>> {} gallery items loaded in {} msec", items.size(), System.currentTimeMillis() - time);
142: }
143:
144: /*******************************************************************************************************************
145: *
146: * {@inheritDoc}
147: *
148: ******************************************************************************************************************/
149: @Override @Nonnull
150: public Finder<SiteNode> findVirtualSiteNodes()
151: {
152: return new VirtualSiteNodeFinder(this);
153: }
154: }