Content of file DefaultDataManagerPresentationControl.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>DefaultDataManagerPresentationControl.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">SolidBlue III :: Application no GUI</a> > <a href="index.source.html" class="el_package">it.tidalwave.datamanager.application.nogui.impl</a> > <span class="el_source">DefaultDataManagerPresentationControl.java</span></div><h1>DefaultDataManagerPresentationControl.java</h1><pre class="source lang-java linenums">/*
* *********************************************************************************************************************
*
* SolidBlue 3: Data safety
* http://tidalwave.it/projects/solidblue3
*
* Copyright (C) 2023 - 2023 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/solidblue3j-src
* git clone https://github.com/tidalwave-it/solidblue3j-src
*
* *********************************************************************************************************************
*/
package it.tidalwave.datamanager.application.nogui.impl;
import jakarta.annotation.Nonnull;
import java.util.List;
import java.util.Optional;
import java.util.function.Predicate;
import java.nio.file.Files;
import org.springframework.stereotype.Component;
import it.tidalwave.util.RoleFactory;
import it.tidalwave.role.SimpleComposite;
import it.tidalwave.role.ui.PresentationModel;
import it.tidalwave.datamanager.model.DataManager;
import it.tidalwave.datamanager.model.ManagedFile;
import it.tidalwave.datamanager.application.nogui.DataManagerPresentation;
import it.tidalwave.datamanager.application.nogui.DataManagerPresentationController;
import lombok.RequiredArgsConstructor;
import static it.tidalwave.util.Finder.SortDirection.ASCENDING;
import static it.tidalwave.util.spring.jpa.JpaRepositoryFinder.by;
import static it.tidalwave.role.ui.spi.PresentationModelCollectors.toCompositePresentationModel;
/***********************************************************************************************************************
*
* The default implementation of {@link DataManagerPresentationController}.
*
* @stereotype Presentation Control
* @author Fabrizio Giudici
*
**********************************************************************************************************************/
<span class="fc" id="L55">@Component @RequiredArgsConstructor</span>
public class DefaultDataManagerPresentationControl implements DataManagerPresentationController
{
@Nonnull
private final DataManager dataManager;
@Nonnull
private final DataManagerPresentation presentation;
/*******************************************************************************************************************
* {@inheritDoc}
******************************************************************************************************************/
@Override
public void renderManagedFiles (final boolean renderFingerprints,
@Nonnull final Optional<Integer> max,
@Nonnull final Optional<String> regex,
final boolean missing)
{
<span class="fc" id="L73"> final Predicate<ManagedFile> filter1 = __ -> true;</span>
<span class="fc" id="L74"> final var filter2 = regex.map(r -> filter1.and(mf -> mf.getPath().toString().matches(r))).orElse(filter1);</span>
<span class="pc bpc" id="L75" title="3 of 4 branches missed."> final var filter3 = !missing ? filter2 : filter2.and(mf -> !Files.exists(mf.getPath()));</span>
<span class="fc" id="L77"> final RoleFactory<ManagedFile> rf =</span>
<span class="fc bfc" id="L78" title="All 2 branches covered."> o -> SimpleComposite.ofCloned(renderFingerprints ? o.getFingerprints() : List.of());</span>
<span class="fc" id="L80"> final var pm = dataManager.findManagedFiles()</span>
<span class="fc" id="L81"> .sort(by("path"), ASCENDING)</span>
<span class="fc" id="L82"> .max(max)</span>
<span class="fc" id="L83"> .stream()</span>
<span class="fc" id="L84"> .filter(filter3)</span>
<span class="fc" id="L85"> .map(m -> PresentationModel.of(m, rf))</span>
// .map(m -> m.as(_Presentable_).createPresentationModel(rf)) TODO breaks test
<span class="fc" id="L87"> .collect(toCompositePresentationModel());</span>
<span class="fc" id="L88"> presentation.renderManagedFiles(pm);</span>
<span class="fc" id="L89"> }</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>