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