1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.student.core.proposal.service.impl; |
17 | |
|
18 | |
import java.util.List; |
19 | |
|
20 | |
import javax.jws.WebService; |
21 | |
|
22 | |
import org.kuali.student.common.dictionary.dto.ObjectStructureDefinition; |
23 | |
import org.kuali.student.common.dictionary.service.DictionaryService; |
24 | |
import org.kuali.student.common.dto.ReferenceTypeInfo; |
25 | |
import org.kuali.student.common.dto.StatusInfo; |
26 | |
import org.kuali.student.common.exceptions.AlreadyExistsException; |
27 | |
import org.kuali.student.common.exceptions.DataValidationErrorException; |
28 | |
import org.kuali.student.common.exceptions.DependentObjectsExistException; |
29 | |
import org.kuali.student.common.exceptions.DoesNotExistException; |
30 | |
import org.kuali.student.common.exceptions.InvalidParameterException; |
31 | |
import org.kuali.student.common.exceptions.MissingParameterException; |
32 | |
import org.kuali.student.common.exceptions.OperationFailedException; |
33 | |
import org.kuali.student.common.exceptions.PermissionDeniedException; |
34 | |
import org.kuali.student.common.exceptions.VersionMismatchException; |
35 | |
import org.kuali.student.common.search.dto.SearchCriteriaTypeInfo; |
36 | |
import org.kuali.student.common.search.dto.SearchParam; |
37 | |
import org.kuali.student.common.search.dto.SearchRequest; |
38 | |
import org.kuali.student.common.search.dto.SearchResult; |
39 | |
import org.kuali.student.common.search.dto.SearchResultRow; |
40 | |
import org.kuali.student.common.search.dto.SearchResultTypeInfo; |
41 | |
import org.kuali.student.common.search.dto.SearchTypeInfo; |
42 | |
import org.kuali.student.common.search.service.SearchManager; |
43 | |
import org.kuali.student.common.validation.dto.ValidationResultInfo; |
44 | |
import org.kuali.student.common.validator.Validator; |
45 | |
import org.kuali.student.common.validator.ValidatorFactory; |
46 | |
import org.kuali.student.core.proposal.dao.ProposalDao; |
47 | |
import org.kuali.student.core.proposal.dto.ProposalInfo; |
48 | |
import org.kuali.student.core.proposal.dto.ProposalTypeInfo; |
49 | |
import org.kuali.student.core.proposal.entity.Proposal; |
50 | |
import org.kuali.student.core.proposal.entity.ProposalReference; |
51 | |
import org.kuali.student.core.proposal.entity.ProposalReferenceType; |
52 | |
import org.kuali.student.core.proposal.entity.ProposalType; |
53 | |
import org.kuali.student.core.proposal.service.ProposalService; |
54 | |
import org.springframework.transaction.annotation.Transactional; |
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
@WebService(endpointInterface = "org.kuali.student.core.proposal.service.ProposalService", serviceName = "ProposalService", portName = "ProposalService", targetNamespace = "http://student.kuali.org/wsdl/proposal") |
64 | 2 | public class ProposalServiceImpl implements ProposalService { |
65 | |
private ProposalDao proposalDao; |
66 | |
|
67 | |
private SearchManager searchManager; |
68 | |
private DictionaryService dictionaryServiceDelegate; |
69 | |
private ValidatorFactory validatorFactory; |
70 | |
|
71 | |
public void setSearchManager(SearchManager searchManager) { |
72 | 1 | this.searchManager = searchManager; |
73 | 1 | } |
74 | |
|
75 | |
public void setDictionaryServiceDelegate(DictionaryService dictionaryServiceDelegate) { |
76 | 1 | this.dictionaryServiceDelegate = dictionaryServiceDelegate; |
77 | 1 | } |
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
@Override |
83 | |
@Transactional(readOnly=false,noRollbackFor={DoesNotExistException.class},rollbackFor={Throwable.class}) |
84 | |
public ProposalInfo createProposal(String proposalTypeKey, ProposalInfo proposalInfo) throws AlreadyExistsException, DataValidationErrorException, DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
85 | 1 | checkForMissingParameter(proposalTypeKey, "proposalTypeKey"); |
86 | 1 | checkForMissingParameter(proposalInfo, "proposalInfo"); |
87 | |
|
88 | |
|
89 | 1 | List<ValidationResultInfo> validationResults = validateProposal("OBJECT", proposalInfo); |
90 | 1 | if (null != validationResults && validationResults.size() > 0) { |
91 | 0 | throw new DataValidationErrorException("Validation error!", validationResults); |
92 | |
} |
93 | |
|
94 | |
|
95 | 1 | if (proposalInfo.getProposerPerson() != null && !proposalInfo.getProposerPerson().isEmpty() && proposalInfo.getProposerOrg() != null && !proposalInfo.getProposerOrg().isEmpty()) { |
96 | 0 | throw new InvalidParameterException("Not allowed to have both Person and Organization propsers"); |
97 | |
} |
98 | |
try { |
99 | 1 | Proposal proposal = ProposalAssembler.toProposal(proposalTypeKey, proposalInfo, proposalDao); |
100 | 1 | proposalDao.create(proposal); |
101 | |
|
102 | 1 | return ProposalAssembler.toProposalInfo(proposal); |
103 | 0 | } catch (VersionMismatchException e) { |
104 | 0 | throw new InvalidParameterException(e.getMessage()); |
105 | |
} |
106 | |
|
107 | |
} |
108 | |
|
109 | |
|
110 | |
|
111 | |
|
112 | |
@Override |
113 | |
@Transactional(readOnly=false,noRollbackFor={DoesNotExistException.class},rollbackFor={Throwable.class}) |
114 | |
public StatusInfo deleteProposal(String proposalId) throws DoesNotExistException, InvalidParameterException, MissingParameterException, DependentObjectsExistException, OperationFailedException, PermissionDeniedException { |
115 | 2 | checkForMissingParameter(proposalId, "proposalId"); |
116 | |
|
117 | 2 | StatusInfo status = new StatusInfo(); |
118 | |
try { |
119 | 2 | proposalDao.delete(Proposal.class, proposalId); |
120 | 1 | } catch (DoesNotExistException e) { |
121 | 1 | status.setSuccess(false); |
122 | 1 | } |
123 | |
|
124 | 2 | return status; |
125 | |
} |
126 | |
|
127 | |
|
128 | |
|
129 | |
|
130 | |
|
131 | |
@Override |
132 | |
@Transactional(readOnly=true) |
133 | |
public ProposalInfo getProposal(String proposalId) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException { |
134 | 7 | checkForMissingParameter(proposalId, "proposalId"); |
135 | 6 | Proposal entity = proposalDao.fetch(Proposal.class, proposalId); |
136 | 4 | return ProposalAssembler.toProposalInfo(entity); |
137 | |
} |
138 | |
|
139 | |
|
140 | |
|
141 | |
|
142 | |
|
143 | |
|
144 | |
@Override |
145 | |
@Transactional(readOnly=true) |
146 | |
public ProposalTypeInfo getProposalType(String proposalTypeKey) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException { |
147 | 3 | checkForMissingParameter(proposalTypeKey, "proposalTypeKey"); |
148 | |
|
149 | 2 | ProposalType proposalType = proposalDao.fetch(ProposalType.class, proposalTypeKey); |
150 | 1 | return ProposalAssembler.toProposalTypeInfo(proposalType); |
151 | |
} |
152 | |
|
153 | |
|
154 | |
|
155 | |
|
156 | |
@Override |
157 | |
@Transactional(readOnly=true) |
158 | |
public List<ProposalTypeInfo> getProposalTypes() throws OperationFailedException { |
159 | 1 | List<ProposalType> proposalTypes = proposalDao.find(ProposalType.class); |
160 | 1 | return ProposalAssembler.toProposalTypeInfos(proposalTypes); |
161 | |
} |
162 | |
|
163 | |
|
164 | |
|
165 | |
|
166 | |
@Override |
167 | |
@Transactional(readOnly=true) |
168 | |
public List<ProposalTypeInfo> getProposalTypesForReferenceType(String referenceTypeKey) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException { |
169 | 3 | checkForMissingParameter(referenceTypeKey, "referenceTypeKey"); |
170 | |
|
171 | 2 | List<ProposalType> proposalTypes = proposalDao.getProposalTypesForReferenceType(referenceTypeKey); |
172 | 2 | return ProposalAssembler.toProposalTypeInfos(proposalTypes); |
173 | |
} |
174 | |
|
175 | |
|
176 | |
|
177 | |
|
178 | |
@Override |
179 | |
@Transactional(readOnly=true) |
180 | |
public List<ProposalInfo> getProposalsByIdList(List<String> proposalIdList) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException { |
181 | 4 | checkForMissingParameter(proposalIdList, "proposalIdList"); |
182 | 2 | checkForEmptyList(proposalIdList, "proposalIdList"); |
183 | |
|
184 | 2 | List<Proposal> proposals = proposalDao.getProposalsByIdList(proposalIdList); |
185 | 2 | if (proposals.size() != proposalIdList.size()) { |
186 | 1 | throw new DoesNotExistException(); |
187 | |
} |
188 | 1 | return ProposalAssembler.toProposalInfos(proposals); |
189 | |
} |
190 | |
|
191 | |
|
192 | |
|
193 | |
|
194 | |
@Override |
195 | |
@Transactional(readOnly=true) |
196 | |
public List<ProposalInfo> getProposalsByProposalType(String proposalTypeKey) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException { |
197 | 3 | checkForMissingParameter(proposalTypeKey, "proposalTypeKey"); |
198 | |
|
199 | 2 | List<Proposal> proposals = proposalDao.getProposalsByProposalType(proposalTypeKey); |
200 | 2 | return ProposalAssembler.toProposalInfos(proposals); |
201 | |
} |
202 | |
|
203 | |
|
204 | |
|
205 | |
|
206 | |
@Override |
207 | |
@Transactional(readOnly=true) |
208 | |
public List<ProposalInfo> getProposalsByReference(String referenceTypeKey, String referenceId) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException { |
209 | 5 | checkForMissingParameter(referenceTypeKey, "referenceTypeKey"); |
210 | 4 | checkForMissingParameter(referenceId, "referenceId"); |
211 | |
|
212 | 3 | List<Proposal> proposals = proposalDao.getProposalsByReference(referenceTypeKey, referenceId); |
213 | 3 | return ProposalAssembler.toProposalInfos(proposals); |
214 | |
} |
215 | |
|
216 | |
|
217 | |
|
218 | |
|
219 | |
@Override |
220 | |
@Transactional(readOnly=true) |
221 | |
public List<ProposalInfo> getProposalsByState(String proposalState, String proposalTypeKey) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException { |
222 | 5 | checkForMissingParameter(proposalState, "proposalState"); |
223 | 4 | checkForMissingParameter(proposalTypeKey, "proposalTypeKey"); |
224 | |
|
225 | 3 | List<Proposal> proposals = proposalDao.getProposalsByState(proposalState, proposalTypeKey); |
226 | 3 | return ProposalAssembler.toProposalInfos(proposals); |
227 | |
} |
228 | |
|
229 | |
|
230 | |
|
231 | |
|
232 | |
@Override |
233 | |
@Transactional(readOnly=true) |
234 | |
public ProposalInfo getProposalByWorkflowId(String workflowId) |
235 | |
throws DoesNotExistException, InvalidParameterException, |
236 | |
MissingParameterException, OperationFailedException { |
237 | 0 | checkForMissingParameter(workflowId, "workflowId"); |
238 | |
|
239 | 0 | Proposal entity = proposalDao.getProposalByWorkflowId(workflowId); |
240 | 0 | return ProposalAssembler.toProposalInfo(entity); |
241 | |
} |
242 | |
|
243 | |
|
244 | |
|
245 | |
|
246 | |
@Override |
247 | |
@Transactional(readOnly=true) |
248 | |
public List<ReferenceTypeInfo> getReferenceTypes() throws OperationFailedException { |
249 | 1 | List<ProposalReferenceType> referenceTypes = proposalDao.find(ProposalReferenceType.class); |
250 | 1 | return ProposalAssembler.toReferenceTypeInfos(referenceTypes); |
251 | |
} |
252 | |
|
253 | |
|
254 | |
|
255 | |
|
256 | |
@Override |
257 | |
@Transactional(readOnly=false,noRollbackFor={DoesNotExistException.class},rollbackFor={Throwable.class}) |
258 | |
public ProposalInfo updateProposal(String proposalId, ProposalInfo proposalInfo) throws DataValidationErrorException, DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, VersionMismatchException { |
259 | 3 | checkForMissingParameter(proposalId, "proposalId"); |
260 | 3 | checkForMissingParameter(proposalInfo, "proposalInfo"); |
261 | |
|
262 | |
|
263 | 3 | List<ValidationResultInfo> validationResults = validateProposal("OBJECT", proposalInfo); |
264 | 3 | if (null != validationResults && validationResults.size() > 0) { |
265 | 0 | throw new DataValidationErrorException("Validation error!", validationResults); |
266 | |
} |
267 | |
|
268 | |
|
269 | 3 | proposalInfo.setId(proposalId); |
270 | 3 | if (proposalInfo.getProposerPerson() != null && !proposalInfo.getProposerPerson().isEmpty() && proposalInfo.getProposerOrg() != null && !proposalInfo.getProposerOrg().isEmpty()) { |
271 | 1 | throw new InvalidParameterException("Not allowed to have both Person and Organization propsers"); |
272 | |
} |
273 | |
|
274 | 2 | Proposal proposal = ProposalAssembler.toProposal(proposalInfo.getType(), proposalInfo, proposalDao); |
275 | 2 | Proposal updated = proposalDao.update(proposal); |
276 | |
|
277 | 2 | return ProposalAssembler.toProposalInfo(updated); |
278 | |
} |
279 | |
|
280 | |
|
281 | |
|
282 | |
|
283 | |
@Override |
284 | |
public List<ValidationResultInfo> validateProposal(String validationType, ProposalInfo proposalInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException { |
285 | 4 | checkForMissingParameter(validationType, "validationType"); |
286 | 4 | checkForMissingParameter(proposalInfo, "proposalInfo"); |
287 | |
|
288 | 4 | ObjectStructureDefinition objStructure = this.getObjectStructure(ProposalInfo.class.getName()); |
289 | 4 | Validator defaultValidator = validatorFactory.getValidator(); |
290 | 4 | List<ValidationResultInfo> validationResults = defaultValidator.validateObject(proposalInfo, objStructure); |
291 | 4 | return validationResults; |
292 | |
} |
293 | |
|
294 | |
|
295 | |
|
296 | |
|
297 | |
|
298 | |
|
299 | |
|
300 | |
|
301 | |
private void checkForMissingParameter(Object param, String paramName) |
302 | |
throws MissingParameterException { |
303 | 56 | if (param == null) { |
304 | 10 | throw new MissingParameterException(paramName + " can not be null"); |
305 | |
} |
306 | 46 | } |
307 | |
|
308 | |
|
309 | |
|
310 | |
|
311 | |
|
312 | |
|
313 | |
|
314 | |
private void checkForEmptyList(Object param, String paramName) |
315 | |
throws MissingParameterException { |
316 | 2 | if (param != null && param instanceof List<?> && ((List<?>)param).size() == 0) { |
317 | 0 | throw new MissingParameterException(paramName + " can not be an empty list"); |
318 | |
} |
319 | 2 | } |
320 | |
|
321 | |
public ProposalDao getProposalDao() { |
322 | 0 | return proposalDao; |
323 | |
} |
324 | |
|
325 | |
public void setProposalDao(ProposalDao dao) { |
326 | 1 | this.proposalDao = dao; |
327 | 1 | } |
328 | |
|
329 | |
|
330 | |
|
331 | |
|
332 | |
@Override |
333 | |
public ObjectStructureDefinition getObjectStructure(String objectTypeKey) { |
334 | 4 | return dictionaryServiceDelegate.getObjectStructure(objectTypeKey); |
335 | |
} |
336 | |
|
337 | |
|
338 | |
|
339 | |
|
340 | |
@Override |
341 | |
public List<String> getObjectTypes() { |
342 | 0 | return dictionaryServiceDelegate.getObjectTypes(); |
343 | |
} |
344 | |
|
345 | |
|
346 | |
|
347 | |
|
348 | |
@Override |
349 | |
public SearchCriteriaTypeInfo getSearchCriteriaType(String searchCriteriaTypeKey) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException { |
350 | 0 | checkForMissingParameter(searchCriteriaTypeKey, "searchCriteriaTypeKey"); |
351 | 0 | return searchManager.getSearchCriteriaType(searchCriteriaTypeKey); |
352 | |
} |
353 | |
|
354 | |
|
355 | |
|
356 | |
|
357 | |
@Override |
358 | |
public List<SearchCriteriaTypeInfo> getSearchCriteriaTypes() throws OperationFailedException { |
359 | 0 | return searchManager.getSearchCriteriaTypes(); |
360 | |
} |
361 | |
|
362 | |
|
363 | |
|
364 | |
|
365 | |
@Override |
366 | |
public SearchResultTypeInfo getSearchResultType(String searchResultTypeKey) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException { |
367 | 0 | checkForMissingParameter(searchResultTypeKey, "searchResultTypeKey"); |
368 | 0 | return searchManager.getSearchResultType(searchResultTypeKey); |
369 | |
} |
370 | |
|
371 | |
|
372 | |
|
373 | |
|
374 | |
@Override |
375 | |
public List<SearchResultTypeInfo> getSearchResultTypes() throws OperationFailedException { |
376 | 0 | return searchManager.getSearchResultTypes(); |
377 | |
} |
378 | |
|
379 | |
|
380 | |
|
381 | |
|
382 | |
@Override |
383 | |
public SearchTypeInfo getSearchType(String searchTypeKey) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException { |
384 | 0 | checkForMissingParameter(searchTypeKey, "searchTypeKey"); |
385 | 0 | return searchManager.getSearchType(searchTypeKey); |
386 | |
} |
387 | |
|
388 | |
|
389 | |
|
390 | |
|
391 | |
@Override |
392 | |
public List<SearchTypeInfo> getSearchTypes() throws OperationFailedException { |
393 | 0 | return searchManager.getSearchTypes(); |
394 | |
} |
395 | |
|
396 | |
|
397 | |
|
398 | |
|
399 | |
@Override |
400 | |
public List<SearchTypeInfo> getSearchTypesByCriteria(String searchCriteriaTypeKey) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException { |
401 | 0 | return searchManager.getSearchTypesByCriteria(searchCriteriaTypeKey); |
402 | |
} |
403 | |
|
404 | |
|
405 | |
|
406 | |
|
407 | |
@Override |
408 | |
public List<SearchTypeInfo> getSearchTypesByResult(String searchResultTypeKey) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException { |
409 | 0 | return searchManager.getSearchTypesByResult(searchResultTypeKey); |
410 | |
} |
411 | |
|
412 | |
@Override |
413 | |
public SearchResult search(SearchRequest searchRequest) throws MissingParameterException { |
414 | 1 | if("proposal.search.proposalsForReferenceIds".equals(searchRequest.getSearchKey())){ |
415 | 0 | return doSearchProposalsForReferenceIds(searchRequest); |
416 | |
}else{ |
417 | 1 | return searchManager.search(searchRequest, proposalDao); |
418 | |
} |
419 | |
} |
420 | |
|
421 | |
private SearchResult doSearchProposalsForReferenceIds( |
422 | |
SearchRequest searchRequest) { |
423 | |
|
424 | 0 | List<String> referenceIds = null; |
425 | 0 | for(SearchParam param: searchRequest.getParams()){ |
426 | 0 | if("proposal.queryParam.proposalOptionalReferenceIds".equals(param.getKey())){ |
427 | 0 | referenceIds = (List<String>) param.getValue(); |
428 | |
} |
429 | |
} |
430 | 0 | List<Proposal> proposals = proposalDao.getProposalsByRefernceIds(referenceIds); |
431 | 0 | SearchResult result = new SearchResult(); |
432 | 0 | for(Proposal proposal:proposals){ |
433 | 0 | for(ProposalReference reference:proposal.getProposalReference()){ |
434 | 0 | SearchResultRow row = new SearchResultRow(); |
435 | 0 | row.addCell("proposal.resultColumn.proposalId", proposal.getId()); |
436 | 0 | row.addCell("proposal.resultColumn.proposalOptionalName", proposal.getName()); |
437 | 0 | row.addCell("proposal.resultColumn.proposalOptionalReferenceId", reference.getObjectReferenceId()); |
438 | 0 | result.getRows().add(row); |
439 | 0 | } |
440 | |
} |
441 | 0 | return result; |
442 | |
} |
443 | |
|
444 | |
|
445 | |
|
446 | |
|
447 | |
public ValidatorFactory getValidatorFactory() { |
448 | 0 | return validatorFactory; |
449 | |
} |
450 | |
|
451 | |
|
452 | |
|
453 | |
|
454 | |
public void setValidatorFactory(ValidatorFactory validatorFactory) { |
455 | 1 | this.validatorFactory = validatorFactory; |
456 | 1 | } |
457 | |
|
458 | |
|
459 | |
|
460 | |
|
461 | |
public SearchManager getSearchManager() { |
462 | 0 | return searchManager; |
463 | |
} |
464 | |
|
465 | |
|
466 | |
|
467 | |
|
468 | |
public DictionaryService getDictionaryServiceDelegate() { |
469 | 0 | return dictionaryServiceDelegate; |
470 | |
} |
471 | |
|
472 | |
|
473 | |
} |