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.trade;
020
021import io.konik.zugferd.entity.trade.item.Item;
022
023import java.util.ArrayList;
024import java.util.List;
025
026import javax.validation.Valid;
027import javax.validation.constraints.NotNull;
028import javax.xml.bind.annotation.XmlAccessType;
029import javax.xml.bind.annotation.XmlAccessorType;
030import javax.xml.bind.annotation.XmlElement;
031import javax.xml.bind.annotation.XmlType;
032
033/**
034 * = The Trade transaction.
035 * 
036 * A Trade contains "global" agreements, delivery and settlement. On Item basis those parameters can be refined.
037 */
038@XmlAccessorType(XmlAccessType.FIELD)
039@XmlType(name = "SupplyChainTradeTransactionType", propOrder = { "agreement", "delivery", "settlement", "items" })
040public class Trade {
041
042   @NotNull
043   @Valid
044   @XmlElement(name = "ApplicableSupplyChainTradeAgreement")
045   private Agreement agreement;
046
047   @NotNull
048   @Valid
049   @XmlElement(name = "ApplicableSupplyChainTradeDelivery")
050   private Delivery delivery;
051
052   @NotNull
053   @Valid
054   @XmlElement(name = "ApplicableSupplyChainTradeSettlement")
055   private Settlement settlement;
056
057   @NotNull
058   @Valid
059   @XmlElement(name = "IncludedSupplyChainTradeLineItem")
060   private List<Item> items;
061
062   /**
063    * Gets the trade agreement.
064    *
065    * @return the agreement
066    */
067   public Agreement getAgreement() {
068      return agreement;
069   }
070
071   /**
072    * Sets the trade agreement.
073    *
074    * @param agreement the new agreement
075    * @return the trade
076    */
077   public Trade setAgreement(Agreement agreement) {
078      this.agreement = agreement;
079      return this;
080   }
081
082   /**
083    * Gets the trade delivery.
084    * 
085    * @return the trade delivery
086    */
087   public Delivery getDelivery() {
088      return delivery;
089   }
090
091   /**
092    * Sets the trade delivery.
093    * 
094    * @param delivery the new trade delivery
095    * @return the trade
096    */
097   public Trade setDelivery(Delivery delivery) {
098      this.delivery = delivery;
099      return this;
100   }
101
102   /**
103    * Gets the trade settlement.
104    * 
105    * @return the trade settlement
106    */
107   public Settlement getSettlement() {
108      return settlement;
109   }
110
111   /**
112    * Sets the trade settlement.
113    *
114    * @param tradeSettlement the new trade settlement
115    * @return the trade
116    */
117   public Trade setSettlement(Settlement tradeSettlement) {
118      this.settlement = tradeSettlement;
119      return this;
120   }
121
122   /**
123    * Gets the item.
124    * 
125    * @return the items
126    */
127   public List<Item> getItems() {
128      if (items == null) {
129         items = new ArrayList<Item>();
130      }
131      return this.items;
132   }
133
134   /**
135    * Adds an item.
136    * 
137    * @param item the item
138    * @return the trade
139    */
140   public Trade addItem(Item item) {
141      getItems().add(item);
142      return this;
143   }
144
145}