1 | |
package org.kuali.student.lum.program.server.transform; |
2 | |
|
3 | |
import java.util.List; |
4 | |
import java.util.Map; |
5 | |
|
6 | |
import org.kuali.student.common.assembly.data.Data; |
7 | |
import org.kuali.student.common.assembly.data.Metadata; |
8 | |
import org.kuali.student.common.assembly.data.QueryPath; |
9 | |
import org.kuali.student.common.assembly.data.Data.DataType; |
10 | |
import org.kuali.student.common.assembly.data.Data.StringKey; |
11 | |
import org.kuali.student.common.assembly.transform.AbstractDataFilter; |
12 | |
import org.kuali.student.common.assembly.transform.MetadataFilter; |
13 | |
import org.kuali.student.common.ui.client.mvc.DataModelDefinition; |
14 | |
import org.kuali.student.lum.program.client.ProgramConstants; |
15 | |
import org.kuali.student.lum.program.dto.MajorDisciplineInfo; |
16 | |
import org.kuali.student.lum.program.dto.ProgramVariationInfo; |
17 | |
import org.kuali.student.lum.program.service.ProgramService; |
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | 0 | public class VersionProgramFilter extends AbstractDataFilter implements MetadataFilter{ |
27 | |
public static final String PREVIOUS_VERSION_DATA = "VersionProgramFilter.PreviousVersionData"; |
28 | |
public static final String PREVIOUS_VERSION_INFO = "previousVersionInfo"; |
29 | |
|
30 | |
private Metadata previousVersionMetadata; |
31 | |
protected ProgramService programService; |
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
@Override |
37 | |
public void applyInboundDataFilter(Data data, Metadata metadata, |
38 | |
Map<String, Object> properties) throws Exception { |
39 | 0 | Data previousVersionData = data.query(PREVIOUS_VERSION_INFO); |
40 | 0 | data.remove(new StringKey(PREVIOUS_VERSION_INFO)); |
41 | |
|
42 | 0 | if (previousVersionData != null){ |
43 | 0 | properties.put(PREVIOUS_VERSION_DATA, previousVersionData); |
44 | |
} |
45 | 0 | } |
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
@Override |
52 | |
public void applyOutboundDataFilter(Data data, Metadata metadata, |
53 | |
Map<String, Object> properties) throws Exception { |
54 | 0 | Data previousVersionData = (Data)properties.get(PREVIOUS_VERSION_DATA); |
55 | 0 | String versionFromId = data.query(ProgramConstants.VERSION_FROM_ID); |
56 | |
|
57 | 0 | if (versionFromId != null){ |
58 | 0 | MajorDisciplineInfo previousVersionMajorInfo = programService.getMajorDiscipline(versionFromId); |
59 | |
|
60 | 0 | if (previousVersionData == null){ |
61 | |
|
62 | 0 | previousVersionData = new Data(); |
63 | 0 | previousVersionData.set(ProgramConstants.ID, previousVersionMajorInfo.getId()); |
64 | 0 | previousVersionData.set(ProgramConstants.END_PROGRAM_ENTRY_TERM, previousVersionMajorInfo.getEndProgramEntryTerm()); |
65 | 0 | previousVersionData.set(ProgramConstants.END_PROGRAM_ENROLL_TERM, previousVersionMajorInfo.getEndTerm()); |
66 | 0 | previousVersionData.set(ProgramConstants.STATE, previousVersionMajorInfo.getState()); |
67 | |
} |
68 | |
|
69 | 0 | data.set(PREVIOUS_VERSION_INFO, previousVersionData); |
70 | |
} |
71 | 0 | } |
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
@Override |
77 | |
public void applyMetadataFilter(String dtoName, Metadata metadata, |
78 | |
Map<String, Object> filterProperties) { |
79 | 0 | metadata.getProperties().put(PREVIOUS_VERSION_INFO, getPreviousVersionMetadata(metadata)); |
80 | 0 | } |
81 | |
|
82 | |
|
83 | |
|
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | |
protected Metadata getPreviousVersionMetadata(Metadata metadata){ |
90 | 0 | if (previousVersionMetadata == null){ |
91 | 0 | DataModelDefinition modelDef = new DataModelDefinition(metadata); |
92 | 0 | Metadata programIdMeta = modelDef.getMetadata(QueryPath.parse(ProgramConstants.ID)); |
93 | 0 | Metadata programStateMeta = modelDef.getMetadata(QueryPath.parse(ProgramConstants.STATE)); |
94 | 0 | Metadata endEntryTermMeta = modelDef.getMetadata(QueryPath.parse(ProgramConstants.END_PROGRAM_ENTRY_TERM)); |
95 | 0 | Metadata endEnrollTermMeta = modelDef.getMetadata(QueryPath.parse(ProgramConstants.END_PROGRAM_ENROLL_TERM)); |
96 | |
|
97 | 0 | previousVersionMetadata = new Metadata(); |
98 | 0 | previousVersionMetadata.setDataType(DataType.DATA); |
99 | |
|
100 | 0 | Map<String, Metadata> properties = previousVersionMetadata.getProperties(); |
101 | 0 | properties.put(ProgramConstants.ID, programIdMeta); |
102 | 0 | properties.put(ProgramConstants.STATE, programStateMeta); |
103 | 0 | properties.put(ProgramConstants.END_PROGRAM_ENTRY_TERM, endEntryTermMeta); |
104 | 0 | properties.put(ProgramConstants.END_PROGRAM_ENROLL_TERM, endEnrollTermMeta); |
105 | |
} |
106 | |
|
107 | 0 | return previousVersionMetadata; |
108 | |
} |
109 | |
|
110 | |
public void setProgramService(ProgramService programService) { |
111 | 0 | this.programService = programService; |
112 | 0 | } |
113 | |
} |