From edf56a540203e789d01d526f7364777f0c212373 Mon Sep 17 00:00:00 2001 From: "thiago.penido" Date: Tue, 25 Aug 2015 12:38:20 +0000 Subject: [PATCH] fixes bug#6568 git-svn-id: http://desenvolvimento.rjconsultores.com.br/repositorio/sco/AdmVenta/Model/trunk/modelWeb@47156 d1611594-4594-4d17-8e1d-87c2c4800839 --- .../ventaboletos/dao/PracaPedagioDAO.java | 10 ++ .../hibernate/PracaPedagioHibernateDAO.java | 39 ++++++ .../ventaboletos/entidad/PracaPedagio.java | 129 ++++++++++++++++++ .../service/PracaPedagioService.java | 10 ++ .../service/impl/PracaPedagioServiceImpl.java | 78 +++++++++++ 5 files changed, 266 insertions(+) create mode 100644 src/com/rjconsultores/ventaboletos/dao/PracaPedagioDAO.java create mode 100644 src/com/rjconsultores/ventaboletos/dao/hibernate/PracaPedagioHibernateDAO.java create mode 100644 src/com/rjconsultores/ventaboletos/entidad/PracaPedagio.java create mode 100644 src/com/rjconsultores/ventaboletos/service/PracaPedagioService.java create mode 100644 src/com/rjconsultores/ventaboletos/service/impl/PracaPedagioServiceImpl.java diff --git a/src/com/rjconsultores/ventaboletos/dao/PracaPedagioDAO.java b/src/com/rjconsultores/ventaboletos/dao/PracaPedagioDAO.java new file mode 100644 index 000000000..34e94ce2e --- /dev/null +++ b/src/com/rjconsultores/ventaboletos/dao/PracaPedagioDAO.java @@ -0,0 +1,10 @@ +package com.rjconsultores.ventaboletos.dao; + +import java.util.List; + +import com.rjconsultores.ventaboletos.entidad.PracaPedagio; + +public interface PracaPedagioDAO extends GenericDAO { + + List buscar(String descricaoPracaPedagio); +} \ No newline at end of file diff --git a/src/com/rjconsultores/ventaboletos/dao/hibernate/PracaPedagioHibernateDAO.java b/src/com/rjconsultores/ventaboletos/dao/hibernate/PracaPedagioHibernateDAO.java new file mode 100644 index 000000000..0ec0571ed --- /dev/null +++ b/src/com/rjconsultores/ventaboletos/dao/hibernate/PracaPedagioHibernateDAO.java @@ -0,0 +1,39 @@ +package com.rjconsultores.ventaboletos.dao.hibernate; + +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.PracaPedagioDAO; +import com.rjconsultores.ventaboletos.entidad.PracaPedagio; + +@Repository("pracaPedagioDAO") +public class PracaPedagioHibernateDAO extends GenericHibernateDAO implements PracaPedagioDAO { + + @Autowired + public PracaPedagioHibernateDAO(@Qualifier("sessionFactory") SessionFactory factory) { + setSessionFactory(factory); + } + + @SuppressWarnings("unchecked") + @Override + public List obtenerTodos() { + Criteria c = getSession().createCriteria(getPersistentClass()); + c.add(Restrictions.eq("activo", Boolean.TRUE)); + return (List) c.list(); + } + + @SuppressWarnings("unchecked") + @Override + public List buscar(String descricaoPracaPedagio) { + Criteria c = getSession().createCriteria(getPersistentClass()); + c.add(Restrictions.eq("activo", Boolean.TRUE)); + c.add(Restrictions.eq("descricao", descricaoPracaPedagio)); + return c.list(); + } +} \ No newline at end of file diff --git a/src/com/rjconsultores/ventaboletos/entidad/PracaPedagio.java b/src/com/rjconsultores/ventaboletos/entidad/PracaPedagio.java new file mode 100644 index 000000000..bf943c016 --- /dev/null +++ b/src/com/rjconsultores/ventaboletos/entidad/PracaPedagio.java @@ -0,0 +1,129 @@ +package com.rjconsultores.ventaboletos.entidad; + +import java.io.Serializable; +import java.math.BigDecimal; +import java.util.Date; + +import javax.persistence.Basic; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.SequenceGenerator; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; + +@Entity +@SequenceGenerator(name="CASETA_PEAJE_SEQ", sequenceName="CASETA_PEAJE_SEQ", allocationSize=1) +@Table(name="CASETA_PEAJE") +public class PracaPedagio implements Serializable { + + private static final long serialVersionUID = 1L; + + @Id + @GeneratedValue(strategy = GenerationType.AUTO, generator = "CASETA_PEAJE_SEQ") + @Basic(optional = false) + @Column(name = "CASETAPEAJE_ID") + private Integer pracaPedagioId; + + @Column(name="DESCCASETA", unique = true) + private String descricao; + + @Column(name="IMPORTEIDA") + private BigDecimal quantiaIda; + + @Column(name="IMPORTEVUELTA") + private BigDecimal quantiaVolta; + + @Column(name = "ACTIVO") + private Boolean activo; + + @Column(name = "FECMODIF") + @Temporal(TemporalType.TIMESTAMP) + private Date fecmodif; + + @Column(name = "USUARIO_ID") + private Integer usuarioId; + + @Override + public int hashCode() { + int hash = 0; + hash += pracaPedagioId != null ? pracaPedagioId.hashCode() : 0; + return hash; + } + + @Override + public boolean equals(Object object) { + if (!(object instanceof PracaPedagio)) { + return false; + } + PracaPedagio other = (PracaPedagio) object; + if ((this.pracaPedagioId == null && other.pracaPedagioId != null) || (this.pracaPedagioId != null && !this.pracaPedagioId.equals(other.pracaPedagioId))) { + return false; + } + return true; + } + + @Override + public String toString() { + return this.pracaPedagioId + " - " + this.descricao; + } + + public Integer getPracaPedagioId() { + return pracaPedagioId; + } + + public void setPracaPedagioId(Integer pracaPedagioId) { + this.pracaPedagioId = pracaPedagioId; + } + + public String getDescricao() { + return descricao; + } + + public void setDescricao(String descricao) { + this.descricao = descricao; + } + + public BigDecimal getQuantiaIda() { + return quantiaIda; + } + + public void setQuantiaIda(BigDecimal quantiaIda) { + this.quantiaIda = quantiaIda; + } + + public BigDecimal getQuantiaVolta() { + return quantiaVolta; + } + + public void setQuantiaVolta(BigDecimal quantiaVolta) { + this.quantiaVolta = quantiaVolta; + } + + public Boolean getActivo() { + return activo; + } + + public void setActivo(Boolean activo) { + this.activo = activo; + } + + public Date getFecmodif() { + return fecmodif; + } + + public void setFecmodif(Date fecmodif) { + this.fecmodif = fecmodif; + } + + public Integer getUsuarioId() { + return usuarioId; + } + + public void setUsuarioId(Integer usuarioId) { + this.usuarioId = usuarioId; + } +} \ No newline at end of file diff --git a/src/com/rjconsultores/ventaboletos/service/PracaPedagioService.java b/src/com/rjconsultores/ventaboletos/service/PracaPedagioService.java new file mode 100644 index 000000000..60300e259 --- /dev/null +++ b/src/com/rjconsultores/ventaboletos/service/PracaPedagioService.java @@ -0,0 +1,10 @@ +package com.rjconsultores.ventaboletos.service; + +import java.util.List; + +import com.rjconsultores.ventaboletos.entidad.PracaPedagio; + +public interface PracaPedagioService extends GenericService { + public List buscar(String descricaoPracaPedagio); + public Boolean validarDescricaoPracaPedagio(PracaPedagio pracaPedagio); +} \ No newline at end of file diff --git a/src/com/rjconsultores/ventaboletos/service/impl/PracaPedagioServiceImpl.java b/src/com/rjconsultores/ventaboletos/service/impl/PracaPedagioServiceImpl.java new file mode 100644 index 000000000..a66fb7d00 --- /dev/null +++ b/src/com/rjconsultores/ventaboletos/service/impl/PracaPedagioServiceImpl.java @@ -0,0 +1,78 @@ +package com.rjconsultores.ventaboletos.service.impl; + +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; + +import com.rjconsultores.ventaboletos.dao.PracaPedagioDAO; +import com.rjconsultores.ventaboletos.entidad.PracaPedagio; +import com.rjconsultores.ventaboletos.service.PracaPedagioService; +import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado; + +@Service("pracaPedagioService") +public class PracaPedagioServiceImpl implements PracaPedagioService { + + @Autowired + private PracaPedagioDAO pracaPedagioDAO; + + @Override + public List obtenerTodos() { + return pracaPedagioDAO.obtenerTodos(); + } + + @Transactional + public PracaPedagio obtenerID(Integer id) { + return pracaPedagioDAO.obtenerID(id); + } + + @Transactional + public PracaPedagio suscribir(PracaPedagio entidad) { + entidad.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId()); + entidad.setFecmodif(Calendar.getInstance().getTime()); + entidad.setActivo(Boolean.TRUE); + return pracaPedagioDAO.suscribir(entidad); + } + + @Transactional + public PracaPedagio actualizacion(PracaPedagio entidad) { + entidad.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId()); + entidad.setFecmodif(Calendar.getInstance().getTime()); + entidad.setActivo(Boolean.TRUE); + return pracaPedagioDAO.actualizacion(entidad); + } + + @Transactional + public void borrar(PracaPedagio entidad) { + entidad.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId()); + entidad.setFecmodif(Calendar.getInstance().getTime()); + entidad.setActivo(Boolean.FALSE); + pracaPedagioDAO.actualizacion(entidad); + } + + @Override + public List buscar(String descricaoPracaPedagio) { + return pracaPedagioDAO.buscar(descricaoPracaPedagio); + } + + @Override + public Boolean validarDescricaoPracaPedagio(PracaPedagio pracaPedagio) { + List pracas = buscar(pracaPedagio.getDescricao()); + + if(pracaPedagio.getPracaPedagioId() == null) { + if(pracas.isEmpty()){ + return Boolean.TRUE; + } + } else { + if(pracas.isEmpty() || pracas.get(0).getPracaPedagioId().equals(pracaPedagio.getPracaPedagioId())) { + return Boolean.TRUE; + } else { + return Boolean.FALSE; + } + } + + return Boolean.FALSE; + } +} \ No newline at end of file