Rev 152 | Rev 305 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 106 | espaco | 1 | package br.com.ec.controller.seguranca; |
| 2 | |||
| 3 | import java.io.IOException; |
||
| 4 | import java.io.Serializable; |
||
| 5 | |||
| 6 | import javax.faces.context.FacesContext; |
||
| 7 | import javax.inject.Inject; |
||
| 8 | import javax.inject.Named; |
||
| 9 | |||
| 10 | import org.springframework.context.annotation.Scope; |
||
| 11 | |||
| 195 | espaco | 12 | import br.com.ec.core.util.VerificadorUtil; |
| 106 | espaco | 13 | import br.com.ec.domain.model.Loja; |
| 14 | import br.com.ec.domain.model.Parametro; |
||
| 15 | import br.com.ec.domain.model.Usuario; |
||
| 16 | import br.com.ec.domain.model.UsuarioLoja; |
||
| 17 | import br.com.ec.domain.model.tipos.TipoAno; |
||
| 18 | import br.com.ec.domain.model.tipos.TipoMes; |
||
| 19 | import br.com.ec.domain.service.perfil.PerfilService; |
||
| 20 | import br.com.ec.domain.service.seguranca.ContextoSeguranca; |
||
| 21 | import br.com.ec.domain.service.usuario.UsuarioService; |
||
| 22 | import br.com.ec.domain.shared.ConstantesSEC; |
||
| 195 | espaco | 23 | import br.com.ec.web.exception.VerificadorLancamentoException; |
| 24 | import br.com.ec.web.exception.VerificadorLancamentoException.CommandBean; |
||
| 25 | import br.com.ec.web.message.LancadorMensagem; |
||
| 106 | espaco | 26 | |
| 27 | @Named |
||
| 28 | @Scope("view") |
||
| 29 | public class SegurancaBean implements Serializable{ |
||
| 30 | |||
| 31 | private static final long serialVersionUID = 1L; |
||
| 32 | |||
| 33 | private ContextoSeguranca contextoSeguranca; |
||
| 34 | private Usuario usuario; |
||
| 35 | private String novaSenha; |
||
| 36 | |||
| 37 | private UsuarioService usuarioService; |
||
| 38 | private PerfilService perfilService; |
||
| 39 | |||
| 40 | @Inject |
||
| 41 | public SegurancaBean(ContextoSeguranca contextoSeguranca, UsuarioService usuarioService, PerfilService perfilService) { |
||
| 42 | this.contextoSeguranca = contextoSeguranca; |
||
| 43 | this.usuarioService = usuarioService; |
||
| 44 | this.perfilService = perfilService; |
||
| 45 | } |
||
| 46 | |||
| 47 | public ContextoSeguranca getContextoSeguranca() { |
||
| 48 | return contextoSeguranca; |
||
| 49 | } |
||
| 50 | public void setContextoSeguranca(ContextoSeguranca contextoSeguranca) { |
||
| 51 | this.contextoSeguranca = contextoSeguranca; |
||
| 52 | } |
||
| 53 | |||
| 54 | public Usuario getUsuario() { |
||
| 55 | if (usuario == null) { |
||
| 56 | setUsuario(contextoSeguranca.obterUsuario()); |
||
| 57 | } |
||
| 58 | return usuario; |
||
| 59 | } |
||
| 60 | public void setUsuario(Usuario usuario) { |
||
| 61 | this.usuario = usuario; |
||
| 62 | } |
||
| 63 | |||
| 64 | public String getNovaSenha() { |
||
| 65 | return novaSenha; |
||
| 66 | } |
||
| 67 | public void setNovaSenha(String novaSenha) { |
||
| 68 | this.novaSenha = novaSenha; |
||
| 69 | } |
||
| 70 | |||
| 71 | /************************************************************************/ |
||
| 72 | |||
| 73 | public Boolean temPerfilAdministrador() { |
||
| 74 | return perfilService.temPerfilAdministrador(getUsuario()); |
||
| 75 | } |
||
| 76 | |||
| 77 | public Boolean temPerfilGerenteAdministrativo() { |
||
| 78 | return perfilService.temPerfilGerenteAdministrativo(getUsuario()); |
||
| 79 | } |
||
| 80 | |||
| 81 | /************************************************************************/ |
||
| 82 | |||
| 83 | public Boolean temPerfilGerenteFinanceiro() { |
||
| 84 | return perfilService.temPerfilGerenteFinanceiro(getUsuario()); |
||
| 85 | } |
||
| 86 | |||
| 87 | public Boolean temPerfilGerenteComercial() { |
||
| 88 | return perfilService.temPerfilGerenteComercial(getUsuario()); |
||
| 89 | } |
||
| 90 | |||
| 91 | public Boolean temPerfilGerenteDeLojistica() { |
||
| 92 | return perfilService.temPerfilGerenteDeLojistica(getUsuario()); |
||
| 93 | } |
||
| 94 | |||
| 95 | public Boolean temPerfilVendedor() { |
||
| 96 | return perfilService.temPerfilVendedor(getUsuario()); |
||
| 97 | } |
||
| 98 | |||
| 99 | public Boolean temPerfilGerenteDeCompras() { |
||
| 100 | return perfilService.temPerfilGerenteDeCompras(getUsuario()); |
||
| 101 | } |
||
| 102 | |||
| 103 | public Boolean temPerfilGerenteVivo() { |
||
| 104 | return perfilService.temPerfilGerenteVivo(getUsuario()); |
||
| 105 | } |
||
| 106 | |||
| 107 | public Boolean temPerfilTecnico() { |
||
| 108 | return perfilService.temPerfilTecnico(getUsuario()); |
||
| 109 | } |
||
| 110 | |||
| 111 | public Boolean temPerfilRecursosHumanos() { |
||
| 112 | return perfilService.temPerfilRecursosHumanos(getUsuario()); |
||
| 113 | } |
||
| 114 | |||
| 115 | public Boolean temPerfilGerenteDeOperacoes() { |
||
| 116 | return perfilService.temPerfilGerenteDeOperacoes(getUsuario()); |
||
| 117 | } |
||
| 118 | |||
| 119 | public Boolean temPerfilSupervisor() { |
||
| 120 | return perfilService.temPerfilSupervisor(getUsuario()); |
||
| 121 | } |
||
| 122 | |||
| 123 | public Boolean temPerfilTreinamento() { |
||
| 124 | return perfilService.temPerfilTreinamento(getUsuario()); |
||
| 125 | } |
||
| 126 | |||
| 127 | public Boolean temPerfilLoja() { |
||
| 128 | return perfilService.temPerfilLoja(getUsuario()); |
||
| 129 | } |
||
| 130 | |||
| 131 | public Boolean temAcessoLoja(Long sequencialLoja) { |
||
| 132 | return temPerfilGerenteAdministrativo() || verificarAcessoLoja(getUsuario(), sequencialLoja); |
||
| 133 | } |
||
| 134 | |||
| 135 | public Boolean temAcessoLojaVivo() { |
||
| 136 | return temPerfilGerenteAdministrativo() || verificarAcessoLoja(getUsuario(), ConstantesSEC.SEQUENCIAL_LOJA_VIVO_4); |
||
| 137 | } |
||
| 138 | |||
| 139 | public Boolean temAcessoLojaCasaDasCapas() { |
||
| 152 | espaco | 140 | return temPerfilGerenteDeCompras() || temPerfilGerenteComercial() || (verificarAcessoLoja(getUsuario(), ConstantesSEC.SEQUENCIAL_CASA_DAS_CAPAS_17) && temPerfilVendedor()); |
| 106 | espaco | 141 | } |
| 142 | |||
| 143 | public Boolean naoTemAcessoLojaCasaDasCapas() { |
||
| 152 | espaco | 144 | return temPerfilGerenteDeCompras() || temPerfilGerenteComercial() || !(verificarAcessoLoja(getUsuario(), ConstantesSEC.SEQUENCIAL_CASA_DAS_CAPAS_17) && temPerfilVendedor()); |
| 106 | espaco | 145 | } |
| 146 | |||
| 147 | private Boolean verificarAcessoLoja(Usuario usuario, Long sequencialLoja) { |
||
| 148 | for (UsuarioLoja usuarioLoja : usuario.getLojas()) { |
||
| 149 | if (usuarioLoja.getLoja().getSequencial().equals(sequencialLoja)) { |
||
| 150 | return true; |
||
| 151 | } |
||
| 152 | } |
||
| 153 | return false; |
||
| 154 | } |
||
| 155 | |||
| 156 | public void restaurarTelaPDV(Loja loja) throws IOException { |
||
| 157 | FacesContext.getCurrentInstance().getExternalContext().redirect(FacesContext.getCurrentInstance().getExternalContext().getRequestContextPath() + "/sistema/pdv.xhtml?sequencialLoja=" + loja.getSequencial()); |
||
| 158 | } |
||
| 159 | |||
| 160 | public void restaurarTelaPDVVivo(Loja loja) throws IOException { |
||
| 161 | FacesContext.getCurrentInstance().getExternalContext().redirect(FacesContext.getCurrentInstance().getExternalContext().getRequestContextPath() + "/sistema/pdv_vivo.xhtml?sequencialLoja=" + loja.getSequencial()); |
||
| 162 | } |
||
| 163 | |||
| 164 | public void restaurarTelaPDVFarma(Loja loja) throws IOException { |
||
| 165 | FacesContext.getCurrentInstance().getExternalContext().redirect(FacesContext.getCurrentInstance().getExternalContext().getRequestContextPath() + "/sistema/pdv.xhtml?sequencialLoja=" + loja.getSequencial()); |
||
| 166 | } |
||
| 167 | |||
| 168 | public void invalidarSessao() { |
||
| 169 | FacesContext.getCurrentInstance().getExternalContext().invalidateSession(); |
||
| 170 | } |
||
| 171 | |||
| 172 | public void alterarSenhaUsuario() { |
||
| 173 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 174 | public void execute() { |
||
| 175 | getUsuario().setSenha(getNovaSenha()); |
||
| 176 | usuarioService.alterarSenhaUsuario(getUsuario()); |
||
| 177 | setNovaSenha(""); |
||
| 178 | LancadorMensagem.lancarSucesso("SENHA ALTERADA COM SUCESSO"); |
||
| 179 | } |
||
| 180 | }); |
||
| 181 | } |
||
| 182 | |||
| 183 | public Integer getTempoEstoqueMinimoParaComprasEmDias() { |
||
| 184 | Parametro parametro = new Parametro(); |
||
| 185 | parametro.setCodigo(ConstantesSEC.Parametro.CODIGO_PARAMETRO_TEMPO_ESTOQUE_MINIMO_PARA_COMPRAS); |
||
| 186 | parametro = getUsuario().getParametros().get(getUsuario().getParametros().indexOf(parametro)); |
||
| 187 | return VerificadorUtil.naoEstaNulo(parametro)? new Integer(parametro.getValor()) : 15; |
||
| 188 | } |
||
| 189 | |||
| 190 | public Integer getTempoEstoqueParaReporEmDias() { |
||
| 191 | Parametro parametro = new Parametro(); |
||
| 192 | parametro.setCodigo(ConstantesSEC.Parametro.CODIGO_PARAMETRO_TEMPO_ESTOQUE_REPOSICAO_PARA_COMPRAS); |
||
| 193 | parametro = getUsuario().getParametros().get(getUsuario().getParametros().indexOf(parametro)); |
||
| 194 | return VerificadorUtil.naoEstaNulo(parametro)? new Integer(parametro.getValor()) : 60; |
||
| 195 | } |
||
| 196 | |||
| 197 | public TipoAno[] getTiposAno() { |
||
| 198 | return TipoAno.values(); |
||
| 199 | } |
||
| 200 | |||
| 201 | public TipoMes[] getTiposMes() { |
||
| 202 | return TipoMes.values(); |
||
| 203 | } |
||
| 204 | |||
| 152 | espaco | 205 | public String textoSobreCorMargem() { |
| 206 | return ConstantesSEC.Textos.TEXTO_COR_MARGEM; |
||
| 207 | } |
||
| 208 | |||
| 106 | espaco | 209 | } |