001/*
002 * Copyright (C) 2014 konik.io
003 *
004 * This file is part of Konik library.
005 *
006 * Konik library is free software: you can redistribute it and/or modify
007 * it under the terms of the GNU Affero General Public License as published by
008 * the Free Software Foundation, either version 3 of the License, or
009 * (at your option) any later version.
010 *
011 * Konik library is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014 * GNU Affero General Public License for more details.
015 *
016 * You should have received a copy of the GNU Affero General Public License
017 * along with Konik library.  If not, see <http://www.gnu.org/licenses/>.
018 */
019package io.konik.zugferd.entity;
020
021import io.konik.validator.annotation.Basic;
022import io.konik.validator.annotation.Comfort;
023import io.konik.validator.annotation.Extended;
024import io.konik.validator.annotation.NotBlank;
025import io.konik.zugferd.unqualified.ID;
026
027import javax.validation.Valid;
028import javax.xml.bind.annotation.XmlElement;
029import javax.xml.bind.annotation.XmlType;
030import javax.xml.bind.annotation.adapters.CollapsedStringAdapter;
031import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
032import java.io.Serializable;
033import java.util.ArrayList;
034import java.util.Collections;
035import java.util.List;
036
037/**
038 * = The Trade Party
039 * 
040 * Applies to a buyer, seller, order recipient or invoice recipient.
041 */
042@XmlType(name = "TradePartyType", propOrder = { "id", "globalIds", "name", "contact", "address", "taxRegistrations" })
043public class TradeParty implements Serializable {
044
045   @XmlElement(name = "ID")
046   @XmlJavaTypeAdapter(CollapsedStringAdapter.class)
047   private String id;
048
049   @XmlElement(name = "GlobalID")
050   private List<ID> globalIds;
051
052   @XmlElement(name = "Name")
053   private String name;
054
055   @XmlElement(name = "DefinedTradeContact")
056   private Contact contact;
057
058   @XmlElement(name = "PostalTradeAddress")
059   private Address address;
060
061   @XmlElement(name = "SpecifiedTaxRegistration")
062   private List<TaxRegistration> taxRegistrations;
063
064   /**
065    * Gets the vendor, customer or recipient number.
066    * 
067    * Example:: {@code The supplier number given by the customer/buyer }
068    * 
069    * @return the id
070    */
071   @Comfort
072   public String getId() {
073      return id;
074   }
075
076   /**
077    * Sets the the vendor, customer or recipient number.
078    * 
079    * Example:: {@code The supplier number given by the customer/buyer }
080    *
081    * @param id the new id
082    * @return the trade party
083    */
084   public TradeParty setId(String id) {
085      this.id = id;
086      return this;
087   }
088
089   /**
090    * Gets the global vendor number or customer number ids. 
091    * 
092    * Example:: GLN, DUNS, BIC, ODETTE
093    * 
094    * Example::
095    * - {@link ID#getValue()} {@code  GENODED1SPK, 4000001000005 } 
096    * - {@link ID#getSchemeId()} the ISO 6523 code {@code 0021, 0088, 0060, 0177 }
097    * 
098    * @return the global id
099    */
100   @Comfort
101   public List<ID> getGlobalIds() {
102      if (globalIds == null) {
103         globalIds = new ArrayList<ID>();
104      }
105      return this.globalIds;
106   }
107
108   /**
109    * Adds the global vendor number or customer number ID.
110    * 
111    * Example:: GLN, DUNS, BIC, ODETTE
112    * 
113    * Example::
114    * - {@link ID#getValue()} {@code  GENODED1SPK, 4000001000005 } 
115    * - {@link ID#getSchemeId()} the ISO 6523 code {@code 0021, 0088, 0060, 0177 }
116    * 
117    * @param additionalGlobalId the additional global id
118    * @return the trade party
119    */
120   public TradeParty addGlobalId(ID additionalGlobalId) {
121      getGlobalIds().add(additionalGlobalId);
122      return this;
123   }
124
125   /**
126    * Gets the trade party name. Usually the Company name.
127    * 
128    * Example:: {@code  ACME Inc.}
129    * 
130    * @return the trade party or company name
131    */
132   @Basic
133   @NotBlank
134   public String getName() {
135      return name;
136   }
137
138   /**
139    * Sets the trade party name. Usually the Company name.
140    * 
141    * Example:: {@code  ACME Inc.}
142    * 
143    * @param name the trade party or company name
144    * @return the trade party
145    */
146   public TradeParty setName(String name) {
147      this.name = name;
148      return this;
149   }
150
151   /**
152    * Gets the contact individual or department of the trade party
153    * 
154    * @return the trade party contact individual/department
155    */
156   @Valid
157   @Extended
158   public Contact getContact() {
159      return contact;
160   }
161
162   /**
163    * Sets the contact individual or department of the trade party
164    * 
165    * @param newContact the trade party contact individual/department
166    * @return the trade party
167    */
168   public TradeParty setContact(Contact newContact) {
169      this.contact = newContact;
170      return this;
171   }
172
173   /**
174    * Gets the postal trade address.
175    * 
176    * @return the postal trade address
177    */
178   @Valid
179   public Address getAddress() {
180      return address;
181   }
182
183   /**
184    * Sets the postal trade address.
185    * 
186    * @param postalAddress the new postal trade address
187    * @return the trade party
188    */
189   public TradeParty setAddress(Address postalAddress) {
190      this.address = postalAddress;
191      return this;
192   }
193
194   /**
195    * Gets the specified tax registration.
196    * 
197    * @return the specified tax registration
198    */
199   @Valid
200   public List<TaxRegistration> getTaxRegistrations() {
201      if (taxRegistrations == null) {
202         taxRegistrations = new ArrayList<TaxRegistration>();
203      }
204      return this.taxRegistrations;
205   }
206
207   /**
208    * Adds the tax registration.
209    * 
210    * @param additionalTaxRegistration an additional Tax Registration
211    * @return the trade party
212    */
213   public TradeParty addTaxRegistrations(TaxRegistration... additionalTaxRegistration) {
214      Collections.addAll(getTaxRegistrations(), additionalTaxRegistration);
215      return this;
216   }
217
218}