Coverage Report - org.kuali.student.process.poc.ProcessPocExemptionServiceDecorator
 
Classes in this File Line Coverage Branch Coverage Complexity
ProcessPocExemptionServiceDecorator
0%
0/63
N/A
3
 
 1  
 /*
 2  
  * To change this template, choose Tools | Templates
 3  
  * and open the template in the editor.
 4  
  */
 5  
 package org.kuali.student.process.poc;
 6  
 
 7  
 import java.text.ParseException;
 8  
 import java.text.SimpleDateFormat;
 9  
 import java.util.Date;
 10  
 import org.kuali.student.r2.common.dto.ContextInfo;
 11  
 import org.kuali.student.r2.common.util.constants.AtpServiceConstants;
 12  
 import org.kuali.student.r2.common.util.constants.ExemptionServiceConstants;
 13  
 import org.kuali.student.r2.common.util.constants.ProcessServiceConstants;
 14  
 import org.kuali.student.r2.core.exemption.dto.DateOverrideInfo;
 15  
 import org.kuali.student.r2.core.exemption.dto.ExemptionInfo;
 16  
 import org.kuali.student.r2.core.exemption.dto.ExemptionRequestInfo;
 17  
 import org.kuali.student.r2.core.exemption.service.ExemptionService;
 18  
 import org.kuali.student.r2.core.exemption.service.ExemptionServiceDecorator;
 19  
 
 20  
 /**
 21  
  *
 22  
  * @author nwright
 23  
  */
 24  
 public class ProcessPocExemptionServiceDecorator extends ExemptionServiceDecorator {
 25  
 
 26  
     public ProcessPocExemptionServiceDecorator(ExemptionService nextDecorator) {
 27  0
         super();
 28  0
         setNextDecorator(nextDecorator);
 29  0
         initializeData();
 30  0
     }
 31  
 
 32  
     private void initializeData() {
 33  0
         ContextInfo context = new ContextInfo();
 34  0
         context.setPrincipalId("POC-Initializer");
 35  
 
 36  0
         ExemptionRequestInfo request1 = _createRequest(ProcessPocConstants.PERSON_ID_JOHNNY_MANNING_2374, context);
 37  0
         ExemptionInfo exemption1 = this._createCheckExemption(request1, context);
 38  
 
 39  0
         ExemptionRequestInfo request2 = _createRequest(ProcessPocConstants.PERSON_ID_EDDIE_PITTMAN_2406, context);
 40  
         Date endDate2;
 41  
         try {
 42  0
             endDate2 = new SimpleDateFormat("yyyy-MM-dd").parse("2011-12-31");
 43  0
         } catch (ParseException ex) {
 44  0
             throw new RuntimeException(ex);
 45  0
         }
 46  0
         ExemptionInfo exemption2 = this._createMilestoneDateExemption(request2, endDate2, context);
 47  
 
 48  0
         ExemptionRequestInfo request3 = _createRequest(ProcessPocConstants.PERSON_ID_TRACY_BURTON_2132, context);
 49  
         Date endDate3;
 50  
         try {
 51  0
             endDate3 = new SimpleDateFormat("yyyy-MM-dd").parse("2011-11-30");
 52  0
         } catch (ParseException ex) {
 53  0
             throw new RuntimeException(ex);
 54  0
         }
 55  0
         ExemptionInfo exemption3 = this._createMilestoneDateExemption(request3, endDate3, context);
 56  0
     }
 57  
 
 58  
     private ExemptionRequestInfo _createRequest(String personId, ContextInfo context) {
 59  0
         ExemptionRequestInfo request = new ExemptionRequestInfo();
 60  0
         request.setTypeKey(ExemptionServiceConstants.GENERIC_EXEMPTION_REQUEST_TYPE_KEY);
 61  0
         request.setStateKey(ExemptionServiceConstants.EXEMPTION_REQUEST_APPROVED_STATE_KEY);
 62  0
         request.setRequesterId(personId);
 63  0
         request.setPersonId(personId);
 64  0
         request.setRequestDate(new Date());
 65  0
         request.setName("test exemption for " + personId);
 66  
         try {
 67  0
             request = this.createExemptionRequest(request, context);
 68  0
         } catch (Exception ex) {
 69  0
             throw new RuntimeException("error creating exemption request", ex);
 70  0
         }
 71  0
         return request;
 72  
     }
 73  
 
 74  
     private ExemptionInfo _createCheckExemption(ExemptionRequestInfo request, ContextInfo context) {
 75  0
         ExemptionInfo info = new ExemptionInfo();
 76  0
         info.setPersonId(request.getPersonId());
 77  0
         info.setExemptionRequestId(request.getId());
 78  0
         info.setTypeKey(ExemptionServiceConstants.CHECK_EXEMPTION_TYPE_KEY);
 79  0
         info.setStateKey(ExemptionServiceConstants.EXEMPTION_ACTIVE_STATE_KEY);
 80  0
         info.setName(request.getName());
 81  0
         info.setProcessKey(ProcessServiceConstants.PROCESS_KEY_ELIGIBILITY_FOR_TERM);
 82  0
         info.setCheckKey(ProcessServiceConstants.CHECK_KEY_REGISTRATION_PERIOD_IS_OPEN);
 83  
         try {
 84  0
             info = this.createExemption(info.getExemptionRequestId(), info, context);
 85  0
         } catch (Exception ex) {
 86  0
             throw new RuntimeException("error creating exemption request", ex);
 87  0
         }
 88  0
         return info;
 89  
     }
 90  
 
 91  
     private ExemptionInfo _createMilestoneDateExemption(ExemptionRequestInfo request, Date endDate, ContextInfo context) {
 92  0
         ExemptionInfo info = new ExemptionInfo();
 93  0
         info.setPersonId(request.getPersonId());
 94  0
         info.setExemptionRequestId(request.getId());
 95  0
         info.setTypeKey(ExemptionServiceConstants.MILESTONE_DATE_EXEMPTION_TYPE_KEY);
 96  0
         info.setStateKey(ExemptionServiceConstants.EXEMPTION_ACTIVE_STATE_KEY);
 97  0
         info.setName(request.getName());
 98  0
         info.setProcessKey(ProcessServiceConstants.PROCESS_KEY_ELIGIBILITY_FOR_TERM);
 99  0
         info.setCheckKey(ProcessServiceConstants.CHECK_KEY_REGISTRATION_PERIOD_IS_NOT_CLOSED);
 100  0
         DateOverrideInfo dateOverride = new DateOverrideInfo();
 101  0
         dateOverride.setMilestoneId(AtpServiceConstants.MILESTONE_REGISTRATION_PERIOD_TYPE_KEY);
 102  0
         dateOverride.setEffectiveEndDate(endDate);
 103  0
         info.setDateOverride(dateOverride);
 104  
         try {
 105  0
             info = this.createExemption(info.getExemptionRequestId(), info, context);
 106  0
         } catch (Exception ex) {
 107  0
             throw new RuntimeException("error creating exemption request", ex);
 108  0
         }
 109  0
         return info;
 110  
     }
 111  
 }