|
@@ -0,0 +1,138 @@
|
|
|
+package edu.nju.util;
|
|
|
+
|
|
|
+import edu.nju.dao.BugDao;
|
|
|
+import edu.nju.dao.ReportDao;
|
|
|
+import edu.nju.entities.Bug;
|
|
|
+import edu.nju.entities.Report;
|
|
|
+import org.aspectj.lang.JoinPoint;
|
|
|
+import org.aspectj.lang.ProceedingJoinPoint;
|
|
|
+import org.aspectj.lang.annotation.*;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ * @Author JiaWei Xu
|
|
|
+ * @Date 2020-01-03 16:43
|
|
|
+ * @Email xjwhhh233@outlook.com
|
|
|
+ */
|
|
|
+
|
|
|
+@Aspect
|
|
|
+@Component
|
|
|
+public class BlockChainAspect {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ BugDao bugDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ ReportDao reportDao;
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 定义切入点,切入点为com.example.demo.aop.AopController中的所有函数
|
|
|
+ *通过@Pointcut注解声明频繁使用的切点表达式
|
|
|
+ */
|
|
|
+ @Pointcut("execution(public * edu.nju.controller.UploadController.submit(..))")
|
|
|
+ public void bugSubmit(){
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Pointcut("execution(public * edu.nju.controller.AnalyzeController.saveGrade(..))")
|
|
|
+ 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){
|
|
|
+ Object[] obj = joinPoint.getArgs();
|
|
|
+ for (Object argItem : obj) {
|
|
|
+ System.out.println("---->now-->argItem:" + argItem);
|
|
|
+ }
|
|
|
+ //todo 将该信息传递给区块链服务
|
|
|
+ //任务ID、缺陷报告ID、分数、报告评审人ID
|
|
|
+
|
|
|
+ String bugId= (String) obj[0];
|
|
|
+ String grade=(String) obj[1];
|
|
|
+
|
|
|
+ Bug bug=bugDao.findByid(bugId);
|
|
|
+ Report report=reportDao.findById(bug.getReport_id());
|
|
|
+ String crowdTestId=report.getCase_take_id();
|
|
|
+
|
|
|
+ String bugReviewerId="default";
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @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
|
|
|
+
|
|
|
+
|
|
|
+ String bugId= (String) obj[0];
|
|
|
+ String grade=(String) obj[1];
|
|
|
+
|
|
|
+ Bug bug=bugDao.findByid(bugId);
|
|
|
+ Report report=reportDao.findById(bug.getReport_id());
|
|
|
+ String crowdTestId=report.getCase_take_id();
|
|
|
+
|
|
|
+ String bugReviewerId="default";
|
|
|
+ }
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * @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("异常通知:球迷要求退票!");
|
|
|
+// }
|
|
|
+// }
|
|
|
+
|
|
|
+
|
|
|
+}
|