001 /*
002 * Copyright 2011 The Kuali Foundation.
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.kfs.module.ar.batch.report;
017
018 import java.util.ArrayList;
019 import java.util.List;
020 import java.util.Map;
021 import java.util.Set;
022 import java.util.TreeMap;
023
024 import org.kuali.kfs.module.ar.batch.report.CustomerLoadResult.EntryType;
025
026 public class CustomerLoadFileResult {
027
028 private String filename;
029 private List<String[]> messages;
030
031 // key=customerName, value=CustomerLoadResult
032 private Map<String,CustomerLoadResult> customers;
033
034 public CustomerLoadFileResult() {
035 customers = new TreeMap<String,CustomerLoadResult>();
036 messages = new ArrayList<String[]>();
037 }
038
039 public CustomerLoadFileResult(String filename) {
040 this.filename = filename;
041 customers = new TreeMap<String,CustomerLoadResult>();
042 messages = new ArrayList<String[]>();
043 }
044
045 public void addCustomerInfoMessage(String customerName, String message) {
046 CustomerLoadResult customer = getOrAddCustomer(customerName);
047 customer.addInfoMessage(message);
048 }
049
050 public void addCustomerErrorMessage(String customerName, String message) {
051 CustomerLoadResult customer = getOrAddCustomer(customerName);
052 customer.addErrorMessage(message);
053 }
054
055 public void setCustomerSuccessResult(String customerName) {
056 CustomerLoadResult customer = getOrAddCustomer(customerName);
057 customer.setSuccessResult();
058 }
059
060 public void setCustomerFailureResult(String customerName) {
061 CustomerLoadResult customer = getOrAddCustomer(customerName);
062 customer.setFailureResult();
063 }
064
065 public void setCustomerErrorResult(String customerName) {
066 CustomerLoadResult customer = getOrAddCustomer(customerName);
067 customer.setErrorResult();
068 }
069
070 public void setCustomerWorkflowDocId(String customerName, String workflowDocId) {
071 CustomerLoadResult customer = getOrAddCustomer(customerName);
072 customer.setWorkflowDocId(workflowDocId);
073 }
074
075 private CustomerLoadResult getOrAddCustomer(String customerName) {
076 if (!customers.containsKey(customerName)) {
077 customers.put(customerName, new CustomerLoadResult(filename, customerName));
078 }
079 return customers.get(customerName);
080 }
081
082 public String getFilename() {
083 return filename;
084 }
085
086 public List<String[]> getMessages() {
087 return messages;
088 }
089
090 public void addFileErrorMessage(String message) {
091 this.messages.add(new String[] { CustomerLoadResult.getEntryTypeString(EntryType.ERROR), message });
092 }
093
094 public void addFileInfoMessage(String message) {
095 this.messages.add(new String[] { CustomerLoadResult.getEntryTypeString(EntryType.INFO), message });
096 }
097
098 public Set<String> getCustomerNames() {
099 return this.customers.keySet();
100 }
101
102 public CustomerLoadResult getCustomer(String customerName) {
103 return customers.get(customerName);
104 }
105
106 }