| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.kuali.student.enrollment.class1.hold.service.decorators; |
| 17 | |
|
| 18 | |
import java.util.List; |
| 19 | |
|
| 20 | |
|
| 21 | |
import org.kuali.student.r2.common.datadictionary.DataDictionaryValidator; |
| 22 | |
import org.kuali.student.r2.common.datadictionary.service.DataDictionaryService; |
| 23 | |
import org.kuali.student.r2.common.dto.ContextInfo; |
| 24 | |
import org.kuali.student.r2.common.dto.ValidationResultInfo; |
| 25 | |
import org.kuali.student.r2.common.exceptions.AlreadyExistsException; |
| 26 | |
import org.kuali.student.r2.common.exceptions.DataValidationErrorException; |
| 27 | |
import org.kuali.student.r2.common.exceptions.DoesNotExistException; |
| 28 | |
import org.kuali.student.r2.common.exceptions.InvalidParameterException; |
| 29 | |
import org.kuali.student.r2.common.exceptions.MissingParameterException; |
| 30 | |
import org.kuali.student.r2.common.exceptions.OperationFailedException; |
| 31 | |
import org.kuali.student.r2.common.exceptions.PermissionDeniedException; |
| 32 | |
import org.kuali.student.r2.common.exceptions.ReadOnlyException; |
| 33 | |
import org.kuali.student.r2.common.exceptions.VersionMismatchException; |
| 34 | |
import org.kuali.student.r2.common.infc.HoldsDataDictionaryService; |
| 35 | |
import org.kuali.student.r2.common.infc.HoldsValidator; |
| 36 | |
import org.kuali.student.r2.core.hold.dto.HoldInfo; |
| 37 | |
import org.kuali.student.r2.core.hold.dto.IssueInfo; |
| 38 | |
import org.kuali.student.r2.core.hold.service.HoldServiceDecorator; |
| 39 | |
import org.kuali.student.r2.core.class1.util.ValidationUtils; |
| 40 | |
|
| 41 | 0 | public class HoldServiceValidationDecorator extends HoldServiceDecorator |
| 42 | |
implements HoldsDataDictionaryService, HoldsValidator |
| 43 | |
{ |
| 44 | |
|
| 45 | |
private DataDictionaryValidator validator; |
| 46 | |
@Override |
| 47 | |
public DataDictionaryValidator getValidator() { |
| 48 | 0 | return validator; |
| 49 | |
} |
| 50 | |
@Override |
| 51 | |
public void setValidator(DataDictionaryValidator validator) { |
| 52 | 0 | this.validator = validator; |
| 53 | 0 | } |
| 54 | |
|
| 55 | |
|
| 56 | |
private DataDictionaryService dataDictionaryService; |
| 57 | |
@Override |
| 58 | |
public DataDictionaryService getDataDictionaryService() { |
| 59 | 0 | return dataDictionaryService; |
| 60 | |
} |
| 61 | |
@Override |
| 62 | |
public void setDataDictionaryService(DataDictionaryService dataDictionaryService) { |
| 63 | 0 | this.dataDictionaryService = dataDictionaryService; |
| 64 | 0 | } |
| 65 | |
|
| 66 | |
|
| 67 | |
@Override |
| 68 | |
public List<ValidationResultInfo> validateHold(String validationTypeKey, HoldInfo holdInfo, ContextInfo context) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException { |
| 69 | |
List<ValidationResultInfo> errors; |
| 70 | |
try { |
| 71 | 0 | errors = ValidationUtils.validateInfo(validator, validationTypeKey, holdInfo, context); |
| 72 | 0 | List<ValidationResultInfo> nextDecorationErrors = |
| 73 | |
getNextDecorator().validateHold(validationTypeKey, holdInfo, context); |
| 74 | 0 | if (null != nextDecorationErrors) { |
| 75 | 0 | errors.addAll(nextDecorationErrors); |
| 76 | |
} |
| 77 | |
} |
| 78 | 0 | catch (DoesNotExistException ex) { |
| 79 | 0 | throw new OperationFailedException("Error validating hold", ex); |
| 80 | 0 | } |
| 81 | 0 | return errors; |
| 82 | |
} |
| 83 | |
|
| 84 | |
@Override |
| 85 | |
public HoldInfo createHold(String personId, |
| 86 | |
String issueId, |
| 87 | |
String holdTypeKey, |
| 88 | |
HoldInfo holdInfo, |
| 89 | |
ContextInfo context) |
| 90 | |
throws AlreadyExistsException, DataValidationErrorException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, ReadOnlyException { |
| 91 | 0 | _holdFullValidation(holdInfo, context); |
| 92 | 0 | return getNextDecorator().createHold(personId, issueId, holdTypeKey, holdInfo, context); |
| 93 | |
|
| 94 | |
} |
| 95 | |
|
| 96 | |
@Override |
| 97 | |
public HoldInfo updateHold(String holdId, HoldInfo holdInfo, ContextInfo context) |
| 98 | |
throws DataValidationErrorException, DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, VersionMismatchException, ReadOnlyException { |
| 99 | 0 | _holdFullValidation(holdInfo, context); |
| 100 | 0 | return getNextDecorator().updateHold(holdId, holdInfo, context); |
| 101 | |
} |
| 102 | |
|
| 103 | |
private void _holdFullValidation(HoldInfo holdInfo, ContextInfo context) |
| 104 | |
throws DataValidationErrorException, OperationFailedException, InvalidParameterException, MissingParameterException { |
| 105 | |
try { |
| 106 | 0 | List<ValidationResultInfo> errors = this.validateHold(DataDictionaryValidator.ValidationType.FULL_VALIDATION.toString(), holdInfo, context); |
| 107 | 0 | if (!errors.isEmpty()) { |
| 108 | 0 | throw new DataValidationErrorException("Error(s) occurred validating hold", errors); |
| 109 | |
} |
| 110 | 0 | } catch (DoesNotExistException ex) { |
| 111 | 0 | throw new OperationFailedException("Error validating hold", ex); |
| 112 | 0 | } |
| 113 | 0 | } |
| 114 | |
|
| 115 | |
@Override |
| 116 | |
public IssueInfo createIssue(String issueTypeKey, IssueInfo issueInfo, ContextInfo context) throws AlreadyExistsException, DataValidationErrorException, InvalidParameterException, MissingParameterException, |
| 117 | |
OperationFailedException, PermissionDeniedException, ReadOnlyException { |
| 118 | 0 | if(issueInfo.getDescr() == null || issueInfo.getDescr().getPlain() == null){ |
| 119 | 0 | throw new InvalidParameterException("Hold issue description cannot be null"); |
| 120 | |
} |
| 121 | 0 | if(issueTypeKey == null || issueInfo.getTypeKey() == null){ |
| 122 | 0 | throw new InvalidParameterException("Hold issue type cannot be null"); |
| 123 | |
} |
| 124 | 0 | if(issueInfo.getStateKey() == null){ |
| 125 | 0 | throw new InvalidParameterException("Hold issue state cannot be null"); |
| 126 | |
} |
| 127 | 0 | return getNextDecorator().createIssue(issueTypeKey, issueInfo, context); |
| 128 | |
} |
| 129 | |
|
| 130 | |
} |