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.web.struts;
017
018 import java.util.HashSet;
019 import java.util.Map;
020 import java.util.Set;
021
022 import org.apache.commons.lang.StringUtils;
023 import org.kuali.kfs.fp.document.BudgetAdjustmentDocument;
024 import org.kuali.kfs.sys.businessobject.AccountingLine;
025 import org.kuali.kfs.sys.businessobject.AccountingLineOverride;
026 import org.kuali.kfs.sys.businessobject.AccountingLineOverride.COMPONENT;
027 import org.kuali.kfs.sys.web.struts.KualiAccountingDocumentFormBase;
028
029 /**
030 * This class is the form class for the ProcurementCard document. This method extends the parent KualiTransactionalDocumentFormBase
031 * class which contains all of the common form methods and form attributes needed by the Procurment Card document.
032 */
033 public class BudgetAdjustmentForm extends KualiAccountingDocumentFormBase {
034
035 protected static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(BudgetAdjustmentForm.class);
036
037
038 /**
039 * Constructs a BudgetAdjustmentForm instance and sets up the appropriately casted document. Also, the
040 * newSourceLine/newTargetLine need to be the extended
041 * BudgetAdjustmentSourceAccountingLine/BudgetAdjustmentTargetAccountingLine.
042 */
043 public BudgetAdjustmentForm() {
044 super();
045 }
046
047 @Override
048 protected String getDefaultDocumentTypeName() {
049 return "BA";
050 }
051
052 @Override
053 protected void repopulateOverrides(AccountingLine line, String accountingLinePropertyName, Map parameterMap) {
054 determineNeededOverrides(line);
055 if (line.getAccountExpiredOverrideNeeded()) {
056 if (LOG.isDebugEnabled()) {
057 StringUtils.join(parameterMap.keySet(), "\n");
058 }
059 if (parameterMap.containsKey(accountingLinePropertyName+".accountExpiredOverride.present")) {
060 line.setAccountExpiredOverride(parameterMap.containsKey(accountingLinePropertyName+".accountExpiredOverride"));
061 }
062 } else {
063 line.setAccountExpiredOverride(false);
064 }
065 }
066
067 /**
068 * Determines what overrides the given line needs.
069 *
070 * @param line
071 * @return what overrides the given line needs.
072 */
073 public static AccountingLineOverride determineNeededOverrides(AccountingLine line) {
074 Set neededOverrideComponents = new HashSet();
075 if (AccountingLineOverride.needsExpiredAccountOverride(line.getAccount())) {
076 neededOverrideComponents.add(COMPONENT.EXPIRED_ACCOUNT);
077 }
078
079 return AccountingLineOverride.valueOf(neededOverrideComponents);
080 }
081 }