Commit 1e433096 authored by dailidong's avatar dailidong
Browse files

Merge remote-tracking branch 'upstream/dev-20190415' into dev-20190415

# Conflicts:
#	escheduler-api/src/main/java/cn/escheduler/api/enums/Status.java
parents a3d9d56f c578e2d2
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -33,3 +33,5 @@ yarn.lock
package-lock.json
config.gypi
test/coverage
/docs/zh_CN/介绍
/docs/zh_CN/贡献代码.md
+1 −1
Original line number Diff line number Diff line
@@ -4,7 +4,7 @@
    <parent>
        <groupId>cn.analysys</groupId>
        <artifactId>escheduler</artifactId>
        <version>1.0.0-SNAPSHOT</version>
        <version>1.0.1-SNAPSHOT</version>
    </parent>
    <artifactId>escheduler-alert</artifactId>
    <packaging>jar</packaging>
+1 −1
Original line number Diff line number Diff line
@@ -3,7 +3,7 @@
  <parent>
    <groupId>cn.analysys</groupId>
    <artifactId>escheduler</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <version>1.0.1-SNAPSHOT</version>
  </parent>
  <artifactId>escheduler-api</artifactId>
  <packaging>jar</packaging>
+169 −0
Original line number Diff line number Diff line
/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package cn.escheduler.api.controller;


import cn.escheduler.api.enums.Status;
import cn.escheduler.api.service.AccessTokenService;
import cn.escheduler.api.service.UsersService;
import cn.escheduler.api.utils.Constants;
import cn.escheduler.api.utils.Result;
import cn.escheduler.dao.model.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

import static cn.escheduler.api.enums.Status.*;


/**
 * user controller
 */
@RestController
@RequestMapping("/access-token")
public class AccessTokenController extends BaseController{


    private static final Logger logger = LoggerFactory.getLogger(AccessTokenController.class);


    @Autowired
    private AccessTokenService accessTokenService;

    /**
     * create token
     * @param loginUser
     * @return
     */
    @PostMapping(value = "/create")
    @ResponseStatus(HttpStatus.CREATED)
    public Result createToken(@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
                                                  @RequestParam(value = "userId") int userId,
                                                  @RequestParam(value = "expireTime") String expireTime,
                                                  @RequestParam(value = "token") String token){
        logger.info("login user {}, create token , userId : {} , token expire time : {} , token : {}", loginUser.getUserName(),
                userId,expireTime,token);

        try {
            Map<String, Object> result = accessTokenService.createToken(userId, expireTime, token);
            return returnDataList(result);
        }catch (Exception e){
            logger.error(CREATE_ACCESS_TOKEN_ERROR.getMsg(),e);
            return error(CREATE_ACCESS_TOKEN_ERROR.getCode(), CREATE_ACCESS_TOKEN_ERROR.getMsg());
        }
    }

    /**
     * create token
     * @param loginUser
     * @return
     */
    @PostMapping(value = "/generate")
    @ResponseStatus(HttpStatus.CREATED)
    public Result generateToken(@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
                              @RequestParam(value = "userId") int userId,
                              @RequestParam(value = "expireTime") String expireTime){
        logger.info("login user {}, generate token , userId : {} , token expire time : {}",loginUser,userId,expireTime);
        try {
            Map<String, Object> result = accessTokenService.generateToken(userId, expireTime);
            return returnDataList(result);
        }catch (Exception e){
            logger.error(GENERATE_TOKEN_ERROR.getMsg(),e);
            return error(GENERATE_TOKEN_ERROR.getCode(), GENERATE_TOKEN_ERROR.getMsg());
        }
    }

    /**
     * query access token list paging
     *
     * @param loginUser
     * @param pageNo
     * @param searchVal
     * @param pageSize
     * @return
     */
    @GetMapping(value="/list-paging")
    @ResponseStatus(HttpStatus.OK)
    public Result queryAccessTokenList(@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
                                @RequestParam("pageNo") Integer pageNo,
                                @RequestParam(value = "searchVal", required = false) String searchVal,
                                @RequestParam("pageSize") Integer pageSize){
        logger.info("login user {}, list access token paging, pageNo: {}, searchVal: {}, pageSize: {}",
                loginUser.getUserName(),pageNo,searchVal,pageSize);
        try{
            Map<String, Object> result = checkPageParams(pageNo, pageSize);
            if(result.get(Constants.STATUS) != Status.SUCCESS){
                return returnDataListPaging(result);
            }
            result = accessTokenService.queryAccessTokenList(loginUser, searchVal, pageNo, pageSize);
            return returnDataListPaging(result);
        }catch (Exception e){
            logger.error(QUERY_ACCESSTOKEN_LIST_PAGING_ERROR.getMsg(),e);
            return error(QUERY_ACCESSTOKEN_LIST_PAGING_ERROR.getCode(),QUERY_ACCESSTOKEN_LIST_PAGING_ERROR.getMsg());
        }
    }

