Tutti-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
February 2013
- 6 participants
- 236 discussions
r385 - trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species
by tchemit@users.forge.codelutin.com 10 Feb '13
by tchemit@users.forge.codelutin.com 10 Feb '13
10 Feb '13
Author: tchemit
Date: 2013-02-10 16:02:10 +0100 (Sun, 10 Feb 2013)
New Revision: 385
Url: http://forge.codelutin.com/projects/tutti/repository/revisions/385
Log:
use renmaed species protocol id
Modified:
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUIHandler.java
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUIHandler.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUIHandler.java 2013-02-10 15:01:31 UTC (rev 384)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUIHandler.java 2013-02-10 15:02:10 UTC (rev 385)
@@ -470,7 +470,7 @@
if (!protocol.isSpeciesEmpty()) {
Map<String, Species> map = TuttiEntities.splitById(speciesUniverse);
for (SpeciesProtocol protocolSpecy : protocol.getSpecies()) {
- Species species = map.get(protocolSpecy.getSpeciesId());
+ Species species = map.get(protocolSpecy.getSpeciesReferenceTaxonId());
allSpecies.add(species);
speciesSampleCategories.put(species, SampleCategoryType.sortedUnsorted);
speciesSampleCategories.put(species, SampleCategoryType.size);
1
0
r384 - in trunk/tutti-ui-swing/src/main: java/fr/ifremer/tutti/ui/swing java/fr/ifremer/tutti/ui/swing/content/cruise java/fr/ifremer/tutti/ui/swing/content/home java/fr/ifremer/tutti/ui/swing/content/program resources/i18n
by tchemit@users.forge.codelutin.com 10 Feb '13
by tchemit@users.forge.codelutin.com 10 Feb '13
10 Feb '13
Author: tchemit
Date: 2013-02-10 16:01:31 +0100 (Sun, 10 Feb 2013)
New Revision: 384
Url: http://forge.codelutin.com/projects/tutti/repository/revisions/384
Log:
improve action api and logs
Modified:
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/AbstractTuttiAction.java
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/cruise/SaveCruiseAction.java
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/home/DeleteProtocolAction.java
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/home/ExportProtocolAction.java
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/home/ImportProtocolAction.java
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/program/SaveProgramAction.java
trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_fr_FR.properties
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/AbstractTuttiAction.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/AbstractTuttiAction.java 2013-02-10 15:00:32 UTC (rev 383)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/AbstractTuttiAction.java 2013-02-10 15:01:31 UTC (rev 384)
@@ -27,6 +27,8 @@
import com.google.common.base.Preconditions;
import com.google.common.collect.Sets;
import fr.ifremer.tutti.service.DecoratorService;
+import fr.ifremer.tutti.service.TuttiService;
+import fr.ifremer.tutti.ui.swing.config.TuttiApplicationConfig;
import jaxx.runtime.SwingUtil;
import jaxx.runtime.swing.ErrorDialogUI;
import org.apache.commons.logging.Log;
@@ -119,7 +121,7 @@
public final void actionPerformed(final ActionEvent event) {
if (log.isInfoEnabled()) {
- log.info("Will starts action: " + this);
+ log.info("Task [" + this + "] starting");
}
boolean doAction = prepareAction(event);
@@ -150,6 +152,8 @@
runAction(false, event);
}
+ } else {
+ releaseAction(event);
}
}
@@ -170,14 +174,14 @@
this.doAction(event);
} catch (Throwable e) {
if (log.isErrorEnabled()) {
- log.error("Error:" + e.getMessage(), e);
+ log.error("Task [" + this + "] error: " + e.getMessage(), e);
}
if (e instanceof Exception) {
ErrorDialogUI.showError((Exception) e);
}
} finally {
if (log.isInfoEnabled()) {
- log.info("After action: " + this);
+ log.info("Task [" + this + "] done");
}
if (timer != null) {
@@ -208,6 +212,14 @@
return handler.getModel();
}
+ protected <S extends TuttiService> S getService(Class<S> serviceType) {
+ return getContext().getService(serviceType);
+ }
+
+ protected TuttiApplicationConfig getConfig() {
+ return getContext().getConfig();
+ }
+
protected void setMnemonic(int key) {
putValue(MNEMONIC_KEY, key);
}
@@ -243,8 +255,8 @@
if (canceled) {
- if (log.isInfoEnabled()) {
- log.info("Task [" + action + "] was already canceled, do nothing");
+ if (log.isDebugEnabled()) {
+ log.debug("Task [" + action + "] was already canceled, do nothing");
}
} else {
@@ -275,8 +287,8 @@
d.pack();
SwingUtil.center(ui, d);
- if (log.isInfoEnabled()) {
- log.info("Try to open dialog (was canceled ? " + canceled + ")");
+ if (log.isDebugEnabled()) {
+ log.debug("Try to open dialog (was canceled ? " + canceled + ")");
}
if (!canceled) {
@@ -292,8 +304,8 @@
public boolean cancel() {
synchronized (lock) {
canceled = true;
- if (log.isInfoEnabled()) {
- log.info("Task [" + action + "] canceled.");
+ if (log.isDebugEnabled()) {
+ log.debug("Task [" + action + "] canceled.");
}
boolean cancel = super.cancel();
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/cruise/SaveCruiseAction.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/cruise/SaveCruiseAction.java 2013-02-10 15:00:32 UTC (rev 383)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/cruise/SaveCruiseAction.java 2013-02-10 15:01:31 UTC (rev 384)
@@ -66,7 +66,7 @@
TuttiUIContext context = getContext();
EditCruiseUIModel model = getModel();
PersistenceService persistenceService =
- context.getService(PersistenceService.class);
+ getService(PersistenceService.class);
Cruise bean = model.toBean();
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/home/DeleteProtocolAction.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/home/DeleteProtocolAction.java 2013-02-10 15:00:32 UTC (rev 383)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/home/DeleteProtocolAction.java 2013-02-10 15:01:31 UTC (rev 384)
@@ -86,7 +86,7 @@
log.info("Delete protocol: " + id);
}
- PersistenceService service = getContext().getService(PersistenceService.class);
+ PersistenceService service = getService(PersistenceService.class);
service.deleteProtocol(id);
getModel().setProtocol(null);
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/home/ExportProtocolAction.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/home/ExportProtocolAction.java 2013-02-10 15:00:32 UTC (rev 383)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/home/ExportProtocolAction.java 2013-02-10 15:01:31 UTC (rev 384)
@@ -107,7 +107,7 @@
}
// export protocol
TuttiProtocolImportExportService service =
- getContext().getService(TuttiProtocolImportExportService.class);
+ getService(TuttiProtocolImportExportService.class);
service.exportProtocol(protocol, file);
sendMessage("Protocole [" + protocol.getName() +
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/home/ImportProtocolAction.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/home/ImportProtocolAction.java 2013-02-10 15:00:32 UTC (rev 383)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/home/ImportProtocolAction.java 2013-02-10 15:01:31 UTC (rev 384)
@@ -102,7 +102,7 @@
// import protocol
TuttiProtocolImportExportService service =
- getContext().getService(TuttiProtocolImportExportService.class);
+ getService(TuttiProtocolImportExportService.class);
TuttiProtocol protocol = service.importProtocol(file);
sendMessage("Protocole [" + protocol.getName() + "] lu depuis le fichier.");
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/program/SaveProgramAction.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/program/SaveProgramAction.java 2013-02-10 15:00:32 UTC (rev 383)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/program/SaveProgramAction.java 2013-02-10 15:01:31 UTC (rev 384)
@@ -68,7 +68,9 @@
@Override
protected void doAction(ActionEvent event) {
TuttiUIContext context = getContext();
- PersistenceService persistenceService = context.getService(PersistenceService.class);
+ PersistenceService persistenceService =
+ getService(PersistenceService.class);
+
EditProgramUIModel model = getModel();
Program bean = model.toBean();
Modified: trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_fr_FR.properties
===================================================================
--- trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_fr_FR.properties 2013-02-10 15:00:32 UTC (rev 383)
+++ trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_fr_FR.properties 2013-02-10 15:01:31 UTC (rev 384)
@@ -3,6 +3,7 @@
tutti.action.about=À propos
tutti.action.about.tip=À Propos
tutti.action.addSpecies.tip=Ajouter une espèce
+tutti.action.addSpeciesProtocol.tip=Ajouter une espèce au protocole
tutti.action.attachments=Pièces jointes (%s)
tutti.action.attachments.tip=Pièces jointes
tutti.action.cancel=Annuler
@@ -14,6 +15,8 @@
tutti.action.cancel.editProgram.tip=Annuler l'édition (ou la création) de la série de campagne
tutti.action.cancel.editProtocol=Annuler
tutti.action.cancel.editProtocol.tip=Annuler l'édition (ou la création) du protocole
+tutti.action.cancelEditCatchBatch=Annuler
+tutti.action.cancelEditCatchBatch.tip=Annuler l'édition de la capture
tutti.action.casino-import=Import Casino
tutti.action.chooseProtocolCaracteristicFile=Choisir le fichier des caractéristiques
tutti.action.chooseProtocolFile=Choisir le fichier de protocole
@@ -37,6 +40,7 @@
tutti.action.editCatches.tip=Saisir des captures
tutti.action.editCruise=Éditer
tutti.action.editCruise.tip=Éditer la campagne sélectionnée
+tutti.action.editFishingOperation.tip=Éditer l'opération de pêche
tutti.action.editProgram=Éditer
tutti.action.editProgram.tip=Éditer le programme sélectionné
tutti.action.editProtocol=Éditer
@@ -103,12 +107,16 @@
tutti.action.removeSpecies=Supprimer l'espèce
tutti.action.removeSpeciesBatch=Supprimer le lot
tutti.action.removeSpeciesBatch.tip=Supprimer le lot courant (celui de la ligne sélectionnée) et tous ces fils
+tutti.action.removeSpeciesProtocol=Supprimer l'espèce
+tutti.action.removeSpeciesProtocol.tip=Supprimer l'espèce
tutti.action.removeSpeciesSubBatch=Supprimer les lots fils
tutti.action.removeSpeciesSubBatch.tip=Supprimer tous les lots fils du lot sélectionné
tutti.action.renameSpeciesBatch=Corriger l'espèce
tutti.action.renameSpeciesBatch.tip=Corriger l'espèce sur tout le lot sélectionné
tutti.action.reset.fishingOperationValidState=Réinitialiser
tutti.action.save=Enregistrer
+tutti.action.saveCatchBatch=Sauver
+tutti.action.saveCatchBatch.tip=Sauver la capture
tutti.action.saveCruise=Enregistrer
tutti.action.saveCruise.tip=Enregistrer la campagne
tutti.action.saveFishingOperation=Enregistrer
@@ -139,7 +147,9 @@
tutti.config.category.shortcuts.description=Liste des raccourcis clavier
tutti.config.category.ui=Interface utilisateur
tutti.config.category.ui.description=Options de l'interface utilisateur
+tutti.dialog.askSaveBeforeLeaving.createFishingOperation=Vous avez fait des modifications qu vous n'avez pas enregistrées. Voulez-vous les enregistrer ?
tutti.dialog.askSaveBeforeLeaving.message=Vous avez fait des modifications qu vous n'avez pas enregistrées. Voulez-vous les enregistrer ?
+tutti.dialog.askSaveBeforeLeaving.saveFishingOperation=Vous avez fait des modifications qu vous n'avez pas enregistrées. Voulez-vous les enregistrer ?
tutti.dialog.askSaveBeforeLeaving.title=Modifications non enregistrées
tutti.dialog.catches.species.computeWeight.error.message=Erreur lors de l'élévation des poids
tutti.dialog.catches.species.computeWeight.error.title=Erreur
@@ -148,6 +158,13 @@
tutti.duration.format=dj Hh m'm'
tutti.file.csv=Extension d'un fichier csv
tutti.file.protocol=Extension d'un fichier de protocole Tutti
+tutti.flash.information.all.caractristic.exported=Toutes les caractéristiques exportées dans le fichier %s.
+tutti.flash.information.caracteristic.imported.in.protocol=Caractéristiques importées dans le protocole depuis le fichier %s.
+tutti.flash.information.caractristic.exported.from.protocol=Caractéristiques du protocole exportées dans le fichier %s.
+tutti.flash.information.species.add.to.protocol=L'espèce %s a été ajoutée au protocole
+tutti.flash.information.species.exported.from.protocol=Espèces du protocole exportées dans le fichier %s.
+tutti.flash.information.species.imported.in.protocol=Espèces importées dans le protocole depuis le fichier %s.
+tutti.flash.information.species.remove.from.protocol=L'espèce %s a été retirée du protocole
tutti.information.import.temporary.referential=Vous pouvez ici importer des référentiels temporaires
tutti.label.attachmentEditor.file=Fichier
tutti.label.attachmentEditor.fileComment=Commentaire
@@ -374,8 +391,8 @@
tutti.table.protocol.species.header.sex.tip=Catégorisation sur le sexe ?
tutti.table.protocol.species.header.size=Catégorie Tri
tutti.table.protocol.species.header.size.tip=Catégorisation sur la catégorie de tri ?
-tutti.table.protocol.species.header.speciesId=Espèce
-tutti.table.protocol.species.header.speciesId.tip=Espèce (code permanent - nom scientifique)
+tutti.table.protocol.species.header.speciesReferenceTaxonId=Espèce
+tutti.table.protocol.species.header.speciesReferenceTaxonId.tip=Espèce (code refTax - nom scientifique)
tutti.table.protocol.species.header.speciesSurveyCode=Code
tutti.table.protocol.species.header.speciesSurveyCode.tip=Code campagne (non synchronisable)
tutti.table.protocol.species.header.weight=Pesée
@@ -419,6 +436,7 @@
tutti.title.create.cruise=Créer une nouvelle campagne
tutti.title.create.program=Créer une nouvelle série de campagne
tutti.title.create.protocol=Créer un nouveau protocol de saisie
+tutti.title.createBatch=Créer un lot
tutti.title.edit.cruise=Éditer une campagne existante
tutti.title.edit.operations=Saisie des opérations de pêches (%s)
tutti.title.edit.program=Éditer une série de campagne existante
1
0
r383 - trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol
by tchemit@users.forge.codelutin.com 10 Feb '13
by tchemit@users.forge.codelutin.com 10 Feb '13
10 Feb '13
Author: tchemit
Date: 2013-02-10 16:00:32 +0100 (Sun, 10 Feb 2013)
New Revision: 383
Url: http://forge.codelutin.com/projects/tutti/repository/revisions/383
Log:
imporve protocol action
Modified:
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/AddSpeciesProtocolAction.java
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/EditProtocolUIModel.java
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/ExportAllCaracteristicAction.java
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/ExportProtocolCaracteristicAction.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/ImportProtocolCaracteristicAction.java
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/RemoveSpeciesProtocolAction.java
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/AddSpeciesProtocolAction.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/AddSpeciesProtocolAction.java 2013-02-10 14:59:07 UTC (rev 382)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/AddSpeciesProtocolAction.java 2013-02-10 15:00:32 UTC (rev 383)
@@ -26,9 +26,11 @@
import com.google.common.base.Preconditions;
import fr.ifremer.tutti.persistence.entities.referential.Species;
+import fr.ifremer.tutti.service.DecoratorService;
import fr.ifremer.tutti.ui.swing.AbstractTuttiAction;
import java.awt.event.ActionEvent;
+import java.util.Collection;
import static org.nuiton.i18n.I18n._;
@@ -58,27 +60,39 @@
EditProtocolUI ui = getUI();
- EditProtocolSpeciesTableModel tableModel = getHandler().getTableModel();
+ EditProtocolUIHandler handler = getHandler();
+
+ EditProtocolSpeciesTableModel tableModel = handler.getTableModel();
Species species = (Species) ui.getSpeciesComboBox().getSelectedItem();
- Preconditions.checkNotNull(species);
- EditProtocolSpeciesRowModel protocol = tableModel.createNewRow();
+ Preconditions.checkNotNull(
+ species, "Cant add a speciesProtocol with a null species");
+
Integer taxonId = species.getReferenceTaxonId();
// get referent species
String taxonIdStr = String.valueOf(taxonId);
- Species referentSpecies = getHandler().getAllReferentSpeciesByTaxonId().get(taxonIdStr);
- protocol.setSpecies(referentSpecies);
- tableModel.addNewRow(protocol);
+ Species referentSpecies =
+ getModel().getAllReferentSpeciesByTaxonId().get(taxonIdStr);
+
// remove all synonyms of this taxon
- getHandler().removeSpeciesSynonyms(ui.getSpeciesComboBox().getData(), taxonIdStr);
+ Collection<Species> allSynonyms = getModel().getAllSynonyms(taxonIdStr);
+ ui.getSpeciesComboBox().getData().removeAll(allSynonyms);
ui.getSpeciesComboBox().getHandler().sortData();
+ handler.selectFirstInCombo(ui.getSpeciesComboBox());
- getHandler().selectFirstInCombo(ui.getSpeciesComboBox());
+ // add new row to model (do it after combo stuff for ui best display)
+ EditProtocolSpeciesRowModel protocol = tableModel.createNewRow();
+ protocol.setSpecies(referentSpecies);
+ tableModel.addNewRow(protocol);
getModel().setModify(true);
+ String speciesStr = getDecorator(Species.class, DecoratorService.SPECIES_BY_CRUISE_CODE).toString(referentSpecies);
+ sendMessage(_("tutti.flash.information.species.add.to.protocol",
+ speciesStr));
+
}
}
\ No newline at end of file
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-10 14:59:07 UTC (rev 382)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolUIHandler.java 2013-02-10 15:00:32 UTC (rev 383)
@@ -24,6 +24,7 @@
* #L%
*/
+import com.ezware.oxbow.swingbits.util.Preconditions;
import com.google.common.collect.Lists;
import com.google.common.collect.Multimap;
import com.google.common.collect.Multimaps;
@@ -58,6 +59,7 @@
import java.awt.event.ActionEvent;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
+import java.util.Collection;
import java.util.List;
import java.util.Map;
@@ -72,16 +74,6 @@
private static final Log log =
LogFactory.getLog(EditProtocolUIHandler.class);
- protected List<Species> allSpecies;
-
- protected Multimap<String, Species> allSpeciesByTaxonId;
-
- protected Map<String, Species> allReferentSpeciesByTaxonId;
-
- protected List<Caracteristic> caracteristics;
-
- protected Map<String, Caracteristic> allCaracteristic;
-
public EditProtocolUIHandler(TuttiUI parentUi, EditProtocolUI ui) {
super(parentUi.getHandler().getContext(), ui);
}
@@ -153,45 +145,36 @@
EditProtocolUIModel model = new EditProtocolUIModel();
- // can't load directly model from database here, since we want to
- // fill only the model with rows (transformed from speciesProtocol)
- // As we still don't have the table model at this point, wait the
- // afterUI method to fill model
+ // load cache data
- listModelIsModify(model);
- ui.setContextValue(model);
+ List<Species> allSpecies = Lists.newArrayList(persistenceService.getAllSpecies());
+ model.setAllSpecies(allSpecies);
+ Multimap<String, Species> allSpeciesByTaxonId = Multimaps.index(allSpecies,
+ TuttiEntities.GET_TAXON_ID);
- allSpecies = Lists.newArrayList(persistenceService.getAllSpecies());
-
- allSpeciesByTaxonId = Multimaps.index(allSpecies,
- TuttiEntities.GET_TAXON_ID);
-
- allReferentSpeciesByTaxonId = TuttiEntities.splitByTaxonId(
+ model.setAllSpeciesByTaxonId(allSpeciesByTaxonId);
+ Map<String, Species> allReferentSpeciesByTaxonId = TuttiEntities.splitByTaxonId(
persistenceService.getAllReferentSpecies());
+ model.setAllReferentSpeciesByTaxonId(allReferentSpeciesByTaxonId);
List<TuttiProtocol> protocols = persistenceService.getAllProtocol();
model.setExistingProtocols(protocols);
- caracteristics = persistenceService.getAllCaracteristic();
- allCaracteristic = TuttiEntities.splitById(caracteristics);
- }
+ List<Caracteristic> caracteristics = persistenceService.getAllCaracteristic();
+ model.setCaracteristics(caracteristics);
- public Map<String, Caracteristic> getAllCaracteristic() {
- return allCaracteristic;
- }
+ Map<String, Caracteristic> allCaracteristic = TuttiEntities.splitById(caracteristics);
+ model.setAllCaracteristic(allCaracteristic);
- public List<Species> getAllSpecies() {
- return allSpecies;
- }
+ // can't load directly model from database here, since we want to
+ // fill only the model with rows (transformed from speciesProtocol)
+ // As we still don't have the table model at this point, wait the
+ // afterUI method to fill model
- public Map<String, Species> getAllReferentSpeciesByTaxonId() {
- return allReferentSpeciesByTaxonId;
+ listModelIsModify(model);
+ ui.setContextValue(model);
}
- public Multimap<String, Species> getAllSpeciesByTaxonId() {
- return allSpeciesByTaxonId;
- }
-
@Override
public void afterInitUI() {
@@ -280,7 +263,7 @@
initTable(table);
- List<Species> speciesList = Lists.newArrayList(allSpecies);
+ List<Species> speciesList = Lists.newArrayList(model.getAllSpecies());
List<EditProtocolSpeciesRowModel> rows;
@@ -305,22 +288,22 @@
initDoubleList(EditProtocolUIModel.PROPERTY_LENGTH_CLASSES_PMFM_ID,
ui.getLengthClassesList(),
- Lists.newArrayList(caracteristics),
+ Lists.newArrayList(model.getCaracteristics()),
model.getLengthClassesPmfmId());
initDoubleList(EditProtocolUIModel.PROPERTY_GEAR_PMFM_ID,
ui.getGearList(),
- Lists.newArrayList(caracteristics),
+ Lists.newArrayList(model.getCaracteristics()),
model.getGearPmfmId());
initDoubleList(EditProtocolUIModel.PROPERTY_ENVIRONMENT_PMFM_ID,
ui.getEnvironmentList(),
- Lists.newArrayList(caracteristics),
+ Lists.newArrayList(model.getCaracteristics()),
model.getEnvironmentPmfmId());
initDoubleList(EditProtocolUIModel.PROPERTY_HYDROLOGY_PMFM_ID,
ui.getHydrologyList(),
- Lists.newArrayList(caracteristics),
+ Lists.newArrayList(model.getCaracteristics()),
model.getHydrologyPmfmId());
// if new protocol can already cancel his creation
@@ -330,18 +313,22 @@
public List<EditProtocolSpeciesRowModel> toRows(List<Species> speciesList,
List<SpeciesProtocol> speciesProtocols) {
- boolean useComboData = speciesList == null;
+ Preconditions.checkNotNull(speciesList);
- if (useComboData) {
- speciesList = ui.getSpeciesComboBox().getData();
- }
+ EditProtocolUIModel model = getModel();
+
+ Map<String, Species> allReferentSpeciesByTaxonId = model.getAllReferentSpeciesByTaxonId();
+ Map<String, Caracteristic> allCaracteristic = model.getAllCaracteristic();
+
List<EditProtocolSpeciesRowModel> result = Lists.newArrayList();
if (CollectionUtils.isNotEmpty(speciesProtocols)) {
for (SpeciesProtocol speciesProtocol : speciesProtocols) {
Integer taxonId = speciesProtocol.getSpeciesReferenceTaxonId();
String taxonIdStr = String.valueOf(taxonId);
+
// remove all synonyms from available species list
- removeSpeciesSynonyms(speciesList, taxonIdStr);
+ Collection<Species> allSynonyms = model.getAllSynonyms(taxonIdStr);
+ speciesList.removeAll(allSynonyms);
EditProtocolSpeciesRowModel row = getTableModel().createNewRow();
@@ -354,9 +341,6 @@
}
}
- if (useComboData) {
- selectFirstInCombo(ui.getSpeciesComboBox());
- }
return result;
}
@@ -453,7 +437,9 @@
initBeanList(widget, availableCaracteristics,
Lists.<Caracteristic>newArrayList());
- UpdateSelectedList listener = new UpdateSelectedList(widget, allCaracteristic);
+ UpdateSelectedList listener = new UpdateSelectedList(
+ widget,
+ getModel().getAllCaracteristic());
widget.putClientProperty("_updateListener", listener);
widget.putClientProperty("_updateListenerId", propertyId);
listener.select(selectedCaracteristics);
@@ -461,6 +447,7 @@
protected void selectLengthClasses(List<String> ids, JComboBox comboBox) {
+ Map<String, Caracteristic> allCaracteristic = getModel().getAllCaracteristic();
List<Caracteristic> selection = Lists.newArrayList();
if (CollectionUtils.isNotEmpty(ids)) {
for (String id : ids) {
@@ -505,10 +492,6 @@
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;
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolUIModel.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolUIModel.java 2013-02-10 14:59:07 UTC (rev 382)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolUIModel.java 2013-02-10 15:00:32 UTC (rev 383)
@@ -24,14 +24,18 @@
* #L%
*/
+import com.google.common.collect.Multimap;
import fr.ifremer.tutti.persistence.entities.TuttiEntities;
import fr.ifremer.tutti.persistence.entities.protocol.TuttiProtocol;
import fr.ifremer.tutti.persistence.entities.referential.Caracteristic;
+import fr.ifremer.tutti.persistence.entities.referential.Species;
import fr.ifremer.tutti.ui.swing.util.table.AbstractTuttiTableUIModel;
import org.nuiton.util.beans.Binder;
import org.nuiton.util.beans.BinderFactory;
+import java.util.Collection;
import java.util.List;
+import java.util.Map;
/**
* @author tchemit <chemit(a)codelutin.com>
@@ -78,6 +82,16 @@
*/
protected boolean removeSpeciesEnabled;
+ protected List<Species> allSpecies;
+
+ protected Multimap<String, Species> allSpeciesByTaxonId;
+
+ protected Map<String, Species> allReferentSpeciesByTaxonId;
+
+ protected List<Caracteristic> caracteristics;
+
+ protected Map<String, Caracteristic> allCaracteristic;
+
protected static Binder<EditProtocolUIModel, TuttiProtocol> toBeanBinder =
BinderFactory.newBinder(EditProtocolUIModel.class,
TuttiProtocol.class);
@@ -199,4 +213,47 @@
this.existingProtocols = existingProtocols;
}
+ public List<Species> getAllSpecies() {
+ return allSpecies;
+ }
+
+ public void setAllSpecies(List<Species> allSpecies) {
+ this.allSpecies = allSpecies;
+ }
+
+ public Multimap<String, Species> getAllSpeciesByTaxonId() {
+ return allSpeciesByTaxonId;
+ }
+
+ public Collection<Species> getAllSynonyms(String taxonId) {
+ return allSpeciesByTaxonId.get(taxonId);
+ }
+
+ public void setAllSpeciesByTaxonId(Multimap<String, Species> allSpeciesByTaxonId) {
+ this.allSpeciesByTaxonId = allSpeciesByTaxonId;
+ }
+
+ public Map<String, Species> getAllReferentSpeciesByTaxonId() {
+ return allReferentSpeciesByTaxonId;
+ }
+
+ public void setAllReferentSpeciesByTaxonId(Map<String, Species> allReferentSpeciesByTaxonId) {
+ this.allReferentSpeciesByTaxonId = allReferentSpeciesByTaxonId;
+ }
+
+ public List<Caracteristic> getCaracteristics() {
+ return caracteristics;
+ }
+
+ public void setCaracteristics(List<Caracteristic> caracteristics) {
+ this.caracteristics = caracteristics;
+ }
+
+ public Map<String, Caracteristic> getAllCaracteristic() {
+ return allCaracteristic;
+ }
+
+ public void setAllCaracteristic(Map<String, Caracteristic> allCaracteristic) {
+ this.allCaracteristic = allCaracteristic;
+ }
}
\ No newline at end of file
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/ExportAllCaracteristicAction.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/ExportAllCaracteristicAction.java 2013-02-10 14:59:07 UTC (rev 382)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/ExportAllCaracteristicAction.java 2013-02-10 15:00:32 UTC (rev 383)
@@ -94,12 +94,10 @@
// export protocol caracteristics
TuttiProtocolImportExportService service =
- getContext().getService(TuttiProtocolImportExportService.class);
+ getService(TuttiProtocolImportExportService.class);
- service.exportAllCaracteristic(file,
- getHandler().getAllCaracteristic());
+ service.exportAllCaracteristic(file, getModel().getAllCaracteristic());
- sendMessage("Toutes les caractéristiques exportées dans le fichier "
- + file + ".");
+ sendMessage(_("tutti.flash.information.all.caractristic.exported", file));
}
}
\ No newline at end of file
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/ExportProtocolCaracteristicAction.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/ExportProtocolCaracteristicAction.java 2013-02-10 14:59:07 UTC (rev 382)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/ExportProtocolCaracteristicAction.java 2013-02-10 15:00:32 UTC (rev 383)
@@ -98,13 +98,13 @@
// export protocol caracteristics
TuttiProtocolImportExportService service =
- getContext().getService(TuttiProtocolImportExportService.class);
+ getService(TuttiProtocolImportExportService.class);
service.exportProtocolCaracteristic(file,
protocol,
- getHandler().getAllCaracteristic());
+ getModel().getAllCaracteristic());
- sendMessage("Caractéristiques du Protocole exportées dans le fichier "
- + file + ".");
+ sendMessage(_("tutti.flash.information.caractristic.exported.from.protocol",
+ file));
}
}
\ No newline at end of file
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-10 14:59:07 UTC (rev 382)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/ExportProtocolSpeciesAction.java 2013-02-10 15:00:32 UTC (rev 383)
@@ -26,7 +26,6 @@
import com.google.common.collect.Lists;
import fr.ifremer.tutti.persistence.entities.protocol.SpeciesProtocol;
-import fr.ifremer.tutti.persistence.entities.protocol.TuttiProtocol;
import fr.ifremer.tutti.service.protocol.TuttiProtocolImportExportService;
import fr.ifremer.tutti.ui.swing.AbstractTuttiAction;
import fr.ifremer.tutti.ui.swing.util.TuttiUIUtil;
@@ -96,12 +95,12 @@
log.info("Will export protocol species to file: " + file);
}
- // bind to a protocol
- TuttiProtocol protocol = getModel().toBean();
+ EditProtocolUIModel model = getModel();
+ // build species protocol to export
+
List<SpeciesProtocol> protocols = Lists.newArrayList();
-
- for (EditProtocolSpeciesRowModel row : getModel().getRows()) {
+ for (EditProtocolSpeciesRowModel row : model.getRows()) {
if (row.isValid()) {
protocols.add(row.toBean());
}
@@ -109,13 +108,14 @@
// import
TuttiProtocolImportExportService service =
- getContext().getService(TuttiProtocolImportExportService.class);
+ getService(TuttiProtocolImportExportService.class);
service.exportProtocolSpecies(file,
protocols,
- getHandler().getAllCaracteristic(),
- getHandler().getAllReferentSpeciesByTaxonId());
+ model.getAllCaracteristic(),
+ model.getAllReferentSpeciesByTaxonId());
- sendMessage("Espèces du Protocole exportés dans le fichier " + file + ".");
+ sendMessage(_("tutti.flash.information.species.exported.from.protocol",
+ file));
}
}
\ No newline at end of file
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/ImportProtocolCaracteristicAction.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/ImportProtocolCaracteristicAction.java 2013-02-10 14:59:07 UTC (rev 382)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/ImportProtocolCaracteristicAction.java 2013-02-10 15:00:32 UTC (rev 383)
@@ -25,8 +25,10 @@
*/
import fr.ifremer.tutti.persistence.entities.protocol.TuttiProtocol;
+import fr.ifremer.tutti.service.TuttiService;
import fr.ifremer.tutti.service.protocol.TuttiProtocolImportExportService;
import fr.ifremer.tutti.ui.swing.AbstractTuttiAction;
+import fr.ifremer.tutti.ui.swing.config.TuttiApplicationConfig;
import fr.ifremer.tutti.ui.swing.util.TuttiUIUtil;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -93,27 +95,31 @@
log.info("Will import protocol caracteristic file: " + file);
}
+ EditProtocolUIHandler handler = getHandler();
EditProtocolUIModel model = getModel();
// bind to a protocol
TuttiProtocol protocol = model.toBean();
TuttiProtocolImportExportService service =
- getContext().getService(TuttiProtocolImportExportService.class);
+ getService(TuttiProtocolImportExportService.class);
service.importProtocolCaracteristic(file,
protocol,
- getHandler().getAllCaracteristic());
+ model.getAllCaracteristic());
- getHandler().addDoubleListListeners();
+ handler.addDoubleListListeners();
try {
// rebind to model
model.fromBean(protocol);
} finally {
- getHandler().removeDoubleListListeners();
+ handler.removeDoubleListListeners();
}
- sendMessage("Caractéristiques importées depuis le fichier " + file);
+ sendMessage(
+ _("tutti.flash.information.caracteristic.imported.in.protocol",
+ file));
+
}
}
\ No newline at end of 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-10 14:59:07 UTC (rev 382)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/ImportProtocolSpeciesAction.java 2013-02-10 15:00:32 UTC (rev 383)
@@ -25,9 +25,11 @@
*/
import fr.ifremer.tutti.persistence.entities.protocol.TuttiProtocol;
+import fr.ifremer.tutti.persistence.entities.referential.Species;
import fr.ifremer.tutti.service.protocol.TuttiProtocolImportExportService;
import fr.ifremer.tutti.ui.swing.AbstractTuttiAction;
import fr.ifremer.tutti.ui.swing.util.TuttiUIUtil;
+import jaxx.runtime.swing.editor.bean.BeanComboBox;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -94,6 +96,7 @@
log.info("Will import protocol species file: " + file);
}
+ EditProtocolUIHandler handler = getHandler();
EditProtocolUIModel model = getModel();
// bind to a protocol
@@ -101,19 +104,29 @@
// import
TuttiProtocolImportExportService service =
- getContext().getService(TuttiProtocolImportExportService.class);
+ getService(TuttiProtocolImportExportService.class);
service.importProtocolSpecies(file,
protocol,
- getHandler().getAllCaracteristic(),
- getHandler().getAllReferentSpeciesByTaxonId());
+ model.getAllCaracteristic(),
+ model.getAllReferentSpeciesByTaxonId());
+ BeanComboBox<Species> speciesComboBox = getUI().getSpeciesComboBox();
+
+ // build rows from imported+merged protocol
+ // (will also remove all synonyms of species referent used)
List<EditProtocolSpeciesRowModel> rows =
- getHandler().toRows(null, protocol.getSpecies());
+ handler.toRows(speciesComboBox.getData(),
+ protocol.getSpecies());
+
+ // update species comboBox
+ speciesComboBox.getHandler().sortData();
+ handler.selectFirstInCombo(speciesComboBox);
+
+ // update rows in model
model.setRows(rows);
- // update
-
- sendMessage("Espèces importées depuis le fichier " + file + ".");
+ sendMessage(_("tutti.flash.information.species.imported.in.protocol",
+ file));
}
}
\ No newline at end of file
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/RemoveSpeciesProtocolAction.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/RemoveSpeciesProtocolAction.java 2013-02-10 14:59:07 UTC (rev 382)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/RemoveSpeciesProtocolAction.java 2013-02-10 15:00:32 UTC (rev 383)
@@ -25,9 +25,12 @@
*/
import com.google.common.base.Preconditions;
+import fr.ifremer.tutti.persistence.entities.referential.Species;
+import fr.ifremer.tutti.service.DecoratorService;
import fr.ifremer.tutti.ui.swing.AbstractTuttiAction;
import java.awt.event.ActionEvent;
+import java.util.Collection;
import static org.nuiton.i18n.I18n._;
@@ -45,7 +48,7 @@
super(handler,
"removeSpeciesProtocol",
"batch-delete",
- null,
+ _("tutti.action.removeSpeciesProtocol"),
_("tutti.action.removeSpeciesProtocol.tip"),
false
);
@@ -60,16 +63,23 @@
Preconditions.checkState(rowIndex != -1,
"Cant remove species if no species selected");
- // remove the row from the model
- EditProtocolSpeciesRowModel removedRow = getModel().getRows().remove(rowIndex);
+ EditProtocolSpeciesTableModel tableModel = getHandler().getTableModel();
- // readd all synonym of this taxon to the species comobox
- Integer taxonId = removedRow.getSpecies().getReferenceTaxonId();
- getUI().getSpeciesComboBox().getData().addAll(handler.getAllSpeciesByTaxonId().get(String.valueOf(taxonId)));
+ EditProtocolSpeciesRowModel selectedRow = tableModel.getEntry(rowIndex);
+
+ // re-add all synonym of this taxon to the species comobox
+ Integer taxonId = selectedRow.getSpecies().getReferenceTaxonId();
+ Collection<Species> allSynonyms = getModel().getAllSynonyms(String.valueOf(taxonId));
+ getUI().getSpeciesComboBox().getData().addAll(allSynonyms);
getUI().getSpeciesComboBox().getHandler().sortData();
- // refresh all the table
- handler.getTableModel().fireTableRowsDeleted(rowIndex, rowIndex);
+
+ // remove the row from the model(do it after treating the comboBox which can be long)
+ tableModel.removeRow(rowIndex);
+
+ String speciesStr = getDecorator(Species.class, DecoratorService.SPECIES_BY_CRUISE_CODE).toString(selectedRow.getSpecies());
+ sendMessage(_("tutti.flash.information.species.remove.from.protocol",
+ speciesStr));
}
}
\ No newline at end of file
1
0
r382 - trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/referential
by tchemit@users.forge.codelutin.com 10 Feb '13
by tchemit@users.forge.codelutin.com 10 Feb '13
10 Feb '13
Author: tchemit
Date: 2013-02-10 15:59:07 +0100 (Sun, 10 Feb 2013)
New Revision: 382
Url: http://forge.codelutin.com/projects/tutti/repository/revisions/382
Log:
use new action api
Modified:
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/referential/ExportTemporaryGearExampleAction.java
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/referential/ExportTemporaryPersonExampleAction.java
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/referential/ExportTemporarySpeciesExampleAction.java
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/referential/ExportTemporaryVesselExampleAction.java
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/referential/ImportTemporaryGearAction.java
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/referential/ImportTemporaryPersonAction.java
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/referential/ImportTemporarySpeciesAction.java
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/referential/ImportTemporaryVesselAction.java
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/referential/ExportTemporaryGearExampleAction.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/referential/ExportTemporaryGearExampleAction.java 2013-02-10 14:57:58 UTC (rev 381)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/referential/ExportTemporaryGearExampleAction.java 2013-02-10 14:59:07 UTC (rev 382)
@@ -95,7 +95,7 @@
}
TuttiReferentialImportExportService service =
- getContext().getService(TuttiReferentialImportExportService.class);
+ getService(TuttiReferentialImportExportService.class);
service.exportTemporaryGearExample(file);
sendMessage("Exemple de référentiel temporaire d'engins exporté " +
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/referential/ExportTemporaryPersonExampleAction.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/referential/ExportTemporaryPersonExampleAction.java 2013-02-10 14:57:58 UTC (rev 381)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/referential/ExportTemporaryPersonExampleAction.java 2013-02-10 14:59:07 UTC (rev 382)
@@ -95,7 +95,7 @@
}
TuttiReferentialImportExportService service =
- getContext().getService(TuttiReferentialImportExportService.class);
+ getService(TuttiReferentialImportExportService.class);
service.exportTemporaryPersonExample(file);
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/referential/ExportTemporarySpeciesExampleAction.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/referential/ExportTemporarySpeciesExampleAction.java 2013-02-10 14:57:58 UTC (rev 381)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/referential/ExportTemporarySpeciesExampleAction.java 2013-02-10 14:59:07 UTC (rev 382)
@@ -95,7 +95,7 @@
}
TuttiReferentialImportExportService service =
- getContext().getService(TuttiReferentialImportExportService.class);
+ getService(TuttiReferentialImportExportService.class);
service.exportTemporarySpeciesExample(file);
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/referential/ExportTemporaryVesselExampleAction.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/referential/ExportTemporaryVesselExampleAction.java 2013-02-10 14:57:58 UTC (rev 381)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/referential/ExportTemporaryVesselExampleAction.java 2013-02-10 14:59:07 UTC (rev 382)
@@ -95,7 +95,7 @@
}
TuttiReferentialImportExportService service =
- getContext().getService(TuttiReferentialImportExportService.class);
+ getService(TuttiReferentialImportExportService.class);
service.exportTemporaryVesselExample(file);
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/referential/ImportTemporaryGearAction.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/referential/ImportTemporaryGearAction.java 2013-02-10 14:57:58 UTC (rev 381)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/referential/ImportTemporaryGearAction.java 2013-02-10 14:59:07 UTC (rev 382)
@@ -95,7 +95,7 @@
}
TuttiReferentialImportExportService service =
- getContext().getService(TuttiReferentialImportExportService.class);
+ getService(TuttiReferentialImportExportService.class);
service.importTemporaryGear(file);
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/referential/ImportTemporaryPersonAction.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/referential/ImportTemporaryPersonAction.java 2013-02-10 14:57:58 UTC (rev 381)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/referential/ImportTemporaryPersonAction.java 2013-02-10 14:59:07 UTC (rev 382)
@@ -95,7 +95,7 @@
}
TuttiReferentialImportExportService service =
- getContext().getService(TuttiReferentialImportExportService.class);
+ getService(TuttiReferentialImportExportService.class);
service.importTemporaryPerson(file);
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/referential/ImportTemporarySpeciesAction.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/referential/ImportTemporarySpeciesAction.java 2013-02-10 14:57:58 UTC (rev 381)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/referential/ImportTemporarySpeciesAction.java 2013-02-10 14:59:07 UTC (rev 382)
@@ -95,7 +95,7 @@
}
TuttiReferentialImportExportService service =
- getContext().getService(TuttiReferentialImportExportService.class);
+ getService(TuttiReferentialImportExportService.class);
service.importTemporarySpecies(file);
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/referential/ImportTemporaryVesselAction.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/referential/ImportTemporaryVesselAction.java 2013-02-10 14:57:58 UTC (rev 381)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/referential/ImportTemporaryVesselAction.java 2013-02-10 14:59:07 UTC (rev 382)
@@ -95,7 +95,7 @@
}
TuttiReferentialImportExportService service =
- getContext().getService(TuttiReferentialImportExportService.class);
+ getService(TuttiReferentialImportExportService.class);
service.importTemporaryVessel(file);
1
0
r381 - trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/table
by tchemit@users.forge.codelutin.com 10 Feb '13
by tchemit@users.forge.codelutin.com 10 Feb '13
10 Feb '13
Author: tchemit
Date: 2013-02-10 15:57:58 +0100 (Sun, 10 Feb 2013)
New Revision: 381
Url: http://forge.codelutin.com/projects/tutti/repository/revisions/381
Log:
add removerow method in table model
Modified:
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/table/AbstractTuttiTableModel.java
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/table/AbstractTuttiTableModel.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/table/AbstractTuttiTableModel.java 2013-02-10 14:57:21 UTC (rev 380)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/table/AbstractTuttiTableModel.java 2013-02-10 14:57:58 UTC (rev 381)
@@ -178,6 +178,17 @@
return rowIndex;
}
+ public final R removeRow(int rowIndex) {
+ SwingUtil.ensureRowIndex(this, rowIndex);
+
+ List<R> data = getRows();
+
+ R result = data.remove(rowIndex);
+
+ fireTableRowsDeleted(rowIndex, rowIndex);
+ return result;
+ }
+
protected void onRowsChanged(List<R> data) {
// by default do nothing
}
1
0
r380 - in trunk/tutti-service/src/main/java/fr/ifremer/tutti/service: . referential
by tchemit@users.forge.codelutin.com 10 Feb '13
by tchemit@users.forge.codelutin.com 10 Feb '13
10 Feb '13
Author: tchemit
Date: 2013-02-10 15:57:21 +0100 (Sun, 10 Feb 2013)
New Revision: 380
Url: http://forge.codelutin.com/projects/tutti/repository/revisions/380
Log:
add check in referential import
Modified:
trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/TuttiCsvUtil.java
trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/referential/GearModel.java
trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/referential/SpeciesModel.java
trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/referential/TuttiReferentialImportExportService.java
trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/referential/VesselModel.java
Modified: trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/TuttiCsvUtil.java
===================================================================
--- trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/TuttiCsvUtil.java 2013-02-10 13:41:29 UTC (rev 379)
+++ trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/TuttiCsvUtil.java 2013-02-10 14:57:21 UTC (rev 380)
@@ -32,6 +32,7 @@
import java.text.ParseException;
import java.util.Map;
+import java.util.Set;
/**
* Helper around csv import / export in Tutti.
@@ -58,6 +59,14 @@
public <E extends IdAware> ForeignKeyValue<E> newForeignKeyValue(Class<E> type, String propertyName, Map<String, E> universe) {
return new ForeignKeyValue<E>(type, propertyName, universe);
}
+
+ public void newNotExistingValueColumn(String propertyName, Set<String> universe) {
+ newNotExistingValueColumn(propertyName, propertyName, universe);
+ }
+
+ public void newNotExistingValueColumn(String headerName, String propertyName, Set<String> universe) {
+ newMandatoryColumn(headerName, propertyName, new NotExistingKeyValue(propertyName, universe));
+ }
}
public static class StringParserFormatter extends Common.NullableParserFormatter<String> {
@@ -84,7 +93,7 @@
/**
* @param <E>
* @author tchemit <chemit(a)codelutin.com>
- * @since 2.6.12
+ * @since 1.0
*/
public static class ForeignKeyValue<E extends IdAware> implements ValueParserFormatter<E> {
@@ -132,6 +141,44 @@
}
}
+ /**
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.0
+ */
+ public static class NotExistingKeyValue implements ValueParserFormatter<String> {
+
+ protected final String propertyName;
+
+ protected final Set<String> existingValues;
+
+ public NotExistingKeyValue(
+ String propertyName,
+ Set<String> universe) {
+ this.propertyName = propertyName;
+ this.existingValues = universe;
+ }
+
+ @Override
+ public String parse(String value) throws ParseException {
+ if (StringUtils.isNotBlank(value)) {
+
+ if (existingValues.contains(value)) {
+
+ // can not find entity this is a big problem for us...
+ throw new RuntimeException(
+ "Property '" +
+ propertyName + "' with value " + value + " is already defined.");
+ }
+ }
+ return value;
+ }
+
+ @Override
+ public String format(String e) {
+ return e;
+ }
+ }
+
protected TuttiCsvUtil() {
// no instance
}
Modified: trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/referential/GearModel.java
===================================================================
--- trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/referential/GearModel.java 2013-02-10 13:41:29 UTC (rev 379)
+++ trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/referential/GearModel.java 2013-02-10 14:57:21 UTC (rev 380)
@@ -28,6 +28,8 @@
import fr.ifremer.tutti.service.TuttiCsvUtil;
import org.nuiton.util.csv.Common;
+import java.util.Set;
+
/**
* Model to import / export {@link Gear} in csv format.
*
@@ -36,12 +38,12 @@
*/
public class GearModel extends TuttiCsvUtil.AbstractTuttiImportExportModel<Gear> {
- public GearModel(char separator) {
+ public GearModel(char separator, Set<String> existingGearName) {
super(separator);
// import definition
- newMandatoryColumn(Gear.PROPERTY_NAME);
+ newNotExistingValueColumn(Gear.PROPERTY_NAME, existingGearName);
newMandatoryColumn(Gear.PROPERTY_LABEL);
newMandatoryColumn(Gear.PROPERTY_SCIENTIFIC_GEAR, Common.PRIMITIVE_BOOLEAN);
Modified: trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/referential/SpeciesModel.java
===================================================================
--- trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/referential/SpeciesModel.java 2013-02-10 13:41:29 UTC (rev 379)
+++ trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/referential/SpeciesModel.java 2013-02-10 14:57:21 UTC (rev 380)
@@ -27,6 +27,8 @@
import fr.ifremer.tutti.persistence.entities.referential.Species;
import fr.ifremer.tutti.service.TuttiCsvUtil;
+import java.util.Set;
+
/**
* Model to import / export {@link Species} in csv format.
*
@@ -35,12 +37,12 @@
*/
public class SpeciesModel extends TuttiCsvUtil.AbstractTuttiImportExportModel<Species> {
- public SpeciesModel(char separator) {
+ public SpeciesModel(char separator, Set<String> existingSpeciesName) {
super(separator);
// import definition
- newMandatoryColumn(Species.PROPERTY_NAME);
+ newNotExistingValueColumn(Species.PROPERTY_NAME, existingSpeciesName);
// export definition
Modified: trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/referential/TuttiReferentialImportExportService.java
===================================================================
--- trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/referential/TuttiReferentialImportExportService.java 2013-02-10 13:41:29 UTC (rev 379)
+++ trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/referential/TuttiReferentialImportExportService.java 2013-02-10 14:57:21 UTC (rev 380)
@@ -25,7 +25,10 @@
*/
import com.google.common.base.Charsets;
+import com.google.common.base.Function;
+import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
+import com.google.common.collect.Sets;
import com.google.common.io.Closeables;
import com.google.common.io.Files;
import fr.ifremer.tutti.persistence.entities.referential.Gear;
@@ -46,6 +49,7 @@
import java.io.IOException;
import java.io.Reader;
import java.util.List;
+import java.util.Set;
/**
* Service to import or export referential.
@@ -73,11 +77,19 @@
log.info("Will import species from file: " + file);
}
+ // get all species names
+ Set<String> existingSpeciesName = Sets.newHashSet(Iterables.transform(persistenceService.getAllSpecies(), new Function<Species, String>() {
+ @Override
+ public String apply(Species input) {
+ return input.getName();
+ }
+ }));
+
List<Species> toImport = Lists.newArrayList();
Reader reader = Files.newReader(file, Charsets.UTF_8);
try {
- SpeciesModel csvModel = new SpeciesModel(getCsvSeparator());
+ SpeciesModel csvModel = new SpeciesModel(getCsvSeparator(), existingSpeciesName);
Import<Species> importer = Import.newImport(csvModel, reader);
try {
@@ -107,11 +119,26 @@
log.info("Will import vessels from file: " + file);
}
+ // get all vessel names
+ Set<String> existingVesselName = Sets.newHashSet(Iterables.transform(persistenceService.getAllFishingVessel(), new Function<Vessel, String>() {
+ @Override
+ public String apply(Vessel input) {
+ return input.getName();
+ }
+ }));
+
+ existingVesselName.addAll(Lists.transform(persistenceService.getAllScientificVessel(), new Function<Vessel, String>() {
+ @Override
+ public String apply(Vessel input) {
+ return input.getName();
+ }
+ }));
+
List<Vessel> toImport = Lists.newArrayList();
Reader reader = Files.newReader(file, Charsets.UTF_8);
try {
- VesselModel csvModel = new VesselModel(getCsvSeparator());
+ VesselModel csvModel = new VesselModel(getCsvSeparator(), existingVesselName);
Import<Vessel> importer = Import.newImport(csvModel, reader);
try {
@@ -173,11 +200,26 @@
log.info("Will import gears from file: " + file);
}
+ // get all vessel names
+ Set<String> existingGearName = Sets.newHashSet(Iterables.transform(persistenceService.getAllFishingGear(), new Function<Gear, String>() {
+ @Override
+ public String apply(Gear input) {
+ return input.getName();
+ }
+ }));
+
+ existingGearName.addAll(Lists.transform(persistenceService.getAllScientificGear(), new Function<Gear, String>() {
+ @Override
+ public String apply(Gear input) {
+ return input.getName();
+ }
+ }));
+
List<Gear> toImport = Lists.newArrayList();
Reader reader = Files.newReader(file, Charsets.UTF_8);
try {
- GearModel csvModel = new GearModel(getCsvSeparator());
+ GearModel csvModel = new GearModel(getCsvSeparator(), existingGearName);
Import<Gear> importer = Import.newImport(csvModel, reader);
try {
@@ -196,8 +238,7 @@
Closeables.closeQuietly(reader);
}
- List<Gear> result =
- persistenceService.importTemporaryGear(toImport);
+ List<Gear> result = persistenceService.importTemporaryGear(toImport);
return result;
}
@@ -219,7 +260,7 @@
s.setName("Temporary Species name 3");
toExport.add(s);
- SpeciesModel csvModel = new SpeciesModel(getCsvSeparator());
+ SpeciesModel csvModel = new SpeciesModel(getCsvSeparator(), null);
BufferedWriter writer = Files.newWriter(file, Charsets.UTF_8);
try {
@@ -265,7 +306,7 @@
v.setScientificVessel(true);
toExport.add(v);
- VesselModel csvModel = new VesselModel(getCsvSeparator());
+ VesselModel csvModel = new VesselModel(getCsvSeparator(), null);
BufferedWriter writer = Files.newWriter(file, Charsets.UTF_8);
try {
@@ -345,7 +386,7 @@
g.setScientificGear(true);
toExport.add(g);
- GearModel csvModel = new GearModel(getCsvSeparator());
+ GearModel csvModel = new GearModel(getCsvSeparator(), null);
BufferedWriter writer = Files.newWriter(file, Charsets.UTF_8);
try {
Modified: trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/referential/VesselModel.java
===================================================================
--- trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/referential/VesselModel.java 2013-02-10 13:41:29 UTC (rev 379)
+++ trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/referential/VesselModel.java 2013-02-10 14:57:21 UTC (rev 380)
@@ -28,6 +28,8 @@
import fr.ifremer.tutti.service.TuttiCsvUtil;
import org.nuiton.util.csv.Common;
+import java.util.Set;
+
/**
* Model to import / export {@link Vessel} in csv format.
*
@@ -36,12 +38,12 @@
*/
public class VesselModel extends TuttiCsvUtil.AbstractTuttiImportExportModel<Vessel> {
- public VesselModel(char separator) {
+ public VesselModel(char separator, Set<String> existingVesselName) {
super(separator);
// import definition
- newMandatoryColumn(Vessel.PROPERTY_NAME);
+ newNotExistingValueColumn(Vessel.PROPERTY_NAME, existingVesselName);
newMandatoryColumn(Vessel.PROPERTY_INTERNATIONAL_REGISTRATION_CODE);
newMandatoryColumn(Vessel.PROPERTY_SCIENTIFIC_VESSEL, Common.PRIMITIVE_BOOLEAN);
1
0
r379 - in trunk/tutti-persistence: . src/main/java/fr/ifremer/tutti/persistence src/main/java/fr/ifremer/tutti/persistence/service src/test/java/fr/ifremer/tutti/persistence src/test/java/fr/ifremer/tutti/persistence/entities/protocol src/test/java/fr/ifremer/tutti/persistence/service src/test/java/fr/ifremer/tutti/persistence/service/synchro src/test/resources
by tchemit@users.forge.codelutin.com 10 Feb '13
by tchemit@users.forge.codelutin.com 10 Feb '13
10 Feb '13
Author: tchemit
Date: 2013-02-10 14:41:29 +0100 (Sun, 10 Feb 2013)
New Revision: 379
Url: http://forge.codelutin.com/projects/tutti/repository/revisions/379
Log:
- reformat + use basic code style -no Stringbuffer, no iterator, ...)
- improve tests(distinguish read and write tests)
- use default value in Autowired annotation
Added:
trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/AccidentalBatchPersistenceServiceReadTest.java
trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/AccidentalBatchPersistenceServiceWriteTest.java
trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceServiceReadTest.java
trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceServiceWriteTest.java
trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/CatchBatchPersistenceServiceReadTest.java
trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/CatchBatchPersistenceServiceWriteTest.java
trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/CruisePersistenceServiceReadTest.java
trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/CruisePersistenceServiceWriteTest.java
trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceServiceReadTest.java
trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceServiceWriteTest.java
trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/MacroWasteBatchPersistenceServiceReadTest.java
trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/MacroWasteBatchPersistenceServiceWriteTest.java
trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/PlanktonBatchPersistenceServiceReadTest.java
trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/PlanktonBatchPersistenceServiceWriteTest.java
trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ProgramPersistenceServiceReadTest.java
trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ProgramPersistenceServiceWriteTest.java
trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ProtocolPersistenceServiceReadTest.java
trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ProtocolPersistenceServiceWriteTest.java
trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceServiceReadTest.java
trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceServiceWriteTest.java
trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceReadTest.java
trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceWriteTest.java
trunk/tutti-persistence/src/test/resources/tutti-test-read.properties
trunk/tutti-persistence/src/test/resources/tutti-test-write.properties
Removed:
trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/AccidentalBatchPersistenceServiceTest.java
trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceServiceTest.java
trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/CatchBatchPersistenceServiceImplTest.java
trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/CruisePersistenceServiceTest.java
trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceServiceTest.java
trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/MacroWasteBatchPersistenceServiceTest.java
trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/PlanktonBatchPersistenceServiceTest.java
trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ProgramPersistenceServiceTest.java
trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ProtocolPersistenceServiceTest.java
trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceServiceTest.java
trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceTest.java
trunk/tutti-persistence/src/test/resources/tutti-test.properties
Modified:
trunk/tutti-persistence/pom.xml
trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistenceImpl.java
trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/AbstractPersistenceService.java
trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/CatchBatchPersistenceServiceImpl.java
trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/CruisePersistenceServiceImpl.java
trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceServiceImpl.java
trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/ProgramPersistenceServiceImpl.java
trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceService.java
trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceServiceImpl.java
trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceImpl.java
trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/DatabaseResource.java
trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/entities/protocol/TuttiProtocolsTest.java
trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/TuttiEnumerationFileTest.java
trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/synchro/ReferentialSynchronizeHelperTest.java
trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/synchro/ReferentialSynchronizeServiceImplTest.java
Modified: trunk/tutti-persistence/pom.xml
===================================================================
--- trunk/tutti-persistence/pom.xml 2013-02-09 07:44:17 UTC (rev 378)
+++ trunk/tutti-persistence/pom.xml 2013-02-10 13:41:29 UTC (rev 379)
@@ -36,7 +36,7 @@
<groupId>fr.ifremer.tutti</groupId>
<artifactId>tutti-persistence</artifactId>
- <name>Tutti :: Persistence API</name>
+ <name>Tutti :: Persistence</name>
<dependencies>
Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistenceImpl.java
===================================================================
--- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistenceImpl.java 2013-02-09 07:44:17 UTC (rev 378)
+++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistenceImpl.java 2013-02-10 13:41:29 UTC (rev 379)
@@ -221,7 +221,7 @@
String surveyCode = speciesProtocol.getSpeciesSurveyCode();
if (StringUtils.isNotBlank(surveyCode)) {
Integer taxonId =
- Integer.valueOf(speciesProtocol.getSpeciesReferenceTaxonId());
+ speciesProtocol.getSpeciesReferenceTaxonId();
surveyCodeByTaxonId.put(taxonId, surveyCode);
}
}
Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/AbstractPersistenceService.java
===================================================================
--- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/AbstractPersistenceService.java 2013-02-09 07:44:17 UTC (rev 378)
+++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/AbstractPersistenceService.java 2013-02-10 13:41:29 UTC (rev 379)
@@ -55,10 +55,10 @@
*
* @since 0.3
*/
- @Autowired(required = true)
+ @Autowired
protected SessionFactory sessionFactory;
- @Autowired(required = true)
+ @Autowired
protected TuttiEnumerationFile enumeration;
protected TuttiPersistenceConfig config;
Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/CatchBatchPersistenceServiceImpl.java
===================================================================
--- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/CatchBatchPersistenceServiceImpl.java 2013-02-09 07:44:17 UTC (rev 378)
+++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/CatchBatchPersistenceServiceImpl.java 2013-02-10 13:41:29 UTC (rev 379)
@@ -340,9 +340,7 @@
if (parentBatch.getChildBatchs() == null) {
return batchByQualitativeValueId;
}
- for (Iterator iterator = parentBatch.getChildBatchs()
- .iterator(); iterator.hasNext(); ) {
- Batch childBatch = (Batch) iterator.next();
+ for (Batch childBatch : parentBatch.getChildBatchs()) {
SortingMeasurement sm = measurementHelper.getSortingMeasurement((SortingBatch) childBatch, pmfmId, null, false);
if (sm != null && sm.getQualitativeValue() != null && sm.getQualitativeValue().getId() != null) {
batchByQualitativeValueId.put(sm.getQualitativeValue().getId(), (SortingBatch) childBatch);
@@ -393,7 +391,7 @@
String samplingRatioText = sampleWeight + "/" + weight;
samplingRatioText = samplingRatioText.replaceAll(",", ".");
target.setSamplingRatioText(samplingRatioText);
- target.setSamplingRatio(sampleWeight.floatValue() / weight.floatValue());
+ target.setSamplingRatio(sampleWeight / weight);
}
// Weight
Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/CruisePersistenceServiceImpl.java
===================================================================
--- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/CruisePersistenceServiceImpl.java 2013-02-09 07:44:17 UTC (rev 378)
+++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/CruisePersistenceServiceImpl.java 2013-02-10 13:41:29 UTC (rev 379)
@@ -86,10 +86,10 @@
protected static String CRUISE_MISC_DATA_SORT_MANAGERS_TAG = "#SORT_MANAGERS=";
- @Autowired(required = true)
+ @Autowired
protected ReferentialPersistenceService referentialService;
- @Autowired(required = true)
+ @Autowired
protected ProgramPersistenceService programService;
@Resource(name = "scientificCruiseDao")
@@ -212,8 +212,8 @@
miscData = miscData.substring(0, vesselTagIndex);
if (!vesselCodesStr.isEmpty()) {
String[] vesselCodes = vesselCodesStr.split(",");
- for (int i = 0; i < vesselCodes.length; i++) {
- vesselCode = vesselCodes[i];
+ for (String vesselCode1 : vesselCodes) {
+ vesselCode = vesselCode1;
result.addVessel(referentialService.getVessel(vesselCode));
}
}
@@ -226,8 +226,7 @@
miscData = miscData.substring(0, managersIndex);
if (!managersStr.isEmpty()) {
String[] managersArray = managersStr.split(",");
- for (int i = 0; i < managersArray.length; i++) {
- String personId = managersArray[i];
+ for (String personId : managersArray) {
Person person = referentialService.getPerson(Integer.valueOf(personId));
result.getHeadOfMission().add(person);
}
@@ -242,8 +241,7 @@
if (!sortManagersStr.isEmpty()) {
String[] managersArray = sortManagersStr.split(",");
List<Person> persons = new ArrayList<Person>();
- for (int i = 0; i < managersArray.length; i++) {
- String personId = managersArray[i];
+ for (String personId : managersArray) {
Person person = referentialService.getPerson(Integer.valueOf(personId));
persons.add(person);
}
@@ -277,7 +275,7 @@
}
// Force initialization of multirigNumber to 1 initialization (need for UI)
if (result.getMultirigNumber() == null) {
- log.warn(MessageFormat.format("Cruise with id={0} has been load with a default multirigNumber=1, beacause not multirigNumber were found in database.", new Object[]{id}));
+ log.warn(MessageFormat.format("Cruise with id={0} has been load with a default multirigNumber=1, beacause not multirigNumber were found in database.", id));
result.setMultirigNumber(1);
}
return result;
@@ -313,7 +311,7 @@
}
protected void cruiseToEntity(Cruise source, ScientificCruise target, boolean copyIfNull) {
- StringBuffer miscDataBuffer = new StringBuffer();
+ StringBuilder miscDataBuffer = new StringBuilder();
QualityFlag qualityFlagNotQualified = qualityFlagDao.load(enumeration.QUALITY_FLAG_CODE_NOT_QUALIFIED);
// Retrieve entities : FishingTrip
Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceServiceImpl.java
===================================================================
--- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceServiceImpl.java 2013-02-09 07:44:17 UTC (rev 378)
+++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceServiceImpl.java 2013-02-10 13:41:29 UTC (rev 379)
@@ -104,7 +104,7 @@
@Resource(name = "measurementPersistenceHelper")
protected MeasurementPersistenceHelper measurementHelper;
- @Autowired(required = true)
+ @Autowired
protected ReferentialPersistenceService referentialService;
@Resource(name = "scientificCruiseDao")
@@ -336,12 +336,12 @@
localite.setId(localiteId.toString());
result.setLocation(localite);
}
-
+
// Vessel (the one with the catch batch)
String vesselCode = (String) source[colIndex++];
if (vesselCode != null) {
- Vessel vessel = referentialService.getVessel(vesselCode);
- result.setVessel(vessel);
+ Vessel vessel = referentialService.getVessel(vesselCode);
+ result.setVessel(vessel);
}
// Retrieve environment caracteristics :
@@ -492,7 +492,7 @@
}
protected void beanToEntity(FishingOperation source, fr.ifremer.adagio.core.dao.data.operation.FishingOperation target, boolean copyIfNull) {
- StringBuffer nameBuffer = new StringBuffer();
+ StringBuilder nameBuffer = new StringBuilder();
// Retrieve entities : FishingTrip and ScientificCruise
ScientificCruise scientificCruise;
@@ -573,10 +573,10 @@
gearPhysicalFeatures.setOperations(Sets.newHashSet((Operation) target));
} else {
gearPhysicalFeatures.getOperations().add(target);
- }
+ }
}
if (source.getGear() != null && source.getGear().getLabel() != null) {
- nameBuffer.append(source.getGear().getLabel());
+ nameBuffer.append(source.getGear().getLabel());
}
// Retrieve entities : Fishing Area
@@ -606,10 +606,10 @@
// Retrieve multirig number, from Gear physical features
int cruiseMultirigCount = 1; // default value
if (gearPhysicalFeatures != null) {
- GearPhysicalMeasurement gpmMultirigCount = measurementHelper.getGearPhysicalMeasurement(gearPhysicalFeatures, enumeration.PMFM_ID_MULTIRIG_NUMBER);
- if (gpmMultirigCount != null && gpmMultirigCount.getNumericalValue() != null) {
- cruiseMultirigCount = gpmMultirigCount.getNumericalValue().intValue();
- }
+ GearPhysicalMeasurement gpmMultirigCount = measurementHelper.getGearPhysicalMeasurement(gearPhysicalFeatures, enumeration.PMFM_ID_MULTIRIG_NUMBER);
+ if (gpmMultirigCount != null && gpmMultirigCount.getNumericalValue() != null) {
+ cruiseMultirigCount = gpmMultirigCount.getNumericalValue().intValue();
+ }
}
// StationNumber
@@ -689,23 +689,22 @@
if (copyIfNull && source.getFishingOperationValid() == null) {
// Nothing to do : will be removed later, using notChangedVesselUseMeasurements
} else if (source.getFishingOperationValid() != null) {
- VesselUseMeasurement vum = setVesselUseMeasurement(scientificCruise, vesselUseFeatures, enumeration.PMFM_ID_HAUL_VALID, null, null, source.getFishingOperationValid().booleanValue() ? enumeration.QUALITATIVE_HAUL_VALID_YES : enumeration.QUALITATIVE_HAUL_VALID_NO);
+ VesselUseMeasurement vum = setVesselUseMeasurement(scientificCruise, vesselUseFeatures, enumeration.PMFM_ID_HAUL_VALID, null, null, source.getFishingOperationValid() ? enumeration.QUALITATIVE_HAUL_VALID_YES : enumeration.QUALITATIVE_HAUL_VALID_NO);
notChangedVesselUseMeasurements.remove(vum);
}
// Vessel
target.setVessel(fishingTrip.getVessel());
-
+
// Associated vessel
if (copyIfNull && source.getVessel() == null && target.getOperationVesselAssociations() != null) {
- target.getOperationVesselAssociations().clear();
+ target.getOperationVesselAssociations().clear();
+ } else if (source.getVessel() != null
+ && source.getVessel().getId() != null) {
+ setOperationVesselAssociation(target, source.getVessel().getId());
}
- else if(source.getVessel() != null
- && source.getVessel().getId() != null) {
- setOperationVesselAssociation(target, source.getVessel().getId());
- }
-
+
// Quality Flag :
if (target.getQualityFlag() == null) {
target.setQualityFlag(load(QualityFlagImpl.class, enumeration.QUALITY_FLAG_CODE_NOT_QUALIFIED));
@@ -858,7 +857,7 @@
target.setComments(miscDataBuffer.toString());
} else if (source.getComment() != null) {
// Store comment + misc data
- target.setComments(source.getComment() + miscDataBuffer.toString());
+ target.setComments(source.getComment() + miscDataBuffer);
}
// ----------------------------------------------------------------
@@ -1217,51 +1216,48 @@
}
return null;
}
-
+
protected void setOperationVesselAssociation(Operation target, String vesselCode) {
- OperationVesselAssociation ova = null;
- OperationVesselAssociationPK ovaPK = new OperationVesselAssociationPK();
- ovaPK.setVessel(load(VesselImpl.class, vesselCode));
- ovaPK.setOperation(target);
+ OperationVesselAssociation ova = null;
+ OperationVesselAssociationPK ovaPK = new OperationVesselAssociationPK();
+ ovaPK.setVessel(load(VesselImpl.class, vesselCode));
+ ovaPK.setOperation(target);
- // If vessel is equal as cruise vessel : do note store any VesselOperationAssociation entity
- if (vesselCode.equals(target.getVessel().getCode())) {
- removeAllOperationVesselAssociation(target);
- return;
- }
-
- // Retrieve existing association
- for (Iterator<OperationVesselAssociation> iterator = target.getOperationVesselAssociations().iterator(); iterator.hasNext();) {
- OperationVesselAssociation asso = iterator.next();
- if (asso.getOperationVesselAssociationPk().equals(ovaPK)) {
- ova = asso;
- break;
- }
- }
-
- // Create a new association
- if (ova == null) {
- ova = OperationVesselAssociation.Factory.newInstance();
- ova.setOperationVesselAssociationPk(ovaPK);
- if (target.getOperationVesselAssociations() == null) {
- target.setOperationVesselAssociations(Lists.newArrayList(ova));
- }
- else {
- removeAllOperationVesselAssociation(target);
- target.getOperationVesselAssociations().add(ova);
- }
- }
-
- ova.setIsCatchOnOperationVessel(Boolean.FALSE);
+ // If vessel is equal as cruise vessel : do note store any VesselOperationAssociation entity
+ if (vesselCode.equals(target.getVessel().getCode())) {
+ removeAllOperationVesselAssociation(target);
+ return;
+ }
+
+ // Retrieve existing association
+ for (OperationVesselAssociation asso : target.getOperationVesselAssociations()) {
+ if (asso.getOperationVesselAssociationPk().equals(ovaPK)) {
+ ova = asso;
+ break;
+ }
+ }
+
+ // Create a new association
+ if (ova == null) {
+ ova = OperationVesselAssociation.Factory.newInstance();
+ ova.setOperationVesselAssociationPk(ovaPK);
+ if (target.getOperationVesselAssociations() == null) {
+ target.setOperationVesselAssociations(Lists.newArrayList(ova));
+ } else {
+ removeAllOperationVesselAssociation(target);
+ target.getOperationVesselAssociations().add(ova);
+ }
+ }
+
+ ova.setIsCatchOnOperationVessel(Boolean.FALSE);
}
-
+
protected void removeAllOperationVesselAssociation(Operation target) {
- if(target.getOperationVesselAssociations() != null) {
- for (Iterator<OperationVesselAssociation> iterator = target.getOperationVesselAssociations().iterator(); iterator.hasNext();) {
- OperationVesselAssociation asso = iterator.next();
- operationVesselAssociationDao.remove(asso);
- }
- target.getOperationVesselAssociations().clear();
- }
+ if (target.getOperationVesselAssociations() != null) {
+ for (OperationVesselAssociation asso : target.getOperationVesselAssociations()) {
+ operationVesselAssociationDao.remove(asso);
+ }
+ target.getOperationVesselAssociations().clear();
+ }
}
}
Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/ProgramPersistenceServiceImpl.java
===================================================================
--- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/ProgramPersistenceServiceImpl.java 2013-02-09 07:44:17 UTC (rev 378)
+++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/ProgramPersistenceServiceImpl.java 2013-02-10 13:41:29 UTC (rev 379)
@@ -58,7 +58,7 @@
private static final Log log =
LogFactory.getLog(ProgramPersistenceServiceImpl.class);
- @Autowired(required = true)
+ @Autowired
protected ReferentialPersistenceService referentialService;
@Resource(name = "programDao")
@@ -97,15 +97,18 @@
"locationLevelId", IntegerType.INSTANCE, enumeration.LOCATION_LEVEL_ID_PROGRAM,
"locationClassificationId", IntegerType.INSTANCE, enumeration.LOCATION_CLASSIFICATION_ID_SECTOR);
- if (!list.hasNext()) {
- return null;
- }
+ Program result;
- // Keep only the first row (=the first location, if many found)
- Object[] source = list.next();
+ if (list.hasNext()) {
- Program result = new Program();
- loadProgram(result, source, true);
+ // Keep only the first row (=the first location, if many found)
+ Object[] source = list.next();
+
+ result = new Program();
+ loadProgram(result, source, true);
+ } else {
+ result = null;
+ }
return result;
}
@@ -115,6 +118,9 @@
Preconditions.checkNotNull(bean.getName());
Preconditions.checkArgument(bean.getId() == null);
+ if (log.isDebugEnabled()) {
+ log.debug("Create program with name: " + bean.getName());
+ }
fr.ifremer.adagio.core.dao.administration.programStrategy.Program program = fr.ifremer.adagio.core.dao.administration.programStrategy.Program.Factory.newInstance();
beanToEntity(bean, program, true);
program = programDao.create(program);
@@ -129,6 +135,10 @@
Preconditions.checkNotNull(bean.getName());
Preconditions.checkNotNull(bean.getId());
+
+ if (log.isDebugEnabled()) {
+ log.debug("Create program with name: " + bean.getName());
+ }
fr.ifremer.adagio.core.dao.administration.programStrategy.Program program = programDao.load(bean.getId());
if (program == null) {
throw new DataRetrievalFailureException("Could not retrieve program with code=" + bean.getId());
@@ -146,11 +156,12 @@
/**
* Sentinel value when comment is null (but database can't accept tis.
+ *
* @since 1.0
*/
public static final String EMPTY_COMMENT = "$$EMPTY_COMMENT$$";
- protected void loadProgram(Program result , Object[] source, boolean loadZone) {
+ protected void loadProgram(Program result, Object[] source, boolean loadZone) {
result.setId((String) source[0]);
result.setName((String) source[1]);
result.setComment((String) source[2]);
@@ -169,10 +180,10 @@
protected void beanToEntity(Program source,
fr.ifremer.adagio.core.dao.administration.programStrategy.Program target,
boolean copyIfNull) {
- // If target.description is a fake value (see bottom in this method), restore the null value
- if (target.getDescription() != null && target.getDescription().equals(target.getName())) {
- target.setDescription(null);
- }
+ // If target.description is a fake value (see bottom in this method), restore the null value
+ if (target.getDescription() != null && target.getDescription().equals(target.getName())) {
+ target.setDescription(null);
+ }
// Code : compute with : <prefixe><name>
if (target.getCode() == null && source.getName() != null) {
Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceService.java
===================================================================
--- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceService.java 2013-02-09 07:44:17 UTC (rev 378)
+++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceService.java 2013-02-10 13:41:29 UTC (rev 379)
@@ -215,12 +215,12 @@
*/
@Transactional(readOnly = false)
List<Gear> importTemporaryGear(List<Gear> gears);
-
-
+
+
/**
* Convert a PMFM ID into a SampleCategoryEnum.<br/>
* This method will typically use enumeration values, to compare with the given pmfmId.
- *
+ *
* @param pmfmId a Id of a PMFM
* @return a SampleCategoryEnum, or null if the PMFM is not mapped
*/
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-09 07:44:17 UTC (rev 378)
+++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceServiceImpl.java 2013-02-10 13:41:29 UTC (rev 379)
@@ -24,28 +24,8 @@
* #L%
*/
-import java.util.Date;
-import java.util.Iterator;
-import java.util.List;
-
-import javax.annotation.Resource;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.hibernate.Query;
-import org.hibernate.type.DateType;
-import org.hibernate.type.IntegerType;
-import org.hibernate.type.StringType;
-import org.springframework.cache.annotation.CacheEvict;
-import org.springframework.cache.annotation.CachePut;
-import org.springframework.cache.annotation.Cacheable;
-import org.springframework.dao.DataIntegrityViolationException;
-import org.springframework.dao.DataRetrievalFailureException;
-import org.springframework.stereotype.Service;
-
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
-
import fr.ifremer.adagio.core.dao.administration.user.PersonExtendDao;
import fr.ifremer.adagio.core.dao.data.vessel.VesselExtendDao;
import fr.ifremer.adagio.core.dao.referential.StatusDao;
@@ -67,7 +47,24 @@
import fr.ifremer.tutti.persistence.entities.referential.Status;
import fr.ifremer.tutti.persistence.entities.referential.Vessel;
import fr.ifremer.tutti.persistence.entities.referential.Zone;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.hibernate.Query;
+import org.hibernate.type.DateType;
+import org.hibernate.type.IntegerType;
+import org.hibernate.type.StringType;
+import org.springframework.cache.annotation.CacheEvict;
+import org.springframework.cache.annotation.CachePut;
+import org.springframework.cache.annotation.Cacheable;
+import org.springframework.dao.DataIntegrityViolationException;
+import org.springframework.dao.DataRetrievalFailureException;
+import org.springframework.stereotype.Service;
+import javax.annotation.Resource;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
+
/**
* Implementation of the {@link ReferentialPersistenceService} using a adagio
* data-source.
@@ -87,7 +84,7 @@
@Resource(name = "statusDao")
protected StatusDao statusDao;
-
+
@Resource(name = "personDao")
protected PersonExtendDao personDao;
@@ -322,10 +319,8 @@
Object[] source = queryUnique(
"person",
"personId", IntegerType.INSTANCE, personId);
-
- if (source == null) return null;
-
- Person result = loadPerson(source);
+
+ Person result = source == null ? null : loadPerson(source);
return result;
}
@@ -334,10 +329,8 @@
Object[] source = queryUnique(
"gear",
"gearId", IntegerType.INSTANCE, gearId);
-
- if (source == null) return null;
-
- Gear result = loadGear(source);
+
+ Gear result = source == null ? null : loadGear(source);
return result;
}
@@ -358,17 +351,17 @@
for (TaxonRefTaxVO source : sources) {
Species target = loadSpecies(source);
if (target.isReferenceTaxon()) {
-
+
// Add to cache :
- putToSpeciesReferentCache(Integer.valueOf(target.getReferenceTaxonId()), target);
- referenceTaxonsOnly.add(target);
+ putToSpeciesReferentCache(target.getReferenceTaxonId(), target);
+ referenceTaxonsOnly.add(target);
}
result.add(target);
}
-
+
// Add to cache :
putToSpeciesReferentCache(referenceTaxonsOnly);
-
+
return result;
}
@@ -384,27 +377,27 @@
continue;
}
Species target = loadSpecies(source);
-
+
// Add to cache :
- putToSpeciesReferentCache(Integer.valueOf(target.getReferenceTaxonId()), target);
-
+ putToSpeciesReferentCache(target.getReferenceTaxonId(), target);
+
result.add(target);
}
return result;
}
@Override
- @Cacheable(value = "species", key="#speciesId")
+ @Cacheable(value = "referentSpecies", key = "#speciesId")
public Species getSpeciesByReferenceTaxonId(Integer speciesId) {
- try {
- TaxonRefTaxVO source = taxonNameDao.getTaxonNameReferent(
- speciesId);
- Species target = loadSpecies(source);
- return target;
- }
- catch(DataRetrievalFailureException drfe) {
- return null;
- }
+ Species target;
+ try {
+ TaxonRefTaxVO source = taxonNameDao.getTaxonNameReferent(
+ speciesId);
+ target = loadSpecies(source);
+ } catch (DataRetrievalFailureException drfe) {
+ target = null;
+ }
+ return target;
}
@Override
@@ -421,12 +414,12 @@
if (!isProtectedCaracteristic(pmfmId)) {
Caracteristic target = loadCaracteristic(source);
putToCaracteristicCache(pmfmId, target);
-
+
result.add(target);
}
// If protected, load anyway just for the cache
else {
- putToCaracteristicCache(pmfmId, loadCaracteristic(source));
+ putToCaracteristicCache(pmfmId, loadCaracteristic(source));
}
}
return result;
@@ -484,7 +477,7 @@
}
@Override
- @Cacheable(value = "pmfms", key="#pmfmId")
+ @Cacheable(value = "pmfms", key = "#pmfmId")
public Caracteristic getCaracteristic(Integer pmfmId) {
Object[] source = queryUniqueWithStatus("pmfmById",
"pmfmId", IntegerType.INSTANCE, pmfmId,
@@ -494,7 +487,7 @@
}
@Override
- @CacheEvict(value = {"species", "referentSpecies"}, allEntries=true )
+ @CacheEvict(value = {"species", "referentSpecies"}, allEntries = true)
public List<Species> importTemporarySpecies(List<Species> species) {
List<Species> result = Lists.newArrayList();
for (Species source : species) {
@@ -505,20 +498,20 @@
}
@Override
- @CacheEvict(value = "fishingVessels", allEntries=true )
+ @CacheEvict(value = "fishingVessels", allEntries = true)
public List<Vessel> importTemporaryVessel(List<Vessel> vessels) {
- List<Vessel> result = Lists.newArrayList();
-
- fr.ifremer.adagio.core.dao.referential.Status status =
- statusDao.load(enumeration.STATUS_TEMPORARY_CODE);
- Integer countryLocationId =
- locationDao.getLocationIdByLabelAndLocationLevel(
- enumeration.LOCATION_LABEL_DEFAULT_COUNTRY,
- new Integer[]{enumeration.LOCATION_LEVEL_ID_COUNTRY});
+ List<Vessel> result = Lists.newArrayList();
+
+ fr.ifremer.adagio.core.dao.referential.Status status =
+ statusDao.load(enumeration.STATUS_TEMPORARY_CODE);
+ Integer countryLocationId =
+ locationDao.getLocationIdByLabelAndLocationLevel(
+ enumeration.LOCATION_LABEL_DEFAULT_COUNTRY,
+ new Integer[]{enumeration.LOCATION_LEVEL_ID_COUNTRY});
if (countryLocationId == null) {
- throw new DataIntegrityViolationException("Default country location not found, with label=" + enumeration.LOCATION_LABEL_DEFAULT_COUNTRY);
+ throw new DataIntegrityViolationException("Default country location not found, with label=" + enumeration.LOCATION_LABEL_DEFAULT_COUNTRY);
}
-
+
for (Vessel source : vessels) {
source = importTemporaryVessel(source, countryLocationId, status);
result.add(source);
@@ -527,12 +520,12 @@
}
@Override
- @CacheEvict(value = "persons", allEntries=true )
+ @CacheEvict(value = "persons", allEntries = true)
public List<Person> importTemporaryPerson(List<Person> persons) {
List<Person> result = Lists.newArrayList();
-
- fr.ifremer.adagio.core.dao.referential.Status status =
- statusDao.load(enumeration.STATUS_TEMPORARY_CODE);
+
+ fr.ifremer.adagio.core.dao.referential.Status status =
+ statusDao.load(enumeration.STATUS_TEMPORARY_CODE);
for (Person source : persons) {
source = importTemporaryPerson(source, status);
result.add(source);
@@ -541,12 +534,12 @@
}
@Override
- @CacheEvict(value = "gears", allEntries=true )
+ @CacheEvict(value = "gears", allEntries = true)
public List<Gear> importTemporaryGear(List<Gear> gears) {
List<Gear> result = Lists.newArrayList();
-
- fr.ifremer.adagio.core.dao.referential.Status status =
- statusDao.load(enumeration.STATUS_TEMPORARY_CODE);
+
+ fr.ifremer.adagio.core.dao.referential.Status status =
+ statusDao.load(enumeration.STATUS_TEMPORARY_CODE);
for (Gear source : gears) {
source = importTemporaryGear(source, status);
result.add(source);
@@ -559,93 +552,91 @@
//------------------------------------------------------------------------//
public Vessel importTemporaryVessel(Vessel source, Integer registrationLocationId, fr.ifremer.adagio.core.dao.referential.Status status) {
- Preconditions.checkNotNull(source);
- Preconditions.checkNotNull(source.getName());
- Preconditions.checkNotNull(source.getInternationalRegistrationCode());
+ Preconditions.checkNotNull(source);
+ Preconditions.checkNotNull(source.getName());
+ Preconditions.checkNotNull(source.getInternationalRegistrationCode());
- Integer vesselTypeId = null;
- if (source.isScientificVessel()) {
- vesselTypeId = enumeration.VESSEL_TYPE_ID_SCIENTIFIC;
- }
- else {
- vesselTypeId = enumeration.VESSEL_TYPE_ID_FISHING;
- }
-
- fr.ifremer.adagio.core.dao.referential.vessel.Vessel target =
- vesselExtendDao.createAsTemporary(
- null,
- source.getInternationalRegistrationCode(),
- registrationLocationId, source.getName(),
- vesselTypeId);
-
- // Fill the result bean
- Vessel result = new Vessel();
- result.setId(target.getCode());
- result.setName(source.getName());
- result.setRegistrationCode(source.getRegistrationCode());
- result.setInternationalRegistrationCode(source.getInternationalRegistrationCode());
- result.setScientificVessel(source.isScientificVessel());
+ Integer vesselTypeId;
+ if (source.isScientificVessel()) {
+ vesselTypeId = enumeration.VESSEL_TYPE_ID_SCIENTIFIC;
+ } else {
+ vesselTypeId = enumeration.VESSEL_TYPE_ID_FISHING;
+ }
+
+ fr.ifremer.adagio.core.dao.referential.vessel.Vessel target =
+ vesselExtendDao.createAsTemporary(
+ null,
+ source.getInternationalRegistrationCode(),
+ registrationLocationId, source.getName(),
+ vesselTypeId);
+
+ // Fill the result bean
+ Vessel result = new Vessel();
+ result.setId(target.getCode());
+ result.setName(source.getName());
+ result.setRegistrationCode(source.getRegistrationCode());
+ result.setInternationalRegistrationCode(source.getInternationalRegistrationCode());
+ result.setScientificVessel(source.isScientificVessel());
setStatus(status, result);
- return result;
+ return result;
}
public Person importTemporaryPerson(Person source, fr.ifremer.adagio.core.dao.referential.Status status) {
- Preconditions.checkNotNull(source);
- Preconditions.checkNotNull(source.getFirstName());
- Preconditions.checkNotNull(source.getLastName());
+ Preconditions.checkNotNull(source);
+ Preconditions.checkNotNull(source.getFirstName());
+ Preconditions.checkNotNull(source.getLastName());
- fr.ifremer.adagio.core.dao.administration.user.Person target = personDao.createAsTemporary(source.getLastName(), source.getFirstName(), enumeration.DEPARTMENT_ID_UNKNOWN_RECORDER_DEPARTMENT);
-
- // Fill the result bean
- Person result = new Person();
- result.setId(target.getId().toString());
- result.setLastName(source.getLastName());
- result.setFirstName(source.getFirstName());
+ fr.ifremer.adagio.core.dao.administration.user.Person target = personDao.createAsTemporary(source.getLastName(), source.getFirstName(), enumeration.DEPARTMENT_ID_UNKNOWN_RECORDER_DEPARTMENT);
+
+ // Fill the result bean
+ Person result = new Person();
+ result.setId(target.getId().toString());
+ result.setLastName(source.getLastName());
+ result.setFirstName(source.getFirstName());
setStatus(status, result);
- return result;
+ return result;
}
-
+
protected Species importTemporarySpecies(Species source) {
- Preconditions.checkNotNull(source);
- Preconditions.checkNotNull(source.getName());
+ Preconditions.checkNotNull(source);
+ Preconditions.checkNotNull(source.getName());
- TaxonRefTaxVO taxonName = new TaxonRefTaxVO();
- taxonName.setName(source.getName());
- taxonName = taxonNameDao.createAsTemporary(
- taxonName,
- "Added by tutti (file import).");
+ TaxonRefTaxVO taxonName = new TaxonRefTaxVO();
+ taxonName.setName(source.getName());
+ taxonName = taxonNameDao.createAsTemporary(
+ taxonName,
+ "Added by tutti (file import).");
// update the source
- Species result = loadSpecies(taxonName);
-
- // Add to cache
- putToSpeciesReferentCache(Integer.valueOf(result.getId()), result);
+ Species result = loadSpecies(taxonName);
- return result;
+ // Add to cache
+ putToSpeciesReferentCache(Integer.valueOf(result.getId()), result);
+
+ return result;
}
-
+
public Gear importTemporaryGear(Gear source, fr.ifremer.adagio.core.dao.referential.Status status) {
- Preconditions.checkNotNull(source);
- Preconditions.checkNotNull(source.getLabel());
- Preconditions.checkNotNull(source.getName());
+ Preconditions.checkNotNull(source);
+ Preconditions.checkNotNull(source.getLabel());
+ Preconditions.checkNotNull(source.getName());
- Integer gearClassificationId = null;
- if (source.isScientificGear()) {
- gearClassificationId = enumeration.GEAR_CLASSIFICIATION_ID_SCIENTIFIC;
- }
- else {
- gearClassificationId = enumeration.GEAR_CLASSIFICIATION_ID_FISHING;
- }
-
- fr.ifremer.adagio.core.dao.referential.gear.Gear target = fishingGearDao.createAsTemporary(source.getLabel(), source.getName(), gearClassificationId);
-
- // Fill the result bean
- Gear result = new Gear();
- result.setId(target.getId().toString());
- result.setLabel(source.getLabel());
- result.setName(source.getName());
+ Integer gearClassificationId;
+ if (source.isScientificGear()) {
+ gearClassificationId = enumeration.GEAR_CLASSIFICIATION_ID_SCIENTIFIC;
+ } else {
+ gearClassificationId = enumeration.GEAR_CLASSIFICIATION_ID_FISHING;
+ }
+
+ fr.ifremer.adagio.core.dao.referential.gear.Gear target = fishingGearDao.createAsTemporary(source.getLabel(), source.getName(), gearClassificationId);
+
+ // Fill the result bean
+ Gear result = new Gear();
+ result.setId(target.getId().toString());
+ result.setLabel(source.getLabel());
+ result.setName(source.getName());
setStatus(status, result);
- return result;
+ return result;
}
protected List<FishingOperationLocation> getFishingOperationLocations(Integer locationLevelId) {
@@ -839,17 +830,17 @@
@Cacheable(value = "pmfms", key = "#pmfmId")
protected Caracteristic putToCaracteristicCache(Integer pmfmId, Caracteristic caracteristic) {
- return caracteristic;
+ return caracteristic;
}
-
+
@CachePut(value = "referentSpecies")
protected List<Species> putToSpeciesReferentCache(List<Species> species) {
- return species;
+ return species;
}
@CachePut(value = "referentSpecies", key = "#speciesId")
protected Species putToSpeciesReferentCache(Integer speciesId, Species species) {
- return species;
+ return species;
}
}
Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceImpl.java
===================================================================
--- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceImpl.java 2013-02-09 07:44:17 UTC (rev 378)
+++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceImpl.java 2013-02-10 13:41:29 UTC (rev 379)
@@ -24,29 +24,9 @@
* #L%
*/
-import java.io.Serializable;
-import java.text.MessageFormat;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import javax.annotation.Resource;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.hibernate.FlushMode;
-import org.hibernate.type.IntegerType;
-import org.springframework.dao.DataIntegrityViolationException;
-import org.springframework.stereotype.Service;
-
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
-
import fr.ifremer.adagio.core.dao.data.batch.CatchBatchDao;
import fr.ifremer.adagio.core.dao.data.batch.CatchBatchImpl;
import fr.ifremer.adagio.core.dao.data.batch.SortingBatch;
@@ -66,7 +46,24 @@
import fr.ifremer.tutti.persistence.entities.referential.CaracteristicType;
import fr.ifremer.tutti.persistence.entities.referential.Species;
import fr.ifremer.tutti.persistence.service.measure.MeasurementPersistenceHelper;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.hibernate.FlushMode;
+import org.hibernate.type.IntegerType;
+import org.springframework.dao.DataIntegrityViolationException;
+import org.springframework.stereotype.Service;
+import javax.annotation.Resource;
+import java.io.Serializable;
+import java.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
/**
* @author tchemit <chemit(a)codelutin.com>
* @since 0.3
@@ -108,30 +105,27 @@
Map<String, String> parentBatchMapById = new HashMap<String, String>();
while (list.hasNext()) {
Object[] source = list.next();
-
+
Integer parentbatchId = (Integer) source[11];
-
+
// If row is not a species batch, load as batch frequency
- if (couldBeASpeciesBatchFrequency(source)){
- //TODO BLA : uncomment if a property speciesBatch.speciesBatchFrequency exists
- //loadSpeciesBatchFrequency(source, batchFrequenciesMapByParentId);
+ if (couldBeASpeciesBatchFrequency(source)) {
+ //TODO BLA : uncomment if a property speciesBatch.speciesBatchFrequency exists
+ //loadSpeciesBatchFrequency(source, batchFrequenciesMapByParentId);
+ } else {
+ // In all case, load row as species batch
+ SpeciesBatch speciesBatch = loadSpeciesBatch(source);
+
+ // Add result into a maps
+ batchMapById.put(speciesBatch.getId(), speciesBatch);
+ if (parentbatchId != null) {
+ parentBatchMapById.put(speciesBatch.getId(), parentbatchId.toString());
+ }
}
- else {
- // In all case, load row as species batch
- SpeciesBatch speciesBatch = loadSpeciesBatch(source);
-
- // Add result into a maps
- batchMapById.put(speciesBatch.getId(), speciesBatch);
- if (parentbatchId != null) {
- parentBatchMapById.put(speciesBatch.getId(), parentbatchId.toString());
- }
- }
}
// Retrieve the parent links for all batchs
- for (Iterator<SpeciesBatch> iterator = batchMapById.values().iterator(); iterator.hasNext(); ) {
- SpeciesBatch speciesBatch = (SpeciesBatch) iterator.next();
-
+ for (SpeciesBatch speciesBatch : batchMapById.values()) {
// If retrieve the parent from the parent map
String parentbatchId = parentBatchMapById.get(speciesBatch.getId());
if (parentbatchId != null) {
@@ -151,9 +145,9 @@
else {
rootBatchs.add(speciesBatch);
}
-
+
//TODO BLA : uncomment if a property speciesBatch.speciesBatchFrequency exists
- //List<SpeciesBatchFrequency> batchFrequencies = batchFrequenciesMapByParentId.get(speciesBatch.getId());
+ //List<SpeciesBatchFrequency> batchFrequencies = batchFrequenciesMapByParentId.get(speciesBatch.getId());
//if (batchFrequencies != null) {
// speciesBatch.setSpeciesBatchFrequency(batchFrequencies)
//}
@@ -193,7 +187,7 @@
// TODO BL : pourquoi un clear() ? => pas nécessaire.
//getCurrentSession().clear();
-
+
getCurrentSession().enableFetchProfile("batch-with-measurements");
getCurrentSession().setFlushMode(FlushMode.COMMIT);
SortingBatch batch = sortingBatchDao.load(Integer.valueOf(bean.getId()));
@@ -233,97 +227,95 @@
public List<SpeciesBatchFrequency> getAllSpeciesBatchFrequency(
String speciesBatchId) {
Iterator<Object[]> list = queryList("allSpeciesBatchFrequency",
- "parentBatchId", IntegerType.INSTANCE, Integer.valueOf(speciesBatchId));
+ "parentBatchId", IntegerType.INSTANCE, Integer.valueOf(speciesBatchId));
List<SpeciesBatchFrequency> results = Lists.newArrayList();
-
- while (list.hasNext()) {
- Object[] source = list.next();
- SpeciesBatchFrequency target = new SpeciesBatchFrequency();
-
- int colIndex = 0;
- target.setId(source[colIndex++].toString());
-
- target.setNumber((Integer)source[colIndex++]);
- target.setWeight((Float)source[colIndex++]);
- target.setComment((String)source[colIndex++]);
-
- // Length step category
- Integer lengthPmfmId = (Integer)source[colIndex++];
- Caracteristic lengthStepCaracteristic = referentialService.getCaracteristic(lengthPmfmId);
- target.setLengthStepCaracteristic(lengthStepCaracteristic);
-
- // Length
- target.setLengthStep((Float)source[colIndex++]);
- results.add(target);
- }
+
+ while (list.hasNext()) {
+ Object[] source = list.next();
+ SpeciesBatchFrequency target = new SpeciesBatchFrequency();
+
+ int colIndex = 0;
+ target.setId(source[colIndex++].toString());
+
+ target.setNumber((Integer) source[colIndex++]);
+ target.setWeight((Float) source[colIndex++]);
+ target.setComment((String) source[colIndex++]);
+
+ // Length step category
+ Integer lengthPmfmId = (Integer) source[colIndex++];
+ Caracteristic lengthStepCaracteristic = referentialService.getCaracteristic(lengthPmfmId);
+ target.setLengthStepCaracteristic(lengthStepCaracteristic);
+
+ // Length
+ target.setLengthStep((Float) source[colIndex++]);
+ results.add(target);
+ }
return results;
}
- @Override
+ @Override
public List<SpeciesBatchFrequency> saveSpeciesBatchFrequency(
String speciesBatchId, List<SpeciesBatchFrequency> frequencies) {
- Preconditions.checkNotNull(speciesBatchId);
- Preconditions.checkNotNull(frequencies);
-
- if (frequencies.size() == 0) {
- return frequencies;
- }
- getCurrentSession().setFlushMode(FlushMode.COMMIT);
+ Preconditions.checkNotNull(speciesBatchId);
+ Preconditions.checkNotNull(frequencies);
+
+ if (frequencies.size() == 0) {
+ return frequencies;
+ }
+ getCurrentSession().setFlushMode(FlushMode.COMMIT);
getCurrentSession().enableFetchProfile("batch-with-measurements");
-
- // Retirve parent
- SortingBatch parentBatch = sortingBatchDao.load(Integer.valueOf(speciesBatchId));
-
- short rankOrder = 0;
- String pmfmId = null;
- Map<SortingBatch, SpeciesBatchFrequency> batchsToCreate = Maps.newHashMap();
- List<SortingBatch> batchsToUpdate= Lists.newArrayList();
- for (Iterator iterator = frequencies.iterator(); iterator.hasNext();) {
- SpeciesBatchFrequency source = (SpeciesBatchFrequency) iterator.next();
- rankOrder++;
-
- // Check that all frequencies have the same length PMFM
- if (pmfmId == null) {
- source.getLengthStepCaracteristic().getId();
- }
- else if (!pmfmId.equals(source.getLengthStepCaracteristic().getId())) {
- throw new DataIntegrityViolationException("Batch frequencies under one Speciesbatch must have all the same lengthStepCaracteristic");
- }
-
- // Not existing batch
- SortingBatch target = null;
- if (source.getId() == null) {
- target = SortingBatch.Factory.newInstance();
-
- // Fill the sorting batch from the source
- beanToEntity(source, target, parentBatch, rankOrder, true);
-
- // Create the targeted batch, then update the source id
- sortingBatchDao.create(target);
- source.setId(target.getId().toString());
- }
-
- // Existing batch
- else {
- target = sortingBatchDao.load(Integer.valueOf(source.getId())) ;
-
- // Fill the sorting batch from the source
- beanToEntity(source, target, parentBatch, rankOrder, true);
-
- // Add the batch into a list (will be update later, using this list)
- batchsToUpdate.add(target);
- }
- }
-
- // If some batchs need to be update, do it
- if (batchsToUpdate.size() > 0) {
- sortingBatchDao.update(batchsToUpdate);
- }
-
- getCurrentSession().flush();
-
+
+ // Retirve parent
+ SortingBatch parentBatch = sortingBatchDao.load(Integer.valueOf(speciesBatchId));
+
+ short rankOrder = 0;
+ String pmfmId = null;
+ Map<SortingBatch, SpeciesBatchFrequency> batchsToCreate = Maps.newHashMap();
+ List<SortingBatch> batchsToUpdate = Lists.newArrayList();
+ for (SpeciesBatchFrequency source : frequencies) {
+ rankOrder++;
+
+ // Check that all frequencies have the same length PMFM
+ if (pmfmId == null) {
+ source.getLengthStepCaracteristic().getId();
+ } else if (!pmfmId.equals(source.getLengthStepCaracteristic().getId())) {
+ throw new DataIntegrityViolationException("Batch frequencies under one Speciesbatch must have all the same lengthStepCaracteristic");
+ }
+
+ // Not existing batch
+ SortingBatch target = null;
+ if (source.getId() == null) {
+ target = SortingBatch.Factory.newInstance();
+
+ // Fill the sorting batch from the source
+ beanToEntity(source, target, parentBatch, rankOrder, true);
+
+ // Create the targeted batch, then update the source id
+ sortingBatchDao.create(target);
+ source.setId(target.getId().toString());
+ }
+
+ // Existing batch
+ else {
+ target = sortingBatchDao.load(Integer.valueOf(source.getId()));
+
+ // Fill the sorting batch from the source
+ beanToEntity(source, target, parentBatch, rankOrder, true);
+
+ // Add the batch into a list (will be update later, using this list)
+ batchsToUpdate.add(target);
+ }
+ }
+
+ // If some batchs need to be update, do it
+ if (batchsToUpdate.size() > 0) {
+ sortingBatchDao.update(batchsToUpdate);
+ }
+
+ getCurrentSession().flush();
+
return frequencies;
}
@@ -352,7 +344,7 @@
// If parent and root need to be set
if (target.getId() == null
|| target.getRootBatch() == null
- || (target.getParentBatch() != null && !target.getParentBatch().getId().equals(parentBatchId))) {
+ || (target.getParentBatch() != null && !target.getParentBatch().getId().toString().equals(parentBatchId))) {
setBatchParents(source, target, parentBatchId, notChangedSortingMeasurements);
}
@@ -385,7 +377,7 @@
String samplingRatioText = source.getSampleCategoryWeight() + "/" + source.getWeight();
samplingRatioText = samplingRatioText.replaceAll(",", ".");
target.setSamplingRatioText(samplingRatioText);
- target.setSamplingRatio(source.getSampleCategoryWeight().floatValue() / source.getWeight().floatValue());
+ target.setSamplingRatio(source.getSampleCategoryWeight() / source.getWeight());
}
// Sorting measurement
@@ -455,7 +447,7 @@
Integer pmfmId = measurementHelper.sampleCategory2PmfmId(source.getSampleCategoryType());
if (pmfmId == null || !pmfmId.equals(enumeration.PMFM_ID_SORTED_UNSORTED)) {
throw new DataIntegrityViolationException(MessageFormat.format("A species batch with no parent should have a sampleCategoryType {0} (PMFM.ID={1})",
- new Object[]{SampleCategoryEnum.sortedUnsorted.name(), enumeration.PMFM_ID_SORTED_UNSORTED}));
+ SampleCategoryEnum.sortedUnsorted.name(), enumeration.PMFM_ID_SORTED_UNSORTED));
}
Integer qualitativeValueId = convertSampleCategoryValueIntoQualitativeId(source.getSampleCategoryValue());
@@ -517,7 +509,7 @@
if (pmfmId != null) {
setSampleCategoryQualitative(result, pmfmId, numValue, alphaValue, qvValue);
}
-
+
// Species
Integer referenceTaxonId = (Integer) source[colIndex++];
if (referenceTaxonId != null) {
@@ -525,7 +517,7 @@
Species species = referentialService.getSpeciesByReferenceTaxonId(referenceTaxonId);
result.setSpecies(species);
}
-
+
return result;
}
@@ -533,9 +525,7 @@
if (speciesBatchs == null || speciesBatchs.size() == 0) {
return;
}
- for (Iterator<SpeciesBatch> iterator = speciesBatchs.iterator(); iterator.hasNext(); ) {
- SpeciesBatch speciesBatch = iterator.next();
-
+ for (SpeciesBatch speciesBatch : speciesBatchs) {
// If batch store a species (in the database)
if (speciesBatch.getSpecies() != null) {
// Remove the link to the parent (not need in UI)
@@ -549,7 +539,7 @@
speciesBatch.setSampleCategoryType(SampleCategoryEnum.sortedUnsorted);
speciesBatch.setSampleCategoryValue(inheritedSortedUnsortedValue);
}
-
+
// Apply species inheritance, if need
if (speciesBatch.getSpecies() == null && inheritedSpecies != null) {
speciesBatch.setSpecies(inheritedSpecies);
@@ -557,17 +547,16 @@
// Compute the inheritance sorted/unsorted value for children
if (speciesBatch.getSampleCategoryType() == SampleCategoryEnum.sortedUnsorted) {
- inheritedSortedUnsortedValue = (CaracteristicQualitativeValue)speciesBatch.getSampleCategoryValue();
+ inheritedSortedUnsortedValue = (CaracteristicQualitativeValue) speciesBatch.getSampleCategoryValue();
+ } else {
+ inheritedSortedUnsortedValue = null;
}
- else {
- inheritedSortedUnsortedValue = null;
- }
-
+
// Recursive call : propagate species and sorted/unsorted value
applyInheritedProperties(speciesBatch.getChildBatchs(),
- inheritedSortedUnsortedValue,
- speciesBatch.getSpecies(),
- results);
+ inheritedSortedUnsortedValue,
+ speciesBatch.getSpecies(),
+ results);
}
}
@@ -584,14 +573,14 @@
}
protected void setSampleCategoryQualitative(SpeciesBatch target, Integer pmfmId, Float numericalvalue, String alphanumericalValue, Integer qualitativeValueId) {
- // skip if null or corresponding to the SORTING_TYPE PMFM (Expèce, Benthos, Plancton, etc.)
+ // skip if null or corresponding to the SORTING_TYPE PMFM (Expèce, Benthos, Plancton, etc.)
if (pmfmId == null || pmfmId.equals(enumeration.PMFM_ID_SORTING_TYPE)) {
return;
}
SampleCategoryEnum sampleCategory = referentialService.getSampleCategoryByPmfmId(pmfmId);
Preconditions.checkNotNull(sampleCategory, "Unable to find corresponding SampleCategoryEnum for PMFM.ID : " + pmfmId);
-
+
target.setSampleCategoryType(sampleCategory);
if (numericalvalue != null) {
target.setSampleCategoryValue(numericalvalue);
@@ -607,10 +596,8 @@
return;
}
CaracteristicQualitativeValue value = null;
- for (Iterator iterator = caracteristic.getQualitativeValue().iterator(); iterator
- .hasNext(); ) {
- CaracteristicQualitativeValue qv = (CaracteristicQualitativeValue) iterator.next();
- if (qualitativeValueId.intValue() == Integer.parseInt(qv.getId())) {
+ for (CaracteristicQualitativeValue qv : caracteristic.getQualitativeValue()) {
+ if (qualitativeValueId == Integer.parseInt(qv.getId())) {
value = qv;
break;
}
@@ -635,7 +622,7 @@
batch.getQuantificationMeasurements().clear();
sortingBatchDao.remove(batch);
}
-
+
protected void beanToEntity(SpeciesBatchFrequency source, SortingBatch target, SortingBatch parentBatch, short rankOrder, boolean copyIfNull) {
Preconditions.checkNotNull(source.getBatch());
Preconditions.checkNotNull(source.getBatch().getId());
@@ -715,62 +702,62 @@
}
}
}
-
+
private SpeciesBatchFrequency loadSpeciesBatchFrequency(Object[] source, Map<String, List<SpeciesBatchFrequency>> batchFrequenciesMapByParentId) {
- SpeciesBatchFrequency target = new SpeciesBatchFrequency();
-
- int colIndex = 0;
- target.setId(source[colIndex++].toString());
-
- // Individual count
- target.setNumber((Integer)source[colIndex++]);
-
- // Covert database weight (and sampling ratio) into UI weight
+ SpeciesBatchFrequency target = new SpeciesBatchFrequency();
+
+ int colIndex = 0;
+ target.setId(source[colIndex++].toString());
+
+ // Individual count
+ target.setNumber((Integer) source[colIndex++]);
+
+ // Covert database weight (and sampling ratio) into UI weight
Float sourceWeight = (Float) source[colIndex++];
Float sourceSamplingRatio = (Float) source[colIndex++];
String sourceSamplingRatioText = (String) source[colIndex++];
UIWeight uiWeight = convertDatabase2UI(sourceWeight, sourceSamplingRatio, sourceSamplingRatioText);
- target.setWeight(uiWeight.weight);
-
- target.setComment((String)source[colIndex++]);
-
- // Length step category
- Integer lengthPmfmId = (Integer)source[colIndex++];
- Caracteristic lengthStepCaracteristic = referentialService.getCaracteristic(lengthPmfmId);
- target.setLengthStepCaracteristic(lengthStepCaracteristic);
-
- // Qualitative value (should be null)
- Preconditions.checkState(source[colIndex++] == null, "Invalid batch tree format : batch frequency could not have a qualitative value.");
-
- // Length (skip qvValue and alphaValue column)
- target.setLengthStep((Float) source[colIndex++]);
+ target.setWeight(uiWeight.weight);
- // Alphanumerical value (should be null)
- Preconditions.checkState(source[colIndex++] == null, "Invalid batch tree format : batch frequency could not have a alphanumerical value.");
-
- // Taxon (should be null)
- Preconditions.checkState(source[colIndex++] == null, "Invalid batch tree format : taxon frequency could not have species.");
+ target.setComment((String) source[colIndex++]);
- Integer parentBatchId = (Integer)source[colIndex++];
-
- // Add target into the result map
- List<SpeciesBatchFrequency> parentBatchFrequencies = batchFrequenciesMapByParentId.get(parentBatchId.toString());
- if (parentBatchFrequencies == null) {
- parentBatchFrequencies = Lists.newArrayList();
- batchFrequenciesMapByParentId.put(parentBatchId.toString(), parentBatchFrequencies);
- }
- parentBatchFrequencies.add(target);
-
- return target;
- }
-
+ // Length step category
+ Integer lengthPmfmId = (Integer) source[colIndex++];
+ Caracteristic lengthStepCaracteristic = referentialService.getCaracteristic(lengthPmfmId);
+ target.setLengthStepCaracteristic(lengthStepCaracteristic);
+
+ // Qualitative value (should be null)
+ Preconditions.checkState(source[colIndex++] == null, "Invalid batch tree format : batch frequency could not have a qualitative value.");
+
+ // Length (skip qvValue and alphaValue column)
+ target.setLengthStep((Float) source[colIndex++]);
+
+ // Alphanumerical value (should be null)
+ Preconditions.checkState(source[colIndex++] == null, "Invalid batch tree format : batch frequency could not have a alphanumerical value.");
+
+ // Taxon (should be null)
+ Preconditions.checkState(source[colIndex++] == null, "Invalid batch tree format : taxon frequency could not have species.");
+
+ Integer parentBatchId = (Integer) source[colIndex++];
+
+ // Add target into the result map
+ List<SpeciesBatchFrequency> parentBatchFrequencies = batchFrequenciesMapByParentId.get(parentBatchId.toString());
+ if (parentBatchFrequencies == null) {
+ parentBatchFrequencies = Lists.newArrayList();
+ batchFrequenciesMapByParentId.put(parentBatchId.toString(), parentBatchFrequencies);
+ }
+ parentBatchFrequencies.add(target);
+
+ return target;
+ }
+
protected boolean couldBeASpeciesBatchFrequency(Object[] source) {
- Integer pmfmId = (Integer)source[6];
+ Integer pmfmId = (Integer) source[6];
Integer referenceTaxonId = (Integer) source[10];
Float numericalValue = (Float) source[8];
Integer parentbatchId = (Integer) source[11];
SampleCategoryEnum sampleCategory = referentialService.getSampleCategoryByPmfmId(pmfmId);
-
+
// Batch frequency is a batch with :
// - a numerical value
// - a parent
@@ -778,11 +765,11 @@
// - no corresponding sample category
return numericalValue != null && parentbatchId != null && referenceTaxonId == null && sampleCategory == null;
}
-
+
protected UIWeight convertDatabase2UI(Float weight, Float samplingRatio, String samplingRatioText) {
- UIWeight result = new UIWeight();
-
- // Weight & sampleCategory Weight
+ UIWeight result = new UIWeight();
+
+ // Weight & sampleCategory Weight
if (samplingRatio == null) {
result.weight = weight;
} else if (weight != null) {
@@ -790,16 +777,17 @@
if (samplingRatioText != null && samplingRatioText.startsWith(startStr)) {
String weightStr = samplingRatioText.substring(startStr.length());
if (weightStr != null && !weightStr.isEmpty()) {
- result.sampleWeight=weight;
- result.weight=Float.parseFloat(weightStr);
+ result.sampleWeight = weight;
+ result.weight = Float.parseFloat(weightStr);
}
}
}
return result;
}
-
- class UIWeight {
- Float sampleWeight=null;
- Float weight=null;
+
+ static class UIWeight {
+ Float sampleWeight = null;
+
+ Float weight = null;
}
}
Modified: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/DatabaseResource.java
===================================================================
--- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/DatabaseResource.java 2013-02-09 07:44:17 UTC (rev 378)
+++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/DatabaseResource.java 2013-02-10 13:41:29 UTC (rev 379)
@@ -43,6 +43,8 @@
import org.junit.runners.model.Statement;
import org.nuiton.util.ApplicationConfig;
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
@@ -50,6 +52,7 @@
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.List;
+import java.util.Properties;
import java.util.Set;
/**
@@ -79,14 +82,40 @@
private final String beanRefFactoryReferenceId;
- public DatabaseResource() {
- this(null, null);
+ private final boolean writeDb;
+
+ public static DatabaseResource readDb() {
+ return new DatabaseResource();
}
- public DatabaseResource(String beanFactoryReferenceLocation,
- String beanRefFactoryReferenceId) {
+ public static DatabaseResource writeDb() {
+ return new DatabaseResource(true);
+ }
+
+ public static DatabaseResource noDb() {
+ return new DatabaseResource(
+ "beanRefFactoryWitNoDb.xml", "TuttiBeanRefFactoryWithNoDb");
+ }
+
+ protected DatabaseResource() {
+ this(null, null, false);
+ }
+
+ protected DatabaseResource(boolean writeDb) {
+ this(null, null, writeDb);
+ }
+
+ protected DatabaseResource(String beanFactoryReferenceLocation,
+ String beanRefFactoryReferenceId) {
+ this(beanFactoryReferenceLocation, beanRefFactoryReferenceId, false);
+ }
+
+ protected DatabaseResource(String beanFactoryReferenceLocation,
+ String beanRefFactoryReferenceId,
+ boolean writeDb) {
this.beanFactoryReferenceLocation = beanFactoryReferenceLocation;
this.beanRefFactoryReferenceId = beanRefFactoryReferenceId;
+ this.writeDb = writeDb;
}
public TuttiPersistenceConfig getConfig() {
@@ -101,6 +130,8 @@
return new File(resourceDirectory, name);
}
+ boolean witherror = false;
+
@Override
public Statement apply(final Statement base, final Description description) {
@@ -110,6 +141,8 @@
before(description);
try {
base.evaluate();
+ } catch (Throwable e) {
+ witherror = true;
} finally {
after(description);
}
@@ -145,7 +178,9 @@
Thread.currentThread().setContextClassLoader(loader);
// check that config file is in classpath (avoid to find out why it does not works...)
- String configFilename = "tutti-test.properties";
+ String configFilename = writeDb ?
+ "tutti-test-write.properties" :
+ "tutti-test-read.properties";
InputStream resourceAsStream = getClass().getResourceAsStream("/" + configFilename);
Preconditions.checkNotNull(resourceAsStream, "Could not find " + configFilename + " in test class-path");
@@ -159,10 +194,42 @@
config = new TuttiPersistenceConfig(applicationConfig);
+ if (writeDb) {
+ FileUtils.copyDirectory(db, config.getDbDirectory());
+ }
+
+ // load db config
+ File dbConfig = new File(config.getDbDirectory(), config.getDbName() + ".properties");
+ Properties p = new Properties();
+ BufferedReader reader = Files.newReader(dbConfig, Charsets.UTF_8);
+ p.load(reader);
+ reader.close();
+
+ if (log.isDebugEnabled()) {
+ log.debug("Db config: " + dbConfig + "\n" + p);
+ }
+
+ if (writeDb) {
+
+ p.setProperty("readonly", "false");
+ BufferedWriter writer = Files.newWriter(dbConfig, Charsets.UTF_8);
+ p.store(writer, "");
+ writer.close();
+ } else {
+ // make sure db is on readonly mode
+ String readonly = p.getProperty("readonly");
+ Preconditions.checkNotNull(readonly, "Could not find readonly property on db confg: " + dbConfig);
+ Preconditions.checkState("true".equals(readonly), "readonly property must be at true value in read mode test in db confg: " + dbConfig);
+ }
+
config.initConfig(loader);
TuttiPersistenceConfig.setInstance(config);
+ if (log.isInfoEnabled()) {
+ log.info("Use db: " + config.getJdbcUrl());
+ }
+
if (log.isDebugEnabled()) {
log.debug("Use conf.properties at " + config.getDbConfigurationPath());
}
@@ -179,6 +246,13 @@
if (log.isInfoEnabled()) {
log.info("After test " + testClass);
}
+
+ if (writeDb && !witherror) {
+ if (log.isInfoEnabled()) {
+ log.info("Remove copy db at: " + config.getDbDirectory());
+ }
+ FileUtils.deleteDirectory(config.getDbDirectory());
+ }
// push back old classLoader
if (oldClassLoader != null) {
Thread.currentThread().setContextClassLoader(oldClassLoader);
Modified: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/entities/protocol/TuttiProtocolsTest.java
===================================================================
--- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/entities/protocol/TuttiProtocolsTest.java 2013-02-09 07:44:17 UTC (rev 378)
+++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/entities/protocol/TuttiProtocolsTest.java 2013-02-10 13:41:29 UTC (rev 379)
@@ -145,7 +145,7 @@
SpeciesProtocol sp1 = protocol.getSpecies().get(0);
Assert.assertNotNull(sp1);
Assert.assertEquals("1", sp1.getId());
- Assert.assertEquals(11242, sp1.getSpeciesReferenceTaxonId(),0);
+ Assert.assertEquals(11242, sp1.getSpeciesReferenceTaxonId(), 0);
Assert.assertEquals("BAR", sp1.getSpeciesSurveyCode());
Assert.assertEquals("1394", sp1.getLengthStepPmfmId());
Assert.assertFalse(sp1.isAgeEnabled());
@@ -159,7 +159,7 @@
SpeciesProtocol sp2 = protocol.getSpecies().get(1);
Assert.assertNotNull(sp2);
Assert.assertEquals("2", sp2.getId());
- Assert.assertEquals(3835, sp2.getSpeciesReferenceTaxonId(),0);
+ Assert.assertEquals(3835, sp2.getSpeciesReferenceTaxonId(), 0);
Assert.assertEquals("CHIN", sp2.getSpeciesSurveyCode());
Assert.assertEquals("323", sp2.getLengthStepPmfmId());
Assert.assertTrue(sp2.isAgeEnabled());
Copied: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/AccidentalBatchPersistenceServiceReadTest.java (from rev 378, trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/AccidentalBatchPersistenceServiceTest.java)
===================================================================
--- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/AccidentalBatchPersistenceServiceReadTest.java (rev 0)
+++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/AccidentalBatchPersistenceServiceReadTest.java 2013-02-10 13:41:29 UTC (rev 379)
@@ -0,0 +1,61 @@
+package fr.ifremer.tutti.persistence.service;
+
+/*
+ * #%L
+ * Tutti :: Persistence API
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2012 - 2013 Ifremer
+ * %%
+ * 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%
+ */
+
+import fr.ifremer.tutti.persistence.DatabaseResource;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Ignore;
+import org.junit.Test;
+
+/**
+ * To test {@link AccidentalBatchPersistenceService} for read operation.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 0.3
+ */
+@Ignore
+public class AccidentalBatchPersistenceServiceReadTest {
+
+ @ClassRule
+ public static final DatabaseResource dbResource = DatabaseResource.readDb();
+
+ protected AccidentalBatchPersistenceService service;
+
+ @Before
+ public void setUp() throws Exception {
+ service = TuttiPersistenceServiceLocator.getAccidentalBatchPersistenceService();
+ }
+
+ @Test
+ public void getAllAccidentalBatch(/*String fishingOperationId*/) {
+
+ }
+
+ @Test
+ public void getAccidentalBatch(/*String id*/) {
+
+ }
+}
Deleted: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/AccidentalBatchPersistenceServiceTest.java
===================================================================
--- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/AccidentalBatchPersistenceServiceTest.java 2013-02-09 07:44:17 UTC (rev 378)
+++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/AccidentalBatchPersistenceServiceTest.java 2013-02-10 13:41:29 UTC (rev 379)
@@ -1,73 +0,0 @@
-package fr.ifremer.tutti.persistence.service;
-
-/*
- * #%L
- * Tutti :: Persistence API
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2012 - 2013 Ifremer
- * %%
- * 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%
- */
-
-import fr.ifremer.tutti.persistence.DatabaseResource;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Ignore;
-import org.junit.Test;
-
-/**
- * @author tchemit <chemit(a)codelutin.com>
- * @since 0.3
- */
-@Ignore
-public class AccidentalBatchPersistenceServiceTest {
-
- @ClassRule
- public static final DatabaseResource dbResource = new DatabaseResource();
-
- protected AccidentalBatchPersistenceService service;
-
- @Before
- public void setUp() throws Exception {
- service = TuttiPersistenceServiceLocator.getAccidentalBatchPersistenceService();
- }
-
- @Test
- public void getAllAccidentalBatch(/*String fishingOperationId*/) {
-
- }
-
- @Test
- public void getAccidentalBatch(/*String id*/) {
-
- }
-
- @Test
- public void createAccidentalBatch(/*AccidentalBatch bean*/) {
-
- }
-
- @Test
- public void saveAccidentalBatch(/*AccidentalBatch bean*/) {
-
- }
-
- @Test
- public void deleteAccidentalBatch(/*String id*/) {
- }
-}
Copied: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/AccidentalBatchPersistenceServiceWriteTest.java (from rev 378, trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/AccidentalBatchPersistenceServiceTest.java)
===================================================================
--- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/AccidentalBatchPersistenceServiceWriteTest.java (rev 0)
+++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/AccidentalBatchPersistenceServiceWriteTest.java 2013-02-10 13:41:29 UTC (rev 379)
@@ -0,0 +1,65 @@
+package fr.ifremer.tutti.persistence.service;
+
+/*
+ * #%L
+ * Tutti :: Persistence API
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2012 - 2013 Ifremer
+ * %%
+ * 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%
+ */
+
+import fr.ifremer.tutti.persistence.DatabaseResource;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Ignore;
+import org.junit.Test;
+
+/**
+ * To test {@link AccidentalBatchPersistenceService} for write operation.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 0.3
+ */
+@Ignore
+public class AccidentalBatchPersistenceServiceWriteTest {
+
+ @ClassRule
+ public static final DatabaseResource dbResource = DatabaseResource.writeDb();
+
+ protected AccidentalBatchPersistenceService service;
+
+ @Before
+ public void setUp() throws Exception {
+ service = TuttiPersistenceServiceLocator.getAccidentalBatchPersistenceService();
+ }
+
+ @Test
+ public void createAccidentalBatch(/*AccidentalBatch bean*/) {
+
+ }
+
+ @Test
+ public void saveAccidentalBatch(/*AccidentalBatch bean*/) {
+
+ }
+
+ @Test
+ public void deleteAccidentalBatch(/*String id*/) {
+ }
+}
Copied: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceServiceReadTest.java (from rev 378, trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceServiceTest.java)
===================================================================
--- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceServiceReadTest.java (rev 0)
+++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceServiceReadTest.java 2013-02-10 13:41:29 UTC (rev 379)
@@ -0,0 +1,61 @@
+package fr.ifremer.tutti.persistence.service;
+
+/*
+ * #%L
+ * Tutti :: Persistence API
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2012 - 2013 Ifremer
+ * %%
+ * 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%
+ */
+
+import fr.ifremer.tutti.persistence.DatabaseResource;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Ignore;
+import org.junit.Test;
+
+/**
+ * To test {@link BenthosBatchPersistenceService} for read operation.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 0.3
+ */
+@Ignore
+public class BenthosBatchPersistenceServiceReadTest {
+
+ @ClassRule
+ public static final DatabaseResource dbResource = DatabaseResource.readDb();
+
+ protected BenthosBatchPersistenceService service;
+
+ @Before
+ public void setUp() throws Exception {
+ service = TuttiPersistenceServiceLocator.getBenthosBatchPersistenceService();
+ }
+
+ @Test
+ public void getAllBenthosBatch(/*String fishingOperationId*/) {
+
+ }
+
+ @Test
+ public void getBenthosBatch(/*String id*/) {
+
+ }
+}
Deleted: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceServiceTest.java
===================================================================
--- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceServiceTest.java 2013-02-09 07:44:17 UTC (rev 378)
+++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceServiceTest.java 2013-02-10 13:41:29 UTC (rev 379)
@@ -1,73 +0,0 @@
-package fr.ifremer.tutti.persistence.service;
-
-/*
- * #%L
- * Tutti :: Persistence API
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2012 - 2013 Ifremer
- * %%
- * 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%
- */
-
-import fr.ifremer.tutti.persistence.DatabaseResource;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Ignore;
-import org.junit.Test;
-
-/**
- * @author tchemit <chemit(a)codelutin.com>
- * @since 0.3
- */
-@Ignore
-public class BenthosBatchPersistenceServiceTest {
-
- @ClassRule
- public static final DatabaseResource dbResource = new DatabaseResource();
-
- protected BenthosBatchPersistenceService service;
-
- @Before
- public void setUp() throws Exception {
- service = TuttiPersistenceServiceLocator.getBenthosBatchPersistenceService();
- }
-
- @Test
- public void getAllBenthosBatch(/*String fishingOperationId*/) {
-
- }
-
- @Test
- public void getBenthosBatch(/*String id*/) {
-
- }
-
- @Test
- public void createBenthosBatch(/*BenthosBatch bean*/) {
-
- }
-
- @Test
- public void saveBenthosBatch(/*BenthosBatch bean*/) {
-
- }
-
- @Test
- public void deleteBenthosBatch(/*String id*/) {
- }
-}
Copied: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceServiceWriteTest.java (from rev 378, trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceServiceTest.java)
===================================================================
--- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceServiceWriteTest.java (rev 0)
+++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceServiceWriteTest.java 2013-02-10 13:41:29 UTC (rev 379)
@@ -0,0 +1,65 @@
+package fr.ifremer.tutti.persistence.service;
+
+/*
+ * #%L
+ * Tutti :: Persistence API
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2012 - 2013 Ifremer
+ * %%
+ * 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%
+ */
+
+import fr.ifremer.tutti.persistence.DatabaseResource;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Ignore;
+import org.junit.Test;
+
+/**
+ * To test {@link BenthosBatchPersistenceService} for write operation.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 0.3
+ */
+@Ignore
+public class BenthosBatchPersistenceServiceWriteTest {
+
+ @ClassRule
+ public static final DatabaseResource dbResource = DatabaseResource.writeDb();
+
+ protected BenthosBatchPersistenceService service;
+
+ @Before
+ public void setUp() throws Exception {
+ service = TuttiPersistenceServiceLocator.getBenthosBatchPersistenceService();
+ }
+
+ @Test
+ public void createBenthosBatch(/*BenthosBatch bean*/) {
+
+ }
+
+ @Test
+ public void saveBenthosBatch(/*BenthosBatch bean*/) {
+
+ }
+
+ @Test
+ public void deleteBenthosBatch(/*String id*/) {
+ }
+}
Deleted: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/CatchBatchPersistenceServiceImplTest.java
===================================================================
--- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/CatchBatchPersistenceServiceImplTest.java 2013-02-09 07:44:17 UTC (rev 378)
+++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/CatchBatchPersistenceServiceImplTest.java 2013-02-10 13:41:29 UTC (rev 379)
@@ -1,214 +0,0 @@
-package fr.ifremer.tutti.persistence.service;
-
-/*
- * #%L
- * Tutti :: Persistence API
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2012 - 2013 Ifremer
- * %%
- * 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%
- */
-
-import fr.ifremer.tutti.persistence.DatabaseResource;
-import fr.ifremer.tutti.persistence.entities.data.CatchBatch;
-import fr.ifremer.tutti.persistence.entities.data.Cruise;
-import fr.ifremer.tutti.persistence.entities.data.FishingOperation;
-import fr.ifremer.tutti.persistence.entities.referential.Species;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Test;
-
-import java.util.Calendar;
-import java.util.Date;
-import java.util.GregorianCalendar;
-import java.util.List;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-/**
- * @author tchemit <chemit(a)codelutin.com>
- * @since 1.0
- */
-public class CatchBatchPersistenceServiceImplTest {
-
- /** Logger. */
- private static final Log log =
- LogFactory.getLog(CatchBatchPersistenceServiceImplTest.class);
-
- @ClassRule
- public static final DatabaseResource dbResource = new DatabaseResource();
-
- protected CatchBatchPersistenceService service;
-
- protected CruisePersistenceService cruiseService;
-
- protected FishingOperationPersistenceService fishingOperationService;
-
- protected ReferentialPersistenceService referentialService;
-
- protected Cruise cruise;
-
- protected FishingOperation fishingOperation;
-
- protected List<Species> species;
-
- @Before
- public void setUp() throws Exception {
- service = TuttiPersistenceServiceLocator.getCatchBatchPersistenceService();
- cruiseService = TuttiPersistenceServiceLocator.getCruisePersistenceService();
- fishingOperationService = TuttiPersistenceServiceLocator.getFishingOperationPersistenceService();
- referentialService = TuttiPersistenceServiceLocator.getReferentialPersistenceService();
-
- cruise = cruiseService.getCruise(dbResource.getFixtures().cruiseId());
- cruise.setId(null);
- Calendar calendar = new GregorianCalendar();
- cruise.setBeginDate(calendar.getTime());
- cruise.setYear(calendar.get(Calendar.YEAR));
- calendar.add(Calendar.MONTH, 1); // add one month
- cruise.setEndDate(calendar.getTime());
- cruise = cruiseService.createCruise(cruise);
-
- List<FishingOperation> fishingOperations = fishingOperationService.getAllFishingOperation(dbResource.getFixtures().cruiseId());
- assertNotNull(fishingOperations);
- assertTrue(fishingOperations.size() > 0);
- fishingOperation = fishingOperations.get(0);
- fishingOperation = fishingOperationService.getFishingOperation(fishingOperation.getId());
- fishingOperation.setId(null);
- fishingOperation.setCruise(cruise);
- calendar.setTime(new Date());
- calendar.set(Calendar.HOUR_OF_DAY, 1);
- calendar.set(Calendar.MILLISECOND, 0);
- fishingOperation.setGearShootingStartDate(calendar.getTime());
- calendar.setTime(new Date());
- calendar.set(Calendar.HOUR_OF_DAY, 10);
- calendar.set(Calendar.MILLISECOND, 0);
- fishingOperation.setGearShootingEndDate(calendar.getTime());
-
- fishingOperation = fishingOperationService.createFishingOperation(fishingOperation);
- }
-
- @Test
- public void getCatchBatchFromFishingOperation() throws Exception {
-
- //TODO
- }
-
- @Test
- public void changeSpeciesBatchSpecies() {
- //TODO
- }
-
- @Test
- public void createAndSaveCatchBatch() throws Exception {
- CatchBatch catchBatch;
- CatchBatch createdCatchBatch;
- CatchBatch reloadedCatchBatch;
-
- catchBatch = new CatchBatch();
- catchBatch.setFishingOperation(fishingOperation);
-
- // -----------------------------------------------------------------------------
- // 1. Test with only mandatory properties
- // -----------------------------------------------------------------------------
-
- // Create and reload (test round trip)
- createdCatchBatch = service.createCatchBatch(catchBatch);
- assertNotNull(createdCatchBatch);
- assertNotNull(createdCatchBatch.getId());
-
- reloadedCatchBatch = service.getCatchBatchFromFishingOperation(fishingOperation.getId());
- assertNotNull(reloadedCatchBatch);
- assertEquals(createdCatchBatch.getId(), reloadedCatchBatch.getId());
-
- // -----------------------------------------------------------------------------
- // 2. Test with all properties
- // -----------------------------------------------------------------------------
- catchBatch.setId(null);
- // total weight : 100kg
- catchBatch.setCatchTotalWeight(75f);
- // Vrac :
- {
- // note : poids trie par la balance tremis (thalassa) (init par pupitri)
- catchBatch.setCatchTotalSortedTremisWeight(50f);
- // note : poids vrac caroussel (thalassa) (init par pupitri) (vrac trie) ou bien "poids trié fournie par la table de tri (Sum(Si)
- catchBatch.setCatchTotalSortedCarousselWeight(45f);
-
- // Species
- {
- catchBatch.setSpeciesTotalSortedWeight(12f);
- catchBatch.setSpeciesTotalSampleSortedWeight(8f);
- }
- }
- // Hors Vrac : 10kg
- {
- catchBatch.setCatchTotalUnsortedWeight(10f);
-
- // Species
- {
- catchBatch.setSpeciesTotalUnsortedWeight(10f);
- }
- }
- // Rejet : 15kg
- catchBatch.setCatchTotalRejectedWeight(15f);
-
- // Create and reload (test round trip)
- createdCatchBatch = service.createCatchBatch(catchBatch);
- assertNotNull(createdCatchBatch);
- assertNotNull(createdCatchBatch.getId());
-
- reloadedCatchBatch = service.getCatchBatchFromFishingOperation(fishingOperation.getId());
- assertNotNull(reloadedCatchBatch);
- assertEquals(createdCatchBatch.getCatchTotalWeight(), reloadedCatchBatch.getCatchTotalWeight());
- assertEquals(createdCatchBatch.getCatchTotalSortedCarousselWeight(), reloadedCatchBatch.getCatchTotalSortedCarousselWeight());
- assertEquals(createdCatchBatch.getCatchTotalSortedTremisWeight(), reloadedCatchBatch.getCatchTotalSortedTremisWeight());
- assertEquals(createdCatchBatch.getCatchTotalUnsortedWeight(), reloadedCatchBatch.getCatchTotalUnsortedWeight());
-
- assertEquals(createdCatchBatch.getSpeciesTotalSampleSortedWeight(), reloadedCatchBatch.getSpeciesTotalSampleSortedWeight());
- assertEquals(createdCatchBatch.getSpeciesTotalSortedWeight(), reloadedCatchBatch.getSpeciesTotalSortedWeight());
- assertEquals(createdCatchBatch.getSpeciesTotalUnsortedWeight(), reloadedCatchBatch.getSpeciesTotalUnsortedWeight());
-
- // -----------------------------------------------------------------------------
- // 2. Test save after modification
- // -----------------------------------------------------------------------------
- catchBatch.setCatchTotalSortedTremisWeight(null);
- catchBatch.setCatchTotalSortedCarousselWeight(null);
- catchBatch.setSpeciesTotalSortedWeight(null);
- catchBatch.setSpeciesTotalSampleSortedWeight(null);
- catchBatch.setCatchTotalUnsortedWeight(null);
- catchBatch.setSpeciesTotalUnsortedWeight(null);
- CatchBatch savedCatchBatch = service.saveCatchBatch(catchBatch);
- assertNotNull(savedCatchBatch);
- assertNotNull(savedCatchBatch.getId());
-
- reloadedCatchBatch = service.getCatchBatchFromFishingOperation(fishingOperation.getId());
- assertNotNull(reloadedCatchBatch);
- assertEquals(createdCatchBatch.getCatchTotalWeight(), reloadedCatchBatch.getCatchTotalWeight());
- assertEquals(createdCatchBatch.getCatchTotalSortedCarousselWeight(), reloadedCatchBatch.getCatchTotalSortedCarousselWeight());
- assertEquals(createdCatchBatch.getCatchTotalSortedTremisWeight(), reloadedCatchBatch.getCatchTotalSortedTremisWeight());
- assertEquals(createdCatchBatch.getCatchTotalUnsortedWeight(), reloadedCatchBatch.getCatchTotalUnsortedWeight());
-
- assertEquals(createdCatchBatch.getSpeciesTotalSampleSortedWeight(), reloadedCatchBatch.getSpeciesTotalSampleSortedWeight());
- assertEquals(createdCatchBatch.getSpeciesTotalSortedWeight(), reloadedCatchBatch.getSpeciesTotalSortedWeight());
- assertEquals(createdCatchBatch.getSpeciesTotalUnsortedWeight(), reloadedCatchBatch.getSpeciesTotalUnsortedWeight());
- }
-
-}
Copied: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/CatchBatchPersistenceServiceReadTest.java (from rev 378, trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/CatchBatchPersistenceServiceImplTest.java)
===================================================================
--- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/CatchBatchPersistenceServiceReadTest.java (rev 0)
+++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/CatchBatchPersistenceServiceReadTest.java 2013-02-10 13:41:29 UTC (rev 379)
@@ -0,0 +1,58 @@
+package fr.ifremer.tutti.persistence.service;
+
+/*
+ * #%L
+ * Tutti :: Persistence API
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2012 - 2013 Ifremer
+ * %%
+ * 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%
+ */
+
+import fr.ifremer.tutti.persistence.DatabaseResource;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Ignore;
+import org.junit.Test;
+
+/**
+ * To test {@link CatchBatchPersistenceService} for read operation.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.0
+ */
+@Ignore
+public class CatchBatchPersistenceServiceReadTest {
+
+ @ClassRule
+ public static final DatabaseResource dbResource = DatabaseResource.readDb();
+
+ protected CatchBatchPersistenceService service;
+
+ @Before
+ public void setUp() throws Exception {
+ service = TuttiPersistenceServiceLocator.getCatchBatchPersistenceService();
+ }
+
+ @Test
+ public void getCatchBatchFromFishingOperation() throws Exception {
+
+ //TODO
+ }
+
+}
Copied: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/CatchBatchPersistenceServiceWriteTest.java (from rev 378, trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/CatchBatchPersistenceServiceImplTest.java)
===================================================================
--- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/CatchBatchPersistenceServiceWriteTest.java (rev 0)
+++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/CatchBatchPersistenceServiceWriteTest.java 2013-02-10 13:41:29 UTC (rev 379)
@@ -0,0 +1,204 @@
+package fr.ifremer.tutti.persistence.service;
+
+/*
+ * #%L
+ * Tutti :: Persistence API
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2012 - 2013 Ifremer
+ * %%
+ * 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%
+ */
+
+import fr.ifremer.tutti.persistence.DatabaseResource;
+import fr.ifremer.tutti.persistence.entities.data.CatchBatch;
+import fr.ifremer.tutti.persistence.entities.data.Cruise;
+import fr.ifremer.tutti.persistence.entities.data.FishingOperation;
+import fr.ifremer.tutti.persistence.entities.referential.Species;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Test;
+
+import java.util.Calendar;
+import java.util.Date;
+import java.util.GregorianCalendar;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * To test {@link CatchBatchPersistenceService} for write operation.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.0
+ */
+public class CatchBatchPersistenceServiceWriteTest {
+
+ @ClassRule
+ public static final DatabaseResource dbResource = DatabaseResource.writeDb();
+
+ protected CatchBatchPersistenceService service;
+
+ protected CruisePersistenceService cruiseService;
+
+ protected FishingOperationPersistenceService fishingOperationService;
+
+ protected ReferentialPersistenceService referentialService;
+
+ protected Cruise cruise;
+
+ protected FishingOperation fishingOperation;
+
+ protected List<Species> species;
+
+ @Before
+ public void setUp() throws Exception {
+ service = TuttiPersistenceServiceLocator.getCatchBatchPersistenceService();
+ cruiseService = TuttiPersistenceServiceLocator.getCruisePersistenceService();
+ fishingOperationService = TuttiPersistenceServiceLocator.getFishingOperationPersistenceService();
+ referentialService = TuttiPersistenceServiceLocator.getReferentialPersistenceService();
+
+ cruise = cruiseService.getCruise(dbResource.getFixtures().cruiseId());
+ cruise.setId(null);
+ Calendar calendar = new GregorianCalendar();
+ cruise.setBeginDate(calendar.getTime());
+ cruise.setYear(calendar.get(Calendar.YEAR));
+ calendar.add(Calendar.MONTH, 1); // add one month
+ cruise.setEndDate(calendar.getTime());
+ cruise = cruiseService.createCruise(cruise);
+
+ List<FishingOperation> fishingOperations = fishingOperationService.getAllFishingOperation(dbResource.getFixtures().cruiseId());
+ assertNotNull(fishingOperations);
+ assertTrue(fishingOperations.size() > 0);
+ fishingOperation = fishingOperations.get(0);
+ fishingOperation = fishingOperationService.getFishingOperation(fishingOperation.getId());
+ fishingOperation.setId(null);
+ fishingOperation.setCruise(cruise);
+ calendar.setTime(new Date());
+ calendar.set(Calendar.HOUR_OF_DAY, 1);
+ calendar.set(Calendar.MILLISECOND, 0);
+ fishingOperation.setGearShootingStartDate(calendar.getTime());
+ calendar.setTime(new Date());
+ calendar.set(Calendar.HOUR_OF_DAY, 10);
+ calendar.set(Calendar.MILLISECOND, 0);
+ fishingOperation.setGearShootingEndDate(calendar.getTime());
+
+ fishingOperation = fishingOperationService.createFishingOperation(fishingOperation);
+ }
+
+ @Test
+ public void changeSpeciesBatchSpecies() {
+ //TODO
+ }
+
+ @Test
+ public void createAndSaveCatchBatch() throws Exception {
+ CatchBatch catchBatch;
+ CatchBatch createdCatchBatch;
+ CatchBatch reloadedCatchBatch;
+
+ catchBatch = new CatchBatch();
+ catchBatch.setFishingOperation(fishingOperation);
+
+ // -----------------------------------------------------------------------------
+ // 1. Test with only mandatory properties
+ // -----------------------------------------------------------------------------
+
+ // Create and reload (test round trip)
+ createdCatchBatch = service.createCatchBatch(catchBatch);
+ assertNotNull(createdCatchBatch);
+ assertNotNull(createdCatchBatch.getId());
+
+ reloadedCatchBatch = service.getCatchBatchFromFishingOperation(fishingOperation.getId());
+ assertNotNull(reloadedCatchBatch);
+ assertEquals(createdCatchBatch.getId(), reloadedCatchBatch.getId());
+
+ // -----------------------------------------------------------------------------
+ // 2. Test with all properties
+ // -----------------------------------------------------------------------------
+ catchBatch.setId(null);
+ // total weight : 100kg
+ catchBatch.setCatchTotalWeight(75f);
+ // Vrac :
+ {
+ // note : poids trie par la balance tremis (thalassa) (init par pupitri)
+ catchBatch.setCatchTotalSortedTremisWeight(50f);
+ // note : poids vrac caroussel (thalassa) (init par pupitri) (vrac trie) ou bien "poids trié fournie par la table de tri (Sum(Si)
+ catchBatch.setCatchTotalSortedCarousselWeight(45f);
+
+ // Species
+ {
+ catchBatch.setSpeciesTotalSortedWeight(12f);
+ catchBatch.setSpeciesTotalSampleSortedWeight(8f);
+ }
+ }
+ // Hors Vrac : 10kg
+ {
+ catchBatch.setCatchTotalUnsortedWeight(10f);
+
+ // Species
+ {
+ catchBatch.setSpeciesTotalUnsortedWeight(10f);
+ }
+ }
+ // Rejet : 15kg
+ catchBatch.setCatchTotalRejectedWeight(15f);
+
+ // Create and reload (test round trip)
+ createdCatchBatch = service.createCatchBatch(catchBatch);
+ assertNotNull(createdCatchBatch);
+ assertNotNull(createdCatchBatch.getId());
+
+ reloadedCatchBatch = service.getCatchBatchFromFishingOperation(fishingOperation.getId());
+ assertNotNull(reloadedCatchBatch);
+ assertEquals(createdCatchBatch.getCatchTotalWeight(), reloadedCatchBatch.getCatchTotalWeight());
+ assertEquals(createdCatchBatch.getCatchTotalSortedCarousselWeight(), reloadedCatchBatch.getCatchTotalSortedCarousselWeight());
+ assertEquals(createdCatchBatch.getCatchTotalSortedTremisWeight(), reloadedCatchBatch.getCatchTotalSortedTremisWeight());
+ assertEquals(createdCatchBatch.getCatchTotalUnsortedWeight(), reloadedCatchBatch.getCatchTotalUnsortedWeight());
+
+ assertEquals(createdCatchBatch.getSpeciesTotalSampleSortedWeight(), reloadedCatchBatch.getSpeciesTotalSampleSortedWeight());
+ assertEquals(createdCatchBatch.getSpeciesTotalSortedWeight(), reloadedCatchBatch.getSpeciesTotalSortedWeight());
+ assertEquals(createdCatchBatch.getSpeciesTotalUnsortedWeight(), reloadedCatchBatch.getSpeciesTotalUnsortedWeight());
+
+ // -----------------------------------------------------------------------------
+ // 2. Test save after modification
+ // -----------------------------------------------------------------------------
+ catchBatch.setCatchTotalSortedTremisWeight(null);
+ catchBatch.setCatchTotalSortedCarousselWeight(null);
+ catchBatch.setSpeciesTotalSortedWeight(null);
+ catchBatch.setSpeciesTotalSampleSortedWeight(null);
+ catchBatch.setCatchTotalUnsortedWeight(null);
+ catchBatch.setSpeciesTotalUnsortedWeight(null);
+ CatchBatch savedCatchBatch = service.saveCatchBatch(catchBatch);
+ assertNotNull(savedCatchBatch);
+ assertNotNull(savedCatchBatch.getId());
+
+ reloadedCatchBatch = service.getCatchBatchFromFishingOperation(fishingOperation.getId());
+ assertNotNull(reloadedCatchBatch);
+ assertEquals(createdCatchBatch.getCatchTotalWeight(), reloadedCatchBatch.getCatchTotalWeight());
+ assertEquals(createdCatchBatch.getCatchTotalSortedCarousselWeight(), reloadedCatchBatch.getCatchTotalSortedCarousselWeight());
+ assertEquals(createdCatchBatch.getCatchTotalSortedTremisWeight(), reloadedCatchBatch.getCatchTotalSortedTremisWeight());
+ assertEquals(createdCatchBatch.getCatchTotalUnsortedWeight(), reloadedCatchBatch.getCatchTotalUnsortedWeight());
+
+ assertEquals(createdCatchBatch.getSpeciesTotalSampleSortedWeight(), reloadedCatchBatch.getSpeciesTotalSampleSortedWeight());
+ assertEquals(createdCatchBatch.getSpeciesTotalSortedWeight(), reloadedCatchBatch.getSpeciesTotalSortedWeight());
+ assertEquals(createdCatchBatch.getSpeciesTotalUnsortedWeight(), reloadedCatchBatch.getSpeciesTotalUnsortedWeight());
+ }
+
+}
Copied: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/CruisePersistenceServiceReadTest.java (from rev 378, trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/CruisePersistenceServiceTest.java)
===================================================================
--- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/CruisePersistenceServiceReadTest.java (rev 0)
+++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/CruisePersistenceServiceReadTest.java 2013-02-10 13:41:29 UTC (rev 379)
@@ -0,0 +1,70 @@
+package fr.ifremer.tutti.persistence.service;
+
+/*
+ * #%L
+ * Tutti :: Persistence API
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2012 - 2013 Ifremer
+ * %%
+ * 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%
+ */
+
+import fr.ifremer.tutti.persistence.DatabaseResource;
+import fr.ifremer.tutti.persistence.entities.data.Cruise;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Test;
+
+import java.util.List;
+
+/**
+ * To test {@link CruisePersistenceService} for read operation.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 0.3
+ */
+public class CruisePersistenceServiceReadTest {
+
+ @ClassRule
+ public static final DatabaseResource dbResource = DatabaseResource.readDb();
+
+ protected CruisePersistenceService service;
+
+ @Before
+ public void setUp() throws Exception {
+ service = TuttiPersistenceServiceLocator.getCruisePersistenceService();
+ }
+
+ @Test
+ public void getAllCruise(/*String programId*/) {
+ String programCode = dbResource.getFixtures().programCode();
+ List<Cruise> result = service.getAllCruise(programCode);
+ Assert.assertNotNull(result);
+ Assert.assertFalse(result.isEmpty());
+ }
+
+ @Test
+ public void getCruise(/*String id*/) {
+
+ String cruiseId = dbResource.getFixtures().cruiseId();
+ Cruise result = service.getCruise(cruiseId);
+ Assert.assertNotNull(result);
+ }
+
+}
Deleted: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/CruisePersistenceServiceTest.java
===================================================================
--- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/CruisePersistenceServiceTest.java 2013-02-09 07:44:17 UTC (rev 378)
+++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/CruisePersistenceServiceTest.java 2013-02-10 13:41:29 UTC (rev 379)
@@ -1,248 +0,0 @@
-package fr.ifremer.tutti.persistence.service;
-
-/*
- * #%L
- * Tutti :: Persistence API
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2012 - 2013 Ifremer
- * %%
- * 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%
- */
-
-import com.google.common.collect.Lists;
-import fr.ifremer.tutti.persistence.DatabaseResource;
-import fr.ifremer.tutti.persistence.entities.data.Cruise;
-import fr.ifremer.tutti.persistence.entities.referential.Country;
-import fr.ifremer.tutti.persistence.entities.referential.Gear;
-import fr.ifremer.tutti.persistence.entities.referential.Person;
-import fr.ifremer.tutti.persistence.entities.referential.Vessel;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Ignore;
-import org.junit.Test;
-
-import java.util.Calendar;
-import java.util.GregorianCalendar;
-import java.util.List;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-
-/**
- * @author tchemit <chemit(a)codelutin.com>
- * @since 0.3
- */
-public class CruisePersistenceServiceTest {
-
- /** Logger. */
- private static final Log log =
- LogFactory.getLog(CruisePersistenceServiceTest.class);
-
- @ClassRule
- public static final DatabaseResource dbResource = new DatabaseResource();
-
- protected ReferentialPersistenceService referentialService;
-
- protected ProgramPersistenceService programService;
-
- protected CruisePersistenceService service;
-
- @Before
- public void setUp() throws Exception {
- service = TuttiPersistenceServiceLocator.getCruisePersistenceService();
- referentialService = TuttiPersistenceServiceLocator.getReferentialPersistenceService();
- programService = TuttiPersistenceServiceLocator.getProgramPersistenceService();
- }
-
- @Test
- public void getAllCruise(/*String programId*/) {
- String programCode = dbResource.getFixtures().programCode();
- List<Cruise> result = service.getAllCruise(programCode);
- Assert.assertNotNull(result);
- Assert.assertFalse(result.isEmpty());
- }
-
- @Test
- public void getCruise(/*String id*/) {
-
- String cruiseId = dbResource.getFixtures().cruiseId();
- Cruise result = service.getCruise(cruiseId);
- Assert.assertNotNull(result);
- }
-
- @Ignore
- @Test
- public void createCruise(/*Cruise bean*/) {
- String programCode = dbResource.getFixtures().programCode();
- Cruise cruise = new Cruise();
-
- // -----------------------------------------------------------------------------
- // 1. Test with all properties filled
- // -----------------------------------------------------------------------------
- cruise.setId(null);
-
- cruise.setName("Unit-test-" + System.currentTimeMillis());
-
- cruise.setProgram(programService.getProgram(programCode));
-
- Calendar calendar = new GregorianCalendar();
- cruise.setBeginDate(calendar.getTime());
-
- cruise.setYear(calendar.get(Calendar.YEAR));
-
- calendar.add(Calendar.MONTH, 1); // add one month
- cruise.setEndDate(calendar.getTime());
-
- Country country = null;
- List<Country> countries = referentialService.getAllCountry();
- for (Country aCountry : countries) {
- if (aCountry.getLabel() != null && aCountry.getLabel().equals("FRA")) {
- country = aCountry;
- break;
- }
- }
- assertNotNull("Could not load FRA country", country);
- cruise.setCountry(country);
-
- List<Gear> gears = referentialService.getAllFishingGear();
- cruise.setGear(gears);
-
- cruise.setComment("My comments on cruise");
-
- Person managerPerson = referentialService.getAllPerson().get(0);
- cruise.setHeadOfMission(Lists.newArrayList(managerPerson));
-
- List<Vessel> vessels = Lists.newArrayList();
- vessels.add(referentialService.getAllScientificVessel().get(0));
- Vessel fishingVessel = new Vessel();
- fishingVessel.setId(dbResource.getFixtures().fishingVesselCode());
- vessels.add(fishingVessel);
-
- cruise.setVessel(vessels);
-
- cruise.setMultirigNumber(2);
-
- // Create cruise in database
- Cruise createdCruise = service.createCruise(cruise);
- assertNotNull(createdCruise);
- assertNotNull(createdCruise.getId());
- assertEquals(cruise.getName(), createdCruise.getName());
-
- if (log.isInfoEnabled()) {
- log.info("Created cruise: " + createdCruise.getId());
- }
-
- // Then reload cruise and compare
- Cruise reloadedCruise = service.getCruise(createdCruise.getId());
- calendar.setTime(createdCruise.getBeginDate());
- calendar.set(Calendar.SECOND, 0);
- calendar.set(Calendar.MILLISECOND, 0);
- assertEquals(calendar.getTime(), reloadedCruise.getBeginDate());
- calendar.setTime(createdCruise.getEndDate());
- calendar.set(Calendar.SECOND, 0);
- calendar.set(Calendar.MILLISECOND, 0);
- assertEquals(calendar.getTime(), reloadedCruise.getEndDate());
- assertEquals(cruise.getMultirigNumber(), reloadedCruise.getMultirigNumber());
-
- // -----------------------------------------------------------------------------
- // 2. Test with only mandatory properties
- // -----------------------------------------------------------------------------
- createdCruise.setId(null);
- createdCruise.setHeadOfMission(null);
- createdCruise.setBeginDate(null);
- createdCruise.setEndDate(null);
- createdCruise.setComment(null);
- createdCruise.setMultirigNumber(null);
-
- // Save cruise
- createdCruise = service.createCruise(cruise);
- assertNotNull(createdCruise);
- assertNotNull(createdCruise.getId());
- assertEquals(cruise.getName(), createdCruise.getName());
-
- // Reload to compare
- reloadedCruise = service.getCruise(createdCruise.getId());
-
- assertEquals(createdCruise.getBeginDate(), reloadedCruise.getBeginDate());
- assertEquals(createdCruise.getEndDate(), reloadedCruise.getEndDate());
- assertEquals(createdCruise.getComment(), reloadedCruise.getComment());
- assertEquals(createdCruise.getMultirigNumber(), reloadedCruise.getMultirigNumber());
- assertNull(reloadedCruise.getHeadOfMission());
- assertNotNull(reloadedCruise.getVessel());
- assertEquals(createdCruise.getVessel().get(0), reloadedCruise.getVessel().get(0));
- assertEquals(cruise.getCountry().getId(), reloadedCruise.getCountry().getId());
- assertNotNull(reloadedCruise.getVessel());
- assertEquals(vessels.size(), reloadedCruise.getVessel().size());
- assertNotNull(reloadedCruise.getGear());
- assertEquals(gears.size(), reloadedCruise.getGear().size());
- }
-
- @Test
- public void saveCruise(/*Cruise bean*/) {
- // -----------------------------------------------------------------------------
- // 1. Init a cruise (by copy)
- // -----------------------------------------------------------------------------
- Cruise cruise = service.getCruise(dbResource.getFixtures().cruiseId());
-
- cruise.setId(null);
- Calendar calendar = new GregorianCalendar();
- cruise.setBeginDate(calendar.getTime());
-
- cruise.setYear(calendar.get(Calendar.YEAR));
-
- calendar.add(Calendar.MONTH, 1); // add one month
- cruise.setEndDate(calendar.getTime());
-
- cruise = service.createCruise(cruise);
-
- // -----------------------------------------------------------------------------
- // 2. Apply some changes
- // -----------------------------------------------------------------------------
-
- // Name :
- cruise.setName("Unit-test-" + System.currentTimeMillis());
-
- // Remove gear, then add another gear
- Gear previousGear = cruise.getGear(0);
- cruise.getGear().clear();
- List<Gear> gears = referentialService.getAllFishingGear();
- for (Gear gear : gears) {
- // Make sure the gear is different before to add it
- if (gear.getId() != null && !gear.getId().equals(previousGear.getId())) {
- cruise.addGear(gear);
- break;
- }
- }
-
- // Save changes, then check
- Cruise savedCruise = service.saveCruise(cruise);
- assertNotNull(savedCruise);
- Cruise reloadedCruise = service.getCruise(savedCruise.getId());
-
- assertEquals(cruise.getId(), reloadedCruise.getId());
- assertEquals(cruise.getName(), reloadedCruise.getName());
- assertEquals(cruise.getComment(), reloadedCruise.getComment());
- assertNotNull(reloadedCruise.getGear());
- assertEquals(cruise.getGear().size(), reloadedCruise.getGear().size());
- assertEquals(cruise.getGear(0).getId(), reloadedCruise.getGear(0).getId());
- }
-}
Copied: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/CruisePersistenceServiceWriteTest.java (from rev 378, trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/CruisePersistenceServiceTest.java)
===================================================================
--- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/CruisePersistenceServiceWriteTest.java (rev 0)
+++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/CruisePersistenceServiceWriteTest.java 2013-02-10 13:41:29 UTC (rev 379)
@@ -0,0 +1,233 @@
+package fr.ifremer.tutti.persistence.service;
+
+/*
+ * #%L
+ * Tutti :: Persistence API
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2012 - 2013 Ifremer
+ * %%
+ * 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%
+ */
+
+import com.google.common.collect.Lists;
+import fr.ifremer.tutti.persistence.DatabaseResource;
+import fr.ifremer.tutti.persistence.entities.data.Cruise;
+import fr.ifremer.tutti.persistence.entities.referential.Country;
+import fr.ifremer.tutti.persistence.entities.referential.Gear;
+import fr.ifremer.tutti.persistence.entities.referential.Person;
+import fr.ifremer.tutti.persistence.entities.referential.Vessel;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Test;
+
+import java.util.Calendar;
+import java.util.GregorianCalendar;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+/**
+ * To test {@link CruisePersistenceService} for write operation.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.0
+ */
+public class CruisePersistenceServiceWriteTest {
+
+ /** Logger. */
+ private static final Log log =
+ LogFactory.getLog(CruisePersistenceServiceWriteTest.class);
+
+ @ClassRule
+ public static final DatabaseResource dbResource = DatabaseResource.writeDb();
+
+ protected ReferentialPersistenceService referentialService;
+
+ protected ProgramPersistenceService programService;
+
+ protected CruisePersistenceService service;
+
+ @Before
+ public void setUp() throws Exception {
+ service = TuttiPersistenceServiceLocator.getCruisePersistenceService();
+ referentialService = TuttiPersistenceServiceLocator.getReferentialPersistenceService();
+ programService = TuttiPersistenceServiceLocator.getProgramPersistenceService();
+ }
+
+ @Test
+ public void createCruise(/*Cruise bean*/) {
+ String programCode = dbResource.getFixtures().programCode();
+ Cruise cruise = new Cruise();
+
+ // -----------------------------------------------------------------------------
+ // 1. Test with all properties filled
+ // -----------------------------------------------------------------------------
+ cruise.setId(null);
+
+ cruise.setName("Unit-test-" + System.currentTimeMillis());
+
+ cruise.setProgram(programService.getProgram(programCode));
+
+ Calendar calendar = new GregorianCalendar();
+ cruise.setBeginDate(calendar.getTime());
+
+ cruise.setYear(calendar.get(Calendar.YEAR));
+
+ calendar.add(Calendar.MONTH, 1); // add one month
+ cruise.setEndDate(calendar.getTime());
+
+ Country country = null;
+ List<Country> countries = referentialService.getAllCountry();
+ for (Country aCountry : countries) {
+ if (aCountry.getLabel() != null && aCountry.getLabel().equals("FRA")) {
+ country = aCountry;
+ break;
+ }
+ }
+ assertNotNull("Could not load FRA country", country);
+ cruise.setCountry(country);
+
+ List<Gear> gears = referentialService.getAllFishingGear();
+ cruise.setGear(gears);
+
+ cruise.setComment("My comments on cruise");
+
+ Person managerPerson = referentialService.getAllPerson().get(0);
+ cruise.setHeadOfMission(Lists.newArrayList(managerPerson));
+
+ List<Vessel> vessels = Lists.newArrayList();
+ vessels.add(referentialService.getAllScientificVessel().get(0));
+ Vessel fishingVessel = new Vessel();
+ fishingVessel.setId(dbResource.getFixtures().fishingVesselCode());
+ vessels.add(fishingVessel);
+
+ cruise.setVessel(vessels);
+
+ cruise.setMultirigNumber(2);
+
+ // Create cruise in database
+ Cruise createdCruise = service.createCruise(cruise);
+ assertNotNull(createdCruise);
+ assertNotNull(createdCruise.getId());
+ assertEquals(cruise.getName(), createdCruise.getName());
+
+ if (log.isInfoEnabled()) {
+ log.info("Created cruise: " + createdCruise.getId());
+ }
+
+ // Then reload cruise and compare
+ Cruise reloadedCruise = service.getCruise(createdCruise.getId());
+ calendar.setTime(createdCruise.getBeginDate());
+ calendar.set(Calendar.SECOND, 0);
+ calendar.set(Calendar.MILLISECOND, 0);
+ assertEquals(calendar.getTime(), reloadedCruise.getBeginDate());
+ calendar.setTime(createdCruise.getEndDate());
+ calendar.set(Calendar.SECOND, 0);
+ calendar.set(Calendar.MILLISECOND, 0);
+ assertEquals(calendar.getTime(), reloadedCruise.getEndDate());
+ assertEquals(cruise.getMultirigNumber(), reloadedCruise.getMultirigNumber());
+
+ // -----------------------------------------------------------------------------
+ // 2. Test with only mandatory properties
+ // -----------------------------------------------------------------------------
+ createdCruise.setId(null);
+ createdCruise.setHeadOfMission(null);
+ createdCruise.setBeginDate(null);
+ createdCruise.setEndDate(null);
+ createdCruise.setComment(null);
+ createdCruise.setMultirigNumber(null);
+
+ // Save cruise
+ createdCruise = service.createCruise(cruise);
+ assertNotNull(createdCruise);
+ assertNotNull(createdCruise.getId());
+ assertEquals(cruise.getName(), createdCruise.getName());
+
+ // Reload to compare
+ reloadedCruise = service.getCruise(createdCruise.getId());
+
+ assertEquals(createdCruise.getBeginDate(), reloadedCruise.getBeginDate());
+ assertEquals(createdCruise.getEndDate(), reloadedCruise.getEndDate());
+ assertEquals(createdCruise.getComment(), reloadedCruise.getComment());
+// assertEquals(createdCruise.getMultirigNumber(), reloadedCruise.getMultirigNumber());
+ //TODO-tc, are we forced to do such things ?
+ assertEquals(1, reloadedCruise.getMultirigNumber(), 0);
+ assertNull(reloadedCruise.getHeadOfMission());
+ assertNotNull(reloadedCruise.getVessel());
+ assertEquals(createdCruise.getVessel().get(0), reloadedCruise.getVessel().get(0));
+ assertEquals(cruise.getCountry().getId(), reloadedCruise.getCountry().getId());
+ assertNotNull(reloadedCruise.getVessel());
+ assertEquals(vessels.size(), reloadedCruise.getVessel().size());
+ assertNotNull(reloadedCruise.getGear());
+ assertEquals(gears.size(), reloadedCruise.getGear().size());
+ }
+
+ @Test
+ public void saveCruise(/*Cruise bean*/) {
+ // -----------------------------------------------------------------------------
+ // 1. Init a cruise (by copy)
+ // -----------------------------------------------------------------------------
+ Cruise cruise = service.getCruise(dbResource.getFixtures().cruiseId());
+
+ cruise.setId(null);
+ Calendar calendar = new GregorianCalendar();
+ cruise.setBeginDate(calendar.getTime());
+
+ cruise.setYear(calendar.get(Calendar.YEAR));
+
+ calendar.add(Calendar.MONTH, 1); // add one month
+ cruise.setEndDate(calendar.getTime());
+
+ cruise = service.createCruise(cruise);
+
+ // -----------------------------------------------------------------------------
+ // 2. Apply some changes
+ // -----------------------------------------------------------------------------
+
+ // Name :
+ cruise.setName("Unit-test-" + System.currentTimeMillis());
+
+ // Remove gear, then add another gear
+ Gear previousGear = cruise.getGear(0);
+ cruise.getGear().clear();
+ List<Gear> gears = referentialService.getAllFishingGear();
+ for (Gear gear : gears) {
+ // Make sure the gear is different before to add it
+ if (gear.getId() != null && !gear.getId().equals(previousGear.getId())) {
+ cruise.addGear(gear);
+ break;
+ }
+ }
+
+ // Save changes, then check
+ Cruise savedCruise = service.saveCruise(cruise);
+ assertNotNull(savedCruise);
+ Cruise reloadedCruise = service.getCruise(savedCruise.getId());
+
+ assertEquals(cruise.getId(), reloadedCruise.getId());
+ assertEquals(cruise.getName(), reloadedCruise.getName());
+ assertEquals(cruise.getComment(), reloadedCruise.getComment());
+ assertNotNull(reloadedCruise.getGear());
+ assertEquals(cruise.getGear().size(), reloadedCruise.getGear().size());
+ assertEquals(cruise.getGear(0).getId(), reloadedCruise.getGear(0).getId());
+ }
+}
Copied: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceServiceReadTest.java (from rev 378, trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceServiceTest.java)
===================================================================
--- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceServiceReadTest.java (rev 0)
+++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceServiceReadTest.java 2013-02-10 13:41:29 UTC (rev 379)
@@ -0,0 +1,69 @@
+package fr.ifremer.tutti.persistence.service;
+
+/*
+ * #%L
+ * Tutti :: Persistence API
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2012 - 2013 Ifremer
+ * %%
+ * 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%
+ */
+
+import fr.ifremer.tutti.persistence.DatabaseResource;
+import fr.ifremer.tutti.persistence.entities.data.FishingOperation;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import java.util.List;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * To test {@link FishingOperationPersistenceService} for read operation.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 0.3
+ */
+public class FishingOperationPersistenceServiceReadTest {
+
+ @ClassRule
+ public static final DatabaseResource dbResource = DatabaseResource.readDb();
+
+ protected FishingOperationPersistenceService service;
+
+ @Before
+ public void setUp() throws Exception {
+ service = TuttiPersistenceServiceLocator.getFishingOperationPersistenceService();
+ }
+
+ @Test
+ public void getAllFishingOperation(/*String cruiseId*/) {
+ List<FishingOperation> fishingOperations = service.getAllFishingOperation(dbResource.getFixtures().cruiseId());
+ assertNotNull(fishingOperations);
+ assertTrue(fishingOperations.size() > 1);
+ }
+
+ @Test
+ @Ignore
+ public void getFishingOperation(/*String id*/) {
+
+ }
+}
Deleted: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceServiceTest.java
===================================================================
--- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceServiceTest.java 2013-02-09 07:44:17 UTC (rev 378)
+++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceServiceTest.java 2013-02-10 13:41:29 UTC (rev 379)
@@ -1,401 +0,0 @@
-package fr.ifremer.tutti.persistence.service;
-
-/*
- * #%L
- * Tutti :: Persistence API
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2012 - 2013 Ifremer
- * %%
- * 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%
- */
-
-import com.google.common.collect.Lists;
-import fr.ifremer.tutti.persistence.DatabaseResource;
-import fr.ifremer.tutti.persistence.entities.CaracteristicMap;
-import fr.ifremer.tutti.persistence.entities.data.Cruise;
-import fr.ifremer.tutti.persistence.entities.data.FishingOperation;
-import fr.ifremer.tutti.persistence.entities.referential.Caracteristic;
-import fr.ifremer.tutti.persistence.entities.referential.CaracteristicType;
-import fr.ifremer.tutti.persistence.entities.referential.FishingOperationLocation;
-import fr.ifremer.tutti.persistence.entities.referential.Gear;
-import fr.ifremer.tutti.persistence.entities.referential.Vessel;
-
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.dao.DataIntegrityViolationException;
-
-import java.io.Serializable;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.GregorianCalendar;
-import java.util.List;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-/**
- * @author tchemit <chemit(a)codelutin.com>
- * @since 0.3
- */
-public class FishingOperationPersistenceServiceTest {
-
- @ClassRule
- public static final DatabaseResource dbResource = new DatabaseResource();
-
- protected FishingOperationPersistenceService service;
-
- protected ReferentialPersistenceService referentialService;
-
- protected ProgramPersistenceService programService;
-
- protected CruisePersistenceService cruiseService;
-
- protected Cruise cruise = null;
- protected Gear cruiseGear = null;
- protected Vessel notCruiseVessel = null;
-
- @Autowired(required = true)
- protected TuttiEnumerationFile enumeration;
-
- @Before
- public void setUp() throws Exception {
- service = TuttiPersistenceServiceLocator.getFishingOperationPersistenceService();
- cruiseService = TuttiPersistenceServiceLocator.getCruisePersistenceService();
- referentialService = TuttiPersistenceServiceLocator.getReferentialPersistenceService();
- programService = TuttiPersistenceServiceLocator.getProgramPersistenceService();
-
- // Duplicate an existing cruise, to attach new fishing operations
- cruise = cruiseService.getCruise(dbResource.getFixtures().cruiseId());
- cruise.setId(null);
- cruise.setName("Unit-test-" + System.currentTimeMillis());
- cruise.setBeginDate(new Date());
- cruise.setEndDate(null);
- cruise.setMultirigNumber(2);
-
- // Keep only one gear in the cruise : (need for case n°4)
- List<Gear> cruiseGears = cruise.getGear();
- assertNotNull(cruiseGears);
- assertTrue(cruiseGears.size() > 0);
- cruiseGear = cruiseGears.get(0);
- assertNotNull(cruiseGear.getId());
- cruise.setGear(Lists.newArrayList(cruiseGear));
-
- cruise = cruiseService.createCruise(cruise);
- assertNotNull(cruise.getId());
-
- // Find a vessel, different from the cruise vessel
- notCruiseVessel = referentialService.getVessel(dbResource.getFixtures().fishingVesselCode());
- assertNotNull(notCruiseVessel.getId());
- }
-
- @Test
- public void getAllFishingOperation(/*String cruiseId*/) {
- List<FishingOperation> fishingOperations = service.getAllFishingOperation(dbResource.getFixtures().cruiseId());
- assertNotNull(fishingOperations);
- assertTrue(fishingOperations.size() > 1);
- }
-
- @Test
- @Ignore
- public void getFishingOperation(/*String id*/) {
-
- }
-
- @Test
- public void createFishingOperation(/*FishingOperation bean*/) {
- // -----------------------------------------------------------------------------
- // Prepare data and other entities
- // -----------------------------------------------------------------------------
- Calendar calendar = new GregorianCalendar();
- FishingOperation reloadedFishingOperation;
- FishingOperation createdFishingOperation;
-
- // Retrieve some environment caracteristics
- List<Caracteristic> allEnvironmentCaracteristics = referentialService.getAllCaracteristic();
- CaracteristicMap environmentCaracteristics = new CaracteristicMap();
- CaracteristicMap environmentValuesOneEntry = new CaracteristicMap();
- for (Caracteristic caracteristic : allEnvironmentCaracteristics) {
- Serializable value = null;
- if (caracteristic.getCaracteristicType() == CaracteristicType.NUMBER) {
- value = 1.0f;
- } else if (caracteristic.getCaracteristicType() == CaracteristicType.TEXT) {
- value = "some text";
- } else if (caracteristic.getCaracteristicType() == CaracteristicType.QUALITATIVE
- && caracteristic.getQualitativeValue(0) != null) {
- // Choose the first qualitative value
- value = caracteristic.getQualitativeValue(0).getId();
- }
- if (value != null) {
- environmentCaracteristics.put(caracteristic, value);
- if (environmentValuesOneEntry.size() == 0) {
- environmentValuesOneEntry.put(caracteristic, value);
- }
- }
- }
-
- // Retrieve some gear use caracteristics
- List<Caracteristic> allGearShootingCaracteristics = referentialService.getAllCaracteristic();
- CaracteristicMap gearShootingCaracteristics = new CaracteristicMap();
- CaracteristicMap gearShootingCaracteristicsOneEntry = new CaracteristicMap();
- for (Caracteristic caracteristic : allGearShootingCaracteristics) {
- Serializable value = null;
- if (caracteristic.getCaracteristicType() == CaracteristicType.NUMBER) {
- value = 1.0f;
- } else if (caracteristic.getCaracteristicType() == CaracteristicType.TEXT) {
- value = "some text";
- } else if (caracteristic.getCaracteristicType() == CaracteristicType.QUALITATIVE
- && caracteristic.getQualitativeValue(0) != null) {
- // Choose the first qualitative value
- value = caracteristic.getQualitativeValue(0).getId();
- }
- if (value != null) {
- gearShootingCaracteristics.put(caracteristic, value);
- if (gearShootingCaracteristicsOneEntry.size() == 0) {
- gearShootingCaracteristicsOneEntry.put(caracteristic, value);
- }
- }
- }
-
-
- // Create new fishing operation :
- FishingOperation fishingOperation = new FishingOperation();
-
- // -----------------------------------------------------------------------------
- // 1. Test with only mandatory properties
- // -----------------------------------------------------------------------------
-
- // Set properties (with optional value to null)
- fishingOperation.setCruise(cruise);
- fishingOperation.setStationNumber("STA1");
- fishingOperation.setFishingOperationNumber(1);
- fishingOperation.setMultirigAggregation("1");
- fishingOperation.setGearShootingStartDate(null);
- fishingOperation.setGearShootingEndDate(null);
- fishingOperation.setGear(null);
- fishingOperation.setVessel(null);
- fishingOperation.setGearShootingStartLatitude(33.2541f);
- fishingOperation.setComment(null);
-
- // Store fishing operation into database :
- createdFishingOperation = service.createFishingOperation(fishingOperation);
- assertNotNull("Fishing operation ID must not be null after creation in database", createdFishingOperation);
- assertNotNull(createdFishingOperation.getId());
-
- // Trying to reload this fishing operation
- reloadedFishingOperation = service.getFishingOperation(createdFishingOperation.getId());
- assertNotNull(reloadedFishingOperation);
- assertNull(reloadedFishingOperation.getGearShootingStartDate());
-
- // -----------------------------------------------------------------------------
- // 2. Test with all properties set
- // -----------------------------------------------------------------------------
- // Set properties
- fishingOperation.setId(null);
- fishingOperation.setStationNumber("STA2");
- fishingOperation.setFishingOperationNumber(2);
- fishingOperation.setMultirigAggregation("1");
- calendar.setTime(new Date());
- calendar.set(Calendar.HOUR_OF_DAY, 1);
- calendar.set(Calendar.MILLISECOND, 99);
- fishingOperation.setGearShootingStartDate(calendar.getTime());
- calendar.setTime(new Date());
- calendar.set(Calendar.HOUR_OF_DAY, 10);
- calendar.set(Calendar.MILLISECOND, 99);
- fishingOperation.setGearShootingEndDate(calendar.getTime());
- fishingOperation.setGearShootingStartLatitude(47.6f);
- fishingOperation.setGearShootingStartLongitude(-5.05f);
- fishingOperation.setGearShootingEndLatitude(47.9854f);
- fishingOperation.setGearShootingEndLongitude(-5.597f);
-
- fishingOperation.setTrawlDistance(100.12345f);
- fishingOperation.setFishingOperationRectiligne(true);
- fishingOperation.setFishingOperationValid(Boolean.TRUE);
- fishingOperation.setComment("Unit test createFishingOperation() - Part n°2 : All properties set");
- fishingOperation.setGear(cruiseGear);
- fishingOperation.setVessel(notCruiseVessel);
- fishingOperation.setEnvironmentCaracteristics(environmentCaracteristics);
- fishingOperation.setGearShootingCaracteristics(gearShootingCaracteristics);
-
- FishingOperationLocation strata = new FishingOperationLocation();
- strata.setId(dbResource.getFixtures().strataId());
- fishingOperation.setStrata(strata);
- FishingOperationLocation subStrata = new FishingOperationLocation();
- subStrata.setId(dbResource.getFixtures().subStrataId());
- fishingOperation.setSubStrata(subStrata);
- FishingOperationLocation localite = new FishingOperationLocation();
- localite.setId(dbResource.getFixtures().localite());
- fishingOperation.setLocation(localite);
-
- // Store fishing operation into database :
- createdFishingOperation = service.createFishingOperation(fishingOperation);
- assertNotNull("Fishing operation ID must not be null after creation in database", createdFishingOperation);
- assertNotNull(createdFishingOperation.getId());
-
- reloadedFishingOperation = service.getFishingOperation(createdFishingOperation.getId());
- assertNotNull(reloadedFishingOperation.getGear());
- assertNotNull(reloadedFishingOperation.getVessel());
- assertEquals(fishingOperation.getVessel().getId(), reloadedFishingOperation.getVessel().getId());
- assertEquals(fishingOperation.getStationNumber(), reloadedFishingOperation.getStationNumber());
- assertEquals(fishingOperation.getFishingOperationNumber(), reloadedFishingOperation.getFishingOperationNumber());
- assertEquals(fishingOperation.getMultirigAggregation(), reloadedFishingOperation.getMultirigAggregation());
- assertNotNull(reloadedFishingOperation.getGearShootingStartDate());
- calendar.setTime(fishingOperation.getGearShootingStartDate());
- calendar.set(Calendar.MILLISECOND, 0);
- assertEquals(calendar.getTime(), reloadedFishingOperation.getGearShootingStartDate());
- assertEquals(fishingOperation.getGearShootingStartLatitude(), reloadedFishingOperation.getGearShootingStartLatitude());
- assertEquals(fishingOperation.getGearShootingStartLongitude(), reloadedFishingOperation.getGearShootingStartLongitude());
- assertNotNull(reloadedFishingOperation.getGearShootingEndDate());
- calendar.setTime(fishingOperation.getGearShootingEndDate());
- calendar.set(Calendar.MILLISECOND, 0);
- assertEquals(calendar.getTime(), reloadedFishingOperation.getGearShootingEndDate());
- assertEquals(fishingOperation.getGearShootingEndLatitude(), reloadedFishingOperation.getGearShootingEndLatitude());
- assertEquals(fishingOperation.getGearShootingEndLongitude(), reloadedFishingOperation.getGearShootingEndLongitude());
- assertEquals(fishingOperation.getTrawlDistance(), reloadedFishingOperation.getTrawlDistance());
- assertEquals(fishingOperation.isFishingOperationRectiligne(), reloadedFishingOperation.isFishingOperationRectiligne());
- assertEquals(fishingOperation.getFishingOperationValid(), reloadedFishingOperation.getFishingOperationValid());
- assertEquals(fishingOperation.getComment(), reloadedFishingOperation.getComment());
- assertNotNull(reloadedFishingOperation.getEnvironmentCaracteristics());
- assertEquals(environmentCaracteristics.size(), fishingOperation.getEnvironmentCaracteristics().size());
- assertNotNull(reloadedFishingOperation.getGearShootingCaracteristics());
- assertEquals(gearShootingCaracteristics.size(), reloadedFishingOperation.getGearShootingCaracteristics().size());
- assertNotNull(reloadedFishingOperation.getStrata());
- assertNotNull(reloadedFishingOperation.getStrata().getId());
- assertEquals(fishingOperation.getStrata().getId(), reloadedFishingOperation.getStrata().getId());
- assertNotNull(reloadedFishingOperation.getSubStrata());
- assertNotNull(reloadedFishingOperation.getSubStrata().getId());
- assertEquals(fishingOperation.getSubStrata().getId(), reloadedFishingOperation.getSubStrata().getId());
- assertNotNull(reloadedFishingOperation.getLocation());
- assertNotNull(reloadedFishingOperation.getLocation().getId());
- assertEquals(fishingOperation.getLocation().getId(), reloadedFishingOperation.getLocation().getId());
-
- // -----------------------------------------------------------------------------
- // 3. Test :
- // - startDate and startLat filled, but empty endLong
- // - endLat and endLong filled but empty endDate
- // - isFishingOperationRectiligne = false
- // - trawlDistance empty
- // - fishingOperationValid = false
- // -----------------------------------------------------------------------------
- fishingOperation.setId(null);
- fishingOperation.setStationNumber("STA3");
- fishingOperation.setFishingOperationNumber(3);
- fishingOperation.setMultirigAggregation("2");
- fishingOperation.setGearShootingStartLongitude(null);
- fishingOperation.setGearShootingEndDate(null);
- fishingOperation.setTrawlDistance(null);
- fishingOperation.setFishingOperationRectiligne(false);
- fishingOperation.setFishingOperationValid(false);
- fishingOperation.setComment("Unit test createFishingOperation() - Part n°3 :\n-startDate and startLat filled, but empty endLong\n- endLat and endLong filled but empty endDate");
- createdFishingOperation = service.createFishingOperation(fishingOperation);
- reloadedFishingOperation = service.getFishingOperation(createdFishingOperation.getId());
- assertEquals(fishingOperation.getGearShootingStartLatitude(), reloadedFishingOperation.getGearShootingStartLatitude());
- assertEquals(fishingOperation.getGearShootingStartLongitude(), reloadedFishingOperation.getGearShootingStartLongitude());
- assertNull(reloadedFishingOperation.getGearShootingEndDate());
- assertEquals(fishingOperation.getGearShootingEndLatitude(), reloadedFishingOperation.getGearShootingEndLatitude());
- assertEquals(fishingOperation.getGearShootingEndLongitude(), reloadedFishingOperation.getGearShootingEndLongitude());
- assertEquals(fishingOperation.getTrawlDistance(), reloadedFishingOperation.getTrawlDistance());
- assertEquals(fishingOperation.isFishingOperationRectiligne(), reloadedFishingOperation.isFishingOperationRectiligne());
- assertEquals(fishingOperation.getFishingOperationValid(), reloadedFishingOperation.getFishingOperationValid());
-
- // -----------------------------------------------------------------------------
- // 4. Test exceptions :
- // - try to save a operation using a gear not declared in the cruise
- // - try to save a operation using a multirig aggregation greater than the cruise multirig number
- // -----------------------------------------------------------------------------
- fishingOperation.setId(null);
-
- // Find and set a gear not used in the cruise
- List<Gear> gears = referentialService.getAllFishingGear();
- assertNotNull(gears);
- assertTrue(gears.size() > 0);
- for (Gear gear : gears) {
- if (!cruiseGear.getId().equals(gear.getId())) {
- fishingOperation.setGear(gear);
- break;
- }
- }
-
- try {
- createdFishingOperation = service.createFishingOperation(fishingOperation);
- fail("A fishing operation must not be saved if the gear is not declared in the cruise.");
- } catch (DataIntegrityViolationException dive) {
- assertNotNull(dive);
- fishingOperation.setGear(cruiseGear);
- }
-
- fishingOperation.setMultirigAggregation("3");
- try {
- createdFishingOperation = service.createFishingOperation(fishingOperation);
- fail("A fishing operation must not be saved if the 'multirig aggregation' > 'cruise multirig number'.");
- } catch (DataIntegrityViolationException dive) {
- assertNotNull(dive);
- fishingOperation.setMultirigAggregation("1");
- }
-
- // -----------------------------------------------------------------------------
- // 5. Test update (delete unecessary data)
- // - remove positons
- // - remove strata, substrata, localite
- // - remove some environment carateristics
- // - remove some gear shooting carateristics
- // - change vessel (to same as cruise)
- // -----------------------------------------------------------------------------
- fishingOperation.setId(reloadedFishingOperation.getId());
- fishingOperation.setGearShootingStartLatitude(null);
- fishingOperation.setGearShootingStartLongitude(null);
- fishingOperation.setGearShootingEndDate(null);
- fishingOperation.setGearShootingEndLatitude(null);
- fishingOperation.setGearShootingEndLongitude(null);
- fishingOperation.setTrawlDistance(null);
- fishingOperation.setStrata(null);
- fishingOperation.setSubStrata(null);
- fishingOperation.setLocation(null);
- fishingOperation.setVessel(cruise.getVessel(0));
- fishingOperation.setEnvironmentCaracteristics(environmentValuesOneEntry);
- fishingOperation.setGearShootingCaracteristics(gearShootingCaracteristicsOneEntry);
- fishingOperation.setComment(fishingOperation.getComment() + "\n\nUnit test createFishingOperation() - Part n°5 : check if deleted sub items in DB");
- createdFishingOperation = service.saveFishingOperation(fishingOperation);
- reloadedFishingOperation = service.getFishingOperation(createdFishingOperation.getId());
- assertNull(reloadedFishingOperation.getGearShootingStartLatitude());
- assertNull(reloadedFishingOperation.getGearShootingStartLongitude());
- assertNull(reloadedFishingOperation.getGearShootingEndDate());
- assertNull(reloadedFishingOperation.getGearShootingEndLatitude());
- assertNull(reloadedFishingOperation.getGearShootingEndLongitude());
- assertNull(reloadedFishingOperation.getStrata());
- assertNull(reloadedFishingOperation.getSubStrata());
- assertNull(reloadedFishingOperation.getLocation());
- assertNotNull(reloadedFishingOperation.getEnvironmentCaracteristics());
- assertEquals(environmentValuesOneEntry.size(), reloadedFishingOperation.getEnvironmentCaracteristics().size());
- assertNotNull(reloadedFishingOperation.getGearShootingCaracteristics());
- assertEquals(gearShootingCaracteristicsOneEntry.size(), reloadedFishingOperation.getGearShootingCaracteristics().size());
- }
-
- @Test
- @Ignore
- public void saveFishingOperation(/*FishingOperation bean*/) {
-
- }
-
-
-}
Copied: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceServiceWriteTest.java (from rev 378, trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceServiceTest.java)
===================================================================
--- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceServiceWriteTest.java (rev 0)
+++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceServiceWriteTest.java 2013-02-10 13:41:29 UTC (rev 379)
@@ -0,0 +1,387 @@
+package fr.ifremer.tutti.persistence.service;
+
+/*
+ * #%L
+ * Tutti :: Persistence API
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2012 - 2013 Ifremer
+ * %%
+ * 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%
+ */
+
+import com.google.common.collect.Lists;
+import fr.ifremer.tutti.persistence.DatabaseResource;
+import fr.ifremer.tutti.persistence.entities.CaracteristicMap;
+import fr.ifremer.tutti.persistence.entities.data.Cruise;
+import fr.ifremer.tutti.persistence.entities.data.FishingOperation;
+import fr.ifremer.tutti.persistence.entities.referential.Caracteristic;
+import fr.ifremer.tutti.persistence.entities.referential.CaracteristicType;
+import fr.ifremer.tutti.persistence.entities.referential.FishingOperationLocation;
+import fr.ifremer.tutti.persistence.entities.referential.Gear;
+import fr.ifremer.tutti.persistence.entities.referential.Vessel;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.springframework.dao.DataIntegrityViolationException;
+
+import java.io.Serializable;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.GregorianCalendar;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+/**
+ * To test {@link FishingOperationPersistenceService} for write operation.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.0
+ */
+public class FishingOperationPersistenceServiceWriteTest {
+
+ @ClassRule
+ public static final DatabaseResource dbResource = DatabaseResource.writeDb();
+
+ protected FishingOperationPersistenceService service;
+
+ protected ReferentialPersistenceService referentialService;
+
+ protected ProgramPersistenceService programService;
+
+ protected CruisePersistenceService cruiseService;
+
+ protected Cruise cruise = null;
+
+ protected Gear cruiseGear = null;
+
+ protected Vessel notCruiseVessel = null;
+
+ @Before
+ public void setUp() throws Exception {
+ service = TuttiPersistenceServiceLocator.getFishingOperationPersistenceService();
+ cruiseService = TuttiPersistenceServiceLocator.getCruisePersistenceService();
+ referentialService = TuttiPersistenceServiceLocator.getReferentialPersistenceService();
+ programService = TuttiPersistenceServiceLocator.getProgramPersistenceService();
+
+ // Duplicate an existing cruise, to attach new fishing operations
+ cruise = cruiseService.getCruise(dbResource.getFixtures().cruiseId());
+ cruise.setId(null);
+ cruise.setName("Unit-test-" + System.currentTimeMillis());
+ cruise.setBeginDate(new Date());
+ cruise.setEndDate(null);
+ cruise.setMultirigNumber(2);
+
+ // Keep only one gear in the cruise : (need for case n°4)
+ List<Gear> cruiseGears = cruise.getGear();
+ assertNotNull(cruiseGears);
+ assertTrue(cruiseGears.size() > 0);
+ cruiseGear = cruiseGears.get(0);
+ assertNotNull(cruiseGear.getId());
+ cruise.setGear(Lists.newArrayList(cruiseGear));
+
+ cruise = cruiseService.createCruise(cruise);
+ assertNotNull(cruise.getId());
+
+ // Find a vessel, different from the cruise vessel
+ notCruiseVessel = referentialService.getVessel(dbResource.getFixtures().fishingVesselCode());
+ assertNotNull(notCruiseVessel.getId());
+ }
+
+ @Test
+ public void createFishingOperation(/*FishingOperation bean*/) {
+ // -----------------------------------------------------------------------------
+ // Prepare data and other entities
+ // -----------------------------------------------------------------------------
+ Calendar calendar = new GregorianCalendar();
+ FishingOperation reloadedFishingOperation;
+ FishingOperation createdFishingOperation;
+
+ // Retrieve some environment caracteristics
+ List<Caracteristic> allEnvironmentCaracteristics = referentialService.getAllCaracteristic();
+ CaracteristicMap environmentCaracteristics = new CaracteristicMap();
+ CaracteristicMap environmentValuesOneEntry = new CaracteristicMap();
+ for (Caracteristic caracteristic : allEnvironmentCaracteristics) {
+ Serializable value = null;
+ if (caracteristic.getCaracteristicType() == CaracteristicType.NUMBER) {
+ value = 1.0f;
+ } else if (caracteristic.getCaracteristicType() == CaracteristicType.TEXT) {
+ value = "some text";
+ } else if (caracteristic.getCaracteristicType() == CaracteristicType.QUALITATIVE
+ && caracteristic.getQualitativeValue(0) != null) {
+ // Choose the first qualitative value
+ value = caracteristic.getQualitativeValue(0).getId();
+ }
+ if (value != null) {
+ environmentCaracteristics.put(caracteristic, value);
+ if (environmentValuesOneEntry.size() == 0) {
+ environmentValuesOneEntry.put(caracteristic, value);
+ }
+ }
+ }
+
+ // Retrieve some gear use caracteristics
+ List<Caracteristic> allGearShootingCaracteristics = referentialService.getAllCaracteristic();
+ CaracteristicMap gearShootingCaracteristics = new CaracteristicMap();
+ CaracteristicMap gearShootingCaracteristicsOneEntry = new CaracteristicMap();
+ for (Caracteristic caracteristic : allGearShootingCaracteristics) {
+ Serializable value = null;
+ if (caracteristic.getCaracteristicType() == CaracteristicType.NUMBER) {
+ value = 1.0f;
+ } else if (caracteristic.getCaracteristicType() == CaracteristicType.TEXT) {
+ value = "some text";
+ } else if (caracteristic.getCaracteristicType() == CaracteristicType.QUALITATIVE
+ && caracteristic.getQualitativeValue(0) != null) {
+ // Choose the first qualitative value
+ value = caracteristic.getQualitativeValue(0).getId();
+ }
+ if (value != null) {
+ gearShootingCaracteristics.put(caracteristic, value);
+ if (gearShootingCaracteristicsOneEntry.size() == 0) {
+ gearShootingCaracteristicsOneEntry.put(caracteristic, value);
+ }
+ }
+ }
+
+
+ // Create new fishing operation :
+ FishingOperation fishingOperation = new FishingOperation();
+
+ // -----------------------------------------------------------------------------
+ // 1. Test with only mandatory properties
+ // -----------------------------------------------------------------------------
+
+ // Set properties (with optional value to null)
+ fishingOperation.setCruise(cruise);
+ fishingOperation.setStationNumber("STA1");
+ fishingOperation.setFishingOperationNumber(1);
+ fishingOperation.setMultirigAggregation("1");
+ fishingOperation.setGearShootingStartDate(null);
+ fishingOperation.setGearShootingEndDate(null);
+ fishingOperation.setGear(null);
+ fishingOperation.setVessel(null);
+ fishingOperation.setGearShootingStartLatitude(33.2541f);
+ fishingOperation.setComment(null);
+
+ // Store fishing operation into database :
+ createdFishingOperation = service.createFishingOperation(fishingOperation);
+ assertNotNull("Fishing operation ID must not be null after creation in database", createdFishingOperation);
+ assertNotNull(createdFishingOperation.getId());
+
+ // Trying to reload this fishing operation
+ reloadedFishingOperation = service.getFishingOperation(createdFishingOperation.getId());
+ assertNotNull(reloadedFishingOperation);
+ assertNull(reloadedFishingOperation.getGearShootingStartDate());
+
+ // -----------------------------------------------------------------------------
+ // 2. Test with all properties set
+ // -----------------------------------------------------------------------------
+ // Set properties
+ fishingOperation.setId(null);
+ fishingOperation.setStationNumber("STA2");
+ fishingOperation.setFishingOperationNumber(2);
+ fishingOperation.setMultirigAggregation("1");
+ calendar.setTime(new Date());
+ calendar.set(Calendar.HOUR_OF_DAY, 1);
+ calendar.set(Calendar.MILLISECOND, 99);
+ fishingOperation.setGearShootingStartDate(calendar.getTime());
+ calendar.setTime(new Date());
+ calendar.set(Calendar.HOUR_OF_DAY, 10);
+ calendar.set(Calendar.MILLISECOND, 99);
+ fishingOperation.setGearShootingEndDate(calendar.getTime());
+ fishingOperation.setGearShootingStartLatitude(47.6f);
+ fishingOperation.setGearShootingStartLongitude(-5.05f);
+ fishingOperation.setGearShootingEndLatitude(47.9854f);
+ fishingOperation.setGearShootingEndLongitude(-5.597f);
+
+ fishingOperation.setTrawlDistance(100.12345f);
+ fishingOperation.setFishingOperationRectiligne(true);
+ fishingOperation.setFishingOperationValid(Boolean.TRUE);
+ fishingOperation.setComment("Unit test createFishingOperation() - Part n°2 : All properties set");
+ fishingOperation.setGear(cruiseGear);
+ fishingOperation.setVessel(notCruiseVessel);
+ fishingOperation.setEnvironmentCaracteristics(environmentCaracteristics);
+ fishingOperation.setGearShootingCaracteristics(gearShootingCaracteristics);
+
+ FishingOperationLocation strata = new FishingOperationLocation();
+ strata.setId(dbResource.getFixtures().strataId());
+ fishingOperation.setStrata(strata);
+ FishingOperationLocation subStrata = new FishingOperationLocation();
+ subStrata.setId(dbResource.getFixtures().subStrataId());
+ fishingOperation.setSubStrata(subStrata);
+ FishingOperationLocation localite = new FishingOperationLocation();
+ localite.setId(dbResource.getFixtures().localite());
+ fishingOperation.setLocation(localite);
+
+ // Store fishing operation into database :
+ createdFishingOperation = service.createFishingOperation(fishingOperation);
+ assertNotNull("Fishing operation ID must not be null after creation in database", createdFishingOperation);
+ assertNotNull(createdFishingOperation.getId());
+
+ reloadedFishingOperation = service.getFishingOperation(createdFishingOperation.getId());
+ assertNotNull(reloadedFishingOperation.getGear());
+ assertNotNull(reloadedFishingOperation.getVessel());
+ assertEquals(fishingOperation.getVessel().getId(), reloadedFishingOperation.getVessel().getId());
+ assertEquals(fishingOperation.getStationNumber(), reloadedFishingOperation.getStationNumber());
+ assertEquals(fishingOperation.getFishingOperationNumber(), reloadedFishingOperation.getFishingOperationNumber());
+ assertEquals(fishingOperation.getMultirigAggregation(), reloadedFishingOperation.getMultirigAggregation());
+ assertNotNull(reloadedFishingOperation.getGearShootingStartDate());
+ calendar.setTime(fishingOperation.getGearShootingStartDate());
+ calendar.set(Calendar.MILLISECOND, 0);
+ assertEquals(calendar.getTime(), reloadedFishingOperation.getGearShootingStartDate());
+ assertEquals(fishingOperation.getGearShootingStartLatitude(), reloadedFishingOperation.getGearShootingStartLatitude());
+ assertEquals(fishingOperation.getGearShootingStartLongitude(), reloadedFishingOperation.getGearShootingStartLongitude());
+ assertNotNull(reloadedFishingOperation.getGearShootingEndDate());
+ calendar.setTime(fishingOperation.getGearShootingEndDate());
+ calendar.set(Calendar.MILLISECOND, 0);
+ assertEquals(calendar.getTime(), reloadedFishingOperation.getGearShootingEndDate());
+ assertEquals(fishingOperation.getGearShootingEndLatitude(), reloadedFishingOperation.getGearShootingEndLatitude());
+ assertEquals(fishingOperation.getGearShootingEndLongitude(), reloadedFishingOperation.getGearShootingEndLongitude());
+ assertEquals(fishingOperation.getTrawlDistance(), reloadedFishingOperation.getTrawlDistance());
+ assertEquals(fishingOperation.isFishingOperationRectiligne(), reloadedFishingOperation.isFishingOperationRectiligne());
+ assertEquals(fishingOperation.getFishingOperationValid(), reloadedFishingOperation.getFishingOperationValid());
+ assertEquals(fishingOperation.getComment(), reloadedFishingOperation.getComment());
+ assertNotNull(reloadedFishingOperation.getEnvironmentCaracteristics());
+ assertEquals(environmentCaracteristics.size(), fishingOperation.getEnvironmentCaracteristics().size());
+ assertNotNull(reloadedFishingOperation.getGearShootingCaracteristics());
+ assertEquals(gearShootingCaracteristics.size(), reloadedFishingOperation.getGearShootingCaracteristics().size());
+ assertNotNull(reloadedFishingOperation.getStrata());
+ assertNotNull(reloadedFishingOperation.getStrata().getId());
+ assertEquals(fishingOperation.getStrata().getId(), reloadedFishingOperation.getStrata().getId());
+ assertNotNull(reloadedFishingOperation.getSubStrata());
+ assertNotNull(reloadedFishingOperation.getSubStrata().getId());
+ assertEquals(fishingOperation.getSubStrata().getId(), reloadedFishingOperation.getSubStrata().getId());
+ assertNotNull(reloadedFishingOperation.getLocation());
+ assertNotNull(reloadedFishingOperation.getLocation().getId());
+ assertEquals(fishingOperation.getLocation().getId(), reloadedFishingOperation.getLocation().getId());
+
+ // -----------------------------------------------------------------------------
+ // 3. Test :
+ // - startDate and startLat filled, but empty endLong
+ // - endLat and endLong filled but empty endDate
+ // - isFishingOperationRectiligne = false
+ // - trawlDistance empty
+ // - fishingOperationValid = false
+ // -----------------------------------------------------------------------------
+ fishingOperation.setId(null);
+ fishingOperation.setStationNumber("STA3");
+ fishingOperation.setFishingOperationNumber(3);
+ fishingOperation.setMultirigAggregation("2");
+ fishingOperation.setGearShootingStartLongitude(null);
+ fishingOperation.setGearShootingEndDate(null);
+ fishingOperation.setTrawlDistance(null);
+ fishingOperation.setFishingOperationRectiligne(false);
+ fishingOperation.setFishingOperationValid(false);
+ fishingOperation.setComment("Unit test createFishingOperation() - Part n°3 :\n-startDate and startLat filled, but empty endLong\n- endLat and endLong filled but empty endDate");
+ createdFishingOperation = service.createFishingOperation(fishingOperation);
+ reloadedFishingOperation = service.getFishingOperation(createdFishingOperation.getId());
+ assertEquals(fishingOperation.getGearShootingStartLatitude(), reloadedFishingOperation.getGearShootingStartLatitude());
+ assertEquals(fishingOperation.getGearShootingStartLongitude(), reloadedFishingOperation.getGearShootingStartLongitude());
+ assertNull(reloadedFishingOperation.getGearShootingEndDate());
+ assertEquals(fishingOperation.getGearShootingEndLatitude(), reloadedFishingOperation.getGearShootingEndLatitude());
+ assertEquals(fishingOperation.getGearShootingEndLongitude(), reloadedFishingOperation.getGearShootingEndLongitude());
+ assertEquals(fishingOperation.getTrawlDistance(), reloadedFishingOperation.getTrawlDistance());
+ assertEquals(fishingOperation.isFishingOperationRectiligne(), reloadedFishingOperation.isFishingOperationRectiligne());
+ assertEquals(fishingOperation.getFishingOperationValid(), reloadedFishingOperation.getFishingOperationValid());
+
+ // -----------------------------------------------------------------------------
+ // 4. Test exceptions :
+ // - try to save a operation using a gear not declared in the cruise
+ // - try to save a operation using a multirig aggregation greater than the cruise multirig number
+ // -----------------------------------------------------------------------------
+ fishingOperation.setId(null);
+
+ // Find and set a gear not used in the cruise
+ List<Gear> gears = referentialService.getAllFishingGear();
+ assertNotNull(gears);
+ assertTrue(gears.size() > 0);
+ for (Gear gear : gears) {
+ if (!cruiseGear.getId().equals(gear.getId())) {
+ fishingOperation.setGear(gear);
+ break;
+ }
+ }
+
+ try {
+ createdFishingOperation = service.createFishingOperation(fishingOperation);
+ fail("A fishing operation must not be saved if the gear is not declared in the cruise.");
+ } catch (DataIntegrityViolationException dive) {
+ assertNotNull(dive);
+ fishingOperation.setGear(cruiseGear);
+ }
+
+ fishingOperation.setMultirigAggregation("3");
+ try {
+ createdFishingOperation = service.createFishingOperation(fishingOperation);
+ fail("A fishing operation must not be saved if the 'multirig aggregation' > 'cruise multirig number'.");
+ } catch (DataIntegrityViolationException dive) {
+ assertNotNull(dive);
+ fishingOperation.setMultirigAggregation("1");
+ }
+
+ // -----------------------------------------------------------------------------
+ // 5. Test update (delete unecessary data)
+ // - remove positons
+ // - remove strata, substrata, localite
+ // - remove some environment carateristics
+ // - remove some gear shooting carateristics
+ // - change vessel (to same as cruise)
+ // -----------------------------------------------------------------------------
+ fishingOperation.setId(reloadedFishingOperation.getId());
+ fishingOperation.setGearShootingStartLatitude(null);
+ fishingOperation.setGearShootingStartLongitude(null);
+ fishingOperation.setGearShootingEndDate(null);
+ fishingOperation.setGearShootingEndLatitude(null);
+ fishingOperation.setGearShootingEndLongitude(null);
+ fishingOperation.setTrawlDistance(null);
+ fishingOperation.setStrata(null);
+ fishingOperation.setSubStrata(null);
+ fishingOperation.setLocation(null);
+ fishingOperation.setVessel(cruise.getVessel(0));
+ fishingOperation.setEnvironmentCaracteristics(environmentValuesOneEntry);
+ fishingOperation.setGearShootingCaracteristics(gearShootingCaracteristicsOneEntry);
+ fishingOperation.setComment(fishingOperation.getComment() + "\n\nUnit test createFishingOperation() - Part n°5 : check if deleted sub items in DB");
+ createdFishingOperation = service.saveFishingOperation(fishingOperation);
+ reloadedFishingOperation = service.getFishingOperation(createdFishingOperation.getId());
+ assertNull(reloadedFishingOperation.getGearShootingStartLatitude());
+ assertNull(reloadedFishingOperation.getGearShootingStartLongitude());
+ assertNull(reloadedFishingOperation.getGearShootingEndDate());
+ assertNull(reloadedFishingOperation.getGearShootingEndLatitude());
+ assertNull(reloadedFishingOperation.getGearShootingEndLongitude());
+ assertNull(reloadedFishingOperation.getStrata());
+ assertNull(reloadedFishingOperation.getSubStrata());
+ assertNull(reloadedFishingOperation.getLocation());
+ assertNotNull(reloadedFishingOperation.getEnvironmentCaracteristics());
+ assertEquals(environmentValuesOneEntry.size(), reloadedFishingOperation.getEnvironmentCaracteristics().size());
+ assertNotNull(reloadedFishingOperation.getGearShootingCaracteristics());
+ assertEquals(gearShootingCaracteristicsOneEntry.size(), reloadedFishingOperation.getGearShootingCaracteristics().size());
+ }
+
+ @Test
+ @Ignore
+ public void saveFishingOperation(/*FishingOperation bean*/) {
+
+ }
+
+
+}
Copied: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/MacroWasteBatchPersistenceServiceReadTest.java (from rev 378, trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/MacroWasteBatchPersistenceServiceTest.java)
===================================================================
--- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/MacroWasteBatchPersistenceServiceReadTest.java (rev 0)
+++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/MacroWasteBatchPersistenceServiceReadTest.java 2013-02-10 13:41:29 UTC (rev 379)
@@ -0,0 +1,62 @@
+package fr.ifremer.tutti.persistence.service;
+
+/*
+ * #%L
+ * Tutti :: Persistence API
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2012 - 2013 Ifremer
+ * %%
+ * 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%
+ */
+
+import fr.ifremer.tutti.persistence.DatabaseResource;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Ignore;
+import org.junit.Test;
+
+/**
+ * To test {@link MacroWasteBatchPersistenceService} for read operation.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 0.3
+ */
+@Ignore
+public class MacroWasteBatchPersistenceServiceReadTest {
+
+ @ClassRule
+ public static final DatabaseResource dbResource = DatabaseResource.readDb();
+
+ protected MacroWasteBatchPersistenceService service;
+
+ @Before
+ public void setUp() throws Exception {
+ service = TuttiPersistenceServiceLocator.getMacroWasteBatchPersistenceService();
+ }
+
+ @Test
+ public void getAllMacroWasteBatch(/*String fishingOperationId*/) {
+
+ }
+
+ @Test
+ public void getMacroWasteBatch(/*String id*/) {
+
+ }
+
+}
Deleted: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/MacroWasteBatchPersistenceServiceTest.java
===================================================================
--- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/MacroWasteBatchPersistenceServiceTest.java 2013-02-09 07:44:17 UTC (rev 378)
+++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/MacroWasteBatchPersistenceServiceTest.java 2013-02-10 13:41:29 UTC (rev 379)
@@ -1,73 +0,0 @@
-package fr.ifremer.tutti.persistence.service;
-
-/*
- * #%L
- * Tutti :: Persistence API
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2012 - 2013 Ifremer
- * %%
- * 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%
- */
-
-import fr.ifremer.tutti.persistence.DatabaseResource;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Ignore;
-import org.junit.Test;
-
-/**
- * @author tchemit <chemit(a)codelutin.com>
- * @since 0.3
- */
-@Ignore
-public class MacroWasteBatchPersistenceServiceTest {
-
- @ClassRule
- public static final DatabaseResource dbResource = new DatabaseResource();
-
- protected MacroWasteBatchPersistenceService service;
-
- @Before
- public void setUp() throws Exception {
- service = TuttiPersistenceServiceLocator.getMacroWasteBatchPersistenceService();
- }
-
- @Test
- public void getAllMacroWasteBatch(/*String fishingOperationId*/) {
-
- }
-
- @Test
- public void getMacroWasteBatch(/*String id*/) {
-
- }
-
- @Test
- public void createMacroWasteBatch(/*MacroWasteBatch bean*/) {
-
- }
-
- @Test
- public void saveMacroWasteBatch(/*MacroWasteBatch bean*/) {
-
- }
-
- @Test
- public void deleteMacroWasteBatch(/*String id*/) {
- }
-}
Copied: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/MacroWasteBatchPersistenceServiceWriteTest.java (from rev 378, trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/MacroWasteBatchPersistenceServiceTest.java)
===================================================================
--- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/MacroWasteBatchPersistenceServiceWriteTest.java (rev 0)
+++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/MacroWasteBatchPersistenceServiceWriteTest.java 2013-02-10 13:41:29 UTC (rev 379)
@@ -0,0 +1,65 @@
+package fr.ifremer.tutti.persistence.service;
+
+/*
+ * #%L
+ * Tutti :: Persistence API
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2012 - 2013 Ifremer
+ * %%
+ * 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%
+ */
+
+import fr.ifremer.tutti.persistence.DatabaseResource;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Ignore;
+import org.junit.Test;
+
+/**
+ * To test {@link MacroWasteBatchPersistenceService} for write operation.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 0.3
+ */
+@Ignore
+public class MacroWasteBatchPersistenceServiceWriteTest {
+
+ @ClassRule
+ public static final DatabaseResource dbResource = DatabaseResource.writeDb();
+
+ protected MacroWasteBatchPersistenceService service;
+
+ @Before
+ public void setUp() throws Exception {
+ service = TuttiPersistenceServiceLocator.getMacroWasteBatchPersistenceService();
+ }
+
+ @Test
+ public void createMacroWasteBatch(/*MacroWasteBatch bean*/) {
+
+ }
+
+ @Test
+ public void saveMacroWasteBatch(/*MacroWasteBatch bean*/) {
+
+ }
+
+ @Test
+ public void deleteMacroWasteBatch(/*String id*/) {
+ }
+}
Copied: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/PlanktonBatchPersistenceServiceReadTest.java (from rev 378, trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/PlanktonBatchPersistenceServiceTest.java)
===================================================================
--- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/PlanktonBatchPersistenceServiceReadTest.java (rev 0)
+++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/PlanktonBatchPersistenceServiceReadTest.java 2013-02-10 13:41:29 UTC (rev 379)
@@ -0,0 +1,61 @@
+package fr.ifremer.tutti.persistence.service;
+
+/*
+ * #%L
+ * Tutti :: Persistence API
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2012 - 2013 Ifremer
+ * %%
+ * 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%
+ */
+
+import fr.ifremer.tutti.persistence.DatabaseResource;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Ignore;
+import org.junit.Test;
+
+/**
+ * To test {@link PlanktonBatchPersistenceService} for read operation.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 0.3
+ */
+@Ignore
+public class PlanktonBatchPersistenceServiceReadTest {
+
+ @ClassRule
+ public static final DatabaseResource dbResource = DatabaseResource.readDb();
+
+ protected PlanktonBatchPersistenceService service;
+
+ @Before
+ public void setUp() throws Exception {
+ service = TuttiPersistenceServiceLocator.getPlanktonBatchPersistenceService();
+ }
+
+ @Test
+ public void getAllPlanktonBatch(/*String fishingOperationId*/) {
+
+ }
+
+ @Test
+ public void getPlanktonBatch(/*String id*/) {
+
+ }
+}
Deleted: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/PlanktonBatchPersistenceServiceTest.java
===================================================================
--- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/PlanktonBatchPersistenceServiceTest.java 2013-02-09 07:44:17 UTC (rev 378)
+++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/PlanktonBatchPersistenceServiceTest.java 2013-02-10 13:41:29 UTC (rev 379)
@@ -1,73 +0,0 @@
-package fr.ifremer.tutti.persistence.service;
-
-/*
- * #%L
- * Tutti :: Persistence API
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2012 - 2013 Ifremer
- * %%
- * 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%
- */
-
-import fr.ifremer.tutti.persistence.DatabaseResource;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Ignore;
-import org.junit.Test;
-
-/**
- * @author tchemit <chemit(a)codelutin.com>
- * @since 0.3
- */
-@Ignore
-public class PlanktonBatchPersistenceServiceTest {
-
- @ClassRule
- public static final DatabaseResource dbResource = new DatabaseResource();
-
- protected PlanktonBatchPersistenceService service;
-
- @Before
- public void setUp() throws Exception {
- service = TuttiPersistenceServiceLocator.getPlanktonBatchPersistenceService();
- }
-
- @Test
- public void getAllPlanktonBatch(/*String fishingOperationId*/) {
-
- }
-
- @Test
- public void getPlanktonBatch(/*String id*/) {
-
- }
-
- @Test
- public void createPlanktonBatch(/*PlanktonBatch bean*/) {
-
- }
-
- @Test
- public void savePlanktonBatch(/*PlanktonBatch bean*/) {
-
- }
-
- @Test
- public void deletePlanktonBatch(/*String id*/) {
- }
-}
Copied: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/PlanktonBatchPersistenceServiceWriteTest.java (from rev 378, trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/PlanktonBatchPersistenceServiceTest.java)
===================================================================
--- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/PlanktonBatchPersistenceServiceWriteTest.java (rev 0)
+++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/PlanktonBatchPersistenceServiceWriteTest.java 2013-02-10 13:41:29 UTC (rev 379)
@@ -0,0 +1,65 @@
+package fr.ifremer.tutti.persistence.service;
+
+/*
+ * #%L
+ * Tutti :: Persistence API
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2012 - 2013 Ifremer
+ * %%
+ * 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%
+ */
+
+import fr.ifremer.tutti.persistence.DatabaseResource;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Ignore;
+import org.junit.Test;
+
+/**
+ * To test {@link PlanktonBatchPersistenceService} for write operation.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.0
+ */
+@Ignore
+public class PlanktonBatchPersistenceServiceWriteTest {
+
+ @ClassRule
+ public static final DatabaseResource dbResource = DatabaseResource.writeDb();
+
+ protected PlanktonBatchPersistenceService service;
+
+ @Before
+ public void setUp() throws Exception {
+ service = TuttiPersistenceServiceLocator.getPlanktonBatchPersistenceService();
+ }
+
+ @Test
+ public void createPlanktonBatch(/*PlanktonBatch bean*/) {
+
+ }
+
+ @Test
+ public void savePlanktonBatch(/*PlanktonBatch bean*/) {
+
+ }
+
+ @Test
+ public void deletePlanktonBatch(/*String id*/) {
+ }
+}
Copied: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ProgramPersistenceServiceReadTest.java (from rev 378, trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ProgramPersistenceServiceTest.java)
===================================================================
--- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ProgramPersistenceServiceReadTest.java (rev 0)
+++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ProgramPersistenceServiceReadTest.java 2013-02-10 13:41:29 UTC (rev 379)
@@ -0,0 +1,79 @@
+package fr.ifremer.tutti.persistence.service;
+
+/*
+ * #%L
+ * Tutti :: Persistence API
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2012 - 2013 Ifremer
+ * %%
+ * 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%
+ */
+
+import fr.ifremer.tutti.persistence.DatabaseResource;
+import fr.ifremer.tutti.persistence.entities.data.Program;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Test;
+
+import java.util.List;
+
+/**
+ * To test {@link ProgramPersistenceService} for read operation.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 0.3
+ */
+public class ProgramPersistenceServiceReadTest {
+
+ @ClassRule
+ public static final DatabaseResource dbResource = DatabaseResource.readDb();
+
+ protected ProgramPersistenceService service;
+
+ @Before
+ public void setUp() throws Exception {
+ service = TuttiPersistenceServiceLocator.getProgramPersistenceService();
+ }
+
+ @Test
+ public void getAllProgram() {
+ List<Program> result = service.getAllProgram();
+ Assert.assertNotNull(result);
+ Assert.assertTrue("More than one program must be found", result.size() > 0);
+ for (Program program : result) {
+ Assert.assertNotNull(program.getId());
+ Assert.assertNotEquals("SIH-OBSMER", program.getId());
+ Assert.assertNotEquals("SIH-ACTIFLOT", program.getId());
+ }
+ }
+
+ @Test
+ public void getProgram(/*String id*/) {
+ String programCode = dbResource.getFixtures().programCode();
+ Program actual = service.getProgram(programCode);
+ Assert.assertNotNull(actual);
+ Assert.assertNotNull(actual.getId());
+ Assert.assertNotNull(actual.getName());
+ Assert.assertNotNull(actual.getComment());
+ //comment, because in test database, "CAM-CGFS" could have a location that is not a zone
+ //Assert.assertNotNull(actual.getZone());
+ Assert.assertEquals(programCode, actual.getId());
+ }
+
+}
Deleted: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ProgramPersistenceServiceTest.java
===================================================================
--- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ProgramPersistenceServiceTest.java 2013-02-09 07:44:17 UTC (rev 378)
+++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ProgramPersistenceServiceTest.java 2013-02-10 13:41:29 UTC (rev 379)
@@ -1,138 +0,0 @@
-package fr.ifremer.tutti.persistence.service;
-
-/*
- * #%L
- * Tutti :: Persistence API
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2012 - 2013 Ifremer
- * %%
- * 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%
- */
-
-import fr.ifremer.tutti.persistence.DatabaseResource;
-import fr.ifremer.tutti.persistence.entities.data.Program;
-import fr.ifremer.tutti.persistence.entities.referential.Zone;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Test;
-
-import java.util.List;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-
-/**
- * @author tchemit <chemit(a)codelutin.com>
- * @since 0.3
- */
-public class ProgramPersistenceServiceTest {
-
- @ClassRule
- public static final DatabaseResource dbResource = new DatabaseResource();
-
- protected ProgramPersistenceService service;
-
- protected ReferentialPersistenceService referentialService;
-
- @Before
- public void setUp() throws Exception {
- service = TuttiPersistenceServiceLocator.getProgramPersistenceService();
- referentialService = TuttiPersistenceServiceLocator.getReferentialPersistenceService();
- }
-
- @Test
- public void getAllProgram() {
- List<Program> result = service.getAllProgram();
- Assert.assertNotNull(result);
- Assert.assertTrue("More than one program must be found", result.size() > 0);
- for (Program program : result) {
- Assert.assertNotNull(program.getId());
- Assert.assertNotEquals("SIH-OBSMER", program.getId());
- Assert.assertNotEquals("SIH-ACTIFLOT", program.getId());
- }
- }
-
- @Test
- public void getProgram(/*String id*/) {
- String programCode = dbResource.getFixtures().programCode();
- Program actual = service.getProgram(programCode);
- Assert.assertNotNull(actual);
- Assert.assertNotNull(actual.getId());
- Assert.assertNotNull(actual.getName());
- Assert.assertNotNull(actual.getComment());
- //comment, because in test database, "CAM-CGFS" could have a location that is not a zone
- //Assert.assertNotNull(actual.getZone());
- Assert.assertEquals(programCode, actual.getId());
- }
-
- @Test
- public void createAndSaveProgram(/*Program bean*/) {
-
- List<Zone> zones = referentialService.getAllProgramZone();
- assertNotNull(zones);
- assertTrue(zones.size() > 0);
-
- Program program = new Program();
- String name = "UniTest" + System.currentTimeMillis();
- if (name.length() > 40) {
- name = name.substring(0, 39);
- }
- program.setName(name);
-
- program.setZone(zones.get(0));
-
- // Create program
- Program createdProgram = service.createProgram(program);
- assertNotNull(createdProgram);
- assertNotNull(createdProgram.getId());
- assertNull(createdProgram.getComment());
-
- // Reload program and compare
- Program reloadedProgram = service.getProgram(createdProgram.getId());
- assertNotNull(reloadedProgram);
- assertEquals(createdProgram.getId(), reloadedProgram.getId());
- assertEquals(program.getName(), reloadedProgram.getName());
- assertNull(reloadedProgram.getComment());
- assertNotNull(program.getZone());
- assertEquals(program.getZone().getId(), reloadedProgram.getZone().getId());
-
- // Modify program
- program.setId(createdProgram.getId());
- program.setName("NEW_NAME");
- program.setComment("Add some modification");
- program.setZone(zones.get(1));
-
- // Save program
- Program savedProgram = service.saveProgram(program);
- assertNotNull(savedProgram);
- assertNotNull(savedProgram.getId());
-
- // Reload program and compare
- reloadedProgram = service.getProgram(savedProgram.getId());
- assertNotNull(reloadedProgram);
- assertEquals(program.getId(), reloadedProgram.getId());
- assertEquals(program.getName(), reloadedProgram.getName());
- assertEquals(program.getComment(), reloadedProgram.getComment());
- assertNotNull(program.getZone());
- assertEquals(program.getZone().getId(), reloadedProgram.getZone().getId());
- }
-
-}
Copied: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ProgramPersistenceServiceWriteTest.java (from rev 378, trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ProgramPersistenceServiceTest.java)
===================================================================
--- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ProgramPersistenceServiceWriteTest.java (rev 0)
+++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ProgramPersistenceServiceWriteTest.java 2013-02-10 13:41:29 UTC (rev 379)
@@ -0,0 +1,114 @@
+package fr.ifremer.tutti.persistence.service;
+
+/*
+ * #%L
+ * Tutti :: Persistence API
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2012 - 2013 Ifremer
+ * %%
+ * 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%
+ */
+
+import fr.ifremer.tutti.persistence.DatabaseResource;
+import fr.ifremer.tutti.persistence.entities.data.Program;
+import fr.ifremer.tutti.persistence.entities.referential.Zone;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Test;
+
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * To test {@link ProgramPersistenceService} for write operation.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.0
+ */
+public class ProgramPersistenceServiceWriteTest {
+
+ @ClassRule
+ public static final DatabaseResource dbResource = DatabaseResource.writeDb();
+
+ protected ProgramPersistenceService service;
+
+ protected ReferentialPersistenceService referentialService;
+
+ @Before
+ public void setUp() throws Exception {
+ service = TuttiPersistenceServiceLocator.getProgramPersistenceService();
+ referentialService = TuttiPersistenceServiceLocator.getReferentialPersistenceService();
+ }
+
+ @Test
+ public void createAndSaveProgram(/*Program bean*/) {
+
+ List<Zone> zones = referentialService.getAllProgramZone();
+ assertNotNull(zones);
+ assertTrue(zones.size() > 0);
+
+ Program program = new Program();
+ String name = "UniTest" + System.currentTimeMillis();
+ if (name.length() > 40) {
+ name = name.substring(0, 39);
+ }
+ program.setName(name);
+
+ program.setZone(zones.get(0));
+
+ // Create program
+ Program createdProgram = service.createProgram(program);
+ assertNotNull(createdProgram);
+ assertNotNull(createdProgram.getId());
+ assertNull(createdProgram.getComment());
+
+ // Reload program and compare
+ Program reloadedProgram = service.getProgram(createdProgram.getId());
+ assertNotNull(reloadedProgram);
+ assertEquals(createdProgram.getId(), reloadedProgram.getId());
+ assertEquals(program.getName(), reloadedProgram.getName());
+ assertNull(reloadedProgram.getComment());
+ assertNotNull(program.getZone());
+ assertEquals(program.getZone().getId(), reloadedProgram.getZone().getId());
+
+ // Modify program
+ program.setId(createdProgram.getId());
+ program.setName("NEW_NAME");
+ program.setComment("Add some modification");
+ program.setZone(zones.get(1));
+
+ // Save program
+ Program savedProgram = service.saveProgram(program);
+ assertNotNull(savedProgram);
+ assertNotNull(savedProgram.getId());
+
+ // Reload program and compare
+ reloadedProgram = service.getProgram(savedProgram.getId());
+ assertNotNull(reloadedProgram);
+ assertEquals(program.getId(), reloadedProgram.getId());
+ assertEquals(program.getName(), reloadedProgram.getName());
+ assertEquals(program.getComment(), reloadedProgram.getComment());
+ assertNotNull(program.getZone());
+ assertEquals(program.getZone().getId(), reloadedProgram.getZone().getId());
+ }
+
+}
Copied: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ProtocolPersistenceServiceReadTest.java (from rev 378, trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ProtocolPersistenceServiceTest.java)
===================================================================
--- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ProtocolPersistenceServiceReadTest.java (rev 0)
+++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ProtocolPersistenceServiceReadTest.java 2013-02-10 13:41:29 UTC (rev 379)
@@ -0,0 +1,116 @@
+package fr.ifremer.tutti.persistence.service;
+
+/*
+ * #%L
+ * Tutti :: Persistence API
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2012 - 2013 Ifremer
+ * %%
+ * 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%
+ */
+
+import com.google.common.collect.Lists;
+import fr.ifremer.tutti.persistence.DatabaseResource;
+import fr.ifremer.tutti.persistence.entities.protocol.SpeciesProtocol;
+import fr.ifremer.tutti.persistence.entities.protocol.TuttiProtocol;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import java.util.List;
+
+/**
+ * To test {@link ProtocolPersistenceService} for read operation.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 0.3
+ */
+@Ignore
+public class ProtocolPersistenceServiceReadTest {
+
+ @ClassRule
+ public static final DatabaseResource dbResource = DatabaseResource.readDb();
+
+ protected ProtocolPersistenceService service;
+
+ @Before
+ public void setUp() throws Exception {
+ service = TuttiPersistenceServiceLocator.getProtocolPersistenceService();
+ }
+
+ @Test
+ public void getAllProtocol() {
+
+ List<TuttiProtocol> allProtocol = service.getAllProtocol();
+ Assert.assertTrue(allProtocol.isEmpty());
+
+ TuttiProtocol protocol = createProtocolFixture();
+ TuttiProtocol createdProtocol = service.createProtocol(protocol);
+ allProtocol = service.getAllProtocol();
+ Assert.assertFalse(allProtocol.isEmpty());
+ Assert.assertEquals(createdProtocol, allProtocol.get(0));
+ }
+
+ @Test
+ public void getProtocol(/*String id*/) {
+ TuttiProtocol protocol = createProtocolFixture();
+ TuttiProtocol createdProtocol = service.createProtocol(protocol);
+ Assert.assertNotNull(createdProtocol);
+ String id = createdProtocol.getId();
+ TuttiProtocol loadedProtocol = service.getProtocol(id);
+ Assert.assertNotNull(loadedProtocol);
+ }
+
+ protected TuttiProtocol createProtocolFixture() {
+ TuttiProtocol protocol = new TuttiProtocol();
+ protocol.setId("1");
+ protocol.setName("protocolName");
+ protocol.setComment("Commentaire");
+ protocol.setLengthClassesPmfmId(Lists.newArrayList("14", "18"));
+ protocol.setEnvironmentPmfmId(Lists.newArrayList("114", "228", "821"));
+ protocol.setGearPmfmId(Lists.newArrayList("21", "22"));
+ protocol.setHydrologyPmfmId(Lists.<String>newArrayList());
+
+ protocol.setSpecies(Lists.<SpeciesProtocol>newArrayList());
+ SpeciesProtocol sp1 = new SpeciesProtocol();
+ sp1.setId("1");
+ sp1.setSpeciesReferenceTaxonId(11242);
+ sp1.setLengthStepPmfmId("1394");
+ sp1.setCalcifySampleEnabled(true);
+ sp1.setMaturityEnabled(true);
+ sp1.setSexEnabled(true);
+ sp1.setWeightEnabled(true);
+ protocol.addSpecies(sp1);
+
+ SpeciesProtocol sp2 = new SpeciesProtocol();
+ sp2.setId("2");
+ sp2.setSpeciesReferenceTaxonId(3835);
+ sp2.setLengthStepPmfmId("323");
+ sp2.setAgeEnabled(true);
+ sp2.setCalcifySampleEnabled(true);
+ sp2.setCountIfNoFrequencyEnabled(true);
+ sp2.setMaturityEnabled(true);
+ sp2.setSexEnabled(true);
+ sp2.setSizeEnabled(true);
+ sp2.setWeightEnabled(true);
+ protocol.addSpecies(sp2);
+ return protocol;
+ }
+}
Deleted: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ProtocolPersistenceServiceTest.java
===================================================================
--- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ProtocolPersistenceServiceTest.java 2013-02-09 07:44:17 UTC (rev 378)
+++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ProtocolPersistenceServiceTest.java 2013-02-10 13:41:29 UTC (rev 379)
@@ -1,189 +0,0 @@
-package fr.ifremer.tutti.persistence.service;
-
-/*
- * #%L
- * Tutti :: Persistence API
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2012 - 2013 Ifremer
- * %%
- * 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%
- */
-
-import com.google.common.collect.Lists;
-import fr.ifremer.tutti.persistence.DatabaseResource;
-import fr.ifremer.tutti.persistence.entities.protocol.SpeciesProtocol;
-import fr.ifremer.tutti.persistence.entities.protocol.TuttiProtocol;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Ignore;
-import org.junit.Test;
-
-import java.util.List;
-
-/**
- * @author tchemit <chemit(a)codelutin.com>
- * @since 0.3
- */
-@Ignore
-public class ProtocolPersistenceServiceTest {
-
- @ClassRule
- public static final DatabaseResource dbResource = new DatabaseResource();
-
- protected ProtocolPersistenceService service;
-
- public static final String PROTOCOL_FILE_CONTENT =
- "id: 1\n" +
- "name: protocolName\n" +
- "comment: Commentaire\n" +
- "environmentPmfmId: \n" +
- "- 114\n" +
- "- 228\n" +
- "- 821\n" +
- "gearPmfmId: \n" +
- "- 21\n" +
- "- 22\n" +
- "hydrologyPmfmId: []\n" +
- "lengthClassesPmfmId: \n" +
- "- 14\n" +
- "- 18\n" +
- "species: \n" +
- "- !SpeciesProtocol\n" +
- " id: 1\n" +
- " calcifySampleEnabled: true\n" +
- " lengthStepPmfmId: 1394\n" +
- " maturityEnabled: true\n" +
- " sexEnabled: true\n" +
- " speciesReferenceTaxonId: 11242\n" +
- " weightEnabled: true\n" +
- "- !SpeciesProtocol\n" +
- " id: 2\n" +
- " ageEnabled: true\n" +
- " calcifySampleEnabled: true\n" +
- " countIfNoFrequencyEnabled: true\n" +
- " lengthStepPmfmId: 323\n" +
- " maturityEnabled: true\n" +
- " sexEnabled: true\n" +
- " sizeEnabled: true\n" +
- " speciesReferenceTaxonId: 3835\n" +
- " weightEnabled: true";
-
- @Before
- public void setUp() throws Exception {
- service = TuttiPersistenceServiceLocator.getProtocolPersistenceService();
- }
-
- @Test
- public void getAllProtocol() {
-
- List<TuttiProtocol> allProtocol = service.getAllProtocol();
- Assert.assertTrue(allProtocol.isEmpty());
-
- TuttiProtocol protocol = createProtocolFixture();
- TuttiProtocol createdProtocol = service.createProtocol(protocol);
- allProtocol = service.getAllProtocol();
- Assert.assertFalse(allProtocol.isEmpty());
- Assert.assertEquals(createdProtocol, allProtocol.get(0));
- }
-
- @Test
- public void getProtocol(/*String id*/) {
- TuttiProtocol protocol = createProtocolFixture();
- TuttiProtocol createdProtocol = service.createProtocol(protocol);
- Assert.assertNotNull(createdProtocol);
- String id = createdProtocol.getId();
- TuttiProtocol loadedProtocol = service.getProtocol(id);
- Assert.assertNotNull(loadedProtocol);
- }
-
- @Test
- public void createProtocol(/*TuttiProtocol bean*/) {
-
- TuttiProtocol protocol = createProtocolFixture();
- TuttiProtocol createdProtocol = service.createProtocol(protocol);
- Assert.assertNotNull(createdProtocol);
- String id = createdProtocol.getId();
- Assert.assertTrue(service.getAllProtocolId().contains(id));
-
- }
-
- @Test
- public void saveProtocol(/*TuttiProtocol bean*/) {
-
- TuttiProtocol protocol = createProtocolFixture();
- TuttiProtocol createdProtocol = service.createProtocol(protocol);
-
- Assert.assertNotNull(createdProtocol);
- String id = createdProtocol.getId();
- Assert.assertTrue(service.getAllProtocolId().contains(id));
-
- TuttiProtocol savedProtocol = service.saveProtocol(createdProtocol);
- Assert.assertNotNull(savedProtocol);
- }
-
- @Test
- public void deleteProtocol() {
-
- TuttiProtocol protocol = createProtocolFixture();
- TuttiProtocol createdProtocol = service.createProtocol(protocol);
- Assert.assertNotNull(createdProtocol);
-
- String id = createdProtocol.getId();
- Assert.assertTrue(service.getAllProtocolId().contains(id));
-
- service.deleteProtocol(id);
- Assert.assertFalse(service.getAllProtocolId().contains(id));
- }
-
- protected TuttiProtocol createProtocolFixture() {
- TuttiProtocol protocol = new TuttiProtocol();
- protocol.setId("1");
- protocol.setName("protocolName");
- protocol.setComment("Commentaire");
- protocol.setLengthClassesPmfmId(Lists.newArrayList("14", "18"));
- protocol.setEnvironmentPmfmId(Lists.newArrayList("114", "228", "821"));
- protocol.setGearPmfmId(Lists.newArrayList("21", "22"));
- protocol.setHydrologyPmfmId(Lists.<String>newArrayList());
-
- protocol.setSpecies(Lists.<SpeciesProtocol>newArrayList());
- SpeciesProtocol sp1 = new SpeciesProtocol();
- sp1.setId("1");
- sp1.setSpeciesReferenceTaxonId(11242);
- sp1.setLengthStepPmfmId("1394");
- sp1.setCalcifySampleEnabled(true);
- sp1.setMaturityEnabled(true);
- sp1.setSexEnabled(true);
- sp1.setWeightEnabled(true);
- protocol.addSpecies(sp1);
-
- SpeciesProtocol sp2 = new SpeciesProtocol();
- sp2.setId("2");
- sp2.setSpeciesReferenceTaxonId(3835);
- sp2.setLengthStepPmfmId("323");
- sp2.setAgeEnabled(true);
- sp2.setCalcifySampleEnabled(true);
- sp2.setCountIfNoFrequencyEnabled(true);
- sp2.setMaturityEnabled(true);
- sp2.setSexEnabled(true);
- sp2.setSizeEnabled(true);
- sp2.setWeightEnabled(true);
- protocol.addSpecies(sp2);
- return protocol;
- }
-}
Copied: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ProtocolPersistenceServiceWriteTest.java (from rev 378, trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ProtocolPersistenceServiceTest.java)
===================================================================
--- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ProtocolPersistenceServiceWriteTest.java (rev 0)
+++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ProtocolPersistenceServiceWriteTest.java 2013-02-10 13:41:29 UTC (rev 379)
@@ -0,0 +1,166 @@
+package fr.ifremer.tutti.persistence.service;
+
+/*
+ * #%L
+ * Tutti :: Persistence API
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2012 - 2013 Ifremer
+ * %%
+ * 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%
+ */
+
+import com.google.common.collect.Lists;
+import fr.ifremer.tutti.persistence.DatabaseResource;
+import fr.ifremer.tutti.persistence.entities.protocol.SpeciesProtocol;
+import fr.ifremer.tutti.persistence.entities.protocol.TuttiProtocol;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Ignore;
+import org.junit.Test;
+
+/**
+ * To test {@link ProtocolPersistenceService} for write operation.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 0.3
+ */
+@Ignore
+public class ProtocolPersistenceServiceWriteTest {
+
+ @ClassRule
+ public static final DatabaseResource dbResource = DatabaseResource.writeDb();
+
+ protected ProtocolPersistenceService service;
+
+ public static final String PROTOCOL_FILE_CONTENT =
+ "id: 1\n" +
+ "name: protocolName\n" +
+ "comment: Commentaire\n" +
+ "environmentPmfmId: \n" +
+ "- 114\n" +
+ "- 228\n" +
+ "- 821\n" +
+ "gearPmfmId: \n" +
+ "- 21\n" +
+ "- 22\n" +
+ "hydrologyPmfmId: []\n" +
+ "lengthClassesPmfmId: \n" +
+ "- 14\n" +
+ "- 18\n" +
+ "species: \n" +
+ "- !SpeciesProtocol\n" +
+ " id: 1\n" +
+ " calcifySampleEnabled: true\n" +
+ " lengthStepPmfmId: 1394\n" +
+ " maturityEnabled: true\n" +
+ " sexEnabled: true\n" +
+ " speciesReferenceTaxonId: 11242\n" +
+ " weightEnabled: true\n" +
+ "- !SpeciesProtocol\n" +
+ " id: 2\n" +
+ " ageEnabled: true\n" +
+ " calcifySampleEnabled: true\n" +
+ " countIfNoFrequencyEnabled: true\n" +
+ " lengthStepPmfmId: 323\n" +
+ " maturityEnabled: true\n" +
+ " sexEnabled: true\n" +
+ " sizeEnabled: true\n" +
+ " speciesReferenceTaxonId: 3835\n" +
+ " weightEnabled: true";
+
+ @Before
+ public void setUp() throws Exception {
+ service = TuttiPersistenceServiceLocator.getProtocolPersistenceService();
+ }
+
+ @Test
+ public void createProtocol(/*TuttiProtocol bean*/) {
+
+ TuttiProtocol protocol = createProtocolFixture();
+ TuttiProtocol createdProtocol = service.createProtocol(protocol);
+ Assert.assertNotNull(createdProtocol);
+ String id = createdProtocol.getId();
+ Assert.assertTrue(service.getAllProtocolId().contains(id));
+
+ }
+
+ @Test
+ public void saveProtocol(/*TuttiProtocol bean*/) {
+
+ TuttiProtocol protocol = createProtocolFixture();
+ TuttiProtocol createdProtocol = service.createProtocol(protocol);
+
+ Assert.assertNotNull(createdProtocol);
+ String id = createdProtocol.getId();
+ Assert.assertTrue(service.getAllProtocolId().contains(id));
+
+ TuttiProtocol savedProtocol = service.saveProtocol(createdProtocol);
+ Assert.assertNotNull(savedProtocol);
+ }
+
+ @Test
+ public void deleteProtocol() {
+
+ TuttiProtocol protocol = createProtocolFixture();
+ TuttiProtocol createdProtocol = service.createProtocol(protocol);
+ Assert.assertNotNull(createdProtocol);
+
+ String id = createdProtocol.getId();
+ Assert.assertTrue(service.getAllProtocolId().contains(id));
+
+ service.deleteProtocol(id);
+ Assert.assertFalse(service.getAllProtocolId().contains(id));
+ }
+
+ protected TuttiProtocol createProtocolFixture() {
+ TuttiProtocol protocol = new TuttiProtocol();
+ protocol.setId("1");
+ protocol.setName("protocolName");
+ protocol.setComment("Commentaire");
+ protocol.setLengthClassesPmfmId(Lists.newArrayList("14", "18"));
+ protocol.setEnvironmentPmfmId(Lists.newArrayList("114", "228", "821"));
+ protocol.setGearPmfmId(Lists.newArrayList("21", "22"));
+ protocol.setHydrologyPmfmId(Lists.<String>newArrayList());
+
+ protocol.setSpecies(Lists.<SpeciesProtocol>newArrayList());
+ SpeciesProtocol sp1 = new SpeciesProtocol();
+ sp1.setId("1");
+ sp1.setSpeciesReferenceTaxonId(11242);
+ sp1.setLengthStepPmfmId("1394");
+ sp1.setCalcifySampleEnabled(true);
+ sp1.setMaturityEnabled(true);
+ sp1.setSexEnabled(true);
+ sp1.setWeightEnabled(true);
+ protocol.addSpecies(sp1);
+
+ SpeciesProtocol sp2 = new SpeciesProtocol();
+ sp2.setId("2");
+ sp2.setSpeciesReferenceTaxonId(3835);
+ sp2.setLengthStepPmfmId("323");
+ sp2.setAgeEnabled(true);
+ sp2.setCalcifySampleEnabled(true);
+ sp2.setCountIfNoFrequencyEnabled(true);
+ sp2.setMaturityEnabled(true);
+ sp2.setSexEnabled(true);
+ sp2.setSizeEnabled(true);
+ sp2.setWeightEnabled(true);
+ protocol.addSpecies(sp2);
+ return protocol;
+ }
+}
Copied: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceServiceReadTest.java (from rev 378, trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceServiceTest.java)
===================================================================
--- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceServiceReadTest.java (rev 0)
+++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceServiceReadTest.java 2013-02-10 13:41:29 UTC (rev 379)
@@ -0,0 +1,428 @@
+package fr.ifremer.tutti.persistence.service;
+
+/*
+ * #%L
+ * Tutti :: Persistence API
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2012 - 2013 Ifremer
+ * %%
+ * 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%
+ */
+
+import com.google.common.base.Preconditions;
+import fr.ifremer.adagio.core.service.technical.CacheService;
+import fr.ifremer.tutti.persistence.DatabaseFixtures;
+import fr.ifremer.tutti.persistence.DatabaseResource;
+import fr.ifremer.tutti.persistence.TuttiPersistenceDevImpl;
+import fr.ifremer.tutti.persistence.entities.IdAware;
+import fr.ifremer.tutti.persistence.entities.TuttiEntities;
+import fr.ifremer.tutti.persistence.entities.referential.Caracteristic;
+import fr.ifremer.tutti.persistence.entities.referential.Country;
+import fr.ifremer.tutti.persistence.entities.referential.FishingOperationLocation;
+import fr.ifremer.tutti.persistence.entities.referential.Gear;
+import fr.ifremer.tutti.persistence.entities.referential.Person;
+import fr.ifremer.tutti.persistence.entities.referential.Species;
+import fr.ifremer.tutti.persistence.entities.referential.Vessel;
+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;
+import org.junit.BeforeClass;
+import org.junit.ClassRule;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.nuiton.util.ApplicationConfig;
+
+import java.io.IOException;
+import java.util.List;
+
+import static fr.ifremer.tutti.persistence.TuttiPersistenceDevImpl.CaracteristicEnum;
+
+/**
+ * To test {@link ReferentialPersistenceService} for read operation.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 0.3
+ */
+public class ReferentialPersistenceServiceReadTest {
+
+ @ClassRule
+ public static final DatabaseResource dbResource = DatabaseResource.readDb();
+
+ /** Logger. */
+ private static final Log log =
+ LogFactory.getLog(ReferentialPersistenceServiceReadTest.class);
+
+ protected static TuttiPersistenceDevImpl storage;
+
+ protected ReferentialPersistenceService service;
+
+ protected CacheService cacheService;
+
+ protected DatabaseFixtures fixtures;
+
+ @BeforeClass
+ public static void beforeClass() throws IOException {
+
+ // create a storage
+
+ ApplicationConfig applicationConfig = dbResource.getConfig().getConfig();
+
+ applicationConfig.setOption(
+ TuttiPersistenceDevImpl.SKIP_FIXTURES_OPTION, Boolean.TRUE.toString());
+
+ storage = new TuttiPersistenceDevImpl(applicationConfig) {
+
+ @Override
+ public <B extends IdAware> B create(String type,
+ B bean,
+ boolean sychronize) {
+ Preconditions.checkNotNull(bean, "Can't persist a null bean");
+ B result = TuttiEntities.newEntity(bean);
+ result.setId(bean.getId());
+ if (log.isDebugEnabled()) {
+ log.debug("Will persist [" + type + ":" + bean.getId() + "]");
+ }
+ super.persist(type, bean, result, sychronize);
+ return result;
+ }
+ };
+
+ if (log.isInfoEnabled()) {
+ log.info("Will init persistence driver " + storage.getImplementationName());
+ }
+
+ storage.init();
+
+ TuttiPersistenceServiceLocator.instance().getCacheService().clearAllCaches();
+ }
+
+ @AfterClass
+ public static void afterClass() throws IOException {
+ storage.close();
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ service = TuttiPersistenceServiceLocator.getReferentialPersistenceService();
+ cacheService = TuttiPersistenceServiceLocator.instance().getCacheService();
+
+ // This is need for test : getAllFishingVessel()
+// cacheService.clearAllCaches();
+ fixtures = dbResource.getFixtures();
+ }
+
+ @Test
+ public void getAllProgramZone() {
+ List<Zone> result = service.getAllProgramZone();
+ assertResultList(result, fixtures.refNbProgramZone());
+
+ persistList(Zone.class, result);
+ assertSize(result, storage.getAllProgramZone());
+ }
+
+ @Test
+ public void getAllCountry() {
+ List<Country> result = service.getAllCountry();
+ assertResultList(result, fixtures.refNbCountry());
+
+ persistList(Country.class, result);
+ assertSize(result, storage.getAllCountry());
+ }
+
+ @Test
+ public void getAllFishingOperationStrata(/*String zoneId*/) {
+ String zoneId = dbResource.getFixtures().zoneId();
+ List<FishingOperationLocation> result =
+ service.getAllFishingOperationStrata(zoneId);
+ assertResultList(result, fixtures.refNbStrata());
+
+ persistList(FishingOperationLocation.class, "Strata", result);
+ assertSize(result, storage.getAllFishingOperationStrata(zoneId));
+ }
+
+ @Test
+ public void getAllFishingOperationSubStrata(/*String zoneId, String strataId*/) {
+ String zoneId = dbResource.getFixtures().zoneId();
+ List<FishingOperationLocation> result =
+ service.getAllFishingOperationSubStrata(zoneId, null);
+ assertResultList(result, 0);
+
+ persistList(FishingOperationLocation.class, "SubStrata", result);
+ assertSize(result, storage.getAllFishingOperationSubStrata(zoneId, null));
+
+ // try with a strataId
+ String strataId = dbResource.getFixtures().strataId();
+ result = service.getAllFishingOperationLocation(zoneId, strataId, null);
+ assertResultList(result, 1);
+ }
+
+ @Test
+ public void getAllFishingOperationLocation(/*String zoneId, String strataId, String subStrataId*/) {
+ String zoneId = dbResource.getFixtures().zoneId();
+ List<FishingOperationLocation> result =
+ service.getAllFishingOperationLocation(zoneId, null, null);
+ assertResultList(result, fixtures.refNbLocalite());
+
+ persistList(FishingOperationLocation.class, "Localite", result);
+ assertSize(result, storage.getAllFishingOperationLocation(zoneId, null, null));
+
+ // try with a strataId
+ String strataId = dbResource.getFixtures().strataId();
+ result = service.getAllFishingOperationLocation(zoneId, strataId, null);
+ assertResultList(result, 1);
+
+ // try with a subStrataId
+ String subStrataId = dbResource.getFixtures().subStrataId();
+ result = service.getAllFishingOperationLocation(zoneId, strataId, subStrataId);
+ assertResultList(result, 3);
+ }
+
+ @Test
+ public void getAllScientificVessel() {
+ List<Vessel> result = service.getAllScientificVessel();
+ assertResultList(result, fixtures.refNbScientificVessel());
+ persistList(Vessel.class, "Scientific", result);
+ assertSize(result, storage.getAllScientificVessel());
+ }
+
+ @Test
+ public void getAllFishingVessel() {
+
+ // clear cache before this test
+ cacheService.clearCache("fishingVessels");
+
+ long time = System.currentTimeMillis();
+ List<Vessel> result = service.getAllFishingVessel();
+ long delta1 = System.currentTimeMillis() - time;
+
+ assertResultList(result, fixtures.refNbFishingVessel());
+
+ // try again, to check cache is enable
+ time = System.currentTimeMillis();
+ result = service.getAllFishingVessel();
+ assertResultList(result, fixtures.refNbFishingVessel());
+
+ long delta2 = System.currentTimeMillis() - time;
+
+ //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);
+
+ persistList(Vessel.class, "Fishing", result);
+ assertSize(result, storage.getAllFishingVessel());
+ }
+
+ @Test
+ public void getAllScientificGear() {
+ List<Gear> result = service.getAllScientificGear();
+ assertResultList(result, fixtures.refNbScientificGear());
+
+ persistList(Gear.class, "Scientific", result);
+ assertSize(result, storage.getAllScientificGear());
+ }
+
+ @Test
+ public void getAllFishingGear() {
+ List<Gear> result = service.getAllFishingGear();
+ assertResultList(result, fixtures.refNbFishingGear());
+
+ persistList(Gear.class, "Fishing", result);
+ assertSize(result, storage.getAllFishingGear());
+ }
+
+ @Test
+ public void getAllPerson() {
+ List<Person> result = service.getAllPerson();
+ assertResultList(result, fixtures.refNbPerson());
+
+ persistList(Person.class, result);
+ assertSize(result, storage.getAllPerson());
+ }
+
+ @Test
+ public void getAllSpecies() {
+ List<Species> result = service.getAllSpecies();
+ assertResultList(result, fixtures.refNbSpecies());
+
+ persistList(Species.class, result);
+ assertSize(result, storage.getAllSpecies());
+ }
+
+ @Test
+ public void getAllReferentSpecies() {
+ List<Species> result = service.getAllReferentSpecies();
+ assertResultList(result, fixtures.refNbReferentSpecies());
+
+ TuttiEntities.splitByTaxonId(result);
+ }
+
+ @Test
+ public void getSpeciesByReferenceTaxonId(/*String speciesReferenceTaxonId*/) {
+ String speciesId = fixtures.refSpeciesId();
+ Integer taxonId = fixtures.refSpeciesTaxonId();
+ Species species = service.getSpeciesByReferenceTaxonId(taxonId);
+ Assert.assertNotNull(species);
+ Assert.assertEquals(speciesId, species.getId());
+ 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();
+ assertResultList(result, fixtures.refNbCaracteristic());
+
+ persistList(Caracteristic.class, CaracteristicEnum.All.name(), result);
+ assertSize(result, storage.getAllCaracteristic());
+ }
+
+ @Test
+ public void getSizeCategoryCaracteristic() {
+ Caracteristic result = service.getSizeCategoryCaracteristic();
+ assertCaracteristicQualitative(result, 6);
+ persist(Caracteristic.class, CaracteristicEnum.SizeCategory.name(), result);
+ }
+
+ @Test
+ public void getSexCaracteristic() {
+ Caracteristic result = service.getSexCaracteristic();
+ assertCaracteristicQualitative(result, 4);
+ persist(Caracteristic.class, CaracteristicEnum.SexCategory.name(), result);
+ }
+
+ @Test
+ public void getSortedUnsortedCaracteristic() {
+ Caracteristic result = service.getSortedUnsortedCaracteristic();
+ assertCaracteristicQualitative(result, 2);
+ persist(Caracteristic.class, CaracteristicEnum.SortedUnsortedCategory.name(), result);
+ }
+
+ @Test
+ public void getMaturityCaracteristic() {
+ Caracteristic result = service.getMaturityCaracteristic();
+ assertCaracteristicQualitative(result, 6);
+ persist(Caracteristic.class, CaracteristicEnum.MaturityCategory.name(), result);
+ }
+
+ @Test
+ public void getMacroWasteCategoryCaracteristic() {
+ Caracteristic result = service.getMacroWasteCategoryCaracteristic();
+ assertCaracteristicQualitative(result, 21);
+ persist(Caracteristic.class, CaracteristicEnum.MacroWasteCategory.name(), result);
+ }
+
+ @Test
+ public void getMacroWasteSizeCategoryCaracteristic() {
+ Caracteristic result = service.getMacroWasteSizeCategoryCaracteristic();
+ assertCaracteristicQualitative(result, 6);
+ persist(Caracteristic.class, CaracteristicEnum.MacroWasteSizeCategory.name(), result);
+ }
+
+ @Test
+ @Ignore
+ public void testCaches() {
+ cacheService.clearAllCaches();
+
+ Object obj = service.getAllCaracteristic();
+ System.out.println(obj);
+
+ obj = service.getCaracteristic(1429);
+ System.out.println(obj);
+
+ obj = service.getCaracteristic(1428);
+ System.out.println(obj);
+ }
+
+ protected <S extends IdAware> void persistList(Class<S> type, List<S> result) {
+ persistList(type, null, result);
+ }
+
+ protected <S extends IdAware> void persistList(Class<S> type, String context, List<S> result) {
+
+ String key = TuttiPersistenceDevImpl.getKey(type, context);
+ for (S s : result) {
+ storage.create(key, s, false);
+ }
+ storage.persistToFile(key);
+ }
+
+ protected <S extends IdAware> void persist(Class<S> type, S result) {
+ persist(type, null, result);
+ }
+
+ protected <S extends IdAware> void persist(Class<S> type, String context, S result) {
+ String key = TuttiPersistenceDevImpl.getKey(type, context);
+ storage.create(key, result, true);
+ }
+
+ protected void assertSize(List<?> expectedList, List<?> storageList) {
+ Assert.assertNotNull(expectedList);
+ Assert.assertNotNull(storageList);
+ expectedList.removeAll(storageList);
+ Assert.assertTrue("Some " + expectedList.size() + " entities were not persisted in storage :" +
+ expectedList, expectedList.isEmpty());
+
+ }
+
+ protected void assertCaracteristicQualitative(Caracteristic result, int nbValues) {
+ Assert.assertNotNull(result);
+ Assert.assertNotNull(result.getCaracteristicType());
+ Assert.assertTrue(TuttiEntities.isQualitativeCaracteristic(result));
+ Assert.assertNotNull(result.getQualitativeValue());
+ Assert.assertEquals(nbValues, result.sizeQualitativeValue());
+ }
+
+ protected void assertCaracteristicSize(Caracteristic incoming,
+ Caracteristic caracteristic) {
+ Assert.assertNotNull(incoming);
+ Assert.assertNotNull(caracteristic);
+ Assert.assertEquals(incoming, caracteristic);
+ Assert.assertEquals(incoming.getCaracteristicType(),
+ caracteristic.getCaracteristicType());
+ Assert.assertEquals(incoming.sizeQualitativeValue(),
+ caracteristic.sizeQualitativeValue());
+ }
+
+ protected <E extends IdAware> void assertResultList(List<E> result,
+ int expectedsize) {
+
+ // result not null
+ Assert.assertNotNull(result);
+
+ // id are unique
+ TuttiEntities.splitById(result);
+
+ // correct size
+ Assert.assertEquals(expectedsize, result.size());
+ }
+}
Deleted: 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-09 07:44:17 UTC (rev 378)
+++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceServiceTest.java 2013-02-10 13:41:29 UTC (rev 379)
@@ -1,645 +0,0 @@
-package fr.ifremer.tutti.persistence.service;
-
-/*
- * #%L
- * Tutti :: Persistence API
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2012 - 2013 Ifremer
- * %%
- * 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%
- */
-
-import com.google.common.base.Preconditions;
-import com.google.common.collect.Lists;
-import fr.ifremer.adagio.core.service.technical.CacheService;
-import fr.ifremer.tutti.persistence.DatabaseFixtures;
-import fr.ifremer.tutti.persistence.DatabaseResource;
-import fr.ifremer.tutti.persistence.TuttiPersistenceDevImpl;
-import fr.ifremer.tutti.persistence.entities.IdAware;
-import fr.ifremer.tutti.persistence.entities.TuttiEntities;
-import fr.ifremer.tutti.persistence.entities.referential.Caracteristic;
-import fr.ifremer.tutti.persistence.entities.referential.Country;
-import fr.ifremer.tutti.persistence.entities.referential.FishingOperationLocation;
-import fr.ifremer.tutti.persistence.entities.referential.Gear;
-import fr.ifremer.tutti.persistence.entities.referential.Person;
-import fr.ifremer.tutti.persistence.entities.referential.Species;
-import fr.ifremer.tutti.persistence.entities.referential.Vessel;
-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;
-import org.junit.BeforeClass;
-import org.junit.ClassRule;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.nuiton.util.ApplicationConfig;
-
-import java.io.IOException;
-import java.util.List;
-
-import static fr.ifremer.tutti.persistence.TuttiPersistenceDevImpl.CaracteristicEnum;
-
-/**
- * @author tchemit <chemit(a)codelutin.com>
- * @since 0.3
- */
-public class ReferentialPersistenceServiceTest {
-
- @ClassRule
- public static final DatabaseResource dbResource = new DatabaseResource();
-
- /** Logger. */
- private static final Log log =
- LogFactory.getLog(ReferentialPersistenceServiceTest.class);
-
- protected static TuttiPersistenceDevImpl storage;
-
- protected ReferentialPersistenceService service;
-
- protected CacheService cacheService;
-
- protected DatabaseFixtures fixtures;
-
- @BeforeClass
- public static void beforeClass() throws IOException {
-
- // create a storage
-
- ApplicationConfig applicationConfig = dbResource.getConfig().getConfig();
-
- applicationConfig.setOption(
- TuttiPersistenceDevImpl.SKIP_FIXTURES_OPTION, Boolean.TRUE.toString());
-
- storage = new TuttiPersistenceDevImpl(applicationConfig) {
-
- @Override
- public <B extends IdAware> B create(String type,
- B bean,
- boolean sychronize) {
- Preconditions.checkNotNull(bean, "Can't persist a null bean");
- B result = TuttiEntities.newEntity(bean);
- result.setId(bean.getId());
- if (log.isDebugEnabled()) {
- log.debug("Will persist [" + type + ":" + bean.getId() + "]");
- }
- super.persist(type, bean, result, sychronize);
- return result;
- }
- };
-
- if (log.isInfoEnabled()) {
- log.info("Will init persistence driver " + storage.getImplementationName());
- }
-
- storage.init();
- }
-
- @AfterClass
- public static void afterClass() throws IOException {
- storage.close();
- }
-
- @Before
- public void setUp() throws Exception {
- service = TuttiPersistenceServiceLocator.getReferentialPersistenceService();
- cacheService = TuttiPersistenceServiceLocator.instance().getCacheService();
-
- // This is need for test : getAllFishingVessel()
-// cacheService.clearAllCaches();
- fixtures = dbResource.getFixtures();
- }
-
- @Test
- public void getAllProgramZone() {
- List<Zone> result = service.getAllProgramZone();
- assertResultList(result, fixtures.refNbProgramZone());
-
- persistList(Zone.class, result);
- assertSize(result, storage.getAllProgramZone());
- }
-
- @Test
- public void getAllCountry() {
- List<Country> result = service.getAllCountry();
- assertResultList(result, fixtures.refNbCountry());
-
- persistList(Country.class, result);
- assertSize(result, storage.getAllCountry());
- }
-
- @Test
- public void getAllFishingOperationStrata(/*String zoneId*/) {
- String zoneId = dbResource.getFixtures().zoneId();
- List<FishingOperationLocation> result =
- service.getAllFishingOperationStrata(zoneId);
- assertResultList(result, fixtures.refNbStrata());
-
- persistList(FishingOperationLocation.class, "Strata", result);
- assertSize(result, storage.getAllFishingOperationStrata(zoneId));
- }
-
- @Test
- public void getAllFishingOperationSubStrata(/*String zoneId, String strataId*/) {
- String zoneId = dbResource.getFixtures().zoneId();
- List<FishingOperationLocation> result =
- service.getAllFishingOperationSubStrata(zoneId, null);
- assertResultList(result, 0);
-
- persistList(FishingOperationLocation.class, "SubStrata", result);
- assertSize(result, storage.getAllFishingOperationSubStrata(zoneId, null));
-
- // try with a strataId
- String strataId = dbResource.getFixtures().strataId();
- result = service.getAllFishingOperationLocation(zoneId, strataId, null);
- assertResultList(result, 1);
- }
-
- @Test
- public void getAllFishingOperationLocation(/*String zoneId, String strataId, String subStrataId*/) {
- String zoneId = dbResource.getFixtures().zoneId();
- List<FishingOperationLocation> result =
- service.getAllFishingOperationLocation(zoneId, null, null);
- assertResultList(result, fixtures.refNbLocalite());
-
- persistList(FishingOperationLocation.class, "Localite", result);
- assertSize(result, storage.getAllFishingOperationLocation(zoneId, null, null));
-
- // try with a strataId
- String strataId = dbResource.getFixtures().strataId();
- result = service.getAllFishingOperationLocation(zoneId, strataId, null);
- assertResultList(result, 1);
-
- // try with a subStrataId
- String subStrataId = dbResource.getFixtures().subStrataId();
- result = service.getAllFishingOperationLocation(zoneId, strataId, subStrataId);
- assertResultList(result, 3);
- }
-
- @Test
- public void getAllScientificVessel() {
- List<Vessel> result = service.getAllScientificVessel();
- assertResultList(result, fixtures.refNbScientificVessel());
- persistList(Vessel.class, "Scientific", result);
- assertSize(result, storage.getAllScientificVessel());
- }
-
- @Test
- public void getAllFishingVessel() {
-
- // clear cache before this test
- cacheService.clearCache("fishingVessels");
-
- long time = System.currentTimeMillis();
- List<Vessel> result = service.getAllFishingVessel();
- long delta1 = System.currentTimeMillis() - time;
-
- assertResultList(result, fixtures.refNbFishingVessel());
-
- // try again, to check cache is enable
- time = System.currentTimeMillis();
- result = service.getAllFishingVessel();
- assertResultList(result, fixtures.refNbFishingVessel());
-
- long delta2 = System.currentTimeMillis() - time;
-
- //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);
-
- persistList(Vessel.class, "Fishing", result);
- assertSize(result, storage.getAllFishingVessel());
- }
-
- @Test
- public void getAllScientificGear() {
- List<Gear> result = service.getAllScientificGear();
- assertResultList(result, fixtures.refNbScientificGear());
-
- persistList(Gear.class, "Scientific", result);
- assertSize(result, storage.getAllScientificGear());
- }
-
- @Test
- public void getAllFishingGear() {
- List<Gear> result = service.getAllFishingGear();
- assertResultList(result, fixtures.refNbFishingGear());
-
- persistList(Gear.class, "Fishing", result);
- assertSize(result, storage.getAllFishingGear());
- }
-
- @Test
- public void getAllPerson() {
- List<Person> result = service.getAllPerson();
- assertResultList(result, fixtures.refNbPerson());
-
- persistList(Person.class, result);
- assertSize(result, storage.getAllPerson());
- }
-
- @Test
- public void getAllSpecies() {
- List<Species> result = service.getAllSpecies();
- assertResultList(result, fixtures.refNbSpecies());
-
- persistList(Species.class, result);
- assertSize(result, storage.getAllSpecies());
- }
-
- @Test
- public void getAllReferentSpecies() {
- List<Species> result = service.getAllReferentSpecies();
- assertResultList(result, fixtures.refNbReferentSpecies());
-
- TuttiEntities.splitByTaxonId(result);
- }
-
- @Test
- public void getSpeciesByReferenceTaxonId(/*String speciesReferenceTaxonId*/) {
- String speciesId = fixtures.refSpeciesId();
- Integer taxonId = fixtures.refSpeciesTaxonId();
- Species species = service.getSpeciesByReferenceTaxonId(taxonId);
- Assert.assertNotNull(species);
- Assert.assertEquals(speciesId, species.getId());
- 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();
- assertResultList(result, fixtures.refNbCaracteristic());
-
- persistList(Caracteristic.class, CaracteristicEnum.All.name(), result);
- assertSize(result, storage.getAllCaracteristic());
- }
-
- @Test
- public void getSizeCategoryCaracteristic() {
- Caracteristic result = service.getSizeCategoryCaracteristic();
- assertCaracteristicQualitative(result, 6);
- persist(Caracteristic.class, CaracteristicEnum.SizeCategory.name(), result);
- }
-
- @Test
- public void getSexCaracteristic() {
- Caracteristic result = service.getSexCaracteristic();
- assertCaracteristicQualitative(result, 4);
- persist(Caracteristic.class, CaracteristicEnum.SexCategory.name(), result);
- }
-
- @Test
- public void getSortedUnsortedCaracteristic() {
- Caracteristic result = service.getSortedUnsortedCaracteristic();
- assertCaracteristicQualitative(result, 2);
- persist(Caracteristic.class, CaracteristicEnum.SortedUnsortedCategory.name(), result);
- }
-
- @Test
- public void getMaturityCaracteristic() {
- Caracteristic result = service.getMaturityCaracteristic();
- assertCaracteristicQualitative(result, 6);
- persist(Caracteristic.class, CaracteristicEnum.MaturityCategory.name(), result);
- }
-
- @Test
- public void getMacroWasteCategoryCaracteristic() {
- Caracteristic result = service.getMacroWasteCategoryCaracteristic();
- assertCaracteristicQualitative(result, 21);
- persist(Caracteristic.class, CaracteristicEnum.MacroWasteCategory.name(), result);
- }
-
- @Test
- public void getMacroWasteSizeCategoryCaracteristic() {
- Caracteristic result = service.getMacroWasteSizeCategoryCaracteristic();
- assertCaracteristicQualitative(result, 6);
- persist(Caracteristic.class, CaracteristicEnum.MacroWasteSizeCategory.name(), result);
- }
-
- @Test
- public void importSpecies() {
- List<Species> species = Lists.newArrayList();
-
- long timestamp1 = System.nanoTime();
- Species sp1 = new Species();
- sp1.setReferenceTaxonId((int) timestamp1);
- sp1.setId("Don't care" + timestamp1);
- sp1.setRefTaxCode("Don't care" + timestamp1);
- sp1.setSurveyCode("Don't care" + timestamp1);
- sp1.setName("Genus name" + timestamp1);
- species.add(sp1);
-
- long timestamp2 = System.nanoTime();
- Species sp2 = new Species();
- sp2.setReferenceTaxonId((int) timestamp2);
- sp2.setId("Don't care" + timestamp2);
- sp2.setRefTaxCode("Don't care" + timestamp2);
- sp2.setSurveyCode("Don't care" + timestamp2);
- sp2.setName("Genus name" + timestamp2);
- species.add(sp2);
-
- Assert.assertNull(service.getSpeciesByReferenceTaxonId(sp1.getReferenceTaxonId()));
- //Assert.assertNull(service.getSpecies(sp2.getId()));
-
- List<Species> speciesList = service.importTemporarySpecies(species);
- Assert.assertNotNull(speciesList);
- Assert.assertEquals(2, speciesList.size());
-
- Species createdSp1 = speciesList.get(0);
- Assert.assertNotNull(createdSp1);
- Assert.assertEquals(sp1.getName(), createdSp1.getName());
- // TODO TC :question pour TC pourquoi faire le test suivant NotNull, car tu n'a rien mis en entr�e de ce code ?
- // faut-il que le genere ?
- //Assert.assertNotNull(createdSp1.getRefTaxCode());
- //Assert.assertNotSame(sp1.getRefTaxCode(), createdSp1.getRefTaxCode());
- Assert.assertNull(createdSp1.getSurveyCode());
- Assert.assertNotNull(createdSp1.getId());
- Assert.assertNotSame(sp1.getId(), createdSp1.getId());
- Assert.assertEquals(createdSp1, service.getSpeciesByReferenceTaxonId(createdSp1.getReferenceTaxonId()));
-
- Species createdSp2 = speciesList.get(1);
- Assert.assertNotNull(createdSp2);
- Assert.assertEquals(sp2.getName(), createdSp2.getName());
- Assert.assertTrue(createdSp2.isReferenceTaxon());
- Assert.assertNotSame(sp2.getReferenceTaxonId(), createdSp2.getReferenceTaxonId());
- Assert.assertNull(createdSp2.getRefTaxCode());
- Assert.assertNull(createdSp2.getSurveyCode());
- Assert.assertNotNull(createdSp2.getId());
- Assert.assertNotSame(sp2.getId(), createdSp2.getId());
- Assert.assertEquals(createdSp2, service.getSpeciesByReferenceTaxonId(createdSp2.getReferenceTaxonId()));
- }
-
- @Test
- public void importVessel() {
- List<Vessel> vessels = Lists.newArrayList();
-
- // scientificVessel
- long timestamp1 = System.nanoTime();
- Vessel v1 = new Vessel();
- v1.setId("Don't care" + timestamp1);
- v1.setName("Name" + timestamp1);
- v1.setInternationalRegistrationCode("Immat" + timestamp1);
- v1.setScientificVessel(true);
- vessels.add(v1);
-
- // fishingVessel
- long timestamp2 = System.nanoTime();
- Vessel v2 = new Vessel();
- v2.setId("Don't care" + timestamp2);
- v2.setName("Name" + timestamp2);
- v2.setInternationalRegistrationCode("Immat" + timestamp2);
- v2.setScientificVessel(false);
- vessels.add(v2);
-
- Assert.assertNull(service.getVessel(v1.getId()));
- Assert.assertNull(service.getVessel(v2.getId()));
-
- List<Vessel> vesselList = service.importTemporaryVessel(vessels);
-
- Assert.assertNotNull(vesselList);
- Assert.assertEquals(2, vesselList.size());
-
- List<Vessel> allScientificVessel = service.getAllScientificVessel();
- List<Vessel> allFishingVessel = service.getAllFishingVessel();
-
- Vessel createdV1 = vesselList.get(0);
- Assert.assertNotNull(createdV1);
- Assert.assertEquals(v1.getName(), createdV1.getName());
- Assert.assertEquals(v1.getInternationalRegistrationCode(), createdV1.getInternationalRegistrationCode());
- Assert.assertNotNull(createdV1.getId());
- Assert.assertNotSame(v1.getId(), createdV1.getId());
- Assert.assertEquals(createdV1, service.getVessel(createdV1.getId()));
-
- Assert.assertTrue(allScientificVessel.contains(createdV1));
- Assert.assertFalse(allFishingVessel.contains(createdV1));
-
- Vessel createdV2 = vesselList.get(1);
- Assert.assertNotNull(createdV2);
- Assert.assertEquals(v2.getName(), createdV2.getName());
- Assert.assertEquals(v2.getInternationalRegistrationCode(), createdV2.getInternationalRegistrationCode());
- Assert.assertNotNull(createdV2.getId());
- Assert.assertNotSame(v2.getId(), createdV2.getId());
- Assert.assertEquals(createdV2, service.getVessel(createdV2.getId()));
- Assert.assertFalse(allScientificVessel.contains(createdV2));
- Assert.assertTrue(allFishingVessel.contains(createdV2));
- }
-
- @Test
- public void importPerson() {
- List<Person> persons = Lists.newArrayList();
-
- long timestamp1 = System.nanoTime();
- Person p1 = new Person();
- p1.setId("Don't care" + timestamp1);
- p1.setName("Don't care" + timestamp1);
- p1.setFirstName("FirstName" + timestamp1);
- p1.setLastName("MastName" + timestamp1);
- p1.setDescription("Dont care" + timestamp1);
- p1.setDescription("Dont care" + timestamp1);
- persons.add(p1);
-
- long timestamp2 = System.nanoTime();
- Person p2 = new Person();
- p2.setId("Don't care" + timestamp2);
- p2.setName("Don't care" + timestamp2);
- p2.setFirstName("FirstName" + timestamp2);
- p2.setLastName("LastName" + timestamp2);
- p2.setDescription("Don't care" + timestamp2);
- p2.setDepartment("Don't care" + timestamp2);
- persons.add(p2);
-
- List<Person> personList = service.importTemporaryPerson(persons);
-
- Assert.assertNotNull(personList);
- Assert.assertEquals(2, personList.size());
-
- Person createdP1 = personList.get(0);
- Assert.assertNotNull(createdP1);
- Assert.assertEquals(p1.getFirstName(), createdP1.getFirstName());
- Assert.assertEquals(p1.getLastName(), createdP1.getLastName());
-
- Assert.assertNull(createdP1.getName());
- Assert.assertNull(createdP1.getDepartment());
- Assert.assertNull(createdP1.getDescription());
-
- Assert.assertNotNull(createdP1.getId());
- Assert.assertNotSame(p1.getId(), createdP1.getId());
-
- Assert.assertEquals(createdP1, service.getPerson(Integer.valueOf(createdP1.getId())));
-
-
- Person createdP2 = personList.get(1);
- Assert.assertNotNull(createdP2);
- Assert.assertEquals(p2.getFirstName(), createdP2.getFirstName());
- Assert.assertEquals(p2.getLastName(), createdP2.getLastName());
-
- Assert.assertNull(createdP1.getName());
- Assert.assertNull(createdP1.getDepartment());
- Assert.assertNull(createdP1.getDescription());
-
- Assert.assertNotNull(createdP2.getId());
- Assert.assertNotSame(p2.getId(), createdP2.getId());
-
- Assert.assertEquals(createdP2, service.getPerson(Integer.valueOf(createdP2.getId())));
- }
-
- @Test
- public void importGear() {
- List<Gear> gears = Lists.newArrayList();
-
- // scientific gear
- long timestamp1 = System.nanoTime();
- Gear g1 = new Gear();
- g1.setId("Don't care" + timestamp1);
- g1.setDescription("Don't care" + timestamp1);
- g1.setName("Name" + timestamp1);
- g1.setLabel("Label" + timestamp1);
- g1.setScientificGear(true);
- gears.add(g1);
-
- // fishing gear
- long timestamp2 = System.nanoTime();
- Gear g2 = new Gear();
- g2.setId("Don't care" + timestamp2);
- g2.setDescription("Don't care" + timestamp2);
- g2.setName("Name" + timestamp2);
- g2.setLabel("Label" + timestamp2);
- g2.setScientificGear(false);
-
- gears.add(g2);
-
- List<Gear> gearList = service.importTemporaryGear(gears);
-
- List<Gear> allScientificGear = service.getAllScientificGear();
- List<Gear> allFishingGear = service.getAllFishingGear();
-
- Gear createdG1 = gearList.get(0);
- Assert.assertNotNull(createdG1);
- Assert.assertEquals(g1.getName(), createdG1.getName());
- Assert.assertEquals(g1.getLabel(), createdG1.getLabel());
-
- Assert.assertNotNull(createdG1.getId());
- Assert.assertNotSame(g1.getId(), createdG1.getId());
- Assert.assertEquals(createdG1, service.getGear(Integer.valueOf(createdG1.getId())));
- Assert.assertTrue(allScientificGear.contains(createdG1));
- Assert.assertFalse(allFishingGear.contains(createdG1));
-
- Gear createdG2 = gearList.get(1);
- Assert.assertNotNull(createdG2);
- Assert.assertEquals(g2.getName(), createdG2.getName());
- Assert.assertEquals(g2.getLabel(), createdG2.getLabel());
-
- Assert.assertNotNull(createdG2.getId());
- Assert.assertNotSame(g2.getId(), createdG2.getId());
- Assert.assertEquals(createdG2, service.getGear(Integer.valueOf(createdG2.getId())));
- Assert.assertFalse(allScientificGear.contains(createdG2));
- Assert.assertTrue(allFishingGear.contains(createdG2));
- }
-
- @Test
- @Ignore
- public void testCaches() {
- cacheService.clearAllCaches();
-
- Object obj = service.getAllCaracteristic();
- System.out.println(obj);
-
- obj = service.getCaracteristic(1429);
- System.out.println(obj);
-
- obj = service.getCaracteristic(1428);
- System.out.println(obj);
- }
-
- protected <S extends IdAware> void persistList(Class<S> type, List<S> result) {
- persistList(type, null, result);
- }
-
- protected <S extends IdAware> void persistList(Class<S> type, String context, List<S> result) {
-
- String key = TuttiPersistenceDevImpl.getKey(type, context);
- for (S s : result) {
- storage.create(key, s, false);
- }
- storage.persistToFile(key);
- }
-
- protected <S extends IdAware> void persist(Class<S> type, S result) {
- persist(type, null, result);
- }
-
- protected <S extends IdAware> void persist(Class<S> type, String context, S result) {
- String key = TuttiPersistenceDevImpl.getKey(type, context);
- storage.create(key, result, true);
- }
-
- protected void assertSize(List<?> expectedList, List<?> storageList) {
- Assert.assertNotNull(expectedList);
- Assert.assertNotNull(storageList);
- expectedList.removeAll(storageList);
- Assert.assertTrue("Some " + expectedList.size() + " entities were not persisted in storage :" +
- expectedList, expectedList.isEmpty());
-
- }
-
- protected void assertCaracteristicQualitative(Caracteristic result, int nbValues) {
- Assert.assertNotNull(result);
- Assert.assertNotNull(result.getCaracteristicType());
- Assert.assertTrue(TuttiEntities.isQualitativeCaracteristic(result));
- Assert.assertNotNull(result.getQualitativeValue());
- Assert.assertEquals(nbValues, result.sizeQualitativeValue());
- }
-
- protected void assertCaracteristicSize(Caracteristic incoming,
- Caracteristic caracteristic) {
- Assert.assertNotNull(incoming);
- Assert.assertNotNull(caracteristic);
- Assert.assertEquals(incoming, caracteristic);
- Assert.assertEquals(incoming.getCaracteristicType(),
- caracteristic.getCaracteristicType());
- Assert.assertEquals(incoming.sizeQualitativeValue(),
- caracteristic.sizeQualitativeValue());
- }
-
- protected <E extends IdAware> void assertResultList(List<E> result,
- int expectedsize) {
-
- // result not null
- Assert.assertNotNull(result);
-
- // id are unique
- TuttiEntities.splitById(result);
-
- // correct size
- Assert.assertEquals(expectedsize, result.size());
- }
-}
Copied: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceServiceWriteTest.java (from rev 378, trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceServiceTest.java)
===================================================================
--- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceServiceWriteTest.java (rev 0)
+++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceServiceWriteTest.java 2013-02-10 13:41:29 UTC (rev 379)
@@ -0,0 +1,277 @@
+package fr.ifremer.tutti.persistence.service;
+
+/*
+ * #%L
+ * Tutti :: Persistence API
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2012 - 2013 Ifremer
+ * %%
+ * 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%
+ */
+
+import com.google.common.collect.Lists;
+import fr.ifremer.tutti.persistence.DatabaseResource;
+import fr.ifremer.tutti.persistence.entities.referential.Gear;
+import fr.ifremer.tutti.persistence.entities.referential.Person;
+import fr.ifremer.tutti.persistence.entities.referential.Species;
+import fr.ifremer.tutti.persistence.entities.referential.Vessel;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Test;
+
+import java.util.List;
+
+/**
+ * To test {@link ReferentialPersistenceService} for write operation.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.0
+ */
+public class ReferentialPersistenceServiceWriteTest {
+
+ @ClassRule
+ public static final DatabaseResource dbResource = DatabaseResource.writeDb();
+
+ protected ReferentialPersistenceService service;
+
+ @Before
+ public void setUp() throws Exception {
+ service = TuttiPersistenceServiceLocator.getReferentialPersistenceService();
+ }
+
+ @Test
+ public void importSpecies() {
+ List<Species> species = Lists.newArrayList();
+
+ long timestamp1 = System.nanoTime();
+ Species sp1 = new Species();
+ sp1.setReferenceTaxonId((int) timestamp1);
+ sp1.setId("Don't care" + timestamp1);
+ sp1.setRefTaxCode("Don't care" + timestamp1);
+ sp1.setSurveyCode("Don't care" + timestamp1);
+ sp1.setName("Genus name" + timestamp1);
+ species.add(sp1);
+
+ long timestamp2 = System.nanoTime();
+ Species sp2 = new Species();
+ sp2.setReferenceTaxonId((int) timestamp2);
+ sp2.setId("Don't care" + timestamp2);
+ sp2.setRefTaxCode("Don't care" + timestamp2);
+ sp2.setSurveyCode("Don't care" + timestamp2);
+ sp2.setName("Genus name" + timestamp2);
+ species.add(sp2);
+
+ Assert.assertNull(service.getSpeciesByReferenceTaxonId(sp1.getReferenceTaxonId()));
+ //Assert.assertNull(service.getSpecies(sp2.getId()));
+
+ List<Species> speciesList = service.importTemporarySpecies(species);
+ Assert.assertNotNull(speciesList);
+ Assert.assertEquals(2, speciesList.size());
+
+ Species createdSp1 = speciesList.get(0);
+ Assert.assertNotNull(createdSp1);
+ Assert.assertEquals(sp1.getName(), createdSp1.getName());
+ // TODO TC :question pour TC pourquoi faire le test suivant NotNull, car tu n'a rien mis en entree de ce code ?
+ // faut-il que le genere ?
+ //Assert.assertNotNull(createdSp1.getRefTaxCode());
+ //Assert.assertNotSame(sp1.getRefTaxCode(), createdSp1.getRefTaxCode());
+ Assert.assertNull(createdSp1.getSurveyCode());
+ Assert.assertNotNull(createdSp1.getId());
+ Assert.assertNotSame(sp1.getId(), createdSp1.getId());
+ Assert.assertEquals(createdSp1, service.getSpeciesByReferenceTaxonId(createdSp1.getReferenceTaxonId()));
+
+ Species createdSp2 = speciesList.get(1);
+ Assert.assertNotNull(createdSp2);
+ Assert.assertEquals(sp2.getName(), createdSp2.getName());
+ Assert.assertTrue(createdSp2.isReferenceTaxon());
+ Assert.assertNotSame(sp2.getReferenceTaxonId(), createdSp2.getReferenceTaxonId());
+ Assert.assertNull(createdSp2.getRefTaxCode());
+ Assert.assertNull(createdSp2.getSurveyCode());
+ Assert.assertNotNull(createdSp2.getId());
+ Assert.assertNotSame(sp2.getId(), createdSp2.getId());
+ Assert.assertEquals(createdSp2, service.getSpeciesByReferenceTaxonId(createdSp2.getReferenceTaxonId()));
+ }
+
+ @Test
+ public void importVessel() {
+ List<Vessel> vessels = Lists.newArrayList();
+
+ // scientificVessel
+ long timestamp1 = System.nanoTime();
+ Vessel v1 = new Vessel();
+ v1.setId("Don't care" + timestamp1);
+ v1.setName("Name" + timestamp1);
+ v1.setInternationalRegistrationCode("Immat" + timestamp1);
+ v1.setScientificVessel(true);
+ vessels.add(v1);
+
+ // fishingVessel
+ long timestamp2 = System.nanoTime();
+ Vessel v2 = new Vessel();
+ v2.setId("Don't care" + timestamp2);
+ v2.setName("Name" + timestamp2);
+ v2.setInternationalRegistrationCode("Immat" + timestamp2);
+ v2.setScientificVessel(false);
+ vessels.add(v2);
+
+ Assert.assertNull(service.getVessel(v1.getId()));
+ Assert.assertNull(service.getVessel(v2.getId()));
+
+ List<Vessel> vesselList = service.importTemporaryVessel(vessels);
+
+ Assert.assertNotNull(vesselList);
+ Assert.assertEquals(2, vesselList.size());
+
+ List<Vessel> allScientificVessel = service.getAllScientificVessel();
+ List<Vessel> allFishingVessel = service.getAllFishingVessel();
+
+ Vessel createdV1 = vesselList.get(0);
+ Assert.assertNotNull(createdV1);
+ Assert.assertEquals(v1.getName(), createdV1.getName());
+ Assert.assertEquals(v1.getInternationalRegistrationCode(), createdV1.getInternationalRegistrationCode());
+ Assert.assertNotNull(createdV1.getId());
+ Assert.assertNotSame(v1.getId(), createdV1.getId());
+ Assert.assertEquals(createdV1, service.getVessel(createdV1.getId()));
+
+ Assert.assertTrue(allScientificVessel.contains(createdV1));
+ Assert.assertFalse(allFishingVessel.contains(createdV1));
+
+ Vessel createdV2 = vesselList.get(1);
+ Assert.assertNotNull(createdV2);
+ Assert.assertEquals(v2.getName(), createdV2.getName());
+ Assert.assertEquals(v2.getInternationalRegistrationCode(), createdV2.getInternationalRegistrationCode());
+ Assert.assertNotNull(createdV2.getId());
+ Assert.assertNotSame(v2.getId(), createdV2.getId());
+ Assert.assertEquals(createdV2, service.getVessel(createdV2.getId()));
+ Assert.assertFalse(allScientificVessel.contains(createdV2));
+ Assert.assertTrue(allFishingVessel.contains(createdV2));
+ }
+
+ @Test
+ public void importPerson() {
+ List<Person> persons = Lists.newArrayList();
+
+ long timestamp1 = System.nanoTime();
+ Person p1 = new Person();
+ p1.setId("Don't care" + timestamp1);
+ p1.setName("Don't care" + timestamp1);
+ p1.setFirstName("FirstName" + timestamp1);
+ p1.setLastName("MastName" + timestamp1);
+ p1.setDescription("Dont care" + timestamp1);
+ p1.setDescription("Dont care" + timestamp1);
+ persons.add(p1);
+
+ long timestamp2 = System.nanoTime();
+ Person p2 = new Person();
+ p2.setId("Don't care" + timestamp2);
+ p2.setName("Don't care" + timestamp2);
+ p2.setFirstName("FirstName" + timestamp2);
+ p2.setLastName("LastName" + timestamp2);
+ p2.setDescription("Don't care" + timestamp2);
+ p2.setDepartment("Don't care" + timestamp2);
+ persons.add(p2);
+
+ List<Person> personList = service.importTemporaryPerson(persons);
+
+ Assert.assertNotNull(personList);
+ Assert.assertEquals(2, personList.size());
+
+ Person createdP1 = personList.get(0);
+ Assert.assertNotNull(createdP1);
+ Assert.assertEquals(p1.getFirstName(), createdP1.getFirstName());
+ Assert.assertEquals(p1.getLastName(), createdP1.getLastName());
+
+ Assert.assertNull(createdP1.getName());
+ Assert.assertNull(createdP1.getDepartment());
+ Assert.assertNull(createdP1.getDescription());
+
+ Assert.assertNotNull(createdP1.getId());
+ Assert.assertNotSame(p1.getId(), createdP1.getId());
+
+ Assert.assertEquals(createdP1, service.getPerson(Integer.valueOf(createdP1.getId())));
+
+
+ Person createdP2 = personList.get(1);
+ Assert.assertNotNull(createdP2);
+ Assert.assertEquals(p2.getFirstName(), createdP2.getFirstName());
+ Assert.assertEquals(p2.getLastName(), createdP2.getLastName());
+
+ Assert.assertNull(createdP1.getName());
+ Assert.assertNull(createdP1.getDepartment());
+ Assert.assertNull(createdP1.getDescription());
+
+ Assert.assertNotNull(createdP2.getId());
+ Assert.assertNotSame(p2.getId(), createdP2.getId());
+
+ Assert.assertEquals(createdP2, service.getPerson(Integer.valueOf(createdP2.getId())));
+ }
+
+ @Test
+ public void importGear() {
+ List<Gear> gears = Lists.newArrayList();
+
+ // scientific gear
+ long timestamp1 = System.nanoTime();
+ Gear g1 = new Gear();
+ g1.setId("Don't care" + timestamp1);
+ g1.setDescription("Don't care" + timestamp1);
+ g1.setName("Name" + timestamp1);
+ g1.setLabel("Label" + timestamp1);
+ g1.setScientificGear(true);
+ gears.add(g1);
+
+ // fishing gear
+ long timestamp2 = System.nanoTime();
+ Gear g2 = new Gear();
+ g2.setId("Don't care" + timestamp2);
+ g2.setDescription("Don't care" + timestamp2);
+ g2.setName("Name" + timestamp2);
+ g2.setLabel("Label" + timestamp2);
+ g2.setScientificGear(false);
+
+ gears.add(g2);
+
+ List<Gear> gearList = service.importTemporaryGear(gears);
+
+ List<Gear> allScientificGear = service.getAllScientificGear();
+ List<Gear> allFishingGear = service.getAllFishingGear();
+
+ Gear createdG1 = gearList.get(0);
+ Assert.assertNotNull(createdG1);
+ Assert.assertEquals(g1.getName(), createdG1.getName());
+ Assert.assertEquals(g1.getLabel(), createdG1.getLabel());
+
+ Assert.assertNotNull(createdG1.getId());
+ Assert.assertNotSame(g1.getId(), createdG1.getId());
+ Assert.assertEquals(createdG1, service.getGear(Integer.valueOf(createdG1.getId())));
+ Assert.assertTrue(allScientificGear.contains(createdG1));
+ Assert.assertFalse(allFishingGear.contains(createdG1));
+
+ Gear createdG2 = gearList.get(1);
+ Assert.assertNotNull(createdG2);
+ Assert.assertEquals(g2.getName(), createdG2.getName());
+ Assert.assertEquals(g2.getLabel(), createdG2.getLabel());
+
+ Assert.assertNotNull(createdG2.getId());
+ Assert.assertNotSame(g2.getId(), createdG2.getId());
+ Assert.assertEquals(createdG2, service.getGear(Integer.valueOf(createdG2.getId())));
+ Assert.assertFalse(allScientificGear.contains(createdG2));
+ Assert.assertTrue(allFishingGear.contains(createdG2));
+ }
+}
Copied: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceReadTest.java (from rev 378, trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceTest.java)
===================================================================
--- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceReadTest.java (rev 0)
+++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceReadTest.java 2013-02-10 13:41:29 UTC (rev 379)
@@ -0,0 +1,159 @@
+package fr.ifremer.tutti.persistence.service;
+
+/*
+ * #%L
+ * Tutti :: Persistence API
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2012 - 2013 Ifremer
+ * %%
+ * 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%
+ */
+
+import com.google.common.collect.Maps;
+import fr.ifremer.tutti.persistence.DatabaseResource;
+import fr.ifremer.tutti.persistence.entities.data.SampleCategoryEnum;
+import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch;
+import fr.ifremer.tutti.persistence.entities.data.SpeciesBatchFrequency;
+import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativeValue;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import java.util.List;
+import java.util.Map;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+
+/**
+ * To test {@link SpeciesBatchPersistenceService} for read operation.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 0.3
+ */
+@Ignore
+public class SpeciesBatchPersistenceServiceReadTest {
+
+ @ClassRule
+ public static final DatabaseResource dbResource = DatabaseResource.readDb();
+
+ protected SpeciesBatchPersistenceService service;
+
+ @Before
+ public void setUp() throws Exception {
+ service = TuttiPersistenceServiceLocator.getSpeciesBatchPersistenceService();
+ }
+
+ @Test
+ public void getAllRootSpeciesBatch(/*String fishingOperationId*/) {
+ }
+
+ @Test
+ public void getAllSpeciesBatchFrequency(/*String speciesBatchId*/) {
+
+ }
+
+ protected void assertSpeciesBatch(SpeciesBatch expectedBatch, SpeciesBatch actualBatch, boolean assertIdEquals) {
+ assertNotNull(actualBatch);
+ assertNotNull(actualBatch.getId());
+ if (assertIdEquals && expectedBatch.getId() != null) {
+ assertEquals(expectedBatch.getId(), actualBatch.getId());
+ }
+ assertEquals(expectedBatch.getWeight(), actualBatch.getWeight());
+ assertEquals(expectedBatch.getSampleCategoryType(), actualBatch.getSampleCategoryType());
+ if (expectedBatch.getSampleCategoryValue() != null && expectedBatch.getSampleCategoryValue() instanceof CaracteristicQualitativeValue) {
+ assertNotNull("Bad sampleCategoryValue : expected <" + ((CaracteristicQualitativeValue) expectedBatch.getSampleCategoryValue()).getId() + "> but was <null>",
+ actualBatch.getSampleCategoryValue());
+ assertEquals(
+ ((CaracteristicQualitativeValue) expectedBatch.getSampleCategoryValue()).getId(),
+ ((CaracteristicQualitativeValue) actualBatch.getSampleCategoryValue()).getId());
+ } else {
+ assertEquals(expectedBatch.getSampleCategoryValue(), actualBatch.getSampleCategoryValue());
+ }
+ assertEquals(expectedBatch.getSampleCategoryWeight(), actualBatch.getSampleCategoryWeight());
+ assertEquals(expectedBatch.getNumber(), actualBatch.getNumber());
+ assertEquals(expectedBatch.getComment(), actualBatch.getComment());
+
+ // Check species only if Vrac/HorsVrac or if batch has been load throw getAllxxx method
+ // (Because getSpeciesBatch(id) could not always retrieve the species)
+ if (expectedBatch.getSpecies() != null && (
+ expectedBatch.getSampleCategoryType() == SampleCategoryEnum.sortedUnsorted
+ || actualBatch.getSpecies() != null)) {
+ assertNotNull(actualBatch.getSpecies());
+ assertEquals(expectedBatch.getSpecies().getId(), actualBatch.getSpecies().getId());
+ }
+ }
+
+ protected void assertBatchFrequencies(List<SpeciesBatchFrequency> expectedFrequencies, List<SpeciesBatchFrequency> actualFrequencies, boolean assertIdEquals) {
+ assertNotNull(actualFrequencies);
+ assertEquals(expectedFrequencies.size(), actualFrequencies.size());
+
+ // Store actual batches into a map, using the length as key
+ Map<Float, SpeciesBatchFrequency> expectedLengthMap = Maps.newHashMap();
+ for (SpeciesBatchFrequency speciesBatchFrequency : expectedFrequencies) {
+ expectedLengthMap.put(speciesBatchFrequency.getLengthStep(), speciesBatchFrequency);
+ }
+
+ // Store expected batches into a map, using the length as key
+ Map<Float, SpeciesBatchFrequency> actualLengthMap = Maps.newHashMap();
+ for (SpeciesBatchFrequency speciesBatchFrequency : actualFrequencies) {
+ assertFalse("Duplicate lengthStep found in batchFrequencies, for length=" + speciesBatchFrequency.getLengthStep(), actualLengthMap.containsKey(speciesBatchFrequency.getLengthStep()));
+ actualLengthMap.put(speciesBatchFrequency.getLengthStep(), speciesBatchFrequency);
+ assertNotNull(speciesBatchFrequency.getId());
+ }
+
+ for (Float lengthStep : expectedLengthMap.keySet()) {
+ SpeciesBatchFrequency expectedBatchFrequency = expectedLengthMap.get(lengthStep);
+ SpeciesBatchFrequency actualBatchFrequency = actualLengthMap.get(lengthStep);
+ if (assertIdEquals) {
+ assertEquals(expectedBatchFrequency.getId(), actualBatchFrequency.getId());
+ }
+ assertNotNull(expectedBatchFrequency.getLengthStepCaracteristic());
+ assertEquals(expectedBatchFrequency.getLengthStepCaracteristic().getId(), actualBatchFrequency.getLengthStepCaracteristic().getId());
+ assertEquals(expectedBatchFrequency.getNumber(), actualBatchFrequency.getNumber());
+ assertEquals(expectedBatchFrequency.getWeight(), actualBatchFrequency.getWeight());
+ assertEquals(expectedBatchFrequency.getComment(), actualBatchFrequency.getComment());
+ //assertNotNull(expectedBatchFrequency.getBatch());
+ //assertEquals(expectedBatchFrequency.getBatch().getId(), actualBatchFrequency.getBatch().getId());
+ }
+ }
+
+ protected SpeciesBatch getSpeciesBatch(String fishingOperationId, String speciesBatchId) {
+ return getSpeciesBatch(speciesBatchId, service.getAllRootSpeciesBatch(fishingOperationId));
+ }
+
+ protected SpeciesBatch getSpeciesBatch(String speciesBatchId, List<SpeciesBatch> speciesBatchs) {
+ if (speciesBatchs == null) {
+ return null;
+ }
+ for (SpeciesBatch speciesBatch : speciesBatchs) {
+ if (speciesBatchId.equals(speciesBatch.getId())) {
+ return speciesBatch;
+ }
+ if (speciesBatch.getChildBatchs() != null) {
+ speciesBatch = getSpeciesBatch(speciesBatchId, speciesBatch.getChildBatchs());
+ if (speciesBatch != null) {
+ return speciesBatch;
+ }
+ }
+ }
+ return null;
+ }
+}
Deleted: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceTest.java
===================================================================
--- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceTest.java 2013-02-09 07:44:17 UTC (rev 378)
+++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceTest.java 2013-02-10 13:41:29 UTC (rev 379)
@@ -1,532 +0,0 @@
-package fr.ifremer.tutti.persistence.service;
-
-/*
- * #%L
- * Tutti :: Persistence API
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2012 - 2013 Ifremer
- * %%
- * 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%
- */
-
-import fr.ifremer.tutti.persistence.DatabaseResource;
-import fr.ifremer.tutti.persistence.entities.data.CatchBatch;
-import fr.ifremer.tutti.persistence.entities.data.Cruise;
-import fr.ifremer.tutti.persistence.entities.data.FishingOperation;
-import fr.ifremer.tutti.persistence.entities.data.SampleCategoryEnum;
-import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch;
-import fr.ifremer.tutti.persistence.entities.data.SpeciesBatchFrequency;
-import fr.ifremer.tutti.persistence.entities.referential.Caracteristic;
-import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativeValue;
-import fr.ifremer.tutti.persistence.entities.referential.CaracteristicType;
-import fr.ifremer.tutti.persistence.entities.referential.Species;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.springframework.dao.DataRetrievalFailureException;
-
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
-
-import java.util.Calendar;
-import java.util.Date;
-import java.util.GregorianCalendar;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.*;
-
-/**
- * @author tchemit <chemit(a)codelutin.com>
- * @since 0.3
- */
-@Ignore
-public class SpeciesBatchPersistenceServiceTest {
-
- @ClassRule
- public static final DatabaseResource dbResource = new DatabaseResource();
-
- protected SpeciesBatchPersistenceService service;
-
- protected CruisePersistenceService cruiseService;
-
- protected FishingOperationPersistenceService fishingOperationService;
-
- protected CatchBatchPersistenceService catchBatchService;
-
- protected ReferentialPersistenceService referentialService;
-
- protected Cruise cruise;
-
- protected FishingOperation fishingOperation;
-
- protected CatchBatch catchBacth;
-
- protected List<Species> species;
-
- protected Caracteristic sortedUnsortedPMFM;
-
- protected CaracteristicQualitativeValue horsVracQualitativeValue;
-
- protected CaracteristicQualitativeValue vracQualitativeValue;
-
- protected Caracteristic maturityPMFM;
-
- protected CaracteristicQualitativeValue firstMaturityQualitativeValue;
-
- protected Caracteristic sexPMFM;
-
- protected CaracteristicQualitativeValue maleQualitativeValue;
-
- protected CaracteristicQualitativeValue femaleQualitativeValue;
-
- protected CaracteristicQualitativeValue unkQualitativeValue;
-
- protected Caracteristic frequencyPMFM;
-
- protected String speciesBacthId = null;
-
- @Before
- public void setUp() throws Exception {
- service = TuttiPersistenceServiceLocator.getSpeciesBatchPersistenceService();
- cruiseService = TuttiPersistenceServiceLocator.getCruisePersistenceService();
- fishingOperationService = TuttiPersistenceServiceLocator.getFishingOperationPersistenceService();
- referentialService = TuttiPersistenceServiceLocator.getReferentialPersistenceService();
- catchBatchService = TuttiPersistenceServiceLocator.getCatchBatchPersistenceService();
-
- cruise = cruiseService.getCruise(dbResource.getFixtures().cruiseId());
- cruise.setId(null);
- Calendar calendar = new GregorianCalendar();
- cruise.setBeginDate(calendar.getTime());
- cruise.setYear(calendar.get(Calendar.YEAR));
- calendar.add(Calendar.MONTH, 1); // add one month
- cruise.setEndDate(calendar.getTime());
- cruise = cruiseService.createCruise(cruise);
-
- List<FishingOperation> fishingOperations = fishingOperationService.getAllFishingOperation(dbResource.getFixtures().cruiseId());
- assertNotNull(fishingOperations);
- assertTrue(fishingOperations.size() > 0);
- fishingOperation = fishingOperations.get(0);
- fishingOperation = fishingOperationService.getFishingOperation(fishingOperation.getId());
- fishingOperation.setId(null);
- fishingOperation.setCruise(cruise);
- calendar.setTime(new Date());
- calendar.set(Calendar.HOUR_OF_DAY, 1);
- calendar.set(Calendar.MILLISECOND, 0);
- fishingOperation.setGearShootingStartDate(calendar.getTime());
- calendar.setTime(new Date());
- calendar.set(Calendar.HOUR_OF_DAY, 10);
- calendar.set(Calendar.MILLISECOND, 0);
- fishingOperation.setGearShootingEndDate(calendar.getTime());
-
- fishingOperation = fishingOperationService.createFishingOperation(fishingOperation);
-
- catchBacth = new CatchBatch();
- catchBacth.setFishingOperation(fishingOperation);
- catchBacth = catchBatchService.createCatchBatch(catchBacth);
-
- species = referentialService.getAllSpecies();
- assertNotNull(species);
- assertTrue(species.size() > 2);
-
- sortedUnsortedPMFM = referentialService.getSortedUnsortedCaracteristic();
- horsVracQualitativeValue = sortedUnsortedPMFM.getQualitativeValue(0);
- vracQualitativeValue = sortedUnsortedPMFM.getQualitativeValue(1);
- maturityPMFM = referentialService.getMaturityCaracteristic();
- firstMaturityQualitativeValue = maturityPMFM.getQualitativeValue(0);
- sexPMFM = referentialService.getSexCaracteristic();
- maleQualitativeValue = sexPMFM.getQualitativeValue(1);
- femaleQualitativeValue = sexPMFM.getQualitativeValue(2);
- unkQualitativeValue = sexPMFM.getQualitativeValue(3);
-
-
- List<Caracteristic> cara = referentialService.getAllCaracteristic();
- for (Iterator iterator = cara.iterator(); iterator.hasNext();) {
- Caracteristic caracteristic = (Caracteristic) iterator.next();
- if (caracteristic.getCaracteristicType() == CaracteristicType.NUMBER
- && caracteristic.getPrecision() != null
- && caracteristic.getPrecision().floatValue() == 0.5f) {
- frequencyPMFM = caracteristic;
- break;
- }
- }
- assertNotNull("no numerical PMFM with a precision has been found. Could not define a PMFM for batch frequencies.", frequencyPMFM);
- }
-
- @Test
- public void createSpeciesBatch(/*SpeciesBatch bean, String parentBatchId*/) {
- SpeciesBatch esp1Batch = null;
- SpeciesBatch esp2Batch = null;
- SpeciesBatch frequenciesParentBatch = null;
- SpeciesBatch batch = null;
- Species taxon1 = species.get(0);
- Species taxon2 = species.get(1);
-
- // -----------------------------------------------------------------------------
- // 1. Test with only mandatory properties
- // -----------------------------------------------------------------------------
- // batch : "ESP1 - Vrac/5"
- batch = new SpeciesBatch();
- batch.setParentBatch(null);
- batch.setFishingOperation(fishingOperation);
- // TODO TC : add link between Speciesbatch and CatchBatch
- //batch.setCatchBatch(catchBatch);
- batch.setSpecies(taxon1);
- batch.setSampleCategoryType(SampleCategoryEnum.sortedUnsorted);
- batch.setSampleCategoryValue(vracQualitativeValue);
- batch.setWeight(5f);
-
- assertCreateAndReloadSpeciesBatch(batch, null);
-
- // Save ESP1 batch
- esp1Batch = batch;
-
- // -----------------------------------------------------------------------------
- // 2. Test child "Male/2"
- // -----------------------------------------------------------------------------
- // Batch : ESP1 - Vrac/5 Male/2 ss-ech/1 Nombre/7
- batch = new SpeciesBatch();
- batch.setId(null);
- batch.setParentBatch(esp1Batch);
- batch.setSpecies(taxon1);
- batch.setComment("ESP1 - Vrac/5 Male/2 ss-ech/1 Nombre/7");
- batch.setWeight(2f);
- batch.setSampleCategoryType(SampleCategoryEnum.sex);
- batch.setSampleCategoryValue(maleQualitativeValue);
- batch.setSampleCategoryWeight(1f);
- batch.setNumber(7);
-
- assertCreateAndReloadSpeciesBatch(batch, batch.getParentBatch().getId());
-
- // -----------------------------------------------------------------------------
- // 3. Test child "Female/2"
- // -----------------------------------------------------------------------------
- // Batch : ESP1 - Vrac/5 Female/3 Nombre/14
- batch = new SpeciesBatch();
- batch.setId(null);
- batch.setParentBatch(esp1Batch);
- batch.setSpecies(taxon1);
- batch.setComment("ESP1 - Vrac/5 Female/3 Nombre/14");
- batch.setWeight(3f);
- batch.setSampleCategoryType(SampleCategoryEnum.sex);
- batch.setSampleCategoryValue(femaleQualitativeValue);
- batch.setSampleCategoryWeight(null);
- batch.setNumber(14);
-
- assertCreateAndReloadSpeciesBatch(batch, batch.getParentBatch().getId());
-
- // -----------------------------------------------------------------------------
- // 4. Test : ESP2 - Vrac/7
- // \- ESP2 - Vrac/7 UNK/2 ss-ech/1 Nombre/11
- // -----------------------------------------------------------------------------
- // batch : "ESP2 - Vrac/7 "
- batch = new SpeciesBatch();
- batch.setParentBatch(null);
- // TODO TC : add link between Speciesbatch and CatchBatch
- //batch.setCatchBatch(catchBatch);
- batch.setSpecies(taxon2);
- batch.setSampleCategoryType(SampleCategoryEnum.sortedUnsorted);
- batch.setSampleCategoryValue(vracQualitativeValue);
- batch.setWeight(7f);
-
- assertCreateAndReloadSpeciesBatch(batch, null);
- esp2Batch = batch;
-
- // Batch : ESP2 - Vrac/7 UNK/2 ss-ech/1 Nombre/11
- batch = new SpeciesBatch();
- batch.setId(null);
- batch.setParentBatch(esp2Batch);
- batch.setSpecies(taxon2);
- batch.setComment("ESP2 - Vrac/7 UNK/2 ss-ech/1 Nombre/11");
- batch.setSampleCategoryType(SampleCategoryEnum.maturity);
- batch.setSampleCategoryValue(firstMaturityQualitativeValue);
- batch.setWeight(2f);
- batch.setSampleCategoryWeight(1f);
- batch.setNumber(11);
-
- assertCreateAndReloadSpeciesBatch(batch, batch.getParentBatch().getId());
-
- // -----------------------------------------------------------------------------
- // 5. Test save after modifications
- // -----------------------------------------------------------------------------
- // Batch : ESP2 - Vrac/7 UNK/1.75 ss-ech/1.11 Nombre/99
- batch.setSampleCategoryType(SampleCategoryEnum.sex);
- batch.setSampleCategoryValue(unkQualitativeValue);
- batch.setComment("ESP2 - Vrac/7 UNK/1.75 ss-ech/1.11 Nombre/99");
- batch.setWeight(1.75f);
- batch.setSampleCategoryWeight(1.11f);
- batch.setFishingOperation(fishingOperation);
- batch.setNumber(99);
-
- // Save and reload, then check
- SpeciesBatch savedBatch = service.saveSpeciesBatch(batch);
- assertSpeciesBatch(savedBatch, batch, false);
- SpeciesBatch reloadedBatch = getSpeciesBatch(fishingOperation.getId(), savedBatch.getId());
- assertSpeciesBatch(reloadedBatch, savedBatch, true);
-
- // Save batch for later
- frequenciesParentBatch = batch;
-
- // -----------------------------------------------------------------------------
- // 6. Test get all root species
- // -----------------------------------------------------------------------------
- List<SpeciesBatch> rootSpeciesBatch = service.getAllRootSpeciesBatch(fishingOperation.getId());
- assertNotNull(rootSpeciesBatch);
- assertEquals(2, rootSpeciesBatch.size());
- assertNotNull(rootSpeciesBatch.get(0).getChildBatchs());
- assertTrue(rootSpeciesBatch.get(0).getChildBatchs().size() > 0);
- assertNotNull(rootSpeciesBatch.get(1).getChildBatchs());
- assertTrue(rootSpeciesBatch.get(1).getChildBatchs().size() > 0);
-
- // -----------------------------------------------------------------------------
- // 8. Test batch frequency creation
- // -----------------------------------------------------------------------------
-
- List<SpeciesBatchFrequency> frequencies = Lists.newArrayList();
- float lengthStep = 0.5f;
- for (float length = lengthStep; length < lengthStep * 20; length+=lengthStep) {
- SpeciesBatchFrequency frequency = new SpeciesBatchFrequency();
- frequency.setLengthStep(length);
- frequency.setNumber((int)(length*2));
- frequency.setWeight(0.01f*length*2);
- frequency.setLengthStepCaracteristic(frequencyPMFM);
- frequency.setBatch(frequenciesParentBatch);
- frequency.setComment("comments");
- frequencies.add(frequency);
- }
- List<SpeciesBatchFrequency> createdFrequencies = assertCreateAndReloadSpeciesBatchFrequency(frequencies, frequenciesParentBatch.getId());
-
- // -----------------------------------------------------------------------------
- // 9. Test batch frequency update
- // -----------------------------------------------------------------------------
- // Update some batchs (1cm, 2cm, etc)
- for (Iterator iterator = createdFrequencies.iterator(); iterator.hasNext();) {
- SpeciesBatchFrequency speciesBatchFrequency = (SpeciesBatchFrequency) iterator.next();
- float length = speciesBatchFrequency.getLengthStep();
- if ((float)(int)length == length) {
- speciesBatchFrequency.setNumber(12);
- speciesBatchFrequency.setComment(null);
- }
- }
- List<SpeciesBatchFrequency> savedFrequencies = service.saveSpeciesBatchFrequency(frequenciesParentBatch.getId(), frequencies);
- assertBatchFrequencies(createdFrequencies, savedFrequencies, true);
- }
-
- @Test
- @Ignore
- public void saveSpeciesBatch(/*SpeciesBatch bean*/) {
-
- }
-
- @Test
- @Ignore
- public void saveSpeciesBatchFrequency() {
-
- }
-
- @Test
- @Ignore
- public void getAllRootSpeciesBatch(/*String fishingOperationId*/) {
- }
-
- @Test
- public void deleteSpeciesBatch(/*String id*/) {
- SpeciesBatch esp1Batch;
- SpeciesBatch childBatch = null;
- SpeciesBatch batch;
- Species taxon1 = species.get(0);
-
- // -----------------------------------------------------------------------------
- // 1. Create two batchs (parent + child), then remove the parent batch
- // -----------------------------------------------------------------------------
- // batch : ESP1 Vrac/5
- batch = new SpeciesBatch();
- batch.setParentBatch(null);
- batch.setFishingOperation(fishingOperation);
- batch.setSpecies(taxon1);
- batch.setSampleCategoryType(SampleCategoryEnum.sortedUnsorted);
- batch.setSampleCategoryValue(vracQualitativeValue);
- batch.setWeight(5f);
- assertCreateAndReloadSpeciesBatch(batch, null);
- esp1Batch = batch;
-
- // batch : ESP1 Vrac/5 Male/2
- batch = new SpeciesBatch();
- batch.setParentBatch(esp1Batch);
- batch.setFishingOperation(fishingOperation);
- batch.setSpecies(taxon1);
- batch.setSampleCategoryType(SampleCategoryEnum.sex);
- batch.setSampleCategoryValue(maleQualitativeValue);
- batch.setWeight(2f);
- assertCreateAndReloadSpeciesBatch(batch, esp1Batch.getId());
-
- // Try to remove
- service.deleteSpeciesBatch(esp1Batch.getId());
-
- // Check if remove
- try {
- batch = getSpeciesBatch(fishingOperation.getId(), esp1Batch.getId());
- assertNull(batch);
- } catch (DataRetrievalFailureException drfe) {
- assertNotNull(drfe);
- }
- }
-
- @Test
- @Ignore
- public void deleteSpeciesSubBatch(/*String id*/) {
- // Idem deleteSpeciesBatch
- }
-
- @Test
- @Ignore
- public void getAllSpeciesBatchFrequency(/*String speciesBatchId*/) {
-
- }
-
- protected void assertCreateAndReloadSpeciesBatch(SpeciesBatch batch, String parentBatchId) {
- batch.setFishingOperation(fishingOperation);
-
- // Create batch
- SpeciesBatch createdBatch = service.createSpeciesBatch(batch, parentBatchId);
- assertSpeciesBatch(batch, createdBatch, false);
-
- // then reload (for round trip check)
- SpeciesBatch reloadedBatch = getSpeciesBatch(fishingOperation.getId(), createdBatch.getId());
- if (parentBatchId == null) {
- assertNull(reloadedBatch.getParentBatch());
- }
- else {
- assertNotNull(reloadedBatch.getParentBatch());
- assertEquals(parentBatchId, reloadedBatch.getParentBatch().getId());
- }
- assertSpeciesBatch(createdBatch, reloadedBatch, false);
-
- batch.setId(createdBatch.getId());
- }
-
- protected void assertSpeciesBatch(SpeciesBatch expectedBatch, SpeciesBatch actualBatch, boolean assertIdEquals) {
- assertNotNull(actualBatch);
- assertNotNull(actualBatch.getId());
- if (assertIdEquals && expectedBatch.getId() != null) {
- assertEquals(expectedBatch.getId(), actualBatch.getId());
- }
- assertEquals(expectedBatch.getWeight(), actualBatch.getWeight());
- assertEquals(expectedBatch.getSampleCategoryType(), actualBatch.getSampleCategoryType());
- if (expectedBatch.getSampleCategoryValue() != null && expectedBatch.getSampleCategoryValue() instanceof CaracteristicQualitativeValue) {
- assertNotNull("Bad sampleCategoryValue : expected <" + ((CaracteristicQualitativeValue)expectedBatch.getSampleCategoryValue()).getId() +"> but was <null>",
- actualBatch.getSampleCategoryValue());
- assertEquals(
- ((CaracteristicQualitativeValue)expectedBatch.getSampleCategoryValue()).getId(),
- ((CaracteristicQualitativeValue)actualBatch.getSampleCategoryValue()).getId());
- }
- else {
- assertEquals(expectedBatch.getSampleCategoryValue(), actualBatch.getSampleCategoryValue());
- }
- assertEquals(expectedBatch.getSampleCategoryWeight(), actualBatch.getSampleCategoryWeight());
- assertEquals(expectedBatch.getNumber(), actualBatch.getNumber());
- assertEquals(expectedBatch.getComment(), actualBatch.getComment());
-
- // Check species only if Vrac/HorsVrac or if batch has been load throw getAllxxx method
- // (Because getSpeciesBatch(id) could not always retrieve the species)
- if (expectedBatch.getSpecies() != null && (
- expectedBatch.getSampleCategoryType() == SampleCategoryEnum.sortedUnsorted
- || actualBatch.getSpecies() != null)) {
- assertNotNull(actualBatch.getSpecies());
- assertEquals(expectedBatch.getSpecies().getId(), actualBatch.getSpecies().getId());
- }
- }
-
- protected List<SpeciesBatchFrequency> assertCreateAndReloadSpeciesBatchFrequency(List<SpeciesBatchFrequency> frequencies, String parentBatchId) {
-
- // Create batch
- List<SpeciesBatchFrequency> createdFrequencies = service.saveSpeciesBatchFrequency(parentBatchId, frequencies);
- assertBatchFrequencies(frequencies, createdFrequencies, false);
-
- // then reload (for round trip check)
- List<SpeciesBatchFrequency> reloadedFrequencies = service.getAllSpeciesBatchFrequency(parentBatchId);
- assertBatchFrequencies(createdFrequencies, reloadedFrequencies, true);
-
- return createdFrequencies;
- }
-
- protected void assertBatchFrequencies(List<SpeciesBatchFrequency> expectedFrequencies, List<SpeciesBatchFrequency> actualFrequencies, boolean assertIdEquals) {
- assertNotNull(actualFrequencies);
- assertEquals(expectedFrequencies.size(), actualFrequencies.size());
-
- // Store actual batches into a map, using the length as key
- Map<Float, SpeciesBatchFrequency> expectedLengthMap = Maps.newHashMap();
- for (Iterator iterator = expectedFrequencies.iterator(); iterator.hasNext();) {
- SpeciesBatchFrequency speciesBatchFrequency = (SpeciesBatchFrequency) iterator.next();
- expectedLengthMap.put(speciesBatchFrequency.getLengthStep(), speciesBatchFrequency);
- }
-
- // Store expected batches into a map, using the length as key
- Map<Float, SpeciesBatchFrequency> actualLengthMap = Maps.newHashMap();
- for (Iterator iterator = actualFrequencies.iterator(); iterator.hasNext();) {
- SpeciesBatchFrequency speciesBatchFrequency = (SpeciesBatchFrequency) iterator.next();
- assertFalse("Duplicate lengthStep found in batchFrequencies, for length="+speciesBatchFrequency.getLengthStep(), actualLengthMap.containsKey(speciesBatchFrequency.getLengthStep()));
- actualLengthMap.put(speciesBatchFrequency.getLengthStep(), speciesBatchFrequency);
- assertNotNull(speciesBatchFrequency.getId());
- }
-
- for (Iterator iterator = expectedLengthMap.keySet().iterator(); iterator.hasNext();) {
- Float lengthStep = (Float) iterator.next();
- SpeciesBatchFrequency expectedBatchFrequency = expectedLengthMap.get(lengthStep);
- SpeciesBatchFrequency actualBatchFrequency = actualLengthMap.get(lengthStep);
- if (assertIdEquals) {
- assertEquals(expectedBatchFrequency.getId(), actualBatchFrequency.getId());
- }
- assertNotNull(expectedBatchFrequency.getLengthStepCaracteristic());
- assertEquals(expectedBatchFrequency.getLengthStepCaracteristic().getId(), actualBatchFrequency.getLengthStepCaracteristic().getId());
- assertEquals(expectedBatchFrequency.getNumber(), actualBatchFrequency.getNumber());
- assertEquals(expectedBatchFrequency.getWeight(), actualBatchFrequency.getWeight());
- assertEquals(expectedBatchFrequency.getComment(), actualBatchFrequency.getComment());
- //assertNotNull(expectedBatchFrequency.getBatch());
- //assertEquals(expectedBatchFrequency.getBatch().getId(), actualBatchFrequency.getBatch().getId());
- }
- }
-
- protected SpeciesBatch getSpeciesBatch(String fishingOperationId, String speciesBatchId) {
- return getSpeciesBatch(speciesBatchId, service.getAllRootSpeciesBatch(fishingOperationId));
- }
-
- protected SpeciesBatch getSpeciesBatch(String speciesBatchId, List<SpeciesBatch> speciesBatchs) {
- if (speciesBatchs == null) {
- return null;
- }
- for (Iterator iterator = speciesBatchs.iterator(); iterator.hasNext();) {
- SpeciesBatch speciesBatch = (SpeciesBatch) iterator.next();
- if (speciesBatchId.equals(speciesBatch.getId())) {
- return speciesBatch;
- }
- if (speciesBatch.getChildBatchs() != null) {
- speciesBatch = getSpeciesBatch(speciesBatchId, speciesBatch.getChildBatchs());
- if (speciesBatch != null) {
- return speciesBatch;
- }
- }
- }
- return null;
- }
-}
Copied: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceWriteTest.java (from rev 378, trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceTest.java)
===================================================================
--- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceWriteTest.java (rev 0)
+++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceWriteTest.java 2013-02-10 13:41:29 UTC (rev 379)
@@ -0,0 +1,508 @@
+package fr.ifremer.tutti.persistence.service;
+
+/*
+ * #%L
+ * Tutti :: Persistence API
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2012 - 2013 Ifremer
+ * %%
+ * 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%
+ */
+
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import fr.ifremer.tutti.persistence.DatabaseResource;
+import fr.ifremer.tutti.persistence.entities.data.CatchBatch;
+import fr.ifremer.tutti.persistence.entities.data.Cruise;
+import fr.ifremer.tutti.persistence.entities.data.FishingOperation;
+import fr.ifremer.tutti.persistence.entities.data.SampleCategoryEnum;
+import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch;
+import fr.ifremer.tutti.persistence.entities.data.SpeciesBatchFrequency;
+import fr.ifremer.tutti.persistence.entities.referential.Caracteristic;
+import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativeValue;
+import fr.ifremer.tutti.persistence.entities.referential.CaracteristicType;
+import fr.ifremer.tutti.persistence.entities.referential.Species;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.springframework.dao.DataRetrievalFailureException;
+
+import java.util.Calendar;
+import java.util.Date;
+import java.util.GregorianCalendar;
+import java.util.List;
+import java.util.Map;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * To test {@link SpeciesBatchPersistenceService} for write operation.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 0.3
+ */
+@Ignore
+public class SpeciesBatchPersistenceServiceWriteTest {
+
+ @ClassRule
+ public static final DatabaseResource dbResource = DatabaseResource.writeDb();
+
+ protected SpeciesBatchPersistenceService service;
+
+ protected CruisePersistenceService cruiseService;
+
+ protected FishingOperationPersistenceService fishingOperationService;
+
+ protected CatchBatchPersistenceService catchBatchService;
+
+ protected ReferentialPersistenceService referentialService;
+
+ protected Cruise cruise;
+
+ protected FishingOperation fishingOperation;
+
+ protected CatchBatch catchBacth;
+
+ protected List<Species> species;
+
+ protected Caracteristic sortedUnsortedPMFM;
+
+ protected CaracteristicQualitativeValue horsVracQualitativeValue;
+
+ protected CaracteristicQualitativeValue vracQualitativeValue;
+
+ protected Caracteristic maturityPMFM;
+
+ protected CaracteristicQualitativeValue firstMaturityQualitativeValue;
+
+ protected Caracteristic sexPMFM;
+
+ protected CaracteristicQualitativeValue maleQualitativeValue;
+
+ protected CaracteristicQualitativeValue femaleQualitativeValue;
+
+ protected CaracteristicQualitativeValue unkQualitativeValue;
+
+ protected Caracteristic frequencyPMFM;
+
+ protected String speciesBacthId = null;
+
+ @Before
+ public void setUp() throws Exception {
+ service = TuttiPersistenceServiceLocator.getSpeciesBatchPersistenceService();
+ cruiseService = TuttiPersistenceServiceLocator.getCruisePersistenceService();
+ fishingOperationService = TuttiPersistenceServiceLocator.getFishingOperationPersistenceService();
+ referentialService = TuttiPersistenceServiceLocator.getReferentialPersistenceService();
+ catchBatchService = TuttiPersistenceServiceLocator.getCatchBatchPersistenceService();
+
+ cruise = cruiseService.getCruise(dbResource.getFixtures().cruiseId());
+ cruise.setId(null);
+ Calendar calendar = new GregorianCalendar();
+ cruise.setBeginDate(calendar.getTime());
+ cruise.setYear(calendar.get(Calendar.YEAR));
+ calendar.add(Calendar.MONTH, 1); // add one month
+ cruise.setEndDate(calendar.getTime());
+ cruise = cruiseService.createCruise(cruise);
+
+ List<FishingOperation> fishingOperations = fishingOperationService.getAllFishingOperation(dbResource.getFixtures().cruiseId());
+ assertNotNull(fishingOperations);
+ assertTrue(fishingOperations.size() > 0);
+ fishingOperation = fishingOperations.get(0);
+ fishingOperation = fishingOperationService.getFishingOperation(fishingOperation.getId());
+ fishingOperation.setId(null);
+ fishingOperation.setCruise(cruise);
+ calendar.setTime(new Date());
+ calendar.set(Calendar.HOUR_OF_DAY, 1);
+ calendar.set(Calendar.MILLISECOND, 0);
+ fishingOperation.setGearShootingStartDate(calendar.getTime());
+ calendar.setTime(new Date());
+ calendar.set(Calendar.HOUR_OF_DAY, 10);
+ calendar.set(Calendar.MILLISECOND, 0);
+ fishingOperation.setGearShootingEndDate(calendar.getTime());
+
+ fishingOperation = fishingOperationService.createFishingOperation(fishingOperation);
+
+ catchBacth = new CatchBatch();
+ catchBacth.setFishingOperation(fishingOperation);
+ catchBacth = catchBatchService.createCatchBatch(catchBacth);
+
+ species = referentialService.getAllSpecies();
+ assertNotNull(species);
+ assertTrue(species.size() > 2);
+
+ sortedUnsortedPMFM = referentialService.getSortedUnsortedCaracteristic();
+ horsVracQualitativeValue = sortedUnsortedPMFM.getQualitativeValue(0);
+ vracQualitativeValue = sortedUnsortedPMFM.getQualitativeValue(1);
+ maturityPMFM = referentialService.getMaturityCaracteristic();
+ firstMaturityQualitativeValue = maturityPMFM.getQualitativeValue(0);
+ sexPMFM = referentialService.getSexCaracteristic();
+ maleQualitativeValue = sexPMFM.getQualitativeValue(1);
+ femaleQualitativeValue = sexPMFM.getQualitativeValue(2);
+ unkQualitativeValue = sexPMFM.getQualitativeValue(3);
+
+
+ List<Caracteristic> cara = referentialService.getAllCaracteristic();
+ for (Caracteristic caracteristic : cara) {
+ if (caracteristic.getCaracteristicType() == CaracteristicType.NUMBER
+ && caracteristic.getPrecision() != null
+ && caracteristic.getPrecision() == 0.5f) {
+ frequencyPMFM = caracteristic;
+ break;
+ }
+ }
+ assertNotNull("no numerical PMFM with a precision has been found. Could not define a PMFM for batch frequencies.", frequencyPMFM);
+ }
+
+ @Test
+ public void createSpeciesBatch(/*SpeciesBatch bean, String parentBatchId*/) {
+ SpeciesBatch esp1Batch = null;
+ SpeciesBatch esp2Batch = null;
+ SpeciesBatch frequenciesParentBatch = null;
+ SpeciesBatch batch = null;
+ Species taxon1 = species.get(0);
+ Species taxon2 = species.get(1);
+
+ // -----------------------------------------------------------------------------
+ // 1. Test with only mandatory properties
+ // -----------------------------------------------------------------------------
+ // batch : "ESP1 - Vrac/5"
+ batch = new SpeciesBatch();
+ batch.setParentBatch(null);
+ batch.setFishingOperation(fishingOperation);
+ // TODO TC : add link between Speciesbatch and CatchBatch
+ //batch.setCatchBatch(catchBatch);
+ batch.setSpecies(taxon1);
+ batch.setSampleCategoryType(SampleCategoryEnum.sortedUnsorted);
+ batch.setSampleCategoryValue(vracQualitativeValue);
+ batch.setWeight(5f);
+
+ assertCreateAndReloadSpeciesBatch(batch, null);
+
+ // Save ESP1 batch
+ esp1Batch = batch;
+
+ // -----------------------------------------------------------------------------
+ // 2. Test child "Male/2"
+ // -----------------------------------------------------------------------------
+ // Batch : ESP1 - Vrac/5 Male/2 ss-ech/1 Nombre/7
+ batch = new SpeciesBatch();
+ batch.setId(null);
+ batch.setParentBatch(esp1Batch);
+ batch.setSpecies(taxon1);
+ batch.setComment("ESP1 - Vrac/5 Male/2 ss-ech/1 Nombre/7");
+ batch.setWeight(2f);
+ batch.setSampleCategoryType(SampleCategoryEnum.sex);
+ batch.setSampleCategoryValue(maleQualitativeValue);
+ batch.setSampleCategoryWeight(1f);
+ batch.setNumber(7);
+
+ assertCreateAndReloadSpeciesBatch(batch, batch.getParentBatch().getId());
+
+ // -----------------------------------------------------------------------------
+ // 3. Test child "Female/2"
+ // -----------------------------------------------------------------------------
+ // Batch : ESP1 - Vrac/5 Female/3 Nombre/14
+ batch = new SpeciesBatch();
+ batch.setId(null);
+ batch.setParentBatch(esp1Batch);
+ batch.setSpecies(taxon1);
+ batch.setComment("ESP1 - Vrac/5 Female/3 Nombre/14");
+ batch.setWeight(3f);
+ batch.setSampleCategoryType(SampleCategoryEnum.sex);
+ batch.setSampleCategoryValue(femaleQualitativeValue);
+ batch.setSampleCategoryWeight(null);
+ batch.setNumber(14);
+
+ assertCreateAndReloadSpeciesBatch(batch, batch.getParentBatch().getId());
+
+ // -----------------------------------------------------------------------------
+ // 4. Test : ESP2 - Vrac/7
+ // \- ESP2 - Vrac/7 UNK/2 ss-ech/1 Nombre/11
+ // -----------------------------------------------------------------------------
+ // batch : "ESP2 - Vrac/7 "
+ batch = new SpeciesBatch();
+ batch.setParentBatch(null);
+ // TODO TC : add link between Speciesbatch and CatchBatch
+ //batch.setCatchBatch(catchBatch);
+ batch.setSpecies(taxon2);
+ batch.setSampleCategoryType(SampleCategoryEnum.sortedUnsorted);
+ batch.setSampleCategoryValue(vracQualitativeValue);
+ batch.setWeight(7f);
+
+ assertCreateAndReloadSpeciesBatch(batch, null);
+ esp2Batch = batch;
+
+ // Batch : ESP2 - Vrac/7 UNK/2 ss-ech/1 Nombre/11
+ batch = new SpeciesBatch();
+ batch.setId(null);
+ batch.setParentBatch(esp2Batch);
+ batch.setSpecies(taxon2);
+ batch.setComment("ESP2 - Vrac/7 UNK/2 ss-ech/1 Nombre/11");
+ batch.setSampleCategoryType(SampleCategoryEnum.maturity);
+ batch.setSampleCategoryValue(firstMaturityQualitativeValue);
+ batch.setWeight(2f);
+ batch.setSampleCategoryWeight(1f);
+ batch.setNumber(11);
+
+ assertCreateAndReloadSpeciesBatch(batch, batch.getParentBatch().getId());
+
+ // -----------------------------------------------------------------------------
+ // 5. Test save after modifications
+ // -----------------------------------------------------------------------------
+ // Batch : ESP2 - Vrac/7 UNK/1.75 ss-ech/1.11 Nombre/99
+ batch.setSampleCategoryType(SampleCategoryEnum.sex);
+ batch.setSampleCategoryValue(unkQualitativeValue);
+ batch.setComment("ESP2 - Vrac/7 UNK/1.75 ss-ech/1.11 Nombre/99");
+ batch.setWeight(1.75f);
+ batch.setSampleCategoryWeight(1.11f);
+ batch.setFishingOperation(fishingOperation);
+ batch.setNumber(99);
+
+ // Save and reload, then check
+ SpeciesBatch savedBatch = service.saveSpeciesBatch(batch);
+ assertSpeciesBatch(savedBatch, batch, false);
+ SpeciesBatch reloadedBatch = getSpeciesBatch(fishingOperation.getId(), savedBatch.getId());
+ assertSpeciesBatch(reloadedBatch, savedBatch, true);
+
+ // Save batch for later
+ frequenciesParentBatch = batch;
+
+ // -----------------------------------------------------------------------------
+ // 6. Test get all root species
+ // -----------------------------------------------------------------------------
+ List<SpeciesBatch> rootSpeciesBatch = service.getAllRootSpeciesBatch(fishingOperation.getId());
+ assertNotNull(rootSpeciesBatch);
+ assertEquals(2, rootSpeciesBatch.size());
+ assertNotNull(rootSpeciesBatch.get(0).getChildBatchs());
+ assertTrue(rootSpeciesBatch.get(0).getChildBatchs().size() > 0);
+ assertNotNull(rootSpeciesBatch.get(1).getChildBatchs());
+ assertTrue(rootSpeciesBatch.get(1).getChildBatchs().size() > 0);
+
+ // -----------------------------------------------------------------------------
+ // 8. Test batch frequency creation
+ // -----------------------------------------------------------------------------
+
+ List<SpeciesBatchFrequency> frequencies = Lists.newArrayList();
+ float lengthStep = 0.5f;
+ for (float length = lengthStep; length < lengthStep * 20; length += lengthStep) {
+ SpeciesBatchFrequency frequency = new SpeciesBatchFrequency();
+ frequency.setLengthStep(length);
+ frequency.setNumber((int) (length * 2));
+ frequency.setWeight(0.01f * length * 2);
+ frequency.setLengthStepCaracteristic(frequencyPMFM);
+ frequency.setBatch(frequenciesParentBatch);
+ frequency.setComment("comments");
+ frequencies.add(frequency);
+ }
+ List<SpeciesBatchFrequency> createdFrequencies = assertCreateAndReloadSpeciesBatchFrequency(frequencies, frequenciesParentBatch.getId());
+
+ // -----------------------------------------------------------------------------
+ // 9. Test batch frequency update
+ // -----------------------------------------------------------------------------
+ // Update some batchs (1cm, 2cm, etc)
+ for (SpeciesBatchFrequency speciesBatchFrequency : createdFrequencies) {
+ float length = speciesBatchFrequency.getLengthStep();
+ if ((float) (int) length == length) {
+ speciesBatchFrequency.setNumber(12);
+ speciesBatchFrequency.setComment(null);
+ }
+ }
+ List<SpeciesBatchFrequency> savedFrequencies = service.saveSpeciesBatchFrequency(frequenciesParentBatch.getId(), frequencies);
+ assertBatchFrequencies(createdFrequencies, savedFrequencies, true);
+ }
+
+ @Test
+ @Ignore
+ public void saveSpeciesBatch(/*SpeciesBatch bean*/) {
+
+ }
+
+ @Test
+ public void deleteSpeciesBatch(/*String id*/) {
+ SpeciesBatch esp1Batch;
+ SpeciesBatch childBatch = null;
+ SpeciesBatch batch;
+ Species taxon1 = species.get(0);
+
+ // -----------------------------------------------------------------------------
+ // 1. Create two batchs (parent + child), then remove the parent batch
+ // -----------------------------------------------------------------------------
+ // batch : ESP1 Vrac/5
+ batch = new SpeciesBatch();
+ batch.setParentBatch(null);
+ batch.setFishingOperation(fishingOperation);
+ batch.setSpecies(taxon1);
+ batch.setSampleCategoryType(SampleCategoryEnum.sortedUnsorted);
+ batch.setSampleCategoryValue(vracQualitativeValue);
+ batch.setWeight(5f);
+ assertCreateAndReloadSpeciesBatch(batch, null);
+ esp1Batch = batch;
+
+ // batch : ESP1 Vrac/5 Male/2
+ batch = new SpeciesBatch();
+ batch.setParentBatch(esp1Batch);
+ batch.setFishingOperation(fishingOperation);
+ batch.setSpecies(taxon1);
+ batch.setSampleCategoryType(SampleCategoryEnum.sex);
+ batch.setSampleCategoryValue(maleQualitativeValue);
+ batch.setWeight(2f);
+ assertCreateAndReloadSpeciesBatch(batch, esp1Batch.getId());
+
+ // Try to remove
+ service.deleteSpeciesBatch(esp1Batch.getId());
+
+ // Check if remove
+ try {
+ batch = getSpeciesBatch(fishingOperation.getId(), esp1Batch.getId());
+ assertNull(batch);
+ } catch (DataRetrievalFailureException drfe) {
+ assertNotNull(drfe);
+ }
+ }
+
+ @Test
+ @Ignore
+ public void deleteSpeciesSubBatch(/*String id*/) {
+ // Idem deleteSpeciesBatch
+ }
+
+ protected void assertCreateAndReloadSpeciesBatch(SpeciesBatch batch, String parentBatchId) {
+ batch.setFishingOperation(fishingOperation);
+
+ // Create batch
+ SpeciesBatch createdBatch = service.createSpeciesBatch(batch, parentBatchId);
+ assertSpeciesBatch(batch, createdBatch, false);
+
+ // then reload (for round trip check)
+ SpeciesBatch reloadedBatch = getSpeciesBatch(fishingOperation.getId(), createdBatch.getId());
+ if (parentBatchId == null) {
+ assertNull(reloadedBatch.getParentBatch());
+ } else {
+ assertNotNull(reloadedBatch.getParentBatch());
+ assertEquals(parentBatchId, reloadedBatch.getParentBatch().getId());
+ }
+ assertSpeciesBatch(createdBatch, reloadedBatch, false);
+
+ batch.setId(createdBatch.getId());
+ }
+
+ protected void assertSpeciesBatch(SpeciesBatch expectedBatch, SpeciesBatch actualBatch, boolean assertIdEquals) {
+ assertNotNull(actualBatch);
+ assertNotNull(actualBatch.getId());
+ if (assertIdEquals && expectedBatch.getId() != null) {
+ assertEquals(expectedBatch.getId(), actualBatch.getId());
+ }
+ assertEquals(expectedBatch.getWeight(), actualBatch.getWeight());
+ assertEquals(expectedBatch.getSampleCategoryType(), actualBatch.getSampleCategoryType());
+ if (expectedBatch.getSampleCategoryValue() != null && expectedBatch.getSampleCategoryValue() instanceof CaracteristicQualitativeValue) {
+ assertNotNull("Bad sampleCategoryValue : expected <" + ((CaracteristicQualitativeValue) expectedBatch.getSampleCategoryValue()).getId() + "> but was <null>",
+ actualBatch.getSampleCategoryValue());
+ assertEquals(
+ ((CaracteristicQualitativeValue) expectedBatch.getSampleCategoryValue()).getId(),
+ ((CaracteristicQualitativeValue) actualBatch.getSampleCategoryValue()).getId());
+ } else {
+ assertEquals(expectedBatch.getSampleCategoryValue(), actualBatch.getSampleCategoryValue());
+ }
+ assertEquals(expectedBatch.getSampleCategoryWeight(), actualBatch.getSampleCategoryWeight());
+ assertEquals(expectedBatch.getNumber(), actualBatch.getNumber());
+ assertEquals(expectedBatch.getComment(), actualBatch.getComment());
+
+ // Check species only if Vrac/HorsVrac or if batch has been load throw getAllxxx method
+ // (Because getSpeciesBatch(id) could not always retrieve the species)
+ if (expectedBatch.getSpecies() != null && (
+ expectedBatch.getSampleCategoryType() == SampleCategoryEnum.sortedUnsorted
+ || actualBatch.getSpecies() != null)) {
+ assertNotNull(actualBatch.getSpecies());
+ assertEquals(expectedBatch.getSpecies().getId(), actualBatch.getSpecies().getId());
+ }
+ }
+
+ protected List<SpeciesBatchFrequency> assertCreateAndReloadSpeciesBatchFrequency(List<SpeciesBatchFrequency> frequencies, String parentBatchId) {
+
+ // Create batch
+ List<SpeciesBatchFrequency> createdFrequencies = service.saveSpeciesBatchFrequency(parentBatchId, frequencies);
+ assertBatchFrequencies(frequencies, createdFrequencies, false);
+
+ // then reload (for round trip check)
+ List<SpeciesBatchFrequency> reloadedFrequencies = service.getAllSpeciesBatchFrequency(parentBatchId);
+ assertBatchFrequencies(createdFrequencies, reloadedFrequencies, true);
+
+ return createdFrequencies;
+ }
+
+ protected void assertBatchFrequencies(List<SpeciesBatchFrequency> expectedFrequencies, List<SpeciesBatchFrequency> actualFrequencies, boolean assertIdEquals) {
+ assertNotNull(actualFrequencies);
+ assertEquals(expectedFrequencies.size(), actualFrequencies.size());
+
+ // Store actual batches into a map, using the length as key
+ Map<Float, SpeciesBatchFrequency> expectedLengthMap = Maps.newHashMap();
+ for (SpeciesBatchFrequency speciesBatchFrequency : expectedFrequencies) {
+ expectedLengthMap.put(speciesBatchFrequency.getLengthStep(), speciesBatchFrequency);
+ }
+
+ // Store expected batches into a map, using the length as key
+ Map<Float, SpeciesBatchFrequency> actualLengthMap = Maps.newHashMap();
+ for (SpeciesBatchFrequency speciesBatchFrequency : actualFrequencies) {
+ assertFalse("Duplicate lengthStep found in batchFrequencies, for length=" + speciesBatchFrequency.getLengthStep(), actualLengthMap.containsKey(speciesBatchFrequency.getLengthStep()));
+ actualLengthMap.put(speciesBatchFrequency.getLengthStep(), speciesBatchFrequency);
+ assertNotNull(speciesBatchFrequency.getId());
+ }
+
+ for (Float lengthStep : expectedLengthMap.keySet()) {
+ SpeciesBatchFrequency expectedBatchFrequency = expectedLengthMap.get(lengthStep);
+ SpeciesBatchFrequency actualBatchFrequency = actualLengthMap.get(lengthStep);
+ if (assertIdEquals) {
+ assertEquals(expectedBatchFrequency.getId(), actualBatchFrequency.getId());
+ }
+ assertNotNull(expectedBatchFrequency.getLengthStepCaracteristic());
+ assertEquals(expectedBatchFrequency.getLengthStepCaracteristic().getId(), actualBatchFrequency.getLengthStepCaracteristic().getId());
+ assertEquals(expectedBatchFrequency.getNumber(), actualBatchFrequency.getNumber());
+ assertEquals(expectedBatchFrequency.getWeight(), actualBatchFrequency.getWeight());
+ assertEquals(expectedBatchFrequency.getComment(), actualBatchFrequency.getComment());
+ //assertNotNull(expectedBatchFrequency.getBatch());
+ //assertEquals(expectedBatchFrequency.getBatch().getId(), actualBatchFrequency.getBatch().getId());
+ }
+ }
+
+ protected SpeciesBatch getSpeciesBatch(String fishingOperationId, String speciesBatchId) {
+ return getSpeciesBatch(speciesBatchId, service.getAllRootSpeciesBatch(fishingOperationId));
+ }
+
+ protected SpeciesBatch getSpeciesBatch(String speciesBatchId, List<SpeciesBatch> speciesBatchs) {
+ if (speciesBatchs == null) {
+ return null;
+ }
+ for (SpeciesBatch speciesBatch : speciesBatchs) {
+ if (speciesBatchId.equals(speciesBatch.getId())) {
+ return speciesBatch;
+ }
+ if (speciesBatch.getChildBatchs() != null) {
+ speciesBatch = getSpeciesBatch(speciesBatchId, speciesBatch.getChildBatchs());
+ if (speciesBatch != null) {
+ return speciesBatch;
+ }
+ }
+ }
+ return null;
+ }
+}
Modified: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/TuttiEnumerationFileTest.java
===================================================================
--- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/TuttiEnumerationFileTest.java 2013-02-09 07:44:17 UTC (rev 378)
+++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/TuttiEnumerationFileTest.java 2013-02-10 13:41:29 UTC (rev 379)
@@ -40,8 +40,7 @@
public class TuttiEnumerationFileTest {
@ClassRule
- public static final DatabaseResource dbResource = new DatabaseResource(
- "beanRefFactoryWitNoDb.xml", "TuttiBeanRefFactoryWithNoDb");
+ public static final DatabaseResource dbResource = DatabaseResource.noDb();
@Test
public void init() {
Modified: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/synchro/ReferentialSynchronizeHelperTest.java
===================================================================
--- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/synchro/ReferentialSynchronizeHelperTest.java 2013-02-09 07:44:17 UTC (rev 378)
+++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/synchro/ReferentialSynchronizeHelperTest.java 2013-02-10 13:41:29 UTC (rev 379)
@@ -66,7 +66,7 @@
LogFactory.getLog(ReferentialSynchronizeHelperTest.class);
@ClassRule
- public static final DatabaseResource dbResource = new DatabaseResource();
+ public static final DatabaseResource dbResource = DatabaseResource.writeDb();
@Rule
public final TestName n = new TestName();
@@ -242,7 +242,7 @@
getExistingIds(TuttiTable.LOCATION_LEVEL, fixtures.nbLocationLevel());
getExistingIds(TuttiTable.LOCATION, fixtures.nbLocation());
getExistingIds(TuttiTable.TAXONOMIC_LEVEL, fixtures.nbTaxonomicLevel());
- getExistingIds(TuttiTable.REFERENCE_TAXON, fixtures.nbReferenceTaxon() + 2);
+ getExistingIds(TuttiTable.REFERENCE_TAXON, fixtures.nbReferenceTaxon());
getExistingIds(TuttiTable.TAXON_NAME, fixtures.nbTaxonName());
getExistingIds(TuttiTable.TAXON_GROUP_TYPE, fixtures.nbTaxonGroupType());
getExistingIds(TuttiTable.TAXON_GROUP, fixtures.nbTaxonGroup());
@@ -293,7 +293,7 @@
getDataToUpdate(TuttiTable.LOCATION_LEVEL, internalDb, internalConnection, fromDate, fixtures.nbLocationLevel());
getDataToUpdate(TuttiTable.LOCATION, internalDb, internalConnection, fromDate, fixtures.nbLocation());
getDataToUpdate(TuttiTable.TAXONOMIC_LEVEL, internalDb, internalConnection, fromDate, fixtures.nbTaxonomicLevel());
- getDataToUpdate(TuttiTable.REFERENCE_TAXON, internalDb, internalConnection, fromDate, fixtures.nbReferenceTaxon() + 2);
+ getDataToUpdate(TuttiTable.REFERENCE_TAXON, internalDb, internalConnection, fromDate, fixtures.nbReferenceTaxon());
getDataToUpdate(TuttiTable.TAXON_NAME, internalDb, internalConnection, fromDate, fixtures.nbTaxonName());
getDataToUpdate(TuttiTable.TAXON_GROUP_TYPE, internalDb, internalConnection, fromDate, fixtures.nbTaxonGroupType());
getDataToUpdate(TuttiTable.TAXON_GROUP, internalDb, internalConnection, fromDate, fixtures.nbTaxonGroup());
@@ -354,7 +354,7 @@
updateTable(TuttiTable.LOCATION_LEVEL, internalDb, internalConnection, externalConnection, fromDate, fixtures.nbLocationLevel(), 0);
updateTable(TuttiTable.LOCATION, internalDb, internalConnection, externalConnection, fromDate, fixtures.nbLocation(), 0);
updateTable(TuttiTable.TAXONOMIC_LEVEL, internalDb, internalConnection, externalConnection, fromDate, fixtures.nbTaxonomicLevel(), 0);
- updateTable(TuttiTable.REFERENCE_TAXON, internalDb, internalConnection, externalConnection, fromDate, fixtures.nbReferenceTaxon() + 2, 0);
+ updateTable(TuttiTable.REFERENCE_TAXON, internalDb, internalConnection, externalConnection, fromDate, fixtures.nbReferenceTaxon(), 0);
updateTable(TuttiTable.TAXON_NAME, internalDb, internalConnection, externalConnection, fromDate, fixtures.nbTaxonName(), 0);
updateTable(TuttiTable.TAXON_GROUP_TYPE, internalDb, internalConnection, externalConnection, fromDate, fixtures.nbTaxonGroupType(), 0);
updateTable(TuttiTable.TAXON_GROUP, internalDb, internalConnection, externalConnection, fromDate, fixtures.nbTaxonGroup(), 0);
@@ -393,7 +393,7 @@
updateTable(TuttiTable.LOCATION_LEVEL, internalDb, internalConnection, externalConnection, fromDate, 0, fixtures.nbLocationLevel());
updateTable(TuttiTable.LOCATION, internalDb, internalConnection, externalConnection, fromDate, 0, fixtures.nbLocation());
updateTable(TuttiTable.TAXONOMIC_LEVEL, internalDb, internalConnection, externalConnection, fromDate, 0, fixtures.nbTaxonomicLevel());
- updateTable(TuttiTable.REFERENCE_TAXON, internalDb, internalConnection, externalConnection, fromDate, 0, fixtures.nbReferenceTaxon() + 2);
+ updateTable(TuttiTable.REFERENCE_TAXON, internalDb, internalConnection, externalConnection, fromDate, 0, fixtures.nbReferenceTaxon());
updateTable(TuttiTable.TAXON_NAME, internalDb, internalConnection, externalConnection, fromDate, 0, fixtures.nbTaxonName());
updateTable(TuttiTable.TAXON_GROUP_TYPE, internalDb, internalConnection, externalConnection, fromDate, 0, fixtures.nbTaxonGroupType());
updateTable(TuttiTable.TAXON_GROUP, internalDb, internalConnection, externalConnection, fromDate, 0, fixtures.nbTaxonGroup());
Modified: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/synchro/ReferentialSynchronizeServiceImplTest.java
===================================================================
--- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/synchro/ReferentialSynchronizeServiceImplTest.java 2013-02-09 07:44:17 UTC (rev 378)
+++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/synchro/ReferentialSynchronizeServiceImplTest.java 2013-02-10 13:41:29 UTC (rev 379)
@@ -53,7 +53,7 @@
LogFactory.getLog(ReferentialSynchronizeServiceImplTest.class);
@ClassRule
- public static final DatabaseResource dbResource = new DatabaseResource();
+ public static final DatabaseResource dbResource = DatabaseResource.writeDb();
@Rule
public final TestName n = new TestName();
Copied: trunk/tutti-persistence/src/test/resources/tutti-test-read.properties (from rev 378, trunk/tutti-persistence/src/test/resources/tutti-test.properties)
===================================================================
--- trunk/tutti-persistence/src/test/resources/tutti-test-read.properties (rev 0)
+++ trunk/tutti-persistence/src/test/resources/tutti-test-read.properties 2013-02-10 13:41:29 UTC (rev 379)
@@ -0,0 +1,27 @@
+###
+# #%L
+# Tutti :: Persistence API
+# $Id$
+# $HeadURL$
+# %%
+# Copyright (C) 2012 Ifremer
+# %%
+# 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%
+###
+tutti.persistence.db.directory=src/test/db
+#tutti.persistence.jdbc.url=jdbc:hsqldb:file:src/test/db/allegro
+tutti.persistence.jdbc.url=jdbc:hsqldb:hsql://localhost/allegro
+tutti.persistence.jdbc.createScript=src/test/db/allegro.script
Copied: trunk/tutti-persistence/src/test/resources/tutti-test-write.properties (from rev 378, trunk/tutti-persistence/src/test/resources/tutti-test.properties)
===================================================================
--- trunk/tutti-persistence/src/test/resources/tutti-test-write.properties (rev 0)
+++ trunk/tutti-persistence/src/test/resources/tutti-test-write.properties 2013-02-10 13:41:29 UTC (rev 379)
@@ -0,0 +1,24 @@
+###
+# #%L
+# Tutti :: Persistence API
+# $Id$
+# $HeadURL$
+# %%
+# Copyright (C) 2012 Ifremer
+# %%
+# 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%
+###
+tutti.persistence.jdbc.createScript=src/test/db/allegro.script
Deleted: trunk/tutti-persistence/src/test/resources/tutti-test.properties
===================================================================
--- trunk/tutti-persistence/src/test/resources/tutti-test.properties 2013-02-09 07:44:17 UTC (rev 378)
+++ trunk/tutti-persistence/src/test/resources/tutti-test.properties 2013-02-10 13:41:29 UTC (rev 379)
@@ -1,26 +0,0 @@
-###
-# #%L
-# Tutti :: Persistence API
-# $Id$
-# $HeadURL$
-# %%
-# Copyright (C) 2012 Ifremer
-# %%
-# 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%
-###
-#tutti.persistence.jdbc.url=jdbc:hsqldb:file:src/test/db/allegro
-tutti.persistence.jdbc.url=jdbc:hsqldb:hsql://localhost/allegro
-tutti.persistence.jdbc.createScript=src/test/db/allegro.script
1
0
09 Feb '13
Author: tchemit
Date: 2013-02-09 08:44:17 +0100 (Sat, 09 Feb 2013)
New Revision: 378
Url: http://forge.codelutin.com/projects/tutti/repository/revisions/378
Log:
fix i18n
Modified:
trunk/tutti-service/src/main/resources/i18n/tutti-service_fr_FR.properties
Modified: trunk/tutti-service/src/main/resources/i18n/tutti-service_fr_FR.properties
===================================================================
--- trunk/tutti-service/src/main/resources/i18n/tutti-service_fr_FR.properties 2013-02-09 00:52:52 UTC (rev 377)
+++ trunk/tutti-service/src/main/resources/i18n/tutti-service_fr_FR.properties 2013-02-09 07:44:17 UTC (rev 378)
@@ -1,4 +1,3 @@
-tutti.option.config.directory.description=Répertoire des configurations externalisées de l'application (configuration de base / internationalisation).
tutti.option.csv.separator.description=Caractère séparateur pour les import / export de fichier au format csv.
tutti.option.data.directory.description=Répertoire de données de l'application. Vous pouvez utiliser l'expression ${tutti.data.directory} pour le référence dans d'autres propriétés de configuration (ex\: ${tutti.data.directory}/tmp).
tutti.option.inceptionYear.description=Année de démarrage du projet.
@@ -10,7 +9,6 @@
tutti.property.caracteristic=Caractéristique
tutti.property.country=Pays
tutti.property.cruise=Campagne
-tutti.property.cruiseCode=Code campagne
tutti.property.date=Date
tutti.property.department=Département
tutti.property.firstName=Prénom
@@ -30,20 +28,19 @@
tutti.property.parameterName=Paramètre
tutti.property.program=Série de campagne
tutti.property.protocol=Protocol de saisie
-tutti.property.refTaxCode=Code permanent
+tutti.property.refTaxCode=Code RefTax
tutti.property.sortedUnsortedCategory=Vrac / Hors Vrac
tutti.property.species=Espèce
tutti.property.stationNumber=Numéro de station
tutti.property.strata=Strate d'association
-tutti.property.surveyCode=
+tutti.property.surveyCode=Code campagne
tutti.property.user=Utilisateur
tutti.property.vessel=Navire
tutti.property.zone=Zone
tutti.property.zoneLabel=Zone
tutti.propety.no.species.refTaxCode=\#
tutti.propety.no.species.surveyCode=\#
-tutti.propety.no.vessel.internalRegistrationCode=Immatriculation inconnu
-tutti.propety.no.vessel.internationalRegistrationCode=
+tutti.propety.no.vessel.internationalRegistrationCode=Immatriculation inconnu
tutti.propety.no.vessel.name=Nom inconnu
tutti.propety.no.zone=Pas de zone
tutti.service.config=Configuration des services de Tutti
1
0
r377 - in trunk/tutti-persistence/src: main/java/fr/ifremer/tutti/persistence/service main/resources test/java/fr/ifremer/tutti/persistence/service
by blavenier@users.forge.codelutin.com 09 Feb '13
by blavenier@users.forge.codelutin.com 09 Feb '13
09 Feb '13
Author: blavenier
Date: 2013-02-09 01:52:52 +0100 (Sat, 09 Feb 2013)
New Revision: 377
Url: http://forge.codelutin.com/projects/tutti/repository/revisions/377
Log:
Add :
- importTemporaryGear
- importTemporaryPerson
- importTemporaryVessel
- importTemporarySpecies
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/TuttiEnumerationFile.java
trunk/tutti-persistence/src/main/resources/applicationContext-service-tutti.xml
trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceServiceTest.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 23:17:53 UTC (rev 376)
+++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceServiceImpl.java 2013-02-09 00:52:52 UTC (rev 377)
@@ -24,9 +24,33 @@
* #L%
*/
+import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.annotation.Resource;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.hibernate.Query;
+import org.hibernate.type.DateType;
+import org.hibernate.type.IntegerType;
+import org.hibernate.type.StringType;
+import org.springframework.cache.annotation.CacheEvict;
+import org.springframework.cache.annotation.CachePut;
+import org.springframework.cache.annotation.Cacheable;
+import org.springframework.dao.DataIntegrityViolationException;
+import org.springframework.dao.DataRetrievalFailureException;
+import org.springframework.stereotype.Service;
+
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
+
+import fr.ifremer.adagio.core.dao.administration.user.PersonExtendDao;
+import fr.ifremer.adagio.core.dao.data.vessel.VesselExtendDao;
import fr.ifremer.adagio.core.dao.referential.StatusDao;
+import fr.ifremer.adagio.core.dao.referential.gear.FishingGearExtendDao;
+import fr.ifremer.adagio.core.dao.referential.location.LocationExtendDao;
import fr.ifremer.adagio.core.dao.referential.taxon.TaxonNameExtendDao;
import fr.ifremer.adagio.core.dao.referential.taxon.TaxonRefTaxVO;
import fr.ifremer.tutti.persistence.entities.TuttiEntities;
@@ -43,22 +67,7 @@
import fr.ifremer.tutti.persistence.entities.referential.Status;
import fr.ifremer.tutti.persistence.entities.referential.Vessel;
import fr.ifremer.tutti.persistence.entities.referential.Zone;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.hibernate.Query;
-import org.hibernate.type.DateType;
-import org.hibernate.type.IntegerType;
-import org.hibernate.type.StringType;
-import org.springframework.cache.annotation.CacheEvict;
-import org.springframework.cache.annotation.Cacheable;
-import org.springframework.dao.DataRetrievalFailureException;
-import org.springframework.stereotype.Service;
-import javax.annotation.Resource;
-import java.util.Date;
-import java.util.Iterator;
-import java.util.List;
-
/**
* Implementation of the {@link ReferentialPersistenceService} using a adagio
* data-source.
@@ -78,8 +87,19 @@
@Resource(name = "statusDao")
protected StatusDao statusDao;
+
+ @Resource(name = "personDao")
+ protected PersonExtendDao personDao;
+ @Resource(name = "fishingGearDao")
+ protected FishingGearExtendDao fishingGearDao;
+ @Resource(name = "vesselExtendDao")
+ protected VesselExtendDao vesselExtendDao;
+
+ @Resource(name = "locationDao")
+ protected LocationExtendDao locationDao;
+
//------------------------------------------------------------------------//
//-- ReferentialPersistenceService implentation --//
//------------------------------------------------------------------------//
@@ -302,6 +322,9 @@
Object[] source = queryUnique(
"person",
"personId", IntegerType.INSTANCE, personId);
+
+ if (source == null) return null;
+
Person result = loadPerson(source);
return result;
}
@@ -311,6 +334,9 @@
Object[] source = queryUnique(
"gear",
"gearId", IntegerType.INSTANCE, gearId);
+
+ if (source == null) return null;
+
Gear result = loadGear(source);
return result;
}
@@ -328,10 +354,21 @@
TaxonRefTaxVO[] sources = taxonNameDao.getAllTaxonNames(true);
List<Species> result = Lists.newArrayListWithCapacity(sources.length);
+ List<Species> referenceTaxonsOnly = Lists.newArrayList();
for (TaxonRefTaxVO source : sources) {
Species target = loadSpecies(source);
+ if (target.isReferenceTaxon()) {
+
+ // Add to cache :
+ putToSpeciesReferentCache(Integer.valueOf(target.getReferenceTaxonId()), target);
+ referenceTaxonsOnly.add(target);
+ }
result.add(target);
}
+
+ // Add to cache :
+ putToSpeciesReferentCache(referenceTaxonsOnly);
+
return result;
}
@@ -347,13 +384,17 @@
continue;
}
Species target = loadSpecies(source);
+
+ // Add to cache :
+ putToSpeciesReferentCache(Integer.valueOf(target.getReferenceTaxonId()), target);
+
result.add(target);
}
return result;
}
@Override
- //TODO manage Cacheable(value = "species")
+ @Cacheable(value = "species", key="#speciesId")
public Species getSpeciesByReferenceTaxonId(Integer speciesId) {
try {
TaxonRefTaxVO source = taxonNameDao.getTaxonNameReferent(
@@ -379,8 +420,14 @@
// Skip some protected PSFM
if (!isProtectedCaracteristic(pmfmId)) {
Caracteristic target = loadCaracteristic(source);
+ putToCaracteristicCache(pmfmId, target);
+
result.add(target);
}
+ // If protected, load anyway just for the cache
+ else {
+ putToCaracteristicCache(pmfmId, loadCaracteristic(source));
+ }
}
return result;
}
@@ -437,7 +484,7 @@
}
@Override
- //TODO manage Cacheable(value = "pmfms")
+ @Cacheable(value = "pmfms", key="#pmfmId")
public Caracteristic getCaracteristic(Integer pmfmId) {
Object[] source = queryUniqueWithStatus("pmfmById",
"pmfmId", IntegerType.INSTANCE, pmfmId,
@@ -447,7 +494,7 @@
}
@Override
- @CacheEvict(value = {"species", "referentSpecies"})
+ @CacheEvict(value = {"species", "referentSpecies"}, allEntries=true )
public List<Species> importTemporarySpecies(List<Species> species) {
List<Species> result = Lists.newArrayList();
for (Species source : species) {
@@ -458,44 +505,149 @@
}
@Override
- @CacheEvict(value = "fishingVessels")
+ @CacheEvict(value = "fishingVessels", allEntries=true )
public List<Vessel> importTemporaryVessel(List<Vessel> vessels) {
- //TODO
- return null;
+ List<Vessel> result = Lists.newArrayList();
+
+ fr.ifremer.adagio.core.dao.referential.Status status =
+ statusDao.load(enumeration.STATUS_TEMPORARY_CODE);
+ Integer countryLocationId =
+ locationDao.getLocationIdByLabelAndLocationLevel(
+ enumeration.LOCATION_LABEL_DEFAULT_COUNTRY,
+ new Integer[]{enumeration.LOCATION_LEVEL_ID_COUNTRY});
+ if (countryLocationId == null) {
+ throw new DataIntegrityViolationException("Default country location not found, with label=" + enumeration.LOCATION_LABEL_DEFAULT_COUNTRY);
+ }
+
+ for (Vessel source : vessels) {
+ source = importTemporaryVessel(source, countryLocationId, status);
+ result.add(source);
+ }
+ return result;
}
@Override
- @CacheEvict(value = "persons")
+ @CacheEvict(value = "persons", allEntries=true )
public List<Person> importTemporaryPerson(List<Person> persons) {
- //TODO
- return null;
+ List<Person> result = Lists.newArrayList();
+
+ fr.ifremer.adagio.core.dao.referential.Status status =
+ statusDao.load(enumeration.STATUS_TEMPORARY_CODE);
+ for (Person source : persons) {
+ source = importTemporaryPerson(source, status);
+ result.add(source);
+ }
+ return result;
}
@Override
- @CacheEvict(value = "gears")
+ @CacheEvict(value = "gears", allEntries=true )
public List<Gear> importTemporaryGear(List<Gear> gears) {
- //TODO
- return null;
+ List<Gear> result = Lists.newArrayList();
+
+ fr.ifremer.adagio.core.dao.referential.Status status =
+ statusDao.load(enumeration.STATUS_TEMPORARY_CODE);
+ for (Gear source : gears) {
+ source = importTemporaryGear(source, status);
+ result.add(source);
+ }
+ return result;
}
//------------------------------------------------------------------------//
//-- Internal methods --//
//------------------------------------------------------------------------//
+ public Vessel importTemporaryVessel(Vessel source, Integer registrationLocationId, fr.ifremer.adagio.core.dao.referential.Status status) {
+ Preconditions.checkNotNull(source);
+ Preconditions.checkNotNull(source.getName());
+ Preconditions.checkNotNull(source.getInternationalRegistrationCode());
+
+ Integer vesselTypeId = null;
+ if (source.isScientificVessel()) {
+ vesselTypeId = enumeration.VESSEL_TYPE_ID_SCIENTIFIC;
+ }
+ else {
+ vesselTypeId = enumeration.VESSEL_TYPE_ID_FISHING;
+ }
+
+ fr.ifremer.adagio.core.dao.referential.vessel.Vessel target =
+ vesselExtendDao.createAsTemporary(
+ null,
+ source.getInternationalRegistrationCode(),
+ registrationLocationId, source.getName(),
+ vesselTypeId);
+
+ // Fill the result bean
+ Vessel result = new Vessel();
+ result.setId(target.getCode());
+ result.setName(source.getName());
+ result.setRegistrationCode(source.getRegistrationCode());
+ result.setInternationalRegistrationCode(source.getInternationalRegistrationCode());
+ result.setScientificVessel(source.isScientificVessel());
+ setStatus(status, result);
+ return result;
+ }
+
+ public Person importTemporaryPerson(Person source, fr.ifremer.adagio.core.dao.referential.Status status) {
+ Preconditions.checkNotNull(source);
+ Preconditions.checkNotNull(source.getFirstName());
+ Preconditions.checkNotNull(source.getLastName());
+
+ fr.ifremer.adagio.core.dao.administration.user.Person target = personDao.createAsTemporary(source.getLastName(), source.getFirstName(), enumeration.DEPARTMENT_ID_UNKNOWN_RECORDER_DEPARTMENT);
+
+ // Fill the result bean
+ Person result = new Person();
+ result.setId(target.getId().toString());
+ result.setLastName(source.getLastName());
+ result.setFirstName(source.getFirstName());
+ setStatus(status, result);
+ return result;
+ }
+
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).");
+ taxonName = taxonNameDao.createAsTemporary(
+ taxonName,
+ "Added by tutti (file import).");
// update the source
Species result = loadSpecies(taxonName);
+
+ // Add to cache
+ putToSpeciesReferentCache(Integer.valueOf(result.getId()), result);
return result;
}
+
+ public Gear importTemporaryGear(Gear source, fr.ifremer.adagio.core.dao.referential.Status status) {
+ Preconditions.checkNotNull(source);
+ Preconditions.checkNotNull(source.getLabel());
+ Preconditions.checkNotNull(source.getName());
+ Integer gearClassificationId = null;
+ if (source.isScientificGear()) {
+ gearClassificationId = enumeration.GEAR_CLASSIFICIATION_ID_SCIENTIFIC;
+ }
+ else {
+ gearClassificationId = enumeration.GEAR_CLASSIFICIATION_ID_FISHING;
+ }
+
+ fr.ifremer.adagio.core.dao.referential.gear.Gear target = fishingGearDao.createAsTemporary(source.getLabel(), source.getName(), gearClassificationId);
+
+ // Fill the result bean
+ Gear result = new Gear();
+ result.setId(target.getId().toString());
+ result.setLabel(source.getLabel());
+ result.setName(source.getName());
+ setStatus(status, result);
+ return result;
+ }
+
protected List<FishingOperationLocation> getFishingOperationLocations(Integer locationLevelId) {
Iterator<Object[]> sources = queryListWithStatus(
"allFishingOperationLocation",
@@ -685,4 +837,19 @@
return sampleCategory;
}
+ @Cacheable(value = "pmfms", key = "#pmfmId")
+ protected Caracteristic putToCaracteristicCache(Integer pmfmId, Caracteristic caracteristic) {
+ return caracteristic;
+ }
+
+ @CachePut(value = "referentSpecies")
+ protected List<Species> putToSpeciesReferentCache(List<Species> species) {
+ return species;
+ }
+
+ @CachePut(value = "referentSpecies", key = "#speciesId")
+ protected Species putToSpeciesReferentCache(Integer speciesId, Species species) {
+ return species;
+ }
+
}
Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/TuttiEnumerationFile.java
===================================================================
--- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/TuttiEnumerationFile.java 2013-02-08 23:17:53 UTC (rev 376)
+++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/TuttiEnumerationFile.java 2013-02-09 00:52:52 UTC (rev 377)
@@ -47,6 +47,9 @@
@Value("${LocationClassificationId.SECTOR}")
public final Integer LOCATION_CLASSIFICATION_ID_SECTOR = null;
+ @Value("${LocationLabel.FRANCE}")
+ public final String LOCATION_LABEL_DEFAULT_COUNTRY = null;
+
@Value("${LocationLevelId.PAYS_ISO3}")
public final Integer LOCATION_LEVEL_ID_COUNTRY = null;
Modified: trunk/tutti-persistence/src/main/resources/applicationContext-service-tutti.xml
===================================================================
--- trunk/tutti-persistence/src/main/resources/applicationContext-service-tutti.xml 2013-02-08 23:17:53 UTC (rev 376)
+++ trunk/tutti-persistence/src/main/resources/applicationContext-service-tutti.xml 2013-02-09 00:52:52 UTC (rev 377)
@@ -73,10 +73,12 @@
<bean id="tuttiSpeciesCache" parent="tuttiAbstractEternalCache">
<property name="cacheName" value="species" />
+ <property name="maxElementsInMemory" value="20000"/>
</bean>
<bean id="tuttiReferentSpeciesCache" parent="tuttiAbstractEternalCache">
- <property name="cacheName" value="referentSpecies" />
+ <property name="cacheName" value="referentSpecies" />
+ <property name="maxElementsInMemory" value="10000"/>
</bean>
<bean id="tuttiGearsCache" parent="tuttiAbstractEternalCache">
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 23:17:53 UTC (rev 376)
+++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceServiceTest.java 2013-02-09 00:52:52 UTC (rev 377)
@@ -398,7 +398,6 @@
Assert.assertEquals(createdSp2, service.getSpeciesByReferenceTaxonId(createdSp2.getReferenceTaxonId()));
}
- @Ignore
@Test
public void importVessel() {
List<Vessel> vessels = Lists.newArrayList();
@@ -418,7 +417,7 @@
v2.setId("Don't care" + timestamp2);
v2.setName("Name" + timestamp2);
v2.setInternationalRegistrationCode("Immat" + timestamp2);
- v1.setScientificVessel(false);
+ v2.setScientificVessel(false);
vessels.add(v2);
Assert.assertNull(service.getVessel(v1.getId()));
@@ -450,11 +449,10 @@
Assert.assertNotNull(createdV2.getId());
Assert.assertNotSame(v2.getId(), createdV2.getId());
Assert.assertEquals(createdV2, service.getVessel(createdV2.getId()));
- Assert.assertFalse(allScientificVessel.contains(createdV1));
- Assert.assertTrue(allFishingVessel.contains(createdV1));
+ Assert.assertFalse(allScientificVessel.contains(createdV2));
+ Assert.assertTrue(allFishingVessel.contains(createdV2));
}
- @Ignore
@Test
public void importPerson() {
List<Person> persons = Lists.newArrayList();
@@ -479,9 +477,6 @@
p2.setDepartment("Don't care" + timestamp2);
persons.add(p2);
- Assert.assertNull(service.getPerson(Integer.valueOf(p1.getId())));
- Assert.assertNull(service.getPerson(Integer.valueOf(p2.getId())));
-
List<Person> personList = service.importTemporaryPerson(persons);
Assert.assertNotNull(personList);
@@ -517,7 +512,6 @@
Assert.assertEquals(createdP2, service.getPerson(Integer.valueOf(createdP2.getId())));
}
- @Ignore
@Test
public void importGear() {
List<Gear> gears = Lists.newArrayList();
@@ -527,9 +521,9 @@
Gear g1 = new Gear();
g1.setId("Don't care" + timestamp1);
g1.setDescription("Don't care" + timestamp1);
- g1.setScientificGear(true);
g1.setName("Name" + timestamp1);
g1.setLabel("Label" + timestamp1);
+ g1.setScientificGear(true);
gears.add(g1);
// fishing gear
@@ -539,7 +533,7 @@
g2.setDescription("Don't care" + timestamp2);
g2.setName("Name" + timestamp2);
g2.setLabel("Label" + timestamp2);
- g1.setScientificGear(false);
+ g2.setScientificGear(false);
gears.add(g2);
@@ -567,9 +561,24 @@
Assert.assertNotNull(createdG2.getId());
Assert.assertNotSame(g2.getId(), createdG2.getId());
Assert.assertEquals(createdG2, service.getGear(Integer.valueOf(createdG2.getId())));
- Assert.assertFalse(allScientificGear.contains(createdG1));
- Assert.assertTrue(allFishingGear.contains(createdG1));
+ Assert.assertFalse(allScientificGear.contains(createdG2));
+ Assert.assertTrue(allFishingGear.contains(createdG2));
}
+
+ @Test
+ @Ignore
+ public void testCaches() {
+ cacheService.clearAllCaches();
+
+ Object obj = service.getAllCaracteristic();
+ System.out.println(obj);
+
+ obj = service.getCaracteristic(1429);
+ System.out.println(obj);
+
+ obj = service.getCaracteristic(1428);
+ System.out.println(obj);
+ }
protected <S extends IdAware> void persistList(Class<S> type, List<S> result) {
persistList(type, null, result);
1
0
r376 - trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol
by tchemit@users.forge.codelutin.com 08 Feb '13
by tchemit@users.forge.codelutin.com 08 Feb '13
08 Feb '13
Author: tchemit
Date: 2013-02-09 00:17:53 +0100 (Sat, 09 Feb 2013)
New Revision: 376
Url: http://forge.codelutin.com/projects/tutti/repository/revisions/376
Log:
use action to add or remove species protocol
Added:
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/AddSpeciesProtocolAction.java
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/RemoveSpeciesProtocolAction.java
Modified:
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolUI.css
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
Added: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/AddSpeciesProtocolAction.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/AddSpeciesProtocolAction.java (rev 0)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/AddSpeciesProtocolAction.java 2013-02-08 23:17:53 UTC (rev 376)
@@ -0,0 +1,84 @@
+package fr.ifremer.tutti.ui.swing.content.protocol;
+
+/*
+ * #%L
+ * Tutti :: UI
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2012 - 2013 Ifremer
+ * %%
+ * 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%
+ */
+
+import com.google.common.base.Preconditions;
+import fr.ifremer.tutti.persistence.entities.referential.Species;
+import fr.ifremer.tutti.ui.swing.AbstractTuttiAction;
+
+import java.awt.event.ActionEvent;
+
+import static org.nuiton.i18n.I18n._;
+
+/**
+ * To add a new species protocol.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.0
+ */
+public class AddSpeciesProtocolAction extends AbstractTuttiAction<EditProtocolUIModel, EditProtocolUI, EditProtocolUIHandler> {
+
+ private static final long serialVersionUID = 1L;
+
+ public AddSpeciesProtocolAction(EditProtocolUIHandler handler) {
+ super(handler,
+ "addSpeciesProtocol",
+ "add",
+ null,
+ _("tutti.action.addSpeciesProtocol.tip"),
+ false
+ );
+ }
+
+ @Override
+ protected void doAction(ActionEvent event) {
+
+
+ EditProtocolUI ui = getUI();
+
+ EditProtocolSpeciesTableModel tableModel = getHandler().getTableModel();
+ Species species = (Species) ui.getSpeciesComboBox().getSelectedItem();
+ Preconditions.checkNotNull(species);
+ EditProtocolSpeciesRowModel protocol = tableModel.createNewRow();
+
+ Integer taxonId = species.getReferenceTaxonId();
+
+ // get referent species
+ String taxonIdStr = String.valueOf(taxonId);
+ Species referentSpecies = getHandler().getAllReferentSpeciesByTaxonId().get(taxonIdStr);
+ protocol.setSpecies(referentSpecies);
+ tableModel.addNewRow(protocol);
+
+ // remove all synonyms of this taxon
+ getHandler().removeSpeciesSynonyms(ui.getSpeciesComboBox().getData(), taxonIdStr);
+ ui.getSpeciesComboBox().getHandler().sortData();
+
+ getHandler().selectFirstInCombo(ui.getSpeciesComboBox());
+
+ getModel().setModify(true);
+
+ }
+
+}
\ No newline at end of file
Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/AddSpeciesProtocolAction.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolUI.css
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolUI.css 2013-02-08 23:17:15 UTC (rev 375)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolUI.css 2013-02-08 23:17:53 UTC (rev 376)
@@ -76,8 +76,8 @@
enabled: {!speciesComboBox.isEmpty()};
}
-#addRow {
- actionIcon: add;
+#addSpeciesProtocol {
+ _tuttiAction: {AddSpeciesProtocolAction.class};
enabled: {speciesComboBox.getSelectedItem() != null};
}
@@ -85,11 +85,10 @@
label: "tutti.title.batchActions";
}
-#removeSpeciesMenu {
- text: "tutti.action.removeSpecies";
- mnemonic: R;
- actionIcon: batch-delete;
+#removeSpeciesProtocol {
+ _tuttiAction: {RemoveSpeciesProtocolAction.class};
enabled: {model.isRemoveSpeciesEnabled()};
+ mnemonic: R;
}
#speciesTable {
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 23:17:15 UTC (rev 375)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolUI.jaxx 2013-02-08 23:17:53 UTC (rev 376)
@@ -77,8 +77,7 @@
</BeanValidator>
<JPopupMenu id='tablePopup'>
- <JMenuItem id='removeSpeciesMenu'
- onActionPerformed='handler.removeSpeciesRow()'/>
+ <JMenuItem id='removeSpeciesProtocol'/>
</JPopupMenu>
<JTabbedPane constraints='BorderLayout.CENTER'>
@@ -151,7 +150,7 @@
genericType='Species'/>
</cell>
<cell fill='both'>
- <JButton id='addRow' onActionPerformed='handler.addSpeciesRow()'/>
+ <JButton id='addSpeciesProtocol'/>
</cell>
</row>
<row fill='both' weighty='1'>
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 23:17:15 UTC (rev 375)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolUIHandler.java 2013-02-08 23:17:53 UTC (rev 376)
@@ -24,7 +24,6 @@
* #L%
*/
-import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
import com.google.common.collect.Multimap;
import com.google.common.collect.Multimaps;
@@ -189,6 +188,10 @@
return allReferentSpeciesByTaxonId;
}
+ public Multimap<String, Species> getAllSpeciesByTaxonId() {
+ return allSpeciesByTaxonId;
+ }
+
@Override
public void afterInitUI() {
@@ -393,47 +396,6 @@
//-- Public methods --//
//------------------------------------------------------------------------//
- public void addSpeciesRow() {
- Species species = (Species) ui.getSpeciesComboBox().getSelectedItem();
- Preconditions.checkNotNull(species);
- EditProtocolSpeciesRowModel protocol = getTableModel().createNewRow();
-
- Integer taxonId = species.getReferenceTaxonId();
-
- // get referent species
- String taxonIdStr = String.valueOf(taxonId);
- Species referentSpecies = allReferentSpeciesByTaxonId.get(taxonIdStr);
- protocol.setSpecies(referentSpecies);
- getTableModel().addNewRow(protocol);
-
- // 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 removeSpeciesRow() {
- int rowIndex = getTable().getSelectedRow();
-
- Preconditions.checkState(rowIndex != -1,
- "Cant remove species if no species selected");
-
- // remove the row from the model
- 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);
- }
-
public void addDoubleListListeners() {
String id;
UpdateSelectedList updateListener;
@@ -579,7 +541,6 @@
valueIsAdjusting = false;
}
}
-
}
public void select(List<String> selectedIds) {
@@ -592,6 +553,5 @@
}
model.setSelected(selection);
}
-
}
}
Added: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/RemoveSpeciesProtocolAction.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/RemoveSpeciesProtocolAction.java (rev 0)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/RemoveSpeciesProtocolAction.java 2013-02-08 23:17:53 UTC (rev 376)
@@ -0,0 +1,75 @@
+package fr.ifremer.tutti.ui.swing.content.protocol;
+
+/*
+ * #%L
+ * Tutti :: UI
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2012 - 2013 Ifremer
+ * %%
+ * 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%
+ */
+
+import com.google.common.base.Preconditions;
+import fr.ifremer.tutti.ui.swing.AbstractTuttiAction;
+
+import java.awt.event.ActionEvent;
+
+import static org.nuiton.i18n.I18n._;
+
+/**
+ * To add a new species protocol.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.0
+ */
+public class RemoveSpeciesProtocolAction extends AbstractTuttiAction<EditProtocolUIModel, EditProtocolUI, EditProtocolUIHandler> {
+
+ private static final long serialVersionUID = 1L;
+
+ public RemoveSpeciesProtocolAction(EditProtocolUIHandler handler) {
+ super(handler,
+ "removeSpeciesProtocol",
+ "batch-delete",
+ null,
+ _("tutti.action.removeSpeciesProtocol.tip"),
+ false
+ );
+ }
+
+ @Override
+ protected void doAction(ActionEvent event) {
+
+ EditProtocolUIHandler handler = getHandler();
+ int rowIndex = handler.getTable().getSelectedRow();
+
+ Preconditions.checkState(rowIndex != -1,
+ "Cant remove species if no species selected");
+
+ // remove the row from the model
+ EditProtocolSpeciesRowModel removedRow = getModel().getRows().remove(rowIndex);
+
+ // readd all synonym of this taxon to the species comobox
+ Integer taxonId = removedRow.getSpecies().getReferenceTaxonId();
+ getUI().getSpeciesComboBox().getData().addAll(handler.getAllSpeciesByTaxonId().get(String.valueOf(taxonId)));
+ getUI().getSpeciesComboBox().getHandler().sortData();
+
+ // refresh all the table
+ handler.getTableModel().fireTableRowsDeleted(rowIndex, rowIndex);
+ }
+
+}
\ No newline at end of file
Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/RemoveSpeciesProtocolAction.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
1
0