1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.coreservice.impl.namespace;
17
18 import static java.util.Collections.singletonMap;
19
20 import java.util.ArrayList;
21 import java.util.Collections;
22 import java.util.List;
23
24 import org.apache.commons.lang.StringUtils;
25 import org.kuali.rice.core.api.criteria.QueryResults;
26 import org.kuali.rice.core.api.exception.RiceIllegalArgumentException;
27 import org.kuali.rice.coreservice.api.namespace.Namespace;
28 import org.kuali.rice.coreservice.api.namespace.NamespaceService;
29 import org.kuali.rice.krad.data.CompoundKey;
30 import org.kuali.rice.krad.data.DataObjectService;
31 import org.springframework.beans.factory.annotation.Required;
32
33 public class NamespaceServiceImpl implements NamespaceService {
34 private DataObjectService dataObjectService;
35
36 @Override
37 public Namespace getNamespace(String code) {
38 if (StringUtils.isBlank(code)) {
39 throw new RiceIllegalArgumentException("the code is blank");
40 }
41 return NamespaceBo.to(dataObjectService.find(NamespaceBo.class, new CompoundKey(singletonMap("code", code))));
42 }
43
44 @Override
45 public List<Namespace> findAllNamespaces() {
46 QueryResults<NamespaceBo> namespaceBos = dataObjectService.findAll(NamespaceBo.class);
47 List<Namespace> namespaces = new ArrayList<Namespace>();
48 if(namespaceBos != null){
49 for (NamespaceBo bo : namespaceBos.getResults()) {
50 namespaces.add(NamespaceBo.to(bo));
51 }
52 }
53
54 return Collections.unmodifiableList(namespaces);
55 }
56
57 public DataObjectService getDataObjectService() {
58 return dataObjectService;
59 }
60 @Required
61 public void setDataObjectService(DataObjectService dataObjectService) {
62 this.dataObjectService = dataObjectService;
63 }
64 }