Subversion Repositories Integrator Subversion

Rev

Rev 195 | Rev 356 | 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
 
305 espaco 83
        public Boolean temPerfilFinanceiro() {
84
                return perfilService.temPerfilFinanceiro(getUsuario());
106 espaco 85
        }
86
 
305 espaco 87
        public Boolean temPerfilComercial() {
88
                return perfilService.temPerfilComercial(getUsuario());
106 espaco 89
        }
90
 
305 espaco 91
        public Boolean temPerfilLojistica() {
92
                return perfilService.temPerfilLojistica(getUsuario());
106 espaco 93
        }
94
 
95
        public Boolean temPerfilVendedor() {
96
                return perfilService.temPerfilVendedor(getUsuario());
97
        }
98
 
305 espaco 99
        public Boolean temPerfilCompras() {
100
                return perfilService.temPerfilCompras(getUsuario());
106 espaco 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
 
305 espaco 115
        public Boolean temPerfilOperacoes() {
116
                return perfilService.temPerfilOperacoes(getUsuario());
106 espaco 117
        }
118
 
305 espaco 119
        public Boolean temPerfilProducao() {
120
                return perfilService.temPerfilProducao(getUsuario());
121
        }
122
 
106 espaco 123
        public Boolean temPerfilSupervisor() {
124
                return perfilService.temPerfilSupervisor(getUsuario());
125
        }
126
 
127
        public Boolean temPerfilTreinamento() {
128
                return perfilService.temPerfilTreinamento(getUsuario());
129
        }
130
 
131
        public Boolean temPerfilLoja() {
132
                return perfilService.temPerfilLoja(getUsuario());
133
        }
134
 
135
        public Boolean temAcessoLoja(Long sequencialLoja) {
136
                return temPerfilGerenteAdministrativo() || verificarAcessoLoja(getUsuario(), sequencialLoja);
137
        }
138
 
139
        public Boolean temAcessoLojaVivo() {
140
                return temPerfilGerenteAdministrativo() || verificarAcessoLoja(getUsuario(), ConstantesSEC.SEQUENCIAL_LOJA_VIVO_4);
141
        }
142
 
143
        public Boolean temAcessoLojaCasaDasCapas() {
305 espaco 144
                return temPerfilCompras() || temPerfilComercial() || (verificarAcessoLoja(getUsuario(), ConstantesSEC.SEQUENCIAL_CASA_DAS_CAPAS_17) && temPerfilVendedor());
106 espaco 145
        }
146
 
147
        public Boolean naoTemAcessoLojaCasaDasCapas() {
305 espaco 148
                return temPerfilCompras() || temPerfilComercial() || !(verificarAcessoLoja(getUsuario(), ConstantesSEC.SEQUENCIAL_CASA_DAS_CAPAS_17) && temPerfilVendedor());
106 espaco 149
        }
150
 
151
        private Boolean verificarAcessoLoja(Usuario usuario, Long sequencialLoja) {
152
                for (UsuarioLoja usuarioLoja : usuario.getLojas()) {
153
                        if (usuarioLoja.getLoja().getSequencial().equals(sequencialLoja)) {
154
                                return true;
155
                        }
156
                }
157
                return false;
158
        }
159
 
160
        public void restaurarTelaPDV(Loja loja) throws IOException {
161
            FacesContext.getCurrentInstance().getExternalContext().redirect(FacesContext.getCurrentInstance().getExternalContext().getRequestContextPath() + "/sistema/pdv.xhtml?sequencialLoja=" + loja.getSequencial());
162
        }
163
 
164
        public void restaurarTelaPDVVivo(Loja loja) throws IOException {
165
            FacesContext.getCurrentInstance().getExternalContext().redirect(FacesContext.getCurrentInstance().getExternalContext().getRequestContextPath() + "/sistema/pdv_vivo.xhtml?sequencialLoja=" + loja.getSequencial());
166
        }
167
 
168
        public void restaurarTelaPDVFarma(Loja loja) throws IOException {
169
            FacesContext.getCurrentInstance().getExternalContext().redirect(FacesContext.getCurrentInstance().getExternalContext().getRequestContextPath() + "/sistema/pdv.xhtml?sequencialLoja=" + loja.getSequencial());
170
        }
171
 
172
        public void invalidarSessao() {
173
                FacesContext.getCurrentInstance().getExternalContext().invalidateSession();
174
        }
175
 
176
        public void alterarSenhaUsuario() {
177
                new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() {
178
                        public void execute() {
179
                                getUsuario().setSenha(getNovaSenha());
180
                                usuarioService.alterarSenhaUsuario(getUsuario());
181
                                setNovaSenha("");
182
                                LancadorMensagem.lancarSucesso("SENHA ALTERADA COM SUCESSO");
183
                        }
184
                });
185
        }
186
 
187
        public Integer getTempoEstoqueMinimoParaComprasEmDias() {
188
                Parametro parametro = new Parametro();
189
                parametro.setCodigo(ConstantesSEC.Parametro.CODIGO_PARAMETRO_TEMPO_ESTOQUE_MINIMO_PARA_COMPRAS);
190
                parametro = getUsuario().getParametros().get(getUsuario().getParametros().indexOf(parametro));
191
                return VerificadorUtil.naoEstaNulo(parametro)? new Integer(parametro.getValor()) : 15;
192
        }
193
 
194
        public Integer getTempoEstoqueParaReporEmDias() {
195
                Parametro parametro = new Parametro();
196
                parametro.setCodigo(ConstantesSEC.Parametro.CODIGO_PARAMETRO_TEMPO_ESTOQUE_REPOSICAO_PARA_COMPRAS);
197
                parametro = getUsuario().getParametros().get(getUsuario().getParametros().indexOf(parametro));
198
                return VerificadorUtil.naoEstaNulo(parametro)? new Integer(parametro.getValor()) : 60;
199
        }
200
 
201
        public TipoAno[] getTiposAno() {
202
                return TipoAno.values();
203
        }
204
 
205
        public TipoMes[] getTiposMes() {
206
                return TipoMes.values();
207
        }
208
 
152 espaco 209
        public String textoSobreCorMargem() {
210
                return ConstantesSEC.Textos.TEXTO_COR_MARGEM;
211
        }
212
 
106 espaco 213
}