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