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.authorization;
17  
18  import java.util.List;
19  
20  import org.kuali.ole.fp.document.DistributionOfIncomeAndExpenseDocument;
21  import org.kuali.ole.sys.OLEPropertyConstants;
22  import org.kuali.ole.sys.businessobject.AccountingLine;
23  import org.kuali.ole.sys.businessobject.ElectronicPaymentClaim;
24  import org.kuali.ole.sys.document.AccountingDocument;
25  import org.kuali.rice.krad.util.ObjectUtils;
26  
27  /**
28   * Authorizer which deals with financial processing document issues, specifically sales tax lines on documents This class utilizes
29   * the new accountingLine model.
30   */
31  public class DistributionOfIncomeAndExpenseAccountingLineAuthorizer extends FinancialProcessingAccountingLineAuthorizer {
32  
33      /**
34       * This method determines if the current accounting line is editable based upon if electronic claims exists on the DI document.
35       * 
36       * @see org.kuali.ole.sys.document.authorization.AccountingLineAuthorizerBase#determineFieldModifyability(org.kuali.ole.sys.document.AccountingDocument,
37       *      org.kuali.ole.sys.businessobject.AccountingLine, org.kuali.ole.sys.document.web.AccountingLineViewField, java.util.Map)
38       */
39      @Override
40      public boolean determineEditPermissionOnField(AccountingDocument accountingDocument, AccountingLine accountingLine, String accountingLineCollectionProperty, String fieldName, boolean editablePage) {
41          final boolean canModify = super.determineEditPermissionOnField(accountingDocument, accountingLine, accountingLineCollectionProperty, fieldName, editablePage);
42          if (canModify && accountingLine.isSourceAccountingLine()) {
43              return !hasElectronicPaymentClaims(accountingDocument);
44          }
45          
46          return canModify;
47      }
48  
49      /**
50       * Don't render a new line if this is the source group and there's electronic payment claims
51       * @see org.kuali.ole.sys.document.authorization.AccountingLineAuthorizerBase#renderNewLine(org.kuali.ole.sys.document.AccountingDocument, java.lang.String)
52       */
53      @Override
54      public boolean renderNewLine(AccountingDocument accountingDocument, String accountingGroupProperty) {
55          final boolean shouldRender = super.renderNewLine(accountingDocument, accountingGroupProperty);
56          if (shouldRender && accountingGroupProperty.contains("source")) {
57              return !hasElectronicPaymentClaims(accountingDocument);
58          }
59          return shouldRender;
60      }
61  
62      /**
63       * There's no edit permission on lines in the source group on documents claiming electronic payments
64       * @see org.kuali.ole.sys.document.authorization.AccountingLineAuthorizerBase#determineEditPermissionOnLine(org.kuali.ole.sys.document.AccountingDocument, org.kuali.ole.sys.businessobject.AccountingLine, java.lang.String)
65       */
66      @Override
67      public boolean determineEditPermissionOnLine(AccountingDocument accountingDocument, AccountingLine accountingLine, String accountingLineCollectionProperty, boolean currentUserIsDocumentInitiator, boolean pageIsEditable) {
68          final boolean hasEditPermOnLine = super.determineEditPermissionOnLine(accountingDocument, accountingLine, accountingLineCollectionProperty, currentUserIsDocumentInitiator, pageIsEditable);
69          if (hasEditPermOnLine && accountingLineCollectionProperty.contains("source")) {
70              return !hasElectronicPaymentClaims(accountingDocument);
71          }
72          return hasEditPermOnLine;
73      }
74  
75      /**
76       * Determines if the DI document has electronic payment claims associated with it
77       * @param accountingDocument a DI document
78       * @return true if there are electronic payment claims, false otherwise
79       */
80      protected boolean hasElectronicPaymentClaims(AccountingDocument accountingDocument) {
81          DistributionOfIncomeAndExpenseDocument diDoc = (DistributionOfIncomeAndExpenseDocument) accountingDocument;
82  
83          List<ElectronicPaymentClaim> epcs = diDoc.getElectronicPaymentClaims();
84  
85          if (epcs == null) {
86              diDoc.refreshReferenceObject(OLEPropertyConstants.ELECTRONIC_PAYMENT_CLAIMS);
87              epcs = diDoc.getElectronicPaymentClaims();
88          }
89  
90          return (!ObjectUtils.isNull(epcs) && epcs.size() > 0);
91      }
92  
93  }