Coverage Report - org.kuali.student.process.poc.krms.proposition.RegistrationHoldProposition
 
Classes in this File Line Coverage Branch Coverage Complexity
RegistrationHoldProposition
0%
0/24
0%
0/12
4
 
 1  
 /**
 2  
  * Copyright 2011 The Kuali Foundation Licensed under the
 3  
  * Educational Community License, Version 2.0 (the "License"); you may
 4  
  * not use this file except in compliance with the License. You may
 5  
  * obtain a copy of the License at
 6  
  *
 7  
  * http://www.osedu.org/licenses/ECL-2.0
 8  
  *
 9  
  * Unless required by applicable law or agreed to in writing,
 10  
  * software distributed under the License is distributed on an "AS IS"
 11  
  * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 12  
  * or implied. See the License for the specific language governing
 13  
  * permissions and limitations under the License.
 14  
  */
 15  
 
 16  
 package org.kuali.student.process.poc.krms.proposition;
 17  
 
 18  
 import org.kuali.rice.krms.api.engine.ExecutionEnvironment;
 19  
 import org.kuali.rice.krms.api.engine.ResultEvent;
 20  
 import org.kuali.rice.krms.api.engine.Term;
 21  
 import org.kuali.rice.krms.framework.engine.PropositionResult;
 22  
 import org.kuali.rice.krms.framework.engine.result.BasicResult;
 23  
 import org.kuali.student.common.util.krms.RulesExecutionConstants;
 24  
 import org.kuali.student.common.util.krms.proposition.AbstractLeafProposition;
 25  
 import org.kuali.student.r2.core.hold.dto.HoldInfo;
 26  
 
 27  
 import java.util.ArrayList;
 28  
 import java.util.Collections;
 29  
 import java.util.List;
 30  
 
 31  
 /**
 32  
  * This class represents a proposition to evaluate if a student has a Hold that would prevent registration
 33  
  *
 34  
  * @author alubbers
 35  
  */
 36  
 public class RegistrationHoldProposition extends AbstractLeafProposition {
 37  
 
 38  
     private final String issueKey;
 39  
 
 40  0
     public RegistrationHoldProposition(String issueKey) {
 41  0
         this.issueKey = issueKey;
 42  0
     }
 43  
 
 44  
     @Override
 45  
     public PropositionResult evaluate(ExecutionEnvironment environment) {
 46  
 
 47  
 
 48  0
         Term studentRegistrationHoldsTerm = new Term(RulesExecutionConstants.STUDENT_REGISTRATION_HOLDS_TERM_NAME, Collections.singletonMap(RulesExecutionConstants.ISSUE_KEY_TERM_PROPERTY, issueKey));
 49  0
         List<HoldInfo> studentRegistrationHolds = environment.resolveTerm(studentRegistrationHoldsTerm, this);
 50  
 
 51  0
         PropositionResult result = null;
 52  
 
 53  0
         if(studentRegistrationHolds.isEmpty()) {
 54  0
             result = new PropositionResult(true);
 55  
         }
 56  
         else {
 57  0
             List<HoldInfo> blockingHolds = new ArrayList<HoldInfo>();
 58  0
             List<HoldInfo> warningHolds = new ArrayList<HoldInfo>();
 59  
 
 60  
             // Split the found holds into warning and blocking holds
 61  0
             for(HoldInfo hold : studentRegistrationHolds) {
 62  0
                 if(hold.getIsWarning()) {
 63  0
                     warningHolds.add(hold);
 64  
                 }
 65  
                 else {
 66  0
                     blockingHolds.add(hold);
 67  
                 }
 68  
             }
 69  
 
 70  
             // if there are no blocking holds, the result of the evaluation is true
 71  0
             result = new PropositionResult(blockingHolds.isEmpty());
 72  
 
 73  
             // check the warning holds, add the hold Ids to the environment attributes if any have been found for the student
 74  0
             if(!warningHolds.isEmpty()) {
 75  0
                 List<String> warningHoldIds = (List<String>) environment.getEngineResults().getAttribute(RulesExecutionConstants.REGISTRATION_HOLD_WARNINGS_ATTRIBUTE);
 76  0
                 if(warningHoldIds == null) {
 77  0
                     warningHoldIds = new ArrayList<String>(warningHolds.size());
 78  
                 }
 79  
 
 80  0
                 for(HoldInfo hold : warningHolds) {
 81  0
                     warningHoldIds.add(hold.getId());
 82  
                 }
 83  
 
 84  0
                 environment.getEngineResults().setAttribute(RulesExecutionConstants.REGISTRATION_HOLD_WARNINGS_ATTRIBUTE, warningHoldIds);
 85  
             }
 86  
         }
 87  
 
 88  0
         environment.getEngineResults().addResult(new BasicResult(ResultEvent.PropositionEvaluated, this, environment, result.getResult()));
 89  
 
 90  0
         return result;
 91  
     }
 92  
 }