- validação ao salvar aliasservicio
git-svn-id: http://desenvolvimento.rjconsultores.com.br/repositorio/sco/AdmVenta/Model/trunk/modelWeb@24354 d1611594-4594-4d17-8e1d-87c2c4800839master
parent
b8868d41e3
commit
6474559df2
|
@ -1,7 +1,29 @@
|
||||||
package com.rjconsultores.ventaboletos.dao;
|
package com.rjconsultores.ventaboletos.dao;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import com.rjconsultores.ventaboletos.entidad.AliasServico;
|
import com.rjconsultores.ventaboletos.entidad.AliasServico;
|
||||||
|
|
||||||
public interface AliasServicoDAO extends GenericDAO<AliasServico, Integer>{
|
public interface AliasServicoDAO extends GenericDAO<AliasServico, Integer>{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Realiza a buscar com os filtros informados e restringindo o corridaId para is null
|
||||||
|
*
|
||||||
|
* @param origenId
|
||||||
|
* @param destinoId
|
||||||
|
* @param rutaId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public List<AliasServico> buscarAliasSemCorrida(Integer origenId,Integer destinoId,Integer rutaId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Realiza a busca com os filtro informados.
|
||||||
|
* @param origenId
|
||||||
|
* @param destinoId
|
||||||
|
* @param rutaId
|
||||||
|
* @param corridaId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public List<AliasServico> buscar(Integer origenId,Integer destinoId,Integer rutaId,Integer corridaId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
package com.rjconsultores.ventaboletos.dao.hibernate;
|
package com.rjconsultores.ventaboletos.dao.hibernate;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.hibernate.Criteria;
|
||||||
import org.hibernate.SessionFactory;
|
import org.hibernate.SessionFactory;
|
||||||
|
import org.hibernate.criterion.Restrictions;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
@ -16,4 +20,29 @@ public class AliasServicoHibernateDAO extends GenericHibernateDAO<AliasServico,
|
||||||
public AliasServicoHibernateDAO(@Qualifier("sessionFactory") SessionFactory factory) {
|
public AliasServicoHibernateDAO(@Qualifier("sessionFactory") SessionFactory factory) {
|
||||||
setSessionFactory(factory);
|
setSessionFactory(factory);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<AliasServico> buscarAliasSemCorrida(Integer origenId, Integer destinoId, Integer rutaId) {
|
||||||
|
|
||||||
|
Criteria c = makeCriteria();
|
||||||
|
c.add(Restrictions.eq("activo", Boolean.TRUE));
|
||||||
|
c.add(Restrictions.eq("origen.paradaId",origenId));
|
||||||
|
c.add(Restrictions.eq("destino.paradaId",destinoId));
|
||||||
|
c.add(Restrictions.eq("ruta.rutaId",rutaId));
|
||||||
|
c.add(Restrictions.isNull("corridaId"));
|
||||||
|
|
||||||
|
return c.list();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<AliasServico> buscar(Integer origenId, Integer destinoId, Integer rutaId, Integer corridaId) {
|
||||||
|
Criteria c = makeCriteria();
|
||||||
|
c.add(Restrictions.eq("activo", Boolean.TRUE));
|
||||||
|
c.add(Restrictions.eq("origen.paradaId",origenId));
|
||||||
|
c.add(Restrictions.eq("destino.paradaId",destinoId));
|
||||||
|
c.add(Restrictions.eq("ruta.rutaId",rutaId));
|
||||||
|
c.add(Restrictions.eq("corridaId",corridaId));
|
||||||
|
|
||||||
|
return c.list();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,10 @@ import org.zkoss.util.resource.Labels;
|
||||||
|
|
||||||
public class BusinessException extends Exception {
|
public class BusinessException extends Exception {
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param message
|
* @param message
|
||||||
|
|
|
@ -1,7 +1,17 @@
|
||||||
package com.rjconsultores.ventaboletos.service;
|
package com.rjconsultores.ventaboletos.service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import com.rjconsultores.ventaboletos.entidad.AliasServico;
|
import com.rjconsultores.ventaboletos.entidad.AliasServico;
|
||||||
|
import com.rjconsultores.ventaboletos.exception.BusinessException;
|
||||||
|
|
||||||
public interface AliasServicoService extends GenericService<AliasServico, Integer>{
|
public interface AliasServicoService{
|
||||||
|
|
||||||
|
public List<AliasServico> obtenerTodos();
|
||||||
|
|
||||||
|
public AliasServico obtenerID(Integer id);
|
||||||
|
|
||||||
|
public AliasServico suscribirActualizar(AliasServico entidad) throws BusinessException;
|
||||||
|
|
||||||
|
public void borrar(AliasServico entidad);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,18 @@
|
||||||
package com.rjconsultores.ventaboletos.service.impl;
|
package com.rjconsultores.ventaboletos.service.impl;
|
||||||
|
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
|
import org.apache.commons.collections.Predicate;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import com.rjconsultores.ventaboletos.dao.AliasServicoDAO;
|
import com.rjconsultores.ventaboletos.dao.AliasServicoDAO;
|
||||||
import com.rjconsultores.ventaboletos.entidad.AliasServico;
|
import com.rjconsultores.ventaboletos.entidad.AliasServico;
|
||||||
|
import com.rjconsultores.ventaboletos.exception.BusinessException;
|
||||||
import com.rjconsultores.ventaboletos.service.AliasServicoService;
|
import com.rjconsultores.ventaboletos.service.AliasServicoService;
|
||||||
import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado;
|
import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado;
|
||||||
|
|
||||||
|
@ -27,22 +31,44 @@ public class AliasServicoServiceImpl implements AliasServicoService {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public AliasServico suscribir(AliasServico entidad) {
|
public AliasServico suscribirActualizar(AliasServico entidad) throws BusinessException {
|
||||||
entidad.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId());
|
|
||||||
entidad.setFecmodif(Calendar.getInstance().getTime());
|
|
||||||
entidad.setActivo(Boolean.TRUE);
|
|
||||||
|
|
||||||
return aliasServicoDAO.suscribir(entidad);
|
if ( (entidad.getOrigen() == null) || (entidad.getDestino() == null) || (entidad.getAliasDestino()== null) || (entidad.getAliasOrigen()== null) || (entidad.getRuta()== null)){
|
||||||
|
throw new BusinessException("editarAliasServicoController.MSG.camposObrigatorios");
|
||||||
|
}
|
||||||
|
|
||||||
|
List<AliasServico> lsBusca = Collections.emptyList();
|
||||||
|
|
||||||
|
if (entidad.getCorridaId() != null){
|
||||||
|
lsBusca = aliasServicoDAO.buscar(entidad.getOrigen().getParadaId(), entidad.getDestino().getParadaId(), entidad.getRuta().getRutaId(), entidad.getCorridaId());
|
||||||
|
}else{
|
||||||
|
lsBusca = aliasServicoDAO.buscarAliasSemCorrida(entidad.getOrigen().getParadaId(), entidad.getDestino().getParadaId(), entidad.getRuta().getRutaId());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!lsBusca.isEmpty()){
|
||||||
|
boolean existe = false;
|
||||||
|
|
||||||
|
for(AliasServico as : lsBusca){
|
||||||
|
if (as.equals(entidad)){
|
||||||
|
existe = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!existe){
|
||||||
|
throw new BusinessException("editarAliasServicoController.MSG.registroYaExiste");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
|
||||||
public AliasServico actualizacion(AliasServico entidad) {
|
|
||||||
entidad.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId());
|
entidad.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId());
|
||||||
entidad.setFecmodif(Calendar.getInstance().getTime());
|
entidad.setFecmodif(Calendar.getInstance().getTime());
|
||||||
entidad.setActivo(Boolean.TRUE);
|
entidad.setActivo(Boolean.TRUE);
|
||||||
|
|
||||||
|
if (entidad.getAliasServicoId() == null){
|
||||||
|
return aliasServicoDAO.suscribir(entidad);
|
||||||
|
}else{
|
||||||
return aliasServicoDAO.actualizacion(entidad);
|
return aliasServicoDAO.actualizacion(entidad);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public void borrar(AliasServico entidad) {
|
public void borrar(AliasServico entidad) {
|
||||||
|
|
Loading…
Reference in New Issue