source: ether_eccad/trunk/ECCAD_INTERFACE/WEB-INF/src/org/medias/eccad/metier/emission/ServiceEmission.java @ 68

Last change on this file since 68 was 68, checked in by cbipsl, 14 years ago

commit v1 eccad

  • Property svn:executable set to *
File size: 9.0 KB
Line 
1package org.medias.eccad.metier.emission;
2
3import java.util.LinkedList;
4import java.util.List;
5
6import org.medias.eccad.helpers.Donnees;
7import org.medias.eccad.helpers.LoggerPerso;
8import org.medias.eccad.helpers.SpringBeanFactory;
9import org.medias.eccad.metier.dessinCarte.ServiceCarte;
10import org.medias.eccad.metier.generationRaster.GenerateurLegendRaster;
11import org.medias.eccad.metier.generationRaster.GenerateurLegendeImg;
12import org.medias.eccad.metier.generationRaster.GenerateurWorldFile;
13import org.medias.eccad.metier.generationRaster.InformationLegend;
14import org.medias.eccad.metier.generationRaster.colorMap.ColorMapping;
15import org.medias.eccad.metier.generationRaster.colorMap.ColorMappingLineaire;
16import org.medias.eccad.metier.statistique.GrapheCGI;
17import org.medias.eccad.metier.statistique.ServiceStatistique;
18import org.medias.eccad.metier.traducteur.TraducteurStat;
19import org.medias.eccad.modele.ColorTab;
20import org.medias.eccad.modele.Grille;
21import org.medias.eccad.modele.Parametre;
22import org.medias.eccad.modele.Produit;
23import org.medias.eccad.modele.RequeteFacteurEmission;
24import org.medias.eccad.modele.StatReponse;
25import org.medias.eccad.modele.Zone;
26import org.medias.eccad.persistance.dao.ColorTabDAO;
27import org.medias.eccad.persistance.dao.GrilleDAO;
28import org.medias.eccad.persistance.dao.ParametreDAO;
29import org.medias.eccad.persistance.dao.ProduitDAO;
30import org.medias.eccad.persistance.exception.PersistanceException;
31import org.medias.jni.RasterDAO;
32import org.springframework.beans.factory.xml.XmlBeanFactory;
33
34
35public class ServiceEmission {
36        private XmlBeanFactory xmlbean;
37        private static String BURNT = "burned area";
38        private static String FACTOR = "biomass burning emission factor";
39        private static String BIOMASS = "Biomass_Density";
40        private static String BURNEFF = "Burning_Efficiency";
41       
42        private ServiceCarte carte;
43        private StatReponse reponse;
44       
45        public ServiceEmission() {
46                xmlbean = SpringBeanFactory.getXmlFactory();
47                carte = new ServiceCarte();
48        }
49       
50        public Grille getGrilleBiomass() {
51                Produit prod = getProduitByName(BIOMASS);
52                GrilleDAO grilledao    = (GrilleDAO) xmlbean.getBean("grilleDAO");
53                Grille grille = null;
54               
55                try {
56                        grille = grilledao.getListGrille(prod.getIdentifiant(), null, null).get(0);
57                }
58                catch (PersistanceException e) {
59                        e.printStackTrace();
60                }
61               
62                return grille; 
63        }
64       
65        public Grille getGrilleBurnEff() {
66                Produit prod = getProduitByName(BURNEFF);
67                GrilleDAO grilledao    = (GrilleDAO) xmlbean.getBean("grilleDAO");
68                Grille grille = null;
69               
70                try {
71                        grille = grilledao.getListGrille(prod.getIdentifiant(), null, null).get(0);
72                }
73                catch (PersistanceException e) {
74                        e.printStackTrace();
75                }
76               
77                return grille; 
78        }
79       
80        public List<Produit> getProduitFacteurEmission() {
81                return getProduitByParamNAme(FACTOR);
82        }
83
84        public List<Produit> getProduitBurntArea() {
85                return getProduitByParamNAme(BURNT);
86        }
87       
88        public long getParamIdBurntArea() {
89                return getParamIdByName(BURNT);
90        }
91       
92        private int getParamIdByName(String paramName) {
93                ParametreDAO paramdao = (ParametreDAO) xmlbean.getBean("parametreDAO");
94                               
95                Parametre param = null; 
96                               
97                try {
98                        param = paramdao.getParametreByName(paramName);
99                        }
100                catch (Exception e) {
101                        LoggerPerso.log(ServiceEmission.class, LoggerPerso.ERROR, "erreur getGazFacteurEmission parametre : ", e);
102                        return -1;
103                }
104                               
105                return param.getIdentifiant();
106        }
107       
108        public Produit getProduitByName(String name) {
109                ProduitDAO produitdao    = (ProduitDAO) xmlbean.getBean("produitDAO");
110                Produit prod = null;
111               
112                try {
113                                prod = produitdao.getProduitByName(name);
114                }
115                catch (Exception e) {
116                        LoggerPerso.log(ServiceEmission.class, LoggerPerso.ERROR, "erreur getGazFacteurEmission parametre : ", e);
117                }
118                LoggerPerso.log(ServiceEmission.class, LoggerPerso.DEBUG, " get produit :"  + " " + prod + " ");               
119                return prod;
120        }
121       
122        private List<Produit> getProduitByParamNAme(String paramName) {
123                ParametreDAO paramdao = (ParametreDAO) xmlbean.getBean("parametreDAO");
124                ProduitDAO produitdao    = (ProduitDAO) xmlbean.getBean("produitDAO");
125               
126                Parametre param = null; 
127                List<Produit> liste = null;
128               
129                try {
130                        param = paramdao.getParametreByName(paramName);
131                        liste = produitdao.getListProductByParam(param.getIdentifiant());
132                }
133                catch (Exception e) {
134                        LoggerPerso.log(ServiceEmission.class, LoggerPerso.ERROR, "erreur getGazFacteurEmission parametre : ", e);
135                }
136                LoggerPerso.log(ServiceEmission.class, LoggerPerso.DEBUG, " getGazFacteurEmission param"  + " " + liste.size() + " " + liste);         
137                return liste;
138        }
139       
140       
141       
142        public List<Grille> getClassEmission(Long id_produit) {
143                GrilleDAO grilledao = (GrilleDAO) xmlbean.getBean("grilleDAO");
144                List<Grille> liste = new LinkedList<Grille>();
145               
146                try {
147                        liste = grilledao.getListGrille(id_produit, null, null);
148                } catch (PersistanceException e) {
149                        LoggerPerso.log(ServiceEmission.class, LoggerPerso.ERROR, "erreur getGazFacteurEmission produit : " + id_produit, e);
150                }
151                LoggerPerso.log(ServiceEmission.class, LoggerPerso.DEBUG, " getGazFacteurEmission produit : " + id_produit + " " + liste.size() + " " + liste);
152                return liste;
153        }
154       
155       
156       
157        public List<Produit> getListLand(Long facteur) {
158                ProduitDAO produitdao    = (ProduitDAO) xmlbean.getBean("produitDAO");
159                List<Produit> liste = null;
160               
161                try {
162                        liste = produitdao.getProduitByLink(null, facteur);
163                }
164                catch (Exception e) {
165                        LoggerPerso.log(ServiceEmission.class, LoggerPerso.ERROR, "erreur getListLand parametre : ", e);
166                }
167                LoggerPerso.log(ServiceEmission.class, LoggerPerso.DEBUG, " getListLand param"  + " " + liste.size() + " " + liste);           
168                return liste;
169        }
170       
171       
172        /*
173         * Manipulation de la carte
174         */
175       
176        /**
177         * zoom
178         * @param clicX
179         * @param clicY
180         */
181        public void zoom(int clicX, int clicY) {
182                carte.zoomCarte(2, clicX, clicY, 0.5);
183        }
184       
185        /**
186         *
187         * @param requete
188         * @param affiche
189         * @param id_unique
190         * @return
191         */
192        public String getCarte(RequeteFacteurEmission requete, Zone affiche, String id_unique) {
193                String temp = getRasterFacteur(requete);
194                return carte.gestionImageCarte(temp, affiche, id_unique);
195        }
196       
197        public String getLegend(long id_colormap, long id_grille, String url_images) {
198                ColorMapping colormap = getColorMap(id_colormap);
199                InformationLegend info_legend = new InformationLegend();
200                GenerateurLegendRaster gen_legend = new GenerateurLegendeImg();
201                gen_legend.genereLegendVertical(colormap, info_legend.getLegendDynamic(colormap.getColorTable(), reponse.getMaximal(), reponse.getMinimal()), "g(X)/m2/jour");
202                //system.out.println(reponse);
203                //gen_legend.genereLegendVertical(colormap, info_legend.getLegendDynamic(colormap.getColorTable(), 150, 0), info_legend.getInfoSup(id_grille));
204                gen_legend.enregistreLegend(Donnees.getHome()  +url_images+".legend.png");
205               
206                return url_images+".legend.png";
207        }
208       
209        /**
210         *
211         * @return
212         */
213        public Zone getzone() {
214                return carte.getCarteCoordinate();
215        }
216       
217        /**
218         *
219         * @param requete
220         * @return
221         */
222        private String getRasterFacteur(RequeteFacteurEmission requete) {
223                String xml = requete.toXml();
224                System.out.println(xml);
225                // TODO: ATTENDRE LIB DE HAKIM
226                GrapheCGI rasterdao = new GrapheCGI();
227               
228                //system.out.println(rasterdao.getStatistique(xml));
229               
230                reponse = decodeReponse(rasterdao.getStatistique(xml));
231                if (reponse.getError() != null && !reponse.getError().equals(""))
232                        return "erreur";
233               
234                GenerateurWorldFile gen_worldfile = (GenerateurWorldFile) xmlbean.getBean("worldfile");
235                gen_worldfile.setPasX(reponse.getCarte().getPasX());
236                gen_worldfile.setPasY(reponse.getCarte().getPasY());
237                gen_worldfile.setPixelY(reponse.getZone().getNorthbc() - (reponse.getCarte().getPasY()/2));
238                gen_worldfile.setPixelX(reponse.getZone().getWestbc() + (reponse.getCarte().getPasY()/2));
239               
240               
241                String nom = reponse.getUrlImage();
242               
243                nom = nom.substring(0, nom.length()-4);
244                gen_worldfile.writeWorldFile(nom);
245               
246                //system.out.println("\n\n\n" + nom);
247                return reponse.getUrlImage();
248                //return "/tmp/4113.31.png";
249        }
250       
251        private String encodeData() {
252                return "";
253        }
254       
255        private StatReponse decodeReponse(String reponse_xml) {
256                reponse = new TraducteurStat().getReponse(reponse_xml);
257               
258                if (reponse.getError() != null && !reponse.getError().equals(""))
259                        return null;
260                LoggerPerso.log(ServiceStatistique.class, LoggerPerso.DEBUG, reponse_xml);
261                return reponse;
262        }
263       
264        /**
265         * Interroge la base de données pour obtenir la table de couleur de la grille
266         *
267         * @param colormapid l'identifiant de la colormap
268         * @return la table de couleur par défaut
269         */
270        private ColorMapping getColorMap(long colormapid) {
271                ColorTabDAO colorDAO = (ColorTabDAO) xmlbean.getBean("colorTabDAO");
272               
273                ColorTab colortab = null;
274                // je recupere les informations de la colotab dans la base
275                // pour une dynamique expo je vais recevoir des valeurs min de la forme : 0 0.0001 0.001 0.01 0.1 1
276                // mais la j'ai un résultat chelou :/
277                try {
278                        colortab = colorDAO.getColorMapByID(colormapid);
279                } catch (PersistanceException e) {
280                        e.printStackTrace();
281                }
282                // FIXME c pas une colormap linéaire normalement ^^
283                ColorMapping colormap = new ColorMappingLineaire();
284                colormap.setColorTable(colortab);
285                return colormap;
286        }
287}
Note: See TracBrowser for help on using the repository browser.