Coverage Report - org.kuali.student.enrollment.lpr.service.adapter.validation.LuiPersonRelationReadOnlyFieldUpdatesCheckerAdapter
 
Classes in this File Line Coverage Branch Coverage Complexity
LuiPersonRelationReadOnlyFieldUpdatesCheckerAdapter
0%
0/26
0%
0/14
3.6
 
 1  
 /*
 2  
  * Copyright 2009 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 1.0 (the
 5  
  * "License"); you may not use this file except in compliance with the
 6  
  * License.  You may obtain a copy of the License at
 7  
  *
 8  
  * http://www.opensource.org/licenses/ecl1.php
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
 13  
  * implied.  See the License for the specific language governing
 14  
  * permissions and limitations under the License.
 15  
  */
 16  
 package org.kuali.student.enrollment.lpr.service.adapter.validation;
 17  
 
 18  
 import org.kuali.student.common.exceptions.InvalidParameterException;
 19  
 import org.kuali.student.common.exceptions.VersionMismatchException;
 20  
 import org.kuali.student.common.exceptions.MissingParameterException;
 21  
 import org.kuali.student.common.exceptions.OperationFailedException;
 22  
 import org.kuali.student.common.exceptions.DataValidationErrorException;
 23  
 import org.kuali.student.common.exceptions.PermissionDeniedException;
 24  
 import org.kuali.student.common.exceptions.DisabledIdentifierException;
 25  
 import org.kuali.student.common.exceptions.AlreadyExistsException;
 26  
 import org.kuali.student.common.exceptions.DoesNotExistException;
 27  
 import org.kuali.student.common.exceptions.ReadOnlyException;
 28  
 import org.kuali.student.common.exceptions.*;
 29  
 
 30  
 import java.util.List;
 31  
 import org.kuali.student.common.dto.ContextInfo;
 32  
 import org.kuali.student.enrollment.lpr.dto.LuiPersonRelationInfo;
 33  
 import org.kuali.student.enrollment.lpr.mock.LuiPersonRelationServiceAdapter;
 34  
 
 35  
 /**
 36  
  * Checks if updating read only fields.
 37  
  *
 38  
  * @Author Norm
 39  
  */
 40  0
 public class LuiPersonRelationReadOnlyFieldUpdatesCheckerAdapter
 41  
                 extends LuiPersonRelationServiceAdapter {
 42  
 
 43  
          
 44  
         @Override
 45  
         public List<String> createBulkRelationshipsForPerson(String personId, List<String> luiIdList, String relationState, String luiPersonRelationType, LuiPersonRelationInfo luiPersonRelationInfo, ContextInfo context)
 46  
                         throws DataValidationErrorException,
 47  
                         AlreadyExistsException,
 48  
                         DoesNotExistException,
 49  
                         DisabledIdentifierException,
 50  
                         ReadOnlyException,
 51  
                         InvalidParameterException,
 52  
                         MissingParameterException,
 53  
                         OperationFailedException,
 54  
                         PermissionDeniedException {
 55  0
                 if (luiPersonRelationInfo.getId() != null) {
 56  0
                         throw new ReadOnlyException("Id is not allowed to be supplied on a create");
 57  
                 }
 58  0
                 if (luiPersonRelationInfo.getMetaInfo() != null) {
 59  0
                         throw new ReadOnlyException("MetaInfo is not allowed to be supplied on a create");
 60  
                 }
 61  0
                 return this.getLprService().createBulkRelationshipsForPerson(personId, luiIdList, relationState, luiPersonRelationType, luiPersonRelationInfo, context);
 62  
         }
 63  
 
 64  
         @Override
 65  
         public String createLuiPersonRelation(String personId, String luiId,
 66  
           String luiPersonRelationType,
 67  
           LuiPersonRelationInfo luiPersonRelationInfo,
 68  
           ContextInfo context)
 69  
           throws DataValidationErrorException,
 70  
           AlreadyExistsException,
 71  
           DoesNotExistException,
 72  
           DisabledIdentifierException,
 73  
           ReadOnlyException,
 74  
           InvalidParameterException,
 75  
           MissingParameterException,
 76  
           OperationFailedException,
 77  
           PermissionDeniedException {
 78  0
                 if (luiPersonRelationInfo.getId() != null) {
 79  0
                         throw new ReadOnlyException("Id is not allowed to be supplied on a create");
 80  
                 }
 81  0
                 if (luiPersonRelationInfo.getMetaInfo() != null) {
 82  0
                         throw new ReadOnlyException("MetaInfo is not allowed to be supplied on a create");
 83  
                 }
 84  0
                 return this.getLprService().createLuiPersonRelation(personId, luiId, luiPersonRelationType, luiPersonRelationInfo, context);
 85  
         }
 86  
 
 87  
         @Override
 88  
         public LuiPersonRelationInfo updateLuiPersonRelation(String luiPersonRelationId, 
 89  
           LuiPersonRelationInfo luiPersonRelationInfo,
 90  
           ContextInfo context)
 91  
           throws DataValidationErrorException,
 92  
           DoesNotExistException,
 93  
           InvalidParameterException,
 94  
           MissingParameterException,
 95  
           ReadOnlyException,
 96  
           OperationFailedException,
 97  
           PermissionDeniedException,
 98  
           VersionMismatchException {
 99  0
                 LuiPersonRelationInfo orig = this.fetchLuiPersonRelation(luiPersonRelationId, context);
 100  
                 // once created these fields are never updatable directly by the application
 101  0
                 checkReadOnly("id", orig.getId(), luiPersonRelationInfo.getId());
 102  0
                 checkReadOnly("type", orig.getType(), luiPersonRelationInfo.getType());
 103  0
                 checkReadOnly("createId", orig.getMetaInfo().getCreateId(), luiPersonRelationInfo.getMetaInfo().getCreateId());
 104  0
                 checkReadOnly("createTime", orig.getMetaInfo().getCreateTime(), luiPersonRelationInfo.getMetaInfo().getCreateTime());
 105  
                 // if nothing has changed since fetching then cannot update update info either
 106  
                 // TODO: consider throwing the optimistic lock exception (VersionMismatchException) if version ids do not match
 107  0
                 if (orig.getMetaInfo().getVersionInd().equals(luiPersonRelationInfo.getMetaInfo().getVersionInd())) {
 108  0
                         checkReadOnly("updateId", orig.getMetaInfo().getUpdateId(), luiPersonRelationInfo.getMetaInfo().getUpdateId());
 109  0
                         checkReadOnly("updateTime", orig.getMetaInfo().getUpdateTime(), luiPersonRelationInfo.getMetaInfo().getUpdateTime());
 110  
                 }
 111  0
                 return this.getLprService().updateLuiPersonRelation(luiPersonRelationId, luiPersonRelationInfo, context);
 112  
         }
 113  
 
 114  
         private void checkReadOnly(String field, Object orig, Object supplied)
 115  
                         throws ReadOnlyException {
 116  0
                 checkReadOnly(field, orig, supplied, "" + orig, "" + supplied);
 117  0
         }
 118  
 
 119  
         private void checkReadOnly(String field, Object orig, Object supplied, String origStr, String suppliedStr)
 120  
                         throws ReadOnlyException {
 121  0
                 if (orig != null) {
 122  0
                         if (orig.equals(supplied)) {
 123  0
                                 return;
 124  
                         }
 125  
                 }
 126  0
                 throw new ReadOnlyException(field + " is read only but the original value " + origStr + " and the supplied new=" + suppliedStr);
 127  
         }
 128  
 }