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