Author: chatellier Date: 2010-12-22 15:27:46 +0000 (Wed, 22 Dec 2010) New Revision: 441 Log: Update web code (receive uploaded zip by application) Added: trunk/coser-business/src/main/java/fr/ifremer/coser/services/WebService.java trunk/coser-web/src/main/java/fr/ifremer/coser/web/CoserWebConstants.java trunk/coser-web/src/main/java/fr/ifremer/coser/web/CoserWebException.java trunk/coser-web/src/main/java/fr/ifremer/coser/web/ServiceFactory.java trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/SelectSpeciesAction.java trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/SelectZoneAction.java trunk/coser-web/src/main/resources/log4j.properties trunk/coser-web/src/main/resources/struts.xml trunk/coser-web/src/main/webapp/WEB-INF/content/footer.jsp trunk/coser-web/src/main/webapp/WEB-INF/content/header.jsp trunk/coser-web/src/main/webapp/WEB-INF/content/select-species.jsp trunk/coser-web/src/main/webapp/WEB-INF/content/select-zone.jsp trunk/coser-web/src/main/webapp/images/ trunk/coser-web/src/main/webapp/images/logo_ifremer.gif trunk/coser-web/src/main/webapp/images/logo_sih.gif trunk/coser-web/src/main/webapp/images/zonesmap.jpg trunk/coser-web/src/main/webapp/styles/ trunk/coser-web/src/main/webapp/styles/coser.css Removed: trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/WelcomeUserAction.java trunk/coser-web/src/main/webapp/WEB-INF/content/welcome-user.jsp Modified: trunk/coser-web/pom.xml trunk/coser-web/src/main/java/fr/ifremer/coser/web/CoserWebConfig.java trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/IndexAction.java trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/SelectIndicatorAction.java trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/UploadResultAction.java trunk/coser-web/src/main/resources/i18n/coser-web_en_GB.properties trunk/coser-web/src/main/resources/i18n/coser-web_fr_FR.properties trunk/coser-web/src/main/webapp/WEB-INF/content/index.jsp trunk/coser-web/src/main/webapp/WEB-INF/content/upload-result.jsp Added: trunk/coser-business/src/main/java/fr/ifremer/coser/services/WebService.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/services/WebService.java (rev 0) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/services/WebService.java 2010-12-22 15:27:46 UTC (rev 441) @@ -0,0 +1,182 @@ +/* + * #%L + * + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2010 Codelutin, Chatellier Eric + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser 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 Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +package fr.ifremer.coser.services; + +import java.io.File; +import java.io.IOException; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.TreeMap; + +import org.apache.commons.io.FileUtils; +import org.apache.commons.lang.StringUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.util.ZipUtil; + +import fr.ifremer.coser.CoserBusinessConfig; +import fr.ifremer.coser.CoserBusinessException; +import fr.ifremer.coser.bean.Project; +import fr.ifremer.coser.bean.RSufiResult; +import fr.ifremer.coser.bean.Selection; +import fr.ifremer.coser.data.Catch; + +/** + * Service for web server. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public class WebService { + + private static final Log log = LogFactory.getLog(WebService.class); + + protected CoserBusinessConfig config; + + protected ProjectService projectService; + + public WebService(CoserBusinessConfig config) { + this.config = config; + + projectService = new ProjectService(config); + } + + /** + * Traite le fichier uploade par l'application client et l'enregistre + * dans le stockage coté web. + * + * @param archiveFile uploaded file + * @throws CoserBusinessException + */ + public void registerNewUploadedResults(File archiveFile) throws CoserBusinessException { + + File webDirectory = config.getWebServerDirectory(); + File newDirectory = new File(webDirectory, "tutu"); + try { + FileUtils.deleteDirectory(newDirectory); + newDirectory.mkdirs(); + + if (log.isInfoEnabled()) { + log.info("Unzipping file " + archiveFile + " to " + newDirectory); + } + ZipUtil.uncompress(archiveFile, newDirectory); + } catch (IOException ex) { + throw new CoserBusinessException("Can't uncompress file", ex); + } + } + + /** + * Recuperer la liste des populations pour une zone données. + * + * @param zone zone + * @return map species nom info>nom officiel + * @throws CoserBusinessException + */ + public Map<String, String> getSpecies(String zone) throws CoserBusinessException { + + Map<String, String> result = new TreeMap<String, String>(); + + File webDirectory = config.getWebServerDirectory(); + File newDirectory = new File(webDirectory, "tutu"); + File[] projectFiles = newDirectory.listFiles(); + if (projectFiles != null) { + for (File projectFile : projectFiles) { + if (projectFile.isDirectory()) { + Project project = projectService.openProject(projectFile.getName(), newDirectory); + + for (Selection selection : project.getSelections().values()) { + boolean resultFound = false; + + for (RSufiResult rsufiResult : selection.getRsufiResults()) { + if (rsufiResult.getZone() != null && rsufiResult.getZone().equals(zone)) { + projectService.loadSelectionData(project, selection); + Map<String, String> resultSpecies = getRsufiResultSpecies(project, selection, rsufiResult); + result.putAll(resultSpecies); + resultFound = true; + break; + } + } + + if (resultFound) { + break; + } + } + } + } + } + + return result; + } + + /** + * Recupere la liste de toutes les especes nom sci et nom off à partir + * d'un resultat. + * + * @param project + * @param selection + * @param rsufiResult + * @return + */ + protected Map<String, String> getRsufiResultSpecies(Project project, + Selection selection, RSufiResult rsufiResult) { + Map<String, String> result = new HashMap<String, String>(); + + // load reftax in memory + Map<String, String> speciesNames = new HashMap<String, String>(); + Iterator<String[]> reftax = project.getRefTaxSpecies().iterator(); + reftax.next(); // skip header + while (reftax.hasNext()) { + String[] tuple = reftax.next(); + + // "C_Perm","NumSys","NivSys","C_VALIDE","L_VALIDE","AA_VALIDE","C_TxP\u00E8re","Taxa" + String speciesCode = tuple[3]; + String speciesName = tuple[4]; + + speciesNames.put(speciesCode, speciesName); + } + + // get this selection data + // FIXME echatellier sould be result data, but there is no such data + Iterator<String[]> catchIterator = selection.getCatch().iterator(); + catchIterator.next(); // skip header + while (catchIterator.hasNext()) { + String[] tuple = catchIterator.next(); + + String specyCode = tuple[Catch.INDEX_SPECIES]; + String specyName = speciesNames.get(specyCode); + + if (StringUtils.isNotEmpty(specyName)) { + result.put(specyCode, specyName); + } + } + + return result; + } +} Property changes on: trunk/coser-business/src/main/java/fr/ifremer/coser/services/WebService.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Modified: trunk/coser-web/pom.xml =================================================================== --- trunk/coser-web/pom.xml 2010-12-22 15:26:32 UTC (rev 440) +++ trunk/coser-web/pom.xml 2010-12-22 15:27:46 UTC (rev 441) @@ -21,6 +21,15 @@ <scope>compile</scope> </dependency> <dependency> + <groupId>log4j</groupId> + <artifactId>log4j</artifactId> + <scope>runtime</scope> + </dependency> + <dependency> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </dependency> + <dependency> <groupId>org.nuiton</groupId> <artifactId>nuiton-utils</artifactId> </dependency> Modified: trunk/coser-web/src/main/java/fr/ifremer/coser/web/CoserWebConfig.java =================================================================== --- trunk/coser-web/src/main/java/fr/ifremer/coser/web/CoserWebConfig.java 2010-12-22 15:26:32 UTC (rev 440) +++ trunk/coser-web/src/main/java/fr/ifremer/coser/web/CoserWebConfig.java 2010-12-22 15:27:46 UTC (rev 441) @@ -24,8 +24,6 @@ import static org.nuiton.i18n.I18n._; -import java.io.File; - import fr.ifremer.coser.CoserBusinessConfig; /** @@ -49,20 +47,33 @@ } /** - * Get coser web result directory. + * Get admin password. * - * @return + * @return admin password */ - public File getResultDirectory() { - File result = getOptionAsFile(CoserWebOption.RESULT_DIRECTORY.key); + public String getAdminPassword() { + String result = getOption(CoserWebOption.ADMIN_PASSWORD.key); return result; } + /** + * Get eastwood server url to use. + * + * @return eastwood context url + */ + public String getEastWoodUrl() { + String result = getOption(CoserWebOption.EASTWOOD_URL.key); + return result; + } + public enum CoserWebOption { + CONFIG_FILE(CONFIG_FILE_NAME, _("coser.config.config.file.description"), "coserweb.properties"), - RESULT_DIRECTORY("coser.web.directory", _("coser.config.config.file.description"), "${java.io.tmpdir}" + File.separator + "coserweb"); + ADMIN_PASSWORD("coser.admin.password", _("coser.config.admin.password.description"), null), + EASTWOOD_URL("coser.eastwood.url", _("coser.config.eastwood.url.description"), "http://www.ifremer.fr/eastwood"); + protected String key; protected String description; protected String defaultValue; Added: trunk/coser-web/src/main/java/fr/ifremer/coser/web/CoserWebConstants.java =================================================================== --- trunk/coser-web/src/main/java/fr/ifremer/coser/web/CoserWebConstants.java (rev 0) +++ trunk/coser-web/src/main/java/fr/ifremer/coser/web/CoserWebConstants.java 2010-12-22 15:27:46 UTC (rev 441) @@ -0,0 +1,41 @@ +/* + * #%L + * + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2010 Ifremer, Codelutin, Chatellier Eric + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser 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 Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +package fr.ifremer.coser.web; + +/** + * Constantes cote web. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public class CoserWebConstants { + + /** Nom du fichier de proprietes du serveur. */ + public static final String WEB_PROPERTIES_NAME = "web.properties"; +} Property changes on: trunk/coser-web/src/main/java/fr/ifremer/coser/web/CoserWebConstants.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: trunk/coser-web/src/main/java/fr/ifremer/coser/web/CoserWebException.java =================================================================== --- trunk/coser-web/src/main/java/fr/ifremer/coser/web/CoserWebException.java (rev 0) +++ trunk/coser-web/src/main/java/fr/ifremer/coser/web/CoserWebException.java 2010-12-22 15:27:46 UTC (rev 441) @@ -0,0 +1,59 @@ +/* + * #%L + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2010 Ifremer, Codelutin, Chatellier Eric + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +package fr.ifremer.coser.web; + +/** + * Coser web runtime exception. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public class CoserWebException extends RuntimeException { + + /** serialVersionUID. */ + private static final long serialVersionUID = -1002725698959514244L; + + /** + * Constructs a new exception with the specified detail message. + * + * @param message the detail message + */ + public CoserWebException(String message) { + super(message); + } + + /** + * Constructs a new exception with the specified detail message and cause. + * + * @param message the detail message + * @param cause the cause + */ + public CoserWebException(String message, Throwable cause) { + super(message, cause); + } + +} Property changes on: trunk/coser-web/src/main/java/fr/ifremer/coser/web/CoserWebException.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: trunk/coser-web/src/main/java/fr/ifremer/coser/web/ServiceFactory.java =================================================================== --- trunk/coser-web/src/main/java/fr/ifremer/coser/web/ServiceFactory.java (rev 0) +++ trunk/coser-web/src/main/java/fr/ifremer/coser/web/ServiceFactory.java 2010-12-22 15:27:46 UTC (rev 441) @@ -0,0 +1,75 @@ +/* + * #%L + * + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2010 Ifremer, Codelutin, Chatellier Eric + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser 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 Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +package fr.ifremer.coser.web; + +import org.nuiton.util.ArgumentsParserException; + +import fr.ifremer.coser.services.WebService; + +/** + * Coser service singleton factory. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public class ServiceFactory { + + protected static CoserWebConfig coserConfig; + + protected static WebService webService; + + /** + * Get application config configuration. + * + * @return configuration + */ + public static synchronized CoserWebConfig getCoserConfig() { + if (coserConfig == null) { + coserConfig = new CoserWebConfig(); + try { + coserConfig.parse(new String[0]); + } catch (ArgumentsParserException ex) { + throw new CoserWebException("Can't read configuration", ex); + } + } + return coserConfig; + } + + /** + * Get web service. + * + * @return web service + */ + public static synchronized WebService getWebService() { + if (webService == null) { + webService = new WebService(getCoserConfig()); + } + return webService; + } +} Property changes on: trunk/coser-web/src/main/java/fr/ifremer/coser/web/ServiceFactory.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Modified: trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/IndexAction.java =================================================================== --- trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/IndexAction.java 2010-12-22 15:26:32 UTC (rev 440) +++ trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/IndexAction.java 2010-12-22 15:27:46 UTC (rev 441) @@ -23,14 +23,18 @@ package fr.ifremer.coser.web.actions; import java.io.File; -import java.util.ArrayList; -import java.util.List; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.Date; +import java.util.Properties; -import org.nuiton.util.ArgumentsParserException; - import com.opensymphony.xwork2.ActionSupport; import fr.ifremer.coser.web.CoserWebConfig; +import fr.ifremer.coser.web.CoserWebConstants; +import fr.ifremer.coser.web.CoserWebException; +import fr.ifremer.coser.web.ServiceFactory; /** * Action index, recupere la liste des resultats. @@ -46,31 +50,34 @@ /** serialVersionUID. */ private static final long serialVersionUID = 1663244944108703571L; - protected List<String> results; + protected Date dataUpdateDate; - public List<String> getResults() { - return results; + public Date getDataUpdateDate() { + return dataUpdateDate; } @Override public String execute() { + + CoserWebConfig config = ServiceFactory.getCoserConfig(); + File webProperties = new File(config.getWebServerDirectory(), CoserWebConstants.WEB_PROPERTIES_NAME); - CoserWebConfig config = new CoserWebConfig(); + // get update date + Properties props = new Properties(); try { - config.parse(new String[]{}); - } catch (ArgumentsParserException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } + props.load(new FileInputStream(webProperties)); - File directory = config.getResultDirectory(); - File[] subDirectories = directory.listFiles(); + if (props.containsKey("updateDate")) { + String date = props.getProperty("updateDate"); + long time = Long.parseLong(date); + dataUpdateDate = new Date(time); + } + else { + dataUpdateDate = new Date(0); + } - results = new ArrayList<String>(); - for (File subDirectory : subDirectories) { - if (subDirectory.isDirectory()) { - results.add(subDirectory.getName()); - } + } catch (IOException ex) { + throw new CoserWebException("Can't save properties file", ex); } return SUCCESS; Modified: trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/SelectIndicatorAction.java =================================================================== --- trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/SelectIndicatorAction.java 2010-12-22 15:26:32 UTC (rev 440) +++ trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/SelectIndicatorAction.java 2010-12-22 15:27:46 UTC (rev 441) @@ -22,15 +22,10 @@ package fr.ifremer.coser.web.actions; -import java.io.File; import java.util.List; -import org.nuiton.util.ArgumentsParserException; - import com.opensymphony.xwork2.ActionSupport; -import fr.ifremer.coser.web.CoserWebConfig; - /** * Action index, recupere la liste des resultats. * @@ -67,20 +62,7 @@ @Override public String execute() { - - CoserWebConfig config = new CoserWebConfig(); - try { - config.parse(new String[]{}); - } catch (ArgumentsParserException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - File directory = config.getResultDirectory(); - File resultDirectory = new File(directory, result); - - - return SUCCESS; } } Added: trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/SelectSpeciesAction.java =================================================================== --- trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/SelectSpeciesAction.java (rev 0) +++ trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/SelectSpeciesAction.java 2010-12-22 15:27:46 UTC (rev 441) @@ -0,0 +1,90 @@ +/* + * #%L + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2010 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; + +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 SelectSpeciesAction extends ActionSupport { + + /** serialVersionUID. */ + private static final long serialVersionUID = 1663244944108703571L; + + private static final Log log = LogFactory.getLog(SelectSpeciesAction.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 e) { + throw new CoserWebException("Can't get zone species"); + } + + return SUCCESS; + } +} Property changes on: trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/SelectSpeciesAction.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/SelectZoneAction.java =================================================================== --- trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/SelectZoneAction.java (rev 0) +++ trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/SelectZoneAction.java 2010-12-22 15:27:46 UTC (rev 441) @@ -0,0 +1,46 @@ +/* + * #%L + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2010 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; + +import com.opensymphony.xwork2.ActionSupport; + +/** + * Action index, affiche une liste fixe de 10 zones. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public class SelectZoneAction extends ActionSupport { + + /** serialVersionUID. */ + private static final long serialVersionUID = 3385467755357775199L; + + @Override + public String execute() { + + return SUCCESS; + } +} Property changes on: trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/SelectZoneAction.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Modified: trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/UploadResultAction.java =================================================================== --- trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/UploadResultAction.java 2010-12-22 15:26:32 UTC (rev 440) +++ trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/UploadResultAction.java 2010-12-22 15:27:46 UTC (rev 441) @@ -23,51 +23,121 @@ package fr.ifremer.coser.web.actions; import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.Date; +import java.util.Properties; -import com.opensymphony.xwork2.ActionSupport; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import com.opensymphony.xwork2.Action; + +import fr.ifremer.coser.CoserBusinessException; +import fr.ifremer.coser.services.WebService; +import fr.ifremer.coser.web.CoserWebConfig; +import fr.ifremer.coser.web.CoserWebConstants; +import fr.ifremer.coser.web.CoserWebException; +import fr.ifremer.coser.web.ServiceFactory; + /** + * Upload results action. * + * Cette action est appelée par l'interface swing cliente. + * * @author chatellier * @version $Revision$ * * Last update : $Date$ * By : $Author$ */ -public class UploadResultAction extends ActionSupport { +public class UploadResultAction implements Action { /** serialVersionUID. */ private static final long serialVersionUID = 3887268253160622587L; - protected File resultFile; - - protected File resultFileFileName; + private static final Log log = LogFactory.getLog(UploadResultAction.class); + private File resultFile; + + private String password; + public void setResultFile(File resultFile) { + System.out.println("resultFile = " + resultFile); this.resultFile = resultFile; } + public void setPassword(String password) { + this.password = password; + } + public File getResultFile() { return resultFile; } - public File getResultFileFileName() { - return resultFileFileName; + public String getPassword() { + return password; } - public void setResultFileFileName(File resultFileFileName) { - this.resultFileFileName = resultFileFileName; - } + public String execute() { - //@Action(params={"allowedTypes", "application/zip"}) - public String execute() { - if (resultFile == null) { - System.out.println("File size = " + null); - return INPUT; + // check + CoserWebConfig config = ServiceFactory.getCoserConfig(); + if (config.getAdminPassword() == null) { + if (log.isWarnEnabled()) { + log.warn("No admin password set, cannot enable result upload"); + } } else { - System.out.println("File size = " + resultFile.length()); - return SUCCESS; + + if (config.getAdminPassword().equals(password)) { + if (resultFile != null) { + WebService webService = ServiceFactory.getWebService(); + try { + webService.registerNewUploadedResults(resultFile); + + updateDataProperties(); + } catch (CoserBusinessException ex) { + throw new CoserWebException("Can't register new result file", ex); + } + return SUCCESS; + } + else { + if (log.isWarnEnabled()) { + log.warn("File is null"); + } + } + } + else { + if (log.isWarnEnabled()) { + log.warn("Wrong password"); + } + } } + + return INPUT; } + + /** + * Met à jour certaines proprietes apres la mise à jour des données. + */ + protected void updateDataProperties() { + + CoserWebConfig config = ServiceFactory.getCoserConfig(); + File webProperties = new File(config.getWebServerDirectory(), CoserWebConstants.WEB_PROPERTIES_NAME); + + Properties props = new Properties(); + try { + props.load(new FileInputStream(webProperties)); + + props.setProperty("updateDate", String.valueOf(new Date().getTime())); + props.store(new FileOutputStream(webProperties), "Update data"); + } catch (IOException ex) { + throw new CoserWebException("Can't save properties file", ex); + } + + + } } Deleted: trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/WelcomeUserAction.java =================================================================== --- trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/WelcomeUserAction.java 2010-12-22 15:26:32 UTC (rev 440) +++ trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/WelcomeUserAction.java 2010-12-22 15:27:46 UTC (rev 441) @@ -1,64 +0,0 @@ -/* - * #%L - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2010 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; - -import com.opensymphony.xwork2.ActionSupport; - -/** - * TODO add comment here. - * - * @author chatellier - * @version $Revision$ - * - * Last update : $Date$ - * By : $Author$ - */ -public class WelcomeUserAction extends ActionSupport { - - /** serialVersionUID. */ - private static final long serialVersionUID = 3887268253160622587L; - - private String userName; - private String message; - - public String execute() { - message = "Welcome " + userName; - return SUCCESS; - } - - public void setUserName(String userName) { - this.userName = userName; - } - - public void setMessage(String message) { - this.message = message; - } - - public String getUserName() { - return userName; - } - - public String getMessage() { - return message; - } -} Modified: trunk/coser-web/src/main/resources/i18n/coser-web_en_GB.properties =================================================================== --- trunk/coser-web/src/main/resources/i18n/coser-web_en_GB.properties 2010-12-22 15:26:32 UTC (rev 440) +++ trunk/coser-web/src/main/resources/i18n/coser-web_en_GB.properties 2010-12-22 15:27:46 UTC (rev 441) @@ -1 +1,3 @@ +coser.config.admin.password.description= coser.config.config.file.description= +coser.config.eastwood.url.description= Modified: trunk/coser-web/src/main/resources/i18n/coser-web_fr_FR.properties =================================================================== --- trunk/coser-web/src/main/resources/i18n/coser-web_fr_FR.properties 2010-12-22 15:26:32 UTC (rev 440) +++ trunk/coser-web/src/main/resources/i18n/coser-web_fr_FR.properties 2010-12-22 15:27:46 UTC (rev 441) @@ -1 +1,3 @@ +coser.config.admin.password.description= coser.config.config.file.description= +coser.config.eastwood.url.description= Added: trunk/coser-web/src/main/resources/log4j.properties =================================================================== --- trunk/coser-web/src/main/resources/log4j.properties (rev 0) +++ trunk/coser-web/src/main/resources/log4j.properties 2010-12-22 15:27:46 UTC (rev 441) @@ -0,0 +1,35 @@ +### +# #%L +# +# +# $Id$ +# $HeadURL$ +# %% +# Copyright (C) 2010 Ifremer, Codelutin, Chatellier Eric +# %% +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser 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 Lesser Public License for more details. +# +# You should have received a copy of the GNU General Lesser Public +# License along with this program. If not, see +# <http://www.gnu.org/licenses/lgpl-3.0.html>. +# #L% +### + +# Global logging configuration +log4j.rootLogger=ERROR, stdout + +# Console output +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%d{HH:mm:ss} %-5p %c:%L - %m%n + +# Categories +log4j.category.fr.ifremer.coser=INFO Added: trunk/coser-web/src/main/resources/struts.xml =================================================================== --- trunk/coser-web/src/main/resources/struts.xml (rev 0) +++ trunk/coser-web/src/main/resources/struts.xml 2010-12-22 15:27:46 UTC (rev 441) @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> +<struts> + <constant name="struts.multipart.maxSize" value="100097152"/> + + +</struts> Added: trunk/coser-web/src/main/webapp/WEB-INF/content/footer.jsp =================================================================== --- trunk/coser-web/src/main/webapp/WEB-INF/content/footer.jsp (rev 0) +++ trunk/coser-web/src/main/webapp/WEB-INF/content/footer.jsp 2010-12-22 15:27:46 UTC (rev 441) @@ -0,0 +1,29 @@ +<!-- + #%L + Coser :: Web + + $Id$ + $HeadURL$ + %% + Copyright (C) 2010 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% + --> +<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> +<%@taglib uri="/struts-tags" prefix="s" %> + + <div> + Copyright 2010 Ifremer + </div> \ No newline at end of file Added: trunk/coser-web/src/main/webapp/WEB-INF/content/header.jsp =================================================================== --- trunk/coser-web/src/main/webapp/WEB-INF/content/header.jsp (rev 0) +++ trunk/coser-web/src/main/webapp/WEB-INF/content/header.jsp 2010-12-22 15:27:46 UTC (rev 441) @@ -0,0 +1,33 @@ +<!-- + #%L + Coser :: Web + + $Id$ + $HeadURL$ + %% + Copyright (C) 2010 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% + --> +<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> +<%@taglib uri="/struts-tags" prefix="s" %> + + <div> + <img src="images/logo_sih.gif" /> + <img src="images/logo_ifremer.gif" /> + </div> + + <hr /> + Modified: trunk/coser-web/src/main/webapp/WEB-INF/content/index.jsp =================================================================== --- trunk/coser-web/src/main/webapp/WEB-INF/content/index.jsp 2010-12-22 15:26:32 UTC (rev 440) +++ trunk/coser-web/src/main/webapp/WEB-INF/content/index.jsp 2010-12-22 15:27:46 UTC (rev 441) @@ -27,21 +27,64 @@ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> - <title>Hello World</title> + <title>Coser</title> + <link rel="stylesheet" type="text/css" href="styles/coser.css" /> </head> <body> - <s:form action="upload-result" method="post" enctype="multipart/form-data"> - <s:actionerror /> - <s:file name="resultFile" label="Result archive" /> - <s:submit /> - </s:form> - <s:form action="welcome-user"> - <s:textfield name="userName" label="User Name" /> - <s:submit /> - </s:form> - <hr /> - <s:form action="select-indicator"> - <s:select name="result" list="results" label="Result name"/> - </s:form> + <h2>Indices de populations et de communauté issus des campagnes de surveillance halieutique de l'Ifremer</h2> + + <p>Ce site présente des indices de populations et de communauté calculés à partir des + données du réseau des campagnes de surveillance halieutiques opérées par l'Ifremer + en mer du Nord, Manche, Atlantique et Méditerranée. + Il contient des informations relatives à 15 séries de campagnes</p> + + <a href="http://www.ifremer.fr/SIH-indices-campagnes/fichiers/Web_EstPopInd_Presentat..." + target="_blank">Les campagnes de surveillance halieutique de l'Ifremer</a> + + <h3>Les indices de populations et de communauté</h3> + <ul> + <li>10 indices de populations et 4 indices de communauté</li> + <li>168 taxons pris en compte</li> + </ul> + + <table> + <tr> + <td>Informations sur les</td> + <td>populations</td> + <td>/</td> + <td>Communautés</td> + </tr> + <tr> + <td>Les indices calculés</td> + <td> + <a href="http://www.ifremer.fr/SIH-indices-campagnes/fichiers/Web_EstPopInd_PresentationIndic_FR.pdf">X</a> + </td> + <td /> + <td> + <a href="http://www.ifremer.fr/SIH-indices-campagnes/fichiers/Web_EstComInd_PresentationIndic_FR.pdf">X</a> + </td> + </tr> + <tr> + <td>Accès aux données</td> + <td> + <s:a action="select-zone">X</s:a> + </td> + <td /> + <td> + <s:a action="select-zone">X</s:a> + </td> + </tr> + </table> + + <p><b>Pour citer ce site :</b> Ifremer <s:date name="dataUpdateDate" format="yyyy" />. Indices de populations et de communautés + issus des campagnes de surveillance halieutique de l'Ifremer. + http://www.ifremer.fr/SIH-indices-campagnes/ <s:date name="dataUpdateDate" format="dd MMMM" />.</p> + + <p>Gestion des données des campagnes océanographiques : + <ul> + <li><a href="http://www.ifremer.fr/sismer/index_FR.htm">le Système d'informations scientifiques pour la mer de l'Ifremer (SISMER)</a></li> + <li><a href="http://www.ifremer.fr/sih">le Système d'information halieutique de l'Ifremer (SIH)</a></li> + </ul></p> + </body> </html> \ No newline at end of file Added: trunk/coser-web/src/main/webapp/WEB-INF/content/select-species.jsp =================================================================== --- trunk/coser-web/src/main/webapp/WEB-INF/content/select-species.jsp (rev 0) +++ trunk/coser-web/src/main/webapp/WEB-INF/content/select-species.jsp 2010-12-22 15:27:46 UTC (rev 441) @@ -0,0 +1,50 @@ +<!-- + #%L + Coser :: Web + + $Id$ + $HeadURL$ + %% + Copyright (C) 2010 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% + --> +<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<%@taglib uri="/struts-tags" prefix="s" %> + +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr"> + <head> + <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> + <title>Coser</title> + <link rel="stylesheet" type="text/css" href="styles/coser.css" /> + </head> + <body> + + <%@ include file="header.jsp" %> + + <img src="images/zonesmap.jpg" /> + + <br /> + + <s:form action="select-indicator"> + + <s:select name="species" list="species" label="Select a country" /> + <s:hidden name="zone" value="zone" /> + </s:form> + + <%@ include file="footer.jsp" %> + </body> +</html> \ No newline at end of file Added: trunk/coser-web/src/main/webapp/WEB-INF/content/select-zone.jsp =================================================================== --- trunk/coser-web/src/main/webapp/WEB-INF/content/select-zone.jsp (rev 0) +++ trunk/coser-web/src/main/webapp/WEB-INF/content/select-zone.jsp 2010-12-22 15:27:46 UTC (rev 441) @@ -0,0 +1,63 @@ +<!-- + #%L + Coser :: Web + + $Id$ + $HeadURL$ + %% + Copyright (C) 2010 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% + --> +<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<%@taglib uri="/struts-tags" prefix="s" %> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr"> + <head> + <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> + <title>Coser</title> + <link rel="stylesheet" type="text/css" href="styles/coser.css" /> + </head> + <body> + + <%@ include file="header.jsp" %> + + <img src="images/zonesmap.jpg" /> + + <br /> + + <s:form action="select-species"> + <select name="zone"> + <option value="manchecgfs">Plateau - Manche CGFS</option> + <option value="celtiqueevhoe">Plateau - Celtique EVHOE</option> + <option value="gascogneevhoe">Plateau - Gascogne EVHOE</option> + <option value="gascogneressgasc01">Plateau - Gascogne RESSGASC_01</option> + <option value="gascogneressgasc02">Plateau - Gascogne RESSGASC_02</option> + <option value="gascogneressgasc03">Plateau - Gascogne RESSGASC_03</option> + <option value="gascogneressgasc04">Plateau - Gascogne RESSGASC_04</option> + <option value="lionmedtis">Plateau - Lion MEDITS</option> + <option value="estcorsemedits">Plateau - Est-Corse MEDITS</option> + <option value="sommenoursom">Baie - Somme NOURSOM</option> + <option value="seinenoursei">Baie - Seine NOURSEI</option> + <option value="vilainenourvil">Baie - Vilaine NOURVIL</option> + <option value="crustaflamjuin">Cap - Flamanville CRUSTAFLAM Juin</option> + <option value="crustaflamsept">Cap - Flamanville CRUSTAFLAM Septembre</option> + </select> + <s:submit label="Suite"/> + </s:form> + + <%@ include file="footer.jsp" %> + </body> +</html> \ No newline at end of file Modified: trunk/coser-web/src/main/webapp/WEB-INF/content/upload-result.jsp =================================================================== --- trunk/coser-web/src/main/webapp/WEB-INF/content/upload-result.jsp 2010-12-22 15:26:32 UTC (rev 440) +++ trunk/coser-web/src/main/webapp/WEB-INF/content/upload-result.jsp 2010-12-22 15:27:46 UTC (rev 441) @@ -35,6 +35,7 @@ <s:form action="upload-result" method="post" enctype="multipart/form-data"> <s:actionerror /> <s:file name="resultFile" label="Result archive" /> + <s:textfield name="password" label="Password" /> <s:submit /> </s:form> </body> Deleted: trunk/coser-web/src/main/webapp/WEB-INF/content/welcome-user.jsp =================================================================== --- trunk/coser-web/src/main/webapp/WEB-INF/content/welcome-user.jsp 2010-12-22 15:26:32 UTC (rev 440) +++ trunk/coser-web/src/main/webapp/WEB-INF/content/welcome-user.jsp 2010-12-22 15:27:46 UTC (rev 441) @@ -1,35 +0,0 @@ -<!-- - #%L - Coser :: Web - - $Id$ - $HeadURL$ - %% - Copyright (C) 2010 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% - --> -<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> -<%@taglib uri="/struts-tags" prefix="s" %> -<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr"> - <head> - <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> - <title>Welcome User</title> - </head> - <body> - <h1>Hi : ${message}</h1> - </body> -</html> \ No newline at end of file Added: trunk/coser-web/src/main/webapp/images/logo_ifremer.gif =================================================================== (Binary files differ) Property changes on: trunk/coser-web/src/main/webapp/images/logo_ifremer.gif ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: trunk/coser-web/src/main/webapp/images/logo_sih.gif =================================================================== (Binary files differ) Property changes on: trunk/coser-web/src/main/webapp/images/logo_sih.gif ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: trunk/coser-web/src/main/webapp/images/zonesmap.jpg =================================================================== (Binary files differ) Property changes on: trunk/coser-web/src/main/webapp/images/zonesmap.jpg ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: trunk/coser-web/src/main/webapp/styles/coser.css =================================================================== --- trunk/coser-web/src/main/webapp/styles/coser.css (rev 0) +++ trunk/coser-web/src/main/webapp/styles/coser.css 2010-12-22 15:27:46 UTC (rev 441) @@ -0,0 +1,13 @@ +body { + background-color: #1F7DCB; + color: #2A2A2A; +} + +a { + color: #2C9FF; +} + +a:hover { + color: #165A97; +} +