ITurnoAluno ta = (ITurnoAluno)sp.getITurnoAlunoPersistente().readByTurnoAndAluno(turno, student);
ITurnoAluno ta = sp.getITurnoAlunoPersistente().readByTurnoAndAluno(turno, student);
    public Object run(Integer executionCourseCode, List curricularPlansIds, List enrollmentTypeFilters, List shiftIds) throws ExcepcaoInexistente,            FenixServiceException{        ISite site = null;        try {            final ISuportePersistente sp = SuportePersistenteOJB.getInstance();            final IPersistentEnrollment persistentEnrollment = sp.getIPersistentEnrolment();            final IExecutionCourse executionCourse = (IExecutionCourse)sp.getIPersistentExecutionCourse().readByOID(ExecutionCourse.class,executionCourseCode);            InfoExecutionCourse infoExecutionCourse = InfoExecutionCourseWithExecutionPeriod.newInfoFromDomain(executionCourse);                        IPersistentSite persistentSite = sp.getIPersistentSite();            site = persistentSite.readByExecutionCourse(executionCourse);            List attends = executionCourse.getAttends();                        List allDegreeCurricularPlans = getDegreeCurricularPlansFromAttends(attends);            List allShifts = sp.getITurnoPersistente().readByExecutionCourse(executionCourse);            List groupProperties = executionCourse.getGroupProperties();                        Map studentGroupsMap = getStudentGroupsMapFromGroupPropertiesList(groupProperties,sp);                        InfoAttendsSummary infoAttendsSummary = new InfoAttendsSummary();            Map enrollmentDistribution = new HashMap();            List enrollmentDistributionKeys = new ArrayList();            // filter by Course            if (curricularPlansIds != null)            {                final List dcpIds = new ArrayList();                dcpIds.addAll(curricularPlansIds);                                Predicate pCourses = new Predicate()                {                    public boolean evaluate (Object o)                    {                        IFrequenta attendance = (IFrequenta)o;                                                List scps = attendance.getAluno().getStudentCurricularPlans();                                                if(scps != null && !scps.isEmpty())                        {                            IStudentCurricularPlan lastSCP = getStudentCurricularPlanFromAttends(attendance);	                        final Integer lastDCPId = lastSCP.getDegreeCurricularPlan().getIdInternal();	                        	                        return dcpIds.contains(lastDCPId);                        }                        else                            return false;                    }                };                                attends=(List)CollectionUtils.select(attends,pCourses);            }                        // filter by Enrollment type            if (enrollmentTypeFilters != null)             {                boolean enrolledFilter = enrollmentTypeFilters.contains(AttendacyStateSelectionType.ENROLLED);                boolean notEnrolledFilter = enrollmentTypeFilters.contains(AttendacyStateSelectionType.NOT_ENROLLED);                boolean improvementFilter = enrollmentTypeFilters.contains(AttendacyStateSelectionType.IMPROVEMENT);                                List newAttends = new ArrayList();                Iterator attendsIterator = attends.iterator();                while(attendsIterator.hasNext()){                    IFrequenta attendacy = (IFrequenta)attendsIterator.next();                                        // improvement student (he/she is enrolled)                    if (improvementFilter && attendacy.getEnrolment() != null &&                            (!attendacy.getEnrolment().getExecutionPeriod().equals(executionCourse.getExecutionPeriod()))){                        newAttends.add(attendacy);                                        // normal student (cannot be an improvement student)                    } else if (enrolledFilter && attendacy.getEnrolment() != null &&                            (attendacy.getEnrolment().getExecutionPeriod().equals(executionCourse.getExecutionPeriod()))){                        newAttends.add(attendacy);                    // not enrolled student                    } else if (notEnrolledFilter && attendacy.getEnrolment() == null){                        newAttends.add(attendacy);                    }                }                attends = newAttends;            }                                    // filter by Shift            if (shiftIds != null){                 Iterator shiftIterator = shiftIds.iterator();                List collectedAttends = new ArrayList();                                while(shiftIterator.hasNext()) {                                     Integer shiftId = (Integer)shiftIterator.next();	                final ITurno turno = (ITurno) sp.getITurnoPersistente().readByOID(Turno.class,shiftId);	                                	                Iterator attendsIterator = attends.iterator();	                	                while(attendsIterator.hasNext()){	                    IFrequenta attendance = (IFrequenta)attendsIterator.next();	                	                    //	if an attendance is related to a Shift	                    IStudent student = attendance.getAluno();	                	                    try {	                        ITurnoAluno ta = (ITurnoAluno)sp.getITurnoAlunoPersistente().readByTurnoAndAluno(turno, student);	                        	                        if (ta != null)	                            collectedAttends.add(attendance);	                    }	                	                    catch(ExcepcaoPersistencia ep) {	                        FenixServiceException newEx = new FenixServiceException("Persistence layer error");	                        newEx.fillInStackTrace();	                        throw newEx;	                    }	                }                }                attends = collectedAttends;            }            // building the info            InfoForReadStudentsWithAttendsByExecutionCourse infoDTO = new InfoForReadStudentsWithAttendsByExecutionCourse();            List shifts = sp.getITurnoPersistente().readByExecutionCourseID(executionCourse.getIdInternal());                        List infoCompositions = new ArrayList();            Iterator it = attends.iterator();            while(it.hasNext()){                IFrequenta iFrequenta = (IFrequenta)it.next();                                InfoCompositionOfAttendAndDegreeCurricularPlanAndShiftsAndStudentGroups infoComposition = new InfoCompositionOfAttendAndDegreeCurricularPlanAndShiftsAndStudentGroups();                                InfoFrequenta infoFrequenta = InfoAttendsWithInfoStudentAndPersonAndInfoEnrollment.newInfoFromDomain(iFrequenta);                infoComposition.setInfoAttends(infoFrequenta);                // determining the EnrolmentEvaluationType                if (iFrequenta.getEnrolment() != null){                    EnrolmentEvaluationType enrollmentEvaluationType = null;                    if (iFrequenta.getEnrolment().getExecutionPeriod().equals(executionCourse.getExecutionPeriod())){                        enrollmentEvaluationType = EnrolmentEvaluationType.NORMAL_OBJ;                    }                    else{                        enrollmentEvaluationType = EnrolmentEvaluationType.IMPROVEMENT_OBJ;                                            }                    infoFrequenta.getInfoEnrolment().setEnrolmentEvaluationType(enrollmentEvaluationType);                                    }                                IStudentCurricularPlan studentCurricularPlan = getStudentCurricularPlanFromAttends(iFrequenta);                IDegreeCurricularPlan degreeCP = studentCurricularPlan.getDegreeCurricularPlan();                InfoDegreeCurricularPlan infoDCP = InfoDegreeCurricularPlanWithDegree.newInfoFromDomain(degreeCP);                infoComposition.setAttendingStudentInfoDCP(infoDCP);                                Map infoShifts = getShiftsByAttends(shifts,iFrequenta,sp);                infoComposition.setInfoShifts(infoShifts);                                Map infoStudentGroups = getInfoStudentGroupsByAttends(studentGroupsMap,iFrequenta);                infoComposition.setInfoStudentGroups(infoStudentGroups);                                IStudent student = iFrequenta.getAluno();                IEnrollment enrollment = iFrequenta.getEnrolment();                Integer numberOfEnrollments = null;                                if (enrollment != null){                    List studentEnrollments = persistentEnrollment.readEnrollmentsByStudentAndCurricularCourseNameAndDegree(student,enrollment.getCurricularCourse(),studentCurricularPlan.getDegreeCurricularPlan().getDegree());                    numberOfEnrollments = new Integer(studentEnrollments.size());                                    }                else{                    numberOfEnrollments = new Integer(0);                                    }                                Integer num = (Integer)enrollmentDistribution.get(numberOfEnrollments);                if (num == null)                    num = new Integer(0);                enrollmentDistribution.put(numberOfEnrollments,new Integer(num.intValue()+1));                                if (!enrollmentDistributionKeys.contains(numberOfEnrollments)){                    enrollmentDistributionKeys.add(numberOfEnrollments);                }                                infoComposition.setNumberOfEnrollments(numberOfEnrollments);                                infoCompositions.add(infoComposition);            }            infoDTO.setInfoAttends(infoCompositions);            infoDTO.setInfoExecutionCourse(infoExecutionCourse);                        List tipoAulas = getClassTypesFromExecutionCourse(executionCourse);            infoDTO.setClassTypes(tipoAulas);                        infoDTO.setInfoShifts(getInfoShiftsFromList(allShifts));            infoDTO.setInfoDegreeCurricularPlans(getInfoDegreeCurricularPlansFromList(allDegreeCurricularPlans));                        List infoGroupProperties = getInfoGroupPropertiesFromList(groupProperties);            infoDTO.setInfoGroupProperties(infoGroupProperties);                        Collections.sort(enrollmentDistributionKeys);            infoAttendsSummary.setEnrollmentDistribution(enrollmentDistribution);            infoAttendsSummary.setNumberOfEnrollments(enrollmentDistributionKeys);            infoDTO.setInfoAttendsSummary(infoAttendsSummary);                        TeacherAdministrationSiteView siteView = createSiteView(infoDTO, site);            return siteView;        } catch (ExcepcaoPersistencia ex) {            ex.printStackTrace();            FenixServiceException newEx = new FenixServiceException("");            newEx.fillInStackTrace();            throw newEx;        }    }