1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.student.lum.lu.ui.course.server.gwt;
17
18 import java.util.Date;
19 import java.util.HashMap;
20 import java.util.List;
21 import java.util.Map;
22
23 import org.kuali.student.common.dto.StatusInfo;
24 import org.kuali.student.common.ui.client.service.DataSaveResult;
25 import org.kuali.student.common.ui.server.gwt.DataGwtServlet;
26 import org.kuali.student.core.statement.dto.ReqComponentInfo;
27 import org.kuali.student.core.statement.dto.StatementTreeViewInfo;
28 import org.kuali.student.core.statement.service.StatementService;
29 import org.kuali.student.core.statement.ui.client.widgets.rules.ReqComponentInfoUi;
30 import org.kuali.student.core.statement.ui.client.widgets.rules.RulesUtil;
31 import org.kuali.student.lum.common.server.StatementUtil;
32 import org.kuali.student.lum.course.service.CourseService;
33 import org.kuali.student.lum.lu.ui.course.client.requirements.CourseRequirementsDataModel;
34 import org.kuali.student.lum.lu.ui.course.client.service.CourseRpcService;
35
36 public class CourseRpcGwtServlet extends DataGwtServlet implements CourseRpcService {
37
38 private static final long serialVersionUID = 1L;
39
40 private CourseService courseService;
41 private StatementService statementService;
42 private CourseStateChangeServiceImpl stateChangeService;
43
44 @Override
45 public List<StatementTreeViewInfo> getCourseStatements(String courseId, String nlUsageTypeKey, String language) throws Exception {
46 List<StatementTreeViewInfo> rules = courseService.getCourseStatements(courseId, nlUsageTypeKey, language);
47 if (rules != null) {
48 for (StatementTreeViewInfo rule : rules) {
49 setReqCompNL(rule);
50 }
51 }
52 return rules;
53 }
54
55 public Map<Integer, StatementTreeViewInfo> storeCourseStatements(String courseId, String courseState, Map<Integer, CourseRequirementsDataModel.requirementState> states,
56 Map<Integer, StatementTreeViewInfo> rules) throws Exception {
57
58 Map<Integer, StatementTreeViewInfo> storedRules = new HashMap<Integer, StatementTreeViewInfo>();
59
60 for (Integer key : rules.keySet()) {
61 StatementTreeViewInfo rule = rules.get(key);
62 switch (states.get(key)) {
63 case STORED:
64
65 storedRules.put(key, null);
66 break;
67 case ADDED:
68 storedRules.put(key, createCourseStatement(courseId, courseState, rule));
69 break;
70 case EDITED:
71 storedRules.put(key, updateCourseStatement(courseId, courseState, rule));
72 break;
73 case DELETED:
74 storedRules.put(key, null);
75 deleteCourseStatement(courseId, rule);
76 break;
77 default:
78 break;
79 }
80 }
81 return storedRules;
82 }
83
84 @Override
85 public StatementTreeViewInfo createCourseStatement(String courseId, String courseState, StatementTreeViewInfo statementTreeViewInfo) throws Exception {
86 StatementUtil.updateStatementTreeViewInfoState(courseState, statementTreeViewInfo);
87 CourseRequirementsDataModel.stripStatementIds(statementTreeViewInfo);
88 StatementTreeViewInfo rule = courseService.createCourseStatement(courseId, statementTreeViewInfo);
89 setReqCompNL(rule);
90 return rule;
91 }
92
93 @Override
94 public StatusInfo deleteCourseStatement(String courseId, StatementTreeViewInfo statementTreeViewInfo) throws Exception {
95 return courseService.deleteCourseStatement(courseId, statementTreeViewInfo);
96 }
97
98 @Override
99 public StatementTreeViewInfo updateCourseStatement(String courseId, String courseState, StatementTreeViewInfo statementTreeViewInfo) throws Exception {
100 StatementUtil.updateStatementTreeViewInfoState(courseState, statementTreeViewInfo);
101 CourseRequirementsDataModel.stripStatementIds(statementTreeViewInfo);
102 StatementTreeViewInfo rule = courseService.updateCourseStatement(courseId, statementTreeViewInfo);
103 setReqCompNL(rule);
104 return rule;
105 }
106
107 @Override
108 public DataSaveResult createCopyCourse(String originalCluId)
109 throws Exception {
110 throw new UnsupportedOperationException("Copy is not implemented without a proposal.");
111 }
112
113 @Override
114 public DataSaveResult createCopyCourseProposal(String originalProposalId)
115 throws Exception {
116 throw new UnsupportedOperationException("Copy is not implemented without a proposal.");
117 }
118
119
120 public StatusInfo changeState(String courseId, String newState) throws Exception {
121 return changeState(courseId, newState, null);
122 }
123
124 public StatusInfo changeState(String courseId, String newState, Date currentVersionStart) throws Exception {
125 return stateChangeService.changeState(courseId, newState, currentVersionStart);
126 }
127
128 private void setReqCompNL(StatementTreeViewInfo tree) throws Exception {
129 List<StatementTreeViewInfo> statements = tree.getStatements();
130 List<ReqComponentInfo> reqComponentInfos = tree.getReqComponents();
131
132 if ((statements != null) && (statements.size() > 0)) {
133
134 for (StatementTreeViewInfo statement : statements) {
135 setReqCompNL(statement);
136 }
137 } else if ((reqComponentInfos != null) && (reqComponentInfos.size() > 0)) {
138
139 for (int i = 0; i < reqComponentInfos.size(); i++) {
140 ReqComponentInfoUi reqUi = RulesUtil.clone(reqComponentInfos.get(i));
141 reqUi.setNaturalLanguageTranslation(statementService.translateReqComponentToNL(reqUi, "KUALI.RULE", "en"));
142 reqUi.setPreviewNaturalLanguageTranslation(statementService.translateReqComponentToNL(reqUi, "KUALI.RULE.PREVIEW", "en"));
143 reqComponentInfos.set(i, reqUi);
144 }
145 }
146 }
147
148 public void setCourseService(CourseService courseService) {
149 this.courseService = courseService;
150 }
151
152 public void setStatementService(StatementService statementService) {
153 this.statementService = statementService;
154 }
155
156 public void setStateChangeService(
157 CourseStateChangeServiceImpl stateChangeService) {
158 this.stateChangeService = stateChangeService;
159 }
160 }