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