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