package net.sourceforge.fenixedu.domain; import java.util.ArrayList; import java.util.List; import net.sourceforge.fenixedu.domain.degree.DegreeType; import net.sourceforge.fenixedu.domain.exceptions.DomainException; import net.sourceforge.fenixedu.util.EvaluationType; /** * @author Tânia Pousão * */ public class FinalEvaluation extends FinalEvaluation_Base { public FinalEvaluation() { super(); } public Integer getGradesListVersion() { int lastVersion = 0; for (Mark mark : getMarks()) { FinalMark finalMark = (FinalMark) mark; if (finalMark.getGradeListVersion() > lastVersion) { lastVersion = finalMark.getGradeListVersion(); } } if (lastVersion == 99) { throw new DomainException("grades list version cannot be higher than 99"); } return Integer.valueOf(++lastVersion); } @Override public FinalMark addNewMark(Attends attends, String markValue) { if (attends.getMarkByEvaluation(this) != null) { throw new DomainException("error.Evaluation.attend.already.has.mark.for.evaluation"); } return new FinalMark(attends, this, markValue); } public EvaluationType getEvaluationType() { return EvaluationType.FINAL_TYPE; } public List getAlreadySubmitedMarks(ExecutionCourse executionCourse) { List result = new ArrayList(); for (Mark mark : getMarks()) { FinalMark finalMark = (FinalMark) mark; if (finalMark.getAttend().getExecutionCourse().equals(executionCourse) && finalMark.getGradeListVersion() != 0 && finalMark.getSubmitedMark() != null) { result.add(finalMark); } } return result; } public List getNotSubmitedMarkAttends(ExecutionCourse executionCourse) { List result = new ArrayList(); for (Attends attends : executionCourse.getAttends()) { if (attends.getEnrolment() != null && attends.getRegistration().getDegreeType().equals(DegreeType.DEGREE)) { FinalMark mark = getFinalMark(attends); if (mark == null || (mark.getGradeListVersion() == 0 && mark.getSubmitedMark() == null)) { result.add(attends); } } } return result; } private FinalMark getFinalMark(Attends attends) { for (Mark mark : attends.getAssociatedMarks()) { if (mark.getEvaluation().equals(this)) { return (FinalMark) mark; } } return null; } private void checkRulesToDelete() { if (hasAnyMarks()) { throw new DomainException("error.existing.marks"); } } @Override public void delete() { checkRulesToDelete(); super.delete(); } @Override public boolean isFinal() { return true; } }