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;
}
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("删除失败");
}
}
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);
}
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("添加失败");
}
}
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("更新失败!");
}
}
Aggregations