| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
package org.kuali.student.r2.core.class1.process; |
| 6 | |
|
| 7 | |
import java.util.Arrays; |
| 8 | |
import org.kuali.student.r2.common.dto.ContextInfo; |
| 9 | |
import org.kuali.student.r2.common.exceptions.DoesNotExistException; |
| 10 | |
import org.kuali.student.r2.common.util.RichTextHelper; |
| 11 | |
import org.kuali.student.r2.common.util.constants.ProcessServiceConstants; |
| 12 | |
import org.kuali.student.r2.core.process.dto.CheckInfo; |
| 13 | |
import org.kuali.student.r2.core.process.dto.InstructionInfo; |
| 14 | |
import org.kuali.student.r2.core.process.dto.ProcessInfo; |
| 15 | |
import org.kuali.student.r2.core.process.service.ProcessService; |
| 16 | |
import org.kuali.student.r2.core.process.service.ProcessServiceDecorator; |
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
|
| 21 | |
|
| 22 | |
public class ProcessPocProcessServiceDecorator extends ProcessServiceDecorator { |
| 23 | |
|
| 24 | |
public ProcessPocProcessServiceDecorator(ProcessService nextDecorator) { |
| 25 | 0 | super(); |
| 26 | 0 | this.setNextDecorator(nextDecorator); |
| 27 | 0 | initializeData(); |
| 28 | 0 | } |
| 29 | |
|
| 30 | |
private boolean isInitalized() { |
| 31 | 0 | ContextInfo context = new ContextInfo(); |
| 32 | 0 | context.setPrincipalId("POC-Initializer"); |
| 33 | |
try { |
| 34 | 0 | ProcessInfo info = this.getNextDecorator().getProcess(ProcessServiceConstants.PROCESS_KEY_BASIC_ELIGIBILITY, context); |
| 35 | 0 | } catch (DoesNotExistException ex) { |
| 36 | 0 | return false; |
| 37 | 0 | } catch (Exception ex) { |
| 38 | 0 | throw new RuntimeException(ex); |
| 39 | 0 | } |
| 40 | 0 | return true; |
| 41 | |
} |
| 42 | |
|
| 43 | |
private void initializeData() { |
| 44 | 0 | if (isInitalized()) { |
| 45 | 0 | return; |
| 46 | |
} |
| 47 | |
|
| 48 | 0 | ContextInfo context = new ContextInfo(); |
| 49 | 0 | context.setPrincipalId("POC-Initializer"); |
| 50 | |
|
| 51 | 0 | _createProcess(ProcessServiceConstants.PROCESS_KEY_BASIC_ELIGIBILITY, "Basic Eligibility", "The process of checking a student's basic eligibility to register for courses.", context); |
| 52 | 0 | _createProcess(ProcessServiceConstants.PROCESS_KEY_ELIGIBILITY_FOR_TERM, "Eligibility for Term", "The process of checking a student's eligibility to register for a particular term.", context); |
| 53 | 0 | _createProcess(ProcessServiceConstants.PROCESS_KEY_HOLDS_CLEARED, "Holds Cleared", "The process of checking a student's eligibility to register for a particular term.", context); |
| 54 | 0 | _createProcess(ProcessServiceConstants.PROCESS_KEY_ELIGIBLE_FOR_COURSE, "Eligible for Course", "The process of checking a student's eligibility to register for a particular course.", context); |
| 55 | 0 | _createProcess(ProcessServiceConstants.PROCESS_KEY_ELIGIBLE_FOR_COURSES, "Eligible for Courses", "The process of checking a student's eligibility and ability to register for a proposed set of courses.", context); |
| 56 | 0 | _createProcess(ProcessServiceConstants.PROCESS_KEY_REGISTER_FOR_COURSES, "Register for Courses", "The process of checking a student's eligibility and actually register for a proposed set of courses.", context); |
| 57 | |
|
| 58 | 0 | _createCheck(ProcessServiceConstants.CHECK_KEY_IS_ALIVE, ProcessServiceConstants.DIRECT_RULE_CHECK_TYPE_KEY, "", "", "kuali.agenda.is.alive", "", "is alive", "Checks if student is actually alive", context); |
| 59 | 0 | _createCheck(ProcessServiceConstants.CHECK_KEY_HAS_OVERDUE_LIBRARY_BOOK, ProcessServiceConstants.HOLD_CHECK_TYPE_KEY, "kuali.hold.issue.library.book.overdue", "", "", "", "has overdue library book", "Checks if student has an overdue library book", context); |
| 60 | 0 | _createCheck(ProcessServiceConstants.CHECK_KEY_HAS_NOT_PAID_BILL_FROM_PRIOR_TERM, ProcessServiceConstants.HOLD_CHECK_TYPE_KEY, "kuali.hold.issue.financial.unpaid.tuition.prior.term", "", "", "", "has not paid bill from prior term", "Checks if student has an unpaid bill from a prior term", context); |
| 61 | 0 | _createCheck(ProcessServiceConstants.CHECK_KEY_STUDENT_HAS_BASIC_ELIGIBILITY, ProcessServiceConstants.PROCESS_CHECK_TYPE_KEY, "", "", "", "kuali.process.registration.basic.eligibility", "student has basic eligibility", "Checks all the checks defined in the basic eligibility process", context); |
| 62 | 0 | _createCheck(ProcessServiceConstants.CHECK_KEY_REGISTRATION_PERIOD_IS_OPEN, ProcessServiceConstants.START_DATE_CHECK_TYPE_KEY, "", "kuali.atp.milestone.RegistrationPeriod", "", "", "registration period is open", "Checks that the registration period is open", context); |
| 63 | 0 | _createCheck(ProcessServiceConstants.CHECK_KEY_REGISTRATION_PERIOD_IS_NOT_CLOSED, ProcessServiceConstants.DEADLINE_CHECK_TYPE_KEY, "", "kuali.atp.milestone.RegistrationPeriod", "", "", "registration period is not closed", "Checks that the registration period is not yet closed", context); |
| 64 | 0 | _createCheck(ProcessServiceConstants.CHECK_KEY_REGISTRATION_HOLDS_CLEARED, ProcessServiceConstants.PROCESS_CHECK_TYPE_KEY, "", "", "", "kuali.process.registration.holds.cleared", "Registration Holds Cleared", "Checks that the checks in the registration holds process", context); |
| 65 | 0 | _createCheck(ProcessServiceConstants.CHECK_KEY_IS_NOT_SUMMER_TERM, ProcessServiceConstants.DIRECT_RULE_CHECK_TYPE_KEY, "", "", "kuali.agenda.is.not.summer.term", "", "is not Summer Term", "Checks that this is not the summer term", context); |
| 66 | 0 | _createCheck(ProcessServiceConstants.CHECK_KEY_ELIGIBILITY_FOR_TERM, ProcessServiceConstants.PROCESS_CHECK_TYPE_KEY, "", "", "", "kuali.process.registration.eligibility.for.term", "Eligibility for Term", "Checks all the checks that the student is eligible for the term", context); |
| 67 | 0 | _createCheck(ProcessServiceConstants.CHECK_KEY_HAS_THE_NECESSARY_PREREQ, ProcessServiceConstants.INDIRECT_RULE_CHECK_TYPE_KEY, "", "", "", "", "Has the necessary pre-req", "Checks that the student has all the necessary pee-requisites to take the course", context); |
| 68 | 0 | _createCheck(ProcessServiceConstants.CHECK_KEY_STUDENT_HAS_ELIGIBILITY_FOR_EACH_COURSE, ProcessServiceConstants.PROCESS_CHECK_TYPE_KEY, "", "", "", "kuali.process.registration.eligible.for.course", "student has eligibility for each course", "Checks all the checks that make sure the student is eligible for a particular course but does it for all the courses in the proposed set of courses", context); |
| 69 | 0 | _createCheck(ProcessServiceConstants.CHECK_KEY_DOES_NOT_EXCEED_CREDIT_LIMIT, ProcessServiceConstants.MAXIMUM_VALUE_CHECK_TYPE_KEY, "", "", "", "", "does not exceed credit limit", "Checks that the student has not exceeded her credit limit", context); |
| 70 | |
|
| 71 | 0 | _createInstruction(ProcessServiceConstants.PROCESS_KEY_BASIC_ELIGIBILITY, "kuali.population.everyone", "kuali.check.is.alive", "A key piece of data is wrong on your biographic record. Please come to the Registrar's office to clear it up.", 1, false, false, false, context); |
| 72 | 0 | _createInstruction(ProcessServiceConstants.PROCESS_KEY_HOLDS_CLEARED, "kuali.population.everyone", "kuali.check.has.overdue.library.book", "Please note: you have an overdue library book", 3, true, true, true, context); |
| 73 | 0 | _createInstruction(ProcessServiceConstants.PROCESS_KEY_HOLDS_CLEARED, "kuali.population.everyone", "kuali.check.has.not.paid.bill.from.prior.term", "You have unpaid tuition charges from last term, please contact the bursars office to resolve this matter", 5, false, true, true, context); |
| 74 | 0 | _createInstruction(ProcessServiceConstants.PROCESS_KEY_ELIGIBILITY_FOR_TERM, "kuali.population.everyone", "kuali.check.student.has.basic.eligibility", "Something about you as a person or your relationship with this institution needs to be fixed", 1, false, false, false, context); |
| 75 | 0 | _createInstruction(ProcessServiceConstants.PROCESS_KEY_ELIGIBILITY_FOR_TERM, "kuali.population.everyone", "kuali.check.registration.period.is.open", "Registration period for this term has not yet begun", 3, false, true, true, context); |
| 76 | 0 | _createInstruction(ProcessServiceConstants.PROCESS_KEY_ELIGIBILITY_FOR_TERM, "kuali.population.everyone", "kuali.check.registration.period.is.not.closed", "Registration period for this term is closed", 4, false, true, true, context); |
| 77 | 0 | _createInstruction(ProcessServiceConstants.PROCESS_KEY_ELIGIBILITY_FOR_TERM, "kuali.population.everyone", "kuali.check.registration.holds.cleared", "You have one or more holds that need to be cleared", 5, false, true, true, context); |
| 78 | 0 | _createInstruction(ProcessServiceConstants.PROCESS_KEY_ELIGIBILITY_FOR_TERM, "kuali.population.summer.only.student", "kuali.check.is.not.summer.term", "Summer only students cannot register for fall, winter or spring terms", 9, false, true, true, context); |
| 79 | 0 | _createInstruction(ProcessServiceConstants.PROCESS_KEY_ELIGIBLE_FOR_COURSE, "kuali.population.everyone", "kuali.check.eligibility.for.term", "", 1, false, false, true, context); |
| 80 | 0 | _createInstruction(ProcessServiceConstants.PROCESS_KEY_ELIGIBLE_FOR_COURSE, "kuali.population.everyone", "kuali.check.has.the.necessary.prereq", "", 2, false, true, true, context); |
| 81 | 0 | _createInstruction(ProcessServiceConstants.PROCESS_KEY_ELIGIBLE_FOR_COURSES, "kuali.population.everyone", "kuali.check.student.has.eligibility.for.each.course", "", 1, false, false, true, context); |
| 82 | 0 | _createInstruction(ProcessServiceConstants.PROCESS_KEY_ELIGIBLE_FOR_COURSES, "kuali.population.everyone", "kuali.check.does.not.exceed.credit.limit", "You are exceeding your credit limit", 2, false, false, true, context); |
| 83 | 0 | } |
| 84 | |
|
| 85 | |
private void _createInstruction(String processKey, |
| 86 | |
String populationKey, |
| 87 | |
String checkKey, |
| 88 | |
String message, |
| 89 | |
int position, |
| 90 | |
boolean isWarning, |
| 91 | |
boolean continueOnFail, |
| 92 | |
boolean canBeExempted, |
| 93 | |
ContextInfo context) { |
| 94 | |
|
| 95 | 0 | InstructionInfo info = new InstructionInfo(); |
| 96 | 0 | info.setTypeKey(ProcessServiceConstants.INSTRUCTION_TYPE_KEY); |
| 97 | 0 | info.setStateKey(ProcessServiceConstants.INSTRUCTION_ENABLED_STATE_KEY); |
| 98 | 0 | info.setProcessKey(processKey); |
| 99 | 0 | info.setAppliedPopulationKeys(Arrays.asList(populationKey)); |
| 100 | 0 | info.setCheckKey(checkKey); |
| 101 | 0 | info.setMessage(new RichTextHelper().fromPlain(message)); |
| 102 | 0 | info.setPosition(position); |
| 103 | 0 | info.setContinueOnFail(continueOnFail); |
| 104 | 0 | info.setIsWarning(isWarning); |
| 105 | 0 | info.setIsExemptable(canBeExempted); |
| 106 | |
try { |
| 107 | 0 | info = this.createInstruction(info.getProcessKey(), info.getCheckKey(), info, context); |
| 108 | 0 | } catch (Exception ex) { |
| 109 | 0 | throw new RuntimeException("error creating exemption request", ex); |
| 110 | 0 | } |
| 111 | |
|
| 112 | 0 | } |
| 113 | |
|
| 114 | |
private ProcessInfo _createProcess(String key, String name, String descr, ContextInfo context) { |
| 115 | 0 | ProcessInfo info = new ProcessInfo(); |
| 116 | 0 | info.setKey(key); |
| 117 | 0 | info.setTypeKey(ProcessServiceConstants.PROCESS_TYPE_KEY); |
| 118 | 0 | info.setStateKey(ProcessServiceConstants.PROCESS_ENABLED_STATE_KEY); |
| 119 | 0 | info.setName(name); |
| 120 | 0 | info.setDescr(new RichTextHelper().fromPlain(descr)); |
| 121 | |
try { |
| 122 | 0 | info = this.createProcess(info.getKey(), info, context); |
| 123 | 0 | } catch (Exception ex) { |
| 124 | 0 | throw new RuntimeException("error creating exemption request", ex); |
| 125 | 0 | } |
| 126 | 0 | return info; |
| 127 | |
} |
| 128 | |
|
| 129 | |
private CheckInfo _createCheck(String key, String type, String issueId, String milestoneTypeKey, String agendaId, String processKey, String name, String descr, ContextInfo context) { |
| 130 | 0 | CheckInfo info = new CheckInfo(); |
| 131 | 0 | info.setKey(key); |
| 132 | 0 | info.setTypeKey(type); |
| 133 | 0 | info.setStateKey(ProcessServiceConstants.PROCESS_CHECK_STATE_ENABLED); |
| 134 | 0 | info.setName(name); |
| 135 | 0 | info.setIssueId(_toNull(issueId)); |
| 136 | 0 | info.setMilestoneTypeKey(_toNull(milestoneTypeKey)); |
| 137 | 0 | info.setAgendaId(_toNull(agendaId)); |
| 138 | 0 | info.setProcessKey(_toNull(processKey)); |
| 139 | 0 | info.setDescr(new RichTextHelper().fromPlain(descr)); |
| 140 | |
|
| 141 | |
try { |
| 142 | 0 | info = this.createCheck(key, info, context); |
| 143 | 0 | } catch (Exception ex) { |
| 144 | 0 | throw new RuntimeException("error creating exemption request", ex); |
| 145 | 0 | } |
| 146 | 0 | return info; |
| 147 | |
} |
| 148 | |
|
| 149 | |
private String _toNull(String str) { |
| 150 | 0 | if (str.isEmpty()) { |
| 151 | 0 | return null; |
| 152 | |
} |
| 153 | 0 | return str; |
| 154 | |
} |
| 155 | |
} |