Search in sources :

Example 1 with PreMatriculaAluno

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

the class AtividadesEnsinoServiceSimpleImpl method createPreMatricula.

@Override
@Transactional
public void createPreMatricula(PreMatriculaDTO[] preMatriculas) {
    PreMatriculaDAO preMatriculaDAO = factory.getPreMatriculaDAO();
    IndicacaoDAO indicacaoDAO = factory.getIndicacaoDAO();
    List<PreMatricula> preMatriculasList = new ArrayList<PreMatricula>();
    List<Indicacao> indicacoesList = new ArrayList<Indicacao>();
    for (PreMatriculaDTO preMatriculaDTO : preMatriculas) {
        PreMatricula _preMatricula = null;
        if (preMatriculaDTO instanceof PreMatriculaAlunoDTO) {
            _preMatricula = new PreMatriculaAluno((PreMatriculaAlunoDTO) preMatriculaDTO);
        } else {
            _preMatricula = new PreMatriculaInstrutor((PreMatriculaInstrutorDTO) preMatriculaDTO);
        }
        preMatriculasList.add(_preMatricula);
        indicacoesList.add(_preMatricula.getIndicacao());
    }
    try {
        preMatriculaDAO.create(preMatriculasList);
        for (Indicacao indicacao : indicacoesList) {
            indicacao.setPreMatriculado(true);
            indicacaoDAO.update(indicacao);
        }
    } catch (DAOException ex) {
        ex.printStackTrace();
        throw new CoreException(ex.getMessage());
    } catch (Exception ex) {
        ex.printStackTrace();
        throw new CoreException("Erro em tempo de execução: " + ex.getMessage());
    }
}
Also used : ArrayList(java.util.ArrayList) Indicacao(com.tomasio.projects.trainning.model.Indicacao) PreMatriculaAluno(com.tomasio.projects.trainning.model.PreMatriculaAluno) PreMatriculaDTO(com.tomasio.projects.trainning.dto.PreMatriculaDTO) PreMatriculaAlunoDTO(com.tomasio.projects.trainning.dto.PreMatriculaAlunoDTO) DAOException(com.tomasio.projects.trainning.exception.DAOException) ParseException(java.text.ParseException) CoreException(com.tomasio.projects.trainning.exeption.CoreException) IndicacaoDAO(com.tomasio.projects.trainning.dao.IndicacaoDAO) DAOException(com.tomasio.projects.trainning.exception.DAOException) CoreException(com.tomasio.projects.trainning.exeption.CoreException) PreMatricula(com.tomasio.projects.trainning.model.PreMatricula) PreMatriculaInstrutor(com.tomasio.projects.trainning.model.PreMatriculaInstrutor) PreMatriculaInstrutorDTO(com.tomasio.projects.trainning.dto.PreMatriculaInstrutorDTO) PreMatriculaDAO(com.tomasio.projects.trainning.dao.PreMatriculaDAO) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with PreMatriculaAluno

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

the class AtividadesEnsinoServiceSimpleImpl method createPreMatricula.

@Override
@Transactional
public Long createPreMatricula(PreMatriculaDTO preMatricula) {
    PreMatriculaDAO preMatriculaDAO = factory.getPreMatriculaDAO();
    IndicacaoDAO indicacaoDAO = factory.getIndicacaoDAO();
    TurmaDAO turmaDAO = factory.getTurmaDAO();
    PreMatricula _preMatricula = null;
    if (preMatricula instanceof PreMatriculaAlunoDTO) {
        _preMatricula = new PreMatriculaAluno((PreMatriculaAlunoDTO) preMatricula);
    } else {
        _preMatricula = new PreMatriculaInstrutor((PreMatriculaInstrutorDTO) preMatricula);
    }
    Long id = null;
    try {
        Indicacao _indicacao = _preMatricula.getIndicacao();
        TurmaEfetiva _turma = _preMatricula.getTurma();
        id = preMatriculaDAO.create(_preMatricula);
        _indicacao.setPreMatriculado(true);
        _turma.setPreAtivado(true);
        indicacaoDAO.update(_indicacao);
        turmaDAO.update(_turma);
    } catch (DAOException ex) {
        ex.printStackTrace();
        throw new CoreException(ex.getMessage());
    } catch (Exception ex) {
        ex.printStackTrace();
        throw new CoreException("Erro em tempo de execução: " + ex.getMessage());
    }
    return id;
}
Also used : StatusTurmaEfetiva(com.tomasio.projects.trainning.model.StatusTurmaEfetiva) TurmaEfetiva(com.tomasio.projects.trainning.model.TurmaEfetiva) Indicacao(com.tomasio.projects.trainning.model.Indicacao) PreMatriculaAluno(com.tomasio.projects.trainning.model.PreMatriculaAluno) PreMatriculaAlunoDTO(com.tomasio.projects.trainning.dto.PreMatriculaAlunoDTO) DAOException(com.tomasio.projects.trainning.exception.DAOException) ParseException(java.text.ParseException) CoreException(com.tomasio.projects.trainning.exeption.CoreException) IndicacaoDAO(com.tomasio.projects.trainning.dao.IndicacaoDAO) DAOException(com.tomasio.projects.trainning.exception.DAOException) CoreException(com.tomasio.projects.trainning.exeption.CoreException) PreMatricula(com.tomasio.projects.trainning.model.PreMatricula) PreMatriculaInstrutor(com.tomasio.projects.trainning.model.PreMatriculaInstrutor) PreMatriculaInstrutorDTO(com.tomasio.projects.trainning.dto.PreMatriculaInstrutorDTO) TurmaDAO(com.tomasio.projects.trainning.dao.TurmaDAO) PreMatriculaDAO(com.tomasio.projects.trainning.dao.PreMatriculaDAO) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with PreMatriculaAluno

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

