View Javadoc
1   package org.kuali.ole.deliver.controller;
2   
3   import org.apache.log4j.Logger;
4   import org.kuali.ole.OLEConstants;
5   import org.kuali.ole.deliver.bo.OlePatronDocument;
6   import org.kuali.ole.deliver.bo.OleTemporaryCirculationHistory;
7   import org.kuali.ole.deliver.form.OleTemporaryCirculationRecordsForm;
8   import org.kuali.ole.deliver.processor.LoanProcessor;
9   import org.kuali.rice.kim.impl.identity.entity.EntityBo;
10  import org.kuali.rice.kim.impl.identity.name.EntityNameBo;
11  import org.kuali.rice.krad.service.KRADServiceLocator;
12  import org.kuali.rice.krad.util.GlobalVariables;
13  import org.kuali.rice.krad.util.KRADConstants;
14  import org.kuali.rice.krad.web.controller.UifControllerBase;
15  import org.kuali.rice.krad.web.form.UifFormBase;
16  import org.springframework.stereotype.Controller;
17  import org.springframework.validation.BindingResult;
18  import org.springframework.web.bind.annotation.ModelAttribute;
19  import org.springframework.web.bind.annotation.RequestMapping;
20  import org.springframework.web.servlet.ModelAndView;
21  
22  import javax.servlet.http.HttpServletRequest;
23  import javax.servlet.http.HttpServletResponse;
24  import java.util.HashMap;
25  import java.util.List;
26  import java.util.Map;
27  
28  /**
29   * .OlePatronMaintenanceDocumentController invokes Transaction document Controller and returns instance of Transaction document service.
30   */
31  @Controller
32  @RequestMapping(value = "/temporaryCirculationRecord")
33  public class OleTemporaryCirculationRecordsController extends UifControllerBase {
34  
35      /**
36       * @see org.kuali.rice.krad.web.controller.UifControllerBase#createInitialForm(javax.servlet.http.HttpServletRequest)
37       */
38      private static final Logger LOG = Logger.getLogger(OleTemporaryCirculationRecordsController.class);
39  
40      @Override
41      protected OleTemporaryCirculationRecordsForm createInitialForm(HttpServletRequest request) {
42          return new OleTemporaryCirculationRecordsForm();
43      }
44  
45      /**
46       * This method takes the initial request when click on temporaryCirculationRecord Screen.
47       *
48       * @param form
49       * @param result
50       * @param request
51       * @param response
52       * @return ModelAndView
53       */
54      @Override
55      @RequestMapping(params = "methodToCall=start")
56      public ModelAndView start(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
57                                HttpServletRequest request, HttpServletResponse response) {
58          LOG.debug("Start -- Start Method of OleTemporaryCirculationRecordsForm");
59          OleTemporaryCirculationRecordsForm oleTemporaryCirculationRecordsForm = (OleTemporaryCirculationRecordsForm) form;
60          return super.start(oleTemporaryCirculationRecordsForm, result, request, response);
61      }
62  
63      /**
64       * This method persist to viewing all the temporary circulation history records.
65       *
66       * @param form
67       * @param result
68       * @param request
69       * @param response
70       * @return ModelAndView
71       * @throws Exception
72       */
73      @RequestMapping(params = "methodToCall=viewTempCircRecords")
74      public ModelAndView viewTempCircRecords(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
75                                              HttpServletRequest request, HttpServletResponse response) throws Exception {
76  
77          OleTemporaryCirculationRecordsForm oleTemporaryCirculationRecordsForm = (OleTemporaryCirculationRecordsForm) form;
78          String patronId = request.getParameter("patronId");
79          Map patron = new HashMap();
80          patron.put(OLEConstants.OlePatron.PATRON_ID, patronId);
81          OlePatronDocument olePatronDocument = KRADServiceLocator.getBusinessObjectService().findByPrimaryKey(OlePatronDocument.class, patron);
82          if (olePatronDocument != null) {
83              EntityBo entity = olePatronDocument.getEntity();
84              EntityNameBo entityName = entity.getNames().get(0);
85              String firstName = entityName.getFirstName();
86              String lastName = entityName.getLastName();
87              String name = firstName + " " + lastName;
88              oleTemporaryCirculationRecordsForm.setPatronName(name);
89              oleTemporaryCirculationRecordsForm.setOlePatronDocument(olePatronDocument);
90              LoanProcessor loanProcessor = new LoanProcessor();
91              try {
92                  olePatronDocument.setOleTemporaryCirculationHistoryRecords(loanProcessor.getPatronTemporaryCirculationHistoryRecords(olePatronDocument.getOlePatronId()));
93              } catch (Exception e) {
94                  LOG.error("Exception while setting temporary circulation history records", e);
95              }
96              List<OleTemporaryCirculationHistory> oleTemporaryCirculationHistoryRecords = olePatronDocument.getOleTemporaryCirculationHistoryRecords();
97              oleTemporaryCirculationRecordsForm.setOleTemporaryCirculationHistoryRecords(oleTemporaryCirculationHistoryRecords);
98          } else {
99              GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.OlePatron.ERROR_PATRON_NOT_FOUND);
100         }
101         return getUIFModelAndView(oleTemporaryCirculationRecordsForm, "OleTemporaryCirculationHistoryRecordPage");
102     }
103 }