Coverage Report - org.kuali.student.core.proposal.service.impl.ProposalServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
ProposalServiceImpl
75%
77/102
58%
20/34
1.8
 
 1  
 /**
 2  
  * Copyright 2010 The Kuali Foundation Licensed under the
 3  
  * Educational Community License, Version 2.0 (the "License"); you may
 4  
  * not use this file except in compliance with the License. You may
 5  
  * obtain a copy of the License at
 6  
  *
 7  
  * http://www.osedu.org/licenses/ECL-2.0
 8  
  *
 9  
  * Unless required by applicable law or agreed to in writing,
 10  
  * software distributed under the License is distributed on an "AS IS"
 11  
  * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 12  
  * or implied. See the License for the specific language governing
 13  
  * permissions and limitations under the License.
 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  
  * Implementation of the Proposal Service
 55  
  *
 56  
  * @author Kuali Rice Team (kuali-rice@googlegroups.com)
 57  
  *
 58  
  * @See <a href="https://test.kuali.org/confluence/display/KULSTU/Proposal+Service">ProposalService</>
 59  
  */
 60  
 @WebService(endpointInterface = "org.kuali.student.core.proposal.service.ProposalService", serviceName = "ProposalService", portName = "ProposalService", targetNamespace = "http://student.kuali.org/wsdl/proposal")
 61  
 @Transactional(noRollbackFor={DoesNotExistException.class},rollbackFor={Throwable.class})
 62  2
 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  1
         this.searchManager = searchManager;
 71  1
     }
 72  
 
 73  
     public void setDictionaryServiceDelegate(DictionaryService dictionaryServiceDelegate) {
 74  1
         this.dictionaryServiceDelegate = dictionaryServiceDelegate;
 75  1
     }
 76  
 
 77  
     /**
 78  
      * @see org.kuali.student.core.proposal.service.ProposalService#createProposal(java.lang.String, org.kuali.student.core.proposal.dto.ProposalInfo)
 79  
      */
 80  
     @Override
 81  
     public ProposalInfo createProposal(String proposalTypeKey, ProposalInfo proposalInfo) throws AlreadyExistsException, DataValidationErrorException, DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 82  1
         checkForMissingParameter(proposalTypeKey, "proposalTypeKey");
 83  1
         checkForMissingParameter(proposalInfo, "proposalInfo");
 84  
 
 85  
         // Validate
 86  1
         List<ValidationResultInfo> validationResults = validateProposal("OBJECT", proposalInfo);
 87  1
         if (null != validationResults && validationResults.size() > 0) {
 88  0
             throw new DataValidationErrorException("Validation error!", validationResults);
 89  
         }
 90  
         
 91  
         
 92  1
         if (proposalInfo.getProposerPerson() != null && !proposalInfo.getProposerPerson().isEmpty() && proposalInfo.getProposerOrg() != null && !proposalInfo.getProposerOrg().isEmpty()) {
 93  0
             throw new InvalidParameterException("Not allowed to have both Person and Organization propsers");
 94  
         }
 95  
        try {
 96  1
            Proposal proposal = ProposalAssembler.toProposal(proposalTypeKey, proposalInfo, proposalDao);
 97  1
            proposalDao.create(proposal);
 98  
 
 99  1
            return ProposalAssembler.toProposalInfo(proposal);
 100  0
        } catch (VersionMismatchException e) {
 101  0
            throw new InvalidParameterException(e.getMessage());
 102  
        }
 103  
 
 104  
     }
 105  
 
 106  
     /**
 107  
      * @see org.kuali.student.core.proposal.service.ProposalService#deleteProposal(java.lang.String)
 108  
      */
 109  
     @Override
 110  
     public StatusInfo deleteProposal(String proposalId) throws DoesNotExistException, InvalidParameterException, MissingParameterException, DependentObjectsExistException, OperationFailedException, PermissionDeniedException {
 111  2
         checkForMissingParameter(proposalId, "proposalId");
 112  
 
 113  2
         StatusInfo status = new StatusInfo();
 114  
         try {
 115  2
             proposalDao.delete(Proposal.class, proposalId);
 116  1
         } catch (DoesNotExistException e) {
 117  1
             status.setSuccess(false);
 118  1
         }
 119  
 
 120  2
         return status;
 121  
     }
 122  
 
 123  
 
 124  
     /**
 125  
      * @see org.kuali.student.core.proposal.service.ProposalService#getProposal(java.lang.String)
 126  
      */
 127  
     @Override
 128  
     public ProposalInfo getProposal(String proposalId) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException {
 129  7
         checkForMissingParameter(proposalId, "proposalId");
 130  6
         Proposal entity = proposalDao.fetch(Proposal.class, proposalId);
 131  4
         return ProposalAssembler.toProposalInfo(entity);
 132  
     }
 133  
 
 134  
     /**
 135  
      * This overridden method ...
 136  
      *
 137  
      * @see org.kuali.student.core.proposal.service.ProposalService#getProposalType(java.lang.String)
 138  
      */
 139  
     @Override
 140  
     public ProposalTypeInfo getProposalType(String proposalTypeKey) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException {
 141  3
         checkForMissingParameter(proposalTypeKey, "proposalTypeKey");
 142  
 
 143  2
         ProposalType proposalType = proposalDao.fetch(ProposalType.class, proposalTypeKey);
 144  1
         return ProposalAssembler.toProposalTypeInfo(proposalType);
 145  
     }
 146  
 
 147  
     /**
 148  
      * @see org.kuali.student.core.proposal.service.ProposalService#getProposalTypes()
 149  
      */
 150  
     @Override
 151  
     public List<ProposalTypeInfo> getProposalTypes() throws OperationFailedException {
 152  1
         List<ProposalType> proposalTypes = proposalDao.find(ProposalType.class);
 153  1
         return ProposalAssembler.toProposalTypeInfos(proposalTypes);
 154  
     }
 155  
 
 156  
     /**
 157  
      * @see org.kuali.student.core.proposal.service.ProposalService#getProposalTypesForReferenceType(java.lang.String)
 158  
      */
 159  
     @Override
 160  
     public List<ProposalTypeInfo> getProposalTypesForReferenceType(String referenceTypeKey) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException {
 161  3
         checkForMissingParameter(referenceTypeKey, "referenceTypeKey");
 162  
 
 163  2
         List<ProposalType> proposalTypes = proposalDao.getProposalTypesForReferenceType(referenceTypeKey);
 164  2
         return ProposalAssembler.toProposalTypeInfos(proposalTypes);
 165  
     }
 166  
 
 167  
     /**
 168  
      * @see org.kuali.student.core.proposal.service.ProposalService#getProposalsByIdList(java.util.List)
 169  
      */
 170  
     @Override
 171  
     public List<ProposalInfo> getProposalsByIdList(List<String> proposalIdList) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException {
 172  4
         checkForMissingParameter(proposalIdList, "proposalIdList");
 173  2
         checkForEmptyList(proposalIdList, "proposalIdList");
 174  
 
 175  2
         List<Proposal> proposals = proposalDao.getProposalsByIdList(proposalIdList);
 176  2
         if (proposals.size() != proposalIdList.size()) {
 177  1
             throw new DoesNotExistException();
 178  
         }
 179  1
         return ProposalAssembler.toProposalInfos(proposals);
 180  
     }
 181  
 
 182  
     /**
 183  
      * @see org.kuali.student.core.proposal.service.ProposalService#getProposalsByProposalType(java.lang.String)
 184  
      */
 185  
     @Override
 186  
     public List<ProposalInfo> getProposalsByProposalType(String proposalTypeKey) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException {
 187  3
         checkForMissingParameter(proposalTypeKey, "proposalTypeKey");
 188  
 
 189  2
         List<Proposal> proposals = proposalDao.getProposalsByProposalType(proposalTypeKey);
 190  2
         return ProposalAssembler.toProposalInfos(proposals);
 191  
     }
 192  
 
 193  
     /**
 194  
      * @see org.kuali.student.core.proposal.service.ProposalService#getProposalsByReference(java.lang.String, java.lang.String)
 195  
      */
 196  
     @Override
 197  
     public List<ProposalInfo> getProposalsByReference(String referenceTypeKey, String referenceId) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException {
 198  5
         checkForMissingParameter(referenceTypeKey, "referenceTypeKey");
 199  4
         checkForMissingParameter(referenceId, "referenceId");
 200  
 
 201  3
         List<Proposal> proposals = proposalDao.getProposalsByReference(referenceTypeKey, referenceId);
 202  3
         return ProposalAssembler.toProposalInfos(proposals);
 203  
     }
 204  
 
 205  
     /**
 206  
      * @see org.kuali.student.core.proposal.service.ProposalService#getProposalsByState(java.lang.String, java.lang.String)
 207  
      */
 208  
     @Override
 209  
     public List<ProposalInfo> getProposalsByState(String proposalState, String proposalTypeKey) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException {
 210  5
         checkForMissingParameter(proposalState, "proposalState");
 211  4
         checkForMissingParameter(proposalTypeKey, "proposalTypeKey");
 212  
 
 213  3
         List<Proposal> proposals = proposalDao.getProposalsByState(proposalState, proposalTypeKey);
 214  3
         return ProposalAssembler.toProposalInfos(proposals);
 215  
     }
 216  
 
 217  
     /**
 218  
      * @see org.kuali.student.core.proposal.service.ProposalService#getProposalByWorkflowId()
 219  
      */
 220  
         @Override
 221  
         public ProposalInfo getProposalByWorkflowId(String workflowId)
 222  
                         throws DoesNotExistException, InvalidParameterException,
 223  
                         MissingParameterException, OperationFailedException {
 224  0
                 checkForMissingParameter(workflowId, "workflowId");
 225  
                 
 226  0
         Proposal entity = proposalDao.getProposalByWorkflowId(workflowId);
 227  0
         return ProposalAssembler.toProposalInfo(entity);
 228  
         }
 229  
 
 230  
     /**
 231  
      * @see org.kuali.student.core.proposal.service.ProposalService#getReferenceTypes()
 232  
      */
 233  
     @Override
 234  
     public List<ReferenceTypeInfo> getReferenceTypes() throws OperationFailedException {
 235  1
         List<ProposalReferenceType> referenceTypes = proposalDao.find(ProposalReferenceType.class);
 236  1
         return ProposalAssembler.toReferenceTypeInfos(referenceTypes);
 237  
     }
 238  
 
 239  
     /**
 240  
      * @see org.kuali.student.core.proposal.service.ProposalService#updateProposal(java.lang.String, org.kuali.student.core.proposal.dto.ProposalInfo)
 241  
      */
 242  
     @Override
 243  
     public ProposalInfo updateProposal(String proposalId, ProposalInfo proposalInfo) throws DataValidationErrorException, DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, VersionMismatchException {
 244  3
         checkForMissingParameter(proposalId, "proposalId");
 245  3
         checkForMissingParameter(proposalInfo, "proposalInfo");
 246  
 
 247  
         // Validate
 248  3
         List<ValidationResultInfo> validationResults = validateProposal("OBJECT", proposalInfo);
 249  3
         if (null != validationResults && validationResults.size() > 0) {
 250  0
             throw new DataValidationErrorException("Validation error!", validationResults);
 251  
         }
 252  
         
 253  
         
 254  3
         proposalInfo.setId(proposalId);
 255  3
         if (proposalInfo.getProposerPerson() != null && !proposalInfo.getProposerPerson().isEmpty() && proposalInfo.getProposerOrg() != null && !proposalInfo.getProposerOrg().isEmpty()) {
 256  1
             throw new InvalidParameterException("Not allowed to have both Person and Organization propsers");
 257  
         }
 258  
 
 259  2
         Proposal proposal = ProposalAssembler.toProposal(proposalInfo.getType(), proposalInfo, proposalDao);
 260  2
         Proposal updated = proposalDao.update(proposal);
 261  
 
 262  2
         return ProposalAssembler.toProposalInfo(updated);
 263  
     }
 264  
 
 265  
     /**
 266  
      * @see org.kuali.student.core.proposal.service.ProposalService#validateProposal(java.lang.String, org.kuali.student.core.proposal.dto.ProposalInfo)
 267  
      */
 268  
     @Override
 269  
     public List<ValidationResultInfo> validateProposal(String validationType, ProposalInfo proposalInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException {
 270  4
         checkForMissingParameter(validationType, "validationType");
 271  4
         checkForMissingParameter(proposalInfo, "proposalInfo");
 272  
 
 273  4
         ObjectStructureDefinition objStructure = this.getObjectStructure(ProposalInfo.class.getName());
 274  4
         Validator defaultValidator = validatorFactory.getValidator();
 275  4
         List<ValidationResultInfo> validationResults = defaultValidator.validateObject(proposalInfo, objStructure);
 276  4
         return validationResults;         
 277  
     }
 278  
 
 279  
     /**
 280  
      * Check for missing parameter and thow localized exception if missing
 281  
      *
 282  
      * @param param
 283  
      * @param parameter name
 284  
      * @throws MissingParameterException
 285  
      */
 286  
     private void checkForMissingParameter(Object param, String paramName)
 287  
             throws MissingParameterException {
 288  56
         if (param == null) {
 289  10
             throw new MissingParameterException(paramName + " can not be null");
 290  
         }
 291  46
     }
 292  
 
 293  
     /**
 294  
      * Check for an empty list
 295  
      * @param param
 296  
      * @param paramName
 297  
      * @throws MissingParameterException
 298  
      */
 299  
     private void checkForEmptyList(Object param, String paramName)
 300  
             throws MissingParameterException {
 301  2
         if (param != null && param instanceof List<?> && ((List<?>)param).size() == 0) {
 302  0
             throw new MissingParameterException(paramName + " can not be an empty list");
 303  
         }
 304  2
     }
 305  
 
 306  
     public ProposalDao getProposalDao() {
 307  0
         return proposalDao;
 308  
     }
 309  
 
 310  
     public void setProposalDao(ProposalDao dao) {
 311  1
         this.proposalDao = dao;
 312  1
     }
 313  
 
 314  
     /**
 315  
      * @see org.kuali.student.core.dictionary.service.old.DictionaryService#getObjectStructure(java.lang.String)
 316  
      */
 317  
     @Override
 318  
     public ObjectStructureDefinition getObjectStructure(String objectTypeKey) {
 319  4
         return dictionaryServiceDelegate.getObjectStructure(objectTypeKey);
 320  
     }
 321  
 
 322  
     /**
 323  
      * @see org.kuali.student.core.dictionary.service.old.DictionaryService#getObjectTypes()
 324  
      */
 325  
     @Override
 326  
     public List<String> getObjectTypes() {
 327  0
         return dictionaryServiceDelegate.getObjectTypes();
 328  
     }
 329  
 
 330  
     /**
 331  
      * @see org.kuali.student.core.search.service.SearchService#getSearchCriteriaType(java.lang.String)
 332  
      */
 333  
     @Override
 334  
     public SearchCriteriaTypeInfo getSearchCriteriaType(String searchCriteriaTypeKey) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException {
 335  0
         checkForMissingParameter(searchCriteriaTypeKey, "searchCriteriaTypeKey");
 336  0
         return searchManager.getSearchCriteriaType(searchCriteriaTypeKey);
 337  
     }
 338  
 
 339  
     /**
 340  
      * @see org.kuali.student.core.search.service.SearchService#getSearchCriteriaTypes()
 341  
      */
 342  
     @Override
 343  
     public List<SearchCriteriaTypeInfo> getSearchCriteriaTypes() throws OperationFailedException {
 344  0
         return searchManager.getSearchCriteriaTypes();
 345  
     }
 346  
 
 347  
     /**
 348  
      * @see org.kuali.student.core.search.service.SearchService#getSearchResultType(java.lang.String)
 349  
      */
 350  
     @Override
 351  
     public SearchResultTypeInfo getSearchResultType(String searchResultTypeKey) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException {
 352  0
         checkForMissingParameter(searchResultTypeKey, "searchResultTypeKey");
 353  0
         return searchManager.getSearchResultType(searchResultTypeKey);
 354  
     }
 355  
 
 356  
     /**
 357  
      * @see org.kuali.student.core.search.service.SearchService#getSearchResultTypes()
 358  
      */
 359  
     @Override
 360  
     public List<SearchResultTypeInfo> getSearchResultTypes() throws OperationFailedException {
 361  0
         return searchManager.getSearchResultTypes();
 362  
     }
 363  
 
 364  
     /**
 365  
      * @see org.kuali.student.core.search.service.SearchService#getSearchType(java.lang.String)
 366  
      */
 367  
     @Override
 368  
     public SearchTypeInfo getSearchType(String searchTypeKey) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException {
 369  0
         checkForMissingParameter(searchTypeKey, "searchTypeKey");
 370  0
         return searchManager.getSearchType(searchTypeKey);    
 371  
     }
 372  
 
 373  
     /**
 374  
      * @see org.kuali.student.core.search.service.SearchService#getSearchTypes()
 375  
      */
 376  
     @Override
 377  
     public List<SearchTypeInfo> getSearchTypes() throws OperationFailedException {
 378  0
         return searchManager.getSearchTypes();
 379  
     }
 380  
 
 381  
     /**
 382  
      * @see org.kuali.student.core.search.service.SearchService#getSearchTypesByCriteria(java.lang.String)
 383  
      */
 384  
     @Override
 385  
     public List<SearchTypeInfo> getSearchTypesByCriteria(String searchCriteriaTypeKey) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException {
 386  0
         return searchManager.getSearchTypesByCriteria(searchCriteriaTypeKey);
 387  
     }
 388  
 
 389  
     /**
 390  
      * @see org.kuali.student.core.search.service.SearchService#getSearchTypesByResult(java.lang.String)
 391  
      */
 392  
     @Override
 393  
     public List<SearchTypeInfo> getSearchTypesByResult(String searchResultTypeKey) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException {
 394  0
         return searchManager.getSearchTypesByResult(searchResultTypeKey);
 395  
     }
 396  
 
 397  
         @Override
 398  
         public SearchResult search(SearchRequest searchRequest) throws MissingParameterException {
 399  1
                 return searchManager.search(searchRequest, proposalDao);
 400  
         }
 401  
 
 402  
     /**
 403  
      * @return the validatorFactory
 404  
      */
 405  
     public ValidatorFactory getValidatorFactory() {
 406  0
         return validatorFactory;
 407  
     }
 408  
 
 409  
     /**
 410  
      * @param validatorFactory the validatorFactory to set
 411  
      */
 412  
     public void setValidatorFactory(ValidatorFactory validatorFactory) {
 413  1
         this.validatorFactory = validatorFactory;
 414  1
     }
 415  
 
 416  
     /**
 417  
      * @return the searchManager
 418  
      */
 419  
     public SearchManager getSearchManager() {
 420  0
         return searchManager;
 421  
     }
 422  
 
 423  
     /**
 424  
      * @return the dictionaryServiceDelegate
 425  
      */
 426  
     public DictionaryService getDictionaryServiceDelegate() {
 427  0
         return dictionaryServiceDelegate;
 428  
     }
 429  
 
 430  
         
 431  
 }