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 bobhurt on 10/31/12
16   */
17  package org.kuali.student.common.kitchensink;
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.student.r2.common.dto.ContextInfo;
23  import org.kuali.student.r2.common.util.ContextUtils;
24  import org.kuali.student.r2.core.constants.PopulationServiceConstants;
25  import org.kuali.student.r2.core.population.dto.PopulationInfo;
26  import org.kuali.student.r2.core.population.service.PopulationService;
27  
28  import javax.xml.namespace.QName;
29  import java.util.Map;
30  
31  /**
32   * This class does PopulationInfo maintenance
33   *
34   * @author Kuali Student Team
35   */
36  public class KitchenSinkPopulationInfoMaintainableImpl extends MaintainableImpl {
37  
38      private transient PopulationService populationService;
39      private transient ContextInfo contextInfo;
40  
41      @Override
42      public void saveDataObject() {
43          try {
44              PopulationInfo populationInfo = (PopulationInfo)getDataObject();
45              // code to update PopulationInfo
46          }
47          catch (Exception e) {
48              throw new RuntimeException(e);
49          }
50  
51      }
52  
53      @Override
54      public Object retrieveObjectForEditOrCopy(MaintenanceDocument document, Map<String, String> dataObjectKeys) {
55          try {
56              String populationId =  dataObjectKeys.get("id");
57              PopulationInfo populationInfo = getPopulationService().getPopulation(populationId, getContextInfo());
58              return populationInfo;
59          }
60          catch (Exception e) {
61              throw new RuntimeException("Could not retrieve PopulationInfo for edit", e);
62          }
63      }
64  /*
65      @Override
66      public void prepareForSave() {
67          if (getMaintenanceAction().equalsIgnoreCase(KRADConstants.MAINTENANCE_NEW_ACTION)) {
68              PopulationInfo populationInfo = (PopulationInfo)getDataObject();
69              populationInfo.setStateKey(PopulationServiceConstants.POPULATION_ACTIVE_STATE_KEY);
70              populationInfo.setTypeKey(PopulationServiceConstants.POPULATION_STUDENT_TYPE_KEY);
71          }
72          super.prepareForSave();
73      }
74  
75      @Override
76      public void processAfterEdit(MaintenanceDocument document, Map<String, String[]> requestParameters) {
77          // document description is required for save
78          document.getDocumentHeader().setDocumentDescription("Edit Population Info");
79  
80      }
81  */
82  
83      private ContextInfo getContextInfo() {
84          if (null == contextInfo) {
85              contextInfo = ContextUtils.getContextInfo();
86          }
87          return contextInfo;
88      }
89  
90      private PopulationService getPopulationService() {
91          if (populationService == null) {
92              populationService = (PopulationService) GlobalResourceLoader.getService(new QName(PopulationServiceConstants.NAMESPACE, "PopulationService"));
93          }
94          return populationService;
95      }
96  
97  }