1 /*
2 * Created on 13/09/2004
3 */
4 package ecar.dao;
5
6 import java.util.ArrayList;
7 import java.util.Iterator;
8 import java.util.List;
9 import java.util.Set;
10
11 import javax.servlet.http.HttpServletRequest;
12
13 import org.hibernate.HibernateException;
14 import org.hibernate.Query;
15 import org.hibernate.criterion.Restrictions;
16
17 import comum.database.Dao;
18 import comum.util.Pagina;
19
20 import ecar.exception.ECARException;
21 import ecar.login.SegurancaECAR;
22 import ecar.permissao.ValidaPermissao;
23 import ecar.pojo.EstruturaAcessoEtta;
24 import ecar.pojo.EstruturaAcessoEttaPK;
25 import ecar.pojo.EstruturaEtt;
26 import ecar.pojo.SisAtributoSatb;
27 import ecar.util.Dominios;
28 import ecar.pojo.TipoAcompGrpAcesso;
29 import ecar.pojo.TipoAcompanhamentoTa;
30
31 /**
32 * @author evandro
33 */
34 public class EstruturaAcessoDao extends Dao {
35
36 public static final short PERMISSAO_ACESSO_SECRETARIA = 1;
37 public static final short PERMISSAO_ACESSO_OUTRA_SECRETARIA = 2;
38
39 ValidaPermissao validaPermissao = new ValidaPermissao();
40
41 /**
42 * Construtor. Chama o Session factory do Hibernate
43 */
44 public EstruturaAcessoDao(HttpServletRequest request) {
45 super();
46 this.request = request;
47 }
48
49 public EstruturaAcessoDao() {
50 super();
51 }
52
53 /**
54 * Verifica se um grupo de usuario tem permissao de incluir registro de
55 * monitoramento em qualquer estrutura.
56 * @param estrutura
57 * @param gruposUsuario
58 * @return
59 * @throws ECARException
60 */
61 // @@ALTERAR@@
62 // public boolean temPermissoesAcessoAcompMonitorado(Set gruposUsuario) throws
63 // ECARException {
64 // boolean resultado = false;
65 //
66 // try {
67 // Query q =
68 // this.getSession().createQuery("select permissoes.estruturaEtt.codEtt " +
69 // "from EstruturaAcessoEtta permissoes " +
70 // "where permissoes.indIncAcompMonitoradoEtta = :incluir " +
71 // "and permissoes.sisAtributoSatb.codSatb in (:lista) ");
72 //
73 // q.setMaxResults(1);
74 //
75 // q.setString("incluir", ValidaPermissao.SIM);
76 //
77 // List codigos = new ArrayList();
78 // Iterator it = gruposUsuario.iterator();
79 //
80 // while(it.hasNext()){
81 // SisAtributoSatb atributo = (SisAtributoSatb) it.next();
82 // codigos.add(atributo.getCodSatb());
83 // }
84 // q.setParameterList("lista", codigos);
85 //
86 // List retorno = q.list();
87 // if(!retorno.isEmpty()) {
88 // resultado = true;
89 // }
90 //
91 // } catch (HibernateException e) {
92 // this.logger.error(e);
93 // throw new ECARException(e);
94 // }
95 // return resultado;
96 //
97 // }
98 /**
99 * Verifica se um grupo de usuario tem permissao de incluir registro de
100 * monitoramento em qualquer estrutura para registros de sua propria
101 * secretaria.
102 * @param estrutura
103 * @param gruposUsuario
104 * @return
105 * @throws ECARException
106 */
107 // @@ALTERAR@@
108 // public boolean temPermissoesAcessoSecretaria(Set gruposUsuario) throws
109 // ECARException {
110 // boolean resultado = false;
111 //
112 // try {
113 // Query q =
114 // this.getSession().createQuery("select permissoes.estruturaEtt.codEtt " +
115 // "from EstruturaAcessoEtta permissoes " +
116 // "where permissoes.indLeiAcompSecpropEtta = :incluir " +
117 // "and permissoes.sisAtributoSatb.codSatb in (:lista) ");
118 //
119 // q.setMaxResults(1);
120 //
121 // q.setString("incluir", ValidaPermissao.SIM);
122 //
123 // List codigos = new ArrayList();
124 // Iterator it = gruposUsuario.iterator();
125 //
126 // while(it.hasNext()){
127 // SisAtributoSatb atributo = (SisAtributoSatb) it.next();
128 // codigos.add(atributo.getCodSatb());
129 // }
130 // q.setParameterList("lista", codigos);
131 //
132 // List retorno = q.list();
133 // if(!retorno.isEmpty()) {
134 // resultado = true;
135 // }
136 //
137 // } catch (HibernateException e) {
138 // this.logger.error(e);
139 // throw new ECARException(e);
140 // }
141 // return resultado;
142 //
143 // }
144 /**
145 * Verifica se um grupo de usuario tem permissao de incluir registro de
146 * monitoramento em qualquer estrutura para registros de qualquer secretaria
147 * que não a sua própria.
148 * @param estrutura
149 * @param gruposUsuario
150 * @return
151 * @throws ECARException
152 */
153 // @@ALTERAR@@
154 // public boolean temPermissoesAcessoOutraSecretaria(Set gruposUsuario) throws
155 // ECARException {
156 // boolean resultado = false;
157 //
158 // try {
159 // Query q =
160 // this.getSession().createQuery("select permissoes.estruturaEtt.codEtt " +
161 // "from EstruturaAcessoEtta permissoes " +
162 // "where permissoes.indIncAcompSecoutrEtta = :incluir " +
163 // "and permissoes.sisAtributoSatb.codSatb in (:lista) ");
164 //
165 // q.setMaxResults(1);
166 //
167 // q.setString("incluir", ValidaPermissao.SIM);
168 //
169 // List codigos = new ArrayList();
170 // Iterator it = gruposUsuario.iterator();
171 //
172 // while(it.hasNext()){
173 // SisAtributoSatb atributo = (SisAtributoSatb) it.next();
174 // codigos.add(atributo.getCodSatb());
175 // }
176 // q.setParameterList("lista", codigos);
177 //
178 // List retorno = q.list();
179 // if(!retorno.isEmpty()) {
180 // resultado = true;
181 // }
182 //
183 // } catch (HibernateException e) {
184 // this.logger.error(e);
185 // throw new ECARException(e);
186 // }
187 // return resultado;
188 //
189 // }
190 /**
191 * Verifica se um grupo de usuario tem permissao de incluir registro de
192 * monitoramento em uma estrutura.
193 * @param estrutura
194 * @param gruposUsuario
195 * @return
196 * @throws ECARException
197 */
198 // @@ALTERAR@@
199 // public boolean temPermissoesAcessoAcompMonitorado(Set gruposUsuario,
200 // EstruturaEtt estrutura) throws ECARException {
201 // boolean resultado = false;
202 //
203 // try {
204 // Query q =
205 // this.getSession().createQuery("select permissoes.estruturaEtt.codEtt " +
206 // "from EstruturaAcessoEtta permissoes " +
207 // "where permissoes.indIncAcompMonitoradoEtta = :incluir " +
208 // "and permissoes.sisAtributoSatb.codSatb in (:lista) " +
209 // "and permissoes.estruturaEtt.codEtt = :codEtt");
210 //
211 // q.setMaxResults(1);
212 //
213 // q.setString("incluir", ValidaPermissao.SIM);
214 //
215 // List codigos = new ArrayList();
216 // Iterator it = gruposUsuario.iterator();
217 //
218 // while(it.hasNext()){
219 // SisAtributoSatb atributo = (SisAtributoSatb) it.next();
220 // codigos.add(atributo.getCodSatb());
221 // }
222 // q.setParameterList("lista", codigos);
223 //
224 // q.setLong("codEtt", estrutura.getCodEtt().longValue());
225 //
226 // List retorno = q.list();
227 // if(!retorno.isEmpty()) {
228 // resultado = true;
229 // }
230 //
231 // } catch (HibernateException e) {
232 // this.logger.error(e);
233 // throw new ECARException(e);
234 // }
235 // return resultado;
236 //
237 // }
238 /**
239 * Verifica se um grupo de usuario tem permissao de incluir registro de
240 * monitoramento em uma estrutura para registros de sua propria secretaria.
241 * @param estrutura
242 * @param gruposUsuario
243 * @return
244 * @throws ECARException
245 */
246 // @@ALTERAR@@
247 // public boolean temPermissoesAcessoSecretaria(Set gruposUsuario,
248 // EstruturaEtt estrutura) throws ECARException {
249 // boolean resultado = false;
250 //
251 // try {
252 // Query q =
253 // this.getSession().createQuery("select permissoes.estruturaEtt.codEtt " +
254 // "from EstruturaAcessoEtta permissoes " +
255 // "where permissoes.estruturaEtt.codEtt = :codEtt and " +
256 // "permissoes.indLeiAcompSecpropEtta = :incluir " +
257 // "and permissoes.sisAtributoSatb.codSatb in (:lista) ");
258 //
259 // q.setMaxResults(1);
260 //
261 // q.setLong("codEtt", estrutura.getCodEtt().longValue());
262 // q.setString("incluir", ValidaPermissao.SIM);
263 //
264 // List codigos = new ArrayList();
265 // Iterator it = gruposUsuario.iterator();
266 //
267 // while(it.hasNext()){
268 // SisAtributoSatb atributo = (SisAtributoSatb) it.next();
269 // codigos.add(atributo.getCodSatb());
270 // }
271 // q.setParameterList("lista", codigos);
272 //
273 // List retorno = q.list();
274 // if(!retorno.isEmpty()) {
275 // resultado = true;
276 // }
277 //
278 // } catch (HibernateException e) {
279 // this.logger.error(e);
280 // throw new ECARException(e);
281 // }
282 // return resultado;
283 //
284 // }
285 /**
286 * Verifica se um grupo de usuario tem permissao de incluir registro de
287 * monitoramento em qualquer estrutura para registros de qualquer secretaria
288 * que não a sua própria.
289 * @param estrutura
290 * @param gruposUsuario
291 * @return
292 * @throws ECARException
293 */
294 // @@ALTERAR@@
295 // public boolean temPermissoesAcessoOutraSecretaria(Set gruposUsuario,
296 // EstruturaEtt estrutura) throws ECARException {
297 // boolean resultado = false;
298 //
299 // try {
300 // Query q =
301 // this.getSession().createQuery("select permissoes.estruturaEtt.codEtt " +
302 // "from EstruturaAcessoEtta permissoes " +
303 // "where permissoes.estruturaEtt.codEtt = :codEtt and " +
304 // "permissoes.indIncAcompSecoutrEtta = :incluir " +
305 // "and permissoes.sisAtributoSatb.codSatb in (:lista) ");
306 //
307 // q.setMaxResults(1);
308 //
309 // q.setLong("codEtt", estrutura.getCodEtt().longValue());
310 // q.setString("incluir", ValidaPermissao.SIM);
311 //
312 // List codigos = new ArrayList();
313 // Iterator it = gruposUsuario.iterator();
314 //
315 // while(it.hasNext()){
316 // SisAtributoSatb atributo = (SisAtributoSatb) it.next();
317 // codigos.add(atributo.getCodSatb());
318 // }
319 // q.setParameterList("lista", codigos);
320 //
321 // List retorno = q.list();
322 // if(!retorno.isEmpty()) {
323 // resultado = true;
324 // }
325 //
326 // } catch (HibernateException e) {
327 // this.logger.error(e);
328 // throw new ECARException(e);
329 // }
330 // return resultado;
331 //
332 // }
333
334 /**
335 * Verifica um conjunto de grupos de acesso tem permissao de leitura de
336 * acompanhamento para registros monitorados de sua responsabilidade
337 * @param estrutura
338 * @param gruposUsuario
339 * @return
340 * @throws ECARException
341 */
342 // @@ALTERAR@@
343 // public boolean temPermissoesLeituraAcompSuaResponsabilidade(Set
344 // gruposUsuario, EstruturaEtt estrutura) throws ECARException {
345 // boolean resultado = false;
346 //
347 // try {
348 // Query q =
349 // this.getSession().createQuery("select permissoes.estruturaEtt.codEtt " +
350 // "from EstruturaAcessoEtta permissoes " +
351 // "where permissoes.estruturaEtt.codEtt = :codEtt and " +
352 // "permissoes.indLeiAcompSuaResponsEtta = :leitura " +
353 // "and permissoes.sisAtributoSatb.codSatb in (:lista) ");
354 //
355 // q.setMaxResults(1);
356 //
357 // q.setLong("codEtt", estrutura.getCodEtt().longValue());
358 // q.setString("leitura", ValidaPermissao.SIM);
359 //
360 // List codigos = new ArrayList();
361 // Iterator it = gruposUsuario.iterator();
362 //
363 // while(it.hasNext()){
364 // SisAtributoSatb atributo = (SisAtributoSatb) it.next();
365 // codigos.add(atributo.getCodSatb());
366 // }
367 // q.setParameterList("lista", codigos);
368 //
369 // List retorno = q.list();
370 // if(!retorno.isEmpty()) {
371 // resultado = true;
372 // }
373 //
374 // } catch (HibernateException e) {
375 // this.logger.error(e);
376 // throw new ECARException(e);
377 // }
378 // return resultado;
379 //
380 // }
381 /**
382 * Verifica se um grupo de grupos de acesso tem permissao de leitura de
383 * acompanhamento para registros monitorados de sua secretaria/órgão
384 * @param estrutura
385 * @param gruposUsuario
386 * @return
387 * @throws ECARException
388 */
389 // @@ALTERAR@@
390 // public boolean temPermissoesLeituraAcompMonitoradoSuaSecretaria(Set
391 // gruposUsuario, EstruturaEtt estrutura) throws ECARException {
392 // boolean resultado = false;
393 //
394 // try {
395 // Query q =
396 // this.getSession().createQuery("select permissoes.estruturaEtt.codEtt " +
397 // "from EstruturaAcessoEtta permissoes " +
398 // "where permissoes.estruturaEtt.codEtt = :codEtt and " +
399 // "permissoes.indLeiAcompMoniSecProEtta = :leitura " +
400 // "and permissoes.sisAtributoSatb.codSatb in (:lista) ");
401 //
402 // q.setMaxResults(1);
403 //
404 // q.setLong("codEtt", estrutura.getCodEtt().longValue());
405 // q.setString("leitura", ValidaPermissao.SIM);
406 //
407 // List codigos = new ArrayList();
408 // Iterator it = gruposUsuario.iterator();
409 //
410 // while(it.hasNext()){
411 // SisAtributoSatb atributo = (SisAtributoSatb) it.next();
412 // codigos.add(atributo.getCodSatb());
413 // }
414 // q.setParameterList("lista", codigos);
415 //
416 // List retorno = q.list();
417 // if(!retorno.isEmpty()) {
418 // resultado = true;
419 // }
420 //
421 // } catch (HibernateException e) {
422 // this.logger.error(e);
423 // throw new ECARException(e);
424 // }
425 // return resultado;
426 //
427 // }
428 /**
429 * Verifica se um grupo de grupos de acesso tem permissao de leitura de
430 * acompanhamento para registros monitorados de outra secretaria/órgão
431 * @param estrutura
432 * @param gruposUsuario
433 * @return
434 * @throws ECARException
435 */
436 // @@ALTERAR@@
437 // public boolean temPermissoesLeituraAcompMonitoradoOutraSecretaria(Set
438 // gruposUsuario, EstruturaEtt estrutura) throws ECARException {
439 // boolean resultado = false;
440 //
441 // try {
442 // Query q =
443 // this.getSession().createQuery("select permissoes.estruturaEtt.codEtt " +
444 // "from EstruturaAcessoEtta permissoes " +
445 // "where permissoes.estruturaEtt.codEtt = :codEtt and " +
446 // "permissoes.indLeiAcompMoniSecOutEtta = :leitura " +
447 // "and permissoes.sisAtributoSatb.codSatb in (:lista) ");
448 //
449 // q.setMaxResults(1);
450 //
451 // q.setLong("codEtt", estrutura.getCodEtt().longValue());
452 // q.setString("leitura", ValidaPermissao.SIM);
453 //
454 // List codigos = new ArrayList();
455 // Iterator it = gruposUsuario.iterator();
456 //
457 // while(it.hasNext()){
458 // SisAtributoSatb atributo = (SisAtributoSatb) it.next();
459 // codigos.add(atributo.getCodSatb());
460 // }
461 // q.setParameterList("lista", codigos);
462 //
463 // List retorno = q.list();
464 // if(!retorno.isEmpty()) {
465 // resultado = true;
466 // }
467 //
468 // } catch (HibernateException e) {
469 // this.logger.error(e);
470 // throw new ECARException(e);
471 // }
472 // return resultado;
473 //
474 // }
475 /**
476 * Verifica se um grupo de grupos de acesso tem permissao de leitura de
477 * acompanhamento para registros monitorados próprios
478 * @param estrutura
479 * @param gruposUsuario
480 * @return
481 * @throws ECARException
482 */
483 // @@ALTERAR@@
484 // public boolean temPermissoesLeituraAcompMonitoradoProprio(Set
485 // gruposUsuario, EstruturaEtt estrutura) throws ECARException {
486 // boolean resultado = false;
487 //
488 // try {
489 // Query q =
490 // this.getSession().createQuery("select permissoes.estruturaEtt.codEtt " +
491 // "from EstruturaAcessoEtta permissoes " +
492 // "where permissoes.estruturaEtt.codEtt = :codEtt and " +
493 // "permissoes.indLeiAcompMoniProprEtta = :leitura " +
494 // "and permissoes.sisAtributoSatb.codSatb in (:lista) ");
495 //
496 // q.setMaxResults(1);
497 //
498 // q.setLong("codEtt", estrutura.getCodEtt().longValue());
499 // q.setString("leitura", ValidaPermissao.SIM);
500 //
501 // List codigos = new ArrayList();
502 // Iterator it = gruposUsuario.iterator();
503 //
504 // while(it.hasNext()){
505 // SisAtributoSatb atributo = (SisAtributoSatb) it.next();
506 // codigos.add(atributo.getCodSatb());
507 // }
508 // q.setParameterList("lista", codigos);
509 //
510 // List retorno = q.list();
511 // if(!retorno.isEmpty()) {
512 // resultado = true;
513 // }
514 //
515 // } catch (HibernateException e) {
516 // this.logger.error(e);
517 // throw new ECARException(e);
518 // }
519 // return resultado;
520 //
521 // }
522 /**
523 * @author Robson
524 * @param EstruturaEtt
525 * @param SisAtributoSatb
526 * @return EstruturaAcessoEtta
527 * @throws ECARException
528 */
529 public EstruturaAcessoEtta getEstruturaAcessoEtta(SisAtributoSatb atributo, EstruturaEtt estruturaEtt) throws ECARException {
530 // XXX: Novas funções de acesso
531 try {
532 EstruturaAcessoEttaPK id = new EstruturaAcessoEttaPK(estruturaEtt.getCodEtt(), atributo.getCodSatb());
533 // return (EstruturaAcessoEtta)
534 // this.getSession().createCriteria(EstruturaAcessoEtta.class)
535 // .add(Restrictions.eq("estruturaEtt", estruturaEtt))
536 // .add(Restrictions.eq("sisAtributoSatb", atributo))
537 // .uniqueResult();
538 return (EstruturaAcessoEtta) this.getSession().get(EstruturaAcessoEtta.class, id);
539 } catch (HibernateException e) {
540 this.logger.error(e);
541 throw new ECARException(e);
542 }
543 }
544
545 /**
546 * @author Robson
547 * @param Arraylist
548 * @return NULL
549 * @throws EcarException
550 */
551 public void setEstruturaAcessoEtta(EstruturaAcessoEtta etta, HttpServletRequest request) {
552 // XXX: Novas funções de acesso
553 etta.setIndIncItemEtta(Pagina.getParamOrDefault(request, "indIncItemEtta" + etta.getComp_id().getCodEtt(), EstruturaAcessoEtta.SEM_ACESSO_INCLUSAO));
554 }
555
556 // tb_tipo_acomp_grp_acesso
557
558 /**
559 * Verifica se um grupo de usuario tem permissao de acessar um acompanhamento
560 * de um tipo de acompanhamento
561 * @param estrutura
562 * @param gruposUsuario
563 * @return
564 * @throws ECARException
565 */
566 public boolean temPermissoesAcessoAcomp(TipoAcompanhamentoTa tipoAcompanhamentoTa, Set gruposUsuario) throws ECARException {
567 boolean resultado = false;
568
569 try {
570 Query q = this.getSession().createQuery("select tipoAcompGrpAcesso " + "from TipoAcompGrpAcesso tipoAcompGrpAcesso " + "where tipoAcompGrpAcesso.tipoAcompanhamentoTa = :tipoAcompanhamentoTa " + "and tipoAcompGrpAcesso.sisAtributoSatb in (:gruposUsuarios) " + "and tipoAcompGrpAcesso.acessoInclusao = :acessoInclusao");
571
572 q.setMaxResults(1);
573
574 q.setString("acessoInclusao", ValidaPermissao.SIM);
575 q.setParameter("tipoAcompanhamentoTa", tipoAcompanhamentoTa);
576 q.setParameterList("gruposUsuarios", gruposUsuario);
577
578 List retorno = q.list();
579 if (!retorno.isEmpty()) {
580 resultado = true;
581 }
582
583 } catch (HibernateException e) {
584 this.logger.error(e);
585 throw new ECARException(e);
586 }
587
588 return resultado;
589
590 }
591
592 /**
593 * Verifica se um grupo de usuario tem permissao de acessar algum
594 * acompanhamento
595 * @param gruposUsuario
596 * @return
597 * @throws ECARException
598 */
599 public boolean temPermissoesAcessoAcomp(Set gruposUsuario) throws ECARException {
600 boolean resultado = false;
601
602 try {
603 Query q = this.getSession().createQuery("select tipoAcompGrpAcesso " + "from TipoAcompGrpAcesso tipoAcompGrpAcesso " + "where tipoAcompGrpAcesso.sisAtributoSatb in (:gruposUsuarios) " + "and tipoAcompGrpAcesso.acessoInclusao = :acessoInclusao");
604
605 q.setMaxResults(1);
606
607 q.setString("acessoInclusao", ValidaPermissao.SIM);
608 q.setParameterList("gruposUsuarios", gruposUsuario);
609
610 List retorno = q.list();
611 if (!retorno.isEmpty()) {
612 resultado = true;
613 }
614
615 } catch (HibernateException e) {
616 this.logger.error(e);
617 throw new ECARException(e);
618 }
619
620 return resultado;
621
622 }
623
624 public boolean temPermissoesAcessoAcompTodosOrgaos(TipoAcompanhamentoTa tipoAcompanhamentoTa, Set gruposUsuario) throws ECARException {
625 boolean resultado = false;
626
627 try {
628 TipoAcompGrpAcesso tipoAcompGrpAcesso = new TipoAcompGrpAcesso();
629 tipoAcompGrpAcesso.getSepararPorOrgao();
630 Query q = this.getSession().createQuery("select tipoAcompGrpAcesso " + "from TipoAcompGrpAcesso tipoAcompGrpAcesso " + "where tipoAcompGrpAcesso.tipoAcompanhamentoTa = :tipoAcompanhamentoTa " + "and tipoAcompGrpAcesso.sisAtributoSatb in (:gruposUsuarios) " + "and tipoAcompGrpAcesso.acessoInclusao = :acessoInclusao " + "and (tipoAcompGrpAcesso.separarPorOrgao = :separarPorOrgao or tipoAcompGrpAcesso.separarPorOrgao is null)");
631
632 q.setMaxResults(1);
633
634 q.setString("acessoInclusao", ValidaPermissao.SIM);
635 q.setParameter("tipoAcompanhamentoTa", tipoAcompanhamentoTa);
636 q.setInteger("separarPorOrgao", ValidaPermissao.PERMISSAO_TODOS_ORGAOS);
637 q.setParameterList("gruposUsuarios", gruposUsuario);
638
639 List retorno = q.list();
640 if (!retorno.isEmpty()) {
641 resultado = true;
642 }
643
644 } catch (HibernateException e) {
645 this.logger.error(e);
646 throw new ECARException(e);
647 }
648
649 return resultado;
650
651 }
652
653 public boolean temPermissoesAcessoAcompSeusOrgaos(TipoAcompanhamentoTa tipoAcompanhamentoTa, Set gruposUsuario) throws ECARException {
654 boolean resultado = false;
655
656 try {
657 TipoAcompGrpAcesso tipoAcompGrpAcesso = new TipoAcompGrpAcesso();
658 tipoAcompGrpAcesso.getSepararPorOrgao();
659 Query q = this.getSession().createQuery("select tipoAcompGrpAcesso " + "from TipoAcompGrpAcesso tipoAcompGrpAcesso " + "where tipoAcompGrpAcesso.tipoAcompanhamentoTa = :tipoAcompanhamentoTa " + "and tipoAcompGrpAcesso.sisAtributoSatb in (:gruposUsuarios) " + "and tipoAcompGrpAcesso.acessoInclusao = :acessoInclusao " + "and tipoAcompGrpAcesso.separarPorOrgao = :separarPorOrgao");
660
661 q.setMaxResults(1);
662
663 q.setString("acessoInclusao", ValidaPermissao.SIM);
664 q.setParameter("tipoAcompanhamentoTa", tipoAcompanhamentoTa);
665 q.setInteger("separarPorOrgao", ValidaPermissao.PERMISSAO_SEUS_ORGAOS);
666 q.setParameterList("gruposUsuarios", gruposUsuario);
667
668 List retorno = q.list();
669 if (!retorno.isEmpty()) {
670 resultado = true;
671 }
672
673 } catch (HibernateException e) {
674 this.logger.error(e);
675 throw new ECARException(e);
676 }
677
678 return resultado;
679
680 }
681
682 public boolean temPermissoesAcessoAcompOrgaosSuaResponsabilidade(TipoAcompanhamentoTa tipoAcompanhamentoTa, Set gruposUsuario) throws ECARException {
683 boolean resultado = false;
684
685 try {
686 TipoAcompGrpAcesso tipoAcompGrpAcesso = new TipoAcompGrpAcesso();
687 tipoAcompGrpAcesso.getSepararPorOrgao();
688 Query q = this.getSession().createQuery("select tipoAcompGrpAcesso " + "from TipoAcompGrpAcesso tipoAcompGrpAcesso " + "where tipoAcompGrpAcesso.tipoAcompanhamentoTa = :tipoAcompanhamentoTa " + "and tipoAcompGrpAcesso.sisAtributoSatb in (:gruposUsuarios) " + "and tipoAcompGrpAcesso.acessoInclusao = :acessoInclusao " + "and tipoAcompGrpAcesso.separarPorOrgao = :separarPorOrgao");
689
690 q.setMaxResults(1);
691
692 q.setString("acessoInclusao", ValidaPermissao.SIM);
693 q.setParameter("tipoAcompanhamentoTa", tipoAcompanhamentoTa);
694 q.setInteger("separarPorOrgao", ValidaPermissao.PERMISSAO_SUA_RESPONSABILIDADE);
695 q.setParameterList("gruposUsuarios", gruposUsuario);
696
697 List retorno = q.list();
698 if (!retorno.isEmpty()) {
699 resultado = true;
700 }
701
702 } catch (HibernateException e) {
703 this.logger.error(e);
704 throw new ECARException(e);
705 }
706
707 return resultado;
708
709 }
710
711 // public boolean temPermissaoAcessoEstrutura(SegurancaECAR seguranca,
712 // EstruturaEtt ett){
713 // Set gruposUsuario = seguranca.getGruposAcesso();
714 // Query q = this.getSession().createQuery("select ett " +
715 // "from EstruturaEtt Ett " +
716 // "inner join Ett.tipoAcompanhamentoTa ta " +
717 // "inner join ta.tipoacompTipofuncacompSisatributoTatpfasatbs parecer " +
718 // "inner join ta.tipoacompAbasSisatributoTaabasatbs aba " +
719 // "where Ett = :ett " +
720 // "and((parecer.sisAtributoSatb in (:atributosparecer) and parecer.indLeituraParecer = :leitura) "
721 // +
722 // "or (aba.sisAtributoSatb in (:atributosaba) and aba.indVisualizaAba = :visualiza)) ")
723 // .setParameter("ett", ett)
724 // .setParameterList("atributosparecer", gruposUsuario)
725 // .setString("leitura", Dominios.COM_ACESSO_LEITURA)
726 // .setParameterList("atributosaba", gruposUsuario)
727 // .setString("visualiza", Dominios.COM_ACESSO_LEITURA);
728 // return !q.list().isEmpty();
729 // }
730
731 /**
732 * @author Robson
733 * @param Set gruposUsuario
734 * @param EstruturaEtt ett
735 * @param short acao
736 * @return booelan
737 * @throws ECARException TODO: nao terminado, falta incluir acoes Funcao que
738 * verifica se usuario pode executar determinada acao na Estrutura
739 */
740 public boolean PermissaoAcessoGrupoEstrutura(Set gruposUsuario, EstruturaEtt ett, short acao) throws ECARException {
741 // XXX: Novas funções de acesso
742 try {
743 StringBuilder str = new StringBuilder("from EstruturaAcessoEtta etta " + "where etta.estruturaEtt = :ett " + "and etta.sisAtributoSatb in (:lista) ");
744 if (acao == PERMISSAO_ACESSO_SECRETARIA)
745 str.append("and etta.indLeiAcompSecpropEtta = :sim ");
746
747 else if (acao == PERMISSAO_ACESSO_OUTRA_SECRETARIA)
748 str.append("and etta.indIncAcompSecoutrEtta = :sim ");
749
750 Query q = this.getSession().createQuery(str.toString());
751
752 q.setMaxResults(1);
753 q.setParameter("ett", ett);
754 q.setParameterList("lista", gruposUsuario);
755 q.setString("sim", Dominios.SIM);
756
757 return !q.list().isEmpty();
758
759 } catch (HibernateException e) {
760 this.logger.error(e);
761 throw new ECARException(e);
762 }
763 }
764
765 }