public void before()

in bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/aop/AuditAspect.java [50:92]


    public void before(JoinPoint joinPoint) {
        MethodSignature ms = (MethodSignature) joinPoint.getSignature();
        Long userId = SessionUserHolder.getUserId();
        ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        if (attributes != null && userId != null) {
            // obtain request uri
            HttpServletRequest request = attributes.getRequest();
            String uri = request.getRequestURI();
            // obtain controller name
            Class<?> controller = joinPoint.getThis().getClass();
            Tag annotation = controller.getAnnotation(Tag.class);
            String apiName = "";
            String apiDesc = "";
            if (annotation != null) {
                apiName = annotation.name();
                apiDesc = annotation.description();
            }
            // obtain method name
            String methodName = ms.getName();
            // obtain method desc
            String operationSummary = "";
            String operationDesc = "";
            Operation operation = ms.getMethod().getDeclaredAnnotation(Operation.class);
            if (operation != null) {
                operationSummary = operation.summary();
                operationDesc = operation.description();
            }

            AuditLogPO auditLogPO = new AuditLogPO();
            auditLogPO.setUserId(userId);
            auditLogPO.setUri(uri);
            auditLogPO.setTagName(apiName);
            auditLogPO.setTagDesc(apiDesc);
            auditLogPO.setOperationSummary(operationSummary);
            auditLogPO.setOperationDesc(operationDesc);
            auditLogPO.setArgs(JsonUtils.writeAsString(joinPoint.getArgs()));

            log.debug("auditLog: {}", auditLogPO);
            log.debug("request method:{}.{}", joinPoint.getSignature().getDeclaringTypeName(), methodName);

            auditLogDao.save(auditLogPO);
        }
    }