001 /*
002 * Copyright 2011 The Kuali Foundation.
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.kfs.fp.document.authorization;
017
018 import org.apache.commons.lang.StringUtils;
019 import org.kuali.kfs.sys.KFSConstants;
020 import org.kuali.kfs.sys.businessobject.AccountingLine;
021 import org.kuali.rice.kns.util.KNSConstants;
022
023 public class ProcurementCardAccountingLineAuthorizer extends FinancialProcessingAccountingLineAuthorizer {
024 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(ProcurementCardAccountingLineAuthorizer.class);
025
026 /**
027 * @see org.kuali.kfs.sys.document.authorization.AccountingLineAuthorizerBase#getKimHappyPropertyNameForField(java.lang.String)
028 */
029 @Override
030 protected String getKimHappyPropertyNameForField(String convertedName) {
031 String name = stripDocumentPrefixFromName(convertedName);
032 name = name.replaceAll("\\[\\d+\\]", StringUtils.EMPTY);
033 name = name.replaceFirst("(.)*transactionEntries\\.", StringUtils.EMPTY);
034
035 return name;
036 }
037
038 /**
039 * @see org.kuali.kfs.sys.document.authorization.AccountingLineAuthorizerBase#getDeleteLineMethod(org.kuali.kfs.sys.businessobject.AccountingLine,
040 * java.lang.String, java.lang.Integer)
041 */
042 @Override
043 protected String getDeleteLineMethod(AccountingLine accountingLine, String accountingLineProperty, Integer accountingLineIndex) {
044 final String infix = getActionInfixForExtantAccountingLine(accountingLine, accountingLineProperty);
045 String lineIndex = this.getLineContainerIndex(accountingLineProperty);
046 String lineContainer = this.getLineContainer(accountingLineProperty) + ".";
047
048 return KNSConstants.DELETE_METHOD + infix + "Line." + lineContainer + "line" + accountingLineIndex + ".anchoraccounting" + infix + "Anchor";
049 }
050
051 /**
052 * @see org.kuali.kfs.sys.document.authorization.AccountingLineAuthorizerBase#getAddMethod(org.kuali.kfs.sys.businessobject.AccountingLine,
053 * java.lang.String, java.lang.Integer)
054 */
055 @Override
056 protected String getAddMethod(AccountingLine accountingLine, String accountingLineProperty) {
057 String infix = getActionInfixForNewAccountingLine(accountingLine, accountingLineProperty);
058 String lineIndex = this.getLineContainerIndex(accountingLineProperty);
059 String lineContainer = this.getLineContainer(accountingLineProperty) + ".";
060
061 return KFSConstants.INSERT_METHOD + infix + "Line." + lineContainer + "line" + lineIndex + ".anchoraccounting" + infix + "Anchor";
062 }
063
064 /**
065 * @see org.kuali.kfs.sys.document.authorization.AccountingLineAuthorizerBase#getBalanceInquiryMethod(org.kuali.kfs.sys.businessobject.AccountingLine,
066 * java.lang.String, java.lang.Integer)
067 */
068 @Override
069 protected String getBalanceInquiryMethod(AccountingLine accountingLine, String accountingLineProperty, Integer accountingLineIndex) {
070 String infix = getActionInfixForExtantAccountingLine(accountingLine, accountingLineProperty);
071 String lineContainer = this.getLineContainer(accountingLineProperty) + ".";
072
073 return KFSConstants.PERFORMANCE_BALANCE_INQUIRY_FOR_METHOD + infix + "Line." + lineContainer + "line" + accountingLineIndex + ".anchoraccounting" + infix + "existingLineLineAnchor" + accountingLineIndex;
074 }
075
076 protected String getLineContainer(String accountingLineProperty) {
077 String lineContainer = stripDocumentPrefixFromName(accountingLineProperty);
078 return StringUtils.substringBeforeLast(lineContainer, ".");
079 }
080
081 protected String getLineContainerIndex(String accountingLineProperty) {
082 String lineContainer = this.getLineContainer(accountingLineProperty);
083 return StringUtils.substringBetween(lineContainer, "[", "]");
084 }
085 }