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