1 package org.kuali.student.lum.lu.ui.dependency.server;
2
3 import java.util.ArrayList;
4 import java.util.List;
5
6 import org.kuali.student.core.statement.dto.ReqComponentInfo;
7 import org.kuali.student.core.statement.dto.StatementTreeViewInfo;
8 import org.kuali.student.core.statement.service.StatementService;
9 import org.kuali.student.core.statement.ui.client.widgets.rules.ReqComponentInfoUi;
10 import org.kuali.student.core.statement.ui.client.widgets.rules.RulesUtil;
11 import org.kuali.student.lum.lu.ui.dependency.client.service.DependencyAnalysisRpcService;
12 import org.kuali.student.lum.program.dto.ProgramRequirementInfo;
13 import org.kuali.student.lum.program.service.ProgramService;
14
15 import com.google.gwt.user.server.rpc.RemoteServiceServlet;
16
17 public class DependencyAnalysisRpcServlet extends RemoteServiceServlet implements DependencyAnalysisRpcService{
18
19 private static final long serialVersionUID = 1L;
20
21 StatementService statementService;
22 ProgramService programService;
23
24 @Override
25 public String getRequirementComponentNL(String reqComponentId) {
26 return null;
27 }
28
29 @Override
30 public List<String> getRequirementComponentNL(List<String> reqComponentIds) throws Exception{
31 List<String> reqComponents = new ArrayList<String>();
32 for (String reqComponentId:reqComponentIds){
33 String reqCompNL = statementService.getNaturalLanguageForReqComponent(reqComponentId, "KUALI.RULE", "en");
34 reqComponents.add(reqCompNL);
35 }
36
37 return reqComponents;
38 }
39
40
41 @Override
42 public ProgramRequirementInfo getProgramRequirement(String reqId) throws Exception {
43 ProgramRequirementInfo programRequirementInfo = programService.getProgramRequirement(reqId, null, null);
44
45 setProgReqNL(programRequirementInfo);
46 return programRequirementInfo;
47 }
48
49 public StatementService getStatementService() {
50 return statementService;
51 }
52
53 public void setStatementService(StatementService statementService) {
54 this.statementService = statementService;
55 }
56
57 public ProgramService getProgramService() {
58 return programService;
59 }
60
61 public void setProgramService(ProgramService programService) {
62 this.programService = programService;
63 }
64
65 private void setProgReqNL(ProgramRequirementInfo programRequirementInfo) throws Exception {
66 setReqCompNL(programRequirementInfo.getStatement());
67 }
68
69 private void setReqCompNL(StatementTreeViewInfo tree) throws Exception {
70 List<StatementTreeViewInfo> statements = tree.getStatements();
71 List<ReqComponentInfo> reqComponentInfos = tree.getReqComponents();
72
73 if ((statements != null) && (statements.size() > 0)) {
74
75 for (StatementTreeViewInfo statement : statements) {
76 setReqCompNL(statement);
77 }
78 } else if ((reqComponentInfos != null) && (reqComponentInfos.size() > 0)) {
79
80 for (int i = 0; i < reqComponentInfos.size(); i++) {
81 ReqComponentInfoUi reqUi = RulesUtil.clone(reqComponentInfos.get(i));
82 reqUi.setNaturalLanguageTranslation(statementService.translateReqComponentToNL(reqUi, "KUALI.RULE", "en"));
83 reqUi.setPreviewNaturalLanguageTranslation(statementService.translateReqComponentToNL(reqUi, "KUALI.RULE.PREVIEW", "en"));
84 reqComponentInfos.set(i, reqUi);
85 }
86 }
87 }
88
89 }