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.kuali.student.common.dto.RichTextInfo; |
9 | |
import org.kuali.student.common.dto.StatusInfo; |
10 | |
import org.kuali.student.common.ui.server.gwt.DataGwtServlet; |
11 | |
import org.kuali.student.common.versionmanagement.dto.VersionDisplayInfo; |
12 | |
import org.kuali.student.core.statement.dto.ReqComponentInfo; |
13 | |
import org.kuali.student.core.statement.dto.StatementTreeViewInfo; |
14 | |
import org.kuali.student.core.statement.service.StatementService; |
15 | |
import org.kuali.student.core.statement.ui.client.widgets.rules.ReqComponentInfoUi; |
16 | |
import org.kuali.student.core.statement.ui.client.widgets.rules.RulesUtil; |
17 | |
import org.kuali.student.lum.program.client.requirements.ProgramRequirementsDataModel; |
18 | |
import org.kuali.student.lum.program.client.requirements.ProgramRequirementsSummaryView; |
19 | |
import org.kuali.student.lum.program.client.rpc.MajorDisciplineRpcService; |
20 | |
import org.kuali.student.lum.program.dto.ProgramRequirementInfo; |
21 | |
import org.kuali.student.lum.program.service.ProgramService; |
22 | |
import org.kuali.student.lum.program.service.ProgramServiceConstants; |
23 | |
|
24 | 0 | public class MajorDisciplineRpcServlet extends DataGwtServlet implements MajorDisciplineRpcService { |
25 | |
|
26 | |
private static final long serialVersionUID = 1L; |
27 | |
|
28 | |
private ProgramService programService; |
29 | |
private StatementService statementService; |
30 | |
|
31 | |
public List<ProgramRequirementInfo> getProgramRequirements(List<String> programRequirementIds) throws Exception { |
32 | |
|
33 | 0 | List<ProgramRequirementInfo> programReqInfos = new ArrayList<ProgramRequirementInfo>(); |
34 | |
|
35 | 0 | for (String programReqId : programRequirementIds) { |
36 | 0 | ProgramRequirementInfo rule = programService.getProgramRequirement(programReqId, null, null); |
37 | 0 | setProgReqNL(rule); |
38 | 0 | programReqInfos.add(rule); |
39 | 0 | } |
40 | |
|
41 | 0 | return programReqInfos; |
42 | |
} |
43 | |
|
44 | |
public Map<Integer, ProgramRequirementInfo> storeProgramRequirements(Map<Integer, ProgramRequirementsDataModel.requirementState> states, |
45 | |
Map<Integer, ProgramRequirementInfo> progReqs) throws Exception { |
46 | 0 | Map<Integer, ProgramRequirementInfo> storedRules = new HashMap<Integer, ProgramRequirementInfo>(); |
47 | |
|
48 | 0 | for (Integer key : progReqs.keySet()) { |
49 | 0 | ProgramRequirementInfo rule = progReqs.get(key); |
50 | 0 | switch (states.get(key)) { |
51 | |
case STORED: |
52 | |
|
53 | 0 | storedRules.put(key, null); |
54 | 0 | break; |
55 | |
case ADDED: |
56 | 0 | storedRules.put(key, createProgramRequirement(rule)); |
57 | 0 | break; |
58 | |
case EDITED: |
59 | 0 | storedRules.put(key, updateProgramRequirement(rule)); |
60 | 0 | break; |
61 | |
case DELETED: |
62 | 0 | storedRules.put(key, null); |
63 | 0 | deleteProgramRequirement(rule.getId()); |
64 | 0 | break; |
65 | |
default: |
66 | 0 | break; |
67 | |
} |
68 | 0 | } |
69 | 0 | return storedRules; |
70 | |
} |
71 | |
|
72 | |
public ProgramRequirementInfo createProgramRequirement(ProgramRequirementInfo programRequirementInfo) throws Exception { |
73 | |
|
74 | 0 | if (programRequirementInfo.getId().indexOf(ProgramRequirementsSummaryView.NEW_PROG_REQ_ID) >= 0) { |
75 | 0 | programRequirementInfo.setId(null); |
76 | |
} |
77 | |
|
78 | 0 | ProgramRequirementsDataModel.stripStatementIds(programRequirementInfo.getStatement()); |
79 | 0 | ProgramRequirementInfo rule = programService.createProgramRequirement(programRequirementInfo); |
80 | 0 | setProgReqNL(rule); |
81 | |
|
82 | 0 | return rule; |
83 | |
} |
84 | |
|
85 | |
public StatusInfo deleteProgramRequirement(String programRequirementId) throws Exception { |
86 | 0 | return programService.deleteProgramRequirement(programRequirementId); |
87 | |
} |
88 | |
|
89 | |
public ProgramRequirementInfo updateProgramRequirement(ProgramRequirementInfo programRequirementInfo) throws Exception { |
90 | 0 | ProgramRequirementsDataModel.stripStatementIds(programRequirementInfo.getStatement()); |
91 | |
|
92 | |
|
93 | 0 | if (programRequirementInfo.getDescr() == null) { |
94 | 0 | programRequirementInfo.setDescr(new RichTextInfo()); |
95 | |
} |
96 | |
|
97 | 0 | ProgramRequirementInfo rule = programService.updateProgramRequirement(programRequirementInfo); |
98 | 0 | setProgReqNL(rule); |
99 | 0 | return rule; |
100 | |
} |
101 | |
|
102 | |
private void setProgReqNL(ProgramRequirementInfo programRequirementInfo) throws Exception { |
103 | 0 | setReqCompNL(programRequirementInfo.getStatement()); |
104 | 0 | } |
105 | |
|
106 | |
private void setReqCompNL(StatementTreeViewInfo tree) throws Exception { |
107 | 0 | List<StatementTreeViewInfo> statements = tree.getStatements(); |
108 | 0 | List<ReqComponentInfo> reqComponentInfos = tree.getReqComponents(); |
109 | |
|
110 | 0 | if ((statements != null) && (statements.size() > 0)) { |
111 | |
|
112 | 0 | for (StatementTreeViewInfo statement : statements) { |
113 | 0 | setReqCompNL(statement); |
114 | |
} |
115 | 0 | } else if ((reqComponentInfos != null) && (reqComponentInfos.size() > 0)) { |
116 | |
|
117 | 0 | for (int i = 0; i < reqComponentInfos.size(); i++) { |
118 | 0 | ReqComponentInfoUi reqUi = RulesUtil.clone(reqComponentInfos.get(i)); |
119 | 0 | reqUi.setNaturalLanguageTranslation(statementService.translateReqComponentToNL(reqUi, "KUALI.RULE", "en")); |
120 | 0 | reqUi.setPreviewNaturalLanguageTranslation(statementService.translateReqComponentToNL(reqUi, "KUALI.RULE.PREVIEW", "en")); |
121 | 0 | reqComponentInfos.set(i, reqUi); |
122 | |
} |
123 | |
} |
124 | 0 | } |
125 | |
|
126 | |
@Override |
127 | |
public Boolean isLatestVersion(String versionIndId, Long versionSequenceNumber) throws Exception { |
128 | 0 | VersionDisplayInfo versionDisplayInfo = programService.getLatestVersion(ProgramServiceConstants.PROGRAM_NAMESPACE_MAJOR_DISCIPLINE_URI, versionIndId); |
129 | 0 | Long latestSequenceNumber = versionDisplayInfo.getSequenceNumber(); |
130 | 0 | boolean isLatest = latestSequenceNumber.equals(versionSequenceNumber); |
131 | |
|
132 | 0 | return isLatest; |
133 | |
} |
134 | |
|
135 | |
public void setProgramService(ProgramService programService) { |
136 | 0 | this.programService = programService; |
137 | 0 | } |
138 | |
|
139 | |
public void setStatementService(StatementService statementService) { |
140 | 0 | this.statementService = statementService; |
141 | 0 | } |
142 | |
} |