1 | |
package org.kuali.student.r2.core.class1.state.service.impl; |
2 | |
|
3 | |
import java.util.ArrayList; |
4 | |
import java.util.List; |
5 | |
|
6 | |
import javax.jws.WebParam; |
7 | |
import javax.jws.WebService; |
8 | |
import javax.persistence.NoResultException; |
9 | |
|
10 | |
import org.kuali.rice.core.api.criteria.GenericQueryResults; |
11 | |
import org.kuali.rice.core.api.criteria.QueryByCriteria; |
12 | |
import org.kuali.student.r2.common.criteria.CriteriaLookupService; |
13 | |
import org.kuali.student.r2.common.dto.ContextInfo; |
14 | |
import org.kuali.student.r2.common.dto.StatusInfo; |
15 | |
import org.kuali.student.r2.common.dto.ValidationResultInfo; |
16 | |
import org.kuali.student.r2.common.exceptions.AlreadyExistsException; |
17 | |
import org.kuali.student.r2.common.exceptions.DataValidationErrorException; |
18 | |
import org.kuali.student.r2.common.exceptions.DoesNotExistException; |
19 | |
import org.kuali.student.r2.common.exceptions.InvalidParameterException; |
20 | |
import org.kuali.student.r2.common.exceptions.MissingParameterException; |
21 | |
import org.kuali.student.r2.common.exceptions.OperationFailedException; |
22 | |
import org.kuali.student.r2.common.exceptions.PermissionDeniedException; |
23 | |
import org.kuali.student.r2.common.exceptions.ReadOnlyException; |
24 | |
import org.kuali.student.r2.common.exceptions.VersionMismatchException; |
25 | |
import org.kuali.student.r2.core.class1.state.dao.LifecycleDao; |
26 | |
import org.kuali.student.r2.core.class1.state.dao.StateDao; |
27 | |
import org.kuali.student.r2.core.class1.state.model.LifecycleEntity; |
28 | |
import org.kuali.student.r2.core.class1.state.model.StateEntity; |
29 | |
import org.kuali.student.r2.core.state.dto.LifecycleInfo; |
30 | |
import org.kuali.student.r2.core.state.dto.StateInfo; |
31 | |
import org.kuali.student.r2.core.state.service.StateService; |
32 | |
import org.springframework.transaction.annotation.Transactional; |
33 | |
|
34 | |
@WebService(name = "StateService", serviceName = "StateService", portName = "StateService", targetNamespace = "http://student.kuali.org/wsdl/state") |
35 | |
@Transactional(readOnly = true, noRollbackFor = {DoesNotExistException.class}, rollbackFor = {Throwable.class}) |
36 | 0 | public class StateServiceImpl implements StateService { |
37 | |
|
38 | |
private StateDao stateDao; |
39 | |
private LifecycleDao lifecycleDao; |
40 | |
private CriteriaLookupService criteriaLookupService; |
41 | |
|
42 | |
public StateDao getStateDao() { |
43 | 0 | return stateDao; |
44 | |
} |
45 | |
|
46 | |
public void setStateDao(StateDao stateDao) { |
47 | 0 | this.stateDao = stateDao; |
48 | 0 | } |
49 | |
|
50 | |
public LifecycleDao getLifecycleDao() { |
51 | 0 | return lifecycleDao; |
52 | |
} |
53 | |
|
54 | |
public void setLifecycleDao(LifecycleDao lifecycleDao) { |
55 | 0 | this.lifecycleDao = lifecycleDao; |
56 | 0 | } |
57 | |
|
58 | |
public CriteriaLookupService getCriteriaLookupService() { |
59 | 0 | return criteriaLookupService; |
60 | |
} |
61 | |
|
62 | |
public void setCriteriaLookupService(CriteriaLookupService criteriaLookupService) { |
63 | 0 | this.criteriaLookupService = criteriaLookupService; |
64 | 0 | } |
65 | |
|
66 | |
@Override |
67 | |
public LifecycleInfo getLifecycle(String lifecycleKey, ContextInfo context) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException { |
68 | |
try { |
69 | 0 | LifecycleEntity sp = lifecycleDao.getProcessByKey(lifecycleKey); |
70 | 0 | if (null == sp) { |
71 | 0 | throw new DoesNotExistException(lifecycleKey); |
72 | |
} |
73 | 0 | return sp.toDto(); |
74 | 0 | } catch (NoResultException ex) { |
75 | 0 | throw new DoesNotExistException(lifecycleKey); |
76 | |
} |
77 | |
} |
78 | |
|
79 | |
@Override |
80 | |
public StateInfo getState(String stateKey, ContextInfo context) |
81 | |
throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException { |
82 | |
try { |
83 | 0 | StateEntity state = stateDao.getState(stateKey); |
84 | 0 | if (null == state) { |
85 | 0 | throw new DoesNotExistException(stateKey); |
86 | |
} |
87 | 0 | return state.toDto(); |
88 | 0 | } catch (NoResultException ex) { |
89 | 0 | throw new DoesNotExistException(stateKey); |
90 | |
} |
91 | |
} |
92 | |
|
93 | |
@Override |
94 | |
public List<LifecycleInfo> getLifecyclesByKeys(List<String> lifecycleKeys, ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
95 | 0 | List<LifecycleEntity> lifecycles = lifecycleDao.findByIds(lifecycleKeys); |
96 | 0 | List<LifecycleInfo> result = new ArrayList<LifecycleInfo>(lifecycles.size()); |
97 | 0 | for (int i = 0; i < lifecycles.size(); i++) { |
98 | 0 | LifecycleEntity entity = lifecycles.get(i); |
99 | 0 | if (entity == null) { |
100 | |
|
101 | |
|
102 | 0 | throw new DoesNotExistException(lifecycleKeys.get(i)); |
103 | |
} |
104 | 0 | result.add(entity.toDto()); |
105 | |
} |
106 | 0 | return result; |
107 | |
} |
108 | |
|
109 | |
@Override |
110 | |
public List<String> getLifecycleKeysByRefObjectUri(String refObjectUri, ContextInfo contextInfo) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
111 | 0 | List<LifecycleEntity> lifecycles = lifecycleDao.getLifecyclesByRefObjectUri(refObjectUri); |
112 | 0 | List<String> result = new ArrayList<String>(); |
113 | 0 | for (LifecycleEntity entity : lifecycles) { |
114 | 0 | if (entity != null) { |
115 | 0 | result.add(entity.getId()); |
116 | |
} |
117 | |
} |
118 | 0 | return result; |
119 | |
} |
120 | |
|
121 | |
@Override |
122 | |
public List<String> searchForLifecycleKeys(QueryByCriteria criteria, ContextInfo contextInfo) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
123 | 0 | List<String> lifecycleKeys = new ArrayList<String>(); |
124 | 0 | GenericQueryResults<LifecycleEntity> results = criteriaLookupService.lookup(LifecycleEntity.class, criteria); |
125 | 0 | if (null != results && results.getResults().size() > 0) { |
126 | 0 | for (LifecycleEntity lifecycle : results.getResults()) { |
127 | 0 | lifecycleKeys.add(lifecycle.getId()); |
128 | |
} |
129 | |
} |
130 | 0 | return lifecycleKeys; |
131 | |
} |
132 | |
|
133 | |
@Override |
134 | |
public List<LifecycleInfo> searchForLifecycles(QueryByCriteria criteria, ContextInfo contextInfo) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
135 | 0 | List<LifecycleInfo> lifecycleInfos = new ArrayList<LifecycleInfo>(); |
136 | 0 | GenericQueryResults<LifecycleEntity> results = criteriaLookupService.lookup(LifecycleEntity.class, criteria); |
137 | 0 | if (null != results && results.getResults().size() > 0) { |
138 | 0 | for (LifecycleEntity lifecycle : results.getResults()) { |
139 | 0 | lifecycleInfos.add(lifecycle.toDto()); |
140 | |
} |
141 | |
} |
142 | 0 | return lifecycleInfos; |
143 | |
} |
144 | |
|
145 | |
@Override |
146 | |
public List<ValidationResultInfo> validateLifecycle(String validationTypeKey, LifecycleInfo lifecycleInfo, ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
147 | 0 | return new ArrayList<ValidationResultInfo>(); |
148 | |
} |
149 | |
|
150 | |
@Override |
151 | |
@Transactional |
152 | |
public LifecycleInfo createLifecycle(String lifecycleKey, LifecycleInfo lifecycleInfo, ContextInfo contextInfo) |
153 | |
throws AlreadyExistsException, DataValidationErrorException, InvalidParameterException, |
154 | |
MissingParameterException, OperationFailedException, PermissionDeniedException, ReadOnlyException { |
155 | 0 | LifecycleEntity entity = lifecycleDao.find(lifecycleKey); |
156 | 0 | if (entity != null) { |
157 | 0 | throw new AlreadyExistsException(lifecycleKey); |
158 | |
} |
159 | 0 | if (!lifecycleKey.equals(lifecycleInfo.getKey())) { |
160 | 0 | throw new InvalidParameterException(lifecycleKey + " does not match the key in the info object " + lifecycleInfo.getKey()); |
161 | |
} |
162 | |
|
163 | 0 | entity = new LifecycleEntity(lifecycleInfo); |
164 | 0 | entity.setId(lifecycleKey); |
165 | |
|
166 | 0 | entity.setEntityCreated(contextInfo); |
167 | |
|
168 | 0 | lifecycleDao.persist(entity); |
169 | 0 | return entity.toDto(); |
170 | |
} |
171 | |
|
172 | |
@Override |
173 | |
@Transactional |
174 | |
public LifecycleInfo updateLifecycle(String lifecycleKey, LifecycleInfo lifecycleInfo, ContextInfo contextInfo) |
175 | |
throws DataValidationErrorException, DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, ReadOnlyException, VersionMismatchException { |
176 | 0 | LifecycleEntity entity = lifecycleDao.find(lifecycleKey); |
177 | 0 | if (entity == null) { |
178 | 0 | throw new DoesNotExistException(lifecycleKey); |
179 | |
} |
180 | 0 | entity.fromDto(lifecycleInfo); |
181 | |
|
182 | 0 | entity.setEntityUpdated(contextInfo); |
183 | |
|
184 | 0 | lifecycleDao.merge(entity); |
185 | 0 | return entity.toDto(); |
186 | |
} |
187 | |
|
188 | |
@Override |
189 | |
@Transactional |
190 | |
public StatusInfo deleteLifecycle(String lifecycleKey, ContextInfo contextInfo) |
191 | |
throws DoesNotExistException, InvalidParameterException, |
192 | |
MissingParameterException, OperationFailedException, PermissionDeniedException { |
193 | 0 | LifecycleEntity lifecycle = lifecycleDao.find(lifecycleKey); |
194 | 0 | if (lifecycle == null) { |
195 | 0 | throw new DoesNotExistException(lifecycleKey); |
196 | |
} |
197 | 0 | lifecycleDao.remove(lifecycle); |
198 | 0 | StatusInfo status = new StatusInfo(); |
199 | 0 | status.setSuccess(Boolean.TRUE); |
200 | 0 | return status; |
201 | |
} |
202 | |
|
203 | |
@Override |
204 | |
public List<StateInfo> getStatesByKeys(List<String> stateKeys, ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
205 | 0 | List<StateEntity> list = stateDao.findByIds(stateKeys); |
206 | 0 | List<StateInfo> result = new ArrayList<StateInfo>(list.size()); |
207 | 0 | for (int i = 0; i < list.size(); i++) { |
208 | 0 | StateEntity entity = list.get(i); |
209 | 0 | if (entity == null) { |
210 | |
|
211 | |
|
212 | 0 | throw new DoesNotExistException(stateKeys.get(i)); |
213 | |
} |
214 | 0 | result.add(entity.toDto()); |
215 | |
} |
216 | 0 | return result; |
217 | |
} |
218 | |
|
219 | |
@Override |
220 | |
public List<StateInfo> getStatesByLifecycle(String lifecycleKey, ContextInfo contextInfo) |
221 | |
throws DoesNotExistException, InvalidParameterException, MissingParameterException, |
222 | |
OperationFailedException, PermissionDeniedException { |
223 | |
|
224 | 0 | this.getLifecycle(lifecycleKey, contextInfo); |
225 | 0 | List<StateEntity> entities = null; |
226 | 0 | entities = stateDao.getStatesByLifecycle(lifecycleKey); |
227 | 0 | List<StateInfo> infos = new ArrayList<StateInfo>(); |
228 | 0 | for (StateEntity state : entities) { |
229 | 0 | infos.add(state.toDto()); |
230 | |
} |
231 | 0 | return infos; |
232 | |
} |
233 | |
|
234 | |
@Override |
235 | |
public List<String> searchForStateKeys(QueryByCriteria criteria, ContextInfo contextInfo) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
236 | 0 | List<String> stateKeys = new ArrayList<String>(); |
237 | 0 | GenericQueryResults<StateEntity> results = criteriaLookupService.lookup(StateEntity.class, criteria); |
238 | 0 | if (null != results && results.getResults().size() > 0) { |
239 | 0 | for (StateEntity state : results.getResults()) { |
240 | 0 | stateKeys.add(state.getId()); |
241 | |
} |
242 | |
} |
243 | 0 | return stateKeys; |
244 | |
} |
245 | |
|
246 | |
@Override |
247 | |
public List<StateInfo> searchForStates(QueryByCriteria criteria, ContextInfo contextInfo) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
248 | 0 | List<StateInfo> stateInfos = new ArrayList<StateInfo>(); |
249 | 0 | GenericQueryResults<StateEntity> results = criteriaLookupService.lookup(StateEntity.class, criteria); |
250 | 0 | if (null != results && results.getResults().size() > 0) { |
251 | 0 | for (StateEntity state : results.getResults()) { |
252 | 0 | stateInfos.add(state.toDto()); |
253 | |
} |
254 | |
} |
255 | 0 | return stateInfos; |
256 | |
} |
257 | |
|
258 | |
@Override |
259 | |
public List<ValidationResultInfo> validateState(String validationTypeKey, String lifecycleKey, StateInfo stateInfo, ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
260 | 0 | return new ArrayList<ValidationResultInfo>(); |
261 | |
} |
262 | |
|
263 | |
@Override |
264 | |
@Transactional |
265 | |
public StateInfo createState(String lifecycleKey, String stateKey, StateInfo stateInfo, ContextInfo contextInfo) throws AlreadyExistsException, DataValidationErrorException, DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, ReadOnlyException { |
266 | 0 | StateEntity entity = stateDao.find(stateKey); |
267 | 0 | if (entity != null) { |
268 | 0 | throw new AlreadyExistsException(stateKey); |
269 | |
} |
270 | 0 | if (!lifecycleKey.equals(stateInfo.getLifecycleKey())) { |
271 | 0 | throw new InvalidParameterException(lifecycleKey + " life cycle key does not match the key in the info object " + stateInfo.getLifecycleKey()); |
272 | |
} |
273 | 0 | if (!stateKey.equals(stateInfo.getKey())) { |
274 | 0 | throw new InvalidParameterException(stateKey + " state key does not match the key in the info object " + stateInfo.getKey()); |
275 | |
} |
276 | 0 | entity = new StateEntity(stateInfo); |
277 | 0 | entity.setId(stateKey); |
278 | 0 | entity.setLifecycleKey(lifecycleKey); |
279 | |
|
280 | 0 | entity.setEntityCreated(contextInfo); |
281 | |
|
282 | 0 | stateDao.persist(entity); |
283 | 0 | return entity.toDto(); |
284 | |
} |
285 | |
|
286 | |
@Override |
287 | |
@Transactional |
288 | |
public StateInfo updateState(String stateKey, StateInfo stateInfo, ContextInfo contextInfo) |
289 | |
throws DataValidationErrorException, DoesNotExistException, |
290 | |
InvalidParameterException, MissingParameterException, OperationFailedException, |
291 | |
PermissionDeniedException, ReadOnlyException, VersionMismatchException { |
292 | 0 | StateEntity entity = stateDao.find(stateKey); |
293 | 0 | if (entity == null) { |
294 | 0 | throw new DoesNotExistException(stateKey); |
295 | |
} |
296 | 0 | entity.fromDto(stateInfo); |
297 | |
|
298 | 0 | entity.setEntityUpdated(contextInfo); |
299 | |
|
300 | 0 | stateDao.merge(entity); |
301 | 0 | return entity.toDto(); |
302 | |
} |
303 | |
|
304 | |
@Override |
305 | |
@Transactional |
306 | |
public StatusInfo deleteState(String stateKey, ContextInfo contextInfo) |
307 | |
throws DoesNotExistException, InvalidParameterException, MissingParameterException, |
308 | |
OperationFailedException, PermissionDeniedException { |
309 | 0 | StateEntity entity = stateDao.find(stateKey); |
310 | 0 | if (entity == null) { |
311 | 0 | throw new DoesNotExistException(stateKey); |
312 | |
} |
313 | 0 | stateDao.remove(entity); |
314 | 0 | StatusInfo deleteStatus = new StatusInfo(); |
315 | 0 | deleteStatus.setSuccess(true); |
316 | 0 | return deleteStatus; |
317 | |
} |
318 | |
} |