1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.kpme.core.web;
17
18 import java.util.Map;
19
20 import javax.servlet.http.HttpServletRequest;
21 import javax.servlet.http.HttpServletResponse;
22
23 import org.apache.log4j.Logger;
24 import org.apache.struts.action.ActionForm;
25 import org.apache.struts.action.ActionForward;
26 import org.apache.struts.action.ActionMapping;
27 import org.kuali.kpme.core.util.HrConstants;
28 import org.kuali.rice.core.api.util.RiceConstants;
29 import org.kuali.rice.core.api.util.RiceKeyConstants;
30 import org.kuali.rice.kns.inquiry.Inquirable;
31 import org.kuali.rice.kns.web.struts.action.KualiInquiryAction;
32 import org.kuali.rice.kns.web.struts.form.InquiryForm;
33 import org.kuali.rice.krad.bo.BusinessObject;
34 import org.kuali.rice.krad.util.GlobalVariables;
35 import org.kuali.rice.krad.util.KRADConstants;
36
37 public class KPMEInquiryAction extends KualiInquiryAction {
38
39 private static final Logger LOG = Logger.getLogger(KPMEInquiryAction.class);
40
41 protected BusinessObject retrieveBOUsingKeyMap(Map<String, String> keyMap, Inquirable kualiInquirable) {
42 BusinessObject bo = kualiInquirable.getBusinessObject(keyMap);
43 if (bo == null) {
44 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, RiceKeyConstants.ERROR_INQUIRY);
45 }
46 return bo;
47 }
48
49 @Override
50 public ActionForward continueWithInquiry(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
51 InquiryForm inquiryForm = (InquiryForm) form;
52
53 if (inquiryForm.getBusinessObjectClassName() == null) {
54 LOG.error("Business object name not given.");
55 throw new RuntimeException("Business object name not given.");
56 }
57 BusinessObject bo;
58 if(HrConstants.CLASS_INQUIRY_KEY_MAP.containsKey(inquiryForm.getBusinessObjectClassName())) {
59 Map<String, String> keyMap = inquiryForm.retrieveInquiryDecryptedPrimaryKeys();
60 for(String aKey : HrConstants.CLASS_INQUIRY_KEY_MAP.get(inquiryForm.getBusinessObjectClassName())) {
61 if(request.getParameter(aKey) != null) {
62 keyMap.put(aKey, request.getParameter(aKey).toString());
63 }
64 }
65 bo = retrieveBOUsingKeyMap(keyMap, inquiryForm.getInquirable());
66 } else {
67 bo = retrieveBOFromInquirable(inquiryForm);
68 }
69 checkBO(bo);
70
71 populateSections(mapping, request, inquiryForm, bo);
72
73 return mapping.findForward(RiceConstants.MAPPING_BASIC);
74 }
75
76 private void checkBO(BusinessObject bo) {
77 if (bo == null && GlobalVariables.getMessageMap().hasNoMessages()) {
78 throw new UnsupportedOperationException("The record you have inquired on does not exist.");
79 }
80 }
81
82 }