View Javadoc
1   package org.kuali.ole.sys.batch;
2   
3   import java.util.ArrayList;
4   import java.util.HashMap;
5   import java.util.List;
6   import java.util.Map;
7   
8   /**
9    * A holder of error messages and informative messages associated with a single logical file within a larger physical file
10   */
11  public class FlatFileInformation {
12      private String fileName;
13      private List<String[]> messages;
14      private Map<String, FlatFileTransactionInformation> flatFileIdentifierToTransactionInfomationMap;
15   
16      /**
17       * Constructs a new FlatFileInformation
18       */
19      public FlatFileInformation() {
20          messages = new ArrayList<String[]>();
21          flatFileIdentifierToTransactionInfomationMap = new HashMap<String, FlatFileTransactionInformation>();
22      }
23      
24      /**
25       * Constructs a new FlatFileInformation
26       * @param fileName the file name of the physical file with the encapsulated logical file therein
27       */
28      public FlatFileInformation(String fileName) {
29          this.fileName = fileName;
30          messages = new ArrayList<String[]>();
31          flatFileIdentifierToTransactionInfomationMap = new HashMap<String, FlatFileTransactionInformation>();
32      }
33  
34      /**
35       * Adds the given messages about a transaction to the map of transaction messages if necessary and returns the first set of messages about a transaction put into the map
36       * @param flatFileDataIdentifier the identifier of the transaction
37       * @param flatFileTransactionInformation the messages about that transaction
38       * @return the messages about the transaction, either just added or previously added
39       */
40      public FlatFileTransactionInformation getOrAddFlatFileData(String flatFileDataIdentifier, FlatFileTransactionInformation flatFileTransactionInformation) {
41          if (!flatFileIdentifierToTransactionInfomationMap.containsKey(flatFileDataIdentifier)) {
42              flatFileIdentifierToTransactionInfomationMap.put(flatFileDataIdentifier, flatFileTransactionInformation);
43          }
44          return (FlatFileTransactionInformation) flatFileIdentifierToTransactionInfomationMap.get(flatFileDataIdentifier);
45      }
46  
47      /**
48       * Adds an error message for this logical file
49       * @param message the error message
50       */
51      public void addFileErrorMessage(String message) {
52          this.messages.add(new String[] { FlatFileTransactionInformation.getEntryTypeString(FlatFileTransactionInformation.EntryType.ERROR), message });
53      }
54  
55      /**
56       * Adds an informative message for this logical file
57       * @param message the informative message
58       */
59      public void addFileInfoMessage(String message) {
60          this.messages.add(new String[] { FlatFileTransactionInformation.getEntryTypeString(FlatFileTransactionInformation.EntryType.INFO), message });
61      }
62  
63      /**
64       * @return the name of the physical file the logical file this holds messages for is associated with
65       */
66      public String getFileName() {
67          return fileName;
68      }
69  
70      /**
71       * Sets the name of the physical file the logical file this holds messages for is associated with
72       * @param fileName the name of the physical file the logical file this holds messages for is associated with
73       */
74      public void setFileName(String fileName) {
75          this.fileName = fileName;
76      }
77  
78      /**
79       * @return the full List of messages associated with this logical file
80       */
81      public List<String[]> getMessages() {
82          return messages;
83      }
84  
85      /**
86       * Sets the full List of messages associated with this logical file
87       * @param messages the List of messages
88       */
89      public void setMessages(List<String[]> messages) {
90          this.messages = messages;
91      }
92  
93      /**
94       * @return the map that associates the transaction identifier to its associated messages
95       */
96      public Map<String, FlatFileTransactionInformation> getFlatFileIdentifierToTransactionInfomationMap() {
97          return flatFileIdentifierToTransactionInfomationMap;
98      }
99  
100     /**
101      * Sets the map that associates the transaction identifier to its associated messages
102      * @param flatFileIdentifierToTransactionInfomationMap the map that associates the transaction identifier to its associated messages
103      */
104     public void setFlatFileIdentifierToTransactionInfomationMap(Map<String, FlatFileTransactionInformation> flatFileIdentifierToTransactionInfomationMap) {
105         this.flatFileIdentifierToTransactionInfomationMap = flatFileIdentifierToTransactionInfomationMap;
106     }
107 }