Search in sources :

Example 21 with BusinessException

use of cn.edu.zjnu.acm.judge.exception.BusinessException in project judge by zjnu-acm.

the class BBSController method showMessage.

@Secured("ROLE_USER")
@GetMapping("showmessage")
public String showMessage(@RequestParam("message_id") long messageId, Model model) {
    Message message = messageMapper.findOne(messageId);
    if (message == null) {
        throw new BusinessException(BusinessCode.MESSAGE_NOT_FOUND);
    }
    final DateTimeFormatter formatter = dtf.withZone(ZoneId.systemDefault());
    final Instant inDate = message.getInDate();
    final Long parentId = message.getParent();
    final String uid = message.getUser();
    final String title = message.getTitle();
    final Long pid = message.getProblem();
    final long depth = message.getDepth() + 1;
    final long thread = message.getThread();
    final long order = message.getOrder();
    model.addAttribute("title", "Detail of message");
    StringBuilder sb = new StringBuilder("<table border=\"0\" width=\"980\" class=\"table-back\">" + "<tr><td>" + "<center><h2><font color=\"blue\">").append(HtmlEscape.escapeHtml4Xml(title)).append("</font></h2></center>" + "Posted by <b><a href=\"userstatus?user_id=").append(uid).append("\"><font color=\"black\">").append(uid).append("</font></a></b>" + "at ").append(formatter.format(inDate));
    if (pid != null && pid != 0) {
        sb.append("on <b><a href=\"showproblem?problem_id=").append(pid).append("\"><font color=\"black\">Problem ").append(pid).append("</font></a></b>");
    }
    if (parentId != null && parentId != 0) {
        Message parent = messageMapper.findOne(parentId);
        if (parent != null) {
            String title1 = parent.getTitle();
            Instant inDate1 = parent.getInDate();
            sb.append("<br/>In Reply To:<a href=\"showmessage?message_id=").append(parentId).append("\"><font color=\"blue\">").append(HtmlEscape.escapeHtml4Xml(title1)).append("</font></a>" + "Posted by:<b><a href=\"userstatus?user_id=").append(parent.getUser()).append("\"><font color=\"black\">").append(parent.getUser()).append("</font></a></b>" + "at ").append(formatter.format(inDate1));
        }
    }
    sb.append("<HR noshade color=#FFF><pre>");
    sb.append(HtmlEscape.escapeHtml4Xml(message.getContent()));
    sb.append("</pre><HR noshade color=\"#FFF\"><b>Followed by:</b><br/><ul>");
    long dep = depth;
    List<Message> messages = messageMapper.findAllByThreadIdAndOrderNumGreaterThanOrderByOrderNum(thread, order);
    for (Message m : messages) {
        String user = m.getUser();
        long id = m.getId();
        String title1 = m.getTitle();
        Instant inDate1 = m.getInDate();
        final long depth1 = m.getDepth();
        if (depth1 < depth) {
            break;
        }
        for (long i = dep; i < depth1; ++i) {
            sb.append("<ul>");
        }
        for (long i = depth1; i < dep; i++) {
            sb.append("</ul>");
        }
        sb.append("<li><a href=\"showmessage?message_id=").append(id).append("\"><font color=\"blue\">").append(HtmlEscape.escapeHtml4Xml(title1)).append("</font></a>" + " -- <b><a href=\"userstatus?user_id=").append(user).append("\"><font color=\"black\">").append(user).append("</font></a></b> ");
        sb.append(formatter.format(inDate1));
        dep = depth1;
    }
    for (long i = depth; i < dep; ++i) {
        sb.append("</ul>");
    }
    sb.append("</ul>" + "<HR noshade color=\"#FFF\">" + "<font color=\"blue\">Post your reply here:</font><br/>" + "<form method=\"POST\" action=\"post\">");
    if (pid != null) {
        sb.append("<input type=\"hidden\" name=\"problem_id\" value=\"").append(pid).append("\"/>");
    }
    sb.append("<input type=\"hidden\" name=\"parent_id\" value=\"").append(messageId).append("\"/>");
    sb.append("Title:<br/><input type=\"text\" name=\"title\" value=\"").append(HtmlEscape.escapeHtml4Xml(!title.regionMatches(true, 0, "re:", 0, 3) ? "Reply:" + title : title)).append("\" size=75><br/>" + "Content:<br/><textarea rows=\"15\" name=\"content\" cols=\"75\">").append(JudgeUtils.INSTANCE.getReplyString(message.getContent())).append("</textarea><br/><button type=\"submit\">reply</button></td></tr></table>");
    model.addAttribute("content", sb.toString());
    return "legacy";
}
Also used : BusinessException(cn.edu.zjnu.acm.judge.exception.BusinessException) Message(cn.edu.zjnu.acm.judge.domain.Message) Instant(java.time.Instant) DateTimeFormatter(java.time.format.DateTimeFormatter) GetMapping(org.springframework.web.bind.annotation.GetMapping) Secured(org.springframework.security.access.annotation.Secured)

Example 22 with BusinessException

use of cn.edu.zjnu.acm.judge.exception.BusinessException in project judge by zjnu-acm.

the class ExcelUtil method parse.

public static <T> List<T> parse(InputStream inputStream, Class<T> type, @Nonnull Locale locale) {
    Objects.requireNonNull(locale, "locale");
    boolean support = inputStream.markSupported();
    InputStream is = support ? inputStream : new BufferedInputStream(inputStream);
    try (Workbook workbook = WorkbookFactory.create(is)) {
        FormulaEvaluator evaluator = workbook.getCreationHelper().createFormulaEvaluator();
        return parse(workbook, evaluator, type, locale);
    } catch (IOException | IllegalStateException ex) {
        throw new BusinessException(BusinessCode.INVALID_EXCEL);
    }
}
Also used : BusinessException(cn.edu.zjnu.acm.judge.exception.BusinessException) BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) Workbook(org.apache.poi.ss.usermodel.Workbook) FormulaEvaluator(org.apache.poi.ss.usermodel.FormulaEvaluator)

Aggregations

BusinessException (cn.edu.zjnu.acm.judge.exception.BusinessException)22 GetMapping (org.springframework.web.bind.annotation.GetMapping)8 Problem (cn.edu.zjnu.acm.judge.domain.Problem)7 Submission (cn.edu.zjnu.acm.judge.domain.Submission)6 Contest (cn.edu.zjnu.acm.judge.domain.Contest)5 User (cn.edu.zjnu.acm.judge.domain.User)5 PostMapping (org.springframework.web.bind.annotation.PostMapping)4 Secured (org.springframework.security.access.annotation.Secured)3 Account (cn.edu.zjnu.acm.judge.data.excel.Account)2 Message (cn.edu.zjnu.acm.judge.domain.Message)2 MessageException (cn.edu.zjnu.acm.judge.exception.MessageException)2 IOException (java.io.IOException)2 Transactional (org.springframework.transaction.annotation.Transactional)2 JudgeException (cn.edu.zjnu.acm.judge.core.JudgeException)1 SimpleValidator (cn.edu.zjnu.acm.judge.core.SimpleValidator)1 Validator (cn.edu.zjnu.acm.judge.core.Validator)1 RunRecord (cn.edu.zjnu.acm.judge.data.dto.RunRecord)1 SubmissionDetail (cn.edu.zjnu.acm.judge.data.dto.SubmissionDetail)1 SubmissionDetailDTO (cn.edu.zjnu.acm.judge.data.dto.SubmissionDetailDTO)1 Mail (cn.edu.zjnu.acm.judge.domain.Mail)1