001/* Copyright (C) 2014 konik.io
002 *
003 * This file is part of the Konik library.
004 *
005 * The Konik library is free software: you can redistribute it and/or modify
006 * it under the terms of the GNU Affero General Public License as
007 * published by the Free Software Foundation, either version 3 of the
008 * License, or (at your option) any later version.
009 *
010 * The Konik library is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
013 * GNU Affero General Public License for more details.
014 *
015 * You should have received a copy of the GNU Affero General Public License
016 * along with the Konik library. If not, see <http://www.gnu.org/licenses/>.
017 */
018package io.konik.zugferd.entity;
019
020import io.konik.jaxb.adapter.ParameterProfileAdapter;
021import io.konik.validator.annotation.Basic;
022import io.konik.validator.annotation.Extended;
023import io.konik.zugferd.profile.ConformanceLevel;
024import io.konik.zugferd.profile.Profile;
025import io.konik.zugferd.unqualified.Indicator;
026
027import javax.validation.Valid;
028import javax.validation.constraints.NotNull;
029import javax.xml.bind.annotation.XmlAccessType;
030import javax.xml.bind.annotation.XmlAccessorType;
031import javax.xml.bind.annotation.XmlElement;
032import javax.xml.bind.annotation.XmlType;
033import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
034
035/**
036 * = The Exchanged Document Context
037 * 
038 * Grouping of the properties of the message.
039 */
040@XmlAccessorType(XmlAccessType.FIELD)
041@XmlType(name = "ExchangedDocumentContextType", propOrder = { "test", "businessProcess", "guideline" })
042public class Context {
043
044   @XmlElement(name = "TestIndicator")
045   private Indicator test;
046
047   @Valid
048   @XmlElement(name = "BusinessProcessSpecifiedDocumentContextParameter")
049   private Parameter businessProcess;
050
051   @NotNull
052   @Valid
053   @XmlElement(name = "GuidelineSpecifiedDocumentContextParameter", required = true)
054   @XmlJavaTypeAdapter(ParameterProfileAdapter.class)
055   private Profile guideline;
056
057   /**
058    * Instantiates a new context.
059    */
060   public Context() {
061   }
062
063   /**
064    * Instantiates a new context with a latest version profile.
065    *
066    * @param conformanceLevel the profile
067    */
068   public Context(ConformanceLevel conformanceLevel) {
069      this.guideline = new Profile(conformanceLevel);
070   }
071
072   /**
073    * The test indicator.
074    * 
075    * Flags the invoice such that it should not be processed in the target system.
076    * 
077    * The sales tax liability does not arise. This flag is used in particular in the introductory period of new business
078    * relationships.
079    * 
080    * Profile:: BASIC
081    * 
082    * Default:: +false+
083    * 
084    * @return true if this invoice is for testing purpose only
085    */
086   @Basic
087   public boolean isTest() {
088      if (test == null) { return false; }
089      return test.getIndicator();
090   }
091
092   /**
093    * The test indicator.
094    * 
095    * Flags the invoice such that it should not be processed in the target system.
096    * 
097    * Profile:: BASIC
098    * 
099    * Default:: +false+
100    *
101    * @return the context
102    */
103   public Context setTest() {
104      this.test = Indicator.trueIndicator();
105      return this;
106   }
107
108   /**
109    * The test indicator.
110    * 
111    * Flags the invoice such that it should not be processed in the target system.
112    * 
113    * The sales tax liability does not arise. This flag is used in particular in the introductory period of new business
114    * relationships.
115    * 
116    * Profile:: BASIC
117    * 
118    * Default:: +false+
119    *
120    * @return the context
121    */
122   public Context setNotTest() {
123      this.test = Indicator.falseIndicator();
124      return this;
125   }
126
127   /**
128    * Gets the business process.
129    *
130    * Profile:: EXTENDED
131    *
132    * Example:: production Materials, other Materials, freight Invoices
133    *
134    * @return the business process
135    */
136   @Extended
137   public String getBusinessProcess() {
138      return businessProcess == null ? null : businessProcess.getId();
139   }
140
141   /**
142    * Sets the business process.
143    * 
144    * Profile:: EXTENDED
145    * 
146    * Example:: production Materials, other Materials, freight Invoices
147    * 
148    * @param businessProcess the new business process
149    * @return the context
150    */
151   public Context setBusinessProcess(String businessProcess) {
152      this.businessProcess = new Parameter(businessProcess);
153      return this;
154   }
155
156   /**
157    * Gets the guideline or profile of the invoice
158    * 
159    * Profile:: BASIC
160    * 
161    * Example:: +urn:ferd:CrossIndustryDocument:invoice:1p0:extended+
162    * 
163    * @return the profile
164    */
165   @Basic
166   public Profile getGuideline() {
167      return this.guideline;
168   }
169
170   /**
171    * Sets the guideline or profile of the invoice
172    * 
173    * Profile:: BASIC
174    * 
175    * Example:: +urn:ferd:CrossIndustryDocument:invoice:1p0:extended+
176    *
177    * @param guideline the new profile
178    * @return the context
179    */
180   public Context setGuideline(Profile guideline) {
181      this.guideline = guideline;
182      return this;
183   }
184}