| 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.HashSet; |
| 32 | |
import java.util.List; |
| 33 | |
import java.util.Map; |
| 34 | |
import java.util.Set; |
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | |
|
| 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 | |
|
| 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 | |
} |