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