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