1 package ecar.dao;
2
3 import java.util.ArrayList;
4 import java.util.Collections;
5 import java.util.Comparator;
6 import java.util.Iterator;
7 import java.util.List;
8
9 import javax.servlet.http.HttpServletRequest;
10
11 import org.hibernate.Criteria;
12 import org.hibernate.HibernateException;
13 import org.hibernate.Query;
14 import org.hibernate.criterion.Restrictions;
15
16 import comum.database.Dao;
17
18 import comum.util.Pagina;
19
20 import ecar.exception.ECARException;
21 import ecar.pojo.AtributoDemandaAtbdem;
22 import ecar.pojo.AtributosAtb;
23 import ecar.pojo.EstAtribTipoAcompEata;
24 import ecar.pojo.EstruturaAtributoEttat;
25 import ecar.pojo.EstruturaEtt;
26 import ecar.pojo.ObjetoDemanda;
27 import ecar.pojo.ObjetoEstrutura;
28 import ecar.pojo.SisGrupoAtributoSga;
29 import ecar.pojo.TipoAcompanhamentoTa;
30 import ecar.util.Dominios;
31
32
33
34
35
36
37
38 public class AtributoDemandaDao extends Dao {
39
40
41
42 public AtributoDemandaDao(HttpServletRequest request) {
43 super();
44 this.request = request;
45 }
46
47 public void salvar(AtributoDemandaAtbdem atributoDemanda) throws ECARException {
48
49 if (pesquisarDuplos(atributoDemanda, new String[] { "nomeAtbdem", "labelPadraoAtbdem" }, "codAtbdem").size() > 0)
50 throw new ECARException("atributo.validacao.registroDuplicado");
51
52 if (atributoDemanda.getIndAtivoAtbdem() != null && "S".equals(atributoDemanda.getIndAtivoAtbdem())) {
53 if (pesquisarDuplosAtributoDemanda(atributoDemanda, atributoDemanda.getSisGrupoAtributoSga(), atributoDemanda.getIndAtivoAtbdem()))
54 throw new ECARException("atributo.validacao.registroDuplicadoAtivo");
55 }
56
57 if (atributoDemanda.getIndRestritivo().equals("S") && (atributoDemanda.getSisGrupoAtributoSga() == null || !atributoDemanda.getSisGrupoAtributoSga().getIndCadUsuSga().equals("S"))) {
58 throw new ECARException("atributo.validacao.indRestritivoInvalido");
59 }
60
61 if (atributoDemanda.getSisGrupoAtributoSga() == null) {
62 validarNomeAtributoDemanda(atributoDemanda);
63 }
64
65 super.salvar(atributoDemanda);
66 }
67
68 public void excluir(AtributoDemandaAtbdem atributoDemanda) throws ECARException {
69 try {
70 boolean excluir = true;
71
72 if (excluir)
73 super.excluir(atributoDemanda);
74 } catch (ECARException e) {
75 this.logger.error(e);
76 throw e;
77 }
78 }
79
80 public void alterar(AtributoDemandaAtbdem atributoDemanda) throws ECARException {
81
82 if (pesquisarDuplos(atributoDemanda, new String[] { "nomeAtbdem", "labelPadraoAtbdem" }, "codAtbdem").size() > 0)
83 throw new ECARException("atributo.validacao.registroDuplicado");
84
85 if (atributoDemanda.getIndAtivoAtbdem() != null && "S".equals(atributoDemanda.getIndAtivoAtbdem())) {
86 if (pesquisarDuplosAtributoDemanda(atributoDemanda, atributoDemanda.getSisGrupoAtributoSga(), atributoDemanda.getIndAtivoAtbdem()))
87 throw new ECARException("atributo.validacao.registroDuplicadoAtivo");
88 }
89
90 if (atributoDemanda.getSisGrupoAtributoSga() == null) {
91 validarNomeAtributoDemanda(atributoDemanda);
92 }
93
94 if (atributoDemanda.getIndRestritivo().equals("S") && (atributoDemanda.getSisGrupoAtributoSga() == null || !atributoDemanda.getSisGrupoAtributoSga().getIndCadUsuSga().equals("S"))) {
95 throw new ECARException("atributo.validacao.indRestritivoInvalido");
96 }
97
98 super.alterar(atributoDemanda);
99 }
100
101 public boolean pesquisarDuplosAtributoDemanda(AtributoDemandaAtbdem obj, SisGrupoAtributoSga sisGrupo, String indAtivoAtbdem) throws ECARException {
102
103 boolean retorno = false;
104
105 try {
106
107 Criteria crits = session.createCriteria(AtributoDemandaAtbdem.class);
108
109 crits.add(Restrictions.eq("sisGrupoAtributoSga.codSga", (sisGrupo == null ? 0L : sisGrupo.getCodSga())));
110 crits.add(Restrictions.eq("indAtivoAtbdem", indAtivoAtbdem));
111 crits.add(Restrictions.ne("codAtbdem", (obj.getCodAtbdem() == null ? 0L : obj.getCodAtbdem())));
112
113
114 List<AtributoDemandaAtbdem> lista = (List<AtributoDemandaAtbdem>) crits.list();
115
116 if (lista.size() > 0) {
117 retorno = true;
118 }
119
120 return retorno;
121
122 } catch (Exception e) {
123 this.logger.error(e);
124 throw new ECARException("erro.hibernateException");
125 }
126 }
127
128
129
130
131
132
133
134
135
136 public void setAtributoDemanda(HttpServletRequest request, AtributoDemandaAtbdem atributoDemanda, boolean usarGetParamStr) throws ECARException {
137
138 if (Pagina.getParam(request, "codigo") != null)
139 atributoDemanda.setCodAtbdem(Long.valueOf(Pagina.getParam(request, "codigo")));
140 else
141 atributoDemanda.setCodAtbdem(null);
142
143 if (usarGetParamStr) {
144 atributoDemanda.setIndAtivoAtbdem(Pagina.getParamOrDefault(request, "indAtivoAtbdem", Pagina.NAO));
145 atributoDemanda.setNomeAtbdem(Pagina.getParamStr(request, "nomeAtbdem").trim());
146 atributoDemanda.setLabelPadraoAtbdem(Pagina.getParamStr(request, "labelPadraoAtbdem").trim());
147 atributoDemanda.setCodFkAtbdem(Pagina.getParamStr(request, "codFkAtbdem").trim());
148 atributoDemanda.setNomeFkAtbdem(Pagina.getParamStr(request, "nomeFkAtbdem").trim());
149 atributoDemanda.setDocumentacaoAtbdem(Pagina.getParamStr(request, "documentacaoAtbdem").trim());
150 atributoDemanda.setIndObrigatorioAtbdem((Pagina.getParamOrDefault(request, "indObrigatorioAtbdem", Pagina.NAO)));
151 atributoDemanda.setDicaAtbdem((Pagina.getParamStr(request, "dicaAtbdem").trim()));
152 atributoDemanda.setIndListagemItensAtbdem(((Pagina.getParamOrDefault(request, "indListagemItensAtbdem", Pagina.NAO))));
153 atributoDemanda.setIndFiltroAtbdem((((Pagina.getParamOrDefault(request, "indFiltroAtbdem", Pagina.NAO)))));
154 atributoDemanda.setIndRestritivo((((Pagina.getParamOrDefault(request, "indRestritivo", Pagina.NAO)))));
155
156 }
157 else {
158 atributoDemanda.setIndAtivoAtbdem(Pagina.getParam(request, "indAtivoAtbdem"));
159 atributoDemanda.setNomeAtbdem(Pagina.getParam(request, "nomeAtbdem"));
160 atributoDemanda.setLabelPadraoAtbdem(Pagina.getParam(request, "labelPadraoAtbdem"));
161 atributoDemanda.setCodFkAtbdem(Pagina.getParam(request, "codFkAtbdem"));
162 atributoDemanda.setNomeFkAtbdem(Pagina.getParam(request, "nomeFkAtbdem"));
163 atributoDemanda.setDocumentacaoAtbdem(Pagina.getParam(request, "documentacaoAtbdem"));
164 atributoDemanda.setIndObrigatorioAtbdem((Pagina.getParam(request, "indObrigatorioAtbdem")));
165 atributoDemanda.setDicaAtbdem((Pagina.getParam(request, "dicaAtbdem")));
166 atributoDemanda.setIndListagemItensAtbdem(((Pagina.getParam(request, "indListagemItensAtbdem"))));
167 atributoDemanda.setIndFiltroAtbdem((((Pagina.getParam(request, "indFiltroAtbdem")))));
168 atributoDemanda.setIndRestritivo((((Pagina.getParam(request, "indRestritivo")))));
169 }
170
171 SisGrupoAtributoDao sgaDao = new SisGrupoAtributoDao(request);
172
173 if (Pagina.getParam(request, "sisGrupoAtributoSga") != null) {
174 atributoDemanda.setSisGrupoAtributoSga((SisGrupoAtributoSga) sgaDao.buscar(SisGrupoAtributoSga.class, Long.valueOf(Pagina.getParamStr(request, "sisGrupoAtributoSga"))));
175 }
176 else {
177 atributoDemanda.setSisGrupoAtributoSga(null);
178 }
179
180
181 if (Pagina.getParam(request, "seqApresListagemTelaAtbdem") != null)
182 atributoDemanda.setSeqApresListagemTelaAtbdem((Integer.valueOf(Pagina.getParam(request, "seqApresListagemTelaAtbdem"))));
183 else
184 atributoDemanda.setSeqApresListagemTelaAtbdem(null);
185
186
187 if (Pagina.getParam(request, "larguraListagemTelaAtbdem") != null)
188 atributoDemanda.setLarguraListagemTelaAtbdem((Integer.valueOf(Pagina.getParam(request, "larguraListagemTelaAtbdem"))));
189 else
190 atributoDemanda.setLarguraListagemTelaAtbdem(null);
191
192
193 if (Pagina.getParam(request, "seqApresTelaCampoAtbdem") != null)
194 atributoDemanda.setSeqApresTelaCampoAtbdem((Integer.valueOf(Pagina.getParam(request, "seqApresTelaCampoAtbdem"))));
195 else
196 atributoDemanda.setSeqApresTelaCampoAtbdem(null);
197
198
199 if (Pagina.getParam(request, "tamanhoConteudoAtbdem") != null)
200 atributoDemanda.setTamanhoConteudoAtbdem((Integer.valueOf(Pagina.getParam(request, "tamanhoConteudoAtbdem"))));
201 else
202 atributoDemanda.setTamanhoConteudoAtbdem(null);
203 }
204
205 public List getAtributosDemandaAtivosOrdenadosPorSequenciaLista() throws ECARException {
206
207 List retorno = new ArrayList();
208 AtributoDemandaAtbdem atributoDemanda = new AtributoDemandaAtbdem();
209
210 try {
211 StringBuilder query = new StringBuilder("select atributoDemanda from AtributoDemandaAtbdem as atributoDemanda").append(" where atributoDemanda.indAtivoAtbdem = 'S'").append(" and atributoDemanda.indListagemItensAtbdem = 'S'").append(" order by atributoDemanda.seqApresListagemTelaAtbdem asc");
212
213 Query q = this.getSession().createQuery(query.toString());
214
215 retorno = q.list();
216
217 } catch (HibernateException e) {
218 this.logger.error(e);
219 throw new ECARException("erro.hibernateException");
220 }
221 return retorno;
222 }
223
224
225
226
227
228
229
230
231 public List getAtributosDemandaAtivosOrdenadosPorSequenciaTelaCampo() throws ECARException {
232 List retorno = new ArrayList();
233 ObjetoDemanda atributoDemanda = new AtributoDemandaAtbdem();
234
235 try {
236 StringBuilder query = new StringBuilder("select atributoDemanda from AtributoDemandaAtbdem as atributoDemanda").append(" where atributoDemanda.indAtivoAtbdem = 'S'").append(" order by atributoDemanda.seqApresTelaCampoAtbdem asc");
237 Query q = this.getSession().createQuery(query.toString());
238
239 retorno = q.list();
240
241 } catch (HibernateException e) {
242 this.logger.error(e);
243 throw new ECARException("erro.hibernateException");
244 }
245 return retorno;
246 }
247
248
249
250
251
252
253
254
255 public List getAtributosDemandaAtivosPorGrupo(SisGrupoAtributoSga sisGrupoAtributoSga) throws ECARException {
256 List retorno = new ArrayList();
257 ObjetoDemanda atributoDemanda = new AtributoDemandaAtbdem();
258
259 try {
260 StringBuilder query = new StringBuilder("select atributoDemanda from AtributoDemandaAtbdem as atributoDemanda").append(" where atributoDemanda.indAtivoAtbdem = 'S'").append(" and atributoDemanda.sisGrupoAtributoSga = '").append(sisGrupoAtributoSga.getCodSga() + "'").append(" order by atributoDemanda.seqApresTelaCampoAtbdem asc");
261
262 Query q = this.getSession().createQuery(query.toString());
263
264 retorno = q.list();
265
266 } catch (HibernateException e) {
267 this.logger.error(e);
268 throw new ECARException("erro.hibernateException");
269 }
270 return retorno;
271 }
272
273
274
275
276
277
278
279 public void validarNomeAtributoDemanda(AtributoDemandaAtbdem atributoDemandaAtbdem) throws ECARException {
280 if (!atributoDemandaAtbdem.iGetNome().equals("codRegd") && !atributoDemandaAtbdem.iGetNome().equals("dataLimiteRegd") && !atributoDemandaAtbdem.iGetNome().equals("descricaoRegd") && !atributoDemandaAtbdem.iGetNome().equals("observacaoRegd") && !atributoDemandaAtbdem.iGetNome().equals("numeroDocOrigemRegd") && !atributoDemandaAtbdem.iGetNome().equals("dataSolicitacaoRegd") && !atributoDemandaAtbdem.iGetNome().equals("dataInclusaoRegd") && !atributoDemandaAtbdem.iGetNome().equals("indAtivoRegd") && !atributoDemandaAtbdem.iGetNome().equals("nomeSolicitanteRegd") && !atributoDemandaAtbdem.iGetNome().equals("dataSituacaoRegd") && !atributoDemandaAtbdem.iGetNome().equals("prioridadePrior") && !atributoDemandaAtbdem.iGetNome().equals("sitDemandaSitd") && !atributoDemandaAtbdem.iGetNome().equals("usuarioUsuByCodUsuInclusaoRegd") && !atributoDemandaAtbdem.iGetNome().equals("entidadeOrgaoDemandaEntorgds") && !atributoDemandaAtbdem.iGetNome().equals("localDemandaLdems") && !atributoDemandaAtbdem.iGetNome().equals("regApontamentoRegdas") && !atributoDemandaAtbdem.iGetNome().equals("itemRegdemandaIregds") && !atributoDemandaAtbdem.iGetNome().equals("demAtributoDemas") && !atributoDemandaAtbdem.iGetNome().equals("regDemandaRegds") && !atributoDemandaAtbdem.iGetNome().equals("regDemandaRegd") && !atributoDemandaAtbdem.iGetNome().equals("entidadeDemandaEntds") && !atributoDemandaAtbdem.iGetNome().equals("indRestritivo")) {
281
282 throw new ECARException("atributoDemanda.validacao.nomeAtributoDemandaInvalido");
283
284 }
285 }
286 }