Coverage Report - org.kuali.student.enrollment.class2.acal.service.AcademicCalendarInfoMaintainableImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
AcademicCalendarInfoMaintainableImpl
0%
0/51
0%
0/10
4.167
 
 1  
 package org.kuali.student.enrollment.class2.acal.service;
 2  
 
 3  
 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
 4  
 import org.kuali.rice.krad.maintenance.MaintainableImpl;
 5  
 import org.kuali.rice.krad.maintenance.MaintenanceDocument;
 6  
 import org.kuali.rice.krad.util.KRADConstants;
 7  
 import org.kuali.student.enrollment.acal.dto.AcademicCalendarInfo;
 8  
 import org.kuali.student.enrollment.acal.service.AcademicCalendarService;
 9  
 import org.kuali.student.r2.common.dto.ContextInfo;
 10  
 import org.kuali.student.r2.common.exceptions.*;
 11  
 import org.kuali.student.r2.common.util.constants.AtpServiceConstants;
 12  
 
 13  
 import javax.xml.namespace.QName;
 14  
 import java.util.Calendar;
 15  
 import java.util.Date;
 16  
 import java.util.Map;
 17  
 
 18  
 //Core slice class.
 19  
 @Deprecated
 20  0
 public class AcademicCalendarInfoMaintainableImpl extends MaintainableImpl {
 21  
         private static final long serialVersionUID = 1L;        
 22  
         
 23  
     public final static String ACADEMIC_CALENDAR_KEY_PREFIX = "kuali.academic.calendar.";
 24  
     public final static String CREDENTIAL_PROGRAM_TYPE_KEY_PREFIX = "kuali.lu.type.credential.";
 25  
     
 26  
     private transient AcademicCalendarService academicCalendarService;
 27  
   
 28  
     @Override
 29  
     public void saveDataObject() {
 30  0
         AcademicCalendarInfo academicCalendarInfo = (AcademicCalendarInfo)getDataObject();
 31  0
         String academicCalendarKey = getAcademicCalendarKey (academicCalendarInfo);
 32  0
         academicCalendarInfo.setId(academicCalendarKey);
 33  0
         academicCalendarInfo.setStateKey(AtpServiceConstants.ATP_OFFICIAL_STATE_KEY);
 34  0
         System.out.println(">>>>adminOrgId = "+academicCalendarInfo.getAdminOrgId());
 35  
         try{
 36  0
                 if(getMaintenanceAction().equals(KRADConstants.MAINTENANCE_NEW_ACTION) ||
 37  
                 getMaintenanceAction().equals(KRADConstants.MAINTENANCE_COPY_ACTION)) {   
 38  0
                         getAcademicCalendarService().createAcademicCalendar(academicCalendarKey, academicCalendarInfo, new ContextInfo());
 39  
                 }
 40  
                 else {
 41  0
                         getAcademicCalendarService().updateAcademicCalendar(academicCalendarKey, academicCalendarInfo, new ContextInfo());
 42  
                 }
 43  0
         }catch (DataValidationErrorException dvee){
 44  
             
 45  0
         }catch (InvalidParameterException ipe){
 46  
 
 47  0
         }catch (MissingParameterException mpe){
 48  
 
 49  0
         }catch (OperationFailedException ofe){
 50  
            
 51  0
         }catch (PermissionDeniedException pde){
 52  
 
 53  0
         }catch (ReadOnlyException roe){
 54  
 
 55  0
         }catch (DoesNotExistException dee){
 56  
             
 57  0
         }catch (VersionMismatchException vme){
 58  
             
 59  0
         }       
 60  
         
 61  0
     }
 62  
 
 63  
     @Override
 64  
     public Object retrieveObjectForEditOrCopy(MaintenanceDocument document, Map<String, String> dataObjectKeys) {
 65  0
             ContextInfo context = new ContextInfo();
 66  
             try{
 67  0
                     return getAcademicCalendarService().getAcademicCalendar(dataObjectKeys.get("key"), context);
 68  
             
 69  0
         }catch (InvalidParameterException ipe){
 70  
             
 71  0
         }catch (MissingParameterException mpe){
 72  
             
 73  0
         }catch (OperationFailedException ofe){
 74  
            
 75  0
         }catch (PermissionDeniedException pde){
 76  
             
 77  0
         }catch (DoesNotExistException dee){
 78  
             
 79  0
         }
 80  0
         return null;
 81  
   
 82  
     }
 83  
     
 84  
   
 85  
     /**
 86  
      * @see org.kuali.rice.kns.maintenance.KualiMaintainableImpl#prepareForSave()
 87  
      */
 88  
     @Override
 89  
     public void prepareForSave() {
 90  0
             System.out.println (">>> in prepareForSave ");
 91  0
         if (getMaintenanceAction().equalsIgnoreCase(KRADConstants.MAINTENANCE_NEW_ACTION)) {
 92  0
                 AcademicCalendarInfo newAcal = (AcademicCalendarInfo)getDataObject();           
 93  0
                 newAcal.setTypeKey("kuali.atp.type.AcademicCalendar");
 94  0
             newAcal.setStateKey(AtpServiceConstants.ATP_OFFICIAL_STATE_KEY);
 95  
         }
 96  0
         super.prepareForSave();
 97  0
     }
 98  
     
 99  
     protected AcademicCalendarService getAcademicCalendarService() {
 100  0
          if(academicCalendarService == null) {
 101  0
                  academicCalendarService = (AcademicCalendarService) GlobalResourceLoader.getService(new QName("http://student.kuali.org/wsdl/acal","AcademicCalendarService"));
 102  
         }
 103  
 
 104  0
         return academicCalendarService;
 105  
     }
 106  
     /*
 107  
      *  Based on Norm's suggestion at 
 108  
      *  https://wiki.kuali.org/display/STUDENT/How+to+Calculate+Keys+for+Academic+Calendar+Entities
 109  
      *  AcademicCalendarKey should be 
 110  
      *  kuali.academic.calendar.<last part of credentialProgramTypeKey>.<yearOfStartDate>-<yearOfEndDate>
 111  
      */
 112  
     private String getAcademicCalendarKey(AcademicCalendarInfo academicCalendarInfo){
 113  0
         String academicCalendarKey = new String (ACADEMIC_CALENDAR_KEY_PREFIX);
 114  
         String adminOrg;
 115  
         
 116  0
         String adminOrgId = academicCalendarInfo.getAdminOrgId();
 117  0
         if (adminOrgId.startsWith(CREDENTIAL_PROGRAM_TYPE_KEY_PREFIX)){
 118  0
             adminOrg  = adminOrgId.substring(25);
 119  
         }
 120  
         else {
 121  0
             adminOrg = adminOrgId;
 122  
         }        
 123  0
         String yearOfStartDate = getYearFromDate(academicCalendarInfo.getStartDate());
 124  0
         String yearOfEndDate = getYearFromDate(academicCalendarInfo.getEndDate());
 125  0
         academicCalendarKey = academicCalendarKey.concat(adminOrg.toLowerCase()+"."+yearOfStartDate+"-"+yearOfEndDate);
 126  0
         return academicCalendarKey;       
 127  
         
 128  
     }
 129  
     
 130  
     private String getYearFromDate(Date date){
 131  0
             Calendar cal = Calendar.getInstance();
 132  0
             cal.setTime(date);
 133  0
             int year = cal.get(Calendar.YEAR);
 134  0
             return new Integer(year).toString();
 135  
     }
 136  
 }