Content of file DefaultContentDirectory.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>DefaultContentDirectory.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">blueMarine II :: Services :: StoppingDown</a> > <a href="../index.html" class="el_bundle">it-tidalwave-bluemarine2-mediaserver</a> > <a href="index.source.html" class="el_package">it.tidalwave.bluemarine2.mediaserver.impl</a> > <span class="el_source">DefaultContentDirectory.java</span></div><h1>DefaultContentDirectory.java</h1><pre class="source lang-java linenums">/*
* *********************************************************************************************************************
*
* blueMarine II: Semantic Media Centre
* http://tidalwave.it/projects/bluemarine2
*
* Copyright (C) 2015 - 2021 by 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.
*
* *********************************************************************************************************************
*
* git clone https://bitbucket.org/tidalwave/bluemarine2-src
* git clone https://github.com/tidalwave-it/bluemarine2-src
*
* *********************************************************************************************************************
*/
package it.tidalwave.bluemarine2.mediaserver.impl;
import javax.annotation.Nonnull;
import javax.annotation.PostConstruct;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.nio.file.Path;
import java.nio.file.Paths;
import org.springframework.beans.factory.annotation.Autowired;
import it.tidalwave.role.ui.Displayable;
import it.tidalwave.bluemarine2.model.MediaFolder;
import it.tidalwave.bluemarine2.model.VirtualMediaFolder;
import it.tidalwave.bluemarine2.model.VirtualMediaFolder.EntityCollectionFactory;
import it.tidalwave.bluemarine2.model.impl.PathAwareMediaFolderDecorator;
import it.tidalwave.bluemarine2.model.role.EntityBrowser;
import it.tidalwave.bluemarine2.model.spi.PathAwareEntity;
import it.tidalwave.bluemarine2.mediaserver.ContentDirectory;
import it.tidalwave.bluemarine2.mediaserver.spi.MediaServerService;
import lombok.extern.slf4j.Slf4j;
import static java.util.Comparator.*;
import static java.util.stream.Collectors.*;
import static it.tidalwave.util.Parameters.r;
import static it.tidalwave.role.Identifiable._Identifiable_;
/***********************************************************************************************************************
*
* @author Fabrizio Giudici
*
**********************************************************************************************************************/
<span class="fc" id="L58">@Slf4j</span>
<span class="fc" id="L59">public class DefaultContentDirectory implements ContentDirectory</span>
{
<span class="fc" id="L61"> private static final Path PATH_ROOT = Paths.get("/");</span>
<span class="fc" id="L63"> private static final Path PATH_VIDEOS = Paths.get("videos");</span>
<span class="fc" id="L65"> private static final Path PATH_PHOTOS = Paths.get("photos");</span>
<span class="fc" id="L67"> private static final Path PATH_MUSIC = Paths.get("music");</span>
<span class="fc" id="L69"> private static final Path PATH_SERVICES = Paths.get("services");</span>
<span class="fc" id="L71"> private static final EntityCollectionFactory EMPTY = x -> Collections.emptyList(); // FIXME: move to ECF</span>
// @Inject FIXME
<span class="fc" id="L74"> @Autowired(required = false)</span>
<span class="fc" id="L75"> private final List<EntityBrowser> entityBrowsers = Collections.emptyList();</span>
// @Inject FIXME
<span class="fc" id="L78"> @Autowired(required = false)</span>
<span class="fc" id="L79"> private final List<MediaServerService> services = Collections.emptyList();</span>
private MediaFolder root;
@Override @Nonnull
public MediaFolder findRoot()
{
<span class="fc" id="L86"> return root;</span>
}
@PostConstruct
private void initialize()
{
// FIXME: why is this called multiple times?
| why is this called multiple times? | |
<span class="fc" id="L93"> log.info(">>>> discovered entity browsers: {}", entityBrowsers);</span>
<span class="fc" id="L94"> log.info(">>>> discovered services: {}", services);</span>
<span class="fc" id="L95"> root = new VirtualMediaFolder(Optional.empty(), PATH_ROOT, "", this::childrenFactory);</span>
<span class="fc" id="L96"> }</span>
@Nonnull
private Collection<PathAwareEntity> childrenFactory (@Nonnull final MediaFolder parent)
{
<span class="fc" id="L101"> return List.of(new VirtualMediaFolder(parent, PATH_MUSIC, "Music", this::musicFactory),</span>
new VirtualMediaFolder(parent, PATH_PHOTOS, "Photos", EMPTY),
new VirtualMediaFolder(parent, PATH_VIDEOS, "Videos", EMPTY),
new VirtualMediaFolder(parent, PATH_SERVICES, "Services", this::servicesFactory));
}
@Nonnull
private Collection<MediaFolder> musicFactory (@Nonnull final MediaFolder parent)
{
// TODO: filter by MIME type
<span class="fc" id="L111"> return entityBrowsers.stream()</span>
<span class="fc" id="L112"> .sorted(comparing(browser -> browser.as(Displayable.class).getDisplayName()))</span>
<span class="fc" id="L113"> .map(browser -> createMediaFolder(parent, browser))</span>
<span class="fc" id="L114"> .collect(toList());</span>
}
@Nonnull
private Collection<MediaFolder> servicesFactory (@Nonnull final MediaFolder parent)
{
<span class="pc" id="L120"> return services.stream().map(service -> service.createRootFolder(parent)).collect(toList());</span>
}
@Nonnull
private static MediaFolder createMediaFolder (@Nonnull final MediaFolder parent,
@Nonnull final EntityBrowser browser)
{
<span class="fc" id="L127"> final String fallBack = browser.getClass().getSimpleName();</span>
<span class="pc" id="L128"> final String pathSegment = browser.maybeAs(_Identifiable_).map(i -> i.getId().stringValue()).orElse(fallBack);</span>
<span class="fc" id="L129"> final Displayable displayable = browser.maybeAs(Displayable.class).orElse(Displayable.of(fallBack));</span>
<span class="fc" id="L130"> log.trace("createMediaFolder({}, {}) - path: {} displayable: {}", parent, browser, pathSegment, displayable);</span>
<span class="fc" id="L131"> return new PathAwareMediaFolderDecorator(browser.getRoot(), parent, Paths.get(pathSegment), r(displayable));</span>
}
}
</pre><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.8.7.202105040129</span></div></body></html>