Commit cd4c9f93 authored by baoliang's avatar baoliang
Browse files

Merge remote-tracking branch 'upstream/branch-1.0.2' into 102

parents 9d53ad98 2347773a
Loading
Loading
Loading
Loading
+25 −0
Original line number Diff line number Diff line
@@ -325,4 +325,29 @@ public class ProcessDefinitionController extends BaseController{
        }
    }

    /**
     * delete process definition by id
     *
     * @param loginUser
     * @param projectName
     * @param processDefinitionId
     * @return
     */
    @GetMapping(value="/delete")
    @ResponseStatus(HttpStatus.OK)
    public Result deleteProcessDefinitionById(@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
                                            @PathVariable String projectName,
                                            @RequestParam("processDefinitionId") Integer processDefinitionId
    ){
        try{
            logger.info("delete process definition by id, login user:{}, project name:{}, process definition id:{}",
                    loginUser.getUserName(), projectName, processDefinitionId);
            Map<String, Object> result = processDefinitionService.deleteProcessDefinitionById(loginUser, projectName, processDefinitionId);
            return returnDataList(result);
        }catch (Exception e){
            logger.error(DELETE_PROCESS_DEFINE_BY_ID_ERROR.getMsg(),e);
            return error(Status.DELETE_PROCESS_DEFINE_BY_ID_ERROR.getCode(), Status.DELETE_PROCESS_DEFINE_BY_ID_ERROR.getMsg());
        }
    }

}
+22 −1
Original line number Diff line number Diff line
@@ -285,6 +285,26 @@ public class UsersController extends BaseController{
    @GetMapping(value="/list")
    @ResponseStatus(HttpStatus.OK)
    public Result listUser(@RequestAttribute(value = Constants.SESSION_USER) User loginUser){
        logger.info("login user {}, user list");
        try{
            Map<String, Object> result = usersService.queryAllGeneralUsers(loginUser);
            return returnDataList(result);
        }catch (Exception e){
            logger.error(USER_LIST_ERROR.getMsg(),e);
            return error(Status.USER_LIST_ERROR.getCode(), Status.USER_LIST_ERROR.getMsg());
        }
    }


    /**
     * user list no paging
     *
     * @param loginUser
     * @return
     */
    @GetMapping(value="/list-all")
    @ResponseStatus(HttpStatus.OK)
    public Result listAll(@RequestAttribute(value = Constants.SESSION_USER) User loginUser){
        logger.info("login user {}, user list");
        try{
            Map<String, Object> result = usersService.queryUserList(loginUser);
@@ -295,6 +315,7 @@ public class UsersController extends BaseController{
        }
    }


    /**
     * verify username
     *
+3 −0
Original line number Diff line number Diff line
@@ -201,6 +201,9 @@ public enum Status {
    DATA_IS_NULL(50018,"data %s is null"),
    PROCESS_NODE_HAS_CYCLE(50019,"process node has cycle"),
    PROCESS_NODE_S_PARAMETER_INVALID(50020,"process node %s parameter invalid"),
    PROCESS_DEFINE_STATE_ONLINE(50021, "process definition {0} is already on line"),
    DELETE_PROCESS_DEFINE_BY_ID_ERROR(50022,"delete process definition by id error"),
    SCHEDULE_CRON_STATE_ONLINE(50023,"the status of schedule {0} is already on line"),

    HDFS_NOT_STARTUP(60001,"hdfs not startup"),

+59 −0
Original line number Diff line number Diff line
@@ -336,6 +336,65 @@ public class ProcessDefinitionService extends BaseDAGService {
        return result;
    }

    /**
     * delete process definition by id
     *
     * @param loginUser
     * @param projectName
     * @param processDefinitionId
     * @return
     */
    @Transactional(value = "TransactionManager", rollbackFor = Exception.class)
    public Map<String, Object> deleteProcessDefinitionById(User loginUser, String projectName, Integer processDefinitionId) {

        Map<String, Object> result = new HashMap<>(5);
        Project project = projectMapper.queryByName(projectName);

        Map<String, Object> checkResult = projectService.checkProjectAndAuth(loginUser, project, projectName);
        Status resultEnum = (Status) checkResult.get(Constants.STATUS);
        if (resultEnum != Status.SUCCESS) {
            return checkResult;
        }


        ProcessDefinition processDefinition = processDefineMapper.queryByDefineId(processDefinitionId);

        if (processDefinition == null) {
            putMsg(result, Status.PROCESS_DEFINE_NOT_EXIST, processDefinitionId);
            return result;
        }
        // check process definition is already online
        if (processDefinition.getReleaseState() == ReleaseState.ONLINE) {
            putMsg(result, Status.PROCESS_DEFINE_STATE_ONLINE,processDefinitionId);
            return result;
        }

        // get the timing according to the process definition
        List<Schedule> schedules = scheduleMapper.selectAllByProcessDefineArray(new int[processDefinitionId]);
        if (!schedules.isEmpty() && schedules.size() > 1) {
            logger.warn("scheduler num is {},Greater than 1",schedules.size());
            putMsg(result, Status.DELETE_PROCESS_DEFINE_BY_ID_ERROR);
            return result;
        }else if(schedules.size() == 1){
            Schedule schedule = schedules.get(0);
            if(schedule.getReleaseState() == ReleaseState.OFFLINE){
                scheduleMapper.delete(schedule.getId());
            }else if(schedule.getReleaseState() == ReleaseState.ONLINE){
                putMsg(result, Status.SCHEDULE_CRON_STATE_ONLINE,schedule.getId());
                return result;
            }
        }

        int delete = processDefineMapper.delete(processDefinitionId);

        if (delete > 0) {
            putMsg(result, Status.SUCCESS);
        } else {
            putMsg(result, Status.DELETE_PROCESS_DEFINE_BY_ID_ERROR);
        }
        return result;
    }

    /**
     * release process definition: online / offline
     *
+21 −0
Original line number Diff line number Diff line
@@ -518,6 +518,27 @@ public class UsersService extends BaseService {
        return result;
    }

    /**
     * query user list
     *
     * @param loginUser
     * @return
     */
    public Map<String, Object> queryAllGeneralUsers(User loginUser) {
        Map<String, Object> result = new HashMap<>(5);
        //only admin can operate
        if (check(result, !isAdmin(loginUser), Status.USER_NO_OPERATION_PERM, Constants.STATUS)) {
            return result;
        }

        List<User> userList = userMapper.queryAllGeneralUsers();
        result.put(Constants.DATA_LIST, userList);
        putMsg(result, Status.SUCCESS);

        return result;
    }


    /**
     * query user list
     *
Loading