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.IssueDateTimeAdapter;
021import io.konik.validator.annotation.Comfort;
022import io.konik.validator.annotation.NotBlank;
023
024import javax.xml.bind.annotation.XmlElement;
025import javax.xml.bind.annotation.XmlType;
026import javax.xml.bind.annotation.adapters.CollapsedStringAdapter;
027import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
028import java.io.Serializable;
029import java.util.Date;
030
031/**
032 * = The Referenced Document
033 * 
034 * References a external Document.
035 */
036@XmlType(name = "ReferencedDocumentType", propOrder = { "issued", "linePos", "typeCode", "id", "referenceType" })
037public class ReferencedDocument implements Serializable {
038
039   @XmlElement(name = "IssueDateTime")
040   @XmlJavaTypeAdapter(value = IssueDateTimeAdapter.class)
041   private Date issued;
042
043   @XmlElement(name = "LineID")
044   protected String linePos;
045
046   @XmlElement(name = "TypeCode")
047   @XmlJavaTypeAdapter(CollapsedStringAdapter.class)
048   protected String typeCode;
049
050   @XmlElement(name = "ID")
051   @XmlJavaTypeAdapter(CollapsedStringAdapter.class)
052   private String id;
053
054   @XmlElement(name = "ReferenceTypeCode")
055   @XmlJavaTypeAdapter(CollapsedStringAdapter.class)
056   protected String referenceType;
057
058   protected ReferencedDocument() {
059   }
060
061   /**
062    * The Constructor.
063    *
064    * @param identifier the id value of the referenced document
065    */
066   public ReferencedDocument(String identifier) {
067      super();
068      this.id = identifier;
069   }
070
071   /**
072    * Gets the issue date time.
073    * 
074    * @return the issue date time
075    */
076   @Comfort
077   public Date getIssued() {
078      return issued == null?null:new Date(issued.getTime());
079   }
080
081   /**
082    * Sets the issue date time.
083    * 
084    * @param issued the new issue date time
085    * @return the referenced document
086    */
087   public ReferencedDocument setIssued(Date issued) {
088      if (issued != null) {
089         this.issued = new Date(issued.getTime());
090      }
091      return this;
092   }
093
094   /**
095    * Sets the reference document identifier.
096    * 
097    * Examples:: Order number, document number, number of customer order, delivery note numbers
098    *
099    * @param referenceDocumentIdentifier the id of the document
100    * @return the referenced document
101    */
102   public ReferencedDocument setId(String referenceDocumentIdentifier) {
103      id = referenceDocumentIdentifier;
104      return this;
105   }
106
107   /**
108    * Gets the identifier.
109    * 
110    * Examples:: Order number, document number, number of customer order, delivery note numbers
111    * 
112    * @return the id the identifier of the referenced document
113    */
114   @Comfort
115   @NotBlank(groups = Comfort.class)
116   public String getId() {
117      return id;
118   }
119}