1 package org.kuali.ole.deliver.controller;
2
3 import org.apache.commons.lang.StringUtils;
4 import org.kuali.ole.OLEConstants;
5 import org.kuali.ole.deliver.bo.OLEFlaggedItems;
6 import org.kuali.ole.deliver.bo.OlePatronDocument;
7 import org.kuali.ole.deliver.bo.OlePatronNotes;
8 import org.kuali.ole.deliver.form.OLEPatronFlaggedItemHistoryForm;
9 import org.kuali.ole.deliver.service.OLEDeliverService;
10 import org.kuali.rice.krad.service.KRADServiceLocator;
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.io.IOException;
22 import java.util.ArrayList;
23 import java.util.HashMap;
24 import java.util.List;
25 import java.util.Map;
26
27
28
29
30
31
32
33
34 @Controller
35 @RequestMapping(value = "/olePatronFlaggedItemHistoryController")
36 public class OLEPatronFlaggedItemHistoryController extends UifControllerBase {
37
38 @Override
39 protected UifFormBase createInitialForm(HttpServletRequest request) {
40 return new OLEPatronFlaggedItemHistoryForm();
41 }
42
43
44 @Override
45 public ModelAndView start(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, HttpServletRequest request, HttpServletResponse response) {
46 super.start(form, result, request, response);
47 OLEPatronFlaggedItemHistoryForm olePatronFlaggedItemHistoryForm=(OLEPatronFlaggedItemHistoryForm)form;
48 if(StringUtils.isNotEmpty(request.getParameter("itemBarcode"))){
49 olePatronFlaggedItemHistoryForm.setItemBarcode(request.getParameter("itemBarcode"));
50 }
51 if (StringUtils.isNotEmpty((olePatronFlaggedItemHistoryForm.getItemBarcode()))) {
52 olePatronFlaggedItemHistoryForm.setItemsList(getItemFlaggedHistoryUsingBarcode(olePatronFlaggedItemHistoryForm.getItemBarcode()));
53 } else {
54 olePatronFlaggedItemHistoryForm.setItemsList(new ArrayList<OLEFlaggedItems>());
55 }
56 return getUIFModelAndView(olePatronFlaggedItemHistoryForm);
57 }
58
59 private List<OLEFlaggedItems> getItemFlaggedHistoryUsingBarcode(String itemBarcode){
60 List<OLEFlaggedItems> items=new ArrayList<OLEFlaggedItems>();
61 List<OlePatronNotes> olePatronNotes =(List<OlePatronNotes>)KRADServiceLocator.getBusinessObjectService().findAll(OlePatronNotes.class);
62 String checkInTextType1="Item: " + itemBarcode + " checked in";
63 String checkInTextType2="Item : "+itemBarcode+" checked in";
64 if (olePatronNotes != null) {
65 for (OlePatronNotes notes : olePatronNotes) {
66 if (notes.getPatronNoteText() != null && (notes.getPatronNoteText().toUpperCase().contains(checkInTextType1.toUpperCase()) ||notes.getPatronNoteText().toUpperCase().contains(checkInTextType2.toUpperCase()) )) {
67 OLEFlaggedItems oleFlaggedItems = new OLEFlaggedItems();
68 oleFlaggedItems.setPatronId(notes.getOlePatronId());
69 oleFlaggedItems.setPatronNote(notes.getPatronNoteText());
70 if(notes.getPatronNoteText().toUpperCase().contains(checkInTextType2.toUpperCase())){
71 oleFlaggedItems.setPatronFlagType(OLEConstants.FLAG_TYP_ITM_DAMAGED);
72 }
73 if(notes.getPatronNoteText().toUpperCase().contains(checkInTextType1.toUpperCase())){
74 oleFlaggedItems.setPatronFlagType(OLEConstants.FLAG_TYP_ITM_MISSING);
75 }
76 String name = "";
77 if (notes.getOlePatron() != null) {
78 oleFlaggedItems.setPatronBarcode(notes.getOlePatron().getBarcode());
79 }
80 if(notes.getOlePatronId()!=null){
81 Map<String, String> patronId = new HashMap<String, String>();
82 patronId.put(OLEConstants.OlePatron.PAY_BILL_PATRON_ID, notes.getOlePatronId());
83 OlePatronDocument document = (OlePatronDocument) KRADServiceLocator.getBusinessObjectService().findByPrimaryKey(OlePatronDocument.class, patronId);
84 if (document != null) {
85 document = OLEDeliverService.populatePatronName(document);
86 if (document.getFirstName() != null && !document.getFirstName().equalsIgnoreCase("")) {
87 name = name + document.getFirstName();
88 }
89 if (document.getLastName() != null && !document.getLastName().equalsIgnoreCase("")) {
90 name = name + " " + document.getLastName();
91 }
92 }
93 }
94 oleFlaggedItems.setPatronName(name);
95 items.add(oleFlaggedItems);
96 }
97 }
98 }
99 return items;
100 }
101
102 }