001    /*
002     * Copyright (C) 2008 Adam Cornett This program is free software; you can
003     * redistribute it and/or modify it under the terms of the GNU General Public
004     * License as published by the Free Software Foundation; either version 3 of the
005     * License, or (at your option) any later version. This program is distributed
006     * in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
007     * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
008     * See the GNU General Public License for more details. You should have received
009     * a copy of the GNU General Public License along with this program; if not, see
010     * <http://www.gnu.org/licenses>.
011     */
012    
013    package net.codescore.controllers;
014    
015    import java.util.List;
016    
017    import net.codescore.dbo.Clarification;
018    import net.codescore.dbo.Judge;
019    import net.codescore.dbo.Problem;
020    import net.codescore.dbo.ProblemStatus;
021    import net.codescore.dbo.Submission;
022    import net.codescore.dbo.TeamSubmission;
023    import net.codescore.managers.ClarificationListener;
024    import net.codescore.managers.CompetitionManager;
025    import net.codescore.managers.SubmissionListener;
026    import net.codescore.ui.ClariUpdateListener;
027    import net.codescore.ui.SubUpdateListener;
028    import net.codescore.ui.admin.JudgeHome;
029    
030    public class JudgeController extends CompController implements
031            SubUpdateListener, ClariUpdateListener {
032            @Override
033            public void onClariAdd(Clarification c) {
034                    if (c.getCompetition().equals(judge.getCompetition()))
035                            setPendingUpdates();
036            }
037    
038            @Override
039            public void onClariUpdate(Clarification c) {
040                    if (c.getCompetition().equals(judge.getCompetition()))
041                            setPendingUpdates();
042            }
043    
044            @Override
045            public void onSubAdd(TeamSubmission s) {
046                    if (s.getCompetition().equals(judge.getCompetition())) {
047                            if (watchedProblem != null) {
048                                    if (s.getProblem().equals(watchedProblem))
049                                            setPendingUpdates();
050                            } else {
051                                    setPendingUpdates();
052                            }
053                    }
054            }
055    
056            @Override
057            public void onSubUpdate(TeamSubmission s) {
058                    if (s.getCompetition().equals(judge.getCompetition())) {
059                            if (watchedProblem != null) {
060                                    if (s.getProblem().equals(watchedProblem))
061                                            setPendingUpdates();
062                            } else {
063                                    setPendingUpdates();
064                            }
065                    }
066            }
067    
068            private Judge judge;
069            private Problem watchedProblem = null;
070    
071            public JudgeController(JudgeHome jh, CompetitionManager cm) {
072                    super(jh.getDesktop(), cm);
073                    SubmissionListener.registerCallback(this);
074                    ClarificationListener.registerCallback(this);
075            }
076    
077            public void answerQuestion(String answer, Clarification c) {
078                    c.setResponse(answer);
079                    c.getObjectContext().commitChanges();
080            }
081    
082            public Judge getJudge() {
083                    return this.judge;
084            }
085    
086            public Problem getWatchedProblem() {
087                    return this.watchedProblem;
088            }
089    
090            public void gradeSub(Submission sub, ProblemStatus ps) {
091                    sub.setStatus(ps);
092                    sub.getObjectContext().commitChanges();
093            }
094    
095            @Override
096            public void processUpdates() {
097                    // TODO Auto-generated method stub
098    
099            }
100    
101            public void reGradeProblem(Problem p) {
102                    List<TeamSubmission> subList = p.getSubmissions();
103                    for (Submission s : subList)
104                            getCompManager().addSubmissionToGradeQueue(s);
105            }
106    
107            public void setJudge(Judge judge) {
108                    this.judge = judge;
109            }
110    
111            public void setWatchedProblem(Problem watchedProblem) {
112                    this.watchedProblem = watchedProblem;
113            }
114    
115            public String toString() {
116                    return "Judge Controller:" + judge;
117            }
118    }