Author: chatellier Date: 2011-01-10 17:45:53 +0000 (Mon, 10 Jan 2011) New Revision: 492 Log: Affichage des graph a partir d'une image g?\195?\169n?\195?\169r?\195?\169e par jfreechart. Added: trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/com/GraphAction.java trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/com/GraphDataAction.java trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/com/IndicatorAction.java trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/com/SubzoneAction.java trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/com/ZoneAction.java trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/pop/GraphDataAction.java Modified: trunk/coser-business/src/main/java/fr/ifremer/coser/services/PublicationService.java trunk/coser-business/src/main/java/fr/ifremer/coser/services/WebService.java trunk/coser-web/src/main/java/fr/ifremer/coser/web/ServiceFactory.java trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/pop/GraphAction.java Modified: trunk/coser-business/src/main/java/fr/ifremer/coser/services/PublicationService.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/services/PublicationService.java 2011-01-10 16:08:48 UTC (rev 491) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/services/PublicationService.java 2011-01-10 17:45:53 UTC (rev 492) @@ -45,6 +45,7 @@ import java.util.TreeMap; import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.collections.map.MultiKeyMap; import org.apache.commons.io.IOUtils; import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; @@ -60,16 +61,20 @@ import org.jfree.chart.plot.PlotOrientation; import org.jfree.chart.renderer.category.CategoryItemRenderer; import org.jfree.chart.renderer.category.LineAndShapeRenderer; +import org.jfree.chart.renderer.category.StatisticalLineAndShapeRenderer; import org.jfree.data.category.CategoryDataset; import org.jfree.data.category.DefaultCategoryDataset; +import org.jfree.data.statistics.DefaultStatisticalCategoryDataset; import org.jfree.util.ShapeUtilities; import fr.ifremer.coser.CoserBusinessConfig; import fr.ifremer.coser.CoserBusinessException; +import fr.ifremer.coser.CoserConstants; import fr.ifremer.coser.CoserConstants.Category; import fr.ifremer.coser.bean.AbstractDataContainer; import fr.ifremer.coser.bean.Control; import fr.ifremer.coser.bean.Project; +import fr.ifremer.coser.bean.RSufiResult; import fr.ifremer.coser.bean.Selection; import fr.ifremer.coser.command.CategoryLineCommand; import fr.ifremer.coser.command.Command; @@ -78,6 +83,7 @@ import fr.ifremer.coser.control.DiffCatchLengthControlError; import fr.ifremer.coser.data.Catch; import fr.ifremer.coser.data.Length; +import fr.ifremer.coser.storage.DataStorage; /** * Publication service (charts, reports, export...) @@ -96,9 +102,12 @@ protected ProjectService projectService; + protected ImportService importService; + public PublicationService(CoserBusinessConfig config) { this.config = config; projectService = new ProjectService(config); + importService = new ImportService(config); } /** @@ -637,5 +646,136 @@ } out.println("</ol>"); } + + /** + * @param resultDirectory + * @param rsufiResult + * @param locale + * @return + * @throws CoserBusinessException + */ + public File getRsufiResultComChart(File resultDirectory, + RSufiResult rsufiResult, String indicator, String locale) throws CoserBusinessException { + + File result = null; + + // le fichier estcomind + File estPopIndFile = new File(resultDirectory, rsufiResult.getEstPopIndName()); + + // Campagne Indicateur Liste Strate Annee Estimation EcartType CV + DataStorage dataStorage = importService.loadCSVFile(estPopIndFile, CoserConstants.CSV_RESULT_SEPARATOR_CHAR); + + DefaultStatisticalCategoryDataset statisticalDataset = new DefaultStatisticalCategoryDataset(); + Iterator<String[]> estPopIndIterator = dataStorage.iterator(true); + while (estPopIndIterator.hasNext()) { + String[] tuple = estPopIndIterator.next(); + + String indicatorCode = tuple[1]; + if (indicatorCode.equals(indicator)) { + Double estimation = Double.parseDouble(tuple[5]); + //Double ecart = estimation * 0.97; + Double ecart = Double.parseDouble(tuple[6]); + String year = tuple[4]; + statisticalDataset.add(estimation, ecart, "Serie1", year); + } + } + + // configure chart + CategoryAxis categoryAxis = new CategoryAxis(_("coser.business.common.year")); + categoryAxis.setCategoryMargin(0); + // label horizontaux + //categoryAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); + ValueAxis valueAxis = new NumberAxis(_("coser.business.common.number")); + valueAxis.setUpperMargin(0.1); + + CategoryItemRenderer renderer = new StatisticalLineAndShapeRenderer(false, true); + + // n'affiche pas les nombre sur le graphique + //StandardCategoryItemLabelGenerator itemLabelGenerator = new StandardCategoryItemLabelGenerator(); + //renderer.setBaseItemLabelGenerator(itemLabelGenerator); + //renderer.setBaseItemLabelsVisible(true); + + CategoryPlot plot = new CategoryPlot(statisticalDataset, categoryAxis, valueAxis, renderer); + plot.setOrientation(PlotOrientation.VERTICAL); + JFreeChart chart = new JFreeChart("Titre", + JFreeChart.DEFAULT_TITLE_FONT, plot, true); + + try { + result = File.createTempFile("coser-", ".chart"); + result.deleteOnExit(); + ChartUtilities.saveChartAsPNG(result, chart, 800, 400); + } catch (IOException ex) { + throw new CoserBusinessException("Can't save chart", ex); + } + + return result; + } + + /** + * @param resultDirectory + * @param rsufiResult + * @param species + * @param locale + * @return + * @throws CoserBusinessException + */ + public File getRsufiResultPopChart(File resultDirectory, + RSufiResult rsufiResult, String species, String indicator, String locale) throws CoserBusinessException { + + File result = null; + + // le fichier estcomind + File estPopIndFile = new File(resultDirectory, rsufiResult.getEstPopIndName()); + + // Campagne Indicateur Liste Species Strate Annee Estimation EcartType CV + DataStorage dataStorage = importService.loadCSVFile(estPopIndFile, CoserConstants.CSV_RESULT_SEPARATOR_CHAR); + + DefaultStatisticalCategoryDataset statisticalDataset = new DefaultStatisticalCategoryDataset(); + Iterator<String[]> estPopIndIterator = dataStorage.iterator(true); + while (estPopIndIterator.hasNext()) { + String[] tuple = estPopIndIterator.next(); + + String speciesCode = tuple[3]; + String indicatorCode = tuple[1]; + if (speciesCode.equals(species) && indicatorCode.equals(indicator)) { + Double estimation = Double.parseDouble(tuple[6]); + //Double ecart = estimation * 0.97; + Double ecart = Double.parseDouble(tuple[7]); + String year = tuple[5]; + statisticalDataset.add(estimation, ecart, "Serie1", year); + } + } + + // configure chart + CategoryAxis categoryAxis = new CategoryAxis(_("coser.business.common.year")); + categoryAxis.setCategoryMargin(0); + // label horizontaux + //categoryAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); + ValueAxis valueAxis = new NumberAxis(_("coser.business.common.number")); + valueAxis.setUpperMargin(0.1); + + CategoryItemRenderer renderer = new StatisticalLineAndShapeRenderer(false, true); + + // n'affiche pas les nombre sur le graphique + //StandardCategoryItemLabelGenerator itemLabelGenerator = new StandardCategoryItemLabelGenerator(); + //renderer.setBaseItemLabelGenerator(itemLabelGenerator); + //renderer.setBaseItemLabelsVisible(true); + + CategoryPlot plot = new CategoryPlot(statisticalDataset, categoryAxis, valueAxis, renderer); + plot.setOrientation(PlotOrientation.VERTICAL); + JFreeChart chart = new JFreeChart("Titre", + JFreeChart.DEFAULT_TITLE_FONT, plot, true); + + try { + result = File.createTempFile("coser-", ".chart"); + result.deleteOnExit(); + ChartUtilities.saveChartAsPNG(result, chart, 800, 400); + } catch (IOException ex) { + throw new CoserBusinessException("Can't save chart", ex); + } + + return result; + + } } Modified: trunk/coser-business/src/main/java/fr/ifremer/coser/services/WebService.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/services/WebService.java 2011-01-10 16:08:48 UTC (rev 491) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/services/WebService.java 2011-01-10 17:45:53 UTC (rev 492) @@ -81,6 +81,8 @@ protected ProjectService projectService; + protected PublicationService publicationService; + /** Indicator map (id, locale > translation) (etat du service). */ protected MultiKeyMap indicatorsMap; @@ -92,6 +94,7 @@ importService = new ImportService(config); projectService = new ProjectService(config); + publicationService = new PublicationService(config); } /** @@ -531,7 +534,7 @@ * pour la zone et l'especes souhaitées. * * @param zone zone (zoneid-surveyname) - * @param species especes + * @param species especes (if {@code null} look for com indicators * @param locale locale ({@code fr} ou {@code en}) * @return la liste des indicateurs * @throws CoserBusinessException @@ -572,7 +575,14 @@ // data loading not necessary here if (surveyName.equals(survey)) { - Map<String, String> resultIndicators = getRsufiResultIndicators(resultFile, rsufiResult, species, locale); + Map<String, String> resultIndicators = null; + + if (species == null) { + resultIndicators = getRsufiResultComIndicators(resultFile, rsufiResult, locale); + } + else { + resultIndicators = getRsufiResultPopIndicators(resultFile, rsufiResult, species, locale); + } indicators.putAll(resultIndicators); break; } @@ -601,7 +611,7 @@ * @return indicator for species * @throws CoserBusinessException */ - protected Map<String, String> getRsufiResultIndicators(File resultDirectory, RSufiResult rsufiResult, String species, String locale) throws CoserBusinessException { + protected Map<String, String> getRsufiResultPopIndicators(File resultDirectory, RSufiResult rsufiResult, String species, String locale) throws CoserBusinessException { MultiKeyMap defaultIndicators = getIndicatorsMap(); @@ -631,22 +641,63 @@ return result; } + + /** + * Recupere la liste de toutes les especes nom sci et nom off à partir + * d'un resultat. + * + * @param resultDirectory rsufi result directory + * @param rsufiResult result + * @param species to get indicator + * @param locale locale ({@code fr} ou {@code en}) + * @return indicator for species + * @throws CoserBusinessException + */ + protected Map<String, String> getRsufiResultComIndicators(File resultDirectory, RSufiResult rsufiResult, String locale) throws CoserBusinessException { + MultiKeyMap defaultIndicators = getIndicatorsMap(); + + Map<String, String> result = new HashMap<String, String>(); + + // le fichier estcomind + File estComIndFile = new File(resultDirectory, rsufiResult.getEstComIndName()); + + // Campagne Indicateur Liste Strate Annee Estimation EcartType CV + DataStorage dataStorage = importService.loadCSVFile(estComIndFile, CoserConstants.CSV_RESULT_SEPARATOR_CHAR); + + Iterator<String[]> estPopIndIterator = dataStorage.iterator(true); + while (estPopIndIterator.hasNext()) { + String[] tuple = estPopIndIterator.next(); + + String indicatorCode = tuple[1]; + String translations = (String)defaultIndicators.get(indicatorCode, locale.toLowerCase()); + if (translations == null) { + translations = "##" + indicatorCode + "##"; + } + result.put(indicatorCode, translations); + } + + return result; + } + /** - * Generer les données du graph et genere la liste des parametres pour - * les generateurs de graph (eastwood ou jfreechart). + * Retourne les indicateurs calculés avec leurs traductions scientifique + * pour la zone et l'especes souhaitées. * - * @param zone zone - * @param species species + * @param zone zone (zoneid-surveyname) + * @param species especes (if {@code null} look for com indicators * @param indicator indicator - * @return chart parameters + * @param locale locale ({@code fr} ou {@code en}) + * @return la liste des indicateurs * @throws CoserBusinessException */ - public String getChartParameters(String zone, String species, String indicator) throws CoserBusinessException { + public File getChart(String zone, String species, String indicator, String locale) throws CoserBusinessException { + File result = null; - // charge du fichier EstComInd_survey.txt ou EstPopInd_survey.txt - // suivant le type de resultat demandé (communauté/population) + String zoneId = zone.substring(0, zone.indexOf('-')); + String survey = zone.substring(zone.indexOf('-') + 1); + // parcours des resultats disponibles File projectsDirectory = config.getWebProjectsDirectory(); File[] projectFiles = projectsDirectory.listFiles(); if (projectFiles != null) { @@ -661,20 +712,31 @@ if (selectionFile.isDirectory()) { File resultsDirectory = new File(selectionFile, CoserConstants.STORAGE_RESULTS_DIRECTORY); File[] resultFiles = resultsDirectory.listFiles(); - + // result iteration if (resultFiles != null) { for (File resultFile : resultFiles) { if (resultFile.isDirectory()) { RSufiResult rsufiResult = projectService.getRSufiResult(resultFile); - if (rsufiResult.getZone() != null && rsufiResult.getZone().equals(zone)) { - - // load project (without data to get reftax data) - Project project = projectService.openProject(projectFile.getName(), projectsDirectory); - Map<String, String> resultSpecies = getRsufiResultSpecies(project, resultFile, rsufiResult); - //result.putAll(resultSpecies); - break; + // extraction des especes pour le résultat demandé + if (rsufiResult.getZone() != null && rsufiResult.getZone().equals(zoneId)) { + + // get survey name (other condition) + String surveyName = projectService.getProjectSurveyName(resultFile, rsufiResult); + + // data loading not necessary here + if (surveyName.equals(survey)) { + Map<String, String> resultIndicators = null; + + if (species == null) { + result = publicationService.getRsufiResultComChart(resultFile, rsufiResult, indicator, locale); + } + else { + result = publicationService.getRsufiResultPopChart(resultFile, rsufiResult, species, indicator, locale); + } + break; + } } } } @@ -685,8 +747,8 @@ } } } - - return null; + + return result; } /** Modified: trunk/coser-web/src/main/java/fr/ifremer/coser/web/ServiceFactory.java =================================================================== --- trunk/coser-web/src/main/java/fr/ifremer/coser/web/ServiceFactory.java 2011-01-10 16:08:48 UTC (rev 491) +++ trunk/coser-web/src/main/java/fr/ifremer/coser/web/ServiceFactory.java 2011-01-10 17:45:53 UTC (rev 492) @@ -25,6 +25,7 @@ import org.nuiton.i18n.I18n; import org.nuiton.util.ArgumentsParserException; +import fr.ifremer.coser.services.PublicationService; import fr.ifremer.coser.services.WebService; /** Added: trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/com/GraphAction.java =================================================================== --- trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/com/GraphAction.java (rev 0) +++ trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/com/GraphAction.java 2011-01-10 17:45:53 UTC (rev 492) @@ -0,0 +1,86 @@ +/* + * #%L + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2010 - 2011 Ifremer, Codelutin, Chatellier Eric + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ + +package fr.ifremer.coser.web.actions.com; + +import com.opensymphony.xwork2.ActionSupport; + +/** + * Affiche le graphique demandé. + * + * Parametre : zone, species, indicator. + * + * Based on eastwoood, same doc as google chart api : + * http://code.google.com/apis/chart/docs/making_charts.html + * + * chart?cht=<chart_type>&chd=<chart_data>&chs=<chart_size>&...additional_parameters... + * + * Dans ce cas, on va faire un graphe avec des points pour les valeurs + * et des traits (en dessous/au dessus) pour les ecarts types. + * chd=t: + * 12,16,16,24,26,28,41,51,66,68,13,45,81| + * 16,14,22,34,22,31,31,48,71,64,15,38,84| + * 8,6,4,5,2,13,9,8,7,6,1,8,8 + * chm= + * o,0000FF,0,-1,0| + * h,FF0000,0,0:9:,5| + * h,FF0000,0,0:9:,5 + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public class GraphAction extends ActionSupport { + + /** serialVersionUID. */ + private static final long serialVersionUID = 3385467755357775199L; + + protected String zone; + + protected String indicator; + + protected String chartUrl; + + public String getZone() { + return zone; + } + + public void setZone(String zone) { + this.zone = zone; + } + + public String getIndicator() { + return indicator; + } + + public void setIndicator(String indicator) { + this.indicator = indicator; + } + + @Override + public String execute() { + + return SUCCESS; + } +} Property changes on: trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/com/GraphAction.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/com/GraphDataAction.java =================================================================== --- trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/com/GraphDataAction.java (rev 0) +++ trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/com/GraphDataAction.java 2011-01-10 17:45:53 UTC (rev 492) @@ -0,0 +1,118 @@ +/* + * #%L + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2010 - 2011 Ifremer, Codelutin, Chatellier Eric + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ + +package fr.ifremer.coser.web.actions.com; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.InputStream; +import java.util.Locale; + +import org.apache.struts2.convention.annotation.Action; +import org.apache.struts2.convention.annotation.Result; + +import com.opensymphony.xwork2.ActionSupport; + +import fr.ifremer.coser.CoserBusinessException; +import fr.ifremer.coser.services.WebService; +import fr.ifremer.coser.web.CoserWebException; +import fr.ifremer.coser.web.ServiceFactory; + +/** + * Affiche le graphique demandé. + * + * Parametre : zone, species, indicator. + * + * Based on eastwoood, same doc as google chart api : + * http://code.google.com/apis/chart/docs/making_charts.html + * + * chart?cht=<chart_type>&chd=<chart_data>&chs=<chart_size>&...additional_parameters... + * + * Dans ce cas, on va faire un graphe avec des points pour les valeurs + * et des traits (en dessous/au dessus) pour les ecarts types. + * chd=t: + * 12,16,16,24,26,28,41,51,66,68,13,45,81| + * 16,14,22,34,22,31,31,48,71,64,15,38,84| + * 8,6,4,5,2,13,9,8,7,6,1,8,8 + * chm= + * o,0000FF,0,-1,0| + * h,FF0000,0,0:9:,5| + * h,FF0000,0,0:9:,5 + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public class GraphDataAction extends ActionSupport { + + /** serialVersionUID. */ + private static final long serialVersionUID = 3385467755357775199L; + + protected String zone; + + protected String indicator; + + protected String chartUrl; + + public String getZone() { + return zone; + } + + public void setZone(String zone) { + this.zone = zone; + } + + public String getIndicator() { + return indicator; + } + + public void setIndicator(String indicator) { + this.indicator = indicator; + } + + @Action(results= {@Result(type="stream", params={"contentType", "image/png", "inputName", "inputStream"})}) + public String execute() { + return SUCCESS; + } + + public InputStream getInputStream() { + WebService webService = ServiceFactory.getWebService(); + + Locale locale = getLocale(); + String localeCode = locale.getLanguage(); + + InputStream input = null; + try { + File mapImage = webService.getChart(zone, null, indicator, localeCode); + input = new FileInputStream(mapImage); + } catch (CoserBusinessException ex) { + throw new CoserWebException("Can't get map file", ex); + } catch (FileNotFoundException ex) { + throw new CoserWebException("Can't get map file", ex); + } + + return input; + } +} Property changes on: trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/com/GraphDataAction.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/com/IndicatorAction.java =================================================================== --- trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/com/IndicatorAction.java (rev 0) +++ trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/com/IndicatorAction.java 2011-01-10 17:45:53 UTC (rev 492) @@ -0,0 +1,90 @@ +/* + * #%L + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2010 - 2011 Ifremer, Codelutin, Chatellier Eric + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ + +package fr.ifremer.coser.web.actions.com; + +import java.util.Locale; +import java.util.Map; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import com.opensymphony.xwork2.ActionSupport; + +import fr.ifremer.coser.CoserBusinessException; +import fr.ifremer.coser.services.WebService; +import fr.ifremer.coser.web.CoserWebException; +import fr.ifremer.coser.web.ServiceFactory; + +/** + * Action index, recupere la liste des resultats. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public class IndicatorAction extends ActionSupport { + + /** serialVersionUID. */ + private static final long serialVersionUID = 1663244944108703571L; + + private static final Log log = LogFactory.getLog(IndicatorAction.class); + + protected String zone; + + protected Map<String, String> indicators; + + public String getZone() { + return zone; + } + + public void setZone(String zone) { + this.zone = zone; + } + + public Map<String, String> getIndicators() { + return indicators; + } + + @Override + public String execute() { + + if (log.isInfoEnabled()) { + log.info(String.format("Looking for com indicator for zone %s", zone)); + } + + WebService webService = ServiceFactory.getWebService(); + + Locale locale = getLocale(); + String localeCode = locale.getLanguage(); + + try { + indicators = webService.getIndicators(zone, null, localeCode); + } catch (CoserBusinessException ex) { + throw new CoserWebException("Can't get indicators", ex); + } + + return SUCCESS; + } +} Property changes on: trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/com/IndicatorAction.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/com/SubzoneAction.java =================================================================== --- trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/com/SubzoneAction.java (rev 0) +++ trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/com/SubzoneAction.java 2011-01-10 17:45:53 UTC (rev 492) @@ -0,0 +1,76 @@ +/* + * #%L + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2010 - 2011 Ifremer, Codelutin, Chatellier Eric + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ + +package fr.ifremer.coser.web.actions.com; + +import java.util.Map; + +import com.opensymphony.xwork2.ActionSupport; + +import fr.ifremer.coser.CoserBusinessException; +import fr.ifremer.coser.services.WebService; +import fr.ifremer.coser.web.CoserWebException; +import fr.ifremer.coser.web.ServiceFactory; + +/** + * Affiche la liste des sous zones (zone). + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public class SubzoneAction extends ActionSupport { + + /** serialVersionUID. */ + private static final long serialVersionUID = 3385467755357775199L; + + protected String mainZone; + + public void setMainZone(String mainZone) { + this.mainZone = mainZone; + } + + protected Map<String, String> zones; + + public Map<String, String> getZones() { + return zones; + } + + @Override + public String execute() { + + WebService webService = ServiceFactory.getWebService(); + try { + + // renvoi la liste des id subzone-survey et leurs label + // associé + zones = webService.getSurveysForZone(mainZone); + + } catch (CoserBusinessException ex) { + throw new CoserWebException("Can't get zone map", ex); + } + + return SUCCESS; + } +} Property changes on: trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/com/SubzoneAction.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/com/ZoneAction.java =================================================================== --- trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/com/ZoneAction.java (rev 0) +++ trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/com/ZoneAction.java 2011-01-10 17:45:53 UTC (rev 492) @@ -0,0 +1,74 @@ +/* + * #%L + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2010 - 2011 Ifremer, Codelutin, Chatellier Eric + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ + +package fr.ifremer.coser.web.actions.com; + +import java.util.HashMap; +import java.util.Map; + +import com.opensymphony.xwork2.ActionSupport; + +import fr.ifremer.coser.CoserBusinessException; +import fr.ifremer.coser.services.WebService; +import fr.ifremer.coser.web.CoserWebException; +import fr.ifremer.coser.web.ServiceFactory; + +/** + * Action index, affiche la liste des zones majeures (main zone). + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public class ZoneAction extends ActionSupport { + + /** serialVersionUID. */ + private static final long serialVersionUID = 3385467755357775199L; + + protected Map<String, String> mainZones; + + public Map<String, String> getMainZones() { + return mainZones; + } + + @Override + public String execute() { + + mainZones = new HashMap<String, String>(); + + WebService webService = ServiceFactory.getWebService(); + try { + Map<String, String[]> zonesMap = webService.getZonesMap(); + + for (Map.Entry<String, String[]> zoneMapEntry : zonesMap.entrySet()) { + mainZones.put(zoneMapEntry.getValue()[0], zoneMapEntry.getValue()[0]); + } + + } catch (CoserBusinessException ex) { + throw new CoserWebException("Can't get zone map", ex); + } + + return SUCCESS; + } +} Property changes on: trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/com/ZoneAction.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Modified: trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/pop/GraphAction.java =================================================================== --- trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/pop/GraphAction.java 2011-01-10 16:08:48 UTC (rev 491) +++ trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/pop/GraphAction.java 2011-01-10 17:45:53 UTC (rev 492) @@ -90,16 +90,11 @@ public void setIndicator(String indicator) { this.indicator = indicator; } - - public String getChartUrl() { - return chartUrl; - } - @Override public String execute() { - CoserWebConfig config = ServiceFactory.getCoserConfig(); + /*CoserWebConfig config = ServiceFactory.getCoserConfig(); chartUrl = config.getEastWoodUrl() + "/chart?"; @@ -120,7 +115,7 @@ // taille de la courbe chartUrl += "&chls=2"; // titre du graphique - chartUrl += "&chtt=" + zone + ";" + species + ";" + indicator; + chartUrl += "&chtt=" + zone + ";" + species + ";" + indicator;*/ return SUCCESS; } Added: trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/pop/GraphDataAction.java =================================================================== --- trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/pop/GraphDataAction.java (rev 0) +++ trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/pop/GraphDataAction.java 2011-01-10 17:45:53 UTC (rev 492) @@ -0,0 +1,130 @@ +/* + * #%L + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2010 - 2011 Ifremer, Codelutin, Chatellier Eric + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ + +package fr.ifremer.coser.web.actions.pop; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.InputStream; +import java.util.Locale; + +import org.apache.struts2.convention.annotation.Action; +import org.apache.struts2.convention.annotation.Result; + +import com.opensymphony.xwork2.ActionSupport; + +import fr.ifremer.coser.CoserBusinessException; +import fr.ifremer.coser.services.PublicationService; +import fr.ifremer.coser.services.WebService; +import fr.ifremer.coser.web.CoserWebConfig; +import fr.ifremer.coser.web.CoserWebException; +import fr.ifremer.coser.web.ServiceFactory; + +/** + * Affiche le graphique demandé. + * + * Parametre : zone, species, indicator. + * + * Based on eastwoood, same doc as google chart api : + * http://code.google.com/apis/chart/docs/making_charts.html + * + * chart?cht=<chart_type>&chd=<chart_data>&chs=<chart_size>&...additional_parameters... + * + * Dans ce cas, on va faire un graphe avec des points pour les valeurs + * et des traits (en dessous/au dessus) pour les ecarts types. + * chd=t: + * 12,16,16,24,26,28,41,51,66,68,13,45,81| + * 16,14,22,34,22,31,31,48,71,64,15,38,84| + * 8,6,4,5,2,13,9,8,7,6,1,8,8 + * chm= + * o,0000FF,0,-1,0| + * h,FF0000,0,0:9:,5| + * h,FF0000,0,0:9:,5 + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public class GraphDataAction extends ActionSupport { + + /** serialVersionUID. */ + private static final long serialVersionUID = 3385467755357775199L; + + protected String zone; + + protected String species; + + protected String indicator; + + protected String chartUrl; + + public String getZone() { + return zone; + } + + public void setZone(String zone) { + this.zone = zone; + } + + public String getSpecies() { + return species; + } + + public void setSpecies(String species) { + this.species = species; + } + + public String getIndicator() { + return indicator; + } + + public void setIndicator(String indicator) { + this.indicator = indicator; + } + + @Action(results= {@Result(type="stream", params={"contentType", "image/png", "inputName", "inputStream"})}) + public String execute() { + return SUCCESS; + } + + public InputStream getInputStream() { + WebService webService = ServiceFactory.getWebService(); + + Locale locale = getLocale(); + String localeCode = locale.getLanguage(); + + InputStream input = null; + try { + File mapImage = webService.getChart(zone, species, indicator, localeCode); + input = new FileInputStream(mapImage); + } catch (CoserBusinessException ex) { + throw new CoserWebException("Can't get map file", ex); + } catch (FileNotFoundException ex) { + throw new CoserWebException("Can't get map file", ex); + } + + return input; + } +} Property changes on: trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/pop/GraphDataAction.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL