001/*
002 * Copyright 2009 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 */
016package org.kuali.ole.fp.document.authorization;
017
018import org.apache.commons.lang.StringUtils;
019import org.kuali.ole.fp.businessobject.ProcurementCardTargetAccountingLine;
020import org.kuali.ole.sys.OLEConstants;
021import org.kuali.ole.sys.businessobject.AccountingLine;
022import org.kuali.rice.krad.util.KRADConstants;
023
024public class ProcurementCardAccountingLineAuthorizer extends FinancialProcessingAccountingLineAuthorizer {
025    private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(ProcurementCardAccountingLineAuthorizer.class);
026
027    /**
028     * @see org.kuali.ole.sys.document.authorization.AccountingLineAuthorizerBase#getKimHappyPropertyNameForField(java.lang.String)
029     */
030    @Override
031    protected String getKimHappyPropertyNameForField(String convertedName) {
032        String name = stripDocumentPrefixFromName(convertedName);
033        name = name.replaceAll("\\[\\d+\\]", StringUtils.EMPTY);
034        name = name.replaceFirst("(.)*transactionEntries\\.", StringUtils.EMPTY);
035
036        return name;
037    }
038
039    /**
040     * @see org.kuali.ole.sys.document.authorization.AccountingLineAuthorizerBase#getDeleteLineMethod(org.kuali.ole.sys.businessobject.AccountingLine,
041     *      java.lang.String, java.lang.Integer)
042     */
043    @Override
044    protected String getDeleteLineMethod(AccountingLine accountingLine, String accountingLineProperty, Integer accountingLineIndex) {
045        final String infix = getActionInfixForExtantAccountingLine(accountingLine, accountingLineProperty);
046        String lineIndex = this.getLineContainerIndex(accountingLineProperty);
047        String lineContainer = this.getLineContainer(accountingLineProperty) + ".";
048
049        return KRADConstants.DELETE_METHOD + infix + "Line." + lineContainer + "line" + accountingLineIndex + ".anchoraccounting" + infix + "Anchor";
050    }
051
052    /**
053     * @see org.kuali.ole.sys.document.authorization.AccountingLineAuthorizerBase#getAddMethod(org.kuali.ole.sys.businessobject.AccountingLine,
054     *      java.lang.String, java.lang.Integer)
055     */
056    @Override
057    protected String getAddMethod(AccountingLine accountingLine, String accountingLineProperty) {
058        Integer lineIndex = ((ProcurementCardTargetAccountingLine) accountingLine).getTransactionContainerIndex();
059        String lineIndexString = lineIndex.toString();
060
061        String infix = getActionInfixForNewAccountingLine(accountingLine, accountingLineProperty);
062
063        return OLEConstants.INSERT_METHOD + infix + "Line" + ".transactionEntries[" + lineIndex + "]";
064    }
065
066    /**
067     * @see org.kuali.ole.sys.document.authorization.AccountingLineAuthorizerBase#getBalanceInquiryMethod(org.kuali.ole.sys.businessobject.AccountingLine,
068     *      java.lang.String, java.lang.Integer)
069     */
070    @Override
071    protected String getBalanceInquiryMethod(AccountingLine accountingLine, String accountingLineProperty, Integer accountingLineIndex) {
072        String infix = getActionInfixForExtantAccountingLine(accountingLine, accountingLineProperty);
073        String lineContainer = this.getLineContainer(accountingLineProperty) + ".";
074
075        return OLEConstants.PERFORMANCE_BALANCE_INQUIRY_FOR_METHOD + infix + "Line." + lineContainer + "line" + accountingLineIndex + ".anchoraccounting" + infix + "existingLineLineAnchor" + accountingLineIndex;
076    }
077
078    protected String getLineContainer(String accountingLineProperty) {
079        String lineContainer = stripDocumentPrefixFromName(accountingLineProperty);
080        return StringUtils.substringBeforeLast(lineContainer, ".");
081    }
082
083    protected String getLineContainerIndex(String accountingLineProperty) {
084        String lineContainer = this.getLineContainer(accountingLineProperty);
085        return StringUtils.substringBetween(lineContainer, "[", "]");
086    }
087}