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(readOnly=true,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  
     @Transactional(readOnly=false)
 82  
         public ProposalInfo createProposal(String proposalTypeKey, ProposalInfo proposalInfo) throws AlreadyExistsException, DataValidationErrorException, DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 83  1
         checkForMissingParameter(proposalTypeKey, "proposalTypeKey");
 84  1
         checkForMissingParameter(proposalInfo, "proposalInfo");
 85  
 
 86  
         // Validate
 87  1
         List<ValidationResultInfo> validationResults = validateProposal("OBJECT", proposalInfo);
 88  1
         if (null != validationResults && validationResults.size() > 0) {
 89  0
             throw new DataValidationErrorException("Validation error!", validationResults);
 90  
         }
 91  
         
 92  
         
 93  1
         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  1
            Proposal proposal = ProposalAssembler.toProposal(proposalTypeKey, proposalInfo, proposalDao);
 98  1
            proposalDao.create(proposal);
 99  
 
 100  1
            return ProposalAssembler.toProposalInfo(proposal);
 101  0
        } catch (VersionMismatchException e) {
 102  0
            throw new InvalidParameterException(e.getMessage());
 103  
        }
 104  
 
 105  
     }
 106  
 
 107  
     /**
 108  
      * @see org.kuali.student.core.proposal.service.ProposalService#deleteProposal(java.lang.String)
 109  
      */
 110  
     @Override
 111  
     @Transactional(readOnly=false)
 112  
         public StatusInfo deleteProposal(String proposalId) throws DoesNotExistException, InvalidParameterException, MissingParameterException, DependentObjectsExistException, OperationFailedException, PermissionDeniedException {
 113  2
         checkForMissingParameter(proposalId, "proposalId");
 114  
 
 115  2
         StatusInfo status = new StatusInfo();
 116  
         try {
 117  2
             proposalDao.delete(Proposal.class, proposalId);
 118  1
         } catch (DoesNotExistException e) {
 119  1
             status.setSuccess(false);
 120  1
         }
 121  
 
 122  2
         return status;
 123  
     }
 124  
 
 125  
 
 126  
     /**
 127  
      * @see org.kuali.student.core.proposal.service.ProposalService#getProposal(java.lang.String)
 128  
      */
 129  
     @Override
 130  
     public ProposalInfo getProposal(String proposalId) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException {
 131  7
         checkForMissingParameter(proposalId, "proposalId");
 132  6
         Proposal entity = proposalDao.fetch(Proposal.class, proposalId);
 133  4
         return ProposalAssembler.toProposalInfo(entity);
 134  
     }
 135  
 
 136  
     /**
 137  
      * This overridden method ...
 138  
      *
 139  
      * @see org.kuali.student.core.proposal.service.ProposalService#getProposalType(java.lang.String)
 140  
      */
 141  
     @Override
 142  
     public ProposalTypeInfo getProposalType(String proposalTypeKey) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException {
 143  3
         checkForMissingParameter(proposalTypeKey, "proposalTypeKey");
 144  
 
 145  2
         ProposalType proposalType = proposalDao.fetch(ProposalType.class, proposalTypeKey);
 146  1
         return ProposalAssembler.toProposalTypeInfo(proposalType);
 147  
     }
 148  
 
 149  
     /**
 150  
      * @see org.kuali.student.core.proposal.service.ProposalService#getProposalTypes()
 151  
      */
 152  
     @Override
 153  
     public List<ProposalTypeInfo> getProposalTypes() throws OperationFailedException {
 154  1
         List<ProposalType> proposalTypes = proposalDao.find(ProposalType.class);
 155  1
         return ProposalAssembler.toProposalTypeInfos(proposalTypes);
 156  
     }
 157  
 
 158  
     /**
 159  
      * @see org.kuali.student.core.proposal.service.ProposalService#getProposalTypesForReferenceType(java.lang.String)
 160  
      */
 161  
     @Override
 162  
     public List<ProposalTypeInfo> getProposalTypesForReferenceType(String referenceTypeKey) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException {
 163  3
         checkForMissingParameter(referenceTypeKey, "referenceTypeKey");
 164  
 
 165  2
         List<ProposalType> proposalTypes = proposalDao.getProposalTypesForReferenceType(referenceTypeKey);
 166  2
         return ProposalAssembler.toProposalTypeInfos(proposalTypes);
 167  
     }
 168  
 
 169  
     /**
 170  
      * @see org.kuali.student.core.proposal.service.ProposalService#getProposalsByIdList(java.util.List)
 171  
      */
 172  
     @Override
 173  
     public List<ProposalInfo> getProposalsByIdList(List<String> proposalIdList) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException {
 174  4
         checkForMissingParameter(proposalIdList, "proposalIdList");
 175  2
         checkForEmptyList(proposalIdList, "proposalIdList");
 176  
 
 177  2
         List<Proposal> proposals = proposalDao.getProposalsByIdList(proposalIdList);
 178  2
         if (proposals.size() != proposalIdList.size()) {
 179  1
             throw new DoesNotExistException();
 180  
         }
 181  1
         return ProposalAssembler.toProposalInfos(proposals);
 182  
     }
 183  
 
 184  
     /**
 185  
      * @see org.kuali.student.core.proposal.service.ProposalService#getProposalsByProposalType(java.lang.String)
 186  
      */
 187  
     @Override
 188  
     public List<ProposalInfo> getProposalsByProposalType(String proposalTypeKey) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException {
 189  3
         checkForMissingParameter(proposalTypeKey, "proposalTypeKey");
 190  
 
 191  2
         List<Proposal> proposals = proposalDao.getProposalsByProposalType(proposalTypeKey);
 192  2
         return ProposalAssembler.toProposalInfos(proposals);
 193  
     }
 194  
 
 195  
     /**
 196  
      * @see org.kuali.student.core.proposal.service.ProposalService#getProposalsByReference(java.lang.String, java.lang.String)
 197  
      */
 198  
     @Override
 199  
     public List<ProposalInfo> getProposalsByReference(String referenceTypeKey, String referenceId) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException {
 200  5
         checkForMissingParameter(referenceTypeKey, "referenceTypeKey");
 201  4
         checkForMissingParameter(referenceId, "referenceId");
 202  
 
 203  3
         List<Proposal> proposals = proposalDao.getProposalsByReference(referenceTypeKey, referenceId);
 204  3
         return ProposalAssembler.toProposalInfos(proposals);
 205  
     }
 206  
 
 207  
     /**
 208  
      * @see org.kuali.student.core.proposal.service.ProposalService#getProposalsByState(java.lang.String, java.lang.String)
 209  
      */
 210  
     @Override
 211  
     public List<ProposalInfo> getProposalsByState(String proposalState, String proposalTypeKey) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException {
 212  5
         checkForMissingParameter(proposalState, "proposalState");
 213  4
         checkForMissingParameter(proposalTypeKey, "proposalTypeKey");
 214  
 
 215  3
         List<Proposal> proposals = proposalDao.getProposalsByState(proposalState, proposalTypeKey);
 216  3
         return ProposalAssembler.toProposalInfos(proposals);
 217  
     }
 218  
 
 219  
     /**
 220  
      * @see org.kuali.student.core.proposal.service.ProposalService#getProposalByWorkflowId()
 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  
      * @see org.kuali.student.core.proposal.service.ProposalService#getReferenceTypes()
 234  
      */
 235  
     @Override
 236  
     public List<ReferenceTypeInfo> getReferenceTypes() throws OperationFailedException {
 237  1
         List<ProposalReferenceType> referenceTypes = proposalDao.find(ProposalReferenceType.class);
 238  1
         return ProposalAssembler.toReferenceTypeInfos(referenceTypes);
 239  
     }
 240  
 
 241  
     /**
 242  
      * @see org.kuali.student.core.proposal.service.ProposalService#updateProposal(java.lang.String, org.kuali.student.core.proposal.dto.ProposalInfo)
 243  
      */
 244  
     @Override
 245  
     @Transactional(readOnly=false)
 246  
         public ProposalInfo updateProposal(String proposalId, ProposalInfo proposalInfo) throws DataValidationErrorException, DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, VersionMismatchException {
 247  3
         checkForMissingParameter(proposalId, "proposalId");
 248  3
         checkForMissingParameter(proposalInfo, "proposalInfo");
 249  
 
 250  
         // Validate
 251  3
         List<ValidationResultInfo> validationResults = validateProposal("OBJECT", proposalInfo);
 252  3
         if (null != validationResults && validationResults.size() > 0) {
 253  0
             throw new DataValidationErrorException("Validation error!", validationResults);
 254  
         }
 255  
         
 256  
         
 257  3
         proposalInfo.setId(proposalId);
 258  3
         if (proposalInfo.getProposerPerson() != null && !proposalInfo.getProposerPerson().isEmpty() && proposalInfo.getProposerOrg() != null && !proposalInfo.getProposerOrg().isEmpty()) {
 259  1
             throw new InvalidParameterException("Not allowed to have both Person and Organization propsers");
 260  
         }
 261  
 
 262  2
         Proposal proposal = ProposalAssembler.toProposal(proposalInfo.getType(), proposalInfo, proposalDao);
 263  2
         Proposal updated = proposalDao.update(proposal);
 264  
 
 265  2
         return ProposalAssembler.toProposalInfo(updated);
 266  
     }
 267  
 
 268  
     /**
 269  
      * @see org.kuali.student.core.proposal.service.ProposalService#validateProposal(java.lang.String, org.kuali.student.core.proposal.dto.ProposalInfo)
 270  
      */
 271  
     @Override
 272  
     public List<ValidationResultInfo> validateProposal(String validationType, ProposalInfo proposalInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException {
 273  4
         checkForMissingParameter(validationType, "validationType");
 274  4
         checkForMissingParameter(proposalInfo, "proposalInfo");
 275  
 
 276  4
         ObjectStructureDefinition objStructure = this.getObjectStructure(ProposalInfo.class.getName());
 277  4
         Validator defaultValidator = validatorFactory.getValidator();
 278  4
         List<ValidationResultInfo> validationResults = defaultValidator.validateObject(proposalInfo, objStructure);
 279  4
         return validationResults;         
 280  
     }
 281  
 
 282  
     /**
 283  
      * Check for missing parameter and thow localized exception if missing
 284  
      *
 285  
      * @param param
 286  
      * @param parameter name
 287  
      * @throws MissingParameterException
 288  
      */
 289  
     private void checkForMissingParameter(Object param, String paramName)
 290  
             throws MissingParameterException {
 291  56
         if (param == null) {
 292  10
             throw new MissingParameterException(paramName + " can not be null");
 293  
         }
 294  46
     }
 295  
 
 296  
     /**
 297  
      * Check for an empty list
 298  
      * @param param
 299  
      * @param paramName
 300  
      * @throws MissingParameterException
 301  
      */
 302  
     private void checkForEmptyList(Object param, String paramName)
 303  
             throws MissingParameterException {
 304  2
         if (param != null && param instanceof List<?> && ((List<?>)param).size() == 0) {
 305  0
             throw new MissingParameterException(paramName + " can not be an empty list");
 306  
         }
 307  2
     }
 308  
 
 309  
     public ProposalDao getProposalDao() {
 310  0
         return proposalDao;
 311  
     }
 312  
 
 313  
     public void setProposalDao(ProposalDao dao) {
 314  1
         this.proposalDao = dao;
 315  1
     }
 316  
 
 317  
     /**
 318  
      * @see org.kuali.student.core.dictionary.service.old.DictionaryService#getObjectStructure(java.lang.String)
 319  
      */
 320  
     @Override
 321  
     public ObjectStructureDefinition getObjectStructure(String objectTypeKey) {
 322  4
         return dictionaryServiceDelegate.getObjectStructure(objectTypeKey);
 323  
     }
 324  
 
 325  
     /**
 326  
      * @see org.kuali.student.core.dictionary.service.old.DictionaryService#getObjectTypes()
 327  
      */
 328  
     @Override
 329  
     public List<String> getObjectTypes() {
 330  0
         return dictionaryServiceDelegate.getObjectTypes();
 331  
     }
 332  
 
 333  
     /**
 334  
      * @see org.kuali.student.core.search.service.SearchService#getSearchCriteriaType(java.lang.String)
 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  
      * @see org.kuali.student.core.search.service.SearchService#getSearchCriteriaTypes()
 344  
      */
 345  
     @Override
 346  
     public List<SearchCriteriaTypeInfo> getSearchCriteriaTypes() throws OperationFailedException {
 347  0
         return searchManager.getSearchCriteriaTypes();
 348  
     }
 349  
 
 350  
     /**
 351  
      * @see org.kuali.student.core.search.service.SearchService#getSearchResultType(java.lang.String)
 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  
      * @see org.kuali.student.core.search.service.SearchService#getSearchResultTypes()
 361  
      */
 362  
     @Override
 363  
     public List<SearchResultTypeInfo> getSearchResultTypes() throws OperationFailedException {
 364  0
         return searchManager.getSearchResultTypes();
 365  
     }
 366  
 
 367  
     /**
 368  
      * @see org.kuali.student.core.search.service.SearchService#getSearchType(java.lang.String)
 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  
      * @see org.kuali.student.core.search.service.SearchService#getSearchTypes()
 378  
      */
 379  
     @Override
 380  
     public List<SearchTypeInfo> getSearchTypes() throws OperationFailedException {
 381  0
         return searchManager.getSearchTypes();
 382  
     }
 383  
 
 384  
     /**
 385  
      * @see org.kuali.student.core.search.service.SearchService#getSearchTypesByCriteria(java.lang.String)
 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  
      * @see org.kuali.student.core.search.service.SearchService#getSearchTypesByResult(java.lang.String)
 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  1
                 return searchManager.search(searchRequest, proposalDao);
 403  
         }
 404  
 
 405  
     /**
 406  
      * @return the validatorFactory
 407  
      */
 408  
     public ValidatorFactory getValidatorFactory() {
 409  0
         return validatorFactory;
 410  
     }
 411  
 
 412  
     /**
 413  
      * @param validatorFactory the validatorFactory to set
 414  
      */
 415  
     public void setValidatorFactory(ValidatorFactory validatorFactory) {
 416  1
         this.validatorFactory = validatorFactory;
 417  1
     }
 418  
 
 419  
     /**
 420  
      * @return the searchManager
 421  
      */
 422  
     public SearchManager getSearchManager() {
 423  0
         return searchManager;
 424  
     }
 425  
 
 426  
     /**
 427  
      * @return the dictionaryServiceDelegate
 428  
      */
 429  
     public DictionaryService getDictionaryServiceDelegate() {
 430  0
         return dictionaryServiceDelegate;
 431  
     }
 432  
 
 433  
         
 434  
 }