DistributionTeacherServicesByCourseDTO returnDTO = new DistributionTeacherServicesByCourseDTO();  List<ICompetenceCourse> competenceCourseList;  List<IExecutionPeriod> executionPeriodList;  ITeacher teacher;  IDepartment department;   try {  ISuportePersistente sp = PersistenceSupportFactory.getDefaultPersistenceSupport();  IPersistentTeacher persistenceTeacher = sp.getIPersistentTeacher();  IPersistentExecutionPeriod persistentExecutionPeriod = sp.getIPersistentExecutionPeriod();  executionPeriodList = persistentExecutionPeriod.readByExecutionYear(executionYearID);  teacher = persistenceTeacher.readTeacherByUsername(username);  department = teacher.getCurrentWorkingDepartment();  competenceCourseList =  department.getCompetenceCourses();  } catch (ExcepcaoPersistencia e) {
DistributionTeacherServicesByCourseDTO returnDTO = new DistributionTeacherServicesByCourseDTO();  List<ICompetenceCourse> competenceCourseList;  List<IExecutionPeriod> executionPeriodList;  ITeacher teacher;  IDepartment department;  try {  ISuportePersistente sp = PersistenceSupportFactory.getDefaultPersistenceSupport();  IPersistentTeacher persistenceTeacher = sp.getIPersistentTeacher();  IPersistentExecutionPeriod persistentExecutionPeriod = sp.getIPersistentExecutionPeriod();  executionPeriodList = persistentExecutionPeriod.readByExecutionYear(executionYearID);  teacher = persistenceTeacher.readTeacherByUsername(username);  department = teacher.getLastWorkingDepartment();  competenceCourseList = department.getCompetenceCourses();  } catch (ExcepcaoPersistencia e) {
	public List run(String username, Integer executionYearID) throws FenixServiceException {				DistributionTeacherServicesByCourseDTO returnDTO = new DistributionTeacherServicesByCourseDTO();				List<ICompetenceCourse> competenceCourseList;				List<IExecutionPeriod> executionPeriodList;				ITeacher teacher;				IDepartment department;						try {						ISuportePersistente sp = PersistenceSupportFactory.getDefaultPersistenceSupport();						IPersistentTeacher persistenceTeacher = sp.getIPersistentTeacher();						IPersistentExecutionPeriod persistentExecutionPeriod = sp.getIPersistentExecutionPeriod();						executionPeriodList = persistentExecutionPeriod.readByExecutionYear(executionYearID);									teacher = persistenceTeacher.readTeacherByUsername(username);					department = teacher.getCurrentWorkingDepartment();						competenceCourseList =  department.getCompetenceCourses();					} catch (ExcepcaoPersistencia e) {            throw new FenixServiceException(e);        }											Map<Integer, Boolean> executionCoursesMap = new HashMap<Integer, Boolean>();						for(ICompetenceCourse cc:  competenceCourseList) {			for(ICurricularCourse curricularCourseEntry: cc.getAssociatedCurricularCourses()) {														for(IExecutionPeriod executionPeriodEntry: executionPeriodList) {										List<ICurricularCourseScope> scopesList = curricularCourseEntry.getActiveScopesInExecutionPeriod(executionPeriodEntry);					Set<String> curricularYearsList = new HashSet<String>();					for(ICurricularCourseScope scopeEntry : scopesList){						curricularYearsList.add(curricularCourseEntry.getCurricularYearByBranchAndSemester(scopeEntry.getBranch(), scopeEntry.getCurricularSemester().getSemester()).getYear().toString());					}										for(IExecutionCourse executionCourseEntry: (List<IExecutionCourse>) curricularCourseEntry.getExecutionCoursesByExecutionPeriod(executionPeriodEntry)) {												if(executionCoursesMap.containsKey(executionCourseEntry.getIdInternal())){							returnDTO.addDegreeNameToExecutionCourse(executionCourseEntry.getIdInternal(), curricularCourseEntry.getDegreeCurricularPlan().getName());							continue;						}												int executionCourseFirstTimeEnrollementStudentNumber = executionCourseEntry.getFirstTimeEnrolmentStudentNumber();						int executionCourseSecondTimeEnrollementStudentNumber = executionCourseEntry.getSecondOrMoreTimeEnrolmentStudentNumber();																																String campus = getCampusForCurricularCourseAndExecutionPeriod(curricularCourseEntry, executionPeriodEntry);												returnDTO.addExecutionCourse(executionCourseEntry.getIdInternal(), executionCourseEntry.getNome(), campus, 								curricularCourseEntry.getDegreeCurricularPlan().getDegree().getSigla(), curricularYearsList, 								executionCourseEntry.getExecutionPeriod().getSemester(), 								executionCourseFirstTimeEnrollementStudentNumber, executionCourseSecondTimeEnrollementStudentNumber, 								executionCourseEntry.getTotalHours(ShiftType.TEORICA), executionCourseEntry.getTotalHours(ShiftType.PRATICA), executionCourseEntry.getTotalHours(ShiftType.LABORATORIAL),								executionCourseEntry.getTotalHours(ShiftType.TEORICO_PRATICA), executionCourseEntry.getStudentsNumberByShift(ShiftType.TEORICA), executionCourseEntry.getStudentsNumberByShift(ShiftType.PRATICA),								executionCourseEntry.getStudentsNumberByShift(ShiftType.LABORATORIAL), executionCourseEntry.getStudentsNumberByShift(ShiftType.TEORICO_PRATICA));																											fillExecutionCourseDTOWithTeachers(returnDTO, executionCourseEntry, department);												executionCoursesMap.put(executionCourseEntry.getIdInternal(), true);											}				}			}		}		        				ArrayList<ExecutionCourseDistributionServiceEntryDTO> returnArraylist = new ArrayList<ExecutionCourseDistributionServiceEntryDTO>();				for(ExecutionCourseDistributionServiceEntryDTO teacherDTO: returnDTO.getExecutionCourseMap().values()) {			returnArraylist.add(teacherDTO);		}		Collections.sort(returnArraylist);				return returnArraylist;	}