Coverage Report - org.kuali.student.r2.core.exemption.service.ExemptionServiceMockImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
ExemptionServiceMockImpl
0%
0/116
0%
0/54
2.357
 
 1  
 /*
 2  
  * To change this template, choose Tools | Templates
 3  
  * and open the template in the editor.
 4  
  */
 5  
 package org.kuali.student.r2.core.exemption.service;
 6  
 
 7  
 import java.util.ArrayList;
 8  
 import java.util.Date;
 9  
 import java.util.HashMap;
 10  
 import java.util.List;
 11  
 import java.util.Map;
 12  
 import org.kuali.student.r2.common.dto.ContextInfo;
 13  
 import org.kuali.student.r2.common.dto.MetaInfo;
 14  
 import org.kuali.student.r2.common.dto.StatusInfo;
 15  
 import org.kuali.student.r2.common.dto.ValidationResultInfo;
 16  
 import org.kuali.student.r2.common.exceptions.AlreadyExistsException;
 17  
 import org.kuali.student.r2.common.exceptions.DataValidationErrorException;
 18  
 import org.kuali.student.r2.common.exceptions.DoesNotExistException;
 19  
 import org.kuali.student.r2.common.exceptions.InvalidParameterException;
 20  
 import org.kuali.student.r2.common.exceptions.MissingParameterException;
 21  
 import org.kuali.student.r2.common.exceptions.OperationFailedException;
 22  
 import org.kuali.student.r2.common.exceptions.PermissionDeniedException;
 23  
 import org.kuali.student.r2.common.exceptions.VersionMismatchException;
 24  
 import org.kuali.student.r2.common.util.constants.ExemptionServiceConstants;
 25  
 import org.kuali.student.r2.core.exemption.dto.ExemptionInfo;
 26  
 import org.kuali.student.r2.core.exemption.dto.ExemptionRequestInfo;
 27  
 
 28  
 /**
 29  
  *
 30  
  * @author nwright
 31  
  */
 32  0
 public class ExemptionServiceMockImpl implements ExemptionService {
 33  
 
 34  0
     private Map<String, ExemptionRequestInfo> exemptionRequests = new HashMap<String, ExemptionRequestInfo>();
 35  0
     private Map<String, ExemptionInfo> exemptions = new HashMap<String, ExemptionInfo>();
 36  
 
 37  
     @Override
 38  
     public StatusInfo addUseToExemption(String exemptionId, ContextInfo context) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 39  0
         throw new UnsupportedOperationException("Not supported yet.");
 40  
     }
 41  
 
 42  
     private MetaInfo newMeta(ContextInfo context) {
 43  0
         MetaInfo meta = new MetaInfo();
 44  0
         meta.setCreateId(context.getPrincipalId());
 45  0
         meta.setCreateTime(new Date());
 46  0
         meta.setUpdateId(context.getPrincipalId());
 47  0
         meta.setUpdateTime(meta.getCreateTime());
 48  0
         meta.setVersionInd("0");
 49  0
         return meta;
 50  
     }
 51  
 
 52  
     @Override
 53  
     public ExemptionInfo createExemption(String exemptionRequestId, ExemptionInfo exemptionInfo, ContextInfo context) throws AlreadyExistsException, DataValidationErrorException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 54  0
         ExemptionInfo copy = new ExemptionInfo(exemptionInfo);
 55  0
         copy.setId(exemptions.size() + "");
 56  0
         copy.setMeta(newMeta(context));
 57  0
         exemptions.put(copy.getId(), copy);
 58  0
         return new ExemptionInfo(copy);
 59  
     }
 60  
 
 61  
     @Override
 62  
     public ExemptionRequestInfo createExemptionRequest(ExemptionRequestInfo exemptionRequestInfo, ContextInfo context) throws AlreadyExistsException, DataValidationErrorException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 63  0
         ExemptionRequestInfo copy = new ExemptionRequestInfo(exemptionRequestInfo);
 64  0
         copy.setId(exemptionRequests.size() + "");
 65  0
         copy.setMeta(newMeta(context));
 66  0
         this.exemptionRequests.put(copy.getId(), copy);
 67  0
         return new ExemptionRequestInfo(copy);
 68  
     }
 69  
 
 70  
     private StatusInfo newStatus() {
 71  0
         StatusInfo status = new StatusInfo();
 72  0
         status.setSuccess(Boolean.TRUE);
 73  0
         return status;
 74  
     }
 75  
 
 76  
     @Override
 77  
     public StatusInfo deleteExemption(String exemptionId, ContextInfo context) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 78  0
         if (this.exemptions.remove(exemptionId) == null) {
 79  0
             throw new DoesNotExistException(exemptionId);
 80  
         }
 81  0
         return newStatus();
 82  
     }
 83  
 
 84  
     @Override
 85  
     public StatusInfo deleteExemptionRequest(String exemptionRequestId, ContextInfo context) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 86  0
         if (this.exemptionRequests.remove(exemptionRequestId) == null) {
 87  0
             throw new DoesNotExistException(exemptionRequestId);
 88  
         }
 89  0
         return newStatus();
 90  
     }
 91  
 
 92  
     @Override
 93  
     public List<ExemptionInfo> getActiveExemptionsByTypeForPerson(String typeKey, String personId, ContextInfo context) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 94  0
         List<ExemptionInfo> list = new ArrayList<ExemptionInfo>();
 95  0
         for (ExemptionInfo info : this.getExemptionsByTypeForPerson(typeKey, personId, context)) {
 96  0
             if (info.getStateKey().equals(ExemptionServiceConstants.EXEMPTION_ACTIVE_STATE_KEY)) {
 97  0
                 list.add(info);
 98  
             }
 99  
         }
 100  0
         return list;
 101  
     }
 102  
 
 103  
     @Override
 104  
     public List<ExemptionInfo> getActiveExemptionsForPerson(String personId, ContextInfo context) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 105  0
         List<ExemptionInfo> list = new ArrayList<ExemptionInfo>();
 106  0
         for (ExemptionInfo info : this.getExemptionsForPerson(personId, context)) {
 107  0
             if (info.getStateKey().equals(ExemptionServiceConstants.EXEMPTION_ACTIVE_STATE_KEY)) {
 108  0
                 list.add(info);
 109  
             }
 110  
         }
 111  0
         return list;
 112  
     }
 113  
 
 114  
     @Override
 115  
     public ExemptionInfo getExemption(String exemptionId, ContextInfo context) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 116  0
         ExemptionInfo info = this.exemptions.get(exemptionId);
 117  0
         if (info == null) {
 118  0
             throw new DoesNotExistException(exemptionId);
 119  
         }
 120  0
         return new ExemptionInfo(info);
 121  
     }
 122  
 
 123  
     @Override
 124  
     public List<String> getExemptionIdsByType(String exemptionTypeKey, ContextInfo context) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 125  0
         List<String> list = new ArrayList<String>();
 126  0
         for (ExemptionInfo info : this.exemptions.values()) {
 127  0
             if (info.getTypeKey().equals(exemptionTypeKey)) {
 128  0
                 list.add(info.getId());
 129  
             }
 130  
         }
 131  0
         return list;
 132  
     }
 133  
 
 134  
     @Override
 135  
     public ExemptionRequestInfo getExemptionRequest(String exemptionRequestId, ContextInfo context) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 136  0
         ExemptionRequestInfo info = this.exemptionRequests.get(exemptionRequestId);
 137  0
         if (info == null) {
 138  0
             throw new DoesNotExistException(exemptionRequestId);
 139  
         }
 140  0
         return new ExemptionRequestInfo(info);
 141  
     }
 142  
 
 143  
     @Override
 144  
     public List<String> getExemptionRequestIdsByCheck(String checkKey, ContextInfo context) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 145  0
         List<String> list = new ArrayList<String>();
 146  0
         for (ExemptionRequestInfo info : this.exemptionRequests.values()) {
 147  0
             if (info.getCheckKey().equals(checkKey)) {
 148  0
                 list.add(info.getId());
 149  
             }
 150  
         }
 151  0
         return list;
 152  
     }
 153  
 
 154  
     @Override
 155  
     public List<String> getExemptionRequestIdsByType(String exemptionRequestTypeKey, ContextInfo context) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 156  0
         List<String> list = new ArrayList<String>();
 157  0
         for (ExemptionRequestInfo info : this.exemptionRequests.values()) {
 158  0
             if (info.getTypeKey().equals(exemptionRequestTypeKey)) {
 159  0
                 list.add(info.getId());
 160  
             }
 161  
         }
 162  0
         return list;
 163  
     }
 164  
 
 165  
     @Override
 166  
     public List<ExemptionRequestInfo> getExemptionRequestsByIds(List<String> exemptionRequestIds, ContextInfo context) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 167  0
         List<ExemptionRequestInfo> list = new ArrayList<ExemptionRequestInfo>(exemptionRequestIds.size());
 168  0
         for (String id : exemptionRequestIds) {
 169  0
             list.add(this.getExemptionRequest(id, context));
 170  
         }
 171  0
         return list;
 172  
     }
 173  
 
 174  
     @Override
 175  
     public List<ExemptionInfo> getExemptionsByIds(List<String> exemptionIds, ContextInfo context) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 176  0
         List<ExemptionInfo> list = new ArrayList<ExemptionInfo>(exemptionIds.size());
 177  0
         for (String id : exemptionIds) {
 178  0
             list.add(this.getExemption(id, context));
 179  
         }
 180  0
         return list;
 181  
     }
 182  
 
 183  
     @Override
 184  
     public List<ExemptionInfo> getExemptionsByTypeForPerson(String typeKey, String personId, ContextInfo context) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 185  0
         List<ExemptionInfo> list = new ArrayList<ExemptionInfo>();
 186  0
         for (ExemptionInfo info : this.exemptions.values()) {
 187  0
             if (info.getTypeKey().equals(typeKey)) {
 188  0
                 if (info.getPersonId().equals(personId)) {
 189  0
                     list.add(info);
 190  
                 }
 191  
             }
 192  
         }
 193  0
         return list;
 194  
     }
 195  
 
 196  
     @Override
 197  
     public List<ExemptionInfo> getExemptionsForPerson(String personId, ContextInfo context) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 198  0
         List<ExemptionInfo> list = new ArrayList<ExemptionInfo>();
 199  0
         for (ExemptionInfo info : this.exemptions.values()) {
 200  0
             if (info.getPersonId().equals(personId)) {
 201  0
                 list.add(info);
 202  
             }
 203  
         }
 204  0
         return list;
 205  
     }
 206  
 
 207  
     @Override
 208  
     public List<ExemptionRequestInfo> getRequestsByTypeForPerson(String typeKey, String personId, ContextInfo context) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 209  0
         List<ExemptionRequestInfo> list = new ArrayList<ExemptionRequestInfo>();
 210  0
         for (ExemptionRequestInfo info : this.getRequestsForPerson(personId, context)) {
 211  0
             if (info.getTypeKey().equals(typeKey)) {
 212  0
                 list.add(info);
 213  
             }
 214  
         }
 215  0
         return list;
 216  
     }
 217  
 
 218  
     @Override
 219  
     public List<ExemptionRequestInfo> getRequestsForPerson(String personId, ContextInfo context) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 220  0
         List<ExemptionRequestInfo> list = new ArrayList<ExemptionRequestInfo>();
 221  0
         for (ExemptionRequestInfo info : this.exemptionRequests.values()) {
 222  0
             if (info.getPersonId().equals(personId)) {
 223  0
                 list.add(info);
 224  
             }
 225  
         }
 226  0
         return list;
 227  
     }
 228  
 
 229  
     @Override
 230  
     public ExemptionInfo retrieveDateExemption(String checkKey, String personId, String milestoneId, String qualifierTypeKey, String qualifierId, ContextInfo context) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 231  0
         throw new UnsupportedOperationException("Not supported yet.");
 232  
     }
 233  
 
 234  
     @Override
 235  
     public ExemptionInfo retrieveMilestoneExemption(String checkKey, String personId, String milestoneId, String qualifierTypeKey, String qualifierId, ContextInfo context) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 236  0
         throw new UnsupportedOperationException("Not supported yet.");
 237  
     }
 238  
 
 239  
     private MetaInfo updateMeta(MetaInfo old, ContextInfo context) {
 240  0
         MetaInfo meta = new MetaInfo(old);
 241  0
         meta.setUpdateId(context.getPrincipalId());
 242  0
         meta.setUpdateTime(new Date());
 243  0
         meta.setVersionInd((Integer.parseInt(meta.getVersionInd()) + 1) + "");
 244  0
         return meta;
 245  
     }
 246  
 
 247  
     @Override
 248  
     public ExemptionInfo updateExemption(String exemptionId, ExemptionInfo exemptionInfo, ContextInfo context) throws DataValidationErrorException, DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, VersionMismatchException {
 249  0
         ExemptionInfo copy = new ExemptionInfo(exemptionInfo);
 250  0
         ExemptionInfo old = this.getExemption(exemptionId, context);
 251  0
         if (!old.getMeta().getVersionInd().equals(copy.getMeta().getVersionInd())) {
 252  0
             throw new VersionMismatchException (old.getMeta().getVersionInd());
 253  
         }
 254  0
         copy.setMeta(updateMeta(copy.getMeta(), context));        
 255  0
         this.exemptions.put(exemptionInfo.getId(), copy);
 256  0
         return new ExemptionInfo(copy);
 257  
     }
 258  
 
 259  
     @Override
 260  
     public ExemptionRequestInfo updateExemptionRequest(String exemptionRequestId, ExemptionRequestInfo exemptionRequestInfo, ContextInfo context) throws DataValidationErrorException, DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, VersionMismatchException {
 261  0
         ExemptionRequestInfo copy = new ExemptionRequestInfo(exemptionRequestInfo);
 262  0
         ExemptionRequestInfo old = this.getExemptionRequest(exemptionRequestId, context);
 263  0
         if (!old.getMeta().getVersionInd().equals(copy.getMeta().getVersionInd())) {
 264  0
             throw new VersionMismatchException (old.getMeta().getVersionInd());
 265  
         }        
 266  0
         copy.setMeta(updateMeta(copy.getMeta(), context));
 267  0
         this.exemptionRequests.put(exemptionRequestInfo.getId(), copy);
 268  0
         return new ExemptionRequestInfo(copy);
 269  
     }
 270  
 
 271  
     @Override
 272  
     public List<ValidationResultInfo> validateExemption(String validationTypeKey, ExemptionInfo exemptionInfo, ContextInfo context) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException {
 273  0
         throw new UnsupportedOperationException("Not supported yet.");
 274  
     }
 275  
 
 276  
     @Override
 277  
     public List<ValidationResultInfo> validateExemptionRequest(String validationTypeKey, ExemptionRequestInfo exemptionRequestInfo, ContextInfo context) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException {
 278  0
         throw new UnsupportedOperationException("Not supported yet.");
 279  
     }
 280  
 
 281  
     @Override
 282  
     public List<ExemptionInfo> getActiveExemptionsByTypeProcessAndCheckForPerson(String typeKey, String processKey, String checkKey, String personId, ContextInfo context)
 283  
             throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 284  
         // TODO sambit - THIS METHOD NEEDS JAVADOCS
 285  0
         return null;
 286  
     }
 287  
 
 288  
 }