/** * */ package net.sourceforge.fenixedu.presentationTier.Action.publico; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.List; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import net.sourceforge.fenixedu.dataTransferObject.inquiries.SearchInquiriesResultPageDTO; import net.sourceforge.fenixedu.domain.ExecutionCourse; import net.sourceforge.fenixedu.domain.ExecutionDegree; import net.sourceforge.fenixedu.domain.ExecutionSemester; import net.sourceforge.fenixedu.domain.inquiries.StudentInquiriesCourseResult; import net.sourceforge.fenixedu.domain.inquiries.teacher.InquiryResponsePeriodType; import net.sourceforge.fenixedu.domain.inquiries.teacher.TeachingInquiry; import net.sourceforge.fenixedu.presentationTier.Action.base.FenixDispatchAction; import org.apache.commons.collections.comparators.ReverseComparator; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import pt.ist.fenixWebFramework.struts.annotations.Forward; import pt.ist.fenixWebFramework.struts.annotations.Forwards; import pt.ist.fenixWebFramework.struts.annotations.Mapping; /** * @author - Shezad Anavarali (shezad@ist.utl.pt) * */ @Mapping(path = "/searchInquiriesResultPage", module = "publico", formBeanClass = SearchInquiriesResultPageDTO.class) @Forwards( { @Forward(name = "searchPage", path = "/executionCourse/inquiries/searchInquiriesResultPage.jsp", useTile = false) }) public class SearchInquiriesResultPageDA extends FenixDispatchAction { public ActionForward prepare(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) { SearchInquiriesResultPageDTO searchPageDTO = (SearchInquiriesResultPageDTO) actionForm; if (searchPageDTO.isEmptyExecutionSemesterID()) { final ExecutionSemester executionSemester = ExecutionSemester.readActualExecutionSemester(); if (executionSemester != null) { final ExecutionSemester previous = executionSemester.getPreviousExecutionPeriod(); if (previous != null) { searchPageDTO.setExecutionSemesterID(previous.getOid()); } } } if (!searchPageDTO.isEmptyExecutionSemesterID()) { return selectExecutionSemester(actionMapping, actionForm, request, response); } request.setAttribute("executionCourses", Collections.EMPTY_LIST); request.setAttribute("executionDegrees", Collections.EMPTY_LIST); request.setAttribute("executionSemesters", getExecutionSemesters()); return actionMapping.findForward("searchPage"); } public ActionForward selectExecutionSemester(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) { SearchInquiriesResultPageDTO searchPageDTO = (SearchInquiriesResultPageDTO) actionForm; ExecutionSemester executionSemester = searchPageDTO.getExecutionSemester(); if (executionSemester == null) { return prepare(actionMapping, actionForm, request, response); } request.setAttribute("executionCourses", Collections.EMPTY_LIST); request.setAttribute("executionDegrees", getExecutionDegrees(executionSemester)); request.setAttribute("executionSemesters", getExecutionSemesters()); return actionMapping.findForward("searchPage"); } public ActionForward selectExecutionDegree(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) { SearchInquiriesResultPageDTO searchPageDTO = (SearchInquiriesResultPageDTO) actionForm; ExecutionSemester executionSemester = searchPageDTO.getExecutionSemester(); if (executionSemester == null) { return prepare(actionMapping, actionForm, request, response); } ExecutionDegree executionDegree = searchPageDTO.getExecutionDegree(); if (executionDegree == null) { return selectExecutionSemester(actionMapping, actionForm, request, response); } Collection executionCourses = new ArrayList(); for (StudentInquiriesCourseResult studentInquiriesCourseResult : executionDegree.getStudentInquiriesCourseResults()) { final ExecutionCourse executionCourse = studentInquiriesCourseResult.getExecutionCourse(); if (executionCourse != null && executionCourse.getExecutionPeriod() == executionSemester) { final Boolean publicDisclosure = studentInquiriesCourseResult.getPublicDisclosure(); final TeachingInquiry responsibleTeachingInquiry = executionCourse.getResponsibleTeachingInquiry(); if ((publicDisclosure != null && publicDisclosure.booleanValue()) || (responsibleTeachingInquiry != null && responsibleTeachingInquiry .getResultsDisclosureToAcademicComunity())) { executionCourses.add(studentInquiriesCourseResult.getExecutionCourse()); } } } Collections.sort((List) executionCourses, ExecutionCourse.EXECUTION_COURSE_NAME_COMPARATOR); request.setAttribute("executionCourses", executionCourses); request.setAttribute("executionDegrees", getExecutionDegrees(executionSemester)); request.setAttribute("executionSemesters", getExecutionSemesters()); return actionMapping.findForward("searchPage"); } public ActionForward selectExecutionCourse(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) { request.setAttribute("executionCourse", ((SearchInquiriesResultPageDTO) actionForm).getExecutionCourse()); return selectExecutionDegree(actionMapping, actionForm, request, response); } private Collection getExecutionSemesters() { Collection executionSemesters = new ArrayList(); for (final ExecutionSemester executionSemester : ExecutionSemester.readNotClosedPublicExecutionPeriods()) { if (executionSemester.getInquiryResponsePeriod(InquiryResponsePeriodType.STUDENT) != null) { executionSemesters.add(executionSemester); } } Collections.sort((List) executionSemesters, new ReverseComparator( ExecutionSemester.EXECUTION_PERIOD_COMPARATOR_BY_SEMESTER_AND_YEAR)); return executionSemesters; } private Collection getExecutionDegrees(ExecutionSemester executionSemester) { Collection executionDegrees = new ArrayList(); for (final ExecutionDegree executionDegree : executionSemester.getExecutionYear().getExecutionDegrees()) { if (!executionDegree.getStudentInquiriesCourseResults().isEmpty()) { executionDegrees.add(executionDegree); } } Collections.sort((List) executionDegrees, ExecutionDegree.EXECUTION_DEGREE_COMPARATORY_BY_DEGREE_TYPE_AND_NAME); return executionDegrees; } }