1 | |
package org.kuali.student.lum.program.server; |
2 | |
|
3 | |
import java.util.ArrayList; |
4 | |
import java.util.HashMap; |
5 | |
import java.util.List; |
6 | |
import java.util.Map; |
7 | |
|
8 | |
import org.apache.log4j.Logger; |
9 | |
import org.kuali.student.common.assembly.data.Data; |
10 | |
import org.kuali.student.common.dto.RichTextInfo; |
11 | |
import org.kuali.student.common.dto.StatusInfo; |
12 | |
import org.kuali.student.common.ui.client.service.DataSaveResult; |
13 | |
import org.kuali.student.common.ui.server.gwt.DataGwtServlet; |
14 | |
import org.kuali.student.common.versionmanagement.dto.VersionDisplayInfo; |
15 | |
import org.kuali.student.core.proposal.dto.ProposalInfo; |
16 | |
import org.kuali.student.core.proposal.service.ProposalService; |
17 | |
import org.kuali.student.core.statement.dto.ReqComponentInfo; |
18 | |
import org.kuali.student.core.statement.dto.StatementTreeViewInfo; |
19 | |
import org.kuali.student.core.statement.service.StatementService; |
20 | |
import org.kuali.student.core.statement.ui.client.widgets.rules.ReqComponentInfoUi; |
21 | |
import org.kuali.student.core.statement.ui.client.widgets.rules.RulesUtil; |
22 | |
import org.kuali.student.lum.common.server.StatementUtil; |
23 | |
import org.kuali.student.lum.program.client.ProgramConstants; |
24 | |
import org.kuali.student.lum.program.client.requirements.ProgramRequirementsDataModel; |
25 | |
import org.kuali.student.lum.program.client.requirements.ProgramRequirementsSummaryView; |
26 | |
import org.kuali.student.lum.program.client.rpc.MajorDisciplineProposalRpcService; |
27 | |
import org.kuali.student.lum.program.dto.ProgramRequirementInfo; |
28 | |
import org.kuali.student.lum.program.service.ProgramService; |
29 | |
import org.kuali.student.lum.program.service.ProgramServiceConstants; |
30 | |
|
31 | 0 | public class MajorDisciplineProposalRpcServlet extends DataGwtServlet implements MajorDisciplineProposalRpcService { |
32 | |
|
33 | |
public static final String PREVIOUS_VERSION_INFO = "previousVersionInfo"; |
34 | |
|
35 | 0 | final Logger LOG = Logger.getLogger(MajorDisciplineProposalRpcServlet.class); |
36 | |
|
37 | |
private static final long serialVersionUID = 1L; |
38 | |
|
39 | |
private ProgramService programService; |
40 | |
private StatementService statementService; |
41 | |
protected StateChangeService stateChangeService; |
42 | |
private ProposalService proposalService; |
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
public DataSaveResult updateState(Data data, String state ) throws Exception { |
51 | |
try { |
52 | |
|
53 | 0 | String programId = data.get(ProgramConstants.ID); |
54 | |
|
55 | |
|
56 | |
|
57 | 0 | Data previousVersionInfo = data.query(PREVIOUS_VERSION_INFO); |
58 | 0 | String endEntryTerm = null; |
59 | 0 | String endEnrollTerm = null; |
60 | 0 | if (previousVersionInfo != null) { |
61 | 0 | endEntryTerm = previousVersionInfo.get(ProgramConstants.END_PROGRAM_ENTRY_TERM); |
62 | 0 | endEnrollTerm = previousVersionInfo.get(ProgramConstants.END_PROGRAM_ENROLL_TERM); |
63 | 0 | stateChangeService.changeState(endEntryTerm, endEnrollTerm, programId, state); |
64 | |
} |
65 | |
else{ |
66 | |
|
67 | 0 | stateChangeService.changeState( programId, state); |
68 | |
} |
69 | |
|
70 | |
|
71 | |
|
72 | 0 | DataSaveResult result = new DataSaveResult(); |
73 | 0 | result.setValue(data); |
74 | 0 | return result; |
75 | 0 | } catch(Exception e){ |
76 | 0 | e.printStackTrace(); |
77 | 0 | throw e; |
78 | |
} |
79 | |
|
80 | |
} |
81 | |
public List<ProgramRequirementInfo> getProgramRequirements(List<String> programRequirementIds) throws Exception { |
82 | |
|
83 | 0 | List<ProgramRequirementInfo> programReqInfos = new ArrayList<ProgramRequirementInfo>(); |
84 | |
|
85 | 0 | for (String programReqId : programRequirementIds) { |
86 | 0 | ProgramRequirementInfo rule = programService.getProgramRequirement(programReqId, null, null); |
87 | 0 | setProgReqNL(rule); |
88 | 0 | programReqInfos.add(rule); |
89 | 0 | } |
90 | |
|
91 | 0 | return programReqInfos; |
92 | |
} |
93 | |
|
94 | |
public Map<Integer, ProgramRequirementInfo> storeProgramRequirements(Map<Integer, ProgramRequirementsDataModel.requirementState> states, |
95 | |
Map<Integer, ProgramRequirementInfo> progReqs) throws Exception { |
96 | 0 | Map<Integer, ProgramRequirementInfo> storedRules = new HashMap<Integer, ProgramRequirementInfo>(); |
97 | |
|
98 | 0 | for (Integer key : progReqs.keySet()) { |
99 | 0 | ProgramRequirementInfo rule = progReqs.get(key); |
100 | 0 | switch (states.get(key)) { |
101 | |
case STORED: |
102 | |
|
103 | 0 | storedRules.put(key, null); |
104 | 0 | break; |
105 | |
case ADDED: |
106 | 0 | storedRules.put(key, createProgramRequirement(rule)); |
107 | 0 | break; |
108 | |
case EDITED: |
109 | 0 | storedRules.put(key, updateProgramRequirement(rule)); |
110 | 0 | break; |
111 | |
case DELETED: |
112 | 0 | storedRules.put(key, null); |
113 | 0 | deleteProgramRequirement(rule.getId()); |
114 | 0 | break; |
115 | |
default: |
116 | |
break; |
117 | |
} |
118 | 0 | } |
119 | 0 | return storedRules; |
120 | |
} |
121 | |
|
122 | |
|
123 | |
public ProgramRequirementInfo createProgramRequirement(ProgramRequirementInfo programRequirementInfo) throws Exception { |
124 | |
|
125 | |
|
126 | 0 | if (programRequirementInfo.getId().indexOf(ProgramRequirementsSummaryView.NEW_PROG_REQ_ID) >= 0) { |
127 | 0 | programRequirementInfo.setId(null); |
128 | |
} |
129 | |
|
130 | |
|
131 | 0 | StatementUtil.stripStatementIds(programRequirementInfo.getStatement()); |
132 | |
|
133 | |
|
134 | |
|
135 | 0 | StatementUtil.updateStatementTreeViewInfoState(programRequirementInfo.getState(), programRequirementInfo.getStatement()); |
136 | |
|
137 | |
|
138 | 0 | ProgramRequirementInfo rule = programService.createProgramRequirement(programRequirementInfo); |
139 | |
|
140 | |
|
141 | 0 | setProgReqNL(rule); |
142 | |
|
143 | 0 | return rule; |
144 | |
} |
145 | |
|
146 | |
public StatusInfo deleteProgramRequirement(String programRequirementId) throws Exception { |
147 | 0 | return programService.deleteProgramRequirement(programRequirementId); |
148 | |
} |
149 | |
|
150 | |
public ProgramRequirementInfo updateProgramRequirement(ProgramRequirementInfo programRequirementInfo) throws Exception { |
151 | |
|
152 | |
|
153 | 0 | StatementUtil.stripStatementIds(programRequirementInfo.getStatement()); |
154 | |
|
155 | |
|
156 | |
|
157 | 0 | StatementUtil.updateStatementTreeViewInfoState(programRequirementInfo.getState(), programRequirementInfo.getStatement()); |
158 | |
|
159 | |
|
160 | 0 | if (programRequirementInfo.getDescr() == null) { |
161 | 0 | programRequirementInfo.setDescr(new RichTextInfo()); |
162 | |
} |
163 | |
|
164 | 0 | ProgramRequirementInfo rule = programService.updateProgramRequirement(programRequirementInfo); |
165 | 0 | setProgReqNL(rule); |
166 | 0 | return rule; |
167 | |
} |
168 | |
|
169 | |
private void setProgReqNL(ProgramRequirementInfo programRequirementInfo) throws Exception { |
170 | 0 | setReqCompNL(programRequirementInfo.getStatement()); |
171 | 0 | } |
172 | |
|
173 | |
private void setReqCompNL(StatementTreeViewInfo tree) throws Exception { |
174 | 0 | List<StatementTreeViewInfo> statements = tree.getStatements(); |
175 | 0 | List<ReqComponentInfo> reqComponentInfos = tree.getReqComponents(); |
176 | |
|
177 | 0 | if ((statements != null) && (statements.size() > 0)) { |
178 | |
|
179 | 0 | for (StatementTreeViewInfo statement : statements) { |
180 | 0 | setReqCompNL(statement); |
181 | |
} |
182 | 0 | } else if ((reqComponentInfos != null) && (reqComponentInfos.size() > 0)) { |
183 | |
|
184 | 0 | for (int i = 0; i < reqComponentInfos.size(); i++) { |
185 | 0 | ReqComponentInfoUi reqUi = RulesUtil.clone(reqComponentInfos.get(i)); |
186 | 0 | reqUi.setNaturalLanguageTranslation(statementService.translateReqComponentToNL(reqUi, "KUALI.RULE", "en")); |
187 | 0 | reqUi.setPreviewNaturalLanguageTranslation(statementService.translateReqComponentToNL(reqUi, "KUALI.RULE.PREVIEW", "en")); |
188 | 0 | reqComponentInfos.set(i, reqUi); |
189 | |
} |
190 | |
} |
191 | 0 | } |
192 | |
|
193 | |
@Override |
194 | |
public Boolean isLatestVersion(String versionIndId, Long versionSequenceNumber) throws Exception { |
195 | 0 | VersionDisplayInfo versionDisplayInfo = programService.getLatestVersion(ProgramServiceConstants.PROGRAM_NAMESPACE_MAJOR_DISCIPLINE_URI, versionIndId); |
196 | 0 | Long latestSequenceNumber = versionDisplayInfo.getSequenceNumber(); |
197 | 0 | boolean isLatest = latestSequenceNumber.equals(versionSequenceNumber); |
198 | |
|
199 | 0 | return isLatest; |
200 | |
} |
201 | |
|
202 | |
public void setProgramService(ProgramService programService) { |
203 | 0 | this.programService = programService; |
204 | 0 | } |
205 | |
|
206 | |
public void setStatementService(StatementService statementService) { |
207 | 0 | this.statementService = statementService; |
208 | 0 | } |
209 | |
|
210 | |
public void setStateChangeService(StateChangeService stateChangeService) { |
211 | 0 | this.stateChangeService = stateChangeService; |
212 | 0 | } |
213 | |
|
214 | |
|
215 | |
|
216 | |
|
217 | |
|
218 | |
|
219 | |
|
220 | |
|
221 | |
|
222 | |
|
223 | |
@Override |
224 | |
public Boolean isProposal(String referenceTypeKey, String referenceId){ |
225 | |
try { |
226 | |
|
227 | |
|
228 | |
|
229 | |
|
230 | |
|
231 | 0 | List<ProposalInfo> proposals = proposalService.getProposalsByReference(referenceTypeKey, referenceId); |
232 | |
|
233 | |
|
234 | 0 | if (proposals != null && proposals.size() >= 1){ |
235 | 0 | return new Boolean(true); |
236 | |
} |
237 | |
|
238 | |
|
239 | 0 | return new Boolean(false); |
240 | |
} |
241 | 0 | catch(Exception ex){ |
242 | |
|
243 | 0 | ex.printStackTrace(); |
244 | 0 | throw new RuntimeException(ex); |
245 | |
} |
246 | |
} |
247 | |
|
248 | |
|
249 | |
|
250 | |
|
251 | |
|
252 | |
|
253 | |
|
254 | |
public ProposalService getProposalService() { |
255 | 0 | return proposalService; |
256 | |
} |
257 | |
|
258 | |
public void setProposalService(ProposalService proposalService) { |
259 | 0 | this.proposalService = proposalService; |
260 | 0 | } |
261 | |
} |