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.ar.document.validation.impl;
20  
21  import static org.kuali.kfs.sys.document.validation.impl.AccountingDocumentRuleBaseConstants.ERROR_PATH.DOCUMENT_ERROR_PREFIX;
22  
23  import org.kuali.kfs.module.ar.ArKeyConstants;
24  import org.kuali.kfs.module.ar.ArPropertyConstants;
25  import org.kuali.kfs.module.ar.document.CustomerInvoiceDocument;
26  import org.kuali.kfs.sys.context.SpringContext;
27  import org.kuali.kfs.sys.document.validation.GenericValidation;
28  import org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent;
29  import org.kuali.rice.kim.api.identity.Person;
30  import org.kuali.rice.kim.api.identity.PersonService;
31  import org.kuali.rice.kns.service.DocumentHelperService;
32  import org.kuali.rice.krad.document.DocumentAuthorizer;
33  import org.kuali.rice.krad.util.GlobalVariables;
34  import org.kuali.rice.krad.util.ObjectUtils;
35  
36  public class CustomerInvoiceRecurrenceInitiatorValidation extends GenericValidation {
37      
38      private CustomerInvoiceDocument customerInvoiceDocument;
39  
40      public boolean validate(AttributedDocumentEvent event) {
41  
42          // short circuit if no recurrence object at all
43          if (ObjectUtils.isNull(customerInvoiceDocument.getCustomerInvoiceRecurrenceDetails())) {
44              return true;
45          }
46          
47          if (customerInvoiceDocument.getNoRecurrenceDataFlag())
48              return true;
49          
50          String initiatorUserIdentifier = customerInvoiceDocument.getCustomerInvoiceRecurrenceDetails().getDocumentInitiatorUserIdentifier();
51          if (ObjectUtils.isNull(initiatorUserIdentifier)) {
52              GlobalVariables.getMessageMap().putError(DOCUMENT_ERROR_PREFIX + ArPropertyConstants.CustomerInvoiceDocumentFields.INVOICE_DOCUMENT_RECURRENCE_INITIATOR, ArKeyConstants.ERROR_INVOICE_RECURRENCE_INITIATOR_IS_REQUIRED);
53              return false;
54          }
55  
56          DocumentAuthorizer documentAuthorizer = SpringContext.getBean(DocumentHelperService.class).getDocumentAuthorizer("INVR");
57          Person person = SpringContext.getBean(PersonService.class).getPerson(initiatorUserIdentifier);
58          if (person == null) {
59              GlobalVariables.getMessageMap().putError(DOCUMENT_ERROR_PREFIX + ArPropertyConstants.CustomerInvoiceDocumentFields.INVOICE_DOCUMENT_RECURRENCE_INITIATOR, ArKeyConstants.ERROR_INVOICE_RECURRENCE_INITIATOR_DOES_NOT_EXIST);
60              return false;
61          }
62          if (!documentAuthorizer.canInitiate("INVR", person)) {
63              GlobalVariables.getMessageMap().putError(DOCUMENT_ERROR_PREFIX + ArPropertyConstants.CustomerInvoiceDocumentFields.INVOICE_DOCUMENT_RECURRENCE_INITIATOR, ArKeyConstants.ERROR_INVOICE_RECURRENCE_INITIATOR_IS_NOT_AUTHORIZED);
64              return false;
65          }
66          return true;
67      }
68  
69      public CustomerInvoiceDocument getCustomerInvoiceDocument() {
70          return customerInvoiceDocument;
71      }
72  
73      public void setCustomerInvoiceDocument(CustomerInvoiceDocument customerInvoiceDocument) {
74          this.customerInvoiceDocument = customerInvoiceDocument;
75      }
76  }