Search in sources :

Example 1 with StatusNotFoundException

use of top.hcode.hoj.common.exception.StatusNotFoundException in project HOJ by HimitZH.

the class GroupContestManager method getContest.

public AdminContestVo getContest(Long cid) throws StatusForbiddenException, StatusNotFoundException, StatusFailException {
    Session session = SecurityUtils.getSubject().getSession();
    UserRolesVo userRolesVo = (UserRolesVo) session.getAttribute("userInfo");
    boolean isRoot = SecurityUtils.getSubject().hasRole("root");
    Contest contest = contestEntityService.getById(cid);
    if (contest == null) {
        throw new StatusNotFoundException("该比赛不存在!");
    }
    Long gid = contest.getGid();
    Group group = groupEntityService.getById(gid);
    if (group == null || group.getStatus() == 1 && !isRoot) {
        throw new StatusNotFoundException("该团队不存在或已被封禁!");
    }
    if (!userRolesVo.getUid().equals(contest.getUid()) && !isRoot && !groupValidator.isGroupRoot(userRolesVo.getUid(), gid)) {
        throw new StatusForbiddenException("对不起,您无权限操作!");
    }
    AdminContestVo adminContestVo = BeanUtil.copyProperties(contest, AdminContestVo.class, "starAccount");
    if (StringUtils.isEmpty(contest.getStarAccount())) {
        adminContestVo.setStarAccount(new ArrayList<>());
    } else {
        JSONObject jsonObject = JSONUtil.parseObj(contest.getStarAccount());
        List<String> starAccount = jsonObject.get("star_account", List.class);
        adminContestVo.setStarAccount(starAccount);
    }
    return adminContestVo;
}
Also used : Group(top.hcode.hoj.pojo.entity.group.Group) StatusForbiddenException(top.hcode.hoj.common.exception.StatusForbiddenException) StatusNotFoundException(top.hcode.hoj.common.exception.StatusNotFoundException) AdminContestVo(top.hcode.hoj.pojo.vo.AdminContestVo) JSONObject(cn.hutool.json.JSONObject) UserRolesVo(top.hcode.hoj.pojo.vo.UserRolesVo) Contest(top.hcode.hoj.pojo.entity.contest.Contest) Session(org.apache.shiro.session.Session)

Example 2 with StatusNotFoundException

use of top.hcode.hoj.common.exception.StatusNotFoundException in project HOJ by HimitZH.

the class GroupContestManager method deleteContest.

public void deleteContest(Long cid) throws StatusForbiddenException, StatusNotFoundException, StatusFailException {
    Session session = SecurityUtils.getSubject().getSession();
    UserRolesVo userRolesVo = (UserRolesVo) session.getAttribute("userInfo");
    boolean isRoot = SecurityUtils.getSubject().hasRole("root");
    Contest contest = contestEntityService.getById(cid);
    if (contest == null) {
        throw new StatusNotFoundException("该比赛不存在!");
    }
    Long gid = contest.getGid();
    Group group = groupEntityService.getById(gid);
    if (group == null || group.getStatus() == 1 && !isRoot) {
        throw new StatusNotFoundException("该团队不存在或已被封禁!");
    }
    if (!userRolesVo.getUid().equals(contest.getUid()) && !isRoot && !groupValidator.isGroupRoot(userRolesVo.getUid(), gid)) {
        throw new StatusForbiddenException("对不起,您无权限操作!");
    }
    boolean isOk = contestEntityService.removeById(cid);
    if (!isOk) {
        throw new StatusFailException("删除失败");
    }
}
Also used : Group(top.hcode.hoj.pojo.entity.group.Group) StatusForbiddenException(top.hcode.hoj.common.exception.StatusForbiddenException) UserRolesVo(top.hcode.hoj.pojo.vo.UserRolesVo) StatusNotFoundException(top.hcode.hoj.common.exception.StatusNotFoundException) StatusFailException(top.hcode.hoj.common.exception.StatusFailException) Contest(top.hcode.hoj.pojo.entity.contest.Contest) Session(org.apache.shiro.session.Session)

Example 3 with StatusNotFoundException

