001package org.kuali.ole.sys.batch; 002 003import java.util.ArrayList; 004import java.util.HashMap; 005import java.util.List; 006import java.util.Map; 007 008/** 009 * A holder of error messages and informative messages associated with a single logical file within a larger physical file 010 */ 011public class FlatFileInformation { 012 private String fileName; 013 private List<String[]> messages; 014 private Map<String, FlatFileTransactionInformation> flatFileIdentifierToTransactionInfomationMap; 015 016 /** 017 * Constructs a new FlatFileInformation 018 */ 019 public FlatFileInformation() { 020 messages = new ArrayList<String[]>(); 021 flatFileIdentifierToTransactionInfomationMap = new HashMap<String, FlatFileTransactionInformation>(); 022 } 023 024 /** 025 * Constructs a new FlatFileInformation 026 * @param fileName the file name of the physical file with the encapsulated logical file therein 027 */ 028 public FlatFileInformation(String fileName) { 029 this.fileName = fileName; 030 messages = new ArrayList<String[]>(); 031 flatFileIdentifierToTransactionInfomationMap = new HashMap<String, FlatFileTransactionInformation>(); 032 } 033 034 /** 035 * 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 036 * @param flatFileDataIdentifier the identifier of the transaction 037 * @param flatFileTransactionInformation the messages about that transaction 038 * @return the messages about the transaction, either just added or previously added 039 */ 040 public FlatFileTransactionInformation getOrAddFlatFileData(String flatFileDataIdentifier, FlatFileTransactionInformation flatFileTransactionInformation) { 041 if (!flatFileIdentifierToTransactionInfomationMap.containsKey(flatFileDataIdentifier)) { 042 flatFileIdentifierToTransactionInfomationMap.put(flatFileDataIdentifier, flatFileTransactionInformation); 043 } 044 return (FlatFileTransactionInformation) flatFileIdentifierToTransactionInfomationMap.get(flatFileDataIdentifier); 045 } 046 047 /** 048 * Adds an error message for this logical file 049 * @param message the error message 050 */ 051 public void addFileErrorMessage(String message) { 052 this.messages.add(new String[] { FlatFileTransactionInformation.getEntryTypeString(FlatFileTransactionInformation.EntryType.ERROR), message }); 053 } 054 055 /** 056 * Adds an informative message for this logical file 057 * @param message the informative message 058 */ 059 public void addFileInfoMessage(String message) { 060 this.messages.add(new String[] { FlatFileTransactionInformation.getEntryTypeString(FlatFileTransactionInformation.EntryType.INFO), message }); 061 } 062 063 /** 064 * @return the name of the physical file the logical file this holds messages for is associated with 065 */ 066 public String getFileName() { 067 return fileName; 068 } 069 070 /** 071 * Sets the name of the physical file the logical file this holds messages for is associated with 072 * @param fileName the name of the physical file the logical file this holds messages for is associated with 073 */ 074 public void setFileName(String fileName) { 075 this.fileName = fileName; 076 } 077 078 /** 079 * @return the full List of messages associated with this logical file 080 */ 081 public List<String[]> getMessages() { 082 return messages; 083 } 084 085 /** 086 * Sets the full List of messages associated with this logical file 087 * @param messages the List of messages 088 */ 089 public void setMessages(List<String[]> messages) { 090 this.messages = messages; 091 } 092 093 /** 094 * @return the map that associates the transaction identifier to its associated messages 095 */ 096 public Map<String, FlatFileTransactionInformation> getFlatFileIdentifierToTransactionInfomationMap() { 097 return flatFileIdentifierToTransactionInfomationMap; 098 } 099 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}