View Javadoc

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.krad.maintenance.MaintainableImpl;
20  import org.kuali.rice.krad.maintenance.MaintenanceDocument;
21  import org.kuali.rice.krad.util.KRADConstants;
22  import org.kuali.student.enrollment.class2.courseoffering.util.CourseOfferingManagementUtil;
23  import org.kuali.student.enrollment.courseoffering.dto.FormatOfferingInfo;
24  import org.kuali.student.r2.common.util.ContextUtils;
25  import org.kuali.student.r2.common.util.constants.LuiServiceConstants;
26  
27  import javax.xml.namespace.QName;
28  import java.util.Map;
29  
30  /**
31   * This class provides a Maintable logic for Format Offerings
32   *
33   * @author Kuali Student Team
34   */
35  public class FormatOfferingInfoMaintainableImpl extends MaintainableImpl {
36      private static final long serialVersionUID = 1L;
37  
38      private static final String DEFAULT_DOCUMENT_DESC_FOR_CREATING_FORMAT_OFFERING =
39              "Create a new Format offering";
40      private static final String DEFAULT_DOCUMENT_DESC_FOR_EDITING_FORMAT_OFFERING =
41              "Edit an existing Format offering";
42      private static final String DEFAULT_DOCUMENT_DESC_FOR_COPYING_FORMAT_OFFERING =
43              "Copy from an existing Format offering to create a new one";
44  
45      @Override
46      public void saveDataObject() {
47          //System.out.println (">>> in save ");
48          FormatOfferingInfo formatOfferingInfoMaintenance = (FormatOfferingInfo) getDataObject();
49          if(getMaintenanceAction().equals(KRADConstants.MAINTENANCE_NEW_ACTION) ||
50                  getMaintenanceAction().equals(KRADConstants.MAINTENANCE_COPY_ACTION)) {
51              try {
52  
53                  CourseOfferingManagementUtil.getCourseOfferingService().createFormatOffering(formatOfferingInfoMaintenance.getCourseOfferingId(), formatOfferingInfoMaintenance.getFormatId(),
54                                                                                              LuiServiceConstants.FORMAT_OFFERING_TYPE_KEY, formatOfferingInfoMaintenance, ContextUtils.createDefaultContextInfo());
55                  //setDataObject(new FormatOfferingInfo(formatOfferingInfoCreated));
56              } catch (Exception e) {
57                  //logger.error("FormatOfferingInfoMaintenance - create new failed. ", e);
58                  throw new RuntimeException("FormatOfferingInfoMaintenance - create new failed. ", e);
59              }
60          }
61          else {   //should be edit action
62              try {
63                  CourseOfferingManagementUtil.getCourseOfferingService().updateFormatOffering(formatOfferingInfoMaintenance.getId(), formatOfferingInfoMaintenance, ContextUtils.createDefaultContextInfo());
64              } catch (Exception e) {
65                  //logger.error("FormatOfferingInfoMaintenance - edit failed. ", e);
66                  throw new RuntimeException("FormatOfferingInfoMaintenance - edit failed. ", e);
67              }
68          }
69      }
70  
71      /**
72       * @see org.kuali.rice.kns.maintenance.KualiMaintainableImpl#prepareForSave()
73       */
74      @Override
75      public void prepareForSave() {
76          System.out.println (">>> in prepareForSave ");
77          if (getMaintenanceAction().equalsIgnoreCase(KRADConstants.MAINTENANCE_NEW_ACTION)) {
78              FormatOfferingInfo formatOfferingInfoMaintenance = (FormatOfferingInfo) getDataObject();
79              formatOfferingInfoMaintenance.setTypeKey(LuiServiceConstants.FORMAT_OFFERING_TYPE_KEY);
80              formatOfferingInfoMaintenance.setStateKey(LuiServiceConstants.LUI_DRAFT_STATE_KEY);
81          }
82          super.prepareForSave();
83      }
84  
85      @Override
86      public Object retrieveObjectForEditOrCopy(MaintenanceDocument document, Map<String, String> dataObjectKeys) {
87          try {
88              FormatOfferingInfo info = CourseOfferingManagementUtil.getCourseOfferingService().getFormatOffering(dataObjectKeys.get("id"), ContextUtils.createDefaultContextInfo());
89              return info;
90          } catch (Exception e) {
91              throw new RuntimeException("FormatOfferingInfoMaintenance - edit/copy failed. ", e);
92          }
93      }
94  
95      /**
96       * @see org.kuali.rice.krad.maintenance.Maintainable#processAfterCopy
97       */
98      @Override
99      public void processAfterCopy(MaintenanceDocument document, Map<String, String[]> requestParameters) {
100         //set documentDescription to document.documentHeader.documentDescription
101         document.getDocumentHeader().setDocumentDescription(DEFAULT_DOCUMENT_DESC_FOR_COPYING_FORMAT_OFFERING);
102     }
103 
104     /**
105      * @see org.kuali.rice.krad.maintenance.Maintainable#processAfterEdit
106      */
107     @Override
108     public void processAfterEdit(MaintenanceDocument document, Map<String, String[]> requestParameters) {
109         //set documentDescription to document.documentHeader.documentDescription
110         document.getDocumentHeader().setDocumentDescription(DEFAULT_DOCUMENT_DESC_FOR_EDITING_FORMAT_OFFERING);
111 
112     }
113 
114     /**
115      * @see org.kuali.rice.krad.maintenance.Maintainable#processAfterNew
116      */
117     @Override
118     public void processAfterNew(MaintenanceDocument document, Map<String, String[]> requestParameters) {
119         //set documentDescription to document.documentHeader.documentDescription
120         document.getDocumentHeader().setDocumentDescription(DEFAULT_DOCUMENT_DESC_FOR_CREATING_FORMAT_OFFERING);
121     }
122 }