View Javadoc

1   package org.kuali.student.lum.program.server;
2   
3   import java.util.List;
4   import java.util.Map;
5   
6   import org.kuali.student.r2.common.dto.ContextInfo;
7   import org.kuali.student.r2.common.dto.DtoConstants;
8   import org.kuali.student.r2.common.exceptions.InvalidParameterException;
9   import org.kuali.student.common.ui.server.gwt.AbstractDataService;
10  import org.kuali.student.r2.common.util.ContextUtils;
11  import org.kuali.student.r2.common.dto.ValidationResultInfo;
12  import org.kuali.student.lum.program.client.ProgramClientConstants;
13  import org.kuali.student.r2.lum.program.dto.MajorDisciplineInfo;
14  import org.kuali.student.r2.lum.program.service.ProgramService;
15  
16  /**
17   * @author Igor
18   */
19  public class MajorDisciplineDataService extends AbstractDataService {
20  
21      private static final long serialVersionUID = 1L;
22      
23      private ProgramService programService;
24  
25      @Override
26      protected String getDefaultWorkflowDocumentType() {
27          return null;
28      }
29  
30      @Override
31      protected String getDefaultMetaDataState() {
32          return null;
33      }
34  
35      @Override
36      protected Object get(String id, ContextInfo contextInfo) throws Exception {
37      	//TODO Just Major Discipline for now - need to check for other types later
38          MajorDisciplineInfo returnDTO;
39          if (null == id || id.length() == 0) {
40              returnDTO = new MajorDisciplineInfo();
41              returnDTO.setTypeKey(ProgramClientConstants.MAJOR_PROGRAM);
42              returnDTO.setStateKey(DtoConstants.STATE_DRAFT);
43          } else {
44              returnDTO = programService.getMajorDiscipline(id, ContextUtils.getContextInfo());
45          }
46          return returnDTO;
47      }
48  
49      @Override
50      protected Object save(Object dto, Map<String, Object> properties, ContextInfo contextInfo) throws Exception {
51          if (dto instanceof MajorDisciplineInfo) {
52              MajorDisciplineInfo mdInfo = (MajorDisciplineInfo) dto;
53              if (mdInfo.getId() == null && mdInfo.getVersion() != null) {
54              	String majorVersionIndId = null;
55              	
56              	majorVersionIndId = mdInfo.getVersion().getVersionIndId();
57              	mdInfo = programService.createNewMajorDisciplineVersion(majorVersionIndId, "New major discipline version",ContextUtils.getContextInfo());
58              } else if (mdInfo.getId() == null){
59                  mdInfo = programService.createMajorDiscipline(mdInfo.getId(), mdInfo, ContextUtils.getContextInfo());
60              } else {
61              	mdInfo = programService.updateMajorDiscipline(mdInfo.getId(), mdInfo, ContextUtils.getContextInfo());
62              }
63              return mdInfo;
64          } else {
65              throw new InvalidParameterException("Only persistence of MajorDiscipline is supported by this DataService implementation.");
66          }
67      }  
68  
69      
70      @Override
71  	protected List<ValidationResultInfo> validate(Object dto, ContextInfo contextInfo) throws Exception {
72  		return programService.validateMajorDiscipline("OBJECT", (MajorDisciplineInfo)dto, ContextUtils.getContextInfo());
73  	}
74      
75      @Override
76      protected Class<?> getDtoClass() {
77          return MajorDisciplineInfo.class;
78      }
79  
80      public void setProgramService(ProgramService programService) {
81          this.programService = programService;
82      }
83  
84  }