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