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.gl.businessobject.options;
017
018 import java.io.File;
019 import java.util.ArrayList;
020 import java.util.Arrays;
021 import java.util.Collections;
022 import java.util.Date;
023 import java.util.List;
024
025 import org.kuali.kfs.gl.service.OriginEntryGroupService;
026 import org.kuali.kfs.gl.web.util.OriginEntryFileComparator;
027 import org.kuali.kfs.sys.context.SpringContext;
028 import org.kuali.rice.core.util.KeyLabelPair;
029 import org.kuali.rice.kns.lookup.keyvalues.KeyValuesBase;
030 import org.kuali.rice.kns.service.DateTimeService;
031
032 /**
033 * Returns list of GL origin entry filenames
034 */
035 public class CorrectionGroupEntriesFinder extends KeyValuesBase {
036
037 /**
038 * Returns a list of key/value pairs to display correction groups that can be used in a Correction Document
039 *
040 * @return a List of key/value pairs for correction groups
041 * @see org.kuali.rice.kns.lookup.keyvalues.KeyValuesFinder#getKeyValues()
042 */
043 public List getKeyValues() {
044 List activeLabels = new ArrayList();
045
046 OriginEntryGroupService originEntryGroupService = SpringContext.getBean(OriginEntryGroupService.class);
047 File[] fileList = originEntryGroupService.getAllFileInBatchDirectory();
048
049 List<File> sortedFileList = Arrays.asList(fileList);
050 Collections.sort(sortedFileList, new OriginEntryFileComparator());
051
052 for (File file : sortedFileList) {
053 String fileName = file.getName();
054
055 // build display file name with date and size
056 Date date = new Date(file.lastModified());
057 String timeInfo = "(" + SpringContext.getBean(DateTimeService.class).toDateTimeString(date) + ")";
058 String sizeInfo = "(" + (new Long(file.length())).toString() + ")";
059
060 activeLabels.add(new KeyLabelPair(fileName, timeInfo + " " + fileName + " " + sizeInfo));
061 }
062
063 return activeLabels;
064 }
065
066 }