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 javax.servlet.http.HttpServletRequest;
019 import javax.servlet.http.HttpServletResponse;
020
021 import org.apache.struts.action.ActionForm;
022 import org.apache.struts.action.ActionForward;
023 import org.apache.struts.action.ActionMapping;
024 import org.kuali.kfs.module.endow.businessobject.ClassCode;
025 import org.kuali.kfs.module.endow.businessobject.EndowmentTransactionCode;
026 import org.kuali.kfs.module.endow.businessobject.Security;
027 import org.kuali.kfs.module.endow.businessobject.SecurityValuationMethod;
028 import org.kuali.kfs.module.endow.document.EndowmentSecurityDetailsDocumentBase;
029 import org.kuali.kfs.module.endow.document.EndowmentTransactionLinesDocumentBase;
030 import org.kuali.kfs.module.endow.document.HoldingHistoryValueAdjustmentDocument;
031 import org.kuali.kfs.module.endow.document.service.ClassCodeService;
032 import org.kuali.kfs.module.endow.document.service.EndowmentTransactionCodeService;
033 import org.kuali.kfs.module.endow.document.service.SecurityService;
034 import org.kuali.kfs.module.endow.document.service.SecurityValuationMethodService;
035 import org.kuali.kfs.sys.KFSConstants;
036 import org.kuali.kfs.sys.context.SpringContext;
037 import org.kuali.kfs.sys.document.web.struts.FinancialSystemTransactionalDocumentActionBase;
038 import org.kuali.kfs.module.endow.document.HoldingHistoryValueAdjustmentDocument;
039
040 public class HoldingHistoryValueAdjustmentDocumentAction extends FinancialSystemTransactionalDocumentActionBase {
041
042 /**
043 * @see org.kuali.rice.kns.web.struts.action.KualiDocumentActionBase#refresh(org.apache.struts.action.ActionMapping,
044 * org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
045 */
046 @Override
047 public ActionForward refresh(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
048 super.refresh(mapping, form, request, response);
049
050 // To Determine if the refresh is coming from Security lookup
051 refreshSecurityDetails(mapping, form, request, response);
052
053 return mapping.findForward(KFSConstants.MAPPING_BASIC);
054 }
055
056 /**
057 * Retrieves and sets the reference Security object on Source or Target transactionsecurity based on the looked up value.
058 *
059 * @param mapping
060 * @param form
061 * @param request
062 * @param response
063 * @return
064 * @throws Exception
065 */
066 public ActionForward refreshSecurityDetails(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
067 HoldingHistoryValueAdjustmentDocumentForm ehvaForm = (HoldingHistoryValueAdjustmentDocumentForm) form;
068
069 HoldingHistoryValueAdjustmentDocument ehvaDocument = (HoldingHistoryValueAdjustmentDocument) ehvaForm.getDocument();
070 Security security = SpringContext.getBean(SecurityService.class).getByPrimaryKey(ehvaDocument.getSecurityId());
071
072 ClassCode classCode = SpringContext.getBean(ClassCodeService.class).getByPrimaryKey(security.getSecurityClassCode());
073 security.setClassCode(classCode);
074
075 SecurityValuationMethod securityValuation = SpringContext.getBean(SecurityValuationMethodService.class).getByPrimaryKey(classCode.getValuationMethod());
076 classCode.setSecurityValuationMethod(securityValuation);
077 ehvaDocument.setSecurity(security);
078
079 return null;
080 }
081
082 }