View Javadoc

1   /*
2    * Copyright 2010 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  
16  package org.kuali.student.lum.common.server;
17  
18  import org.kuali.student.common.exceptions.DoesNotExistException;
19  import org.kuali.student.common.exceptions.InvalidParameterException;
20  import org.kuali.student.common.ui.server.gwt.AbstractDataService;
21  import org.kuali.student.lum.lo.dto.LoCategoryInfo;
22  import org.kuali.student.lum.lo.dto.LoInfo;
23  import org.kuali.student.lum.lo.service.LearningObjectiveService;
24  
25  import org.kuali.student.lum.program.dto.MajorDisciplineInfo;
26  import java.util.Map;
27  
28  public class LoCategoryDataService extends AbstractDataService {
29  
30      private static final long serialVersionUID = 1L;
31      
32      private LearningObjectiveService loService;
33  
34      @Override
35      protected String getDefaultWorkflowDocumentType() {
36          return null;
37      }
38  
39      @Override
40      protected String getDefaultMetaDataState() {
41          return null;
42      }
43  
44      @Override
45      protected Object get(String id) throws Exception {
46  
47          //TODO Check that only LO categories are coming through this way. LOs are persisted only in the context of a CLU?
48          Object returnDTO ;
49  
50          try {
51              returnDTO = loService.getLoCategory(id);
52          }
53          catch (DoesNotExistException e) {
54              throw new InvalidParameterException("Only LoCategoryInfo supported by this DataService implementation.");
55          }
56          return  returnDTO;
57      }
58  
59      @Override
60      protected Object save(Object dto, Map<String, Object> properties) throws Exception {
61          if (dto instanceof LoCategoryInfo) {
62              LoCategoryInfo loCatInfo = (LoCategoryInfo) dto;
63              if (loCatInfo.getId() == null ) {
64              	loCatInfo = loService.createLoCategory(loCatInfo.getLoRepository(), loCatInfo.getType(), loCatInfo);
65              } else {
66                  loCatInfo = loService.updateLoCategory(loCatInfo.getId(), loCatInfo);
67              }
68              return loCatInfo;
69          } else  {
70              throw new InvalidParameterException("Only LoCategoryInfo supported by this DataService implementation.");
71          }
72      }
73  
74      @Override
75      protected Class<?> getDtoClass() {
76          return LoCategoryInfo.class;
77      }
78  
79      public void setLearningObjectiveService(LearningObjectiveService loService) {
80          this.loService = loService;
81      }
82  
83  
84  }