Author: tchemit Date: 2013-02-08 23:00:54 +0100 (Fri, 08 Feb 2013) New Revision: 369 Url: http://forge.codelutin.com/projects/tutti/repository/revisions/369 Log: - add tu (will be fix when taxon referential will be sane) - use synonyms translation in protocol Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceServiceImpl.java trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/DatabaseFixtures.java trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceServiceTest.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolSpeciesRowModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolSpeciesTableModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolUI.jaxx trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/ExportProtocolSpeciesAction.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/ImportProtocolSpeciesAction.java Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceServiceImpl.java =================================================================== --- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceServiceImpl.java 2013-02-08 20:33:53 UTC (rev 368) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceServiceImpl.java 2013-02-08 22:00:54 UTC (rev 369) @@ -347,6 +347,9 @@ List<Species> result = Lists.newArrayListWithCapacity(sources.length); for (TaxonRefTaxVO source : sources) { + if (36403 == source.getTaxonNameId() || 34539 == source.getTaxonNameId()) { + continue; + } Species target = loadSpecies(source); result.add(target); } @@ -486,11 +489,11 @@ protected Species importTemporarySpecies(Species source) { Preconditions.checkNotNull(source); Preconditions.checkNotNull(source.getName()); - + TaxonRefTaxVO taxonName = new TaxonRefTaxVO(); taxonName.setName(source.getName()); taxonName = taxonNameDao.createAsTemporary(taxonName, "Added by tutti (file import)."); - + // update the source Species result = loadSpecies(taxonName); Modified: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/DatabaseFixtures.java =================================================================== --- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/DatabaseFixtures.java 2013-02-08 20:33:53 UTC (rev 368) +++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/DatabaseFixtures.java 2013-02-08 22:00:54 UTC (rev 369) @@ -87,7 +87,7 @@ } public int refNbReferentSpecies() { - return 8516; + return 8514; } public int refNbScientificGear() { @@ -231,9 +231,18 @@ } public String refSpeciesId() { - return "35883"; + return "15461"; } + public Integer refSpeciesTaxonId() { - return 11242; + return 1; } + + public Integer refBadSpeciesTaxonId() { + return 7632; + } + + public Integer refBad2SpeciesTaxonId() { + return 2320; + } } Modified: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceServiceTest.java =================================================================== --- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceServiceTest.java 2013-02-08 20:33:53 UTC (rev 368) +++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceServiceTest.java 2013-02-08 22:00:54 UTC (rev 369) @@ -42,6 +42,7 @@ import fr.ifremer.tutti.persistence.entities.referential.Zone; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.hibernate.NonUniqueResultException; import org.junit.AfterClass; import org.junit.Assert; import org.junit.Before; @@ -219,7 +220,7 @@ long delta2 = System.currentTimeMillis() - time; - //TODO-tc We should not test cache performance like this, depends to much of the computer used,... + //TODO-tc We should not test cache performance like this, depends to much of the computer usage,... // float reduceFactor = delta2 * 100 / delta1; // Assert.assertTrue("The cache on getAllFishingVessel() should have speed up more than factor 10. Make sure EhCache is well configured.", reduceFactor < 0.1); @@ -272,7 +273,7 @@ } @Test - public void getSpecies(/*String speciesReferenceTaxonId*/) { + public void getSpeciesByReferenceTaxonId(/*String speciesReferenceTaxonId*/) { String speciesId = fixtures.refSpeciesId(); Integer taxonId = fixtures.refSpeciesTaxonId(); Species species = service.getSpeciesByReferenceTaxonId(taxonId); @@ -281,6 +282,18 @@ Assert.assertEquals(fixtures.refSpeciesTaxonId(), species.getReferenceTaxonId()); } + @Test(expected = NonUniqueResultException.class) + public void getBadSpeciesByReferenceTaxonId(/*String speciesReferenceTaxonId*/) { + Integer taxonId = fixtures.refBadSpeciesTaxonId(); + service.getSpeciesByReferenceTaxonId(taxonId); + } + + @Test(expected = NonUniqueResultException.class) + public void getBad2SpeciesByReferenceTaxonId(/*String speciesReferenceTaxonId*/) { + Integer taxonId = fixtures.refBad2SpeciesTaxonId(); + service.getSpeciesByReferenceTaxonId(taxonId); + } + @Test public void getAllCaracteristic() { List<Caracteristic> result = service.getAllCaracteristic(); Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolSpeciesRowModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolSpeciesRowModel.java 2013-02-08 20:33:53 UTC (rev 368) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolSpeciesRowModel.java 2013-02-08 22:00:54 UTC (rev 369) @@ -91,8 +91,8 @@ super(SpeciesProtocol.class, fromBeanBinder, toBeanBinder); } - public String getSpeciesId() { - return species.getId(); + public Integer getSpeciesReferenceTaxonId() { + return species.getReferenceTaxonId(); } public Species getSpecies() { Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolSpeciesTableModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolSpeciesTableModel.java 2013-02-08 20:33:53 UTC (rev 368) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolSpeciesTableModel.java 2013-02-08 22:00:54 UTC (rev 369) @@ -39,8 +39,8 @@ public static final ColumnIdentifier<EditProtocolSpeciesRowModel> SPECIES_ID = ColumnIdentifier.newId( EditProtocolSpeciesRowModel.PROPERTY_SPECIES, - n_("tutti.table.protocol.species.header.speciesId"), - n_("tutti.table.protocol.species.header.speciesId.tip")); + n_("tutti.table.protocol.species.header.speciesReferenceTaxonId"), + n_("tutti.table.protocol.species.header.speciesReferenceTaxonId.tip")); public static final ColumnIdentifier<EditProtocolSpeciesRowModel> SURVEY_CODE_ID = ColumnIdentifier.newId( EditProtocolSpeciesRowModel.PROPERTY_SPECIES_SURVEY_CODE, Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolUI.jaxx =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolUI.jaxx 2013-02-08 20:33:53 UTC (rev 368) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolUI.jaxx 2013-02-08 22:00:54 UTC (rev 369) @@ -78,7 +78,7 @@ <JPopupMenu id='tablePopup'> <JMenuItem id='removeSpeciesMenu' - onActionPerformed='handler.removeSpecies()'/> + onActionPerformed='handler.removeSpeciesRow()'/> </JPopupMenu> <JTabbedPane constraints='BorderLayout.CENTER'> @@ -151,7 +151,7 @@ genericType='Species'/> </cell> <cell fill='both'> - <JButton id='addRow' onActionPerformed='handler.addRow()'/> + <JButton id='addRow' onActionPerformed='handler.addSpeciesRow()'/> </cell> </row> <row fill='both' weighty='1'> @@ -166,16 +166,13 @@ </JPanel> </tab> <tab title='tutti.label.tab.protocol.benthos' enabled='false'> - <JLabel text='tutti.to.be.done' enabled='false' - horizontalAlignment="{JLabel.CENTER}"/> + <JLabel text='tutti.to.be.done' horizontalAlignment="{JLabel.CENTER}"/> </tab> <tab title='tutti.label.tab.protocol.plankton' enabled='false'> - <JLabel text='tutti.to.be.done' enabled='false' - horizontalAlignment="{JLabel.CENTER}"/> + <JLabel text='tutti.to.be.done' horizontalAlignment="{JLabel.CENTER}"/> </tab> <tab title='tutti.label.tab.protocol.accidental' enabled='false'> - <JLabel text='tutti.to.be.done' enabled='false' - horizontalAlignment="{JLabel.CENTER}"/> + <JLabel text='tutti.to.be.done' horizontalAlignment="{JLabel.CENTER}"/> </tab> </JTabbedPane> Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolUIHandler.java 2013-02-08 20:33:53 UTC (rev 368) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolUIHandler.java 2013-02-08 22:00:54 UTC (rev 369) @@ -26,6 +26,8 @@ import com.google.common.base.Preconditions; import com.google.common.collect.Lists; +import com.google.common.collect.Multimap; +import com.google.common.collect.Multimaps; import fr.ifremer.tutti.persistence.entities.TuttiEntities; import fr.ifremer.tutti.persistence.entities.protocol.SpeciesProtocol; import fr.ifremer.tutti.persistence.entities.protocol.TuttiProtocol; @@ -37,7 +39,6 @@ import fr.ifremer.tutti.ui.swing.content.home.ImportProtocolAction; import fr.ifremer.tutti.ui.swing.util.TuttiBeanMonitor; import fr.ifremer.tutti.ui.swing.util.table.AbstractTuttiTableUIHandler; -import fr.ifremer.tutti.ui.swing.util.table.ColumnIdentifier; import jaxx.runtime.SwingUtil; import jaxx.runtime.swing.editor.bean.BeanDoubleList; import jaxx.runtime.swing.editor.bean.BeanDoubleListModel; @@ -72,8 +73,12 @@ private static final Log log = LogFactory.getLog(EditProtocolUIHandler.class); - protected Map<String, Species> allSpecies; + protected List<Species> allSpecies; + protected Multimap<String, Species> allSpeciesByTaxonId; + + protected Map<String, Species> allReferentSpeciesByTaxonId; + protected List<Caracteristic> caracteristics; protected Map<String, Caracteristic> allCaracteristic; @@ -157,8 +162,14 @@ listModelIsModify(model); ui.setContextValue(model); - allSpecies = TuttiEntities.splitById(persistenceService.getAllSpecies()); + allSpecies = Lists.newArrayList(persistenceService.getAllSpecies()); + allSpeciesByTaxonId = Multimaps.index(allSpecies, + TuttiEntities.GET_TAXON_ID); + + allReferentSpeciesByTaxonId = TuttiEntities.splitByTaxonId( + persistenceService.getAllReferentSpecies()); + List<TuttiProtocol> protocols = persistenceService.getAllProtocol(); model.setExistingProtocols(protocols); @@ -170,10 +181,14 @@ return allCaracteristic; } - public Map<String, Species> getAllSpecies() { + public List<Species> getAllSpecies() { return allSpecies; } + public Map<String, Species> getAllReferentSpeciesByTaxonId() { + return allReferentSpeciesByTaxonId; + } + @Override public void afterInitUI() { @@ -206,12 +221,12 @@ if (mustClone != null && mustClone) { ui.setContextValue(false, MainUIHandler.CLONE_PROTOCOL); model.setId(null); - + } else { log.debug(model.getExistingProtocols()); model.getExistingProtocols().remove(protocol); } - + } else { // create new protocol @@ -262,7 +277,7 @@ initTable(table); - List<Species> speciesList = Lists.newArrayList(allSpecies.values()); + List<Species> speciesList = Lists.newArrayList(allSpecies); List<EditProtocolSpeciesRowModel> rows; @@ -320,9 +335,15 @@ List<EditProtocolSpeciesRowModel> result = Lists.newArrayList(); if (CollectionUtils.isNotEmpty(speciesProtocols)) { for (SpeciesProtocol speciesProtocol : speciesProtocols) { - Species species = allSpecies.get(speciesProtocol.getSpeciesId()); - speciesList.remove(species); + Integer taxonId = speciesProtocol.getSpeciesReferenceTaxonId(); + String taxonIdStr = String.valueOf(taxonId); + // remove all synonyms from available species list + removeSpeciesSynonyms(speciesList, taxonIdStr); + EditProtocolSpeciesRowModel row = getTableModel().createNewRow(); + + // get species referent taxon + Species species = allReferentSpeciesByTaxonId.get(taxonIdStr); row.setSpecies(species); row.setLengthStepPmfm(allCaracteristic.get(speciesProtocol.getLengthStepPmfmId())); row.fromBean(speciesProtocol); @@ -372,27 +393,43 @@ //-- Public methods --// //------------------------------------------------------------------------// - public void addRow() { + public void addSpeciesRow() { Species species = (Species) ui.getSpeciesComboBox().getSelectedItem(); + Preconditions.checkNotNull(species); EditProtocolSpeciesRowModel protocol = getTableModel().createNewRow(); - protocol.setSpecies(species); + + Integer taxonId = species.getReferenceTaxonId(); + + // get referent species + String taxonIdStr = String.valueOf(taxonId); + Species referentSpecies = allReferentSpeciesByTaxonId.get(taxonIdStr); + protocol.setSpecies(referentSpecies); getTableModel().addNewRow(protocol); - ui.getSpeciesComboBox().getData().remove(species); + + // remove all synonyms of this taxon + removeSpeciesSynonyms(ui.getSpeciesComboBox().getData(), taxonIdStr); + ui.getSpeciesComboBox().getHandler().sortData(); + selectFirstInCombo(ui.getSpeciesComboBox()); getModel().setModify(true); } /** Removes a species */ - public void removeSpecies() { + public void removeSpeciesRow() { int rowIndex = getTable().getSelectedRow(); Preconditions.checkState(rowIndex != -1, "Cant remove species if no species selected"); // remove the row from the model - getModel().getRows().remove(rowIndex); + EditProtocolSpeciesRowModel removedRow = getModel().getRows().remove(rowIndex); + // readd all synonym of this taxon to the species comobox + Integer taxonId = removedRow.getSpecies().getReferenceTaxonId(); + ui.getSpeciesComboBox().getData().addAll(allSpeciesByTaxonId.get(String.valueOf(taxonId))); + ui.getSpeciesComboBox().getHandler().sortData(); + // refresh all the table getTableModel().fireTableRowsDeleted(rowIndex, rowIndex); } @@ -480,9 +517,6 @@ protected void addLengthClassesColumnToModel(TableColumnModel model, List<String> selectedIds) { - ColumnIdentifier<EditProtocolSpeciesRowModel> identifier = - EditProtocolSpeciesTableModel.LENGTH_STEP_PMFM_ID; - Decorator<Caracteristic> decorator = getDecorator(Caracteristic.class, null); @@ -509,6 +543,10 @@ EditProtocolSpeciesTableModel.LENGTH_STEP_PMFM_ID); } + protected void removeSpeciesSynonyms(List<Species> speciesList, String taxonId) { + speciesList.removeAll(allSpeciesByTaxonId.get(taxonId)); + } + protected static class UpdateSelectedList implements PropertyChangeListener { private final BeanDoubleListModel<Caracteristic> model; @@ -554,5 +592,6 @@ } model.setSelected(selection); } + } } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/ExportProtocolSpeciesAction.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/ExportProtocolSpeciesAction.java 2013-02-08 20:33:53 UTC (rev 368) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/ExportProtocolSpeciesAction.java 2013-02-08 22:00:54 UTC (rev 369) @@ -114,7 +114,7 @@ service.exportProtocolSpecies(file, protocols, getHandler().getAllCaracteristic(), - getHandler().getAllSpecies()); + getHandler().getAllReferentSpeciesByTaxonId()); sendMessage("Espèces du Protocole exportés dans le fichier " + file + "."); } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/ImportProtocolSpeciesAction.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/ImportProtocolSpeciesAction.java 2013-02-08 20:33:53 UTC (rev 368) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/ImportProtocolSpeciesAction.java 2013-02-08 22:00:54 UTC (rev 369) @@ -106,12 +106,14 @@ service.importProtocolSpecies(file, protocol, getHandler().getAllCaracteristic(), - getHandler().getAllSpecies()); + getHandler().getAllReferentSpeciesByTaxonId()); List<EditProtocolSpeciesRowModel> rows = getHandler().toRows(null, protocol.getSpecies()); model.setRows(rows); + // update + sendMessage("Espèces importées depuis le fichier " + file + "."); } } \ No newline at end of file