View Javadoc
1   /*
2    * Copyright 2007 The Kuali Foundation
3    * 
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    * http://www.opensource.org/licenses/ecl2.php
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.ole.gl.batch;
17  
18  import java.io.BufferedReader;
19  import java.io.FileReader;
20  import java.io.IOException;
21  import java.io.PrintStream;
22  import java.sql.Date;
23  import java.text.SimpleDateFormat;
24  import java.util.ArrayList;
25  import java.util.LinkedHashMap;
26  import java.util.List;
27  import java.util.Map;
28  
29  import org.apache.commons.io.IOUtils;
30  import org.apache.commons.lang.StringUtils;
31  import org.kuali.ole.coa.businessobject.Chart;
32  import org.kuali.ole.coa.businessobject.Organization;
33  import org.kuali.ole.gl.GeneralLedgerConstants;
34  import org.kuali.ole.gl.batch.service.RunDateService;
35  import org.kuali.ole.gl.batch.service.impl.OriginEntryTotals;
36  import org.kuali.ole.gl.businessobject.CollectorDetail;
37  import org.kuali.ole.gl.businessobject.CollectorHeader;
38  import org.kuali.ole.gl.businessobject.OriginEntryFull;
39  import org.kuali.ole.gl.businessobject.OriginEntryGroup;
40  import org.kuali.ole.gl.businessobject.OriginEntrySource;
41  import org.kuali.ole.gl.report.CollectorReportData;
42  import org.kuali.ole.gl.service.CollectorDetailService;
43  import org.kuali.ole.sys.OLEConstants;
44  import org.kuali.ole.sys.OLEKeyConstants;
45  import org.kuali.ole.sys.OLEPropertyConstants;
46  import org.kuali.ole.sys.ObjectUtil;
47  import org.kuali.ole.sys.context.SpringContext;
48  import org.kuali.ole.sys.exception.ParseException;
49  import org.kuali.rice.core.api.datetime.DateTimeService;
50  import org.kuali.rice.core.api.util.type.KualiDecimal;
51  import org.kuali.rice.kns.service.BusinessObjectDictionaryService;
52  import org.kuali.rice.kns.service.DataDictionaryService;
53  import org.kuali.rice.krad.bo.PersistableBusinessObjectBase;
54  import org.kuali.rice.krad.service.BusinessObjectService;
55  import org.kuali.rice.krad.util.MessageMap;
56  
57  /**
58   * Object representation of collector xml input.
59   */
60  public class CollectorBatch extends PersistableBusinessObjectBase {
61      // way to distinguish this batch from others
62      private String batchName;
63  
64      // common field for header records and trailer records
65      private String universityFiscalYear;
66      private String chartOfAccountsCode;
67      private String organizationCode;
68      private Date transmissionDate;
69      private String recordType;
70      
71      // header record additional fields
72      private String personUserID;
73      private Integer batchSequenceNumber;
74      private String emailAddress;
75      private String campusCode;
76      private String phoneNumber;
77      private String mailingAddress;
78      private String departmentName;
79  
80      private List<OriginEntryFull> originEntries;
81      private List<CollectorDetail> collectorDetails;
82  
83      // trailer records
84      private String firstEmptyField; //first,second,third Empty Fields are dummy fields to read the spaces in the file using dd
85      private String secondEmptyField;
86      private Integer totalRecords;
87      private KualiDecimal totalAmount;
88      
89      private MessageMap messageMap;
90      private OriginEntryTotals originEntryTotals;
91      
92      private boolean headerlessBatch;
93      
94      private static CollectorBatchHeaderFieldUtil collectorBatchHeaderFieldUtil;
95      private static CollectorBatchTrailerRecordFieldUtil collectorBatchTrailerRecordFieldUtil;
96      
97      /**
98       * Constructs a CollectorBatch
99       */
100     public CollectorBatch() {
101         originEntries = new ArrayList();
102         collectorDetails = new ArrayList();
103         messageMap = new MessageMap();
104         originEntryTotals = null;
105         totalRecords = 0;
106         headerlessBatch = false;
107     }
108 
109     /**
110      * Gets the universityFiscalYear attribute. 
111      */
112     public String getUniversityFiscalYear() {
113         return universityFiscalYear;
114     }
115     
116     /**
117      * Sets the universityFiscalYear attribute
118      */
119     public void setUniversityFiscalYear(String universityFiscalYear) {
120         this.universityFiscalYear = universityFiscalYear;
121     }
122     
123     /**
124      * Gets the batchSequenceNumber attribute.
125      */
126     public Integer getBatchSequenceNumber() {
127         return batchSequenceNumber;
128     }
129 
130     /**
131      * Sets the batchSequenceNumber attribute value.
132      */
133     public void setBatchSequenceNumber(Integer batchSequenceNumber) {
134         this.batchSequenceNumber = batchSequenceNumber;
135     }
136 
137     /**
138      * Gets the chartOfAccountsCode attribute.
139      */
140     public String getChartOfAccountsCode() {
141         return chartOfAccountsCode;
142     }
143 
144     /**
145      * Sets the chartOfAccountsCode attribute value.
146      */
147     public void setChartOfAccountsCode(String chartOfAccountsCode) {
148         this.chartOfAccountsCode = chartOfAccountsCode;
149     }
150 
151     /**
152      * Gets the organizationCode attribute.
153      */
154     public String getOrganizationCode() {
155         return organizationCode;
156     }
157 
158     /**
159      * Sets the organizationCode attribute value.
160      */
161     public void setOrganizationCode(String organizationCode) {
162         this.organizationCode = organizationCode;
163     }
164 
165     /**
166      * Gets the totalAmount attribute.
167      */
168     public KualiDecimal getTotalAmount() {
169         return totalAmount;
170     }
171 
172     /**
173      * Sets the totalAmount attribute value.
174      */
175     public void setTotalAmount(KualiDecimal totalAmount) {
176         this.totalAmount = totalAmount;
177     }
178 
179     /**
180      * Sets the total amount from the String.
181      */
182     public void setTotalAmount(String totalAmount) {
183         this.totalAmount = new KualiDecimal(totalAmount);
184     }
185 
186     /**
187      * Sets the total amount field to null.
188      */
189     public void clearTotalAmount() {
190         this.totalAmount = null;
191     }
192 
193     /**
194      * Gets the secondEmptyField attribute
195      */
196     public String getSecondEmptyField() {
197         return secondEmptyField;
198     }
199     
200     /**
201      * Sets the secondEmptyField attribute
202      */
203     public void setSecondEmptyField(String secondEmptyField) {
204         this.secondEmptyField = secondEmptyField;
205     }
206     
207     /**
208      * Gets the firstEmptyField attribute
209      */
210     public String getFirstEmptyField() {
211         return firstEmptyField;
212     }
213     
214     /**
215      * Sets the firstEmptyField attribute
216      */
217     public void setFirstEmptyField(String firstEmptyField) {
218         this.firstEmptyField = firstEmptyField;
219     }
220 
221     /**
222      * Gets the totalRecords attribute.
223      */
224     public Integer getTotalRecords() {
225         return totalRecords;
226     }
227 
228     /**
229      * Sets the totalRecords attribute value.
230      */
231     public void setTotalRecords(Integer totalRecords) {
232         this.totalRecords = totalRecords;
233     }
234 
235     /**
236      * Gets the transmissionDate attribute.
237      */
238     public Date getTransmissionDate() {
239         return transmissionDate;
240     }
241 
242     /**
243      * Sets the transmissionDate attribute value.
244      */
245     public void setTransmissionDate(Date transmissionDate) {
246         this.transmissionDate = transmissionDate;
247     }
248 
249     /**
250      * Gets the recordType attribute.
251      */
252     public String getRecordType() {
253         return recordType;
254     }
255     
256     /**
257      * Sets the recordType attribute.
258      */
259     public void setRecordType(String recordType) {
260         this.recordType = recordType;
261     }
262         
263     /**
264      * Gets the emailAddress attribute.
265      */
266     public String getEmailAddress() {
267         return emailAddress;
268     }
269 
270     /**
271      * Sets the emailAddress attribute value.
272      */
273     public void setEmailAddress(String emailAddress) {
274         this.emailAddress = emailAddress;
275     }
276 
277     /**
278      * Gets the personUserID attribute.
279      */
280     public String getPersonUserID() {
281         return personUserID;
282     }
283 
284     /**
285      * Sets the personUserID attribute value.
286      */
287     public void setPersonUserID(String personUserID) {
288         this.personUserID = personUserID;
289     }
290 
291     /**
292      * Gets the idBillings attribute.
293      */
294     public List<CollectorDetail> getCollectorDetails() {
295         return collectorDetails;
296     }
297 
298     /**
299      * Sets the idBillings attribute value.
300      */
301     public void setCollectorDetails(List<CollectorDetail> idDetails) {
302         this.collectorDetails = idDetails;
303     }
304 
305     /**
306      * Gets the originEntries attribute.
307      */
308     public List<OriginEntryFull> getOriginEntries() {
309         return originEntries;
310     }
311 
312     /**
313      * Sets the originEntries attribute value.
314      */
315     public void setOriginEntries(List<OriginEntryFull> batchOriginEntry) {
316         this.originEntries = batchOriginEntry;
317     }
318 
319     /**
320      * Adds a processed origin entry to the list.
321      */
322     public void addOriginEntry(OriginEntryFull orginEntry) {
323         this.originEntries.add(orginEntry);
324     }
325 
326     /**
327      * Adds a processed id billing to the list.
328      */
329     public void addCollectorDetail(CollectorDetail collectorDetail) {
330         this.collectorDetails.add(collectorDetail);
331     }
332 
333     /**
334      * Attempts to retrieve a collector header already exists with the primary key values given for this object
335      * 
336      * @return the CollectorHeader found in the database
337      */
338     public CollectorHeader retrieveDuplicateHeader() {
339         // checkHeader is used to check whether a record with the same PK values exist already (i.e. only PK values are filled in).
340         CollectorHeader checkHeader = createCollectorHeaderWithPKValuesOnly();
341 
342         CollectorHeader foundHeader = (CollectorHeader) SpringContext.getBean(BusinessObjectService.class).retrieve(checkHeader);
343         return foundHeader;
344     }
345 
346     /**
347      * Sets defaults for fields not populated from file. Store an origin entry group, all gl entries and id billing entries from the
348      * processed file. Also write the header for the duplicate file check.
349      * 
350      * @param originEntryGroup the group into which to store the origin entries
351      * @param collectorReportData report data
352      */
353     public void setDefaultsAndStore(CollectorReportData collectorReportData, String demergerOutputFileName, PrintStream originEntryOutputPs) {
354         BusinessObjectService businessObjectService = SpringContext.getBean(BusinessObjectService.class);  
355         CollectorDetailService collectorDetailService = SpringContext.getBean(CollectorDetailService.class);
356         
357         // persistHeader is used to persist a collector header record into the DB
358         CollectorHeader persistHeader = createCollectorHeaderForStorage();
359         CollectorHeader foundHeader = retrieveDuplicateHeader();
360 
361         if (foundHeader != null) {
362             // update the version number to prevent OptimisticLockingExceptions
363             persistHeader.setVersionNumber(foundHeader.getVersionNumber());
364         }
365         businessObjectService.save(persistHeader);
366               
367         // store origin entries by using the demerger output file
368         
369         BufferedReader inputFileReader = null;
370         try {
371             inputFileReader = new BufferedReader(new FileReader(demergerOutputFileName));
372             String line = null;
373             while ((line = inputFileReader.readLine()) != null) {
374                 originEntryOutputPs.printf("%s\n", line);
375             }
376         }
377         catch (IOException e) {
378             throw new RuntimeException("IO Error encountered trying to persist collector batch.", e);
379         }
380         finally {
381             IOUtils.closeQuietly(inputFileReader);
382             inputFileReader = null;
383         }  
384         Date nowDate  = new Date(SpringContext.getBean(DateTimeService.class).getCurrentDate().getTime());
385         RunDateService runDateService = SpringContext.getBean(RunDateService.class);
386         Date createDate = new java.sql.Date((runDateService.calculateRunDate(nowDate).getTime()));
387         
388         Integer sequenceNumber = new Integer(0);
389         Integer nextSequence = collectorDetailService.getNextCreateSequence(createDate);
390         if (nextSequence != null) {
391             sequenceNumber = nextSequence;
392         }
393         int countOfdetails = collectorDetails.size();
394         for (int numSavedDetails = 0; numSavedDetails < countOfdetails; numSavedDetails++) {
395             CollectorDetail idDetail = this.collectorDetails.get(numSavedDetails);           
396           //  setDefaultsCollectorDetail(idDetail);
397          
398             idDetail.setTransactionLedgerEntrySequenceNumber( ++sequenceNumber);
399             idDetail.setCreateDate(createDate);
400             CollectorDetail foundIdDetail = (CollectorDetail) businessObjectService.retrieve(idDetail);
401             if (foundIdDetail != null) {
402                 idDetail.setVersionNumber(foundIdDetail.getVersionNumber());
403             }
404 
405             businessObjectService.save(idDetail);
406         }
407         
408         collectorReportData.setNumSavedDetails(this, countOfdetails);
409     }
410 
411     /**
412      * Uppercases the appropriate fields in the batch, if told to do so by the data dictionary
413      */
414     public void prepareDataForStorage() {
415         BusinessObjectDictionaryService businessObjectDictionaryService = SpringContext.getBean(BusinessObjectDictionaryService.class);
416         DataDictionaryService dataDictionaryService = SpringContext.getBean(DataDictionaryService.class);
417 
418         // uppercase the data used to generate the collector header
419         if (dataDictionaryService.getAttributeForceUppercase(Chart.class, OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE)) {
420             setChartOfAccountsCode(getChartOfAccountsCode().toUpperCase());
421         }
422         if (dataDictionaryService.getAttributeForceUppercase(Organization.class, OLEPropertyConstants.ORGANIZATION_CODE)) {
423             setOrganizationCode(getOrganizationCode().toUpperCase());
424         }
425 
426         // now uppercase all of the origin entry data
427         for (OriginEntryFull entry : originEntries) {
428             businessObjectDictionaryService.performForceUppercase(entry);
429         }
430 
431         // uppercase the id billing entries
432         for (CollectorDetail collectorDetail : collectorDetails) {
433             businessObjectDictionaryService.performForceUppercase(collectorDetail);
434         }
435     }
436 
437     /**
438      * Creates origin entry group from header fields.
439      * 
440      * @return OriginEntryGroup
441      */
442     private OriginEntryGroup createOriginEntryGroup() {
443         OriginEntryGroup group = new OriginEntryGroup();
444 
445         group.setSourceCode(OriginEntrySource.COLLECTOR);
446         group.setDate(new java.sql.Date(SpringContext.getBean(DateTimeService.class).getCurrentDate().getTime()));
447         group.setProcess(new Boolean(true));
448         group.setScrub(new Boolean(true));
449         group.setValid(new Boolean(true));
450 
451         return group;
452     }
453 
454     /**
455      * Creates a CollectorHeader from the batch to be used for storage
456      * 
457      * @return CollectorHeader
458      */
459     public CollectorHeader createCollectorHeaderForStorage() {
460         CollectorHeader header = new CollectorHeader();
461 
462         header.setChartOfAccountsCode(getChartOfAccountsCode());
463         header.setOrganizationCode(getOrganizationCode());
464         header.setProcessTransmissionDate(getTransmissionDate());
465         header.setProcessBatchSequenceNumber(getBatchSequenceNumber());
466         header.setProcessTotalRecordCount(getTotalRecords());
467         header.setProcessTotalAmount(getTotalAmount());
468         header.setContactCampusCode(getCampusCode());
469         header.setContactPersonPhoneNumber(getPhoneNumber());
470         header.setContactMailingAddress(getMailingAddress());
471         header.setContactDepartmentName(getDepartmentName());
472 
473         return header;
474     }
475 
476     /**
477      * Creates an origin entry record with the PK values filled in only. This is useful to check for duplicate headers.
478      * 
479      * @return CollectorHeader with chart of accounts code, organization code, process transmission date, batch sequence number
480      * total record count, and process total amount from this CollectorBatch
481      */
482     public CollectorHeader createCollectorHeaderWithPKValuesOnly() {
483         CollectorHeader header = new CollectorHeader();
484 
485         header.setChartOfAccountsCode(getChartOfAccountsCode());
486         header.setOrganizationCode(getOrganizationCode());
487         header.setProcessTransmissionDate(getTransmissionDate());
488         header.setProcessBatchSequenceNumber(getBatchSequenceNumber());
489         header.setProcessTotalRecordCount(getTotalRecords());
490         header.setProcessTotalAmount(getTotalAmount());
491 
492         return header;
493     }
494 
495 //    /**
496 //     * Sets defaults for missing id billing fields.
497 //     * 
498 //     * @param idDetail CollectorDetail object which has its create date being set
499 //     */
500 //    private void setDefaultsCollectorDetail(CollectorDetail idDetail) {
501 //        // TODO: Get current fiscal year and period if blank?
502 //        // idBilling.setUniversityFiscalPeriodCode(String.valueOf(RandomUtils.nextInt(2)));
503 //        // idBilling.setCreateSequence(String.valueOf(RandomUtils.nextInt(2)));
504 //        // idBilling.setInterDepartmentalBillingSequenceNumber(String.valueOf(RandomUtils.nextInt(2)));
505 //        idDetail.setCreateDate(new Date(SpringContext.getBean(DateTimeService.class).getCurrentDate().getTime()));
506 //        
507 //    }
508 
509     /**
510      * Gets the campusCode attribute.
511      * 
512      * @return Returns the campusCode.
513      */
514     public String getCampusCode() {
515         return campusCode;
516     }
517 
518     /**
519      * Sets the campusCode attribute value.
520      * 
521      * @param campusCode The campusCode to set.
522      */
523     public void setCampusCode(String campusCode) {
524         this.campusCode = campusCode;
525     }
526 
527     /**
528      * Gets the departmentName attribute.
529      * 
530      * @return Returns the departmentName.
531      */
532     public String getDepartmentName() {
533         return departmentName;
534     }
535 
536     /**
537      * Sets the departmentName attribute value.
538      * 
539      * @param departmentName The departmentName to set.
540      */
541     public void setDepartmentName(String departmentName) {
542         this.departmentName = departmentName;
543     }
544 
545     /**
546      * Gets the mailingAddress attribute.
547      * 
548      * @return Returns the mailingAddress.
549      */
550     public String getMailingAddress() {
551         return mailingAddress;
552     }
553 
554     /**
555      * Sets the mailingAddress attribute value.
556      * 
557      * @param mailingAddress The mailingAddress to set.
558      */
559     public void setMailingAddress(String mailingAddress) {
560         this.mailingAddress = mailingAddress;
561     }
562 
563     /**
564      * Gets the phoneNumber attribute.
565      * 
566      * @return Returns the phoneNumber.
567      */
568     public String getPhoneNumber() {
569         return phoneNumber;
570     }
571 
572     /**
573      * Sets the phoneNumber attribute value.
574      * 
575      * @param phoneNumber The phoneNumber to set.
576      */
577     public void setPhoneNumber(String phoneNumber) {
578         this.phoneNumber = phoneNumber;
579     }
580 
581     /**
582      * Gets the batchName attribute.
583      * 
584      * @return Returns the batchName.
585      */
586     public String getBatchName() {
587         return batchName;
588     }
589 
590     /**
591      * Sets the batchName attribute value.
592      * 
593      * @param batchName The batchName to set.
594      */
595     public void setBatchName(String batchName) {
596         this.batchName = batchName;
597     }
598 
599     public MessageMap getMessageMap() {
600         return messageMap;
601     }
602 
603     public void setMessageMap(MessageMap messageMap) {
604         if (messageMap == null) {
605             throw new NullPointerException("messageMap is null");
606         }
607         if (this.messageMap.hasMessages()) {
608             throw new RuntimeException("Cannot reset MessageMap unless original instance has no messages.");
609         }
610         this.messageMap = messageMap;
611     }
612 
613     public OriginEntryTotals getOriginEntryTotals() {
614         return originEntryTotals;
615     }
616 
617     public void setOriginEntryTotals(OriginEntryTotals originEntryTotals) {
618         this.originEntryTotals = originEntryTotals;
619     }
620 
621     public boolean isHeaderlessBatch() {
622         return headerlessBatch;
623     }
624 
625     public void setHeaderlessBatch(boolean headerlessBatch) {
626         this.headerlessBatch = headerlessBatch;
627     }
628     
629     protected LinkedHashMap toStringMapper_RICE20_REFACTORME() {
630         LinkedHashMap map = new LinkedHashMap();
631         map.put("chartOfAccountsCode", getChartOfAccountsCode());
632         map.put("organizationCode", getOrganizationCode());
633         map.put("transmissionDate", getTransmissionDate());
634         map.put("personUserID", getPersonUserID());
635         map.put("batchSequenceNumber", getBatchSequenceNumber());
636         map.put("emailAddress", getEmailAddress());
637         map.put("campusCode", getCampusCode());
638         map.put("phoneNumber", getPhoneNumber());
639         map.put("mailingAddress", getMailingAddress());
640         map.put("departmentName", getDepartmentName());
641         map.put("firstEmptyField", getFirstEmptyField());
642         map.put("totalRecords", getTotalRecords());        
643         map.put("secondEmptyField", getSecondEmptyField());
644         map.put("totalAmount", getTotalAmount());
645         
646         return map;
647     }
648     
649     protected Date parseSqlDate(String date) throws ParseException {
650         try {
651             return new Date(new SimpleDateFormat("yy-MM-dd").parse(date).getTime());
652         }
653         catch (java.text.ParseException e) {
654             throw new ParseException(e.getMessage(), e);
655         }
656     }
657     
658     protected String getValue(String headerLine, int s, int e) {
659           return org.springframework.util.StringUtils.trimTrailingWhitespace(StringUtils.substring(headerLine, s, e));
660       }
661     
662     /**
663      * @return the static instance of the CollectorBatchHeaderFieldUtil
664      */
665     protected static CollectorBatchHeaderFieldUtil getCollectorBatchHeaderFieldUtil() {
666         if (collectorBatchHeaderFieldUtil == null) {
667             collectorBatchHeaderFieldUtil = new CollectorBatchHeaderFieldUtil();
668         }
669         return collectorBatchHeaderFieldUtil;
670     }
671     
672     public void setFromTextFileForCollectorBatch(String headerLine) {
673         try{
674             final Map<String, Integer> pMap = getCollectorBatchHeaderFieldUtil().getFieldBeginningPositionMap();
675             
676             headerLine = org.apache.commons.lang.StringUtils.rightPad(headerLine, GeneralLedgerConstants.getSpaceAllCollectorBatchHeaderFields().length(), ' ');
677             
678             setChartOfAccountsCode(getValue(headerLine, pMap.get(OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE), pMap.get(OLEPropertyConstants.ORGANIZATION_CODE)));
679             setOrganizationCode(getValue(headerLine, pMap.get(OLEPropertyConstants.ORGANIZATION_CODE), pMap.get(OLEPropertyConstants.TRANSMISSION_DATE)));
680 
681             String transmissionDate = org.apache.commons.lang.StringUtils.trim(getValue(headerLine, pMap.get(OLEPropertyConstants.TRANSMISSION_DATE), pMap.get(OLEPropertyConstants.COLLECTOR_BATCH_RECORD_TYPE)));
682             try {
683                 setTransmissionDate(parseSqlDate(transmissionDate));
684             }
685             catch (ParseException e) {
686                 getMessageMap().putError(OLEConstants.GLOBAL_ERRORS, OLEKeyConstants.Collector.HEADER_BAD_TRANSMISSION_DATE_FORMAT, transmissionDate);
687                 setTransmissionDate(null);
688             }
689             String batchNumber = org.apache.commons.lang.StringUtils.trim(getValue(headerLine, pMap.get(OLEPropertyConstants.BATCH_SEQUENCE_NUMBER), pMap.get(OLEPropertyConstants.EMAIL_ADDRESS)));
690             
691             if (ObjectUtil.isInteger(batchNumber)) { 
692                 setBatchSequenceNumber(new Integer(batchNumber));
693             } else {
694                 setBatchSequenceNumber(0);
695             }
696             setEmailAddress(getValue(headerLine, pMap.get(OLEPropertyConstants.EMAIL_ADDRESS), pMap.get(OLEPropertyConstants.COLLECTOR_BATCH_PERSON_USER_ID)));
697             setPersonUserID(getValue(headerLine, pMap.get(OLEPropertyConstants.COLLECTOR_BATCH_PERSON_USER_ID), pMap.get(OLEPropertyConstants.DEPARTMENT_NAME)));
698             setDepartmentName(getValue(headerLine, pMap.get(OLEPropertyConstants.DEPARTMENT_NAME), pMap.get(OLEPropertyConstants.MAILING_ADDRESS)));
699             setMailingAddress(getValue(headerLine, pMap.get(OLEPropertyConstants.MAILING_ADDRESS), pMap.get(OLEPropertyConstants.CAMPUS_CODE)));
700             setCampusCode(getValue(headerLine, pMap.get(OLEPropertyConstants.CAMPUS_CODE), pMap.get(OLEPropertyConstants.PHONE_NUMBER)));
701             setPhoneNumber(org.apache.commons.lang.StringUtils.trim(getValue(headerLine, pMap.get(OLEPropertyConstants.PHONE_NUMBER), GeneralLedgerConstants.getSpaceAllCollectorBatchHeaderFields().length())));
702         } catch (Exception e){
703             throw new RuntimeException(e + " occurred in CollectorBatch.setFromTextFileForCollectorBatch()");
704         }
705     }
706     
707     /**
708      * @return the static instance of the CollectorBatchTrailerRecordFieldUtil
709      */
710     protected static CollectorBatchTrailerRecordFieldUtil getCollectorBatchTrailerRecordFieldUtil() {
711         if (collectorBatchTrailerRecordFieldUtil == null) {
712             collectorBatchTrailerRecordFieldUtil = new CollectorBatchTrailerRecordFieldUtil();
713         }
714         return collectorBatchTrailerRecordFieldUtil;
715     }
716     
717     public void setFromTextFileForCollectorBatchTrailerRecord(String trailerLine, int lineNumber) {
718         final Map<String, Integer> pMap = getCollectorBatchTrailerRecordFieldUtil().getFieldBeginningPositionMap();
719 
720         trailerLine = org.apache.commons.lang.StringUtils.rightPad(trailerLine, GeneralLedgerConstants.getSpaceAllCollectorBatchTrailerFields().length(), ' ');
721         setTotalRecords(new Integer(org.apache.commons.lang.StringUtils.trim(getValue(trailerLine, pMap.get(OLEPropertyConstants.TOTAL_RECORDS), pMap.get(OLEPropertyConstants.TRAILER_RECORD_SECOND_EMPTY_FIELD)))));
722         
723         String trailerAmount = org.apache.commons.lang.StringUtils.trim(getValue(trailerLine, pMap.get(OLEPropertyConstants.TOTAL_AMOUNT), GeneralLedgerConstants.getSpaceAllCollectorBatchTrailerFields().length()));
724         
725         try {
726             setTotalAmount(trailerAmount);
727         }
728         catch (NumberFormatException e) {
729             setTotalAmount(KualiDecimal.ZERO);
730             getMessageMap().putError(OLEConstants.GLOBAL_ERRORS, OLEKeyConstants.ERROR_CUSTOM, "Collector trailer total amount cannot be parsed on line " + lineNumber + " amount string " + trailerAmount);
731         }
732     }
733 }