CustomerXml.java

  1. /*
  2.  * *************************************************************************************************************************************************************
  3.  *
  4.  * blueHour: open source accounting
  5.  * http://tidalwave.it/projects/bluehour
  6.  *
  7.  * Copyright (C) 2013 - 2025 by Tidalwave s.a.s. (http://tidalwave.it)
  8.  *
  9.  * *************************************************************************************************************************************************************
  10.  *
  11.  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
  12.  * You may obtain a copy of the License at
  13.  *
  14.  *     http://www.apache.org/licenses/LICENSE-2.0
  15.  *
  16.  * 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
  17.  * CONDITIONS OF ANY KIND, either express or implied.  See the License for the specific language governing permissions and limitations under the License.
  18.  *
  19.  * *************************************************************************************************************************************************************
  20.  *
  21.  * git clone https://bitbucket.org/tidalwave/bluehour-src
  22.  * git clone https://github.com/tidalwave-it/bluehour-src
  23.  *
  24.  * *************************************************************************************************************************************************************
  25.  */
  26. package it.tidalwave.accounting.exporter.xml.impl.xml;

  27. import jakarta.annotation.Nonnull;
  28. import javax.xml.bind.annotation.XmlAccessorOrder;
  29. import javax.xml.bind.annotation.XmlAccessorType;
  30. import javax.xml.bind.annotation.XmlAttribute;
  31. import javax.xml.bind.annotation.XmlElement;
  32. import javax.xml.bind.annotation.XmlID;
  33. import javax.xml.bind.annotation.XmlRootElement;
  34. import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
  35. import it.tidalwave.accounting.exporter.xml.impl.adapters.IdAdapter;
  36. import it.tidalwave.accounting.model.Customer;
  37. import it.tidalwave.util.Id;
  38. import lombok.Getter;
  39. import lombok.NoArgsConstructor;
  40. import static javax.xml.bind.annotation.XmlAccessOrder.ALPHABETICAL;
  41. import static javax.xml.bind.annotation.XmlAccessType.FIELD;

  42. /***************************************************************************************************************************************************************
  43.  *
  44.  * @author  Fabrizio Giudici
  45.  *
  46.  **************************************************************************************************************************************************************/
  47. //@Mutable
  48. @NoArgsConstructor
  49. @XmlRootElement(name = "customer") @XmlAccessorType(FIELD) @XmlAccessorOrder(ALPHABETICAL)
  50. public class CustomerXml
  51.   {
  52.     @Getter // FIXME
  53.    
  54.     @XmlAttribute(name = "id")
  55.     @XmlID
  56.     @XmlJavaTypeAdapter(IdAdapter.class)
  57.     private Id id;

  58.     @XmlElement(name = "name")
  59.     private String name;

  60.     @XmlElement(name = "billingAddress")
  61.     private AddressXml billingAddressXml;

  62.     @XmlElement(name = "vatNumber")
  63.     private String vatNumber;
  64.    
  65.     public CustomerXml (@Nonnull final Customer customer)
  66.       {
  67.         final var builder = customer.toBuilder();
  68.         this.id = builder.getId();
  69.         this.name = builder.getName();
  70.         this.billingAddressXml = new AddressXml(builder.getBillingAddress());
  71.         this.vatNumber = builder.getVatNumber();
  72.       }
  73.    
  74.     @Nonnull
  75.     public Customer.Builder toBuilder()
  76.       {
  77.         return new Customer.Builder().withId(id)
  78.                                      .withName(name)
  79.                                      .withBillingAddress(billingAddressXml.toAddress())
  80.                                      .withVatNumber(vatNumber);
  81.       }
  82.   }