From 08b66ff46ef204d7ce1b58646031c2012d810400 Mon Sep 17 00:00:00 2001 From: gleimar Date: Thu, 16 Jan 2014 14:18:11 +0000 Subject: [PATCH] git-svn-id: http://desenvolvimento.rjconsultores.com.br/repositorio/sco/AdmVenta/Model/trunk/modelWeb@33151 d1611594-4594-4d17-8e1d-87c2c4800839 --- .../dao/hibernate/EstacionHibernateDAO.java | 4 +-- .../service/impl/EstacionServiceImpl.java | 31 +++++++++++++------ 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/com/rjconsultores/ventaboletos/dao/hibernate/EstacionHibernateDAO.java b/src/com/rjconsultores/ventaboletos/dao/hibernate/EstacionHibernateDAO.java index 04e28247b..5cfe47ae0 100644 --- a/src/com/rjconsultores/ventaboletos/dao/hibernate/EstacionHibernateDAO.java +++ b/src/com/rjconsultores/ventaboletos/dao/hibernate/EstacionHibernateDAO.java @@ -4,15 +4,12 @@ */ package com.rjconsultores.ventaboletos.dao.hibernate; -import com.rjconsultores.ventaboletos.entidad.Usuario; - import java.math.BigDecimal; import java.util.List; import org.hibernate.Criteria; import org.hibernate.SQLQuery; import org.hibernate.SessionFactory; -import org.hibernate.criterion.DetachedCriteria; import org.hibernate.criterion.Order; import org.hibernate.criterion.Projections; import org.hibernate.criterion.Property; @@ -24,6 +21,7 @@ import org.springframework.stereotype.Repository; import com.rjconsultores.ventaboletos.dao.EstacionDAO; import com.rjconsultores.ventaboletos.entidad.Estacion; import com.rjconsultores.ventaboletos.entidad.PuntoVenta; +import com.rjconsultores.ventaboletos.entidad.Usuario; /** * diff --git a/src/com/rjconsultores/ventaboletos/service/impl/EstacionServiceImpl.java b/src/com/rjconsultores/ventaboletos/service/impl/EstacionServiceImpl.java index 4b1e3da79..5504f4f7d 100644 --- a/src/com/rjconsultores/ventaboletos/service/impl/EstacionServiceImpl.java +++ b/src/com/rjconsultores/ventaboletos/service/impl/EstacionServiceImpl.java @@ -45,8 +45,8 @@ public class EstacionServiceImpl implements EstacionService { @Transactional(rollbackFor = BusinessException.class) public Estacion suscribirActualizar(Estacion estacion) throws BusinessException { - validarEstoque(estacion); - + validarEstoqueUpdate(estacion); + Boolean esMacDuplicado = Boolean.FALSE; List lsEstacionMac = estacionDAO.buscar(estacion.getDescmac()); if (!lsEstacionMac.isEmpty()) { @@ -93,22 +93,35 @@ public class EstacionServiceImpl implements EstacionService { } - private void validarEstoque(Estacion estacion) throws BusinessException { - if (!ApplicationProperties.getInstance().generarRotinaFolios()){ + private void validarEstoqueUpdate(Estacion estacion) throws BusinessException { + + if (estacion.getEstacionId() == null) { + return; + } + + if (!ApplicationProperties.getInstance().generarRotinaFolios()) { Estacion estacionPuntoVentaAnterior = estacionDAO.obtenerID(estacion.getEstacionId()); - if (!estacionPuntoVentaAnterior.getPuntoVenta().equals(estacion.getPuntoVenta())){ - if (estacionDAO.temEstoque(estacionPuntoVentaAnterior.getPuntoVenta(), estacion)){ + if (!estacionPuntoVentaAnterior.getPuntoVenta().equals(estacion.getPuntoVenta())) { + if (estacionDAO.temEstoque(estacionPuntoVentaAnterior.getPuntoVenta(), estacion)) { throw new BusinessException("estacionServiceImpl.msg.hayStock"); } } } } + private void validarEstoqueBorrar(Estacion estacion) throws BusinessException { + if (!ApplicationProperties.getInstance().generarRotinaFolios()) { + if (estacionDAO.temEstoque(estacion.getPuntoVenta(), estacion)) { + throw new BusinessException("estacionServiceImpl.msg.hayStock"); + } + } + } + @Transactional public void borrar(Estacion entidad) throws BusinessException { - - validarEstoque(entidad); - + + validarEstoqueBorrar(entidad); + entidad.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId()); entidad.setFecmodif(Calendar.getInstance().getTime()); entidad.setActivo(Boolean.FALSE);