Author: echatellier Date: 2012-01-03 15:55:42 +0100 (Tue, 03 Jan 2012) New Revision: 937 Url: http://forge.codelutin.com/repositories/revision/coser/937 Log: Autoselection des listes L1 ?\195?\160 L4 lors du replay. Ajout de tests. Modified: trunk/coser-business/src/main/java/fr/ifremer/coser/services/ProjectService.java trunk/coser-business/src/test/java/fr/ifremer/coser/services/ProjectServiceTest.java trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/SelectionHandler.java trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/replay/SelectionReplayHandler.java Modified: trunk/coser-business/src/main/java/fr/ifremer/coser/services/ProjectService.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/services/ProjectService.java 2012-01-03 14:55:01 UTC (rev 936) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/services/ProjectService.java 2012-01-03 14:55:42 UTC (rev 937) @@ -5,7 +5,7 @@ * $Id$ * $HeadURL$ * %% - * Copyright (C) 2010 - 2011 Ifremer, Codelutin, Chatellier Eric + * Copyright (C) 2010 - 2012 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 @@ -59,6 +59,7 @@ import org.apache.commons.beanutils.PropertyUtils; import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.collections.ListUtils; import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; @@ -2138,8 +2139,10 @@ * if(language==2) tab=cbind(Strate=dimnames(haulcount)[[1]],haulcount) * else tab=cbind(Stratum=dimnames(haulcount)[[1]],haulcount) * - * @param project - * @param selection + * Can return {@code null} if there is not enought data to build matrix. + * + * @param project project + * @param selection selection * @return sampling effort as matrix */ public MatrixND getSamplingEffort(Project project, Selection selection) { @@ -2177,15 +2180,18 @@ } List<String> lineNames2 = new ArrayList<String>(lineNames); - Collections.sort(lineNames2); List<String> columnsNames2 = new ArrayList<String>(columns); - Collections.sort(columnsNames2); - MatrixND matrix = MatrixFactory.getInstance().create(n_("coser.business.matrix.samplingeffort"), new List<?>[] { - lineNames2 , columnsNames2}); + MatrixND matrix = null; + if (!lineNames2.isEmpty() && !columnsNames2.isEmpty()) { + Collections.sort(lineNames2); + Collections.sort(columnsNames2); + matrix = MatrixFactory.getInstance().create(n_("coser.business.matrix.samplingeffort"), new List<?>[] { + lineNames2 , columnsNames2}); - for (Map.Entry<String, Map<String, Double>> dynMatrixEntry : dynMatrix.entrySet()) { - for (Map.Entry<String, Double> haulCountForYearEntry : dynMatrixEntry.getValue().entrySet()) { - matrix.setValue(dynMatrixEntry.getKey(), haulCountForYearEntry.getKey(), haulCountForYearEntry.getValue()); + for (Map.Entry<String, Map<String, Double>> dynMatrixEntry : dynMatrix.entrySet()) { + for (Map.Entry<String, Double> haulCountForYearEntry : dynMatrixEntry.getValue().entrySet()) { + matrix.setValue(dynMatrixEntry.getKey(), haulCountForYearEntry.getKey(), haulCountForYearEntry.getValue()); + } } } @@ -2894,6 +2900,7 @@ * @param strataCollection starta collection to get haul * @return haul collection * @throws CoserBusinessException + * @since 1.1 */ public List<Coordinate> getStrataHaulCoordinate(Selection selection, Collection<String> strataCollection) throws CoserBusinessException { @@ -2940,6 +2947,7 @@ * selectionner une selection pour la rejouer dans l'ui. * * @return all selections + * @since 1.2 */ public SortedMap<String, List<String>> getSelectionByProject() { SortedMap<String, List<String>> selectionByProject = new TreeMap<String, List<String>>(); @@ -2983,7 +2991,8 @@ * @param projectName project containing selection * @param selectionName selection name to open in project * @return opened selection - * @throws CoserBusinessException + * @throws CoserBusinessException + * @since 1.2 */ public Selection openSelection(String projectName, String selectionName) throws CoserBusinessException { File projectsDirectory = config.getProjectsDirectory(); @@ -3023,4 +3032,32 @@ } return selection; } + + /** + * Definie dans la selection les listes L2 à L4 avec les 3 listes + * en parametres. + * Fait attention a ne pas conserver dans les listes des especes qui + * ne sont pas dans la liste L1 (liste de toutes les especes). + * + * @param selection + * @param selectedSpeciesOccDens + * @param selectedSpeciesSizeAllYear + * @param selectedSpeciesMaturity + * @since 1.2 + */ + public void fillListsSelection(Selection selection, List<String> selectedSpeciesOccDens, + List<String> selectedSpeciesSizeAllYear, List<String> selectedSpeciesMaturity) { + + List<String> allSpecies = selection.getSelectedSpecies(); + + // filters species that doesn't exists anymore + List<String> localSpeciesOccDens = ListUtils.retainAll(selectedSpeciesOccDens, allSpecies); + List<String> localSpeciesSizeAllYear = ListUtils.retainAll(selectedSpeciesSizeAllYear, allSpecies); + List<String> localSpeciesMaturity = ListUtils.retainAll(selectedSpeciesMaturity, allSpecies); + + // save lists + selection.setSelectedSpeciesOccDens(localSpeciesOccDens); + selection.setSelectedSpeciesSizeAllYear(localSpeciesSizeAllYear); + selection.setSelectedSpeciesMaturity(localSpeciesMaturity); + } } 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 2012-01-03 14:55:01 UTC (rev 936) +++ trunk/coser-business/src/test/java/fr/ifremer/coser/services/ProjectServiceTest.java 2012-01-03 14:55:42 UTC (rev 937) @@ -5,7 +5,7 @@ * $Id$ * $HeadURL$ * %% - * Copyright (C) 2010 Ifremer, Codelutin, Chatellier Eric + * Copyright (C) 2010 - 2012 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 @@ -28,9 +28,11 @@ import java.io.File; import java.io.IOException; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Properties; import org.junit.Assert; @@ -48,6 +50,7 @@ import fr.ifremer.coser.command.DeleteLineCommand; import fr.ifremer.coser.command.MergeSpeciesCommand; import fr.ifremer.coser.command.ModifyFieldCommand; +import fr.ifremer.coser.util.Coordinate; /** * Project service tests. @@ -483,4 +486,70 @@ Assert.assertEquals(38.5, projectService.getHalfStepValue(38.999), 0.00001); Assert.assertEquals(42.5, projectService.getHalfStepValue(42.745), 0.00001); } + + /** + * Test la recuperation des coordonnées des strates. + * + * @throws CoserBusinessException + */ + public void testGetStrataHaulCoordinate() throws CoserBusinessException { + Project projectValidated = openTestProject(projectService, "projectctrvalidated"); + Selection selection = projectValidated.getSelections().get("testselection1"); + + List<Coordinate> coordinates = projectService.getStrataHaulCoordinate(selection, Collections.EMPTY_LIST); + Assert.assertTrue(coordinates.isEmpty()); + coordinates = projectService.getStrataHaulCoordinate(selection, Collections.singleton("STR1")); + Assert.assertEquals(1, coordinates.size()); + coordinates = projectService.getStrataHaulCoordinate(selection, Collections.singleton("STR2")); + Assert.assertEquals(1, coordinates.size()); + coordinates = projectService.getStrataHaulCoordinate(selection, Arrays.asList(new String[]{"STR1", "STR3", "STR5"})); + Assert.assertEquals(3, coordinates.size()); + } + + /** + * Test la recuperation de l'arbre des projets et selection. + */ + @Test + public void testSelectionByProject() { + Map<String, List<String>> projectsAndSelection = projectService.getSelectionByProject(); + + Assert.assertEquals(2, projectsAndSelection.size()); + Assert.assertEquals(1, projectsAndSelection.get("projectctrvalidated").size()); + } + + /** + * Test que l'ouverture de selection fonctionne et ne charge pas de données. + * Test que l'historique est chargé. + * + * @throws CoserBusinessException + */ + @Test + public void testOpenSelection() throws CoserBusinessException { + Selection selection = projectService.openSelection("projectctrvalidated", "testselection1"); + + Assert.assertEquals(1, selection.getHistoryCommand().size()); + Assert.assertNull(selection.getCatch()); + Assert.assertEquals(3.5, selection.getDensityFilter(), 0.0001); + } + + /** + * Test que la methode de sauvegarde des selections retire bien les + * especes qui ne sont plus disponible. + * + * @throws CoserBusinessException + */ + @Test + public void testFillListsSelection() throws CoserBusinessException { + Selection selection = projectService.openSelection("projectctrvalidated", "testselection1"); + + selection.setSelectedSpecies(Arrays.asList(new String[]{"species1", "species2", "species4"})); + projectService.fillListsSelection(selection, + Arrays.asList(new String[]{"species1", "species2", "species3"}), + Arrays.asList(new String[]{"species2", "species3", "species4"}), + Arrays.asList(new String[]{"species3", "species4", "species5"})); + + Assert.assertEquals(2, selection.getSelectedSpeciesOccDens().size()); + Assert.assertEquals(2, selection.getSelectedSpeciesSizeAllYear().size()); + Assert.assertEquals(1, selection.getSelectedSpeciesMaturity().size()); + } } Modified: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/SelectionHandler.java =================================================================== --- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/SelectionHandler.java 2012-01-03 14:55:01 UTC (rev 936) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/SelectionHandler.java 2012-01-03 14:55:42 UTC (rev 937) @@ -1041,12 +1041,16 @@ Selection selection = view.getContextValue(Selection.class); ProjectService projectService = view.getContextValue(ProjectService.class); MatrixND samplingEffort = projectService.getSamplingEffort(project, selection); - view.getMatrixPanelEditor().setMatrix(samplingEffort); - - // replace default renderer with a renderer that display - // null values in red background - view.getMatrixPanelEditor().getTable().setDefaultRenderer(String.class, + + // can return null if there is not enought data + if (samplingEffort != null) { + view.getMatrixPanelEditor().setMatrix(samplingEffort); + + // replace default renderer with a renderer that display + // null values in red background + view.getMatrixPanelEditor().getTable().setDefaultRenderer(String.class, new SamplingEffortRenderer((MatrixTableModelND)view.getMatrixPanelEditor().getTable().getModel())); + } } /** Modified: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/replay/SelectionReplayHandler.java =================================================================== --- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/replay/SelectionReplayHandler.java 2012-01-03 14:55:01 UTC (rev 936) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/replay/SelectionReplayHandler.java 2012-01-03 14:55:42 UTC (rev 937) @@ -3,7 +3,7 @@ * $Id$ * $HeadURL$ * %% - * Copyright (C) 2011 Ifremer, Codelutin, Chatellier Eric + * Copyright (C) 2011 - 2012 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 @@ -279,6 +279,7 @@ ProjectService projectService = view.getContextValue(ProjectService.class); Project project = view.getContextValue(Project.class); Selection selection = view.getSelection(); + Selection replayedSelection = view.getReplayedSelection(); try { setWaitCursor(view); @@ -292,6 +293,12 @@ } projectService.filterDataSpecies(project, selection, selectedSpecies); + // auto selection des listes L2 à L4 + projectService.fillListsSelection(selection, + replayedSelection.getSelectedSpeciesOccDens(), + replayedSelection.getSelectedSpeciesSizeAllYear(), + replayedSelection.getSelectedSpeciesMaturity()); + // init next step view.getWizardLayout().show(view.getWizardPanel(), "step6");
participants (1)
-
echatellier@users.forge.codelutin.com