1 package ecar.dao;
2
3 import java.util.ArrayList;
4 import java.util.Iterator;
5 import java.util.List;
6 import java.util.Set;
7
8 import javax.servlet.http.HttpServletRequest;
9
10 import org.hibernate.HibernateException;
11
12 import comum.database.Dao;
13 import comum.util.Pagina;
14 import ecar.exception.ECARException;
15 import ecar.pojo.SisAtributoSatb;
16 import ecar.pojo.TipoAcompGrpAcesso;
17 import ecar.pojo.TipoAcompGrpAcessoId;
18 import ecar.pojo.TipoAcompanhamentoTa;
19 import ecar.util.Dominios;
20
21
22
23
24
25 public class TipoAcompGrpAcessoDao extends Dao {
26
27 public TipoAcompGrpAcesso getTipoAcompGrpAcesso(SisAtributoSatb satb, TipoAcompanhamentoTa ta) throws ECARException {
28 try {
29
30
31
32
33
34 return (TipoAcompGrpAcesso) this.getSession().get(TipoAcompGrpAcesso.class, new TipoAcompGrpAcessoId(ta.getCodTa(), satb.getCodSatb()));
35 } catch (HibernateException e) {
36 this.logger.error(e);
37 throw new ECARException(e);
38 }
39 }
40
41 public void setTipoAcompGrpAcesso(TipoAcompGrpAcesso taa, HttpServletRequest request) {
42
43 taa.setAcessoInclusao(Pagina.getParamOrDefault(request, "GeraAcomp" + taa.getId().getCodTa(), Dominios.SEM_ACESSO_INCLUSAO));
44 try {
45 if (Dominios.COM_ACESSO_INCLUSAO.equals(taa.getAcessoInclusao()))
46 taa.setSepararPorOrgao(Integer.valueOf(Pagina.getParamStr(request, "SepararPorOrgao" + taa.getId().getCodTa())));
47 else
48 taa.setSepararPorOrgao(null);
49 } catch (NumberFormatException e) {
50 taa.setSepararPorOrgao(null);
51 }
52 }
53
54 public boolean permissaoAcessoSecretariasUsuario(Set gruposUsuario, int tipoAcesso) {
55
56 List listaCods = new ArrayList();
57 for (Iterator it = gruposUsuario.iterator(); it.hasNext();) {
58 SisAtributoSatb satb = (SisAtributoSatb) it.next();
59 listaCods.add(satb.getCodSatb());
60 }
61
62 return !this.getSession().createQuery(
63 "select acesso " +
64 " from TipoAcompGrpAcesso acesso " +
65 " where acessoInclusao = :incluir " +
66 " and acesso.separarPorOrgao = :tipo " +
67 " and acesso.sisAtributoSatb.codSatb in (:lista) ")
68 .setMaxResults(1)
69 .setString("incluir", Dominios.SIM)
70 .setInteger("tipo", tipoAcesso)
71 .setParameterList("lista", listaCods)
72 .list()
73 .isEmpty();
74 }
75 }