Coverage Report - org.kuali.student.enrollment.class2.courseoffering.service.impl.ActivityOfferingMaintainableImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
ActivityOfferingMaintainableImpl
0%
0/43
0%
0/12
3
 
 1  
 package org.kuali.student.enrollment.class2.courseoffering.service.impl;
 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.GlobalVariables;
 7  
 import org.kuali.rice.krad.util.KRADConstants;
 8  
 import org.kuali.student.enrollment.class2.courseoffering.dto.ActivityOfferingFormObject;
 9  
 import org.kuali.student.enrollment.class2.courseoffering.service.ActivityOfferingMaintainable;
 10  
 import org.kuali.student.enrollment.courseoffering.dto.ActivityOfferingInfo;
 11  
 import org.kuali.student.enrollment.courseoffering.service.CourseOfferingService;
 12  
 import org.kuali.student.r2.common.dto.ContextInfo;
 13  
 import org.kuali.student.r2.common.dto.LocaleInfo;
 14  
 import org.kuali.student.r2.common.util.constants.CourseOfferingServiceConstants;
 15  
 import org.kuali.student.r2.common.util.constants.LuiServiceConstants;
 16  
 import org.kuali.student.r2.common.util.constants.StateServiceConstants;
 17  
 import org.kuali.student.r2.common.util.constants.TypeServiceConstants;
 18  
 import org.kuali.student.r2.core.state.service.StateService;
 19  
 import org.kuali.student.r2.core.type.service.TypeService;
 20  
 
 21  
 import javax.xml.namespace.QName;
 22  
 import java.util.Locale;
 23  
 import java.util.Map;
 24  
 
 25  0
 public class ActivityOfferingMaintainableImpl extends MaintainableImpl implements ActivityOfferingMaintainable {
 26  
 
 27  
     private transient CourseOfferingService courseOfferingService;
 28  
     private ContextInfo contextInfo;
 29  
     private transient TypeService typeService;
 30  
     private transient StateService stateService;
 31  
 
 32  
     @Override
 33  
     public void saveDataObject() {
 34  0
         if(getMaintenanceAction().equals(KRADConstants.MAINTENANCE_NEW_ACTION) ||
 35  
                 getMaintenanceAction().equals(KRADConstants.MAINTENANCE_COPY_ACTION)) {
 36  
             try {
 37  0
                 ActivityOfferingFormObject activityOfferingFormObject = (ActivityOfferingFormObject) getDataObject();
 38  0
                 ActivityOfferingInfo activityOfferingInfo = getCourseOfferingService().createActivityOffering(activityOfferingFormObject.getAoInfo().getFormatOfferingId(),activityOfferingFormObject.getAoInfo().getActivityId(), LuiServiceConstants.LECTURE_ACTIVITY_OFFERING_TYPE_KEY,activityOfferingFormObject.getAoInfo(),getContextInfo());
 39  0
                 setDataObject(new ActivityOfferingFormObject(activityOfferingInfo));
 40  0
             } catch (Exception e) {
 41  0
                 throw new RuntimeException(e);
 42  0
             }
 43  
         }
 44  
         else {   //should be edit action
 45  0
             ActivityOfferingFormObject activityOfferingFormObject = (ActivityOfferingFormObject) getDataObject();
 46  
             try {
 47  0
                 ActivityOfferingInfo activityOfferingInfo = getCourseOfferingService().updateActivityOffering(activityOfferingFormObject.getAoInfo().getId(), activityOfferingFormObject.getAoInfo(), getContextInfo());
 48  0
             } catch (Exception e) {
 49  0
                 throw new RuntimeException(e);
 50  0
             }
 51  
         }
 52  0
     }
 53  
 
 54  
     @Override
 55  
     public Object retrieveObjectForEditOrCopy(MaintenanceDocument document, Map<String, String> dataObjectKeys) {
 56  
         try {
 57  0
             ActivityOfferingInfo info = getCourseOfferingService().getActivityOffering(dataObjectKeys.get("aoInfo.id"),getContextInfo());
 58  0
             ActivityOfferingFormObject formObject = new ActivityOfferingFormObject(info);
 59  0
             document.getNewMaintainableObject().setDataObject(formObject);
 60  0
             document.getOldMaintainableObject().setDataObject(formObject);
 61  
 //            StateInfo state = getStateService().getState(formObject.getDto().getStateKey(), getContextInfo());
 62  
 //            formObject.setStateName(state.getName());
 63  0
             return formObject;
 64  0
         } catch (Exception e) {
 65  0
             throw new RuntimeException(e);
 66  
         }
 67  
     }
 68  
 
 69  
     @Override
 70  
     public void processAfterNew(MaintenanceDocument document, Map<String, String[]> requestParameters) {
 71  0
         ActivityOfferingFormObject formObject = (ActivityOfferingFormObject)document.getNewMaintainableObject().getDataObject();
 72  0
         document.getDocumentHeader().setDocumentDescription("Activity Offering");
 73  
         try {
 74  
 //            StateInfo state = getStateService().getState(formObject.getDto().getStateKey(), getContextInfo());
 75  
 //            formObject.setStateName(state.getName());
 76  
         } catch (Exception e) {
 77  
             e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
 78  0
         }
 79  0
     }
 80  
 
 81  
     public ContextInfo getContextInfo() {
 82  0
         if (null == contextInfo) {
 83  0
             contextInfo = new ContextInfo();
 84  0
             contextInfo.setAuthenticatedPrincipalId(GlobalVariables.getUserSession().getPrincipalId());
 85  0
             contextInfo.setPrincipalId(GlobalVariables.getUserSession().getPrincipalId());
 86  0
             LocaleInfo localeInfo = new LocaleInfo();
 87  0
             localeInfo.setLocaleLanguage(Locale.getDefault().getLanguage());
 88  0
             localeInfo.setLocaleRegion(Locale.getDefault().getCountry());
 89  0
             contextInfo.setLocale(localeInfo);
 90  
         }
 91  0
         return contextInfo;
 92  
     }
 93  
 
 94  
     public TypeService getTypeService() {
 95  0
            if(typeService == null) {
 96  0
              typeService = (TypeService) GlobalResourceLoader.getService(new QName(TypeServiceConstants.NAMESPACE, TypeServiceConstants.SERVICE_NAME_LOCAL_PART));
 97  
         }
 98  0
         return this.typeService;
 99  
     }
 100  
 
 101  
     public StateService getStateService() {
 102  0
            if(stateService == null) {
 103  0
              stateService = (StateService) GlobalResourceLoader.getService(new QName(StateServiceConstants.NAMESPACE, StateServiceConstants.SERVICE_NAME_LOCAL_PART));
 104  
         }
 105  0
         return stateService;
 106  
     }
 107  
 
 108  
     protected CourseOfferingService getCourseOfferingService() {
 109  0
         if (courseOfferingService == null) {
 110  0
             courseOfferingService = (CourseOfferingService) GlobalResourceLoader.getService(new QName(CourseOfferingServiceConstants.NAMESPACE, "CourseOfferingService"));
 111  
         }
 112  0
         return courseOfferingService;
 113  
     }
 114  
 }