diff --git a/src/com/rjconsultores/ventaboletos/dao/EmpresaDAO.java b/src/com/rjconsultores/ventaboletos/dao/EmpresaDAO.java index 49de4c883..6748e5f92 100644 --- a/src/com/rjconsultores/ventaboletos/dao/EmpresaDAO.java +++ b/src/com/rjconsultores/ventaboletos/dao/EmpresaDAO.java @@ -15,7 +15,7 @@ import java.util.List; */ public interface EmpresaDAO extends GenericDAO { - public List buscarTodosExceto(Integer... idEmpresa); + public List buscarTodosExceto(List empresa,Integer... idEmpresa); public List obtenerIndExternoFalse(); diff --git a/src/com/rjconsultores/ventaboletos/dao/MarcaDAO.java b/src/com/rjconsultores/ventaboletos/dao/MarcaDAO.java index 7ecaaad3e..e922da92b 100644 --- a/src/com/rjconsultores/ventaboletos/dao/MarcaDAO.java +++ b/src/com/rjconsultores/ventaboletos/dao/MarcaDAO.java @@ -6,6 +6,7 @@ package com.rjconsultores.ventaboletos.dao; import java.util.List; +import com.rjconsultores.ventaboletos.entidad.Empresa; import com.rjconsultores.ventaboletos.entidad.Marca; import com.rjconsultores.ventaboletos.entidad.Usuario; @@ -21,6 +22,6 @@ public interface MarcaDAO extends GenericDAO { public List buscarDescricaoIdMarca(); - public List buscarMarcaPorEmpresa(Usuario usario); + public List buscarMarcaPorEmpresa(List empresa); } \ No newline at end of file diff --git a/src/com/rjconsultores/ventaboletos/dao/hibernate/EmpresaHibernateDAO.java b/src/com/rjconsultores/ventaboletos/dao/hibernate/EmpresaHibernateDAO.java index dc04265d8..4093da5a4 100644 --- a/src/com/rjconsultores/ventaboletos/dao/hibernate/EmpresaHibernateDAO.java +++ b/src/com/rjconsultores/ventaboletos/dao/hibernate/EmpresaHibernateDAO.java @@ -9,6 +9,7 @@ import com.rjconsultores.ventaboletos.entidad.Empresa; import com.rjconsultores.ventaboletos.entidad.Usuario; import com.rjconsultores.ventaboletos.service.UsuarioEmpresaService; +import java.util.ArrayList; import java.util.List; import org.hibernate.Criteria; import org.hibernate.SessionFactory; @@ -50,14 +51,15 @@ public class EmpresaHibernateDAO extends GenericHibernateDAO return c.list(); } - public List buscarTodosExceto(Integer... idEmpresa) { - Criteria c = this.makeCriteria(); + public List buscarTodosExceto(List empresa,Integer... idEmpresa) { + List empresaList = new ArrayList(); for (Integer id : idEmpresa) { - c.add(Restrictions.ne("empresaId", id)); + for(Empresa e : empresa){ + e.getEmpresaId().equals(id); + } } - c.add(Restrictions.eq("activo", Boolean.TRUE)); - c.addOrder(Order.asc("nombempresa")); - return c.list(); + + return empresaList; } diff --git a/src/com/rjconsultores/ventaboletos/dao/hibernate/MarcaHibernateDAO.java b/src/com/rjconsultores/ventaboletos/dao/hibernate/MarcaHibernateDAO.java index 21ba71a91..834a7fc44 100644 --- a/src/com/rjconsultores/ventaboletos/dao/hibernate/MarcaHibernateDAO.java +++ b/src/com/rjconsultores/ventaboletos/dao/hibernate/MarcaHibernateDAO.java @@ -4,6 +4,7 @@ */ package com.rjconsultores.ventaboletos.dao.hibernate; +import java.util.ArrayList; import java.util.List; import org.hibernate.Criteria; @@ -16,6 +17,7 @@ import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Repository; import com.rjconsultores.ventaboletos.dao.MarcaDAO; +import com.rjconsultores.ventaboletos.entidad.Empresa; import com.rjconsultores.ventaboletos.entidad.Marca; import com.rjconsultores.ventaboletos.entidad.Usuario; @@ -33,15 +35,15 @@ public class MarcaHibernateDAO extends GenericHibernateDAO setSessionFactory(factory); } -// @Override -// public List obtenerTodos() { -// Criteria c = getSession().createCriteria(getPersistentClass()); -// c.add(Restrictions.eq("activo", Boolean.TRUE)); -// c.addOrder(Order.asc("descmarca")); -// -// return c.list(); -// -// } + @Override + public List obtenerTodos() { + Criteria c = getSession().createCriteria(getPersistentClass()); + c.add(Restrictions.eq("activo", Boolean.TRUE)); + c.addOrder(Order.asc("descmarca")); + + return c.list(); + + } public List buscarPorNome(String nomeMarca) { Criteria c = getSession().createCriteria(getPersistentClass()); @@ -70,16 +72,15 @@ public class MarcaHibernateDAO extends GenericHibernateDAO return lsMarca; } + - @Override - public List buscarMarcaPorEmpresa(Usuario usario) { - String hql = " select new com.rjconsultores.ventaboletos.entidad.Marca(marca.marcaId, marca.descmarca) from com.rjconsultores.ventaboletos.entidad.Marca marca inner join marca.empresa empresa, UsuarioEmpresa ue where " + - " empresa.empresaId = ue.empresa.empresaId and marca.activo = 1 and ue.usuario.usuarioId =:usuarioId"; - - Query sq = getSession().createQuery(hql); - sq.setParameter("usuarioId", 225); - List lsMarca = sq.list(); - return lsMarca; + public List buscarMarcaPorEmpresa(List usuario) { + Criteria c = getSession().createCriteria(getPersistentClass()); + c.add(Restrictions.eq("activo", Boolean.TRUE)); + for (Empresa id : usuario) { + c.add(Restrictions.eq("empresa", id)); + } + return c.list(); } } diff --git a/src/com/rjconsultores/ventaboletos/dao/hibernate/UsuarioEmpresaHibernateDAO.java b/src/com/rjconsultores/ventaboletos/dao/hibernate/UsuarioEmpresaHibernateDAO.java index 2265e1f55..a36197ac5 100644 --- a/src/com/rjconsultores/ventaboletos/dao/hibernate/UsuarioEmpresaHibernateDAO.java +++ b/src/com/rjconsultores/ventaboletos/dao/hibernate/UsuarioEmpresaHibernateDAO.java @@ -37,7 +37,7 @@ public class UsuarioEmpresaHibernateDAO extends GenericHibernateDAO obtenerPorUsuario(Usuario usuario) { Criteria c = getSession().createCriteria(getPersistentClass()); c.add(Restrictions.eq("activo", Boolean.TRUE)); - c.add(Restrictions.eq("usuario", usuario)); + c.add(Restrictions.eq("usuarioLog", usuario)); return c.list(); } @@ -46,7 +46,7 @@ public class UsuarioEmpresaHibernateDAO extends GenericHibernateDAO obtenerEmpresa(Usuario usuario) { Criteria c = getSession().createCriteria(getPersistentClass()); c.add(Restrictions.eq("activo", Boolean.TRUE)); - c.add(Restrictions.eq("usuario", usuario)); + c.add(Restrictions.eq("usuarioLog", usuario)); List usuarioEmpresaList = c.list(); List empresaList = new ArrayList(); - for(UsuarioEmpresa ue : usuarioEmpresaList){ - empresaList.add(ue.getEmpresa()); + if(!usuarioEmpresaList.isEmpty()){ + for(UsuarioEmpresa ue : usuarioEmpresaList){ + empresaList.add(ue.getEmpresa()); + } } return empresaList; } diff --git a/src/com/rjconsultores/ventaboletos/entidad/Marca.java b/src/com/rjconsultores/ventaboletos/entidad/Marca.java index 2ca6ec343..818806373 100644 --- a/src/com/rjconsultores/ventaboletos/entidad/Marca.java +++ b/src/com/rjconsultores/ventaboletos/entidad/Marca.java @@ -93,6 +93,13 @@ public class Marca implements Serializable { this.marcaId = marcaId; this.descmarca = descMarca; } + + public Marca(Short marcaId, String descMarca, Integer usuarioId , Date fecmodif) { + this.marcaId = marcaId; + this.descmarca = descMarca; + this.usuarioId = usuarioId; + this.fecmodif = fecmodif; + } public Short getMarcaId() { return marcaId; diff --git a/src/com/rjconsultores/ventaboletos/entidad/Usuario.java b/src/com/rjconsultores/ventaboletos/entidad/Usuario.java index 963a4fea6..079a71dae 100644 --- a/src/com/rjconsultores/ventaboletos/entidad/Usuario.java +++ b/src/com/rjconsultores/ventaboletos/entidad/Usuario.java @@ -14,6 +14,7 @@ import javax.persistence.Basic; import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; +import javax.persistence.FetchType; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; @@ -65,11 +66,12 @@ public class Usuario implements Serializable, Authentication, UserDetails { private String descCorreo; @OneToMany(mappedBy = "usuario", cascade = CascadeType.ALL) private List usuarioPerfilList; + @OneToOne @JoinColumn(name = "EMPLEADO_ID") private Empleado empleado; - @OneToMany(mappedBy = "usuario", cascade = CascadeType.ALL) + @OneToMany(mappedBy = "usuarioLog", cascade = CascadeType.ALL,fetch=FetchType.EAGER) private List usuarioEmpresaList; public String getClaveUsuario() { @@ -181,6 +183,20 @@ public class Usuario implements Serializable, Authentication, UserDetails { return tmp; } + + + public List getEmpresa() { + List tmp = new ArrayList(); + if (usuarioEmpresaList != null) { + for (UsuarioEmpresa cp : this.usuarioEmpresaList) { + if ((cp.getActivo())) { + tmp.add(cp.getEmpresa()); + } + } + } + + return tmp; + } public void setUsuarioPerfilList(List usuarioPerfilList) { this.usuarioPerfilList = usuarioPerfilList; diff --git a/src/com/rjconsultores/ventaboletos/entidad/UsuarioEmpresa.java b/src/com/rjconsultores/ventaboletos/entidad/UsuarioEmpresa.java index 65484b4e3..f15e3e091 100644 --- a/src/com/rjconsultores/ventaboletos/entidad/UsuarioEmpresa.java +++ b/src/com/rjconsultores/ventaboletos/entidad/UsuarioEmpresa.java @@ -45,7 +45,8 @@ public class UsuarioEmpresa implements Serializable { @JoinColumn(name = "USUARIO_ID", referencedColumnName = "USUARIO_ID") @ManyToOne - private Usuario usuario; + private Usuario usuarioLog; + @JoinColumn(name = "EMPRESA_ID", referencedColumnName = "EMPRESA_ID") @ManyToOne private Empresa empresa; @@ -100,12 +101,12 @@ public class UsuarioEmpresa implements Serializable { } - public Usuario getUsuario() { - return usuario; + public Usuario getUsuarioLog() { + return usuarioLog; } - public void setUsuario(Usuario usuario) { - this.usuario = usuario; + public void setUsuarioLog(Usuario usuario) { + this.usuarioLog = usuario; } public void setEmpresa(Empresa empresa) { diff --git a/src/com/rjconsultores/ventaboletos/service/EmpresaService.java b/src/com/rjconsultores/ventaboletos/service/EmpresaService.java index 0652ee9a2..1ff989b47 100644 --- a/src/com/rjconsultores/ventaboletos/service/EmpresaService.java +++ b/src/com/rjconsultores/ventaboletos/service/EmpresaService.java @@ -17,7 +17,7 @@ public interface EmpresaService extends GenericService { public List buscar(String nombempresa, Boolean indExterna, Short indTipo); - public List buscarTodosExceto(Integer... idEmpresa); + public List buscarTodosExceto(List empresa,Integer... idEmpresa); public List obtenerIndExternoFalse(); diff --git a/src/com/rjconsultores/ventaboletos/service/MarcaService.java b/src/com/rjconsultores/ventaboletos/service/MarcaService.java index 9dad8a391..5d2b93e0e 100644 --- a/src/com/rjconsultores/ventaboletos/service/MarcaService.java +++ b/src/com/rjconsultores/ventaboletos/service/MarcaService.java @@ -4,6 +4,7 @@ */ package com.rjconsultores.ventaboletos.service; +import com.rjconsultores.ventaboletos.entidad.Empresa; import com.rjconsultores.ventaboletos.entidad.Marca; import com.rjconsultores.ventaboletos.entidad.Usuario; @@ -21,5 +22,5 @@ public interface MarcaService extends GenericService { public List buscarDescricaoIdMarca(); - public List buscarMarcaPorEmpresa(Usuario usario); + public List buscarMarcaPorEmpresa(List empresa); } \ No newline at end of file diff --git a/src/com/rjconsultores/ventaboletos/service/impl/EmpresaServiceImpl.java b/src/com/rjconsultores/ventaboletos/service/impl/EmpresaServiceImpl.java index f53101bf3..375dfb9a3 100644 --- a/src/com/rjconsultores/ventaboletos/service/impl/EmpresaServiceImpl.java +++ b/src/com/rjconsultores/ventaboletos/service/impl/EmpresaServiceImpl.java @@ -64,8 +64,8 @@ public class EmpresaServiceImpl implements EmpresaService { return empresaDAO.buscar(nombempresa, indExterna, indTipo); } - public List buscarTodosExceto(Integer... idEmpresa) { - return empresaDAO.buscarTodosExceto(idEmpresa); + public List buscarTodosExceto(List empresa,Integer... idEmpresa) { + return empresaDAO.buscarTodosExceto( empresa, idEmpresa); } public List obtenerIndExternoFalse() { diff --git a/src/com/rjconsultores/ventaboletos/service/impl/MarcaServiceImpl.java b/src/com/rjconsultores/ventaboletos/service/impl/MarcaServiceImpl.java index de8d78f34..0b5be27b0 100644 --- a/src/com/rjconsultores/ventaboletos/service/impl/MarcaServiceImpl.java +++ b/src/com/rjconsultores/ventaboletos/service/impl/MarcaServiceImpl.java @@ -5,6 +5,7 @@ package com.rjconsultores.ventaboletos.service.impl; import com.rjconsultores.ventaboletos.dao.MarcaDAO; +import com.rjconsultores.ventaboletos.entidad.Empresa; import com.rjconsultores.ventaboletos.entidad.Marca; import com.rjconsultores.ventaboletos.entidad.Usuario; import com.rjconsultores.ventaboletos.service.MarcaService; @@ -73,8 +74,8 @@ public class MarcaServiceImpl implements MarcaService { return marcaDAO.buscarDescricaoIdMarca(); } - - public List buscarMarcaPorEmpresa(Usuario usario) { - return marcaDAO.buscarMarcaPorEmpresa(usario); + + public List buscarMarcaPorEmpresa(List empresa){ + return marcaDAO.buscarMarcaPorEmpresa(empresa); } }