Content of file DefaultGalleryViewController.java.html
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../../jacoco-resources/report.css" type="text/css"/><link rel="shortcut icon" href="../../jacoco-resources/report.gif" type="image/gif"/><title>DefaultGalleryViewController.java</title><link rel="stylesheet" href="../../jacoco-resources/prettify.css" type="text/css"/><script type="text/javascript" src="../../jacoco-resources/prettify.js"></script></head><body onload="window['PR_TAB_WIDTH']=4;prettyPrint()"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../../index.html" class="el_report">NorthernWind :: Frontend :: Media</a> > <a href="../index.html" class="el_bundle">it-tidalwave-northernwind-frontend-components</a> > <a href="index.source.html" class="el_package">it.tidalwave.northernwind.frontend.ui.component.gallery</a> > <span class="el_source">DefaultGalleryViewController.java</span></div><h1>DefaultGalleryViewController.java</h1><pre class="source lang-java linenums">/*
* #%L
* *********************************************************************************************************************
*
* NorthernWind - lightweight CMS
* http://northernwind.tidalwave.it - git clone https://bitbucket.org/tidalwave/northernwind-src.git
* %%
* Copyright (C) 2011 - 2023 Tidalwave s.a.s. (http://tidalwave.it)
* %%
* *********************************************************************************************************************
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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 CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* *********************************************************************************************************************
*
*
* *********************************************************************************************************************
* #L%
*/
package it.tidalwave.northernwind.frontend.ui.component.gallery;
import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.BeanFactory;
import it.tidalwave.util.Finder;
import it.tidalwave.util.Id;
import it.tidalwave.util.spi.HierarchicFinderSupport;
import it.tidalwave.northernwind.core.model.RequestLocaleManager;
import it.tidalwave.northernwind.core.model.SiteNode;
import it.tidalwave.northernwind.frontend.ui.component.gallery.spi.GalleryAdapter;
import it.tidalwave.northernwind.frontend.ui.component.gallery.spi.GalleryLoader;
import it.tidalwave.northernwind.frontend.ui.component.gallery.spi.loader.SlideShowProPlayerGalleryLoader;
import it.tidalwave.northernwind.frontend.ui.component.nodecontainer.DefaultNodeContainerViewController;
import it.tidalwave.northernwind.frontend.ui.component.nodecontainer.NodeContainerView;
import it.tidalwave.northernwind.frontend.ui.spi.VirtualSiteNode;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import static java.util.stream.Collectors.*;
/***********************************************************************************************************************
*
* @author Fabrizio Giudici
*
**********************************************************************************************************************/
<span class="nc" id="L55">@Slf4j</span>
public class DefaultGalleryViewController extends DefaultNodeContainerViewController implements GalleryViewController
{
/*******************************************************************************************************************
*
* A {@link Finder} which returns virtual {@link SiteNode}s representing the multiple contents served by the
* {@link SiteNode} associated to this controller. This is typically used to create site maps.
*
******************************************************************************************************************/
<span class="nc" id="L64"> @RequiredArgsConstructor</span>
private static class VirtualSiteNodeFinder extends HierarchicFinderSupport<SiteNode, VirtualSiteNodeFinder>
{
private static final long serialVersionUID = 1L;
@Nonnull
private final transient DefaultGalleryViewController controller;
public VirtualSiteNodeFinder (@Nonnull final VirtualSiteNodeFinder other, @Nonnull final Object override)
{
<span class="nc" id="L74"> super(other, override);</span>
<span class="nc" id="L75"> final var source = getSource(VirtualSiteNodeFinder.class, other, override);</span>
<span class="nc" id="L76"> this.controller = source.controller;</span>
<span class="nc" id="L77"> }</span>
@Override @Nonnull
protected List<SiteNode> computeResults()
{
<span class="nc" id="L82"> final var siteNode = controller.siteNode;</span>
<span class="nc" id="L83"> final List<SiteNode> result = controller.itemMapById.values().stream()</span>
<span class="nc" id="L84"> .map(gallery -> createVirtualNode(siteNode, gallery.getId().stringValue()))</span>
<span class="nc" id="L85"> .collect(toList());</span>
<span class="nc" id="L86"> result.add(0, createVirtualNode(siteNode, "lightbox"));</span>
<span class="nc" id="L87"> return result;</span>
}
@Nonnull
private static VirtualSiteNode createVirtualNode (@Nonnull final SiteNode siteNode, final String relativeUri)
{
<span class="nc" id="L93"> return new VirtualSiteNode(siteNode,</span>
<span class="nc" id="L94"> siteNode.getRelativeUri().appendedWith(relativeUri),</span>
<span class="nc" id="L95"> siteNode.getProperties());</span>
}
}
@Nonnull
private final SiteNode siteNode;
@Nonnull
private final BeanFactory beanFactory;
@Nonnull
protected GalleryAdapter galleryAdapter;
<span class="nc" id="L108"> protected final List<GalleryItem> items = new ArrayList<>();</span>
<span class="nc" id="L110"> protected final Map<Id, GalleryItem> itemMapById = new HashMap<>();</span>
/*******************************************************************************************************************
*
*
******************************************************************************************************************/
public DefaultGalleryViewController (@Nonnull final NodeContainerView view,
@Nonnull final SiteNode siteNode,
@Nonnull final RequestLocaleManager requestLocaleManager,
@Nonnull final BeanFactory beanFactory)
{
<span class="nc" id="L121"> super(view, siteNode, requestLocaleManager);</span>
<span class="nc" id="L122"> this.siteNode = siteNode;</span>
<span class="nc" id="L123"> this.beanFactory = beanFactory;</span>
<span class="nc" id="L124"> }</span>
/*******************************************************************************************************************
*
* {@inheritDoc}
*
******************************************************************************************************************/
@Override
public void initialize()
throws Exception
{
<span class="nc" id="L135"> super.initialize();</span>
<span class="nc" id="L136"> log.info("initialize() - {}", siteNode.getRelativeUri());</span>
<span class="nc" id="L137"> final var time = System.currentTimeMillis();</span>
<span class="nc" id="L138"> final GalleryLoader loader = new SlideShowProPlayerGalleryLoader(beanFactory, siteNode.getProperties()); // FIXME: make it configurable</span>
<span class="nc" id="L139"> items.addAll(loader.loadGallery(siteNode));</span>
<span class="nc" id="L140"> itemMapById.putAll(items.stream().collect(toMap(GalleryItem::getId, i -> i)));</span>
<span class="nc" id="L141"> log.info(">>>> {} gallery items loaded in {} msec", items.size(), System.currentTimeMillis() - time);</span>
<span class="nc" id="L142"> }</span>
/*******************************************************************************************************************
*
* {@inheritDoc}
*
******************************************************************************************************************/
@Override @Nonnull
public Finder<SiteNode> findVirtualSiteNodes()
{
<span class="nc" id="L152"> return new VirtualSiteNodeFinder(this);</span>
}
}
</pre><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.8.9.202303310957</span></div></body></html>