View Javadoc

1   /**
2    * Copyright 2004-2013 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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  }