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.common;
23  
24  import fr.ifremer.coser.result.CoserRequest;
25  
26  import java.util.Map;
27  
28  /**
29   * Recupere la liste des indicateurs à partir d'une zone et d'une espece (peut
30   * être null dans le cas des communautés).
31   *
32   * @author chatellier
33   * @version $Revision$
34   *          <p/>
35   *          Last update : $Date$
36   *          By : $Author$
37   */
38  public abstract class CommonIndicator extends AbstractCoserJspAction {
39  
40      /** serialVersionUID. */
41      private static final long serialVersionUID = 1663244944108703571L;
42  
43      protected String facade;
44  
45      protected String zone;
46  
47      protected String zonePicture;
48  
49      protected Map<String, String> indicators;
50  
51      /**
52       * @return the request to get zones
53       */
54      protected abstract CoserRequest createZonesRequest();
55  
56      /**
57       * @return the request to get indicators
58       */
59      protected abstract CoserRequest createIndicatorsRequest();
60  
61      public String getFacade() {
62          return facade;
63      }
64  
65      public void setFacade(String facade) {
66          this.facade = facade;
67      }
68  
69      public String getZone() {
70          return zone;
71      }
72  
73      public void setZone(String zone) {
74          this.zone = zone;
75      }
76  
77      public Map<String, String> getIndicators() {
78          return indicators;
79      }
80  
81      public String getZonePicture() {
82          return zonePicture;
83      }
84  
85      public String getFacadeDisplayName() {
86          return getService().getFacadeDisplayName(facade);
87      }
88  
89      public String getZoneDisplayName() {
90          CoserRequest zonesRequest = createZonesRequest();
91          return getService().getZoneDisplayName(zonesRequest, zone);
92      }
93  
94      @Override
95      public String execute() {
96  
97          CoserRequest request = createIndicatorsRequest();
98          indicators = getService().toMap(request);
99          zonePicture = getService().getZonePictures().get(zone);
100 
101         return SUCCESS;
102     }
103 
104 //      public String getFacadeDisplayName() {
105 //        WebService webService = ServiceFactory.getWebService();
106 //        String displayName = null;
107 //        try {
108 //            displayName = webService.getFacades().get(facade);
109 //        } catch (CoserBusinessException ex) {
110 //            throw new CoserWebException("Can't get facade display name", ex);
111 //        }
112 //        return displayName;
113 //    }
114 //
115 //    public String getZoneDisplayName() {
116 //        WebService webService = ServiceFactory.getWebService();
117 //        String displayName = null;
118 //        try {
119 //            displayName = webService.getZoneForFacade(facade, false, false).get(zone);
120 //        } catch (CoserBusinessException ex) {
121 //            throw new CoserWebException("Can't get zone display name", ex);
122 //        }
123 //        return displayName;
124 //    }
125 //
126 //    public String getSpeciesDisplayName() {
127 //        WebService webService = ServiceFactory.getWebService();
128 //        String displayName = null;
129 //        try {
130 //            displayName = webService.getSpecies(zone, false).get(species);
131 //        } catch (CoserBusinessException ex) {
132 //            throw new CoserWebException("Can't get species display name", ex);
133 //        }
134 //        return displayName;
135 //    }
136 //    @Override
137 //    public String execute() {
138 //
139 //        if (log.isInfoEnabled()) {
140 //            log.info(String.format("Looking for indicator for zone %s and species %s", zone, species));
141 //        }
142 //
143 //        WebService webService = ServiceFactory.getWebService();
144 //
145 //        Locale locale = getLocale();
146 //
147 //        try {
148 //            indicators = webService.getIndicators(zone, species, locale);
149 //
150 //            zonePicture = webService.getZonePictures().get(zone);
151 //        } catch (CoserBusinessException ex) {
152 //            throw new CoserWebException("Can't get indicators", ex);
153 //        }
154 //
155 //        return SUCCESS;
156 //    }
157 }