Search in sources :

Example 21 with Problem

use of top.hcode.hoj.pojo.entity.problem.Problem in project HOJ by HimitZH.

the class GroupContestProblemManager method addProblemFromPublic.

public void addProblemFromPublic(ContestProblemDto contestProblemDto) throws StatusNotFoundException, StatusForbiddenException, StatusFailException {
    Session session = SecurityUtils.getSubject().getSession();
    UserRolesVo userRolesVo = (UserRolesVo) session.getAttribute("userInfo");
    boolean isRoot = SecurityUtils.getSubject().hasRole("root");
    Long pid = contestProblemDto.getPid();
    Problem problem = problemEntityService.getById(pid);
    if (problem == null || problem.getAuth() != 1 || problem.getIsGroup()) {
        throw new StatusNotFoundException("该题目不存在或已被隐藏!");
    }
    Long cid = contestProblemDto.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("对不起,您无权限操作!");
    }
    String displayId = contestProblemDto.getDisplayId();
    QueryWrapper<ContestProblem> contestProblemQueryWrapper = new QueryWrapper<>();
    contestProblemQueryWrapper.eq("cid", cid).and(wrapper -> wrapper.eq("pid", pid).or().eq("display_id", displayId));
    ContestProblem contestProblem = contestProblemEntityService.getOne(contestProblemQueryWrapper, false);
    if (contestProblem != null) {
        throw new StatusFailException("添加失败,该题目已添加或者题目的比赛展示ID已存在!");
    }
    String displayName = problem.getTitle();
    ContestProblem newCProblem = new ContestProblem();
    boolean isOk = contestProblemEntityService.saveOrUpdate(newCProblem.setCid(cid).setPid(pid).setDisplayTitle(displayName).setDisplayId(displayId));
    if (!isOk) {
        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)

Example 22 with Problem

use of top.hcode.hoj.pojo.entity.problem.Problem in project HOJ by HimitZH.

the class GroupProblemManager method changeProblemAuth.

public void changeProblemAuth(Long pid, Integer auth) throws StatusForbiddenException, StatusNotFoundException, StatusFailException {
    Session session = SecurityUtils.getSubject().getSession();
    UserRolesVo userRolesVo = (UserRolesVo) session.getAttribute("userInfo");
    boolean isRoot = SecurityUtils.getSubject().hasRole("root");
    Problem problem = problemEntityService.getById(pid);
    if (problem == null) {
        throw new StatusNotFoundException("该题目不存在!");
    }
    Long gid = problem.getGid();
    Group group = groupEntityService.getById(gid);
    if (group == null || group.getStatus() == 1 && !isRoot) {
        throw new StatusNotFoundException("该团队不存在或已被封禁!");
    }
    if (!userRolesVo.getUsername().equals(problem.getAuthor()) && !isRoot && !groupValidator.isGroupRoot(userRolesVo.getUid(), gid)) {
        throw new StatusForbiddenException("对不起,您无权限操作!");
    }
    UpdateWrapper<Problem> problemUpdateWrapper = new UpdateWrapper<>();
    problemUpdateWrapper.eq("id", pid).set("auth", auth).set("modified_user", userRolesVo.getUsername());
    boolean isOk = problemEntityService.update(problemUpdateWrapper);
    if (!isOk) {
        throw new StatusFailException("修改失败");
    }
}
Also used : Group(top.hcode.hoj.pojo.entity.group.Group) StatusForbiddenException(top.hcode.hoj.common.exception.StatusForbiddenException) UpdateWrapper(com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper) UserRolesVo(top.hcode.hoj.pojo.vo.UserRolesVo) StatusNotFoundException(top.hcode.hoj.common.exception.StatusNotFoundException) Problem(top.hcode.hoj.pojo.entity.problem.Problem) StatusFailException(top.hcode.hoj.common.exception.StatusFailException) Session(org.apache.shiro.session.Session)

Example 23 with Problem

use of top.hcode.hoj.pojo.entity.problem.Problem in project HOJ by HimitZH.

the class GroupProblemManager method getProblem.

public Problem getProblem(Long pid) throws StatusForbiddenException, StatusNotFoundException, StatusFailException {
    Session session = SecurityUtils.getSubject().getSession();
    UserRolesVo userRolesVo = (UserRolesVo) session.getAttribute("userInfo");
    boolean isRoot = SecurityUtils.getSubject().hasRole("root");
    Problem problem = problemEntityService.getById(pid);
    if (problem == null) {
        throw new StatusNotFoundException("该题目不存在!");
    }
    Long gid = problem.getGid();
    Group group = groupEntityService.getById(gid);
    if (group == null || group.getStatus() == 1 && !isRoot) {
        throw new StatusNotFoundException("该团队不存在或已被封禁!");
    }
    if (!groupValidator.isGroupRoot(userRolesVo.getUid(), gid) && !userRolesVo.getUsername().equals(problem.getAuthor()) && !isRoot) {
        throw new StatusForbiddenException("对不起,您无权限操作!");
    }
    return problem;
}
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) Problem(top.hcode.hoj.pojo.entity.problem.Problem) Session(org.apache.shiro.session.Session)

Example 24 with Problem

use of top.hcode.hoj.pojo.entity.problem.Problem in project HOJ by HimitZH.

the class GroupProblemManager method addProblem.

