1 package ecar.dao;
2
3 import java.util.ArrayList;
4 import java.util.Collection;
5 import java.util.Iterator;
6 import java.util.List;
7 import java.util.Set;
8
9 import javax.servlet.http.HttpServletRequest;
10
11 import org.hibernate.HibernateException;
12 import org.hibernate.Transaction;
13 import org.hibernate.criterion.Order;
14 import org.hibernate.criterion.Restrictions;
15
16 import comum.database.Dao;
17 import comum.util.Data;
18 import comum.util.Pagina;
19
20 import ecar.exception.ECARException;
21 import ecar.pojo.Aba;
22 import ecar.pojo.FuncaoFun;
23 import ecar.pojo.TipoAcompanhamentoTa;
24 import ecar.util.Dominios;
25
26
27
28
29
30 public class AbaDao extends Dao {
31
32 public AbaDao(HttpServletRequest request) {
33 super();
34 this.request = request;
35 }
36
37 @SuppressWarnings("unchecked")
38 public void alterar(HttpServletRequest request) throws ECARException {
39 Transaction tx = null;
40 try {
41 ArrayList<Aba> objetos = new ArrayList<Aba>();
42 super.inicializarLogBean();
43 tx = session.beginTransaction();
44
45
46 ArrayList<Aba> lista = (ArrayList<Aba>) this.listar(Aba.class, new String[] { "codAba", "asc" });
47
48 for (Aba aba : lista) {
49
50 if (Dominios.SIM.equals(Pagina.getParamStr(request, "exibePosicaoAba" + aba.getCodAba().toString()))) {
51 aba.setExibePosicaoAba(Dominios.SIM);
52 }
53 else {
54 aba.setExibePosicaoAba(Dominios.NAO);
55 }
56
57 aba.setOrdemAba(Integer.valueOf(Pagina.getParamInt(request, "ordemAba" + aba.getCodAba().toString())));
58 aba.setLabelAba(Pagina.getParamStr(request, "labelAba" + aba.getCodAba().toString()));
59
60 if ("".equals(Pagina.getParamStr(request, "funAba" + aba.getCodAba().toString())))
61 aba.setFuncaoFun(null);
62 else {
63 FuncaoDao funcaoDao = new FuncaoDao(request);
64 FuncaoFun funcao = (FuncaoFun) funcaoDao.buscar(FuncaoFun.class, Long.valueOf(Pagina.getParamStr(request, "funAba" + aba.getCodAba().toString())));
65 aba.setFuncaoFun(funcao);
66 }
67 session.update(aba);
68 objetos.add(aba);
69 }
70
71 tx.commit();
72
73
74 if (super.logBean != null) {
75 super.logBean.setCodigoTransacao(Data.getHoraAtual(false));
76 super.logBean.setOperacao("ALT");
77
78 for (Iterator itObj = objetos.iterator(); itObj.hasNext();) {
79 super.logBean.setObj(itObj.next());
80 super.loggerAuditoria.info(logBean.toString());
81 }
82 }
83 } catch (HibernateException e) {
84 if (tx != null)
85 try {
86 tx.rollback();
87 } catch (HibernateException r) {
88 this.logger.error(r);
89 throw new ECARException("erro.hibernateException");
90 }
91 this.logger.error(e);
92 throw new ECARException("erro.hibernateException");
93 } catch (ECARException e) {
94 if (tx != null)
95 try {
96 tx.rollback();
97 } catch (HibernateException r) {
98 this.logger.error(r);
99 throw new ECARException("erro.hibernateException");
100 }
101 this.logger.error(e);
102 throw e;
103 }
104 }
105
106
107
108
109
110
111
112
113 @SuppressWarnings("unchecked")
114 public boolean verificaNivelPlanejamento(String opcao) {
115 boolean retorno = false;
116
117 try {
118 Aba abaAux = new Aba();
119 abaAux.setNomeAba("NIVEL_PLANEJAMENTO");
120
121 ArrayList<Aba> lista = (ArrayList<Aba>) this.pesquisar(abaAux, new String[] { "ordemAba", "asc" });
122 Iterator<Aba> it = lista.iterator();
123
124 if (it.hasNext()) {
125 Aba aba = (Aba) it.next();
126 if ("P".equals(opcao)) {
127 if ("S".equals(aba.getExibePosicaoAba())) {
128 retorno = true;
129 }
130 }
131 }
132 } catch (Exception e) {
133 this.logger.error(e);
134 retorno = false;
135 }
136
137 return retorno;
138 }
139
140 public List getListaAbas() {
141 return this.getSession().createCriteria(Aba.class).add(Restrictions.eq("exibePosicaoAba", Dominios.SIM)).addOrder(Order.asc("ordemAba")).list();
142
143 }
144
145 public List getListaAbasComAcesso(TipoAcompanhamentoTa ta, Set gruposUsuario) {
146 return this.getSession().createQuery("select distinct aba " + "from Aba aba " + "inner join aba.tipoacompAbasSisatributoTaabasatbs acesso " + "where acesso.tipoAcompanhamentoTa = :ta " + "and aba.abaSuperior = :abaSuperior " + "and aba.exibePosicaoAba = :exibe " + "and acesso.indVisualizaAba = :le " + "and acesso.sisAtributoSatb in (:grupo) " + "order by aba.ordemAba ").setParameter("ta", ta).setParameter("abaSuperior", Dominios.NAO).setString("exibe", Dominios.SIM).setString("le", Dominios.COM_ACESSO_LEITURA).setParameterList("grupo", gruposUsuario).list();
147 }
148
149 public List getListaAbasSuperiorComAcesso(TipoAcompanhamentoTa ta, Set gruposUsuario) {
150
151 return this.getSession().createQuery("select distinct aba " + "from Aba aba " + "inner join aba.tipoacompAbasSisatributoTaabasatbs acesso " + "where acesso.tipoAcompanhamentoTa = :ta " + "and aba.abaSuperior = :abaSuperior " + "and aba.exibePosicaoAba = :exibe " + "and acesso.indVisualizaAba = :le " + "and acesso.sisAtributoSatb in (:grupo) " + "order by aba.ordemAba ").setParameter("ta", ta).setParameter("abaSuperior", Dominios.SIM).setString("exibe", Dominios.SIM).setString("le", Dominios.COM_ACESSO_LEITURA).setParameterList("grupo", gruposUsuario).list();
152
153 }
154
155 public Aba buscarAba(String nomeAba) {
156 List<Aba> listAbas = this.getSession().createQuery("select distinct aba " + "from Aba aba " + "where nomeAba = :nomeAba ").setParameter("nomeAba", nomeAba).list();
157
158 if (listAbas != null && (!listAbas.isEmpty())) {
159 return (Aba) listAbas.iterator().next();
160 }
161 else {
162 return null;
163 }
164 }
165
166 public Collection<Aba> listarSuperior() {
167
168 return this.getSession().createCriteria(Aba.class).add(Restrictions.eq("abaSuperior", Dominios.SIM)).addOrder(Order.asc("ordemAba")).list();
169 }
170
171 public Collection<Aba> listarAbasMonitoramento() {
172
173 return this.getSession().createCriteria(Aba.class).add(Restrictions.eq("abaSuperior", Dominios.NAO)).addOrder(Order.asc("ordemAba")).list();
174 }
175
176 }