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