1 /*
2 * #%L
3 * Coser :: Web
4 * %%
5 * Copyright (C) 2010 - 2012 Ifremer, Codelutin, Chatellier Eric, Chemit Tony
6 * %%
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 * #L%
20 */
21
22 package fr.ifremer.coser.web.actions.pop;
23
24 import fr.ifremer.coser.result.result.FileResult;
25 import fr.ifremer.coser.result.request.GetPopulationIndicatorResultGraphRequest;
26 import fr.ifremer.coser.web.actions.common.AbstractCoserJspAction;
27 import org.apache.struts2.convention.annotation.Action;
28 import org.apache.struts2.convention.annotation.Result;
29
30 import java.io.InputStream;
31
32 /**
33 * Affiche le graphique demandé.
34 * <p/>
35 * Parametre : zone, species, indicator.
36 *
37 * @author chatellier
38 * @version $Revision$
39 * <p/>
40 * Last update : $Date$
41 * By : $Author$
42 */
43 public class GraphDataAction extends AbstractCoserJspAction {
44
45 /** serialVersionUID. */
46 private static final long serialVersionUID = 3385467755357775199L;
47
48 protected String facade;
49
50 protected String zone;
51
52 protected String species;
53
54 protected String indicator;
55
56 protected String chartUrl;
57
58 protected FileResult result;
59
60 public void setFacade(String facade) {
61 this.facade = facade;
62 }
63
64 public String getZone() {
65 return zone;
66 }
67
68 public void setZone(String zone) {
69 this.zone = zone;
70 }
71
72 public String getSpecies() {
73 return species;
74 }
75
76 public void setSpecies(String species) {
77 this.species = species;
78 }
79
80 public String getIndicator() {
81 return indicator;
82 }
83
84 public void setIndicator(String indicator) {
85 this.indicator = indicator;
86 }
87
88 public String getSource() {
89 return result.getSource();
90 }
91
92 @Action(results = {@Result(type = "stream", params = {"contentType", "image/png"})})
93 public String execute() {
94 GetPopulationIndicatorResultGraphRequest request =
95 requestBuilder(GetPopulationIndicatorResultGraphRequest.class).
96 addFacade(facade).
97 addZone(zone).
98 addSpecies(species).
99 addIndicator(indicator).
100 toRequest();
101 result = getService().toFileResult(request);
102 return SUCCESS;
103 }
104
105 public InputStream getInputStream() {
106 InputStream input = result.getInputStream();
107 return input;
108 }
109
110 // public InputStream getInputStream() {
111 // WebService webService = ServiceFactory.getWebService();
112 //
113 // Locale locale = getLocale();
114 //
115 // InputStream input = null;
116 // try {
117 // File mapImage = webService.getChart(zone, species, indicator, null, locale);
118 // input = new FileInputStream(mapImage);
119 // } catch (CoserBusinessException ex) {
120 // throw new CoserWebException("Can't get map file", ex);
121 // } catch (FileNotFoundException ex) {
122 // throw new CoserWebException("Can't get map file", ex);
123 // }
124 //
125 // return input;
126 // }
127 }