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.module.ld.document.web.struts;
017
018 import java.util.ArrayList;
019
020 import javax.servlet.http.HttpServletRequest;
021 import javax.servlet.http.HttpServletResponse;
022 import org.kuali.kfs.module.ld.document.web.struts.BenefitExpenseTransferForm;
023 import org.apache.commons.lang.StringUtils;
024 import org.apache.struts.action.ActionForm;
025 import org.apache.struts.action.ActionForward;
026 import org.apache.struts.action.ActionMapping;
027 import org.kuali.kfs.module.ld.LaborConstants;
028 import org.kuali.kfs.module.ld.businessobject.ExpenseTransferAccountingLine;
029 import org.kuali.kfs.module.ld.businessobject.LaborLedgerPendingEntry;
030 import org.kuali.kfs.module.ld.businessobject.LedgerBalance;
031 import org.kuali.kfs.sys.KFSConstants;
032 import org.kuali.kfs.sys.ObjectUtil;
033 import org.kuali.rice.kns.util.KualiDecimal;
034
035 /**
036 * Struts Action class for the Benefit Expense Transfer Document.
037 */
038 public class BenefitExpenseTransferAction extends ExpenseTransferDocumentActionBase {
039 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(BenefitExpenseTransferAction.class);
040
041 /**
042 * Gets the Business object class name
043 *
044 * @param expenseTransferDocumentFormBase ExpenseTransferDocumentForm type
045 * @return String classname
046 * @see org.kuali.kfs.module.ld.document.web.struts.ExpenseTransferDocumentActionBase#getLookupResultsBOClassName(org.kuali.kfs.module.ld.document.web.struts.ExpenseTransferDocumentFormBase)
047 */
048 @Override
049 protected String getLookupResultsBOClassName(ExpenseTransferDocumentFormBase expenseTransferDocumentForm) {
050 return LedgerBalance.class.getName();
051 }
052
053 /**
054 * @param expenseTransferDocumentFormBase ExpenseTransferDocumentForm type
055 * @param balance LedgerBalance type
056 * @return none
057 * @see org.kuali.kfs.module.ld.document.web.struts.ExpenseTransferDocumentActionBase#resetLookupFields(org.kuali.kfs.module.ld.document.web.struts.ExpenseTransferDocumentFormBase,
058 * org.kuali.kfs.module.ld.businessobject.LedgerBalance)
059 */
060 @Override
061 protected void resetLookupFields(ExpenseTransferDocumentFormBase expenseTransferDocumentForm, LedgerBalance balance) {
062 BenefitExpenseTransferForm benefitExpenseTransferForm = (BenefitExpenseTransferForm) expenseTransferDocumentForm;
063 ObjectUtil.buildObject(benefitExpenseTransferForm, balance);
064 }
065
066 /**
067 * @param mapping ActionMapping
068 * @param form ActionForm
069 * @param request HttpServletRequest
070 * @param response HttpServletResponse
071 * @see org.kuali.rice.kns.web.struts.action.KualiAction#performLookup(org.apache.struts.action.ActionMapping,
072 * org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
073 */
074 @Override
075 public ActionForward performLookup(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
076 // parse out the business object name from our methodToCall parameter
077 String fullParameter = (String) request.getAttribute(KFSConstants.METHOD_TO_CALL_ATTRIBUTE);
078 String boClassName = StringUtils.substringBetween(fullParameter, KFSConstants.METHOD_TO_CALL_BOPARM_LEFT_DEL, KFSConstants.METHOD_TO_CALL_BOPARM_RIGHT_DEL);
079
080 if (!StringUtils.equals(boClassName, LaborLedgerPendingEntry.class.getName())) {
081 return super.performLookup(mapping, form, request, response);
082 }
083
084 String path = super.performLookup(mapping, form, request, response).getPath();
085 path = path.replaceFirst(KFSConstants.LOOKUP_ACTION, LaborConstants.LONG_ROW_TABLE_INRUIRY_ACTION);
086 return new ActionForward(path, true);
087 }
088
089 /**
090 * Delete all source accounting lines
091 *
092 * @param mapping
093 * @param form
094 * @param request
095 * @param response
096 * @return ActionMapping
097 * @throws Exception
098 */
099 @Override
100 public ActionForward deleteAllSourceAccountingLines(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
101 BenefitExpenseTransferForm financialDocumentForm = (BenefitExpenseTransferForm) form;
102 financialDocumentForm.getBenefitExpenseTransferDocument().setNextSourceLineNumber(KFSConstants.ONE.intValue());
103
104 return super.deleteAllSourceAccountingLines(mapping, form, request, response);
105 }
106
107 /**
108 * Delete all target accounting lines
109 *
110 * @param mapping
111 * @param form
112 * @param request
113 * @param response
114 * @return ActionMapping
115 * @throws Exception
116 */
117 @Override
118 public ActionForward deleteAllTargetAccountingLines(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
119 BenefitExpenseTransferForm financialDocumentForm = (BenefitExpenseTransferForm) form;
120 financialDocumentForm.getBenefitExpenseTransferDocument().setNextTargetLineNumber(KFSConstants.ONE.intValue());
121
122 return super.deleteAllTargetAccountingLines(mapping, form, request, response);
123 }
124
125 /**
126 * @see org.kuali.kfs.module.ld.document.web.struts.ExpenseTransferDocumentActionBase#buildAccountingLineFromLedgerBalance(org.kuali.kfs.module.ld.businessobject.LedgerBalance, org.kuali.kfs.module.ld.businessobject.ExpenseTransferAccountingLine, org.kuali.rice.kns.util.KualiDecimal, java.lang.String)
127 */
128 @Override
129 protected void buildAccountingLineFromLedgerBalance(LedgerBalance ledgerBalance, ExpenseTransferAccountingLine line, KualiDecimal amount, String periodCode) {
130 super.buildAccountingLineFromLedgerBalance(ledgerBalance, line, amount, periodCode);
131 line.setEmplid(LaborConstants.getDashEmplId());
132 line.setPositionNumber(LaborConstants.getDashPositionNumber());
133
134 }
135 }