| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359 |
- package edu.nju.controller;
- import java.io.IOException;
- import java.io.PrintWriter;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Set;
- import javax.servlet.http.HttpServletResponse;
- import javax.servlet.http.HttpSession;
- import edu.nju.entities.Bug;
- import edu.nju.entities.BugHistory;
- import org.json.JSONArray;
- import org.json.JSONObject;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Controller;
- import org.springframework.web.bind.annotation.CrossOrigin;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.ResponseBody;
- import edu.nju.service.AnalyzeService;
- import edu.nju.service.HistoryService;
- import edu.nju.service.RecommendService;
- @Controller
- @RequestMapping(value = "/history")
- @CrossOrigin(origins = "*", maxAge = 3600, allowCredentials = "true")
- public class HistoryController {
-
- @Autowired
- HistoryService hisservice;
-
- @Autowired
- AnalyzeService aservice;
-
- @Autowired
- RecommendService recservice;
-
- //获取指定节点的历史信息
- @RequestMapping(value = "/getHistory")
- @ResponseBody
- public void getHistory(String id, HttpServletResponse response) {
- try {
- PrintWriter out = response.getWriter();
- out.print(new JSONObject(hisservice.getHistory(id)));
- out.flush();
- out.close();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
-
- //获取所有根节点
- @RequestMapping(value = "/getRoots")
- @ResponseBody
- public void getRoots(String case_take_id, HttpServletResponse response) {
- try {
- PrintWriter out = response.getWriter();
- JSONObject result = new JSONObject();
- List<String> list = hisservice.getRoots(case_take_id);
- result.put("Count", list.size());
- result.put("TreeRoot", new JSONArray(list));
- out.print(result);
- out.flush();
- out.close();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
-
- //获取所有形成树状结构的bug根节点
- @RequestMapping(value = "/getTrees")
- @ResponseBody
- public void getTrees(String case_take_id, String start, String count, String page, HttpSession session, HttpServletResponse response) {
- try {
- PrintWriter out = response.getWriter();
- JSONObject result = new JSONObject();
- List<String> all = hisservice.getTreeRoots(case_take_id);
- hisservice.pageFilter(all, page);
- List<String> ids = all.subList(Integer.parseInt(start), Math.min(all.size(), Integer.parseInt(start) + Integer.parseInt(count)));
- List<List<String>> list = new ArrayList<List<String>>();
- for(String id: ids) {
- list.add(hisservice.getDetail(id));
- }
- result.put("Count", all.size());
- result.put("TreeRoot", new JSONArray(list));
- out.print(result);
- out.flush();
- out.close();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- //学生获取所有形成树状结构的bug根节点
- @RequestMapping(value = "/getTreesStu")
- @ResponseBody
- public void getTreesStu(String case_take_id, String start, String count, String page, HttpSession session, HttpServletResponse response) {
- try {
- PrintWriter out = response.getWriter();
- JSONObject result = new JSONObject();
- List<String> all = hisservice.getTreeRoots(case_take_id);
- hisservice.pageFilter(all, page);
- hisservice.hotSortTree(all);
- List<String> ids = all.subList(Integer.parseInt(start), Math.min(all.size(), Integer.parseInt(start) + Integer.parseInt(count)));
- List<List<String>> list = new ArrayList<List<String>>();
- for(String id: ids) {
- list.add(hisservice.getDetail(id));
- }
- result.put("Count", all.size());
- result.put("TreeRoot", new JSONArray(list));
- out.print(result);
- out.flush();
- out.close();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- //获取所有单个节点的数据
- @RequestMapping(value = "/getSingle")
- @ResponseBody
- public void getSingle(String case_take_id, String start, String count, String page, HttpSession session, HttpServletResponse response) {
- try {
- PrintWriter out = response.getWriter();
- JSONObject result = new JSONObject();
- List<String> all = new ArrayList<String>();
- //// 获取所有单个节点
- //// for(String id : hisservice.getRoots(case_take_id)) {
- //// if(hisservice.getHistory(id).getChildren().size() == 0) {all.add(id);}
- //// }
- // //三级页面筛选,单个节点筛选
- // for(String id : hisservice.getBugIdListByPage(case_take_id,page,start,count)) {
- // if(hisservice.getHistory(id).getChildren().size() == 0) {all.add(id);}
- // }
- // //根据三级页面筛选
- //// hisservice.pageFilter(all, page);
- ////
- //三级页面筛选,单个节点筛选(没有parent,也没有children)
- for(String id : hisservice.getBugIdListByPage(case_take_id,page,start,count)) {
- BugHistory bugHistory=hisservice.getHistory(id);
- if(bugHistory.getChildren().size() == 0&&bugHistory.getParent().equals("null")) {all.add(id);}
- }
- //根据三级页面筛选
- //分页
- List<String> ids = all.subList(Integer.parseInt(start), Math.min(all.size(), Integer.parseInt(start) + Integer.parseInt(count)));
- List<String> invalid = hisservice.getInvalid(ids);
- for(String id: invalid) {
- if(ids.contains(id)) {ids.remove(id);}
- }
- List<List<String>> list = new ArrayList<List<String>>();
- for(String id : ids) {
- List<String> temp = new ArrayList<String>();
- temp.add(id);
- int score = aservice.getGrade(id);
- if(score != -1) {temp.add("true");}
- else {temp.add("false");}
- temp.add(recservice.getTitle(id));
- list.add(temp);
- }
- result.put("Count", all.size());
- result.put("TreeRoot", new JSONArray(list));
- out.print(result);
- out.flush();
- out.close();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- //学生获取所有单个节点的数据
- @RequestMapping(value = "/getSingleStu")
- @ResponseBody
- public void getSingleStu(String case_take_id, String start, String count, String page, HttpSession session, HttpServletResponse response) {
- try {
- PrintWriter out = response.getWriter();
- JSONObject result = new JSONObject();
- List<String> all = new ArrayList<String>();
- // //获取所有root
- // for(String id : hisservice.getRoots(case_take_id)) {
- // if(hisservice.getHistory(id).getChildren().size() == 0) {all.add(id);}
- // }
- // //根据三级页面筛选
- // hisservice.pageFilter(all, page);
- //
- // //根据热度排序
- // hisservice.hotSortSingle(all);
- //
- // //分页
- // List<String> ids = all.subList(Integer.parseInt(start), Math.min(all.size(), Integer.parseInt(start) + Integer.parseInt(count)));
- //三级页面筛选,单个节点筛选(没有parent,也没有children)
- for(String id : hisservice.getBugIdListByPage(case_take_id,page,start,count)) {
- BugHistory bugHistory=hisservice.getHistory(id);
- if(bugHistory.getChildren().size() == 0&&bugHistory.getParent().equals("null")) {all.add(id);}
- }
- //根据热度排序,热度低的排在前面
- hisservice.hotSortSingle(all);
- //根据三级页面筛选
- //分页
- List<String> ids = all.subList(Integer.parseInt(start), Math.min(all.size(), Integer.parseInt(start) + Integer.parseInt(count)));
- List<String> invalid = hisservice.getInvalid(ids);
- for(String id: invalid) {
- if(ids.contains(id)) {ids.remove(id);}
- }
- //判断是否已被评分
- List<List<String>> list = new ArrayList<List<String>>();
- for(String id : ids) {
- List<String> temp = new ArrayList<String>();
- temp.add(id);
- int score = aservice.getGrade(id);
- if(score != -1) {temp.add("true");}
- else {temp.add("false");}
- temp.add(recservice.getTitle(id));
- list.add(temp);
- }
- result.put("Count", all.size());
- result.put("TreeRoot", new JSONArray(list));
- out.print(result);
- out.flush();
- out.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
-
- //获取指定bug的所有路径
- @RequestMapping(value = "/getPath")
- @ResponseBody
- public void getPath(String id, HttpServletResponse response) {
- try {
- PrintWriter out = response.getWriter();
- JSONObject result = new JSONObject();
- List<List<String>> lists = hisservice.getDepth(id);
- Set<String> filter = hisservice.filter(lists);
- result.put("path", new JSONArray(lists));
- result.put("invalid", new JSONArray(hisservice.getInvalid(filter)));
- List<String> ids = new ArrayList<String>(filter);
- result.put("score", new JSONArray(aservice.getScores(ids)));
- out.print(result);
- out.flush();
- out.close();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
-
- @RequestMapping(value = "/fresh")
- @ResponseBody
- public void fresh(HttpSession session, HttpServletResponse response) {
- if(session.getAttribute("trees") != null) {session.removeAttribute("trees");}
- if(session.getAttribute("single") != null) {session.removeAttribute("single");}
- }
- //根据条件筛选单个节点的数据
- @RequestMapping(value = "/getSingleByCondition")
- @ResponseBody
- public void getSingleByCondition(String case_take_id, String start, String count, String page,String condition, HttpSession session, HttpServletResponse response) {
- try {
- String bugCondition="";
- PrintWriter out = response.getWriter();
- JSONObject result = new JSONObject();
- List<String> all = new ArrayList<String>();
- // for(String id : hisservice.getRoots(case_take_id)) {
- // //根据是否有子bug判断是否是单节点
- // if(hisservice.getHistory(id).getChildren().size() == 0) {
- // //判断是否满足条件
- // int score = aservice.getGrade(id);
- // if(score != -1) {
- // bugCondition="true";
- // }
- // else {bugCondition="false";}
- // if(bugCondition.equals(condition)){
- // all.add(id);
- // }
- // }
- // }
- // hisservice.pageFilter(all, page);
- //
- for(String id : hisservice.getBugIdListByPage(case_take_id,page,start,count)) {
- BugHistory bugHistory=hisservice.getHistory(id);
- if(bugHistory.getChildren().size() == 0&&bugHistory.getParent().equals("null")) {
- int score = aservice.getGrade(id);
- if(score != -1) {
- bugCondition="true";
- }
- else {bugCondition="false";}
- if(bugCondition.equals(condition)) {
- all.add(id);
- }
- }
- }
- hisservice.hotSortSingle(all);
- List<String> ids = all.subList(Integer.parseInt(start), Math.min(all.size(), Integer.parseInt(start) + Integer.parseInt(count)));
- //根据热度排序,热度低的排在前面
- List<String> invalid = hisservice.getInvalid(ids);
- for(String id: invalid) {
- if(ids.contains(id)) {ids.remove(id);}
- }
- List<List<String>> list = new ArrayList<List<String>>();
- for(String id : ids) {
- List<String> temp = new ArrayList<String>();
- temp.add(id);
- temp.add(condition);
- temp.add(recservice.getTitle(id));
- list.add(temp);
- }
- //所有符合条件的,而非仅仅是展示的
- result.put("Count", all.size());
- result.put("TreeRoot", new JSONArray(list));
- out.print(result);
- out.flush();
- out.close();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- @RequestMapping(value = "/test")
- @ResponseBody
- public void getBugByPage(String case_take_id, String start, String count, String page, HttpSession session, HttpServletResponse response){
- List<String> bugList=hisservice.getBugIdListByPage(case_take_id,page,start,count);
- try {
- PrintWriter out = response.getWriter();
- JSONObject result = new JSONObject();
- result.put("Count",bugList.size());
- result.put("TreeRoot", new JSONArray(bugList));
- out.print(result);
- out.flush();
- out.close();
- }catch (IOException e){
- e.printStackTrace();
- }
- }
- }
|