Author: chatellier Date: 2011-01-06 14:26:08 +0000 (Thu, 06 Jan 2011) New Revision: 478 Log: Affichage des traductions des indicateurs Modified: trunk/coser-business/src/main/java/fr/ifremer/coser/CoserBusinessConfig.java trunk/coser-business/src/main/java/fr/ifremer/coser/services/ImportService.java trunk/coser-business/src/main/java/fr/ifremer/coser/services/WebService.java trunk/coser-business/src/test/java/fr/ifremer/coser/services/ProjectServiceTest.java trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/pop/IndicatorAction.java Modified: trunk/coser-business/src/main/java/fr/ifremer/coser/CoserBusinessConfig.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/CoserBusinessConfig.java 2011-01-06 13:19:35 UTC (rev 477) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/CoserBusinessConfig.java 2011-01-06 14:26:08 UTC (rev 478) @@ -166,7 +166,7 @@ /** Server side. */ WEB_SERVER_DIRECTORY("coser.web.server.directory", _("coser.config.web.server.directory.description"), "${" + DATABASE_DIRECTORY.key + "}" + File.separator + "web", String.class, false, false), WEB_PROJECTS_DIRECTORY("coser.web.projects.directory", _("coser.config.web.projects.directory.description"), "${" + WEB_SERVER_DIRECTORY.key + "}" + File.separator + "projects", String.class, false, false), - WEB_MATCH_INDICATORS("coser.web.matchindicators.file", _("coser.config.web.matchindicators.file.description"), "${" + WEB_SERVER_DIRECTORY.key + "}" + File.separator + "correspondanceindicateurs.txt", String.class, false, false), + WEB_MATCH_INDICATORS("coser.web.matchindicators.file", _("coser.config.web.matchindicators.file.description"), "${" + WEB_SERVER_DIRECTORY.key + "}" + File.separator + "matchindicators.csv", String.class, false, false), WEB_MATCH_ZONES("coser.web.matchzones.file", _("coser.config.web.matchzones.file.description"), "${" + WEB_SERVER_DIRECTORY.key + "}" + File.separator + "correspondancezones.txt", String.class, false, false); protected String key; Modified: trunk/coser-business/src/main/java/fr/ifremer/coser/services/ImportService.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/services/ImportService.java 2011-01-06 13:19:35 UTC (rev 477) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/services/ImportService.java 2011-01-06 14:26:08 UTC (rev 478) @@ -327,18 +327,32 @@ return content; } - + /** - * Charge un fichier de résultat (estcomind/estpopind). C'est a peu pret - * le meme code qu'au dessus, sauf que le storage est simplement retourné - * et que les séparateurs ne sont pas les même. + * Charge un fichier csv (estcomind/estpopind ...) mais sans verification. + * C'est a peu pret le meme code qu'au dessus, sauf que le storage est + * simplement retourné et que les séparateurs ne sont pas les même. * * @param file file to load * @return data storage with file content * @throws CoserBusinessException */ - public DataStorage loadResultCSVFile(File file) throws CoserBusinessException { + public DataStorage loadCSVFile(File file) throws CoserBusinessException { + return loadCSVFile(file, CoserConstants.CSV_SEPARATOR_CHAR); + } + /** + * Charge un fichier csv (estcomind/estpopind ...) mais sans verification. + * C'est a peu pret le meme code qu'au dessus, sauf que le storage est + * simplement retourné et que les séparateurs ne sont pas les même. + * + * @param file file to load + * @param separator separator to use to load file + * @return data storage with file content + * @throws CoserBusinessException + */ + public DataStorage loadCSVFile(File file, char separator) throws CoserBusinessException { + DataStorage content = new MemoryDataStorage(); CSVReader csvReader = null; @@ -346,7 +360,7 @@ InputStream stream = new FileInputStream(file); Reader reader = new BufferedReader(new InputStreamReader(stream, CoserConstants.CSV_FILE_ENCODING)); - csvReader = new CSVReader(reader, CoserConstants.CSV_RESULT_SEPARATOR_CHAR); + csvReader = new CSVReader(reader, separator); // check header String[] line = csvReader.readNext(); 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-06 13:19:35 UTC (rev 477) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/services/WebService.java 2011-01-06 14:26:08 UTC (rev 478) @@ -34,6 +34,7 @@ import java.util.Map; import java.util.TreeMap; +import org.apache.commons.collections.map.MultiKeyMap; import org.apache.commons.io.FileUtils; import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; @@ -52,6 +53,10 @@ /** * Service specifique à l'interface web de visualisation. * + * Ce service, contrairement au autre a un état, les indicateurs et zones + * chargées persistent apres chargement, car elle ne peuvent pas changer + * tant que l'application est a cours d'utilisation. + * * @author chatellier * @version $Revision$ * @@ -68,6 +73,9 @@ protected ProjectService projectService; + /** Indicator map (fr, en) (etat du service). */ + protected MultiKeyMap indicatorMap; + public WebService(CoserBusinessConfig config) { this.config = config; @@ -76,6 +84,31 @@ } /** + * Charge les indicateurs disponible depuis le fichier des indicateurs. + * (indid, indname) + * + * @return default indicators + * @throws CoserBusinessException + */ + protected MultiKeyMap getDefaultIndicators() throws CoserBusinessException { + + if (indicatorMap == null) { + indicatorMap = new MultiKeyMap(); + File indicatorFile = config.getMatchIndicatorsFile(); + DataStorage indicatorStorage = importService.loadCSVFile(indicatorFile); + Iterator<String[]> iteratorInd = indicatorStorage.iterator(true); + while(iteratorInd.hasNext()) { + // "id";"label_fr";"label_en" + String[] indicator = iteratorInd.next(); + indicatorMap.put(indicator[0], "fr", indicator[1]); + indicatorMap.put(indicator[0], "en", indicator[2]); + } + } + + return indicatorMap; + } + + /** * Traite le fichier uploade par l'application client et l'enregistre * dans le stockage coté web. * @@ -247,6 +280,7 @@ Map<String, String> result = new TreeMap<String, String>(); + // parcours des resultats disponibles File projectsDirectory = config.getWebProjectsDirectory(); File[] projectFiles = projectsDirectory.listFiles(); @@ -321,7 +355,7 @@ File estPopIndFile = new File(resultDirectory, rsufiResult.getEstPopIndName()); // Campagne Indicateur Liste Espece Strate Annee Estimation EcartType CV - DataStorage dataStorage = importService.loadResultCSVFile(estPopIndFile); + DataStorage dataStorage = importService.loadCSVFile(estPopIndFile, CoserConstants.CSV_RESULT_SEPARATOR_CHAR); Iterator<String[]> estPopIndIterator = dataStorage.iterator(); estPopIndIterator.next(); // skip header @@ -340,14 +374,16 @@ } /** - * Retourne les indicateurs calculés. + * Retourne les indicateurs calculés avec leurs traductions scientifique + * pour la zone et l'especes souhaitées. * * @param zone zone * @param species especes + * @param locale locale ({@code fr} ou {@code en}) * @return la liste des indicateurs * @throws CoserBusinessException */ - public Map<String, String> getIndicators(String zone, String species) throws CoserBusinessException { + public Map<String, String> getIndicators(String zone, String species, String locale) throws CoserBusinessException { Map<String, String> indicators = new TreeMap<String, String>(); // parcours des resultats disponibles @@ -360,19 +396,19 @@ for (Selection selection : project.getSelections().values()) { boolean resultFound = false; - + for (RSufiResult rsufiResult : selection.getRsufiResults()) { - + // extraction des especes pour le résultat demandé if (rsufiResult.getZone() != null && rsufiResult.getZone().equals(zone)) { // data loading not necessary here - Map<String, String> resultIndicators = getRsufiResultIndicators(project, selection, rsufiResult, species); + Map<String, String> resultIndicators = getRsufiResultIndicators(project, selection, rsufiResult, species, locale); indicators.putAll(resultIndicators); resultFound = true; break; } } - + if (resultFound) { break; } @@ -388,15 +424,19 @@ * Recupere la liste de toutes les especes nom sci et nom off à partir * d'un resultat. * - * @param project - * @param selection - * @param rsufiResult + * @param project project + * @param selection selection + * @param rsufiResult result * @param species to get indicator + * @param locale locale ({@code fr} ou {@code en}) * @return indicator for species * @throws CoserBusinessException */ protected Map<String, String> getRsufiResultIndicators(Project project, - Selection selection, RSufiResult rsufiResult, String species) throws CoserBusinessException { + Selection selection, RSufiResult rsufiResult, String species, String locale) throws CoserBusinessException { + + MultiKeyMap defaultIndicators = getDefaultIndicators(); + Map<String, String> result = new HashMap<String, String>(); // on peu lours mais reconstruit le path jusqu'au fichier estcomind @@ -411,7 +451,7 @@ File estPopIndFile = new File(resultDirectory, rsufiResult.getEstPopIndName()); // Campagne Indicateur Liste Espece Strate Annee Estimation EcartType CV - DataStorage dataStorage = importService.loadResultCSVFile(estPopIndFile); + DataStorage dataStorage = importService.loadCSVFile(estPopIndFile, CoserConstants.CSV_RESULT_SEPARATOR_CHAR); Iterator<String[]> estPopIndIterator = dataStorage.iterator(); estPopIndIterator.next(); // skip header @@ -420,9 +460,13 @@ String specyCode = tuple[3]; if (specyCode.equals(species)) { - + String indicatorCode = tuple[1]; - result.put(indicatorCode, indicatorCode); + String translations = (String)defaultIndicators.get(indicatorCode, locale.toLowerCase()); + if (translations == null) { + translations = "##" + indicatorCode + "##"; + } + result.put(indicatorCode, translations); } } Modified: trunk/coser-business/src/test/java/fr/ifremer/coser/services/ProjectServiceTest.java =================================================================== --- trunk/coser-business/src/test/java/fr/ifremer/coser/services/ProjectServiceTest.java 2011-01-06 13:19:35 UTC (rev 477) +++ trunk/coser-business/src/test/java/fr/ifremer/coser/services/ProjectServiceTest.java 2011-01-06 14:26:08 UTC (rev 478) @@ -114,7 +114,7 @@ Project projectValidated = openTestProject(projectService, "projectctrvalidated"); // ce projet a un control validé Assert.assertTrue(projectValidated.getControl().isValidated()); - + // la selection Selection selection = projectValidated.getSelections().get("testselection1"); Assert.assertNotNull(selection); @@ -131,7 +131,6 @@ // non validé Project projectNotValidated = openTestProject(projectService, "project2"); Assert.assertFalse(projectNotValidated.getControl().isValidated()); - } /** Modified: trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/pop/IndicatorAction.java =================================================================== --- trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/pop/IndicatorAction.java 2011-01-06 13:19:35 UTC (rev 477) +++ trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/pop/IndicatorAction.java 2011-01-06 14:26:08 UTC (rev 478) @@ -22,6 +22,7 @@ package fr.ifremer.coser.web.actions.pop; +import java.util.Locale; import java.util.Map; import org.apache.commons.logging.Log; @@ -85,8 +86,11 @@ WebService webService = ServiceFactory.getWebService(); + Locale locale = getLocale(); + String localeCode = locale.getLanguage(); + try { - indicators = webService.getIndicators(zone, species); + indicators = webService.getIndicators(zone, species, localeCode); } catch (CoserBusinessException ex) { throw new CoserWebException("Can't get indicators", ex); }
participants (1)
-
chatellier@users.labs.libre-entreprise.org