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