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.CredentialProgramInfo;
14  import org.kuali.student.lum.program.dto.MajorDisciplineInfo;
15  import org.kuali.student.lum.program.service.ProgramService;
16  
17  /**
18   * @author Igor
19   */
20  public class CredentialProgramDataService extends AbstractDataService {
21  
22      private static final long serialVersionUID = 1L;
23      
24      private ProgramService programService;
25      private LuService luService;
26      
27      @Override
28      protected String getDefaultWorkflowDocumentType() {
29          return null;
30      }
31  
32      @Override
33      protected String getDefaultMetaDataState() {
34          return null;
35      }
36  
37      @Override
38      protected Object get(String id) throws Exception {
39      	if (ProgramClientConstants.CREDENTIAL_PROGRAM_TYPES.contains(id)){
40              List<String> credIds = luService.getCluIdsByLuType(id, DtoConstants.STATE_ACTIVE);
41              if (null == credIds || credIds.size() != 1) {
42                  throw new OperationFailedException("A single credential program of type " + id + " is required; database contains " +
43                                                      (null == credIds ? "0" : credIds.size() +
44                                                      "."));
45              }
46              return programService.getCredentialProgram(credIds.get(0));
47          } else {
48          	return programService.getCredentialProgram(id);
49          }
50      }
51  
52      @Override
53      protected Object save(Object dto, Map<String, Object> properties) throws Exception {
54          if (dto instanceof CredentialProgramInfo) {
55              CredentialProgramInfo cpInfo = (CredentialProgramInfo) dto;
56              if (cpInfo.getId() == null && cpInfo.getVersionInfo() != null) {
57              	String credentialVersionIndId = cpInfo.getVersionInfo().getVersionIndId();
58              	cpInfo = programService.createNewCredentialProgramVersion(credentialVersionIndId, "New credential program version");
59              } else if (cpInfo.getId() == null) {
60                  cpInfo = programService.createCredentialProgram(cpInfo);
61              } else {
62                  cpInfo = programService.updateCredentialProgram(cpInfo);
63              }
64              return cpInfo;
65          } else {
66              throw new InvalidParameterException("Only persistence of CredentialProgram is supported by this DataService implementation.");
67          }
68      }
69  
70      @Override
71  	protected List<ValidationResultInfo> validate(Object dto) throws Exception {
72  		return programService.validateCredentialProgram("OBJECT", (CredentialProgramInfo)dto);
73  	}
74      
75      @Override
76      protected Class<?> getDtoClass() {
77          return CredentialProgramInfo.class;
78      }
79  
80      public void setProgramService(ProgramService programService) {
81          this.programService = programService;
82      }
83  
84      public void setLuService(LuService luService) {
85          this.luService = luService;
86      }
87  }