View Javadoc
1   /*
2    * Copyright 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.fp.document.authorization;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.kuali.ole.fp.businessobject.ProcurementCardTargetAccountingLine;
20  import org.kuali.ole.sys.OLEConstants;
21  import org.kuali.ole.sys.businessobject.AccountingLine;
22  import org.kuali.rice.krad.util.KRADConstants;
23  
24  public class ProcurementCardAccountingLineAuthorizer extends FinancialProcessingAccountingLineAuthorizer {
25      private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(ProcurementCardAccountingLineAuthorizer.class);
26  
27      /**
28       * @see org.kuali.ole.sys.document.authorization.AccountingLineAuthorizerBase#getKimHappyPropertyNameForField(java.lang.String)
29       */
30      @Override
31      protected String getKimHappyPropertyNameForField(String convertedName) {
32          String name = stripDocumentPrefixFromName(convertedName);
33          name = name.replaceAll("\\[\\d+\\]", StringUtils.EMPTY);
34          name = name.replaceFirst("(.)*transactionEntries\\.", StringUtils.EMPTY);
35  
36          return name;
37      }
38  
39      /**
40       * @see org.kuali.ole.sys.document.authorization.AccountingLineAuthorizerBase#getDeleteLineMethod(org.kuali.ole.sys.businessobject.AccountingLine,
41       *      java.lang.String, java.lang.Integer)
42       */
43      @Override
44      protected String getDeleteLineMethod(AccountingLine accountingLine, String accountingLineProperty, Integer accountingLineIndex) {
45          final String infix = getActionInfixForExtantAccountingLine(accountingLine, accountingLineProperty);
46          String lineIndex = this.getLineContainerIndex(accountingLineProperty);
47          String lineContainer = this.getLineContainer(accountingLineProperty) + ".";
48  
49          return KRADConstants.DELETE_METHOD + infix + "Line." + lineContainer + "line" + accountingLineIndex + ".anchoraccounting" + infix + "Anchor";
50      }
51  
52      /**
53       * @see org.kuali.ole.sys.document.authorization.AccountingLineAuthorizerBase#getAddMethod(org.kuali.ole.sys.businessobject.AccountingLine,
54       *      java.lang.String, java.lang.Integer)
55       */
56      @Override
57      protected String getAddMethod(AccountingLine accountingLine, String accountingLineProperty) {
58          Integer lineIndex = ((ProcurementCardTargetAccountingLine) accountingLine).getTransactionContainerIndex();
59          String lineIndexString = lineIndex.toString();
60  
61          String infix = getActionInfixForNewAccountingLine(accountingLine, accountingLineProperty);
62  
63          return OLEConstants.INSERT_METHOD + infix + "Line" + ".transactionEntries[" + lineIndex + "]";
64      }
65  
66      /**
67       * @see org.kuali.ole.sys.document.authorization.AccountingLineAuthorizerBase#getBalanceInquiryMethod(org.kuali.ole.sys.businessobject.AccountingLine,
68       *      java.lang.String, java.lang.Integer)
69       */
70      @Override
71      protected String getBalanceInquiryMethod(AccountingLine accountingLine, String accountingLineProperty, Integer accountingLineIndex) {
72          String infix = getActionInfixForExtantAccountingLine(accountingLine, accountingLineProperty);
73          String lineContainer = this.getLineContainer(accountingLineProperty) + ".";
74  
75          return OLEConstants.PERFORMANCE_BALANCE_INQUIRY_FOR_METHOD + infix + "Line." + lineContainer + "line" + accountingLineIndex + ".anchoraccounting" + infix + "existingLineLineAnchor" + accountingLineIndex;
76      }
77  
78      protected String getLineContainer(String accountingLineProperty) {
79          String lineContainer = stripDocumentPrefixFromName(accountingLineProperty);
80          return StringUtils.substringBeforeLast(lineContainer, ".");
81      }
82  
83      protected String getLineContainerIndex(String accountingLineProperty) {
84          String lineContainer = this.getLineContainer(accountingLineProperty);
85          return StringUtils.substringBetween(lineContainer, "[", "]");
86      }
87  }