1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
34
35
36
37
38
39
40
41
42
43 public class GraphDownloadAction extends AbstractCoserJspAction {
44
45
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130 }