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 org.apache.commons.lang.StringUtils;
19 import org.kuali.rice.core.api.criteria.QueryByCriteria;
20 import org.kuali.rice.core.api.criteria.QueryResults;
21 import org.kuali.rice.core.api.exception.RiceIllegalArgumentException;
22 import org.kuali.rice.coreservice.api.namespace.Namespace;
23 import org.kuali.rice.coreservice.api.namespace.NamespaceService;
24 import org.kuali.rice.krad.data.CompoundKey;
25 import org.kuali.rice.krad.data.DataObjectService;
26 import org.springframework.beans.factory.annotation.Required;
27
28 import java.util.ArrayList;
29 import java.util.Collections;
30 import java.util.HashMap;
31 import java.util.List;
32
33 import static java.util.Collections.singletonMap;
34
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.findMatching(
49 NamespaceBo.class,QueryByCriteria.Builder.andAttributes(new HashMap<String, String>()).build());
50 List<Namespace> namespaces = new ArrayList<Namespace>();
51 if(namespaceBos != null){
52 for (NamespaceBo bo : namespaceBos.getResults()) {
53 namespaces.add(NamespaceBo.to(bo));
54 }
55 }
56
57 return Collections.unmodifiableList(namespaces);
58 }
59
60 public DataObjectService getDataObjectService() {
61 return dataObjectService;
62 }
63 @Required
64 public void setDataObjectService(DataObjectService dataObjectService) {
65 this.dataObjectService = dataObjectService;
66 }
67 }