View Javadoc

1   /**
2    * Copyright 2005-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.rice.coreservice.web.component;
17  
18  import org.kuali.rice.coreservice.impl.component.ComponentBo;
19  import org.kuali.rice.coreservice.impl.component.DerivedComponentBo;
20  import org.kuali.rice.kns.inquiry.KualiInquirableImpl;
21  import org.kuali.rice.krad.bo.BusinessObject;
22  import org.kuali.rice.krad.service.KRADServiceLocator;
23  
24  import java.util.HashMap;
25  import java.util.Map;
26  
27  /**
28   * Since ParameterDetailType can be either DataDictionary or DB based, we need a custom {@link org.kuali.rice.krad.inquiry.Inquirable} to
29   * check both.
30   * 
31   * @author Kuali Rice Team (rice.collab@kuali.org)
32   *
33   */
34  public class ComponentInquirableImpl extends KualiInquirableImpl {
35  
36  	private static final String COMPONENT_CODE = "code";
37  	private static final String NAMESPACE_CODE = "namespaceCode";
38  	
39  	@Override
40  	public Object retrieveDataObject(Map fieldValues){
41  		BusinessObject result = (BusinessObject)super.retrieveDataObject(fieldValues);
42  		if (result == null) {
43              result = loadDerivedComponent(fieldValues);
44          }
45  		return result; 
46      }
47  	
48  	@Override
49  	public BusinessObject getBusinessObject(Map fieldValues) {
50  		BusinessObject result = super.getBusinessObject(fieldValues);
51  		if (result == null) {
52  			result = loadDerivedComponent(fieldValues);
53  		}
54  		return result; 
55  	}
56  
57      protected ComponentBo loadDerivedComponent(Map fieldValues) {
58          String componentCode = (String)fieldValues.get(COMPONENT_CODE);
59  	    String namespaceCode = (String)fieldValues.get(NAMESPACE_CODE);
60          if (componentCode == null) {
61              throw new RuntimeException(COMPONENT_CODE + " is a required key for this inquiry");
62          }
63  	    if (namespaceCode == null) {
64              throw new RuntimeException(NAMESPACE_CODE + " is a required key for this inquiry");
65          }
66          Map<String, Object> primaryKeys = new HashMap<String, Object>();
67          primaryKeys.put(COMPONENT_CODE, componentCode);
68          primaryKeys.put(NAMESPACE_CODE, namespaceCode);
69  
70          DerivedComponentBo derivedComponentBo = KRADServiceLocator.getBusinessObjectService().findByPrimaryKey(
71                  DerivedComponentBo.class, primaryKeys);
72          if (derivedComponentBo != null) {
73              return DerivedComponentBo.toComponentBo(derivedComponentBo);
74          }
75          return null;
76      }
77  	
78  }