001 /* 002 * Copyright 2011 The Kuali Foundation. 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 package org.kuali.kfs.module.ar.document.validation.impl; 017 018 import static org.kuali.kfs.sys.document.validation.impl.AccountingDocumentRuleBaseConstants.ERROR_PATH.DOCUMENT_ERROR_PREFIX; 019 020 import org.kuali.kfs.module.ar.ArKeyConstants; 021 import org.kuali.kfs.module.ar.ArPropertyConstants; 022 import org.kuali.kfs.module.ar.document.CustomerInvoiceDocument; 023 import org.kuali.kfs.sys.context.SpringContext; 024 import org.kuali.kfs.sys.document.validation.GenericValidation; 025 import org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent; 026 import org.kuali.rice.kns.document.authorization.DocumentAuthorizer; 027 import org.kuali.rice.kns.service.DocumentHelperService; 028 import org.kuali.rice.kns.util.GlobalVariables; 029 import org.kuali.rice.kns.util.ObjectUtils; 030 import org.kuali.rice.kim.bo.Person; 031 032 public class CustomerInvoiceRecurrenceInitiatorValidation extends GenericValidation { 033 034 private CustomerInvoiceDocument customerInvoiceDocument; 035 036 public boolean validate(AttributedDocumentEvent event) { 037 038 // short circuit if no recurrence object at all 039 if (ObjectUtils.isNull(customerInvoiceDocument.getCustomerInvoiceRecurrenceDetails())) { 040 return true; 041 } 042 043 if (customerInvoiceDocument.getNoRecurrenceDataFlag()) 044 return true; 045 046 String initiatorUserIdentifier = customerInvoiceDocument.getCustomerInvoiceRecurrenceDetails().getDocumentInitiatorUserIdentifier(); 047 if (ObjectUtils.isNull(initiatorUserIdentifier)) { 048 GlobalVariables.getMessageMap().putError(DOCUMENT_ERROR_PREFIX + ArPropertyConstants.CustomerInvoiceDocumentFields.INVOICE_DOCUMENT_RECURRENCE_INITIATOR, ArKeyConstants.ERROR_INVOICE_RECURRENCE_INITIATOR_IS_REQUIRED); 049 return false; 050 } 051 052 DocumentAuthorizer documentAuthorizer = SpringContext.getBean(DocumentHelperService.class).getDocumentAuthorizer("INVR"); 053 Person person = org.kuali.rice.kim.service.KIMServiceLocator.getPersonService().getPerson(initiatorUserIdentifier); 054 if (person == null) { 055 GlobalVariables.getMessageMap().putError(DOCUMENT_ERROR_PREFIX + ArPropertyConstants.CustomerInvoiceDocumentFields.INVOICE_DOCUMENT_RECURRENCE_INITIATOR, ArKeyConstants.ERROR_INVOICE_RECURRENCE_INITIATOR_DOES_NOT_EXIST); 056 return false; 057 } 058 if (!documentAuthorizer.canInitiate("INVR", person)) { 059 GlobalVariables.getMessageMap().putError(DOCUMENT_ERROR_PREFIX + ArPropertyConstants.CustomerInvoiceDocumentFields.INVOICE_DOCUMENT_RECURRENCE_INITIATOR, ArKeyConstants.ERROR_INVOICE_RECURRENCE_INITIATOR_IS_NOT_AUTHORIZED); 060 return false; 061 } 062 return true; 063 } 064 065 public CustomerInvoiceDocument getCustomerInvoiceDocument() { 066 return customerInvoiceDocument; 067 } 068 069 public void setCustomerInvoiceDocument(CustomerInvoiceDocument customerInvoiceDocument) { 070 this.customerInvoiceDocument = customerInvoiceDocument; 071 } 072 }