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.businessobject.PurApAccountingLine;
19  import org.kuali.ole.module.purap.document.OlePurchasingAccountsPayableDocument;
20  import org.kuali.ole.module.purap.document.PurchasingAccountsPayableDocument;
21  import org.kuali.ole.module.purap.document.service.PurapService;
22  import org.kuali.ole.sys.context.SpringContext;
23  import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
24  import org.kuali.ole.sys.service.FinancialSystemWorkflowHelperService;
25  import org.kuali.rice.krad.util.GlobalVariables;
26  
27  /**
28   * A validation that checks whether the given accounting line is accessible to the given user or not
29   */
30  public class PurchaseOrderAmendmentAccountingLineAccessibleValidation extends OlePurchasingAccountsPayableAccountingLineAccessibleValidation {
31  
32      protected PurapService purapService;
33  
34      /**
35       * Validates that the given accounting line is accessible for editing by the current user.
36       * <strong>This method expects a document as the first parameter and an accounting line as the second</strong>
37       *
38       * @see org.kuali.ole.sys.document.validation.Validation#validate(java.lang.Object[])
39       */
40      @Override
41      public boolean validate(AttributedDocumentEvent event) {
42  
43          if (purapService.isDocumentStoppedInRouteNode((OlePurchasingAccountsPayableDocument) event.getDocument(), "New Unordered Items")) {
44              //DO NOTHING: do not check that user owns acct lines; at this level, they can edit all accounts on PO amendment
45              return true;
46  
47          } else if (SpringContext.getBean(FinancialSystemWorkflowHelperService.class).isAdhocApprovalRequestedForPrincipal(event.getDocument().getDocumentHeader().getWorkflowDocument(), GlobalVariables.getUserSession().getPrincipalId())) {
48              return true;
49          } else {
50              boolean result = false;
51              boolean setDummyAccountIdentifier = false;
52  
53              if (needsDummyAccountIdentifier()) {
54                  ((PurApAccountingLine) getAccountingLineForValidation()).setAccountIdentifier(Integer.MAX_VALUE);  // avoid conflicts with any accouting identifier on any other accounting lines in the doc because, you know, you never know...
55                  setDummyAccountIdentifier = true;
56              }
57  
58              result = super.validate(event);
59  
60              if (setDummyAccountIdentifier) {
61                  ((PurApAccountingLine) getAccountingLineForValidation()).setAccountIdentifier(null);
62              }
63  
64              return result;
65          }
66      }
67  
68      public void setPurapService(PurapService purapService) {
69          this.purapService = purapService;
70      }
71  
72  }
73