the class AtividadesEnsinoServiceSimpleImpl method updatePreMatricula.

@Override
@Transactional
public void updatePreMatricula(PreMatriculaDTO preMatricula) {
    PreMatriculaDAO dao = factory.getPreMatriculaDAO();
    PreMatricula _preMatricula = null;
    if (preMatricula instanceof PreMatriculaAlunoDTO) {
        _preMatricula = new PreMatriculaAluno((PreMatriculaAlunoDTO) preMatricula);
    } else {
        _preMatricula = new PreMatriculaInstrutor((PreMatriculaInstrutorDTO) preMatricula);
    }
    try {
        dao.update(_preMatricula);
    } catch (DAOException ex) {
        ex.printStackTrace();
        throw new CoreException(ex.getMessage());
    } catch (Exception ex) {
        ex.printStackTrace();
        throw new CoreException("Erro em tempo de execução: " + ex.getMessage());
    }
}
Also used : DAOException(com.tomasio.projects.trainning.exception.DAOException) CoreException(com.tomasio.projects.trainning.exeption.CoreException) PreMatricula(com.tomasio.projects.trainning.model.PreMatricula) PreMatriculaInstrutor(com.tomasio.projects.trainning.model.PreMatriculaInstrutor) PreMatriculaAluno(com.tomasio.projects.trainning.model.PreMatriculaAluno) PreMatriculaInstrutorDTO(com.tomasio.projects.trainning.dto.PreMatriculaInstrutorDTO) PreMatriculaAlunoDTO(com.tomasio.projects.trainning.dto.PreMatriculaAlunoDTO) DAOException(com.tomasio.projects.trainning.exception.DAOException) ParseException(java.text.ParseException) CoreException(com.tomasio.projects.trainning.exeption.CoreException) PreMatriculaDAO(com.tomasio.projects.trainning.dao.PreMatriculaDAO) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with PreMatriculaAluno

use of com.tomasio.projects.trainning.model.PreMatriculaAluno 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

PreMatriculaDAO (com.tomasio.projects.trainning.dao.PreMatriculaDAO)4 DAOException (com.tomasio.projects.trainning.exception.DAOException)4 PreMatricula (com.tomasio.projects.trainning.model.PreMatricula)4 PreMatriculaAluno (com.tomasio.projects.trainning.model.PreMatriculaAluno)4 IndicacaoDAO (com.tomasio.projects.trainning.dao.IndicacaoDAO)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 PreMatriculaInstrutor (com.tomasio.projects.trainning.model.PreMatriculaInstrutor)3 ParseException (java.text.ParseException)3 Transactional (org.springframework.transaction.annotation.Transactional)3 Indicacao (com.tomasio.projects.trainning.model.Indicacao)2 HibernateIndicacaoDAO (com.tomasio.projects.trainning.dao.HibernateIndicacaoDAO)1 HibernatePreMatriculaDAO (com.tomasio.projects.trainning.dao.HibernatePreMatriculaDAO)1 TurmaDAO (com.tomasio.projects.trainning.dao.TurmaDAO)1 PreMatriculaDTO (com.tomasio.projects.trainning.dto.PreMatriculaDTO)1 IndicacaoAluno (com.tomasio.projects.trainning.model.IndicacaoAluno)1 IndicacaoInstrutor (com.tomasio.projects.trainning.model.IndicacaoInstrutor)1 StatusTurmaEfetiva (com.tomasio.projects.trainning.model.StatusTurmaEfetiva)1 TurmaEfetiva (com.tomasio.projects.trainning.model.TurmaEfetiva)1