From 00f59411140e2eda0eeba9844cf21061161d921d Mon Sep 17 00:00:00 2001 From: leonardo Date: Mon, 16 May 2016 19:29:43 +0000 Subject: [PATCH] fixes bug #7448 git-svn-id: http://desenvolvimento.rjconsultores.com.br/repositorio/sco/AdmVenta/Model/trunk/modelWeb@56023 d1611594-4594-4d17-8e1d-87c2c4800839 --- .../dao/SecretariaEmpresaDAO.java | 11 ++ .../SecretariaEmpresaHibernateDAO.java | 33 ++++++ .../ventaboletos/entidad/Secretaria.java | 53 ++++++++- .../entidad/SecretariaEmpresa.java | 108 ++++++++++++++++++ .../service/SecretariaEmpresaService.java | 11 ++ .../impl/SecretariaEmpresaServiceImpl.java | 58 ++++++++++ 6 files changed, 272 insertions(+), 2 deletions(-) create mode 100644 src/com/rjconsultores/ventaboletos/dao/SecretariaEmpresaDAO.java create mode 100644 src/com/rjconsultores/ventaboletos/dao/hibernate/SecretariaEmpresaHibernateDAO.java create mode 100644 src/com/rjconsultores/ventaboletos/entidad/SecretariaEmpresa.java create mode 100644 src/com/rjconsultores/ventaboletos/service/SecretariaEmpresaService.java create mode 100644 src/com/rjconsultores/ventaboletos/service/impl/SecretariaEmpresaServiceImpl.java diff --git a/src/com/rjconsultores/ventaboletos/dao/SecretariaEmpresaDAO.java b/src/com/rjconsultores/ventaboletos/dao/SecretariaEmpresaDAO.java new file mode 100644 index 000000000..3975ecf8f --- /dev/null +++ b/src/com/rjconsultores/ventaboletos/dao/SecretariaEmpresaDAO.java @@ -0,0 +1,11 @@ +package com.rjconsultores.ventaboletos.dao; + +import java.util.List; + +import com.rjconsultores.ventaboletos.entidad.Secretaria; +import com.rjconsultores.ventaboletos.entidad.SecretariaEmpresa; + +public interface SecretariaEmpresaDAO extends GenericDAO { + + public List buscarPorSecretaria(Secretaria secretaria); +} diff --git a/src/com/rjconsultores/ventaboletos/dao/hibernate/SecretariaEmpresaHibernateDAO.java b/src/com/rjconsultores/ventaboletos/dao/hibernate/SecretariaEmpresaHibernateDAO.java new file mode 100644 index 000000000..609fa3771 --- /dev/null +++ b/src/com/rjconsultores/ventaboletos/dao/hibernate/SecretariaEmpresaHibernateDAO.java @@ -0,0 +1,33 @@ +package com.rjconsultores.ventaboletos.dao.hibernate; + +import java.util.List; + +import org.hibernate.Criteria; +import org.hibernate.HibernateException; +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.SecretariaEmpresaDAO; +import com.rjconsultores.ventaboletos.entidad.Secretaria; +import com.rjconsultores.ventaboletos.entidad.SecretariaEmpresa; + +@Repository("secretariaEmpresaDAO") +public class SecretariaEmpresaHibernateDAO extends GenericHibernateDAO + implements SecretariaEmpresaDAO { + + @Autowired + public SecretariaEmpresaHibernateDAO(@Qualifier("sessionFactory") SessionFactory factory) { + setSessionFactory(factory); + } + + public List buscarPorSecretaria(Secretaria secretaria) { + Criteria c = getSession().createCriteria(getPersistentClass()); + c.add(Restrictions.eq("activo", Boolean.TRUE)); + c.add(Restrictions.eq("secretaria", secretaria)); + + return c.list(); + } +} diff --git a/src/com/rjconsultores/ventaboletos/entidad/Secretaria.java b/src/com/rjconsultores/ventaboletos/entidad/Secretaria.java index 5fa06b9dd..3f155fa85 100644 --- a/src/com/rjconsultores/ventaboletos/entidad/Secretaria.java +++ b/src/com/rjconsultores/ventaboletos/entidad/Secretaria.java @@ -6,8 +6,10 @@ package com.rjconsultores.ventaboletos.entidad; import java.io.Serializable; import java.util.ArrayList; +import java.util.Calendar; import java.util.Date; import java.util.List; + import javax.persistence.Basic; import javax.persistence.CascadeType; import javax.persistence.Column; @@ -22,6 +24,11 @@ import javax.persistence.Table; import javax.persistence.Temporal; import javax.persistence.TemporalType; +import org.hibernate.annotations.LazyCollection; +import org.hibernate.annotations.LazyCollectionOption; + +import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado; + /** * * @author Administrador @@ -58,10 +65,37 @@ public class Secretaria implements Serializable { @OneToMany(cascade = CascadeType.ALL) @JoinColumn(name = "SECRETARIA_ID") private List lsCuponSecretaria; - + @OneToMany(cascade = CascadeType.ALL, mappedBy = "secretaria") + @LazyCollection(LazyCollectionOption.FALSE) + private List empresas = new ArrayList(); + public Secretaria() { } + public SecretariaEmpresa addEmpresa(Empresa e) { + SecretariaEmpresa se = new SecretariaEmpresa(); + se.setEmpresa(e); + se.setSecretaria(this); + se.setActivo(Boolean.TRUE); + se.setFecmodif(Calendar.getInstance().getTime()); + se.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId()); + this.empresas.add(se); + return se; + } + + public void removeEmpresa(SecretariaEmpresa e) { + this.empresas.remove(e); + } + + public void removeEmpresa(Empresa e) { + for (SecretariaEmpresa se : empresas) { + if (se.getEmpresa().equals(e)) { + this.empresas.remove(e); + break; + } + } + } + public Secretaria(Integer secretariaId) { this.secretariaId = secretariaId; } @@ -144,7 +178,22 @@ public class Secretaria implements Serializable { return tmp; } - public void setLsCuponSecretaria(List lsCuponSecretaria) { + + public List getEmpresas() { + List lista = new ArrayList(); + for (SecretariaEmpresa eb : empresas) { + if (eb.getActivo()) { + lista.add(eb); + } + } + return lista; + } + + public void setEmpresas(List empresas) { + this.empresas = empresas; + } + + public void setLsCuponSecretaria(List lsCuponSecretaria) { this.lsCuponSecretaria = lsCuponSecretaria; } diff --git a/src/com/rjconsultores/ventaboletos/entidad/SecretariaEmpresa.java b/src/com/rjconsultores/ventaboletos/entidad/SecretariaEmpresa.java new file mode 100644 index 000000000..2b5e82de5 --- /dev/null +++ b/src/com/rjconsultores/ventaboletos/entidad/SecretariaEmpresa.java @@ -0,0 +1,108 @@ +package com.rjconsultores.ventaboletos.entidad; + +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 = "SECRETARIA_EMPRESA_SEQ", sequenceName = "SECRETARIA_EMPRESA_SEQ", allocationSize = 1) +@Table(name = "SECRETARIA_EMPRESA") +public class SecretariaEmpresa { + private static final long serialVersionUID = 1L; + @Id + @Basic(optional = false) + @GeneratedValue(strategy = GenerationType.AUTO, generator = "SECRETARIA_EMPRESA_SEQ") + @Column(name = "SECRETARIAEMPRESA_ID") + private Integer secretariaempresaId; + @ManyToOne + @JoinColumn(name = "SECRETARIA_ID") + private Secretaria secretaria; + @ManyToOne + @JoinColumn(name = "EMPRESA_ID") + private Empresa empresa; + + @Column(name = "FECMODIF") + @Temporal(TemporalType.TIMESTAMP) + private Date fecmodif; + @Column(name = "USUARIO_ID") + private Integer usuarioId; + @Column(name = "ACTIVO") + private Boolean activo; + + public SecretariaEmpresa(){ + this.activo = true; + } + + public Integer getSecretariaempresaId() { + return secretariaempresaId; + } + public void setSecretariaempresaId(Integer secretariaempresaId) { + this.secretariaempresaId = secretariaempresaId; + } + public Secretaria getSecretaria() { + return secretaria; + } + public void setSecretaria(Secretaria secretaria) { + this.secretaria = secretaria; + } + public Empresa getEmpresa() { + return empresa; + } + public void setEmpresa(Empresa empresa) { + this.empresa = empresa; + } + 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 Boolean getActivo() { + return activo; + } + public void setActivo(Boolean activo) { + this.activo = activo; + } + + @Override + public int hashCode() { + int hash = 0; + hash += (secretariaempresaId != null ? secretariaempresaId.hashCode() : 0); + return hash; + } + + @Override + public boolean equals(Object object) { + // TODO: Warning - this method won't work in the case the id fields are not set + if (!(object instanceof SecretariaEmpresa)) { + return false; + } + SecretariaEmpresa other = (SecretariaEmpresa) object; + if ((this.secretariaempresaId == null && other.secretariaempresaId != null) || (this.secretariaempresaId != null && !this.secretariaempresaId.equals(other.secretariaempresaId))) { + return false; + } + return true; + } + + @Override + public String toString() { + return "com.rjconsultores.ventaboletos.entidad.SecretariaEmpresa[secretariaempresaId=" + secretariaempresaId + "]"; + } +} diff --git a/src/com/rjconsultores/ventaboletos/service/SecretariaEmpresaService.java b/src/com/rjconsultores/ventaboletos/service/SecretariaEmpresaService.java new file mode 100644 index 000000000..20c06c157 --- /dev/null +++ b/src/com/rjconsultores/ventaboletos/service/SecretariaEmpresaService.java @@ -0,0 +1,11 @@ +package com.rjconsultores.ventaboletos.service; + +import java.util.List; + +import com.rjconsultores.ventaboletos.entidad.Secretaria; +import com.rjconsultores.ventaboletos.entidad.SecretariaEmpresa; + +public interface SecretariaEmpresaService extends GenericService { + + public List buscarPorSecretaria(Secretaria secretaria); +} diff --git a/src/com/rjconsultores/ventaboletos/service/impl/SecretariaEmpresaServiceImpl.java b/src/com/rjconsultores/ventaboletos/service/impl/SecretariaEmpresaServiceImpl.java new file mode 100644 index 000000000..df68a6782 --- /dev/null +++ b/src/com/rjconsultores/ventaboletos/service/impl/SecretariaEmpresaServiceImpl.java @@ -0,0 +1,58 @@ +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.SecretariaEmpresaDAO; +import com.rjconsultores.ventaboletos.entidad.Secretaria; +import com.rjconsultores.ventaboletos.entidad.SecretariaEmpresa; +import com.rjconsultores.ventaboletos.service.SecretariaEmpresaService; +import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado; + +@Service("secretariaEmpresaService") +public class SecretariaEmpresaServiceImpl implements SecretariaEmpresaService { + + @Autowired + private SecretariaEmpresaDAO secretariaEmpresaDAO; + + public List obtenerTodos() { + return secretariaEmpresaDAO.obtenerTodos(); + } + + public SecretariaEmpresa obtenerID(Integer id) { + return secretariaEmpresaDAO.obtenerID(id); + } + + @Transactional + public SecretariaEmpresa suscribir(SecretariaEmpresa entidad) { + entidad.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId()); + entidad.setFecmodif(Calendar.getInstance().getTime()); + entidad.setActivo(Boolean.TRUE); + + return secretariaEmpresaDAO.suscribir(entidad); + } + + @Transactional + public SecretariaEmpresa actualizacion(SecretariaEmpresa entidad) { + entidad.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId()); + entidad.setFecmodif(Calendar.getInstance().getTime()); + entidad.setActivo(Boolean.TRUE); + + return secretariaEmpresaDAO.actualizacion(entidad); + } + + @Transactional + public void borrar(SecretariaEmpresa entidad) { + secretariaEmpresaDAO.borrar(entidad); + } + + + @Override + public List buscarPorSecretaria(Secretaria secretaria){ + return secretariaEmpresaDAO.buscarPorSecretaria(secretaria); + } +}