1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 package it.tidalwave.accounting.exporter.xml.impl.xml;
27
28 import javax.annotation.Nonnull;
29 import javax.xml.bind.annotation.XmlAccessorOrder;
30 import javax.xml.bind.annotation.XmlAccessorType;
31 import javax.xml.bind.annotation.XmlAttribute;
32 import javax.xml.bind.annotation.XmlElement;
33 import javax.xml.bind.annotation.XmlID;
34 import javax.xml.bind.annotation.XmlRootElement;
35 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
36 import it.tidalwave.accounting.exporter.xml.impl.adapters.IdAdapter;
37 import it.tidalwave.accounting.model.Customer;
38 import it.tidalwave.util.Id;
39 import lombok.Getter;
40 import lombok.NoArgsConstructor;
41 import static javax.xml.bind.annotation.XmlAccessOrder.ALPHABETICAL;
42 import static javax.xml.bind.annotation.XmlAccessType.FIELD;
43
44
45
46
47
48
49
50 @NoArgsConstructor
51 @XmlRootElement(name = "customer") @XmlAccessorType(FIELD) @XmlAccessorOrder(ALPHABETICAL)
52 public class CustomerXml
53 {
54 @Getter
55
56 @XmlAttribute(name = "id")
57 @XmlID
58 @XmlJavaTypeAdapter(IdAdapter.class)
59 private Id id;
60
61 @XmlElement(name = "name")
62 private String name;
63
64 @XmlElement(name = "billingAddress")
65 private AddressXml billingAddressXml;
66
67 @XmlElement(name = "vatNumber")
68 private String vatNumber;
69
70 public CustomerXml (@Nonnull final Customer customer)
71 {
72 final var builder = customer.toBuilder();
73 this.id = builder.getId();
74 this.name = builder.getName();
75 this.billingAddressXml = new AddressXml(builder.getBillingAddress());
76 this.vatNumber = builder.getVatNumber();
77 }
78
79 @Nonnull
80 public Customer.Builder toBuilder()
81 {
82 return new Customer.Builder().withId(id)
83 .withName(name)
84 .withBillingAddress(billingAddressXml.toAddress())
85 .withVatNumber(vatNumber);
86 }
87 }