Subversion Repositories Integrator Subversion

Rev

Rev 195 | Rev 572 | 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.managedbean;
2
 
3
import java.io.Serializable;
4
 
5
import javax.inject.Inject;
6
import javax.inject.Named;
571 blopes 7
import javax.servlet.http.HttpServletRequest;
106 espaco 8
 
571 blopes 9
import org.springframework.beans.factory.annotation.Autowired;
106 espaco 10
import org.springframework.context.annotation.Scope;
11
 
571 blopes 12
import br.com.ec.controller.util.IpUtil;
195 espaco 13
import br.com.ec.core.generic.GenericService;
14
import br.com.ec.core.util.DataUtils;
106 espaco 15
import br.com.ec.domain.model.Ponto;
16
import br.com.ec.domain.service.ponto.PontoService;
195 espaco 17
import br.com.ec.web.exception.VerificadorLancamentoException;
18
import br.com.ec.web.exception.VerificadorLancamentoException.CommandBean;
19
import br.com.ec.web.generic.AbstractBean;
20
import br.com.ec.web.message.LancadorMensagem;
106 espaco 21
 
22
@Named
23
@Scope("view")
24
public class PontoBean extends AbstractBean<Ponto> implements Serializable {
25
 
26
        private static final long serialVersionUID = 1L;
27
 
28
        private String senhaUsuario;
29
 
30
        private PontoService pontoService;
31
 
571 blopes 32
//      @Autowired
33
//    private HttpServletRequest request;
34
 
106 espaco 35
        @Inject
36
        public PontoBean(PontoService pontoService) {
37
                this.pontoService = pontoService;
38
        }
39
 
40
        @Override
41
        public void preCarregamento() {
42
                limparEntidade();
43
        }
44
 
45
        @Override
46
        public void limparEntidade() {
47
                entidade = new Ponto();
48
                setSenhaUsuario("");
49
        }
50
 
51
        @Override
52
        public GenericService<Ponto> getService() {
53
                return pontoService;
54
        }
55
 
56
        @Override
57
        public Ponto getEntidade() {
58
                return entidade;
59
        }
60
 
61
        @Override
62
        public Ponto getId() {
63
                return getEntidade();
64
        }
65
 
66
        public String getSenhaUsuario() {
67
                return senhaUsuario;
68
        }
69
        public void setSenhaUsuario(String senhaUsuario) {
70
                this.senhaUsuario = senhaUsuario;
71
        }
72
 
73
        /***************************************************************/
74
 
75
        public void iniciarPonto(final Long lojaSequencial) {
76
                new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() {
77
                        public void execute() {
78
                                setEntidade(pontoService.consultarPonto(DataUtils.getDataAtual(), senhaUsuario, lojaSequencial));
79
                        }
80
                });
81
        }
82
 
83
        public void baterPontoInicio() {
84
                new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() {
85
                        public void execute() {
86
                                getEntidade().setDataHoraPontoInicio(DataUtils.getDataAtual());
571 blopes 87
                                getEntidade().setIpPontoInicio(recuperarIpUsuario());
106 espaco 88
                                baterPonto();
89
                        }
90
                });
91
        }
92
 
93
        public void excluirPontoInicio() {
94
                new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() {
95
                        public void execute() {
96
                                getEntidade().setDataHoraPontoInicio(null);
97
                                baterPonto();
98
                        }
99
                });
100
        }
101
 
102
        public void baterPontoFim() {
103
                new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() {
104
                        public void execute() {
105
                                getEntidade().setDataHoraPontoFim(DataUtils.getDataAtual());
571 blopes 106
                                getEntidade().setIpPontoFim(recuperarIpUsuario());
106 espaco 107
                                baterPonto();
108
                        }
109
                });
110
        }
111
 
112
        public void excluirPontoFim() {
113
                new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() {
114
                        public void execute() {
115
                                getEntidade().setDataHoraPontoFim(null);
116
                                baterPonto();
117
                        }
118
                });
119
        }
120
 
121
        public void baterIntervaloInicio() {
122
                new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() {
123
                        public void execute() {
124
                                getEntidade().setDataHoraIntervaloInicio(DataUtils.getDataAtual());
571 blopes 125
                                getEntidade().setIpPontoIntervaloInicio(recuperarIpUsuario());
106 espaco 126
                                baterPonto();
127
                        }
128
                });
129
        }
130
 
131
        public void excluirIntervaloInicio() {
132
                new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() {
133
                        public void execute() {
134
                                getEntidade().setDataHoraIntervaloInicio(null);
135
                                baterPonto();
136
                        }
137
                });
138
        }
139
 
140
        public void baterIntervaloFim() {
141
                new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() {
142
                        public void execute() {
143
                                getEntidade().setDataHoraIntervaloFim(DataUtils.getDataAtual());
571 blopes 144
                                getEntidade().setIpPontoIntervaloFim(recuperarIpUsuario());
106 espaco 145
                                baterPonto();
146
                        }
147
                });
148
        }
149
 
150
        public void excluirIntervaloFim() {
151
                new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() {
152
                        public void execute() {
153
                                getEntidade().setDataHoraIntervaloFim(null);
154
                                baterPonto();
155
                        }
156
                });
157
        }
158
 
571 blopes 159
        private String recuperarIpUsuario() {
160
                HttpServletRequest request = (HttpServletRequest) getContext().getExternalContext().getRequest();
161
                return IpUtil.getClientIp(request);
162
        }
163
 
106 espaco 164
        private void baterPonto() {
165
                pontoService.alterar(getEntidade());
166
                limparEntidade();
167
                LancadorMensagem.lancarSucesso("PONTO ALTERADO COM SUCESSO!");
168
        }
169
 
170
}