From 8c6964162d7d665acb69e159e47384305d60db22 Mon Sep 17 00:00:00 2001 From: "valdir.cordeiro" Date: Fri, 10 Nov 2023 10:37:38 -0300 Subject: [PATCH 01/10] =?UTF-8?q?bug#al-3254=2066363=20-=20Servi=C3=A7os?= =?UTF-8?q?=20-=20Ajustes=20na=20Tela=20de=20Configura=C3=A7=C3=A3o=20de?= =?UTF-8?q?=20Servi=C3=A7o=20na=20ADM=20dev:=20qua:?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- .../dao/HeaderEsquemaCorridaDAO.java | 10 ++ .../HeaderEsquemaCorridaHibernateDAO.java | 35 ++++++ .../entidad/HeaderTabelaEsquemaCorrida.java | 60 ++++++++++ .../service/HeaderEsquemaCorridaService.java | 12 ++ .../impl/HeaderEsquemaCorridaServiceImpl.java | 103 ++++++++++++++++++ 6 files changed, 221 insertions(+), 1 deletion(-) create mode 100644 src/com/rjconsultores/ventaboletos/dao/HeaderEsquemaCorridaDAO.java create mode 100644 src/com/rjconsultores/ventaboletos/dao/hibernate/HeaderEsquemaCorridaHibernateDAO.java create mode 100644 src/com/rjconsultores/ventaboletos/entidad/HeaderTabelaEsquemaCorrida.java create mode 100644 src/com/rjconsultores/ventaboletos/service/HeaderEsquemaCorridaService.java create mode 100644 src/com/rjconsultores/ventaboletos/service/impl/HeaderEsquemaCorridaServiceImpl.java diff --git a/pom.xml b/pom.xml index 143097f80..6b92e468a 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 br.com.rjconsultores ModelWeb - 1.19.1 + 1.20.0 diff --git a/src/com/rjconsultores/ventaboletos/dao/HeaderEsquemaCorridaDAO.java b/src/com/rjconsultores/ventaboletos/dao/HeaderEsquemaCorridaDAO.java new file mode 100644 index 000000000..d052dee20 --- /dev/null +++ b/src/com/rjconsultores/ventaboletos/dao/HeaderEsquemaCorridaDAO.java @@ -0,0 +1,10 @@ +package com.rjconsultores.ventaboletos.dao; + +import com.rjconsultores.ventaboletos.entidad.HeaderTabelaEsquemaCorrida; + +public interface HeaderEsquemaCorridaDAO extends GenericDAO { + + public HeaderTabelaEsquemaCorrida buscarHeader(); + + +} diff --git a/src/com/rjconsultores/ventaboletos/dao/hibernate/HeaderEsquemaCorridaHibernateDAO.java b/src/com/rjconsultores/ventaboletos/dao/hibernate/HeaderEsquemaCorridaHibernateDAO.java new file mode 100644 index 000000000..a8f030bfd --- /dev/null +++ b/src/com/rjconsultores/ventaboletos/dao/hibernate/HeaderEsquemaCorridaHibernateDAO.java @@ -0,0 +1,35 @@ +package com.rjconsultores.ventaboletos.dao.hibernate; + +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.HeaderEsquemaCorridaDAO; +import com.rjconsultores.ventaboletos.entidad.HeaderTabelaEsquemaCorrida; + +@Repository("headerEsquemaCorridaHibernateDAO") +public class HeaderEsquemaCorridaHibernateDAO extends GenericHibernateDAO implements HeaderEsquemaCorridaDAO { + + @Autowired + public HeaderEsquemaCorridaHibernateDAO(@Qualifier("sessionFactory") SessionFactory factory) { + setSessionFactory(factory); + } + + @Override + public HeaderTabelaEsquemaCorrida buscarHeader() { + try { + Criteria c = getSession().createCriteria(getPersistentClass()); + c.add(Restrictions.eq("headerEsquemaCorridaId", 1)); + + c.setMaxResults(1); + + return (HeaderTabelaEsquemaCorrida) c.uniqueResult(); + } catch (Exception e) { + return null; + } + } + +} diff --git a/src/com/rjconsultores/ventaboletos/entidad/HeaderTabelaEsquemaCorrida.java b/src/com/rjconsultores/ventaboletos/entidad/HeaderTabelaEsquemaCorrida.java new file mode 100644 index 000000000..0f52fa5ed --- /dev/null +++ b/src/com/rjconsultores/ventaboletos/entidad/HeaderTabelaEsquemaCorrida.java @@ -0,0 +1,60 @@ +/** + * + */ +package com.rjconsultores.ventaboletos.entidad; + +import java.io.Serializable; + +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; + +/** + * @author valdir.cordeiro + * + */ +@Entity +@SequenceGenerator(name = "HEADER_ESQUEMA_CORRIDA_SEQ", sequenceName = "HEADER_ESQUEMA_CORRIDA_SEQ", allocationSize = 1) +@Table(name = "HEADER_ESQUEMA_CORRIDA") +public class HeaderTabelaEsquemaCorrida implements Serializable{ + + private static final long serialVersionUID = 1L; + @Id + @Basic(optional = false) + @Column(name = "HEADERESQUEMACORRIDA_ID") + @GeneratedValue(strategy = GenerationType.AUTO, generator = "HEADER_ESQUEMA_CORRIDA_SEQ") + private Integer headerEsquemaCorridaId; + + @Column(name = "SEQUENCIA_HEADER") + private String sequenciaHeader; + + public HeaderTabelaEsquemaCorrida() { + super(); + } + + public HeaderTabelaEsquemaCorrida(int id, String sequencia) { + this.headerEsquemaCorridaId = id; + this.sequenciaHeader = sequencia; + } + + public Integer getHeaderEsquemaCorridaId() { + return headerEsquemaCorridaId; + } + + public void setHeaderEsquemaCorridaId(Integer headerEsquemaCorridaId) { + this.headerEsquemaCorridaId = headerEsquemaCorridaId; + } + + public String getSequenciaHeader() { + return sequenciaHeader; + } + + public void setSequenciaHeader(String sequenciaHeader) { + this.sequenciaHeader = sequenciaHeader; + } +} diff --git a/src/com/rjconsultores/ventaboletos/service/HeaderEsquemaCorridaService.java b/src/com/rjconsultores/ventaboletos/service/HeaderEsquemaCorridaService.java new file mode 100644 index 000000000..e1178f508 --- /dev/null +++ b/src/com/rjconsultores/ventaboletos/service/HeaderEsquemaCorridaService.java @@ -0,0 +1,12 @@ +package com.rjconsultores.ventaboletos.service; + +import com.rjconsultores.ventaboletos.entidad.HeaderTabelaEsquemaCorrida; + +public interface HeaderEsquemaCorridaService extends GenericService { + + public Integer[] buscarHeader(); + + public void salvarPosicoesHeader(Integer[] posicoesColunasTabela); + + +} diff --git a/src/com/rjconsultores/ventaboletos/service/impl/HeaderEsquemaCorridaServiceImpl.java b/src/com/rjconsultores/ventaboletos/service/impl/HeaderEsquemaCorridaServiceImpl.java new file mode 100644 index 000000000..0f959881e --- /dev/null +++ b/src/com/rjconsultores/ventaboletos/service/impl/HeaderEsquemaCorridaServiceImpl.java @@ -0,0 +1,103 @@ +package com.rjconsultores.ventaboletos.service.impl; + +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.HeaderEsquemaCorridaDAO; +import com.rjconsultores.ventaboletos.entidad.HeaderTabelaEsquemaCorrida; +import com.rjconsultores.ventaboletos.service.HeaderEsquemaCorridaService; + +@Service("headerEsquemaCorridaService") +public class HeaderEsquemaCorridaServiceImpl implements HeaderEsquemaCorridaService { + + @Autowired + private HeaderEsquemaCorridaDAO headerEsquemaCorridaDAO; + + @Override + public List obtenerTodos() { + return null; + } + + @Override + public HeaderTabelaEsquemaCorrida obtenerID(Integer id) { + return null; + } + + @Override + public Integer[] buscarHeader() { + HeaderTabelaEsquemaCorrida header = headerEsquemaCorridaDAO.buscarHeader(); + + if(header == null) { + //Se for nulo retorna com o valor padrao + header = new HeaderTabelaEsquemaCorrida(1, "1,2,3,4,5,6,7,8,9,10,11,12,13,14,15"); + } + + String headerString = header.getSequenciaHeader(); + + String[] arrayString = headerString.split(","); + + Integer[] arrayInt = new Integer[15]; + + int i = 0; + for(String pos : arrayString) { + arrayInt[i] = Integer.valueOf(pos); + i++; + } + + return arrayInt; + } + + @Override + @Transactional + public HeaderTabelaEsquemaCorrida suscribir(HeaderTabelaEsquemaCorrida entidad) { + //o Id vai ser sempre 1 + entidad.setHeaderEsquemaCorridaId(1); + return headerEsquemaCorridaDAO.suscribir(entidad); + } + + @Override + @Transactional + public HeaderTabelaEsquemaCorrida actualizacion(HeaderTabelaEsquemaCorrida entidad) { + entidad.setHeaderEsquemaCorridaId(1); + return headerEsquemaCorridaDAO.actualizacion(entidad); + } + + @Override + public void borrar(HeaderTabelaEsquemaCorrida entidad) { + // TODO Auto-generated method stub + } + + @Override + @Transactional + public void salvarPosicoesHeader(Integer[] posicoesColunasTabela) { + HeaderTabelaEsquemaCorrida header = headerEsquemaCorridaDAO.buscarHeader(); + + StringBuilder pos = new StringBuilder(); + + int i = 1; + for(Integer posicao : posicoesColunasTabela) { + + if(i < 15) { + pos.append(posicao).append(","); + } else { + pos.append(posicao); + } + + i++; + } + + if(header == null) { + //Se for nulo retorna com o valor padrao + header = new HeaderTabelaEsquemaCorrida(1, pos.toString()); + suscribir(header); + } else { + header.setSequenciaHeader(pos.toString()); + actualizacion(header); + } + + } + +} From 2477ccf760e8f93b3dd5621fc540b89f75c0cc20 Mon Sep 17 00:00:00 2001 From: "wallace.henrique" Date: Fri, 10 Nov 2023 15:01:04 -0300 Subject: [PATCH 02/10] fixes bug#AL-3351 dev: qua: --- pom.xml | 2 +- .../ventaboletos/entidad/PuntoVenta.java | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 6b92e468a..10da69d61 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 br.com.rjconsultores ModelWeb - 1.20.0 + 1.21.0 diff --git a/src/com/rjconsultores/ventaboletos/entidad/PuntoVenta.java b/src/com/rjconsultores/ventaboletos/entidad/PuntoVenta.java index 061e1ae88..7e9007657 100644 --- a/src/com/rjconsultores/ventaboletos/entidad/PuntoVenta.java +++ b/src/com/rjconsultores/ventaboletos/entidad/PuntoVenta.java @@ -346,6 +346,9 @@ public class PuntoVenta implements Serializable, Auditavel { @Column(name = "INDBLOQUEARDESCONTOWEB") private Boolean indBloquearDescontoWEB; + @Column(name = "INDTAXACONVENIENCIAORGAOCONCEDENTE") + private Boolean indTaxaConvenienciaOrgaoConcedente; + public List getCobrancaAdicionalList() { return cobrancaAdicionalList; } @@ -1377,6 +1380,13 @@ public class PuntoVenta implements Serializable, Auditavel { public void setTempoMaxServicoEmVenda(Integer tempoMaxServicoEmVenda) { this.tempoMaxServicoEmVenda = tempoMaxServicoEmVenda; } - - + + public Boolean getIndTaxaConvenienciaOrgaoConcedente() { + return indTaxaConvenienciaOrgaoConcedente; + } + + public void setIndTaxaConvenienciaOrgaoConcedente(Boolean indTaxaConvenienciaOrgaoConcedente) { + this.indTaxaConvenienciaOrgaoConcedente = indTaxaConvenienciaOrgaoConcedente; + } + } \ No newline at end of file From d8f05b4be61dbda950a12328455c26eb979548d2 Mon Sep 17 00:00:00 2001 From: Gleimar Botelho Baleeiro Date: Tue, 14 Nov 2023 17:14:01 -0300 Subject: [PATCH 03/10] =?UTF-8?q?Implementa=C3=A7=C3=A3o=20do=20fluxo=20de?= =?UTF-8?q?=20autoriza=C3=A7=C3=A3o=20para=20novas=20empresas?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 7 + .../ventaboletos/dao/EmpresaDAO.java | 2 + .../dao/hibernate/EmpresaHibernateDAO.java | 33 ++++ .../ventaboletos/entidad/Empresa.java | 25 +++ .../ventaboletos/entidad/Usuario.java | 21 ++- .../ventaboletos/service/EmpresaService.java | 13 ++ .../service/impl/EmpresaServiceImpl.java | 87 ++++++++++- .../web/utilerias/security/AESGSMHelper.java | 106 +++++++++++++ .../security/SecurityEmpresaToken.java | 145 ++++++++++++++++++ 9 files changed, 436 insertions(+), 3 deletions(-) create mode 100644 src/com/rjconsultores/ventaboletos/web/utilerias/security/AESGSMHelper.java create mode 100644 src/com/rjconsultores/ventaboletos/web/utilerias/security/SecurityEmpresaToken.java diff --git a/pom.xml b/pom.xml index 143097f80..30d7630fb 100644 --- a/pom.xml +++ b/pom.xml @@ -203,6 +203,13 @@ 3.1.0 provided + + + com.nimbusds + nimbus-jose-jwt + jdk16 + 4.11.2 + diff --git a/src/com/rjconsultores/ventaboletos/dao/EmpresaDAO.java b/src/com/rjconsultores/ventaboletos/dao/EmpresaDAO.java index f81b99488..c088a3c8b 100644 --- a/src/com/rjconsultores/ventaboletos/dao/EmpresaDAO.java +++ b/src/com/rjconsultores/ventaboletos/dao/EmpresaDAO.java @@ -73,5 +73,7 @@ public interface EmpresaDAO { public void gerarSeqNumFolioSistema(Integer idEmpresa, String cveEstado) throws RuntimeException; public List buscarEmpresaPtoVtaComissao(); + + public boolean isPrimeiraVezLicenca(); } diff --git a/src/com/rjconsultores/ventaboletos/dao/hibernate/EmpresaHibernateDAO.java b/src/com/rjconsultores/ventaboletos/dao/hibernate/EmpresaHibernateDAO.java index fa24233f0..d9ebf341a 100644 --- a/src/com/rjconsultores/ventaboletos/dao/hibernate/EmpresaHibernateDAO.java +++ b/src/com/rjconsultores/ventaboletos/dao/hibernate/EmpresaHibernateDAO.java @@ -14,6 +14,7 @@ import java.util.List; import javax.sql.DataSource; import org.apache.commons.lang.StringUtils; +import org.apache.log4j.Logger; import org.hibernate.Criteria; import org.hibernate.Hibernate; import org.hibernate.Query; @@ -21,6 +22,7 @@ import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.criterion.MatchMode; import org.hibernate.criterion.Order; +import org.hibernate.criterion.Projections; import org.hibernate.criterion.Restrictions; import org.hibernate.type.BooleanType; import org.hibernate.type.IntegerType; @@ -50,6 +52,7 @@ public class EmpresaHibernateDAO extends GenericHibernateDAO i private static String FS_BPE = "FS_BPE_"; + private static Logger log = Logger.getLogger(EmpresaHibernateDAO.class); @Autowired private DataSource dataSource; @@ -106,6 +109,36 @@ public class EmpresaHibernateDAO extends GenericHibernateDAO i } + /** + * Indica se está no momento em que nenhuma empresa tem a licença. + * + * @return + */ + @Override + public boolean isPrimeiraVezLicenca(){ + + Criteria c = makeCriteria(); + c.setProjection(Projections.rowCount()); + c.add(Restrictions.eq("activo", Boolean.TRUE)); + c.add(Restrictions.ne("empresaId", -1)); + + Long cantEmpresasBaseDados = HibernateFix.count(c.list()); + + c = makeCriteria(); + c.setProjection(Projections.rowCount()); + c.add(Restrictions.eq("activo", Boolean.TRUE)); + c.add(Restrictions.ne("empresaId", -1)); + c.add(Restrictions.isNull("licenca")); + + Long cantEmpresasSemLicenca = HibernateFix.count(c.list()); + + return (cantEmpresasBaseDados.equals(cantEmpresasSemLicenca)); + } + + public List listarEmpresasSemLicenca(){ + + return null; + } @SuppressWarnings("unchecked") public List obtenerIndExternoFalse() { Criteria c = getSession().createCriteria(getPersistentClass()); diff --git a/src/com/rjconsultores/ventaboletos/entidad/Empresa.java b/src/com/rjconsultores/ventaboletos/entidad/Empresa.java index a9632ead3..841e3baaa 100644 --- a/src/com/rjconsultores/ventaboletos/entidad/Empresa.java +++ b/src/com/rjconsultores/ventaboletos/entidad/Empresa.java @@ -421,6 +421,9 @@ public class Empresa implements Serializable, Auditavel { @Column(name = "INDTAXACONVENIENCIASOVENDA") private Boolean indTaxaConvenienciaSoVenda; + @Column(name = "LICENCA") + private String licenca; + @Column(name = "HORAINICIOEMBARQUE") @Temporal(TemporalType.TIME) @AuditarAtributo(pattern = "HH:mm") @@ -434,6 +437,10 @@ public class Empresa implements Serializable, Auditavel { @Transient @NaoAuditar private Empresa empresaClone; + + @Transient + @NaoAuditar + private String token; public Empresa() { super(); @@ -1586,4 +1593,22 @@ public class Empresa implements Serializable, Auditavel { public void setHoraFimEmbarque(Date horaFimEmbarque) { this.horaFimEmbarque = horaFimEmbarque; } + + public String getToken() { + return token; + } + + public void setToken(String token) { + this.token = token; + } + + public String getLicenca() { + return licenca; + } + + public void setLicenca(String licenca) { + this.licenca = licenca; + } + + } diff --git a/src/com/rjconsultores/ventaboletos/entidad/Usuario.java b/src/com/rjconsultores/ventaboletos/entidad/Usuario.java index eabc61af5..c1b3310a1 100644 --- a/src/com/rjconsultores/ventaboletos/entidad/Usuario.java +++ b/src/com/rjconsultores/ventaboletos/entidad/Usuario.java @@ -30,15 +30,18 @@ import javax.persistence.Transient; import org.apache.commons.lang.BooleanUtils; import org.apache.commons.lang.StringUtils; +import org.apache.log4j.Logger; import org.hibernate.annotations.Fetch; import org.hibernate.annotations.FetchMode; import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.userdetails.UserDetails; import com.rjconsultores.ventaboletos.service.ConstanteService; +import com.rjconsultores.ventaboletos.service.impl.EmpresaServiceImpl; import com.rjconsultores.ventaboletos.utilerias.ApplicationProperties; import com.rjconsultores.ventaboletos.utilerias.CustomEnum; import com.rjconsultores.ventaboletos.utilerias.DateUtil; +import com.rjconsultores.ventaboletos.web.utilerias.security.SecurityEmpresaToken; import com.rjconsultores.ventaboletos.web.utilerias.spring.AppContext; import br.com.rjconsultores.auditador.annotations.AuditarClasse; @@ -59,6 +62,7 @@ import br.com.rjconsultores.auditador.interfaces.Auditavel; public class Usuario implements Serializable, UserDetails, Auditavel { public final static int CANT_DIAS_CONTRASENA = 999; + private static Logger log = Logger.getLogger(Usuario.class); private static final long serialVersionUID = 1L; @AuditarID @@ -255,10 +259,25 @@ public class Usuario implements Serializable, UserDetails, Auditavel { public List getEmpresa() { List tmp = new ArrayList(); + + SecurityEmpresaToken security = new SecurityEmpresaToken(); + if (usuarioEmpresaList != null) { for (UsuarioEmpresa cp : this.usuarioEmpresaList) { if ((cp.getActivo())) { - tmp.add(cp.getEmpresa()); + Empresa empresa = cp.getEmpresa(); + boolean licenseValidate = false; + + try{ + licenseValidate = security.licenseValidate(empresa.getLicenca(), empresa.getEmpresaId(), empresa.getCnpj()); + }catch(Throwable th){ + log.error(String.format("Licença não validada para a empresaId: %s e cnpj: %s", empresa.getEmpresaId(),empresa.getCnpj()), th); + } + + + if (licenseValidate){ + tmp.add(cp.getEmpresa()); + } } } } diff --git a/src/com/rjconsultores/ventaboletos/service/EmpresaService.java b/src/com/rjconsultores/ventaboletos/service/EmpresaService.java index 5f9119b8d..8f89ebfe3 100644 --- a/src/com/rjconsultores/ventaboletos/service/EmpresaService.java +++ b/src/com/rjconsultores/ventaboletos/service/EmpresaService.java @@ -63,5 +63,18 @@ public interface EmpresaService { public ComEmpConferencia suscribirOrActualizacion(ComEmpConferencia comEmpConferencia); public List buscarEmpresaPtoVtaComissao(); + + /** + * Atualiza se necessário as licenças no primeiro acesso + * + * @return A quantidade de empresas atualizadas + */ + public Integer atualizarLicencaEmpresasPrimeiraVez(); + + public List filtrarApenasEmpresasLicencaValida(List lsEmpresa); + + public String token(Empresa empresa); + + public String validarTokenLicensa(Empresa empresa, String tokenLicenca); } diff --git a/src/com/rjconsultores/ventaboletos/service/impl/EmpresaServiceImpl.java b/src/com/rjconsultores/ventaboletos/service/impl/EmpresaServiceImpl.java index 352ed5e62..413220e8a 100644 --- a/src/com/rjconsultores/ventaboletos/service/impl/EmpresaServiceImpl.java +++ b/src/com/rjconsultores/ventaboletos/service/impl/EmpresaServiceImpl.java @@ -4,6 +4,7 @@ */ package com.rjconsultores.ventaboletos.service.impl; +import java.util.ArrayList; import java.util.Calendar; import java.util.List; @@ -29,6 +30,7 @@ import com.rjconsultores.ventaboletos.service.LogAuditoriaService; import com.rjconsultores.ventaboletos.service.MarcaService; import com.rjconsultores.ventaboletos.utilerias.RegistroConDependenciaException; import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado; +import com.rjconsultores.ventaboletos.web.utilerias.security.SecurityEmpresaToken; /** * @@ -60,6 +62,8 @@ public class EmpresaServiceImpl implements EmpresaService { public Empresa obtenerID(Integer id) { Empresa empresa = empresaDAO.obtenerID(id); + empresa.setToken(this.token(empresa)); + try { empresa.clonar(); } catch (Exception e) { @@ -85,6 +89,7 @@ public class EmpresaServiceImpl implements EmpresaService { entidad = empresaDAO.suscribir(entidad); logAuditoriaService.auditar(null, entidad, null); + entidad.setToken(this.token(entidad)); gerarMarca(entidad); @@ -138,7 +143,7 @@ public class EmpresaServiceImpl implements EmpresaService { } public List buscarTodosExceto(List empresa, Integer... idEmpresa) { - return empresaDAO.buscarTodosExceto(empresa, idEmpresa); + return this.filtrarApenasEmpresasLicencaValida(empresaDAO.buscarTodosExceto(empresa, idEmpresa)); } public List obtenerIndExternoFalse() { @@ -170,9 +175,31 @@ public class EmpresaServiceImpl implements EmpresaService { empresaDAO.actualizaInscEstadual(inscricaoEstadual); } + @Override + public List filtrarApenasEmpresasLicencaValida(List lsEmpresa){ + SecurityEmpresaToken security = new SecurityEmpresaToken(); + List lsRetorno = new ArrayList<>(); + + if (lsEmpresa == null || lsEmpresa.isEmpty()){ + return lsEmpresa; + } + + for(Empresa empresa:lsEmpresa){ + boolean licenseValidate = security.licenseValidate(empresa.getLicenca(), empresa.getEmpresaId(), empresa.getCnpj()); + if (!licenseValidate){ + log.info(String.format("Empresa sem licença válida", empresa.getEmpresaId())); + + continue; + } + lsRetorno.add(empresa); + } + return lsRetorno; + } @Override public List buscaLike(String nombempresa) { - return empresaDAO.buscaLike(nombempresa); + List lsEmpresa = empresaDAO.buscaLike(nombempresa); + + return this.filtrarApenasEmpresasLicencaValida(lsEmpresa); } @Override @@ -240,9 +267,65 @@ public class EmpresaServiceImpl implements EmpresaService { return empresaDAO.actualizacion(comEmpConferencia); } } + + @Override + public String validarTokenLicensa(Empresa empresa,String tokenLicenca){ + if (tokenLicenca == null){ + return null; + } + try{ + SecurityEmpresaToken security = new SecurityEmpresaToken(); + + final String license = security.tokenValidate(tokenLicenca); + + return license; + }catch(Throwable th){ + log.error("Erro ao validar token",th); + } + + return null; + } + + @Override + public String token(Empresa empresa){ + + SecurityEmpresaToken security = new SecurityEmpresaToken(); + final String bodyRequest = security.bodyRequestGenerate(empresa.getEmpresaId(), empresa.getCnpj()); + final String request = security.requestGenerate(bodyRequest); + + return request; + } @Override public List buscarEmpresaPtoVtaComissao() { return empresaDAO.buscarEmpresaPtoVtaComissao(); } + + @Override + @Transactional + public Integer atualizarLicencaEmpresasPrimeiraVez(){ + boolean primeiraVezLicenca = empresaDAO.isPrimeiraVezLicenca(); + int cantEmpresasAtualizadas = 0; + + log.info(String.format("primeiraVezLicenca: %s", primeiraVezLicenca)); + + if (primeiraVezLicenca){ + SecurityEmpresaToken security = new SecurityEmpresaToken(); + List lsEmpresas = empresaDAO.obtenerTodos(); + + for(Empresa empresa:lsEmpresas){ + String licenseDefaultGenerate = security.licenseDefaultGenerate(empresa.getEmpresaId(), empresa.getCnpj()); + + log.info(String.format("licenseDefaultGenerate: %s", licenseDefaultGenerate)); + + empresa.setLicenca(licenseDefaultGenerate); + + empresaDAO.actualizacion(empresa); + cantEmpresasAtualizadas++; + } + + } + + return cantEmpresasAtualizadas; + } } diff --git a/src/com/rjconsultores/ventaboletos/web/utilerias/security/AESGSMHelper.java b/src/com/rjconsultores/ventaboletos/web/utilerias/security/AESGSMHelper.java new file mode 100644 index 000000000..bc7f43653 --- /dev/null +++ b/src/com/rjconsultores/ventaboletos/web/utilerias/security/AESGSMHelper.java @@ -0,0 +1,106 @@ +package com.rjconsultores.ventaboletos.web.utilerias.security; + +import java.nio.ByteBuffer; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; +import java.security.NoSuchAlgorithmException; +import java.security.SecureRandom; +import java.security.spec.InvalidKeySpecException; +import java.security.spec.KeySpec; + +import javax.crypto.Cipher; +import javax.crypto.SecretKey; +import javax.crypto.SecretKeyFactory; +import javax.crypto.spec.GCMParameterSpec; +import javax.crypto.spec.PBEKeySpec; +import javax.crypto.spec.SecretKeySpec; + +import org.apache.commons.codec.DecoderException; +import org.apache.commons.codec.binary.Hex; + +public class AESGSMHelper { + private final String SECRET_KEY = "RJ@2019#c0n5ul10r35"; + private final String SALT = "HrqoFr44GtkAhhYN+jP8Ag=="; + private final String ENCRYPT_ALGO = "AES/GCM/NoPadding"; + private final int TAG_LENGTH_BIT = 128; + private final int IV_LENGTH_BYTE = 12; + + private final Charset UTF_8 = StandardCharsets.UTF_8; + + public String encrypt(String value) throws Exception { + SecretKey secret = getAESKeyFromPassword(SECRET_KEY.toCharArray()); + + byte[] pText = value.getBytes(StandardCharsets.UTF_8); + byte[] iv = getRandomNonce(12); + byte[] cipherText = encrypt(pText, secret, iv); + + byte[] cipherTextWithIv = ByteBuffer.allocate(iv.length + cipherText.length) + .put(iv) + .put(cipherText) + .array(); + + return hex(cipherTextWithIv); + } + + private byte[] encrypt(byte[] pText, SecretKey secret, byte[] iv) throws Exception { + Cipher cipher = Cipher.getInstance(ENCRYPT_ALGO); + cipher.init(Cipher.ENCRYPT_MODE, secret, new GCMParameterSpec(TAG_LENGTH_BIT, iv)); + + byte[] encryptedText = cipher.doFinal(pText); + + return encryptedText; + + } + + public String decrypt(String value) throws Exception { + SecretKey secret = getAESKeyFromPassword(SECRET_KEY.toCharArray()); + + byte[] cText = unhex(value); + + ByteBuffer bb = ByteBuffer.wrap(cText); + + byte[] iv = new byte[IV_LENGTH_BYTE]; + bb.get(iv); + + byte[] cipherText = new byte[bb.remaining()]; + bb.get(cipherText); + + String plainText = decrypt(cipherText, secret, iv); + + return plainText; + } + + private String decrypt(byte[] cText, SecretKey secret, byte[] iv) throws Exception { + Cipher cipher = Cipher.getInstance(ENCRYPT_ALGO); + cipher.init(Cipher.DECRYPT_MODE, secret, new GCMParameterSpec(TAG_LENGTH_BIT, iv)); + + byte[] plainText = cipher.doFinal(cText); + + return new String(plainText, UTF_8); + } + + private byte[] getRandomNonce(int numBytes) { + byte[] nonce = new byte[numBytes]; + new SecureRandom().nextBytes(nonce); + + return nonce; + } + + private SecretKey getAESKeyFromPassword(char[] password) throws NoSuchAlgorithmException, InvalidKeySpecException { + SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA256"); + + KeySpec spec = new PBEKeySpec(password, SALT.getBytes(), 65536, 256); + SecretKeySpec secret = new SecretKeySpec(factory.generateSecret(spec).getEncoded(), "AES"); + + return secret; + } + + private String hex(byte[] bytes) { + char[] result = Hex.encodeHex(bytes); + return new String(result); + } + + private byte[] unhex(String hex) throws DecoderException { + return Hex.decodeHex(hex.toCharArray()); + } +} diff --git a/src/com/rjconsultores/ventaboletos/web/utilerias/security/SecurityEmpresaToken.java b/src/com/rjconsultores/ventaboletos/web/utilerias/security/SecurityEmpresaToken.java new file mode 100644 index 000000000..738bcacef --- /dev/null +++ b/src/com/rjconsultores/ventaboletos/web/utilerias/security/SecurityEmpresaToken.java @@ -0,0 +1,145 @@ +package com.rjconsultores.ventaboletos.web.utilerias.security; + +import java.text.ParseException; +import java.time.Duration; +import java.util.Calendar; + +import javax.xml.bind.DatatypeConverter; + +import org.apache.commons.lang.StringUtils; +import org.apache.log4j.Logger; + +import com.google.gson.Gson; +import com.google.gson.JsonObject; +import com.nimbusds.jose.JWSAlgorithm; +import com.nimbusds.jose.JWSHeader; +import com.nimbusds.jose.JWSObject; +import com.nimbusds.jose.Payload; +import com.nimbusds.jose.crypto.MACSigner; +import com.nimbusds.jwt.JWTClaimsSet; + +import net.minidev.json.JSONObject; + +public class SecurityEmpresaToken { + private static Logger log = Logger.getLogger(SecurityEmpresaToken.class); + + private String secret = "#KO&Fm4_k.sU9M8`6Mx'F\\\"H:*Qxu]6F4r,)JmZ2Jwafd)I.2[RET'1:)VQ6mG9,"; + private static final Duration ttl = Duration.ofDays(7); + + private Gson gson = new Gson(); + + public String bodyRequestGenerate(final Integer empresaId, final String cnpj) throws SecurityException { + try { + AESGSMHelper crypto = new AESGSMHelper(); + + JsonObject json = new JsonObject(); + json.addProperty("empresaId", empresaId); + json.addProperty("CNPJ", cnpj); + + return crypto.encrypt(json.toString()); + + } catch (Exception e) { + log.error("Erro ao gerar o body usado no request da licença: " + e.getMessage(), e); + + throw new SecurityException(e); + } + } + + public String licenseDefaultGenerate(final Integer empresaId, final String cnpj) throws SecurityException { + try { + AESGSMHelper crypto = new AESGSMHelper(); + + JsonObject json = new JsonObject(); + json.addProperty("empresaId", empresaId); + json.addProperty("CNPJ", cnpj); + json.addProperty("aprovado", 1); + + return crypto.encrypt(json.toString()); + + } catch (Exception e) { + log.error("Erro ao gerar a licença padrão para as empresas existentes: " + e.getMessage(), e); + + throw new SecurityException(e); + } + } + + public boolean licenseValidate(final String license, final Integer empresaId, final String cnpj) { + try { + if (StringUtils.isBlank(license)){ + return false; + } + + AESGSMHelper crypto = new AESGSMHelper(); + + final String value = crypto.decrypt(license); + final JsonObject json = gson.fromJson(value, JsonObject.class); + + if (json.has("empresaId") && json.get("empresaId").getAsInt() == empresaId.intValue() + && json.has("CNPJ") && json.get("CNPJ").getAsString().equals(cnpj) + && json.has("aprovado")) { + log.debug("[empresaId=" + json.get("empresaId").getAsString() + ", CNPJ=" + json.get("CNPJ").getAsString() + ", aprovado=" + json.get("aprovado").getAsString() + "]"); + + return json.get("aprovado").getAsString().equals("1"); + } + } catch (Exception e) { + log.error("Erro ao gerar o body usado no request da licença: " + e.getMessage(), e); + } + + return false; + } + + public String requestGenerate(String licenseRequest) throws SecurityException { + return requestGenerate(licenseRequest, ttl); + } + + public String requestGenerate(String licenseRequest, Duration ttl) throws SecurityException { + try { + Calendar cal = Calendar.getInstance(); + cal.add(Calendar.MILLISECOND, (int) ttl.toMillis()); + + JWTClaimsSet claims = new JWTClaimsSet.Builder() + .expirationTime(cal.getTime()) + .claim("sub", licenseRequest) + .claim("userId", "adm") + .claim("role", "ROLE_TOKEN") + .build(); + + JWSObject jwsObject = new JWSObject(new JWSHeader(JWSAlgorithm.HS256), new Payload(claims.toJSONObject())); + + jwsObject.sign(new MACSigner(DatatypeConverter.parseBase64Binary(secret))); + + return jwsObject.serialize(); + } catch (Exception e) { + log.error("Erro ao gerar a request: " + e.getMessage(), e); + + throw new SecurityException(e); + } + } + + public String tokenValidate(final String token) throws SecurityException { + try { + JWSObject jwsObject = JWSObject.parse(token); + JSONObject jsonPayload = jwsObject.getPayload().toJSONObject(); + JWTClaimsSet claims = JWTClaimsSet.parse(jsonPayload); + + if (claims.getExpirationTime().compareTo(Calendar.getInstance().getTime()) < 0) { + throw new SecurityException("Token expirado"); + } + + return claims.getSubject(); + + } catch (SecurityException e) { + throw e; + + } catch (ParseException e) { + log.error("Erro no parser do token: " + e.getMessage(), e); + + throw new SecurityException(e); + + } catch (Exception e) { + log.error("Erro ao validar o token: " + e.getMessage(), e); + + throw new SecurityException(e); + } + } +} From bf73260b0a654e916669053823a06426719427cf Mon Sep 17 00:00:00 2001 From: Gleimar Botelho Baleeiro Date: Thu, 16 Nov 2023 10:25:37 -0300 Subject: [PATCH 04/10] =?UTF-8?q?Implementa=C3=A7=C3=A3o=20do=20fluxo=20de?= =?UTF-8?q?=20autoriza=C3=A7=C3=A3o=20para=20novas=20empresas?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 10da69d61..286b43215 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 br.com.rjconsultores ModelWeb - 1.21.0 + 1.22.0 From 06a1c04b1cedca06c2496c4693330d61e6d8a6ab Mon Sep 17 00:00:00 2001 From: Gleimar Botelho Baleeiro Date: Thu, 16 Nov 2023 10:26:45 -0300 Subject: [PATCH 05/10] =?UTF-8?q?Implementa=C3=A7=C3=A3o=20do=20fluxo=20de?= =?UTF-8?q?=20autoriza=C3=A7=C3=A3o=20para=20novas=20empresas?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 30d7630fb..c6b831cc7 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 br.com.rjconsultores ModelWeb - 1.19.1 + 1.22.0 From be39c021c857aa51aee00ded4447f18b096e0e81 Mon Sep 17 00:00:00 2001 From: "wallace.henrique" Date: Thu, 16 Nov 2023 11:04:46 -0300 Subject: [PATCH 06/10] fixes bug#AL-3498 --- pom.xml | 2 +- .../ventaboletos/dao/CorridaInfoDAO.java | 6 +++--- .../dao/hibernate/CorridaInfoHibernateDAO.java | 15 +++++++++++++++ .../ventaboletos/service/CorridaInfoService.java | 3 +++ .../service/impl/CorridaInfoServiceImpl.java | 8 ++++++++ 5 files changed, 30 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index c6b831cc7..0c7076fd4 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 br.com.rjconsultores ModelWeb - 1.22.0 + 1.22.1 diff --git a/src/com/rjconsultores/ventaboletos/dao/CorridaInfoDAO.java b/src/com/rjconsultores/ventaboletos/dao/CorridaInfoDAO.java index 4f429f748..e22f2298d 100644 --- a/src/com/rjconsultores/ventaboletos/dao/CorridaInfoDAO.java +++ b/src/com/rjconsultores/ventaboletos/dao/CorridaInfoDAO.java @@ -1,11 +1,11 @@ package com.rjconsultores.ventaboletos.dao; -import java.util.List; - +import com.rjconsultores.ventaboletos.entidad.Corrida; import com.rjconsultores.ventaboletos.entidad.CorridaInfo; -import com.rjconsultores.ventaboletos.entidad.EsquemaCorridaInfo; public interface CorridaInfoDAO extends GenericDAO { + void borrarByCorrida(Corrida corrida); + } diff --git a/src/com/rjconsultores/ventaboletos/dao/hibernate/CorridaInfoHibernateDAO.java b/src/com/rjconsultores/ventaboletos/dao/hibernate/CorridaInfoHibernateDAO.java index afe2ab235..aba3b4587 100644 --- a/src/com/rjconsultores/ventaboletos/dao/hibernate/CorridaInfoHibernateDAO.java +++ b/src/com/rjconsultores/ventaboletos/dao/hibernate/CorridaInfoHibernateDAO.java @@ -1,11 +1,13 @@ package com.rjconsultores.ventaboletos.dao.hibernate; +import org.hibernate.SQLQuery; import org.hibernate.SessionFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Repository; import com.rjconsultores.ventaboletos.dao.CorridaInfoDAO; +import com.rjconsultores.ventaboletos.entidad.Corrida; import com.rjconsultores.ventaboletos.entidad.CorridaInfo; @Repository("corridaInfoDAO") @@ -15,5 +17,18 @@ public class CorridaInfoHibernateDAO extends GenericHibernateDAO { + void borrarByCorrida(Corrida corrida); + } diff --git a/src/com/rjconsultores/ventaboletos/service/impl/CorridaInfoServiceImpl.java b/src/com/rjconsultores/ventaboletos/service/impl/CorridaInfoServiceImpl.java index 07cab1cf6..6e103b946 100644 --- a/src/com/rjconsultores/ventaboletos/service/impl/CorridaInfoServiceImpl.java +++ b/src/com/rjconsultores/ventaboletos/service/impl/CorridaInfoServiceImpl.java @@ -8,6 +8,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import com.rjconsultores.ventaboletos.dao.CorridaInfoDAO; +import com.rjconsultores.ventaboletos.entidad.Corrida; import com.rjconsultores.ventaboletos.entidad.CorridaInfo; import com.rjconsultores.ventaboletos.service.CorridaInfoService; import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado; @@ -59,4 +60,11 @@ public class CorridaInfoServiceImpl implements CorridaInfoService { corridaInfoDAO.actualizacion(entidad); } + @Transactional + + @Override + public void borrarByCorrida(Corrida corrida) { + corridaInfoDAO.borrarByCorrida(corrida); + } + } From e5d26578e3c797b848e525cc73bf1c5074275534 Mon Sep 17 00:00:00 2001 From: "valdir.cordeiro" Date: Fri, 17 Nov 2023 11:12:50 -0300 Subject: [PATCH 07/10] =?UTF-8?q?bug#al-3485=20Continua=C3=A7=C3=A3o=20663?= =?UTF-8?q?63=20-=20Ajustes=20na=20Tela=20de=20Configura=C3=A7=C3=A3o=20de?= =?UTF-8?q?=20Servi=C3=A7o=20na=20ADM=20dev:=20qua:?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- .../impl/HeaderEsquemaCorridaServiceImpl.java | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index 0c7076fd4..721b3305c 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 br.com.rjconsultores ModelWeb - 1.22.1 + 1.23.0 diff --git a/src/com/rjconsultores/ventaboletos/service/impl/HeaderEsquemaCorridaServiceImpl.java b/src/com/rjconsultores/ventaboletos/service/impl/HeaderEsquemaCorridaServiceImpl.java index 0f959881e..644363d0b 100644 --- a/src/com/rjconsultores/ventaboletos/service/impl/HeaderEsquemaCorridaServiceImpl.java +++ b/src/com/rjconsultores/ventaboletos/service/impl/HeaderEsquemaCorridaServiceImpl.java @@ -32,14 +32,14 @@ public class HeaderEsquemaCorridaServiceImpl implements HeaderEsquemaCorridaServ if(header == null) { //Se for nulo retorna com o valor padrao - header = new HeaderTabelaEsquemaCorrida(1, "1,2,3,4,5,6,7,8,9,10,11,12,13,14,15"); + header = new HeaderTabelaEsquemaCorrida(1, "1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16"); } String headerString = header.getSequenciaHeader(); String[] arrayString = headerString.split(","); - - Integer[] arrayInt = new Integer[15]; + + Integer[] arrayInt = new Integer[16]; int i = 0; for(String pos : arrayString) { @@ -47,6 +47,10 @@ public class HeaderEsquemaCorridaServiceImpl implements HeaderEsquemaCorridaServ i++; } + if(arrayString.length == 15) { + arrayInt[15] = 16; + } + return arrayInt; } @@ -80,7 +84,7 @@ public class HeaderEsquemaCorridaServiceImpl implements HeaderEsquemaCorridaServ int i = 1; for(Integer posicao : posicoesColunasTabela) { - if(i < 15) { + if(i < 16) { pos.append(posicao).append(","); } else { pos.append(posicao); From 38b02cb7db1d4da1de8d210354ec62e54de9fec0 Mon Sep 17 00:00:00 2001 From: "wallace.henrique" Date: Fri, 17 Nov 2023 12:20:59 -0300 Subject: [PATCH 08/10] fixes bug#3499 --- pom.xml | 2 +- src/com/rjconsultores/ventaboletos/entidad/PuntoVenta.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 721b3305c..1f32b53ea 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 br.com.rjconsultores ModelWeb - 1.23.0 + 1.23.1 diff --git a/src/com/rjconsultores/ventaboletos/entidad/PuntoVenta.java b/src/com/rjconsultores/ventaboletos/entidad/PuntoVenta.java index 7e9007657..a03658e4b 100644 --- a/src/com/rjconsultores/ventaboletos/entidad/PuntoVenta.java +++ b/src/com/rjconsultores/ventaboletos/entidad/PuntoVenta.java @@ -346,7 +346,7 @@ public class PuntoVenta implements Serializable, Auditavel { @Column(name = "INDBLOQUEARDESCONTOWEB") private Boolean indBloquearDescontoWEB; - @Column(name = "INDTAXACONVENIENCIAORGAOCONCEDENTE") + @Column(name = "INDTAXACONVORGAOCONCEDENTE") private Boolean indTaxaConvenienciaOrgaoConcedente; public List getCobrancaAdicionalList() { From ff220fa9b740a04baf5abb1f71ec01f8098b1843 Mon Sep 17 00:00:00 2001 From: "wallace.henrique" Date: Fri, 17 Nov 2023 12:23:59 -0300 Subject: [PATCH 09/10] fixes bug#AL-3499 --- pom.xml | 2 +- src/com/rjconsultores/ventaboletos/entidad/PuntoVenta.java | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 1f32b53ea..6a47f9b99 100644 --- a/pom.xml +++ b/pom.xml @@ -1,5 +1,5 @@ + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd "> 4.0.0 br.com.rjconsultores ModelWeb diff --git a/src/com/rjconsultores/ventaboletos/entidad/PuntoVenta.java b/src/com/rjconsultores/ventaboletos/entidad/PuntoVenta.java index a03658e4b..7a510a676 100644 --- a/src/com/rjconsultores/ventaboletos/entidad/PuntoVenta.java +++ b/src/com/rjconsultores/ventaboletos/entidad/PuntoVenta.java @@ -1388,5 +1388,6 @@ public class PuntoVenta implements Serializable, Auditavel { public void setIndTaxaConvenienciaOrgaoConcedente(Boolean indTaxaConvenienciaOrgaoConcedente) { this.indTaxaConvenienciaOrgaoConcedente = indTaxaConvenienciaOrgaoConcedente; } - + + } \ No newline at end of file From bfabb5f822b65b694f20b7547cb5c57522f0c37a Mon Sep 17 00:00:00 2001 From: "wallace.henrique" Date: Fri, 17 Nov 2023 16:34:15 -0300 Subject: [PATCH 10/10] fixes bug#AL-3516 --- pom.xml | 2 +- .../ventaboletos/dao/AsientoExclusivoDAO.java | 4 + .../ventaboletos/dao/DisponibilidadDAO.java | 18 ++++ .../ventaboletos/dao/IntegracaoTotvsDAO.java | 3 + .../dao/IntgeracaoTotvsHibernateDAO.java | 20 ----- .../AsientoExclusivoHibernateDAO.java | 23 ++++- .../hibernate/DisponibilidadHibernateDAO.java | 34 ++++++++ .../IntegracaoTotvsHibernateDAO.java | 34 ++++++++ .../ventaboletos/entidad/Disponibilidad.java | 85 +++++++++++++++++++ .../service/AsientoExclusivoService.java | 4 + .../service/DisponibilidadService.java | 17 ++++ .../service/IntegracaoTotvsService.java | 3 + .../impl/AsientoExclusivoServiceImpl.java | 7 ++ .../impl/DisponibilidadServiceImpl.java | 74 ++++++++++++++++ .../impl/IntegracaoTotvsServiceImpl.java | 7 ++ 15 files changed, 311 insertions(+), 24 deletions(-) create mode 100644 src/com/rjconsultores/ventaboletos/dao/DisponibilidadDAO.java delete mode 100644 src/com/rjconsultores/ventaboletos/dao/IntgeracaoTotvsHibernateDAO.java create mode 100644 src/com/rjconsultores/ventaboletos/dao/hibernate/DisponibilidadHibernateDAO.java create mode 100644 src/com/rjconsultores/ventaboletos/dao/hibernate/IntegracaoTotvsHibernateDAO.java create mode 100644 src/com/rjconsultores/ventaboletos/entidad/Disponibilidad.java create mode 100644 src/com/rjconsultores/ventaboletos/service/DisponibilidadService.java create mode 100644 src/com/rjconsultores/ventaboletos/service/impl/DisponibilidadServiceImpl.java diff --git a/pom.xml b/pom.xml index 6a47f9b99..fe105962f 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 br.com.rjconsultores ModelWeb - 1.23.1 + 1.23.2 diff --git a/src/com/rjconsultores/ventaboletos/dao/AsientoExclusivoDAO.java b/src/com/rjconsultores/ventaboletos/dao/AsientoExclusivoDAO.java index 062d691cf..de6788cca 100644 --- a/src/com/rjconsultores/ventaboletos/dao/AsientoExclusivoDAO.java +++ b/src/com/rjconsultores/ventaboletos/dao/AsientoExclusivoDAO.java @@ -5,10 +5,14 @@ package com.rjconsultores.ventaboletos.dao; import com.rjconsultores.ventaboletos.entidad.AsientoExclusivo; +import com.rjconsultores.ventaboletos.entidad.Corrida; /** * * @author rodrigo */ public interface AsientoExclusivoDAO extends GenericDAO { + + void borrarByCorrida(Corrida corrida); + } diff --git a/src/com/rjconsultores/ventaboletos/dao/DisponibilidadDAO.java b/src/com/rjconsultores/ventaboletos/dao/DisponibilidadDAO.java new file mode 100644 index 000000000..c3a86c24b --- /dev/null +++ b/src/com/rjconsultores/ventaboletos/dao/DisponibilidadDAO.java @@ -0,0 +1,18 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package com.rjconsultores.ventaboletos.dao; + +import com.rjconsultores.ventaboletos.entidad.Corrida; +import com.rjconsultores.ventaboletos.entidad.Disponibilidad; + +/** + * + * @author wallace + */ +public interface DisponibilidadDAO extends GenericDAO { + + void borrarByCorrida(Corrida corrida); + +} diff --git a/src/com/rjconsultores/ventaboletos/dao/IntegracaoTotvsDAO.java b/src/com/rjconsultores/ventaboletos/dao/IntegracaoTotvsDAO.java index efa57eabc..5cf98ef8b 100644 --- a/src/com/rjconsultores/ventaboletos/dao/IntegracaoTotvsDAO.java +++ b/src/com/rjconsultores/ventaboletos/dao/IntegracaoTotvsDAO.java @@ -1,7 +1,10 @@ package com.rjconsultores.ventaboletos.dao; +import com.rjconsultores.ventaboletos.entidad.Corrida; import com.rjconsultores.ventaboletos.entidad.IntegracaoTotvs; public interface IntegracaoTotvsDAO extends GenericDAO { + + public void borrarByCorrida(Corrida corrida); } diff --git a/src/com/rjconsultores/ventaboletos/dao/IntgeracaoTotvsHibernateDAO.java b/src/com/rjconsultores/ventaboletos/dao/IntgeracaoTotvsHibernateDAO.java deleted file mode 100644 index 6566cce8c..000000000 --- a/src/com/rjconsultores/ventaboletos/dao/IntgeracaoTotvsHibernateDAO.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.rjconsultores.ventaboletos.dao; - -import org.hibernate.SessionFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.stereotype.Repository; - -import com.rjconsultores.ventaboletos.dao.hibernate.GenericHibernateDAO; -import com.rjconsultores.ventaboletos.entidad.IntegracaoTotvs; - -@Repository("IntgeracaoTotvsDAO") -public class IntgeracaoTotvsHibernateDAO extends GenericHibernateDAO - implements IntegracaoTotvsDAO { - - @Autowired - public IntgeracaoTotvsHibernateDAO(@Qualifier("sessionFactory") SessionFactory factory) { - setSessionFactory(factory); - } - -} diff --git a/src/com/rjconsultores/ventaboletos/dao/hibernate/AsientoExclusivoHibernateDAO.java b/src/com/rjconsultores/ventaboletos/dao/hibernate/AsientoExclusivoHibernateDAO.java index e62e7b0d7..990e6fe53 100644 --- a/src/com/rjconsultores/ventaboletos/dao/hibernate/AsientoExclusivoHibernateDAO.java +++ b/src/com/rjconsultores/ventaboletos/dao/hibernate/AsientoExclusivoHibernateDAO.java @@ -4,19 +4,23 @@ */ package com.rjconsultores.ventaboletos.dao.hibernate; -import com.rjconsultores.ventaboletos.dao.AsientoExclusivoDAO; -import com.rjconsultores.ventaboletos.entidad.AsientoExclusivo; import java.util.List; + import org.hibernate.Criteria; +import org.hibernate.SQLQuery; 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.AsientoExclusivoDAO; +import com.rjconsultores.ventaboletos.entidad.AsientoExclusivo; +import com.rjconsultores.ventaboletos.entidad.Corrida; + /** * - * @author rodrigo + * @author walace */ @Repository("asientoExclusivoDAO") public class AsientoExclusivoHibernateDAO extends GenericHibernateDAO @@ -34,4 +38,17 @@ public class AsientoExclusivoHibernateDAO extends GenericHibernateDAO implements DisponibilidadDAO { + + @Autowired + public DisponibilidadHibernateDAO(@Qualifier("sessionFactory") SessionFactory factory) { + setSessionFactory(factory); + } + + @Override + public void borrarByCorrida(Corrida corrida) { + + StringBuilder sQuery = new StringBuilder("DELETE FROM Disponibilidad WHERE corrida_Id = :corridaId AND TRUNC(feccorrida) = :feccorrida "); + SQLQuery qrUpdate = getSession().createSQLQuery(sQuery.toString()); + + qrUpdate.setParameter("feccorrida", corrida.getId().getFeccorrida()); + qrUpdate.setParameter("corridaId", corrida.getId().getCorridaId()); + qrUpdate.executeUpdate(); + + + } +} + diff --git a/src/com/rjconsultores/ventaboletos/dao/hibernate/IntegracaoTotvsHibernateDAO.java b/src/com/rjconsultores/ventaboletos/dao/hibernate/IntegracaoTotvsHibernateDAO.java new file mode 100644 index 000000000..26c3cf210 --- /dev/null +++ b/src/com/rjconsultores/ventaboletos/dao/hibernate/IntegracaoTotvsHibernateDAO.java @@ -0,0 +1,34 @@ +package com.rjconsultores.ventaboletos.dao.hibernate; + +import org.hibernate.SQLQuery; +import org.hibernate.SessionFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Repository; + +import com.rjconsultores.ventaboletos.dao.IntegracaoTotvsDAO; +import com.rjconsultores.ventaboletos.entidad.Corrida; +import com.rjconsultores.ventaboletos.entidad.IntegracaoTotvs; + +@Repository("integracaoTotvsDAO") +public class IntegracaoTotvsHibernateDAO extends GenericHibernateDAO implements IntegracaoTotvsDAO { + + @Autowired + public IntegracaoTotvsHibernateDAO(@Qualifier("sessionFactory") SessionFactory factory) { + setSessionFactory(factory); + } + + @Override + public void borrarByCorrida(Corrida corrida) { + + StringBuilder sQuery = new StringBuilder("DELETE FROM INTEGRACAO_TOTVS_CORRIDA WHERE corrida_Id = :corridaId AND TRUNC(feccorrida) = :feccorrida "); + SQLQuery qrUpdate = getSession().createSQLQuery(sQuery.toString()); + + qrUpdate.setParameter("feccorrida", corrida.getId().getFeccorrida()); + qrUpdate.setParameter("corridaId", corrida.getId().getCorridaId()); + qrUpdate.executeUpdate(); + + + } +} + diff --git a/src/com/rjconsultores/ventaboletos/entidad/Disponibilidad.java b/src/com/rjconsultores/ventaboletos/entidad/Disponibilidad.java new file mode 100644 index 000000000..aa3096635 --- /dev/null +++ b/src/com/rjconsultores/ventaboletos/entidad/Disponibilidad.java @@ -0,0 +1,85 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +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.JoinColumns; +import javax.persistence.OneToOne; +import javax.persistence.SequenceGenerator; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; + +/** + * + * @author wallace + */ +@Entity +@SequenceGenerator(name = "DISPONIBILIDAD_SEQ", sequenceName = "DISPONIBILIDAD_SEQ", allocationSize = 1) +@Table(name = "DISPONIBILIDAD") +public class Disponibilidad implements Serializable { + + private static final long serialVersionUID = 1L; + @Id + @Basic(optional = false) + @Column(name = "DISPONIBILIDAD_ID") + @GeneratedValue(strategy = GenerationType.AUTO, generator = "DISPONIBILIDAD_SEQ") + private long disponibilidadId; + @OneToOne + @JoinColumns({ + @JoinColumn(name = "CORRIDA_ID"), + @JoinColumn(name = "FECCORRIDA")}) + private Corrida corrida; + @Column(name = "ACTIVO") + private Boolean activo; + @Basic(optional = false) + @Column(name = "FECMODIF") + @Temporal(TemporalType.TIMESTAMP) + private Date fecmodif; + @Column(name = "USUARIO_ID") + private Integer usuarioId; + + public long getDisponibilidadId() { + return disponibilidadId; + } + public void setDisponibilidadId(long disponibilidadId) { + this.disponibilidadId = disponibilidadId; + } + public Corrida getCorrida() { + return corrida; + } + public void setCorrida(Corrida corrida) { + this.corrida = corrida; + } + 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; + } + + +} diff --git a/src/com/rjconsultores/ventaboletos/service/AsientoExclusivoService.java b/src/com/rjconsultores/ventaboletos/service/AsientoExclusivoService.java index e932896fa..4153dcc5c 100644 --- a/src/com/rjconsultores/ventaboletos/service/AsientoExclusivoService.java +++ b/src/com/rjconsultores/ventaboletos/service/AsientoExclusivoService.java @@ -5,10 +5,14 @@ package com.rjconsultores.ventaboletos.service; import com.rjconsultores.ventaboletos.entidad.AsientoExclusivo; +import com.rjconsultores.ventaboletos.entidad.Corrida; /** * * @author rodrigo */ public interface AsientoExclusivoService extends GenericService { + + void borrarByCorrida(Corrida corrida); + } diff --git a/src/com/rjconsultores/ventaboletos/service/DisponibilidadService.java b/src/com/rjconsultores/ventaboletos/service/DisponibilidadService.java new file mode 100644 index 000000000..c469e7071 --- /dev/null +++ b/src/com/rjconsultores/ventaboletos/service/DisponibilidadService.java @@ -0,0 +1,17 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package com.rjconsultores.ventaboletos.service; + +import com.rjconsultores.ventaboletos.entidad.Corrida; +import com.rjconsultores.ventaboletos.entidad.Disponibilidad; + +/** + * + * @author wallace + */ +public interface DisponibilidadService extends GenericService { + + public void borrarByCorrida(Corrida corrida); +} diff --git a/src/com/rjconsultores/ventaboletos/service/IntegracaoTotvsService.java b/src/com/rjconsultores/ventaboletos/service/IntegracaoTotvsService.java index 79498ffb9..91a70e8be 100644 --- a/src/com/rjconsultores/ventaboletos/service/IntegracaoTotvsService.java +++ b/src/com/rjconsultores/ventaboletos/service/IntegracaoTotvsService.java @@ -3,6 +3,7 @@ package com.rjconsultores.ventaboletos.service; import java.util.Date; import java.util.List; +import com.rjconsultores.ventaboletos.entidad.Corrida; import com.rjconsultores.ventaboletos.entidad.Empresa; import com.rjconsultores.ventaboletos.entidad.PuntoVenta; import com.rjconsultores.ventaboletos.entidad.Usuario; @@ -18,5 +19,7 @@ public interface IntegracaoTotvsService { public List buscaPuntoVentaEmpresa(Empresa empresa) throws Exception; public Integer solicitaReIntegracaoBilhete(Empresa empresa, Date dataInicial, Date dataFinal, PuntoVenta puntoVenta, Usuario usuario) throws BusinessException; + + public void borrarByCorrida(Corrida corrida); } \ No newline at end of file diff --git a/src/com/rjconsultores/ventaboletos/service/impl/AsientoExclusivoServiceImpl.java b/src/com/rjconsultores/ventaboletos/service/impl/AsientoExclusivoServiceImpl.java index 08fb0e71b..377a860bc 100644 --- a/src/com/rjconsultores/ventaboletos/service/impl/AsientoExclusivoServiceImpl.java +++ b/src/com/rjconsultores/ventaboletos/service/impl/AsientoExclusivoServiceImpl.java @@ -6,6 +6,7 @@ package com.rjconsultores.ventaboletos.service.impl; import com.rjconsultores.ventaboletos.dao.AsientoExclusivoDAO; import com.rjconsultores.ventaboletos.entidad.AsientoExclusivo; +import com.rjconsultores.ventaboletos.entidad.Corrida; import com.rjconsultores.ventaboletos.service.AsientoExclusivoService; import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado; import java.util.Calendar; @@ -62,4 +63,10 @@ public class AsientoExclusivoServiceImpl implements AsientoExclusivoService { asientoExclusivoDAO.actualizacion(entidad); } + + @Override + public void borrarByCorrida(Corrida corrida) { + asientoExclusivoDAO.borrarByCorrida(corrida); + + } } diff --git a/src/com/rjconsultores/ventaboletos/service/impl/DisponibilidadServiceImpl.java b/src/com/rjconsultores/ventaboletos/service/impl/DisponibilidadServiceImpl.java new file mode 100644 index 000000000..2e10d9cdf --- /dev/null +++ b/src/com/rjconsultores/ventaboletos/service/impl/DisponibilidadServiceImpl.java @@ -0,0 +1,74 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +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.DisponibilidadDAO; +import com.rjconsultores.ventaboletos.entidad.Corrida; +import com.rjconsultores.ventaboletos.entidad.Disponibilidad; +import com.rjconsultores.ventaboletos.service.DisponibilidadService; +import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado; + +/** + * + * @author wallace + */ +@Service("disponibilidadService") +public class DisponibilidadServiceImpl implements DisponibilidadService { + + @Autowired + private DisponibilidadDAO disponibilidadDAO; + + public List obtenerTodos() { + return disponibilidadDAO.obtenerTodos(); + } + + public Disponibilidad obtenerID(Integer id) { + return disponibilidadDAO.obtenerID(id); + } + + @Transactional + public Disponibilidad suscribir(Disponibilidad entidad) { + Integer usuarioId = 1; + if (UsuarioLogado.getUsuarioLogado() != null){ + usuarioId = UsuarioLogado.getUsuarioLogado().getUsuarioId(); + } + entidad.setUsuarioId(usuarioId); + entidad.setFecmodif(Calendar.getInstance().getTime()); + entidad.setActivo(Boolean.TRUE); + + return disponibilidadDAO.suscribir(entidad); + } + + @Transactional + public Disponibilidad actualizacion(Disponibilidad entidad) { + entidad.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId()); + entidad.setFecmodif(Calendar.getInstance().getTime()); + entidad.setActivo(Boolean.TRUE); + + return disponibilidadDAO.actualizacion(entidad); + } + + @Transactional + public void borrar(Disponibilidad entidad) { + entidad.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId()); + entidad.setFecmodif(Calendar.getInstance().getTime()); + entidad.setActivo(Boolean.FALSE); + + disponibilidadDAO.actualizacion(entidad); + } + + @Override + public void borrarByCorrida(Corrida corrida) { + disponibilidadDAO.borrarByCorrida(corrida); + + } +} diff --git a/src/com/rjconsultores/ventaboletos/service/impl/IntegracaoTotvsServiceImpl.java b/src/com/rjconsultores/ventaboletos/service/impl/IntegracaoTotvsServiceImpl.java index 6d9c9fdc5..bb6e34701 100644 --- a/src/com/rjconsultores/ventaboletos/service/impl/IntegracaoTotvsServiceImpl.java +++ b/src/com/rjconsultores/ventaboletos/service/impl/IntegracaoTotvsServiceImpl.java @@ -13,6 +13,7 @@ import com.rjconsultores.ventaboletos.dao.EsquemaCorridaDAO; import com.rjconsultores.ventaboletos.dao.IntegracaoTotvsDAO; import com.rjconsultores.ventaboletos.dao.MarcaDAO; import com.rjconsultores.ventaboletos.dao.PuntoVentaDAO; +import com.rjconsultores.ventaboletos.entidad.Corrida; import com.rjconsultores.ventaboletos.entidad.Empresa; import com.rjconsultores.ventaboletos.entidad.IntegracaoTotvs; import com.rjconsultores.ventaboletos.entidad.Marca; @@ -96,4 +97,10 @@ public class IntegracaoTotvsServiceImpl implements IntegracaoTotvsService { } return corridaDao.atualizaCorridasIntegracaoTotvs(marca, dataInicial, dataFinal, numCorrida); } + + @Override + public void borrarByCorrida(Corrida corrida) { + integracaoTotvsDAO.borrarByCorrida(corrida); + + } }