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