Search in sources :

Example 1 with TurmaEfetivaSort

use of com.tomasio.projects.trainning.sort.TurmaEfetivaSort in project trainning by fernandotomasio.

the class HibernateTurmaDAO method findAllTurmasEfetivasNotCancelOfResponsavelOrResponsavelConclusao.

@SuppressWarnings("unchecked")
@Override
public List<TurmaEfetiva> findAllTurmasEfetivasNotCancelOfResponsavelOrResponsavelConclusao(Date exercicio, Long organizacaoId) throws DAOException {
    Session session = sessionFactory.getCurrentSession();
    SimpleDateFormat df = new SimpleDateFormat("yyyy");
    try {
        exercicio = df.parse(df.format(exercicio));
    } catch (ParseException ex) {
        Logger.getLogger(HibernateTurmaDAO.class.getName()).log(Level.SEVERE, null, ex);
    }
    try {
        // selecionar todas turmas da organizacao no ano
        List<TurmaEfetiva> turmas = session.createQuery("from TurmaEfetiva t " + "where t.exercicio = :exercicio " + "and (t.responsavelId = :organizacaoId1 or t.responsavelConclusaoId = :organizacaoId2)" + "and t.cancelado = false").setLong("organizacaoId1", organizacaoId).setLong("organizacaoId2", organizacaoId).setDate("exercicio", exercicio).list();
        Collections.sort(turmas, new TurmaEfetivaSort());
        return turmas;
    } catch (HibernateException e) {
        Logger.getLogger(HibernateTurmaDAO.class.getName()).log(Level.SEVERE, null, e);
        throw new DAOException(MessageHelper.getMessage("turmas.find.list.error"));
    }
}
Also used : DAOException(com.tomasio.projects.trainning.exception.DAOException) StatusTurmaEfetiva(com.tomasio.projects.trainning.model.StatusTurmaEfetiva) TurmaEfetiva(com.tomasio.projects.trainning.model.TurmaEfetiva) TurmaEfetivaSort(com.tomasio.projects.trainning.sort.TurmaEfetivaSort) HibernateException(org.hibernate.HibernateException) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) Session(org.hibernate.Session)

Example 2 with TurmaEfetivaSort

use of com.tomasio.projects.trainning.sort.TurmaEfetivaSort in project trainning by fernandotomasio.

the class HibernateTurmaDAO method findAllTurmasEfetivasWithIndicacoesPendentes.

@Override
public List<TurmaEfetiva> findAllTurmasEfetivasWithIndicacoesPendentes(Date exercicio, Long organizacaoId) throws DAOException {
    Session session = sessionFactory.getCurrentSession();
    SimpleDateFormat df = new SimpleDateFormat("yyyy");
    try {
        exercicio = df.parse(df.format(exercicio));
    } catch (ParseException ex) {
        Logger.getLogger(HibernateTurmaDAO.class.getName()).log(Level.SEVERE, null, ex);
    }
    try {
        @SuppressWarnings("unchecked") List<TurmaEfetiva> turmas = session.createQuery("select distinct indicacao.turma from IndicacaoAluno indicacao " + "where indicacao.turma.exercicio >= :exercicio " + "and indicacao.nextWorkflowActor.id = :organizacaoId " + "and indicacao.turma.cancelado = false " + "and indicacao.matriculado = false " + "and indicacao.preMatriculado = false " + "and indicacao.turma.ativado = false " + "and indicacao.turma.preAtivado = false").setLong("organizacaoId", organizacaoId).setDate("exercicio", exercicio).list();
        // APÓS A COLOCAÇÃO DO CAMPO ATIVADO EM TURMA, OTMIZAR ESTA QUERY ADICIONANDO 'and indicacao.t.ativado = false and indicacao.t.preAtivado=false'
        // List<TurmaEfetiva> turmas = session.createQuery(
        // "select distinct t from TurmaEfetiva t join t.indicacoes i "
        // + "where t.exercicio >= :exercicio and i.organizacao.id in (:organizacoesIds) "
        // + "and t.id not in (select distinct t2.id from TurmaEfetiva t2 join t2.matriculas where t2.id=t.id) "
        // + "and t.cancelado = false "
        // + "and t.id not in (select distinct t3.id from TurmaEfetiva t3 join t3.preMatriculas where t3.id=t.id)")
        // .setParameterList("organizacoesIds", organizacoesIds)
        // .setDate("exercicio", exercicio)
        // .list();
        Collections.sort(turmas, new TurmaEfetivaSort());
        return turmas;
    } catch (HibernateException e) {
        Logger.getLogger(HibernateTurmaDAO.class.getName()).log(Level.SEVERE, null, e);
        throw new DAOException(MessageHelper.getMessage("turmas.find.list.error"));
    }
}
Also used : DAOException(com.tomasio.projects.trainning.exception.DAOException) StatusTurmaEfetiva(com.tomasio.projects.trainning.model.StatusTurmaEfetiva) TurmaEfetiva(com.tomasio.projects.trainning.model.TurmaEfetiva) TurmaEfetivaSort(com.tomasio.projects.trainning.sort.TurmaEfetivaSort) HibernateException(org.hibernate.HibernateException) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) Session(org.hibernate.Session)

