Search in sources :

Example 1 with Curso

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

the class TrainningServiceSimpleImpl method searchCurso.

@Override
@Transactional(readOnly = true)
public CursoDTO[] searchCurso(String searchTerm, Long planoId, Long areaId, Boolean ativo, Boolean permiteEstrangeiro) {
    CursoDAO dao = factory.getCursoDAO();
    CursoDTO[] cursosArray = null;
    try {
        List<Curso> cursos = dao.search(searchTerm, planoId, areaId, ativo, permiteEstrangeiro);
        if (cursos != null) {
            cursosArray = new CursoDTO[cursos.size()];
            for (int i = 0; i < cursos.size(); i++) {
                cursosArray[i] = cursos.get(i).createDTOWithoutDependencies();
            }
        }
    } catch (DAOException ex) {
        throw new CoreException("Erro de de acesso ao banco de dados: " + ex.getMessage());
    }
    return cursosArray;
}
Also used : DAOException(com.tomasio.projects.trainning.exception.DAOException) CoreException(com.tomasio.projects.trainning.exeption.CoreException) CursoDTO(com.tomasio.projects.trainning.dto.CursoDTO) Curso(com.tomasio.projects.trainning.model.Curso) CursoDAO(com.tomasio.projects.trainning.dao.CursoDAO) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with Curso

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

the class TrainningServiceSimpleImpl method findCursoByCodigo.

@Override
@Transactional(readOnly = true)
public CursoDTO findCursoByCodigo(String codigo) {
    CursoDAO dao = factory.getCursoDAO();
    Curso curso = null;
    try {
        curso = dao.findByCodigo(codigo);
    } catch (DAOException ex) {
        throw new CoreException("Erro de de acesso ao banco de dados: " + ex.getMessage());
    }
    if (curso != null) {
        return curso.createDTO();
    } else {
        return null;
    }
}
Also used : DAOException(com.tomasio.projects.trainning.exception.DAOException) CoreException(com.tomasio.projects.trainning.exeption.CoreException) Curso(com.tomasio.projects.trainning.model.Curso) CursoDAO(com.tomasio.projects.trainning.dao.CursoDAO) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with Curso

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

the class TrainningServiceSimpleImpl method findCurso.

@Override
@Transactional(readOnly = true)
public CursoDTO findCurso(Long id) {
    CursoDAO dao = factory.getCursoDAO();
    Curso curso = null;
    try {
        curso = dao.find(id);
    } catch (DAOException ex) {
        throw new CoreException("Erro de de acesso ao banco de dados: " + ex.getMessage());
    }
    if (curso != null) {
        return curso.createDTO();
    } else {
        return null;
    }
}
Also used : DAOException(com.tomasio.projects.trainning.exception.DAOException) CoreException(com.tomasio.projects.trainning.exeption.CoreException) Curso(com.tomasio.projects.trainning.model.Curso) CursoDAO(com.tomasio.projects.trainning.dao.CursoDAO) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with Curso

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

the class TrainningServiceSimpleImpl method findAllCursos.

@Override
@Transactional(readOnly = true)
public CursoDTO[] findAllCursos(Long planoId, Long areaId, Boolean ativo, Boolean permiteEstrangeiro) {
    CursoDAO dao = factory.getCursoDAO();
    CursoDTO[] cursosArray = null;
    try {
        List<Curso> cursos = dao.findAll(planoId, areaId, ativo, permiteEstrangeiro);
        if (cursos != null) {
            cursosArray = new CursoDTO[cursos.size()];
            for (int i = 0; i < cursos.size(); i++) {
                cursosArray[i] = cursos.get(i).createDTOWithoutDependencies();
            }
        }
    } catch (DAOException ex) {
        throw new CoreException("Erro de de acesso ao banco de dados: " + ex.getMessage());
    }
    return cursosArray;
}
Also used : DAOException(com.tomasio.projects.trainning.exception.DAOException) CoreException(com.tomasio.projects.trainning.exeption.CoreException) CursoDTO(com.tomasio.projects.trainning.dto.CursoDTO) Curso(com.tomasio.projects.trainning.model.Curso) CursoDAO(com.tomasio.projects.trainning.dao.CursoDAO) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with Curso

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

the class HibernateCursoDAO method remove.

@Override
public void remove(Long id) throws DAOException {
    Session session = getSession();
    Long countTreinamentosSolicitados = (Long) session.createQuery("select count(*) from ItemPlanejamento treinamento " + "where treinamento.curso.id=:cursoId").setLong("cursoId", id).uniqueResult();
    Long countTurmas = (Long) session.createQuery("select count(*) from Turma turma where turma.curso.id=:cursoId").setLong("cursoId", id).uniqueResult();
    Long countConclusoes = (Long) session.createQuery("select count(*) from Conclusao c where c.capacitacao.id=:cursoId").setLong("cursoId", id).uniqueResult();
    Long countItens = (Long) session.createQuery("select count(*) from ItemPlanejamento item where item.curso.id=:cursoId").setLong("cursoId", id).uniqueResult();
    if (countTreinamentosSolicitados > 0) {
        throw new DAOException(MessageHelper.getMessage("cursos.remove.error.treinamentos"));
    }
    if (countTurmas > 0) {
        throw new DAOException(MessageHelper.getMessage("cursos.remove.error.turmas"));
    }
    if (countItens > 0) {
        throw new DAOException(MessageHelper.getMessage("cursos.remove.error.itensplanejamento"));
    }
    if (countConclusoes > 0) {
        throw new DAOException(MessageHelper.getMessage("cursos.remove.error.conclusao"));
    }
    try {
        Curso curso = (Curso) session.get(Curso.class, id);
        session.delete(curso);
    } catch (HibernateException e) {
        Logger.getLogger(HibernateCursoDAO.class.getName()).log(Level.SEVERE, null, e);
        throw new DAOException(MessageHelper.getMessage("cursos.remove.error"));
    }
}
Also used : DAOException(com.tomasio.projects.trainning.exception.DAOException) Curso(com.tomasio.projects.trainning.model.Curso)

Aggregations

Curso (com.tomasio.projects.trainning.model.Curso)20 DAOException (com.tomasio.projects.trainning.exception.DAOException)18 CursoDAO (com.tomasio.projects.trainning.dao.CursoDAO)12 CoreException (com.tomasio.projects.trainning.exeption.CoreException)7 Transactional (org.springframework.transaction.annotation.Transactional)7 HibernateCursoDAO (com.tomasio.projects.trainning.dao.HibernateCursoDAO)4 Organizacao (com.tomasio.projects.trainning.model.Organizacao)4 CursoDTO (com.tomasio.projects.trainning.dto.CursoDTO)3 ItemPlanejamento (com.tomasio.projects.trainning.model.ItemPlanejamento)3 Planejamento (com.tomasio.projects.trainning.model.Planejamento)3 DAOFactory (com.tomasio.projects.trainning.dao.DAOFactory)2 HibernateOrganizacaoDAO (com.tomasio.projects.trainning.dao.HibernateOrganizacaoDAO)2 OrganizacaoDAO (com.tomasio.projects.trainning.dao.OrganizacaoDAO)2 PlanejamentoDAO (com.tomasio.projects.trainning.dao.PlanejamentoDAO)2 Fase (com.tomasio.projects.trainning.model.Fase)2 Periodo (com.tomasio.projects.trainning.model.Periodo)2 TurmaEfetiva (com.tomasio.projects.trainning.model.TurmaEfetiva)2 SimpleDateFormat (java.text.SimpleDateFormat)2 HashSet (java.util.HashSet)2 Session (org.hibernate.Session)2