.readBySiglaAndAnoLectivAndSiglaLicenciatura(
.readBySiglaAndAnoLectivoAndSiglaLicenciatura(
	public static void main(String[] args) {		try {			new LoadCourseEnrolments();		} catch (IOException e) {			e.printStackTrace(System.out);			System.out.println("Erro a carregar as propriedades");		}		try {			SuportePersistenteOJB sp = SuportePersistenteOJB.getInstance();			// Obter interfaces de acesso ao suporte persistente.			IPersistentStudent iAlunoPersistente = sp.getIPersistentStudent();			IPersistentCurricularCourse iDisciplinaCurricularPersistente =				sp.getIPersistentCurricularCourse();			IDisciplinaExecucaoPersistente iDisciplinaExecucaoPersistente =				sp.getIDisciplinaExecucaoPersistente();			IPersistentEnrolment persistentEnrolment =				sp.getIInscricaoPersistente();			IStudentCurricularPlanPersistente studentCurricularPlanPersistente =				sp.getIStudentCurricularPlanPersistente();			IFrequentaPersistente frequentaPersistente =				sp.getIFrequentaPersistente();			ITurnoAlunoPersistente shiftStudentDAO =				sp.getITurnoAlunoPersistente();			// Ler o ficheiro de entrada.			BufferedReader bufferedReader =				new BufferedReader(new FileReader(getDataFilePath()));			String line = bufferedReader.readLine();			while (line != null) {				carregarInscricao(line);				line = bufferedReader.readLine();			}			sp.iniciarTransaccao();			// Percorrer a lista que vem da secretaria.			// Vamos inscrever todos os alunos.			listaInscricoesFinal = new ArrayList();			System.out.println(				"Vai percorrer a lista vinda da secretaria size = "					+ listaInscricoes.size());			for (int i = 0; i < listaInscricoes.size(); i++) {				System.out.println("1");				// Para cada inscricao na secretaria				AlunoDisciplinaCurricular alunoDisciplinaCurricular =					(AlunoDisciplinaCurricular) listaInscricoes.get(i);				System.out.println("2");				// Ler o aluno				IStudent studentCriteria = new Student();				studentCriteria.setNumber(					alunoDisciplinaCurricular.getNumeroAluno());				studentCriteria.setDegreeType(					new TipoCurso(TipoCurso.LICENCIATURA));				IStudent student =					(IStudent) iAlunoPersistente.readDomainObjectByCriteria(						studentCriteria);				System.out.println("student = " + student.getNumber());				System.out.println("3");				// Ler o plano curricular do aluno				IStudentCurricularPlan studentCurricularPlanCriteria =					new StudentCurricularPlan();				studentCurricularPlanCriteria.setStudent(studentCriteria);				studentCurricularPlanCriteria.setCurrentState(					new StudentCurricularPlanState(						StudentCurricularPlanState.ACTIVE));				IStudentCurricularPlan studentCurricularPlan =					(						IStudentCurricularPlan) studentCurricularPlanPersistente							.readDomainObjectByCriteria(						studentCurricularPlanCriteria);				System.out.println("4");				// Ler a disciplina em que o aluno se est a inscreveer				ICurricularCourse curricularCourseCriteria =					new CurricularCourse();				//curricularCourseCriteria.setName(alunoDisciplinaCurricular.getNomeDisciplinaCurricular());				curricularCourseCriteria.setCode(					alunoDisciplinaCurricular.getSiglaDisciplinaCurricular());				ICurricularCourse curricularCourse =					(						ICurricularCourse) iDisciplinaCurricularPersistente							.readDomainObjectByCriteria(						curricularCourseCriteria);				System.out.println(					"disciplinaCurricular nome esperado = "						+ curricularCourseCriteria.getName());				System.out.println(					"disciplinaCurricular sigla esperada = "						+ curricularCourseCriteria.getCode());				System.out.println(					"disciplinaCurricular = " + curricularCourse.getName());				System.out.println("5");				// Ver se a inscricao do aluno na disciplina est na base de dados do CIAPL				IEnrolment enrolmentCriteria = new Enrolment();				enrolmentCriteria.setCurricularCourse(curricularCourseCriteria);				enrolmentCriteria.setStudentCurricularPlan(					studentCurricularPlanCriteria);				IEnrolment enrolment =					(						IEnrolment) persistentEnrolment							.readDomainObjectByCriteria(						enrolmentCriteria);				System.out.println("enrolment == null? " + (enrolment == null));				System.out.println("6");				if (enrolment == null) {					System.out.println("7");					// A inscricao nao esta na base de dados do CIAPL					// Adicionar a inscricao do aluno a base de dados CIAPL					enrolment = new Enrolment();					enrolment.setCurricularCourse(curricularCourse);					enrolment.setStudentCurricularPlan(studentCurricularPlan);					persistentEnrolment.lockWrite(enrolment);					// Ver se existe o frequenta					IFrequenta frequentaCriteria = new Frequenta();					frequentaCriteria.setAluno(studentCriteria);					IDisciplinaExecucao disciplinaExecucaoCriteria =						new DisciplinaExecucao();					disciplinaExecucaoCriteria.setNome(						alunoDisciplinaCurricular							.getNomeDisciplinaCurricular());					frequentaCriteria.setDisciplinaExecucao(						disciplinaExecucaoCriteria);					IFrequenta frequenta =						(							IFrequenta) frequentaPersistente								.readDomainObjectByCriteria(							frequentaCriteria);					// Se o frequenta ainda nao esta na base de dados					if (frequenta == null) {						//Adicionar o frequenta equivalente a inscricao						IDisciplinaExecucao disciplinaExecucao =							(								IDisciplinaExecucao) iDisciplinaExecucaoPersistente									.readDomainObjectByCriteria(								disciplinaExecucaoCriteria);						if (disciplinaExecucao != null) {							frequenta.setDisciplinaExecucao(disciplinaExecucao);							frequenta.setAluno(student);							frequentaPersistente.lockWrite(frequenta);						} else {							System.out.println(								"Nao foi encontrado a disciplina execucao equivalente da disciplina curricular: "									+ alunoDisciplinaCurricular										.getNomeDisciplinaCurricular());						}					}				} else {					System.out.println("8");					// A inscricao ja esta na base de dados do CIAPL					// Nao se faz nada				}				System.out.println("9");				// Construcao da lista de inscricoes com objectos do dominio				listaInscricoesFinal.add(enrolment);			} // for listaInscricoes secretaria			sp.confirmarTransaccao();			sp.iniciarTransaccao();			// Ler a lista de inscricoes da base de dados CIAPL			IEnrolment enrolmentCriteria = new Enrolment();			List listEnrolmentsCiapl =				(List) persistentEnrolment.readByCriteria(enrolmentCriteria);			sp.confirmarTransaccao();			sp.iniciarTransaccao();			// Percorrer a lista			System.out.println(				"Vai percorrer a lista vinda da base	de dados");			for (int j = 0; j < listEnrolmentsCiapl.size(); j++) {				// Para cada inscricao				IEnrolment enrolment = (IEnrolment) listEnrolmentsCiapl.get(j);				if (!listaInscricoesFinal.contains(enrolment)) {					// Se a inscricao nao estiver na lista final e preciso remove-la da base de dados.					// Ler o Frequenta equivalente  inscricao					IFrequenta attendCriteria = new Frequenta();					ICurricularCourse curricularCourse =						enrolment.getCurricularCourse();					IDisciplinaExecucao executionCourse =						iDisciplinaExecucaoPersistente							.readBySiglaAndAnoLectivAndSiglaLicenciatura(							curricularCourse.getCode(),							"2002/2003",							curricularCourse								.getDegreeCurricularPlan()								.getCurso()								.getSigla());					if (executionCourse != null) {						attendCriteria.setAluno(							enrolment.getStudentCurricularPlan().getStudent());						attendCriteria.setDisciplinaExecucao(executionCourse);						IFrequenta persistentAttend =							(								IFrequenta) frequentaPersistente									.readDomainObjectByCriteria(								attendCriteria);						// Ler os TurnoAlunos associados ao frequenta						ITurnoAluno shiftStudentCriteria = new TurnoAluno();						ITurno shiftCriteria = new Turno();						shiftCriteria.setDisciplinaExecucao(executionCourse);						shiftStudentCriteria.setAluno(							enrolment.getStudentCurricularPlan().getStudent());						shiftStudentCriteria.setTurno(shiftCriteria);						// Apagar os TurnoAlunos equivalentes						shiftStudentDAO.deleteByCriteria(shiftStudentCriteria);						// Apagar o Frequenta equivalente						frequentaPersistente.delete(persistentAttend);						// Apagar a Inscricao						persistentEnrolment.delete(enrolment);					} else {						System.out.println(							"A disciplina "								+ curricularCourse.getCode()								+ "-"								+ curricularCourse.getName()								+ " na licenciatura "								+ curricularCourse									.getDegreeCurricularPlan()									.getCurso()									.getSigla()								+ " no tem execuo!");					}				}			}			sp.confirmarTransaccao();		} catch (Exception e) {			System.out.println(				"ATENCAO: LoadCourseEnrolments: " + e.toString());			try {				SuportePersistenteOJB.getInstance().cancelarTransaccao();			} catch (Exception x) {				System.out.println(					"ATENCAO: LoadCourseEnrolments: cancelarTransacccao: "						+ e.toString());			}		}	}