View Javadoc
1   /*
2    * Copyright 2006 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.businessobject.options;
17  
18  import java.io.File;
19  import java.util.ArrayList;
20  import java.util.Arrays;
21  import java.util.Collections;
22  import java.util.Date;
23  import java.util.List;
24  
25  import org.kuali.ole.gl.service.OriginEntryGroupService;
26  import org.kuali.ole.gl.web.util.OriginEntryFileComparator;
27  import org.kuali.ole.sys.context.SpringContext;
28  import org.kuali.rice.core.api.datetime.DateTimeService;
29  import org.kuali.rice.core.api.util.ConcreteKeyValue;
30  import org.kuali.rice.krad.keyvalues.KeyValuesBase;
31  
32  /**
33   * Returns list of GL origin entry filenames
34   */
35  public class CorrectionGroupEntriesFinder extends KeyValuesBase {
36  
37      /**
38       * Returns a list of key/value pairs to display correction groups that can be used in a Correction Document
39       * 
40       * @return a List of key/value pairs for correction groups
41       * @see org.kuali.rice.kns.lookup.keyvalues.KeyValuesFinder#getKeyValues()
42       */
43      public List getKeyValues() {
44          List activeLabels = new ArrayList();
45  
46          OriginEntryGroupService originEntryGroupService = SpringContext.getBean(OriginEntryGroupService.class);
47          File[] fileList = originEntryGroupService.getAllFileInBatchDirectory();
48  
49          List<File> sortedFileList = Arrays.asList(fileList);
50          Collections.sort(sortedFileList, new OriginEntryFileComparator());
51  
52          for (File file : sortedFileList) {
53              String fileName = file.getName();
54  
55              // build display file name with date and size
56              Date date = new Date(file.lastModified());
57              String timeInfo = "(" + SpringContext.getBean(DateTimeService.class).toDateTimeString(date) + ")";
58              String sizeInfo = "(" + (new Long(file.length())).toString() + ")";
59  
60              activeLabels.add(new ConcreteKeyValue(fileName, timeInfo + " " + fileName + " " + sizeInfo));
61          }
62  
63          return activeLabels;
64      }
65  
66  }