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.DisbursementVoucherConstants;
20  import org.kuali.ole.fp.document.DisbursementVoucherDocument;
21  import org.kuali.ole.sys.OLEConstants;
22  import org.kuali.ole.sys.OLEPropertyConstants;
23  import org.kuali.ole.sys.businessobject.ChartOrgHolder;
24  import org.kuali.ole.sys.context.SpringContext;
25  import org.kuali.ole.sys.document.AccountingDocument;
26  import org.kuali.ole.sys.document.validation.GenericValidation;
27  import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
28  import org.kuali.ole.sys.service.FinancialSystemUserService;
29  import org.kuali.rice.core.api.parameter.ParameterEvaluator;
30  import org.kuali.rice.core.api.parameter.ParameterEvaluatorService;
31  import org.kuali.rice.coreservice.framework.parameter.ParameterService;
32  import org.kuali.rice.kim.api.identity.Person;
33  import org.kuali.rice.kim.api.services.KimApiServiceLocator;
34  import org.kuali.rice.krad.util.GlobalVariables;
35  import org.kuali.rice.krad.util.MessageMap;
36  import org.kuali.rice.krad.util.ObjectUtils;
37  
38  public class DisbursementVoucherDocumentLocationValidation extends GenericValidation implements DisbursementVoucherConstants {
39      private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(DisbursementVoucherDocumentLocationValidation.class);
40  
41      private ParameterService parameterService;
42      private AccountingDocument accountingDocumentForValidation;
43  
44      /**
45       * @see org.kuali.ole.sys.document.validation.Validation#validate(org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent)
46       */
47      @Override
48      public boolean validate(AttributedDocumentEvent event) {
49          LOG.debug("validate start");
50          boolean isValid = true;
51  
52          DisbursementVoucherDocument document = (DisbursementVoucherDocument) accountingDocumentForValidation;
53          DisbursementVoucherPayeeDetail payeeDetail = document.getDvPayeeDetail();
54          String documentationLocationCode = document.getDisbursementVoucherDocumentationLocationCode();
55  
56          MessageMap errors = GlobalVariables.getMessageMap();
57          int initialErrorCount = errors.getErrorCount();
58          errors.addToErrorPath(OLEPropertyConstants.DOCUMENT);
59  
60          // payment reason restrictions
61          if (ObjectUtils.isNotNull(payeeDetail.getDisbVchrPaymentReasonCode())) {
62              ParameterEvaluator parameterEvaluator = /*REFACTORME*/SpringContext.getBean(ParameterEvaluatorService.class).getParameterEvaluator(DisbursementVoucherDocument.class, DisbursementVoucherConstants.VALID_DOC_LOC_BY_PAYMENT_REASON_PARM, DisbursementVoucherConstants.INVALID_DOC_LOC_BY_PAYMENT_REASON_PARM, payeeDetail.getDisbVchrPaymentReasonCode(), documentationLocationCode);
63              parameterEvaluator.evaluateAndAddError(document.getClass(), OLEPropertyConstants.DISBURSEMENT_VOUCHER_DOCUMENTATION_LOCATION_CODE);
64          }
65  
66        //Commented for the jira issue OLE-3415
67          // alien indicator restrictions
68          /*if (payeeDetail.isDisbVchrAlienPaymentCode()) {
69              ParameterEvaluator parameterEvaluator = SpringContext.getBean(ParameterEvaluatorService.class).getParameterEvaluator(DisbursementVoucherDocument.class, ALIEN_INDICATOR_CHECKED_PARM_NM, documentationLocationCode);
70              parameterEvaluator.evaluateAndAddError(document.getClass(), OLEPropertyConstants.DISBURSEMENT_VOUCHER_DOCUMENTATION_LOCATION_CODE);
71          }*/
72  
73          Person initiator = getInitiator(document);
74          ChartOrgHolder chartOrg = SpringContext.getBean(FinancialSystemUserService.class).getPrimaryOrganization(initiator, OLEConstants.ParameterNamespaces.FINANCIAL);
75          String locationCode = (chartOrg == null || chartOrg.getOrganization() == null) ? null : chartOrg.getOrganization().getOrganizationPhysicalCampusCode();
76  
77          // initiator campus code restrictions
78          ParameterEvaluator parameterEvaluator = /*REFACTORME*/SpringContext.getBean(ParameterEvaluatorService.class).getParameterEvaluator(DisbursementVoucherDocument.class, DisbursementVoucherConstants.VALID_DOC_LOC_BY_CAMPUS_PARM, DisbursementVoucherConstants.INVALID_DOC_LOC_BY_CAMPUS_PARM, locationCode, documentationLocationCode);
79          parameterEvaluator.evaluateAndAddError(document.getClass(), OLEPropertyConstants.DISBURSEMENT_VOUCHER_DOCUMENTATION_LOCATION_CODE);
80  
81          errors.removeFromErrorPath(OLEPropertyConstants.DOCUMENT);
82  
83          isValid = initialErrorCount == errors.getErrorCount();
84          return isValid;
85      }
86  
87      /**
88       * Returns the initiator of the document as a KualiUser
89       *
90       * @param document submitted document
91       * @return <code>KualiUser</code>
92       */
93      protected Person getInitiator(AccountingDocument document) {
94          Person initUser = KimApiServiceLocator.getPersonService().getPerson(document.getDocumentHeader().getWorkflowDocument().getInitiatorPrincipalId());
95          if (initUser == null) {
96              throw new RuntimeException("Document Initiator not found ");
97          }
98  
99          return initUser;
100     }
101 
102     /**
103      * Sets the accountingDocumentForValidation attribute value.
104      *
105      * @param accountingDocumentForValidation The accountingDocumentForValidation to set.
106      */
107     public void setAccountingDocumentForValidation(AccountingDocument accountingDocumentForValidation) {
108         this.accountingDocumentForValidation = accountingDocumentForValidation;
109     }
110 
111     /**
112      * Sets the parameterService attribute value.
113      * @param parameterService The parameterService to set.
114      */
115     public void setParameterService(ParameterService parameterService) {
116         this.parameterService = parameterService;
117     }
118 
119     /**
120      * Gets the accountingDocumentForValidation attribute.
121      * @return Returns the accountingDocumentForValidation.
122      */
123     public AccountingDocument getAccountingDocumentForValidation() {
124         return accountingDocumentForValidation;
125     }
126 }
127