View Javadoc
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.GetPopulationIndicatorResultDataRequest;
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   * Télécharge les données qui ont servi a généré le graph au format CSV.
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 GraphDownloadAction 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 FileResult result;
57  
58      public void setFacade(String facade) {
59          this.facade = facade;
60      }
61  
62      public String getZone() {
63          return zone;
64      }
65  
66      public void setZone(String zone) {
67          this.zone = zone;
68      }
69  
70      public String getIndicator() {
71          return indicator;
72      }
73  
74      public void setIndicator(String indicator) {
75          this.indicator = indicator;
76      }
77  
78      public String getSpecies() {
79          return species;
80      }
81  
82      public void setSpecies(String species) {
83          this.species = species;
84      }
85  
86      public String getSource() {
87          return result.getSource();
88      }
89  
90      @Action(results = {@Result(type = "stream", params = {"contentType", "text/csv", "contentDisposition", "attachment; filename=\"${filename}\""})})
91      public String execute() {
92          GetPopulationIndicatorResultDataRequest request =
93                  requestBuilder(GetPopulationIndicatorResultDataRequest.class).
94                          addFacade(facade).
95                          addZone(zone).
96                          addSpecies(species).
97                          addIndicator(indicator).
98                          toRequest();
99          result = getService().toFileResult(request);
100         return SUCCESS;
101     }
102 
103     public String getFilename() {
104         return indicator + ".csv";
105     }
106 
107     public InputStream getInputStream() {
108         InputStream input = result.getInputStream();
109         return input;
110     }
111 
112 //    public InputStream getInputStream() {
113 //        WebService webService = ServiceFactory.getWebService();
114 //
115 //        Locale locale = getLocale();
116 //
117 //        InputStream input = null;
118 //        try {
119 //            File mapImage = webService.getChartData(zone, species, indicator, null, locale);
120 //            input = new FileInputStream(mapImage);
121 //        } catch (Exception ex) {
122 //            if (log.isErrorEnabled()) {
123 //                log.error("Can't get file data", ex);
124 //            }
125 //            throw new CoserWebException("Can't get map file", ex);
126 //        }
127 //
128 //        return input;
129 //    }
130 }