001 /** 002 * Copyright 2004-2013 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 package org.kuali.rice.kns.web.struts.action; 017 018 import java.util.Map; 019 020 import javax.servlet.http.HttpServletRequest; 021 import javax.servlet.http.HttpServletResponse; 022 023 import org.apache.log4j.Logger; 024 import org.apache.struts.action.ActionForm; 025 import org.apache.struts.action.ActionForward; 026 import org.apache.struts.action.ActionMapping; 027 import org.kuali.hr.time.util.TkConstants; 028 import org.kuali.rice.core.api.util.RiceConstants; 029 import org.kuali.rice.core.api.util.RiceKeyConstants; 030 import org.kuali.rice.kns.inquiry.Inquirable; 031 import org.kuali.rice.kns.web.struts.form.InquiryForm; 032 import org.kuali.rice.krad.bo.BusinessObject; 033 import org.kuali.rice.krad.util.GlobalVariables; 034 import org.kuali.rice.krad.util.KRADConstants; 035 036 public class TkInquiryAction extends KualiInquiryAction { 037 038 private static final Logger LOG = Logger.getLogger(TkInquiryAction.class); 039 040 protected BusinessObject retrieveBOUsingKeyMap(Map<String, String> keyMap, Inquirable kualiInquirable) { 041 BusinessObject bo = kualiInquirable.getBusinessObject(keyMap); 042 if (bo == null) { 043 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, RiceKeyConstants.ERROR_INQUIRY); 044 } 045 return bo; 046 } 047 048 @Override 049 public ActionForward continueWithInquiry(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { 050 InquiryForm inquiryForm = (InquiryForm) form; 051 052 if (inquiryForm.getBusinessObjectClassName() == null) { 053 LOG.error("Business object name not given."); 054 throw new RuntimeException("Business object name not given."); 055 } 056 BusinessObject bo; 057 if(TkConstants.CLASS_INQUIRY_KEY_MAP.containsKey(inquiryForm.getBusinessObjectClassName())) { 058 Map<String, String> keyMap = inquiryForm.retrieveInquiryDecryptedPrimaryKeys(); 059 for(String aKey : TkConstants.CLASS_INQUIRY_KEY_MAP.get(inquiryForm.getBusinessObjectClassName())) { 060 if(request.getParameter(aKey) != null) { 061 keyMap.put(aKey, request.getParameter(aKey).toString()); 062 } 063 } 064 bo = retrieveBOUsingKeyMap(keyMap, inquiryForm.getInquirable()); 065 } else { 066 bo = retrieveBOFromInquirable(inquiryForm); 067 } 068 checkBO(bo); 069 070 populateSections(mapping, request, inquiryForm, bo); 071 072 return mapping.findForward(RiceConstants.MAPPING_BASIC); 073 } 074 075 private void checkBO(BusinessObject bo) { 076 if (bo == null && GlobalVariables.getMessageMap().hasNoMessages()) { 077 throw new UnsupportedOperationException("The record you have inquired on does not exist."); 078 } 079 } 080 081 }