Search in sources :

Example 6 with IndicacaoAluno

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

the class AtividadesEnsinoServiceSimpleImpl method createIndicacao.

@Override
@Transactional
public Long createIndicacao(IndicacaoDTO indicacao) {
    IndicacaoDAO dao = factory.getIndicacaoDAO();
    OrganizacaoDAO organizacaoDAO = factory.getOrganizacaoDAO();
    TurmaDAO turmaDAO = factory.getTurmaDAO();
    Indicacao _indicacao = null;
    if (indicacao != null) {
        if (indicacao instanceof IndicacaoAlunoDTO) {
            _indicacao = new IndicacaoAluno((IndicacaoAlunoDTO) indicacao);
        } else {
            _indicacao = new IndicacaoInstrutor((IndicacaoInstrutorDTO) indicacao);
        }
    }
    Long id = null;
    try {
        id = dao.create(_indicacao);
        updateWorkflowActors(_indicacao.getId());
    } catch (DAOException ex) {
        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 : IndicacaoDAO(com.tomasio.projects.trainning.dao.IndicacaoDAO) IndicacaoAlunoDTO(com.tomasio.projects.trainning.dto.IndicacaoAlunoDTO) DAOException(com.tomasio.projects.trainning.exception.DAOException) OrganizacaoDAO(com.tomasio.projects.trainning.dao.OrganizacaoDAO) IndicacaoAluno(com.tomasio.projects.trainning.model.IndicacaoAluno) CoreException(com.tomasio.projects.trainning.exeption.CoreException) Indicacao(com.tomasio.projects.trainning.model.Indicacao) IndicacaoInstrutor(com.tomasio.projects.trainning.model.IndicacaoInstrutor) TurmaDAO(com.tomasio.projects.trainning.dao.TurmaDAO) IndicacaoInstrutorDTO(com.tomasio.projects.trainning.dto.IndicacaoInstrutorDTO) 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 7 with IndicacaoAluno

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

the class AtividadesEnsinoServiceSimpleImpl method alertaDeIndicacao.

@Override
@Transactional(readOnly = true)
public void alertaDeIndicacao(IndicacaoDTO indicacao, String chamada) {
    IndicacaoDAO dao = factory.getIndicacaoDAO();
    Indicacao _indicacao = null;
    if (indicacao != null) {
        // if (indicacao instanceof IndicacaoAlunoDTO) {
        _indicacao = new IndicacaoAluno((IndicacaoAlunoDTO) indicacao);
    // } else {
    // _indicacao = new IndicacaoInstrutor((IndicacaoInstrutorDTO) indicacao);
    // }
    }
    try {
        dao.alertaDeIndicacao(_indicacao, chamada);
    } catch (DAOException ex) {
        throw new CoreException(ex.getMessage());
    } catch (Exception ex) {
        ex.printStackTrace();
        throw new CoreException("Erro em tempo de execução: " + ex.getMessage());
    }
}
Also used : IndicacaoDAO(com.tomasio.projects.trainning.dao.IndicacaoDAO) IndicacaoAlunoDTO(com.tomasio.projects.trainning.dto.IndicacaoAlunoDTO) DAOException(com.tomasio.projects.trainning.exception.DAOException) IndicacaoAluno(com.tomasio.projects.trainning.model.IndicacaoAluno) CoreException(com.tomasio.projects.trainning.exeption.CoreException) Indicacao(com.tomasio.projects.trainning.model.Indicacao) 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 8 with IndicacaoAluno

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

the class AtividadesEnsinoServiceSimpleImpl method findAllIndicacoesAlunos.

@Override
@Transactional(readOnly = true)
public IndicacaoAlunoDTO[] findAllIndicacoesAlunos() {
    IndicacaoDAO dao = factory.getIndicacaoDAO();
    IndicacaoAlunoDTO[] indicacoesArray = null;
    try {
        List<IndicacaoAluno> indicacoes = dao.findAllAlunos();
        if (indicacoes != null) {
            indicacoesArray = new IndicacaoAlunoDTO[indicacoes.size()];
            for (int i = 0; i < indicacoes.size(); i++) {
                indicacoesArray[i] = indicacoes.get(i).createDTOWithoutDependencies();
            }
        }
    } 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 indicacoesArray;
}
Also used : IndicacaoDAO(com.tomasio.projects.trainning.dao.IndicacaoDAO) IndicacaoAlunoDTO(com.tomasio.projects.trainning.dto.IndicacaoAlunoDTO) DAOException(com.tomasio.projects.trainning.exception.DAOException) IndicacaoAluno(com.tomasio.projects.trainning.model.IndicacaoAluno) CoreException(com.tomasio.projects.trainning.exeption.CoreException) 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 9 with IndicacaoAluno

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

the class HibernateIndicacaoDAO method update.

@Override
public void update(Indicacao indicacao) throws DAOException {
    Session session = sessionFactory.getCurrentSession();
    if (indicacao instanceof IndicacaoAluno) {
        // teste: se já tem indicao com a mesma prioridade
        // não permitir e avisar ao usuário
        // COMENTADO PARA CORREÇÃO
        Long countIndicacao = 0L;
        // Long countIndicacao = (Long) session.createQuery(""
        // + "select count(*) from IndicacaoAluno i "
        // + "where i.turma.id = :turmaId "
        // + "and i.prioridade = :prioridade "
        // + "and i.organizacao.id=:organizacaoId "
        // + "and i.id != :indicacaoId")
        // .setLong("indicacaoId", indicacao.getId())
        // .setLong("turmaId", indicacao.getTurma().getId())
        // .setLong("prioridade", indicacao.getPrioridade())
        // .setLong("organizacaoId", indicacao.getOrganizacao().getId())
        // .uniqueResult();
        // if (countIndicacao > 0) {
        // throw new DAOException("Prioridade já utilizada em outra indicação desta Organização");
        // }
        // teste: se já indicado para esta turma do curso
        // não permitir e avisar ao usuário
        countIndicacao = (Long) session.createQuery("" + "select count(*) from IndicacaoAluno i " + "where i.pessoa.id = :pessoaId " + "and i.turma.id = :turmaId " + "and i.id <> :indicacaoId").setLong("indicacaoId", indicacao.getId()).setLong("pessoaId", indicacao.getPessoa().getId()).setLong("turmaId", indicacao.getTurma().getId()).uniqueResult();
        if (countIndicacao > 0) {
            throw new DAOException("Indicação já existente");
        }
    }
    try {
        session.update(indicacao);
    } catch (HibernateException e) {
        Logger.getLogger(HibernateIndicacaoDAO.class.getName()).log(Level.SEVERE, null, e);
        throw new DAOException(MessageHelper.getMessage("indicacoes.update.error"));
    }
}
Also used : DAOException(com.tomasio.projects.trainning.exception.DAOException) IndicacaoAluno(com.tomasio.projects.trainning.model.IndicacaoAluno) HibernateException(org.hibernate.HibernateException) Session(org.hibernate.Session)

Example 10 with IndicacaoAluno

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

the class HibernateIndicacaoDAO method findAllAlunos.

@SuppressWarnings("unchecked")
@Override
public List<IndicacaoAluno> findAllAlunos(Long turmaId, Long organizacaoId, Long pessoaId, Date exercicio) throws DAOException {
    Session session = sessionFactory.getCurrentSession();
    try {
        Criteria criteria = session.createCriteria(IndicacaoAluno.class);
        criteria.createAlias("turma", "t");
        if (turmaId != null) {
            criteria = criteria.add(Restrictions.eq("turma.id", turmaId));
        }
        if (organizacaoId != null) {
            criteria = criteria.add(Restrictions.eq("organizacao.id", organizacaoId));
        }
        if (pessoaId != null) {
            criteria = criteria.add(Restrictions.eq("pessoa.id", pessoaId));
        }
        if (exercicio != null) {
            SimpleDateFormat df = new SimpleDateFormat("yyyy");
            try {
                exercicio = df.parse(df.format(exercicio));
            } catch (ParseException ex) {
                Logger.getLogger(HibernateIndicacaoDAO.class.getName()).log(Level.SEVERE, null, ex);
            }
            criteria = criteria.add(Restrictions.eq("t.exercicio", exercicio));
        }
        List<IndicacaoAluno> indicacoes = criteria.list();
        for (Indicacao indicacao : indicacoes) {
            indicacao = proccessIndicacao(indicacao, session);
        }
        return indicacoes;
    } catch (HibernateException e) {
        Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, e);
        throw new DAOException(MessageHelper.getMessage("indicacoes.find.list.error"));
    }
}
Also used : DAOException(com.tomasio.projects.trainning.exception.DAOException) IndicacaoAluno(com.tomasio.projects.trainning.model.IndicacaoAluno) HibernateException(org.hibernate.HibernateException) Indicacao(com.tomasio.projects.trainning.model.Indicacao) Criteria(org.hibernate.Criteria) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) Session(org.hibernate.Session)

