B23 - Não permitir excluir uma empresa quando tiver cadastros associados a ela (fixed bug #5253)

git-svn-id: http://desenvolvimento.rjconsultores.com.br/repositorio/sco/AdmVenta/Model/trunk/modelWeb@35239 d1611594-4594-4d17-8e1d-87c2c4800839
master
leonardo 2014-05-02 16:41:42 +00:00
parent dcb78d243b
commit 400c964c7c
4 changed files with 14 additions and 14 deletions

View File

@ -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;
/**
*

View File

@ -51,7 +51,7 @@ public class EsquemaCorridaHibernateDAO extends GenericHibernateDAO<EsquemaCorri
public List<EsquemaCorrida> 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();

View File

@ -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<Empresa> buscar(String nombempresa, Boolean indExterna, Short indTipo);
public List<Empresa> buscarTodosExceto(List<Empresa> empresa, Integer... idEmpresa);

View File

@ -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<Empresa> 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<Empresa> buscar(String nombempresa, Boolean indExterna, Short indTipo) {
return empresaDAO.buscar(nombempresa, indExterna, indTipo);