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 * This class represents a full file which can be separated into a number of logical files, each logical file
010 * holding its own set of errors, warnings, and informative messages for post-processing 
011 */
012public class PhysicalFlatFileInformation {
013    private String fileName;
014    private List<String[]> messages;
015    private List<FlatFileInformation> flatFileInfomationList;
016    
017    /**
018     * Constructs a PhysicalFlatFileInformation
019     * @param fileName the name of the file this encapsulates
020     */
021    public PhysicalFlatFileInformation(String fileName) {
022        this.fileName = fileName;
023        messages = new ArrayList<String[]>();
024        flatFileInfomationList = new ArrayList<FlatFileInformation>();
025    }
026    
027    public void addFileErrorMessages(List<String> messages) {
028        for(String message : messages) {
029            this.messages.add(new String[] { FlatFileTransactionInformation.getEntryTypeString(FlatFileTransactionInformation.EntryType.ERROR), message });
030        }
031    }
032    
033    /**
034     * Adds an error message applicable to the entire file
035     * @param message
036     */
037    public void addFileErrorMessage(String message) {
038        this.messages.add(new String[] { FlatFileTransactionInformation.getEntryTypeString(FlatFileTransactionInformation.EntryType.ERROR), message });
039    }
040    
041    public void addFileInfoMessage(List<String> messages) {
042        for(String message : messages) {
043            this.messages.add(new String[] { FlatFileTransactionInformation.getEntryTypeString(FlatFileTransactionInformation.EntryType.INFO), message });
044        }
045    }
046
047    /**
048     * Adds an informative message applicable to the entire file
049     * @param message
050     */
051    public void addFileInfoMessage(String message) {
052        this.messages.add(new String[] { FlatFileTransactionInformation.getEntryTypeString(FlatFileTransactionInformation.EntryType.INFO), message });
053    }
054
055    /**
056     * @return the file name of the physical file encapsulated in this PhysicalFlatFileInformation object
057     */
058    public String getFileName() {
059        return fileName;
060    }
061
062    /**
063     * Sets the file name of the physical file encapsulated in this PhysicalFlatFileInformation object
064     * @param fileName the file name of the physical file encapsulated in this PhysicalFlatFileInformation object
065     */
066    public void setFileName(String fileName) {
067        this.fileName = fileName;
068    }
069
070    /**
071     * @return a List of all messages associated with the physical file as a whole
072     */
073    public List<String[]> getMessages() {
074        return messages;
075    }
076    
077    public String getAllMessages() {
078        StringBuffer message = new StringBuffer();
079        for(String[] resultMessage : getMessages()) {
080            message.append(resultMessage[1]);
081            message.append("\n");
082        }
083        return message.toString();
084    }
085    
086    /**
087     * Sets a List of messages associated with the physical file as a whole
088     * @param messages a List of messages
089     */
090    public void setMessages(List<String[]> messages) {
091        this.messages = messages;
092    }
093
094
095    /**
096     * @return a List of the FlatFileInformation objects, each representing a logical file within this physical file
097     */
098    public List<FlatFileInformation> getFlatFileInfomationList() {
099        return flatFileInfomationList;
100    }
101
102
103    /**
104     * Sets the List of FlatFileInformation objects, each representing a logical file within the encapsulated physical file
105     * @param flatFileInfomationList
106     */
107    public void setFlatFileInfomationList(List<FlatFileInformation> flatFileInfomationList) {
108        this.flatFileInfomationList = flatFileInfomationList;
109    }
110}