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.pop;
23
24 import fr.ifremer.coser.result.request.GetSpeciesForPopulationIndicatorResultRequest;
25 import fr.ifremer.coser.result.request.GetZonesForPopulationIndicatorResultRequest;
26 import fr.ifremer.coser.web.actions.common.AbstractCoserJspAction;
27 import org.apache.commons.logging.Log;
28 import org.apache.commons.logging.LogFactory;
29
30 import java.util.Map;
31
32 /**
33 * Action index, recupere la liste des resultats.
34 *
35 * @author chatellier
36 * @version $Revision$
37 * <p/>
38 * Last update : $Date$
39 * By : $Author$
40 */
41 public class SpeciesAction extends AbstractCoserJspAction {
42
43 /** serialVersionUID. */
44 private static final long serialVersionUID = 1663244944108703571L;
45
46 private static final Log log = LogFactory.getLog(SpeciesAction.class);
47
48 protected String facade;
49
50 protected String zone;
51
52 protected Map<String, String> species;
53
54 protected String zonePicture;
55
56 public String getFacade() {
57 return facade;
58 }
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 Map<String, String> getSpecies() {
73 return species;
74 }
75
76 public String getZonePicture() {
77 return zonePicture;
78 }
79
80 public String getFacadeDisplayName() {
81 return getService().getFacadeDisplayName(facade);
82 }
83
84 public String getZoneDisplayName() {
85 GetZonesForPopulationIndicatorResultRequest request =
86 requestBuilder(GetZonesForPopulationIndicatorResultRequest.class).
87 addFacade(facade).
88 toRequest();
89 return getService().getZoneDisplayName(request, zone);
90 }
91
92 @Override
93 public String execute() {
94
95 if (log.isInfoEnabled()) {
96 log.info("Looking for species for zone " + zone);
97 }
98
99 GetSpeciesForPopulationIndicatorResultRequest request =
100 requestBuilder(GetSpeciesForPopulationIndicatorResultRequest.class).
101 addFacade(facade).
102 addZone(zone).
103 toRequest();
104 species = getService().toMap(request);
105
106 if (log.isDebugEnabled()) {
107 log.debug("Species are : " + species);
108 }
109
110 zonePicture = getService().getZonePictures().get(zone);
111
112 return SUCCESS;
113 }
114
115 // public String getFacadeDisplayName() {
116 // WebService webService = ServiceFactory.getWebService();
117 // String displayName = null;
118 // try {
119 // displayName = webService.getFacades().get(facade);
120 // } catch (CoserBusinessException ex) {
121 // throw new CoserWebException("Can't get facade display name", ex);
122 // }
123 // return displayName;
124 // }
125 //
126 // public String getZoneDisplayName() {
127 // WebService webService = ServiceFactory.getWebService();
128 // String displayName = null;
129 // try {
130 // displayName = webService.getZoneForFacade(facade, false, false).get(zone);
131 // } catch (CoserBusinessException ex) {
132 // throw new CoserWebException("Can't get zone display name", ex);
133 // }
134 // return displayName;
135 // }
136 //
137 // @Override
138 // public String execute() {
139 //
140 // if (log.isInfoEnabled()) {
141 // log.info("Looking for species for zone " + zone);
142 // }
143 //
144 // WebService webService = ServiceFactory.getWebService();
145 //
146 // try {
147 // species = webService.getSpecies(zone, false);
148 //
149 // zonePicture = webService.getZonePictures().get(zone);
150 //
151 // if (log.isDebugEnabled()) {
152 // log.debug("Species are : " + species);
153 // }
154 // } catch (CoserBusinessException ex) {
155 // throw new CoserWebException("Can't get zone species", ex);
156 // }
157 //
158 // return SUCCESS;
159 // }
160 }