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