View Javadoc
1   /*
2    * Copyright 2005 The Kuali Foundation
3    * 
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    * http://www.opensource.org/licenses/ecl2.php
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.ole.fp.document.web.struts;
17  
18  import javax.servlet.http.HttpServletRequest;
19  import javax.servlet.http.HttpServletResponse;
20  
21  import org.apache.struts.action.ActionForm;
22  import org.apache.struts.action.ActionForward;
23  import org.apache.struts.action.ActionMapping;
24  import org.kuali.ole.fp.businessobject.InternalBillingItem;
25  import org.kuali.ole.sys.OLEConstants;
26  import org.kuali.ole.sys.OLEPropertyConstants;
27  import org.kuali.ole.sys.context.SpringContext;
28  import org.kuali.rice.kns.service.DictionaryValidationService;
29  
30  /**
31   * This class handles Actions for InternalBilling.
32   */
33  public class InternalBillingAction extends CapitalAccountingLinesActionBase {
34  
35      /**
36       * Adds a new InternalBillingItem from the Form to the Document if valid. This method is called reflectively from KualiAction.
37       * 
38       * @param mapping
39       * @param form
40       * @param request
41       * @param response
42       * @return ActionForward
43       * @throws Exception
44       */
45      public ActionForward insertItem(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
46          InternalBillingForm internalBillingForm = (InternalBillingForm) form;
47          if (validateNewItem(internalBillingForm)) {
48              internalBillingForm.getInternalBillingDocument().addItem(internalBillingForm.getNewItem());
49              internalBillingForm.setNewItem(new InternalBillingItem());
50          }
51          return mapping.findForward(OLEConstants.MAPPING_BASIC);
52      }
53  
54      /**
55       * Validates the new InternalBillingItem on the Form, adding a global error if invalid.
56       * 
57       * @param internalBillingForm
58       * @return whether the new item is valid
59       */
60      protected static boolean validateNewItem(InternalBillingForm internalBillingForm) {
61          return SpringContext.getBean(DictionaryValidationService.class).isBusinessObjectValid(internalBillingForm.getNewItem(), OLEPropertyConstants.NEW_ITEM);
62      }
63  
64      /**
65       * Deletes an InternalBillingItem from the Document. This method is called reflectively from KualiAction.
66       * 
67       * @param mapping
68       * @param form
69       * @param request
70       * @param response
71       * @return ActionForward
72       * @throws Exception
73       */
74      public ActionForward deleteItem(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
75          InternalBillingForm internalBillingForm = (InternalBillingForm) form;
76          internalBillingForm.getInternalBillingDocument().getItems().remove(getLineToDelete(request));
77          return mapping.findForward(OLEConstants.MAPPING_BASIC);
78      }
79  }