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.fp.document.validation.impl;
20  
21  import org.kuali.kfs.fp.businessobject.DisbursementVoucherPayeeDetail;
22  import org.kuali.kfs.fp.document.DisbursementVoucherDocument;
23  import org.kuali.kfs.sys.KFSConstants;
24  import org.kuali.kfs.sys.KFSKeyConstants;
25  import org.kuali.kfs.sys.KFSPropertyConstants;
26  import org.kuali.kfs.sys.context.SpringContext;
27  import org.kuali.kfs.sys.document.AccountingDocument;
28  import org.kuali.kfs.sys.document.validation.GenericValidation;
29  import org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent;
30  import org.kuali.rice.kim.api.identity.Person;
31  import org.kuali.rice.kim.api.identity.PersonService;
32  import org.kuali.rice.kns.service.DataDictionaryService;
33  import org.kuali.rice.krad.util.GlobalVariables;
34  import org.kuali.rice.krad.util.MessageMap;
35  
36  public class DisbursementVoucherEmployeeInformationValidation extends GenericValidation {
37      private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(DisbursementVoucherEmployeeInformationValidation.class);
38  
39      protected AccountingDocument accountingDocumentForValidation;
40  
41      public static final String DV_PAYEE_ID_NUMBER_PROPERTY_PATH = KFSPropertyConstants.DV_PAYEE_DETAIL + "." + KFSPropertyConstants.DISB_VCHR_PAYEE_ID_NUMBER;
42  
43      /**
44       * @see org.kuali.kfs.sys.document.validation.Validation#validate(org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent)
45       */
46      @Override
47      public boolean validate(AttributedDocumentEvent event) {
48          LOG.debug("validate start");
49          boolean isValid = true;
50  
51          DisbursementVoucherDocument document = (DisbursementVoucherDocument) accountingDocumentForValidation;
52          DisbursementVoucherPayeeDetail payeeDetail = document.getDvPayeeDetail();
53  
54          if(!payeeDetail.isEmployee() || payeeDetail.isVendor() || !(document.getDocumentHeader().getWorkflowDocument().isInitiated() || document.getDocumentHeader().getWorkflowDocument().isSaved())) {
55              return true;
56          }
57  
58          String employeeId = payeeDetail.getDisbVchrPayeeIdNumber();
59          Person employee = SpringContext.getBean(PersonService.class).getPersonByEmployeeId(employeeId);
60  
61          MessageMap errors = GlobalVariables.getMessageMap();
62          errors.addToErrorPath(KFSPropertyConstants.DOCUMENT);
63  
64          // check existence of employee
65          if (employee == null) { // If employee is not found, report existence error
66              String label = SpringContext.getBean(DataDictionaryService.class).getAttributeLabel(DisbursementVoucherPayeeDetail.class, KFSPropertyConstants.DISB_VCHR_PAYEE_ID_NUMBER);
67              errors.putError(DV_PAYEE_ID_NUMBER_PROPERTY_PATH, KFSKeyConstants.ERROR_EXISTENCE, label);
68              isValid = false;
69          }
70          else if(!KFSConstants.EMPLOYEE_ACTIVE_STATUS.equals(employee.getEmployeeStatusCode())) {
71              // If employee is found, then check that employee is active
72              String label = SpringContext.getBean(DataDictionaryService.class).getAttributeLabel(DisbursementVoucherPayeeDetail.class, KFSPropertyConstants.DISB_VCHR_PAYEE_ID_NUMBER);
73              errors.putError(DV_PAYEE_ID_NUMBER_PROPERTY_PATH, KFSKeyConstants.ERROR_INACTIVE, label);
74              isValid = false;
75          }
76  
77          errors.removeFromErrorPath(KFSPropertyConstants.DOCUMENT);
78  
79          return isValid;
80      }
81  
82      /**
83       * Gets the accountingDocumentForValidation attribute.
84       * @return Returns the accountingDocumentForValidation.
85       */
86      public AccountingDocument getAccountingDocumentForValidation() {
87          return accountingDocumentForValidation;
88      }
89  
90      /**
91       * Sets the accountingDocumentForValidation attribute value.
92       *
93       * @param accountingDocumentForValidation The accountingDocumentForValidation to set.
94       */
95      public void setAccountingDocumentForValidation(AccountingDocument accountingDocumentForValidation) {
96          this.accountingDocumentForValidation = accountingDocumentForValidation;
97      }
98  }
99