HistoryController.java 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. package edu.nju.controller;
  2. import java.io.IOException;
  3. import java.io.PrintWriter;
  4. import java.util.ArrayList;
  5. import java.util.List;
  6. import java.util.Set;
  7. import javax.servlet.http.HttpServletResponse;
  8. import javax.servlet.http.HttpSession;
  9. import edu.nju.entities.Bug;
  10. import edu.nju.entities.BugHistory;
  11. import org.json.JSONArray;
  12. import org.json.JSONObject;
  13. import org.springframework.beans.factory.annotation.Autowired;
  14. import org.springframework.stereotype.Controller;
  15. import org.springframework.web.bind.annotation.CrossOrigin;
  16. import org.springframework.web.bind.annotation.RequestMapping;
  17. import org.springframework.web.bind.annotation.ResponseBody;
  18. import edu.nju.service.AnalyzeService;
  19. import edu.nju.service.HistoryService;
  20. import edu.nju.service.RecommendService;
  21. @Controller
  22. @RequestMapping(value = "/history")
  23. @CrossOrigin(origins = "*", maxAge = 3600, allowCredentials = "true")
  24. public class HistoryController {
  25. @Autowired
  26. HistoryService hisservice;
  27. @Autowired
  28. AnalyzeService aservice;
  29. @Autowired
  30. RecommendService recservice;
  31. //获取指定节点的历史信息
  32. @RequestMapping(value = "/getHistory")
  33. @ResponseBody
  34. public void getHistory(String id, HttpServletResponse response) {
  35. try {
  36. PrintWriter out = response.getWriter();
  37. out.print(new JSONObject(hisservice.getHistory(id)));
  38. out.flush();
  39. out.close();
  40. } catch (IOException e) {
  41. // TODO Auto-generated catch block
  42. e.printStackTrace();
  43. }
  44. }
  45. //获取所有根节点
  46. @RequestMapping(value = "/getRoots")
  47. @ResponseBody
  48. public void getRoots(String case_take_id, HttpServletResponse response) {
  49. try {
  50. PrintWriter out = response.getWriter();
  51. JSONObject result = new JSONObject();
  52. List<String> list = hisservice.getRoots(case_take_id);
  53. result.put("Count", list.size());
  54. result.put("TreeRoot", new JSONArray(list));
  55. out.print(result);
  56. out.flush();
  57. out.close();
  58. } catch (IOException e) {
  59. // TODO Auto-generated catch block
  60. e.printStackTrace();
  61. }
  62. }
  63. //获取所有形成树状结构的bug根节点
  64. @RequestMapping(value = "/getTrees")
  65. @ResponseBody
  66. public void getTrees(String case_take_id, String start, String count, String page, HttpSession session, HttpServletResponse response) {
  67. try {
  68. PrintWriter out = response.getWriter();
  69. JSONObject result = new JSONObject();
  70. List<String> all = hisservice.getTreeRoots(case_take_id);
  71. hisservice.pageFilter(all, page);
  72. List<String> ids = all.subList(Integer.parseInt(start), Math.min(all.size(), Integer.parseInt(start) + Integer.parseInt(count)));
  73. List<List<String>> list = new ArrayList<List<String>>();
  74. for(String id: ids) {
  75. list.add(hisservice.getDetail(id));
  76. }
  77. result.put("Count", all.size());
  78. result.put("TreeRoot", new JSONArray(list));
  79. out.print(result);
  80. out.flush();
  81. out.close();
  82. } catch (IOException e) {
  83. // TODO Auto-generated catch block
  84. e.printStackTrace();
  85. }
  86. }
  87. //学生获取所有形成树状结构的bug根节点
  88. @RequestMapping(value = "/getTreesStu")
  89. @ResponseBody
  90. public void getTreesStu(String case_take_id, String start, String count, String page, HttpSession session, HttpServletResponse response) {
  91. try {
  92. PrintWriter out = response.getWriter();
  93. JSONObject result = new JSONObject();
  94. List<String> all = hisservice.getTreeRoots(case_take_id);
  95. hisservice.pageFilter(all, page);
  96. hisservice.hotSortTree(all);
  97. List<String> ids = all.subList(Integer.parseInt(start), Math.min(all.size(), Integer.parseInt(start) + Integer.parseInt(count)));
  98. List<List<String>> list = new ArrayList<List<String>>();
  99. for(String id: ids) {
  100. list.add(hisservice.getDetail(id));
  101. }
  102. result.put("Count", all.size());
  103. result.put("TreeRoot", new JSONArray(list));
  104. out.print(result);
  105. out.flush();
  106. out.close();
  107. } catch (IOException e) {
  108. // TODO Auto-generated catch block
  109. e.printStackTrace();
  110. }
  111. }
  112. //获取所有单个节点的数据
  113. @RequestMapping(value = "/getSingle")
  114. @ResponseBody
  115. public void getSingle(String case_take_id, String start, String count, String page, HttpSession session, HttpServletResponse response) {
  116. try {
  117. PrintWriter out = response.getWriter();
  118. JSONObject result = new JSONObject();
  119. List<String> all = new ArrayList<String>();
  120. //// 获取所有单个节点
  121. //// for(String id : hisservice.getRoots(case_take_id)) {
  122. //// if(hisservice.getHistory(id).getChildren().size() == 0) {all.add(id);}
  123. //// }
  124. // //三级页面筛选,单个节点筛选
  125. // for(String id : hisservice.getBugIdListByPage(case_take_id,page,start,count)) {
  126. // if(hisservice.getHistory(id).getChildren().size() == 0) {all.add(id);}
  127. // }
  128. // //根据三级页面筛选
  129. //// hisservice.pageFilter(all, page);
  130. ////
  131. //三级页面筛选,单个节点筛选(没有parent,也没有children)
  132. for(String id : hisservice.getBugIdListByPage(case_take_id,page,start,count)) {
  133. BugHistory bugHistory=hisservice.getHistory(id);
  134. if(bugHistory.getChildren().size() == 0&&bugHistory.getParent().equals("null")) {all.add(id);}
  135. }
  136. //根据三级页面筛选
  137. //分页
  138. List<String> ids = all.subList(Integer.parseInt(start), Math.min(all.size(), Integer.parseInt(start) + Integer.parseInt(count)));
  139. List<String> invalid = hisservice.getInvalid(ids);
  140. for(String id: invalid) {
  141. if(ids.contains(id)) {ids.remove(id);}
  142. }
  143. List<List<String>> list = new ArrayList<List<String>>();
  144. for(String id : ids) {
  145. List<String> temp = new ArrayList<String>();
  146. temp.add(id);
  147. int score = aservice.getGrade(id);
  148. if(score != -1) {temp.add("true");}
  149. else {temp.add("false");}
  150. temp.add(recservice.getTitle(id));
  151. list.add(temp);
  152. }
  153. result.put("Count", all.size());
  154. result.put("TreeRoot", new JSONArray(list));
  155. out.print(result);
  156. out.flush();
  157. out.close();
  158. } catch (IOException e) {
  159. // TODO Auto-generated catch block
  160. e.printStackTrace();
  161. }
  162. }
  163. //学生获取所有单个节点的数据
  164. @RequestMapping(value = "/getSingleStu")
  165. @ResponseBody
  166. public void getSingleStu(String case_take_id, String start, String count, String page, HttpSession session, HttpServletResponse response) {
  167. try {
  168. PrintWriter out = response.getWriter();
  169. JSONObject result = new JSONObject();
  170. List<String> all = new ArrayList<String>();
  171. // //获取所有root
  172. // for(String id : hisservice.getRoots(case_take_id)) {
  173. // if(hisservice.getHistory(id).getChildren().size() == 0) {all.add(id);}
  174. // }
  175. // //根据三级页面筛选
  176. // hisservice.pageFilter(all, page);
  177. //
  178. // //根据热度排序
  179. // hisservice.hotSortSingle(all);
  180. //
  181. // //分页
  182. // List<String> ids = all.subList(Integer.parseInt(start), Math.min(all.size(), Integer.parseInt(start) + Integer.parseInt(count)));
  183. //三级页面筛选,单个节点筛选(没有parent,也没有children)
  184. for(String id : hisservice.getBugIdListByPage(case_take_id,page,start,count)) {
  185. BugHistory bugHistory=hisservice.getHistory(id);
  186. if(bugHistory.getChildren().size() == 0&&bugHistory.getParent().equals("null")) {all.add(id);}
  187. }
  188. //根据热度排序,热度低的排在前面
  189. hisservice.hotSortSingle(all);
  190. //根据三级页面筛选
  191. //分页
  192. List<String> ids = all.subList(Integer.parseInt(start), Math.min(all.size(), Integer.parseInt(start) + Integer.parseInt(count)));
  193. List<String> invalid = hisservice.getInvalid(ids);
  194. for(String id: invalid) {
  195. if(ids.contains(id)) {ids.remove(id);}
  196. }
  197. //判断是否已被评分
  198. List<List<String>> list = new ArrayList<List<String>>();
  199. for(String id : ids) {
  200. List<String> temp = new ArrayList<String>();
  201. temp.add(id);
  202. int score = aservice.getGrade(id);
  203. if(score != -1) {temp.add("true");}
  204. else {temp.add("false");}
  205. temp.add(recservice.getTitle(id));
  206. list.add(temp);
  207. }
  208. result.put("Count", all.size());
  209. result.put("TreeRoot", new JSONArray(list));
  210. out.print(result);
  211. out.flush();
  212. out.close();
  213. } catch (IOException e) {
  214. e.printStackTrace();
  215. }
  216. }
  217. //获取指定bug的所有路径
  218. @RequestMapping(value = "/getPath")
  219. @ResponseBody
  220. public void getPath(String id, HttpServletResponse response) {
  221. try {
  222. PrintWriter out = response.getWriter();
  223. JSONObject result = new JSONObject();
  224. List<List<String>> lists = hisservice.getDepth(id);
  225. Set<String> filter = hisservice.filter(lists);
  226. result.put("path", new JSONArray(lists));
  227. result.put("invalid", new JSONArray(hisservice.getInvalid(filter)));
  228. List<String> ids = new ArrayList<String>(filter);
  229. result.put("score", new JSONArray(aservice.getScores(ids)));
  230. out.print(result);
  231. out.flush();
  232. out.close();
  233. } catch (IOException e) {
  234. // TODO Auto-generated catch block
  235. e.printStackTrace();
  236. }
  237. }
  238. @RequestMapping(value = "/fresh")
  239. @ResponseBody
  240. public void fresh(HttpSession session, HttpServletResponse response) {
  241. if(session.getAttribute("trees") != null) {session.removeAttribute("trees");}
  242. if(session.getAttribute("single") != null) {session.removeAttribute("single");}
  243. }
  244. //根据条件筛选单个节点的数据
  245. @RequestMapping(value = "/getSingleByCondition")
  246. @ResponseBody
  247. public void getSingleByCondition(String case_take_id, String start, String count, String page,String condition, HttpSession session, HttpServletResponse response) {
  248. try {
  249. String bugCondition="";
  250. PrintWriter out = response.getWriter();
  251. JSONObject result = new JSONObject();
  252. List<String> all = new ArrayList<String>();
  253. // for(String id : hisservice.getRoots(case_take_id)) {
  254. // //根据是否有子bug判断是否是单节点
  255. // if(hisservice.getHistory(id).getChildren().size() == 0) {
  256. // //判断是否满足条件
  257. // int score = aservice.getGrade(id);
  258. // if(score != -1) {
  259. // bugCondition="true";
  260. // }
  261. // else {bugCondition="false";}
  262. // if(bugCondition.equals(condition)){
  263. // all.add(id);
  264. // }
  265. // }
  266. // }
  267. // hisservice.pageFilter(all, page);
  268. //
  269. for(String id : hisservice.getBugIdListByPage(case_take_id,page,start,count)) {
  270. BugHistory bugHistory=hisservice.getHistory(id);
  271. if(bugHistory.getChildren().size() == 0&&bugHistory.getParent().equals("null")) {
  272. int score = aservice.getGrade(id);
  273. if(score != -1) {
  274. bugCondition="true";
  275. }
  276. else {bugCondition="false";}
  277. if(bugCondition.equals(condition)) {
  278. all.add(id);
  279. }
  280. }
  281. }
  282. hisservice.hotSortSingle(all);
  283. List<String> ids = all.subList(Integer.parseInt(start), Math.min(all.size(), Integer.parseInt(start) + Integer.parseInt(count)));
  284. //根据热度排序,热度低的排在前面
  285. List<String> invalid = hisservice.getInvalid(ids);
  286. for(String id: invalid) {
  287. if(ids.contains(id)) {ids.remove(id);}
  288. }
  289. List<List<String>> list = new ArrayList<List<String>>();
  290. for(String id : ids) {
  291. List<String> temp = new ArrayList<String>();
  292. temp.add(id);
  293. temp.add(condition);
  294. temp.add(recservice.getTitle(id));
  295. list.add(temp);
  296. }
  297. //所有符合条件的,而非仅仅是展示的
  298. result.put("Count", all.size());
  299. result.put("TreeRoot", new JSONArray(list));
  300. out.print(result);
  301. out.flush();
  302. out.close();
  303. } catch (IOException e) {
  304. // TODO Auto-generated catch block
  305. e.printStackTrace();
  306. }
  307. }
  308. @RequestMapping(value = "/test")
  309. @ResponseBody
  310. public void getBugByPage(String case_take_id, String start, String count, String page, HttpSession session, HttpServletResponse response){
  311. List<String> bugList=hisservice.getBugIdListByPage(case_take_id,page,start,count);
  312. try {
  313. PrintWriter out = response.getWriter();
  314. JSONObject result = new JSONObject();
  315. result.put("Count",bugList.size());
  316. result.put("TreeRoot", new JSONArray(bugList));
  317. out.print(result);
  318. out.flush();
  319. out.close();
  320. }catch (IOException e){
  321. e.printStackTrace();
  322. }
  323. }
  324. }