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.validator.annotation.Basic;
021import io.konik.validator.annotation.Comfort;
022import io.konik.validator.annotation.Extended;
023import io.konik.validator.annotation.NotEmpty;
024import io.konik.validator.annotation.NullableNotBlank;
025
026import java.util.ArrayList;
027import java.util.List;
028
029import javax.xml.bind.annotation.XmlElement;
030import javax.xml.bind.annotation.XmlType;
031import javax.xml.bind.annotation.adapters.CollapsedStringAdapter;
032import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
033
034/**
035 * = The Note
036 */
037@XmlType(name = "NoteType", propOrder = { "contentCode", "contents", "subjectCode" })
038public class Note {
039
040   @XmlElement(name = "ContentCode")
041   @XmlJavaTypeAdapter(CollapsedStringAdapter.class)
042   private String contentCode;
043
044   @XmlElement(name = "Content")
045   private List<String> contents;
046
047   @XmlElement(name = "SubjectCode")
048   @XmlJavaTypeAdapter(CollapsedStringAdapter.class)
049   private String subjectCode;
050
051   /** Instantiates a new note. */
052   public Note() {
053   }
054
055   /**
056    * Instantiates a new note without a content only.
057    *
058    * @param content the content
059    */
060   public Note(String content) {
061      super();
062      addContent(content);
063   }
064
065   /**
066    * Instantiates a new note.
067    *
068    * @param content the content
069    * @param subjectCode the subject code
070    */
071   public Note(String content, String subjectCode) {
072      super();
073      this.addContent(content);
074      this.subjectCode = subjectCode;
075   }
076
077   /**
078    * Gets the code related to the contend text
079    *
080    * @return the content code related to content free text
081    */
082   @Extended
083   @NullableNotBlank
084   public String getContentCode() {
085      return contentCode;
086   }
087
088   /**
089    * Sets the code related to the contend text
090    * 
091    * @param contentCode the content code related to content free text
092    * @return the note
093    */
094   public Note setContentCode(String contentCode) {
095      this.contentCode = contentCode;
096      return this;
097   }
098
099   /**
100    * Gets the human readable content.
101    *
102    * @return the content
103    */
104   @Basic(ifParent = Header.class)
105   @Comfort(ifParent = PositionDocument.class)
106   @NotEmpty
107   public List<String> getContents() {
108      if (contents == null) {
109         this.contents = new ArrayList<String>();
110      }
111      return this.contents;
112   }
113
114   /**
115    * Adds the free text content.
116    *
117    * @param content the additional content
118    * @return the note
119    */
120   public Note addContent(String content) {
121      getContents().add(content);
122      return this;
123   }
124
125   /**
126    * Gets the subject code.
127    * 
128    * @return the subject code
129    */
130   @Comfort(ifParent = Header.class)
131   @Extended(ifParent = PositionDocument.class)
132   @NullableNotBlank
133   public String getSubjectCode() {
134      return subjectCode;
135   }
136
137   /**
138    * Sets the subject code.
139    *
140    * @param subjectCode the new subject code
141    * @return the note
142    */
143   public Note setSubjectCode(String subjectCode) {
144      this.subjectCode = subjectCode;
145      return this;
146   }
147
148}