Example 3 with TurmaEfetivaSort

use of com.tomasio.projects.trainning.sort.TurmaEfetivaSort in project trainning by fernandotomasio.

the class HibernateTurmaDAO method findAllTurmasEfetivasNotCancel.

@Override
public List<TurmaEfetiva> findAllTurmasEfetivasNotCancel(Date exercicio, Long organizacaoId) throws DAOException {
    Session session = sessionFactory.getCurrentSession();
    SimpleDateFormat df = new SimpleDateFormat("yyyy");
    try {
        exercicio = df.parse(df.format(exercicio));
    } catch (ParseException ex) {
        Logger.getLogger(HibernateTurmaDAO.class.getName()).log(Level.SEVERE, null, ex);
    }
    try {
        // selecionar todas turmas da organizacao no ano
        @SuppressWarnings("unchecked") List<TurmaEfetiva> turmas = session.createQuery("from TurmaEfetiva t " + "where t.exercicio = :exercicio " + "and t.responsavelId = :organizacaoId " + "and t.cancelado = false").setLong("organizacaoId", organizacaoId).setDate("exercicio", exercicio).list();
        Collections.sort(turmas, new TurmaEfetivaSort());
        return turmas;
    } catch (HibernateException e) {
        Logger.getLogger(HibernateTurmaDAO.class.getName()).log(Level.SEVERE, null, e);
        throw new DAOException(MessageHelper.getMessage("turmas.find.list.error"));
    }
}
Also used : DAOException(com.tomasio.projects.trainning.exception.DAOException) StatusTurmaEfetiva(com.tomasio.projects.trainning.model.StatusTurmaEfetiva) TurmaEfetiva(com.tomasio.projects.trainning.model.TurmaEfetiva) TurmaEfetivaSort(com.tomasio.projects.trainning.sort.TurmaEfetivaSort) HibernateException(org.hibernate.HibernateException) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) Session(org.hibernate.Session)

Example 4 with TurmaEfetivaSort

use of com.tomasio.projects.trainning.sort.TurmaEfetivaSort in project trainning by fernandotomasio.

the class HibernateTurmaDAO method findAllTurmasEfetivas.