public void addProblem(ProblemDto problemDto) throws StatusForbiddenException, StatusNotFoundException, StatusFailException {
    Session session = SecurityUtils.getSubject().getSession();
    UserRolesVo userRolesVo = (UserRolesVo) session.getAttribute("userInfo");
    boolean isRoot = SecurityUtils.getSubject().hasRole("root");
    Long gid = problemDto.getProblem().getGid();
    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("对不起,您无权限操作!");
    }
    problemDto.getProblem().setProblemId(group.getShortName() + problemDto.getProblem().getProblemId());
    QueryWrapper<Problem> problemQueryWrapper = new QueryWrapper<>();
    problemQueryWrapper.eq("problem_id", problemDto.getProblem().getProblemId().toUpperCase());
    int sameProblemIDCount = problemEntityService.count(problemQueryWrapper);
    if (sameProblemIDCount > 0) {
        throw new StatusFailException("该题目的Problem ID已存在,请更换!");
    }
    problemDto.getProblem().setIsGroup(true);
    List<Tag> tagList = new LinkedList<>();
    for (Tag tag : problemDto.getTags()) {
        if (tag.getGid() != null && tag.getGid().longValue() != gid) {
            throw new StatusForbiddenException("对不起,您无权限操作!");
        }
        if (tag.getId() == null) {
            tag.setGid(gid);
        }
        tagList.add(tag);
    }
    problemDto.setTags(tagList);
    boolean isOk = problemEntityService.adminAddProblem(problemDto);
    if (!isOk) {
        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) LinkedList(java.util.LinkedList) UserRolesVo(top.hcode.hoj.pojo.vo.UserRolesVo) Problem(top.hcode.hoj.pojo.entity.problem.Problem) StatusFailException(top.hcode.hoj.common.exception.StatusFailException) Tag(top.hcode.hoj.pojo.entity.problem.Tag) Session(org.apache.shiro.session.Session)

Example 25 with Problem

use of top.hcode.hoj.pojo.entity.problem.Problem in project HOJ by HimitZH.

the class GroupProblemManager method getProblemCases.

public List<ProblemCase> getProblemCases(Long pid, Boolean isUpload) throws StatusForbiddenException, StatusNotFoundException, StatusFailException {
    Session session = SecurityUtils.getSubject().getSession();
    UserRolesVo userRolesVo = (UserRolesVo) session.getAttribute("userInfo");
    boolean isRoot = SecurityUtils.getSubject().hasRole("root");
    Problem problem = problemEntityService.getById(pid);
    if (problem == null) {
        throw new StatusNotFoundException("该题目不存在!");
    }
    Long gid = problem.getGid();
    Group group = groupEntityService.getById(gid);
    if (group == null || group.getStatus() == 1 && !isRoot) {
        throw new StatusNotFoundException("该团队不存在或已被封禁!");
    }
    if (!userRolesVo.getUsername().equals(problem.getAuthor()) && !isRoot && !groupValidator.isGroupRoot(userRolesVo.getUid(), gid)) {
        throw new StatusForbiddenException("对不起,您无权限操作!");
    }
    QueryWrapper<ProblemCase> problemCaseQueryWrapper = new QueryWrapper<>();
    problemCaseQueryWrapper.eq("pid", pid).eq("status", 0);
    if (isUpload) {
        problemCaseQueryWrapper.last("order by length(input) asc,input asc");
    }
    return problemCaseEntityService.list(problemCaseQueryWrapper);
}
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) UserRolesVo(top.hcode.hoj.pojo.vo.UserRolesVo) StatusNotFoundException(top.hcode.hoj.common.exception.StatusNotFoundException) Problem(top.hcode.hoj.pojo.entity.problem.Problem) ProblemCase(top.hcode.hoj.pojo.entity.problem.ProblemCase) Session(org.apache.shiro.session.Session)

Aggregations

Problem (top.hcode.hoj.pojo.entity.problem.Problem)69 QueryWrapper (com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)46 UserRolesVo (top.hcode.hoj.pojo.vo.UserRolesVo)35 StatusFailException (top.hcode.hoj.common.exception.StatusFailException)26 Session (org.apache.shiro.session.Session)25 Transactional (org.springframework.transaction.annotation.Transactional)24 StatusForbiddenException (top.hcode.hoj.common.exception.StatusForbiddenException)22 ContestProblem (top.hcode.hoj.pojo.entity.contest.ContestProblem)19 UpdateWrapper (com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper)15 StatusNotFoundException (top.hcode.hoj.common.exception.StatusNotFoundException)15 Judge (top.hcode.hoj.pojo.entity.judge.Judge)15 HttpSession (javax.servlet.http.HttpSession)13 RequiresAuthentication (org.apache.shiro.authz.annotation.RequiresAuthentication)13 Group (top.hcode.hoj.pojo.entity.group.Group)13 RequiresRoles (org.apache.shiro.authz.annotation.RequiresRoles)12 LinkedList (java.util.LinkedList)9 Contest (top.hcode.hoj.pojo.entity.contest.Contest)9 ContestRecord (top.hcode.hoj.pojo.entity.contest.ContestRecord)8 Tag (top.hcode.hoj.pojo.entity.problem.Tag)7 JudgeCase (top.hcode.hoj.pojo.entity.judge.JudgeCase)6