Search in sources :

Example 11 with Contest

use of cn.edu.zju.acm.onlinejudge.bean.Contest in project zoj by licheng.

the class ContestPersistenceImplTest method testGetContest2.

/**
	 * Tests getContest method
	 * @throws Exception to JUnit
	 */
public void testGetContest2() throws Exception {
    Contest contest = (Contest) persistence.getContest(contest2.getId());
    checkAbstractContest(contest2, contest);
    assertEquals("wrong start time", contest.getStartTime(), contest2.getStartTime());
    assertEquals("wrong end time", contest.getEndTime(), contest2.getEndTime());
}
Also used : AbstractContest(cn.edu.zju.acm.onlinejudge.bean.AbstractContest) Contest(cn.edu.zju.acm.onlinejudge.bean.Contest)

Example 12 with Contest

use of cn.edu.zju.acm.onlinejudge.bean.Contest in project zoj by licheng.

the class ContestPersistenceImplTest method testUpdateContest2.

/**
	 * Tests updateContest method
	 * @throws Exception to JUnit
	 */
public void testUpdateContest2() throws Exception {
    contest2.setDescription("new");
    contest2.setTitle("new");
    contest2.setLanguages(Arrays.asList(new Object[] { language1, language2, language3 }));
    contest2.setLimit(limit2);
    contest2.setForumId(forum1.getId());
    contest2.setStartTime(new Date(50000));
    contest2.setEndTime(new Date(60000));
    persistence.updateContest(contest2, 11);
    Contest contest = (Contest) persistence.getContest(contest2.getId());
    checkAbstractContest(contest2, contest);
    assertEquals("wrong start time", contest.getStartTime(), contest2.getStartTime());
    assertEquals("wrong end time", contest.getEndTime(), contest2.getEndTime());
}
Also used : AbstractContest(cn.edu.zju.acm.onlinejudge.bean.AbstractContest) Contest(cn.edu.zju.acm.onlinejudge.bean.Contest) Date(java.util.Date)

Example 13 with Contest

use of cn.edu.zju.acm.onlinejudge.bean.Contest 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

Contest (cn.edu.zju.acm.onlinejudge.bean.Contest)13 AbstractContest (cn.edu.zju.acm.onlinejudge.bean.AbstractContest)11 Date (java.util.Date)7 Course (cn.edu.zju.acm.onlinejudge.bean.Course)4 Limit (cn.edu.zju.acm.onlinejudge.bean.Limit)3 Problemset (cn.edu.zju.acm.onlinejudge.bean.Problemset)3 UserSecurity (cn.edu.zju.acm.onlinejudge.security.UserSecurity)2 ArrayList (java.util.ArrayList)2 ActionMessage (org.apache.struts.action.ActionMessage)2 ActionMessages (org.apache.struts.action.ActionMessages)2 Problem (cn.edu.zju.acm.onlinejudge.bean.Problem)1 Language (cn.edu.zju.acm.onlinejudge.bean.enumeration.Language)1 LanguagePersistence (cn.edu.zju.acm.onlinejudge.persistence.LanguagePersistence)1 List (java.util.List)1