123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587 |
- package edu.nju.controller;
- import java.io.File;
- import java.io.IOException;
- import java.io.PrintWriter;
- import java.util.List;
- import javax.servlet.http.HttpServletResponse;
- import edu.nju.entities.*;
- import edu.nju.model.PageExamVO;
- import edu.nju.model.enums.CollaborativeType;
- import lombok.extern.slf4j.Slf4j;
- 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.*;
- import edu.nju.service.ExtraService;
- import org.springframework.web.multipart.MultipartFile;
- import java.net.URL;
- import java.io.BufferedInputStream;
- import java.io.FileOutputStream;
- import java.io.OutputStream;
- import java.net.HttpURLConnection;
- import java.net.URLConnection;
- /**
- * 上传用例报告相关接口/extra
- */
- @Slf4j
- @Controller
- @RequestMapping(value = "/extra")
- @CrossOrigin(origins = "*", maxAge = 3600, allowCredentials = "true")
- public class ExtraController {
- @Autowired
- ExtraService extraService;
- /**
- * 上传测试报告 /uploadReport 返回测试报告id
- * @param case_id 用例id
- * @param task_id 任务id
- * @param case_take_id 用例-任务id
- * @param worker_id 人员id
- * @param name 报告名称
- * @param device_model 设备品牌
- * @param device_brand 设备名称
- * @param device_os 操作系统
- * @param script_location
- * @param report_location
- * @param log_location
- * @param response
- */
- @RequestMapping(value = "/uploadReport", method = RequestMethod.POST)
- @ResponseBody
- public void uploadReport(@RequestParam String case_id, @RequestParam String task_id, @RequestParam String case_take_id, @RequestParam String worker_id,
- @RequestParam String name, @RequestParam String device_model, @RequestParam String device_brand, @RequestParam String device_os,
- String script_location, String report_location, String log_location, HttpServletResponse response) {
- try {
- String id = extraService.saveReport(case_id, task_id, case_take_id, worker_id, name, device_model, device_brand, device_os, script_location, report_location, log_location);
- PrintWriter out = response.getWriter();
- JSONObject result = new JSONObject();
- result.put("id", id);
- out.print(result);
- out.flush();
- out.close();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- /**
- * 更新测试报告 /updateReport 只返回200或500
- * @param report_id 报告id
- * @param case_id 用例id
- * @param task_id 任务id
- * @param case_take_id 用例-任务id
- * @param worker_id 人员id
- * @param name 报告名称
- * @param device_model 设备品牌
- * @param device_brand 设备名称
- * @param device_os 操作系统
- * @param script_location
- * @param report_location
- * @param log_location
- * @param response
- */
- @RequestMapping(value = "/updateReport", method = RequestMethod.POST)
- @ResponseBody
- public void updateReport(String report_id, String case_id, String task_id, String case_take_id, String worker_id, String name, String device_model,
- String device_brand, String device_os, String script_location, String report_location,
- String log_location, HttpServletResponse response) {
- try {
- boolean bool = extraService.updateReport(report_id, case_id, task_id, case_take_id, worker_id, name,
- device_model, device_brand, device_os, script_location, report_location, log_location);
- PrintWriter out = response.getWriter();
- JSONObject result = new JSONObject();
- if(bool) { result.put("status", 200); }
- else { result.put("status", 500); }
- out.print(result);
- out.flush();
- out.close();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- /**
- * 获取测试报告 /getReport
- * @param report_id 报告id
- * @param response
- */
- @RequestMapping(value = "/getReport")
- @ResponseBody
- public void getReport(String report_id, HttpServletResponse response) {
- try {
- PrintWriter out = response.getWriter();
- JSONObject result = new JSONObject();
- Report report = extraService.getReport(report_id);
- if(report != null) {
- result.put("status", 200);
- result.put("result", new JSONObject(report));
- }
- else { result.put("status", 500); }
- out.print(result);
- out.flush();
- out.close();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- //获得一场众测三级页面信息
- @RequestMapping(value = "/getPageVo")
- @ResponseBody
- public PageExamVO findPage(Long examId, Long caseId) {
- return extraService.findPageAndExam(examId,caseId);
- }
- /**
- * /findByWorker 使用case_take_id 和 worker_id获取测试报告信息
- * @param case_take_id
- * @param worker_id
- * @param response
- */
- @GetMapping(value = "/findByWorker")
- @ResponseBody
- public void findByWorker(String case_take_id, String worker_id, HttpServletResponse response) {
- try {
- PrintWriter out = response.getWriter();
- JSONObject result = new JSONObject();
- Report report = extraService.findByWorker(case_take_id, worker_id);
- if(report != null) {
- result.put("status", 200);
- result.put("result", new JSONObject(report));
- }
- else { result.put("status", 500); }
- out.print(result);
- out.flush();
- out.close();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- /**
- * 获取测试用例列表 /getCaseList 返回报告下的所有用例信息
- * @param report_id 报告id
- * @param response
- */
- @GetMapping(value = "/getCaseList")
- @ResponseBody
- public void getCaseList(String report_id, HttpServletResponse response) {
- try {
- PrintWriter out = response.getWriter();
- JSONObject result = new JSONObject();
- List<TestCase> caseList = extraService.getCaseList(report_id);
- if(caseList != null) {
- result.put("status", 200);
- result.put("result", new JSONArray(caseList));
- }
- else { result.put("status", 500); }
- out.print(result);
- out.flush();
- out.close();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- /**
- * 获取测试Bug列表 /getBugList 返回报告下的所有bug
- * @param report_id 报告id
- * @param case_take_id 用例-任务id
- * @param response
- */
- @GetMapping(value = "/getBugList")
- @ResponseBody
- public void getBugList(String report_id, String case_take_id, HttpServletResponse response) {
- try {
- PrintWriter out = response.getWriter();
- JSONObject result = new JSONObject();
- List<Bug> bugList = extraService.getBugList(report_id, case_take_id);
- if(bugList != null && bugList.size() > 0) {
- result.put("status", 200);
- result.put("result", new JSONArray(bugList));
- }
- else { result.put("status", 500); }
- out.print(result);
- out.flush();
- out.close();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- /**
- * 47.99.140.117:9001/Bug/api/extra/uploadExam
- *
- * @param file
- * 文件流
- * @param case_id
- * 测试目标id
- * @param file_name
- * 上传excel的文件名
- * @param paper_type
- * 试卷类型,即试卷的显示矩阵
- * @param test_type
- * 测试分类,如工具
- * @param description
- * 测试说明
- * @param app_name
- * 测试目标的名称
- * @return JSONArray
- */
- @RequestMapping(value = "/uploadExam", method = RequestMethod.POST)
- @ResponseBody
- public String uploadExam(@RequestParam("file") MultipartFile file, String file_name, String paper_type,
- String case_id, String test_type, String description, String app_name) {
- try {
- File dest = new File("/Users/guochao/Downloads/" + file_name);
- if(!dest.getParentFile().exists()) { dest.getParentFile().mkdirs(); }
- if(!file.isEmpty()) { file.transferTo(dest); }
- String json = extraService.saveExam(case_id, dest.getPath(), app_name, paper_type, test_type, description, CollaborativeType.IS_COLLABORATIVE.getId()+"");
- return json;
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- return "";
- }
- }
- /**
- * 创建任务
- * @param file 文件oss的url
- * @param file_name
- * @param paper_type
- * @param case_id
- * @param test_type
- * @param description
- * @param app_name
- * @param collaborative_type
- * @return
- */
- @RequestMapping(value = "/uploadExamUrl", method = RequestMethod.POST)
- @ResponseBody
- public String uploadExamUrl(String file, String file_name, String paper_type,
- String case_id, String test_type, String description, String app_name, @PathVariable(required = false) String collaborative_type) {
- try {
- System.out.println("file " + file);
- System.out.println("file_name " + file_name);
- File dest = new File("/Users/guochao/Downloads/" + file_name);
- if(!dest.getParentFile().exists()) { dest.getParentFile().mkdirs(); }
- //从oss下载文件
- // 统一资源
- URL url = new URL(file);
- // 连接类的父类,抽象类
- URLConnection urlConnection = url.openConnection();
- // http的连接类
- HttpURLConnection httpURLConnection = (HttpURLConnection) urlConnection;
- //设置超时
- httpURLConnection.setConnectTimeout(1000*5);
- //设置请求方式,默认是GET
- // httpURLConnection.setRequestMethod("GET");
- // 设置字符编码
- httpURLConnection.setRequestProperty("Charset", "UTF-8");
- // 打开到此 URL引用的资源的通信链接(如果尚未建立这样的连接)。
- httpURLConnection.connect();
- // 文件大小
- int fileLength = httpURLConnection.getContentLength();
- // 建立链接从请求中获取数据
- URLConnection con = url.openConnection();
- BufferedInputStream bin = new BufferedInputStream(httpURLConnection.getInputStream());
- // 指定文件名称(有需求可以自定义)
- // 指定存放位置(有需求可以自定义)
- OutputStream out = new FileOutputStream(dest);
- int size = 0;
- int len = 0;
- byte[] buf = new byte[2048];
- while ((size = bin.read(buf)) != -1) {
- len += size;
- out.write(buf, 0, size);
- }
- // 关闭资源
- bin.close();
- out.close();
- if(collaborative_type == null || collaborative_type == ""){
- collaborative_type = CollaborativeType.IS_COLLABORATIVE.getId() + "";
- }
- System.out.println(dest.getPath());
- String json = extraService.saveExam(case_id, dest.getPath(), app_name, paper_type, test_type, description, collaborative_type);
- return json;
- } catch (IOException e) {
- e.printStackTrace();
- return "";
- }
- }
- // @RequestMapping(value = "/uploadExamUrl", method = RequestMethod.POST)
- // @ResponseBody
- // public String uploadExamUrl1(String file, String file_name, String paper_type,
- // String case_id, String test_type, String description, String app_name,
- // String if_test_case,String if_bug) {
- // try {
- //
- // File dest = new File("/Users/guochao/Downloads/" + file_name);
- // if(!dest.getParentFile().exists()) { dest.getParentFile().mkdirs(); }
- // //从oss下载文件
- // // 统一资源
- // URL url = new URL(file);
- // // 连接类的父类,抽象类
- // URLConnection urlConnection = url.openConnection();
- // // http的连接类
- // HttpURLConnection httpURLConnection = (HttpURLConnection) urlConnection;
- // //设置超时
- // httpURLConnection.setConnectTimeout(1000*5);
- // //设置请求方式,默认是GET
- //// httpURLConnection.setRequestMethod("GET");
- // // 设置字符编码
- // httpURLConnection.setRequestProperty("Charset", "UTF-8");
- // // 打开到此 URL引用的资源的通信链接(如果尚未建立这样的连接)。
- // httpURLConnection.connect();
- // // 文件大小
- // int fileLength = httpURLConnection.getContentLength();
- //
- // // 建立链接从请求中获取数据
- // URLConnection con = url.openConnection();
- // BufferedInputStream bin = new BufferedInputStream(httpURLConnection.getInputStream());
- // // 指定文件名称(有需求可以自定义)
- // // 指定存放位置(有需求可以自定义)
- //
- //
- // OutputStream out = new FileOutputStream(dest);
- // int size = 0;
- // int len = 0;
- // byte[] buf = new byte[2048];
- // while ((size = bin.read(buf)) != -1) {
- // len += size;
- // out.write(buf, 0, size);
- // }
- // // 关闭资源
- // bin.close();
- // out.close();
- // String json = extraService.saveExam1(case_id, dest.getPath(), app_name, paper_type, test_type, description,if_test_case,if_bug);
- // return json;
- // } catch (IOException e) {
- // e.printStackTrace();
- // return "";
- // }
- // }
- /**
- * 47.99.140.117:9001/Bug/api/extra/getExamList
- *
- * @return 200 成功; 500 失败
- */
- @RequestMapping(value = "/getExamList", method = RequestMethod.GET)
- @ResponseBody
- public void getExamList(HttpServletResponse response) {
- try {
- PrintWriter out = response.getWriter();
- JSONObject result = new JSONObject();
- result.put("data", extraService.getExamList());
- result.put("status", 200);
- out.print(result);
- out.flush();
- out.close();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- /**
- * /getExam 获取考试的操作类型信息
- * @param id 考试id
- * @param response
- */
- @GetMapping(value = "/getExam")
- @ResponseBody
- public void getExam(String id, HttpServletResponse response) {
- try {
- PrintWriter out = response.getWriter();
- JSONObject result = new JSONObject();
- Exam exam = extraService.getExam(id);
- if(exam != null) {
- result.put("status", 200);
- result.put("result", new JSONObject(exam));
- }
- else { result.put("status", 500); }
- out.print(result);
- out.flush();
- out.close();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- /**
- * 上传测试用例 /uploadTestCase
- * @param report_id 报告id
- * @param name 用例名称
- * @param front 前置条件
- * @param behind 测试步骤
- * @param description 预期结果
- * @param if_execute 是否执行
- * @param if_bug 是否是bug
- * @param response
- */
- @RequestMapping(value = "/uploadTestCase", method = RequestMethod.POST)
- @ResponseBody
- public void uploadTestCase(String report_id, String name, String front, String behind,
- String description,String if_execute,String if_bug, HttpServletResponse response) {
- try {
- System.out.println(if_execute);
- System.out.println(if_bug);
- String id = extraService.saveTestCase(report_id, name, front, behind, description);
- PrintWriter out = response.getWriter();
- JSONObject result = new JSONObject();
- result.put("id", id);
- out.print(result);
- out.flush();
- out.close();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- /**
- * 获取指定用例id的用例信息 /getTestCase
- * @param id
- * @param response
- */
- @GetMapping(value = "/getTestCase")
- @ResponseBody
- public void getTestCase(String id, HttpServletResponse response) {
- try {
- PrintWriter out = response.getWriter();
- JSONObject result = new JSONObject();
- TestCase testCase = extraService.getTestCase(id);
- if(testCase != null) {
- result.put("status", 200);
- result.put("result", new JSONObject(testCase));
- }
- else { result.put("status", 500); }
- out.print(result);
- out.flush();
- out.close();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- /**
- * 更新测试用例 /updateTestCase 返回200或500
- * @param id 用例id
- * @param report_id 报告id
- * @param name 用例名称
- * @param front 前置条件
- * @param behind 测试步骤
- * @param description 预期结果
- * @param response
- */
- @RequestMapping(value = "/updateTestCase", method = RequestMethod.POST)
- @ResponseBody
- public void updateTestCase(String id, String report_id, String name, String front, String behind,
- String description, HttpServletResponse response) {
- try {
- PrintWriter out = response.getWriter();
- JSONObject result = new JSONObject();
- if(extraService.updateTestCase(id, report_id, name, front, behind, description)) {
- result.put("status", 200);
- } else { result.put("status", 500); }
- out.print(result);
- out.flush();
- out.close();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- @RequestMapping(value = "/updateTask", method = RequestMethod.POST)
- @ResponseBody
- public void updateTask(String id,double writeMins, HttpServletResponse response) {
- try {
- PrintWriter out = response.getWriter();
- JSONObject result = new JSONObject();
- if(extraService.updateTask(id, writeMins)) {
- result.put("status", 200);
- }
- else { result.put("status", 500); }
- out.print(result);
- out.flush();
- out.close();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- /**
- * 获取任务相关信息
- * @param id 任务ID
- * @param response
- */
- @RequestMapping(value = "/getTask")
- @ResponseBody
- public void getTask(String id, HttpServletResponse response) {
- try {
- PrintWriter out = response.getWriter();
- JSONObject result = new JSONObject();
- Task task=extraService.saveTask(id);
- if(task!=null) {
- result.put("status", 200);
- result.put("result",new JSONObject(task));
- }
- else { result.put("status", 500); }
- out.print(result);
- out.flush();
- out.close();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- @RequestMapping(value = "/reportsToReviewPaper")
- @ResponseBody
- public String getTask(String case_take_id) {
- String uploadUrl = extraService.reportsToReviewPaper(case_take_id);
- return uploadUrl;
- }
- @RequestMapping(value = "/pageUrl")
- @ResponseBody
- public void getPageUrl(String caseId,HttpServletResponse response){
- try {
- PrintWriter out = response.getWriter();
- JSONObject result = new JSONObject();
- result.put("status", 200);
- result.put("result",extraService.getPageUrl(caseId));
- out.print(result);
- out.flush();
- out.close();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
|