1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kns.web.spring.controller; |
17 | |
|
18 | |
import javax.servlet.http.HttpServletRequest; |
19 | |
import javax.servlet.http.HttpServletResponse; |
20 | |
|
21 | |
import org.kuali.rice.core.util.RiceKeyConstants; |
22 | |
import org.kuali.rice.kns.inquiry.Inquirable; |
23 | |
import org.kuali.rice.kns.util.GlobalVariables; |
24 | |
import org.kuali.rice.kns.util.KNSConstants; |
25 | |
import org.kuali.rice.kns.web.spring.form.InquiryForm; |
26 | |
import org.springframework.stereotype.Controller; |
27 | |
import org.springframework.validation.BindingResult; |
28 | |
import org.springframework.web.bind.annotation.ModelAttribute; |
29 | |
import org.springframework.web.bind.annotation.RequestMapping; |
30 | |
import org.springframework.web.servlet.ModelAndView; |
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | 0 | @Controller |
38 | |
@RequestMapping(value = "/inquiry") |
39 | 0 | public class InquiryController extends UifControllerBase { |
40 | 0 | private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(InquiryController.class); |
41 | |
|
42 | |
@Override |
43 | |
protected InquiryForm createInitialForm(HttpServletRequest request) { |
44 | 0 | return new InquiryForm(); |
45 | |
} |
46 | |
|
47 | |
@RequestMapping(params = "methodToCall=start") |
48 | |
public ModelAndView start(@ModelAttribute("KualiForm") InquiryForm inquiryForm, BindingResult result, |
49 | |
HttpServletRequest request, HttpServletResponse response) { |
50 | 0 | return continueWithInquiry(inquiryForm, result, request, response); |
51 | |
} |
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
@RequestMapping(params = "methodToCall=continueWithInquiry") |
58 | |
public ModelAndView continueWithInquiry(@ModelAttribute("KualiForm") InquiryForm inquiryForm, BindingResult result, |
59 | |
HttpServletRequest request, HttpServletResponse response) { |
60 | |
|
61 | 0 | Object bo = retrieveBOFromInquirable(inquiryForm); |
62 | 0 | checkBO(bo); |
63 | |
|
64 | 0 | inquiryForm.setBo(bo); |
65 | |
|
66 | 0 | return getUIFModelAndView(inquiryForm); |
67 | |
} |
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
|
77 | |
private void checkBO(Object bo) { |
78 | 0 | if (bo == null && GlobalVariables.getMessageMap().hasNoMessages()) { |
79 | 0 | throw new UnsupportedOperationException("The record you have inquired on does not exist."); |
80 | |
} |
81 | 0 | } |
82 | |
|
83 | |
protected Object retrieveBOFromInquirable(InquiryForm inquiryForm) { |
84 | 0 | Inquirable kualiInquirable = inquiryForm.getInquirable(); |
85 | |
|
86 | |
|
87 | 0 | Object inquiryObject = kualiInquirable.getDataObject(inquiryForm.retrieveInquiryDecryptedPrimaryKeys()); |
88 | 0 | if (inquiryObject == null) { |
89 | 0 | LOG.error("No records found in inquiry action."); |
90 | 0 | GlobalVariables.getMessageMap().putError(KNSConstants.GLOBAL_ERRORS, RiceKeyConstants.ERROR_INQUIRY); |
91 | |
} |
92 | |
|
93 | 0 | return inquiryObject; |
94 | |
} |
95 | |
|
96 | |
} |