Coverage Report - org.kuali.student.enrollment.class2.courseoffering.service.impl.FormatOfferingInfoMaintainableImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
FormatOfferingInfoMaintainableImpl
0%
0/45
0%
0/10
2.5
 
 1  
 /**
 2  
  * Copyright 2012 The Kuali Foundation Licensed under the
 3  
  * Educational Community License, Version 2.0 (the "License"); you may
 4  
  * not use this file except in compliance with the License. You may
 5  
  * obtain a copy of the License at
 6  
  *
 7  
  * http://www.osedu.org/licenses/ECL-2.0
 8  
  *
 9  
  * Unless required by applicable law or agreed to in writing,
 10  
  * software distributed under the License is distributed on an "AS IS"
 11  
  * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 12  
  * or implied. See the License for the specific language governing
 13  
  * permissions and limitations under the License.
 14  
  *
 15  
  * Created by David Yin on 5/15/12
 16  
  */
 17  
 package org.kuali.student.enrollment.class2.courseoffering.service.impl;
 18  
 
 19  
 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
 20  
 import org.kuali.rice.krad.maintenance.MaintainableImpl;
 21  
 import org.kuali.rice.krad.maintenance.MaintenanceDocument;
 22  
 import org.kuali.rice.krad.util.GlobalVariables;
 23  
 import org.kuali.rice.krad.util.KRADConstants;
 24  
 import org.kuali.student.enrollment.class2.courseoffering.dto.FormatOfferingInfoFormObject;
 25  
 import org.kuali.student.enrollment.courseoffering.dto.FormatOfferingInfo;
 26  
 import org.kuali.student.enrollment.courseoffering.service.CourseOfferingService;
 27  
 import org.kuali.student.r2.common.dto.ContextInfo;
 28  
 import org.kuali.student.r2.common.dto.LocaleInfo;
 29  
 import org.kuali.student.r2.common.exceptions.*;
 30  
 import org.kuali.student.r2.common.util.constants.AtpServiceConstants;
 31  
 import org.kuali.student.r2.common.util.constants.CourseOfferingServiceConstants;
 32  
 import org.kuali.student.r2.common.util.constants.LuiServiceConstants;
 33  
 import org.kuali.student.r2.core.state.service.StateService;
 34  
 import org.kuali.student.r2.core.type.service.TypeService;
 35  
 
 36  
 import javax.xml.namespace.QName;
 37  
 import java.util.Locale;
 38  
 import java.util.Map;
 39  
 
 40  
 /**
 41  
  * This class //TODO ...
 42  
  *
 43  
  * @author Kuali Student Team
 44  
  */
 45  0
 public class FormatOfferingInfoMaintainableImpl extends MaintainableImpl {
 46  
     private static final long serialVersionUID = 1L;
 47  
 
 48  
     private static final String DEFAULT_DOCUMENT_DESC_FOR_CREATING_FORMAT_OFFERING =
 49  
             "Create a new Format offering";
 50  
     private static final String DEFAULT_DOCUMENT_DESC_FOR_EDITING_FORMAT_OFFERING =
 51  
             "Edit an existing Format offering";
 52  
     private static final String DEFAULT_DOCUMENT_DESC_FOR_COPYING_FORMAT_OFFERING =
 53  
             "Copy from an existing Format offering to create a new one";
 54  
 
 55  
     private transient CourseOfferingService courseOfferingService;
 56  
     private ContextInfo contextInfo;
 57  
 
 58  
     @Override
 59  
     public void saveDataObject() {
 60  0
         FormatOfferingInfo formatOfferingInfoMaintenance = (FormatOfferingInfo) getDataObject();
 61  0
         if(getMaintenanceAction().equals(KRADConstants.MAINTENANCE_NEW_ACTION) ||
 62  
                 getMaintenanceAction().equals(KRADConstants.MAINTENANCE_COPY_ACTION)) {
 63  
             try {
 64  0
                 FormatOfferingInfo formatOfferingInfoCreated = getCourseOfferingService().createFormatOffering(formatOfferingInfoMaintenance.getCourseOfferingId(), formatOfferingInfoMaintenance.getFormatId(),
 65  
                                                                                             LuiServiceConstants.FORMAT_OFFERING_TYPE_KEY, formatOfferingInfoMaintenance, getContextInfo());
 66  0
                 setDataObject(new FormatOfferingInfo(formatOfferingInfoCreated));
 67  0
             } catch (Exception e) {
 68  0
                 throw new RuntimeException(e);
 69  0
             }
 70  
         }
 71  
         else {   //should be edit action
 72  
             try {
 73  0
                 FormatOfferingInfo formatOfferingInfoUpdated = getCourseOfferingService().updateFormatOffering(formatOfferingInfoMaintenance.getId(), formatOfferingInfoMaintenance, getContextInfo());
 74  0
             } catch (Exception e) {
 75  0
                 throw new RuntimeException(e);
 76  0
             }
 77  
         }
 78  0
     }
 79  
 
 80  
     /**
 81  
      * @see org.kuali.rice.kns.maintenance.KualiMaintainableImpl#prepareForSave()
 82  
      */
 83  
     @Override
 84  
     public void prepareForSave() {
 85  0
         System.out.println (">>> in prepareForSave ");
 86  0
         if (getMaintenanceAction().equalsIgnoreCase(KRADConstants.MAINTENANCE_NEW_ACTION)) {
 87  0
             FormatOfferingInfo formatOfferingInfoMaintenance = (FormatOfferingInfo) getDataObject();
 88  0
             formatOfferingInfoMaintenance.setTypeKey("kuali.atp.type.FormatOfferingInfo");
 89  0
             formatOfferingInfoMaintenance.setStateKey(AtpServiceConstants.ATP_OFFICIAL_STATE_KEY);
 90  
         }
 91  0
         super.prepareForSave();
 92  0
     }
 93  
 
 94  
     @Override
 95  
     public Object retrieveObjectForEditOrCopy(MaintenanceDocument document, Map<String, String> dataObjectKeys) {
 96  
         try {
 97  0
             FormatOfferingInfo info = getCourseOfferingService().getFormatOffering(dataObjectKeys.get("formatOfferingInfo.id"), getContextInfo());
 98  0
             FormatOfferingInfoFormObject formObject = new FormatOfferingInfoFormObject(info);
 99  0
             document.getNewMaintainableObject().setDataObject(formObject);
 100  0
             document.getOldMaintainableObject().setDataObject(formObject);
 101  
 //            StateInfo state = getStateService().getState(formObject.getDto().getStateKey(), getContextInfo());
 102  
 //            formObject.setStateName(state.getName());
 103  0
             return formObject;
 104  0
         } catch (Exception e) {
 105  0
             throw new RuntimeException(e);
 106  
         }
 107  
     }
 108  
 
 109  
     /**
 110  
      * @see org.kuali.rice.krad.maintenance.Maintainable#processAfterCopy
 111  
      */
 112  
     @Override
 113  
     public void processAfterCopy(MaintenanceDocument document, Map<String, String[]> requestParameters) {
 114  
         //set documentDescription to document.documentHeader.documentDescription
 115  0
         document.getDocumentHeader().setDocumentDescription(DEFAULT_DOCUMENT_DESC_FOR_COPYING_FORMAT_OFFERING);
 116  0
     }
 117  
 
 118  
     /**
 119  
      * @see org.kuali.rice.krad.maintenance.Maintainable#processAfterEdit
 120  
      */
 121  
     @Override
 122  
     public void processAfterEdit(MaintenanceDocument document, Map<String, String[]> requestParameters) {
 123  
         //set documentDescription to document.documentHeader.documentDescription
 124  0
         document.getDocumentHeader().setDocumentDescription(DEFAULT_DOCUMENT_DESC_FOR_EDITING_FORMAT_OFFERING);
 125  
 
 126  0
     }
 127  
 
 128  
     /**
 129  
      * @see org.kuali.rice.krad.maintenance.Maintainable#processAfterNew
 130  
      */
 131  
     @Override
 132  
     public void processAfterNew(MaintenanceDocument document, Map<String, String[]> requestParameters) {
 133  
         //set documentDescription to document.documentHeader.documentDescription
 134  0
         document.getDocumentHeader().setDocumentDescription(DEFAULT_DOCUMENT_DESC_FOR_CREATING_FORMAT_OFFERING);
 135  
 
 136  0
     }
 137  
 
 138  
     public ContextInfo getContextInfo() {
 139  0
         if (null == contextInfo) {
 140  0
             contextInfo = new ContextInfo();
 141  0
             contextInfo.setAuthenticatedPrincipalId(GlobalVariables.getUserSession().getPrincipalId());
 142  0
             contextInfo.setPrincipalId(GlobalVariables.getUserSession().getPrincipalId());
 143  0
             LocaleInfo localeInfo = new LocaleInfo();
 144  0
             localeInfo.setLocaleLanguage(Locale.getDefault().getLanguage());
 145  0
             localeInfo.setLocaleRegion(Locale.getDefault().getCountry());
 146  0
             contextInfo.setLocale(localeInfo);
 147  
         }
 148  0
         return contextInfo;
 149  
     }
 150  
 
 151  
     protected CourseOfferingService getCourseOfferingService() {
 152  0
         if (courseOfferingService == null) {
 153  0
             courseOfferingService = (CourseOfferingService) GlobalResourceLoader.getService(new QName(CourseOfferingServiceConstants.NAMESPACE, "CourseOfferingService"));
 154  
         }
 155  0
         return courseOfferingService;
 156  
     }
 157  
 }
 158