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.endow.document.web.struts; 017 018 import static org.kuali.kfs.module.endow.EndowConstants.EXISTING_SOURCE_TRAN_LINE_PROPERTY_NAME; 019 import static org.kuali.kfs.module.endow.EndowConstants.EXISTING_TARGET_TRAN_LINE_PROPERTY_NAME; 020 import static org.kuali.kfs.module.endow.EndowConstants.NEW_SOURCE_TRAN_LINE_PROPERTY_NAME; 021 import static org.kuali.kfs.module.endow.EndowConstants.NEW_TARGET_TRAN_LINE_PROPERTY_NAME; 022 import static org.kuali.kfs.module.endow.EndowConstants.TRANSACTION_LINE_ERRORS; 023 024 import java.util.List; 025 import java.util.Properties; 026 027 import javax.servlet.http.HttpServletRequest; 028 import javax.servlet.http.HttpServletResponse; 029 030 import org.apache.commons.lang.StringUtils; 031 import org.apache.struts.action.ActionForm; 032 import org.apache.struts.action.ActionForward; 033 import org.apache.struts.action.ActionMapping; 034 import org.apache.struts.upload.FormFile; 035 import org.kuali.kfs.module.endow.EndowKeyConstants; 036 import org.kuali.kfs.module.endow.EndowPropertyConstants; 037 import org.kuali.kfs.module.endow.businessobject.ClassCode; 038 import org.kuali.kfs.module.endow.businessobject.EndowmentSourceTransactionLine; 039 import org.kuali.kfs.module.endow.businessobject.EndowmentTargetTransactionLine; 040 import org.kuali.kfs.module.endow.businessobject.EndowmentTransactionCode; 041 import org.kuali.kfs.module.endow.businessobject.EndowmentTransactionLine; 042 import org.kuali.kfs.module.endow.businessobject.KEMID; 043 import org.kuali.kfs.module.endow.businessobject.KEMIDCurrentBalance; 044 import org.kuali.kfs.module.endow.businessobject.RegistrationCode; 045 import org.kuali.kfs.module.endow.businessobject.Security; 046 import org.kuali.kfs.module.endow.document.EndowmentSecurityDetailsDocumentBase; 047 import org.kuali.kfs.module.endow.document.EndowmentTransactionLinesDocument; 048 import org.kuali.kfs.module.endow.document.EndowmentTransactionLinesDocumentBase; 049 import org.kuali.kfs.module.endow.document.service.ClassCodeService; 050 import org.kuali.kfs.module.endow.document.service.EndowmentTransactionCodeService; 051 import org.kuali.kfs.module.endow.document.service.KEMIDService; 052 import org.kuali.kfs.module.endow.document.service.RegistrationCodeService; 053 import org.kuali.kfs.module.endow.document.service.SecurityService; 054 import org.kuali.kfs.module.endow.document.validation.event.AddTransactionLineEvent; 055 import org.kuali.kfs.module.endow.document.validation.event.DeleteTransactionLineEvent; 056 import org.kuali.kfs.module.endow.exception.LineParserException; 057 import org.kuali.kfs.module.endow.util.LineParser; 058 import org.kuali.kfs.sys.KFSConstants; 059 import org.kuali.kfs.sys.businessobject.FinancialSystemDocumentHeader; 060 import org.kuali.kfs.sys.context.SpringContext; 061 import org.kuali.kfs.sys.document.AmountTotaling; 062 import org.kuali.kfs.sys.document.web.struts.FinancialSystemTransactionalDocumentActionBase; 063 import org.kuali.rice.kew.exception.WorkflowException; 064 import org.kuali.rice.kns.service.KualiConfigurationService; 065 import org.kuali.rice.kns.service.KualiRuleService; 066 import org.kuali.rice.kns.util.GlobalVariables; 067 import org.kuali.rice.kns.util.KNSConstants; 068 import org.kuali.rice.kns.util.UrlFactory; 069 import org.kuali.rice.kns.web.struts.form.KualiDocumentFormBase; 070 import org.kuali.rice.kns.web.struts.form.KualiForm; 071 072 public abstract class EndowmentTransactionLinesDocumentActionBase extends FinancialSystemTransactionalDocumentActionBase { 073 074 private static final String SECURITY_SOURCE_REFRESH = "document.sourceTransactionSecurity.securityID"; 075 private static final String SECURITY_TARGET_REFRESH = "document.targetTransactionSecurity.securityID"; 076 private static final String REGISTRATION_SOURCE_REFRESH = "document.sourceTransactionSecurity.registrationCode"; 077 private static final String REGISTRATION_TARGET_REFRESH = "document.targetTransactionSecurity.registrationCode"; 078 079 protected static org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger(EndowmentTransactionLinesDocumentActionBase.class); 080 081 082 /** 083 * @see org.kuali.rice.kns.web.struts.action.KualiDocumentActionBase#loadDocument(org.kuali.rice.kns.web.struts.form.KualiDocumentFormBase) 084 */ 085 @Override 086 protected void loadDocument(KualiDocumentFormBase kualiDocumentFormBase) throws WorkflowException { 087 088 super.loadDocument(kualiDocumentFormBase); 089 090 EndowmentTransactionLinesDocumentFormBase form = (EndowmentTransactionLinesDocumentFormBase) kualiDocumentFormBase; 091 EndowmentTransactionLinesDocumentBase document = form.getEndowmentTransactionLinesDocumentBase(); 092 093 // for documents that have Security Details section update referenced info 094 if (document != null && document instanceof EndowmentSecurityDetailsDocumentBase) { 095 096 EndowmentSecurityDetailsDocumentBase securityDetailsDocumentBase = (EndowmentSecurityDetailsDocumentBase) document; 097 098 // source 099 if (securityDetailsDocumentBase.getSourceTransactionSecurity() != null) { 100 // update security and class code if security ID not empty 101 if (securityDetailsDocumentBase.getSourceTransactionSecurity().getSecurityID() != null) { 102 securityDetailsDocumentBase.getSourceTransactionSecurity().refreshReferenceObject(EndowPropertyConstants.TRANSACTION_SECURITY); 103 securityDetailsDocumentBase.getSourceTransactionSecurity().getSecurity().refreshReferenceObject(EndowPropertyConstants.SECURITY_CLASS_CODE_REF); 104 } 105 // update registration code if registration code not empty 106 if (securityDetailsDocumentBase.getSourceTransactionSecurity().getRegistrationCode() != null) { 107 securityDetailsDocumentBase.getSourceTransactionSecurity().refreshReferenceObject(EndowPropertyConstants.TRANSACTION_REGISTRATION_CD); 108 } 109 } 110 // target 111 if (securityDetailsDocumentBase.getTargetTransactionSecurity() != null) { 112 // update security and class code if security ID not empty 113 if (securityDetailsDocumentBase.getTargetTransactionSecurity().getSecurityID() != null) { 114 securityDetailsDocumentBase.getTargetTransactionSecurity().refreshReferenceObject(EndowPropertyConstants.TRANSACTION_SECURITY); 115 securityDetailsDocumentBase.getTargetTransactionSecurity().getSecurity().refreshReferenceObject(EndowPropertyConstants.SECURITY_CLASS_CODE_REF); 116 } 117 // update registration code if registration code not empty 118 if (securityDetailsDocumentBase.getTargetTransactionSecurity().getRegistrationCode() != null) { 119 securityDetailsDocumentBase.getTargetTransactionSecurity().refreshReferenceObject(EndowPropertyConstants.TRANSACTION_REGISTRATION_CD); 120 } 121 } 122 } 123 } 124 125 /** 126 * @param mapping 127 * @param form 128 * @param request 129 * @param response 130 * @return ActionForward 131 * @throws Exception 132 */ 133 public ActionForward importSourceTransactionLines(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { 134 importTransactionLines(true, form); 135 return mapping.findForward(KFSConstants.MAPPING_BASIC); 136 } 137 138 /** 139 * @param mapping 140 * @param form 141 * @param request 142 * @param response 143 * @return ActionForward 144 * @throws Exception 145 */ 146 public ActionForward importTargetTransactionLines(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { 147 148 importTransactionLines(false, form); 149 return mapping.findForward(KFSConstants.MAPPING_BASIC); 150 } 151 152 /** 153 * Cancels import. 154 * 155 * @param mapping 156 * @param form 157 * @param request 158 * @param response 159 * @return 160 * @throws Exception 161 */ 162 public ActionForward cancelImport(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { 163 return mapping.findForward(KFSConstants.MAPPING_BASIC); 164 } 165 166 167 /** 168 * @param mapping 169 * @param form 170 * @param request 171 * @param response 172 * @return ActionForward 173 * @throws Exception 174 */ 175 public void importTransactionLines(boolean isSource, ActionForm form) throws Exception { 176 log.info("Importing item lines"); 177 178 EndowmentTransactionLinesDocumentFormBase tranLineForm = (EndowmentTransactionLinesDocumentFormBase) form; 179 EndowmentTransactionLinesDocument tranLineDocument = (EndowmentTransactionLinesDocument) tranLineForm.getDocument(); 180 String documentNumber = tranLineDocument.getDocumentNumber(); 181 182 FormFile lineFile = (isSource ? tranLineForm.getTransactionSourceLinesImportFile() : tranLineForm.getTransactionLineImportFile()); 183 Class lineClass = tranLineDocument.getTranLineClass(isSource); 184 List<EndowmentTransactionLine> importedTransactionLines = null; 185 186 String errorPath = TRANSACTION_LINE_ERRORS; 187 LineParser lineParser = tranLineDocument.getLineParser(); 188 189 // Starting position of the imported items, equals the # of existing above-the-line items. 190 int itemLinePosition = 0; 191 int transactionLineSize = 0; 192 if (isSource) { 193 itemLinePosition = tranLineDocument.getNextSourceLineNumber(); 194 transactionLineSize = tranLineDocument.getSourceTransactionLines().size(); 195 } 196 else { 197 itemLinePosition = tranLineDocument.getNextTargetLineNumber(); 198 transactionLineSize = tranLineDocument.getTargetTransactionLines().size(); 199 } 200 201 try { 202 importedTransactionLines = lineParser.importLines(lineFile, lineClass, documentNumber); 203 204 // Validate imported items 205 boolean rulePassed = true; 206 int lineNumber = 1; 207 208 // for (EndowmentTransactionLine line : importedTransactionLines) { 209 // // Before the validation, set the item line number to the same as the line number in the import file (starting from 210 // // 1) So that the error message will use the correct line number if there're errors for the current item line. 211 // line.setTransactionLineNumber(++lineNumber); 212 // 213 // if (isSource) { 214 // // check any business rules 215 // rulePassed &= SpringContext.getBean(KualiRuleService.class).applyRules(new AddTransactionLineEvent(NEW_SOURCE_TRAN_LINE_PROPERTY_NAME, tranLineDocument, line)); 216 // } 217 // else { 218 // // check any business rules 219 // rulePassed &= SpringContext.getBean(KualiRuleService.class).applyRules(new AddTransactionLineEvent(NEW_TARGET_TRAN_LINE_PROPERTY_NAME, tranLineDocument, line)); 220 // } 221 // } 222 // 223 if (rulePassed) { 224 // Add the lines to the collection 1 by one. 225 for (EndowmentTransactionLine line : importedTransactionLines) { 226 insertTransactionLine(isSource, tranLineForm, line); 227 } 228 } 229 } 230 catch (LineParserException e) { 231 GlobalVariables.getMessageMap().putError(errorPath, e.getErrorKey(), e.getErrorParameters()); 232 } 233 } 234 235 /** 236 * This action executes an insert of an EndowmentTargetTransactionLine into a document only after validating the Transaction 237 * line and checking any appropriate business rules. 238 * 239 * @param mapping 240 * @param form 241 * @param request 242 * @param response 243 * @return 244 * @throws Exception 245 */ 246 public ActionForward insertTargetTransactionLine(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { 247 EndowmentTransactionLinesDocumentFormBase documentForm = (EndowmentTransactionLinesDocumentFormBase) form; 248 EndowmentTransactionLinesDocument endowmentDocument = (EndowmentTransactionLinesDocument) documentForm.getDocument(); 249 250 EndowmentTargetTransactionLine transLine = (EndowmentTargetTransactionLine) documentForm.getNewTargetTransactionLine(); 251 252 boolean rulePassed = true; 253 254 // check any business rules 255 rulePassed &= SpringContext.getBean(KualiRuleService.class).applyRules(new AddTransactionLineEvent(NEW_TARGET_TRAN_LINE_PROPERTY_NAME, endowmentDocument, transLine)); 256 257 if (rulePassed) { 258 // add accountingLine 259 260 // SpringContext.getBean(PersistenceService.class).refreshAllNonUpdatingReferences(transLine); 261 insertTransactionLine(false, documentForm, transLine); 262 263 // clear the used newTargetLine 264 documentForm.setNewTargetTransactionLine(new EndowmentTargetTransactionLine()); 265 } 266 267 return mapping.findForward(KFSConstants.MAPPING_BASIC); 268 } 269 270 /** 271 * This action executes an insert of an EndowmentTargetTransactionLine into a document only after validating the Transaction 272 * line and checking any appropriate business rules. 273 * 274 * @param mapping 275 * @param form 276 * @param request 277 * @param response 278 * @return 279 * @throws Exception 280 */ 281 public ActionForward insertSourceTransactionLine(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { 282 EndowmentTransactionLinesDocumentFormBase documentForm = (EndowmentTransactionLinesDocumentFormBase) form; 283 EndowmentTransactionLinesDocument endowmentDocument = (EndowmentTransactionLinesDocument) documentForm.getDocument(); 284 285 EndowmentSourceTransactionLine transLine = (EndowmentSourceTransactionLine) documentForm.getNewSourceTransactionLine(); 286 287 boolean rulePassed = true; 288 289 // check any business rules 290 rulePassed &= SpringContext.getBean(KualiRuleService.class).applyRules(new AddTransactionLineEvent(NEW_SOURCE_TRAN_LINE_PROPERTY_NAME, endowmentDocument, transLine)); 291 292 if (rulePassed) { 293 // add accountingLine 294 // SpringContext.getBean(PersistenceService.class).refreshAllNonUpdatingReferences(transLine); 295 insertTransactionLine(true, documentForm, transLine); 296 297 // clear the used newTargetLine 298 documentForm.setNewSourceTransactionLine(new EndowmentSourceTransactionLine()); 299 } 300 301 return mapping.findForward(KFSConstants.MAPPING_BASIC); 302 } 303 304 /** 305 * Adds the given transactionLine to the appropriate form-related datastructures. 306 * 307 * @param isSource 308 * @param etlDocumentForm 309 * @param line 310 */ 311 protected void insertTransactionLine(boolean isSource, EndowmentTransactionLinesDocumentFormBase etlDocumentForm, EndowmentTransactionLine line) { 312 EndowmentTransactionLinesDocumentBase etlDoc = etlDocumentForm.getEndowmentTransactionLinesDocumentBase(); 313 314 if (isSource) { 315 // add it to the document 316 etlDoc.addSourceTransactionLine((EndowmentSourceTransactionLine) line); 317 } 318 else { 319 // add it to the document 320 etlDoc.addTargetTransactionLine((EndowmentTargetTransactionLine) line); 321 } 322 323 // Update the doc total 324 if (etlDoc instanceof AmountTotaling) 325 ((FinancialSystemDocumentHeader) etlDocumentForm.getDocument().getDocumentHeader()).setFinancialDocumentTotalAmount(((AmountTotaling) etlDoc).getTotalDollarAmount()); 326 } 327 328 /** 329 * This action deletes an EndowmentSourceTransactionLine from a document. 330 * 331 * @param mapping 332 * @param form 333 * @param request 334 * @param response 335 * @return 336 * @throws Exception 337 */ 338 public ActionForward deleteSourceTransactionLine(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { 339 EndowmentTransactionLinesDocumentFormBase etlForm = (EndowmentTransactionLinesDocumentFormBase) form; 340 EndowmentTransactionLinesDocument etlDoc = etlForm.getEndowmentTransactionLinesDocumentBase(); 341 342 int deleteIndex = getLineToDelete(request); 343 String errorPath = KFSConstants.DOCUMENT_PROPERTY_NAME + "." + EXISTING_SOURCE_TRAN_LINE_PROPERTY_NAME + "[" + deleteIndex + "]"; 344 boolean rulePassed = SpringContext.getBean(KualiRuleService.class).applyRules(new DeleteTransactionLineEvent(errorPath, etlDoc, etlDoc.getSourceTransactionLine(deleteIndex))); 345 346 // if the rule evaluation passed, let's delete it 347 if (rulePassed) { 348 deleteTransactionLine(true, etlForm, deleteIndex); 349 } 350 else { 351 String[] errorParams = new String[] { "source", Integer.toString(deleteIndex + 1) }; 352 GlobalVariables.getMessageMap().putError(errorPath, EndowKeyConstants.EndowmentTransactionDocumentConstants.ERROR_DELETING_TRANSACTION_LINE, errorParams); 353 } 354 355 return mapping.findForward(KFSConstants.MAPPING_BASIC); 356 } 357 358 /** 359 * This action deletes an EndowmentTargetTransactionLine from a document. 360 * 361 * @param mapping 362 * @param form 363 * @param request 364 * @param response 365 * @return 366 * @throws Exception 367 */ 368 public ActionForward deleteTargetTransactionLine(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { 369 EndowmentTransactionLinesDocumentFormBase etlForm = (EndowmentTransactionLinesDocumentFormBase) form; 370 EndowmentTransactionLinesDocument etlDoc = etlForm.getEndowmentTransactionLinesDocumentBase(); 371 372 int deleteIndex = getLineToDelete(request); 373 String errorPath = KFSConstants.DOCUMENT_PROPERTY_NAME + "." + EXISTING_TARGET_TRAN_LINE_PROPERTY_NAME + "[" + deleteIndex + "]"; 374 boolean rulePassed = SpringContext.getBean(KualiRuleService.class).applyRules(new DeleteTransactionLineEvent(errorPath, etlDoc, etlDoc.getTargetTransactionLine(deleteIndex))); 375 376 // if the rule evaluation passed, let's delete it 377 if (rulePassed) { 378 deleteTransactionLine(false, etlForm, deleteIndex); 379 } 380 else { 381 String[] errorParams = new String[] { "target", Integer.toString(deleteIndex + 1) }; 382 GlobalVariables.getMessageMap().putError(errorPath, EndowKeyConstants.EndowmentTransactionDocumentConstants.ERROR_DELETING_TRANSACTION_LINE, errorParams); 383 } 384 385 return mapping.findForward(KFSConstants.MAPPING_BASIC); 386 } 387 388 /** 389 * Deletes a Transaction Line. 390 * 391 * @param isSource 392 * @param etlDocumentForm 393 * @param index 394 */ 395 protected void deleteTransactionLine(boolean isSource, EndowmentTransactionLinesDocumentFormBase etlDocumentForm, int index) { 396 if (isSource) { 397 // remove from document 398 etlDocumentForm.getEndowmentTransactionLinesDocumentBase().getSourceTransactionLines().remove(index); 399 400 } 401 else { 402 // remove from document 403 etlDocumentForm.getEndowmentTransactionLinesDocumentBase().getTargetTransactionLines().remove(index); 404 } 405 // update the doc total 406 EndowmentTransactionLinesDocument tdoc = etlDocumentForm.getEndowmentTransactionLinesDocumentBase(); 407 if (tdoc instanceof AmountTotaling) { 408 ((FinancialSystemDocumentHeader) etlDocumentForm.getDocument().getDocumentHeader()).setFinancialDocumentTotalAmount(((AmountTotaling) tdoc).getTotalDollarAmount()); 409 } 410 } 411 412 413 /** 414 * @see org.kuali.rice.kns.web.struts.action.KualiDocumentActionBase#refresh(org.apache.struts.action.ActionMapping, 415 * org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) 416 */ 417 @Override 418 public ActionForward refresh(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { 419 super.refresh(mapping, form, request, response); 420 421 EndowmentTransactionLinesDocumentFormBase etlForm = (EndowmentTransactionLinesDocumentFormBase) form; 422 EndowmentTransactionLinesDocumentBase etlDoc = ((EndowmentTransactionLinesDocumentFormBase) form).getEndowmentTransactionLinesDocumentBase(); 423 424 // To Determine if the refresh is coming from Security lookup 425 if (request.getParameterMap().containsKey(SECURITY_SOURCE_REFRESH) || request.getParameterMap().containsKey(SECURITY_TARGET_REFRESH)) { 426 refreshSecurityDetails(mapping, form, request, response); 427 } 428 429 // To Determine if the refresh is coming from Registration lookup 430 if (request.getParameterMap().containsKey(REGISTRATION_SOURCE_REFRESH) || request.getParameterMap().containsKey(REGISTRATION_TARGET_REFRESH)) { 431 refreshRegistrationDetails(mapping, form, request, response); 432 } 433 434 // To determine if the refresh is coming from KEMID lookup 435 if (request.getParameterMap().containsKey("newSourceTransactionLine.kemid")) { 436 refreshKemid(etlForm, true); 437 } 438 if (request.getParameterMap().containsKey("newTargetTransactionLine.kemid")) { 439 refreshKemid(etlForm, false); 440 } 441 442 // To determine if the refresh is coming from Etran Code lookup 443 if (request.getParameterMap().containsKey("newSourceTransactionLine.etranCode")) { 444 refreshEtranCode(etlForm, true); 445 } 446 if (request.getParameterMap().containsKey("newTargetTransactionLine.etranCode")) { 447 refreshEtranCode(etlForm, false); 448 } 449 450 451 // balance inquiry anchor is set before doing a balance inquiry 452 if (etlForm.getBalanceInquiryReturnAnchor() != null) { 453 etlForm.setAnchor(etlForm.getBalanceInquiryReturnAnchor()); 454 etlForm.setBalanceInquiryReturnAnchor(null); 455 } 456 457 458 return mapping.findForward(KFSConstants.MAPPING_BASIC); 459 } 460 461 /** 462 * Retrieves and sets the reference kemid object on newSourceTransactionLine or newTargetTransactionLine based on the kemid 463 * looked up value. 464 * 465 * @param etlForm 466 * @param isSource 467 */ 468 private void refreshKemid(EndowmentTransactionLinesDocumentFormBase etlForm, boolean isSource) { 469 KEMID kemid = null; 470 471 if (isSource) { 472 kemid = SpringContext.getBean(KEMIDService.class).getByPrimaryKey(etlForm.getNewSourceTransactionLine().getKemid()); 473 etlForm.getNewSourceTransactionLine().setKemidObj(kemid); 474 } 475 else { 476 kemid = SpringContext.getBean(KEMIDService.class).getByPrimaryKey(etlForm.getNewTargetTransactionLine().getKemid()); 477 etlForm.getNewTargetTransactionLine().setKemidObj(kemid); 478 } 479 480 } 481 482 /** 483 * Retrieves and sets the reference endowment transaction code object on newSourceTransactionLine or newTargetTransactionLine 484 * based on the etranCode looked up value. 485 * 486 * @param etlForm 487 * @param isSource 488 */ 489 private void refreshEtranCode(EndowmentTransactionLinesDocumentFormBase etlForm, boolean isSource) { 490 EndowmentTransactionCode etranCode = null; 491 492 if (isSource) { 493 etranCode = SpringContext.getBean(EndowmentTransactionCodeService.class).getByPrimaryKey(etlForm.getNewSourceTransactionLine().getEtranCode()); 494 etlForm.getNewSourceTransactionLine().setEtranCodeObj(etranCode); 495 } 496 else { 497 etranCode = SpringContext.getBean(EndowmentTransactionCodeService.class).getByPrimaryKey(etlForm.getNewTargetTransactionLine().getEtranCode()); 498 etlForm.getNewTargetTransactionLine().setEtranCodeObj(etranCode); 499 } 500 501 } 502 503 /** 504 * Retrieves and sets the reference Security object on Source or Target transactionsecurity based on the looked up value. 505 * 506 * @param mapping 507 * @param form 508 * @param request 509 * @param response 510 * @return 511 * @throws Exception 512 */ 513 public ActionForward refreshSecurityDetails(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { 514 EndowmentSecurityDetailsDocumentBase endowmentSecurityDetailsDocumentBase = (EndowmentSecurityDetailsDocumentBase) ((EndowmentTransactionLinesDocumentFormBase) form).getDocument(); 515 516 Security security; 517 if (request.getParameterMap().containsKey(SECURITY_SOURCE_REFRESH)) 518 security = SpringContext.getBean(SecurityService.class).getByPrimaryKey(endowmentSecurityDetailsDocumentBase.getSourceTransactionSecurity().getSecurityID()); 519 else 520 security = SpringContext.getBean(SecurityService.class).getByPrimaryKey(endowmentSecurityDetailsDocumentBase.getTargetTransactionSecurity().getSecurityID()); 521 522 ClassCode classCode = SpringContext.getBean(ClassCodeService.class).getByPrimaryKey(security.getSecurityClassCode()); 523 security.setClassCode(classCode); 524 EndowmentTransactionCode endowmentTransactionCode = SpringContext.getBean(EndowmentTransactionCodeService.class).getByPrimaryKey(classCode.getSecurityEndowmentTransactionCode()); 525 classCode.setEndowmentTransactionCode(endowmentTransactionCode); 526 527 if (request.getParameterMap().containsKey(SECURITY_SOURCE_REFRESH)) 528 endowmentSecurityDetailsDocumentBase.getSourceTransactionSecurity().setSecurity(security); 529 else 530 endowmentSecurityDetailsDocumentBase.getTargetTransactionSecurity().setSecurity(security); 531 532 return null; 533 } 534 535 /** 536 * Retrieves and sets the reference RegistrationCode object on Source or Target transactionsecurity based on the looked up 537 * value. 538 * 539 * @param mapping 540 * @param form 541 * @param request 542 * @param response 543 * @return 544 * @throws Exception 545 */ 546 public ActionForward refreshRegistrationDetails(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { 547 EndowmentSecurityDetailsDocumentBase endowmentSecurityDetailsDocumentBase = (EndowmentSecurityDetailsDocumentBase) ((EndowmentTransactionLinesDocumentFormBase) form).getDocument(); 548 549 RegistrationCode registrationCode = null; 550 if (request.getParameterMap().containsKey(REGISTRATION_SOURCE_REFRESH)) 551 registrationCode = SpringContext.getBean(RegistrationCodeService.class).getByPrimaryKey(endowmentSecurityDetailsDocumentBase.getSourceTransactionSecurity().getRegistrationCode()); 552 else 553 registrationCode = SpringContext.getBean(RegistrationCodeService.class).getByPrimaryKey(endowmentSecurityDetailsDocumentBase.getTargetTransactionSecurity().getRegistrationCode()); 554 555 if (request.getParameterMap().containsKey(REGISTRATION_SOURCE_REFRESH)) 556 endowmentSecurityDetailsDocumentBase.getSourceTransactionSecurity().setRegistrationCodeObj(registrationCode); 557 else 558 endowmentSecurityDetailsDocumentBase.getTargetTransactionSecurity().setRegistrationCodeObj(registrationCode); 559 560 return null; 561 } 562 563 564 /** 565 * This method returns the balance inquiry for target transaction lines. 566 * 567 * @param mapping 568 * @param form 569 * @param request 570 * @param response 571 * @return 572 * @throws Exception 573 */ 574 public ActionForward performBalanceInquiryForTargetTransactionLine(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { 575 return performBalanceInquiry(false, mapping, form, request, response); 576 } 577 578 /** 579 * This method returns the balance inquiry for source transaction lines. 580 * 581 * @param mapping 582 * @param form 583 * @param request 584 * @param response 585 * @return 586 * @throws Exception 587 */ 588 public ActionForward performBalanceInquiryForSourceTransactionLine(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { 589 return performBalanceInquiry(true, mapping, form, request, response); 590 } 591 592 /** 593 * This method provides the KEMIDCurrentBalance as the default lookup object. If a different lookup is needed this method should 594 * be overriden. 595 * 596 * @param isSource 597 * @param mapping 598 * @param form 599 * @param request 600 * @param response 601 * @return 602 * @throws Exception 603 */ 604 public ActionForward performBalanceInquiry(boolean isSource, ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { 605 String boName = KEMIDCurrentBalance.class.getName(); 606 return performBalanceInquiry(isSource, boName, mapping, form, request, response); 607 } 608 609 /** 610 * This method is similar to org.kuali.kfs.sys.web.struts.KualiAccountingDocumentActionBase.performBalanceInquiry() 611 * 612 * @param isRevenue 613 * @param mapping 614 * @param form 615 * @param request 616 * @param response 617 * @return 618 * @throws Exception 619 */ 620 public ActionForward performBalanceInquiry(boolean isSource, String boName, ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { 621 final String docNumber; 622 623 // get the selected line, setup parms and redirect to balance inquiry 624 EndowmentTransactionLinesDocumentFormBase etlForm = (EndowmentTransactionLinesDocumentFormBase) form; 625 EndowmentTransactionLinesDocumentBase etlDoc = ((EndowmentTransactionLinesDocumentFormBase) form).getEndowmentTransactionLinesDocumentBase(); 626 627 628 // when we return from the lookup, our next request's method to call is going to be refresh 629 etlForm.registerEditableProperty(KNSConstants.DISPATCH_REQUEST_PARAMETER); 630 631 EndowmentTransactionLine etLine; 632 if (isSource) { 633 etLine = etlDoc.getSourceTransactionLines().get(this.getSelectedLine(request)); 634 } 635 else { 636 etLine = etlDoc.getTargetTransactionLines().get(this.getSelectedLine(request)); 637 } 638 639 // build out base path for return location, use config service 640 String basePath = SpringContext.getBean(KualiConfigurationService.class).getPropertyString(KFSConstants.APPLICATION_URL_KEY); 641 642 // this hack sets the return anchor we want to return too after the inquiry 643 // do this here so it gets into the session stored form version 644 // refresh checks for this after and resets the anchor 645 if (form instanceof KualiForm && StringUtils.isNotEmpty(((KualiForm) form).getAnchor())) { 646 etlForm.setBalanceInquiryReturnAnchor(((KualiForm) form).getAnchor()); 647 } 648 649 // build out the actual form key that will be used to retrieve the form on refresh 650 String callerDocFormKey = GlobalVariables.getUserSession().addObject(form); 651 652 // now add required parameters 653 Properties params = new Properties(); 654 params.put(KFSConstants.DISPATCH_REQUEST_PARAMETER, KFSConstants.SEARCH_METHOD); 655 params.put(KFSConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, boName); 656 params.put(KFSConstants.DOC_FORM_KEY, GlobalVariables.getUserSession().addObject(form)); 657 params.put(KFSConstants.HIDE_LOOKUP_RETURN_LINK, "true"); 658 params.put(KFSConstants.RETURN_LOCATION_PARAMETER, basePath + mapping.getPath() + ".do"); 659 660 if (StringUtils.isNotBlank(etLine.getKemid())) { 661 params.put(EndowPropertyConstants.KEMID, etLine.getKemid()); 662 } 663 664 String lookupUrl = UrlFactory.parameterizeUrl(KFSConstants.LOOKUP_ACTION, params); 665 666 this.setupDocumentExit(); 667 return new ActionForward(lookupUrl, true); 668 } 669 670 671 }