Coverage Report - org.kuali.student.process.poc.krms.termresolver.MilestoneByTypeResolver
 
Classes in this File Line Coverage Branch Coverage Complexity
MilestoneByTypeResolver
0%
0/27
N/A
2.333
 
 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.termresolver;
 17  
 
 18  
 import org.kuali.rice.krms.api.engine.TermResolutionException;
 19  
 import org.kuali.rice.krms.api.engine.TermResolver;
 20  
 import org.kuali.student.common.util.krms.RulesExecutionConstants;
 21  
 import org.kuali.student.r2.common.dto.ContextInfo;
 22  
 import org.kuali.student.r2.common.exceptions.DoesNotExistException;
 23  
 import org.kuali.student.r2.common.exceptions.InvalidParameterException;
 24  
 import org.kuali.student.r2.common.exceptions.MissingParameterException;
 25  
 import org.kuali.student.r2.common.exceptions.OperationFailedException;
 26  
 import org.kuali.student.r2.common.exceptions.PermissionDeniedException;
 27  
 import org.kuali.student.r2.core.atp.dto.MilestoneInfo;
 28  
 import org.kuali.student.r2.core.atp.service.AtpService;
 29  
 
 30  
 import java.util.Collections;
 31  
 import java.util.HashSet;
 32  
 import java.util.List;
 33  
 import java.util.Map;
 34  
 import java.util.Set;
 35  
 
 36  
 /**
 37  
  * This class resolves a milestone type into MilestoneInfos
 38  
  *
 39  
  * @author alubbers
 40  
  */
 41  0
 public class MilestoneByTypeResolver implements TermResolver<List<MilestoneInfo>> {
 42  
 
 43  
     private AtpService atpService;
 44  
 
 45  
     private final static Set<String> requiredParameterNames;
 46  
 
 47  
     static {
 48  0
         Set<String> temp = new HashSet<String>(2);
 49  0
         temp.add(RulesExecutionConstants.MILESTONE_ATP_KEY_TERM_PROPERTY);
 50  0
         temp.add(RulesExecutionConstants.MILESTONE_TYPE_TERM_PROPERTY);
 51  
 
 52  0
         requiredParameterNames = Collections.unmodifiableSet(temp);
 53  0
     }
 54  
 
 55  
     public void setAtpService(AtpService atpService) {
 56  0
         this.atpService = atpService;
 57  0
     }
 58  
 
 59  
     @Override
 60  
     public Set<String> getPrerequisites() {
 61  0
         return Collections.singleton(RulesExecutionConstants.CONTEXT_INFO_TERM_NAME);
 62  
     }
 63  
 
 64  
     @Override
 65  
     public String getOutput() {
 66  0
         return RulesExecutionConstants.MILESTONES_BY_TYPE_TERM_NAME;
 67  
     }
 68  
 
 69  
     @Override
 70  
     public Set<String> getParameterNames() {
 71  0
         return requiredParameterNames;
 72  
     }
 73  
 
 74  
     @Override
 75  
     public int getCost() {
 76  
         // TODO Analyze
 77  0
         return 0;
 78  
     }
 79  
 
 80  
     @Override
 81  
     public List<MilestoneInfo> resolve(Map<String, Object> resolvedPrereqs, Map<String, String> parameters) throws TermResolutionException {
 82  
 
 83  0
         String milestoneType = parameters.get(RulesExecutionConstants.MILESTONE_TYPE_TERM_PROPERTY);
 84  0
         String atpKey = parameters.get(RulesExecutionConstants.MILESTONE_ATP_KEY_TERM_PROPERTY);
 85  0
         ContextInfo context = (ContextInfo) resolvedPrereqs.get(RulesExecutionConstants.CONTEXT_INFO_TERM_NAME);
 86  
 
 87  0
         List<MilestoneInfo> result = null;
 88  
         try {
 89  0
             result = atpService.getMilestonesByTypeForAtp(atpKey, milestoneType, context);
 90  0
         } catch (InvalidParameterException e) {
 91  0
             throw new TermResolutionException(e.getMessage(), this, parameters);
 92  0
         } catch (MissingParameterException e) {
 93  0
             throw new TermResolutionException(e.getMessage(), this, parameters);
 94  0
         } catch (OperationFailedException e) {
 95  0
             throw new TermResolutionException(e.getMessage(), this, parameters);
 96  0
         } catch (PermissionDeniedException e) {
 97  0
             throw new TermResolutionException(e.getMessage(), this, parameters);
 98  0
         }
 99  
 
 100  0
         return result;
 101  
     }
 102  
 }