From 400c964c7c538e704d86b9b832a145c5cc3ee54b Mon Sep 17 00:00:00 2001 From: leonardo Date: Fri, 2 May 2014 16:41:42 +0000 Subject: [PATCH] =?UTF-8?q?B23=20-=20N=C3=A3o=20permitir=20excluir=20uma?= =?UTF-8?q?=20empresa=20quando=20tiver=20cadastros=20associados=20a=20ela?= =?UTF-8?q?=20(fixed=20bug=20#5253)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://desenvolvimento.rjconsultores.com.br/repositorio/sco/AdmVenta/Model/trunk/modelWeb@35239 d1611594-4594-4d17-8e1d-87c2c4800839 --- .../dao/hibernate/EmpresaHibernateDAO.java | 2 -- .../hibernate/EsquemaCorridaHibernateDAO.java | 2 +- .../ventaboletos/service/EmpresaService.java | 5 ++--- .../service/impl/EmpresaServiceImpl.java | 19 +++++++++++-------- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/com/rjconsultores/ventaboletos/dao/hibernate/EmpresaHibernateDAO.java b/src/com/rjconsultores/ventaboletos/dao/hibernate/EmpresaHibernateDAO.java index 4e8ea3263..11bc3247c 100644 --- a/src/com/rjconsultores/ventaboletos/dao/hibernate/EmpresaHibernateDAO.java +++ b/src/com/rjconsultores/ventaboletos/dao/hibernate/EmpresaHibernateDAO.java @@ -21,8 +21,6 @@ import com.rjconsultores.ventaboletos.dao.EmpresaDAO; import com.rjconsultores.ventaboletos.entidad.Empresa; import com.rjconsultores.ventaboletos.entidad.InscricaoEstadual; import com.rjconsultores.ventaboletos.entidad.PuntoVenta; -import com.rjconsultores.ventaboletos.entidad.Ruta; -import com.rjconsultores.ventaboletos.entidad.RutaEmpresa; /** * diff --git a/src/com/rjconsultores/ventaboletos/dao/hibernate/EsquemaCorridaHibernateDAO.java b/src/com/rjconsultores/ventaboletos/dao/hibernate/EsquemaCorridaHibernateDAO.java index 7e615c2de..086483673 100644 --- a/src/com/rjconsultores/ventaboletos/dao/hibernate/EsquemaCorridaHibernateDAO.java +++ b/src/com/rjconsultores/ventaboletos/dao/hibernate/EsquemaCorridaHibernateDAO.java @@ -51,7 +51,7 @@ public class EsquemaCorridaHibernateDAO extends GenericHibernateDAO buscarPorEmpresaCorrida(Empresa empresa){ Criteria c = getSession().createCriteria(getPersistentClass()); - c.add(Restrictions.eq("empresaCorrida", empresa)); + c.add(Restrictions.eq("empresa", empresa)); c.add(Restrictions.eq("activo", Boolean.TRUE)); return c.list(); diff --git a/src/com/rjconsultores/ventaboletos/service/EmpresaService.java b/src/com/rjconsultores/ventaboletos/service/EmpresaService.java index 9722e4357..723255ec0 100644 --- a/src/com/rjconsultores/ventaboletos/service/EmpresaService.java +++ b/src/com/rjconsultores/ventaboletos/service/EmpresaService.java @@ -10,6 +10,7 @@ import com.rjconsultores.ventaboletos.entidad.Empresa; import com.rjconsultores.ventaboletos.entidad.InscricaoEstadual; import com.rjconsultores.ventaboletos.entidad.PuntoVenta; import com.rjconsultores.ventaboletos.exception.BusinessException; +import com.rjconsultores.ventaboletos.utilerias.RegistroConDependenciaException; /** * @@ -23,10 +24,8 @@ public interface EmpresaService { public Empresa suscribirActualizacion(Empresa entidad) throws BusinessException; - public void borrar(Empresa entidad); + public void borrar(Empresa entidad) throws RegistroConDependenciaException; - public boolean puedeBorrar(Empresa entidad); - public List buscar(String nombempresa, Boolean indExterna, Short indTipo); public List buscarTodosExceto(List empresa, Integer... idEmpresa); diff --git a/src/com/rjconsultores/ventaboletos/service/impl/EmpresaServiceImpl.java b/src/com/rjconsultores/ventaboletos/service/impl/EmpresaServiceImpl.java index 67949e50c..13a99a694 100644 --- a/src/com/rjconsultores/ventaboletos/service/impl/EmpresaServiceImpl.java +++ b/src/com/rjconsultores/ventaboletos/service/impl/EmpresaServiceImpl.java @@ -12,6 +12,8 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import com.rjconsultores.ventaboletos.dao.EmpresaDAO; +import com.rjconsultores.ventaboletos.dao.EsquemaCorridaDAO; +import com.rjconsultores.ventaboletos.dao.RutaEmpresaDAO; import com.rjconsultores.ventaboletos.entidad.Empresa; import com.rjconsultores.ventaboletos.entidad.InscricaoEstadual; import com.rjconsultores.ventaboletos.entidad.PuntoVenta; @@ -20,6 +22,7 @@ import com.rjconsultores.ventaboletos.exception.BusinessException; import com.rjconsultores.ventaboletos.service.EmpresaService; import com.rjconsultores.ventaboletos.service.EsquemaCorridaService; import com.rjconsultores.ventaboletos.service.RutaEmpresaService; +import com.rjconsultores.ventaboletos.utilerias.RegistroConDependenciaException; import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado; /** @@ -33,10 +36,10 @@ public class EmpresaServiceImpl implements EmpresaService { private EmpresaDAO empresaDAO; @Autowired - private RutaEmpresaService rutaEmpresaService; + private RutaEmpresaDAO rutaEmpresaDAO; @Autowired - private EsquemaCorridaService esquemaCorridaService; + private EsquemaCorridaDAO esquemaCorridaDAO; public List obtenerTodos() { return empresaDAO.obtenerTodos(); @@ -72,7 +75,12 @@ public class EmpresaServiceImpl implements EmpresaService { } @Transactional - public void borrar(Empresa entidad) { + public void borrar(Empresa entidad) throws RegistroConDependenciaException { + if ((rutaEmpresaDAO.obtenerPorEmpresa(entidad).size() <= 0) && + (esquemaCorridaDAO.buscarPorEmpresaCorrida(entidad).size() <= 0)){ + throw new RegistroConDependenciaException(); + } + entidad.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId()); entidad.setFecmodif(Calendar.getInstance().getTime()); entidad.setActivo(Boolean.FALSE); @@ -80,11 +88,6 @@ public class EmpresaServiceImpl implements EmpresaService { empresaDAO.actualizacion(entidad); } - @Override - public boolean puedeBorrar(Empresa entidad){ - return (rutaEmpresaService.obtenerPorEmpresa(entidad).size() <= 0) && - (esquemaCorridaService.buscarPorEmpresaCorrida(entidad).size() <= 0); - } public List buscar(String nombempresa, Boolean indExterna, Short indTipo) { return empresaDAO.buscar(nombempresa, indExterna, indTipo);