Search in sources :

Example 6 with MatriculaAluno

use of com.tomasio.projects.trainning.model.MatriculaAluno in project trainning by fernandotomasio.

the class ImportIndicacoesToMatricula method execute.

@Override
public void execute() {
    IndicacaoDAO indicacaoDAO = new HibernateIndicacaoDAO();
    MatriculaDAO matriculaDAO = new HibernateMatriculaDAO();
    PreMatriculaDAO preMatriculaDAO = new HibernatePreMatriculaDAO();
    Map<Long, List<IndicacaoAluno>> indicacoesAlunosMap = new HashMap<Long, List<IndicacaoAluno>>();
    Map<Long, List<IndicacaoInstrutor>> indicacoesInstrutoresMap = new HashMap<Long, List<IndicacaoInstrutor>>();
    int i = 0;
    try {
        List<Matricula> matriculas = matriculaDAO.findAll();
        for (Matricula matricula : matriculas) {
            Long turmaId = matricula.getTurma().getId();
            System.out.print(++i + " - ");
            if (matricula instanceof MatriculaAluno) {
                List<IndicacaoAluno> indicacoesAlunos = indicacoesAlunosMap.get(turmaId);
                if (indicacoesAlunos == null) {
                    indicacoesAlunos = indicacaoDAO.findAllAlunos(turmaId);
                    indicacoesAlunosMap.put(turmaId, indicacoesAlunos);
                }
                for (IndicacaoAluno indicacaoAluno : indicacoesAlunos) {
                    if (matricula.getPessoa().getId().equals(indicacaoAluno.getPessoa().getId())) {
                        matricula.setIndicacao(indicacaoAluno);
                        matriculaDAO.update(matricula);
                    }
                }
            } else {
                List<IndicacaoInstrutor> indicacoesInstrutores = indicacoesInstrutoresMap.get(turmaId);
                if (indicacoesInstrutores == null) {
                    indicacoesInstrutores = indicacaoDAO.findAllInstrutores(turmaId);
                    indicacoesInstrutoresMap.put(turmaId, indicacoesInstrutores);
                }
                for (IndicacaoInstrutor indicacaoInstrutor : indicacoesInstrutores) {
                    if (matricula.getPessoa().getId().equals(indicacaoInstrutor.getPessoa().getId())) {
                        matricula.setIndicacao(indicacaoInstrutor);
                        matriculaDAO.update(matricula);
                    }
                }
            }
            System.out.println("");
        }
        System.out.println(matriculas.size());
    } catch (DAOException ex) {
        Logger.getLogger(ImportIndicacoesToMatricula.class.getName()).log(Level.SEVERE, null, ex);
    }
}
Also used : HashMap(java.util.HashMap) Matricula(com.tomasio.projects.trainning.model.Matricula) HibernatePreMatriculaDAO(com.tomasio.projects.trainning.dao.HibernatePreMatriculaDAO) IndicacaoInstrutor(com.tomasio.projects.trainning.model.IndicacaoInstrutor) IndicacaoDAO(com.tomasio.projects.trainning.dao.IndicacaoDAO) HibernateIndicacaoDAO(com.tomasio.projects.trainning.dao.HibernateIndicacaoDAO) DAOException(com.tomasio.projects.trainning.exception.DAOException) IndicacaoAluno(com.tomasio.projects.trainning.model.IndicacaoAluno) MatriculaAluno(com.tomasio.projects.trainning.model.MatriculaAluno) HibernateMatriculaDAO(com.tomasio.projects.trainning.dao.HibernateMatriculaDAO) HibernateMatriculaDAO(com.tomasio.projects.trainning.dao.HibernateMatriculaDAO) MatriculaDAO(com.tomasio.projects.trainning.dao.MatriculaDAO) HibernatePreMatriculaDAO(com.tomasio.projects.trainning.dao.HibernatePreMatriculaDAO) PreMatriculaDAO(com.tomasio.projects.trainning.dao.PreMatriculaDAO) HibernateIndicacaoDAO(com.tomasio.projects.trainning.dao.HibernateIndicacaoDAO) List(java.util.List) HibernatePreMatriculaDAO(com.tomasio.projects.trainning.dao.HibernatePreMatriculaDAO) PreMatriculaDAO(com.tomasio.projects.trainning.dao.PreMatriculaDAO)

Aggregations

MatriculaDAO (com.tomasio.projects.trainning.dao.MatriculaDAO)6 DAOException (com.tomasio.projects.trainning.exception.DAOException)6 MatriculaAluno (com.tomasio.projects.trainning.model.MatriculaAluno)6 IndicacaoDAO (com.tomasio.projects.trainning.dao.IndicacaoDAO)5 Matricula (com.tomasio.projects.trainning.model.Matricula)5 PreMatriculaDAO (com.tomasio.projects.trainning.dao.PreMatriculaDAO)4 CancelamentoMatriculaDAO (com.tomasio.projects.trainning.dao.CancelamentoMatriculaDAO)3 HibernateIndicacaoDAO (com.tomasio.projects.trainning.dao.HibernateIndicacaoDAO)3 HibernateMatriculaDAO (com.tomasio.projects.trainning.dao.HibernateMatriculaDAO)3 NotificacaoMatriculaDAO (com.tomasio.projects.trainning.dao.NotificacaoMatriculaDAO)3 MatriculaAlunoDTO (com.tomasio.projects.trainning.dto.MatriculaAlunoDTO)3 MatriculaInstrutorDTO (com.tomasio.projects.trainning.dto.MatriculaInstrutorDTO)3 PreMatriculaAlunoDTO (com.tomasio.projects.trainning.dto.PreMatriculaAlunoDTO)3 PreMatriculaInstrutorDTO (com.tomasio.projects.trainning.dto.PreMatriculaInstrutorDTO)3 CoreException (com.tomasio.projects.trainning.exeption.CoreException)3 CancelamentoMatricula (com.tomasio.projects.trainning.model.CancelamentoMatricula)3 MatriculaInstrutor (com.tomasio.projects.trainning.model.MatriculaInstrutor)3 NotificacaoMatricula (com.tomasio.projects.trainning.model.NotificacaoMatricula)3 PreMatricula (com.tomasio.projects.trainning.model.PreMatricula)3 PreMatriculaAluno (com.tomasio.projects.trainning.model.PreMatriculaAluno)3