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