Content of file ResourcePropertiesJaxbMarshallable.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>ResourcePropertiesJaxbMarshallable.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 :: Webapp :: Commons</a> > <a href="../index.html" class="el_bundle">it-tidalwave-northernwind-core-marshalling-default</a> > <a href="index.source.html" class="el_package">it.tidalwave.northernwind.core.impl.io</a> > <span class="el_source">ResourcePropertiesJaxbMarshallable.java</span></div><h1>ResourcePropertiesJaxbMarshallable.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.impl.io;
import javax.annotation.Nonnull;
import javax.inject.Inject;
import java.util.Collection;
import java.util.TreeSet;
import java.io.IOException;
import java.io.OutputStream;
import jakarta.xml.bind.Marshaller;
import org.springframework.beans.factory.annotation.Configurable;
import it.tidalwave.util.Id;
import it.tidalwave.util.Key;
import it.tidalwave.dci.annotation.DciRole;
import it.tidalwave.role.io.Marshallable;
import it.tidalwave.northernwind.core.model.ResourceProperties;
import it.tidalwave.northernwind.core.impl.io.jaxb.ObjectFactory;
import it.tidalwave.northernwind.core.impl.io.jaxb.PropertiesJaxb;
import it.tidalwave.northernwind.core.impl.io.jaxb.PropertyJaxb;
import it.tidalwave.northernwind.core.impl.io.jaxb.ValuesJaxb;
import jakarta.xml.bind.JAXBException;
import lombok.extern.slf4j.Slf4j;
/***********************************************************************************************************************
*
* @author Fabrizio Giudici
*
**********************************************************************************************************************/
<span class="nc" id="L54">@DciRole(datumType = ResourceProperties.class) @Configurable @Slf4j</span>
public class ResourcePropertiesJaxbMarshallable implements Marshallable
{
@Nonnull
private final ResourceProperties resourceProperties;
@Inject
private ObjectFactory objectFactory;
@Inject
private Marshaller marshaller;
/*******************************************************************************************************************
*
*
******************************************************************************************************************/
public ResourcePropertiesJaxbMarshallable (@Nonnull final ResourceProperties resourceProperties)
<span class="nc bnc" id="L71" title="All 18 branches missed."> {</span>
<span class="nc" id="L72"> this.resourceProperties = resourceProperties;</span>
<span class="nc bnc" id="L73" title="All 4 branches missed."> }</span>
/*******************************************************************************************************************
*
* {@inheritDoc}
*
******************************************************************************************************************/
@Override
public void marshal (@Nonnull final OutputStream os)
throws IOException
{
try
{
<span class="nc" id="L86"> marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); // FIXME: set in Spring</span>
<span class="nc" id="L87"> marshaller.marshal(objectFactory.createProperties(marshal(resourceProperties)), os);</span>
}
<span class="nc" id="L89"> catch (JAXBException e)</span>
{
<span class="nc" id="L91"> throw new IOException("", e);</span>
<span class="nc" id="L92"> }</span>
<span class="nc" id="L93"> }</span>
/*******************************************************************************************************************
*
*
******************************************************************************************************************/
@Nonnull
private PropertiesJaxb marshal (@Nonnull final ResourceProperties properties)
{
<span class="nc" id="L102"> final PropertiesJaxb propertiesJaxb = objectFactory.createPropertiesJaxb();</span>
<span class="nc" id="L103"> final Id id = properties.getId();</span>
<span class="nc bnc" id="L105" title="All 2 branches missed."> if ("".equals(id.stringValue()))</span>
{
<span class="nc" id="L107"> propertiesJaxb.setVersion("1.0");</span>
}
else
{
<span class="nc" id="L111"> propertiesJaxb.setId(id.stringValue());</span>
}
<span class="nc bnc" id="L114" title="All 2 branches missed."> for (final Key<?> key : new TreeSet<>(properties.getKeys()))</span>
{
<span class="nc" id="L116"> final PropertyJaxb propertyJaxb = objectFactory.createPropertyJaxb();</span>
<span class="nc" id="L117"> propertyJaxb.setName(key.stringValue());</span>
<span class="nc" id="L118"> properties.getProperty(key).ifPresent(value -></span>
{
<span class="nc bnc" id="L120" title="All 2 branches missed."> if (value instanceof Collection)</span>
{
<span class="nc" id="L122"> final ValuesJaxb valuesJaxb = objectFactory.createValuesJaxb();</span>
<span class="nc" id="L123"> propertyJaxb.setValues(valuesJaxb);</span>
<span class="nc bnc" id="L125" title="All 2 branches missed."> for (final Object valueItem : (Collection<?>)value)</span>
{
<span class="nc" id="L127"> valuesJaxb.getValue().add(valueItem.toString());</span>
<span class="nc" id="L128"> }</span>
<span class="nc" id="L129"> }</span>
else
{
<span class="nc" id="L132"> propertyJaxb.setValue(value.toString());</span>
}
<span class="nc" id="L135"> propertiesJaxb.getProperty().add(propertyJaxb);</span>
<span class="nc" id="L136"> });</span>
<span class="nc" id="L137"> }</span>
<span class="nc bnc" id="L139" title="All 2 branches missed."> for (final Id groupId : new TreeSet<>(properties.getGroupIds()))</span>
{
<span class="nc" id="L141"> propertiesJaxb.getProperties().add(marshal(properties.getGroup(groupId)));</span>
<span class="nc" id="L142"> }</span>
<span class="nc" id="L144"> return propertiesJaxb;</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>