numberOfEnrollments = countAllEnrolmentsForSameStudent(studentCurricularPlan, enrollment.getCurricularCourse().getName()); }  if (numberOfEnrollments > enrollmentDistribution.length) { int[] newDistribution = new int[Math.max(numberOfEnrollments + 1, enrollmentDistribution.length * 2)]; System.arraycopy(enrollmentDistribution, 0, newDistribution, 0, enrollmentDistribution.length); enrollmentDistribution = newDistribution; } enrollmentDistribution[numberOfEnrollments]++;
numberOfEnrollments = countAllEnrolmentsForSameStudent(studentCurricularPlan, enrollment .getCurricularCourse().getName()); }  if (numberOfEnrollments >= enrollmentDistribution.length) { int[] newDistribution = new int[Math.max(numberOfEnrollments + 1, enrollmentDistribution.length * 2)]; System.arraycopy(enrollmentDistribution, 0, newDistribution, 0, enrollmentDistribution.length); enrollmentDistribution = newDistribution; } enrollmentDistribution[numberOfEnrollments]++;
    public Object run(Integer executionCourseCode, List curricularPlansIds, List enrollmentTypeFilters,            List shiftIds) throws FenixServiceException, ExcepcaoPersistencia {        ISite site = null;        final ISuportePersistente sp = PersistenceSupportFactory.getDefaultPersistenceSupport();        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(executionCourseCode);        List attends = executionCourse.getAttends();        List allDegreeCurricularPlans = getDegreeCurricularPlansFromAttends(attends);        List allShifts = sp.getITurnoPersistente()                .readByExecutionCourse(executionCourse.getIdInternal());        List groupProperties = executionCourse.getGroupProperties();        Map studentGroupsMap = getStudentGroupsMapFromGroupPropertiesList(groupProperties, sp);        InfoAttendsSummary infoAttendsSummary = new InfoAttendsSummary();	int[] enrollmentDistribution = new int[10];        // filter by Course        if (curricularPlansIds != null) {            final List dcpIds = new ArrayList();            dcpIds.addAll(curricularPlansIds);            Predicate pCourses = new Predicate() {                public boolean evaluate(Object o) {                    IAttends attendance = (IAttends) 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);                    }                    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()) {                IAttends attendacy = (IAttends) 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 IShift turno = (IShift) sp.getITurnoPersistente().readByOID(Shift.class, shiftId);                Iterator attendsIterator = attends.iterator();                while (attendsIterator.hasNext()) {                    IAttends attendance = (IAttends) attendsIterator.next();                    // if an attendance is related to a Shift                    IStudent student = attendance.getAluno();                    if (turno.getStudents().contains(student)) {                        collectedAttends.add(attendance);                    }                }            }            attends = collectedAttends;        }        // building the info        InfoForReadStudentsWithAttendsByExecutionCourse infoDTO = new InfoForReadStudentsWithAttendsByExecutionCourse();        List shifts = sp.getITurnoPersistente().readByExecutionCourse(executionCourse.getIdInternal());        List infoCompositions = new ArrayList();        Iterator it = attends.iterator();        final Map<Integer, InfoShift> clonedShifts = new HashMap<Integer, InfoShift>();        while (it.hasNext()) {            IAttends iFrequenta = (IAttends) 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;                } else {                    enrollmentEvaluationType = EnrolmentEvaluationType.IMPROVEMENT;                }                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, clonedShifts);            infoComposition.setInfoShifts(infoShifts);            Map infoStudentGroups = getInfoStudentGroupsByAttends(studentGroupsMap, iFrequenta);            infoComposition.setInfoStudentGroups(infoStudentGroups);            IStudent student = iFrequenta.getAluno();            IEnrolment enrollment = iFrequenta.getEnrolment();            int numberOfEnrollments = 0;            if (enrollment != null) {                numberOfEnrollments = countAllEnrolmentsForSameStudent(studentCurricularPlan, enrollment.getCurricularCourse().getName());            }	    if (numberOfEnrollments > enrollmentDistribution.length) {		int[] newDistribution = new int[Math.max(numberOfEnrollments + 1, enrollmentDistribution.length * 2)];		System.arraycopy(enrollmentDistribution, 0, newDistribution, 0, enrollmentDistribution.length);		enrollmentDistribution = newDistribution;	    }	    enrollmentDistribution[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);	List enrollmentDistributionKeys = new ArrayList(enrollmentDistribution.length);	Map enrollmentDistributionMap = new HashMap();	for (int i = 0; i < enrollmentDistribution.length; i++) {	    if (enrollmentDistribution[i] != 0) {		Integer key = new Integer(i);		Integer value = new Integer(enrollmentDistribution[i]);		enrollmentDistributionKeys.add(key);		enrollmentDistributionMap.put(key, value);	    }	}        infoAttendsSummary.setEnrollmentDistribution(enrollmentDistributionMap);        infoAttendsSummary.setNumberOfEnrollments(enrollmentDistributionKeys);        infoDTO.setInfoAttendsSummary(infoAttendsSummary);        TeacherAdministrationSiteView siteView = createSiteView(infoDTO, site);        return siteView;    }