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.HibernateException;
12 import org.hibernate.ObjectNotFoundException;
13 import org.hibernate.Query;
14
15 import comum.database.Dao;
16
17 import ecar.exception.ECARException;
18 import ecar.pojo.Cor;
19 import ecar.pojo.ItemEstrtIndResulCorIettrcor;
20 import ecar.pojo.ItemEstrtIndResulIettr;
21 import ecar.pojo.RegApontamentoRegda;
22
23
24
25
26
27
28
29 public class ItemEstrtIndResulCorIettrcorDAO extends Dao {
30
31
32
33
34 public ItemEstrtIndResulCorIettrcorDAO(HttpServletRequest request) {
35 super();
36 this.request = request;
37 }
38
39
40
41
42
43
44
45 public ItemEstrtIndResulCorIettrcor buscar(Cor cor, ItemEstrtIndResulIettr iettr) throws ECARException {
46
47 ItemEstrtIndResulCorIettrcor iettrCor = new ItemEstrtIndResulCorIettrcor();
48 try {
49 if (iettr.getCodIettir() != null) {
50 Query q = session.createQuery("from ItemEstrtIndResulCorIettrcor iettrCor where " + " iettrCor.id.codCor = :cor" + " and iettrCor.id.codIettir = :codIettr");
51 q.setLong("cor", cor.getCodCor().longValue());
52 q.setLong("codIettr", iettr.getCodIettir().longValue());
53
54 List lista = q.list();
55
56 if (lista.size() != 0)
57 iettrCor = (ItemEstrtIndResulCorIettrcor) lista.iterator().next();
58 }
59 } catch (ObjectNotFoundException e) {
60 this.logger.error(e);
61 throw new ECARException("erro.objectNotFound");
62 } catch (HibernateException e) {
63 this.logger.error(e);
64 throw new ECARException("erro.hibernateException");
65 } catch (Exception e) {
66 this.logger.error(e);
67 throw new ECARException("erro.exception");
68 }
69
70 return iettrCor;
71 }
72
73
74
75
76
77
78
79
80
81 public List listarIettrcorAtivosPorIettrOrderByValorPrimEmailIettrcor(ItemEstrtIndResulIettr iettr) throws ECARException {
82 List list = null;
83
84 try {
85 Query query = session.createQuery("from ItemEstrtIndResulCorIettrcor " + "where indAtivoEnvioEmailIettrcor = :ativo " + "and itemEstrtIndResulIettr = :iettr " + "order by valorPrimEmailIettrcor asc ");
86
87 query.setString("ativo", "S");
88 query.setParameter("iettr", iettr);
89
90 list = query.list();
91 } catch (HibernateException e) {
92 this.logger.error(e);
93 throw new ECARException("erro.hibernateException");
94 }
95
96 return list;
97 }
98
99
100
101
102
103
104
105
106 public List listarCoresIettr(ItemEstrtIndResulIettr iettr) throws ECARException {
107 List list = new ArrayList();
108
109 if (iettr != null && iettr.getItemEstrtIndResulCorIettrcores() != null) {
110
111 List itemEstrtIndResulCorIettrcores = new ArrayList(iettr.getItemEstrtIndResulCorIettrcores());
112
113 Collections.sort(itemEstrtIndResulCorIettrcores, new Comparator() {
114 public int compare(Object o1, Object o2) {
115 return ((ItemEstrtIndResulCorIettrcor) o1).getSequenciaIettrcor().compareTo(((ItemEstrtIndResulCorIettrcor) o2).getSequenciaIettrcor());
116 }
117 });
118
119 Iterator iIettrcores = itemEstrtIndResulCorIettrcores.iterator();
120 while (iIettrcores.hasNext()) {
121 ItemEstrtIndResulCorIettrcor iettrcor = (ItemEstrtIndResulCorIettrcor) iIettrcores.next();
122 list.add(iettrcor.getCor());
123 }
124 }
125
126 Cor corFiltro = new Cor();
127 corFiltro.setIndIndicadoresFisicosCor("S");
128
129 Iterator itCores = new CorDao(request).pesquisar(corFiltro, new String[] { "ordemCor", "asc" }).iterator();
130
131 while (itCores.hasNext()) {
132 Cor cor = (Cor) itCores.next();
133 if (!list.contains(cor)) {
134 list.add(cor);
135 }
136 }
137
138 return list;
139 }
140 }