Aggregations

IndicacaoAluno (com.tomasio.projects.trainning.model.IndicacaoAluno)22 DAOException (com.tomasio.projects.trainning.exception.DAOException)20 IndicacaoDAO (com.tomasio.projects.trainning.dao.IndicacaoDAO)15 ParseException (java.text.ParseException)14 IndicacaoAlunoDTO (com.tomasio.projects.trainning.dto.IndicacaoAlunoDTO)12 Transactional (org.springframework.transaction.annotation.Transactional)12 CoreException (com.tomasio.projects.trainning.exeption.CoreException)11 Session (org.hibernate.Session)6 Indicacao (com.tomasio.projects.trainning.model.Indicacao)5 IndicacaoInstrutor (com.tomasio.projects.trainning.model.IndicacaoInstrutor)4 HashMap (java.util.HashMap)4 HibernateException (org.hibernate.HibernateException)4 HibernateIndicacaoDAO (com.tomasio.projects.trainning.dao.HibernateIndicacaoDAO)3 TurmaEfetiva (com.tomasio.projects.trainning.model.TurmaEfetiva)3 SimpleDateFormat (java.text.SimpleDateFormat)3 Date (java.util.Date)3 List (java.util.List)3 HibernateMatriculaDAO (com.tomasio.projects.trainning.dao.HibernateMatriculaDAO)2 HibernatePreMatriculaDAO (com.tomasio.projects.trainning.dao.HibernatePreMatriculaDAO)2 MatriculaDAO (com.tomasio.projects.trainning.dao.MatriculaDAO)2