| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
package org.kuali.rice.krms.impl.repository; |
| 18 | |
|
| 19 | |
|
| 20 | |
import org.apache.commons.lang.StringUtils; |
| 21 | |
import org.kuali.rice.kns.service.BusinessObjectService; |
| 22 | |
import org.kuali.rice.krms.api.repository.KrmsType; |
| 23 | |
import org.kuali.rice.krms.api.repository.KrmsTypeService; |
| 24 | |
|
| 25 | |
import java.util.*; |
| 26 | |
|
| 27 | 0 | public final class KrmsTypeServiceImpl implements KrmsTypeService { |
| 28 | |
|
| 29 | |
private BusinessObjectService businessObjectService; |
| 30 | |
|
| 31 | |
@Override |
| 32 | |
public KrmsType getTypeById(final String id) { |
| 33 | 0 | if (StringUtils.isBlank(id)) { |
| 34 | 0 | throw new IllegalArgumentException("id is blank"); |
| 35 | |
} |
| 36 | |
|
| 37 | 0 | KrmsTypeBo krmsTypeBo = businessObjectService.findByPrimaryKey(KrmsTypeBo.class, Collections.singletonMap("id", id)); |
| 38 | |
|
| 39 | 0 | return KrmsTypeBo.to(krmsTypeBo); |
| 40 | |
} |
| 41 | |
|
| 42 | |
@Override |
| 43 | |
public KrmsType getTypeByNameAndNamespace(final String name, final String namespace) { |
| 44 | 0 | if (StringUtils.isBlank(name)) { |
| 45 | 0 | throw new IllegalArgumentException("name is blank"); |
| 46 | |
} |
| 47 | 0 | if (StringUtils.isBlank(namespace)) { |
| 48 | 0 | throw new IllegalArgumentException("namespace is blank"); |
| 49 | |
} |
| 50 | |
|
| 51 | 0 | final Map<String, Object> map = new HashMap<String, Object>(); |
| 52 | 0 | map.put("name", name); |
| 53 | 0 | map.put("namespace", namespace); |
| 54 | |
|
| 55 | 0 | Collection<KrmsTypeBo> typeList = businessObjectService.findMatching(KrmsTypeBo.class, Collections.unmodifiableMap(map)); |
| 56 | 0 | if (typeList == null || typeList.isEmpty()) { |
| 57 | 0 | return null; |
| 58 | 0 | } else if (typeList.size() == 1) { |
| 59 | 0 | return KrmsTypeBo.to(typeList.iterator().next()); |
| 60 | 0 | } else throw new IllegalStateException("Multiple KRMS types found with same name and namespace"); |
| 61 | |
} |
| 62 | |
|
| 63 | |
@Override |
| 64 | |
public List<KrmsType> findAllTypesByNamespace(final String namespace) { |
| 65 | 0 | final Map<String, Object> map = new HashMap<String, Object>(); |
| 66 | 0 | map.put("namespace", namespace); |
| 67 | 0 | map.put("active", Boolean.TRUE); |
| 68 | |
|
| 69 | 0 | Collection<KrmsTypeBo> krmsTypeBos = businessObjectService.findMatching(KrmsTypeBo.class, Collections.unmodifiableMap(map)); |
| 70 | |
|
| 71 | 0 | return convertListOfBosToImmutables(krmsTypeBos); |
| 72 | |
} |
| 73 | |
|
| 74 | |
@Override |
| 75 | |
public List<KrmsType> findAllTypes() { |
| 76 | 0 | final Map<String, Object> map = new HashMap<String, Object>(); |
| 77 | 0 | map.put("active", Boolean.TRUE); |
| 78 | |
|
| 79 | 0 | Collection<KrmsTypeBo> krmsTypeBos = businessObjectService.findMatching(KrmsTypeBo.class, Collections.unmodifiableMap(map)); |
| 80 | 0 | return convertListOfBosToImmutables(krmsTypeBos); |
| 81 | |
} |
| 82 | |
|
| 83 | |
|
| 84 | |
|
| 85 | |
|
| 86 | |
|
| 87 | |
|
| 88 | |
public void setBusinessObjectService(final BusinessObjectService businessObjectService) { |
| 89 | 0 | this.businessObjectService = businessObjectService; |
| 90 | 0 | } |
| 91 | |
|
| 92 | |
|
| 93 | |
|
| 94 | |
|
| 95 | |
|
| 96 | |
|
| 97 | |
|
| 98 | |
List<KrmsType> convertListOfBosToImmutables(final Collection<KrmsTypeBo> krmsTypeBos) { |
| 99 | 0 | ArrayList<KrmsType> krmsTypes = new ArrayList<KrmsType>(); |
| 100 | 0 | for (KrmsTypeBo bo : krmsTypeBos) { |
| 101 | 0 | KrmsType krmsType = KrmsTypeBo.to(bo); |
| 102 | 0 | krmsTypes.add(krmsType); |
| 103 | 0 | } |
| 104 | 0 | return Collections.unmodifiableList(krmsTypes); |
| 105 | |
} |
| 106 | |
} |