use of top.hcode.hoj.common.exception.StatusNotFoundException in project HOJ by HimitZH.

the class GroupContestManager method getAdminContestList.

public IPage<Contest> getAdminContestList(Integer limit, Integer currentPage, Long gid) throws StatusNotFoundException, StatusForbiddenException {
    Session session = SecurityUtils.getSubject().getSession();
    UserRolesVo userRolesVo = (UserRolesVo) session.getAttribute("userInfo");
    boolean isRoot = SecurityUtils.getSubject().hasRole("root");
    Group group = groupEntityService.getById(gid);
    if (group == null || group.getStatus() == 1 && !isRoot) {
        throw new StatusNotFoundException("该团队不存在或已被封禁!");
    }
    if (!isRoot && !groupValidator.isGroupAdmin(userRolesVo.getUid(), gid)) {
        throw new StatusForbiddenException("对不起,您无权限操作!");
    }
    if (currentPage == null || currentPage < 1)
        currentPage = 1;
    if (limit == null || limit < 1)
        limit = 10;
    return groupContestEntityService.getAdminContestList(limit, currentPage, gid);
}
Also used : Group(top.hcode.hoj.pojo.entity.group.Group) StatusForbiddenException(top.hcode.hoj.common.exception.StatusForbiddenException) UserRolesVo(top.hcode.hoj.pojo.vo.UserRolesVo) StatusNotFoundException(top.hcode.hoj.common.exception.StatusNotFoundException) Session(org.apache.shiro.session.Session)

Example 4 with StatusNotFoundException

use of top.hcode.hoj.common.exception.StatusNotFoundException in project HOJ by HimitZH.

the class GroupContestProblemManager method addProblemFromGroup.

@Transactional(rollbackFor = Exception.class)
public void addProblemFromGroup(String problemId, Long cid, String displayId) throws StatusNotFoundException, StatusForbiddenException, StatusFailException {
    Session session = SecurityUtils.getSubject().getSession();
    UserRolesVo userRolesVo = (UserRolesVo) session.getAttribute("userInfo");
    boolean isRoot = SecurityUtils.getSubject().hasRole("root");
    Contest contest = contestEntityService.getById(cid);
    if (contest == null) {
        throw new StatusNotFoundException("该训练不存在!");
    }
    Long gid = contest.getGid();
    Group group = groupEntityService.getById(gid);
    if (group == null || group.getStatus() == 1 && !isRoot) {
        throw new StatusNotFoundException("该团队不存在或已被封禁!");
    }
    if (!userRolesVo.getUid().equals(contest.getUid()) && !isRoot && !groupValidator.isGroupRoot(userRolesVo.getUid(), gid)) {
        throw new StatusForbiddenException("对不起,您无权限操作!");
    }
    QueryWrapper<Problem> problemQueryWrapper = new QueryWrapper<>();
    problemQueryWrapper.eq("problem_id", problemId).eq("gid", gid);
    Problem problem = problemEntityService.getOne(problemQueryWrapper);
    if (problem == null) {
        throw new StatusNotFoundException("该题目不存在或不是团队题目!");
    }
    QueryWrapper<ContestProblem> contestProblemQueryWrapper = new QueryWrapper<>();
    contestProblemQueryWrapper.eq("cid", cid).and(wrapper -> wrapper.eq("pid", problem.getId()).or().eq("display_id", displayId));
    ContestProblem contestProblem = contestProblemEntityService.getOne(contestProblemQueryWrapper);
    if (contestProblem != null) {
        throw new StatusFailException("添加失败,该题目已添加或者题目的比赛展示ID已存在!");
    }
    ContestProblem newCProblem = new ContestProblem();
    String displayName = problem.getTitle();
    boolean updateProblem = problemEntityService.saveOrUpdate(problem.setAuth(3));
    boolean isOk = contestProblemEntityService.saveOrUpdate(newCProblem.setCid(cid).setPid(problem.getId()).setDisplayTitle(displayName).setDisplayId(displayId));
    if (!isOk || !updateProblem) {
        throw new StatusFailException("添加失败");
    }
}
Also used : Group(top.hcode.hoj.pojo.entity.group.Group) StatusForbiddenException(top.hcode.hoj.common.exception.StatusForbiddenException) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) StatusNotFoundException(top.hcode.hoj.common.exception.StatusNotFoundException) UserRolesVo(top.hcode.hoj.pojo.vo.UserRolesVo) Problem(top.hcode.hoj.pojo.entity.problem.Problem) ContestProblem(top.hcode.hoj.pojo.entity.contest.ContestProblem) StatusFailException(top.hcode.hoj.common.exception.StatusFailException) Contest(top.hcode.hoj.pojo.entity.contest.Contest) ContestProblem(top.hcode.hoj.pojo.entity.contest.ContestProblem) Session(org.apache.shiro.session.Session) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with StatusNotFoundException

