| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.kuali.student.r2.core.class1.process.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.population.service.PopulationService; |
| 28 | |
|
| 29 | |
import java.util.Collections; |
| 30 | |
import java.util.HashSet; |
| 31 | |
import java.util.Map; |
| 32 | |
import java.util.Set; |
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | 0 | public class SummerOnlyStudentTermResolver implements TermResolver<Boolean> { |
| 40 | |
|
| 41 | |
private PopulationService populationService; |
| 42 | |
|
| 43 | 0 | private final static Set<String> prerequisites = new HashSet<String>(2); |
| 44 | |
private final String summerPopulationKey; |
| 45 | |
|
| 46 | |
static { |
| 47 | 0 | prerequisites.add(RulesExecutionConstants.STUDENT_ID_TERM_NAME); |
| 48 | 0 | prerequisites.add(RulesExecutionConstants.CONTEXT_INFO_TERM_NAME); |
| 49 | 0 | } |
| 50 | |
|
| 51 | 0 | public SummerOnlyStudentTermResolver(String summerPopulationKey) { |
| 52 | 0 | this.summerPopulationKey = summerPopulationKey; |
| 53 | 0 | } |
| 54 | |
|
| 55 | |
public void setPopulationService(PopulationService populationService) { |
| 56 | 0 | this.populationService = populationService; |
| 57 | 0 | } |
| 58 | |
|
| 59 | |
@Override |
| 60 | |
public Set<String> getPrerequisites() { |
| 61 | 0 | return prerequisites; |
| 62 | |
} |
| 63 | |
|
| 64 | |
@Override |
| 65 | |
public String getOutput() { |
| 66 | 0 | return RulesExecutionConstants.SUMMER_ONLY_STUDENT_TERM_NAME; |
| 67 | |
} |
| 68 | |
|
| 69 | |
@Override |
| 70 | |
public Set<String> getParameterNames() { |
| 71 | 0 | return Collections.emptySet(); |
| 72 | |
} |
| 73 | |
|
| 74 | |
@Override |
| 75 | |
public int getCost() { |
| 76 | |
|
| 77 | 0 | return 0; |
| 78 | |
} |
| 79 | |
|
| 80 | |
@Override |
| 81 | |
public Boolean resolve(Map<String, Object> resolvedPrereqs, Map<String, String> parameters) throws TermResolutionException { |
| 82 | |
|
| 83 | 0 | Boolean result = false; |
| 84 | |
|
| 85 | 0 | String studentId = (String) resolvedPrereqs.get(RulesExecutionConstants.STUDENT_ID_TERM_NAME); |
| 86 | 0 | ContextInfo context = (ContextInfo) resolvedPrereqs.get(RulesExecutionConstants.CONTEXT_INFO_TERM_NAME); |
| 87 | |
|
| 88 | |
try { |
| 89 | 0 | result = populationService.isMember(studentId, summerPopulationKey, context); |
| 90 | 0 | } catch (DoesNotExistException e) { |
| 91 | 0 | throw new TermResolutionException(e.getMessage(), this, parameters); |
| 92 | 0 | } catch (InvalidParameterException e) { |
| 93 | 0 | throw new TermResolutionException(e.getMessage(), this, parameters); |
| 94 | 0 | } catch (MissingParameterException e) { |
| 95 | 0 | throw new TermResolutionException(e.getMessage(), this, parameters); |
| 96 | 0 | } catch (OperationFailedException e) { |
| 97 | 0 | throw new TermResolutionException(e.getMessage(), this, parameters); |
| 98 | 0 | } catch (PermissionDeniedException e) { |
| 99 | 0 | throw new TermResolutionException(e.getMessage(), this, parameters); |
| 100 | 0 | } |
| 101 | |
|
| 102 | 0 | return result; |
| 103 | |
} |
| 104 | |
} |