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
19 import java.util.HashMap;
20 import java.util.List;
21 import java.util.Map;
22
23 import org.apache.commons.lang.StringUtils;
24 import org.kuali.rice.krad.service.BusinessObjectService;
25 import org.kuali.rice.krms.api.repository.proposition.PropositionDefinition;
26 import org.kuali.rice.krms.api.repository.proposition.PropositionParameter;
27
28
29
30
31
32
33
34
35 public final class PropositionBoServiceImpl implements PropositionBoService {
36
37 private BusinessObjectService businessObjectService;
38
39
40
41
42
43
44
45 @Override
46 public PropositionDefinition createProposition(PropositionDefinition prop) {
47 if (prop == null){
48 throw new IllegalArgumentException("proposition is null");
49 }
50 if (null != prop.getId()) {
51 throw new IllegalStateException("for creation, PropositionDefinition.id must be null");
52 }
53
54 PropositionBo propositionBo = PropositionBo.from(prop);
55 businessObjectService.save(propositionBo);
56 return PropositionBo.to(propositionBo);
57 }
58
59
60
61
62
63
64 @Override
65 public void updateProposition(PropositionDefinition prop) {
66 if (prop == null) {
67 throw new IllegalArgumentException("proposition is null");
68 }
69 final String propIdKey = prop.getId();
70 final PropositionDefinition existing = getPropositionById(propIdKey);
71 if (existing == null) {
72 throw new IllegalStateException("the proposition does not exist: " + prop);
73 }
74 final PropositionDefinition toUpdate;
75 if (!existing.getId().equals(prop.getId())){
76 final PropositionDefinition.Builder builder = PropositionDefinition.Builder.create(prop);
77 builder.setId(existing.getId());
78 toUpdate = builder.build();
79 } else {
80 toUpdate = prop;
81 }
82
83 businessObjectService.save(PropositionBo.from(toUpdate));
84 }
85
86
87
88
89
90
91 @Override
92 public PropositionDefinition getPropositionById(String propId) {
93 if (StringUtils.isBlank(propId)){
94 throw new IllegalArgumentException("propId is null or blank");
95 }
96 PropositionBo bo = businessObjectService.findBySinglePrimaryKey(PropositionBo.class, propId);
97 return PropositionBo.to(bo);
98 }
99
100
101
102
103
104
105
106 @Override
107 public void createParameter(PropositionParameter parameter) {
108 if (parameter == null){
109 throw new IllegalArgumentException("parameter is null");
110 }
111 final String propIdKey = parameter.getPropId();
112 final Integer seqNoKey = parameter.getSequenceNumber();
113 final PropositionParameter existing = getParameterByPropIdAndSequenceNumber(propIdKey, seqNoKey);
114 if (existing != null && existing.getPropId().equals(propIdKey) && existing.getSequenceNumber().equals(seqNoKey)){
115 throw new IllegalStateException("the parameter to create already exists: " + parameter);
116 }
117
118 businessObjectService.save(PropositionParameterBo.from(parameter));
119 }
120
121
122
123
124
125
126 @Override
127 public void updateParameter(PropositionParameter parameter) {
128 if (parameter == null) {
129 throw new IllegalArgumentException("parameter is null");
130 }
131 final String propIdKey = parameter.getPropId();
132 final Integer seqNoKey = parameter.getSequenceNumber();
133 final PropositionParameter existing = getParameterByPropIdAndSequenceNumber(propIdKey, seqNoKey);
134 if (existing == null) {
135 throw new IllegalStateException("the parameter does not exist: " + parameter);
136 }
137 final PropositionParameter toUpdate;
138 if (!existing.getId().equals(parameter.getId())){
139 final PropositionParameter.Builder builder = PropositionParameter.Builder.create(parameter);
140 builder.setId(existing.getId());
141 toUpdate = builder.build();
142 } else {
143 toUpdate = parameter;
144 }
145
146 businessObjectService.save(PropositionParameterBo.from(toUpdate));
147 }
148
149
150
151
152
153
154 @Override
155 public List<PropositionParameter> getParameters(String propId) {
156 if (StringUtils.isBlank(propId)) {
157 throw new IllegalArgumentException("propId is null or blank");
158 }
159 final Map<String, Object> map = new HashMap<String, Object>();
160 map.put("propId", propId);
161 List<PropositionParameterBo> bos = (List<PropositionParameterBo>) businessObjectService.findMatchingOrderBy(PropositionParameterBo.class, map, "sequenceNumber", true);
162 return PropositionParameterBo.to(bos);
163 }
164
165
166
167
168
169
170 @Override
171 public PropositionParameter getParameterById(String id) {
172 if (StringUtils.isBlank(id)) {
173 throw new IllegalArgumentException("id is null or blank");
174 }
175 PropositionParameterBo bo = businessObjectService.findBySinglePrimaryKey(PropositionParameterBo.class, id);
176 return PropositionParameterBo.to(bo);
177 }
178
179
180
181
182
183
184 @Override
185 public PropositionParameter getParameterByPropIdAndSequenceNumber(
186 String propId, Integer sequenceNumber) {
187 if (StringUtils.isBlank(propId)) {
188 throw new IllegalArgumentException("propId is null or blank");
189 }
190 if (sequenceNumber == null) {
191 throw new IllegalArgumentException("sequenceNumber is null");
192 }
193 final Map<String, Object> map = new HashMap<String, Object>();
194 map.put("propId", propId);
195 map.put("sequenceNumber", sequenceNumber);
196 PropositionParameterBo bo = businessObjectService.findByPrimaryKey(PropositionParameterBo.class, map);
197 return PropositionParameterBo.to(bo);
198 }
199
200
201
202
203
204
205 public void setBusinessObjectService(BusinessObjectService businessObjectService) {
206 this.businessObjectService = businessObjectService;
207 }
208
209 }