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