Author: chatellier Date: 2011-01-10 16:06:29 +0000 (Mon, 10 Jan 2011) New Revision: 490 Log: Map action Added: trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/map/ trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/map/MapAction.java trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/map/MapDataAction.java trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/map/SpeciesAction.java trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/map/SubzoneAction.java trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/map/ZoneAction.java Removed: trunk/coser-web/src/main/java/fr/ifremer/coser/web/pop/ Modified: trunk/coser-business/src/main/java/fr/ifremer/coser/services/WebService.java trunk/coser-web/src/main/webapp/WEB-INF/web.xml Modified: trunk/coser-business/src/main/java/fr/ifremer/coser/services/WebService.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/services/WebService.java 2011-01-10 14:42:03 UTC (rev 489) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/services/WebService.java 2011-01-10 16:06:29 UTC (rev 490) @@ -52,7 +52,6 @@ import fr.ifremer.coser.CoserConstants; import fr.ifremer.coser.bean.Project; import fr.ifremer.coser.bean.RSufiResult; -import fr.ifremer.coser.bean.Selection; import fr.ifremer.coser.storage.DataStorage; /** @@ -558,7 +557,7 @@ if (selectionFile.isDirectory()) { File resultsDirectory = new File(selectionFile, CoserConstants.STORAGE_RESULTS_DIRECTORY); File[] resultFiles = resultsDirectory.listFiles(); - + // result iteration if (resultFiles != null) { for (File resultFile : resultFiles) { @@ -567,14 +566,16 @@ // extraction des especes pour le résultat demandé if (rsufiResult.getZone() != null && rsufiResult.getZone().equals(zoneId)) { - + // get survey name (other condition) String surveyName = projectService.getProjectSurveyName(resultFile, rsufiResult); - + // data loading not necessary here - Map<String, String> resultIndicators = getRsufiResultIndicators(resultFile, rsufiResult, species, locale); - indicators.putAll(resultIndicators); - break; + if (surveyName.equals(survey)) { + Map<String, String> resultIndicators = getRsufiResultIndicators(resultFile, rsufiResult, species, locale); + indicators.putAll(resultIndicators); + break; + } } } } @@ -687,4 +688,67 @@ return null; } + + /** + * Recupere le fichier image de la carte demandées en fonction de la zone + * et de l'espece. + * + * @param zone zone (zoneid-surveyname) + * @param species + * @return map file + * @throws CoserBusinessException + */ + public File getMapFile(String zone, String species) throws CoserBusinessException { + + File result = null; + + String zoneId = zone.substring(0, zone.indexOf('-')); + String survey = zone.substring(zone.indexOf('-') + 1); + + // parcours des resultats disponibles + File projectsDirectory = config.getWebProjectsDirectory(); + File[] projectFiles = projectsDirectory.listFiles(); + if (projectFiles != null) { + for (File projectFile : projectFiles) { + if (projectFile.isDirectory()) { + File selectionsDirectory = new File(projectFile, CoserConstants.STORAGE_SELECTION_DIRECTORY); + File[] selectionFiles = selectionsDirectory.listFiles(); + + // selection iteration + if (selectionFiles != null) { + for (File selectionFile : selectionFiles) { + if (selectionFile.isDirectory()) { + File resultsDirectory = new File(selectionFile, CoserConstants.STORAGE_RESULTS_DIRECTORY); + File[] resultFiles = resultsDirectory.listFiles(); + + // result iteration + if (resultFiles != null) { + for (File resultFile : resultFiles) { + if (resultFile.isDirectory()) { + RSufiResult rsufiResult = projectService.getRSufiResult(resultFile); + + // extraction des especes pour le résultat demandé + if (rsufiResult.getZone() != null && rsufiResult.getZone().equals(zoneId)) { + + // get survey name (other condition) + String surveyName = projectService.getProjectSurveyName(resultFile, rsufiResult); + + if (surveyName.equals(survey)) { + String mapName = survey + "_" + species.toUpperCase() + ".png"; + File mapsDirectory = new File(resultFile, CoserConstants.STORAGE_MAPS_DIRECTORY); + result = new File(mapsDirectory, mapName); + } + } + } + } + } + } + } + } + } + } + } + + return result; + } } Added: trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/map/MapAction.java =================================================================== --- trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/map/MapAction.java (rev 0) +++ trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/map/MapAction.java 2011-01-10 16:06:29 UTC (rev 490) @@ -0,0 +1,60 @@ +/* + * #%L + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2010 - 2011 Ifremer, Codelutin, Chatellier Eric + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ + +package fr.ifremer.coser.web.actions.map; + +import com.opensymphony.xwork2.ActionSupport; + +/** + * Action index, recupere la liste des resultats. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public class MapAction extends ActionSupport { + + /** serialVersionUID. */ + private static final long serialVersionUID = 1663244944108703571L; + + protected String zone; + + protected String species; + + public String getZone() { + return zone; + } + + public void setZone(String zone) { + this.zone = zone; + } + + public String getSpecies() { + return species; + } + + public void setSpecies(String species) { + this.species = species; + } +} Property changes on: trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/map/MapAction.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/map/MapDataAction.java =================================================================== --- trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/map/MapDataAction.java (rev 0) +++ trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/map/MapDataAction.java 2011-01-10 16:06:29 UTC (rev 490) @@ -0,0 +1,96 @@ +/* + * #%L + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2010 - 2011 Ifremer, Codelutin, Chatellier Eric + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ + +package fr.ifremer.coser.web.actions.map; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.InputStream; +import java.io.OutputStream; + +import org.apache.commons.io.IOUtils; +import org.apache.struts2.convention.annotation.Action; +import org.apache.struts2.convention.annotation.Result; + +import com.opensymphony.xwork2.ActionSupport; + +import fr.ifremer.coser.CoserBusinessException; +import fr.ifremer.coser.services.WebService; +import fr.ifremer.coser.web.CoserWebException; +import fr.ifremer.coser.web.ServiceFactory; + +/** + * Action index, recupere la liste des resultats. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public class MapDataAction extends ActionSupport { + + /** serialVersionUID. */ + private static final long serialVersionUID = 1663244944108703571L; + + protected String zone; + + protected String species; + + public String getZone() { + return zone; + } + + public void setZone(String zone) { + this.zone = zone; + } + + public String getSpecies() { + return species; + } + + public void setSpecies(String species) { + this.species = species; + } + + @Action(results= {@Result(type="stream", params={"contentType", "image/png", "inputName", "inputStream"})}) + public String execute() { + return SUCCESS; + } + + public InputStream getInputStream() { + WebService webService = ServiceFactory.getWebService(); + + InputStream input = null; + try { + File mapImage = webService.getMapFile(zone, species); + input = new FileInputStream(mapImage); + } catch (CoserBusinessException ex) { + throw new CoserWebException("Can't get map file", ex); + } catch (FileNotFoundException ex) { + throw new CoserWebException("Can't get map file", ex); + } + + return input; + } +} Property changes on: trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/map/MapDataAction.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/map/SpeciesAction.java =================================================================== --- trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/map/SpeciesAction.java (rev 0) +++ trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/map/SpeciesAction.java 2011-01-10 16:06:29 UTC (rev 490) @@ -0,0 +1,90 @@ +/* + * #%L + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2010 - 2011 Ifremer, Codelutin, Chatellier Eric + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ + +package fr.ifremer.coser.web.actions.map; + +import java.util.Map; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import com.opensymphony.xwork2.ActionSupport; + +import fr.ifremer.coser.CoserBusinessException; +import fr.ifremer.coser.services.WebService; +import fr.ifremer.coser.web.CoserWebException; +import fr.ifremer.coser.web.ServiceFactory; + +/** + * Action index, recupere la liste des resultats. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public class SpeciesAction extends ActionSupport { + + /** serialVersionUID. */ + private static final long serialVersionUID = 1663244944108703571L; + + private static final Log log = LogFactory.getLog(SpeciesAction.class); + + protected String zone; + + protected Map<String, String> species; + + public String getZone() { + return zone; + } + + public void setZone(String zone) { + this.zone = zone; + } + + public Map<String, String> getSpecies() { + return species; + } + + @Override + public String execute() { + + if (log.isInfoEnabled()) { + log.info("Looking for species for zone " + zone); + } + + WebService webService = ServiceFactory.getWebService(); + + try { + species = webService.getSpecies(zone); + + if (log.isDebugEnabled()) { + log.debug("Species are : " + species); + } + } catch (CoserBusinessException ex) { + throw new CoserWebException("Can't get zone species", ex); + } + + return SUCCESS; + } +} Property changes on: trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/map/SpeciesAction.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/map/SubzoneAction.java =================================================================== --- trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/map/SubzoneAction.java (rev 0) +++ trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/map/SubzoneAction.java 2011-01-10 16:06:29 UTC (rev 490) @@ -0,0 +1,76 @@ +/* + * #%L + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2010 - 2011 Ifremer, Codelutin, Chatellier Eric + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ + +package fr.ifremer.coser.web.actions.map; + +import java.util.Map; + +import com.opensymphony.xwork2.ActionSupport; + +import fr.ifremer.coser.CoserBusinessException; +import fr.ifremer.coser.services.WebService; +import fr.ifremer.coser.web.CoserWebException; +import fr.ifremer.coser.web.ServiceFactory; + +/** + * Affiche la liste des sous zones (zone). + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public class SubzoneAction extends ActionSupport { + + /** serialVersionUID. */ + private static final long serialVersionUID = 3385467755357775199L; + + protected String mainZone; + + public void setMainZone(String mainZone) { + this.mainZone = mainZone; + } + + protected Map<String, String> zones; + + public Map<String, String> getZones() { + return zones; + } + + @Override + public String execute() { + + WebService webService = ServiceFactory.getWebService(); + try { + + // renvoi la liste des id subzone-survey et leurs label + // associé + zones = webService.getSurveysForZone(mainZone); + + } catch (CoserBusinessException ex) { + throw new CoserWebException("Can't get zone map", ex); + } + + return SUCCESS; + } +} Property changes on: trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/map/SubzoneAction.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/map/ZoneAction.java =================================================================== --- trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/map/ZoneAction.java (rev 0) +++ trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/map/ZoneAction.java 2011-01-10 16:06:29 UTC (rev 490) @@ -0,0 +1,74 @@ +/* + * #%L + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2010 - 2011 Ifremer, Codelutin, Chatellier Eric + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ + +package fr.ifremer.coser.web.actions.map; + +import java.util.HashMap; +import java.util.Map; + +import com.opensymphony.xwork2.ActionSupport; + +import fr.ifremer.coser.CoserBusinessException; +import fr.ifremer.coser.services.WebService; +import fr.ifremer.coser.web.CoserWebException; +import fr.ifremer.coser.web.ServiceFactory; + +/** + * Action index, affiche la liste des zones majeures (main zone). + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public class ZoneAction extends ActionSupport { + + /** serialVersionUID. */ + private static final long serialVersionUID = 3385467755357775199L; + + protected Map<String, String> mainZones; + + public Map<String, String> getMainZones() { + return mainZones; + } + + @Override + public String execute() { + + mainZones = new HashMap<String, String>(); + + WebService webService = ServiceFactory.getWebService(); + try { + Map<String, String[]> zonesMap = webService.getZonesMap(); + + for (Map.Entry<String, String[]> zoneMapEntry : zonesMap.entrySet()) { + mainZones.put(zoneMapEntry.getValue()[0], zoneMapEntry.getValue()[0]); + } + + } catch (CoserBusinessException ex) { + throw new CoserWebException("Can't get zone map", ex); + } + + return SUCCESS; + } +} Property changes on: trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/map/ZoneAction.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Modified: trunk/coser-web/src/main/webapp/WEB-INF/web.xml =================================================================== --- trunk/coser-web/src/main/webapp/WEB-INF/web.xml 2011-01-10 14:42:03 UTC (rev 489) +++ trunk/coser-web/src/main/webapp/WEB-INF/web.xml 2011-01-10 16:06:29 UTC (rev 490) @@ -6,7 +6,7 @@ $Id$ $HeadURL$ %% - Copyright (C) 2010 Ifremer, Codelutin, Chatellier Eric + Copyright (C) 2010 - 2011 Ifremer, Codelutin, Chatellier Eric %% This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by @@ -42,27 +42,27 @@ <param-value>true</param-value> </init-param> </filter> - + <filter> <filter-name>struts-execute</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsExecuteFilter</filter-class> </filter> - + <filter> <filter-name>sitemesh</filter-name> <filter-class>com.opensymphony.sitemesh.webapp.SiteMeshFilter</filter-class> </filter> - + <filter-mapping> <filter-name>struts-prepare</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> - + <filter-mapping> <filter-name>sitemesh</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> - + <filter-mapping> <filter-name>struts-execute</filter-name> <url-pattern>/*</url-pattern> @@ -71,5 +71,4 @@ <listener> <listener-class>org.apache.struts2.dispatcher.ng.listener.StrutsListener</listener-class> </listener> - </web-app>
participants (1)
-
chatellier@users.labs.libre-entreprise.org