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.cab.document.web.struts; 017 018 import java.util.ArrayList; 019 import java.util.List; 020 021 import javax.servlet.http.HttpServletRequest; 022 023 import org.apache.commons.lang.StringUtils; 024 import org.apache.struts.action.ActionMapping; 025 import org.kuali.kfs.fp.businessobject.CapitalAssetInformation; 026 import org.kuali.kfs.module.cab.CabConstants; 027 import org.kuali.kfs.module.cab.CabPropertyConstants; 028 import org.kuali.kfs.module.cab.businessobject.GeneralLedgerEntry; 029 import org.kuali.rice.kns.util.KNSConstants; 030 import org.kuali.rice.kns.web.struts.form.KualiForm; 031 032 public class GlLineForm extends KualiForm { 033 private List<GeneralLedgerEntry> relatedGlEntries; 034 private Long primaryGlAccountId; 035 private CapitalAssetInformation capitalAssetInformation; 036 private boolean selectAllGlEntries; 037 private String currDocNumber; 038 039 @Override 040 public boolean shouldMethodToCallParameterBeUsed(String methodToCallParameterName, String methodToCallParameterValue, HttpServletRequest request) { 041 if (StringUtils.equals(methodToCallParameterName, KNSConstants.DISPATCH_REQUEST_PARAMETER) && (StringUtils.equals(methodToCallParameterValue, CabConstants.Actions.PROCESS) || StringUtils.equals(methodToCallParameterValue, CabConstants.Actions.VIEW_DOC))) { 042 return true; 043 } 044 return super.shouldMethodToCallParameterBeUsed(methodToCallParameterName, methodToCallParameterValue, request); 045 } 046 047 @Override 048 public void addRequiredNonEditableProperties() { 049 super.addRequiredNonEditableProperties(); 050 registerRequiredNonEditableProperty(CabPropertyConstants.GeneralLedgerEntry.GENERAL_LEDGER_ACCOUNT_IDENTIFIER); 051 } 052 053 public GlLineForm() { 054 this.relatedGlEntries = new ArrayList<GeneralLedgerEntry>(); 055 } 056 057 /** 058 * Gets the relatedGlEntries attribute. 059 * 060 * @return Returns the relatedGlEntries. 061 */ 062 public List<GeneralLedgerEntry> getRelatedGlEntries() { 063 return relatedGlEntries; 064 } 065 066 /** 067 * Sets the relatedGlEntries attribute value. 068 * 069 * @param relatedGlEntries The relatedGlEntries to set. 070 */ 071 public void setRelatedGlEntries(List<GeneralLedgerEntry> relatedGlEntries) { 072 this.relatedGlEntries = relatedGlEntries; 073 } 074 075 076 /** 077 * Gets the primaryGlAccountId attribute. 078 * 079 * @return Returns the primaryGlAccountId. 080 */ 081 public Long getPrimaryGlAccountId() { 082 return primaryGlAccountId; 083 } 084 085 /** 086 * Sets the primaryGlAccountId attribute value. 087 * 088 * @param primaryGlAccountId The primaryGlAccountId to set. 089 */ 090 public void setPrimaryGlAccountId(Long primaryGlAccountId) { 091 this.primaryGlAccountId = primaryGlAccountId; 092 } 093 094 /** 095 * Gets the capitalAssetInformation attribute. 096 * 097 * @return Returns the capitalAssetInformation. 098 */ 099 public CapitalAssetInformation getCapitalAssetInformation() { 100 return capitalAssetInformation; 101 } 102 103 /** 104 * Sets the capitalAssetInformation attribute value. 105 * 106 * @param capitalAssetInformation The capitalAssetInformation to set. 107 */ 108 public void setCapitalAssetInformation(CapitalAssetInformation capitalAssetInformation) { 109 this.capitalAssetInformation = capitalAssetInformation; 110 } 111 112 /** 113 * Initialize index for struts 114 * 115 * @param index current 116 * @return value 117 */ 118 public GeneralLedgerEntry getRelatedGlEntry(int index) { 119 int size = getRelatedGlEntries().size(); 120 while (size <= index || getRelatedGlEntries().get(index) == null) { 121 getRelatedGlEntries().add(size++, new GeneralLedgerEntry()); 122 } 123 return (GeneralLedgerEntry) getRelatedGlEntries().get(index); 124 } 125 126 /** 127 * Gets the selectAllGlEntries attribute. 128 * 129 * @return Returns the selectAllGlEntries. 130 */ 131 public boolean isSelectAllGlEntries() { 132 return selectAllGlEntries; 133 } 134 135 /** 136 * Sets the selectAllGlEntries attribute value. 137 * 138 * @param selectAllGlEntries The selectAllGlEntries to set. 139 */ 140 public void setSelectAllGlEntries(boolean selectAllGlEntries) { 141 this.selectAllGlEntries = selectAllGlEntries; 142 } 143 144 145 /** 146 * Gets the currDocNumber attribute. 147 * 148 * @return Returns the currDocNumber. 149 */ 150 public String getCurrDocNumber() { 151 return currDocNumber; 152 } 153 154 /** 155 * Sets the currDocNumber attribute value. 156 * 157 * @param currDocNumber The currDocNumber to set. 158 */ 159 public void setCurrDocNumber(String currDocNumber) { 160 this.currDocNumber = currDocNumber; 161 } 162 163 @Override 164 public void reset(ActionMapping mapping, HttpServletRequest request) { 165 super.reset(mapping, request); 166 this.selectAllGlEntries = false; 167 this.currDocNumber = null; 168 } 169 170 @Override 171 public boolean getIsNewForm() { 172 // TODO hack for now 173 // Avoid this exception after first submit 174 /* 175 * java.lang.RuntimeException: Cannot verify that the methodToCall should be methodToCall.submitAssetGlobal.x 176 * org.kuali.rice.kns.util.WebUtils.parseMethodToCall(WebUtils.java:112) 177 */ 178 return true; 179 } 180 }