use of top.hcode.hoj.common.exception.StatusNotFoundException in project HOJ by HimitZH.

the class GroupContestProblemManager method updateContestProblem.

public void updateContestProblem(ContestProblem contestProblem) throws StatusNotFoundException, StatusForbiddenException, StatusFailException {
    Session session = SecurityUtils.getSubject().getSession();
    UserRolesVo userRolesVo = (UserRolesVo) session.getAttribute("userInfo");
    boolean isRoot = SecurityUtils.getSubject().hasRole("root");
    Long cid = contestProblem.getCid();
    Contest contest = contestEntityService.getById(cid);
    if (contest == null) {
        throw new StatusNotFoundException("该比赛不存在!");
    }
    Long gid = contest.getGid();
    Group group = groupEntityService.getById(gid);
    if (group == null || group.getStatus() == 1 && !isRoot) {
        throw new StatusNotFoundException("该团队不存在或已被封禁!");
    }
    if (!userRolesVo.getUid().equals(contest.getUid()) && !isRoot && !groupValidator.isGroupRoot(userRolesVo.getUid(), gid)) {
        throw new StatusForbiddenException("对不起,您无权限操作!");
    }
    boolean isOk = contestProblemEntityService.saveOrUpdate(contestProblem);
    if (isOk) {
        contestProblemEntityService.syncContestRecord(contestProblem.getPid(), contestProblem.getCid(), contestProblem.getDisplayId());
    } else {
        throw new StatusFailException("更新失败!");
    }
}
Also used : Group(top.hcode.hoj.pojo.entity.group.Group) StatusForbiddenException(top.hcode.hoj.common.exception.StatusForbiddenException) UserRolesVo(top.hcode.hoj.pojo.vo.UserRolesVo) StatusNotFoundException(top.hcode.hoj.common.exception.StatusNotFoundException) StatusFailException(top.hcode.hoj.common.exception.StatusFailException) Contest(top.hcode.hoj.pojo.entity.contest.Contest) Session(org.apache.shiro.session.Session)

Aggregations

StatusNotFoundException (top.hcode.hoj.common.exception.StatusNotFoundException)68 StatusForbiddenException (top.hcode.hoj.common.exception.StatusForbiddenException)67 Session (org.apache.shiro.session.Session)66 UserRolesVo (top.hcode.hoj.pojo.vo.UserRolesVo)63 Group (top.hcode.hoj.pojo.entity.group.Group)61 StatusFailException (top.hcode.hoj.common.exception.StatusFailException)40 QueryWrapper (com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)29 Contest (top.hcode.hoj.pojo.entity.contest.Contest)17 Problem (top.hcode.hoj.pojo.entity.problem.Problem)15 UpdateWrapper (com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper)11 Transactional (org.springframework.transaction.annotation.Transactional)7 ContestProblem (top.hcode.hoj.pojo.entity.contest.ContestProblem)7 GroupMember (top.hcode.hoj.pojo.entity.group.GroupMember)5 Discussion (top.hcode.hoj.pojo.entity.discussion.Discussion)4 Tag (top.hcode.hoj.pojo.entity.problem.Tag)4 JSONObject (cn.hutool.json.JSONObject)3 Date (java.util.Date)3 Judge (top.hcode.hoj.pojo.entity.judge.Judge)3 IPage (com.baomidou.mybatisplus.core.metadata.IPage)2 Page (com.baomidou.mybatisplus.extension.plugins.pagination.Page)2