    /**
     * delete access token by id
     * @param loginUser
     * @param id
     * @return
     */
    @PostMapping(value = "/delete")
    @ResponseStatus(HttpStatus.OK)
    public Result delAccessTokenById(@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
                              @RequestParam(value = "id") int  id) {
        logger.info("login user {}, delete access token, id: {},", loginUser.getUserName(), id);
        try {
            Map<String, Object> result = accessTokenService.delAccessTokenById(loginUser, id);
            return returnDataList(result);
        }catch (Exception e){
            logger.error(DELETE_USER_BY_ID_ERROR.getMsg(),e);
            return error(Status.DELETE_USER_BY_ID_ERROR.getCode(), Status.DELETE_USER_BY_ID_ERROR.getMsg());
        }
    }


    /**
     * update token
     * @param loginUser
     * @return
     */
    @PostMapping(value = "/update")
    @ResponseStatus(HttpStatus.CREATED)
    public Result updateToken(@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
                              @RequestParam(value = "id") int id,
                              @RequestParam(value = "userId") int userId,
                              @RequestParam(value = "expireTime") String expireTime,
                              @RequestParam(value = "token") String token){
        logger.info("login user {}, update token , userId : {} , token expire time : {} , token : {}", loginUser.getUserName(),
                userId,expireTime,token);

        try {
            Map<String, Object> result = accessTokenService.updateToken(id,userId, expireTime, token);
            return returnDataList(result);
        }catch (Exception e){
            logger.error(CREATE_ACCESS_TOKEN_ERROR.getMsg(),e);
            return error(CREATE_ACCESS_TOKEN_ERROR.getCode(), CREATE_ACCESS_TOKEN_ERROR.getMsg());
        }
    }

}
+51 −7
Original line number Diff line number Diff line
@@ -57,8 +57,7 @@ public class DataAnalysisController extends BaseController{
    public Result countTaskState(@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
                                                         @RequestParam(value="startDate", required=false) String startDate,
                                                         @RequestParam(value="endDate", required=false) String endDate,
                                                         @RequestParam(value="projectId", required=false, defaultValue = "0") int projectId
    ){
                                                         @RequestParam(value="projectId", required=false, defaultValue = "0") int projectId){
        try{
            logger.info("count task state, user:{}, start date: {}, end date:{}, project id {}",
                    loginUser.getUserName(), startDate, endDate, projectId);
@@ -82,8 +81,7 @@ public class DataAnalysisController extends BaseController{
    public Result countProcessInstanceState(@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
                                            @RequestParam(value="startDate", required=false) String startDate,
                                            @RequestParam(value="endDate", required=false) String endDate,
                                            @RequestParam(value="projectId", required=false, defaultValue = "0") int projectId
    ){
                                            @RequestParam(value="projectId", required=false, defaultValue = "0") int projectId){
        try{
            logger.info("count process instance state, user:{}, start date: {}, end date:{}, project id",
                    loginUser.getUserName(), startDate, endDate, projectId);
@@ -105,8 +103,7 @@ public class DataAnalysisController extends BaseController{
    @GetMapping(value="/define-user-count")
    @ResponseStatus(HttpStatus.OK)
    public Result countDefinitionByUser(@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
                                        @RequestParam(value="projectId", required=false, defaultValue = "0") int projectId
    ){
                                        @RequestParam(value="projectId", required=false, defaultValue = "0") int projectId){
        try{
            logger.info("count process definition , user:{}, project id",
                    loginUser.getUserName(), projectId);
@@ -119,4 +116,51 @@ public class DataAnalysisController extends BaseController{
    }


    /**
     * statistical command status data
     *
     * @param loginUser
     * @param projectId
     * @return
     */
    @GetMapping(value="/command-state-count")
    @ResponseStatus(HttpStatus.OK)
    public Result countCommandState(@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
                                 @RequestParam(value="startDate", required=false) String startDate,
                                 @RequestParam(value="endDate", required=false) String endDate,
                                 @RequestParam(value="projectId", required=false, defaultValue = "0") int projectId){
        try{
            logger.info("count command state, user:{}, start date: {}, end date:{}, project id {}",
                    loginUser.getUserName(), startDate, endDate, projectId);
            Map<String, Object> result = dataAnalysisService.countCommandState(loginUser, projectId, startDate, endDate);
            return returnDataList(result);
        }catch (Exception e){
            logger.error(COMMAND_STATE_COUNT_ERROR.getMsg(),e);
            return error(COMMAND_STATE_COUNT_ERROR.getCode(), COMMAND_STATE_COUNT_ERROR.getMsg());
        }
    }

    /**
     * queue count
     *
     * @param loginUser
     * @param projectId
     * @return
     */
    @GetMapping(value="/queue-count")
    @ResponseStatus(HttpStatus.OK)
    public Result countQueueState(@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
                                    @RequestParam(value="projectId", required=false, defaultValue = "0") int projectId){
        try{
            logger.info("count command state, user:{}, start date: {}, end date:{}, project id {}",
                    loginUser.getUserName(), projectId);
            Map<String, Object> result = dataAnalysisService.countQueueState(loginUser, projectId);
            return returnDataList(result);
        }catch (Exception e){
            logger.error(QUEUE_COUNT_ERROR.getMsg(),e);
            return error(QUEUE_COUNT_ERROR.getCode(), QUEUE_COUNT_ERROR.getMsg());
        }
    }


}
Loading