1 /*
2 * #%L
3 * Coser :: Web
4 * %%
5 * Copyright (C) 2010 - 2011 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.map;
23
24 import fr.ifremer.coser.result.result.FileResult;
25 import fr.ifremer.coser.result.request.GetMapResultRequest;
26 import fr.ifremer.coser.web.actions.common.AbstractCoserJspAction;
27 import org.apache.commons.logging.Log;
28 import org.apache.commons.logging.LogFactory;
29 import org.apache.struts2.convention.annotation.Action;
30 import org.apache.struts2.convention.annotation.Result;
31
32 import java.io.InputStream;
33
34 /**
35 * Appelé par le navigateur pour récuperer le contenu de l'image.
36 *
37 * @author chatellier
38 * @version $Revision$
39 * <p/>
40 * Last update : $Date$
41 * By : $Author$
42 */
43 public class MapDataAction extends AbstractCoserJspAction {
44
45 /** Logger. */
46 private static final Log log = LogFactory.getLog(MapDataAction.class);
47
48 /** serialVersionUID. */
49 private static final long serialVersionUID = 1663244944108703571L;
50
51 protected String facade;
52
53 protected String zone;
54
55 protected String species;
56
57 protected FileResult result;
58
59 public void setFacade(String facade) {
60 this.facade = facade;
61 }
62
63 public String getZone() {
64 return zone;
65 }
66
67 public void setZone(String zone) {
68 this.zone = zone;
69 }
70
71 public String getSpecies() {
72 return species;
73 }
74
75 public void setSpecies(String species) {
76 this.species = species;
77 }
78
79 public String getSource() {
80 return result.getSource();
81 }
82
83 // @Action(results = {@Result(type = "stream", params = {"contentType", "image/png", "inputName", "inputStream"})})
84 @Action(results = {@Result(type = "stream", params = {"contentType", "image/png"})})
85 public String execute() {
86 // work with null species (get Repartition-stations map)
87 GetMapResultRequest request = requestBuilder(GetMapResultRequest.class).
88 addFacade(facade).
89 addZone(zone).
90 addSpecies(species == null ? GetMapResultRequest.NULL_SPECIES : species).
91 toRequest();
92
93 if (log.isInfoEnabled()) {
94 log.info("Looking for map of species: " + request.getSpecies());
95 }
96 result = getService().toFileResult(request);
97 return SUCCESS;
98 }
99
100 public InputStream getInputStream() {
101 InputStream input = result.getInputStream();
102 return input;
103 }
104
105 // InputStream input = null;
106 // try {
107 // // work with null species (get Repartition-stations map)
108 // File mapImage = webService.getMapFile(zone, species);
109 // input = new FileInputStream(mapImage);
110 // } catch (CoserBusinessException ex) {
111 // throw new CoserWebException("Can't get map file", ex);
112 // } catch (FileNotFoundException ex) {
113 // throw new CoserWebException("Can't get map file", ex);
114 // }
115 //
116 // return input;
117 // }
118 }