From c825f447a8b44d2ebceea226d63f1bf71eb8bdc2 Mon Sep 17 00:00:00 2001 From: "lucas.taia" Date: Wed, 27 Feb 2019 23:43:21 +0000 Subject: [PATCH] fixes bug#13611 dev:lucas qua: git-svn-id: http://desenvolvimento.rjconsultores.com.br/repositorio/sco/AdmVenta/Model/trunk/modelWeb@90364 d1611594-4594-4d17-8e1d-87c2c4800839 --- .../ventaboletos/dao/CustomDAO.java | 14 + .../hibernate/CalcularPeajeHibernateDAO.java | 3 +- .../ConferenciaComissaoHibernateDAO.java | 3 +- .../dao/hibernate/CorridaHibernateDAO.java | 3 +- .../dao/hibernate/CustomHibernateDAO.java | 44 +++ .../RutaCombinacionHibernateDAO.java | 3 +- .../hibernate/TarifaOficialHibernateDAO.java | 3 +- .../dao/sqlbuilder/impl/SQLBuilderOracle.java | 3 +- .../ventaboletos/entidad/Custom.java | 167 +++++++++ .../entidad/CustomIdGenerator.java | 3 +- .../ventaboletos/entidad/Usuario.java | 3 +- .../ventaboletos/enums/SistemaEnum.java | 35 ++ .../ventaboletos/service/CustomService.java | 16 + .../service/impl/CustomServiceImpl.java | 69 ++++ .../service/impl/EstacionServiceImpl.java | 7 +- .../service/impl/PuntoVentaServiceImpl.java | 7 +- .../impl/TipoEventoExtraServiceImpl.java | 5 +- .../service/impl/UsuarioServiceImpl.java | 7 +- .../utilerias/ApplicationProperties.java | 322 ++++-------------- .../ventaboletos/utilerias/CustomEnum.java | 148 ++++++++ 20 files changed, 598 insertions(+), 267 deletions(-) create mode 100644 src/com/rjconsultores/ventaboletos/dao/CustomDAO.java create mode 100644 src/com/rjconsultores/ventaboletos/dao/hibernate/CustomHibernateDAO.java create mode 100644 src/com/rjconsultores/ventaboletos/entidad/Custom.java create mode 100644 src/com/rjconsultores/ventaboletos/enums/SistemaEnum.java create mode 100644 src/com/rjconsultores/ventaboletos/service/CustomService.java create mode 100644 src/com/rjconsultores/ventaboletos/service/impl/CustomServiceImpl.java create mode 100644 src/com/rjconsultores/ventaboletos/utilerias/CustomEnum.java diff --git a/src/com/rjconsultores/ventaboletos/dao/CustomDAO.java b/src/com/rjconsultores/ventaboletos/dao/CustomDAO.java new file mode 100644 index 000000000..8093baebf --- /dev/null +++ b/src/com/rjconsultores/ventaboletos/dao/CustomDAO.java @@ -0,0 +1,14 @@ +package com.rjconsultores.ventaboletos.dao; + +import java.util.List; + +import com.rjconsultores.ventaboletos.entidad.Custom; + +/** + * + * @author Lucas + */ +public interface CustomDAO extends GenericDAO { + + public Custom buscar(String chave); +} diff --git a/src/com/rjconsultores/ventaboletos/dao/hibernate/CalcularPeajeHibernateDAO.java b/src/com/rjconsultores/ventaboletos/dao/hibernate/CalcularPeajeHibernateDAO.java index f85f03494..3424d9776 100644 --- a/src/com/rjconsultores/ventaboletos/dao/hibernate/CalcularPeajeHibernateDAO.java +++ b/src/com/rjconsultores/ventaboletos/dao/hibernate/CalcularPeajeHibernateDAO.java @@ -40,6 +40,7 @@ import com.rjconsultores.ventaboletos.service.OrgaoConcedenteService; import com.rjconsultores.ventaboletos.service.PrecioFixoPedagioService; import com.rjconsultores.ventaboletos.service.RutaCombinacionService; import com.rjconsultores.ventaboletos.utilerias.ApplicationProperties; +import com.rjconsultores.ventaboletos.utilerias.CustomEnum; import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado; @Repository("calcularPeajeDAO") @@ -408,7 +409,7 @@ public class CalcularPeajeHibernateDAO extends GenericHibernateDAO + implements CustomDAO { + + @Autowired + public CustomHibernateDAO(@Qualifier("sessionFactory") SessionFactory factory) { + setSessionFactory(factory); + } + + @Override + public List obtenerTodos() { + Criteria c = getSession().createCriteria(getPersistentClass()); + c.add(Restrictions.eq("activo", Boolean.TRUE)); + + return c.list(); + } + + public Custom buscar(String chave) { + Criteria c = getSession().createCriteria(getPersistentClass()); + c.add(Restrictions.eq("activo", Boolean.TRUE)); + + c.add(Restrictions.ilike("chave", chave)); + + return (Custom) c.uniqueResult(); + } +} diff --git a/src/com/rjconsultores/ventaboletos/dao/hibernate/RutaCombinacionHibernateDAO.java b/src/com/rjconsultores/ventaboletos/dao/hibernate/RutaCombinacionHibernateDAO.java index 158600d8b..d41d5d8b5 100644 --- a/src/com/rjconsultores/ventaboletos/dao/hibernate/RutaCombinacionHibernateDAO.java +++ b/src/com/rjconsultores/ventaboletos/dao/hibernate/RutaCombinacionHibernateDAO.java @@ -37,6 +37,7 @@ import com.rjconsultores.ventaboletos.entidad.TipoPuntoVenta; import com.rjconsultores.ventaboletos.entidad.Tramo; import com.rjconsultores.ventaboletos.entidad.VigenciaTarifa; import com.rjconsultores.ventaboletos.utilerias.ApplicationProperties; +import com.rjconsultores.ventaboletos.utilerias.CustomEnum; import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado; import com.rjconsultores.ventaboletos.vo.tarifa.TarifaEscalaGroupVO; import com.rjconsultores.ventaboletos.vo.tarifa.TarifaEscalaVO; @@ -413,7 +414,7 @@ public class RutaCombinacionHibernateDAO extends GenericHibernateDAO 21 "); - if(ApplicationProperties.getInstance().criarTarifaApenasTrechoVendido()){ + if(ApplicationProperties.getInstance().isCustomHabilitado(CustomEnum.CRIAR_TARIFA_APENAS_TRECHO_VENDIDO.getDescricao())){ sb.append(" and rc.indventa = 1 "); } if (idsEmpresas != null) { diff --git a/src/com/rjconsultores/ventaboletos/entidad/Custom.java b/src/com/rjconsultores/ventaboletos/entidad/Custom.java new file mode 100644 index 000000000..90b062625 --- /dev/null +++ b/src/com/rjconsultores/ventaboletos/entidad/Custom.java @@ -0,0 +1,167 @@ +/* + * 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.SequenceGenerator; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; + +/** + * + * @author Lucas + */ +@Entity +@SequenceGenerator(name = "CUSTOM_SEQ", sequenceName = "CUSTOM_SEQ", allocationSize = 1) +@Table(name = "CUSTOM") +public class Custom implements Serializable { + + public static final Integer TIPO_SISTEMA_CLIENTE = 1; + public static final Integer TIPO_SISTEMA_SERVIDOR = 2; + public static final Integer TIPO_SISTEMA_ADM = 3; + + private static final long serialVersionUID = 1L; + @Id + @Basic(optional = false) + @GeneratedValue(strategy = GenerationType.AUTO, generator = "CUSTOM_SEQ") + @Column(name = "CUSTOM_ID") + private Integer customId; + @Column(name = "SISTEMA") + private Integer sistema; + @Column(name = "TIPO") + private Integer tipo; + @Column(name = "ORDEM") + private Integer ordem; + @Column(name = "REFERENCIA") + private String referencia; + @Column(name = "CHAVE") + private String chave; + @Column(name = "VALOR") + private String valor; + @Column(name = "ACTIVO") + private Boolean activo; + @Column(name = "FECMODIF") + @Temporal(TemporalType.TIMESTAMP) + private Date fecmodif; + @Column(name = "USUARIO_ID") + private Integer usuarioId; + + public Custom() { + } + + public Integer getCustomId() { + return customId; + } + + public void setCustomId(Integer customId) { + this.customId = customId; + } + + public Integer getSistema() { + return sistema; + } + + public void setSistema(Integer sistema) { + this.sistema = sistema; + } + + public Integer getTipo() { + return tipo; + } + + public void setTipo(Integer tipo) { + this.tipo = tipo; + } + + public Integer getOrdem() { + return ordem; + } + + public void setOrdem(Integer ordem) { + this.ordem = ordem; + } + + public String getReferencia() { + return referencia; + } + + public void setReferencia(String referencia) { + this.referencia = referencia; + } + + public String getChave() { + return chave; + } + + public void setChave(String chave) { + this.chave = chave; + } + + public String getValor() { + return valor; + } + + public void setValor(String valor) { + this.valor = valor; + } + + 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; + } + + @Override + public int hashCode() { + int hash = 0; + hash += (customId != null ? customId.hashCode() : 0); + return hash; + } + + @Override + public boolean equals(Object object) { + if (!(object instanceof Custom)) { + return false; + } + Custom other = (Custom) object; + if ((this.customId == null && other.customId != null) || (this.customId != null && !this.customId.equals(other.customId))) { + return false; + } + return true; + } + + @Override + public String toString() { + return "com.rjconsultores.ventaboletos.entidad.Custom[customId=" + customId + "]"; + } + +} diff --git a/src/com/rjconsultores/ventaboletos/entidad/CustomIdGenerator.java b/src/com/rjconsultores/ventaboletos/entidad/CustomIdGenerator.java index a9b41d0d9..528f7937f 100644 --- a/src/com/rjconsultores/ventaboletos/entidad/CustomIdGenerator.java +++ b/src/com/rjconsultores/ventaboletos/entidad/CustomIdGenerator.java @@ -16,6 +16,7 @@ import org.hibernate.id.Configurable; import org.hibernate.id.IdentifierGenerator; import com.rjconsultores.ventaboletos.utilerias.ApplicationProperties; +import com.rjconsultores.ventaboletos.utilerias.CustomEnum; public class CustomIdGenerator implements IdentifierGenerator, Configurable { @@ -36,7 +37,7 @@ public class CustomIdGenerator implements IdentifierGenerator, Configurable { if (rs.next()) { Integer id = rs.getInt("NEXTVAL"); String newValue = id.toString(); - if (ApplicationProperties.getInstance().habilitarCustomSequence()) { + if (ApplicationProperties.getInstance().isCustomHabilitado(CustomEnum.HABILITAR_CUSTOM_SEQUENCE.getDescricao())) { newValue = "1" + (StringUtils.leftPad(id.toString(), tamanho, "0")); } return Integer.valueOf(newValue); diff --git a/src/com/rjconsultores/ventaboletos/entidad/Usuario.java b/src/com/rjconsultores/ventaboletos/entidad/Usuario.java index d8fbc0eec..63a32b6a4 100644 --- a/src/com/rjconsultores/ventaboletos/entidad/Usuario.java +++ b/src/com/rjconsultores/ventaboletos/entidad/Usuario.java @@ -37,6 +37,7 @@ import org.springframework.security.core.userdetails.UserDetails; import com.rjconsultores.ventaboletos.service.ConstanteService; import com.rjconsultores.ventaboletos.utilerias.ApplicationProperties; +import com.rjconsultores.ventaboletos.utilerias.CustomEnum; import com.rjconsultores.ventaboletos.utilerias.DateUtil; import com.rjconsultores.ventaboletos.web.utilerias.spring.AppContext; @@ -310,7 +311,7 @@ public class Usuario implements Serializable, Authentication, UserDetails { } public boolean isCredentialsNonExpired() { - if (ApplicationProperties.getInstance().contrasenaValidaComplejidad()) { + if (ApplicationProperties.getInstance().isCustomHabilitado(CustomEnum.CONTRASENA_VALIDA_COMPLEJIDAD.getDescricao())) { if (getFecContrasena() != null) { ConstanteService constanteService = (ConstanteService) AppContext.getApplicationContext().getBean("constanteService"); Constante contante = constanteService.buscarPorNomeConstante("CANT_DIAS_CONTRASENA"); diff --git a/src/com/rjconsultores/ventaboletos/enums/SistemaEnum.java b/src/com/rjconsultores/ventaboletos/enums/SistemaEnum.java new file mode 100644 index 000000000..bd5eec30a --- /dev/null +++ b/src/com/rjconsultores/ventaboletos/enums/SistemaEnum.java @@ -0,0 +1,35 @@ +package com.rjconsultores.ventaboletos.enums; + +public enum SistemaEnum { + + VENDA_CLIENTE(1, "Venda Cliente"), + VENDA_SERVIDOR(2, "Venda Servidor"), + ADM(3, "Administração"); + + private Integer valor; + private String descricao; + + private SistemaEnum(Integer valor, String descricao) { + this.valor = valor; + this.descricao = descricao; + } + + public Integer getValor() { + return this.valor; + } + + @Override + public String toString() { + return this.descricao; + } + + public static SistemaEnum getSistema(Integer tValor) { + for (SistemaEnum valor : SistemaEnum.values()) { + if (valor.getValor().equals(tValor)) { + return valor; + } + } + return null; + } + +} diff --git a/src/com/rjconsultores/ventaboletos/service/CustomService.java b/src/com/rjconsultores/ventaboletos/service/CustomService.java new file mode 100644 index 000000000..7ac7e85ba --- /dev/null +++ b/src/com/rjconsultores/ventaboletos/service/CustomService.java @@ -0,0 +1,16 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package com.rjconsultores.ventaboletos.service; + +import com.rjconsultores.ventaboletos.entidad.Custom; + +/** + * + * @author Lucas + */ +public interface CustomService extends GenericService { + + public Custom buscar(String chave); +} diff --git a/src/com/rjconsultores/ventaboletos/service/impl/CustomServiceImpl.java b/src/com/rjconsultores/ventaboletos/service/impl/CustomServiceImpl.java new file mode 100644 index 000000000..447f7dcc1 --- /dev/null +++ b/src/com/rjconsultores/ventaboletos/service/impl/CustomServiceImpl.java @@ -0,0 +1,69 @@ +/* + * 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.Propagation; +import org.springframework.transaction.annotation.Transactional; + +import com.rjconsultores.ventaboletos.dao.CustomDAO; +import com.rjconsultores.ventaboletos.entidad.Custom; +import com.rjconsultores.ventaboletos.service.CustomService; +import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado; + +/** + * + * @author Lucas + */ +@Service("customService") +public class CustomServiceImpl implements CustomService { + + @Autowired + private CustomDAO customDAO; + + public List obtenerTodos() { + return customDAO.obtenerTodos(); + } + + public Custom obtenerID(Integer id) { + return customDAO.obtenerID(id); + } + + @Transactional(propagation = Propagation.SUPPORTS) + public Custom suscribir(Custom entidad) { + entidad.setUsuarioId(UsuarioLogado.getUsuarioLogado() != null ? UsuarioLogado.getUsuarioLogado().getUsuarioId() : null); + entidad.setFecmodif(Calendar.getInstance().getTime()); + entidad.setActivo(Boolean.TRUE); + + return customDAO.suscribir(entidad); + } + + @Transactional + public Custom actualizacion(Custom entidad) { + entidad.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId()); + entidad.setFecmodif(Calendar.getInstance().getTime()); + entidad.setActivo(Boolean.TRUE); + + return customDAO.actualizacion(entidad); + } + + @Transactional + public void borrar(Custom entidad) { + entidad.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId()); + entidad.setFecmodif(Calendar.getInstance().getTime()); + entidad.setActivo(Boolean.FALSE); + + customDAO.actualizacion(entidad); + } + + @Transactional(readOnly = true, propagation = Propagation.SUPPORTS) + public Custom buscar(String chave) { + return customDAO.buscar(chave); + } +} diff --git a/src/com/rjconsultores/ventaboletos/service/impl/EstacionServiceImpl.java b/src/com/rjconsultores/ventaboletos/service/impl/EstacionServiceImpl.java index e2bb7748d..f6800ab86 100644 --- a/src/com/rjconsultores/ventaboletos/service/impl/EstacionServiceImpl.java +++ b/src/com/rjconsultores/ventaboletos/service/impl/EstacionServiceImpl.java @@ -23,6 +23,7 @@ import com.rjconsultores.ventaboletos.exception.BusinessException; import com.rjconsultores.ventaboletos.service.AutorizaFolioService; import com.rjconsultores.ventaboletos.service.EstacionService; import com.rjconsultores.ventaboletos.utilerias.ApplicationProperties; +import com.rjconsultores.ventaboletos.utilerias.CustomEnum; import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado; /** @@ -96,7 +97,7 @@ public class EstacionServiceImpl implements EstacionService { String errorNoChequeFolio = null; for (EstacionImpresora ei : estacion.getLsEstacionImpresora()) { boolean isImpressoraFiscal = validacionImpressoraFiscal(ei); - if (ApplicationProperties.getInstance().generarRotinaFolios()) { + if (ApplicationProperties.getInstance().isCustomHabilitado(CustomEnum.GENERAR_ROTINA_FOLIOS.getDescricao())) { errorNoChequeFolio = autorizaFolioService.noChequeFolioPreimpresos(ei, false); } else if ((isImpressoraFiscal && isNuevaFiscal) || (estacion.getIndStockCentral() != null && estacion.getIndStockCentral() && isImpressoraFiscal)) { @@ -142,7 +143,7 @@ public class EstacionServiceImpl implements EstacionService { return; } - if (!ApplicationProperties.getInstance().generarRotinaFolios()) { + if (!ApplicationProperties.getInstance().isCustomHabilitado(CustomEnum.GENERAR_ROTINA_FOLIOS.getDescricao())) { Estacion estacionPuntoVentaAnterior = estacionDAO.obtenerID(estacion.getEstacionId()); if (estacionPuntoVentaAnterior.getPuntoVenta() != null) if (!estacionPuntoVentaAnterior.getPuntoVenta().equals(estacion.getPuntoVenta())) { @@ -154,7 +155,7 @@ public class EstacionServiceImpl implements EstacionService { } private void validarEstoqueBorrar(Estacion estacion) throws BusinessException { - if (!ApplicationProperties.getInstance().generarRotinaFolios()) { + if (!ApplicationProperties.getInstance().isCustomHabilitado(CustomEnum.GENERAR_ROTINA_FOLIOS.getDescricao())) { if (estacionDAO.temEstoque(estacion.getPuntoVenta(), estacion)) { throw new BusinessException("estacionServiceImpl.msg.hayStock.borrar"); } diff --git a/src/com/rjconsultores/ventaboletos/service/impl/PuntoVentaServiceImpl.java b/src/com/rjconsultores/ventaboletos/service/impl/PuntoVentaServiceImpl.java index 18183f3ec..a316103fa 100644 --- a/src/com/rjconsultores/ventaboletos/service/impl/PuntoVentaServiceImpl.java +++ b/src/com/rjconsultores/ventaboletos/service/impl/PuntoVentaServiceImpl.java @@ -45,6 +45,7 @@ import com.rjconsultores.ventaboletos.service.ConstanteService; import com.rjconsultores.ventaboletos.service.EstacionService; import com.rjconsultores.ventaboletos.service.PuntoVentaService; import com.rjconsultores.ventaboletos.utilerias.ApplicationProperties; +import com.rjconsultores.ventaboletos.utilerias.CustomEnum; import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado; import com.rjconsultores.ws.totvs.service.TotvsService; import com.rjconsultores.ws.utileria.Atributos; @@ -102,7 +103,7 @@ public class PuntoVentaServiceImpl implements PuntoVentaService { Constante constDesativaTotvs = constanteService.buscarPorNomeConstante("WS_TOTVS_DESATIVA_INTEGRACAO"); Boolean desativaTotvs = constDesativaTotvs != null && constDesativaTotvs.getValorconstante().equals("1"); if (!desativaTotvs){ - if (ApplicationProperties.getInstance().integracionTotvs()) { + if (ApplicationProperties.getInstance().isCustomHabilitado(CustomEnum.INTEGRACION_TOTVS.getDescricao())) { try { if (entidad.getIndIntegracion() == null || (entidad.getIndIntegracion().equals(TipoRetorno.PENDENTE.getValor()) @@ -415,7 +416,7 @@ public class PuntoVentaServiceImpl implements PuntoVentaService { Boolean desativaTotvs = constDesativaTotvs != null && constDesativaTotvs.getValorconstante().equals("1"); // desativaTotvs = true; if (!desativaTotvs){ - if (ApplicationProperties.getInstance().integracionTotvs()) { + if (ApplicationProperties.getInstance().isCustomHabilitado(CustomEnum.INTEGRACION_TOTVS.getDescricao())) { try { if (entidad.getIndIntegracion() == null || (entidad.getIndIntegracion().equals(TipoRetorno.PENDENTE.getValor()) @@ -616,7 +617,7 @@ public class PuntoVentaServiceImpl implements PuntoVentaService { } private String integracionTotvs(PuntoVenta puntoVenta) throws Exception { - if (ApplicationProperties.getInstance().integracionTotvs()) { + if (ApplicationProperties.getInstance().isCustomHabilitado(CustomEnum.INTEGRACION_TOTVS.getDescricao())) { validaCampos(puntoVenta); diff --git a/src/com/rjconsultores/ventaboletos/service/impl/TipoEventoExtraServiceImpl.java b/src/com/rjconsultores/ventaboletos/service/impl/TipoEventoExtraServiceImpl.java index 48000e0ab..a19f2c039 100644 --- a/src/com/rjconsultores/ventaboletos/service/impl/TipoEventoExtraServiceImpl.java +++ b/src/com/rjconsultores/ventaboletos/service/impl/TipoEventoExtraServiceImpl.java @@ -18,6 +18,7 @@ import com.rjconsultores.ventaboletos.exception.ValidacionCampoException; import com.rjconsultores.ventaboletos.service.EventoExtraService; import com.rjconsultores.ventaboletos.service.TipoEventoExtraService; import com.rjconsultores.ventaboletos.utilerias.ApplicationProperties; +import com.rjconsultores.ventaboletos.utilerias.CustomEnum; import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado; /** @@ -46,7 +47,7 @@ public class TipoEventoExtraServiceImpl implements TipoEventoExtraService { entidad.setFecmodif(Calendar.getInstance().getTime()); entidad.setActivo(Boolean.TRUE); - if (ApplicationProperties.getInstance().integracionTotvs()) { + if (ApplicationProperties.getInstance().isCustomHabilitado(CustomEnum.INTEGRACION_TOTVS.getDescricao())) { validaCampos(entidad); } @@ -59,7 +60,7 @@ public class TipoEventoExtraServiceImpl implements TipoEventoExtraService { entidad.setFecmodif(Calendar.getInstance().getTime()); entidad.setActivo(Boolean.TRUE); - if (ApplicationProperties.getInstance().integracionTotvs()) { + if (ApplicationProperties.getInstance().isCustomHabilitado(CustomEnum.INTEGRACION_TOTVS.getDescricao())) { validaCampos(entidad); } diff --git a/src/com/rjconsultores/ventaboletos/service/impl/UsuarioServiceImpl.java b/src/com/rjconsultores/ventaboletos/service/impl/UsuarioServiceImpl.java index c006a8243..7ed65d8a1 100644 --- a/src/com/rjconsultores/ventaboletos/service/impl/UsuarioServiceImpl.java +++ b/src/com/rjconsultores/ventaboletos/service/impl/UsuarioServiceImpl.java @@ -26,6 +26,7 @@ import com.rjconsultores.ventaboletos.entidad.UsuarioPerfil; import com.rjconsultores.ventaboletos.exception.BusinessException; import com.rjconsultores.ventaboletos.service.UsuarioService; import com.rjconsultores.ventaboletos.utilerias.ApplicationProperties; +import com.rjconsultores.ventaboletos.utilerias.CustomEnum; import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado; import com.rjconsultores.ventaboletos.utilerias.seguridad.ContrasenaUtileria; @@ -77,7 +78,7 @@ public class UsuarioServiceImpl implements UsuarioService, UserDetailsService { } if (senha != null) { // validación complejidad contrasena - if (ApplicationProperties.getInstance().contrasenaValidaComplejidad()) { + if (ApplicationProperties.getInstance().isCustomHabilitado(CustomEnum.CONTRASENA_VALIDA_COMPLEJIDAD.getDescricao())) { ContrasenaUtileria contrasenaUtileria = new ContrasenaUtileria(); contrasenaUtileria.validarContrasenaCompleja(senha); } @@ -139,7 +140,7 @@ public class UsuarioServiceImpl implements UsuarioService, UserDetailsService { } if (senha != null) { // validación complejidad contrasena - if (ApplicationProperties.getInstance().contrasenaValidaComplejidad()) { + if (ApplicationProperties.getInstance().isCustomHabilitado(CustomEnum.CONTRASENA_VALIDA_COMPLEJIDAD.getDescricao())) { ContrasenaUtileria contrasenaUtileria = new ContrasenaUtileria(); contrasenaUtileria.validarContrasenaCompleja(senha); } @@ -196,7 +197,7 @@ public class UsuarioServiceImpl implements UsuarioService, UserDetailsService { Usuario user = list.get(0); - if (ApplicationProperties.getInstance().contrasenaValidaComplejidad()) { + if (ApplicationProperties.getInstance().isCustomHabilitado(CustomEnum.CONTRASENA_VALIDA_COMPLEJIDAD.getDescricao())) { if (!user.isCredentialsNonExpired()) { throw new CredentialsExpiredException("Senha Expirada"); } diff --git a/src/com/rjconsultores/ventaboletos/utilerias/ApplicationProperties.java b/src/com/rjconsultores/ventaboletos/utilerias/ApplicationProperties.java index ae2632b31..8582a5bd9 100644 --- a/src/com/rjconsultores/ventaboletos/utilerias/ApplicationProperties.java +++ b/src/com/rjconsultores/ventaboletos/utilerias/ApplicationProperties.java @@ -11,20 +11,35 @@ import java.util.Properties; import org.apache.log4j.Logger; import org.springframework.core.io.ClassPathResource; +import com.rjconsultores.ventaboletos.entidad.Custom; +import com.rjconsultores.ventaboletos.service.ConstanteService; +import com.rjconsultores.ventaboletos.service.CustomService; +import com.rjconsultores.ventaboletos.web.utilerias.spring.AppContext; + /** * Clase con las propriedad especificas de los clientes * * @author Administrador */ + public class ApplicationProperties { private static Logger log = Logger.getLogger(ApplicationProperties.class); private static ApplicationProperties INSTANCE; private static Properties p; - + private ApplicationProperties() { p = new Properties(); this.readConfiguration(); + this.readConfigurationToDatabase(); + } + + public static ApplicationProperties getInstance() { + if (INSTANCE == null) { + INSTANCE = new ApplicationProperties(); + } + + return INSTANCE; } private void readConfiguration() { @@ -37,266 +52,77 @@ public class ApplicationProperties { log.error(e); } } + + /** + * Insere na tabela de custom os registros que existem no Enum, o valor inicial ao inserir de cada custom é baseado no arquivo de propriedades + * {@code database.properties}, caso não exista é inserido com valor {@code null}. A cada novo parâmetro no Enum será adicionado um registro na tabela de custom. Não deverá mais ser adicionado + * mais informações no arquivo de propriedades, somente no Enum {@code CustomEnum}. + * @see #CustomEnum + */ + public void readConfigurationToDatabase() { - public static ApplicationProperties getInstance() { - if (INSTANCE == null) { - INSTANCE = new ApplicationProperties(); + try { + CustomService customService = (CustomService) AppContext.getApplicationContext().getBean("customService"); + for (CustomEnum customEnum : CustomEnum.values()) { + if (customService.buscar(customEnum.toString()) == null) { + + Custom custom = new Custom(); + custom.setChave(customEnum.toString()); + custom.setValor(p.getProperty(customEnum.toString())); + custom.setSistema(Custom.TIPO_SISTEMA_ADM); + customService.suscribir(custom); + + log.info("Adicionado custom=" + customEnum.toString()); + } + } + + } catch (Exception e) { + log.error("", e); + } + } + + private String getValuefromCustom(String key, String defaultValue) { + + try { + CustomService customService = (CustomService) AppContext.getApplicationContext().getBean("customService"); + Custom custom = customService.buscar(key); + if (custom != null) { + String val = custom.getValor(); + return (val == null) ? defaultValue : val; + } + + } catch (Exception e) { + log.error("", e); } - return INSTANCE; - } + return defaultValue; - /** - * Indica se la informacion de equivalencia es visible - * - * @return - */ - public boolean mostrarEquivalencia() { - String property = p.getProperty("equivalencia.mostrar", "0"); - return property.equals("1"); - } - - /** - * Indica se o campo empresa é obrigatório - * @return - */ - public boolean empresaObrigatoria() { - String property = p.getProperty("empresa.obrigatoria", "0"); - return property.equals("1"); - } - - /** - * Indica se es gerado o campo equivalencia corrida na tabela de corrida - * - * @return - */ - public boolean gerarCampoEquivalenciaCorrida() { - String property = p.getProperty("corrida.gerarCampoEquivalencia", "0"); - return property.equals("1"); - } - - /** - * Indica exibe o combo de Division na Gera��o de Corridas do Esquema Operacional. - * - * @return - */ - public boolean exibirDivisionConfiguracionCorrida() { - String property = p.getProperty("esquemaOperacional.configuracionCorrida.exibeDivision", "0"); - return property.equals("1"); - } - - /** - * Indica se va a exhibir la cuenta contable en el catalogo de tipos de eventos - * - * @return - */ - public boolean exhibirCuentaContableTiposEventos() { - String property = p.getProperty("eventosExtras.tiposEventos.exhibirCuentaContable", "1"); - return property.equals("1"); - } - - /** - * Indica se va a exhibir la "aba" de excepciones de tramo_km en la pantalla de tramos - * - * @return - */ - public boolean exhibirExcepcionesTramoKm() { - String property = p.getProperty("tramos.exhibirExcepcionesTramoKm", "0"); - return property.equals("1"); - } - - /** - * Indica se vai exibir botão na modificação massiva de tarifa de geração automatica de tarifas - * - * @return - */ - public boolean generarTarifasAutomatica() { - String property = p.getProperty("tarifa.generarTarifasAutomatica", "0"); - return property.equals("1"); - } - - public boolean generarRotinaFolios() { - String property = p.getProperty("no.cheque.folio", "0"); - return property.equals("1"); - } - - public boolean habilitarPricingCategoria() { - String property = p.getProperty("pricing.categoria.habilitar", "0"); - return property.equals("1"); - } - - public boolean rutaConMasDeUnaClase() { - String property = p.getProperty("ruta.masdeunaclase", "0"); - return property.equals("1"); - } - - public boolean diagramaAutobusDosPestana() { - String property = p.getProperty("diagramaautobus.dospestana", "0"); - return property.equals("1"); - } - - public boolean contrasenaValidaComplejidad() { - String property = p.getProperty("contrasena.validaComplejidad", "0"); - return property.equals("1"); - } - - public boolean habilitarCustomSequence() { - String property = p.getProperty("custom.sequence", "0"); - return property.equals("1"); - } - - public boolean integracionTotvs() { - String property = p.getProperty("integracion.totvs", "0"); - return property.equals("1"); - } - - public boolean integracionAG() { - String property = p.getProperty("integracion.AG", "0"); - return property.equals("1"); - } - - public boolean integracionAGWS() { - String property = p.getProperty("integracion.agws", "0"); - return property.equals("1"); - } - - public boolean integracionRioCard() { - String property = p.getProperty("integracion.riocard", "0"); - return property.equals("1"); - } - - public boolean diagramaAutobusTrem() { - String property = p.getProperty("layoutdiagramaautobus.trem", "0"); - return property.equals("1"); - } - - public boolean validaEstadoNoNomeLocalidade() { - String property = p.getProperty("validaEstadoNomeLocalidade", "0"); - return property.equals("1"); - } - - public boolean podeEditarClienteFidelidade() { - String property = p.getProperty("podeEditarClienteFidelidade", "0"); - return property.equals("1"); - } - - public boolean validaSobreposicaoVigencia() { - String property = p.getProperty("validaSobreposicaoVigencia", "0"); - return property.equals("1"); - } - - public boolean usaCPFComoFidelidade(){ - String property = p.getProperty("usaCPFComoFidelidade", "0"); - return property.equals("1"); - } - - public boolean usaPadraoPricingTipoPassagemPET(){ - String property = p.getProperty("usaPadroPricingEspecificoTipoPassagemPET", "0"); - return property.equals("1"); - } - - public boolean exibeTpp() { - String property = p.getProperty("exibeTpp", "0"); - return property.equals("1"); - } - - public boolean codAnttNaoObrigatorio() { - String property = p.getProperty("codAnttNaoObrigatorio", "0"); - return property.equals("1"); - } - - public boolean artespPedagioIdaVoltaDivPor2() { - String property = p.getProperty("artespPedagioIdaVoltaDivPor2", "0"); - return property.equals("1"); - } - - public boolean calculoPeajeReunidasANTT() { - String property = p.getProperty("calculoPeajeReunidasANTT", "0"); - return property.equals("1"); } public Integer maxSizeNumCorrida() { - String property = p.getProperty("maxSizeNumCorrida", "-1"); + String property = getValuefromCustom(CustomEnum.MAX_SIZE_NUM_CORRIDA.toString(), "-1"); return Integer.parseInt(property); } - - public boolean criarTarifaApenasTrechoVendido() { - String property = p.getProperty("criarTarifaApenasTrechoVendido", "0"); - return property.equals("1"); - } - - public boolean exibirEstacaoCadastroUsuario() { - String property = p.getProperty("exibirEstacaoCadastroUsuario", "0"); - return property.equals("1"); - } - - public boolean utillizaCartaoLiberCard() { - String property = p.getProperty("utilizaLibercard", "0"); - return property.equals("1"); - } - + /** - * - * Indica se ao salvar um ponto de venda será validado se para todas as empresas informadas para venda também será necessário informar o fechamento. - * - * @return - */ - public boolean validaContaCorrenteEmpesaPtoVta() { - String property = p.getProperty("puntoVenta.validaCtaCteEmpresa", "1"); - return property.equals("1"); - } - - public boolean isDataSourceComissaoBancoProducao() { - String property = p.getProperty("datasource.conferencia.comissao", "0"); - return property.equals("0"); - } - - public boolean isPermiteVariasImpressorasMesmaEmpresa() { - String property = p.getProperty("permiteVariasImpressorasMesmaEmpresa", "0"); - return property.equals("1"); - } - - public boolean isFormaPagoPricingInativo() { - String property = p.getProperty("formaPagoPricingInativo", "1"); - return property.equals("1"); - } - - public boolean exibirPuntoVentaCadastroAIDF() { - String property = p.getProperty("exibirPuntoVentaCadastroAIDF", "0"); - return property.equals("1"); - } - public boolean isPuntoVentaCadastroAIDFObrigatorio() { - String property = p.getProperty("puntoVentaCadastroAIDFObrigatorio", "0"); + * Procura a chave no banco de dados, caso exista retorna o valor, caso não exista retorna 0. + * + * @param key o valor da chave. + * @return o valor do custom no banco. + */ + public boolean isCustomHabilitado(String key) { + String property = getValuefromCustom(key, "0"); return property.equals("1"); } - public boolean enderecoClienteObrigatorio() { - String property = p.getProperty("cliente.enderecoObrigatorio", "1"); - return property.equals("1"); - } - - public boolean isPermiteLayoutInternacional() { - String property = p.getProperty("permiteLayoutInternacional", "0"); - return property.equals("1"); - } - - public boolean relatorioTaxasLinhaTxtDownloadVisible() { - String property = p.getProperty("taxasLinhaTxtDownloadVisible", "0"); - return property.equals("1"); - } - - public boolean isPermiteCalculoComissaoPeriodo() { - String property = p.getProperty("permiteCalculoComissaoPeriodo", "0"); - return property.equals("1"); - } - - public boolean isIncluiTipoPagamentoTurismoBGM() { - String property = p.getProperty("incluiTipoPagamentoTurismoBGM", "0"); - return property.equals("1"); - } - - public boolean isGerarTrechoAutomaticoDefaultNao() { - String property = p.getProperty("gerarTrechoAutomaticoDefaultNao", "0"); + /** + * Procura a chave no banco de dados, caso exista retorna o valor, caso não exista retorna o valor default. + * + * @param key o valor da chave. + * @return o valor do custom no banco. + */ + public boolean isCustomHabilitado(String key, String defaultValue) { + String property = getValuefromCustom(key, defaultValue); return property.equals("1"); } } diff --git a/src/com/rjconsultores/ventaboletos/utilerias/CustomEnum.java b/src/com/rjconsultores/ventaboletos/utilerias/CustomEnum.java new file mode 100644 index 000000000..ce00b76e5 --- /dev/null +++ b/src/com/rjconsultores/ventaboletos/utilerias/CustomEnum.java @@ -0,0 +1,148 @@ +package com.rjconsultores.ventaboletos.utilerias; + +public enum CustomEnum { + + /** + * Indica se la informacion de equivalencia es visible + * + * @return + */ + MOSTRAR_EQUIVALENCIA("equivalencia.mostrar"), + + /** + * Indica se o campo empresa é obrigatório + * @return + */ + EMPRESA_OBRIGATORIA("empresa.obrigatoria"), + + /** + * Indica se es gerado o campo equivalencia corrida na tabela de corrida + * + * @return + */ + GERAR_CAMPO_EQUIVALENCIA_CORRIDA("corrida.gerarCampoEquivalencia"), + + /** + * Indica exibe o combo de Division na Gera��o de Corridas do Esquema Operacional. + * + * @return + */ + EXIBIR_DIVISION_CONFIGURACION_CORRIDA("esquemaOperacional.configuracionCorrida.exibeDivision"), + + /** + * Indica se va a exhibir la cuenta contable en el catalogo de tipos de eventos + * + * @return + */ + EXHIBIR_CUENTA_CONTABLE_TIPOS_EVENTOS("eventosExtras.tiposEventos.exhibirCuentaContable"), + + /** + * Indica se va a exhibir la "aba" de excepciones de tramo_km en la pantalla de tramos + * + * @return + */ + EXHIBIR_EXCEPCIONES_TRAMO_KM("tramos.exhibirExcepcionesTramoKm"), + + /** + * Indica se vai exibir botão na modificação massiva de tarifa de geração automatica de tarifas + * + * @return + */ + GENERAR_TARIFAS_AUTOMATICA("tarifa.generarTarifasAutomatica"), + + GENERAR_ROTINA_FOLIOS("no.cheque.folio"), + + HABILITAR_PRICING_CATEGORIA("pricing.categoria.habilitar"), + + RUTA_CON_MAS_DE_UNA_CLASE("ruta.masdeunaclase"), + + DIAGRAMA_AUTOBUS_DOS_PESTANA("diagramaautobus.dospestana"), + + CONTRASENA_VALIDA_COMPLEJIDAD("contrasena.validaComplejidad"), + + HABILITAR_CUSTOM_SEQUENCE("custom.sequence"), + + INTEGRACION_TOTVS("integracion.totvs"), + + INTEGRACION_AG("integracion.AG"), + + INTEGRACION_AGWS("integracion.agws"), + + INTEGRACION_RIOCARD("integracion.riocard"), + + DIAGRAMA_AUTOBUS_TREM("layoutdiagramaautobus.trem"), + + VALIDA_ESTADO_NO_NOME_LOCALIDADE("validaEstadoNomeLocalidade"), + + PODE_EDITAR_CLIENTE_FIDELIDADE("podeEditarClienteFidelidade"), + + VALIDA_SOBREPOSICAO_VIGENCIA("validaSobreposicaoVigencia"), + + USA_CPF_COMO_FIDELIDADE("usaCPFComoFidelidade"), + + USA_PADRAO_PRICING_TIPO_PASSAGEM_PET("usaPadroPricingEspecificoTipoPassagemPET"), + + EXIBE_TPP("exibeTpp"), + + COD_ANTT_NAO_OBRIGATORIO("codAnttNaoObrigatorio"), + + ARTESP_PEDAGIO_IDA_VOLTA_DIV_POR2("artespPedagioIdaVoltaDivPor2"), + + CALCULO_PEAJE_REUNIDAS_ANTT("calculoPeajeReunidasANTT"), + + MAX_SIZE_NUM_CORRIDA("maxSizeNumCorrida"), + + CRIAR_TARIFA_APENAS_TRECHO_VENDIDO("criarTarifaApenasTrechoVendido"), + + EXIBIR_ESTACAO_CADASTRO_USUARIO("exibirEstacaoCadastroUsuario"), + + UTILLIZA_CARTAO_LIBERCARD("utilizaLibercard"), + + /** + * + * Indica se ao salvar um ponto de venda será validado se para todas as empresas informadas para venda também será necessário informar o fechamento. + * + * @return + */ + VALIDA_CONTA_CORRENTE_EMPESA_PTOVTA("puntoVenta.validaCtaCteEmpresa"), + + IS_DATASOURCE_COMISSAO_BANCO_PRODUCAO("datasource.conferencia.comissao"), + + IS_PERMITE_VARIAS_IMPRESSORAS_MESMA_EMPRESA("permiteVariasImpressorasMesmaEmpresa"), + + IS_FORMAPAGO_PRICING_INATIVO("formaPagoPricingInativo"), + + EXIBIR_PUNTO_VENTA_CADASTRO_AIDF("exibirPuntoVentaCadastroAIDF"), + + IS_PUNTOVENTA_CADASTRO_AIDF_OBRIGATORIO("isPuntoVentaCadastroAIDFObrigatorio"), + + ENDERECO_CLIENTE_OBRIGATORIO("cliente.enderecoObrigatorio"), + + IS_PERMITE_LAYOUT_INTERNACIONAL("permiteLayoutInternacional"), + + RELATORIO_TAXAS_LINHA_TXT_DOWNLOAD_VISIBLE("taxasLinhaTxtDownloadVisible"), + + IS_PERMITE_CALCULO_COMISSAO_PERIODO("permiteCalculoComissaoPeriodo"), + + IS_INCLUI_TIPO_PAGAMENTO_TURISMO_BGM("incluiTipoPagamentoTurismoBGM"), + + IS_GERAR_TRECHO_AUTOMATICO_DEFAULT_NAO("gerarTrechoAutomaticoDefaultNao"), + + ; + + private String descricao; + + private CustomEnum(String descricao) { + this.descricao = descricao; + } + + public String getDescricao() { + return descricao; + } + + @Override + public String toString() { + return this.descricao; + } + +}