View Javadoc
1   /*
2    * Copyright 2008-2009 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.PurapConstants.AccountsPayableStatuses;
20  import org.kuali.ole.module.purap.PurapKeyConstants;
21  import org.kuali.ole.module.purap.document.AccountsPayableDocument;
22  import org.kuali.ole.sys.OLEConstants;
23  import org.kuali.ole.sys.OLEPropertyConstants;
24  import org.kuali.ole.sys.document.validation.GenericValidation;
25  import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
26  import org.kuali.rice.kew.api.WorkflowDocument;
27  import org.kuali.rice.krad.util.GlobalVariables;
28  
29  public class AccountsPayableProcessApprovalAtAccountsPayableReviewAllowedValidation extends GenericValidation {
30  
31      /**
32       * If at the node accounts payable review, checks if approval at accounts payable review is allowed.
33       * Returns true if it is, false otherwise.
34       *
35       * @param apDocument - accounts payable document
36       * @return
37       */
38      @Override
39      public boolean validate(AttributedDocumentEvent event) {
40          boolean valid = true;
41          GlobalVariables.getMessageMap().clearErrorPath();
42          GlobalVariables.getMessageMap().addToErrorPath(OLEPropertyConstants.DOCUMENT);
43  
44          if (((AccountsPayableDocument) event.getDocument()).isDocumentStoppedInRouteNode(AccountsPayableStatuses.NODE_ACCOUNT_PAYABLE_REVIEW)) {
45              if (!((AccountsPayableDocument) event.getDocument()).approvalAtAccountsPayableReviewAllowed()) {
46                  valid &= false;
47                  WorkflowDocument workflowDoc = event.getDocument().getDocumentHeader().getWorkflowDocument();
48                  if (PurapConstants.PurapDocTypeCodes.CREDIT_MEMO_DOCUMENT.equals(workflowDoc.getDocumentTypeName())) {
49                      GlobalVariables.getMessageMap().putError(OLEConstants.GLOBAL_ERRORS, PurapKeyConstants.ERROR_CREDIT_MEMO_REQUIRES_ATTACHMENT);
50                  } else {
51                      GlobalVariables.getMessageMap().putError(OLEConstants.GLOBAL_ERRORS, PurapKeyConstants.ERROR_AP_REQUIRES_ATTACHMENT);
52                  }
53  
54  
55              }
56          }
57          GlobalVariables.getMessageMap().clearErrorPath();
58          return valid;
59      }
60  
61  }