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