Coverage Report - org.kuali.rice.core.web.component.ComponentInquirableImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
ComponentInquirableImpl
0%
0/22
0%
0/10
3.667
 
 1  
 /**
 2  
  * Copyright 2005-2011 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.core.web.component;
 17  
 
 18  
 import org.kuali.rice.core.impl.component.ComponentBo;
 19  
 import org.kuali.rice.core.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  0
 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  0
                 BusinessObject result = (BusinessObject)super.retrieveDataObject(fieldValues);
 42  0
                 if (result == null) {
 43  0
             result = loadDerivedComponent(fieldValues);
 44  
         }
 45  0
                 return result; 
 46  
     }
 47  
         
 48  
         @Override
 49  
         public BusinessObject getBusinessObject(Map fieldValues) {
 50  0
                 BusinessObject result = super.getBusinessObject(fieldValues);
 51  0
                 if (result == null) {
 52  0
                         result = loadDerivedComponent(fieldValues);
 53  
                 }
 54  0
                 return result; 
 55  
         }
 56  
 
 57  
     protected ComponentBo loadDerivedComponent(Map fieldValues) {
 58  0
         String componentCode = (String)fieldValues.get(COMPONENT_CODE);
 59  0
             String namespaceCode = (String)fieldValues.get(NAMESPACE_CODE);
 60  0
         if (componentCode == null) {
 61  0
             throw new RuntimeException(COMPONENT_CODE + " is a required key for this inquiry");
 62  
         }
 63  0
             if (namespaceCode == null) {
 64  0
             throw new RuntimeException(NAMESPACE_CODE + " is a required key for this inquiry");
 65  
         }
 66  0
         Map<String, Object> primaryKeys = new HashMap<String, Object>();
 67  0
         primaryKeys.put(COMPONENT_CODE, componentCode);
 68  0
         primaryKeys.put(NAMESPACE_CODE, namespaceCode);
 69  
 
 70  0
         DerivedComponentBo derivedComponentBo = KRADServiceLocator.getBusinessObjectService().findByPrimaryKey(
 71  
                 DerivedComponentBo.class, primaryKeys);
 72  0
         if (derivedComponentBo != null) {
 73  0
             return DerivedComponentBo.toComponentBo(derivedComponentBo);
 74  
         }
 75  0
         return null;
 76  
     }
 77  
         
 78  
 }