Search in sources :

Example 1 with LanguagePersistence

use of cn.edu.zju.acm.onlinejudge.persistence.LanguagePersistence in project zoj by licheng.

the class SubmissionSearchForm method toSubmissionCriteria.

public SubmissionCriteria toSubmissionCriteria() throws ParseException, NumberFormatException, PersistenceException {
    SubmissionCriteria criteria = new SubmissionCriteria();
    if (this.contestId != null && this.contestId.trim().length() > 0) {
        criteria.setContestId(Long.valueOf(this.contestId.trim()));
    }
    if (this.problemCode != null && this.problemCode.trim().length() > 0) {
        criteria.setProblemCode(this.problemCode);
    }
    if (this.handle != null && this.handle.trim().length() > 0) {
        criteria.setHandle(this.handle);
    }
    if (this.idStart != null && this.idStart.trim().length() > 0) {
        criteria.setIdStart(Long.valueOf(this.idStart.trim()));
    }
    if (this.idEnd != null && this.idEnd.trim().length() > 0) {
        criteria.setIdEnd(Long.valueOf(this.idEnd.trim()));
    }
    if (this.timeStart != null && this.timeStart.trim().length() > 0) {
        criteria.setTimeStart(Utility.parseTimestamp(this.timeStart));
    }
    if (this.timeEnd != null && this.timeEnd.trim().length() > 0) {
        criteria.setTimeEnd(Utility.parseTimestamp(this.timeEnd));
    }
    if (this.languageIds != null && this.languageIds.length > 0) {
        LanguagePersistence persistence = PersistenceManager.getInstance().getLanguagePersistence();
        List<Language> languages = new ArrayList<Language>();
        for (int i = 0; i < this.languageIds.length; ++i) {
            languages.add(persistence.getLanguage(Long.parseLong(this.languageIds[i])));
        }
        criteria.setLanguages(languages);
    }
    if (this.judgeReplyIds != null && this.judgeReplyIds.length > 0) {
        List<JudgeReply> judgeReplies = new ArrayList<JudgeReply>();
        for (int i = 0; i < this.judgeReplyIds.length; ++i) {
            judgeReplies.add(JudgeReply.findById(Long.parseLong(this.judgeReplyIds[i])));
        }
        criteria.setJudgeReplies(judgeReplies);
    }
    return criteria;
}
Also used : Language(cn.edu.zju.acm.onlinejudge.bean.enumeration.Language) JudgeReply(cn.edu.zju.acm.onlinejudge.bean.enumeration.JudgeReply) ArrayList(java.util.ArrayList) SubmissionCriteria(cn.edu.zju.acm.onlinejudge.bean.request.SubmissionCriteria) LanguagePersistence(cn.edu.zju.acm.onlinejudge.persistence.LanguagePersistence)

Example 2 with LanguagePersistence

use of cn.edu.zju.acm.onlinejudge.persistence.LanguagePersistence in project zoj by licheng.

the class ContestForm method toContest.

public AbstractContest toContest() throws ParseException, NumberFormatException, PersistenceException {
    AbstractContest contest = null;
    if (this.contestType == 1) {
        contest = new Problemset();
    } else if (this.contestType == 0) {
        contest = new Contest();
    } else {
        contest = new Course();
    }
    if (this.startTime != null && this.startTime.trim().length() > 0) {
        contest.setStartTime(Utility.parseTimestamp(this.startTime));
        contest.setEndTime(new Date(Utility.parseTimestamp(this.startTime).getTime() + Utility.parseTime(this.contestLength) * 1000));
    }
    try {
        if (this.id != null) {
            contest.setId(Long.parseLong(this.id));
        }
    } catch (NumberFormatException e) {
    }
    contest.setTitle(this.name);
    contest.setDescription(this.description);
    contest.setCheckIp(this.checkIp);
    Limit limit = new Limit();
    if (this.useGlobalDefault) {
        limit.setId(1);
    } else {
        limit.setTimeLimit(Integer.parseInt(this.timeLimit));
        limit.setMemoryLimit(Integer.parseInt(this.memoryLimit));
        limit.setSubmissionLimit(Integer.parseInt(this.submissionLimit));
        limit.setOutputLimit(Integer.parseInt(this.outputLimit));
    }
    contest.setLimit(limit);
    contest.setForumId(Long.parseLong(this.forumId));
    List<Language> languages = new ArrayList<Language>();
    LanguagePersistence languagePersistence = PersistenceManager.getInstance().getLanguagePersistence();
    if (this.languageIds != null) {
        for (int i = 0; i < this.languageIds.length; ++i) {
            Language language = languagePersistence.getLanguage(Long.parseLong(this.languageIds[i]));
            if (language != null) {
                languages.add(language);
            }
        }
    }
    contest.setLanguages(languages);
    return contest;
}
Also used : AbstractContest(cn.edu.zju.acm.onlinejudge.bean.AbstractContest) Language(cn.edu.zju.acm.onlinejudge.bean.enumeration.Language) ArrayList(java.util.ArrayList) AbstractContest(cn.edu.zju.acm.onlinejudge.bean.AbstractContest) Contest(cn.edu.zju.acm.onlinejudge.bean.Contest) Limit(cn.edu.zju.acm.onlinejudge.bean.Limit) Problemset(cn.edu.zju.acm.onlinejudge.bean.Problemset) Course(cn.edu.zju.acm.onlinejudge.bean.Course) Date(java.util.Date) LanguagePersistence(cn.edu.zju.acm.onlinejudge.persistence.LanguagePersistence)

Aggregations

Language (cn.edu.zju.acm.onlinejudge.bean.enumeration.Language)2 LanguagePersistence (cn.edu.zju.acm.onlinejudge.persistence.LanguagePersistence)2 ArrayList (java.util.ArrayList)2 AbstractContest (cn.edu.zju.acm.onlinejudge.bean.AbstractContest)1 Contest (cn.edu.zju.acm.onlinejudge.bean.Contest)1 Course (cn.edu.zju.acm.onlinejudge.bean.Course)1 Limit (cn.edu.zju.acm.onlinejudge.bean.Limit)1 Problemset (cn.edu.zju.acm.onlinejudge.bean.Problemset)1 JudgeReply (cn.edu.zju.acm.onlinejudge.bean.enumeration.JudgeReply)1 SubmissionCriteria (cn.edu.zju.acm.onlinejudge.bean.request.SubmissionCriteria)1 Date (java.util.Date)1