View Javadoc

1   /*
2    * Created on 09/05/2005
3    */
4   package ecar.dao;
5   
6   import java.util.ArrayList;
7   import java.util.Date;
8   import java.util.List;
9   
10  import javax.servlet.http.HttpServletRequest;
11  
12  import org.hibernate.HibernateException;
13  import org.hibernate.Query;
14  
15  import comum.database.Dao;
16  import comum.util.Data;
17  import comum.util.Pagina;
18  
19  import ecar.exception.ECARException;
20  import ecar.pojo.PopupComportamentoPppc;
21  import ecar.pojo.PopupPpp;
22  
23  /**
24   * @author felipe
25   */
26  public class PopUpDao extends Dao {
27  
28    public static final int POPUP_COMPORTAMENTO_ABRIR_SEMPRE = 1;
29    public static final int POPUP_COMPORTAMENTO_ABRIR_SOMENTE_UMA_VEZ = 2;
30  
31    /**
32     * Construtora
33     * @param request
34     */
35    public PopUpDao(HttpServletRequest request) {
36      super();
37      this.request = request;
38    }
39  
40    /**
41     * Salva
42     * @param popUp
43     * @throws ECARException
44     */
45    public void salvar(PopupPpp popUp) throws ECARException {
46      popUp.setDataInclusaoPpp(Data.getDataAtual());
47      super.salvar(popUp);
48    }
49  
50    /**
51     * A partir de dados passados por request popula um objeto PopUpPpp
52     * @param segmento
53     * @param campos
54     * @param recuperarParametrosComoString indica se irá recuperar dados nulos
55     *          como String vazia
56     * @throws ECARException
57     */
58    public void setPopup(PopupPpp popUp, HttpServletRequest request, boolean recuperarParametrosComoString) throws ECARException {
59  
60      try {
61        if (!"".equals(Pagina.getParamStr(request, "popupComportamentoPppc"))) {
62          popUp.setPopupComportamentoPppc((PopupComportamentoPppc) this.buscar(PopupComportamentoPppc.class, Long.valueOf(Pagina.getParamStr(request, "popupComportamentoPppc"))));
63        }
64        if (!"".equals(Pagina.getParamStr(request, "janelaAlturaPpp")))
65          popUp.setJanelaAlturaPpp(Integer.valueOf(Pagina.getParamStr(request, "janelaAlturaPpp")));
66        if (!"".equals(Pagina.getParamStr(request, "janelaLarguraPpp")))
67          popUp.setJanelaLarguraPpp(Integer.valueOf(Pagina.getParamStr(request, "janelaLarguraPpp")));
68        if (!"".equals(Pagina.getParamStr(request, "dataIniExibicaoPpp")))
69          popUp.setDataIniExibicaoPpp(Data.parseDate(Pagina.getParamStr(request, "dataIniExibicaoPpp")));
70        if (!"".equals(Pagina.getParamStr(request, "dataFimExibicaoPpp")))
71          popUp.setDataFimExibicaoPpp(Data.parseDate(Pagina.getParamStr(request, "dataFimExibicaoPpp")));
72  
73        if (recuperarParametrosComoString) {
74          popUp.setNomePpp(Pagina.getParamStr(request, "nomePpp"));
75          popUp.setConteudoPpp(Pagina.getParamStr(request, "conteudoPpp"));
76          popUp.setIndDesativarPpp(Pagina.getParamStr(request, "indDesativarPpp"));
77          popUp.setIndAtivaPpp(Pagina.getParamStr(request, "indAtivaPpp"));
78        }
79        else {
80          popUp.setNomePpp(Pagina.getParam(request, "nomePpp"));
81          popUp.setConteudoPpp(Pagina.getParam(request, "conteudoPpp"));
82          popUp.setIndDesativarPpp(Pagina.getParam(request, "indDesativarPpp"));
83          popUp.setIndAtivaPpp(Pagina.getParam(request, "indAtivaPpp"));
84        }
85      } catch (Exception e) {
86        this.logger.error(e);
87        throw new ECARException(e);
88      }
89  
90    }
91  
92    /**
93     * Retorna uma lista de Avisos que podem ser apresentados em um dia.
94     * @param dia
95     * @return
96     * @throws ECARException
97     */
98    public List getPopUpsApresentadasNoDia(Date dia) throws ECARException {
99      List resultado = new ArrayList();
100 
101     try {
102       Query query = session.createQuery("from PopupPpp p where not (:dia < p.dataIniExibicaoPpp or :dia > p.dataFimExibicaoPpp) and p.indAtivaPpp = 'S'");
103 
104       query.setDate("dia", dia);
105 
106       resultado = query.list();
107     } catch (HibernateException e) {
108       this.logger.error(e);
109       throw new ECARException("erro.hibernateException");
110     }
111     return (resultado);
112 
113   }
114 
115 }