1 | |
package org.kuali.student.lum.program.server.transform; |
2 | |
|
3 | |
import java.util.Map; |
4 | |
|
5 | |
import org.kuali.student.common.assembly.data.Data; |
6 | |
import org.kuali.student.common.assembly.data.Data.DataType; |
7 | |
import org.kuali.student.common.assembly.data.Data.StringKey; |
8 | |
import org.kuali.student.common.assembly.data.Metadata; |
9 | |
import org.kuali.student.common.assembly.data.QueryPath; |
10 | |
import org.kuali.student.common.assembly.dictionary.MetadataServiceImpl; |
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.core.atp.dto.AtpInfo; |
15 | |
import org.kuali.student.core.atp.service.AtpService; |
16 | |
import org.kuali.student.lum.program.client.ProgramConstants; |
17 | |
import org.kuali.student.lum.program.dto.MajorDisciplineInfo; |
18 | |
import org.kuali.student.lum.program.dto.ProgramVariationInfo; |
19 | |
import org.kuali.student.lum.program.service.ProgramService; |
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | 0 | public class VersionProgramFilter extends AbstractDataFilter implements MetadataFilter{ |
33 | |
public static final String PREVIOUS_VERSION_DATA = "VersionProgramFilter.PreviousVersionData"; |
34 | |
public static final String PREVIOUS_VERSION_INFO = "proposal"; |
35 | |
|
36 | |
private Metadata previousVersionMetadata; |
37 | |
protected ProgramService programService; |
38 | |
protected MetadataServiceImpl metadataService; |
39 | |
protected AtpService atpService; |
40 | |
protected String proposalObjectType; |
41 | |
|
42 | |
|
43 | |
|
44 | |
@Override |
45 | |
public void applyInboundDataFilter(Data data, Metadata metadata, |
46 | |
Map<String, Object> properties) throws Exception { |
47 | 0 | Data previousVersionData = data.query(PREVIOUS_VERSION_INFO); |
48 | 0 | data.remove(new StringKey(PREVIOUS_VERSION_INFO)); |
49 | |
|
50 | 0 | if (previousVersionData != null){ |
51 | 0 | properties.put(PREVIOUS_VERSION_DATA, previousVersionData); |
52 | |
} |
53 | 0 | } |
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
@Override |
60 | |
public void applyOutboundDataFilter(Data data, Metadata metadata, |
61 | |
Map<String, Object> properties) throws Exception { |
62 | 0 | Data previousVersionData = (Data)properties.get(PREVIOUS_VERSION_DATA); |
63 | 0 | String versionFromId = data.query(ProgramConstants.VERSION_FROM_ID); |
64 | |
|
65 | 0 | if (versionFromId != null){ |
66 | 0 | if (previousVersionData == null){ |
67 | 0 | MajorDisciplineInfo previousVersionMajorInfo = programService.getMajorDiscipline(versionFromId); |
68 | |
|
69 | |
|
70 | 0 | previousVersionData = new Data(); |
71 | 0 | previousVersionData.set(ProgramConstants.ID, previousVersionMajorInfo.getId()); |
72 | 0 | previousVersionData.set(ProgramConstants.PREV_END_PROGRAM_ENTRY_TERM, previousVersionMajorInfo.getEndProgramEntryTerm()); |
73 | 0 | previousVersionData.set(ProgramConstants.PREV_END_PROGRAM_ENROLL_TERM, previousVersionMajorInfo.getEndTerm()); |
74 | 0 | previousVersionData.set(ProgramConstants.PREV_END_INST_ADMIN_TERM, previousVersionMajorInfo.getEndTerm()); |
75 | |
|
76 | |
|
77 | 0 | AtpInfo latestStartAtp = atpService.getAtp(previousVersionMajorInfo.getStartTerm()); |
78 | 0 | for (ProgramVariationInfo variation:previousVersionMajorInfo.getVariations()){ |
79 | 0 | AtpInfo variationAtp = atpService.getAtp(variation.getStartTerm()); |
80 | 0 | if(variationAtp!=null && variationAtp.getStartDate()!=null && variationAtp.getStartDate().compareTo(latestStartAtp.getStartDate())>0){ |
81 | 0 | latestStartAtp = variationAtp; |
82 | |
} |
83 | 0 | } |
84 | |
|
85 | 0 | previousVersionData.set(ProgramConstants.PREV_START_TERM, latestStartAtp.getId()); |
86 | |
} |
87 | |
|
88 | 0 | data.set(PREVIOUS_VERSION_INFO, previousVersionData); |
89 | |
} |
90 | 0 | } |
91 | |
|
92 | |
|
93 | |
|
94 | |
|
95 | |
@Override |
96 | |
public void applyMetadataFilter(String dtoName, Metadata metadata, |
97 | |
Map<String, Object> filterProperties) { |
98 | 0 | metadata.getProperties().put(PREVIOUS_VERSION_INFO, getPreviousVersionMetadata(metadata)); |
99 | 0 | } |
100 | |
|
101 | |
|
102 | |
|
103 | |
|
104 | |
|
105 | |
|
106 | |
|
107 | |
|
108 | |
protected Metadata getPreviousVersionMetadata(Metadata metadata){ |
109 | |
|
110 | 0 | if (previousVersionMetadata == null){ |
111 | |
|
112 | 0 | Metadata proposalMetadata = metadataService.getMetadata(proposalObjectType); |
113 | |
|
114 | |
|
115 | 0 | DataModelDefinition modelDef = new DataModelDefinition(metadata); |
116 | 0 | Metadata programIdMeta = modelDef.getMetadata(QueryPath.parse(ProgramConstants.ID)); |
117 | 0 | Metadata startTermMeta = proposalMetadata.getProperties().get(ProgramConstants.PREV_START_TERM); |
118 | 0 | Metadata endEntryTermMeta = proposalMetadata.getProperties().get(ProgramConstants.PREV_END_PROGRAM_ENTRY_TERM); |
119 | 0 | Metadata endEnrollTermMeta = proposalMetadata.getProperties().get(ProgramConstants.PREV_END_PROGRAM_ENROLL_TERM); |
120 | 0 | Metadata endInstAdminMeta = proposalMetadata.getProperties().get(ProgramConstants.PREV_END_INST_ADMIN_TERM); |
121 | |
|
122 | 0 | endEntryTermMeta.getConstraints().get(0).setRequiredForNextState(true); |
123 | 0 | endEnrollTermMeta.getConstraints().get(0).setRequiredForNextState(true); |
124 | 0 | endInstAdminMeta.getConstraints().get(0).setRequiredForNextState(true); |
125 | |
|
126 | 0 | endEntryTermMeta.getConstraints().get(0).setMinOccurs(1); |
127 | 0 | endEnrollTermMeta.getConstraints().get(0).setMinOccurs(1); |
128 | 0 | endInstAdminMeta.getConstraints().get(0).setMinOccurs(1); |
129 | |
|
130 | 0 | previousVersionMetadata = new Metadata(); |
131 | 0 | previousVersionMetadata.setDataType(DataType.DATA); |
132 | |
|
133 | 0 | Map<String, Metadata> properties = previousVersionMetadata.getProperties(); |
134 | 0 | properties.put(ProgramConstants.ID, programIdMeta); |
135 | 0 | properties.put(ProgramConstants.PREV_START_TERM, startTermMeta); |
136 | 0 | properties.put(ProgramConstants.PREV_END_PROGRAM_ENTRY_TERM, endEntryTermMeta); |
137 | 0 | properties.put(ProgramConstants.PREV_END_PROGRAM_ENROLL_TERM, endEnrollTermMeta); |
138 | 0 | properties.put(ProgramConstants.PREV_END_INST_ADMIN_TERM, endInstAdminMeta); |
139 | |
} |
140 | |
|
141 | 0 | return previousVersionMetadata; |
142 | |
} |
143 | |
|
144 | |
public void setProgramService(ProgramService programService) { |
145 | 0 | this.programService = programService; |
146 | 0 | } |
147 | |
|
148 | |
public void setMetadataService(MetadataServiceImpl metadataService) { |
149 | 0 | this.metadataService = metadataService; |
150 | 0 | } |
151 | |
|
152 | |
public void setProposalObjectType(String proposalObjectType) { |
153 | 0 | this.proposalObjectType = proposalObjectType; |
154 | 0 | } |
155 | |
|
156 | |
public void setAtpService(AtpService atpService) { |
157 | 0 | this.atpService = atpService; |
158 | 0 | } |
159 | |
} |