Coverage Report - org.kuali.student.r2.core.class1.atp.service.decorators.AtpServiceValidationDecorator
 
Classes in this File Line Coverage Branch Coverage Complexity
AtpServiceValidationDecorator
0%
0/88
0%
0/34
3.286
 
 1  
 package org.kuali.student.r2.core.class1.atp.service.decorators;
 2  
 
 3  
 import org.apache.commons.lang.StringUtils;
 4  
 import org.kuali.student.r2.common.datadictionary.DataDictionaryValidator;
 5  
 import org.kuali.student.r2.common.datadictionary.service.DataDictionaryService;
 6  
 import org.kuali.student.r2.common.dto.ContextInfo;
 7  
 import org.kuali.student.r2.common.dto.ValidationResultInfo;
 8  
 import org.kuali.student.r2.common.exceptions.*;
 9  
 import org.kuali.student.r2.common.infc.HoldsDataDictionaryService;
 10  
 import org.kuali.student.r2.common.infc.HoldsValidator;
 11  
 import org.kuali.student.r2.core.atp.dto.AtpAtpRelationInfo;
 12  
 import org.kuali.student.r2.core.atp.dto.AtpInfo;
 13  
 import org.kuali.student.r2.core.atp.dto.MilestoneInfo;
 14  
 import org.kuali.student.r2.core.class1.util.ValidationUtils;
 15  
 
 16  
 import java.util.Date;
 17  
 import java.util.List;
 18  
 import org.kuali.student.r2.common.constants.CommonServiceConstants;
 19  
 
 20  0
 public class AtpServiceValidationDecorator extends AtpServiceDecorator implements HoldsValidator, HoldsDataDictionaryService {
 21  
 
 22  
     private DataDictionaryValidator validator;
 23  
     private DataDictionaryService dataDictionaryService;
 24  
 
 25  
     @Override
 26  
     public DataDictionaryValidator getValidator() {
 27  0
         return validator;
 28  
     }
 29  
 
 30  
     @Override
 31  
     public void setValidator(DataDictionaryValidator validator) {
 32  0
         this.validator = validator;
 33  0
     }
 34  
 
 35  
     @Override
 36  
     public DataDictionaryService getDataDictionaryService() {
 37  0
         return dataDictionaryService;
 38  
     }
 39  
 
 40  
     @Override
 41  
     public void setDataDictionaryService(DataDictionaryService dataDictionaryService) {
 42  0
         this.dataDictionaryService = dataDictionaryService;
 43  0
     }
 44  
 
 45  
     @Override
 46  
     public AtpInfo getAtp(String atpId, ContextInfo context) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 47  
 
 48  0
         if (null == atpId) {
 49  0
             throw new DoesNotExistException("Null parameter in the input:atpId");
 50  
         }
 51  0
         return getNextDecorator().getAtp(atpId, context);
 52  
     }
 53  
 
 54  
     @Override
 55  
     public List<AtpInfo> getAtpsByIds(List<String> atpIds, ContextInfo context) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException,
 56  
             PermissionDeniedException {
 57  0
         if (null == atpIds || atpIds.size() == 0) {
 58  0
             throw new DoesNotExistException("Null parameter in the input:atpId");
 59  
         }
 60  0
         return getNextDecorator().getAtpsByIds(atpIds, context);
 61  
     }
 62  
 
 63  
     @Override
 64  
     public List<AtpInfo> getAtpsByDates(Date startDate, Date endDate, ContextInfo context) throws InvalidParameterException, MissingParameterException, OperationFailedException,
 65  
             PermissionDeniedException {
 66  0
         if (null == startDate || null == endDate) {
 67  0
             throw new MissingParameterException("Null parameter in the input: startDate or endDate");
 68  
         }
 69  0
         return getNextDecorator().getAtpsByDates(startDate, endDate, context);
 70  
     }
 71  
 
 72  
     @Override
 73  
     public AtpInfo createAtp(String atpTypeKey, AtpInfo atpInfo, ContextInfo context) throws DataValidationErrorException, InvalidParameterException, MissingParameterException,
 74  
             OperationFailedException, PermissionDeniedException, ReadOnlyException {
 75  0
         _atpFullValidation(atpInfo, context);
 76  
 
 77  0
         if (atpInfo.getId() != null) {
 78  0
             if (!CommonServiceConstants.isIdAllowedOnCreate(context)) {
 79  0
                 throw new ReadOnlyException("ID cannot be supplied when creating an ATP.");
 80  
             }
 81  
         }
 82  
 
 83  0
         return getNextDecorator().createAtp(atpTypeKey, atpInfo, context);
 84  
     }
 85  
 
 86  
     @Override
 87  
     public AtpInfo updateAtp(String atpId, AtpInfo atpInfo, ContextInfo context) throws DataValidationErrorException, DoesNotExistException, InvalidParameterException, MissingParameterException,
 88  
             OperationFailedException, PermissionDeniedException, VersionMismatchException {
 89  0
         _atpFullValidation(atpInfo, context);
 90  
         try {
 91  0
             return getNextDecorator().updateAtp(atpId, atpInfo, context);
 92  0
         } catch (ReadOnlyException e) {
 93  0
             throw new OperationFailedException(e.getMessage());
 94  
         }
 95  
     }
 96  
 
 97  
     private void _atpFullValidation(AtpInfo atpInfo, ContextInfo context) throws DataValidationErrorException, OperationFailedException, InvalidParameterException, MissingParameterException {
 98  
         try {
 99  0
             List<ValidationResultInfo> errors = this.validateAtp(DataDictionaryValidator.ValidationType.FULL_VALIDATION.toString(), atpInfo.getTypeKey(), atpInfo, context);
 100  0
             if (!errors.isEmpty()) {
 101  0
                 throw new DataValidationErrorException("Error(s) occurred validating atp", errors);
 102  
             }
 103  0
         } catch (DoesNotExistException ex) {
 104  0
             throw new OperationFailedException("Error validating atp", ex);
 105  0
         } catch (PermissionDeniedException e) {
 106  0
             throw new OperationFailedException("Error validating milestone", e);
 107  0
         }
 108  0
     }
 109  
 
 110  
     @Override
 111  
     public List<ValidationResultInfo> validateAtp(String validationType, String atpTypeKey, AtpInfo atpInfo, ContextInfo context)
 112  
             throws DoesNotExistException, InvalidParameterException,
 113  
             MissingParameterException, OperationFailedException, PermissionDeniedException {
 114  
 
 115  
         List<ValidationResultInfo> errors;
 116  
 
 117  0
         errors = ValidationUtils.validateInfo(validator, validationType, atpInfo, context);
 118  0
         List<ValidationResultInfo> nextDecorationErrors = getNextDecorator().validateAtp(validationType, atpTypeKey, atpInfo, context);
 119  0
         if (null != nextDecorationErrors) {
 120  0
             errors.addAll(nextDecorationErrors);
 121  
         }
 122  
 
 123  0
         return errors;
 124  
     }
 125  
 
 126  
     @Override
 127  
     public AtpAtpRelationInfo createAtpAtpRelation(String atpId, String relatedAtpId,
 128  
             String atpAtpRelationTypeKey,
 129  
             AtpAtpRelationInfo atpAtpRelationInfo,
 130  
             ContextInfo context)
 131  
             throws DoesNotExistException, DataValidationErrorException, InvalidParameterException, MissingParameterException,
 132  
             OperationFailedException, PermissionDeniedException, ReadOnlyException {
 133  0
         _atpAtpRelationFullValidation(atpAtpRelationInfo, context);
 134  0
         return getNextDecorator().createAtpAtpRelation(atpId, relatedAtpId, atpAtpRelationTypeKey, atpAtpRelationInfo, context);
 135  
     }
 136  
 
 137  
     @Override
 138  
     public AtpAtpRelationInfo updateAtpAtpRelation(String atpAtpRelationId, AtpAtpRelationInfo atpAtpRelationInfo, ContextInfo context) throws DataValidationErrorException, DoesNotExistException,
 139  
             InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, VersionMismatchException {
 140  0
         _atpAtpRelationFullValidation(atpAtpRelationInfo, context);
 141  
         try {
 142  0
             return getNextDecorator().updateAtpAtpRelation(atpAtpRelationId, atpAtpRelationInfo, context);
 143  0
         } catch (ReadOnlyException e) {
 144  0
             throw new OperationFailedException(e.getMessage());
 145  
         }
 146  
     }
 147  
 
 148  
     private void _atpAtpRelationFullValidation(AtpAtpRelationInfo atpAtpRelationInfo, ContextInfo context) throws DataValidationErrorException, OperationFailedException, InvalidParameterException,
 149  
             MissingParameterException {
 150  
 //        try {
 151  
 //            List<ValidationResultInfo> errors = this.validateAtpAtpRelation(DataDictionaryValidator.ValidationType.FULL_VALIDATION.toString(), atpAtpRelationInfo, context);
 152  
 //            if (!errors.isEmpty()) {
 153  
 //                throw new DataValidationErrorException("Error(s) occurred validating atp-atp relation", errors);
 154  
 //            }
 155  
 //        } catch (DoesNotExistException ex) {
 156  
 //            throw new OperationFailedException("Error validating atp-atp relation", ex);
 157  
 //        }
 158  0
     }
 159  
 
 160  
     @Override
 161  
     public List<ValidationResultInfo> validateAtpAtpRelation(String validationTypeKey, String atpId, String atpPeerKey,
 162  
             String atpAtpRelationTypeKey, AtpAtpRelationInfo atpAtpRelationInfo,
 163  
             ContextInfo context)
 164  
             throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 165  
 
 166  
         List<ValidationResultInfo> errors;
 167  
         try {
 168  0
             errors = ValidationUtils.validateInfo(validator, validationTypeKey, atpAtpRelationInfo, context);
 169  0
             List<ValidationResultInfo> nextDecorationErrors = getNextDecorator().validateAtpAtpRelation(validationTypeKey, atpId, atpPeerKey, atpAtpRelationTypeKey, atpAtpRelationInfo, context);
 170  0
             if (null != nextDecorationErrors) {
 171  0
                 errors.addAll(nextDecorationErrors);
 172  
             }
 173  0
         } catch (DoesNotExistException ex) {
 174  0
             throw new OperationFailedException("Error validating atp-atp relation", ex);
 175  0
         }
 176  0
         return errors;
 177  
     }
 178  
 
 179  
     @Override
 180  
     public MilestoneInfo createMilestone(String milestoneTypeKey, MilestoneInfo milestoneInfo, ContextInfo context)
 181  
             throws DataValidationErrorException,
 182  
             InvalidParameterException, MissingParameterException,
 183  
             OperationFailedException, PermissionDeniedException, ReadOnlyException {
 184  0
         _milestoneFullValidation(milestoneInfo, context);
 185  
 
 186  0
         if (milestoneInfo.getId() != null) {
 187  0
             if (!CommonServiceConstants.isIdAllowedOnCreate(context)) {
 188  0
                 throw new ReadOnlyException("ID cannot be populated when creating milestone.");
 189  
             }
 190  
         }
 191  
 
 192  0
         return getNextDecorator().createMilestone(milestoneTypeKey, milestoneInfo, context);
 193  
     }
 194  
 
 195  
     @Override
 196  
     public MilestoneInfo updateMilestone(String milestoneId, MilestoneInfo milestoneInfo, ContextInfo context) throws DataValidationErrorException, DoesNotExistException, InvalidParameterException,
 197  
             MissingParameterException, OperationFailedException, PermissionDeniedException, VersionMismatchException {
 198  0
         _milestoneFullValidation(milestoneInfo, context);
 199  
         try {
 200  0
             return getNextDecorator().updateMilestone(milestoneId, milestoneInfo, context);
 201  0
         } catch (ReadOnlyException e) {
 202  0
             throw new OperationFailedException(e.getMessage());
 203  
         }
 204  
     }
 205  
 
 206  
     @Override
 207  
     public MilestoneInfo calculateMilestone(String milestoneId, ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 208  0
         if (StringUtils.isEmpty(milestoneId)) {
 209  0
             throw new MissingParameterException("milestoneId");
 210  
         }
 211  0
         if (null == contextInfo) {
 212  0
             throw new MissingParameterException("contextInfo");
 213  
         }
 214  0
         return getNextDecorator().calculateMilestone(milestoneId, contextInfo);
 215  
     }
 216  
 
 217  
     private void _milestoneFullValidation(MilestoneInfo milestoneInfo, ContextInfo context) throws DataValidationErrorException, OperationFailedException, InvalidParameterException,
 218  
             MissingParameterException {
 219  
         try {
 220  0
             List<ValidationResultInfo> errors = this.validateMilestone(DataDictionaryValidator.ValidationType.FULL_VALIDATION.toString(), milestoneInfo, context);
 221  0
             if (!errors.isEmpty()) {
 222  0
                 throw new DataValidationErrorException("Error(s) validating milestone", errors);
 223  
             }
 224  0
         } catch (DoesNotExistException ex) {
 225  0
             throw new OperationFailedException("Error validating milestone", ex);
 226  0
         } catch (PermissionDeniedException e) {
 227  0
             throw new OperationFailedException("Error validating milestone", e);
 228  0
         }
 229  0
     }
 230  
 
 231  
     @Override
 232  
     public List<ValidationResultInfo> validateMilestone(String validationType, MilestoneInfo milestoneInfo, ContextInfo context)
 233  
             throws DoesNotExistException, InvalidParameterException,
 234  
             MissingParameterException, OperationFailedException, PermissionDeniedException {
 235  
 
 236  
         List<ValidationResultInfo> errors;
 237  
         try {
 238  0
             errors = ValidationUtils.validateInfo(validator, validationType, milestoneInfo, context);
 239  0
             List<ValidationResultInfo> nextDecoratorErrors = getNextDecorator().validateMilestone(validationType, milestoneInfo, context);
 240  0
             if (null != nextDecoratorErrors) {
 241  0
                 errors.addAll(nextDecoratorErrors);
 242  
             }
 243  0
         } catch (DoesNotExistException ex) {
 244  0
             throw new OperationFailedException("Error trying to validate milestone", ex);
 245  0
         }
 246  0
         return errors;
 247  
     }
 248  
 
 249  
     @Override
 250  
     public MilestoneInfo getMilestone(String milestoneId, ContextInfo context) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException,
 251  
             PermissionDeniedException {
 252  
 
 253  0
         if (milestoneId == null) {
 254  
 
 255  0
             throw new InvalidParameterException(milestoneId);
 256  
         }
 257  
 
 258  0
         return getNextDecorator().getMilestone(milestoneId, context);
 259  
 
 260  
     }
 261  
 }