Content of file DecoratorResourceFolder.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>DecoratorResourceFolder.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 :: Filesystems :: Basic</a> > <a href="index.source.html" class="el_package">it.tidalwave.northernwind.frontend.filesystem.basic.layered</a> > <span class="el_source">DecoratorResourceFolder.java</span></div><h1>DecoratorResourceFolder.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.filesystem.basic.layered;
import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;
import java.io.IOException;
import it.tidalwave.northernwind.core.model.ResourceFile;
import it.tidalwave.northernwind.core.model.ResourceFileSystemProvider;
import it.tidalwave.northernwind.core.model.ResourcePath;
import it.tidalwave.northernwind.core.model.spi.DecoratedResourceFileSupport;
import it.tidalwave.northernwind.core.model.spi.ResourceFileFinderSupport;
import lombok.ToString;
import lombok.experimental.Delegate;
import lombok.extern.slf4j.Slf4j;
import static java.util.Collections.*;
/***********************************************************************************************************************
*
* @author Fabrizio Giudici
*
**********************************************************************************************************************/
<span class="fc" id="L51">@Slf4j @ToString(of = "delegate")</span>
class DecoratorResourceFolder extends DecoratedResourceFileSupport
{
@Nonnull
private final ResourcePath path;
@Nonnull
private final List<? extends ResourceFileSystemProvider> delegates;
<span class="pc" id="L60"> @Delegate(types = ResourceFile.class, excludes = FolderDelegateExclusions.class) @Nonnull</span>
private final ResourceFile delegate;
private SortedMap<String, ResourceFile> childrenMap;
public DecoratorResourceFolder (@Nonnull final LayeredResourceFileSystem fileSystem,
@Nonnull final List<? extends ResourceFileSystemProvider> delegates,
@Nonnull final ResourcePath path,
@Nonnull final ResourceFile delegate)
{
<span class="fc" id="L70"> super(fileSystem, delegate);</span>
<span class="fc" id="L71"> this.path = path;</span>
<span class="fc" id="L72"> this.delegate = delegate;</span>
<span class="fc" id="L73"> this.delegates = delegates;</span>
<span class="fc" id="L74"> }</span>
@Override @Nonnull
public Finder findChildren()
{
<span class="fc" id="L79"> return ResourceFileFinderSupport.withComputeResults(finder -></span>
{
<span class="fc" id="L81"> final var name = finder.getName();</span>
<span class="fc" id="L82"> final var recursive = finder.isRecursive();</span>
<span class="pc bpc" id="L84" title="1 of 2 branches missed."> if (name != null)</span>
{
<span class="nc bnc" id="L86" title="All 2 branches missed."> if (name.contains("/"))</span>
{
<span class="nc" id="L88"> throw new IllegalArgumentException("relativePath: " + name);</span>
}
<span class="nc" id="L91"> final var child = getChildrenMap().get(name);</span>
<span class="nc bnc" id="L92" title="All 2 branches missed."> return (child != null) ? singletonList(child) : emptyList();</span>
}
//
// FIXME: this reproduces the behaviour before the refactoring for NW-192 - but it's (and was) wrong
| this reproduces the behaviour before the refactoring for NW-192 - but it's (and was) wrong | |
// since it doesn't consider delegates. It should be rewritten by relying on getChildrenMap() and
// making it eventually support recursion.
//
<span class="pc bpc" id="L99" title="1 of 2 branches missed."> else if (recursive)</span>
{
<span class="nc" id="L101"> return delegate.findChildren().withRecursion(recursive).results();</span>
}
else
{
<span class="fc" id="L105"> return new ArrayList<>(getChildrenMap().values());</span>
}
});
}
@Nonnull
private synchronized Map<String, ResourceFile> getChildrenMap()
{
<span class="pc bpc" id="L113" title="1 of 2 branches missed."> if (childrenMap == null)</span>
{
<span class="fc" id="L115"> childrenMap = new TreeMap<>();</span>
<span class="fc" id="L117"> for (final var i = delegates.listIterator(delegates.size());</span>
<span class="fc bfc" id="L118" title="All 2 branches covered."> i.hasPrevious(); )</span>
{
try
{
<span class="fc" id="L122"> final var fileSystem = i.previous().getFileSystem();</span>
<span class="fc" id="L123"> final var delegateDirectory = fileSystem.findFileByPath(path.asString());</span>
<span class="fc bfc" id="L125" title="All 2 branches covered."> if (delegateDirectory != null)</span>
{
<span class="fc bfc" id="L127" title="All 2 branches covered."> for (final var fileObject : delegateDirectory.findChildren().results())</span>
{
<span class="fc bfc" id="L129" title="All 2 branches covered."> if (!childrenMap.containsKey(fileObject.getName()))</span>
{
<span class="fc" id="L131"> childrenMap.put(fileObject.getName(), getFileSystem().createDecoratorFile(fileObject));</span>
}
<span class="fc" id="L133"> }</span>
}
}
<span class="nc" id="L136"> catch (IOException e)</span>
{
<span class="nc" id="L138"> log.warn("", e);</span>
<span class="pc" id="L139"> }</span>
}
<span class="fc" id="L142"> log.trace(">>>> childrenMap: {}", childrenMap);</span>
}
<span class="fc" id="L145"> return childrenMap;</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>