1 | /** |
---|
2 | * Created on 24 Janvier. 2006 |
---|
3 | * @author |
---|
4 | */ |
---|
5 | |
---|
6 | package integration.insertion; |
---|
7 | |
---|
8 | import com.medias.Constantes; |
---|
9 | import com.medias.DateTime; |
---|
10 | import com.medias.database.objects.Adresse; |
---|
11 | import com.medias.database.objects.Bilan; |
---|
12 | import com.medias.database.objects.Capteur; |
---|
13 | import com.medias.database.objects.CategorieParam; |
---|
14 | import com.medias.database.objects.Commentaire; |
---|
15 | import com.medias.database.objects.DeltaMesure; |
---|
16 | import com.medias.database.objects.Fabriquant; |
---|
17 | import com.medias.database.objects.Fichier; |
---|
18 | import com.medias.database.objects.Flag; |
---|
19 | import com.medias.database.objects.Jeu; |
---|
20 | import com.medias.database.objects.Localisation; |
---|
21 | import com.medias.database.objects.Mesure; |
---|
22 | import com.medias.database.objects.Organisme; |
---|
23 | import com.medias.database.objects.Parametre; |
---|
24 | import com.medias.database.objects.Personne; |
---|
25 | import com.medias.database.objects.Plateforme; |
---|
26 | import com.medias.database.objects.RequeteNbvalsJeu; |
---|
27 | import com.medias.database.objects.RequetePlatLoc; |
---|
28 | import com.medias.database.objects.Sequence; |
---|
29 | import com.medias.database.objects.TypeCapteur; |
---|
30 | import com.medias.database.objects.TypePlateforme; |
---|
31 | import com.medias.database.objects.Unite; |
---|
32 | import com.medias.database.objects.Valeur; |
---|
33 | import integration.utils.CommunicationBD; |
---|
34 | import integration.utils.Nombre; |
---|
35 | import integration.utils.Statiques; |
---|
36 | |
---|
37 | import java.util.ArrayList; |
---|
38 | import java.util.Date; |
---|
39 | import java.util.HashSet; |
---|
40 | import java.util.List; |
---|
41 | |
---|
42 | /** |
---|
43 | * Classe permettant d'inserer les jeux de données |
---|
44 | */ |
---|
45 | public class Insertion { |
---|
46 | /** |
---|
47 | * Insertion de la valeur |
---|
48 | */ |
---|
49 | public int insererValeur(Valeur valeur) throws Exception {//,int flagValiditeId |
---|
50 | // on teste si le flag de la valeur est different de null : on l'insere |
---|
51 | if (valeur.getFlagByValeurFlag() != null) { |
---|
52 | int flagValeurId = insererFlag(valeur.getFlagByValeurFlag(),0); |
---|
53 | valeur.getFlagByValeurFlag().setFlagId(flagValeurId); |
---|
54 | } |
---|
55 | // on teste si le flag de la validité est different de null : on l'insere |
---|
56 | if (valeur.getFlagByValiditeFlag() != null) { |
---|
57 | flagValidId = insererFlag(valeur.getFlagByValiditeFlag(),0);//flagValiditeId); |
---|
58 | valeur.getFlagByValiditeFlag().setFlagId(flagValidId); |
---|
59 | } |
---|
60 | |
---|
61 | CommunicationBD.save(valeur); |
---|
62 | return valeur.getValeurId(); |
---|
63 | } |
---|
64 | |
---|
65 | /** |
---|
66 | * Insertion de la mesure |
---|
67 | */ |
---|
68 | public int insererMesure(Mesure mesure, ArrayList<Localisation> listeLocs) throws Exception {//,int flagId |
---|
69 | insererLoc(mesure.getLocalisation(),listeLocs, mesure.getPlateforme().getTypePlateforme().getTypePlateformeNom());//,flagId); |
---|
70 | if (mesure.getDeltaMesure() != null) { |
---|
71 | insererDelta(mesure.getDeltaMesure()); |
---|
72 | } |
---|
73 | CommunicationBD.save(mesure); |
---|
74 | return mesure.getMesureId(); |
---|
75 | } |
---|
76 | |
---|
77 | /** |
---|
78 | * Insertion des flags |
---|
79 | */ |
---|
80 | public int insererFlag(Flag flag, int flagPrecId) throws Exception { |
---|
81 | int flagId = 0; |
---|
82 | if (flagPrecId == 0) { |
---|
83 | Flag flagExistant = (Flag) CommunicationBD.getObjectByColonne(Flag.class, "flagNom", flag.getFlagNom()); |
---|
84 | // si Le flag n'existe pas : on l'insére |
---|
85 | if (flagExistant == null) { |
---|
86 | CommunicationBD.save(flag); |
---|
87 | flagId = flag.getFlagId(); |
---|
88 | } |
---|
89 | // sinon le flag existe : on récupére l'ID |
---|
90 | else { |
---|
91 | flagId = flagExistant.getFlagId(); |
---|
92 | flag.setFlagId(flagId); |
---|
93 | } |
---|
94 | } else { |
---|
95 | flagId = flagPrecId; |
---|
96 | } |
---|
97 | return flagId; |
---|
98 | } |
---|
99 | |
---|
100 | /** |
---|
101 | * Insertion du commentaire |
---|
102 | */ |
---|
103 | public int insererCommentaire(Commentaire commentaire) throws Exception { |
---|
104 | List<?> commentaireExistant = CommunicationBD.getList("select c.commentaireId from Commentaire c where commentaire_txt = '" |
---|
105 | +commentaire.getCommentaireTxt().replaceAll("'", "''")+"'"); |
---|
106 | // Le commentaire existe : on récupére l'ID |
---|
107 | if (commentaireExistant.size() != 0) { |
---|
108 | commentaire.setCommentaireId(((Integer)commentaireExistant.get(0)).intValue()); |
---|
109 | } |
---|
110 | CommunicationBD.save(commentaire); |
---|
111 | int id = commentaire.getCommentaireId(); |
---|
112 | return id; |
---|
113 | } |
---|
114 | |
---|
115 | /** |
---|
116 | * Insertion de l'adresse |
---|
117 | */ |
---|
118 | public int insererAdresse(Adresse adresse) throws Exception { |
---|
119 | List<?> adresseExistant = CommunicationBD.getList("select a.adresseId from Adresse a " + |
---|
120 | "where adresse_rue = '"+adresse.getAdresseRue().replaceAll("'", "''")+"' " + |
---|
121 | "and adresse_zip = '"+adresse.getAdresseZip().replaceAll("'", "''")+"' " + |
---|
122 | "and adresse_ville = '"+adresse.getAdresseVille().replaceAll("'", "''")+"' " + |
---|
123 | "and adresse_pays = '"+adresse.getAdressePays().replaceAll("'", "''")+"'"); |
---|
124 | // si L'adresse existe : on récupére l'ID |
---|
125 | if (adresseExistant.size() != 0) { |
---|
126 | adresse.setAdresseId(((Integer)adresseExistant.get(0)).intValue()); |
---|
127 | } |
---|
128 | CommunicationBD.save(adresse); |
---|
129 | int adresseId = adresse.getAdresseId(); |
---|
130 | return adresseId; |
---|
131 | } |
---|
132 | |
---|
133 | /** |
---|
134 | * Insertion de l'organisme |
---|
135 | */ |
---|
136 | public int insererOrganisme(Organisme organisme) throws Exception { |
---|
137 | // l'adresse de l'organisme n'est pas nul : on l'insere |
---|
138 | insererAdresse(organisme.getAdresse()); |
---|
139 | // si le commentaire de l'organisme n'est pas null : on l'insere |
---|
140 | if (organisme.getCommentaire() != null) { |
---|
141 | insererCommentaire(organisme.getCommentaire()); |
---|
142 | } |
---|
143 | // on verifie si l'organisme n'existe pas dejé dans la base |
---|
144 | List<?> organismeExistant = CommunicationBD.getList("select o.organismeId from Organisme o " + |
---|
145 | "where organisme_nom = '"+organisme.getOrganismeNom().replaceAll("'", "''")+"'"); |
---|
146 | // si l'organisme existe : on récupére l'ID |
---|
147 | if (organismeExistant.size() != 0) { |
---|
148 | organisme.setOrganismeId(((Integer)organismeExistant.get(0)).intValue()); |
---|
149 | } |
---|
150 | CommunicationBD.save(organisme); |
---|
151 | int organismeId = organisme.getOrganismeId(); |
---|
152 | return organismeId; |
---|
153 | } |
---|
154 | |
---|
155 | /** |
---|
156 | * Insertion de la personne |
---|
157 | */ |
---|
158 | public int insererPersonne(Personne personne) throws Exception { |
---|
159 | CommunicationBD.open(); |
---|
160 | insererOrganisme(personne.getOrganisme()); |
---|
161 | if (personne.getCommentaire() != null) { |
---|
162 | insererCommentaire(personne.getCommentaire()); |
---|
163 | } |
---|
164 | List<?> personneExistant = CommunicationBD.getList("select p.personneId from Personne p where personne_mail = '" |
---|
165 | +personne.getPersonneMail().replaceAll("'", "''")+"'"); |
---|
166 | // si la personne existe : on récupére l'ID |
---|
167 | if (personneExistant.size() != 0) { |
---|
168 | personne.setPersonneId(((Integer)personneExistant.get(0)).intValue()); |
---|
169 | } |
---|
170 | CommunicationBD.save(personne); |
---|
171 | int personneId = personne.getPersonneId(); |
---|
172 | CommunicationBD.close(); |
---|
173 | return personneId; |
---|
174 | } |
---|
175 | |
---|
176 | /** |
---|
177 | * Insertion du jeu |
---|
178 | */ |
---|
179 | public int insererJeu(Jeu jeu) throws Exception { |
---|
180 | CommunicationBD.open(); |
---|
181 | // si le commentaire du jeu n'est pas null : on l'insere |
---|
182 | if (jeu.getCommentaire() != null) { |
---|
183 | insererCommentaire(jeu.getCommentaire()); |
---|
184 | } |
---|
185 | // inserer l'organisme du jeu |
---|
186 | insererOrganisme(jeu.getOrganisme()); |
---|
187 | // On vérifie que le jeu n'existe pas déjé dans la base |
---|
188 | List<?> jeuExistant = CommunicationBD.getList("select j.jeuId, j.jeuAltmax, " + |
---|
189 | "j.jeuAltmin, j.jeuDated, j.jeuDatef, j.jeuLatmax, j.jeuLatmin, " + |
---|
190 | "j.jeuLonmax, j.jeuLonmin from Jeu j where jeu_nom = '"+jeu.getJeuNom().replaceAll("'", "''")+"'"); |
---|
191 | |
---|
192 | // si le jeu existe : on récupére l'ID |
---|
193 | if (jeuExistant.size() != 0) { |
---|
194 | Object[] resultats = (Object[])jeuExistant.get(0); |
---|
195 | jeu.setJeuId(((Integer)resultats[0]).intValue()); |
---|
196 | jeu.setJeuAltmax((Integer)resultats[1]); |
---|
197 | jeu.setJeuAltmin((Integer)resultats[2]); |
---|
198 | jeu.setJeuDated((Date)resultats[3]); |
---|
199 | jeu.setJeuDatef((Date)resultats[4]); |
---|
200 | jeu.setJeuLatmax((Integer)resultats[5]); |
---|
201 | jeu.setJeuLatmin((Integer)resultats[6]); |
---|
202 | jeu.setJeuLonmax((Integer)resultats[7]); |
---|
203 | jeu.setJeuLonmin((Integer)resultats[8]); |
---|
204 | } |
---|
205 | CommunicationBD.save(jeu); |
---|
206 | int jeuId = jeu.getJeuId(); |
---|
207 | CommunicationBD.close(); |
---|
208 | return jeuId; |
---|
209 | } |
---|
210 | |
---|
211 | /** |
---|
212 | * Insertion de la categorie (parametre) |
---|
213 | */ |
---|
214 | public int insererCategorieParam(CategorieParam categorieParam)throws Exception { |
---|
215 | List<?> categorieParamExistant = CommunicationBD.getList("select c.categorieParamId from CategorieParam c where categorie_param_nom = '" |
---|
216 | +categorieParam.getCategorieParamNom().replaceAll("'", "''")+"'"); |
---|
217 | // La categorie du parametre existe : on récupére l'ID |
---|
218 | if (categorieParamExistant.size() != 0) { |
---|
219 | categorieParam.setCategorieParamId(((Integer)categorieParamExistant.get(0)).intValue()); |
---|
220 | } |
---|
221 | CommunicationBD.save(categorieParam); |
---|
222 | int catId = categorieParam.getCategorieParamId(); |
---|
223 | return catId; |
---|
224 | } |
---|
225 | |
---|
226 | /** |
---|
227 | * Insertion de l'unite (parametre) |
---|
228 | */ |
---|
229 | public int insererUniteParametre(Unite unite) throws Exception { |
---|
230 | List<?> uniteExistant = CommunicationBD.getList("select u.uniteId from Unite u where unite_code = '"+unite.getUniteCode().replaceAll("'", "''")+"'"); |
---|
231 | // si l'unite existe : on récupére l'ID |
---|
232 | if (uniteExistant.size() != 0) { |
---|
233 | unite.setUniteId(((Integer)uniteExistant.get(0)).intValue()); |
---|
234 | } |
---|
235 | CommunicationBD.save(unite); |
---|
236 | int uniteId = unite.getUniteId(); |
---|
237 | return uniteId; |
---|
238 | } |
---|
239 | |
---|
240 | /** |
---|
241 | * Insertion du parametre |
---|
242 | */ |
---|
243 | public int insererParametre(Parametre parametre) throws Exception { |
---|
244 | CommunicationBD.open(); |
---|
245 | // le commentaire n'est pas null : on l'insere |
---|
246 | if (parametre.getCommentaire() != null) { |
---|
247 | insererCommentaire(parametre.getCommentaire()); |
---|
248 | } |
---|
249 | insererCategorieParam(parametre.getCategorieParam()); |
---|
250 | insererUniteParametre(parametre.getUnite()); |
---|
251 | List<?> parametreExistant = CommunicationBD.getList("select p.parametreId from Parametre p " + |
---|
252 | "where parametre_code = '"+parametre.getParametreCode().replaceAll("'", "''")+"'"); |
---|
253 | // Le parametre existe : on récupére l'ID et les jeux associés |
---|
254 | if (parametreExistant.size() != 0) { |
---|
255 | parametre.setParametreId(((Integer)parametreExistant.get(0)).intValue()); |
---|
256 | List<?> jeusParam = CommunicationBD.getList("select p.jeus from Parametre p where p.parametreId = "+parametre.getParametreId()); |
---|
257 | for (int numJeu=0; numJeu < jeusParam.size(); numJeu++) { |
---|
258 | parametre.getJeus().add((Jeu)jeusParam.get(numJeu)); |
---|
259 | } |
---|
260 | } |
---|
261 | CommunicationBD.save(parametre); |
---|
262 | int parametreId = parametre.getParametreId(); |
---|
263 | CommunicationBD.close(); |
---|
264 | return parametreId; |
---|
265 | } |
---|
266 | |
---|
267 | /** |
---|
268 | * Insertion du fabriquant du capteur |
---|
269 | */ |
---|
270 | public int insererFabriquant(Fabriquant fabriquant) throws Exception { |
---|
271 | List<?> fabriquantExistant = CommunicationBD.getList("select f.fabriquantId from Fabriquant f " + |
---|
272 | "where fabriquant_nom = '"+fabriquant.getFabriquantNom().replaceAll("'", "''")+"'"); |
---|
273 | // Le fabriquant existe : on récupére l'ID |
---|
274 | if (fabriquantExistant.size() != 0) { |
---|
275 | fabriquant.setFabriquantId(((Integer)fabriquantExistant.get(0)).intValue()); |
---|
276 | } |
---|
277 | CommunicationBD.save(fabriquant); |
---|
278 | int fabriquantId = fabriquant.getFabriquantId(); |
---|
279 | return fabriquantId; |
---|
280 | } |
---|
281 | |
---|
282 | /** |
---|
283 | * Insertion du type de capteur |
---|
284 | */ |
---|
285 | public int insererTypeCapteur(TypeCapteur typeCapteur) throws Exception { |
---|
286 | // si le commentaire n est pas null : on insere le commentaire du type du capteur |
---|
287 | if (typeCapteur.getCommentaire() != null) { |
---|
288 | insererCommentaire(typeCapteur.getCommentaire()); |
---|
289 | } |
---|
290 | List<?> typeCapteurExistant = CommunicationBD.getList("select t.typeCapteurId from TypeCapteur t " + |
---|
291 | "where type_capteur_nom = '"+typeCapteur.getTypeCapteurNom().replaceAll("'", "''")+"'"); |
---|
292 | // Le typeCapteur existe : on récupére l'ID |
---|
293 | if (typeCapteurExistant.size() != 0) { |
---|
294 | typeCapteur.setTypeCapteurId(((Integer)typeCapteurExistant.get(0)).intValue()); |
---|
295 | } |
---|
296 | CommunicationBD.save(typeCapteur); |
---|
297 | int typeCapteurId = typeCapteur.getTypeCapteurId(); |
---|
298 | return typeCapteurId; |
---|
299 | } |
---|
300 | |
---|
301 | /** |
---|
302 | * Insertion du capteur |
---|
303 | */ |
---|
304 | public int insererCapteur(Capteur capteur, ArrayList<Parametre> parametres) throws Exception { |
---|
305 | CommunicationBD.open(); |
---|
306 | // On parcourt la liste des paramétres du capteur |
---|
307 | for (Parametre paramCapt : capteur.getParametres()) { |
---|
308 | // On parcourt la liste des paramétres du jeu |
---|
309 | for (Parametre parametre : parametres) { |
---|
310 | // On compléte les identifiants des paramétres |
---|
311 | if (parametre.getParametreCode().equals(paramCapt.getParametreCode())) { |
---|
312 | paramCapt.setParametreId(parametre.getParametreId()); |
---|
313 | break; |
---|
314 | } |
---|
315 | } |
---|
316 | } |
---|
317 | // insertion du fabriquant du capteur |
---|
318 | insererFabriquant(capteur.getFabriquant()); |
---|
319 | // insertion du type du capteur |
---|
320 | insererTypeCapteur(capteur.getTypeCapteur()); |
---|
321 | // insertion du commentaire s'il existe |
---|
322 | if (capteur.getCommentaire() != null) { |
---|
323 | insererCommentaire(capteur.getCommentaire()); |
---|
324 | } |
---|
325 | // On vérifie si le capteur existe déjé |
---|
326 | List<?> capteursExistants = CommunicationBD.getList("select c.capteurId from Capteur c " |
---|
327 | + "where capteur_modele = '" + capteur.getCapteurModele().replaceAll("'", "''")+"' " |
---|
328 | + "and capteur_numserie = '" + capteur.getCapteurNumserie().replaceAll("'", "''") + "' " |
---|
329 | + "and c.fabriquant.fabriquantNom = '"+capteur.getFabriquant().getFabriquantNom().replaceAll("'", "''")+"' " |
---|
330 | + "and c.typeCapteur.typeCapteurNom = '"+capteur.getTypeCapteur().getTypeCapteurNom().replaceAll("'", "''")+"'"); |
---|
331 | // si Le capteur existe : on récupére l'ID et les jeux/paramétres associés |
---|
332 | if (capteursExistants.size() != 0) { |
---|
333 | capteur.setCapteurId(((Integer)capteursExistants.get(0)).intValue()); |
---|
334 | List<?> jeusCapt = CommunicationBD.getList("select c.jeus from Capteur c where c.capteurId = "+capteur.getCapteurId()); |
---|
335 | for (int numJeu=0; numJeu < jeusCapt.size(); numJeu++) { |
---|
336 | capteur.getJeus().add((Jeu)jeusCapt.get(numJeu)); |
---|
337 | } |
---|
338 | List<?> paramsCapt = CommunicationBD.getList("select c.parametres from Capteur c where c.capteurId = "+capteur.getCapteurId()); |
---|
339 | Parametre paramCapt; |
---|
340 | boolean paramPresent; |
---|
341 | for (int numParam=0; numParam < paramsCapt.size(); numParam++) { |
---|
342 | paramCapt = (Parametre)paramsCapt.get(numParam); |
---|
343 | paramPresent = false; |
---|
344 | for (Parametre paramCapt2 : capteur.getParametres()) { |
---|
345 | if (paramCapt2.getParametreCode().equals(paramCapt.getParametreCode())){ |
---|
346 | paramPresent = true; |
---|
347 | break; |
---|
348 | } |
---|
349 | } |
---|
350 | if (!paramPresent) capteur.getParametres().add(paramCapt); |
---|
351 | } |
---|
352 | } |
---|
353 | CommunicationBD.save(capteur); |
---|
354 | int capteurId = capteur.getCapteurId(); |
---|
355 | CommunicationBD.close(); |
---|
356 | return capteurId; |
---|
357 | } |
---|
358 | |
---|
359 | /** |
---|
360 | * Insertion du type de plateforme |
---|
361 | */ |
---|
362 | public int insererTypePlateforme(TypePlateforme typePlateforme) throws Exception { |
---|
363 | if (typePlateforme.getTypePlateformeNom().equals( Constantes.typePlatFix)) |
---|
364 | typePlateforme.setTypePlateformeId(Constantes.typePlatFixID); |
---|
365 | else |
---|
366 | typePlateforme.setTypePlateformeId(Constantes.typePlatMobID); |
---|
367 | return typePlateforme.getTypePlateformeId(); |
---|
368 | } |
---|
369 | |
---|
370 | /** |
---|
371 | * Insertion de la plateforme |
---|
372 | * @param parametres |
---|
373 | * @param capteurs |
---|
374 | */ |
---|
375 | public int insererPlateforme(Plateforme plateforme, ArrayList<Capteur> capteurs, ArrayList<Parametre> parametres) throws Exception { |
---|
376 | CommunicationBD.open(); |
---|
377 | // On parcourt la liste des capteurs de la plateforme |
---|
378 | for (Capteur captPlat : plateforme.getCapteurs()) { |
---|
379 | // On parcourt la liste des capteurs du jeu |
---|
380 | for (Capteur capteur : capteurs) { |
---|
381 | // On compléte les identifiants des capteurs |
---|
382 | if (capteur.getCapteurModele().equals(captPlat.getCapteurModele()) |
---|
383 | && capteur.getCapteurNumserie().equals(captPlat.getCapteurNumserie()) |
---|
384 | && capteur.getTypeCapteur().getTypeCapteurNom().equals(captPlat.getTypeCapteur().getTypeCapteurNom()) |
---|
385 | && capteur.getFabriquant().getFabriquantNom().equals(captPlat.getFabriquant().getFabriquantNom())) { |
---|
386 | captPlat.setCapteurId(capteur.getCapteurId()); |
---|
387 | break; |
---|
388 | } |
---|
389 | } |
---|
390 | } |
---|
391 | // On parcourt la liste des paramétres de la plateforme |
---|
392 | for (Parametre paramPlat : plateforme.getParametres()) { |
---|
393 | // On parcourt la liste des paramétres du jeu |
---|
394 | for (Parametre parametre : parametres) { |
---|
395 | // On compléte les identifiants des paramétres |
---|
396 | if (parametre.getParametreCode().equals(paramPlat.getParametreCode())) { |
---|
397 | paramPlat.setParametreId(parametre.getParametreId()); |
---|
398 | break; |
---|
399 | } |
---|
400 | } |
---|
401 | } |
---|
402 | // On associe le jeu é la plateforme |
---|
403 | // for (Jeu jeuPlat : plateforme.getJeus()) { |
---|
404 | // if (jeuPlat.getJeuNom().equals(jeu.getJeuNom())) { |
---|
405 | // jeuPlat.setJeuId(jeu.getJeuId()); |
---|
406 | // break; |
---|
407 | // } |
---|
408 | // } |
---|
409 | insererTypePlateforme(plateforme.getTypePlateforme()); |
---|
410 | // insertion du commentaire s'il esxiste |
---|
411 | if (plateforme.getCommentaire() != null) { |
---|
412 | insererCommentaire(plateforme.getCommentaire()); |
---|
413 | } |
---|
414 | // On vérifie si la plateforme existe déjé |
---|
415 | // Plateforme plateformeExistant = (Plateforme) CommunicationBD.getObjectByColonne(Plateforme.class, "plateformeNom", |
---|
416 | // plateforme.getPlateformeNom().replaceAll("'", "''")); |
---|
417 | List<?> plateformeExistant = CommunicationBD.getList("select p.plateformeId from Plateforme p " |
---|
418 | + "where plateforme_nom = '" + plateforme.getPlateformeNom().replaceAll("'", "''")+"'"); |
---|
419 | // si la plateforme existe : on récupére l'ID et les jeux associés |
---|
420 | if (plateformeExistant.size() != 0) { |
---|
421 | plateforme.setPlateformeId(((Integer)plateformeExistant.get(0)).intValue()); |
---|
422 | List<?> captsPlat = CommunicationBD.getList("select p.capteurs from Plateforme p where p.plateformeId = "+plateforme.getPlateformeId()); |
---|
423 | Capteur capteur; |
---|
424 | boolean isPresent; |
---|
425 | for (int numCapt=0; numCapt < captsPlat.size(); numCapt++) { |
---|
426 | capteur = (Capteur)captsPlat.get(numCapt); |
---|
427 | isPresent = false; |
---|
428 | for (Capteur capt: plateforme.getCapteurs()) { |
---|
429 | if (capteur.getCapteurModele().equals(capt.getCapteurModele()) |
---|
430 | && capteur.getCapteurNumserie().equals(capt.getCapteurNumserie()) |
---|
431 | && capteur.getTypeCapteur().getTypeCapteurNom().equals(capt.getTypeCapteur().getTypeCapteurNom()) |
---|
432 | && capteur.getFabriquant().getFabriquantNom().equals(capt.getFabriquant().getFabriquantNom())) { |
---|
433 | isPresent = true; |
---|
434 | } |
---|
435 | } |
---|
436 | if (!isPresent) { |
---|
437 | Capteur c = new Capteur(capteur.getCapteurId(), |
---|
438 | new Fabriquant(capteur.getFabriquant().getFabriquantId(), capteur.getFabriquant().getFabriquantNom()), |
---|
439 | new TypeCapteur(capteur.getTypeCapteur().getTypeCapteurId(), capteur.getTypeCapteur().getTypeCapteurNom()), |
---|
440 | null, capteur.getCapteurModele(), capteur.getCapteurNumserie(), capteur.getCapteurEtalonnage(), null, null, null, null, null); |
---|
441 | plateforme.getCapteurs().add(c); |
---|
442 | } |
---|
443 | } |
---|
444 | List<?> paramsPlat = CommunicationBD.getList("select p.parametres from Plateforme p where p.plateformeId = "+plateforme.getPlateformeId()); |
---|
445 | Parametre parametre; |
---|
446 | for (int numParam=0; numParam < paramsPlat.size(); numParam++) { |
---|
447 | parametre = (Parametre)paramsPlat.get(numParam); |
---|
448 | isPresent = false; |
---|
449 | for (Parametre param: plateforme.getParametres()) { |
---|
450 | if (parametre.getParametreCode().equals(param.getParametreCode())) { |
---|
451 | isPresent = true; |
---|
452 | } |
---|
453 | } |
---|
454 | if (!isPresent) { |
---|
455 | Parametre p = new Parametre(parametre.getParametreId(), null, null, null, parametre.getParametreNom(), parametre.getParametreCode(), |
---|
456 | null, null, null, null, null); |
---|
457 | plateforme.getParametres().add(p); |
---|
458 | } |
---|
459 | } |
---|
460 | List<?> jeusPlat = CommunicationBD.getList("select p.jeus from Plateforme p where p.plateformeId = "+plateforme.getPlateformeId()); |
---|
461 | for (int numJeu=0; numJeu < jeusPlat.size(); numJeu++) { |
---|
462 | plateforme.getJeus().add((Jeu)jeusPlat.get(numJeu)); |
---|
463 | } |
---|
464 | } |
---|
465 | CommunicationBD.save(plateforme); |
---|
466 | int plateformeId = plateforme.getPlateformeId(); |
---|
467 | // On insére les positions de la plateforme |
---|
468 | for (RequetePlatLoc requetePlatLoc : plateforme.getRequetePlatLocs()) { |
---|
469 | requetePlatLoc.setPlateforme(plateforme); |
---|
470 | requetePlatLoc.setPlateformeId(plateformeId); |
---|
471 | CommunicationBD.save(requetePlatLoc); |
---|
472 | } |
---|
473 | CommunicationBD.close(); |
---|
474 | return plateformeId; |
---|
475 | } |
---|
476 | |
---|
477 | /** |
---|
478 | * Insertion du fichier |
---|
479 | */ |
---|
480 | public int insererFichier(Fichier fichier) throws Exception { |
---|
481 | List<?> fichiersExistants = CommunicationBD.getList("select f.fichierId from Fichier f " + |
---|
482 | "where jeu_id = "+fichier.getJeu().getJeuId()+" and fichier_nom = '"+fichier.getFichierNom().replaceAll("'", "''")+"'"); |
---|
483 | // si Le fichier n'existe pas : on l'insére |
---|
484 | if (fichiersExistants.size() == 0) { |
---|
485 | fichierExiste = false; |
---|
486 | } |
---|
487 | // sinon Le fichier existe : on récupére l'ID |
---|
488 | else { |
---|
489 | fichierExiste = true; |
---|
490 | fichier.setFichierId(((Integer)fichiersExistants.get(0)).intValue()); |
---|
491 | } |
---|
492 | CommunicationBD.save(fichier); |
---|
493 | int fichierId = fichier.getFichierId(); |
---|
494 | return fichierId; |
---|
495 | } |
---|
496 | |
---|
497 | /** |
---|
498 | * Insertion de la localisation |
---|
499 | */ |
---|
500 | public int insererLoc(Localisation localisation, ArrayList<Localisation> listeLocs, String typePlat) throws Exception {//, int flagId |
---|
501 | int id = findLoc(listeLocs, localisation); |
---|
502 | if (id == -1) { |
---|
503 | if (typePlat.equals(Constantes.typePlatFix)) { |
---|
504 | List<?> localisationsExistants = CommunicationBD.getList("select l.localisationId from Localisation l" + |
---|
505 | " where localisation_lat = "+localisation.getLocalisationLat()+ |
---|
506 | " and localisation_lon = "+localisation.getLocalisationLon()+ |
---|
507 | " and localisation_alt = "+localisation.getLocalisationAlt()); |
---|
508 | // si La localisation n'existe pas : on l'insére |
---|
509 | if (localisationsExistants.size() == 0) { |
---|
510 | // si le flag de longitude n est pas null : on l'insere |
---|
511 | } |
---|
512 | // sinon La localisation existe : on récupére l'ID |
---|
513 | else { |
---|
514 | localisation.setLocalisationId(((Integer)localisationsExistants.get(0)).intValue()); |
---|
515 | } |
---|
516 | } |
---|
517 | CommunicationBD.save(localisation); |
---|
518 | listeLocs.add(new Localisation(localisation.getLocalisationId(), localisation.getLocalisationLat(), localisation.getLocalisationLon(), localisation.getLocalisationAlt())); |
---|
519 | } else { |
---|
520 | localisation.setLocalisationId(id); |
---|
521 | } |
---|
522 | int localisationId = localisation.getLocalisationId(); |
---|
523 | return localisationId; |
---|
524 | } |
---|
525 | |
---|
526 | /** |
---|
527 | * Vérifie si la localisation donnée figure dans la liste de localisations |
---|
528 | * Si oui, retourne l'ID de la localisation trouvée dans la liste |
---|
529 | * Si non, retourne -1 |
---|
530 | */ |
---|
531 | public int findLoc(ArrayList<Localisation> listeLocs, Localisation loc) { |
---|
532 | for (Localisation l : listeLocs) { |
---|
533 | if (l.getLocalisationLat() == loc.getLocalisationLat() |
---|
534 | && l.getLocalisationLon() == loc.getLocalisationLon() |
---|
535 | && l.getLocalisationAlt() == loc.getLocalisationAlt()) |
---|
536 | return l.getLocalisationId(); |
---|
537 | } |
---|
538 | return -1; |
---|
539 | } |
---|
540 | |
---|
541 | /** |
---|
542 | * Insertion du delta |
---|
543 | */ |
---|
544 | public int insererDelta(DeltaMesure deltaMesure) throws Exception { |
---|
545 | List<?> deltasExistants = CommunicationBD.getList("select d.deltaId from Delta d " + |
---|
546 | "where delta_mesure_date = "+deltaMesure.getDeltaMesureDate()+" " + |
---|
547 | "and delta_mesure_lat = "+deltaMesure.getDeltaMesureLat()+" " + |
---|
548 | "and delta_mesure_lon = "+deltaMesure.getDeltaMesureLon()+" " + |
---|
549 | "and delta_mesure_alt = "+deltaMesure.getDeltaMesureLon()); |
---|
550 | // si le delta existe : on récupére l'ID |
---|
551 | if (deltasExistants.size() != 0) { |
---|
552 | deltaMesure.setDeltaMesureId(((Integer)deltasExistants.get(0)).intValue()); |
---|
553 | } |
---|
554 | CommunicationBD.save(deltaMesure); |
---|
555 | int deltaId = deltaMesure.getDeltaMesureId(); |
---|
556 | return deltaId; |
---|
557 | } |
---|
558 | |
---|
559 | /** |
---|
560 | * Insertion de la sequence |
---|
561 | */ |
---|
562 | public int insererSequence(Sequence sequence) throws Exception { |
---|
563 | List<?> sequencesExistants = CommunicationBD |
---|
564 | .getList("select s.sequenceId from Sequence s " |
---|
565 | + "where jeu_id = " + sequence.getJeu().getJeuId() |
---|
566 | + " and sequence_dated = '"+ DateTime.dateToString( sequence.getSequenceDated(), Constantes.formatDateJJMMAAAAHHMMSS ) |
---|
567 | + "' and sequence_datef = '" + DateTime.dateToString(sequence.getSequenceDatef(),Constantes.formatDateJJMMAAAAHHMMSS)+ "'"); |
---|
568 | int sequenceId ; |
---|
569 | |
---|
570 | // La sequence n'existe pas : on l'insére |
---|
571 | if (sequencesExistants.size() == 0) { |
---|
572 | // inserer le commentaire s'il existe |
---|
573 | if (sequence.getCommentaire() != null) { |
---|
574 | insererCommentaire(sequence.getCommentaire()); |
---|
575 | } |
---|
576 | CommunicationBD.save(sequence); |
---|
577 | sequenceId = sequence.getSequenceId(); |
---|
578 | } |
---|
579 | // La sequence existe : on récupére l'ID |
---|
580 | else { |
---|
581 | sequenceId = ((Integer) sequencesExistants.get(0)).intValue(); |
---|
582 | sequence.setSequenceId(sequenceId); |
---|
583 | /**test sur lr commentaire de la sequence*/ |
---|
584 | if (sequence.getCommentaire() != null) { |
---|
585 | sequence.getCommentaire().setCommentaireId(sequence.getCommentaire().getCommentaireId()); |
---|
586 | } |
---|
587 | sequence.getJeu().setJeuAltmax(Statiques.altMaxJeu); |
---|
588 | sequence.getJeu().setJeuAltmax(Statiques.altMinJeu); |
---|
589 | sequence.getJeu().setJeuAltmax(Statiques.latMaxJeu); |
---|
590 | sequence.getJeu().setJeuAltmax(Statiques.latMinJeu); |
---|
591 | sequence.getJeu().setJeuAltmax(Statiques.lonMaxJeu); |
---|
592 | sequence.getJeu().setJeuAltmax(Statiques.lonMinJeu); |
---|
593 | sequence.getJeu().setJeuAltmax(Statiques.hsMaxJeu); |
---|
594 | sequence.getJeu().setJeuAltmax(Statiques.hsMinJeu); |
---|
595 | sequence.getJeu().setJeuDated(Statiques.dateMaxJeu); |
---|
596 | sequence.getJeu().setJeuDatef(Statiques.dateMinJeu); |
---|
597 | } |
---|
598 | return sequenceId; |
---|
599 | } |
---|
600 | |
---|
601 | /** |
---|
602 | * Insertion de la table bilan |
---|
603 | */ |
---|
604 | public void insererBilan(Jeu jeu, ArrayList<Plateforme> plateformes, ArrayList<Capteur> capteurs, ArrayList<Parametre> parametres) throws Exception { |
---|
605 | Bilan bilan; |
---|
606 | List<?> bilansExistants; |
---|
607 | // On parcourt les plateformes du jeu |
---|
608 | for (Plateforme plateforme: plateformes) { |
---|
609 | // On parcourt les capteurs du jeu |
---|
610 | for (Capteur capteur: capteurs) { |
---|
611 | // On parcourt les capteurs liés é la plateforme |
---|
612 | for (Capteur capteurPlat: plateforme.getCapteurs()) { |
---|
613 | if (capteurPlat.getCapteurModele().equals(capteur.getCapteurModele()) |
---|
614 | && capteurPlat.getCapteurNumserie().equals(capteur.getCapteurNumserie()) |
---|
615 | && capteurPlat.getFabriquant().getFabriquantNom().equals(capteur.getFabriquant().getFabriquantNom()) |
---|
616 | && capteurPlat.getTypeCapteur().getTypeCapteurNom().equals(capteur.getTypeCapteur().getTypeCapteurNom())) { |
---|
617 | // S'il y a correspondance sur un capteur... |
---|
618 | // On parcourt les paramétres du jeu |
---|
619 | for (Parametre parametre: parametres) { |
---|
620 | // On parcourt les paramétres liés au capteur |
---|
621 | for (Parametre parametreCapt: capteur.getParametres()) { |
---|
622 | if (parametreCapt.getParametreCode().equals(parametre.getParametreCode())) { |
---|
623 | // S'il y a correspondance sur un paramétre... |
---|
624 | // On vérifie que le bilan n'existe pas déjé dans la base |
---|
625 | bilansExistants = CommunicationBD.getList("from Bilan b where" |
---|
626 | + " plateforme_id = " + plateforme.getPlateformeId() |
---|
627 | + " and capteur_id = " + capteur.getCapteurId() |
---|
628 | + " and jeu_id = " + jeu.getJeuId() |
---|
629 | + " and parametre_id = " + parametre.getParametreId()); |
---|
630 | // si Le bilan n'existe pas : on l'insére |
---|
631 | if (bilansExistants.size() == 0) { |
---|
632 | bilan = new Bilan(); |
---|
633 | bilan.setPlateforme(plateforme); |
---|
634 | bilan.setCapteur(capteur); |
---|
635 | bilan.setJeu(jeu); |
---|
636 | bilan.setParametre(parametre); |
---|
637 | CommunicationBD.save(bilan); |
---|
638 | } |
---|
639 | } |
---|
640 | } |
---|
641 | } |
---|
642 | } |
---|
643 | } |
---|
644 | } |
---|
645 | } |
---|
646 | } |
---|
647 | |
---|
648 | /** |
---|
649 | * Mise é jour des mesures |
---|
650 | */ |
---|
651 | public void mettreAjourMesure(Sequence sequence) throws Exception { |
---|
652 | // faire un select sur la base de donnee afin de récuperer les mesures |
---|
653 | List<?> mesures = CommunicationBD.getList("from Mesure m " |
---|
654 | + "where fichier_id in " |
---|
655 | + "(select f.fichierId from Fichier f where jeu_id = "+sequence.getJeu().getJeuId()+") " |
---|
656 | + "and mesure_date >= '" + DateTime.dateToString(sequence.getSequenceDated(),Constantes.formatDateJJMMAAAAHHMMSS)+"' " |
---|
657 | + "and mesure_date <= '" + DateTime.dateToString(sequence.getSequenceDatef(),Constantes.formatDateJJMMAAAAHHMMSS)+"'"); |
---|
658 | |
---|
659 | Mesure mesure = null; |
---|
660 | int nbMesures = mesures.size(); |
---|
661 | for(int numMesure = 0; numMesure < nbMesures ; numMesure++){ |
---|
662 | mesure = (Mesure) mesures.get(numMesure); |
---|
663 | mesure.setSequence(sequence); |
---|
664 | CommunicationBD.save(mesure); |
---|
665 | } |
---|
666 | } |
---|
667 | |
---|
668 | /** |
---|
669 | * Mise é jour du jeu |
---|
670 | */ |
---|
671 | public void mettreAjourJeu(Jeu jeu) throws Exception { |
---|
672 | if(jeu.getJeuDated() == null || DateTime.plusGrand(jeu.getJeuDated(),Statiques.dateMinJeu)){ |
---|
673 | jeu.setJeuDated(Statiques.dateMinJeu); |
---|
674 | } |
---|
675 | if(jeu.getJeuDatef() == null || DateTime.plusGrand(Statiques.dateMaxJeu,jeu.getJeuDatef())){ |
---|
676 | jeu.setJeuDatef(Statiques.dateMaxJeu); |
---|
677 | } |
---|
678 | if(jeu.getJeuLatmax() == null || Statiques.latMaxJeu > jeu.getJeuLatmax()){ |
---|
679 | jeu.setJeuLatmax(Statiques.latMaxJeu); |
---|
680 | } |
---|
681 | if(jeu.getJeuLatmin() == null || Statiques.latMinJeu < jeu.getJeuLatmin()){ |
---|
682 | jeu.setJeuLatmin(Statiques.latMinJeu); |
---|
683 | } |
---|
684 | if(jeu.getJeuLonmax() == null || Statiques.lonMaxJeu > jeu.getJeuLonmax()){ |
---|
685 | jeu.setJeuLonmax(Statiques.lonMaxJeu); |
---|
686 | } |
---|
687 | if(jeu.getJeuLonmin() == null || Statiques.lonMinJeu < jeu.getJeuLonmin()){ |
---|
688 | jeu.setJeuLonmin(Statiques.lonMinJeu); |
---|
689 | } |
---|
690 | if(jeu.getJeuAltmax() == null || Statiques.altMaxJeu > jeu.getJeuAltmax()){ |
---|
691 | jeu.setJeuAltmax(Statiques.altMaxJeu); |
---|
692 | } |
---|
693 | if(jeu.getJeuAltmin() == null || Statiques.altMinJeu < jeu.getJeuAltmin()){ |
---|
694 | jeu.setJeuAltmin(Statiques.altMinJeu); |
---|
695 | } |
---|
696 | if(Statiques.hsMaxJeu.intValue() != Nombre.altDoubleToInt(Double.valueOf(Constantes.hsMoinsInf)).intValue() |
---|
697 | && (jeu.getJeuHsmax() == null || Statiques.hsMaxJeu > jeu.getJeuHsmax())){ |
---|
698 | jeu.setJeuHsmax(Statiques.hsMaxJeu); |
---|
699 | } |
---|
700 | if(Statiques.hsMinJeu.intValue() != Nombre.altDoubleToInt(new Double(Constantes.hsPlusInf)).intValue() |
---|
701 | && (jeu.getJeuHsmin() == null || Statiques.hsMinJeu < jeu.getJeuHsmin())){ |
---|
702 | jeu.setJeuHsmin(Statiques.hsMinJeu); |
---|
703 | } |
---|
704 | CommunicationBD.save(jeu); |
---|
705 | } |
---|
706 | |
---|
707 | /** |
---|
708 | * Mise é jour des liaisons entre les capteurs et les jeux |
---|
709 | */ |
---|
710 | public void mettreAJourRequeteCaptJeu(Jeu jeu, ArrayList<Capteur> capteurs) throws Exception { |
---|
711 | jeu.setCapteurs(new HashSet<Capteur>()); |
---|
712 | for (Capteur capteur: capteurs) { |
---|
713 | jeu.getCapteurs().add(capteur); |
---|
714 | } |
---|
715 | CommunicationBD.save(jeu); |
---|
716 | } |
---|
717 | |
---|
718 | /** |
---|
719 | * Mise é jour la liason entre les Parametres et les jeux |
---|
720 | */ |
---|
721 | public void mettreAJourRequeteParamJeu(Jeu jeu, ArrayList<Parametre> parametres) throws Exception { |
---|
722 | jeu.setParametres(new HashSet<Parametre>()); |
---|
723 | for (Parametre parametre: parametres) { |
---|
724 | jeu.getParametres().add(parametre); |
---|
725 | } |
---|
726 | CommunicationBD.save(jeu); |
---|
727 | } |
---|
728 | |
---|
729 | /** |
---|
730 | * Mise é jour la liason entre les plateformes et le jeu |
---|
731 | */ |
---|
732 | public void mettreAJourRequetePlatJeu(Jeu jeu, ArrayList<Plateforme> plateformes) throws Exception { |
---|
733 | jeu.setPlateformes(new HashSet<Plateforme>()); |
---|
734 | for (Plateforme plateforme: plateformes) { |
---|
735 | jeu.getPlateformes().add(plateforme); |
---|
736 | } |
---|
737 | CommunicationBD.save(jeu); |
---|
738 | } |
---|
739 | |
---|
740 | /** |
---|
741 | * Mise é jour de la liason entre le nbre de valeurs et jeu |
---|
742 | */ |
---|
743 | public void mettreAJourRequeteNbValsJeu(Jeu jeu, int nbFichiers, int nbMesures, int nbValeurs) throws Exception { |
---|
744 | List<?> reqNbValsJeuExistants = CommunicationBD.getList("from RequeteNbvalsJeu r where jeu_id = "+jeu.getJeuId()); |
---|
745 | RequeteNbvalsJeu requeteNbvalsJeu; |
---|
746 | // si l'objet n'existe pas : on l'insére |
---|
747 | if (reqNbValsJeuExistants.size() == 0) { |
---|
748 | requeteNbvalsJeu = new RequeteNbvalsJeu(); |
---|
749 | requeteNbvalsJeu.setJeu(jeu); |
---|
750 | requeteNbvalsJeu.setJeuId(jeu.getJeuId()); |
---|
751 | requeteNbvalsJeu.setNbFichiers(nbFichiers); |
---|
752 | requeteNbvalsJeu.setNbMesures(nbMesures); |
---|
753 | requeteNbvalsJeu.setNbValeurs(nbValeurs); |
---|
754 | } |
---|
755 | // Sinon on le met é jour |
---|
756 | else { |
---|
757 | requeteNbvalsJeu = (RequeteNbvalsJeu) reqNbValsJeuExistants.get(0); |
---|
758 | if (nbFichiers!=0) { |
---|
759 | requeteNbvalsJeu.setNbFichiers(nbFichiers); |
---|
760 | if (nbMesures!=0) { |
---|
761 | requeteNbvalsJeu.setNbMesures(nbMesures); |
---|
762 | if (nbValeurs!=0) requeteNbvalsJeu.setNbValeurs(nbValeurs); |
---|
763 | } |
---|
764 | } |
---|
765 | } |
---|
766 | CommunicationBD.save(requeteNbvalsJeu); |
---|
767 | } |
---|
768 | |
---|
769 | /** |
---|
770 | * Mise é jour de la liaison entre les parametres et les capteurs |
---|
771 | */ |
---|
772 | public void mettreAJourRequeteParamCapt(ArrayList<Capteur> capteurs, ArrayList<Parametre> parametres) throws Exception { |
---|
773 | // On parcourt la liste des capteurs du jeu |
---|
774 | for (Capteur capteur: capteurs) { |
---|
775 | // On parcourt la liste des paramétres du capteur |
---|
776 | for (Parametre paramCapt : capteur.getParametres()) { |
---|
777 | // On parcourt la liste des paramétres du jeu |
---|
778 | for (Parametre parametre : parametres) { |
---|
779 | // On compléte les identifiants des paramétres |
---|
780 | if (parametre.getParametreCode().equals(paramCapt.getParametreCode())) { |
---|
781 | paramCapt.setParametreId(parametre.getParametreId()); |
---|
782 | break; |
---|
783 | } |
---|
784 | } |
---|
785 | } |
---|
786 | CommunicationBD.save(capteur); |
---|
787 | } |
---|
788 | // on vérifie s'il y a un seul capteur |
---|
789 | } |
---|
790 | |
---|
791 | /** |
---|
792 | * Mise é jour de la liaison entre les plateformes et les capteurs/paramétres |
---|
793 | */ |
---|
794 | public void mettreAJourRequeteCaptPlatParam(ArrayList<Plateforme> plateformes, ArrayList<Capteur> capteurs, ArrayList<Parametre> parametres) throws Exception { |
---|
795 | // On parcourt les plateformes du jeu |
---|
796 | for (Plateforme plateforme: plateformes) { |
---|
797 | // On parcourt la liste des capteurs de la plateforme |
---|
798 | for (Capteur captPlat : plateforme.getCapteurs()) { |
---|
799 | // On parcourt la liste des capteurs du jeu |
---|
800 | for (Capteur capteur : capteurs) { |
---|
801 | // On compléte les identifiants des capteurs |
---|
802 | if (capteur.getCapteurModele().equals(captPlat.getCapteurModele()) |
---|
803 | && capteur.getCapteurNumserie().equals(captPlat.getCapteurNumserie()) |
---|
804 | && capteur.getTypeCapteur().getTypeCapteurNom().equals(captPlat.getTypeCapteur().getTypeCapteurNom()) |
---|
805 | && capteur.getFabriquant().getFabriquantNom().equals(captPlat.getFabriquant().getFabriquantNom())) { |
---|
806 | captPlat.setCapteurId(capteur.getCapteurId()); |
---|
807 | break; |
---|
808 | } |
---|
809 | } |
---|
810 | } |
---|
811 | // On parcourt la liste des paramétres de la plateforme |
---|
812 | for (Parametre paramPlat : plateforme.getParametres()) { |
---|
813 | // On parcourt la liste des paramétres du jeu |
---|
814 | for (Parametre parametre : parametres) { |
---|
815 | // On compléte les identifiants des paramétres |
---|
816 | if (parametre.getParametreCode().equals(paramPlat.getParametreCode())) { |
---|
817 | paramPlat.setParametreId(parametre.getParametreId()); |
---|
818 | break; |
---|
819 | } |
---|
820 | } |
---|
821 | } |
---|
822 | CommunicationBD.save(plateforme); |
---|
823 | } |
---|
824 | // on vérifie s'il y a une seule plateforme ou plusieurs |
---|
825 | } |
---|
826 | |
---|
827 | /** |
---|
828 | * Mise é jour de la liaison entre le bilan |
---|
829 | */ |
---|
830 | public void mettreAJourBilan(Jeu jeu) throws Exception { |
---|
831 | List<?> bilanExistants = CommunicationBD.getList("from Bilan b where jeu_id = " + jeu.getJeuId()); |
---|
832 | Bilan bilan; |
---|
833 | List<?> valsExistants; |
---|
834 | Object[] resultats; |
---|
835 | List<?> datesExistants; |
---|
836 | List<?> locsExistants; |
---|
837 | // Pour chaque bilan du jeu... |
---|
838 | for (int numBilan = 0; numBilan < bilanExistants.size(); numBilan++) { |
---|
839 | bilan = (Bilan) bilanExistants.get(numBilan); |
---|
840 | // Mise é jour des valeurs min, max et du nombre de valeurs |
---|
841 | valsExistants = CommunicationBD.getList("select min(v.valeurVal) as valMin, max(v.valeurVal) as valMax," |
---|
842 | + " count(v.valeurId) as nbVals from Valeur v" |
---|
843 | + " where capteur_id = " + bilan.getCapteur().getCapteurId() |
---|
844 | + " and parametre_id = " + bilan.getParametre().getParametreId() |
---|
845 | + " and v.mesure.plateforme.plateformeId = " + bilan.getPlateforme().getPlateformeId() |
---|
846 | + " and v.mesure.fichier.jeu.jeuId = " + jeu.getJeuId()); |
---|
847 | if (valsExistants.size() != 0) { |
---|
848 | resultats = (Object[]) valsExistants.get(0); |
---|
849 | bilan.setBilanValmin((Double) resultats[0]); |
---|
850 | bilan.setBilanValmax((Double) resultats[1]); |
---|
851 | bilan.setBilanNbval(new Integer(((Long) resultats[2]).intValue())); |
---|
852 | // Mise é jour des dates début et fin |
---|
853 | datesExistants = CommunicationBD.getList("select min(m.mesureDate) as dateMin, max(m.mesureDate) as dateMax" |
---|
854 | + " from Mesure m where plateforme_id = " + bilan.getPlateforme().getPlateformeId() |
---|
855 | + " and m.fichier.jeu.jeuId = " + jeu.getJeuId() |
---|
856 | + " and mesure_id in (select v.mesure.mesureId from Valeur v" |
---|
857 | + " where capteur_id = " + bilan.getCapteur().getCapteurId() |
---|
858 | + " and parametre_id = " + bilan.getParametre().getParametreId()+")"); |
---|
859 | if (datesExistants.size() != 0) { |
---|
860 | resultats = (Object[])datesExistants.get(0); |
---|
861 | bilan.setBilanDated((Date) resultats[0]); |
---|
862 | bilan.setBilanDatef((Date) resultats[1]); |
---|
863 | // Mise é jour des localisations |
---|
864 | locsExistants = CommunicationBD.getList("select min(l.localisationLat) as latMin," |
---|
865 | + " max(l.localisationLat) as latMax, min(l.localisationLon) as lonMin," |
---|
866 | + " max(l.localisationLon) as lonMax, min(l.localisationAlt) as altMin," |
---|
867 | + " max(l.localisationAlt) as altMax, min(l.localisationHs) as hsMin," |
---|
868 | + " max(l.localisationHs) as hsMax from Localisation l where localisation_id" + |
---|
869 | " in (SELECT m.localisation.localisationId FROM Mesure m" |
---|
870 | + " where plateforme_id = " + bilan.getPlateforme().getPlateformeId() |
---|
871 | + " and m.fichier.jeu.jeuId = " + jeu.getJeuId() |
---|
872 | + " and mesure_id IN (SELECT v.mesure.mesureId FROM Valeur v" |
---|
873 | + " WHERE capteur_id = " + bilan.getCapteur().getCapteurId() |
---|
874 | + " and parametre_id = " + bilan.getParametre().getParametreId()+"))"); |
---|
875 | if (locsExistants.size() != 0) { |
---|
876 | resultats = (Object[])locsExistants.get(0); |
---|
877 | bilan.setBilanLatmin((Integer) resultats[0]); |
---|
878 | bilan.setBilanLatmax((Integer) resultats[1]); |
---|
879 | bilan.setBilanLonmin((Integer) resultats[2]); |
---|
880 | bilan.setBilanLonmax((Integer) resultats[3]); |
---|
881 | bilan.setBilanAltmin((Integer) resultats[4]); |
---|
882 | bilan.setBilanAltmax((Integer) resultats[5]); |
---|
883 | if(resultats[6] != null){ |
---|
884 | bilan.setBilanHsmin((Integer) resultats[6]); |
---|
885 | } |
---|
886 | if(resultats[7] != null){ |
---|
887 | bilan.setBilanHsmax((Integer) resultats[7]); |
---|
888 | } |
---|
889 | /**********traitement de la fréquence*****************/ |
---|
890 | } |
---|
891 | } |
---|
892 | // on sauvegarde le bilan |
---|
893 | CommunicationBD.save(bilan); |
---|
894 | } |
---|
895 | } |
---|
896 | } |
---|
897 | |
---|
898 | public boolean isFichierExiste() { |
---|
899 | return fichierExiste; |
---|
900 | } |
---|
901 | |
---|
902 | public void setFichierExiste(boolean fichierExiste) { |
---|
903 | this.fichierExiste = fichierExiste; |
---|
904 | } |
---|
905 | |
---|
906 | public int getFlagLocId() { |
---|
907 | return flagLocId; |
---|
908 | } |
---|
909 | |
---|
910 | public void setFlagLocId(int flagLocId) { |
---|
911 | this.flagLocId = flagLocId; |
---|
912 | } |
---|
913 | |
---|
914 | public int getFlagValidId() { |
---|
915 | return flagValidId; |
---|
916 | } |
---|
917 | |
---|
918 | public void setFlagValidId(int flagValidId) { |
---|
919 | this.flagValidId = flagValidId; |
---|
920 | } |
---|
921 | |
---|
922 | /** |
---|
923 | * Insertion de la valeur |
---|
924 | */ |
---|
925 | private int flagValidId = 0; |
---|
926 | private int flagLocId = 0; |
---|
927 | private boolean fichierExiste = false; |
---|
928 | } |
---|