View Javadoc
1   /*
2    * The Kuali Financial System, a comprehensive financial management system for higher education.
3    * 
4    * Copyright 2005-2014 The Kuali Foundation
5    * 
6    * This program is free software: you can redistribute it and/or modify
7    * it under the terms of the GNU Affero General Public License as
8    * published by the Free Software Foundation, either version 3 of the
9    * License, or (at your option) any later version.
10   * 
11   * This program is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU Affero General Public License for more details.
15   * 
16   * You should have received a copy of the GNU Affero General Public License
17   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18   */
19  package org.kuali.kfs.module.ld.businessobject.inquiry;
20  
21  import java.text.SimpleDateFormat;
22  import java.util.ArrayList;
23  import java.util.Calendar;
24  import java.util.Date;
25  import java.util.List;
26  import java.util.Map;
27  
28  import org.kuali.kfs.integration.ld.businessobject.inquiry.AbstractPositionDataDetailsInquirableImpl;
29  import org.kuali.kfs.module.ld.LaborConstants;
30  import org.kuali.kfs.module.ld.LaborPropertyConstants;
31  import org.kuali.kfs.module.ld.businessobject.PositionData;
32  import org.kuali.rice.krad.bo.BusinessObject;
33  
34  
35  
36  /**
37   * This class is used to generate the URL for the user-defined attributes for the Position Inquiry screen. It is entended the
38   * KualiInquirableImpl class, so it covers both the default implementation and customized implemetnation.
39   */
40  public class PositionDataDetailsInquirableImpl extends AbstractPositionDataDetailsInquirableImpl {
41  
42      @Override
43      protected String getPositionNumberKeyValue() {
44          return LaborConstants.getDashPositionNumber();
45      }
46  
47      @Override
48      protected String getFinancialBalanceTypeCodeKeyValue() {
49          return LaborConstants.BalanceInquiries.BALANCE_TYPE_AC_AND_A21;
50      }
51  
52      @Override
53      protected String getEffectiveDateKey() {
54          return LaborPropertyConstants.EFFECTIVE_DATE;
55      }
56  
57      @Override
58      protected Class getInquiryBusinessObjectClass(String attributeName) {
59          return PositionData.class;
60      }
61  
62      @Override
63      public BusinessObject getBusinessObject(Map fieldValues) {
64          List<PositionData> positionList = new ArrayList<PositionData>(getLookupService().findCollectionBySearch(PositionData.class, fieldValues));
65          SimpleDateFormat formatter = new SimpleDateFormat("MMddyyyy");
66  
67          Date today = Calendar.getInstance().getTime();
68          Date maxEffectiveDate = null;
69  
70          PositionData lookupValue = null;
71          for (PositionData position : positionList) {
72              Date effectiveDate = position.getEffectiveDate();
73              if (effectiveDate.compareTo(today) <= 0 && (maxEffectiveDate == null || effectiveDate.compareTo(maxEffectiveDate) > 0)) {
74                  maxEffectiveDate = effectiveDate;
75                  lookupValue = position;
76              }
77          }
78  
79          return lookupValue;
80      }
81  
82  }