1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krms.impl.repository;
17
18 import java.util.ArrayList;
19 import java.util.Collection;
20 import java.util.Collections;
21 import java.util.HashMap;
22 import java.util.List;
23 import java.util.Map;
24
25 import org.apache.commons.lang.StringUtils;
26 import org.kuali.rice.krad.service.BusinessObjectService;
27 import org.kuali.rice.krms.api.repository.term.TermDefinition;
28 import org.kuali.rice.krms.api.repository.term.TermResolverDefinition;
29 import org.kuali.rice.krms.api.repository.term.TermSpecificationDefinition;
30 import org.springframework.util.CollectionUtils;
31
32
33
34
35
36
37
38 public class TermBoServiceImpl implements TermBoService {
39
40 private BusinessObjectService businessObjectService;
41
42
43
44
45 public void setBusinessObjectService(BusinessObjectService businessObjectService) {
46 this.businessObjectService = businessObjectService;
47 }
48
49
50
51
52 @Override
53 public TermSpecificationDefinition getTermSpecificationById(String id) {
54 TermSpecificationBo termSpecificationBo =
55 businessObjectService.findBySinglePrimaryKey(TermSpecificationBo.class, id);
56 return TermSpecificationDefinition.Builder.create(termSpecificationBo).build();
57 }
58
59
60
61
62 @Override
63 public TermSpecificationDefinition createTermSpecification(TermSpecificationDefinition termSpec) {
64 if (!StringUtils.isBlank(termSpec.getId())) {
65 throw new IllegalArgumentException("for creation, TermSpecification.id must be null");
66 }
67
68 TermSpecificationBo termSpecBo = TermSpecificationBo.from(termSpec);
69
70 businessObjectService.save(termSpecBo);
71
72 return TermSpecificationBo.to(termSpecBo);
73 }
74
75
76
77
78 @Override
79 public TermDefinition createTermDefinition(TermDefinition termDef) {
80 if (!StringUtils.isBlank(termDef.getId())) {
81 throw new IllegalArgumentException("for creation, TermDefinition.id must be null");
82 }
83
84 TermBo termBo = TermBo.from(termDef);
85
86 businessObjectService.save(termBo);
87
88 return TermBo.to(termBo);
89 }
90
91
92
93
94 @Override
95 public TermResolverDefinition createTermResolver(TermResolverDefinition termResolver) {
96 if (!StringUtils.isBlank(termResolver.getId())) {
97 throw new IllegalArgumentException("for creation, TermResolverDefinition.id must be null");
98 }
99
100 TermResolverBo termResolverBo = TermResolverBo.from(termResolver);
101
102 termResolverBo = (TermResolverBo)businessObjectService.save(termResolverBo);
103
104 return TermResolverBo.to(termResolverBo);
105 }
106
107
108
109
110 @Override
111 public TermDefinition getTermById(String id) {
112 TermDefinition result = null;
113
114 if (StringUtils.isBlank(id)) {
115 throw new IllegalArgumentException("id must not be blank or null");
116 }
117 TermBo termBo = businessObjectService.findBySinglePrimaryKey(TermBo.class, id);
118
119 if (termBo != null) {
120 result= TermBo.to(termBo);
121 }
122
123 return result;
124 }
125
126
127
128
129 @Override
130 public TermResolverDefinition getTermResolverById(String id) {
131 TermResolverDefinition result = null;
132
133 if (StringUtils.isBlank(id)) {
134 throw new IllegalArgumentException("id must not be blank or null");
135 }
136 TermResolverBo termResolverBo = businessObjectService.findBySinglePrimaryKey(TermResolverBo.class, id);
137
138 if (termResolverBo != null) {
139 result = TermResolverBo.to(termResolverBo);
140 }
141
142 return result;
143 }
144
145 @Override
146 public List<TermResolverDefinition> getTermResolversByNamespace(String namespace) {
147 List<TermResolverDefinition> results = null;
148
149 if (StringUtils.isBlank(namespace)) {
150 throw new IllegalArgumentException("namespace must not be blank or null");
151 }
152
153 Map fieldValues = new HashMap();
154 fieldValues.put("namespace", namespace);
155
156 Collection<TermResolverBo> termResolverBos = businessObjectService.findMatching(TermResolverBo.class, fieldValues);
157
158 if (!CollectionUtils.isEmpty(termResolverBos)) {
159 results = new ArrayList<TermResolverDefinition>(termResolverBos.size());
160
161 for (TermResolverBo termResolverBo : termResolverBos) if (termResolverBo != null) {
162 results.add(TermResolverBo.to(termResolverBo));
163 }
164 } else {
165 results = Collections.emptyList();
166 }
167
168 return results;
169 }
170 }