View Javadoc

1   package org.kuali.ole.deliver.request.controller;
2   
3   import org.apache.log4j.Logger;
4   
5   import org.kuali.ole.OLEConstants;
6   import org.kuali.ole.deliver.request.bo.OleDeliverRequestBo;
7   import org.kuali.ole.deliver.request.form.OleDeliverRequestReOrderForm;
8   import org.kuali.ole.deliver.request.service.OleDeliverRequestDocumentHelperServiceImpl;
9   import org.kuali.rice.krad.service.KRADServiceLocator;
10  import org.kuali.rice.krad.util.GlobalVariables;
11  import org.kuali.rice.krad.web.controller.UifControllerBase;
12  import org.kuali.rice.krad.web.form.UifFormBase;
13  import org.springframework.stereotype.Controller;
14  import org.springframework.validation.BindingResult;
15  import org.springframework.web.bind.annotation.ModelAttribute;
16  import org.springframework.web.bind.annotation.RequestMapping;
17  import org.springframework.web.servlet.ModelAndView;
18  
19  import javax.servlet.http.HttpServletRequest;
20  import javax.servlet.http.HttpServletResponse;
21  import java.util.HashMap;
22  import java.util.List;
23  import java.util.Map;
24  
25  /**
26   * Created with IntelliJ IDEA.
27   * User: ?
28   * Date: 10/15/12
29   * Time: 10:31 AM
30   * To change this template use File | Settings | File Templates.
31   */
32  @Controller
33  @RequestMapping(value = "/deliverRequestController")
34  public class OleDeliverRequestReOrderController extends UifControllerBase {
35      OleDeliverRequestDocumentHelperServiceImpl oleDeliverRequestDocumentHelperService =  new OleDeliverRequestDocumentHelperServiceImpl();
36  
37      private static final Logger LOG = Logger.getLogger(OleDeliverRequestReOrderController.class);
38  
39      /**
40       *  This method creates new OleDeliverRequestReOrderForm form
41       * @param request
42       * @return  OleDeliverRequestReOrderForm
43       */
44      @Override
45      protected OleDeliverRequestReOrderForm createInitialForm(HttpServletRequest request) {
46          return new OleDeliverRequestReOrderForm();
47      }
48  
49      @Override
50      @RequestMapping(params = "methodToCall=start")
51      public ModelAndView start(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
52                                HttpServletRequest request, HttpServletResponse response) {
53          LOG.info("Inside start method");
54          OleDeliverRequestReOrderForm oleDeliverRequestForm = (OleDeliverRequestReOrderForm) form;
55          return super.start(oleDeliverRequestForm, result, request, response);
56      }
57  
58  
59      @RequestMapping(params = "methodToCall=search")
60      public ModelAndView search(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
61                                 HttpServletRequest request, HttpServletResponse response) {
62          LOG.info("Inside search method");
63          OleDeliverRequestReOrderForm oleDeliverRequestForm = (OleDeliverRequestReOrderForm) form;
64  
65          String itemId = oleDeliverRequestForm.getItemId();
66  
67          Map<String,String> itemMap = new HashMap<String,String>();
68          itemMap.put(OLEConstants.OleDeliverRequest.ITEM_ID,itemId);
69          List<OleDeliverRequestBo> itemList =(List<OleDeliverRequestBo>) KRADServiceLocator.getBusinessObjectService().findMatchingOrderBy(OleDeliverRequestBo.class,itemMap,OLEConstants.OleDeliverRequest.QUEUE_POSITION,true);
70       if(itemList.size()>0){
71          for(int i=0;i<itemList.size();i++){
72               itemList.get(i).setOleItemSearch(oleDeliverRequestDocumentHelperService.getItemDetails(itemList.get(i).getItemId()));
73          }
74       }
75          if(itemList.size()==0){
76              oleDeliverRequestForm.setMessage(OLEConstants.OleDeliverRequest.NO_PENDING_REQUEST);
77          }
78          oleDeliverRequestForm.setDeliverRequestBos(itemList);
79          return getUIFModelAndView(oleDeliverRequestForm, "DeliverRequestSearchPage");
80      }
81  
82      @RequestMapping(params = "methodToCall=reOrder")
83      public ModelAndView reOrder(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
84                                  HttpServletRequest request, HttpServletResponse response) {
85          LOG.info("Inside reOrder method");
86          OleDeliverRequestReOrderForm oleDeliverRequestForm = (OleDeliverRequestReOrderForm) form;
87          List<OleDeliverRequestBo> itemList =(List<OleDeliverRequestBo>) oleDeliverRequestForm.getDeliverRequestBos();
88  
89          OleDeliverRequestDocumentHelperServiceImpl service = new OleDeliverRequestDocumentHelperServiceImpl();
90           if(itemList.size()>0){
91          String message = service.validateQueuePosition(itemList);
92          if(!message.equals(OLEConstants.OleDeliverRequest.REORDER_SUCCESS)){
93              oleDeliverRequestForm.setMessage(message);
94          }
95          else {
96              KRADServiceLocator.getBusinessObjectService().save(itemList);
97              oleDeliverRequestForm.setDeliverRequestBos(null);
98              oleDeliverRequestForm.setMessage(message);
99          }
100          }
101         return getUIFModelAndView(oleDeliverRequestForm, "DeliverRequestSearchPage");
102     }
103 
104     @RequestMapping(params = "methodToCall=refresh")
105     public ModelAndView refresh(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
106                                 HttpServletRequest request, HttpServletResponse response) throws Exception {
107         OleDeliverRequestReOrderForm oleDeliverRequestForm = (OleDeliverRequestReOrderForm) form;
108         ((OleDeliverRequestReOrderForm) form).setMessage(null);
109         super.refresh(form,result,request,response);
110         return search(form,result,request,response);
111     }
112 
113 }