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