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.tem.document.validation.impl;
20  
21  import static org.kuali.kfs.module.tem.TemConstants.TravelParameters.PER_DIEM_CATEGORIES;
22  
23  import java.util.Collection;
24  
25  import org.apache.commons.lang.StringUtils;
26  import org.kuali.kfs.module.tem.TemConstants;
27  import org.kuali.kfs.module.tem.TemKeyConstants;
28  import org.kuali.kfs.module.tem.TemParameterConstants;
29  import org.kuali.kfs.module.tem.businessobject.PerDiemExpense;
30  import org.kuali.kfs.module.tem.document.TravelDocumentBase;
31  import org.kuali.kfs.sys.context.SpringContext;
32  import org.kuali.kfs.sys.document.validation.GenericValidation;
33  import org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent;
34  import org.kuali.rice.coreservice.framework.parameter.ParameterService;
35  import org.kuali.rice.krad.util.GlobalVariables;
36  
37  public class TravelAuthTripDetailMileageRateValidation extends GenericValidation {
38  
39      //@Override
40      @Override
41      public boolean validate(AttributedDocumentEvent event) {
42          boolean rulePassed = true;
43          boolean showMileage = false;
44  
45          TravelDocumentBase document = (TravelDocumentBase) event.getDocument();
46          //check to see if mileage=Y in PER_DIEM_CATEGORIES param
47          ParameterService paramService = SpringContext.getBean(ParameterService.class);
48          Collection<String> perDiemCats = paramService.getParameterValuesAsString(TemParameterConstants.TEM_DOCUMENT.class, PER_DIEM_CATEGORIES);
49          for (String category : perDiemCats) {
50              String[] pair = category.split("=");
51              if (pair[0].equalsIgnoreCase(TemConstants.MILEAGE) && pair[1].equalsIgnoreCase(TemConstants.YES)) {
52                  showMileage = true;
53              }
54          }
55          if (showMileage) {
56              for (PerDiemExpense estimate : document.getPerDiemExpenses()) {
57                  if (StringUtils.isBlank(estimate.getMileageRateExpenseTypeCode())) {
58                      GlobalVariables.getMessageMap().putError("document.perDiemExpenses", TemKeyConstants.ERROR_TA_NO_MILEAGE_RATE);
59                      rulePassed = false;
60                  }
61              }
62          }
63  
64          return rulePassed;
65      }
66  
67  }