|
@@ -2,22 +2,14 @@ package edu.nju.util;
|
|
|
|
|
|
import edu.nju.dao.BugDao;
|
|
|
import edu.nju.dao.ReportDao;
|
|
|
-import edu.nju.dao.StuInfoDao;
|
|
|
-import edu.nju.dao.TaskDao;
|
|
|
import edu.nju.entities.Bug;
|
|
|
import edu.nju.entities.Report;
|
|
|
-import edu.nju.entities.StuInfo;
|
|
|
-import edu.nju.entities.Task;
|
|
|
import org.aspectj.lang.JoinPoint;
|
|
|
import org.aspectj.lang.ProceedingJoinPoint;
|
|
|
import org.aspectj.lang.annotation.*;
|
|
|
-import org.json.JSONArray;
|
|
|
-import org.json.JSONObject;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
-import java.util.List;
|
|
|
|
|
|
|
|
|
/**
|
|
@@ -36,17 +28,6 @@ public class BlockChainAspect {
|
|
|
@Autowired
|
|
|
ReportDao reportDao;
|
|
|
|
|
|
- @Autowired
|
|
|
- TaskDao taskDao;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- StuInfoDao stuInfoDao;
|
|
|
-
|
|
|
- private static final String blockChainHost="http://111.231.68.200:8082/";
|
|
|
-
|
|
|
- @Value("${mooctest.url}")
|
|
|
- private String MOOCTEST_HOST;
|
|
|
-
|
|
|
|
|
|
/**
|
|
|
* 定义切入点,切入点为com.example.demo.aop.AopController中的所有函数
|
|
@@ -61,13 +42,34 @@ public class BlockChainAspect {
|
|
|
public void saveBugGrade(){
|
|
|
|
|
|
}
|
|
|
+ /**
|
|
|
+ * @description 在连接点执行之前执行的通知
|
|
|
+ */
|
|
|
+ @Before("saveBugGrade()")
|
|
|
+ public void doBeforeGame(JoinPoint joinPoint){
|
|
|
+ Object[] obj = joinPoint.getArgs();
|
|
|
+ for (Object argItem : obj) {
|
|
|
+ System.out.println("---->now-->argItem:" + argItem);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @description 在连接点执行之后执行的通知(返回通知和异常通知的异常)
|
|
|
+ */
|
|
|
+ @After("saveBugGrade()")
|
|
|
+ public void doAfterGame(JoinPoint joinPoint){
|
|
|
+ Object[] obj = joinPoint.getArgs();
|
|
|
+ for (Object argItem : obj) {
|
|
|
+ System.out.println("---->now-->argItem:" + argItem);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* @description 保存bug分数后传递给区块链
|
|
|
*/
|
|
|
@AfterReturning(value="saveBugGrade()",returning = "keys")
|
|
|
public void doAfterReturningSaveBugGrade(JoinPoint joinPoint,Object keys){
|
|
|
- System.out.println("传递给区块链");
|
|
|
Object[] obj = joinPoint.getArgs();
|
|
|
for (Object argItem : obj) {
|
|
|
System.out.println("---->now-->argItem:" + argItem);
|
|
@@ -80,231 +82,57 @@ public class BlockChainAspect {
|
|
|
|
|
|
Bug bug=bugDao.findByid(bugId);
|
|
|
Report report=reportDao.findById(bug.getReport_id());
|
|
|
+ String crowdTestId=report.getCase_take_id();
|
|
|
|
|
|
-
|
|
|
-
|
|
|
- String defaultString="慕测管理员";
|
|
|
-
|
|
|
- JSONObject bugReviewVO=new JSONObject();
|
|
|
-
|
|
|
- if(report==null){
|
|
|
- bugReviewVO.put("bugReportId",bugId);
|
|
|
- bugReviewVO.put("bugReportScore",Integer.parseInt(grade));
|
|
|
- bugReviewVO.put("reportReviewer",defaultString);
|
|
|
- bugReviewVO.put("taskId",defaultString);
|
|
|
- bugReviewVO.put("taskName",defaultString);
|
|
|
- bugReviewVO.put("testReportId",defaultString);
|
|
|
- bugReviewVO.put("type",0);
|
|
|
- bugReviewVO.put("updateTime",System.currentTimeMillis());
|
|
|
- }else{
|
|
|
- bugReviewVO.put("bugReportId",bugId);
|
|
|
- bugReviewVO.put("bugReportScore",Integer.parseInt(grade));
|
|
|
- bugReviewVO.put("reportReviewer",defaultString);
|
|
|
- bugReviewVO.put("taskId",report.getCase_take_id());
|
|
|
-
|
|
|
- Task task=taskDao.findById(report.getTask_id());
|
|
|
- if(task==null){
|
|
|
- task=getAndSaveTaskInfo(report.getTask_id());
|
|
|
- if(task==null){
|
|
|
- bugReviewVO.put("taskName",defaultString);
|
|
|
- }else{
|
|
|
- bugReviewVO.put("taskName",task.getName());
|
|
|
- }
|
|
|
- }else {
|
|
|
- bugReviewVO.put("taskName",task.getName());
|
|
|
- }
|
|
|
- bugReviewVO.put("testReportId",report.getId());
|
|
|
- bugReviewVO.put("type",0);
|
|
|
- bugReviewVO.put("updateTime",System.currentTimeMillis());
|
|
|
- }
|
|
|
-
|
|
|
-// System.out.println(bugReviewVO);
|
|
|
- String url=blockChainHost+"reportReview";
|
|
|
- try {
|
|
|
- String result = HTTP.postBody(url, bugReviewVO.toString());
|
|
|
- if (!result.equals("")) {
|
|
|
- JSONObject resultJson = new JSONObject(result);
|
|
|
- System.out.println(resultJson);
|
|
|
- }
|
|
|
- }catch (Exception e){
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
-
|
|
|
+ String bugReviewerId="default";
|
|
|
}
|
|
|
|
|
|
- private Task getAndSaveTaskInfo(String id){
|
|
|
- String result = HTTP.sendGet(MOOCTEST_HOST+"/api/exam/" + id + "/info", "");
|
|
|
- if (!"".equals(result)) {
|
|
|
- JSONObject json = new JSONObject(result);
|
|
|
- long beginTime = json.getLong("beginTime");
|
|
|
- long endTime = json.getLong("endTime");
|
|
|
- String name=json.getString("name");
|
|
|
- double totalMins = (endTime - beginTime) / 1000 / 60.0;
|
|
|
- Task newTask = new Task(id, name,beginTime, endTime, totalMins, totalMins);
|
|
|
- taskDao.save(newTask);
|
|
|
- return newTask;
|
|
|
- }else{
|
|
|
- return null;
|
|
|
+ /**
|
|
|
+ * @description 上传bug后传递给区块链
|
|
|
+ */
|
|
|
+ @AfterReturning(value="bugSubmit()",returning = "keys")
|
|
|
+ public void doAfterReturningBugSubmit(JoinPoint joinPoint,Object keys){
|
|
|
+ Object[] obj = joinPoint.getArgs();
|
|
|
+ for (Object argItem : obj) {
|
|
|
+ System.out.println("---->now-->argItem:" + argItem);
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
+ //todo 将该信息传递给区块链服务 如何获得该bugID????
|
|
|
+ //任务ID、缺陷报告hash、缺陷报告 ID、众测工人ID
|
|
|
|
|
|
- //将一场众测的所有报告上传至区块链
|
|
|
- public void uploadTestReportInfo(String case_take_id){
|
|
|
- String defaultString="defaultString";
|
|
|
- List<Report> reportList=reportDao.findByCaseTakeId(case_take_id);
|
|
|
- if(reportList!=null){
|
|
|
- for(Report report:reportList){
|
|
|
- JSONObject testReportVO=new JSONObject();
|
|
|
- testReportVO.put("reportHash",defaultString);
|
|
|
- testReportVO.put("taskId",report.getCase_take_id());
|
|
|
- Task task=taskDao.findById(report.getTask_id());
|
|
|
- if(task==null){
|
|
|
- task=getAndSaveTaskInfo(report.getTask_id());
|
|
|
- if(task==null){
|
|
|
- testReportVO.put("taskName",defaultString);
|
|
|
- }else{
|
|
|
- testReportVO.put("taskName",task.getName());
|
|
|
- }
|
|
|
- }else {
|
|
|
- testReportVO.put("taskName",task.getName());
|
|
|
- }
|
|
|
- testReportVO.put("testReportId",report.getId());
|
|
|
- testReportVO.put("testReportName",report.getName());
|
|
|
- testReportVO.put("type",0);
|
|
|
- testReportVO.put("updateTime",System.currentTimeMillis());
|
|
|
- testReportVO.put("workerId",report.getWorker_id());
|
|
|
- String workerName=stuInfoDao.findWorkerName(report.getId());
|
|
|
- if(!"null".equals(workerName)){
|
|
|
- testReportVO.put("workerName",workerName);
|
|
|
- }else{
|
|
|
- testReportVO.put("workerName",defaultString);
|
|
|
- }
|
|
|
- List<Bug> bugList=bugDao.findByReport(report.getId(),case_take_id);
|
|
|
- JSONArray bugReportList=new JSONArray();
|
|
|
- for(Bug bug:bugList){
|
|
|
- JSONObject bugInfo=new JSONObject();
|
|
|
- bugInfo.put("bugId",bug.getId());
|
|
|
- bugInfo.put("bugName",bug.getTitle());
|
|
|
- bugReportList.put(bugInfo);
|
|
|
- }
|
|
|
- testReportVO.put("bugReportList",bugReportList);
|
|
|
-// System.out.println(testReportVO);
|
|
|
- String url=blockChainHost+"testReport";
|
|
|
- try {
|
|
|
- String result = HTTP.postBody(url, testReportVO.toString());
|
|
|
-// if (!result.equals("")) {
|
|
|
-// JSONObject resultJson = new JSONObject(result);
|
|
|
-// System.out.println(resultJson);
|
|
|
-// }
|
|
|
- }catch (Exception e){
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
+ String bugId= (String) obj[0];
|
|
|
+ String grade=(String) obj[1];
|
|
|
|
|
|
- public boolean uploadTestReportInfoToBlockChain(String bug_id){
|
|
|
- Bug bug=bugDao.findByid(bug_id);
|
|
|
- String report_id=bug.getReport_id();
|
|
|
- String defaultString="defaultString";
|
|
|
- Report report=reportDao.findById(report_id);
|
|
|
- if(report!=null) {
|
|
|
- JSONObject testReportVO = new JSONObject();
|
|
|
- testReportVO.put("reportHash", defaultString);
|
|
|
- testReportVO.put("taskId", report.getCase_take_id());
|
|
|
- Task task = taskDao.findById(report.getTask_id());
|
|
|
- if (task == null) {
|
|
|
- task = getAndSaveTaskInfo(report.getTask_id());
|
|
|
- if (task == null) {
|
|
|
- testReportVO.put("taskName", defaultString);
|
|
|
- } else {
|
|
|
- testReportVO.put("taskName", task.getName());
|
|
|
- }
|
|
|
- } else {
|
|
|
- testReportVO.put("taskName", task.getName());
|
|
|
- }
|
|
|
- testReportVO.put("testReportId", report.getId());
|
|
|
- testReportVO.put("testReportName", report.getName());
|
|
|
- testReportVO.put("type", 0);
|
|
|
- testReportVO.put("updateTime", System.currentTimeMillis());
|
|
|
- testReportVO.put("workerId", report.getWorker_id());
|
|
|
- String workerName = stuInfoDao.findWorkerName(report.getId());
|
|
|
- if (!"null".equals(workerName)) {
|
|
|
- testReportVO.put("workerName", workerName);
|
|
|
- } else {
|
|
|
- testReportVO.put("workerName", defaultString);
|
|
|
- }
|
|
|
- List<Bug> bugList = bugDao.findByReport(report.getId(), report.getCase_take_id());
|
|
|
- JSONArray bugReportList = new JSONArray();
|
|
|
- JSONObject bugInfo = new JSONObject();
|
|
|
- bugInfo.put("bugId", bug.getId());
|
|
|
- bugInfo.put("bugName", bug.getTitle());
|
|
|
- bugReportList.put(bugInfo);
|
|
|
- testReportVO.put("bugReportList", bugReportList);
|
|
|
- String url = blockChainHost + "testReport";
|
|
|
- try {
|
|
|
- String result = HTTP.postBody(url, testReportVO.toString());
|
|
|
- if (!result.equals("")) {
|
|
|
- JSONObject resultJson = new JSONObject(result);
|
|
|
-// System.out.println(resultJson);
|
|
|
-// System.out.println(resultJson.get("code").toString());
|
|
|
- if("200".equals(resultJson.get("code").toString())){
|
|
|
- return true;
|
|
|
- }else{
|
|
|
- return false;
|
|
|
- }
|
|
|
+ Bug bug=bugDao.findByid(bugId);
|
|
|
+ Report report=reportDao.findById(bug.getReport_id());
|
|
|
+ String crowdTestId=report.getCase_take_id();
|
|
|
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
- return false;
|
|
|
+ String bugReviewerId="default";
|
|
|
}
|
|
|
-
|
|
|
-// public static void main(String[] args){
|
|
|
-// String url=blockChainHost+"testReport";
|
|
|
-//// String json="{\"workerId\":\"22383\",\"reportHash\":\"defaultString\",\"taskName\":\"12-1众包测试\",\"updateTime\":1585284050330,\"type\":0,\"workerName\":\"李陈龙\",\"testReportName\":\"宋少行\",\"taskId\":\"1281-2724\",\"testReportId\":\"5cbc1a9f825a8960cdc7bd4f\",\"bugReportList\":[{\"bugId\":\"5cbc1b5c825a8960cdc7bd53\",\"bugName\":\"我再测试测试这个单独分离的\"},{\"bugId\":\"5cbc1b37825a8960cdc7bd52\",\"bugName\":\"帮助出错了\"},{\"bugId\":\"5cbc38f9825a8960cdc7bd57\",\"bugName\":\"测试图片能不能上传\"},{\"bugId\":\"5cbc1d31825a8960cdc7bd54\",\"bugName\":\"无法打开最近账薄\"},{\"bugId\":\"5cbc3919825a8960cdc7bd58\",\"bugName\":\"测试图片\"},{\"bugId\":\"5cbc3ab3825a8960cdc7bd5a\",\"bugName\":\"测试fork\"},{\"bugId\":\"5cbc3a50825a8960cdc7bd59\",\"bugName\":\"测试图片上传\"},{\"bugId\":\"5cbc3e9b825a8960cdc7bd5b\",\"bugName\":\"测试一键fork\"},{\"bugId\":\"5cde9be7825a8948e757cac1\",\"bugName\":\"测试下不选择页面会咋样\"},{\"bugId\":\"5cdfa0cc825a8948e757cade\",\"bugName\":\"打开一下就闪退了\"},{\"bugId\":\"5d402ef3f00e7a801b85e472\",\"bugName\":\"账薄有问题\"},{\"bugId\":\"5d7e1ac33c5a507c1c1cda33\",\"bugName\":\"账薄有问题\"},{\"bugId\":\"5d7e1b003c5a507c1c1cda37\",\"bugName\":\"账薄有问题\"},{\"bugId\":\"5d7e1c363c5a507c60f0766d\",\"bugName\":\"账薄有问题\"},{\"bugId\":\"5d7e1d3a3c5a507c9120b76a\",\"bugName\":\"test\"},{\"bugId\":\"5d7e1e1b3c5a507c9120b76f\",\"bugName\":\"继续测试\"},{\"bugId\":\"5d7f4254f52b558caaaee01a\",\"bugName\":\"11\"},{\"bugId\":\"5d7f42e1f52b558cecef1ffd\",\"bugName\":\"222\"},{\"bugId\":\"5dd761e307bcfb195d0dfe56\",\"bugName\":\"test\"},{\"bugId\":\"5df8a2a2eea9d780220b1b24\",\"bugName\":\"mm\"},{\"bugId\":\"5df8af01eea9d78664436920\",\"bugName\":\"kkkkk\"},{\"bugId\":\"5df9e097336bd0ad48b598b2\",\"bugName\":\"cninvorm o\"},{\"bugId\":\"5e463a89709308afcfb15a2c\",\"bugName\":\"。。。。\"}]}";
|
|
|
-//// String json="{\"workerId\":\"22383\",\"reportHash\":\"defaultString\",\"taskName\":\"12-1众包测试\",\"updateTime\":1585284050330,\"type\":0,\"workerName\":\"李陈龙\",\"testReportName\":\"宋少行\",\"taskId\":\"1281-2724\",\"testReportId\":\"5cbc1a9f825a8960cdc7bd4f\",\"bugReportList\":[{\"bugId\":\"5cbc1b5c825a8960cdc7bd53\",\"bugName\":\"我再测试测试这个单独分离的\"},{\"bugId\":\"5cbc1b37825a8960cdc7bd52\",\"bugName\":\"帮助出错了\"},{\"bugId\":\"5cbc38f9825a8960cdc7bd57\",\"bugName\":\"测试图片能不能上传\"},{\"bugId\":\"5cbc1d31825a8960cdc7bd54\",\"bugName\":\"无法打开最近账薄\"},{\"bugId\":\"5cbc3919825a8960cdc7bd58\",\"bugName\":\"测试图片\"},{\"bugId\":\"5cbc3ab3825a8960cdc7bd5a\",\"bugName\":\"测试fork\"},{\"bugId\":\"5cbc3a50825a8960cdc7bd59\",\"bugName\":\"测试图片上传\"},{\"bugId\":\"5cbc3e9b825a8960cdc7bd5b\",\"bugName\":\"测试一键fork\"},{\"bugId\":\"5cde9be7825a8948e757cac1\",\"bugName\":\"测试下不选择页面会咋样\"},{\"bugId\":\"5cdfa0cc825a8948e757cade\",\"bugName\":\"打开一下就闪退了\"},{\"bugId\":\"5d402ef3f00e7a801b85e472\",\"bugName\":\"账薄有问题\"},{\"bugId\":\"5d7e1ac33c5a507c1c1cda33\",\"bugName\":\"账薄有问题\"},{\"bugId\":\"5d7e1b003c5a507c1c1cda37\",\"bugName\":\"账薄有问题\"},{\"bugId\":\"5d7e1c363c5a507c60f0766d\",\"bugName\":\"账薄有问题\"},{\"bugId\":\"5d7e1d3a3c5a507c9120b76a\",\"bugName\":\"test\"},{\"bugId\":\"5d7e1e1b3c5a507c9120b76f\",\"bugName\":\"继续测试\"},{\"bugId\":\"5d7f4254f52b558caaaee01a\",\"bugName\":\"11\"},{\"bugId\":\"5d7f42e1f52b558cecef1ffd\",\"bugName\":\"222\"},{\"bugId\":\"5dd761e307bcfb195d0dfe56\",\"bugName\":\"test\"},{\"bugId\":\"5df8a2a2eea9d780220b1b24\",\"bugName\":\"mm\"},{\"bugId\":\"5df8af01eea9d78664436920\",\"bugName\":\"kkkkk\"},{\"bugId\":\"5df9e097336bd0ad48b598b2\",\"bugName\":\"cninvorm o\"},{\"bugId\":\"5e463a89709308afcfb15a2c\",\"bugName\":\"。。。。\"}]}";
|
|
|
-// String json="{\n" +
|
|
|
-// " \"bugReportList\": [\n" +
|
|
|
-// " {\n" +
|
|
|
-// " \"bugId\": \"string\",\n" +
|
|
|
-// " \"bugName\": \"string\"\n" +
|
|
|
-// " },\n" +
|
|
|
-// " {\n" +
|
|
|
-// " \"bugId\": \"string\",\n" +
|
|
|
-// " \"bugName\": \"string\"\n" +
|
|
|
-// " }\n" +
|
|
|
-// "\n" +
|
|
|
-// " ],\n" +
|
|
|
-// " \"reportHash\": \"string\",\n" +
|
|
|
-// " \"taskId\": \"string\",\n" +
|
|
|
-// " \"taskName\": \"string\",\n" +
|
|
|
-// " \"testReportId\": \"string\",\n" +
|
|
|
-// " \"testReportName\": \"string\",\n" +
|
|
|
-// " \"type\": 0,\n" +
|
|
|
-// " \"updateTime\": 0,\n" +
|
|
|
-// " \"workerId\": \"string\",\n" +
|
|
|
-// " \"workerName\": \"string\"\n" +
|
|
|
-// "}";
|
|
|
-// try {
|
|
|
-// String result = HTTP.postBody(url, json);
|
|
|
-// if(!result.equals("")){
|
|
|
-// JSONObject resultJson = new JSONObject(result);
|
|
|
-// System.out.println(resultJson);
|
|
|
-// }
|
|
|
-// }catch (Exception e){
|
|
|
-// e.printStackTrace();
|
|
|
-// }
|
|
|
//
|
|
|
+// /**
|
|
|
+// * @description 在连接点执行之后执行的通知(异常通知)
|
|
|
+// */
|
|
|
+// @AfterThrowing("BugSubmit()")
|
|
|
+// public void doAfterThrowingGame(){
|
|
|
+// System.out.println("异常通知:球迷要求退票!");
|
|
|
// }
|
|
|
|
|
|
-
|
|
|
-
|
|
|
+// /**
|
|
|
+// * @description 使用环绕通知
|
|
|
+// */
|
|
|
+// @Around("saveBugGrade()")
|
|
|
+// public void doAroundGameData(ProceedingJoinPoint pjp) throws Throwable {
|
|
|
+// try{
|
|
|
+// System.out.println("球星上场前热身!");
|
|
|
+// pjp.proceed();
|
|
|
+//
|
|
|
+// System.out.println("球星本场得到" + point + "分" );
|
|
|
+// }
|
|
|
+// catch(Throwable e){
|
|
|
+// System.out.println("异常通知:球迷要求退票!");
|
|
|
+// }
|
|
|
+// }
|
|
|
|
|
|
|
|
|
}
|