1 | |
package org.kuali.student.lum.program.server.transform; |
2 | |
|
3 | |
import java.util.Map; |
4 | |
|
5 | |
import org.kuali.student.core.assembly.data.Data; |
6 | |
import org.kuali.student.core.assembly.data.Metadata; |
7 | |
import org.kuali.student.lum.program.client.ProgramConstants; |
8 | |
import org.kuali.student.lum.program.dto.CredentialProgramInfo; |
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | 0 | public class VersionCredentialProgramFilter extends VersionProgramFilter { |
18 | |
|
19 | |
@Override |
20 | |
public void applyOutboundDataFilter(Data data, Metadata metadata, |
21 | |
Map<String, Object> properties) throws Exception { |
22 | 0 | Data previousVersionData = (Data)properties.get(VersionProgramFilter.PREVIOUS_VERSION_DATA); |
23 | 0 | String versionFromId = data.query(ProgramConstants.VERSION_FROM_ID); |
24 | |
|
25 | 0 | if (versionFromId != null){ |
26 | 0 | CredentialProgramInfo previousVersionCoreInfo = programService.getCredentialProgram(versionFromId); |
27 | |
|
28 | 0 | if (previousVersionData == null){ |
29 | |
|
30 | 0 | previousVersionData = new Data(); |
31 | 0 | previousVersionData.set(ProgramConstants.ID, previousVersionCoreInfo.getId()); |
32 | 0 | previousVersionData.set(ProgramConstants.END_PROGRAM_ENTRY_TERM, previousVersionCoreInfo.getEndProgramEntryTerm()); |
33 | 0 | previousVersionData.set(ProgramConstants.END_PROGRAM_ENROLL_TERM, previousVersionCoreInfo.getEndTerm()); |
34 | 0 | previousVersionData.set(ProgramConstants.STATE, previousVersionCoreInfo.getState()); |
35 | |
} else { |
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | 0 | String state = previousVersionData.get(ProgramConstants.STATE); |
41 | 0 | if (state!= null && !state.equals(previousVersionCoreInfo.getState())){ |
42 | |
|
43 | 0 | String endEntryTerm = previousVersionData.get(ProgramConstants.END_PROGRAM_ENTRY_TERM); |
44 | 0 | String endEnrollTerm = previousVersionData.get(ProgramConstants.END_PROGRAM_ENROLL_TERM); |
45 | |
|
46 | 0 | previousVersionCoreInfo.setState(state); |
47 | 0 | previousVersionCoreInfo.setEndProgramEntryTerm(endEntryTerm); |
48 | 0 | previousVersionCoreInfo.setEndTerm(endEnrollTerm); |
49 | |
|
50 | 0 | programService.updateCredentialProgram(previousVersionCoreInfo); |
51 | |
|
52 | |
|
53 | 0 | String activatedCoreId = data.get(ProgramConstants.ID); |
54 | 0 | programService.setCurrentCredentialProgramVersion(activatedCoreId, null); |
55 | |
} |
56 | |
|
57 | |
} |
58 | |
|
59 | 0 | data.set(PREVIOUS_VERSION_INFO, previousVersionData); |
60 | |
} |
61 | 0 | } |
62 | |
|
63 | |
} |