1 | package org.medias.eccad.metier; |
---|
2 | |
---|
3 | |
---|
4 | import java.util.ArrayList; |
---|
5 | import java.util.LinkedList; |
---|
6 | import java.util.List; |
---|
7 | |
---|
8 | import javax.faces.model.SelectItem; |
---|
9 | |
---|
10 | |
---|
11 | import org.medias.eccad.helpers.LoggerPerso; |
---|
12 | import org.medias.eccad.helpers.SpringBeanFactory; |
---|
13 | import org.medias.eccad.metier.traducteur.TraducteurVisu; |
---|
14 | import org.medias.eccad.modele.*; |
---|
15 | import org.medias.eccad.persistance.ServicePersistance; |
---|
16 | import org.medias.eccad.persistance.dao.ColorTabDAO; |
---|
17 | import org.medias.eccad.persistance.dao.GrilleDAO; |
---|
18 | import org.medias.eccad.persistance.exception.PersistanceException; |
---|
19 | import org.springframework.beans.factory.xml.XmlBeanFactory; |
---|
20 | |
---|
21 | /** |
---|
22 | * Attention cette classe a été créée à l'origine pour faire des tests. Cependant par manque de temps elle s'est vue attribuer un role de plus en plus important... |
---|
23 | * Il faudrait la scinder en petit module indépendant. |
---|
24 | * @author pinaud |
---|
25 | * |
---|
26 | */ |
---|
27 | public class ServiceMetier { |
---|
28 | private ServicePersistance spm; |
---|
29 | |
---|
30 | private XmlBeanFactory xmlbean; |
---|
31 | |
---|
32 | public ServiceMetier() { |
---|
33 | spm = new ServicePersistance(); |
---|
34 | xmlbean = SpringBeanFactory.getXmlFactory(); |
---|
35 | //initMap(); |
---|
36 | } |
---|
37 | |
---|
38 | |
---|
39 | |
---|
40 | |
---|
41 | /** |
---|
42 | * Interrogation de la couche de persistance |
---|
43 | */ |
---|
44 | |
---|
45 | /** |
---|
46 | * |
---|
47 | * @return |
---|
48 | */ |
---|
49 | |
---|
50 | public List<SelectItem> getListCatParametre() { |
---|
51 | // TODO : ici mettre un traducteur plutot ^^LoggerPerso.log(ServiceMetier.class, LoggerPerso.DEBUG, "youhou!!"); |
---|
52 | List<SelectItem> liste_catParam = new ArrayList<SelectItem>(); |
---|
53 | LoggerPerso.log(ServiceMetier.class, LoggerPerso.DEBUG, "youhou!!"); |
---|
54 | List<CatParametre> tempo = spm.getListcatParametre(); |
---|
55 | if (tempo == null) { |
---|
56 | LoggerPerso.log(ServiceMetier.class, LoggerPerso.WARN, "liste de Catparametre vide"); |
---|
57 | return new ArrayList<SelectItem>(); |
---|
58 | } |
---|
59 | |
---|
60 | for (CatParametre catParametreDAO : tempo) { |
---|
61 | |
---|
62 | LoggerPerso.log(ServiceMetier.class, LoggerPerso.DEBUG, "youhou!!"); |
---|
63 | liste_catParam.add(new SelectItem(new Long(catParametreDAO.getIdentifiant()), catParametreDAO.getNom())); |
---|
64 | } |
---|
65 | |
---|
66 | return liste_catParam; |
---|
67 | } |
---|
68 | |
---|
69 | public List<SelectItem> getListParametre() { |
---|
70 | // TODO : ici mettre un traducteur plutot ^^ |
---|
71 | List<SelectItem> liste_param = new ArrayList<SelectItem>(); |
---|
72 | List<Parametre> tempo = spm.getListParametre(); |
---|
73 | if (tempo == null) { |
---|
74 | LoggerPerso.log(ServiceMetier.class, LoggerPerso.WARN, "liste de parametre vide"); |
---|
75 | return new ArrayList<SelectItem>(); |
---|
76 | } |
---|
77 | |
---|
78 | for (Parametre parametreDAO : tempo) { |
---|
79 | liste_param.add(new SelectItem(new Long(parametreDAO.getIdentifiant()), parametreDAO.getNom())); |
---|
80 | } |
---|
81 | |
---|
82 | return liste_param; |
---|
83 | } |
---|
84 | |
---|
85 | public List<SelectItem> getListParamByCatParam(int catParam) { |
---|
86 | // TODO : ici mettre un traducteur plutot ^^ |
---|
87 | List<SelectItem> liste_param = new ArrayList<SelectItem>(); |
---|
88 | List<Parametre> tempo = spm.getListParamByCatParam(catParam); |
---|
89 | if (tempo == null) { |
---|
90 | LoggerPerso.log(ServiceMetier.class, LoggerPerso.WARN, "liste de parametre vide"); |
---|
91 | return new ArrayList<SelectItem>(); |
---|
92 | } |
---|
93 | |
---|
94 | for (Parametre parametreDAO : tempo) { |
---|
95 | |
---|
96 | LoggerPerso.log(ServiceMetier.class, LoggerPerso.DEBUG, "----------------------->id nom"+parametreDAO.getIdentifiant()+" "+ parametreDAO.getNom()); |
---|
97 | liste_param.add(new SelectItem(new Long(parametreDAO.getIdentifiant()), parametreDAO.getNom())); |
---|
98 | } |
---|
99 | |
---|
100 | return liste_param; |
---|
101 | } |
---|
102 | |
---|
103 | public List<SelectItem> getListProduit(int id_param) { |
---|
104 | List<SelectItem> liste_produit = new ArrayList<SelectItem>(); |
---|
105 | List<Produit> tempo = spm.getListProductByParam(id_param); |
---|
106 | if (tempo == null) { |
---|
107 | LoggerPerso.log(ServiceMetier.class, LoggerPerso.WARN, "liste de produit vide"); |
---|
108 | return new ArrayList<SelectItem>(); |
---|
109 | } |
---|
110 | |
---|
111 | for (Produit produit : tempo) { |
---|
112 | liste_produit.add(new SelectItem(new Long(produit.getIdentifiant()), produit.getNom())); |
---|
113 | } |
---|
114 | |
---|
115 | return liste_produit; |
---|
116 | } |
---|
117 | |
---|
118 | /** |
---|
119 | * Traduit la liste de grille reçue en liste d'item |
---|
120 | * @param id_produit identifiant du produit |
---|
121 | * @param date_debut date de début de la recherche |
---|
122 | * @param date_fin date de fin de la recherche |
---|
123 | * @return une liste d'item de sélection de type oid - legende de la grille |
---|
124 | */ |
---|
125 | public List<SelectItem> getListGrille(long id_produit,long id_parametre, String date_debut, String date_fin) { |
---|
126 | Produit produit = spm.getProduitByID(id_produit); |
---|
127 | List<Grille> liste_grille = spm.getListGrille(id_produit, id_parametre, date_debut, date_fin); |
---|
128 | Visualisation visu = spm.getVisuByProduit(produit.getType()); |
---|
129 | |
---|
130 | TraducteurVisu traducteur = (TraducteurVisu) xmlbean.getBean(visu.getTraducteur()); |
---|
131 | |
---|
132 | if (liste_grille == null) { |
---|
133 | LoggerPerso.log(ServiceMetier.class, LoggerPerso.WARN, "liste de produit vide"); |
---|
134 | return new ArrayList<SelectItem>(); |
---|
135 | } |
---|
136 | |
---|
137 | return traducteur.getListGrille(liste_grille); |
---|
138 | } |
---|
139 | |
---|
140 | public List<SelectItem> getListGrille(long id_produit, String date_debut, String date_fin) { |
---|
141 | Produit produit = spm.getProduitByID(id_produit); |
---|
142 | List<Grille> liste_grille = spm.getListGrille(id_produit, date_debut, date_fin); |
---|
143 | Visualisation visu = spm.getVisuByProduit(produit.getType()); |
---|
144 | |
---|
145 | TraducteurVisu traducteur = (TraducteurVisu) xmlbean.getBean(visu.getTraducteur()); |
---|
146 | |
---|
147 | if (liste_grille == null) { |
---|
148 | LoggerPerso.log(ServiceMetier.class, LoggerPerso.WARN, "liste de produit vide"); |
---|
149 | return new ArrayList<SelectItem>(); |
---|
150 | } |
---|
151 | |
---|
152 | return traducteur.getListGrille(liste_grille); |
---|
153 | } |
---|
154 | |
---|
155 | public List<SelectItem> getListMappingColor(long oid) { |
---|
156 | ColorTabDAO colortabDAO = (ColorTabDAO) xmlbean.getBean("colorTabDAO"); |
---|
157 | List<ColorMap> liste_color = null; |
---|
158 | try { |
---|
159 | liste_color = colortabDAO.getListColorTabByGrille(oid); |
---|
160 | } |
---|
161 | catch (PersistanceException e) { |
---|
162 | e.printStackTrace(); |
---|
163 | liste_color = null; |
---|
164 | } |
---|
165 | |
---|
166 | if (liste_color == null) { |
---|
167 | LoggerPerso.log(ServiceMetier.class, LoggerPerso.WARN, "pas de colormap pour la grille :/"); |
---|
168 | return new ArrayList<SelectItem>(); |
---|
169 | } |
---|
170 | |
---|
171 | List<SelectItem> liste_select = new LinkedList<SelectItem>(); |
---|
172 | for (ColorMap colormap : liste_color) { |
---|
173 | liste_select.add(new SelectItem(new Long(colormap.getIdentifiant()), colormap.getNom())); |
---|
174 | } |
---|
175 | |
---|
176 | return liste_select; |
---|
177 | } |
---|
178 | |
---|
179 | public List<SelectItem> getListColorDynamique() { |
---|
180 | ColorTabDAO colortabDAO = (ColorTabDAO) xmlbean.getBean("colorTabDAO"); |
---|
181 | List<ColorMap> liste_color = null; |
---|
182 | try { |
---|
183 | liste_color = colortabDAO.getListColorMapDynamique(); |
---|
184 | } |
---|
185 | catch (PersistanceException e) { |
---|
186 | e.printStackTrace(); |
---|
187 | liste_color = null; |
---|
188 | } |
---|
189 | |
---|
190 | if (liste_color == null) { |
---|
191 | LoggerPerso.log(ServiceMetier.class, LoggerPerso.WARN, "pas de colormap pour la grille :/"); |
---|
192 | return new ArrayList<SelectItem>(); |
---|
193 | } |
---|
194 | |
---|
195 | List<SelectItem> liste_select = new LinkedList<SelectItem>(); |
---|
196 | for (ColorMap colormap : liste_color) { |
---|
197 | liste_select.add(new SelectItem(new Long(colormap.getIdentifiant()), colormap.getNom())); |
---|
198 | } |
---|
199 | |
---|
200 | return liste_select; |
---|
201 | } |
---|
202 | |
---|
203 | public List<SelectItem> getListColorDynamique(boolean lineaire) { |
---|
204 | if (!lineaire) |
---|
205 | return getListColorDynamique(); |
---|
206 | |
---|
207 | ColorTabDAO colortabDAO = (ColorTabDAO) xmlbean.getBean("colorTabDAO"); |
---|
208 | List<ColorMap> liste_color = null; |
---|
209 | try { |
---|
210 | liste_color = colortabDAO.getListColorMapDynamique(); |
---|
211 | } |
---|
212 | catch (PersistanceException e) { |
---|
213 | e.printStackTrace(); |
---|
214 | liste_color = null; |
---|
215 | } |
---|
216 | |
---|
217 | if (liste_color == null) { |
---|
218 | LoggerPerso.log(ServiceMetier.class, LoggerPerso.WARN, "pas de colormap pour la grille :/"); |
---|
219 | return new ArrayList<SelectItem>(); |
---|
220 | } |
---|
221 | |
---|
222 | List<SelectItem> liste_select = new LinkedList<SelectItem>(); |
---|
223 | for (ColorMap colormap : liste_color) { |
---|
224 | if (colormap.getNom().equalsIgnoreCase("logarithm")) |
---|
225 | liste_select.add(new SelectItem(new Long(colormap.getIdentifiant()), colormap.getNom())); |
---|
226 | } |
---|
227 | |
---|
228 | return liste_select; |
---|
229 | } |
---|
230 | |
---|
231 | /** |
---|
232 | * |
---|
233 | * @param id_produit |
---|
234 | * @return |
---|
235 | */ |
---|
236 | public Produit getProduitById(int id_produit) { |
---|
237 | Produit produit = spm.getProduitByID(id_produit); |
---|
238 | LoggerPerso.log(ServiceMetier.class, LoggerPerso.DEBUG, "getProduitById::nom::"+ produit.getNom() + "::date::" + produit.getBeginDate()); |
---|
239 | return produit; |
---|
240 | } |
---|
241 | |
---|
242 | /*public Produit getProduitById(long id_produit) { |
---|
243 | Produit produit = spm.getProduitByID(id_produit); |
---|
244 | LoggerPerso.log(ServiceMetier.class, LoggerPerso.DEBUG, "getProduitById::nom::"+ produit.getNom() + "::date::" + produit.getBeginDate()); |
---|
245 | return produit; |
---|
246 | }*/ |
---|
247 | |
---|
248 | public Grille getGrilleById(Long id_grille) { |
---|
249 | GrilleDAO grilleDAO = (GrilleDAO) xmlbean.getBean("grilleDAO"); |
---|
250 | Grille grille; |
---|
251 | try { |
---|
252 | grille = grilleDAO.getGrille(id_grille); |
---|
253 | } catch (PersistanceException e) { |
---|
254 | LoggerPerso.log(ServiceMetier.class, LoggerPerso.ERROR, "erreur getgrillebyid"); |
---|
255 | return null; |
---|
256 | } |
---|
257 | return grille; |
---|
258 | |
---|
259 | } |
---|
260 | |
---|
261 | /** |
---|
262 | * |
---|
263 | * @param id_param |
---|
264 | * @return |
---|
265 | */ |
---|
266 | public Parametre getParametreById(int id_param) { |
---|
267 | return spm.getParametreById(id_param); |
---|
268 | } |
---|
269 | |
---|
270 | public Visualisation getVisuByTypeProduct(String type_produit) { |
---|
271 | return spm.getVisuByProduit(type_produit); |
---|
272 | } |
---|
273 | } |
---|
274 | |
---|