Search in sources :

Example 11 with PreMatricula

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

the class ImportIndicacoesToPreMatricula method execute.

@Override
public void execute() {
    IndicacaoDAO indicacaoDAO = new HibernateIndicacaoDAO();
    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<PreMatricula> preMatriculas = preMatriculaDAO.findAll();
        for (PreMatricula preMatricula : preMatriculas) {
            Long turmaId = preMatricula.getTurma().getId();
            System.out.print(++i + " - ");
            if (preMatricula instanceof PreMatriculaAluno) {
                List<IndicacaoAluno> indicacoesAlunos = indicacoesAlunosMap.get(turmaId);
                if (indicacoesAlunos == null) {
                    indicacoesAlunos = indicacaoDAO.findAllAlunos(turmaId);
                    indicacoesAlunosMap.put(turmaId, indicacoesAlunos);
                }
                for (IndicacaoAluno indicacaoAluno : indicacoesAlunos) {
                    if (preMatricula.getPessoa().getId().equals(indicacaoAluno.getPessoa().getId())) {
                        preMatricula.setIndicacao(indicacaoAluno);
                        preMatriculaDAO.update(preMatricula);
                    }
                }
            } else {
                List<IndicacaoInstrutor> indicacoesInstrutores = indicacoesInstrutoresMap.get(turmaId);
                if (indicacoesInstrutores == null) {
                    indicacoesInstrutores = indicacaoDAO.findAllInstrutores(turmaId);
                    indicacoesInstrutoresMap.put(turmaId, indicacoesInstrutores);
                }
                for (IndicacaoInstrutor indicacaoInstrutor : indicacoesInstrutores) {
                    if (preMatricula.getPessoa().getId().equals(indicacaoInstrutor.getPessoa().getId())) {
                        preMatricula.setIndicacao(indicacaoInstrutor);
                        preMatriculaDAO.update(preMatricula);
                    }
                }
            }
            System.out.println("");
        }
        System.out.println(preMatriculas.size());
    } catch (DAOException ex) {
        Logger.getLogger(ImportIndicacoesToPreMatricula.class.getName()).log(Level.SEVERE, null, ex);
    }
}
Also used : HashMap(java.util.HashMap) HibernatePreMatriculaDAO(com.tomasio.projects.trainning.dao.HibernatePreMatriculaDAO) PreMatriculaAluno(com.tomasio.projects.trainning.model.PreMatriculaAluno) 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) PreMatricula(com.tomasio.projects.trainning.model.PreMatricula) 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

PreMatricula (com.tomasio.projects.trainning.model.PreMatricula)11 PreMatriculaDAO (com.tomasio.projects.trainning.dao.PreMatriculaDAO)10 DAOException (com.tomasio.projects.trainning.exception.DAOException)10 CoreException (com.tomasio.projects.trainning.exeption.CoreException)8 ParseException (java.text.ParseException)8 Transactional (org.springframework.transaction.annotation.Transactional)8 IndicacaoDAO (com.tomasio.projects.trainning.dao.IndicacaoDAO)4 PreMatriculaDTO (com.tomasio.projects.trainning.dto.PreMatriculaDTO)4 PreMatriculaAluno (com.tomasio.projects.trainning.model.PreMatriculaAluno)4 PreMatriculaAlunoDTO (com.tomasio.projects.trainning.dto.PreMatriculaAlunoDTO)3 PreMatriculaInstrutorDTO (com.tomasio.projects.trainning.dto.PreMatriculaInstrutorDTO)3 Indicacao (com.tomasio.projects.trainning.model.Indicacao)3 PreMatriculaInstrutor (com.tomasio.projects.trainning.model.PreMatriculaInstrutor)3 TurmaDAO (com.tomasio.projects.trainning.dao.TurmaDAO)2 StatusTurmaEfetiva (com.tomasio.projects.trainning.model.StatusTurmaEfetiva)2 TurmaEfetiva (com.tomasio.projects.trainning.model.TurmaEfetiva)2 HibernateIndicacaoDAO (com.tomasio.projects.trainning.dao.HibernateIndicacaoDAO)1 HibernatePreMatriculaDAO (com.tomasio.projects.trainning.dao.HibernatePreMatriculaDAO)1 IndicacaoAluno (com.tomasio.projects.trainning.model.IndicacaoAluno)1 IndicacaoInstrutor (com.tomasio.projects.trainning.model.IndicacaoInstrutor)1