package net.sourceforge.fenixedu.domain.finalDegreeWork; import java.util.ArrayList; import java.util.Calendar; import java.util.Collection; import java.util.Collections; import java.util.Date; import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; import net.sourceforge.fenixedu.domain.ExecutionDegree; import net.sourceforge.fenixedu.domain.ExecutionYear; import net.sourceforge.fenixedu.domain.RootDomainObject; import net.sourceforge.fenixedu.util.FinalDegreeWorkProposalStatus; import org.joda.time.DateTime; import org.joda.time.Interval; public class Scheduleing extends Scheduleing_Base { public Scheduleing() { super(); setRootDomainObject(RootDomainObject.getInstance()); setAllowSimultaneousCoorientationAndCompanion(Boolean.FALSE); setAttributionByTeachers(Boolean.FALSE); } public Date getEndOfProposalPeriod() { if (this.getEndOfProposalPeriodDate() != null && this.getEndOfProposalPeriodTime() != null) { Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(this.getEndOfProposalPeriodDate().getTime()); Calendar calendarTime = Calendar.getInstance(); calendarTime.setTimeInMillis(this.getEndOfProposalPeriodTime().getTime()); calendar.set(Calendar.HOUR_OF_DAY, calendarTime.get(Calendar.HOUR_OF_DAY)); calendar.set(Calendar.MINUTE, calendarTime.get(Calendar.MINUTE)); calendar.set(Calendar.SECOND, calendarTime.get(Calendar.SECOND)); return calendar.getTime(); } return null; } public void setEndOfProposalPeriod(Date endOfProposalPeriod) { this.setEndOfProposalPeriodDate(endOfProposalPeriod); this.setEndOfProposalPeriodTime(endOfProposalPeriod); } public Date getStartOfProposalPeriod() { if (this.getStartOfProposalPeriodDate() != null && this.getStartOfProposalPeriodTime() != null) { Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(this.getStartOfProposalPeriodDate().getTime()); Calendar calendarTime = Calendar.getInstance(); calendarTime.setTimeInMillis(this.getStartOfProposalPeriodTime().getTime()); calendar.set(Calendar.HOUR_OF_DAY, calendarTime.get(Calendar.HOUR_OF_DAY)); calendar.set(Calendar.MINUTE, calendarTime.get(Calendar.MINUTE)); calendar.set(Calendar.SECOND, calendarTime.get(Calendar.SECOND)); return calendar.getTime(); } return null; } public void setStartOfProposalPeriod(Date startOfProposalPeriod) { this.setStartOfProposalPeriodDate(startOfProposalPeriod); this.setStartOfProposalPeriodTime(startOfProposalPeriod); } public Date getStartOfCandidacyPeriod() { if (this.getStartOfCandidacyPeriodDate() != null && this.getStartOfCandidacyPeriodTime() != null) { Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(this.getStartOfCandidacyPeriodDate().getTime()); Calendar calendarTime = Calendar.getInstance(); calendarTime.setTimeInMillis(this.getStartOfCandidacyPeriodTime().getTime()); calendar.set(Calendar.HOUR_OF_DAY, calendarTime.get(Calendar.HOUR_OF_DAY)); calendar.set(Calendar.MINUTE, calendarTime.get(Calendar.MINUTE)); calendar.set(Calendar.SECOND, calendarTime.get(Calendar.SECOND)); return calendar.getTime(); } return null; } public void setStartOfCandidacyPeriod(Date startOfCandidacyPeriod) { this.setStartOfCandidacyPeriodDate(startOfCandidacyPeriod); this.setStartOfCandidacyPeriodTime(startOfCandidacyPeriod); } public Date getEndOfCandidacyPeriod() { if (this.getEndOfCandidacyPeriodDate() != null && this.getEndOfCandidacyPeriodTime() != null) { Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(this.getEndOfCandidacyPeriodDate().getTime()); Calendar calendarTime = Calendar.getInstance(); calendarTime.setTimeInMillis(this.getEndOfCandidacyPeriodTime().getTime()); calendar.set(Calendar.HOUR_OF_DAY, calendarTime.get(Calendar.HOUR_OF_DAY)); calendar.set(Calendar.MINUTE, calendarTime.get(Calendar.MINUTE)); calendar.set(Calendar.SECOND, calendarTime.get(Calendar.SECOND)); return calendar.getTime(); } return null; } public void setEndOfCandidacyPeriod(Date endOfCandidacyPeriod) { this.setEndOfCandidacyPeriodDate(endOfCandidacyPeriod); this.setEndOfCandidacyPeriodTime(endOfCandidacyPeriod); } public Collection getExecutionDegreesSortedByDegreeName() { final List executionDegrees = new ArrayList(getExecutionDegrees()); Collections.sort(executionDegrees, ExecutionDegree.EXECUTION_DEGREE_COMPARATORY_BY_DEGREE_TYPE_AND_NAME); return executionDegrees; } public Set findProposalsByStatus(final FinalDegreeWorkProposalStatus finalDegreeWorkProposalStatus) { final Set proposals = new HashSet(); for (final Proposal proposal : getProposalsSet()) { if (finalDegreeWorkProposalStatus.equals(proposal.getStatus())) { proposals.add(proposal); } } return proposals; } public Set findPublishedProposals() { return findProposalsByStatus(FinalDegreeWorkProposalStatus.PUBLISHED_STATUS); } public Set findApprovedProposals() { return findProposalsByStatus(FinalDegreeWorkProposalStatus.APPROVED_STATUS); } public SortedSet getGroupsSortedByStudentNumbers() { final SortedSet groups = new TreeSet( FinalDegreeWorkGroup.COMPARATOR_BY_STUDENT_NUMBERS); for (final ExecutionDegree executionDegree : getExecutionDegreesSet()) { groups.addAll(executionDegree.getAssociatedFinalDegreeWorkGroupsSet()); } return groups; } public SortedSet getGroupsWithProposalsSortedByStudentNumbers() { final SortedSet groups = new TreeSet( FinalDegreeWorkGroup.COMPARATOR_BY_STUDENT_NUMBERS); for (final ExecutionDegree executionDegree : getExecutionDegreesSet()) { for (final FinalDegreeWorkGroup group : executionDegree.getAssociatedFinalDegreeWorkGroupsSet()) { if (!group.getGroupProposalsSet().isEmpty()) { groups.add(group); } } } return groups; } public boolean isInsideProposalSubmissionPeriod() { final DateTime start = new DateTime(getStartOfProposalPeriod()); final DateTime end = new DateTime(getEndOfProposalPeriod()); return !start.isAfterNow() && !end.isBeforeNow(); } public void delete() { removeRootDomainObject(); deleteDomainObject(); } public Interval getProposalInterval() { final Date startDate = getStartOfProposalPeriodDate(); final Date startTime = getStartOfProposalPeriodTime(); final Date endDate = getEndOfProposalPeriodDate(); final Date endTime = getEndOfProposalPeriodTime(); return getInterval(startDate, startTime, endDate, endTime); } public Interval getCandidacyInterval() { final Date startDate = getStartOfCandidacyPeriodDate(); final Date startTime = getStartOfCandidacyPeriodTime(); final Date endDate = getEndOfCandidacyPeriodDate(); final Date endTime = getEndOfCandidacyPeriodTime(); return getInterval(startDate, startTime, endDate, endTime); } private Interval getInterval(final Date startDate, final Date startTime, final Date endDate, final Date endTime) { if (startDate != null && startTime != null && endDate != null && endTime != null) { final DateTime start = newDateTime(startDate, startTime); final DateTime end = newDateTime(endDate, endTime); if (start != null && end != null) { return new Interval(start, end); } } return null; } private DateTime newDateTime(final Date date, final Date time) { if (date != null && time != null) { return new DateTime(date.getTime()).withHourOfDay(time.getHours()).withMinuteOfHour(time.getMinutes()) .withSecondOfMinute(0).withMillisOfSecond(0); } return null; } public boolean getAreCandidacyConditionsDefined() { return getMinimumCompletedCreditsFirstCycle() != null && getMinimumCompletedCreditsSecondCycle() != null && getMaximumNumberOfProposalCandidaciesPerGroup() != null; } public ExecutionYear getExecutionYearOfOneExecutionDegree() { return getExecutionDegrees().get(0).getExecutionYear(); } }