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 org.kuali.kfs.module.tem.TemKeyConstants;
22  import org.kuali.kfs.module.tem.TemPropertyConstants;
23  import org.kuali.kfs.module.tem.TemPropertyConstants.TravelRelocationFields;
24  import org.kuali.kfs.module.tem.document.TravelRelocationDocument;
25  import org.kuali.kfs.sys.KFSConstants;
26  import org.kuali.kfs.sys.document.validation.GenericValidation;
27  import org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent;
28  import org.kuali.rice.krad.util.GlobalVariables;
29  import org.kuali.rice.core.api.util.type.KualiDecimal;
30  
31  public class RelocationInformationRequiredInfoValidation extends GenericValidation {
32      public static final String USA_COUNTRY_CODE = "US";
33      public static final String ATTACHMENT_TYPE_CODE_RECEIPT = "RECEIPT";
34  
35      @Override
36      public boolean validate(AttributedDocumentEvent event) {
37          boolean valid = true;
38  
39          TravelRelocationDocument document = (TravelRelocationDocument) event.getDocument();
40  
41          // Check to see if from country is selected. If selected from state is required field
42          if (document.getFromCountryCode() != null && document.getFromCountryCode().equals(USA_COUNTRY_CODE)) {
43              valid = !(document.getFromStateCode() == null || document.getFromStateCode().equals(""));
44  
45              if (!valid) {
46                  GlobalVariables.getMessageMap().putError(TravelRelocationFields.FROM_STATE, TemKeyConstants.ERROR_RELO_FROM_STATE_REQUIRED);
47                  return valid;
48              }
49          }
50  
51          // Check to see if to country is selected. If selected to state is required field
52          if (document.getToCountryCode() != null && document.getToCountryCode().equals(USA_COUNTRY_CODE)) {
53              valid = !(document.getToStateCode() == null || document.getToStateCode().equals(""));
54  
55              if (!valid) {
56                  GlobalVariables.getMessageMap().putError(TravelRelocationFields.TO_STATE, TemKeyConstants.ERROR_RELO_TO_STATE_REQUIRED);
57                  return valid;
58              }
59          }           
60  
61          if (document.getDocumentGrandTotal().isLessEqual(KualiDecimal.ZERO)) {
62              GlobalVariables.getMessageMap().putError(KFSConstants.DOCUMENT_PROPERTY_NAME + "." + TemPropertyConstants.TRVL_AUTH_TOTAL_ESTIMATE, TemKeyConstants.ERROR_DOCUMENT_TOTAL_ESTIMATED);
63              valid = false;
64          }
65          
66          return valid;
67      }
68  
69  }