try { InfoDepartment infoDepartment = (InfoDepartment) ServiceUtils.executeService(userView, "ReadDepartmentByTeacher", args); teacher.setDepartment(infoDepartment.getName()); } catch (FenixServiceException fse) { teacher.setDepartment("Desconhecido"); }
InfoDepartment infoDepartment = (InfoDepartment) ServiceUtils.executeService(userView, "ReadDepartmentByTeacher", args); String department = null; if (infoDepartment == null) { final MessageResources messages = MessageResources.getMessageResources("ServidorApresentacao/ApplicationResources"); department = messages.getMessage("UNKNOWN"); } else { department = infoDepartment.getName(); } teacher.setDepartment(department);
    protected void doAfterSearch(SearchActionMapping mapping, HttpServletRequest request,            Collection result) throws Exception {        final InfoExecutionDegree infoExecutionDegree = (InfoExecutionDegree) request                .getAttribute("infoExecutionDegree");        // sort the execution course list        ComparatorChain comparatorChain1 = new ComparatorChain();        comparatorChain1.addComparator(new Comparator() {            private List getInfoScopes(List infoCurricularCourses,                    InfoExecutionDegree infoExecutionDegree) {                Iterator iter = infoCurricularCourses.iterator();                List infoScopes = new ArrayList();                while (iter.hasNext()) {                    InfoCurricularCourse infoCurricularCourse = (InfoCurricularCourse) iter.next();                    if (infoExecutionDegree == null                            || infoExecutionDegree.getInfoDegreeCurricularPlan().equals(                                    infoCurricularCourse.getInfoDegreeCurricularPlan()))                        infoScopes.addAll(infoCurricularCourse.getInfoScopes());                }                return infoScopes;            }            public int compare(Object o1, Object o2) {                InfoSiteCourseInformation information1 = (InfoSiteCourseInformation) o1;                InfoSiteCourseInformation information2 = (InfoSiteCourseInformation) o2;                List infoScopes1 = getInfoScopes(information1.getInfoCurricularCourses(),                        infoExecutionDegree);                List infoScopes2 = getInfoScopes(information2.getInfoCurricularCourses(),                        infoExecutionDegree);                ComparatorChain comparatorChain2 = new ComparatorChain();                comparatorChain2.addComparator(new Comparator() {                    public int compare(Object o1, Object o2) {                        InfoCurricularCourseScope infoScope1 = (InfoCurricularCourseScope) o1;                        InfoCurricularCourseScope infoScope2 = (InfoCurricularCourseScope) o2;                        return infoScope1.getInfoCurricularSemester().getInfoCurricularYear().getYear()                                .compareTo(                                        infoScope2.getInfoCurricularSemester().getInfoCurricularYear()                                                .getYear());                    }                });                comparatorChain2.addComparator(new Comparator() {                    public int compare(Object o1, Object o2) {                        InfoCurricularCourseScope infoScope1 = (InfoCurricularCourseScope) o1;                        InfoCurricularCourseScope infoScope2 = (InfoCurricularCourseScope) o2;                        return infoScope1.getInfoCurricularSemester().getSemester().compareTo(                                infoScope2.getInfoCurricularSemester().getSemester());                    }                });                comparatorChain2.addComparator(new Comparator() {                    public int compare(Object o1, Object o2) {                        InfoCurricularCourseScope infoScope1 = (InfoCurricularCourseScope) o1;                        InfoCurricularCourseScope infoScope2 = (InfoCurricularCourseScope) o2;                        if (infoScope1.getInfoBranch().getAcronym() == null                                || infoScope2.getInfoBranch().getAcronym() == null)                            return 0;                        return infoScope1.getInfoBranch().getAcronym().compareTo(                                infoScope2.getInfoBranch().getAcronym());                    }                });                Collections.sort(infoScopes1, comparatorChain2);                Collections.sort(infoScopes2, comparatorChain2);                InfoCurricularCourseScope infoScope1 = null;                InfoCurricularCourseScope infoScope2 = null;                if(infoScopes1.isEmpty()){                    return 0;                }                   infoScope1 = (InfoCurricularCourseScope) infoScopes1.get(0);                if(infoScopes2.isEmpty()){                    return 0;                }                infoScope2 = (InfoCurricularCourseScope) infoScopes2.get(0);                return comparatorChain2.compare(infoScope1, infoScope2);            }        });        comparatorChain1.addComparator(new Comparator() {            public int compare(Object o1, Object o2) {                InfoSiteCourseInformation information1 = (InfoSiteCourseInformation) o1;                InfoSiteCourseInformation information2 = (InfoSiteCourseInformation) o2;                List infoCurricularCourses1 = getInfoCurricularCourses(information1);                List infoCurricularCourses2 = getInfoCurricularCourses(information2);                ComparatorChain comparatorChain = new ComparatorChain();                comparatorChain.addComparator(new Comparator() {                    public int compare(Object o1, Object o2) {                        InfoCurricularCourse infoCurricularCourse1 = (InfoCurricularCourse) o1;                        InfoCurricularCourse infoCurricularCourse2 = (InfoCurricularCourse) o2;                        return infoCurricularCourse1.getName()                                .compareTo(infoCurricularCourse2.getName());                    }                });                InfoCurricularCourse infoCurricularCourse1 = (InfoCurricularCourse) infoCurricularCourses1                        .get(0);                InfoCurricularCourse infoCurricularCourse2 = (InfoCurricularCourse) infoCurricularCourses2                        .get(0);                return comparatorChain.compare(infoCurricularCourse1, infoCurricularCourse2);            }            /**             * @param information1             * @return             */            private List getInfoCurricularCourses(InfoSiteCourseInformation information1) {                List infoCurricularCourses = information1.getInfoCurricularCourses();                return (List) CollectionUtils.select(infoCurricularCourses, new Predicate() {                    public boolean evaluate(Object arg0) {                        InfoCurricularCourse infoCurricularCourse = (InfoCurricularCourse) arg0;                        return infoExecutionDegree == null                                || infoCurricularCourse.getInfoDegreeCurricularPlan().equals(                                        infoExecutionDegree.getInfoDegreeCurricularPlan());                    }                });            }        });        Collections.sort((List) result, comparatorChain1);        // collect information for the jsp in a especific, proper data bean        List infoSiteCoursesInformation = (List) result;        HashMap statistics = new HashMap();        Integer numberOfCourses = new Integer(infoSiteCoursesInformation.size());        List infoCourses = new ArrayList();                Iterator infoSiteCoursesInformationIter = infoSiteCoursesInformation.iterator();        while (infoSiteCoursesInformationIter.hasNext()) {            InfoSiteCourseInformation infoSiteCourseInformation = (InfoSiteCourseInformation) infoSiteCoursesInformationIter                    .next();            // add info to statistics            Integer numberOfFields = infoSiteCourseInformation.getNumberOfFieldsFilled();			if (!statistics.containsKey(numberOfFields))				statistics.put(numberOfFields, new Integer(1));			else			{				int value = ((Integer) statistics.get(numberOfFields)).intValue();				value++;				statistics.put(numberOfFields, new Integer(value));			}            			InfoCourse infoCourse = new InfoCourse();			// iterate through the courses            Iterator infoCurricularCourseIterator = infoSiteCourseInformation.getInfoCurricularCourses()                    .iterator();            while (infoCurricularCourseIterator.hasNext()) {                InfoCurricularCourse infoCurricularCourse = (InfoCurricularCourse) infoCurricularCourseIterator                        .next();                // ignore this iteration if the curricular course doesn't refer to the execution degree's degree curricular plan                if (infoExecutionDegree != null && infoExecutionDegree.getInfoDegreeCurricularPlan().getIdInternal() != infoCurricularCourse.getInfoDegreeCurricularPlan().getIdInternal())                	continue;                                // set yearSemesterBranch field                List yearSemesterBranch = new ArrayList();                Iterator infoCurricularCourseScopeIterator = infoCurricularCourse.getInfoScopes()                        .iterator();                while (infoCurricularCourseScopeIterator.hasNext()) {                    InfoCurricularCourseScope infoCurricularCourseScope = (InfoCurricularCourseScope) infoCurricularCourseScopeIterator                            .next();                    String year = infoCurricularCourseScope.getInfoCurricularSemester().getInfoCurricularYear().getYear().toString();                    String semester = infoCurricularCourseScope.getInfoCurricularSemester().getSemester().toString();                    String branch = infoCurricularCourseScope.getInfoBranch().getAcronym();                    if(branch == null) branch = new String();                    String yearSemesterBranchElement = year + " " + semester  + " " + branch;                    yearSemesterBranch.add(yearSemesterBranchElement);                }                infoCourse.setYearSemesterBranch(yearSemesterBranch);                // set executionCourseID                infoCourse.setExecutionCourseID(infoSiteCourseInformation.getInfoExecutionCourse().getIdInternal());                                // set curricularCourseNameAndCode field                String curricularCourseNameAndCode = infoCurricularCourse.getName() + " - "                        + infoCurricularCourse.getCode();                infoCourse.setCurricularCourseNameAndCode(curricularCourseNameAndCode);                // set executionCourseCode                String executionCourseCode = infoSiteCourseInformation.getInfoExecutionCourse()                        .getSigla();                infoCourse.setExecutionCourseCode(executionCourseCode);                // set executionPeriod                infoCourse.setExecutionPeriod(infoSiteCourseInformation.getInfoExecutionCourse().getInfoExecutionPeriod().getName());                                // set basic field                infoCourse.setBasic(infoCurricularCourse.getBasic().booleanValue());                                // set degree curricular plan name                if(infoExecutionDegree == null)                    infoCourse.setDegreeCurricularPlanName(infoCurricularCourse.getInfoDegreeCurricularPlan().getName());                                // set teachers                List teachers = new ArrayList();                Iterator infoLecturingTeachersIter = infoSiteCourseInformation.getInfoLecturingTeachers()                        .iterator();                while (infoLecturingTeachersIter.hasNext()) {                    InfoTeacher infoTeacher = (InfoTeacher) infoLecturingTeachersIter.next();                                        InfoSimpleTeacher teacher = new InfoSimpleTeacher();                    teacher.setName(infoTeacher.getInfoPerson().getNome());                    teacher.setResponsible(infoSiteCourseInformation.getInfoResponsibleTeachers().contains(infoTeacher));                                        Object[] args = { infoTeacher };                    IUserView userView = SessionUtils.getUserView(request);                                        try {                        InfoDepartment infoDepartment = (InfoDepartment) ServiceUtils.executeService(userView, "ReadDepartmentByTeacher", args);                                                teacher.setDepartment(infoDepartment.getName());                    } catch (FenixServiceException fse) {                        teacher.setDepartment("Desconhecido");                    }                    teachers.add(teacher);                }                infoCourse.setTeachers(teachers);                                // set numberFieldsFilled                infoCourse.setNumberFieldsFilled(infoSiteCourseInformation.getNumberOfFieldsFilled());                // set lastModificationDate; mighty be null                Date lastModificationDate = infoSiteCourseInformation.getLastModificationDate();                if(lastModificationDate != null) infoCourse.setLastModificationDate(lastModificationDate.getTime());            }            infoCourses.add(infoCourse);        }        request.setAttribute("statistics", statistics);        request.setAttribute("numberOfCourses", numberOfCourses);        request.setAttribute("infoCourses", infoCourses);    }