| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.kuali.student.enrollment.class1.lrr.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.enrollment.lpr.dto.LprInfo; |
| 22 | |
import org.kuali.student.enrollment.lpr.service.LprService; |
| 23 | |
import org.kuali.student.enrollment.lrr.dto.LearningResultRecordInfo; |
| 24 | |
import org.kuali.student.enrollment.lrr.infc.LearningResultRecord; |
| 25 | |
import org.kuali.student.enrollment.lrr.service.LearningResultRecordService; |
| 26 | |
import org.kuali.student.enrollment.lui.dto.LuiInfo; |
| 27 | |
import org.kuali.student.enrollment.lui.service.LuiService; |
| 28 | |
import org.kuali.student.r2.common.dto.ContextInfo; |
| 29 | |
import org.kuali.student.r2.common.exceptions.DisabledIdentifierException; |
| 30 | |
import org.kuali.student.r2.common.exceptions.DoesNotExistException; |
| 31 | |
import org.kuali.student.r2.common.exceptions.InvalidParameterException; |
| 32 | |
import org.kuali.student.r2.common.exceptions.MissingParameterException; |
| 33 | |
import org.kuali.student.r2.common.exceptions.OperationFailedException; |
| 34 | |
import org.kuali.student.r2.common.exceptions.PermissionDeniedException; |
| 35 | |
|
| 36 | |
import java.util.ArrayList; |
| 37 | |
import java.util.Collection; |
| 38 | |
import java.util.Collections; |
| 39 | |
import java.util.HashMap; |
| 40 | |
import java.util.HashSet; |
| 41 | |
import java.util.List; |
| 42 | |
import java.util.Map; |
| 43 | |
import java.util.Set; |
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | 0 | public class CompletedCoursesResolver implements TermResolver<Collection<String>> { |
| 51 | |
|
| 52 | |
private LearningResultRecordService lrrService; |
| 53 | |
|
| 54 | |
private LprService lprService; |
| 55 | |
|
| 56 | |
private LuiService luiService; |
| 57 | |
|
| 58 | 0 | private final static Set<String> prerequisites = new HashSet<String>(2); |
| 59 | |
|
| 60 | |
static { |
| 61 | 0 | prerequisites.add(RulesExecutionConstants.STUDENT_ID_TERM_NAME); |
| 62 | 0 | prerequisites.add(RulesExecutionConstants.CONTEXT_INFO_TERM_NAME); |
| 63 | 0 | } |
| 64 | |
|
| 65 | |
public void setLrrService(LearningResultRecordService lrrService) { |
| 66 | 0 | this.lrrService = lrrService; |
| 67 | 0 | } |
| 68 | |
|
| 69 | |
public void setLprService(LprService lprService) { |
| 70 | 0 | this.lprService = lprService; |
| 71 | 0 | } |
| 72 | |
|
| 73 | |
public void setLuiService(LuiService luiService) { |
| 74 | 0 | this.luiService = luiService; |
| 75 | 0 | } |
| 76 | |
|
| 77 | |
@Override |
| 78 | |
public Set<String> getPrerequisites() { |
| 79 | 0 | return prerequisites; |
| 80 | |
} |
| 81 | |
|
| 82 | |
@Override |
| 83 | |
public String getOutput() { |
| 84 | 0 | return RulesExecutionConstants.STUDENT_COMPLETED_COURSE_IDS_TERM_NAME; |
| 85 | |
} |
| 86 | |
|
| 87 | |
@Override |
| 88 | |
public Set<String> getParameterNames() { |
| 89 | 0 | return Collections.emptySet(); |
| 90 | |
} |
| 91 | |
|
| 92 | |
@Override |
| 93 | |
public int getCost() { |
| 94 | |
|
| 95 | 0 | return 0; |
| 96 | |
} |
| 97 | |
|
| 98 | |
@Override |
| 99 | |
public Collection<String> resolve(Map<String, Object> resolvedPrereqs, Map<String, String> parameters) throws TermResolutionException { |
| 100 | 0 | String studentId = resolvedPrereqs.get(RulesExecutionConstants.STUDENT_ID_TERM_NAME).toString(); |
| 101 | 0 | ContextInfo context = (ContextInfo) resolvedPrereqs.get(RulesExecutionConstants.CONTEXT_INFO_TERM_NAME); |
| 102 | |
|
| 103 | 0 | Collection<String> results = null; |
| 104 | |
|
| 105 | |
try { |
| 106 | 0 | List<LprInfo> lprs = lprService.getLprsByPerson(studentId, context); |
| 107 | |
|
| 108 | 0 | Map<String, String> lprIdToCluId = new HashMap<String, String>(); |
| 109 | 0 | List<String> lprIds = new ArrayList<String>(lprs.size()); |
| 110 | |
|
| 111 | 0 | for(LprInfo lpr : lprs) { |
| 112 | 0 | String luiId = lpr.getLuiId(); |
| 113 | 0 | LuiInfo lui = luiService.getLui(luiId, context); |
| 114 | 0 | lprIdToCluId.put(lpr.getId(), lui.getCluId()); |
| 115 | |
|
| 116 | 0 | lprIds.add(lpr.getId()); |
| 117 | 0 | } |
| 118 | |
|
| 119 | 0 | List<LearningResultRecordInfo> lrrs = lrrService.getLearningResultRecordsForLprIds(lprIds, context); |
| 120 | |
|
| 121 | 0 | results = new ArrayList<String>(); |
| 122 | |
|
| 123 | 0 | for(LearningResultRecord lrr : lrrs) { |
| 124 | 0 | results.add(lprIdToCluId.get(lrr.getLprId())); |
| 125 | |
} |
| 126 | |
|
| 127 | 0 | } catch (DoesNotExistException e) { |
| 128 | 0 | throw new TermResolutionException(e.getMessage(), this, parameters, e); |
| 129 | 0 | }catch (InvalidParameterException e) { |
| 130 | 0 | throw new TermResolutionException(e.getMessage(), this, parameters, e); |
| 131 | 0 | } catch (MissingParameterException e) { |
| 132 | 0 | throw new TermResolutionException(e.getMessage(), this, parameters, e); |
| 133 | 0 | } catch (OperationFailedException e) { |
| 134 | 0 | throw new TermResolutionException(e.getMessage(), this, parameters, e); |
| 135 | 0 | } catch (PermissionDeniedException e) { |
| 136 | 0 | throw new TermResolutionException(e.getMessage(), this, parameters, e); |
| 137 | 0 | } |
| 138 | |
|
| 139 | 0 | return results; |
| 140 | |
|
| 141 | |
} |
| 142 | |
|
| 143 | |
} |