Subversion Repositories Integrator Subversion

Rev

Blame | Last modification | View Log | Download | RSS feed

package br.edu.cesmac.sic.controller.beans;

import java.io.Serializable;

import javax.annotation.PostConstruct;
import javax.inject.Inject;
import javax.inject.Named;

import org.springframework.context.annotation.Scope;

import br.edu.cesmac.core.consulta.ParametrosConsulta;
import br.edu.cesmac.core.generic.GenericService;
import br.edu.cesmac.sic.controller.beans.consultademanda.ProjetoPesquisaConsultaPorDemanda;
import br.edu.cesmac.sic.core.domain.model.ProjetoPesquisa;
import br.edu.cesmac.sic.core.domain.service.ProjetoPesquisaService;
import br.edu.cesmac.web.exception.VerificadorLancamentoException;
import br.edu.cesmac.web.exception.VerificadorLancamentoException.CommandBean;
import br.edu.cesmac.web.generic.AbstractBean;
import br.edu.cesmac.web.message.LancadorMensagem;

@Named
@Scope("view")
public class RecursoBean extends AbstractBean<ProjetoPesquisa> implements Serializable {

        private static final long serialVersionUID = 1L;
       
        private ProjetoPesquisaConsultaPorDemanda lazy;
        private ProjetoPesquisaService projetoPesquisaService;
       
        @Inject
        public RecursoBean(ProjetoPesquisaConsultaPorDemanda lazy, ProjetoPesquisaService projetoPesquisaService) {
                this.lazy = lazy;
                this.projetoPesquisaService = projetoPesquisaService;
        }

        @Override
        public ProjetoPesquisa getId() {
                return getEntidade();
        }

        @Override
        public GenericService<ProjetoPesquisa> getService() {
                return projetoPesquisaService;
        }

        @Override
        public void limparEntidade() {
                setEntidade(new ProjetoPesquisa());
        }
       
        @Override
        public ProjetoPesquisa getEntidade() {
                return entidade;
        }

        public ProjetoPesquisaConsultaPorDemanda getLazy() {
                return lazy;
        }
       
        public void prepararConsultaDemanda() {
                lazy.setarParametrosConsulta(getParametrosConsulta());
        }
       
        @PostConstruct
        public void preCarregamento() {
                parametrosConsulta = new ParametrosConsulta<ProjetoPesquisa>();
                parametrosConsulta.setEntidade(new ProjetoPesquisa());
                prepararConsultaDemanda();
        }
       
        @Override
        public void preDetalhar(ProjetoPesquisa projetoPesquisa) {
                detalharProjetoPesquisa(projetoPesquisa);
                super.preDetalhar(entidade);
        }
       
        public void detalharProjetoPesquisa(ProjetoPesquisa projetoPesquisa) {
                setEntidade(projetoPesquisaService.detalharProjetoPesquisa(projetoPesquisa));
        }
       
        public void prepararSolicitacaoRecurso(ProjetoPesquisa projetoPesquisa) {
                /*
                projetoPesquisa.setProjetoPesquisaRecurso(new ProjetoPesquisaRecurso());
                */

                setEntidade(projetoPesquisa);
        }
       
        public void solicitarRecurso() {
                new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() {
                        public void execute() {
                                projetoPesquisaService.solicitarRecurso(getEntidade());
                                LancadorMensagem.lancarSucesso("Recurso solicitado com sucesso");
                        }
                });
        }
       
        public void atenderRecurso() {
                new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() {
                        public void execute() {
                                projetoPesquisaService.atenderRecurso(getEntidade());
                                LancadorMensagem.lancarSucesso("Recurso atendido com sucesso");
                        }
                });
        }
       
        public void excluirRecurso(final ProjetoPesquisa projetoPesquisa) {
                new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() {
                        public void execute() {
                                projetoPesquisaService.excluirRecurso(projetoPesquisa);
                                LancadorMensagem.lancarSucesso("Dados excluĂ­dos com sucesso");
                        }
                });
        }
       
}