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 | 0 | 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 | 0 | this.searchManager = searchManager; |
74 | 0 | } |
75 | |
|
76 | |
public void setDictionaryServiceDelegate(DictionaryService dictionaryServiceDelegate) { |
77 | 0 | this.dictionaryServiceDelegate = dictionaryServiceDelegate; |
78 | 0 | } |
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | |
@Override |
84 | |
@Transactional(readOnly=false,noRollbackFor={DoesNotExistException.class},rollbackFor={Throwable.class}) |
85 | |
public ProposalInfo createProposal(String proposalTypeKey, ProposalInfo proposalInfo) throws AlreadyExistsException, DataValidationErrorException, DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
86 | 0 | checkForMissingParameter(proposalTypeKey, "proposalTypeKey"); |
87 | 0 | checkForMissingParameter(proposalInfo, "proposalInfo"); |
88 | |
|
89 | |
|
90 | 0 | List<ValidationResultInfo> validationResults = validateProposal("OBJECT", proposalInfo); |
91 | 0 | if (null != validationResults && validationResults.size() > 0) { |
92 | 0 | throw new DataValidationErrorException("Validation error!", validationResults); |
93 | |
} |
94 | |
|
95 | |
|
96 | 0 | 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 | 0 | Proposal proposal = ProposalAssembler.toProposal(proposalTypeKey, proposalInfo, proposalDao); |
101 | 0 | proposalDao.create(proposal); |
102 | |
|
103 | 0 | 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,noRollbackFor={DoesNotExistException.class},rollbackFor={Throwable.class}) |
115 | |
public StatusInfo deleteProposal(String proposalId) throws DoesNotExistException, InvalidParameterException, MissingParameterException, DependentObjectsExistException, OperationFailedException, PermissionDeniedException { |
116 | 0 | checkForMissingParameter(proposalId, "proposalId"); |
117 | |
|
118 | 0 | StatusInfo status = new StatusInfo(); |
119 | |
try { |
120 | 0 | proposalDao.delete(Proposal.class, proposalId); |
121 | 0 | } catch (DoesNotExistException e) { |
122 | 0 | status.setSuccess(false); |
123 | 0 | } |
124 | |
|
125 | 0 | return status; |
126 | |
} |
127 | |
|
128 | |
|
129 | |
|
130 | |
|
131 | |
|
132 | |
@Override |
133 | |
public ProposalInfo getProposal(String proposalId) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException { |
134 | 0 | checkForMissingParameter(proposalId, "proposalId"); |
135 | 0 | Proposal entity = proposalDao.fetch(Proposal.class, proposalId); |
136 | 0 | 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 | 0 | checkForMissingParameter(proposalTypeKey, "proposalTypeKey"); |
147 | |
|
148 | 0 | ProposalType proposalType = proposalDao.fetch(ProposalType.class, proposalTypeKey); |
149 | 0 | return ProposalAssembler.toProposalTypeInfo(proposalType); |
150 | |
} |
151 | |
|
152 | |
|
153 | |
|
154 | |
|
155 | |
@Override |
156 | |
public List<ProposalTypeInfo> getProposalTypes() throws OperationFailedException { |
157 | 0 | List<ProposalType> proposalTypes = proposalDao.find(ProposalType.class); |
158 | 0 | return ProposalAssembler.toProposalTypeInfos(proposalTypes); |
159 | |
} |
160 | |
|
161 | |
|
162 | |
|
163 | |
|
164 | |
@Override |
165 | |
public List<ProposalTypeInfo> getProposalTypesForReferenceType(String referenceTypeKey) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException { |
166 | 0 | checkForMissingParameter(referenceTypeKey, "referenceTypeKey"); |
167 | |
|
168 | 0 | List<ProposalType> proposalTypes = proposalDao.getProposalTypesForReferenceType(referenceTypeKey); |
169 | 0 | 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 | 0 | checkForMissingParameter(proposalIdList, "proposalIdList"); |
178 | 0 | checkForEmptyList(proposalIdList, "proposalIdList"); |
179 | |
|
180 | 0 | List<Proposal> proposals = proposalDao.getProposalsByIdList(proposalIdList); |
181 | 0 | if (proposals.size() != proposalIdList.size()) { |
182 | 0 | throw new DoesNotExistException(); |
183 | |
} |
184 | 0 | return ProposalAssembler.toProposalInfos(proposals); |
185 | |
} |
186 | |
|
187 | |
|
188 | |
|
189 | |
|
190 | |
@Override |
191 | |
public List<ProposalInfo> getProposalsByProposalType(String proposalTypeKey) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException { |
192 | 0 | checkForMissingParameter(proposalTypeKey, "proposalTypeKey"); |
193 | |
|
194 | 0 | List<Proposal> proposals = proposalDao.getProposalsByProposalType(proposalTypeKey); |
195 | 0 | 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 | 0 | checkForMissingParameter(referenceTypeKey, "referenceTypeKey"); |
204 | 0 | checkForMissingParameter(referenceId, "referenceId"); |
205 | |
|
206 | 0 | List<Proposal> proposals = proposalDao.getProposalsByReference(referenceTypeKey, referenceId); |
207 | 0 | 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 | 0 | checkForMissingParameter(proposalState, "proposalState"); |
216 | 0 | checkForMissingParameter(proposalTypeKey, "proposalTypeKey"); |
217 | |
|
218 | 0 | List<Proposal> proposals = proposalDao.getProposalsByState(proposalState, proposalTypeKey); |
219 | 0 | 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 | 0 | List<ProposalReferenceType> referenceTypes = proposalDao.find(ProposalReferenceType.class); |
241 | 0 | return ProposalAssembler.toReferenceTypeInfos(referenceTypes); |
242 | |
} |
243 | |
|
244 | |
|
245 | |
|
246 | |
|
247 | |
@Override |
248 | |
@Transactional(readOnly=false,noRollbackFor={DoesNotExistException.class},rollbackFor={Throwable.class}) |
249 | |
public ProposalInfo updateProposal(String proposalId, ProposalInfo proposalInfo) throws DataValidationErrorException, DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, VersionMismatchException { |
250 | 0 | checkForMissingParameter(proposalId, "proposalId"); |
251 | 0 | checkForMissingParameter(proposalInfo, "proposalInfo"); |
252 | |
|
253 | |
|
254 | 0 | List<ValidationResultInfo> validationResults = validateProposal("OBJECT", proposalInfo); |
255 | 0 | if (null != validationResults && validationResults.size() > 0) { |
256 | 0 | throw new DataValidationErrorException("Validation error!", validationResults); |
257 | |
} |
258 | |
|
259 | |
|
260 | 0 | proposalInfo.setId(proposalId); |
261 | 0 | if (proposalInfo.getProposerPerson() != null && !proposalInfo.getProposerPerson().isEmpty() && proposalInfo.getProposerOrg() != null && !proposalInfo.getProposerOrg().isEmpty()) { |
262 | 0 | throw new InvalidParameterException("Not allowed to have both Person and Organization propsers"); |
263 | |
} |
264 | |
|
265 | 0 | Proposal proposal = ProposalAssembler.toProposal(proposalInfo.getType(), proposalInfo, proposalDao); |
266 | 0 | Proposal updated = proposalDao.update(proposal); |
267 | |
|
268 | 0 | 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 | 0 | checkForMissingParameter(validationType, "validationType"); |
277 | 0 | checkForMissingParameter(proposalInfo, "proposalInfo"); |
278 | |
|
279 | 0 | ObjectStructureDefinition objStructure = this.getObjectStructure(ProposalInfo.class.getName()); |
280 | 0 | Validator defaultValidator = validatorFactory.getValidator(); |
281 | 0 | List<ValidationResultInfo> validationResults = defaultValidator.validateObject(proposalInfo, objStructure); |
282 | 0 | return validationResults; |
283 | |
} |
284 | |
|
285 | |
|
286 | |
|
287 | |
|
288 | |
|
289 | |
|
290 | |
|
291 | |
|
292 | |
private void checkForMissingParameter(Object param, String paramName) |
293 | |
throws MissingParameterException { |
294 | 0 | if (param == null) { |
295 | 0 | throw new MissingParameterException(paramName + " can not be null"); |
296 | |
} |
297 | 0 | } |
298 | |
|
299 | |
|
300 | |
|
301 | |
|
302 | |
|
303 | |
|
304 | |
|
305 | |
private void checkForEmptyList(Object param, String paramName) |
306 | |
throws MissingParameterException { |
307 | 0 | if (param != null && param instanceof List<?> && ((List<?>)param).size() == 0) { |
308 | 0 | throw new MissingParameterException(paramName + " can not be an empty list"); |
309 | |
} |
310 | 0 | } |
311 | |
|
312 | |
public ProposalDao getProposalDao() { |
313 | 0 | return proposalDao; |
314 | |
} |
315 | |
|
316 | |
public void setProposalDao(ProposalDao dao) { |
317 | 0 | this.proposalDao = dao; |
318 | 0 | } |
319 | |
|
320 | |
|
321 | |
|
322 | |
|
323 | |
@Override |
324 | |
public ObjectStructureDefinition getObjectStructure(String objectTypeKey) { |
325 | 0 | 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 | 0 | if("proposal.search.proposalsForReferenceIds".equals(searchRequest.getSearchKey())){ |
406 | 0 | return doSearchProposalsForReferenceIds(searchRequest); |
407 | |
}else{ |
408 | 0 | 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 | 0 | this.validatorFactory = validatorFactory; |
447 | 0 | } |
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 | |
} |