1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
29
30
31
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 }