package com.rjconsultores.ventaboletos.dao.hibernate; import java.util.ArrayList; import java.util.List; import org.hibernate.Criteria; import org.hibernate.SessionFactory; import org.hibernate.criterion.Projections; import org.hibernate.criterion.Restrictions; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Repository; import com.rjconsultores.ventaboletos.dao.UsuarioEmpresaDAO; import com.rjconsultores.ventaboletos.entidad.Empresa; import com.rjconsultores.ventaboletos.entidad.Usuario; import com.rjconsultores.ventaboletos.entidad.UsuarioEmpresa; @Repository("usuarioEmpresaDAO") public class UsuarioEmpresaHibernateDAO extends GenericHibernateDAO implements UsuarioEmpresaDAO { @Autowired public UsuarioEmpresaHibernateDAO(@Qualifier("sessionFactory") SessionFactory factory) { setSessionFactory(factory); } @Override public List obtenerTodos() { Criteria c = getSession().createCriteria(getPersistentClass()); c.add(Restrictions.eq("activo", Boolean.TRUE)); return c.list(); } public List obtenerPorUsuario(Usuario usuario) { Criteria c = getSession().createCriteria(getPersistentClass()); c.add(Restrictions.eq("activo", Boolean.TRUE)); c.add(Restrictions.eq("usuarioLog", usuario)); return c.list(); } public Boolean obtenerPorEmpresaUsuario(Empresa empresa, Usuario usuario) { Criteria c = getSession().createCriteria(getPersistentClass()); c.add(Restrictions.eq("activo", Boolean.TRUE)); c.add(Restrictions.eq("empresa", empresa)); c.add(Restrictions.eq("usuarioLog", usuario)); if(!c.list().isEmpty()){ return true; }else{ return false; } } public List obtenerEmpresa(Usuario usuario) { Criteria c = getSession().createCriteria(getPersistentClass()); c.add(Restrictions.eq("activo", Boolean.TRUE)); c.add(Restrictions.eq("usuarioLog", usuario)); List usuarioEmpresaList = c.list(); List empresaList = new ArrayList(); if(!usuarioEmpresaList.isEmpty()){ for(UsuarioEmpresa ue : usuarioEmpresaList){ empresaList.add(ue.getEmpresa()); } } return empresaList; } }