View Javadoc
1   /*
2    * Copyright 2006-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.module.purap.document.validation.impl;
17  
18  import org.kuali.ole.module.purap.PurapConstants;
19  import org.kuali.ole.module.purap.document.ElectronicInvoiceRejectDocument;
20  import org.kuali.ole.module.purap.service.ElectronicInvoiceHelperService;
21  import org.kuali.ole.sys.OLEConstants;
22  import org.kuali.ole.sys.context.SpringContext;
23  import org.kuali.rice.core.api.util.type.KualiDecimal;
24  import org.kuali.rice.kns.rules.DocumentRuleBase;
25  import org.kuali.rice.krad.document.Document;
26  import org.kuali.rice.krad.util.GlobalVariables;
27  
28  import java.math.BigDecimal;
29  
30  /**
31   * Business rule(s) applicable to Payment Request documents.
32   */
33  public class ElectronicInvoiceRejectDocumentRule extends DocumentRuleBase {
34  
35      protected static KualiDecimal zero = KualiDecimal.ZERO;
36      protected static BigDecimal ONE_HUNDRED = BigDecimal.valueOf(100);
37  
38      /**
39       * @see org.kuali.rice.krad.rules.DocumentRuleBase#processCustomRouteDocumentBusinessRules(org.kuali.rice.krad.document.Document)
40       */
41      @Override
42      protected boolean processCustomRouteDocumentBusinessRules(Document document) {
43          return processBusinessRules(document);
44      }
45  
46      protected boolean processBusinessRules(Document document) {
47          boolean isValid = true;
48  
49          ElectronicInvoiceRejectDocument eirDocument = (ElectronicInvoiceRejectDocument) document;
50  
51          // check to see if the document is being researched
52          if (eirDocument.isInvoiceResearchIndicator()) {
53              GlobalVariables.getMessageMap().putError(OLEConstants.DOCUMENT_ERRORS, PurapConstants.REJECT_DOCUMENT_RESEARCH_INCOMPETE);
54              isValid = false;
55          }
56  
57          if (!eirDocument.isDocumentCreationInProgress()) {
58              isValid = isValid && SpringContext.getBean(ElectronicInvoiceHelperService.class).doMatchingProcess(eirDocument);
59              if (isValid) {
60                  SpringContext.getBean(ElectronicInvoiceHelperService.class).createPaymentRequest(eirDocument);
61              }
62          }
63  
64          return isValid;
65      }
66  
67  }