View Javadoc
1   /*
2    * The Kuali Financial System, a comprehensive financial management system for higher education.
3    * 
4    * Copyright 2005-2014 The Kuali Foundation
5    * 
6    * This program is free software: you can redistribute it and/or modify
7    * it under the terms of the GNU Affero General Public License as
8    * published by the Free Software Foundation, either version 3 of the
9    * License, or (at your option) any later version.
10   * 
11   * This program is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU Affero General Public License for more details.
15   * 
16   * You should have received a copy of the GNU Affero General Public License
17   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18   */
19  package org.kuali.kfs.sys.batch;
20  
21  import java.util.ArrayList;
22  import java.util.List;
23  
24  /**
25   * An encapsulator for validation information associated with a logical file/top level header
26   */
27  public final class FlatFileTransactionInformation {
28      public enum ResultCode { SUCCESS, FAILURE, ERROR, INCOMPLETE }
29      public enum EntryType { INFO,WARN, ERROR  }
30  
31      private String flatFileDataIdentifier;
32      private ResultCode result;
33      private List<String[]> messages;
34  
35      /**
36       * Constructs a FlatFileTransactionInformation
37       */
38      public FlatFileTransactionInformation() {
39          this.messages = new ArrayList<String[]>();
40      }
41  
42      /**
43       * Constructs a FlatFileTransactionInformation
44       * @param flatFileDataIdentifier the identifier for the file the business object this object holds messages for was parsed from
45       */
46      public FlatFileTransactionInformation(String flatFileDataIdentifier) {
47          this.flatFileDataIdentifier = flatFileDataIdentifier;
48          this.result = ResultCode.INCOMPLETE;
49          this.messages = new ArrayList<String[]>();
50      }
51  
52      /**
53       * Creates a String representation for the given entry type
54       * @param type the entry type to get a String representation for
55       * @return the String representation
56       */
57      public static String getEntryTypeString(EntryType type) {
58          if (type == null) {
59              return "UNKNOWN";
60          }
61          return type.name();
62      }
63  
64      /**
65       * Creates a String representation for the given result code
66       * @param type the resultCode to get a String representation for
67       * @return the String representation
68       */
69      public static String getResultCodeString(ResultCode resultCode) {
70          if (resultCode == null) {
71              return "UNKNOWN";
72          }
73          return resultCode.name();
74      }
75  
76      /**
77       * @return returns the resultCode for this transaction information object
78       */
79      public ResultCode getResult() {
80          return result;
81      }
82  
83      /**
84       * @return returns a String representation of the resultCode for this transaction information object
85       */
86      public String getResultString() {
87          return getResultCodeString(result);
88      }
89  
90      /**
91       * Sets the resultCode for this transaction information object
92       * @param result the result code to set
93       */
94      private void setResult(ResultCode result) {
95          this.result = result;
96      }
97  
98      /**
99       * Declares the logical file a success!
100      */
101     public void setSuccessResult() {
102         this.result = ResultCode.SUCCESS;
103     }
104 
105     /**
106      * Sets the result code to failure for the transaction
107      */
108     public void setFailureResult() {
109         this.result = ResultCode.FAILURE;
110     }
111 
112     /**
113      * Sets the result code to error for the transaction
114      */
115     public void setErrorResult() {
116         this.result = ResultCode.ERROR;
117     }
118 
119     /**
120      * @return the identifier for the flat file this is associated with
121      */
122     public String getFlatFileDataIdentifier() {
123         return flatFileDataIdentifier;
124     }
125 
126     /**
127      * Sets the identifier for the flat file this is associated with
128      * @param flatFileDataIdentifier the identifier for the flat file this is associated with
129      */
130     public void setFlatFileDataIdentifier(String flatFileDataIdentifier) {
131         this.flatFileDataIdentifier = flatFileDataIdentifier;
132     }
133 
134     /**
135      * @return the full List of messages associated with the transaction this is associated with
136      */
137     public List<String[]> getMessages() {
138         return messages;
139     }
140 
141     /**
142      * Adds a message to the List of messages for this transaction
143      * @param entryType the kind of message being held
144      * @param message the message to hold
145      */
146     private void addMessage(EntryType entryType, String message) {
147         this.messages.add(new String[] { getEntryTypeString(entryType), message });
148     }
149 
150     /**
151      * Adds an error message for this transaction
152      * @param message the message to explain the error
153      */
154     public void addErrorMessage(String message) {
155         addMessage(EntryType.ERROR, message);
156     }
157 
158     /**
159      * Adds an informative message for this transaction
160      * @param message the informative message, hopefully something more explanatory than this javadoc
161      */
162     public void addInfoMessage(String message) {
163         addMessage(EntryType.INFO, message);
164     }
165 
166     /**
167      * Adds a warning message for this transaction
168      * @param message the warning message
169      */
170     public void addWarnMessage(String message) {
171         addMessage(EntryType.WARN, message);
172     }
173 }