1 package org.kuali.ole.deliver.controller;
2
3 import org.apache.commons.collections.CollectionUtils;
4 import org.apache.commons.lang3.StringUtils;
5 import org.kuali.ole.OLEConstants;
6 import org.kuali.ole.deliver.bo.OleDeliverRequestBo;
7 import org.kuali.ole.deliver.form.OLEItemRequestedRecordsForm;
8 import org.kuali.ole.deliver.service.OleDeliverRequestDocumentHelperServiceImpl;
9 import org.kuali.rice.krad.service.KRADServiceLocator;
10 import org.kuali.rice.krad.web.controller.UifControllerBase;
11 import org.kuali.rice.krad.web.form.UifFormBase;
12 import org.springframework.stereotype.Controller;
13 import org.springframework.validation.BindingResult;
14 import org.springframework.web.bind.annotation.ModelAttribute;
15 import org.springframework.web.bind.annotation.RequestMapping;
16 import org.springframework.web.servlet.ModelAndView;
17
18 import javax.servlet.http.HttpServletRequest;
19 import javax.servlet.http.HttpServletResponse;
20 import java.util.HashMap;
21 import java.util.List;
22 import java.util.Map;
23
24
25
26
27 @Controller
28 @RequestMapping(value = "/itemRequestedRecord")
29 public class OLEItemRequestedRecordsController extends UifControllerBase {
30
31 private OleDeliverRequestDocumentHelperServiceImpl oleDeliverRequestDocumentHelperService;
32
33 public OleDeliverRequestDocumentHelperServiceImpl getOleDeliverRequestDocumentHelperService() {
34 if (oleDeliverRequestDocumentHelperService == null) {
35 oleDeliverRequestDocumentHelperService = new OleDeliverRequestDocumentHelperServiceImpl();
36 }
37 return oleDeliverRequestDocumentHelperService;
38 }
39
40 @Override
41 protected UifFormBase createInitialForm(HttpServletRequest request) {
42 return new OLEItemRequestedRecordsForm();
43 }
44
45 @RequestMapping(params = "methodToCall=viewRequestedRecords")
46 public ModelAndView viewRequestedRecords(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
47 HttpServletRequest request, HttpServletResponse response) throws Exception {
48 OLEItemRequestedRecordsForm oleItemRequestedRecordsForm = (OLEItemRequestedRecordsForm) form;
49 String itemBarcode = request.getParameter(OLEConstants.OleDeliverRequest.ITEM_BARCODE);
50 if (StringUtils.isNotBlank(itemBarcode)) {
51 Map itemMap = new HashMap();
52 itemMap.put(OLEConstants.OleDeliverRequest.ITEM_ID, itemBarcode);
53 List<OleDeliverRequestBo> deliverRequestBos = (List<OleDeliverRequestBo>) KRADServiceLocator.getBusinessObjectService().findMatching(OleDeliverRequestBo.class, itemMap);
54 if (CollectionUtils.isNotEmpty(deliverRequestBos)) {
55 for (int i = 0; i < deliverRequestBos.size(); i++) {
56 getOleDeliverRequestDocumentHelperService().processItem(deliverRequestBos.get(i));
57 }
58 oleItemRequestedRecordsForm.setRequestBos(deliverRequestBos);
59 }
60 }
61 return getUIFModelAndView(oleItemRequestedRecordsForm, "OLEItemRequestedRecordPage");
62 }
63 }