Search in sources :

Example 1 with Desligamento

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

the class AtividadesEnsinoServiceSimpleImpl method removeDesligamento.

@Override
@Transactional
public void removeDesligamento(Long matriculaId) {
    DesligamentoDAO desligamentoDAO = factory.getDesligamentoDAO();
    MatriculaDAO matriculaDAO = factory.getMatriculaDAO();
    IndicacaoDAO indicacaoDAO = factory.getIndicacaoDAO();
    TurmaDAO turmaDAO = factory.getTurmaDAO();
    try {
        // remover um registro na tabela CancelamentoMatricula
        Desligamento d = (Desligamento) desligamentoDAO.findDesligamentoByMatricula(matriculaId);
        Matricula matricula = matriculaDAO.find(d.getMatricula().getId());
        Indicacao indicacao = matricula.getIndicacao();
        TurmaEfetiva turma = matricula.getTurma();
        if (d != null) {
            desligamentoDAO.remove(d.getId());
            indicacao.setMatriculado(true);
            turma.setAtivado(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(ex.getMessage());
    }
}
Also used : IndicacaoDAO(com.tomasio.projects.trainning.dao.IndicacaoDAO) DAOException(com.tomasio.projects.trainning.exception.DAOException) Desligamento(com.tomasio.projects.trainning.model.Desligamento) StatusTurmaEfetiva(com.tomasio.projects.trainning.model.StatusTurmaEfetiva) TurmaEfetiva(com.tomasio.projects.trainning.model.TurmaEfetiva) CoreException(com.tomasio.projects.trainning.exeption.CoreException) DesligamentoDAO(com.tomasio.projects.trainning.dao.DesligamentoDAO) CancelamentoMatriculaDAO(com.tomasio.projects.trainning.dao.CancelamentoMatriculaDAO) MatriculaDAO(com.tomasio.projects.trainning.dao.MatriculaDAO) NotificacaoMatriculaDAO(com.tomasio.projects.trainning.dao.NotificacaoMatriculaDAO) PreMatriculaDAO(com.tomasio.projects.trainning.dao.PreMatriculaDAO) CancelamentoMatricula(com.tomasio.projects.trainning.model.CancelamentoMatricula) Matricula(com.tomasio.projects.trainning.model.Matricula) NotificacaoMatricula(com.tomasio.projects.trainning.model.NotificacaoMatricula) PreMatricula(com.tomasio.projects.trainning.model.PreMatricula) Indicacao(com.tomasio.projects.trainning.model.Indicacao) TurmaDAO(com.tomasio.projects.trainning.dao.TurmaDAO) DAOException(com.tomasio.projects.trainning.exception.DAOException) ParseException(java.text.ParseException) CoreException(com.tomasio.projects.trainning.exeption.CoreException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with Desligamento

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

the class AtividadesEnsinoServiceSimpleImpl method createDesligamento.

@Override
@Transactional
public Long createDesligamento(DesligamentoDTO desligamento) {
    DesligamentoDAO desligamentoDAO = factory.getDesligamentoDAO();
    IndicacaoDAO indicacaoDAO = factory.getIndicacaoDAO();
    MatriculaDAO matriculaDAO = factory.getMatriculaDAO();
    TurmaDAO turmaDAO = factory.getTurmaDAO();
    Long id = null;
    Desligamento _desligamento = null;
    // cria um registro na tabela CancelamentoMatricula
    if (desligamento != null) {
        _desligamento = new Desligamento(desligamento);
    }
    try {
        Matricula matricula = matriculaDAO.find(_desligamento.getMatricula().getId());
        Indicacao indicacao = matricula.getIndicacao();
        TurmaEfetiva turma = matricula.getTurma();
        id = desligamentoDAO.create(_desligamento);
        indicacao.setMatriculado(false);
        indicacaoDAO.update(indicacao);
        if (hasMatriculas(turma.getId())) {
            turma.setAtivado(true);
        } else {
            turma.setAtivado(false);
        }
        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());
        throw new CoreException(ex.getMessage());
    }
    return id;
}
Also used : IndicacaoDAO(com.tomasio.projects.trainning.dao.IndicacaoDAO) DAOException(com.tomasio.projects.trainning.exception.DAOException) Desligamento(com.tomasio.projects.trainning.model.Desligamento) StatusTurmaEfetiva(com.tomasio.projects.trainning.model.StatusTurmaEfetiva) TurmaEfetiva(com.tomasio.projects.trainning.model.TurmaEfetiva) CoreException(com.tomasio.projects.trainning.exeption.CoreException) DesligamentoDAO(com.tomasio.projects.trainning.dao.DesligamentoDAO) CancelamentoMatriculaDAO(com.tomasio.projects.trainning.dao.CancelamentoMatriculaDAO) MatriculaDAO(com.tomasio.projects.trainning.dao.MatriculaDAO) NotificacaoMatriculaDAO(com.tomasio.projects.trainning.dao.NotificacaoMatriculaDAO) PreMatriculaDAO(com.tomasio.projects.trainning.dao.PreMatriculaDAO) CancelamentoMatricula(com.tomasio.projects.trainning.model.CancelamentoMatricula) Matricula(com.tomasio.projects.trainning.model.Matricula) NotificacaoMatricula(com.tomasio.projects.trainning.model.NotificacaoMatricula) PreMatricula(com.tomasio.projects.trainning.model.PreMatricula) Indicacao(com.tomasio.projects.trainning.model.Indicacao) TurmaDAO(com.tomasio.projects.trainning.dao.TurmaDAO) DAOException(com.tomasio.projects.trainning.exception.DAOException) ParseException(java.text.ParseException) CoreException(com.tomasio.projects.trainning.exeption.CoreException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with Desligamento

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

the class HibernateDesligamentoDAO method remove.

@Override
public void remove(Long desligamentoId) throws DAOException {
    Session session = sessionFactory.getCurrentSession();
    Desligamento desligamento = (Desligamento) session.get(Desligamento.class, desligamentoId);
    try {
        session.delete(desligamento);
    } catch (HibernateException e) {
        Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, e);
        throw new DAOException(MessageHelper.getMessage("desligamento.remove.error"));
    }
}
Also used : DAOException(com.tomasio.projects.trainning.exception.DAOException) Desligamento(com.tomasio.projects.trainning.model.Desligamento) HibernateException(org.hibernate.HibernateException) Session(org.hibernate.Session)

Example 4 with Desligamento

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

the class HibernateDesligamentoDAO method create.

@Override
public void create(List<Desligamento> cancelamentosMatriculas) throws DAOException {
    Session session = sessionFactory.getCurrentSession();
    try {
        for (Desligamento desligamento : cancelamentosMatriculas) {
            Long countDesligamentosMatricula = (Long) session.createQuery("select count(*) from Desligamento c where c.matricula.id = :matriculaId").setLong("matriculaId", desligamento.getMatricula().getId()).uniqueResult();
            if (countDesligamentosMatricula > 0) {
                throw new DAOException("Desligamento já existente");
            }
            session.save(desligamento);
        }
    } catch (HibernateException e) {
        Logger.getLogger(HibernateMatriculaDAO.class.getName()).log(Level.SEVERE, null, e);
        throw new DAOException(MessageHelper.getMessage("desligamento.create.list.error"));
    }
}
Also used : DAOException(com.tomasio.projects.trainning.exception.DAOException) Desligamento(com.tomasio.projects.trainning.model.Desligamento) HibernateException(org.hibernate.HibernateException) Session(org.hibernate.Session)

Aggregations

DAOException (com.tomasio.projects.trainning.exception.DAOException)4 Desligamento (com.tomasio.projects.trainning.model.Desligamento)4 CancelamentoMatriculaDAO (com.tomasio.projects.trainning.dao.CancelamentoMatriculaDAO)2 DesligamentoDAO (com.tomasio.projects.trainning.dao.DesligamentoDAO)2 IndicacaoDAO (com.tomasio.projects.trainning.dao.IndicacaoDAO)2 MatriculaDAO (com.tomasio.projects.trainning.dao.MatriculaDAO)2 NotificacaoMatriculaDAO (com.tomasio.projects.trainning.dao.NotificacaoMatriculaDAO)2 PreMatriculaDAO (com.tomasio.projects.trainning.dao.PreMatriculaDAO)2 TurmaDAO (com.tomasio.projects.trainning.dao.TurmaDAO)2 CoreException (com.tomasio.projects.trainning.exeption.CoreException)2 CancelamentoMatricula (com.tomasio.projects.trainning.model.CancelamentoMatricula)2 Indicacao (com.tomasio.projects.trainning.model.Indicacao)2 Matricula (com.tomasio.projects.trainning.model.Matricula)2 NotificacaoMatricula (com.tomasio.projects.trainning.model.NotificacaoMatricula)2 PreMatricula (com.tomasio.projects.trainning.model.PreMatricula)2 StatusTurmaEfetiva (com.tomasio.projects.trainning.model.StatusTurmaEfetiva)2 TurmaEfetiva (com.tomasio.projects.trainning.model.TurmaEfetiva)2 ParseException (java.text.ParseException)2 HibernateException (org.hibernate.HibernateException)2 Session (org.hibernate.Session)2