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