From dcb78d243b2c99edcf0b8002135676ee1050784e Mon Sep 17 00:00:00 2001 From: leonardo Date: Thu, 1 May 2014 19:58:18 +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@35226 d1611594-4594-4d17-8e1d-87c2c4800839 --- .../ventaboletos/dao/EsquemaCorridaDAO.java | 3 +++ .../ventaboletos/dao/RutaEmpresaDAO.java | 5 +++++ .../dao/hibernate/EmpresaHibernateDAO.java | 19 +++---------------- .../hibernate/EsquemaCorridaHibernateDAO.java | 10 ++++++++++ .../hibernate/RutaEmpresaHibernateDAO.java | 17 +++++++++++++++-- .../ventaboletos/service/EmpresaService.java | 2 ++ .../service/EsquemaCorridaService.java | 3 +++ .../service/RutaEmpresaService.java | 5 +++++ .../service/impl/EmpresaServiceImpl.java | 15 +++++++++++++++ .../impl/EsquemaCorridaServiceImpl.java | 6 ++++++ .../service/impl/RutaEmpresaServiceImpl.java | 8 ++++++++ 11 files changed, 75 insertions(+), 18 deletions(-) diff --git a/src/com/rjconsultores/ventaboletos/dao/EsquemaCorridaDAO.java b/src/com/rjconsultores/ventaboletos/dao/EsquemaCorridaDAO.java index bc38e070c..fcbad22b7 100644 --- a/src/com/rjconsultores/ventaboletos/dao/EsquemaCorridaDAO.java +++ b/src/com/rjconsultores/ventaboletos/dao/EsquemaCorridaDAO.java @@ -5,6 +5,7 @@ package com.rjconsultores.ventaboletos.dao; import com.rjconsultores.ventaboletos.entidad.ClaseServicio; +import com.rjconsultores.ventaboletos.entidad.Empresa; import com.rjconsultores.ventaboletos.entidad.EsquemaCorrida; import com.rjconsultores.ventaboletos.entidad.EsquemaOperacional; import com.rjconsultores.ventaboletos.entidad.Marca; @@ -22,6 +23,8 @@ import java.util.List; public interface EsquemaCorridaDAO extends GenericDAO { public List buscarPorEsquemaOperacional(EsquemaOperacional eo); + + public List buscarPorEmpresaCorrida(Empresa empresa); public List buscar(Marca marca, RolOperativo rolOperativo, Ruta ruta, ClaseServicio claseServicio); diff --git a/src/com/rjconsultores/ventaboletos/dao/RutaEmpresaDAO.java b/src/com/rjconsultores/ventaboletos/dao/RutaEmpresaDAO.java index 7ffbc533a..8996a13b1 100644 --- a/src/com/rjconsultores/ventaboletos/dao/RutaEmpresaDAO.java +++ b/src/com/rjconsultores/ventaboletos/dao/RutaEmpresaDAO.java @@ -4,6 +4,9 @@ */ package com.rjconsultores.ventaboletos.dao; +import java.util.List; + +import com.rjconsultores.ventaboletos.entidad.Empresa; import com.rjconsultores.ventaboletos.entidad.RutaEmpresa; /** @@ -11,4 +14,6 @@ import com.rjconsultores.ventaboletos.entidad.RutaEmpresa; * @author Administrador */ public interface RutaEmpresaDAO extends GenericDAO { + + public List obtenerPorEmpresa(Empresa empresa); } diff --git a/src/com/rjconsultores/ventaboletos/dao/hibernate/EmpresaHibernateDAO.java b/src/com/rjconsultores/ventaboletos/dao/hibernate/EmpresaHibernateDAO.java index 9d83af93b..4e8ea3263 100644 --- a/src/com/rjconsultores/ventaboletos/dao/hibernate/EmpresaHibernateDAO.java +++ b/src/com/rjconsultores/ventaboletos/dao/hibernate/EmpresaHibernateDAO.java @@ -21,6 +21,8 @@ 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; /** * @@ -43,7 +45,7 @@ public class EmpresaHibernateDAO extends GenericHibernateDAO return c.list(); } - + public List buscar(String nombempresa, Boolean indExterna, Short indTipo) { Criteria c = getSession().createCriteria(getPersistentClass()); c.add(Restrictions.eq("activo", Boolean.TRUE)); @@ -75,21 +77,6 @@ public class EmpresaHibernateDAO extends GenericHibernateDAO return c.list(); } - - -// public List obtenerIndTipo1(Usuario usuario) { -// Criteria c = getSession().createCriteria(getPersistentClass()); -// c.add(Restrictions.eq("activo", Boolean.TRUE)); -// c.add(Restrictions.eq("indTipo", new Short("1"))); -// -// //Nao Buscar Empresa todas -// c.add(Restrictions.ne("empresaId", -1)); -// -// c.addOrder(Order.asc("nombempresa")); -// -// return c.list(); -// } - public List obtenerIndTipo2() { diff --git a/src/com/rjconsultores/ventaboletos/dao/hibernate/EsquemaCorridaHibernateDAO.java b/src/com/rjconsultores/ventaboletos/dao/hibernate/EsquemaCorridaHibernateDAO.java index 305083b1c..7e615c2de 100644 --- a/src/com/rjconsultores/ventaboletos/dao/hibernate/EsquemaCorridaHibernateDAO.java +++ b/src/com/rjconsultores/ventaboletos/dao/hibernate/EsquemaCorridaHibernateDAO.java @@ -19,6 +19,7 @@ import org.springframework.stereotype.Repository; import com.rjconsultores.ventaboletos.dao.EsquemaCorridaDAO; import com.rjconsultores.ventaboletos.entidad.ClaseServicio; +import com.rjconsultores.ventaboletos.entidad.Empresa; import com.rjconsultores.ventaboletos.entidad.EsquemaCorrida; import com.rjconsultores.ventaboletos.entidad.EsquemaOperacional; import com.rjconsultores.ventaboletos.entidad.Marca; @@ -46,6 +47,15 @@ public class EsquemaCorridaHibernateDAO extends GenericHibernateDAO buscarPorEmpresaCorrida(Empresa empresa){ + Criteria c = getSession().createCriteria(getPersistentClass()); + + c.add(Restrictions.eq("empresaCorrida", empresa)); + c.add(Restrictions.eq("activo", Boolean.TRUE)); + + return c.list(); + } public List buscarPorEsquemaOperacional( EsquemaOperacional eo) { diff --git a/src/com/rjconsultores/ventaboletos/dao/hibernate/RutaEmpresaHibernateDAO.java b/src/com/rjconsultores/ventaboletos/dao/hibernate/RutaEmpresaHibernateDAO.java index 5a01b2860..afb4fba4d 100644 --- a/src/com/rjconsultores/ventaboletos/dao/hibernate/RutaEmpresaHibernateDAO.java +++ b/src/com/rjconsultores/ventaboletos/dao/hibernate/RutaEmpresaHibernateDAO.java @@ -4,13 +4,19 @@ */ package com.rjconsultores.ventaboletos.dao.hibernate; -import com.rjconsultores.ventaboletos.dao.RutaEmpresaDAO; -import com.rjconsultores.ventaboletos.entidad.RutaEmpresa; +import java.util.List; + +import org.hibernate.Criteria; import org.hibernate.SessionFactory; +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.RutaEmpresaDAO; +import com.rjconsultores.ventaboletos.entidad.Empresa; +import com.rjconsultores.ventaboletos.entidad.RutaEmpresa; + /** * * @author Administrador @@ -23,4 +29,11 @@ public class RutaEmpresaHibernateDAO extends GenericHibernateDAO obtenerPorEmpresa(Empresa empresa){ + Criteria c = getSession().createCriteria(getPersistentClass()); + c.add(Restrictions.eq("activo", Boolean.TRUE)); + c.add(Restrictions.eq("empresa", empresa)); + return c.list(); + } } diff --git a/src/com/rjconsultores/ventaboletos/service/EmpresaService.java b/src/com/rjconsultores/ventaboletos/service/EmpresaService.java index 82c0aa5e7..9722e4357 100644 --- a/src/com/rjconsultores/ventaboletos/service/EmpresaService.java +++ b/src/com/rjconsultores/ventaboletos/service/EmpresaService.java @@ -24,6 +24,8 @@ public interface EmpresaService { public Empresa suscribirActualizacion(Empresa entidad) throws BusinessException; public void borrar(Empresa entidad); + + public boolean puedeBorrar(Empresa entidad); public List buscar(String nombempresa, Boolean indExterna, Short indTipo); diff --git a/src/com/rjconsultores/ventaboletos/service/EsquemaCorridaService.java b/src/com/rjconsultores/ventaboletos/service/EsquemaCorridaService.java index 7e7833fa9..dbbbf4896 100644 --- a/src/com/rjconsultores/ventaboletos/service/EsquemaCorridaService.java +++ b/src/com/rjconsultores/ventaboletos/service/EsquemaCorridaService.java @@ -9,6 +9,7 @@ import java.util.List; import com.rjconsultores.ventaboletos.dao.EsquemaCorridaDAO; import com.rjconsultores.ventaboletos.entidad.ClaseServicio; +import com.rjconsultores.ventaboletos.entidad.Empresa; import com.rjconsultores.ventaboletos.entidad.EsquemaCorrida; import com.rjconsultores.ventaboletos.entidad.EsquemaOperacional; import com.rjconsultores.ventaboletos.entidad.Marca; @@ -24,6 +25,8 @@ import com.rjconsultores.ventaboletos.entidad.Tramo; public interface EsquemaCorridaService extends GenericService { public List buscarPorEsquemaOperacional(EsquemaOperacional eo); + + public List buscarPorEmpresaCorrida(Empresa empresa); public List buscar(Marca marca, RolOperativo rolOperativo,Ruta ruta, ClaseServicio claseServicio); diff --git a/src/com/rjconsultores/ventaboletos/service/RutaEmpresaService.java b/src/com/rjconsultores/ventaboletos/service/RutaEmpresaService.java index 6bcc32ed5..70aeaed57 100644 --- a/src/com/rjconsultores/ventaboletos/service/RutaEmpresaService.java +++ b/src/com/rjconsultores/ventaboletos/service/RutaEmpresaService.java @@ -4,6 +4,9 @@ */ package com.rjconsultores.ventaboletos.service; +import java.util.List; + +import com.rjconsultores.ventaboletos.entidad.Empresa; import com.rjconsultores.ventaboletos.entidad.RutaEmpresa; /** @@ -11,4 +14,6 @@ import com.rjconsultores.ventaboletos.entidad.RutaEmpresa; * @author Administrador */ public interface RutaEmpresaService extends GenericService { + + public List obtenerPorEmpresa(Empresa empresa); } diff --git a/src/com/rjconsultores/ventaboletos/service/impl/EmpresaServiceImpl.java b/src/com/rjconsultores/ventaboletos/service/impl/EmpresaServiceImpl.java index 1f7d331af..67949e50c 100644 --- a/src/com/rjconsultores/ventaboletos/service/impl/EmpresaServiceImpl.java +++ b/src/com/rjconsultores/ventaboletos/service/impl/EmpresaServiceImpl.java @@ -15,8 +15,11 @@ 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.RutaEmpresa; 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.UsuarioLogado; /** @@ -29,6 +32,12 @@ public class EmpresaServiceImpl implements EmpresaService { @Autowired private EmpresaDAO empresaDAO; + @Autowired + private RutaEmpresaService rutaEmpresaService; + + @Autowired + private EsquemaCorridaService esquemaCorridaService; + public List obtenerTodos() { return empresaDAO.obtenerTodos(); } @@ -70,6 +79,12 @@ 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); diff --git a/src/com/rjconsultores/ventaboletos/service/impl/EsquemaCorridaServiceImpl.java b/src/com/rjconsultores/ventaboletos/service/impl/EsquemaCorridaServiceImpl.java index 1821a8147..021660692 100644 --- a/src/com/rjconsultores/ventaboletos/service/impl/EsquemaCorridaServiceImpl.java +++ b/src/com/rjconsultores/ventaboletos/service/impl/EsquemaCorridaServiceImpl.java @@ -16,6 +16,7 @@ import com.rjconsultores.ventaboletos.dao.EsquemaCorridaDAO; import com.rjconsultores.ventaboletos.dao.EsquemaTramoDAO; import com.rjconsultores.ventaboletos.dao.RutaCombinacionDAO; import com.rjconsultores.ventaboletos.entidad.ClaseServicio; +import com.rjconsultores.ventaboletos.entidad.Empresa; import com.rjconsultores.ventaboletos.entidad.EsquemaAsiento; import com.rjconsultores.ventaboletos.entidad.EsquemaCorrida; import com.rjconsultores.ventaboletos.entidad.EsquemaOperacional; @@ -52,6 +53,11 @@ public class EsquemaCorridaServiceImpl implements EsquemaCorridaService { return esquemaCorridaDAO.obtenerID(id); } + @Override + public List buscarPorEmpresaCorrida(Empresa empresa){ + return esquemaCorridaDAO.buscarPorEmpresaCorrida(empresa); + } + @Transactional public EsquemaCorrida suscribir(EsquemaCorrida entidad) { entidad.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId()); diff --git a/src/com/rjconsultores/ventaboletos/service/impl/RutaEmpresaServiceImpl.java b/src/com/rjconsultores/ventaboletos/service/impl/RutaEmpresaServiceImpl.java index 94475ff23..4bb1a5535 100644 --- a/src/com/rjconsultores/ventaboletos/service/impl/RutaEmpresaServiceImpl.java +++ b/src/com/rjconsultores/ventaboletos/service/impl/RutaEmpresaServiceImpl.java @@ -5,11 +5,14 @@ package com.rjconsultores.ventaboletos.service.impl; import com.rjconsultores.ventaboletos.dao.RutaEmpresaDAO; +import com.rjconsultores.ventaboletos.entidad.Empresa; import com.rjconsultores.ventaboletos.entidad.RutaEmpresa; import com.rjconsultores.ventaboletos.service.RutaEmpresaService; import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado; + import java.util.Calendar; import java.util.List; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -58,4 +61,9 @@ public class RutaEmpresaServiceImpl implements RutaEmpresaService { rutaEmpresaDAO.actualizacion(entidad); } + + @Override + public List obtenerPorEmpresa(Empresa empresa) { + return rutaEmpresaDAO.obtenerPorEmpresa(empresa); + } }