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 import org.springframework.transaction.annotation.Transactional;
33
34 @Transactional(readOnly=true)
35 public class NamespaceServiceImpl implements NamespaceService {
36 private DataObjectService dataObjectService;
37
38 @Override
39 public Namespace getNamespace(String code) {
40 if (StringUtils.isBlank(code)) {
41 throw new RiceIllegalArgumentException("the code is blank");
42 }
43 return NamespaceBo.to(dataObjectService.find(NamespaceBo.class, new CompoundKey(singletonMap("code", code))));
44 }
45
46 @Override
47 public List<Namespace> findAllNamespaces() {
48 QueryResults<NamespaceBo> namespaceBos = dataObjectService.findAll(NamespaceBo.class);
49 List<Namespace> namespaces = new ArrayList<Namespace>();
50 if(namespaceBos != null){
51 for (NamespaceBo bo : namespaceBos.getResults()) {
52 namespaces.add(NamespaceBo.to(bo));
53 }
54 }
55
56 return Collections.unmodifiableList(namespaces);
57 }
58
59 public DataObjectService getDataObjectService() {
60 return dataObjectService;
61 }
62 @Required
63 public void setDataObjectService(DataObjectService dataObjectService) {
64 this.dataObjectService = dataObjectService;
65 }
66 }