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