private List<TurmaEfetiva> findAllTurmasEfetivas(Map<Object, Object> params) throws DAOException {
    Date exercicio = (Date) params.get("exercicio");
    Long cursoId = (Long) params.get("cursoId");
    Long responsavelId = (Long) params.get("responsavelId");
    Long organizacaoGestoraId = (Long) params.get("organizacaoGestoraId");
    Long planoId = (Long) params.get("planoId");
    String searchTerm = (String) params.get("searchTerm");
    params.get("status");
    Integer pageNumber = (Integer) params.get("pageNumber");
    Integer pageSize = (Integer) params.get("pageSize");
    SimpleDateFormat dfYear = new SimpleDateFormat("yyyy");
    Session session = sessionFactory.getCurrentSession();
    if (exercicio != null) {
        try {
            exercicio = dfYear.parse(dfYear.format(exercicio));
        } catch (ParseException ex) {
            Logger.getLogger(HibernateTurmaDAO.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    try {
        Criteria criteria = session.createCriteria(TurmaEfetiva.class);
        criteria.createAlias("curso", "c");
        if (exercicio != null) {
            criteria.add(Restrictions.eq("exercicio", exercicio));
        }
        if (cursoId != null && cursoId > 0L) {
            criteria.add(Restrictions.eq("c.id", cursoId));
        }
        if (responsavelId != null && responsavelId > 0L) {
            criteria.add(Restrictions.eq("responsavelId", responsavelId));
        }
        if (organizacaoGestoraId != null && organizacaoGestoraId > 0L) {
            criteria.add(Restrictions.eq("organizacaoGestoraId", organizacaoGestoraId));
        }
        if (planoId != null && planoId > 0L) {
            criteria.createAlias("c.plano", "plano");
            criteria.add(Restrictions.eq("plano.id", planoId));
        }
        if (searchTerm != null) {
            Disjunction or = Restrictions.disjunction();
            or.add(Restrictions.ilike("c.codigo", "%" + searchTerm + "%")).add(Restrictions.ilike("c.descricao", "%" + searchTerm + "%"));
            criteria.add(or);
        }
        criteria.addOrder(Order.asc("c.codigo"));
        criteria.addOrder(Order.asc("numeroTurma"));
        if (pageNumber != null && pageSize != null) {
            criteria.setFirstResult(pageNumber);
            criteria.setMaxResults(pageSize);
        }
        @SuppressWarnings("unchecked") List<TurmaEfetiva> turmas = criteria.list();
        for (TurmaEfetiva turmaEfetiva : turmas) {
            fillTurmaEfetiva(session, turmaEfetiva);
        }
        // for (TurmaEfetiva turma : turmas) {
        // System.out.println( turma.getId() + " - " + turma.getOrganizacaoGestoraId() + "- " +turma.getDataInicio() + " - "+ turma.getDataTermino());
        // }
        Collections.sort(turmas, new TurmaEfetivaSort());
        return turmas;
    } catch (HibernateException e) {
        Logger.getLogger(HibernateTurmaDAO.class.getName()).log(Level.SEVERE, null, e);
        throw new DAOException(MessageHelper.getMessage("turmas.find.list.error"));
    }
}
Also used : StatusTurmaEfetiva(com.tomasio.projects.trainning.model.StatusTurmaEfetiva) TurmaEfetiva(com.tomasio.projects.trainning.model.TurmaEfetiva) TurmaEfetivaSort(com.tomasio.projects.trainning.sort.TurmaEfetivaSort) HibernateException(org.hibernate.HibernateException) Criteria(org.hibernate.Criteria) Date(java.util.Date) DAOException(com.tomasio.projects.trainning.exception.DAOException) Disjunction(org.hibernate.criterion.Disjunction) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) Session(org.hibernate.Session)

Example 5 with TurmaEfetivaSort

use of com.tomasio.projects.trainning.sort.TurmaEfetivaSort in project trainning by fernandotomasio.

the class HibernateTurmaDAO method findAllTurmasEfetivasWithIndicacoesPendentes.

@Override
public List<TurmaEfetiva> findAllTurmasEfetivasWithIndicacoesPendentes(Date exercicio, List<Long> organizacoesIds) throws DAOException {
    Session session = sessionFactory.getCurrentSession();
    SimpleDateFormat df = new SimpleDateFormat("yyyy");
    try {
        exercicio = df.parse(df.format(exercicio));
    } catch (ParseException ex) {
        Logger.getLogger(HibernateTurmaDAO.class.getName()).log(Level.SEVERE, null, ex);
    }
    try {
        @SuppressWarnings("unchecked") List<TurmaEfetiva> turmas2 = session.createQuery("select distinct indicacao.turma from IndicacaoAluno indicacao " + "where indicacao.turma.exercicio >= :exercicio " + "and indicacao.organizacao.id in :organizacoesIds " + "and indicacao.turma.cancelado = false " + "and indicacao.matriculado = false " + "and indicacao.preMatriculado = false " + "and indicacao.turma.ativado = false " + "and indicacao.turma.preAtivado = false").setParameterList("organizacoesIds", organizacoesIds).setDate("exercicio", exercicio).list();
        ;
        // APÓS A COLOCAÇÃO DO CAMPO ATIVADO EM TURMA, OTMIZAR ESTA QUERY ADICIONANDO 'and indicacao.t.ativado = false and indicacao.t.preAtivado=false'
        // List<TurmaEfetiva> turmas = session.createQuery(
        // "select distinct t from TurmaEfetiva t join t.indicacoes i "
        // + "where t.exercicio >= :exercicio and i.organizacao.id in (:organizacoesIds) "
        // + "and t.id not in (select distinct t2.id from TurmaEfetiva t2 join t2.matriculas where t2.id=t.id) "
        // + "and t.cancelado = false "
        // + "and t.id not in (select distinct t3.id from TurmaEfetiva t3 join t3.preMatriculas where t3.id=t.id)")
        // .setParameterList("organizacoesIds", organizacoesIds)
        // .setDate("exercicio", exercicio)
        // .list();
        Collections.sort(turmas2, new TurmaEfetivaSort());
        return turmas2;
    } catch (HibernateException e) {
        Logger.getLogger(HibernateTurmaDAO.class.getName()).log(Level.SEVERE, null, e);
        throw new DAOException(MessageHelper.getMessage("turmas.find.list.error"));
    }
}
Also used : DAOException(com.tomasio.projects.trainning.exception.DAOException) StatusTurmaEfetiva(com.tomasio.projects.trainning.model.StatusTurmaEfetiva) TurmaEfetiva(com.tomasio.projects.trainning.model.TurmaEfetiva) TurmaEfetivaSort(com.tomasio.projects.trainning.sort.TurmaEfetivaSort) HibernateException(org.hibernate.HibernateException) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) Session(org.hibernate.Session)

Aggregations

DAOException (com.tomasio.projects.trainning.exception.DAOException)6 StatusTurmaEfetiva (com.tomasio.projects.trainning.model.StatusTurmaEfetiva)6 TurmaEfetiva (com.tomasio.projects.trainning.model.TurmaEfetiva)6 TurmaEfetivaSort (com.tomasio.projects.trainning.sort.TurmaEfetivaSort)6 ParseException (java.text.ParseException)6 SimpleDateFormat (java.text.SimpleDateFormat)6 HibernateException (org.hibernate.HibernateException)6 Session (org.hibernate.Session)6 Date (java.util.Date)1 Criteria (org.hibernate.Criteria)1 Disjunction (org.hibernate.criterion.Disjunction)1