001
002/* Copyright (C) 2014 konik.io
003 *
004 * This file is part of the Konik library.
005 *
006 * The 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
008 * published by the Free Software Foundation, either version 3 of the
009 * License, or (at your option) any later version.
010 *
011 * The 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 the Konik library. If not, see <http://www.gnu.org/licenses/>.
018 */
019package io.konik.zugferd.entity;
020
021import io.konik.jaxb.adapter.CountryAdapter;
022import io.konik.validator.annotation.Basic;
023import io.konik.validator.annotation.Comfort;
024import io.konik.validator.annotation.Extended;
025import io.konik.validator.annotation.NotBlank;
026import io.konik.zugferd.unqualified.ID;
027
028import java.util.ArrayList;
029import java.util.List;
030
031import javax.validation.Valid;
032import javax.xml.bind.annotation.XmlElement;
033import javax.xml.bind.annotation.XmlType;
034import javax.xml.bind.annotation.adapters.CollapsedStringAdapter;
035import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
036
037import com.neovisionaries.i18n.CountryCode;
038
039/**
040 * = The Trade Product
041 */
042@XmlType(name = "TradeProductType", propOrder = { "globalId", "sellerAssignedId", "buyerAssignedId", "name",
043      "description", "characteristics", "classifications", "origins", "containedProducts" })
044public class Product {
045
046   @XmlElement(name = "GlobalID")
047   private ID globalId;
048
049   @XmlElement(name = "SellerAssignedID")
050   @XmlJavaTypeAdapter(CollapsedStringAdapter.class)
051   private String sellerAssignedId;
052
053   @XmlElement(name = "BuyerAssignedID")
054   @XmlJavaTypeAdapter(CollapsedStringAdapter.class)
055   private String buyerAssignedId;
056
057   @XmlElement(name = "Name")
058   private String name;
059
060   @XmlElement(name = "Description")
061   private String description;
062   
063   @Valid
064   @XmlElement(name = "ApplicableProductCharacteristic")
065   private List<ProductCharacteristic> characteristics;
066
067   @XmlElement(name = "DesignatedProductClassification")
068   @Valid
069   private List<ProductClassification> classifications;
070
071   @Valid
072   @XmlElement(name = "OriginTradeCountry")
073   @XmlJavaTypeAdapter(value = CountryAdapter.class)
074   private List<CountryCode> origins;
075
076   @XmlElement(name = "IncludedReferencedProduct")
077   @Valid
078   private List<ReferencedProduct> containedProducts;
079
080   /**
081    * Gets the global id.
082    *
083    * @return the global id
084    */
085   @Comfort
086   @Valid
087   public ID getGlobalId() {
088      return globalId;
089   }
090
091   /**
092    * Sets the global id.
093    *
094    * @param productGlobalId the product global id
095    * @return the trade product
096    */
097   public Product setGlobalId(ID productGlobalId) {
098      this.globalId = productGlobalId;
099      return this;
100   }
101
102   /**
103    * Gets the seller assigned id.
104    *
105    * @return the seller assigned id
106    */
107   @Comfort
108   public String getSellerAssignedId() {
109      return sellerAssignedId;
110   }
111
112   /**
113    * Sets the seller assigned id.
114    *
115    * @param sellerAssignedId the new seller assigned id
116    * @return the trade product
117    */
118   public Product setSellerAssignedId(String sellerAssignedId) {
119      this.sellerAssignedId = sellerAssignedId;
120      return this;
121   }
122
123   /**
124    * Gets the buyer assigned id.
125    *
126    * @return the buyer assigned id
127    */
128   @Comfort
129   public String getBuyerAssignedId() {
130      return buyerAssignedId;
131   }
132
133   /**
134    * Sets the buyer assigned id.
135    *
136    * @param buyerAssignedId the new buyer assigned id
137    * @return the trade product
138    */
139   public Product setBuyerAssignedId(String buyerAssignedId) {
140      this.buyerAssignedId = buyerAssignedId;
141      return this;
142   }
143
144   /**
145    * Gets the product name.
146    *
147    * @return the name
148    */
149   @Basic
150   @NotBlank
151   public String getName() {
152      return name;
153   }
154
155   /**
156    * Sets the product name.
157    *
158    * @param name the new name
159    * @return the trade product
160    */
161   public Product setName(String name) {
162      this.name = name;
163      return this;
164   }
165
166   /**
167    * Gets the description.
168    *
169    * @return the description
170    */
171   @Comfort
172   public String getDescription() {
173      return description;
174   }
175
176   /**
177    * Sets the description.
178    *
179    * @param description the new description
180    * @return the product
181    */
182   public Product setDescription(String description) {
183      this.description = description;
184      return this;
185   }
186
187   /**
188    * Gets the characteristics.
189    *
190    * @return the characteristics
191    */
192   @Extended
193   @Valid
194   public List<ProductCharacteristic> getCharacteristics() {
195      if (characteristics == null) {
196         characteristics = new ArrayList<ProductCharacteristic>();
197      }
198      return characteristics;
199   }
200
201   /**
202    * Sets the characteristics.
203    *
204    * @param characteristic the characteristics
205    * @return the product
206    */
207   public Product addCharacteristic(ProductCharacteristic characteristic) {
208      getCharacteristics().add(characteristic);
209      return this;
210   }
211
212   /**
213    * Gets the classifications.
214    *
215    * @return the classifications
216    */
217   @Extended
218   @Valid
219   public List<ProductClassification> getClassifications() {
220      if (classifications == null) {
221         classifications = new ArrayList<ProductClassification>();
222      }
223      return classifications;
224   }
225
226   /**
227    * Add an additional classifications.
228    *
229    * @param classification the additional classifications
230    * @return the product
231    */
232   public Product addClassification(ProductClassification classification) {
233      getClassifications().add(classification);
234      return this;
235   }
236
237   /**
238    * Gets the origin trade country.
239    *
240    * @return the origin trade country
241    */
242   @Extended
243   public List<CountryCode> getOrigins() {
244      if (origins == null) {
245         origins = new ArrayList<CountryCode>();
246      }
247      return origins;
248   }
249
250   /**
251    * Adds a origin trade country.
252    *
253    * @param originCountry the additional origin country
254    * @return the trade product
255    */
256   public Product addOrigins(CountryCode originCountry) {
257      getOrigins().add(originCountry);
258      return this;
259   }
260
261   /**
262    * Gets the contained products.
263    *
264    * @return the contained products
265    */
266   @Extended
267   @Valid
268   public List<ReferencedProduct> getContainedProducts() {
269      if (containedProducts == null) {
270         containedProducts = new ArrayList<ReferencedProduct>();
271      }
272      return containedProducts;
273   }
274
275   /**
276    * add an contained products.
277    *
278    * @param containedProduct the contained product
279    * @return the product
280    */
281   public Product addContainedProducts(ReferencedProduct containedProduct) {
282      getContainedProducts().add(containedProduct);
283      return this;
284   }
285
286}