1 package org.kuali.ole.sys.batch;
2
3 import java.util.ArrayList;
4 import java.util.List;
5
6 /**
7 * An encapsulator for validation information associated with a logical file/top level header
8 */
9 public final class FlatFileTransactionInformation {
10 public enum ResultCode { SUCCESS, FAILURE, ERROR, INCOMPLETE }
11 public enum EntryType { INFO,WARN, ERROR }
12
13 private String flatFileDataIdentifier;
14 private ResultCode result;
15 private List<String[]> messages;
16
17 /**
18 * Constructs a FlatFileTransactionInformation
19 */
20 public FlatFileTransactionInformation() {
21 this.messages = new ArrayList<String[]>();
22 }
23
24 /**
25 * Constructs a FlatFileTransactionInformation
26 * @param flatFileDataIdentifier the identifier for the file the business object this object holds messages for was parsed from
27 */
28 public FlatFileTransactionInformation(String flatFileDataIdentifier) {
29 this.flatFileDataIdentifier = flatFileDataIdentifier;
30 this.result = ResultCode.INCOMPLETE;
31 this.messages = new ArrayList<String[]>();
32 }
33
34 /**
35 * Creates a String representation for the given entry type
36 * @param type the entry type to get a String representation for
37 * @return the String representation
38 */
39 public static String getEntryTypeString(EntryType type) {
40 if (type == null) return "UNKNOWN";
41 return type.name();
42 }
43
44 /**
45 * Creates a String representation for the given result code
46 * @param type the resultCode to get a String representation for
47 * @return the String representation
48 */
49 public static String getResultCodeString(ResultCode resultCode) {
50 if (resultCode == null) return "UNKNOWN";
51 return resultCode.name();
52 }
53
54 /**
55 * @return returns the resultCode for this transaction information object
56 */
57 public ResultCode getResult() {
58 return result;
59 }
60
61 /**
62 * @return returns a String representation of the resultCode for this transaction information object
63 */
64 public String getResultString() {
65 return getResultCodeString(result);
66 }
67
68 /**
69 * Sets the resultCode for this transaction information object
70 * @param result the result code to set
71 */
72 private void setResult(ResultCode result) {
73 this.result = result;
74 }
75
76 /**
77 * Declares the logical file a success!
78 */
79 public void setSuccessResult() {
80 this.result = ResultCode.SUCCESS;
81 }
82
83 /**
84 * Sets the result code to failure for the transaction
85 */
86 public void setFailureResult() {
87 this.result = ResultCode.FAILURE;
88 }
89
90 /**
91 * Sets the result code to error for the transaction
92 */
93 public void setErrorResult() {
94 this.result = ResultCode.ERROR;
95 }
96
97 /**
98 * @return the identifier for the flat file this is associated with
99 */
100 public String getFlatFileDataIdentifier() {
101 return flatFileDataIdentifier;
102 }
103
104 /**
105 * Sets the identifier for the flat file this is associated with
106 * @param flatFileDataIdentifier the identifier for the flat file this is associated with
107 */
108 public void setFlatFileDataIdentifier(String flatFileDataIdentifier) {
109 this.flatFileDataIdentifier = flatFileDataIdentifier;
110 }
111
112 /**
113 * @return the full List of messages associated with the transaction this is associated with
114 */
115 public List<String[]> getMessages() {
116 return messages;
117 }
118
119 /**
120 * Adds a message to the List of messages for this transaction
121 * @param entryType the kind of message being held
122 * @param message the message to hold
123 */
124 private void addMessage(EntryType entryType, String message) {
125 this.messages.add(new String[] { getEntryTypeString(entryType), message });
126 }
127
128 /**
129 * Adds an error message for this transaction
130 * @param message the message to explain the error
131 */
132 public void addErrorMessage(String message) {
133 addMessage(EntryType.ERROR, message);
134 }
135
136 /**
137 * Adds an informative message for this transaction
138 * @param message the informative message, hopefully something more explanatory than this javadoc
139 */
140 public void addInfoMessage(String message) {
141 addMessage(EntryType.INFO, message);
142 }
143
144 /**
145 * Adds a warning message for this transaction
146 * @param message the warning message
147 */
148 public void addWarnMessage(String message) {
149 addMessage(EntryType.WARN, message);
150 }
151 }