| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.kuali.student.enrollment.classI.lpr.service.decorators; |
| 17 | |
|
| 18 | |
|
| 19 | |
import org.kuali.student.enrollment.lpr.dto.LuiPersonRelationInfo; |
| 20 | |
import org.kuali.student.enrollment.lpr.service.LuiPersonRelationService; |
| 21 | |
import org.kuali.student.enrollment.lpr.service.LuiPersonRelationServiceDecorator; |
| 22 | |
import org.kuali.student.r2.common.datadictionary.DataDictionaryValidator; |
| 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.DisabledIdentifierException; |
| 28 | |
import org.kuali.student.r2.common.exceptions.DoesNotExistException; |
| 29 | |
import org.kuali.student.r2.common.exceptions.InvalidParameterException; |
| 30 | |
import org.kuali.student.r2.common.exceptions.MissingParameterException; |
| 31 | |
import org.kuali.student.r2.common.exceptions.OperationFailedException; |
| 32 | |
import org.kuali.student.r2.common.exceptions.PermissionDeniedException; |
| 33 | |
import org.kuali.student.r2.common.exceptions.ReadOnlyException; |
| 34 | |
import org.kuali.student.r2.common.exceptions.VersionMismatchException; |
| 35 | |
import org.kuali.student.r2.common.infc.HoldsValidator; |
| 36 | |
|
| 37 | |
import java.util.*; |
| 38 | |
|
| 39 | |
|
| 40 | |
|
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | 0 | public class LuiPersonRelationServiceValidationDecorator extends LuiPersonRelationServiceDecorator implements HoldsValidator{ |
| 47 | |
|
| 48 | |
private DataDictionaryValidator validator; |
| 49 | |
|
| 50 | |
@Override |
| 51 | |
public DataDictionaryValidator getValidator() { |
| 52 | 0 | return validator; |
| 53 | |
} |
| 54 | |
|
| 55 | |
@Override |
| 56 | |
public void setValidator(DataDictionaryValidator validator) { |
| 57 | 0 | this.validator = validator; |
| 58 | 0 | } |
| 59 | |
|
| 60 | |
@Override |
| 61 | |
public List<LuiPersonRelationInfo> findLuiPersonRelationsForLui(String luiId, ContextInfo context) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
| 62 | 0 | return nextDecorator.findLuiPersonRelationsForLui(luiId, context); |
| 63 | |
} |
| 64 | |
@Override |
| 65 | |
public List<String> createBulkRelationshipsForPerson(String personId, List<String> luiIdList, String relationState, String luiPersonRelationTypeKey, LuiPersonRelationInfo luiPersonRelationInfo, ContextInfo context) throws DataValidationErrorException, AlreadyExistsException, DoesNotExistException, DisabledIdentifierException, ReadOnlyException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
| 66 | 0 | return nextDecorator.createBulkRelationshipsForPerson(personId, luiIdList, relationState, luiPersonRelationTypeKey, luiPersonRelationInfo, context); |
| 67 | |
} |
| 68 | |
|
| 69 | |
@Override |
| 70 | |
public List<ValidationResultInfo> validateLuiPersonRelation(String validationType, |
| 71 | |
LuiPersonRelationInfo luiPersonRelationInfo, |
| 72 | |
ContextInfo context) |
| 73 | |
throws DoesNotExistException, |
| 74 | |
InvalidParameterException, |
| 75 | |
MissingParameterException, |
| 76 | |
OperationFailedException, |
| 77 | |
PermissionDeniedException { |
| 78 | |
|
| 79 | 0 | this.validator.validate(DataDictionaryValidator.ValidationType.fromString(validationType), luiPersonRelationInfo, context); |
| 80 | |
|
| 81 | 0 | return super.validateLuiPersonRelation(validationType, luiPersonRelationInfo, context); |
| 82 | |
|
| 83 | |
} |
| 84 | |
|
| 85 | |
@Override |
| 86 | |
public String createLuiPersonRelation(String personId, String luiId, |
| 87 | |
String luiPersonRelationType, |
| 88 | |
LuiPersonRelationInfo luiPersonRelationInfo, |
| 89 | |
ContextInfo context) throws |
| 90 | |
AlreadyExistsException, |
| 91 | |
DoesNotExistException, |
| 92 | |
DisabledIdentifierException, |
| 93 | |
InvalidParameterException, |
| 94 | |
MissingParameterException, |
| 95 | |
OperationFailedException, |
| 96 | |
DataValidationErrorException, |
| 97 | |
ReadOnlyException, |
| 98 | |
PermissionDeniedException { |
| 99 | 0 | List<ValidationResultInfo> vris = this.validateLuiPersonRelation(DataDictionaryValidator.ValidationType.FULL_VALIDATION.name(), |
| 100 | |
luiPersonRelationInfo, context); |
| 101 | 0 | if (luiPersonRelationInfo.getId() != null) { |
| 102 | 0 | throw new ReadOnlyException("Id is not allowed to be supplied on a create"); |
| 103 | |
} |
| 104 | 0 | if (luiPersonRelationInfo.getMetaInfo() != null) { |
| 105 | 0 | throw new ReadOnlyException("MetaInfo is not allowed to be supplied on a create"); |
| 106 | |
} |
| 107 | 0 | if (!vris.isEmpty()) { |
| 108 | 0 | throw new DataValidationErrorException("Failed validation", vris); |
| 109 | |
} |
| 110 | 0 | return super.createLuiPersonRelation(personId, luiId, luiPersonRelationType, luiPersonRelationInfo, context); |
| 111 | |
} |
| 112 | |
|
| 113 | |
@Override |
| 114 | |
public LuiPersonRelationInfo updateLuiPersonRelation(String luiPersonRelationId, |
| 115 | |
LuiPersonRelationInfo luiPersonRelationInfo, |
| 116 | |
ContextInfo context) |
| 117 | |
throws DataValidationErrorException, |
| 118 | |
DoesNotExistException, |
| 119 | |
InvalidParameterException, |
| 120 | |
MissingParameterException, |
| 121 | |
ReadOnlyException, |
| 122 | |
OperationFailedException, |
| 123 | |
PermissionDeniedException, |
| 124 | |
VersionMismatchException { |
| 125 | 0 | List<ValidationResultInfo> vris = this.validateLuiPersonRelation(DataDictionaryValidator.ValidationType.FULL_VALIDATION.name(), |
| 126 | |
luiPersonRelationInfo, context); |
| 127 | 0 | LuiPersonRelationInfo orig = this.fetchLuiPersonRelation(luiPersonRelationId, context); |
| 128 | |
|
| 129 | 0 | checkReadOnly("id", orig.getId(), luiPersonRelationInfo.getId()); |
| 130 | 0 | checkReadOnly("type", orig.getTypeKey(), luiPersonRelationInfo.getTypeKey()); |
| 131 | 0 | checkReadOnly("createId", orig.getMetaInfo().getCreateId(), luiPersonRelationInfo.getMetaInfo().getCreateId()); |
| 132 | 0 | checkReadOnly("createTime", orig.getMetaInfo().getCreateTime(), luiPersonRelationInfo.getMetaInfo().getCreateTime()); |
| 133 | |
|
| 134 | 0 | if (orig.getMetaInfo().getVersionInd().equals(luiPersonRelationInfo.getMetaInfo().getVersionInd())) { |
| 135 | 0 | checkReadOnly("updateId", orig.getMetaInfo().getUpdateId(), luiPersonRelationInfo.getMetaInfo().getUpdateId()); |
| 136 | 0 | checkReadOnly("updateTime", orig.getMetaInfo().getUpdateTime(), luiPersonRelationInfo.getMetaInfo().getUpdateTime()); |
| 137 | |
} |
| 138 | |
|
| 139 | 0 | if (!vris.isEmpty()) { |
| 140 | 0 | throw new DataValidationErrorException("Failed validation", vris); |
| 141 | |
} |
| 142 | |
|
| 143 | 0 | return super.updateLuiPersonRelation(luiPersonRelationId, luiPersonRelationInfo, context); |
| 144 | |
} |
| 145 | |
|
| 146 | |
private void checkReadOnly(String field, Object orig, Object supplied) |
| 147 | |
throws ReadOnlyException { |
| 148 | 0 | checkReadOnly(field, orig, supplied, "" + orig, "" + supplied); |
| 149 | 0 | } |
| 150 | |
|
| 151 | |
private void checkReadOnly(String field, Object orig, Object supplied, String origStr, String suppliedStr) |
| 152 | |
throws ReadOnlyException { |
| 153 | 0 | if (orig != null) { |
| 154 | 0 | if (orig.equals(supplied)) { |
| 155 | 0 | return; |
| 156 | |
} |
| 157 | |
} |
| 158 | 0 | throw new ReadOnlyException(field + " is read only but the original value " + origStr + " and the supplied new=" + suppliedStr); |
| 159 | |
} |
| 160 | |
} |
| 161 | |
|