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