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.XmlElement;
030import javax.xml.bind.annotation.XmlType;
031import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
032
033/**
034 * = The Exchanged Document Context
035 * 
036 * Grouping of the properties of the message.
037 */
038@XmlType(name = "ExchangedDocumentContextType", propOrder = { "test", "businessProcess", "guideline" })
039public class Context {
040
041   @XmlElement(name = "TestIndicator")
042   private Indicator test;
043
044   @XmlElement(name = "BusinessProcessSpecifiedDocumentContextParameter")
045   private Parameter businessProcess;
046
047   @XmlElement(name = "GuidelineSpecifiedDocumentContextParameter", required = true)
048   @XmlJavaTypeAdapter(ParameterProfileAdapter.class)
049   private Profile guideline;
050
051   /**
052    * Instantiates a new context.
053    */
054   public Context() {
055   }
056
057   /**
058    * Instantiates a new context with a latest ZUGFeRD profile version.
059    *
060    * @param conformanceLevel the profile
061    */
062   public Context(ConformanceLevel conformanceLevel) {
063      this.guideline = new Profile(conformanceLevel);
064   }
065
066   /**
067    * Checks if that invoice is for test purposes only and should not be processed in the target system.
068    * 
069    * 
070    * Default:: +false+
071    * 
072    * @return true if this invoice is for testing purpose only
073    */
074   @Basic
075   public boolean isTest() {
076      if (test == null) { return false; }
077      return test.getIndicator();
078   }
079
080   /**
081    * Flags the invoice such that it should not be processed in the target system.
082    * The sales tax liability does **NOT** arise. 
083    * This flag is used in particular in the introductory period of new business relationships.
084    * 
085    * Default:: +false+
086    *
087    * @return the context
088    */
089   public Context setTest() {
090      this.test = Indicator.trueIndicator();
091      return this;
092   }
093
094   /**
095    * Flags the invoice such that it should be processed in the target system.
096    * 
097    * The sales tax liability **does** arise. 
098    * This flag is used in particular in the introductory period of new business relationships.
099    * 
100    * Default:: +false+
101    *
102    * @return the context
103    */
104   public Context setNotTest() {
105      this.test = Indicator.falseIndicator();
106      return this;
107   }
108
109   /**
110    * Gets the business process.
111    *
112    * Example:: production Materials, other Materials, freight Invoices
113    *
114    * @return the business process
115    */
116   @Extended
117   public String getBusinessProcess() {
118      return businessProcess == null ? null : businessProcess.getId();
119   }
120
121   /**
122    * Sets the business process.
123    * 
124    * Example:: production Materials, other Materials, freight Invoices
125    * 
126    * @param businessProcess the new business process
127    * @return the context
128    */
129   public Context setBusinessProcess(String businessProcess) {
130      this.businessProcess = new Parameter(businessProcess);
131      return this;
132   }
133
134   /**
135    * Gets the guideline or profile of the invoice
136    * 
137    * Example:: +urn:ferd:CrossIndustryDocument:invoice:1p0:extended+
138    * 
139    * @return the profile
140    */
141   @Basic
142   @NotNull
143   @Valid
144   public Profile getGuideline() {
145      return this.guideline;
146   }
147
148   /**
149    * Sets the guideline or profile of the invoice
150    * 
151    * Example:: +urn:ferd:CrossIndustryDocument:invoice:1p0:extended+
152    *
153    * @param guideline the new profile
154    * @return the context
155    */
156   public Context setGuideline(Profile guideline) {
157      this.guideline = guideline;
158      return this;
159   }
160}