Coverage Report - org.kuali.student.process.poc.evaluator.HoldCheckEvaluator
 
Classes in this File Line Coverage Branch Coverage Complexity
HoldCheckEvaluator
0%
0/37
0%
0/10
2.857
 
 1  
 package org.kuali.student.process.poc.evaluator;
 2  
 
 3  
 import java.util.ArrayList;
 4  
 import java.util.Date;
 5  
 import java.util.List;
 6  
 
 7  
 import org.kuali.student.process.poc.context.HoldCheckContext;
 8  
 import org.kuali.student.r2.common.dto.ContextInfo;
 9  
 import org.kuali.student.r2.common.dto.ValidationResultInfo;
 10  
 import org.kuali.student.r2.common.exceptions.OperationFailedException;
 11  
 import org.kuali.student.r2.core.atp.dto.AtpInfo;
 12  
 import org.kuali.student.r2.core.atp.service.AtpService;
 13  
 import org.kuali.student.r2.core.hold.dto.HoldInfo;
 14  
 import org.kuali.student.r2.core.hold.service.HoldService;
 15  
 import org.kuali.student.r2.core.process.dto.InstructionInfo;
 16  
 
 17  0
 public class HoldCheckEvaluator implements CheckEvaluator<HoldCheckContext> {
 18  
 
 19  
     private HoldService holdService;
 20  
     private AtpService atpService;
 21  
 
 22  
     public AtpService getAtpService() {
 23  0
         return atpService;
 24  
     }
 25  
 
 26  
     public void setAtpService(AtpService atpService) {
 27  0
         this.atpService = atpService;
 28  0
     }
 29  
 
 30  
     public HoldService getHoldService() {
 31  0
         return holdService;
 32  
     }
 33  
 
 34  
     public void setHoldService(HoldService holdService) {
 35  0
         this.holdService = holdService;
 36  0
     }
 37  
 
 38  
     @Override
 39  
     public List<ValidationResultInfo> evaluate(HoldCheckContext checkContext, ContextInfo context) throws OperationFailedException {
 40  
         List<HoldInfo> holds;
 41  
         try {
 42  0
             holds = holdService.getActiveHoldsByIssueAndPerson(checkContext.getCheck().getIssueKey(), checkContext.getStudentId(), context);
 43  0
         } catch (OperationFailedException ex) {
 44  0
             throw ex;
 45  0
         } catch (Exception ex) {
 46  0
             throw new OperationFailedException("unexpected", ex);
 47  0
         }
 48  0
         AtpInfo atp = null;
 49  
         try {
 50  0
             atp = atpService.getAtp(checkContext.getAtpKey(), context);
 51  0
         } catch (OperationFailedException ex) {
 52  0
             throw ex;
 53  0
         } catch (Exception ex) {
 54  0
             throw new OperationFailedException("unexpected", ex);
 55  0
         }
 56  
         // TODO: ask business what date we should use to check for holds? Start date or some specific milestone?
 57  0
         Date holdAsOfDate = atp.getStartDate();
 58  0
         List<ValidationResultInfo> vrs = new ArrayList<ValidationResultInfo>();
 59  0
         ValidationResultInfo vr = null;
 60  0
         for (HoldInfo hold : holds) {
 61  0
             if (holdAsOfDate.before(hold.getEffectiveDate())) {
 62  0
                 continue;
 63  
             }
 64  0
             if (hold.getReleasedDate() != null) {
 65  0
                 if (holdAsOfDate.after(hold.getReleasedDate())) {
 66  0
                     continue;
 67  
                 }
 68  
             }
 69  
             // TODO: Check for an Exemption to this hold and the !hold.getIsOverridable()
 70  0
             vr = initError (checkContext.getInstruction());
 71  0
             vrs.add(vr);
 72  
         }
 73  0
         if (vrs.isEmpty()) {
 74  0
             vr = initInfo(checkContext.getInstruction());
 75  0
             vrs.add(vr);
 76  
         }
 77  
 
 78  0
         return vrs;
 79  
     }
 80  
 
 81  
     private static ValidationResultInfo initError(InstructionInfo instruction) {
 82  
        // TODO: set the error level based on hold.isWarning () but not sure it should even be a property of the hold
 83  0
         return MilestoneCheckEvaluator.initError(instruction);
 84  
     }
 85  
 
 86  
     private static ValidationResultInfo initInfo(InstructionInfo instruction) {
 87  0
         return MilestoneCheckEvaluator.initInfo(instruction);
 88  
     }
 89  
 }