diff --git a/src/com/rjconsultores/ventaboletos/dao/TramoDAO.java b/src/com/rjconsultores/ventaboletos/dao/TramoDAO.java index b88c912bd..76e6ca056 100644 --- a/src/com/rjconsultores/ventaboletos/dao/TramoDAO.java +++ b/src/com/rjconsultores/ventaboletos/dao/TramoDAO.java @@ -4,11 +4,14 @@ */ package com.rjconsultores.ventaboletos.dao; +import java.util.List; + import com.rjconsultores.ventaboletos.entidad.ClaseServicio; +import com.rjconsultores.ventaboletos.entidad.OrgaoTramo; import com.rjconsultores.ventaboletos.entidad.Parada; import com.rjconsultores.ventaboletos.entidad.Tramo; +import com.rjconsultores.ventaboletos.entidad.TramoServicio; import com.rjconsultores.ventaboletos.entidad.Via; -import java.util.List; /** * @@ -23,6 +26,8 @@ public interface TramoDAO extends GenericDAO { public Tramo obtenerTramotPorOrigemDestinoVia(Parada origem, Parada destino, Via via); public Tramo busca(Parada origem, Parada destino, Via via); + + public List getLsOrgaoTramo(Tramo tramo); /** @@ -41,4 +46,5 @@ public interface TramoDAO extends GenericDAO { public Long count(Via via); public List obtenerViasOrigemDestino(Parada origem, Parada destino); public List obtenerPorOrigemDestinoFetchLazy(Parada origem, Parada destino) ; + public List obtenerTramosServiciosPorTramo(Tramo t); } diff --git a/src/com/rjconsultores/ventaboletos/dao/hibernate/TramoHibernateDAO.java b/src/com/rjconsultores/ventaboletos/dao/hibernate/TramoHibernateDAO.java index 50a8b9a93..8446fc82b 100644 --- a/src/com/rjconsultores/ventaboletos/dao/hibernate/TramoHibernateDAO.java +++ b/src/com/rjconsultores/ventaboletos/dao/hibernate/TramoHibernateDAO.java @@ -18,8 +18,10 @@ import org.springframework.stereotype.Repository; import com.rjconsultores.ventaboletos.dao.TramoDAO; import com.rjconsultores.ventaboletos.entidad.ClaseServicio; +import com.rjconsultores.ventaboletos.entidad.OrgaoTramo; import com.rjconsultores.ventaboletos.entidad.Parada; import com.rjconsultores.ventaboletos.entidad.Tramo; +import com.rjconsultores.ventaboletos.entidad.TramoServicio; import com.rjconsultores.ventaboletos.entidad.Via; /** @@ -43,6 +45,10 @@ public class TramoHibernateDAO extends GenericHibernateDAO return c.list(); } + + public List obtenerTramosServiciosPorTramo(Tramo t){ + return obtenerID(t.getTramoId()).getTramoServicioList(); + } public Tramo obtenerPorOrigemDestino(Parada origem, Parada destino) { Criteria c = getSession().createCriteria(getPersistentClass()); @@ -171,4 +177,8 @@ public class TramoHibernateDAO extends GenericHibernateDAO return HibernateFix.count(c.list()); } + + public List getLsOrgaoTramo(Tramo tramo){ + return obtenerID(tramo.getTramoId()).getLsOrgaoTramo(); + } } diff --git a/src/com/rjconsultores/ventaboletos/entidad/Tramo.java b/src/com/rjconsultores/ventaboletos/entidad/Tramo.java index a59d4a801..58c31140f 100644 --- a/src/com/rjconsultores/ventaboletos/entidad/Tramo.java +++ b/src/com/rjconsultores/ventaboletos/entidad/Tramo.java @@ -187,19 +187,17 @@ public class Tramo implements Serializable { this.rutaCombinacionList = rutaCombinacionList; } - public List getTramoServicioList() { + public List getTramoServicioList() throws LazyInitializationException{ List lsTramoServicio = new ArrayList(); - try{ - for (TramoServicio tramoServicio : this.tramoServicioList) { - if (tramoServicio.getActivo()) { - lsTramoServicio.add(tramoServicio); - } + + for (TramoServicio tramoServicio : this.tramoServicioList) { + if (tramoServicio.getActivo()) { + lsTramoServicio.add(tramoServicio); } - - this.tramoServicioList = lsTramoServicio; - } catch (LazyInitializationException le){ - Log.error("", le); } + + this.tramoServicioList = lsTramoServicio; + return lsTramoServicio; } diff --git a/src/com/rjconsultores/ventaboletos/service/TramoService.java b/src/com/rjconsultores/ventaboletos/service/TramoService.java index 670c023c4..b96735b88 100644 --- a/src/com/rjconsultores/ventaboletos/service/TramoService.java +++ b/src/com/rjconsultores/ventaboletos/service/TramoService.java @@ -7,6 +7,7 @@ package com.rjconsultores.ventaboletos.service; import java.util.List; import com.rjconsultores.ventaboletos.entidad.ClaseServicio; +import com.rjconsultores.ventaboletos.entidad.OrgaoTramo; import com.rjconsultores.ventaboletos.entidad.Parada; import com.rjconsultores.ventaboletos.entidad.Tramo; import com.rjconsultores.ventaboletos.entidad.Via; @@ -62,6 +63,8 @@ public interface TramoService { public List obtenerPorOrigemDestinoFetchLazy(Parada origem, Parada destino) ; public Tramo suscribirActualizar(Tramo tramo) throws BusinessException ; + + public List getLsOrgaoTramoByTramo(Tramo tramo); /** * Gerar a descrição automática do tramo diff --git a/src/com/rjconsultores/ventaboletos/service/impl/TramoServiceImpl.java b/src/com/rjconsultores/ventaboletos/service/impl/TramoServiceImpl.java index cf48bfee0..125df8eae 100644 --- a/src/com/rjconsultores/ventaboletos/service/impl/TramoServiceImpl.java +++ b/src/com/rjconsultores/ventaboletos/service/impl/TramoServiceImpl.java @@ -10,6 +10,7 @@ import java.util.List; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.Predicate; +import org.hibernate.LazyInitializationException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -17,6 +18,7 @@ import org.springframework.transaction.annotation.Transactional; import com.rjconsultores.ventaboletos.dao.RutaCombinacionDAO; import com.rjconsultores.ventaboletos.dao.TramoDAO; import com.rjconsultores.ventaboletos.entidad.ClaseServicio; +import com.rjconsultores.ventaboletos.entidad.OrgaoTramo; import com.rjconsultores.ventaboletos.entidad.Parada; import com.rjconsultores.ventaboletos.entidad.Tramo; import com.rjconsultores.ventaboletos.entidad.TramoServicio; @@ -175,6 +177,14 @@ public class TramoServiceImpl implements TramoService { return tramoDAO.obtenerPorOrigemDestinoFetchLazy(origem, destino); } + private List getListTramoService(Tramo t){ + return tramoDAO.obtenerTramosServiciosPorTramo(t); + } + + public List getLsOrgaoTramoByTramo(Tramo tramo){ + return tramoDAO.getLsOrgaoTramo(tramo); + } + @Override @Transactional(rollbackFor = BusinessException.class) public Tramo suscribirActualizar(Tramo tramo) throws BusinessException { @@ -217,19 +227,24 @@ public class TramoServiceImpl implements TramoService { // Esa validación tambien permite que el usuario quite una clase y la agregue de nuevo con otro tiempo de recorrido List lsTramoServicioOriginal = tramoOriginal.getTramoServicioList(); for (final TramoServicio ts : lsTramoServicioOriginal) { - boolean existe = CollectionUtils.exists(tramo.getTramoServicioList(), new Predicate() { - - @Override - public boolean evaluate(Object o) { - TramoServicio t = (TramoServicio) o; - if (t.getActivo()) { - return t.getClaseServicio().equals(ts.getClaseServicio()); - } - return false; + + + boolean alterouClaseTramoServico = true; + + try{ + tramo.getTramoServicioList(); + } catch(LazyInitializationException le){ + tramo.setTramoServicioList(getListTramoService(tramo)); + } + + for( TramoServicio tsNovo : tramo.getTramoServicioList()){ + if (tsNovo.getClaseServicio().equals(ts.getClaseServicio())){ + alterouClaseTramoServico = false; + break; } - }); + } - if (!existe) { + if (alterouClaseTramoServico) { if (rutaCombinacionDAO.existeTramo(tramo, ts.getClaseServicio())) { throw new BusinessException("TramoServiceImpl.msg.validacionTramoServicio"); }