1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kim.impl.type; |
17 | |
|
18 | |
import org.apache.commons.lang.StringUtils; |
19 | |
import org.kuali.rice.core.api.exception.RiceIllegalArgumentException; |
20 | |
import org.kuali.rice.kim.api.type.KimType; |
21 | |
import org.kuali.rice.kim.api.type.KimTypeInfoService; |
22 | |
import org.kuali.rice.krad.service.BusinessObjectService; |
23 | |
|
24 | |
import java.util.ArrayList; |
25 | |
import java.util.Collection; |
26 | |
import java.util.Collections; |
27 | |
import java.util.HashMap; |
28 | |
import java.util.Map; |
29 | |
|
30 | 8 | public class KimTypeInfoServiceImpl implements KimTypeInfoService { |
31 | |
|
32 | |
private BusinessObjectService businessObjectService; |
33 | |
|
34 | |
@Override |
35 | |
public KimType getKimType(final String id) throws RiceIllegalArgumentException { |
36 | 2 | incomingParamCheck(id, "id"); |
37 | |
|
38 | 1 | return KimTypeBo.to(businessObjectService.findBySinglePrimaryKey(KimTypeBo.class, id)); |
39 | |
} |
40 | |
|
41 | |
@Override |
42 | |
public KimType findKimTypeByNameAndNamespace(final String namespaceCode, final String name) throws RiceIllegalArgumentException { |
43 | 4 | incomingParamCheck(namespaceCode, "namespaceCode"); |
44 | 3 | incomingParamCheck(name, "name"); |
45 | |
|
46 | 2 | final Map<String, Object> crit = new HashMap<String, Object>(); |
47 | 2 | crit.put("namespaceCode", namespaceCode); |
48 | 2 | crit.put("name", name); |
49 | 2 | crit.put("active", "true"); |
50 | |
|
51 | 2 | final Collection<KimTypeBo> bos = businessObjectService.findMatching(KimTypeBo.class, crit); |
52 | |
|
53 | 2 | if (bos != null && bos.size() > 1) { |
54 | 1 | throw new IllegalStateException("multiple active results were found for the namespace code: " + namespaceCode + " and name: " + name); |
55 | |
} |
56 | |
|
57 | 1 | return bos != null && bos.iterator().hasNext() ? KimTypeBo.to(bos.iterator().next()) : null; |
58 | |
} |
59 | |
|
60 | |
@Override |
61 | |
public Collection<KimType> findAllKimTypes() { |
62 | 2 | final Collection<KimTypeBo> bos |
63 | |
= businessObjectService.findMatching(KimTypeBo.class, Collections.singletonMap("active", "true")); |
64 | 2 | final Collection<KimType> ims = new ArrayList<KimType>(); |
65 | |
|
66 | 2 | if (bos != null) { |
67 | 1 | for (KimTypeBo bo : bos) { |
68 | 2 | if (bo != null) { |
69 | 2 | ims.add(KimTypeBo.to(bo)); |
70 | |
} |
71 | |
} |
72 | |
} |
73 | 2 | return Collections.unmodifiableCollection(ims); |
74 | |
} |
75 | |
|
76 | |
public void setBusinessObjectService(final BusinessObjectService businessObjectService) { |
77 | 8 | this.businessObjectService = businessObjectService; |
78 | 8 | } |
79 | |
|
80 | |
private void incomingParamCheck(Object object, String name) { |
81 | 9 | if (object == null) { |
82 | 3 | throw new RiceIllegalArgumentException(name + " was null"); |
83 | 6 | } else if (object instanceof String |
84 | |
&& StringUtils.isBlank((String) object)) { |
85 | 0 | throw new RiceIllegalArgumentException(name + " was blank"); |
86 | |
} |
87 | 6 | } |
88 | |
} |