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