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 | 0 | 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 | 0 | return null; |
27 | |
} |
28 | |
|
29 | |
@Override |
30 | |
protected String getDefaultMetaDataState() { |
31 | 0 | return null; |
32 | |
} |
33 | |
|
34 | |
@Override |
35 | |
protected Object get(String id) throws Exception { |
36 | 0 | if (ProgramClientConstants.CREDENTIAL_PROGRAM_TYPES.contains(id)){ |
37 | 0 | List<String> credIds = luService.getCluIdsByLuType(id, ProgramClientConstants.STATE_ACTIVE); |
38 | 0 | if (null == credIds || credIds.size() != 1) { |
39 | 0 | throw new OperationFailedException("A single credential program of type " + id + " is required; database contains " + |
40 | |
(null == credIds ? "0" : credIds.size() + |
41 | |
".")); |
42 | |
} |
43 | 0 | return programService.getCredentialProgram(credIds.get(0)); |
44 | |
} else { |
45 | 0 | return programService.getCredentialProgram(id); |
46 | |
} |
47 | |
} |
48 | |
|
49 | |
@Override |
50 | |
protected Object save(Object dto, Map<String, Object> properties) throws Exception { |
51 | 0 | if (dto instanceof CredentialProgramInfo) { |
52 | 0 | CredentialProgramInfo cpInfo = (CredentialProgramInfo) dto; |
53 | 0 | if (cpInfo.getId() == null && cpInfo.getVersionInfo() != null) { |
54 | 0 | String credentialVersionIndId = cpInfo.getVersionInfo().getVersionIndId(); |
55 | 0 | cpInfo = programService.createNewCredentialProgramVersion(credentialVersionIndId, "New credential program version"); |
56 | 0 | } else if (cpInfo.getId() == null) { |
57 | 0 | cpInfo = programService.createCredentialProgram(cpInfo); |
58 | |
} else { |
59 | 0 | cpInfo = programService.updateCredentialProgram(cpInfo); |
60 | |
} |
61 | 0 | return cpInfo; |
62 | |
} else { |
63 | 0 | throw new InvalidParameterException("Only persistence of CredentialProgram is supported by this DataService implementation."); |
64 | |
} |
65 | |
} |
66 | |
|
67 | |
@Override |
68 | |
protected Class<?> getDtoClass() { |
69 | 0 | return CredentialProgramInfo.class; |
70 | |
} |
71 | |
|
72 | |
public void setProgramService(ProgramService programService) { |
73 | 0 | this.programService = programService; |
74 | 0 | } |
75 | |
|
76 | |
public void setLuService(LuService luService) { |
77 | 0 | this.luService = luService; |
78 | 0 | } |
79 | |
} |