| 1 |  |   | 
  | 2 |  |   | 
  | 3 |  |   | 
  | 4 |  |   | 
  | 5 |  |   | 
  | 6 |  |   | 
  | 7 |  |   | 
  | 8 |  |   | 
  | 9 |  |   | 
  | 10 |  |   | 
  | 11 |  |   | 
  | 12 |  |   | 
  | 13 |  |   | 
  | 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.List; | 
  | 32 |  |  import java.util.Map; | 
  | 33 |  |  import java.util.Set; | 
  | 34 |  |   | 
  | 35 |  |   | 
  | 36 |  |   | 
  | 37 |  |   | 
  | 38 |  |   | 
  | 39 |  |   | 
  | 40 |  |   | 
  | 41 |  |   | 
  | 42 | 0 |  public class MilestoneResolver implements TermResolver<MilestoneInfo> { | 
  | 43 |  |      private AtpService atpService; | 
  | 44 |  |   | 
  | 45 |  |      @Override | 
  | 46 |  |      public Set<String> getPrerequisites() { | 
  | 47 | 0 |          return Collections.singleton(RulesExecutionConstants.CONTEXT_INFO_TERM_NAME); | 
  | 48 |  |      } | 
  | 49 |  |   | 
  | 50 |  |      @Override | 
  | 51 |  |      public String getOutput() { | 
  | 52 | 0 |          return RulesExecutionConstants.MILESTONE_TERM_NAME; | 
  | 53 |  |      } | 
  | 54 |  |   | 
  | 55 |  |      @Override | 
  | 56 |  |      public Set<String> getParameterNames() { | 
  | 57 | 0 |          return Collections.singleton(RulesExecutionConstants.MILESTONE_ID_TERM_PROPERTY); | 
  | 58 |  |      } | 
  | 59 |  |   | 
  | 60 |  |      @Override | 
  | 61 |  |      public int getCost() { | 
  | 62 |  |           | 
  | 63 | 0 |          return 0; | 
  | 64 |  |      } | 
  | 65 |  |   | 
  | 66 |  |      @Override | 
  | 67 |  |      public MilestoneInfo resolve(Map<String, Object> resolvedPrereqs, Map<String, String> parameters) throws TermResolutionException { | 
  | 68 |  |   | 
  | 69 | 0 |          String milestoneId = parameters.get(RulesExecutionConstants.MILESTONE_ID_TERM_PROPERTY); | 
  | 70 | 0 |          ContextInfo context = (ContextInfo) resolvedPrereqs.get(RulesExecutionConstants.CONTEXT_INFO_TERM_NAME); | 
  | 71 |  |   | 
  | 72 | 0 |          MilestoneInfo result = null; | 
  | 73 |  |          try { | 
  | 74 | 0 |              result = atpService.getMilestone(milestoneId, context); | 
  | 75 | 0 |          } catch (DoesNotExistException e) { | 
  | 76 | 0 |              throw new TermResolutionException(e.getMessage(), this, parameters); | 
  | 77 | 0 |          } catch (InvalidParameterException e) { | 
  | 78 | 0 |              throw new TermResolutionException(e.getMessage(), this, parameters); | 
  | 79 | 0 |          } catch (MissingParameterException e) { | 
  | 80 | 0 |              throw new TermResolutionException(e.getMessage(), this, parameters); | 
  | 81 | 0 |          } catch (OperationFailedException e) { | 
  | 82 | 0 |              throw new TermResolutionException(e.getMessage(), this, parameters); | 
  | 83 | 0 |          } catch (PermissionDeniedException e) { | 
  | 84 | 0 |              throw new TermResolutionException(e.getMessage(), this, parameters); | 
  | 85 | 0 |          } | 
  | 86 |  |   | 
  | 87 | 0 |          return result; | 
  | 88 |  |      } | 
  | 89 |  |  } |