Coverage Report - org.kuali.student.enrollment.class1.lpr.service.decorators.LuiPersonRelationServiceValidationDecorator
 
Classes in this File Line Coverage Branch Coverage Complexity
LuiPersonRelationServiceValidationDecorator
0%
0/63
0%
0/42
4.25
 
 1  
 /*
 2  
  * Copyright 2011 The Kuali Foundation Licensed under the Educational Community
 3  
  * License, Version 2.0 (the "License"); you may not use this file except in
 4  
  * compliance with the License. You may obtain a copy of the License at
 5  
  * http://www.osedu.org/licenses/ECL-2.0 Unless required by applicable law or
 6  
  * agreed to in writing, software distributed under the License is distributed
 7  
  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
 8  
  * express or implied. See the License for the specific language governing
 9  
  * permissions and limitations under the License.
 10  
  */
 11  
 package org.kuali.student.enrollment.class1.lpr.service.decorators;
 12  
 
 13  
 import java.util.List;
 14  
 
 15  
 import javax.jws.WebParam;
 16  
 
 17  
 import org.kuali.student.enrollment.lpr.dto.LprTransactionInfo;
 18  
 import org.kuali.student.enrollment.lpr.dto.LuiPersonRelationInfo;
 19  
 import org.kuali.student.enrollment.lpr.service.LuiPersonRelationService;
 20  
 import org.kuali.student.enrollment.lpr.service.LuiPersonRelationServiceDecorator;
 21  
 import org.kuali.student.r2.common.datadictionary.DataDictionaryValidator;
 22  
 import org.kuali.student.r2.common.dto.ContextInfo;
 23  
 import org.kuali.student.r2.common.dto.ValidationResultInfo;
 24  
 import org.kuali.student.r2.common.exceptions.AlreadyExistsException;
 25  
 import org.kuali.student.r2.common.exceptions.DataValidationErrorException;
 26  
 import org.kuali.student.r2.common.exceptions.DisabledIdentifierException;
 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.HoldsValidator;
 35  
 import org.kuali.student.r2.core.class1.util.ValidationUtils;
 36  
 
 37  
 /**
 38  
  * An example Validation decorator for the {@link LuiPersonRelationService}.
 39  
  * Additional validations are performed for the validateLuiPersonRelation,
 40  
  * createLuiPersonRelation and updateLuiPersonRelation methods here
 41  
  * 
 42  
  * @author sambit
 43  
  */
 44  0
 public class LuiPersonRelationServiceValidationDecorator extends LuiPersonRelationServiceDecorator implements
 45  
         HoldsValidator {
 46  
 
 47  
     private DataDictionaryValidator validator;
 48  
 
 49  
     @Override
 50  
     public DataDictionaryValidator getValidator() {
 51  0
         return validator;
 52  
     }
 53  
 
 54  
     @Override
 55  
     public void setValidator(DataDictionaryValidator validator) {
 56  0
         this.validator = validator;
 57  0
     }
 58  
 
 59  
     @Override
 60  
     public List<ValidationResultInfo> validateLpr(String validationType, LuiPersonRelationInfo luiPersonRelationInfo,
 61  
             ContextInfo context) throws DoesNotExistException, InvalidParameterException, MissingParameterException,
 62  
             OperationFailedException, PermissionDeniedException {
 63  
         List<ValidationResultInfo> errors;
 64  
         try {
 65  0
             errors = ValidationUtils.validateInfo(validator, validationType, luiPersonRelationInfo, context);
 66  0
             List<ValidationResultInfo> nextDecoratorErrors = getNextDecorator().validateLpr(validationType,
 67  
                     luiPersonRelationInfo, context);
 68  0
             if (null != nextDecoratorErrors) {
 69  0
                 errors.addAll(nextDecoratorErrors);
 70  
             }
 71  0
         } catch (DoesNotExistException ex) {
 72  0
             throw new OperationFailedException("Error trying to validate lui-person relation", ex);
 73  0
         }
 74  0
         return errors;
 75  
     }
 76  
 
 77  
     @Override
 78  
     public LprTransactionInfo updateLprTransaction(String lprTransactionId, LprTransactionInfo lprTransactionInfo,
 79  
             ContextInfo context) throws DataValidationErrorException, DoesNotExistException, InvalidParameterException,
 80  
             MissingParameterException, OperationFailedException, PermissionDeniedException {
 81  0
         if (lprTransactionInfo.getId() == null) {
 82  0
             throw new DataValidationErrorException("Id is mandatory on an update");
 83  
         }
 84  0
         if(lprTransactionId==null || !lprTransactionId.equals(lprTransactionInfo.getId()))
 85  0
             throw new DataValidationErrorException("Ids are not same in the update parameter");
 86  
 
 87  0
         return getNextDecorator().updateLprTransaction(lprTransactionId, lprTransactionInfo, context);
 88  
     }
 89  
 
 90  
     @Override
 91  
     public String createLpr(String personId, String luiId, String luiPersonRelationType,
 92  
             LuiPersonRelationInfo luiPersonRelationInfo, ContextInfo context) throws AlreadyExistsException,
 93  
             DoesNotExistException, DisabledIdentifierException, InvalidParameterException, MissingParameterException,
 94  
             OperationFailedException, DataValidationErrorException, ReadOnlyException, PermissionDeniedException {
 95  0
         if (luiPersonRelationInfo.getId() != null) {
 96  0
             throw new ReadOnlyException("Id is not allowed to be supplied on a create");
 97  
         }
 98  0
         if (luiPersonRelationInfo.getMeta() != null) {
 99  0
             throw new ReadOnlyException("MetaInfo is not allowed to be supplied on a create");
 100  
         }
 101  
 
 102  0
         _luiPersonRelationFullValidation(luiPersonRelationInfo, context);
 103  0
         return getNextDecorator().createLpr(personId, luiId, luiPersonRelationType, luiPersonRelationInfo, context);
 104  
     }
 105  
 
 106  
     @Override
 107  
     public LuiPersonRelationInfo updateLpr(String luiPersonRelationId, LuiPersonRelationInfo luiPersonRelationInfo,
 108  
             ContextInfo context) throws DataValidationErrorException, DoesNotExistException, InvalidParameterException,
 109  
             MissingParameterException, ReadOnlyException, OperationFailedException, PermissionDeniedException,
 110  
             VersionMismatchException {
 111  0
         _luiPersonRelationFullValidation(luiPersonRelationInfo, context);
 112  0
         LuiPersonRelationInfo orig = this.getLpr(luiPersonRelationId, context);
 113  
 
 114  0
         checkReadOnly("id", orig.getId(), luiPersonRelationInfo.getId());
 115  0
         checkReadOnly("type", orig.getTypeKey(), luiPersonRelationInfo.getTypeKey());
 116  0
         checkReadOnly("createId", orig.getMeta().getCreateId(), luiPersonRelationInfo.getMeta().getCreateId());
 117  0
         checkReadOnly("createTime", orig.getMeta().getCreateTime(), luiPersonRelationInfo.getMeta().getCreateTime());
 118  
 
 119  0
         if (orig.getMeta().getVersionInd().equals(luiPersonRelationInfo.getMeta().getVersionInd())) {
 120  0
             checkReadOnly("updateId", orig.getMeta().getUpdateId(), luiPersonRelationInfo.getMeta().getUpdateId());
 121  0
             checkReadOnly("updateTime", orig.getMeta().getUpdateTime(), luiPersonRelationInfo.getMeta().getUpdateTime());
 122  
         }
 123  
 
 124  0
         return getNextDecorator().updateLpr(luiPersonRelationId, luiPersonRelationInfo, context);
 125  
     }
 126  
 
 127  
     @Override
 128  
     public LprTransactionInfo createLprTransaction(String lprTransactionTypeKey,
 129  
         LprTransactionInfo lprTransactionInfo,
 130  
             ContextInfo context) throws DataValidationErrorException,
 131  
             AlreadyExistsException, InvalidParameterException, MissingParameterException, OperationFailedException,
 132  
             PermissionDeniedException {
 133  0
         if (lprTransactionInfo.getId() != null) {
 134  0
             throw new DataValidationErrorException("Id is not allowed to be supplied on a create");
 135  
         }
 136  
 
 137  0
         return getNextDecorator().createLprTransaction(lprTransactionTypeKey, lprTransactionInfo, context);
 138  
     }
 139  
 
 140  
     @Override
 141  
     public LprTransactionInfo getLprTransaction(String lprTransactionId, ContextInfo context)
 142  
             throws DoesNotExistException, InvalidParameterException, MissingParameterException,
 143  
             OperationFailedException, PermissionDeniedException {
 144  0
         if (lprTransactionId == null) {
 145  0
             throw new InvalidParameterException("Id is mandatory to be supplied on a get*");
 146  
         }
 147  
 
 148  0
         return getNextDecorator().getLprTransaction(lprTransactionId, context);
 149  
     }
 150  
 
 151  
     @Override
 152  
     public List<String> createBulkRelationshipsForPerson(String personId, List<String> luiIds,
 153  
                 String relationState, String luiPersonRelationTypeKey,
 154  
                 LuiPersonRelationInfo luiPersonRelationInfo, ContextInfo context)
 155  
             throws AlreadyExistsException, DataValidationErrorException, DisabledIdentifierException,
 156  
                 DoesNotExistException, InvalidParameterException, MissingParameterException,
 157  
                 OperationFailedException, PermissionDeniedException, ReadOnlyException {
 158  
 
 159  0
         if (null == personId || personId.isEmpty()) {
 160  0
             throw new MissingParameterException("Person ID is required");
 161  
         }
 162  0
         if (null == luiIds || luiIds.isEmpty()) {
 163  0
             throw new MissingParameterException("A list of LUI's is required");
 164  
         }
 165  0
         if (null == luiPersonRelationTypeKey || luiPersonRelationTypeKey.isEmpty()) {
 166  0
             throw new MissingParameterException("Relation state is required");
 167  
         }
 168  0
         if (null == relationState || relationState.isEmpty()) {
 169  0
             throw new MissingParameterException("LUI-Person relation type key is required");
 170  
         }
 171  0
         if (null == luiPersonRelationInfo) {
 172  0
             throw new MissingParameterException("LUI-Person relation info is required");
 173  
         }
 174  
 
 175  0
         return getNextDecorator().createBulkRelationshipsForPerson(
 176  
                 personId, luiIds, relationState, luiPersonRelationTypeKey, luiPersonRelationInfo, context);
 177  
     }
 178  
 
 179  
 
 180  
 
 181  
     private void _luiPersonRelationFullValidation(LuiPersonRelationInfo luiPersonRelationInfo, ContextInfo context)
 182  
             throws DataValidationErrorException, DoesNotExistException, InvalidParameterException,
 183  
             MissingParameterException, OperationFailedException, PermissionDeniedException {
 184  
         try {
 185  0
             List<ValidationResultInfo> errors = this.validateLpr(
 186  
                     DataDictionaryValidator.ValidationType.FULL_VALIDATION.toString(), luiPersonRelationInfo, context);
 187  0
             if (!errors.isEmpty()) {
 188  0
                 throw new DataValidationErrorException("Error(s) validating lui-person relation", errors);
 189  
             }
 190  0
         } catch (DoesNotExistException ex) {
 191  0
             throw new OperationFailedException("Error validating lui-person relation", ex);
 192  0
         }
 193  0
     }
 194  
 
 195  
     private void checkReadOnly(String field, Object orig, Object supplied) throws ReadOnlyException {
 196  0
         checkReadOnly(field, orig, supplied, "" + orig, "" + supplied);
 197  0
     }
 198  
 
 199  
     private void checkReadOnly(String field, Object orig, Object supplied, String origStr, String suppliedStr)
 200  
             throws ReadOnlyException {
 201  0
         if (orig != null) {
 202  0
             if (orig.equals(supplied)) {
 203  0
                 return;
 204  
             }
 205  
         }
 206  0
         throw new ReadOnlyException(field + " is read only but the original value " + origStr
 207  
                 + " and the supplied new=" + suppliedStr);
 208  
     }
 209  
 
 210  
 }