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 | 0 | public class TermBoServiceImpl implements TermBoService { |
39 | |
|
40 | |
private BusinessObjectService businessObjectService; |
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
public void setBusinessObjectService(BusinessObjectService businessObjectService) { |
46 | 0 | this.businessObjectService = businessObjectService; |
47 | 0 | } |
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
@Override |
53 | |
public TermSpecificationDefinition getTermSpecificationById(String id) { |
54 | 0 | TermSpecificationBo termSpecificationBo = |
55 | |
businessObjectService.findBySinglePrimaryKey(TermSpecificationBo.class, id); |
56 | 0 | return TermSpecificationDefinition.Builder.create(termSpecificationBo).build(); |
57 | |
} |
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
@Override |
63 | |
public TermSpecificationDefinition createTermSpecification(TermSpecificationDefinition termSpec) { |
64 | 0 | if (!StringUtils.isBlank(termSpec.getId())) { |
65 | 0 | throw new IllegalArgumentException("for creation, TermSpecification.id must be null"); |
66 | |
} |
67 | |
|
68 | 0 | TermSpecificationBo termSpecBo = TermSpecificationBo.from(termSpec); |
69 | |
|
70 | 0 | businessObjectService.save(termSpecBo); |
71 | |
|
72 | 0 | return TermSpecificationBo.to(termSpecBo); |
73 | |
} |
74 | |
|
75 | |
|
76 | |
|
77 | |
|
78 | |
@Override |
79 | |
public TermDefinition createTermDefinition(TermDefinition termDef) { |
80 | 0 | if (!StringUtils.isBlank(termDef.getId())) { |
81 | 0 | throw new IllegalArgumentException("for creation, TermDefinition.id must be null"); |
82 | |
} |
83 | |
|
84 | 0 | TermBo termBo = TermBo.from(termDef); |
85 | |
|
86 | 0 | businessObjectService.save(termBo); |
87 | |
|
88 | 0 | return TermBo.to(termBo); |
89 | |
} |
90 | |
|
91 | |
|
92 | |
|
93 | |
|
94 | |
@Override |
95 | |
public TermResolverDefinition createTermResolver(TermResolverDefinition termResolver) { |
96 | 0 | if (!StringUtils.isBlank(termResolver.getId())) { |
97 | 0 | throw new IllegalArgumentException("for creation, TermResolverDefinition.id must be null"); |
98 | |
} |
99 | |
|
100 | 0 | TermResolverBo termResolverBo = TermResolverBo.from(termResolver); |
101 | |
|
102 | 0 | termResolverBo = (TermResolverBo)businessObjectService.save(termResolverBo); |
103 | |
|
104 | 0 | return TermResolverBo.to(termResolverBo); |
105 | |
} |
106 | |
|
107 | |
|
108 | |
|
109 | |
|
110 | |
@Override |
111 | |
public TermDefinition getTermById(String id) { |
112 | 0 | TermDefinition result = null; |
113 | |
|
114 | 0 | if (StringUtils.isBlank(id)) { |
115 | 0 | throw new IllegalArgumentException("id must not be blank or null"); |
116 | |
} |
117 | 0 | TermBo termBo = businessObjectService.findBySinglePrimaryKey(TermBo.class, id); |
118 | |
|
119 | 0 | if (termBo != null) { |
120 | 0 | result= TermBo.to(termBo); |
121 | |
} |
122 | |
|
123 | 0 | return result; |
124 | |
} |
125 | |
|
126 | |
|
127 | |
|
128 | |
|
129 | |
@Override |
130 | |
public TermResolverDefinition getTermResolverById(String id) { |
131 | 0 | TermResolverDefinition result = null; |
132 | |
|
133 | 0 | if (StringUtils.isBlank(id)) { |
134 | 0 | throw new IllegalArgumentException("id must not be blank or null"); |
135 | |
} |
136 | 0 | TermResolverBo termResolverBo = businessObjectService.findBySinglePrimaryKey(TermResolverBo.class, id); |
137 | |
|
138 | 0 | if (termResolverBo != null) { |
139 | 0 | result = TermResolverBo.to(termResolverBo); |
140 | |
} |
141 | |
|
142 | 0 | return result; |
143 | |
} |
144 | |
|
145 | |
@Override |
146 | |
public List<TermResolverDefinition> getTermResolversByNamespace(String namespace) { |
147 | 0 | List<TermResolverDefinition> results = null; |
148 | |
|
149 | 0 | if (StringUtils.isBlank(namespace)) { |
150 | 0 | throw new IllegalArgumentException("namespace must not be blank or null"); |
151 | |
} |
152 | |
|
153 | 0 | Map fieldValues = new HashMap(); |
154 | 0 | fieldValues.put("namespace", namespace); |
155 | |
|
156 | 0 | Collection<TermResolverBo> termResolverBos = businessObjectService.findMatching(TermResolverBo.class, fieldValues); |
157 | |
|
158 | 0 | if (!CollectionUtils.isEmpty(termResolverBos)) { |
159 | 0 | results = new ArrayList<TermResolverDefinition>(termResolverBos.size()); |
160 | |
|
161 | 0 | for (TermResolverBo termResolverBo : termResolverBos) if (termResolverBo != null) { |
162 | 0 | results.add(TermResolverBo.to(termResolverBo)); |
163 | |
} |
164 | |
} else { |
165 | 0 | results = Collections.emptyList(); |
166 | |
} |
167 | |
|
168 | 0 | return results; |
169 | |
} |
170 | |
} |