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 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.fp.businessobject.InternalBillingItem; 025 import org.kuali.kfs.sys.KFSConstants; 026 import org.kuali.kfs.sys.KFSPropertyConstants; 027 import org.kuali.kfs.sys.context.SpringContext; 028 import org.kuali.kfs.sys.web.struts.KualiAccountingDocumentActionBase; 029 import org.kuali.rice.kns.service.DictionaryValidationService; 030 031 /** 032 * This class handles Actions for InternalBilling. 033 */ 034 public class InternalBillingAction extends KualiAccountingDocumentActionBase { 035 036 /** 037 * Adds a new InternalBillingItem from the Form to the Document if valid. This method is called reflectively from KualiAction. 038 * 039 * @param mapping 040 * @param form 041 * @param request 042 * @param response 043 * @return ActionForward 044 * @throws Exception 045 */ 046 public ActionForward insertItem(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { 047 InternalBillingForm internalBillingForm = (InternalBillingForm) form; 048 if (validateNewItem(internalBillingForm)) { 049 internalBillingForm.getInternalBillingDocument().addItem(internalBillingForm.getNewItem()); 050 internalBillingForm.setNewItem(new InternalBillingItem()); 051 } 052 return mapping.findForward(KFSConstants.MAPPING_BASIC); 053 } 054 055 /** 056 * Validates the new InternalBillingItem on the Form, adding a global error if invalid. 057 * 058 * @param internalBillingForm 059 * @return whether the new item is valid 060 */ 061 protected static boolean validateNewItem(InternalBillingForm internalBillingForm) { 062 return SpringContext.getBean(DictionaryValidationService.class).isBusinessObjectValid(internalBillingForm.getNewItem(), KFSPropertyConstants.NEW_ITEM); 063 } 064 065 /** 066 * Deletes an InternalBillingItem from the Document. This method is called reflectively from KualiAction. 067 * 068 * @param mapping 069 * @param form 070 * @param request 071 * @param response 072 * @return ActionForward 073 * @throws Exception 074 */ 075 public ActionForward deleteItem(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { 076 InternalBillingForm internalBillingForm = (InternalBillingForm) form; 077 internalBillingForm.getInternalBillingDocument().getItems().remove(getLineToDelete(request)); 078 return mapping.findForward(KFSConstants.MAPPING_BASIC); 079 } 080 }