Coverage Report - org.kuali.student.r2.core.class1.process.ProcessPocProcessServiceDecorator
 
Classes in this File Line Coverage Branch Coverage Complexity
ProcessPocProcessServiceDecorator
0%
0/90
0%
0/4
3
 
 1  
 /*
 2  
  * To change this template, choose Tools | Templates
 3  
  * and open the template in the editor.
 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  
  * @author nwright
 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.DIRECT_RULE_CHECK_TYPE_KEY, "", "", "kuali.agenda.is.alive", "", "is alive", "Checks if student is actually alive", context);
 59  0
         _createCheck(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.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.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.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.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.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.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.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.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.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.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.setStateKey(ProcessServiceConstants.INSTRUCTION_ENABLED_STATE_KEY);
 97  0
         info.setProcessKey(processKey);
 98  0
         info.setAppliedPopulationKeys(Arrays.asList(populationKey));
 99  0
         info.setCheckKey(checkKey);
 100  0
         info.setMessage(new RichTextHelper().fromPlain(message));
 101  0
         info.setPosition(position);
 102  0
         info.setContinueOnFail(continueOnFail);
 103  0
         info.setIsWarning(isWarning);
 104  0
         info.setIsExemptable(canBeExempted);
 105  
         try {
 106  0
             info = this.createInstruction(ProcessServiceConstants.INSTRUCTION_TYPE_KEY, info.getProcessKey(), info.getCheckKey(), info, context);
 107  0
         } catch (Exception ex) {
 108  0
             throw new RuntimeException("error creating exemption request", ex);
 109  0
         }
 110  
 
 111  0
     }
 112  
 
 113  
     private ProcessInfo _createProcess(String key, String name, String descr, ContextInfo context) {
 114  0
         ProcessInfo info = new ProcessInfo();
 115  0
         info.setKey(key);
 116  0
         info.setStateKey(ProcessServiceConstants.PROCESS_ENABLED_STATE_KEY);
 117  0
         info.setName(name);
 118  0
         info.setDescr(new RichTextHelper().fromPlain(descr));
 119  
         try {
 120  0
             info = this.createProcess(ProcessServiceConstants.PROCESS_TYPE_KEY, info.getKey(), info, context);
 121  0
         } catch (Exception ex) {
 122  0
             throw new RuntimeException("error creating exemption request", ex);
 123  0
         }
 124  0
         return info;
 125  
     }
 126  
 
 127  
     private CheckInfo _createCheck(String type, String issueId, String milestoneTypeKey, String agendaId, String processKey, String name, String descr, ContextInfo context) {
 128  0
         CheckInfo info = new CheckInfo();
 129  
 
 130  0
         info.setTypeKey(type);
 131  0
         info.setStateKey(ProcessServiceConstants.PROCESS_CHECK_STATE_ENABLED);
 132  0
         info.setName(name);
 133  0
         info.setIssueId(_toNull(issueId));
 134  0
         info.setMilestoneTypeKey(_toNull(milestoneTypeKey));
 135  0
         info.setAgendaId(_toNull(agendaId));
 136  0
         info.setProcessKey(_toNull(processKey));
 137  0
         info.setDescr(new RichTextHelper().fromPlain(descr));
 138  
 
 139  
         try {
 140  0
             info = this.createCheck(type, info, context);
 141  0
         } catch (Exception ex) {
 142  0
             throw new RuntimeException("error creating exemption request", ex);
 143  0
         }
 144  0
         return info;
 145  
     }
 146  
 
 147  
     private String _toNull(String str) {
 148  0
         if (str.isEmpty()) {
 149  0
             return null;
 150  
         }
 151  0
         return str;
 152  
     }
 153  
 }