View Javadoc
1   /*
2    * Copyright 2005-2007 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.module.purap.document.web.struts;
17  
18  import org.apache.struts.action.ActionForm;
19  import org.apache.struts.action.ActionForward;
20  import org.apache.struts.action.ActionMapping;
21  import org.kuali.ole.select.businessobject.OleRequestor;
22  import org.kuali.ole.select.document.service.OleRequestorService;
23  import org.kuali.ole.select.document.service.impl.OleRequestorServiceImpl;
24  import org.kuali.ole.select.document.web.struts.PersonRequestorLookUpForm;
25  import org.kuali.ole.sys.context.SpringContext;
26  import org.kuali.rice.core.api.util.RiceConstants;
27  import org.kuali.rice.core.api.util.RiceKeyConstants;
28  import org.kuali.rice.kns.util.KNSGlobalVariables;
29  import org.kuali.rice.kns.web.struts.action.KualiLookupAction;
30  import org.kuali.rice.kns.web.struts.form.KualiForm;
31  
32  import javax.servlet.http.HttpServletRequest;
33  import javax.servlet.http.HttpServletResponse;
34  
35  
36  /**
37   * This class handles Actions for lookup flow
38   */
39  
40  public class PersonRequestorLookUpAction extends KualiLookupAction {
41      private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(PersonRequestorLookUpAction.class);
42  
43      /**
44       * This method is take care of creating a New Requestor
45       *
46       * @param mapping
47       * @param form
48       * @param request
49       * @param response
50       * @return
51       * @throws Exception
52       */
53      public ActionForward createNew(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
54  
55          LOG.debug("PersonRequestorLookUpAction : createNew() method -- Starts");
56          PersonRequestorLookUpForm personRequestorLookUpForm = (PersonRequestorLookUpForm) form;
57  
58          String firstName = personRequestorLookUpForm.getFirstName();
59          String lastName = personRequestorLookUpForm.getLastName();
60  
61          if (firstName != null && lastName != null) {
62              OleRequestor oleRequestor = new OleRequestor();
63              oleRequestor.setRequestorFirstName(firstName);
64              oleRequestor.setRequestorLastName(lastName);
65              oleRequestor.setRequestorEmail(personRequestorLookUpForm.getEmail());
66              oleRequestor.setRequestorPhoneNumber(personRequestorLookUpForm.getPhoneNumber());
67              oleRequestor.setRequestorTypeId(personRequestorLookUpForm.getRequestorTypeId());
68              oleRequestor.setRefKrimId(personRequestorLookUpForm.getRefKrimId());
69  
70              OleRequestorService oleRequestorService = SpringContext.getBean(OleRequestorServiceImpl.class);
71              oleRequestorService.saveRequestor(oleRequestor);
72              KNSGlobalVariables.getMessageList().add(RiceKeyConstants.MESSAGE_ROUTE_SUCCESSFUL);
73          } else {
74              if (firstName == null) {
75                  KNSGlobalVariables.getMessageList().add(RiceKeyConstants.ERROR_CUSTOM, "First Name Field is a requried field");
76              }
77              if (lastName == null) {
78                  KNSGlobalVariables.getMessageList().add(RiceKeyConstants.ERROR_CUSTOM, "Last Name Field is a requried field");
79              }
80  
81          }
82          LOG.debug("PersonRequestorLookUpAction : createNew() method -- End");
83          ((KualiForm) form).setMethodToCall("search");
84          super.search(mapping, form, request, response);
85          return mapping.findForward(RiceConstants.MAPPING_BASIC);
86      }
87  
88  
89  }