From c77d9236838aff2c4173d47270a8a86a601d9b7f Mon Sep 17 00:00:00 2001 From: leonardo Date: Thu, 24 Jul 2014 13:32:14 +0000 Subject: [PATCH] W2i - Parametrizar Serie por Empresa (fixed bug #5522) git-svn-id: http://desenvolvimento.rjconsultores.com.br/repositorio/sco/AdmVenta/Model/trunk/modelWeb@36808 d1611594-4594-4d17-8e1d-87c2c4800839 --- .../dao/SeguradoraEmpresaDAO.java | 8 ++ .../SeguradoraEmpresaHibernateDAO.java | 39 +++++++++ .../entidad/SeguradoraEmpresa.java | 80 +++++++++++++++++++ .../service/SeguradoraEmpresaService.java | 9 +++ .../impl/SeguradoraEmpresaServiceImpl.java | 56 +++++++++++++ 5 files changed, 192 insertions(+) create mode 100644 src/com/rjconsultores/ventaboletos/dao/SeguradoraEmpresaDAO.java create mode 100644 src/com/rjconsultores/ventaboletos/dao/hibernate/SeguradoraEmpresaHibernateDAO.java create mode 100644 src/com/rjconsultores/ventaboletos/entidad/SeguradoraEmpresa.java create mode 100644 src/com/rjconsultores/ventaboletos/service/SeguradoraEmpresaService.java create mode 100644 src/com/rjconsultores/ventaboletos/service/impl/SeguradoraEmpresaServiceImpl.java diff --git a/src/com/rjconsultores/ventaboletos/dao/SeguradoraEmpresaDAO.java b/src/com/rjconsultores/ventaboletos/dao/SeguradoraEmpresaDAO.java new file mode 100644 index 000000000..6c9e674f3 --- /dev/null +++ b/src/com/rjconsultores/ventaboletos/dao/SeguradoraEmpresaDAO.java @@ -0,0 +1,8 @@ +package com.rjconsultores.ventaboletos.dao; + +import com.rjconsultores.ventaboletos.entidad.Empresa; +import com.rjconsultores.ventaboletos.entidad.SeguradoraEmpresa; + +public interface SeguradoraEmpresaDAO extends GenericDAO { + public boolean existe(Empresa empresa, String serie); +} diff --git a/src/com/rjconsultores/ventaboletos/dao/hibernate/SeguradoraEmpresaHibernateDAO.java b/src/com/rjconsultores/ventaboletos/dao/hibernate/SeguradoraEmpresaHibernateDAO.java new file mode 100644 index 000000000..c654426ba --- /dev/null +++ b/src/com/rjconsultores/ventaboletos/dao/hibernate/SeguradoraEmpresaHibernateDAO.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.SeguradoraEmpresaDAO; +import com.rjconsultores.ventaboletos.entidad.Empresa; +import com.rjconsultores.ventaboletos.entidad.SeguradoraEmpresa; + +@Repository("seguradoraEmpresaDAO") +public class SeguradoraEmpresaHibernateDAO extends GenericHibernateDAO implements SeguradoraEmpresaDAO { + + @Autowired + public SeguradoraEmpresaHibernateDAO(@Qualifier("sessionFactory") SessionFactory factory) { + setSessionFactory(factory); + } + + public List obtenerTodos() { + Criteria c = makeCriteria(); + c.add(Restrictions.eq("activo", Boolean.TRUE)); + + return c.list(); + } + + public boolean existe(Empresa empresa, String serie){ + Criteria c = makeCriteria(); + c.add(Restrictions.eq("activo", Boolean.TRUE)); + c.add(Restrictions.eq("empresa", empresa)); + c.add(Restrictions.eq("serie", serie)); + + return !c.list().isEmpty(); + } +} diff --git a/src/com/rjconsultores/ventaboletos/entidad/SeguradoraEmpresa.java b/src/com/rjconsultores/ventaboletos/entidad/SeguradoraEmpresa.java new file mode 100644 index 000000000..b0b23bc84 --- /dev/null +++ b/src/com/rjconsultores/ventaboletos/entidad/SeguradoraEmpresa.java @@ -0,0 +1,80 @@ +package com.rjconsultores.ventaboletos.entidad; + +import java.io.Serializable; +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.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.SequenceGenerator; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; + +@Entity +@SequenceGenerator(name = "SEGURADORA_EMPRESA_SEQ", sequenceName = "SEGURADORA_EMPRESA_SEQ", allocationSize = 1) +@Table(name = "SEGURADORA_EMPRESA") +public class SeguradoraEmpresa implements Serializable { + + private static final long serialVersionUID = 1L; + + @Id + @Basic(optional = false) + @GeneratedValue(strategy = GenerationType.AUTO, generator = "SEGURADORA_EMPRESA_SEQ") + @Column(name = "SEGURADORAEMPRESA_ID ") + private Integer seguradoraEmpresaId; + @JoinColumn(name = "EMPRESA_ID", referencedColumnName = "EMPRESA_ID") + @ManyToOne + private Empresa empresa; + @Column(name = "SERIESEGURADORA") + private String serie; + @Column(name = "ACTIVO") + private Boolean activo; + @Column(name = "FECMODIF") + @Temporal(TemporalType.TIMESTAMP) + private Date fecmodif; + @Column(name = "USUARIO_ID") + private Integer usuarioId; + + public Integer getSeguradoraEmpresaId() { + return seguradoraEmpresaId; + } + public void setSeguradoraEmpresaId(Integer seguradoraEmpresaId) { + this.seguradoraEmpresaId = seguradoraEmpresaId; + } + public Empresa getEmpresa() { + return empresa; + } + public void setEmpresa(Empresa empresa) { + this.empresa = empresa; + } + 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; + } + public String getSerie() { + return serie; + } + public void setSerie(String serie) { + this.serie = serie; + } +} diff --git a/src/com/rjconsultores/ventaboletos/service/SeguradoraEmpresaService.java b/src/com/rjconsultores/ventaboletos/service/SeguradoraEmpresaService.java new file mode 100644 index 000000000..21522ece5 --- /dev/null +++ b/src/com/rjconsultores/ventaboletos/service/SeguradoraEmpresaService.java @@ -0,0 +1,9 @@ +package com.rjconsultores.ventaboletos.service; + +import com.rjconsultores.ventaboletos.entidad.Empresa; +import com.rjconsultores.ventaboletos.entidad.SeguradoraEmpresa; + +public interface SeguradoraEmpresaService extends GenericService{ + public boolean existe(Empresa empresa, String serie); + +} \ No newline at end of file diff --git a/src/com/rjconsultores/ventaboletos/service/impl/SeguradoraEmpresaServiceImpl.java b/src/com/rjconsultores/ventaboletos/service/impl/SeguradoraEmpresaServiceImpl.java new file mode 100644 index 000000000..deb650616 --- /dev/null +++ b/src/com/rjconsultores/ventaboletos/service/impl/SeguradoraEmpresaServiceImpl.java @@ -0,0 +1,56 @@ +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.SeguradoraEmpresaDAO; +import com.rjconsultores.ventaboletos.entidad.Empresa; +import com.rjconsultores.ventaboletos.entidad.SeguradoraEmpresa; +import com.rjconsultores.ventaboletos.service.SeguradoraEmpresaService; +import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado; + +@Service("seguradoraEmpresaService") +public class SeguradoraEmpresaServiceImpl implements SeguradoraEmpresaService { + + @Autowired + private SeguradoraEmpresaDAO seguradoraEmpresaDAO; + + public List obtenerTodos() { + return seguradoraEmpresaDAO.obtenerTodos(); + } + + public SeguradoraEmpresa obtenerID(Integer id) { + return seguradoraEmpresaDAO.obtenerID(id); + } + + public boolean existe(Empresa empresa, String serie){ + return seguradoraEmpresaDAO.existe(empresa, serie); + } + + @Transactional + public SeguradoraEmpresa suscribir(SeguradoraEmpresa entidad) { + entidad.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId()); + entidad.setFecmodif(Calendar.getInstance().getTime()); + entidad.setActivo(Boolean.TRUE); + + return seguradoraEmpresaDAO.suscribir(entidad); + } + + @Transactional + public SeguradoraEmpresa actualizacion(SeguradoraEmpresa entidad) { + return seguradoraEmpresaDAO.actualizacion(entidad); + } + + @Transactional + public void borrar(SeguradoraEmpresa entidad) { + entidad.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId()); + entidad.setFecmodif(Calendar.getInstance().getTime()); + entidad.setActivo(Boolean.FALSE); + + seguradoraEmpresaDAO.borrar(entidad); + } +}