Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1 | espaco | 1 | package br.gov.al.saude.scs.web.managebean.turma; |
| 2 | |||
| 3 | import java.io.Serializable; |
||
| 4 | import java.util.ArrayList; |
||
| 5 | import java.util.List; |
||
| 6 | |||
| 7 | import javax.faces.bean.ManagedBean; |
||
| 8 | |||
| 9 | import org.primefaces.event.RowEditEvent; |
||
| 10 | import org.primefaces.event.TabChangeEvent; |
||
| 11 | import org.springframework.beans.factory.annotation.Autowired; |
||
| 12 | import org.springframework.context.annotation.Scope; |
||
| 13 | import org.springframework.stereotype.Component; |
||
| 14 | |||
| 15 | import br.gov.al.saude.framework.core.exception.NegocioException; |
||
| 16 | import br.gov.al.saude.framework.core.generic.GenericFacade; |
||
| 17 | import br.gov.al.saude.framework.core.model.pessoa.PessoaDTO; |
||
| 18 | import br.gov.al.saude.framework.core.util.VerificadorUtil; |
||
| 19 | import br.gov.al.saude.framework.web.exception.VerificadorLancamentoException; |
||
| 20 | import br.gov.al.saude.framework.web.exception.VerificadorLancamentoException.CommandBean; |
||
| 21 | import br.gov.al.saude.framework.web.generic.AbstractBeanComModalScg; |
||
| 22 | import br.gov.al.saude.framework.web.generic.GenericConsultaDemanda; |
||
| 23 | import br.gov.al.saude.framework.web.message.LancadorMensagem; |
||
| 24 | import br.gov.al.saude.framework.web.util.URLUtils; |
||
| 25 | import br.gov.al.saude.sca.model.usuario.view.UsuarioView; |
||
| 26 | import br.gov.al.saude.scg.model.view.MunicipioView; |
||
| 27 | import br.gov.al.saude.scg.model.view.OrgaoView; |
||
| 28 | import br.gov.al.saude.scg.model.view.PessoaFisicaView; |
||
| 29 | import br.gov.al.saude.scs.core.application.municipio.MunicipioFacade; |
||
| 30 | import br.gov.al.saude.scs.core.application.perfil.PerfilFacade; |
||
| 31 | import br.gov.al.saude.scs.core.application.turma.TurmaFacade; |
||
| 32 | import br.gov.al.saude.scs.model.Capacitacao; |
||
| 33 | import br.gov.al.saude.scs.model.Perfil; |
||
| 34 | import br.gov.al.saude.scs.model.Turma; |
||
| 35 | import br.gov.al.saude.scs.model.TurmaParticipante; |
||
| 36 | import br.gov.al.saude.scs.model.TurmaPeriodo; |
||
| 37 | import br.gov.al.saude.scs.model.TurmaProcesso; |
||
| 38 | import br.gov.al.saude.scs.model.dto.ConsultaTurmaDTO; |
||
| 39 | import br.gov.al.saude.scs.model.dto.DespesasTurmaDTO; |
||
| 40 | import br.gov.al.saude.scs.model.dto.TurmaDTO; |
||
| 41 | import br.gov.al.saude.scs.parametros.ParametrosConsultarDespesasTurma; |
||
| 42 | import br.gov.al.saude.scs.parametros.ParametrosConsultarTurma; |
||
| 43 | |||
| 44 | @Component |
||
| 45 | @ManagedBean |
||
| 46 | @Scope("view") |
||
| 47 | public class TurmaBean extends AbstractBeanComModalScg<Turma> implements Serializable { |
||
| 48 | |||
| 49 | private static final long serialVersionUID = 1L; |
||
| 50 | |||
| 51 | private PerfilFacade perfilFacade; |
||
| 52 | private TurmaFacade turmaFacade; |
||
| 53 | private MunicipioFacade municipioFacade; |
||
| 54 | |||
| 55 | private TurmaConsultaDemanda consultaLazy; |
||
| 56 | private ConsultaTurmaDTO consultaTurmaDTO = new ConsultaTurmaDTO(); |
||
| 57 | private Capacitacao capacitacaoSelecionada; |
||
| 58 | private TurmaDtoConsultaDemanda consultaDtoLazy; |
||
| 59 | private TurmaDTO entidadeDto; |
||
| 60 | private ParametrosConsultarTurma parametros; |
||
| 61 | |||
| 62 | private List<TurmaProcesso> processos; |
||
| 63 | private Boolean acaoConfirmarAdicaoPecessoProcesso = false; |
||
| 64 | private Boolean acaoCadastrar = false; |
||
| 65 | private Integer activeIndex = 0; |
||
| 66 | |||
| 67 | private OrgaoView orgao; |
||
| 68 | private String numeroDoProcesso; |
||
| 69 | private Integer anoDoProcesso; |
||
| 70 | private ParametrosConsultarDespesasTurma parametrosConsultarDespesasTurma; |
||
| 71 | |||
| 72 | private List<OrgaoView> orgaos; |
||
| 73 | private List<Perfil> perfis; |
||
| 74 | private List<MunicipioView> municipios; |
||
| 75 | |||
| 76 | private DespesasTurmaDTO despesasTurma; |
||
| 77 | private TurmaParticipante turmaParticipante = new TurmaParticipante(); |
||
| 78 | private TurmaPeriodo turmaPeriodo = new TurmaPeriodo(); |
||
| 79 | |||
| 80 | @Autowired |
||
| 81 | public TurmaBean(TurmaFacade turmaFacade, PerfilFacade perfilFacade, MunicipioFacade municipioFacade, TurmaConsultaDemanda consultaLazy, TurmaDtoConsultaDemanda consultaDtoLazy) { |
||
| 82 | this.turmaFacade = turmaFacade; |
||
| 83 | this.perfilFacade = perfilFacade; |
||
| 84 | this.municipioFacade = municipioFacade; |
||
| 85 | this.consultaLazy = consultaLazy; |
||
| 86 | this.consultaDtoLazy = consultaDtoLazy; |
||
| 87 | } |
||
| 88 | |||
| 89 | @Override |
||
| 90 | public Turma getEntidade() { |
||
| 91 | if (VerificadorUtil.estaNulo(entidade)) { |
||
| 92 | entidade = new Turma(); |
||
| 93 | } |
||
| 94 | return entidade; |
||
| 95 | } |
||
| 96 | |||
| 97 | public TurmaDTO getEntidadeDto() { |
||
| 98 | return entidadeDto; |
||
| 99 | } |
||
| 100 | |||
| 101 | public void setEntidadeDto(TurmaDTO entidadeDto) { |
||
| 102 | this.entidadeDto = entidadeDto; |
||
| 103 | } |
||
| 104 | |||
| 105 | @Override |
||
| 106 | public GenericFacade<Turma> getFacade() { |
||
| 107 | return turmaFacade; |
||
| 108 | } |
||
| 109 | |||
| 110 | @Override |
||
| 111 | public Object getId() { |
||
| 112 | return getEntidade().getId(); |
||
| 113 | } |
||
| 114 | |||
| 115 | @Override |
||
| 116 | public String getTelaCrud() { |
||
| 117 | return "/paginas/turma.xhtml"; |
||
| 118 | } |
||
| 119 | |||
| 120 | @Override |
||
| 121 | public void limparEntidade() { |
||
| 122 | entidade = new Turma(); |
||
| 123 | consultaTurmaDTO = new ConsultaTurmaDTO(); |
||
| 124 | capacitacaoSelecionada = new Capacitacao(); |
||
| 125 | } |
||
| 126 | |||
| 127 | @Override |
||
| 128 | public GenericConsultaDemanda<Turma> getLazy() { |
||
| 129 | return null; |
||
| 130 | } |
||
| 131 | |||
| 132 | public TurmaConsultaDemanda getConsultaLazy() { |
||
| 133 | return consultaLazy; |
||
| 134 | } |
||
| 135 | |||
| 136 | public void setConsultaLazy(TurmaConsultaDemanda consultaLazy) { |
||
| 137 | this.consultaLazy = consultaLazy; |
||
| 138 | } |
||
| 139 | |||
| 140 | public TurmaDtoConsultaDemanda getConsultaDtoLazy() { |
||
| 141 | return consultaDtoLazy; |
||
| 142 | } |
||
| 143 | |||
| 144 | public void setConsultaDtoLazy(TurmaDtoConsultaDemanda consultaDtoLazy) { |
||
| 145 | this.consultaDtoLazy = consultaDtoLazy; |
||
| 146 | } |
||
| 147 | |||
| 148 | public ParametrosConsultarTurma getParametros() { |
||
| 149 | if(VerificadorUtil.estaNulo(parametros)){ |
||
| 150 | parametros = new ParametrosConsultarTurma(); |
||
| 151 | } |
||
| 152 | return parametros; |
||
| 153 | } |
||
| 154 | |||
| 155 | public void setParametros(ParametrosConsultarTurma parametros) { |
||
| 156 | this.parametros = parametros; |
||
| 157 | } |
||
| 158 | |||
| 159 | public void prepararConsultaDemanda() { |
||
| 160 | consultaLazy.setarParametrosConsulta(consultaTurmaDTO); |
||
| 161 | } |
||
| 162 | |||
| 163 | public void prepararConsultaDtoDemanda() { |
||
| 164 | getParametros().setSequencialCapacitacao(getSequencialCapacitacaoSelecionada()); |
||
| 165 | getParametros().setUsuarioLogado((UsuarioView) getUsuario().getPrincipal()); |
||
| 166 | consultaDtoLazy.setParametros(getParametros()); |
||
| 167 | consultaDtoLazy.setConsultaInicial(true); |
||
| 168 | } |
||
| 169 | |||
| 170 | public List<OrgaoView> getListaOrgaos() { |
||
| 171 | return orgaos; |
||
| 172 | } |
||
| 173 | |||
| 174 | public ParametrosConsultarDespesasTurma getParametrosConsultarDespesasTurma() { |
||
| 175 | return parametrosConsultarDespesasTurma; |
||
| 176 | } |
||
| 177 | |||
| 178 | public void setParametrosConsultarDespesasTurma(ParametrosConsultarDespesasTurma parametrosConsultarDespesasTurma) { |
||
| 179 | this.parametrosConsultarDespesasTurma = parametrosConsultarDespesasTurma; |
||
| 180 | } |
||
| 181 | |||
| 182 | public OrgaoView getOrgao() { |
||
| 183 | return orgao; |
||
| 184 | } |
||
| 185 | |||
| 186 | public void setOrgao(OrgaoView orgao) { |
||
| 187 | this.orgao = orgao; |
||
| 188 | } |
||
| 189 | |||
| 190 | public String getNumeroDoProcesso() { |
||
| 191 | return numeroDoProcesso; |
||
| 192 | } |
||
| 193 | |||
| 194 | public void setNumeroDoProcesso(String numeroDoProcesso) { |
||
| 195 | this.numeroDoProcesso = numeroDoProcesso; |
||
| 196 | } |
||
| 197 | |||
| 198 | public Integer getAnoDoProcesso() { |
||
| 199 | return anoDoProcesso; |
||
| 200 | } |
||
| 201 | |||
| 202 | public void setAnoDoProcesso(Integer anoDoProcesso) { |
||
| 203 | this.anoDoProcesso = anoDoProcesso; |
||
| 204 | } |
||
| 205 | |||
| 206 | public DespesasTurmaDTO getDespesasTurma() { |
||
| 207 | return despesasTurma; |
||
| 208 | } |
||
| 209 | |||
| 210 | public void setDespesasTurma(DespesasTurmaDTO despesasTurma) { |
||
| 211 | this.despesasTurma = despesasTurma; |
||
| 212 | } |
||
| 213 | |||
| 214 | public Boolean getAcaoConfirmarAdicaoPecessoProcesso() { |
||
| 215 | return acaoConfirmarAdicaoPecessoProcesso; |
||
| 216 | } |
||
| 217 | |||
| 218 | public void setAcaoConfirmarAdicaoPecessoProcesso( |
||
| 219 | Boolean acaoConfirmarAdicaoPecessoProcesso) { |
||
| 220 | this.acaoConfirmarAdicaoPecessoProcesso = acaoConfirmarAdicaoPecessoProcesso; |
||
| 221 | } |
||
| 222 | |||
| 223 | public void removerRepresentante(PessoaFisicaView representante) { |
||
| 224 | entidade.removerRepresentante(representante); |
||
| 225 | } |
||
| 226 | |||
| 227 | public List<TurmaProcesso> getProcessos() { |
||
| 228 | return processos; |
||
| 229 | } |
||
| 230 | |||
| 231 | public Boolean getAcaoCadastrar() { |
||
| 232 | return acaoCadastrar; |
||
| 233 | } |
||
| 234 | |||
| 235 | public void setAcaoCadastrar(Boolean acaoCadastrar) { |
||
| 236 | this.acaoCadastrar = acaoCadastrar; |
||
| 237 | } |
||
| 238 | |||
| 239 | public TurmaParticipante getTurmaParticipante() { |
||
| 240 | return turmaParticipante; |
||
| 241 | } |
||
| 242 | |||
| 243 | public void setTurmaParticipante(TurmaParticipante turmaParticipante) { |
||
| 244 | this.turmaParticipante = turmaParticipante; |
||
| 245 | } |
||
| 246 | |||
| 247 | public List<Perfil> getPerfis() { |
||
| 248 | if(VerificadorUtil.isListaNulaOuVazia(perfis)) { |
||
| 249 | perfis = perfilFacade.listar(); |
||
| 250 | } |
||
| 251 | return perfis; |
||
| 252 | } |
||
| 253 | |||
| 254 | public Integer getActiveIndex() { |
||
| 255 | return activeIndex; |
||
| 256 | } |
||
| 257 | |||
| 258 | public void setActiveIndex(Integer activeIndex) { |
||
| 259 | this.activeIndex = activeIndex; |
||
| 260 | } |
||
| 261 | |||
| 262 | public TurmaPeriodo getTurmaPeriodo() { |
||
| 263 | return turmaPeriodo; |
||
| 264 | } |
||
| 265 | |||
| 266 | public void setTurmaPeriodo(TurmaPeriodo turmaPeriodo) { |
||
| 267 | this.turmaPeriodo = turmaPeriodo; |
||
| 268 | } |
||
| 269 | |||
| 270 | public ConsultaTurmaDTO getConsultaTurmaDTO() { |
||
| 271 | return consultaTurmaDTO; |
||
| 272 | } |
||
| 273 | |||
| 274 | public void setConsultaTurmaDTO(ConsultaTurmaDTO consultaTurmaDTO) { |
||
| 275 | this.consultaTurmaDTO = consultaTurmaDTO; |
||
| 276 | } |
||
| 277 | |||
| 278 | public Capacitacao getCapacitacaoSelecionada() { |
||
| 279 | return capacitacaoSelecionada; |
||
| 280 | } |
||
| 281 | |||
| 282 | private Long getSequencialCapacitacaoSelecionada(){ |
||
| 283 | return VerificadorUtil.naoEstaNulo(getCapacitacaoSelecionada()) ? getCapacitacaoSelecionada().getSequencial() : null; |
||
| 284 | } |
||
| 285 | |||
| 286 | public void setCapacitacaoSelecionada(Capacitacao capacitacaoSelecionada) { |
||
| 287 | this.capacitacaoSelecionada = capacitacaoSelecionada; |
||
| 288 | this.entidade.setCapacitacao(capacitacaoSelecionada); |
||
| 289 | this.consultaTurmaDTO.setCapacitacao(capacitacaoSelecionada); |
||
| 290 | } |
||
| 291 | |||
| 292 | public void prepararParaAdicionarDespesas() { |
||
| 293 | orgao = new OrgaoView(); |
||
| 294 | numeroDoProcesso = null; |
||
| 295 | anoDoProcesso = null; |
||
| 296 | parametrosConsultarDespesasTurma = new ParametrosConsultarDespesasTurma(); |
||
| 297 | despesasTurma = new DespesasTurmaDTO(); |
||
| 298 | acaoConfirmarAdicaoPecessoProcesso = true; |
||
| 299 | if(VerificadorUtil.isListaNulaOuVazia(orgaos)) { |
||
| 300 | orgaos = turmaFacade.listarOrgaos(); |
||
| 301 | } |
||
| 302 | } |
||
| 303 | |||
| 304 | public void retirarSelecaoDaCapacitacao() { |
||
| 305 | setCapacitacaoSelecionada(null); |
||
| 306 | consultaTurmaDTO.setCapacitacao(null); |
||
| 307 | } |
||
| 308 | |||
| 309 | public void consultarDespesasTurma() { |
||
| 310 | try { |
||
| 311 | despesasTurma = turmaFacade.consultarDespesasTurma(parametrosConsultarDespesasTurma); |
||
| 312 | orgao = parametrosConsultarDespesasTurma.getOrgao(); |
||
| 313 | numeroDoProcesso = parametrosConsultarDespesasTurma.getNumeroProcesso(); |
||
| 314 | anoDoProcesso = parametrosConsultarDespesasTurma.getAnoProcesso(); |
||
| 315 | } catch (NegocioException e) { |
||
| 316 | despesasTurma = null; |
||
| 317 | orgao = null; |
||
| 318 | numeroDoProcesso = null; |
||
| 319 | anoDoProcesso = null; |
||
| 320 | LancadorMensagem.lancarAlerta(e.getMessage()); |
||
| 321 | }catch (Exception e) { |
||
| 322 | LancadorMensagem.lancarErro(e.getMessage()); |
||
| 323 | } |
||
| 324 | } |
||
| 325 | |||
| 326 | public void adicionarTurmaProcesso(DespesasTurmaDTO despesasTurma) { |
||
| 327 | TurmaProcesso turmaProcesso = new TurmaProcesso(); |
||
| 328 | turmaProcesso.setOrgao(orgao); |
||
| 329 | turmaProcesso.setNumeroProcesso(Long.parseLong(numeroDoProcesso)); |
||
| 330 | turmaProcesso.setAno(anoDoProcesso); |
||
| 331 | turmaProcesso.setTurma(entidade); |
||
| 332 | turmaProcesso.setDespesasTurma(despesasTurma); |
||
| 333 | entidade.adicionarProcesso(turmaProcesso); |
||
| 334 | } |
||
| 335 | |||
| 336 | public void removerTurmaProcesso(TurmaProcesso turmaProcesso) { |
||
| 337 | entidade.removerProcesso(turmaProcesso); |
||
| 338 | } |
||
| 339 | |||
| 340 | public void detalharProcesso(TurmaProcesso turmaProcesso) { |
||
| 341 | acaoConfirmarAdicaoPecessoProcesso = false; |
||
| 342 | despesasTurma = turmaFacade.consultarDespesasTurma(new ParametrosConsultarDespesasTurma(turmaProcesso.getOrgao(), turmaProcesso.getNumeroProcesso(), turmaProcesso.getAno())); |
||
| 343 | } |
||
| 344 | |||
| 345 | @Override |
||
| 346 | public void setarPessoa(final PessoaDTO pessoaDTO) { |
||
| 347 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 348 | @Override |
||
| 349 | public void execute() { |
||
| 350 | PessoaFisicaView pessoaFisica = turmaFacade.consultarPessoa(pessoaDTO.getId()); |
||
| 351 | if(activeIndex == 3) { |
||
| 352 | turmaParticipante.setPessoa(pessoaFisica); |
||
| 353 | } else { |
||
| 354 | entidade.adicionarRepresentante(pessoaFisica); |
||
| 355 | } |
||
| 356 | } |
||
| 357 | }); |
||
| 358 | |||
| 359 | } |
||
| 360 | |||
| 361 | @Override |
||
| 362 | protected void popularObjetoSeIdPessoaDiferenteDeNulo(final String idPessoaCadastrada) { |
||
| 363 | if(VerificadorUtil.naoEstaNuloOuVazio(idPessoaCadastrada)) { |
||
| 364 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 365 | @Override |
||
| 366 | public void execute() { |
||
| 367 | if (VerificadorUtil.naoEstaNuloOuVazio(idPessoaCadastrada)) { |
||
| 368 | if(!idPessoaCadastrada.equals("0")) { |
||
| 369 | PessoaFisicaView pessoaFisica = turmaFacade.consultarPessoa(Long.valueOf(idPessoaCadastrada)); |
||
| 370 | if(activeIndex == 3) { |
||
| 371 | turmaParticipante.setPessoa(pessoaFisica); |
||
| 372 | } else { |
||
| 373 | entidade.adicionarRepresentante(pessoaFisica); |
||
| 374 | } |
||
| 375 | } |
||
| 376 | } |
||
| 377 | } |
||
| 378 | }); |
||
| 379 | } |
||
| 380 | } |
||
| 381 | |||
| 382 | @Override |
||
| 383 | public void armazenarObjetoNaSessao() { |
||
| 384 | URLUtils.armazenarObjetoComNomeNaSessao("entidade", getEntidade()); |
||
| 385 | URLUtils.armazenarObjetoComNomeNaSessao("acaoCadastrar", acaoCadastrar); |
||
| 386 | URLUtils.armazenarObjetoComNomeNaSessao("activeIndex", activeIndex); |
||
| 387 | } |
||
| 388 | |||
| 389 | @Override |
||
| 390 | public void recuperarObjetoNaSessao(Boolean collapsed) { |
||
| 391 | if(VerificadorUtil.naoEstaNuloOuVazio(collapsed)) { |
||
| 392 | new VerificadorLancamentoException().tratarExcecaoLimpandoObjetoDaSessao(new CommandBean() { |
||
| 393 | |||
| 394 | @Override |
||
| 395 | public void execute() { |
||
| 396 | setEntidade((Turma) URLUtils.recuperarObjetoComNomeNaSessao("entidade")); |
||
| 397 | URLUtils.limparObjetoDaSessaoPeloNome("entidade"); |
||
| 398 | |||
| 399 | acaoCadastrar = (Boolean) URLUtils.recuperarObjetoComNomeNaSessao("acaoCadastrar"); |
||
| 400 | URLUtils.limparObjetoDaSessaoPeloNome("acaoCadastrar"); |
||
| 401 | |||
| 402 | activeIndex = (Integer) URLUtils.recuperarObjetoComNomeNaSessao("activeIndex"); |
||
| 403 | URLUtils.limparObjetoDaSessaoPeloNome("activeIndex"); |
||
| 404 | } |
||
| 405 | }); |
||
| 406 | } |
||
| 407 | } |
||
| 408 | |||
| 409 | public void prepararParaAlterar(Turma turma){ |
||
| 410 | selecionarTurma(turma); |
||
| 411 | prepararParaAdicionarParticipantes(); |
||
| 412 | } |
||
| 413 | |||
| 414 | public void prepararParaAdicionarParticipantes() { |
||
| 415 | turmaParticipante = new TurmaParticipante(); |
||
| 416 | } |
||
| 417 | |||
| 418 | public void adicionarTurmaParticipante() { |
||
| 419 | try { |
||
| 420 | validarCamposTurmaParticipante(turmaParticipante); |
||
| 421 | verificarSeParticipanteJaFoiAdicionado(turmaParticipante); |
||
| 422 | turmaParticipante.setTurma(entidade); |
||
| 423 | turmaParticipante.setIndicadorServidor(turmaFacade.consultarIndicadorDeServidor(turmaParticipante.getPessoa())); |
||
| 424 | turmaFacade.verificarFaltasDoParticipante((UsuarioView) getUsuario().getPrincipal(), turmaParticipante); |
||
| 425 | entidade.adicionarParticipante(turmaParticipante); |
||
| 426 | atualizarAlertaDeRestricoesDoParticipante(); |
||
| 427 | turmaParticipante = new TurmaParticipante(); |
||
| 428 | } catch (NegocioException ne) { |
||
| 429 | LancadorMensagem.lancarAlerta(ne.getMessage()); |
||
| 430 | } |
||
| 431 | } |
||
| 432 | |||
| 433 | public void removerTurmaParticipante(TurmaParticipante turmaParticipante) { |
||
| 434 | entidade.removerParticipante(turmaParticipante); |
||
| 435 | atualizarAlertaDeRestricoesDoParticipante(); |
||
| 436 | } |
||
| 437 | |||
| 438 | public void adicionarTurmaPeriodo() { |
||
| 439 | try { |
||
| 440 | validarPeriodo(turmaPeriodo); |
||
| 441 | turmaPeriodo.setTurma(entidade); |
||
| 442 | entidade.adicionarTurmaPeriodo(turmaPeriodo); |
||
| 443 | turmaPeriodo = new TurmaPeriodo(); |
||
| 444 | } catch (NegocioException ne) { |
||
| 445 | LancadorMensagem.lancarAlerta(ne.getMessage()); |
||
| 446 | } |
||
| 447 | } |
||
| 448 | |||
| 449 | private void validarPeriodo(TurmaPeriodo turmaPeriodo) { |
||
| 450 | StringBuilder mensagem = new StringBuilder(); |
||
| 451 | String separador = ""; |
||
| 452 | |||
| 453 | if(VerificadorUtil.estaNulo(turmaPeriodo.getDataInicial())) { |
||
| 454 | mensagem.append(separador); |
||
| 455 | mensagem.append("Obrigatório informar a data inicial."); |
||
| 456 | separador = "; "; |
||
| 457 | } |
||
| 458 | |||
| 459 | if(VerificadorUtil.estaNulo(turmaPeriodo.getDataFinal())) { |
||
| 460 | mensagem.append(separador); |
||
| 461 | mensagem.append("Obrigatório informar a data final."); |
||
| 462 | } |
||
| 463 | |||
| 464 | if(VerificadorUtil.naoEstaNulo(turmaPeriodo.getDataInicial()) && VerificadorUtil.naoEstaNulo(turmaPeriodo.getDataFinal())) { |
||
| 465 | if(turmaPeriodo.getDataInicial().after(turmaPeriodo.getDataFinal())) { |
||
| 466 | mensagem.append("Data inicial não pode ser maior que a final."); |
||
| 467 | } |
||
| 468 | } |
||
| 469 | |||
| 470 | if(VerificadorUtil.naoEstaNuloOuVazio(mensagem.toString())) { |
||
| 471 | throw new NegocioException(mensagem.toString()); |
||
| 472 | } |
||
| 473 | } |
||
| 474 | |||
| 475 | public void removerPeriodo(TurmaPeriodo turmaPeriodo) { |
||
| 476 | entidade.removerTurmaPeriodo(turmaPeriodo); |
||
| 477 | } |
||
| 478 | |||
| 479 | public void selecionarTurma(Turma turma) { |
||
| 480 | entidade = turmaFacade.detalharTurma(turma.getSequencial()); |
||
| 481 | atualizarIndicadorServidor(); |
||
| 482 | atualizarAlertaDeRestricoesDoParticipante(); |
||
| 483 | listarMunicipios(); |
||
| 484 | } |
||
| 485 | |||
| 486 | public void detalharTurma(Turma turma) { |
||
| 487 | entidade = turmaFacade.detalharTurma(turma.getSequencial()); |
||
| 488 | atualizarIndicadorServidor(); |
||
| 489 | atualizarAlertaDeRestricoesDoParticipante(); |
||
| 490 | } |
||
| 491 | |||
| 492 | private void verificarSeParticipanteJaFoiAdicionado(TurmaParticipante turmaParticipante) { |
||
| 493 | if(entidade.getParticipantes().contains(turmaParticipante)) { |
||
| 494 | throw new NegocioException("Este participante já foi adicionado."); |
||
| 495 | } |
||
| 496 | } |
||
| 497 | |||
| 498 | private void validarCamposTurmaParticipante(TurmaParticipante turmaParticipante) { |
||
| 499 | StringBuilder mensagem = new StringBuilder(); |
||
| 500 | String separador = ""; |
||
| 501 | |||
| 502 | if(VerificadorUtil.estaNulo(turmaParticipante.getPessoa())) { |
||
| 503 | mensagem.append(separador); |
||
| 504 | mensagem.append("Obrigatório informar o Representante."); |
||
| 505 | separador = "; "; |
||
| 506 | } |
||
| 507 | |||
| 508 | if(VerificadorUtil.estaNulo(turmaParticipante.getPerfil())) { |
||
| 509 | mensagem.append(separador); |
||
| 510 | mensagem.append("Obrigatório informar o Perfil."); |
||
| 511 | separador = "; "; |
||
| 512 | } |
||
| 513 | |||
| 514 | if(VerificadorUtil.estaNulo(turmaParticipante.getIndicadorRemunerado())) { |
||
| 515 | mensagem.append(separador); |
||
| 516 | mensagem.append("Obrigatório informar Indicador Remunerado."); |
||
| 517 | separador = "; "; |
||
| 518 | } |
||
| 519 | |||
| 520 | if(VerificadorUtil.naoEstaNuloOuVazio(mensagem.toString())) { |
||
| 521 | throw new NegocioException(mensagem.toString()); |
||
| 522 | } |
||
| 523 | } |
||
| 524 | |||
| 525 | public void onEditRow(RowEditEvent event) { |
||
| 526 | atualizarAlertaDeRestricoesDoParticipante(); |
||
| 527 | } |
||
| 528 | |||
| 529 | public void listarMunicipios(){ |
||
| 530 | if(VerificadorUtil.naoEstaNulo(entidade.getUf())) { |
||
| 531 | municipios = municipioFacade.listar(entidade.getUf().getCodigo()); |
||
| 532 | } else { |
||
| 533 | municipios = new ArrayList<MunicipioView>(); |
||
| 534 | } |
||
| 535 | } |
||
| 536 | |||
| 537 | public List<MunicipioView> getMunicipios() { |
||
| 538 | return municipios; |
||
| 539 | } |
||
| 540 | |||
| 541 | public void onChange(TabChangeEvent event) { |
||
| 542 | if(VerificadorUtil.estaNulo(entidade.getAnoExercicio())) { |
||
| 543 | LancadorMensagem.lancarAlerta("Informe o ano de exercício na aba Turma para ter uma informação real do indicador de restrição do participante."); |
||
| 544 | } |
||
| 545 | } |
||
| 546 | |||
| 547 | private void atualizarAlertaDeRestricoesDoParticipante() { |
||
| 548 | for (TurmaParticipante turmaParticipante : entidade.getParticipantes()) { |
||
| 549 | try { |
||
| 550 | turmaFacade.verificarAlertaDeRestricaoDoParticipante(turmaParticipante, new ArrayList<TurmaParticipante>(entidade.getParticipantes())); |
||
| 551 | turmaParticipante.setIndicadorRestricao(false); |
||
| 552 | } catch (NegocioException e) { |
||
| 553 | turmaParticipante.setIndicadorRestricao(true); |
||
| 554 | } |
||
| 555 | } |
||
| 556 | } |
||
| 557 | |||
| 558 | private void atualizarIndicadorServidor() { |
||
| 559 | for (TurmaParticipante turmaParticipante : entidade.getParticipantes()) { |
||
| 560 | turmaParticipante.setIndicadorServidor(turmaFacade.consultarIndicadorDeServidor(turmaParticipante.getPessoa())); |
||
| 561 | } |
||
| 562 | } |
||
| 563 | |||
| 564 | } |