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.common.dto.DtoConstants;
7   import org.kuali.student.common.exceptions.InvalidParameterException;
8   import org.kuali.student.common.exceptions.OperationFailedException;
9   import org.kuali.student.common.ui.server.gwt.AbstractDataService;
10  import org.kuali.student.common.validation.dto.ValidationResultInfo;
11  import org.kuali.student.lum.lu.service.LuService;
12  import org.kuali.student.lum.program.client.ProgramClientConstants;
13  import org.kuali.student.lum.program.dto.MajorDisciplineInfo;
14  import org.kuali.student.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      private LuService luService;
25  
26      @Override
27      protected String getDefaultWorkflowDocumentType() {
28          return null;
29      }
30  
31      @Override
32      protected String getDefaultMetaDataState() {
33          return null;
34      }
35  
36      @Override
37      protected Object get(String id) throws Exception {
38      	//TODO Just Major Discipline for now - need to check for other types later
39          MajorDisciplineInfo returnDTO;
40          if (null == id || id.length() == 0) {
41              returnDTO = new MajorDisciplineInfo();
42              returnDTO.setType(ProgramClientConstants.MAJOR_PROGRAM);
43              returnDTO.setState(DtoConstants.STATE_DRAFT);
44              returnDTO.setCredentialProgramId(getCredentialId());
45          } else {
46              returnDTO = programService.getMajorDiscipline(id);
47          }
48          return returnDTO;
49      }
50  
51      @Override
52      protected Object save(Object dto, Map<String, Object> properties) throws Exception {
53          if (dto instanceof MajorDisciplineInfo) {
54              MajorDisciplineInfo mdInfo = (MajorDisciplineInfo) dto;
55              if (mdInfo.getId() == null && mdInfo.getVersionInfo() != null) {
56              	String majorVersionIndId = mdInfo.getVersionInfo().getVersionIndId();
57              	mdInfo = programService.createNewMajorDisciplineVersion(majorVersionIndId, "New major discipline version");
58              } else if (mdInfo.getId() == null){
59                  mdInfo = programService.createMajorDiscipline(mdInfo);
60              } else {
61                  mdInfo = programService.updateMajorDiscipline(mdInfo);
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) throws Exception {
72  		return programService.validateMajorDiscipline("OBJECT", (MajorDisciplineInfo)dto);
73  	}
74  
75  	@Override
76      protected Class<?> getDtoClass() {
77          return MajorDisciplineInfo.class;
78      }
79  
80      private String getCredentialId() throws Exception {
81  
82              List<String> credIds = luService.getCluIdsByLuType(ProgramClientConstants.CREDENTIAL_BACCALAUREATE_PROGRAM, DtoConstants.STATE_ACTIVE);
83              if (null == credIds || credIds.size() != 1) {
84                  throw new OperationFailedException("A single credential program of type " + ProgramClientConstants.CREDENTIAL_BACCALAUREATE_PROGRAM + " is required; database contains " +
85                                                      (null == credIds ? "0" : credIds.size() +
86                                                      "."));
87              }
88              return credIds.get(0);
89      }
90  
91      public void setProgramService(ProgramService programService) {
92          this.programService = programService;
93      }
94  
95      public void setLuService(LuService luService) {
96          this.luService = luService;
97      }
98  
99  }