Subversion Repositories Integrator Subversion

Rev

Rev 182 | Details | Compare with Previous | Last modification | View Log | RSS feed

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