<?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>ResourceProperties.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 :: Core :: Default Marshalling</a> > <a href="../index.html" class="el_bundle">it-tidalwave-northernwind-core</a> > <a href="index.source.html" class="el_package">it.tidalwave.northernwind.core.model</a> > <span class="el_source">ResourceProperties.java</span></div><h1>ResourceProperties.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.core.model;
import javax.annotation.Nonnull;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
import java.io.IOException;
import it.tidalwave.util.As;
import it.tidalwave.util.Id;
import it.tidalwave.util.Key;
import it.tidalwave.util.NotFoundException;
import it.tidalwave.util.TypeSafeMap;
import it.tidalwave.role.Identifiable;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.ToString;
import lombok.With;
/***********************************************************************************************************************
*
* A bag of properties for a {@link Resource}s.
*
* @author Fabrizio Giudici
*
**********************************************************************************************************************/
public interface ResourceProperties extends As, Identifiable
{
/*******************************************************************************************************************
*
* A builder of a {@link ResourceProperties}.
*
******************************************************************************************************************/
<span class="nc" id="L64"> @AllArgsConstructor(access = AccessLevel.PRIVATE) @RequiredArgsConstructor</span>
<span class="nc" id="L65"> @Getter @ToString(exclude = "callBack")</span>
public final class Builder
{
// Workaround for a Lombok limitation with Wither and subclasses
@FunctionalInterface
public static interface CallBack
{
@Nonnull
public ResourceProperties build (@Nonnull Builder builder);
}
@Nonnull
<span class="nc" id="L77"> private final ModelFactory modelFactory;</span>
@Nonnull
<span class="nc" id="L80"> private final CallBack callBack;</span>
<span class="nc bnc" id="L82" title="All 2 branches missed."> @With</span>
<span class="nc" id="L83"> private Id id = new Id("");</span>
<span class="nc bnc" id="L85" title="All 2 branches missed."> @With @Deprecated</span>
<span class="nc" id="L86"> private Map<String, Object> values = Collections.emptyMap();</span>
<span class="nc bnc" id="L88" title="All 2 branches missed."> @With</span>
<span class="nc" id="L89"> private PropertyResolver propertyResolver = PropertyResolver.DEFAULT;</span>
@Nonnull
public ResourceProperties build()
{
<span class="nc" id="L94"> return callBack.build(this);</span>
}
/***************************************************************************************************************
*
* TODO: deprecate withValues(Map<String, Object>) and rename this to withValues().
*
**************************************************************************************************************/
@Nonnull
public Builder withSafeValues (@Nonnull final TypeSafeMap values)
{
<span class="nc" id="L105"> return withValues(values.asMap().entrySet().stream()</span>
<span class="nc" id="L106"> .collect(Collectors.toMap(e -> e.getKey().getName(), Map.Entry::getValue)));</span>
}
}
public static interface PropertyResolver // FIXME: drop this
drop this
{
<span class="nc" id="L112"> public static PropertyResolver DEFAULT = new PropertyResolver()</span>
<span class="nc" id="L113"> {</span>
@Nonnull
@Override
public <T> T resolveProperty (@Nonnull final Id propertyGroupId, @Nonnull final Key<T> key)
throws NotFoundException
{
<span class="nc" id="L119"> throw new NotFoundException(key.stringValue());</span>
}
};
@Nonnull
public <T> T resolveProperty (@Nonnull Id propertyGroupId, @Nonnull Key<T> key)
throws NotFoundException, IOException;
}
/*******************************************************************************************************************
*
* Retrieves a property.
*
* @param key the property key
* @return the property value
*
******************************************************************************************************************/
@Nonnull
public <T> Optional<T> getProperty (@Nonnull Key<? extends T> key);
/*******************************************************************************************************************
*
* Retrieves a property, searching through a sequence of keys.
*
* @param keys the property keys
* @return the property value
*
******************************************************************************************************************/
@Nonnull
public default <T> Optional<T> getProperty (@Nonnull final List<? extends Key<T>> keys)
{
<span class="nc" id="L150"> return keys.stream().flatMap(key -> getProperty(key).stream()).findFirst();</span>
}
/*******************************************************************************************************************
*
* Retrieves a subgroup of properties.
*
* @param id the id
* @return the property group
*
******************************************************************************************************************/
@Nonnull
public ResourceProperties getGroup (@Nonnull Id id);
/*******************************************************************************************************************
*
* Retrieves the collection of property keys.
*
* @return the property keys
*
******************************************************************************************************************/
@Nonnull
public Collection<Key<?>> getKeys();
/*******************************************************************************************************************
*
* Retrieves the collection of ids of groups.
*
* @return the group ids
*
******************************************************************************************************************/
@Nonnull
public Collection<Id> getGroupIds();
/*******************************************************************************************************************
*
* Returns a new instance with an additional property.
*
******************************************************************************************************************/
@Nonnull
public <T> ResourceProperties withProperty (@Nonnull Key<T> key, @Nonnull T value);
/*******************************************************************************************************************
*
* Returns a new instance without a property.
*
******************************************************************************************************************/
@Nonnull
public ResourceProperties withoutProperty (@Nonnull Key<?> key);
/*******************************************************************************************************************
*
* Returns a new instance with an additional property group.
*
******************************************************************************************************************/
@Nonnull
public ResourceProperties withProperties (@Nonnull ResourceProperties properties);
/*******************************************************************************************************************
*
* Returns a new instance which is the logical merge with other properties.
*
******************************************************************************************************************/
@Nonnull
public ResourceProperties merged (@Nonnull ResourceProperties properties);
/*******************************************************************************************************************
*
* Returns a clone with a new id.
*
******************************************************************************************************************/
@Nonnull
public ResourceProperties withId (@Nonnull Id id);
}
</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>