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
- 4058 discussions
r700 - in trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation: catches catches/species/frequency fishing
by kmorin@users.forge.codelutin.com 28 Mar '13
by kmorin@users.forge.codelutin.com 28 Mar '13
28 Mar '13
Author: kmorin
Date: 2013-03-28 14:45:30 +0100 (Thu, 28 Mar 2013)
New Revision: 700
Url: http://forge.codelutin.com/projects/tutti/repository/revisions/700
Log:
fixes #2106 [ESPECE] - saisie des mensurations : cliquer sur "simple d?\195?\169nombrement" alors qu'il y a des mensurations de saisie
Modified:
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUIHandler.java
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUI.css
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUIModel.java
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/fishing/AbstractCaracteristicTabUIModel.java
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUIHandler.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUIHandler.java 2013-03-28 12:54:20 UTC (rev 699)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUIHandler.java 2013-03-28 13:45:30 UTC (rev 700)
@@ -184,9 +184,7 @@
protected boolean onTabChanged(int currentIndex, int newIndex) {
ui.getCatchesCaracteristicsAttachmentsButton().onCloseUI();
ui.getSpeciesTabContent().getSpeciesBatchAttachmentsButton().onCloseUI();
- setSpeciesSelectedCard(EditCatchesUIHandler.MAIN_CARD);
ui.getBenthosTabContent().getBenthosBatchAttachmentsButton().onCloseUI();
- setBenthosSelectedCard(EditCatchesUIHandler.MAIN_CARD);
return super.onTabChanged(currentIndex, newIndex);
}
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUI.css
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUI.css 2013-03-28 12:54:20 UTC (rev 699)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUI.css 2013-03-28 13:45:30 UTC (rev 700)
@@ -235,7 +235,7 @@
#dataInFrequenciesWarningContainer {
background: {new java.awt.Color(245, 218, 88)};
- visible: {!org.apache.commons.collections.CollectionUtils.isEmpty(model.getBatch().getFrequency())};
+ visible: {model.getRowsInError().isEmpty()};
}
#dataInFrequenciesWarning {
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUIModel.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUIModel.java 2013-03-28 12:54:20 UTC (rev 699)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUIModel.java 2013-03-28 13:45:30 UTC (rev 700)
@@ -28,6 +28,9 @@
import fr.ifremer.tutti.ui.swing.content.operation.catches.species.SpeciesBatchRowModel;
import fr.ifremer.tutti.ui.swing.util.table.AbstractTuttiTableUIModel;
+import java.util.Collections;
+import java.util.List;
+
/**
* @author tchemit <chemit(a)codelutin.com>
* @since 0.2
@@ -234,4 +237,10 @@
}
return result;
}
+
+ // method with an argument for the binding
+ public boolean isOneRowValid(List<SpeciesFrequencyRowModel> frequencies) {
+ return isOneRowValid();
+ }
+
}
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/fishing/AbstractCaracteristicTabUIModel.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/fishing/AbstractCaracteristicTabUIModel.java 2013-03-28 12:54:20 UTC (rev 699)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/fishing/AbstractCaracteristicTabUIModel.java 2013-03-28 13:45:30 UTC (rev 700)
@@ -25,6 +25,9 @@
* #L%
*/
+import com.google.common.base.Predicate;
+import com.google.common.base.Predicates;
+import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;
import fr.ifremer.tutti.persistence.entities.CaracteristicMap;
import fr.ifremer.tutti.persistence.entities.data.FishingOperation;
@@ -32,6 +35,7 @@
import fr.ifremer.tutti.ui.swing.util.AbstractTuttiBeanUIModel;
import fr.ifremer.tutti.ui.swing.util.TabContentModel;
import fr.ifremer.tutti.ui.swing.util.table.AbstractTuttiTableUIModel;
+import org.apache.commons.lang3.ObjectUtils;
import java.io.Serializable;
import java.util.List;
@@ -104,13 +108,8 @@
@Override
public boolean isEmpty() {
- boolean result = caracteristicMap == null;
- if (!result) {
- Set s = Sets.newHashSet(caracteristicMap.values());
- s.remove(null);
- result = s.isEmpty();
- }
- return result;
+ return caracteristicMap == null
+ || Iterables.all(caracteristicMap.values(), Predicates.isNull());
}
@Override
1
0
r699 - in trunk/tutti-ui-swing/src/main: filtered-resources java/fr/ifremer/tutti/ui/swing/config java/fr/ifremer/tutti/ui/swing/content
by kmorin@users.forge.codelutin.com 28 Mar '13
by kmorin@users.forge.codelutin.com 28 Mar '13
28 Mar '13
Author: kmorin
Date: 2013-03-28 13:54:20 +0100 (Thu, 28 Mar 2013)
New Revision: 699
Url: http://forge.codelutin.com/projects/tutti/repository/revisions/699
Log:
refs #1840 [REFERENTIEL] - Gestion des fonctionnalit?\195?\169s administrateur
Modified:
trunk/tutti-ui-swing/src/main/filtered-resources/tutti.config
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/config/TuttiApplicationConfig.java
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/config/TuttiApplicationConfigOption.java
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/ImportTemporaryReferentialAction.java
Modified: trunk/tutti-ui-swing/src/main/filtered-resources/tutti.config
===================================================================
--- trunk/tutti-ui-swing/src/main/filtered-resources/tutti.config 2013-03-28 10:05:30 UTC (rev 698)
+++ trunk/tutti-ui-swing/src/main/filtered-resources/tutti.config 2013-03-28 12:54:20 UTC (rev 699)
@@ -24,6 +24,4 @@
tutti.version=${project.version}
tutti.site.url=${project.url}
tutti.inceptionYear=${project.inceptionYear}
-tutti.organizationName=${license.organizationName}
-# the password is ifremer
-tutti.admin.password=ef399a6e6ec62c6e142440241a5b98f8
\ No newline at end of file
+tutti.organizationName=${license.organizationName}
\ No newline at end of file
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/config/TuttiApplicationConfig.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/config/TuttiApplicationConfig.java 2013-03-28 10:05:30 UTC (rev 698)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/config/TuttiApplicationConfig.java 2013-03-28 12:54:20 UTC (rev 699)
@@ -349,4 +349,8 @@
public String getUpdateUrl() {
return applicationConfig.getOption(TuttiApplicationConfigOption.TUTTI_UPDATE_URL.getKey());
}
+
+ public String getAdminPassword() {
+ return applicationConfig.getOption(TuttiApplicationConfigOption.ADMIN_PASSWORD.getKey());
+ }
}
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/config/TuttiApplicationConfigOption.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/config/TuttiApplicationConfigOption.java 2013-03-28 10:05:30 UTC (rev 698)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/config/TuttiApplicationConfigOption.java 2013-03-28 12:54:20 UTC (rev 699)
@@ -207,6 +207,14 @@
n_("tutti.config.option.ui.dateFormat.description"),
"dd/MM/yyyy",
String.class
+ ),
+
+ ADMIN_PASSWORD(
+ "tutti.admin.password",
+ n_("tutti.config.option.ui.dateFormat.description"),
+ // "ifremer" by default
+ "ef399a6e6ec62c6e142440241a5b98f8",
+ String.class
);
/** Configuration key. */
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/ImportTemporaryReferentialAction.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/ImportTemporaryReferentialAction.java 2013-03-28 10:05:30 UTC (rev 698)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/ImportTemporaryReferentialAction.java 2013-03-28 12:54:20 UTC (rev 699)
@@ -56,7 +56,7 @@
JOptionPane.WARNING_MESSAGE);
if (answer != null) {
String cryptedAnswer = StringUtil.encodeMD5(answer);
- String correctAnswer = getConfig().getApplicationConfig().getOption("tutti.admin.password");
+ String correctAnswer = getConfig().getAdminPassword();
result = StringUtils.equals(cryptedAnswer, correctAnswer);
if (!result) {
1
0
r698 - in trunk/tutti-ui-swing/src/main: filtered-resources java/fr/ifremer/tutti/ui/swing/content resources/i18n
by kmorin@users.forge.codelutin.com 28 Mar '13
by kmorin@users.forge.codelutin.com 28 Mar '13
28 Mar '13
Author: kmorin
Date: 2013-03-28 11:05:30 +0100 (Thu, 28 Mar 2013)
New Revision: 698
Url: http://forge.codelutin.com/projects/tutti/repository/revisions/698
Log:
fixes #1840 [REFERENTIEL] - Gestion des fonctionnalit?\195?\169s administrateur
Modified:
trunk/tutti-ui-swing/src/main/filtered-resources/tutti.config
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/ImportTemporaryReferentialAction.java
trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_en_GB.properties
trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_fr_FR.properties
Modified: trunk/tutti-ui-swing/src/main/filtered-resources/tutti.config
===================================================================
--- trunk/tutti-ui-swing/src/main/filtered-resources/tutti.config 2013-03-28 00:20:21 UTC (rev 697)
+++ trunk/tutti-ui-swing/src/main/filtered-resources/tutti.config 2013-03-28 10:05:30 UTC (rev 698)
@@ -24,4 +24,6 @@
tutti.version=${project.version}
tutti.site.url=${project.url}
tutti.inceptionYear=${project.inceptionYear}
-tutti.organizationName=${license.organizationName}
\ No newline at end of file
+tutti.organizationName=${license.organizationName}
+# the password is ifremer
+tutti.admin.password=ef399a6e6ec62c6e142440241a5b98f8
\ No newline at end of file
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/ImportTemporaryReferentialAction.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/ImportTemporaryReferentialAction.java 2013-03-28 00:20:21 UTC (rev 697)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/ImportTemporaryReferentialAction.java 2013-03-28 10:05:30 UTC (rev 698)
@@ -25,11 +25,10 @@
*/
import fr.ifremer.tutti.ui.swing.TuttiScreen;
-import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.lang.StringUtils;
import org.nuiton.util.StringUtil;
-import javax.swing.JOptionPane;
-import javax.swing.SwingUtilities;
+import javax.swing.*;
import static org.nuiton.i18n.I18n._;
@@ -49,19 +48,29 @@
protected boolean prepareAction() throws Exception {
boolean result = super.prepareAction();
if (result) {
- String answer = JOptionPane.showInputDialog(getContext().getActionUI(),
- _("tutti.manageTemporaryReferential.passwordDialog.message"),
- _("tutti.manageTemporaryReferential.passwordDialog.title"),
- JOptionPane.WARNING_MESSAGE);
- if (answer != null) {
- String cryptedAnswer = StringUtil.encodeMD5(answer);
- String correctAnswer = StringUtil.encodeMD5("test");
- //TODO kmorin 20130327 error message if wrong password
- result = StringUtils.equals(cryptedAnswer, correctAnswer);
+ String answer = null;
+ do {
+ answer = JOptionPane.showInputDialog(getContext().getActionUI(),
+ _("tutti.manageTemporaryReferential.passwordDialog.message"),
+ _("tutti.manageTemporaryReferential.passwordDialog.title"),
+ JOptionPane.WARNING_MESSAGE);
+ if (answer != null) {
+ String cryptedAnswer = StringUtil.encodeMD5(answer);
+ String correctAnswer = getConfig().getApplicationConfig().getOption("tutti.admin.password");
+ result = StringUtils.equals(cryptedAnswer, correctAnswer);
- } else {
- result = false;
- }
+ if (!result) {
+ JOptionPane.showMessageDialog(getContext().getActionUI(),
+ _("tutti.manageTemporaryReferential.passwordDialog.error.message"),
+ _("tutti.manageTemporaryReferential.passwordDialog.error.title"),
+ JOptionPane.ERROR_MESSAGE);
+ }
+
+ } else {
+ result = false;
+ }
+
+ } while (!result && answer != null);
}
return result;
}
Modified: trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_en_GB.properties
===================================================================
--- trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_en_GB.properties 2013-03-28 00:20:21 UTC (rev 697)
+++ trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_en_GB.properties 2013-03-28 10:05:30 UTC (rev 698)
@@ -856,6 +856,8 @@
tutti.manageTemporaryReferential.field.species.tip=
tutti.manageTemporaryReferential.field.vessel=
tutti.manageTemporaryReferential.field.vessel.tip=
+tutti.manageTemporaryReferential.passwordDialog.error.message=
+tutti.manageTemporaryReferential.passwordDialog.error.title=
tutti.manageTemporaryReferential.passwordDialog.message=
tutti.manageTemporaryReferential.passwordDialog.title=
tutti.manageTemporaryReferential.title=
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-03-28 00:20:21 UTC (rev 697)
+++ trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_fr_FR.properties 2013-03-28 10:05:30 UTC (rev 698)
@@ -860,6 +860,8 @@
tutti.manageTemporaryReferential.field.species.tip=
tutti.manageTemporaryReferential.field.vessel=Référentiel Navire
tutti.manageTemporaryReferential.field.vessel.tip=
+tutti.manageTemporaryReferential.passwordDialog.error.message=Le mot de passe que vous avez entré est incorrect.
+tutti.manageTemporaryReferential.passwordDialog.error.title=Mot de passe incorrect
tutti.manageTemporaryReferential.passwordDialog.message=Vous souhaitez entrer dans une partie sensible de l'application.\nVous devez entrer le mot de passe pour entrer.
tutti.manageTemporaryReferential.passwordDialog.title=Zone sensible
tutti.manageTemporaryReferential.title=importer des référentiels temporaires
1
0
r697 - in trunk: . src/site/rst tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content
by tchemit@users.forge.codelutin.com 28 Mar '13
by tchemit@users.forge.codelutin.com 28 Mar '13
28 Mar '13
Author: tchemit
Date: 2013-03-28 01:20:21 +0100 (Thu, 28 Mar 2013)
New Revision: 697
Url: http://forge.codelutin.com/projects/tutti/repository/revisions/697
Log:
fix doc and prepare release
Modified:
trunk/pom.xml
trunk/src/site/rst/mapping.rst
trunk/src/site/rst/update.rst.vm
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/ImportTemporaryReferentialAction.java
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2013-03-27 23:49:51 UTC (rev 696)
+++ trunk/pom.xml 2013-03-28 00:20:21 UTC (rev 697)
@@ -135,7 +135,7 @@
<postgresqlVersion>9.1-901-1.jdbc4</postgresqlVersion>
<licensePluginVersion>1.4</licensePluginVersion>
- <jaxxVersion>2.5.15-SNAPSHOT</jaxxVersion>
+ <jaxxVersion>2.5.15</jaxxVersion>
<swingXVersion>1.6.4</swingXVersion>
<xworkVersion>2.3.7</xworkVersion>
Modified: trunk/src/site/rst/mapping.rst
===================================================================
--- trunk/src/site/rst/mapping.rst 2013-03-27 23:49:51 UTC (rev 696)
+++ trunk/src/site/rst/mapping.rst 2013-03-28 00:20:21 UTC (rev 697)
@@ -115,20 +115,29 @@
Espèces > Espèce
La liste des espèces référent non encore utilisés.
Voir `détail des requêtes`_.
- Note: cette liste est partagée sur les deux onglets espèces - benthos).
+ Note: cette liste est partagée sur les deux onglets espèces - benthos).
Espèces > Tableau
Chaque ligne du tableau est stockée sous la forme d'un SpeciesProtocol : *TuttiProtocol.species*.
Espèces > Tableau > Espèce
+
Espèces > Tableau > Code
+
Espèces > Tableau > Classe de Taille
+
Espèces > Tableau > Pesée
+
Espèces > Tableau > Dénombrement
+
Espèces > Tableau > Catégorie Tri
+
Espèces > Tableau > Sexe
+
Espèces > Tableau > Maturité
+
Espèces > Tableau > Age
+
Espèces > Tableau > Prélèvement de pièces calcifiées
Benthos
@@ -141,17 +150,26 @@
Benthos > Tableau
Chaque ligne du tableau est stockée sous la forme d'un SpeciesProtocol: *TuttiProtocol.benthos*.
- Benthos > Tableau > Espèce
- Benthos > Tableau > Code
- Benthos > Tableau > Classe de Taille
- Benthos > Tableau > Pesée
- Benthos > Tableau > Dénombrement
- Benthos > Tableau > Catégorie Tri
- Benthos > Tableau > Sexe
- Benthos > Tableau > Maturité
- Benthos > Tableau > Age
- Benthos > Tableau > Prélèvement de pièces calcifiées
+Benthos > Tableau > Espèce
+Benthos > Tableau > Code
+
+Benthos > Tableau > Classe de Taille
+
+Benthos > Tableau > Pesée
+
+Benthos > Tableau > Dénombrement
+
+Benthos > Tableau > Catégorie Tri
+
+Benthos > Tableau > Sexe
+
+Benthos > Tableau > Maturité
+
+Benthos > Tableau > Age
+
+Benthos > Tableau > Prélèvement de pièces calcifiées
+
Trait
~~~~~
@@ -207,7 +225,7 @@
Navire
(depuis version 1.2)
Identique à celui de la campagne : Operation.vessel (OPERATION.VESSEL_FK)
- (Obosolète) : TODO supprimer le code qui fait cette gestion
+ (Obsolète) : TODO supprimer le code qui fait cette gestion
Si le navire est identique à celui de la campagne : Operation.vessel (OPERATION.VESSEL_FK)
Sinon : Operation.operationVesselAssociation (OPERATION_VESSEL_ASSOCIATION.VESSEL_FK avec IS_CATCH_ON_OPERATION_VESSEL=0).
Operation.vessel est alors rempli avec le premier navire de la liste de la campagne, pour être compatible avec Allegro (on doit toujours avoir : SCIENTIFIC_CRUISE.VESSEL_FK = OPERATION_VESSEL_FK).
Modified: trunk/src/site/rst/update.rst.vm
===================================================================
--- trunk/src/site/rst/update.rst.vm 2013-03-27 23:49:51 UTC (rev 696)
+++ trunk/src/site/rst/update.rst.vm 2013-03-28 00:20:21 UTC (rev 697)
@@ -84,8 +84,8 @@
### DB Updates #################################################################
################################################################################
- db.version=@dbVersion@
- db.url=zip:http://appup.nuiton.org/tutti/auth/tutti-db-@dbVersion@.zip
+ db.version=${dbVersion}
+ db.url=zip:http://appup.nuiton.org/tutti/auth/tutti-db-${dbVersion}.zip
db.auth=true
Au démarrage de l'application le fichier est lu et si un des composants est
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/ImportTemporaryReferentialAction.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/ImportTemporaryReferentialAction.java 2013-03-27 23:49:51 UTC (rev 696)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/ImportTemporaryReferentialAction.java 2013-03-28 00:20:21 UTC (rev 697)
@@ -25,8 +25,8 @@
*/
import fr.ifremer.tutti.ui.swing.TuttiScreen;
-import org.apache.commons.lang.StringUtils;
-import org.springframework.util.DigestUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.nuiton.util.StringUtil;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
@@ -54,8 +54,8 @@
_("tutti.manageTemporaryReferential.passwordDialog.title"),
JOptionPane.WARNING_MESSAGE);
if (answer != null) {
- String cryptedAnswer = DigestUtils.md5DigestAsHex(answer.getBytes());
- String correctAnswer = DigestUtils.md5DigestAsHex("test".getBytes());
+ String cryptedAnswer = StringUtil.encodeMD5(answer);
+ String correctAnswer = StringUtil.encodeMD5("test");
//TODO kmorin 20130327 error message if wrong password
result = StringUtils.equals(cryptedAnswer, correctAnswer);
1
0
r696 - trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service
by tchemit@users.forge.codelutin.com 27 Mar '13
by tchemit@users.forge.codelutin.com 27 Mar '13
27 Mar '13
Author: tchemit
Date: 2013-03-28 00:49:51 +0100 (Thu, 28 Mar 2013)
New Revision: 696
Url: http://forge.codelutin.com/projects/tutti/repository/revisions/696
Log:
add fixme
Modified:
trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/AttachmentPersistenceServiceImpl.java
Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/AttachmentPersistenceServiceImpl.java
===================================================================
--- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/AttachmentPersistenceServiceImpl.java 2013-03-27 23:46:24 UTC (rev 695)
+++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/AttachmentPersistenceServiceImpl.java 2013-03-27 23:49:51 UTC (rev 696)
@@ -134,6 +134,7 @@
// Create measurement file
MeasurementFile measurementFile = MeasurementFile.Factory.newInstance();
+ //FIXME-TC When pmfm will be optional (remove this line)
// set measurementFile pmfm
measurementFile.setPmfm(load(PmfmImpl.class, enumeration.PMFM_ID_MEASUREMENT_FILE));
1
0
r695 - in trunk: . src/site/rst src/update tutti-persistence/src/main/resources tutti-ui-swing
by tchemit@users.forge.codelutin.com 27 Mar '13
by tchemit@users.forge.codelutin.com 27 Mar '13
27 Mar '13
Author: tchemit
Date: 2013-03-28 00:46:24 +0100 (Thu, 28 Mar 2013)
New Revision: 695
Url: http://forge.codelutin.com/projects/tutti/repository/revisions/695
Log:
refs #2002: [TECH] - Documentation installation - mise ?\195?\160 jour (am?\195?\169lioration doc)
Added:
trunk/src/site/rst/update.rst.vm
Removed:
trunk/src/site/rst/update.rst
Modified:
trunk/pom.xml
trunk/src/site/rst/mapping.rst
trunk/src/site/rst/referential.rst
trunk/src/update/update-tutti.properties
trunk/tutti-persistence/src/main/resources/queries-override.hbm.xml
trunk/tutti-ui-swing/pom.xml
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2013-03-27 21:56:27 UTC (rev 694)
+++ trunk/pom.xml 2013-03-27 23:46:24 UTC (rev 695)
@@ -171,7 +171,7 @@
<jreVersion>1.7.17</jreVersion>
<!-- Last tutti db version -->
- <!--<dbVersion>2013.02.27</dbVersion>-->
+ <!--<dbVersion>2013.03.26</dbVersion>-->
</properties>
Modified: trunk/src/site/rst/mapping.rst
===================================================================
--- trunk/src/site/rst/mapping.rst 2013-03-27 21:56:27 UTC (rev 694)
+++ trunk/src/site/rst/mapping.rst 2013-03-27 23:46:24 UTC (rev 695)
@@ -40,7 +40,7 @@
Zone
Program.locations (PROGRAM2LOCATION.LOCATION_FK)
-Commentaire
+Description
Program.description (PROGRAM.DESCRIPTION)
Campagne
@@ -62,25 +62,21 @@
Nombre de poches
En lecture : récupération de la plus grande valeur dans ScientificCruise.fishingTrip.gearPhysicalFeatures.gearPhysicalMeasurement.numericalvalue (GEAR_PHYSICAL_MEASURMENT.NUMERICAL_VALUE avec PMFM_FK=<PMFM_ID_MULTIRIG_NUMBER>)
En écriture : valeur dupliquée pour chaque engin (voir "Engin(s)" ci-dessous) dans ScientificCruise.fishingTrip.gearPhysicalFeatures.gearPhysicalMeasurement.numericalvalue (GEAR_PHYSICAL_MEASURMENT.NUMERICAL_VALUE avec PMFM_FK=<PMFM_ID_MULTIRIG_NUMBER>)
-
-Pays
- En lecture : le pays est calculé à partir de ScientificCruise.departureLocation (SCIENTIFIC_CRUISE.DEPARTURE_LOCATION_FK)
- en utilisant la hiérarchie des lieux (LOCATION_HIERARCHY) our être sûr d'obtenir un payx et non un lieux de niveau inférieur (ex : un port, etc.)
- En écriture : ScientificCruise.departureLocation (SCIENTIFIC_CRUISE.DEPARTURE_LOCATION_FK) et ScientificCruise.returnLocation (SCIENTIFIC_CRUISE.DEPARTURE_LOCATION_FK)
+Port de départ
+ ScientificCruise.fishingTrip.departureLocation (FISHING_TRIP.DEPARTURE_LOCATION_FK)
+
+Port d'arrivée
+ ScientificCruise.fishingTrip.returnLocation (FISHING_TRIP.RETURN_LOCATION_FK)
+
Date de début
ScientificCruise.departureDateTime (SCIENTIFIC_CRUISE.DEPARTURE_DATE_TIME)
Date de fin
ScientificCruise.returnDateTime (SCIENTIFIC_CRUISE.RETURN_DATE_TIME)
-Navire(s)
- Le premier navire dans le liste est stocké dans ScientificCruise.vessel (SCIENTIFIC_CRUISE.VESSEL_FK).
- Les navires suivants sont stockés dans ScientificCruise.fishingTrip.comments
- derrière la balise : "#VESSELS=<liste_des_IDs>"
- Il n'est pas certain qu'il soit nécessaire de stocker cette liste ailleurs, dans la mesure où
- elle peut être calculée à partir de la liste des navires associés à chaque opération (voir "Opération > Navire" ci-dessous),
- comme c'est le cas actuellement à l'ouverture d'une campagne de données historiques.
+Navire
+ ScientificCruise.vessel (SCIENTIFIC_CRUISE.VESSEL_FK)
Engin(s)
ScientificCruise.fishingTrip.gearPhysicalFeatures.gear (GEAR_PHYSICAL_FEATURES.GEAR_FK avec RANK_ORDER=<n° d'ordre dans la liste>)
@@ -101,6 +97,61 @@
Commentaire
ScientificCruise.comments (SCIENTIFIC_CRUISE.COMMENTS)
+Protocole
+~~~~~~~~~
+
+Informations générales > Nom
+ TuttiProtocol.name (persisté dans le fichier)
+
+Informations générales > Commentaire
+ TuttiProtocol.comment (persisté dans le fichier)
+
+Caractéristiques
+ On récupère la liste de tous les pmfm que l'on répartit dans les différents
+ onglets. Chaque pmfm ne peut être sélectionné que dans une seule liste.
+
+Espèces
+
+Espèces > Espèce
+ La liste des espèces référent non encore utilisés.
+ Voir `détail des requêtes`_.
+ Note: cette liste est partagée sur les deux onglets espèces - benthos).
+
+Espèces > Tableau
+ Chaque ligne du tableau est stockée sous la forme d'un SpeciesProtocol : *TuttiProtocol.species*.
+
+Espèces > Tableau > Espèce
+Espèces > Tableau > Code
+Espèces > Tableau > Classe de Taille
+Espèces > Tableau > Pesée
+Espèces > Tableau > Dénombrement
+Espèces > Tableau > Catégorie Tri
+Espèces > Tableau > Sexe
+Espèces > Tableau > Maturité
+Espèces > Tableau > Age
+Espèces > Tableau > Prélèvement de pièces calcifiées
+
+Benthos
+
+Benthos > Espèce
+ La liste des espèces référents non encore utilisés.
+ Voir `détail des requêtes`_.
+ Note: cette liste est partagée sur les deux onglets espèces - benthos).
+
+Benthos > Tableau
+ Chaque ligne du tableau est stockée sous la forme d'un SpeciesProtocol: *TuttiProtocol.benthos*.
+
+ Benthos > Tableau > Espèce
+ Benthos > Tableau > Code
+ Benthos > Tableau > Classe de Taille
+ Benthos > Tableau > Pesée
+ Benthos > Tableau > Dénombrement
+ Benthos > Tableau > Catégorie Tri
+ Benthos > Tableau > Sexe
+ Benthos > Tableau > Maturité
+ Benthos > Tableau > Age
+ Benthos > Tableau > Prélèvement de pièces calcifiées
+
Trait
~~~~~
@@ -116,15 +167,15 @@
Strate
Operation.gearUseFeatures.fishingArea.regulationLocation (FISHING_AREA2REG_LOCATION.LOCATION_FK associé au FISHING_AREA de l'opération)
- En lecture : sélection en tant que locatlité à partir du locationLevel (LOCATION.LOCATION_LEVEL_FK=<LocationLevelId.STRATA>)
+ En lecture : sélection en tant que localité à partir du locationLevel (LOCATION.LOCATION_LEVEL_FK=<LocationLevelId.STRATA>)
Sous-strate
Operation.gearUseFeatures.fishingArea.regulationLocation (FISHING_AREA2REG_LOCATION.LOCATION_FK associé au FISHING_AREA de l'opération)
- En lecture : sélection en tant que locatlité à partir du locationLevel (LOCATION.LOCATION_LEVEL_FK=<LocationLevelId.SUB_STRATA>)
+ En lecture : sélection en tant que localité à partir du locationLevel (LOCATION.LOCATION_LEVEL_FK=<LocationLevelId.SUB_STRATA>)
Localité
operation.gearUseFeatures.fishingArea.regulationLocation (FISHING_AREA2REG_LOCATION.LOCATION_FK associé au FISHING_AREA de l'opération)
- En lecture : sélection en tant que locatlité à partir du locationLevel (LOCATION.LOCATION_LEVEL_FK=<LocationLevelId.LOCALITE>)
+ En lecture : sélection en tant que localité à partir du locationLevel (LOCATION.LOCATION_LEVEL_FK=<LocationLevelId.LOCALITE>)
Début de traine > Latitude, Longitude
Operation.vesselPosition (VESSEL_POSITION.LATITUDE et VESSEL_POSITION.LONGITUDE), avec startDateTime = "Début de traine > Date et heure"
@@ -154,7 +205,10 @@
**WARNING** : modèle UML + synchronisation Allegro à mettre à jour pour pouvoir importer/exporter VesselPersonFeatures et les tables liées
Navire
- Si le navire est identique au premier de la liste de la campagne : Operation.vessel (OPERATION.VESSEL_FK)
+ (depuis version 1.2)
+ Identique à celui de la campagne : Operation.vessel (OPERATION.VESSEL_FK)
+ (Obosolète) : TODO supprimer le code qui fait cette gestion
+ Si le navire est identique à celui de la campagne : Operation.vessel (OPERATION.VESSEL_FK)
Sinon : Operation.operationVesselAssociation (OPERATION_VESSEL_ASSOCIATION.VESSEL_FK avec IS_CATCH_ON_OPERATION_VESSEL=0).
Operation.vessel est alors rempli avec le premier navire de la liste de la campagne, pour être compatible avec Allegro (on doit toujours avoir : SCIENTIFIC_CRUISE.VESSEL_FK = OPERATION_VESSEL_FK).
@@ -164,7 +218,15 @@
Commentaire
Operation.comments (OPERATION.COMMENTS)
-
+
+Pièces Jointes
+ Chaque pièce jointes est stockée dans MeasurementFile
+ (MEASUREMENT_FILE avec PMFM_FK=null, OBJECT_TYPE_FK='OPERATION' et OBJECT_ID=<ID du trait>)
+ MeasurementFile.path : chemin du fichier (copier dans un répertoire, puis stocké en relatif)
+ MeasurementFile.name : nom
+ MeasurementFile.comments : commentaire
+ **WARNING** : modification de modèle à faire pour pouvoir avoir MEASUREMENT_FILE.PMFM_FK=null
+
Trait > Mise en oeuvre de l'engin
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -214,20 +276,28 @@
Batch.quantificationMeasurement.numericalValue (QUANTIFICATION_MEASUREMENT.NUMERICAL_VALUE avec IS_REFERENT=1 et PMFM_FK=<PmfmId.WEIGHT_OBSERVED>)
Benthos > Poids TOTAL
- Sommme des poids des lots "Capture > xxx > Benthos"
+ Sommme des poids des lots "Capture > xxx > Benthos"
Batch.quantificationMeasurement.numericalValue (QUANTIFICATION_MEASUREMENT.NUMERICAL_VALUE avec IS_REFERENT=1 et PMFM_FK=<PmfmId.WEIGHT_OBSERVED>)
-
+
Benthos > Poids total VRAC
Lot "Capture > Vrac > Benthos"
Batch.quantificationMeasurement.numericalValue (QUANTIFICATION_MEASUREMENT.NUMERICAL_VALUE avec IS_REFERENT=1 et PMFM_FK=<PmfmId.WEIGHT_OBSERVED>)
-
+
Benthos > Poids total VRAC trié
Calculé par tutti ? utile seulement si Thalassa ?
Benthos > Poids total HORS VRAC TRIE
- Lot "Capture > Hors Vrac > Benthos"
+ Lot "Capture > Hors Vrac > Benthos"
Batch.quantificationMeasurement.numericalValue (QUANTIFICATION_MEASUREMENT.NUMERICAL_VALUE avec IS_REFERENT=1 et PMFM_FK=<PmfmId.WEIGHT_OBSERVED>)
-
+
+Pièces Jointes
+ Chaque pièce jointes est stockée dans MeasurementFile
+ (MEASUREMENT_FILE avec PMFM_FK=null, OBJECT_TYPE_FK='CATCH_BATCH' et OBJECT_ID=<ID du lot de la capture>)
+ MeasurementFile.path : chemin du fichier (copier dans un répertoire, puis stocké en relatif)
+ MeasurementFile.name : nom
+ MeasurementFile.comments : commentaire
+ **WARNING** : modification de modèle à faire pour pouvoir avoir MEASUREMENT_FILE.PMFM_FK=null
+
Capture > Espèces
~~~~~~~~~~~~~~~~~
@@ -245,6 +315,14 @@
Lot "Capture > Vrac > Espèce > Biota"
Batch.quantificationMeasurement.numericalValue (QUANTIFICATION_MEASUREMENT.NUMERICAL_VALUE avec IS_REFERENT=1 et PMFM_FK=<PmfmId.WEIGHT_OBSERVED>)
+Pièces Jointes
+ Chaque pièce jointes est stockée dans MeasurementFile
+ (MEASUREMENT_FILE avec PMFM_FK=null, OBJECT_TYPE_FK='CATCH_BATCH' et OBJECT_ID=<ID du lot VRAC > ESPECES>)
+ MeasurementFile.path : chemin du fichier (copier dans un répertoire, puis stocké en relatif)
+ MeasurementFile.name : nom
+ MeasurementFile.comments : commentaire
+ **WARNING** : modification de modèle à faire pour pouvoir avoir MEASUREMENT_FILE.PMFM_FK=null
+
Tableau
Chaque ligne du tableau est stockée sous la forme d'un lot (Batch) positionné
soit sous le lot "Capture > Vrac > Espèce"
@@ -268,7 +346,7 @@
Batch.sortingMeasurement.qualitativeValue (SORTING_MEASUREMENT.QUALITATIVE_VALUE_FK avec PMFM_FK=<PmfmId.MATURITY>)
Tableau > Age
- Batch.sortingMeasurement.qualitativeValue (SORTING_MEASUREMENT.QUALITATIVE_VALUE_FK avec PMFM_FK=<PmfmId.AGE>)
+ Batch.sortingMeasurement.numericalValue (SORTING_MEASUREMENT.NUMERICAL_VALUE avec PMFM_FK=<PmfmId.AGE>)
Tableau > Poids sous-échantillonné
Si vide Batch.samplingRatio = 1
@@ -286,7 +364,7 @@
Tableau > Pièces Jointes
Chaque pièce jointes est stockée dans MeasurementFile
- (MEASUREMENT_FILE avec PMFM_FK=null, OBJECT_TYPE_FK='BATCH' et OBJECT_ID=<ID du lot de la ligne du tableau>)
+ (MEASUREMENT_FILE avec PMFM_FK=null, OBJECT_TYPE_FK='SAMPLE' et OBJECT_ID=<ID du lot de la ligne du tableau>)
MeasurementFile.path : chemin du fichier (copier dans un répertoire, puis stocké en relatif ?)
MeasurementFile.name : nom
MeasurementFile.comments : commentaire
@@ -312,4 +390,99 @@
Mensuration > Tableau > Poids observé
Batch.quantificationMeasurement.numericalValue (QUANTIFICATION_MEASUREMENT.NUMERICAL_VALUE avec IS_REFERENT=1)
-
\ No newline at end of file
+
+Capture > Benthos
+~~~~~~~~~~~~~~~~~
+
+Benthos > Poids total VRAC
+ Lot "Capture > Vrac > Benthos"
+ Batch.quantificationMeasurement.numericalValue (QUANTIFICATION_MEASUREMENT.NUMERICAL_VALUE avec IS_REFERENT=1 et PMFM_FK=<PmfmId.WEIGHT_OBSERVED>)
+
+Poids inerte trié
+ Lot "Capture > Vrac > Benthos > [TAXON_INERT]"
+ Batch.referenceTaxon = [TAXON_INERT] (BATCH.REFERENCE_TAXON_FK=<ReferenceTaxonId.INERT>)
+ Batch.quantificationMeasurement.numericalValue (QUANTIFICATION_MEASUREMENT.NUMERICAL_VALUE avec IS_REFERENT=1 et PMFM_FK=<PmfmId.WEIGHT_OBSERVED>)
+ **WARNING** : le taxon référent "Inerte" n'existe pas encore, il faut le créé (action Ifremer/J.Martin ?)
+
+Poids vivant non détaillé trié
+ Lot "Capture > Vrac > Benthos > Biota"
+ Batch.quantificationMeasurement.numericalValue (QUANTIFICATION_MEASUREMENT.NUMERICAL_VALUE avec IS_REFERENT=1 et PMFM_FK=<PmfmId.WEIGHT_OBSERVED>)
+
+Pièces Jointes
+ Chaque pièce jointes est stockée dans MeasurementFile
+ (MEASUREMENT_FILE avec PMFM_FK=null, OBJECT_TYPE_FK='CATCH_BATCH' et OBJECT_ID=<ID du lot VRAC > BENTHOS>)
+ MeasurementFile.path : chemin du fichier (copier dans un répertoire, puis stocké en relatif)
+ MeasurementFile.name : nom
+ MeasurementFile.comments : commentaire
+ **WARNING** : modification de modèle à faire pour pouvoir avoir MEASUREMENT_FILE.PMFM_FK=null
+
+Tableau
+ Chaque ligne du tableau est stockée sous la forme d'un lot (Batch) positionné
+ soit sous le lot "Capture > Vrac > Benthos"
+ soit sous "Capture > Hors Vrac > Benthos"
+
+Tableau > Benthos
+ stockage de l'espèce uniquement pour les lot parent
+ Batch.referenceTaxon (BATCH.REFERENCE_TAXON_FK)
+
+Tableau > V/HV
+ Vrac ou Hors Vrac : Batch.sortingMeasurement.qualitativeValue (SORTING_MEASUREMENT.QUALITATIVE_VALUE_FK avec PMFM_FK=<PmfmId.SORTED_UNSORTED>)
+ Poids : Batch.quantificationMeasurement.numericalValue (QUANTIFICATION_MEASUREMENT.NUMERICAL_VALUE avec IS_REFERENT=1 et PMFM_FK=<PmfmId.WEIGHT_OBSERVED>)
+
+Tableau > Class. Tri
+ Batch.sortingMeasurement.qualitativeValue (SORTING_MEASUREMENT.QUALITATIVE_VALUE_FK avec PMFM_FK=<PmfmId.SIZE_CATEGORY>)
+
+Tableau > Sexe
+ Batch.sortingMeasurement.qualitativeValue (SORTING_MEASUREMENT.QUALITATIVE_VALUE_FK avec PMFM_FK=<PmfmId.SEX>)
+
+Tableau > Maturité
+ Batch.sortingMeasurement.qualitativeValue (SORTING_MEASUREMENT.QUALITATIVE_VALUE_FK avec PMFM_FK=<PmfmId.MATURITY>)
+
+Tableau > Age
+ Batch.sortingMeasurement.numericalValue (SORTING_MEASUREMENT.NUMERICAL_VALUE avec PMFM_FK=<PmfmId.AGE>)
+
+Tableau > Poids sous-échantillonné
+ Si vide Batch.samplingRatio = 1
+ Sinon :
+ Batch.samplingRatioText (BATCH.SAMPLING_RATIO_TEXT) concaténé à partir des chaines : "<Poids sous-échantillonné>" + "/" + "<Poids V/HV>"
+ Batch.samplingRatio (BATCH.SAMPLING_RATIO) calculé par le division : <Poids sous-échantillonné> / <Poids V/HV>
+ Pour la lecture : on parse samplingRatioText pour récupérer le poids sous-échantillonné. si absent on le calculé à partir de samplingRatio (moins précis car perte possible de précision)
+
+Tableau > Nombre
+ Calculé à partir de la somme du nombre d'individus des lots fils (BATCH.INDIVIDUAL_COUNT avec PARENT_BATCH_FK=<ID du lot de la ligne du tableau>)
+ (voir ci-dessous "Mensuration > Tableau")
+
+Tableau > Commentaire
+ Batch.comments
+
+Tableau > Pièces Jointes
+ Chaque pièce jointes est stockée dans MeasurementFile
+ (MEASUREMENT_FILE avec PMFM_FK=null, OBJECT_TYPE_FK='SAMPLE' et OBJECT_ID=<ID du lot de la ligne du tableau>)
+ MeasurementFile.path : chemin du fichier (copier dans un répertoire, puis stocké en relatif)
+ MeasurementFile.name : nom
+ MeasurementFile.comments : commentaire
+ **WARNING** : modification de modèle à faire pour pouvoir avoir MEASUREMENT_FILE.PMFM_FK=null
+
+Mensuration > Type de mesure
+ Dupliqué pour chaque lot de mensuration créé (un lot pour chaque taille saisie)
+ Batch.sortingMeasurement.pmfm (SORTING_MEASUREMENT.PMFM_FK)
+
+Mensuration > Pas de la classe de taille
+ **WARNING** : Non stocké, devrait dépendre de PSFM.precision ?
+ Peut-etre peut-on le calculer par analyse des mensurations saisies ? (et si aucune mesure prendre la précision du PSFM)
+
+Mensuration > Tableau
+ Chaque ligne du tableau de mensuration est stocké sous la forme d'un lot
+ relié au lot correspondant à la ligne parent du tableau des espèces. (BATCH avec PARENT_BATCH_FK=<ID du lot parent dans le tableau des espèces>)
+
+Mensuration > Tableau > Classe de taille
+ Batch.sortingMeasurement.numericalValue (SORTING_MEASUREMENT.NUMERICAL_VALUE avec PMFM_FK=<ID correspondant au "Type de mesure">)
+
+Mensuration > Tableau > Nombre
+ Batch.individualCount (BATCH.INDIVIDUAL_COUNT)
+
+Mensuration > Tableau > Poids observé
+ Batch.quantificationMeasurement.numericalValue (QUANTIFICATION_MEASUREMENT.NUMERICAL_VALUE avec IS_REFERENT=1)
+
+
+.. _détail des requêtes: referential.html
\ No newline at end of file
Modified: trunk/src/site/rst/referential.rst
===================================================================
--- trunk/src/site/rst/referential.rst 2013-03-27 21:56:27 UTC (rev 694)
+++ trunk/src/site/rst/referential.rst 2013-03-27 23:46:24 UTC (rev 695)
@@ -39,89 +39,30 @@
+-----------------------------------------------------+-------+-----------------------------------------------------+
| Nom requète | Etat | Commentaire |
+=====================================================+=======+=====================================================+
-| [REF-01] Liste des zones d'une série de campagne | OK | |
+| [REF-01] Liste des strates / sstrates/ localites | OK | |
+-----------------------------------------------------+-------+-----------------------------------------------------+
-| [REF-02] Liste des pays | OK | |
+| [REF-02] Liste des navires (scientifique) | OK | (filtre sur le type de navire) |
+-----------------------------------------------------+-------+-----------------------------------------------------+
-| [REF-03] Liste des strates / sstrates/ localites | OK | |
+| [REF-03] Liste des engins (scientifique) | OK | (filtre sur le type d'engin) |
+-----------------------------------------------------+-------+-----------------------------------------------------+
-| [REF-04] Liste des navires (scientifique) | OK | |
+| [REF-04] Liste des utilisateurs | OK | Doit-on utiliser limiter aux membres de l'Ifremer ? |
+-----------------------------------------------------+-------+-----------------------------------------------------+
-| [REF-05] Liste des navires (pro) | OK | |
+| [REF-05] Types d'objet | OK | Pour les pièces-jointes |
+-----------------------------------------------------+-------+-----------------------------------------------------+
-| [REF-06] Liste des engins (scientifique) | OK | |
+| [REF-06] Catégorie de macro-déchets | OK | |
+-----------------------------------------------------+-------+-----------------------------------------------------+
-| [REF-07] Liste des engins (pro) | OK | |
+| [REF-07] Catégorie de taille macro-déchets | OK | |
+-----------------------------------------------------+-------+-----------------------------------------------------+
-| [REF-08] Liste des utilisateurs | OK | Doit-on utiliser limiter aux membres de l'Ifremer ? |
+| [REF-08] Catégorie H/VC | OK | |
+-----------------------------------------------------+-------+-----------------------------------------------------+
-| [REF-09] Liste des espèces | OK | Utilisation de synonymes via import refTax ? |
+| [REF-09] Catégorie Classe. Tri | OK | |
+-----------------------------------------------------+-------+-----------------------------------------------------+
-| [REF-10] Catégorie de macro-déchets | OK | |
+| [REF-10] Catégorie Sexe | OK | |
+-----------------------------------------------------+-------+-----------------------------------------------------+
-| [REF-11] Catégorie de taille macro-déchets | OK | |
+| [REF-11] Catégorie Maturité | OK | |
+-----------------------------------------------------+-------+-----------------------------------------------------+
-| [REF-12] Catégorie H/VC | OK | |
-+-----------------------------------------------------+-------+-----------------------------------------------------+
-| [REF-13] Catégorie Classe. Tri | OK | |
-+-----------------------------------------------------+-------+-----------------------------------------------------+
-| [REF-14] Catégorie Sexe | OK | |
-+-----------------------------------------------------+-------+-----------------------------------------------------+
-| [REF-15] Catégorie Maturité | OK | |
-+-----------------------------------------------------+-------+-----------------------------------------------------+
-| [REF-16] Conversion Taille-poids |TODO V2| A voir si vraiment à faire |
-+-----------------------------------------------------+-------+-----------------------------------------------------+
-[REF-01] Liste des zones d'une série de campagne
-------------------------------------------------
-
-::
-
- SELECT
- l.id,
- l.label,
- l.name,
- l.status
- FROM LocationImpl l
- WHERE
- l.locationLevel.id = :locationLevelId
- AND l.locationClassification.id = :locationClassificationId
- AND l.status.code IN (:statusValidCode, :statusTemporaryCode)
-
-Paramètres :
-
-- :locationLevelId = *LocationLevelId.PROGRAM*
-- :locationClassificationId = *LocationClassificationId.SECTOR*
-- :statusValidCode = *StatusCode.ENABLE*
-- :statusTemporaryCode = *StatusCode.TEMPORARY*
-
-*État:* À Valider et définir la valeur de la constante.
-
-[REF-02] Liste des pays
------------------------
-
-::
-
- SELECT
- l.id,
- l.label,
- l.name,
- l.status
- FROM LocationImpl l
- WHERE
- l.locationLevel.id = :locationLevelId
- AND l.status.code IN (:statusValidCode, :statusTemporaryCode)
-
-
-Paramètres :
-
-- :locationLevelId = *LocationLevelId.PAYS_ISO3*
-- :statusValidCode = *StatusCode.ENABLE*
-- :statusTemporaryCode = *StatusCode.TEMPORARY*
-
-*État:* Valide.
-
-[REF-03] Liste des strates / sous-strates / localités
+[REF-01] Liste des strates / sous-strates / localités
-----------------------------------------------------
::
@@ -154,8 +95,8 @@
*État:* Valide.
-[REF-04] Liste des navires (scientifique)
------------------------------------------
+[REF-02] Liste des navires (selon son type)
+-------------------------------------------
::
@@ -166,130 +107,51 @@
vf.name AS vesselName,
v.status AS status
FROM
- VesselImpl v
- INNER JOIN v.vesselRegistrationPeriods AS vrp
- LEFT OUTER JOIN v.vesselFeatures AS vf
- WHERE v.vesselType.id = :vesselTypeId
- AND v.status.code IN (:statusValidCode, :statusTemporaryCode)
- AND vrp.vesselRegistrationPeriodPk.startDateTime =
- (
- SELECT MAX(vrp2.vesselRegistrationPeriodPk.startDateTime)
- FROM VesselRegistrationPeriodImpl vrp2 WHERE
- vrp2.vesselRegistrationPeriodPk.vessel.code = v.code
- AND (vrp2.vesselRegistrationPeriodPk.startDateTime <= :refDate OR :refDate IS NULL)
- GROUP BY vrp2.vesselRegistrationPeriodPk.vessel.code
- )
- AND vf.startDateTime =
- (
- SELECT MAX(vf2.startDateTime)
- FROM VesselFeaturesImpl vf2 WHERE
- vf2.vessel.code = v.code
- AND (vf2.startDateTime <= :refDate OR :refDate IS NULL)
- GROUP BY vf2.vessel.code
- )
+ VesselImpl v
+ INNER JOIN v.vesselRegistrationPeriods AS vrp
+ LEFT OUTER JOIN v.vesselFeatures AS vf
+ WHERE
+ v.vesselType.id = :vesselTypeId
+ AND v.status.code IN (:statusValidCode, :statusTemporaryCode)
+ AND vrp.vesselRegistrationPeriodPk.startDateTime <= :refDate
+ AND vf.startDateTime <= :refDate
+ AND coalesce(vrp.endDateTime, :refDate) >= :refDate
+ AND coalesce(vf.endDateTime, :refDate) >= :refDate
+ )
Paramètres :
-- :gearClassificiationId = *VesselTypeId.SCIENTIFIC_RESEARCH_VESSEL*
+- :vesselTypeId = *VesselTypeId.SCIENTIFIC_RESEARCH_VESSEL* / *VesselTypeId.FISHING_VESSEL*
- :refDate = date (ou null)
- :statusValidCode = *StatusCode.ENABLE*
- :statusTemporaryCode = *StatusCode.TEMPORARY*
-*État:* Valide mais à optimiser.
-
-[REF-05] Liste des navires (pro)
---------------------------------
-
-::
-
- SELECT
- v.code AS vesselCode,
- vrp.registrationCode AS nationalRegistrationCode,
- vrp.internationalRegistrationCode as internationalRegistrationCode,
- vf.name AS vesselName,
- v.status AS status
- FROM
- VesselImpl v
- INNER JOIN v.vesselRegistrationPeriods AS vrp
- LEFT OUTER JOIN v.vesselFeatures AS vf
- WHERE v.vesselType.id = :vesselTypeId
- AND v.status.code IN (:statusValidCode, :statusTemporaryCode)
- AND vrp.vesselRegistrationPeriodPk.startDateTime =
- (
- SELECT MAX(vrp2.vesselRegistrationPeriodPk.startDateTime)
- FROM VesselRegistrationPeriodImpl vrp2 WHERE
- vrp2.vesselRegistrationPeriodPk.vessel.code = v.code
- AND (vrp2.vesselRegistrationPeriodPk.startDateTime <= :refDate OR :refDate IS NULL)
- GROUP BY vrp2.vesselRegistrationPeriodPk.vessel.code
- )
- AND vf.startDateTime =
- (
- SELECT MAX(vf2.startDateTime)
- FROM VesselFeaturesImpl vf2 WHERE
- vf2.vessel.code = v.code
- AND (vf2.startDateTime <= :refDate OR :refDate IS NULL)
- GROUP BY vf2.vessel.code
- )
-
-
-Paramètres :
-
-- :gearClassificiationId = *VesselTypeId.FISHING_VESSEL*
-- :refDate = date (ou null)
-- :statusValidCode = *StatusCode.ENABLE*
-- :statusTemporaryCode = *StatusCode.TEMPORARY*
-
-*État:* Valide mais à optimiser.
-
-[REF-06] Liste des engins (scientifique)
-----------------------------------------
-
-::
-
- SELECT
- g.id,
- g.label,
- g.name,
- g.status AS status
- FROM GearImpl g
- WHERE
- g.gearClassification.id= :gearClassificiationId
- AND g.status.code IN (:statusValidCode, :statusTemporaryCode)
-
-
-Paramètres :
-
-- :gearClassificiationId = *GearClassificationId.SCIENTIFIC_CRUISE*
-- :statusValidCode = *StatusCode.ENABLE*
-- :statusTemporaryCode = *StatusCode.TEMPORARY*
-
*État:* Valide.
-[REF-07] Liste des engins (pro)
--------------------------------
+[REF-03] Liste des engins (selon son type)
+------------------------------------------
::
SELECT
- g.id,
- g.label,
- g.name,
- g.status AS status
- FROM GearImpl g
- WHERE
- g.gearClassification.id= :gearClassificiationId
- AND g.status.code IN (:statusValidCode, :statusTemporaryCode)
+ g.id,
+ g.label,
+ g.name,
+ g.status AS status
+ FROM GearImpl g
+ WHERE
+ g.gearClassification.id= :gearClassificiationId
+ AND g.status.code IN (:statusValidCode, :statusTemporaryCode)
Paramètres :
-- :gearClassificiationId = *GearClassificationId.FAO*
+- :gearClassificiationId = *GearClassificationId.SCIENTIFIC_CRUISE* / *GearClassificationId.FAO*
- :statusValidCode = *StatusCode.ENABLE*
- :statusTemporaryCode = *StatusCode.TEMPORARY*
*État:* Valide.
-
-[REF-08] Liste des utilisateurs
+[REF-04] Liste des utilisateurs
-------------------------------
::
@@ -322,62 +184,48 @@
*État:* Valide.
-[REF-09] Liste des espèces
---------------------------
-
-::
-
- voir TaxonSpecificDao.getAllTaxonRefTax()
-
-*État:* Valide.
-
-[REF-10] Catégorie de macro-déchets
+[REF-05] Catégorie de macro-déchets
-----------------------------------
[REF-T01] + [REF-T02] avec :pmfmId = *PmfmId.MARINE_LITTER_TYPE*
*État:* Valide.
-[REF-11] Catégorie de taille macro-déchets
+[REF-06] Catégorie de taille macro-déchets
-------------------------------------------
[REF-T01] + [REF-T02] avec :pmfmId = *PmfmId.MARINE_LITTER_SIZE_CATEGORY*
*État:* Valide.
-[REF-12] Catégorie H/VC
+[REF-07] Catégorie H/VC
-----------------------
[REF-T01] + [REF-T02] avec :pmfmId = *PmfmId.SORTED_UNSORTED*
*État:* Valide.
-[REF-13] Catégorie Classe. Tri
+[REF-08] Catégorie Classe. Tri
------------------------------
[REF-T01] + [REF-T02] avec :pmfmId = *PmfmId.SIZE_CATEGORY*
*État:* Valide.
-[REF-14] Catégorie Sexe
+[REF-09] Catégorie Sexe
-----------------------
[REF-T01] + [REF-T02] avec :pmfmId = *PmfmId.SEX*
*État:* Valide.
-[REF-15] Catégorie Maturité
+[REF-10] Catégorie Maturité
---------------------------
[REF-T01] + [REF-T02] avec :pmfmId = *PmfmId.MATURITY*
*État:* Valide.
-[REF-16] Conversion Taille-poids
---------------------------------
-
-*État:* A FAIRE.
-
Les requètes techniques
~~~~~~~~~~~~~~~~~~~~~~~
@@ -390,8 +238,12 @@
+-----------------------------------------------------+-------+-----------------------------------------------------+
| [REF-T03] Liste de tous les psfm | OK | |
+-----------------------------------------------------+-------+-----------------------------------------------------+
-| [REF-T04] Lieu statistique à partir de lat/long | OK | |
+| [REF-T04] Liste des lieux | OK | (filtre level Classification) |
+-----------------------------------------------------+-------+-----------------------------------------------------+
+| [REF-T05] Récupération d'un lieu | OK | |
++-----------------------------------------------------+-------+-----------------------------------------------------+
+| [REF-T06] Type d'un object pièce-jointe | OK | |
++-----------------------------------------------------+-------+-----------------------------------------------------+
[REF-T01] Détail d'un psfm par son id
-------------------------------------
@@ -476,9 +328,62 @@
*État:* Valide.
-[REF-T04] Lieu statistique (rectangle statistique) à partir de lat/long
------------------------------------------------------------------------
+[REF-T04] Liste des lieux (filtre locationLevel et locationClassification)
+--------------------------------------------------------------------------
-Utiliser *LocationService.getLocationIdByLatLong()* (adagio-core)
+::
+ SELECT
+ l.id as locationId,
+ l.label as locationLabel,
+ l.name as locationName,
+ l.status as status
+ FROM LocationImpl l
+ WHERE
+ l.locationLevel.id = :locationLevelId
+ AND l.locationClassification.id = :locationClassificationId
+ AND l.status.code IN (:statusValidCode, :statusTemporaryCode)
+
+Paramètres :
+
+- :locationLevelId = id du locationLevel
+- :locationClassificationId = id du locationClassification
+- :unitIdNone = *UnitId.NONE*
+- :statusValidCode = *StatusCode.ENABLE*
+- :statusTemporaryCode = *StatusCode.TEMPORARY*
+
+*État:* Valide.
+
+[REF-T05] Récupération d'un lieu par son id
+-------------------------------------------
+
+::
+
+ SELECT
+ l.id as locationId,
+ l.label as locationLabel,
+ l.name as locationName,
+ l.status as status
+ FROM
+ LocationImpl l
+ WHERE
+ l.id = :locationId
+
+Paramètres :
+
+- :locationId = id du lieu
+
+*État:* Valide.
+
+[REF-06] Type d'un object pièce-jointe
+--------------------------------------
+
+::
+
+ SELECT
+ p.code AS objectTypeCode,
+ p.name AS objectTypeName,
+ p.description AS objectTypeDescription
+ FROM ObjectTypeImpl p
+
*État:* Valide.
\ No newline at end of file
Deleted: trunk/src/site/rst/update.rst
===================================================================
--- trunk/src/site/rst/update.rst 2013-03-27 21:56:27 UTC (rev 694)
+++ trunk/src/site/rst/update.rst 2013-03-27 23:46:24 UTC (rev 695)
@@ -1,119 +0,0 @@
-.. -
-.. * #%L
-.. * Tutti
-.. * $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%
-.. -
-
-=======================
-Mise à jour du logiciel
-=======================
-
-Présentation
-------------
-
-**Tutti** utilise un mécanisme simple pour effectuer les mises à jour de ses
-différents composants, à savoir:
-
-1. Mise à jour de la JRE
-2. Mise à jour du programme Tutti
-3. Mise à jour des fichiers de traductions
-4. Mise à jour de la base de données.
-
-Principe des mises à jour
--------------------------
-
-Chaque composant est contenu dans un répertoire et possède un fichier
-obligatoirement nommé **version.appup** qui contient la version du composant.
-
-Un fichier de propriétés disponible sur le réseau à l'adresse suivante:
-http://appup.forge.codelutin.com/tutti/update-tutti.properties
-
-contient la description des dernières version disponibles.
-
-::
-
- ################################################################################
- ### JRE Updates ################################################################
- ################################################################################
-
- jre.version=1.7.10
- linux.amd64.jre.url=zip:http://nexus.nuiton.org/nexus/content/repositories/…
- linux.i386.jre.url=zip:http://nexus.nuiton.org/nexus/content/repositories/j…
- windows.amd64.jre.url=zip:http://nexus.nuiton.org/nexus/content/repositorie…
- windows.i386.jre.url=zip:http://nexus.nuiton.org/nexus/content/repositories…
-
- ################################################################################
- ### Tutti Updates ##############################################################
- ################################################################################
-
- tutti.version=1.0-SNAPSHOT
- tutti.url=zip:http://nexus.nuiton.org/nexus/content/repositories/other-rele…
-
- ################################################################################
- ### I18n Updates ###############################################################
- ################################################################################
-
- i18n.version=1.0-SNAPSHOT
- i18n.url=zip:http://nexus.nuiton.org/nexus/content/repositories/other-relea…
-
- ################################################################################
- ### DB Updates #################################################################
- ################################################################################
-
- db.version=2013.02.02
- db.url=zip:http://appup.forge.codelutin.com/tutti/auth/tutti-db-2013.02.02.…
- db.auth=true
-
-Au démarrage de l'application le fichier est lu et si un des composants est
-plus récent dans la description du fichier de mises à jour, il est téléchargé
-puis l'application l'intègre.
-
-Chaque composant téléchargeable doit être un fichier zip (mais d'autre formats
-d'archivage sont possibles) et contenir un seul répertoire (il n'est pas
-possible d'avoir le composant directement à la racine de l'archive).
-
-Mettre en place une nouvelle mise à jour
-----------------------------------------
-
-Pour pouvoir définir une nouvelle mise à jour, il faut donc modifier le fichier
-de mises à jour :
-
-1. changer la version du composant
-2. changer l'url de téléchargement du composant.
-
-Mise à jour sécurisées
-----------------------
-
-La mise à jour de la base est sécurisée, à savoir que l'url d'accès au zip de
-la base requière un mot de passe.
-
-Le fichier de mise à jour quand à lui sera toujours disponible publiquement.
-
-Pré-requis à la création d'une nouvelle version de Tutti
---------------------------------------------------------
-
-pour pouvoir créer une nouvelle version de Tutti, il nous faut connaitre la
-dernière mise à jour de la base.
-
-Ainsi nous pourrons monter les version du fichier de mise à jour automatiquement.
-
-Les autres composants (jre, tutti et i18n) sont automatiquement gérés lors de
-la création de la nouvelle version.
\ No newline at end of file
Copied: trunk/src/site/rst/update.rst.vm (from rev 694, trunk/src/site/rst/update.rst)
===================================================================
--- trunk/src/site/rst/update.rst.vm (rev 0)
+++ trunk/src/site/rst/update.rst.vm 2013-03-27 23:46:24 UTC (rev 695)
@@ -0,0 +1,129 @@
+.. -
+.. * #%L
+.. * Tutti
+.. * $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%
+.. -
+
+=======================
+Mise à jour du logiciel
+=======================
+
+Présentation
+------------
+
+**Tutti** utilise un mécanisme simple pour effectuer les mises à jour de ses
+différents composants, à savoir:
+
+1. Mise à jour de la JRE
+2. Mise à jour du programme Tutti
+3. Mise à jour des fichiers de traductions
+4. Mise à jour des fichiers d'aide
+5. Mise à jour de la base de données.
+
+Principe des mises à jour
+-------------------------
+
+Chaque composant est contenu dans un répertoire et possède un fichier
+obligatoirement nommé **version.appup** qui contient la version du composant.
+
+Un fichier de propriétés disponible sur le réseau à l'adresse suivante:
+http://appup.forge.codelutin.com/tutti/update-tutti.properties
+
+contient la description des dernières version disponibles.
+
+::
+
+ ################################################################################
+ ### JRE Updates ################################################################
+ ################################################################################
+
+ jre.version=${jreVersion}
+ linux.i386.jre.url=zip:http://nexus.nuiton.org/nexus/content/repositories/j…
+ windows.i386.jre.url=zip:http://nexus.nuiton.org/nexus/content/repositories…
+
+ ################################################################################
+ ### Tutti Updates ##############################################################
+ ################################################################################
+
+ tutti.version=${project.version}
+ tutti.url=zip:http://nexus.nuiton.org/nexus/content/repositories/other-rele…
+
+ ################################################################################
+ ### I18n Updates ###############################################################
+ ################################################################################
+
+ i18n.version=${project.version}
+ i18n.url=zip:http://nexus.nuiton.org/nexus/content/repositories/other-relea…
+
+ ################################################################################
+ ### Help Updates ###############################################################
+ ################################################################################
+
+ help.version=${project.version}
+ help.url=zip:http://nexus.nuiton.org/nexus/content/repositories/other-relea…
+
+ ################################################################################
+ ### DB Updates #################################################################
+ ################################################################################
+
+ db.version=@dbVersion@
+ db.url=zip:http://appup.nuiton.org/tutti/auth/tutti-db-@dbVersion@.zip
+ db.auth=true
+
+Au démarrage de l'application le fichier est lu et si un des composants est
+plus récent dans la description du fichier de mises à jour, il est téléchargé
+puis l'application l'intègre.
+
+Chaque composant téléchargeable doit être un fichier zip (mais d'autre formats
+d'archivage sont possibles) et contenir un seul répertoire (il n'est pas
+possible d'avoir le composant directement à la racine de l'archive).
+
+Vous pouvez télécharger les composants fournis dans le fichier des mises à jours.
+
+Mettre en place une nouvelle mise à jour
+----------------------------------------
+
+Pour pouvoir définir une nouvelle mise à jour, il faut donc modifier le fichier
+de mises à jour :
+
+1. changer la version du composant
+2. créer l'archive de la mise à jour
+3. changer l'url de téléchargement du composant.
+4. déployer l'archive
+
+Mise à jour sécurisées
+----------------------
+
+La mise à jour de la base est sécurisée, à savoir que l'url d'accès au zip de
+la base requière un mot de passe.
+
+Le fichier de mise à jour quand à lui sera toujours disponible publiquement.
+
+Pré-requis à la création d'une nouvelle version de Tutti
+--------------------------------------------------------
+
+Pour pouvoir créer une nouvelle version de Tutti, il nous faut connaitre la
+dernière mise à jour de la base.
+
+Ainsi nous pourrons monter les versions du fichier de mise à jour automatiquement.
+
+Les autres composants (jre, tutti, i18n, help) sont automatiquement gérés lors de
+la création de la nouvelle version.
\ No newline at end of file
Modified: trunk/src/update/update-tutti.properties
===================================================================
--- trunk/src/update/update-tutti.properties 2013-03-27 21:56:27 UTC (rev 694)
+++ trunk/src/update/update-tutti.properties 2013-03-27 23:46:24 UTC (rev 695)
@@ -27,10 +27,10 @@
################################################################################
jre.version=@jreVersion@
-linux.amd64.jre.url=zip:http://nexus.nuiton.org/nexus/content/repositories/jvm/com/oracle/jre/@jreVersion@/jre-@jreVersion@-linux-x64.zip
linux.i386.jre.url=zip:http://nexus.nuiton.org/nexus/content/repositories/j…
-windows.amd64.jre.url=zip:http://nexus.nuiton.org/nexus/content/repositories/jvm/com/oracle/jre/@jreVersion@/jre-@jreVersion@-windows-x64.zip
windows.i386.jre.url=zip:http://nexus.nuiton.org/nexus/content/repositories…
+#linux.amd64.jre.url=zip:http://nexus.nuiton.org/nexus/content/repositories/jvm/com/oracle/jre/@jreVersion@/jre-@jreVersion@-linux-x64.zip
+#windows.amd64.jre.url=zip:http://nexus.nuiton.org/nexus/content/repositories/jvm/com/oracle/jre/@jreVersion@/jre-@jreVersion@-windows-x64.zip
################################################################################
### Tutti Updates ##############################################################
Modified: trunk/tutti-persistence/src/main/resources/queries-override.hbm.xml
===================================================================
--- trunk/tutti-persistence/src/main/resources/queries-override.hbm.xml 2013-03-27 21:56:27 UTC (rev 694)
+++ trunk/tutti-persistence/src/main/resources/queries-override.hbm.xml 2013-03-27 23:46:24 UTC (rev 695)
@@ -498,11 +498,36 @@
<query-param name="locationId" type="java.lang.Integer"/>
</query>
+
+ <!-- [REF-T06] Get all ObjectType -->
+ <query cacheable="true" name="allObjectType">
+ <![CDATA[
+ SELECT
+ p.code AS objectTypeCode,
+ p.name AS objectTypeName,
+ p.description AS objectTypeDescription
+ FROM ObjectTypeImpl p
+ ]]>
+ </query>
+
+ <!-- [REF-T06-1] Get one ObjectType -->
+ <query cacheable="true" name="objectType">
+ <![CDATA[
+ SELECT
+ p.code AS objectTypeCode,
+ p.name AS objectTypeName,
+ p.description AS objectTypeDescription
+ FROM ObjectTypeImpl p
+ WHERE p.code = :objectTypeCode
+ ]]>
+ <query-param name="objectTypeCode" type="java.lang.String"/>
+ </query>
+
<!-- ===================================================================== -->
<!-- === Requete sur référentiels [REF-XXX] === -->
<!-- ===================================================================== -->
- <!-- [REF-03] Get all fishing operation strata / substrata / localite -->
+ <!-- [REF-01] Get all fishing operation strata / substrata / localite -->
<query cacheable="true" name="allFishingOperationLocationByParent">
<![CDATA[
SELECT
@@ -529,7 +554,7 @@
<query-param name="statusTemporaryCode" type="java.lang.String"/>
</query>
- <!-- [REF-04] et [REF-05] Get all vessel for a given vesselType -->
+ <!-- [REF-02] Get all vessel for a given vesselType -->
<query cacheable="true" name="allVessels">
<![CDATA[
SELECT
@@ -557,27 +582,7 @@
<query-param name="statusTemporaryCode" type="java.lang.String"/>
</query>
- <query cacheable="true" name="allSimpleVessels">
- <![CDATA[
- SELECT
- v.code AS vesselCode,
- vf.name AS vesselName,
- v.status AS status,
- vf.startDateTime
- FROM
- VesselImpl v
- INNER JOIN v.vesselFeatures AS vf
- WHERE
- v.vesselType.id = :vesselTypeId
- AND v.status.code IN (:statusValidCode, :statusTemporaryCode)
- ORDER BY vf.startDateTime DESC
- ]]>
- <query-param name="vesselTypeId" type="java.lang.Integer"/>
- <query-param name="statusValidCode" type="java.lang.String"/>
- <query-param name="statusTemporaryCode" type="java.lang.String"/>
- </query>
-
- <!-- Get a vessel for a given vesselType -->
+ <!-- [REF-02-1] Get a vessel -->
<query cacheable="true" name="vessel">
<![CDATA[
SELECT
@@ -604,26 +609,7 @@
<query-param name="statusTemporaryCode" type="java.lang.String"/>
</query>
- <!-- Get a vessel for a given vesselType -->
- <query cacheable="true" name="vessel2">
- <![CDATA[
- SELECT
- vrp.registrationCode AS nationalRegistrationCode,
- vrp.internationalRegistrationCode as internationalRegistrationCode
- FROM
- VesselImpl v
- INNER JOIN v.vesselRegistrationPeriods AS vrp
- WHERE
- v.code = :vesselCode
- AND NOT(coalesce(vrp.endDateTime, '2999-12-31 00:00:00') < coalesce(:refDate,sysdate)
- OR vrp.vesselRegistrationPeriodPk.startDateTime > coalesce(:refDate,sysdate)
- )
- ]]>
- <query-param name="vesselCode" type="java.lang.String"/>
- <query-param name="refDate" type="java.util.Date"/>
- </query>
-
- <!-- [REF-06] [REF-07] Get all gears -->
+ <!-- [REF-03] Get all gears for a given gearType -->
<query cacheable="true" name="allGears">
<![CDATA[
SELECT
@@ -641,6 +627,7 @@
<query-param name="statusTemporaryCode" type="java.lang.String"/>
</query>
+ <!-- [REF-03-1] Get a gear -->
<query cacheable="true" name="gear">
<![CDATA[
SELECT
@@ -655,7 +642,7 @@
<query-param name="gearId" type="java.lang.Integer"/>
</query>
- <!-- [REF-08] Get all persons -->
+ <!-- [REF-04] Get all persons -->
<query cacheable="true" name="allPersons">
<![CDATA[
SELECT DISTINCT
@@ -683,7 +670,7 @@
<query-param name="statusTemporaryCode" type="java.lang.String"/>
</query>
- <!-- [REF-08-1] Get one person -->
+ <!-- [REF-04-1] Get one person -->
<query cacheable="true" name="person">
<![CDATA[
SELECT DISTINCT
@@ -698,64 +685,6 @@
<query-param name="personId" type="java.lang.Integer"/>
</query>
- <!-- [REF-16] Get all length step catacteristics -->
- <query cacheable="true" name="allLengthStepCaracteristics">
- <![CDATA[
- SELECT
- p.id AS pmfmId,
- p.parameter.name AS parameterName,
- p.matrix.name AS matrixName,
- p.fraction.name AS fractionName,
- p.method.name AS methodName,
- p.parameter.isAlphanumeric AS isAlphanumeric,
- p.parameter.isQualitative AS isQualitative,
- p.signifFiguresNumber,
- p.maximumNumberDecimals,
- p.precision,
- p.unit.symbol AS symbol,
- p.status AS status
- FROM PmfmImpl p
- WHERE
- p.status.code IN (:statusValidCode, :statusTemporaryCode)
- AND p.matrix.id = :matrixId
- AND p.parameter.isQualitative=false
- AND p.parameter.isAlphanumeric=false
- AND p.parameter.isCalculated=false
- AND p.parameter.code not in (:ageParameterCode, :weightParameterCode)
- AND p.method.id <> :methodDeclarationId
- ]]>
- <query-param name="matrixId" type="java.lang.Integer"/>
- <query-param name="ageParameterCode" type="java.lang.String"/>
- <query-param name="weightParameterCode" type="java.lang.String"/>
- <query-param name="methodDeclarationId" type="java.lang.Integer"/>
- <query-param name="statusValidCode" type="java.lang.String"/>
- <query-param name="statusTemporaryCode" type="java.lang.String"/>
- </query>
-
- <!-- [REF-17] Get all ObjectType -->
- <query cacheable="true" name="allObjectType">
- <![CDATA[
- SELECT
- p.code AS objectTypeCode,
- p.name AS objectTypeName,
- p.description AS objectTypeDescription
- FROM ObjectTypeImpl p
- ]]>
- </query>
-
- <!-- [REF-18] Get one ObjectType -->
- <query cacheable="true" name="objectType">
- <![CDATA[
- SELECT
- p.code AS objectTypeCode,
- p.name AS objectTypeName,
- p.description AS objectTypeDescription
- FROM ObjectTypeImpl p
- WHERE p.code = :objectTypeCode
- ]]>
- <query-param name="objectTypeCode" type="java.lang.String"/>
- </query>
-
<!-- ===================================================================== -->
<!-- === Fetch profiles === -->
<!-- ===================================================================== -->
Modified: trunk/tutti-ui-swing/pom.xml
===================================================================
--- trunk/tutti-ui-swing/pom.xml 2013-03-27 21:56:27 UTC (rev 694)
+++ trunk/tutti-ui-swing/pom.xml 2013-03-27 23:46:24 UTC (rev 695)
@@ -249,12 +249,6 @@
<version>${project.version}</version>
</dependency>
- <!--dependency>
- <groupId>org.nuiton</groupId>
- <artifactId>nuiton-profiling</artifactId>
- <version>2.7-SNAPSHOT</version>
- </dependency-->
-
<dependency>
<groupId>org.nuiton</groupId>
<artifactId>nuiton-utils</artifactId>
@@ -366,11 +360,6 @@
<artifactId>swingx-autocomplete</artifactId>
</dependency>
- <!--dependency>
- <groupId>com.ezware.oxbow</groupId>
- <artifactId>swing-bits</artifactId>
- </dependency-->
-
<!-- Logging -->
<dependency>
1
0
27 Mar '13
Author: tchemit
Date: 2013-03-27 22:56:27 +0100 (Wed, 27 Mar 2013)
New Revision: 694
Url: http://forge.codelutin.com/projects/tutti/repository/revisions/694
Log:
prepare release (reformat code, clean imports, ...)
Modified:
trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/ProgressionModel.java
trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistenceImpl.java
trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceService.java
trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/ProtocolPersistenceServiceImpl.java
trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/TuttiEnumerationFile.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/CatchBatchPersistenceServiceWriteTest.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/FishingOperationPersistenceServiceWriteTest.java
trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/protocol/SpeciesRow.java
trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/pupitri/CarrouselRowModel.java
trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/pupitri/PupitriCatch.java
trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/pupitri/SpeciesRow.java
trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/pupitri/SpeciesRowModel.java
trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/pupitri/TuttiPupitriImportExportService.java
trunk/tutti-service/src/test/java/fr/ifremer/tutti/service/referential/TuttiReferentialImportExportServiceTest.java
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/ImportTemporaryReferentialAction.java
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/config/SampleOrderEditorUIHandler.java
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/home/CloneProtocolAction.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/operation/EditFishingOperationAction.java
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationUIModel.java
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/FishingOperationsUIHandler.java
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/FishingOperationsUIModel.java
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/CancelEditCatchBatchAction.java
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUIModel.java
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/ImportPupitriAction.java
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/ImportPupitriPopupUI.jaxx
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/ImportPupitriPopupUIHandler.java
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/SampleCategoryComponent.java
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUIModel.java
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/frequency/BenthosFrequencyCellComponent.java
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/frequency/BenthosFrequencyUI.jaxx
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/frequency/BenthosFrequencyUIHandler.java
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/RemoveSpeciesSubBatchAction.java
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/SpeciesBatchUIModel.java
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUI.jaxx
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSpeciesBatchRowModel.java
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSpeciesBatchUIHandler.java
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/fishing/AbstractCaracteristicTabUIModel.java
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/ExportPupitriAction.java
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/AbstractTuttiUIHandler.java
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/CustomTab.java
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/TabContentModel.java
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/comment/CommentModelAware.java
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/TuttiComputedOrNotDataEditorHandler.java
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/TuttiComputedOrNotDataTableCell.java
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/table/CaracteristicRow.java
trunk/tutti-ui-swing/src/test/java/fr/ifremer/tutti/ui/swing/BeanValidatorDetectorTest.java
Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/ProgressionModel.java
===================================================================
--- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/ProgressionModel.java 2013-03-27 21:49:05 UTC (rev 693)
+++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/ProgressionModel.java 2013-03-27 21:56:27 UTC (rev 694)
@@ -101,11 +101,11 @@
@Override
public void setSize(long size) {
- setTotal((int)size);
+ setTotal((int) size);
}
@Override
public void setCurrent(long current) {
- setCurrent((int)current);
+ setCurrent((int) current);
}
}
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-03-27 21:49:05 UTC (rev 693)
+++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistenceImpl.java 2013-03-27 21:56:27 UTC (rev 694)
@@ -49,8 +49,8 @@
import fr.ifremer.tutti.persistence.entities.referential.Vessel;
import fr.ifremer.tutti.persistence.service.AccidentalBatchPersistenceService;
import fr.ifremer.tutti.persistence.service.AttachmentPersistenceService;
+import fr.ifremer.tutti.persistence.service.BenthosBatchPersistenceService;
import fr.ifremer.tutti.persistence.service.CatchBatchPersistenceService;
-import fr.ifremer.tutti.persistence.service.BenthosBatchPersistenceService;
import fr.ifremer.tutti.persistence.service.CruisePersistenceService;
import fr.ifremer.tutti.persistence.service.FishingOperationPersistenceService;
import fr.ifremer.tutti.persistence.service.MacroWasteBatchPersistenceService;
Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceService.java
===================================================================
--- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceService.java 2013-03-27 21:49:05 UTC (rev 693)
+++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceService.java 2013-03-27 21:56:27 UTC (rev 694)
@@ -51,7 +51,6 @@
* <p/>
* <strong>Note:</strong> All childs of the batch should be loaded here.
*
- *
* @param fishingOperationId if of the fishing operation to seek
* @return the list of root {@link SpeciesBatch}
* @since 1.0
Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/ProtocolPersistenceServiceImpl.java
===================================================================
--- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/ProtocolPersistenceServiceImpl.java 2013-03-27 21:49:05 UTC (rev 693)
+++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/ProtocolPersistenceServiceImpl.java 2013-03-27 21:56:27 UTC (rev 694)
@@ -133,7 +133,7 @@
}
result.setSpecies(species);
- List<SpeciesProtocol> benthos= Lists.newArrayList();
+ List<SpeciesProtocol> benthos = Lists.newArrayList();
if (!bean.isBenthosEmpty()) {
for (SpeciesProtocol speciesProtocol : bean.getBenthos()) {
SpeciesProtocol s = new SpeciesProtocol();
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-03-27 21:49:05 UTC (rev 693)
+++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/TuttiEnumerationFile.java 2013-03-27 21:56:27 UTC (rev 694)
@@ -66,7 +66,7 @@
public final Integer LOCATION_LEVEL_ID_COUNTRY = null;
@Value("${LocationLevelId.PORT}")
- public final Integer LOCATION_LEVEL_ID_HARBOUR= null;
+ public final Integer LOCATION_LEVEL_ID_HARBOUR = null;
@Value("${LocationLevelId.LOCALITE}")
public final Integer LOCATION_LEVEL_ID_LOCALITE = null;
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-03-27 21:49:05 UTC (rev 693)
+++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/entities/protocol/TuttiProtocolsTest.java 2013-03-27 21:56:27 UTC (rev 694)
@@ -159,7 +159,7 @@
Assert.assertEquals(Lists.newArrayList("14", "18"), protocol.getLengthClassesPmfmId());
Assert.assertEquals(Lists.newArrayList("114", "228", "821"), protocol.getVesselUseFeaturePmfmId());
Assert.assertEquals(Lists.newArrayList("21", "22"), protocol.getGearUseFeaturePmfmId());
-
+
Assert.assertNotNull(protocol.getSpecies());
Assert.assertEquals(2, protocol.getSpecies().size());
SpeciesProtocol sp1 = protocol.getSpecies().get(0);
@@ -281,7 +281,7 @@
b2.setSizeEnabled(true);
b2.setWeightEnabled(true);
protocol.addBenthos(b2);
-
+
return protocol;
}
Modified: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/CatchBatchPersistenceServiceWriteTest.java
===================================================================
--- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/CatchBatchPersistenceServiceWriteTest.java 2013-03-27 21:49:05 UTC (rev 693)
+++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/CatchBatchPersistenceServiceWriteTest.java 2013-03-27 21:56:27 UTC (rev 694)
@@ -220,7 +220,7 @@
catchBatch.setSpeciesTotalLivingNotItemizedWeight(0.2f);
catchBatch.setSpeciesTotalInertWeight(0.1f);
}
-
+
// Benthos
{
catchBatch.setBenthosTotalSortedWeight(24f);
Modified: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/CruisePersistenceServiceWriteTest.java
===================================================================
--- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/CruisePersistenceServiceWriteTest.java 2013-03-27 21:49:05 UTC (rev 693)
+++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/CruisePersistenceServiceWriteTest.java 2013-03-27 21:56:27 UTC (rev 694)
@@ -82,7 +82,7 @@
// -----------------------------------------------------------------------------
// 1. Test with all properties filled
// -----------------------------------------------------------------------------
- cruise.setId((String)null);
+ cruise.setId((String) null);
cruise.setName("Unit-test-" + System.currentTimeMillis());
@@ -148,7 +148,7 @@
// -----------------------------------------------------------------------------
// 2. Test with only mandatory properties
// -----------------------------------------------------------------------------
- createdCruise.setId((String)null);
+ createdCruise.setId((String) null);
createdCruise.setHeadOfMission(null);
// createdCruise.setBeginDate(cruise.getBeginDate());
// createdCruise.setEndDate(cruise.getEndDate());
@@ -203,7 +203,7 @@
// -----------------------------------------------------------------------------
Cruise cruise = service.getCruise(dbResource.getFixtures().cruiseId());
- cruise.setId((String)null);
+ cruise.setId((String) null);
Calendar calendar = new GregorianCalendar();
cruise.setBeginDate(calendar.getTime());
Modified: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceServiceWriteTest.java
===================================================================
--- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceServiceWriteTest.java 2013-03-27 21:49:05 UTC (rev 693)
+++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceServiceWriteTest.java 2013-03-27 21:56:27 UTC (rev 694)
@@ -87,7 +87,7 @@
// Duplicate an existing cruise, to attach new fishing operations
cruise = cruiseService.getCruise(dbResource.getFixtures().cruiseId());
- cruise.setId((String)null);
+ cruise.setId((String) null);
cruise.setName("Unit-test-" + System.currentTimeMillis());
Calendar calendar = new GregorianCalendar();
cruise.setBeginDate(calendar.getTime());
@@ -206,7 +206,7 @@
// 2. Test with all properties set
// -----------------------------------------------------------------------------
// Set properties
- fishingOperation.setId((String)null);
+ fishingOperation.setId((String) null);
fishingOperation.setStationNumber("STA2");
fishingOperation.setFishingOperationNumber(2);
fishingOperation.setMultirigAggregation("1");
@@ -319,7 +319,7 @@
// - 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((String)null);
+ fishingOperation.setId((String) null);
// Find and set a gear not used in the cruise
List<Gear> gears = referentialService.getAllFishingGear();
Modified: trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/protocol/SpeciesRow.java
===================================================================
--- trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/protocol/SpeciesRow.java 2013-03-27 21:49:05 UTC (rev 693)
+++ trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/protocol/SpeciesRow.java 2013-03-27 21:56:27 UTC (rev 694)
@@ -27,9 +27,9 @@
import fr.ifremer.tutti.persistence.entities.protocol.SpeciesProtocol;
import fr.ifremer.tutti.persistence.entities.referential.Caracteristic;
import fr.ifremer.tutti.persistence.entities.referential.Species;
+import org.apache.commons.lang3.StringUtils;
import java.io.Serializable;
-import org.apache.commons.lang3.StringUtils;
/**
* Row of a {@link SpeciesProtocol} to import or export.
@@ -104,7 +104,7 @@
if (!StringUtils.isEmpty(name)) {
boolean madeFromAReferentTaxon = isMadeFromAReferentTaxon();
setMadeFromAReferentTaxon(madeFromAReferentTaxon &&
- species != null && species.getName().equals(name));
+ species != null && species.getName().equals(name));
}
}
@@ -116,7 +116,7 @@
if (!StringUtils.isEmpty(refTaxCode)) {
boolean madeFromAReferentTaxon = isMadeFromAReferentTaxon();
setMadeFromAReferentTaxon(madeFromAReferentTaxon &&
- species != null && species.getRefTaxCode().equals(refTaxCode));
+ species != null && species.getRefTaxCode().equals(refTaxCode));
}
}
Modified: trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/pupitri/CarrouselRowModel.java
===================================================================
--- trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/pupitri/CarrouselRowModel.java 2013-03-27 21:49:05 UTC (rev 693)
+++ trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/pupitri/CarrouselRowModel.java 2013-03-27 21:56:27 UTC (rev 694)
@@ -25,12 +25,13 @@
*/
import fr.ifremer.tutti.service.TuttiCsvUtil;
-import java.text.ParseException;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.nuiton.util.csv.ValueParser;
+import java.text.ParseException;
+
/**
* @author kmorin <kmorin(a)codelutin.com>
* @since 1.2
Modified: trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/pupitri/PupitriCatch.java
===================================================================
--- trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/pupitri/PupitriCatch.java 2013-03-27 21:49:05 UTC (rev 693)
+++ trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/pupitri/PupitriCatch.java 2013-03-27 21:56:27 UTC (rev 694)
@@ -1,13 +1,36 @@
-
package fr.ifremer.tutti.service.pupitri;
+/*
+ * #%L
+ * Tutti :: Service
+ * $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.entities.referential.Species;
+
import java.io.Serializable;
import java.util.Map;
/**
- *
* @author kmorin <kmorin(a)codelutin.com>
* @since 1.2
*/
Property changes on: trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/pupitri/PupitriCatch.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/pupitri/SpeciesRow.java
===================================================================
--- trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/pupitri/SpeciesRow.java 2013-03-27 21:49:05 UTC (rev 693)
+++ trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/pupitri/SpeciesRow.java 2013-03-27 21:56:27 UTC (rev 694)
@@ -1,10 +1,32 @@
-
package fr.ifremer.tutti.service.pupitri;
+/*
+ * #%L
+ * Tutti :: Service
+ * $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 java.io.Serializable;
/**
- *
* @author kmorin <kmorin(a)codelutin.com>
* @since 1.2
*/
Property changes on: trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/pupitri/SpeciesRow.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/pupitri/SpeciesRowModel.java
===================================================================
--- trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/pupitri/SpeciesRowModel.java 2013-03-27 21:49:05 UTC (rev 693)
+++ trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/pupitri/SpeciesRowModel.java 2013-03-27 21:56:27 UTC (rev 694)
@@ -25,11 +25,8 @@
*/
import fr.ifremer.tutti.service.TuttiCsvUtil;
-import java.text.ParseException;
-import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.nuiton.util.csv.ValueParser;
/**
* @author kmorin <kmorin(a)codelutin.com>
Modified: trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/pupitri/TuttiPupitriImportExportService.java
===================================================================
--- trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/pupitri/TuttiPupitriImportExportService.java 2013-03-27 21:49:05 UTC (rev 693)
+++ trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/pupitri/TuttiPupitriImportExportService.java 2013-03-27 21:56:27 UTC (rev 694)
@@ -43,19 +43,19 @@
import fr.ifremer.tutti.persistence.entities.data.SizeEnum;
import fr.ifremer.tutti.persistence.entities.data.SortedUnsortedEnum;
import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch;
-import fr.ifremer.tutti.persistence.entities.protocol.SpeciesProtocol;
import fr.ifremer.tutti.persistence.entities.referential.Caracteristic;
import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativeValue;
import fr.ifremer.tutti.persistence.entities.referential.Species;
import fr.ifremer.tutti.service.AbstractTuttiService;
import fr.ifremer.tutti.service.PersistenceService;
import fr.ifremer.tutti.service.TuttiServiceContext;
-import fr.ifremer.tutti.service.protocol.TuttiProtocolImportExportService;
-import java.io.BufferedWriter;
+import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.nuiton.util.csv.Export;
import org.nuiton.util.csv.Import;
import java.io.File;
@@ -65,10 +65,6 @@
import java.util.Collections;
import java.util.List;
import java.util.Map;
-import org.apache.commons.collections.CollectionUtils;
-import org.apache.commons.lang3.StringUtils;
-import org.nuiton.util.csv.Export;
-import org.nuiton.util.csv.ExportModel;
/**
* @author kmorin <kmorin(a)codelutin.com>
@@ -130,7 +126,7 @@
addFileAsAttachment(trunkFile, catchBatch);
addFileAsAttachment(carrouselFile, catchBatch);
addFileAsAttachment(speciesFile, catchBatch);
-
+
persistenceService.saveCatchBatch(catchBatch);
}
@@ -217,10 +213,10 @@
}
protected void importPupitriCarrousel(File carrouselFile,
- File speciesFile,
- FishingOperation operation,
- CatchBatch catchBatch,
- List<Species> referentSpecies) {
+ File speciesFile,
+ FishingOperation operation,
+ CatchBatch catchBatch,
+ List<Species> referentSpecies) {
if (log.isInfoEnabled()) {
log.info("Will import pupitri operation [" + operation.toString() +
@@ -241,25 +237,25 @@
try {
// import the species
- String[] header = new String [] {
- SpeciesRow.PROPERTY_CODE_FIRST_PART,
- SpeciesRow.PROPERTY_CODE_SECOND_PART,
- SpeciesRow.PROPERTY_SCIENTIFIC_NAME
- };
+ String[] header = new String[]{
+ SpeciesRow.PROPERTY_CODE_FIRST_PART,
+ SpeciesRow.PROPERTY_CODE_SECOND_PART,
+ SpeciesRow.PROPERTY_SCIENTIFIC_NAME
+ };
fileWithHeaders = createFileWithHeaders(speciesFile, header, speciesSeparator);
reader = Files.newReader(fileWithHeaders, Charsets.UTF_8);
speciesImporter = Import.newImport(speciesCsvModel, reader);
// get the map of species by survey code
Multimap<String, Species> speciesBySurveyCode =
- Multimaps.index(referentSpecies, new Function<Species, String>() {
- @Override
- public String apply(Species input) {
- String surveyCode = String.valueOf(input.getSurveyCode());
- int end = Math.min(surveyCode.length(), 7);
- return surveyCode.substring(0, end);
- }
- });
+ Multimaps.index(referentSpecies, new Function<Species, String>() {
+ @Override
+ public String apply(Species input) {
+ String surveyCode = String.valueOf(input.getSurveyCode());
+ int end = Math.min(surveyCode.length(), 7);
+ return surveyCode.substring(0, end);
+ }
+ });
// keep only the species whose survey code and name are the same
// in theimported file and the referent species
Map<String, Species> speciesMap = Maps.newHashMap();
@@ -275,20 +271,20 @@
}
// import the batches
- header = new String[] {
- CarrouselRow.PROPERTY_FILE_ORIGIN,
- CarrouselRow.PROPERTY_DATE,
- CarrouselRow.PROPERTY_TIME,
- CarrouselRow.PROPERTY_BALANCE_ID,
- CarrouselRow.PROPERTY_TO_CONFIRM,
- CarrouselRow.PROPERTY_OPERATION_CODE,
- CarrouselRow.PROPERTY_RIG_NUMBER,
- CarrouselRow.PROPERTY_BOX_TYPE,
- CarrouselRow.PROPERTY_SPECIES_ID,
- CarrouselRow.PROPERTY_SIGN,
- CarrouselRow.PROPERTY_DIRECTION,
- CarrouselRow.PROPERTY_WEIGHT
- };
+ header = new String[]{
+ CarrouselRow.PROPERTY_FILE_ORIGIN,
+ CarrouselRow.PROPERTY_DATE,
+ CarrouselRow.PROPERTY_TIME,
+ CarrouselRow.PROPERTY_BALANCE_ID,
+ CarrouselRow.PROPERTY_TO_CONFIRM,
+ CarrouselRow.PROPERTY_OPERATION_CODE,
+ CarrouselRow.PROPERTY_RIG_NUMBER,
+ CarrouselRow.PROPERTY_BOX_TYPE,
+ CarrouselRow.PROPERTY_SPECIES_ID,
+ CarrouselRow.PROPERTY_SIGN,
+ CarrouselRow.PROPERTY_DIRECTION,
+ CarrouselRow.PROPERTY_WEIGHT
+ };
fileWithHeaders = createFileWithHeaders(carrouselFile, header, carrouselSeparator);
reader = Files.newReader(fileWithHeaders, Charsets.UTF_8);
carrouselImporter = Import.newImport(carrouselCsvModel, reader);
@@ -302,7 +298,7 @@
for (CarrouselRow bean : carrouselImporter) {
// is the bean from the current operation and rig ?
if (bean.getOperationCode().equals(operationNumber)
- && bean.getRigNumber().equals(rigNumber)) {
+ && bean.getRigNumber().equals(rigNumber)) {
String speciesId = bean.getSpeciesId();
Species species = speciesMap.get(speciesId);
@@ -316,7 +312,7 @@
sorted = false;
break;
- default :
+ default:
sorted = true;
carrouselSortedWeight += beanWeight;
}
@@ -345,7 +341,7 @@
Float catchWeight = pupitriCatch.getWeightBySign().get(PupitriCatch.Signs.DEFAULT);
CaracteristicQualitativeValue cqv = pupitriCatch.isSorted() ?
- sortedCaracteristic : unsortedCaracteristic;
+ sortedCaracteristic : unsortedCaracteristic;
SpeciesBatch batch = new SpeciesBatch();
batch.setFishingOperation(operation);
@@ -387,7 +383,7 @@
category = SampleCategoryEnum.size;
break;
}
-
+
SpeciesBatch childBatch = new SpeciesBatch();
childBatch.setFishingOperation(operation);
childBatch.setSampleCategoryType(category);
@@ -413,7 +409,6 @@
IOUtils.closeQuietly(reader);
FileUtils.deleteQuietly(fileWithHeaders);
}
-
}
public void exportSpecies(List<Species> species, File target) {
@@ -426,7 +421,7 @@
public SpeciesRow apply(Species input) {
Preconditions.checkNotNull(input.getSurveyCode(),
- "Unable to export a species with a null survey code : " + input);
+ "Unable to export a species with a null survey code : " + input);
SpeciesRow row = new SpeciesRow();
String codeFirstPart = StringUtils.substring(input.getSurveyCode(), 0, 4);
row.setCodeFirstPart(StringUtils.rightPad(codeFirstPart, 4));
Modified: trunk/tutti-service/src/test/java/fr/ifremer/tutti/service/referential/TuttiReferentialImportExportServiceTest.java
===================================================================
--- trunk/tutti-service/src/test/java/fr/ifremer/tutti/service/referential/TuttiReferentialImportExportServiceTest.java 2013-03-27 21:49:05 UTC (rev 693)
+++ trunk/tutti-service/src/test/java/fr/ifremer/tutti/service/referential/TuttiReferentialImportExportServiceTest.java 2013-03-27 21:56:27 UTC (rev 694)
@@ -43,10 +43,10 @@
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestName;
-import org.nuiton.util.config.ApplicationConfig;
import org.nuiton.util.FileUtil;
import org.nuiton.util.beans.Binder;
import org.nuiton.util.beans.BinderFactory;
+import org.nuiton.util.config.ApplicationConfig;
import java.io.File;
import java.util.List;
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/ImportTemporaryReferentialAction.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/ImportTemporaryReferentialAction.java 2013-03-27 21:49:05 UTC (rev 693)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/ImportTemporaryReferentialAction.java 2013-03-27 21:56:27 UTC (rev 694)
@@ -28,8 +28,8 @@
import org.apache.commons.lang.StringUtils;
import org.springframework.util.DigestUtils;
-import javax.swing.*;
-import java.security.MessageDigest;
+import javax.swing.JOptionPane;
+import javax.swing.SwingUtilities;
import static org.nuiton.i18n.I18n._;
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/config/SampleOrderEditorUIHandler.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/config/SampleOrderEditorUIHandler.java 2013-03-27 21:49:05 UTC (rev 693)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/config/SampleOrderEditorUIHandler.java 2013-03-27 21:56:27 UTC (rev 694)
@@ -164,7 +164,7 @@
if (e.getKeyCode() == KeyEvent.VK_DOWN) {
- if (selectedIndex < listModel.size() ) {
+ if (selectedIndex < listModel.size()) {
// can move to down
newSelectedIndex = selectedIndex - 1;
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/home/CloneProtocolAction.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/home/CloneProtocolAction.java 2013-03-27 21:49:05 UTC (rev 693)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/home/CloneProtocolAction.java 2013-03-27 21:56:27 UTC (rev 694)
@@ -61,7 +61,7 @@
TuttiProtocol protocol = getContext().getPersistenceService().getProtocol(getContext().getProtocolId());
// remove id
- protocol.setId(null);
+ protocol.setId((String) null);
// store protocol in context
CLONE_PROTOCOL_ENTRY.setContextValue(getContext().getMainUI(), protocol);
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-03-27 21:49:05 UTC (rev 693)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/home/ImportProtocolAction.java 2013-03-27 21:56:27 UTC (rev 694)
@@ -103,7 +103,7 @@
IMPORT_PROTOCOL_ENTRY.setContextValue(getContext().getMainUI(), protocol);
// remove id
- protocol.setId(null);
+ protocol.setId((String) null);
// removed selected protocol
getContext().setProtocolId(null);
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationAction.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationAction.java 2013-03-27 21:49:05 UTC (rev 693)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationAction.java 2013-03-27 21:56:27 UTC (rev 694)
@@ -532,7 +532,7 @@
Integer objectId = Integer.valueOf(batch.getId());
attachments = persistenceService.getAllAttachments(objectId);
getModel().setCatchEnabled(true);
-
+
} catch (InvalidBatchModelException e) {
// batch is not compatible with Tutti
@@ -565,7 +565,7 @@
// 4) Propagate new selected fishingoperation to others tabs
- ui.getSpeciesTabContent().getHandler().selectFishingOperation(batch == null ? null : bean);
+ ui.getSpeciesTabContent().getHandler().selectFishingOperation(batch == null ? null : bean);
ui.getBenthosTabContent().getHandler().selectFishingOperation(batch == null ? null : bean);
// ui.getPlanktonTabContent().getHandler().selectFishingOperation(bean);
// ui.getMacroWasteTabContent().getHandler().selectFishingOperation(bean);
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationUIModel.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationUIModel.java 2013-03-27 21:49:05 UTC (rev 693)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationUIModel.java 2013-03-27 21:56:27 UTC (rev 694)
@@ -60,7 +60,7 @@
* @since 0.1
*/
public class EditFishingOperationUIModel extends AbstractTuttiBeanUIModel<FishingOperation, EditFishingOperationUIModel>
- implements AttachmentModelAware, TabContentModel {
+ implements AttachmentModelAware, TabContentModel {
private static final long serialVersionUID = 1L;
@@ -227,20 +227,20 @@
public boolean isEmpty() {
return StringUtils.isEmpty(stationNumber)
- && fishingOperationNumber == null
- && strata == null
- && subStrata == null
- && location == null
- && gearShootingStartLatitudeAsSexagecimal.isNull()
- && gearShootingStartLongitudeAsSexagecimal.isNull()
- && gearShootingStartDate == null
- && gearShootingEndLatitudeAsSexagecimal.isNull()
- && gearShootingEndLongitudeAsSexagecimal.isNull()
- && gearShootingEndDate == null
- && recorderPerson == null
- && gear == null
- && StringUtils.isEmpty(comment)
- && CollectionUtils.isEmpty(getAttachment());
+ && fishingOperationNumber == null
+ && strata == null
+ && subStrata == null
+ && location == null
+ && gearShootingStartLatitudeAsSexagecimal.isNull()
+ && gearShootingStartLongitudeAsSexagecimal.isNull()
+ && gearShootingStartDate == null
+ && gearShootingEndLatitudeAsSexagecimal.isNull()
+ && gearShootingEndLongitudeAsSexagecimal.isNull()
+ && gearShootingEndDate == null
+ && recorderPerson == null
+ && gear == null
+ && StringUtils.isEmpty(comment)
+ && CollectionUtils.isEmpty(getAttachment());
// TODO add the otehr ones
}
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/FishingOperationsUIHandler.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/FishingOperationsUIHandler.java 2013-03-27 21:49:05 UTC (rev 693)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/FishingOperationsUIHandler.java 2013-03-27 21:56:27 UTC (rev 694)
@@ -148,8 +148,8 @@
}
editFishingOperationAction.setFishingOperation(operation);
// try {
- AbstractTuttiAction.runAction(editFishingOperationAction);
-
+ AbstractTuttiAction.runAction(editFishingOperationAction);
+
// } catch(RuntimeException e) {
// getModel().setSelectedFishingOperation(null);
//// throw e;
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/FishingOperationsUIModel.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/FishingOperationsUIModel.java 2013-03-27 21:49:05 UTC (rev 693)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/FishingOperationsUIModel.java 2013-03-27 21:56:27 UTC (rev 694)
@@ -53,6 +53,7 @@
public static final String PROPERTY_SELECTED_FISHING_OPERATION = "selectedFishingOperation";
public static final String PROPERTY_EDITED_FISHING_OPERATION = "editedFishingOperation";
+
public static final String PROPERTY_CATCH_ENABLED = "catchEnabled";
/**
@@ -109,6 +110,7 @@
/**
* Flag to use or not catch tab.
+ *
* @since 1.1
*/
protected boolean catchEnabled;
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/CancelEditCatchBatchAction.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/CancelEditCatchBatchAction.java 2013-03-27 21:49:05 UTC (rev 693)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/CancelEditCatchBatchAction.java 2013-03-27 21:56:27 UTC (rev 694)
@@ -60,8 +60,8 @@
public EditFishingOperationAction getEditAction() {
if (editAction == null) {
- editAction = TuttiActionHelper.createLogicAction( getHandler().getParentHandler(),
- EditFishingOperationAction.class);
+ editAction = TuttiActionHelper.createLogicAction(getHandler().getParentHandler(),
+ EditFishingOperationAction.class);
}
return editAction;
}
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUIModel.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUIModel.java 2013-03-27 21:49:05 UTC (rev 693)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUIModel.java 2013-03-27 21:56:27 UTC (rev 694)
@@ -646,8 +646,8 @@
@Override
public boolean isEmpty() {
return getCatchTotalWeight() == null
- && getCatchTotalRejectedWeight() == null
- && CollectionUtils.isEmpty(getAttachment());
+ && getCatchTotalRejectedWeight() == null
+ && CollectionUtils.isEmpty(getAttachment());
}
@Override
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/ImportPupitriAction.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/ImportPupitriAction.java 2013-03-27 21:49:05 UTC (rev 693)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/ImportPupitriAction.java 2013-03-27 21:56:27 UTC (rev 694)
@@ -24,26 +24,13 @@
* #L%
*/
-import com.google.common.collect.Lists;
-import fr.ifremer.tutti.persistence.entities.data.Attachment;
import fr.ifremer.tutti.persistence.entities.data.CatchBatch;
import fr.ifremer.tutti.persistence.entities.data.FishingOperation;
-import fr.ifremer.tutti.persistence.entities.data.SampleCategoryEnum;
-import fr.ifremer.tutti.persistence.entities.data.SexEnum;
-import fr.ifremer.tutti.persistence.entities.data.SizeEnum;
-import fr.ifremer.tutti.persistence.entities.data.SortedUnsortedEnum;
import fr.ifremer.tutti.persistence.entities.protocol.TuttiProtocol;
-import fr.ifremer.tutti.persistence.entities.referential.Caracteristic;
-import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativeValue;
-import fr.ifremer.tutti.persistence.entities.referential.Species;
import fr.ifremer.tutti.service.PersistenceService;
-import fr.ifremer.tutti.service.pupitri.PupitriCatch;
import fr.ifremer.tutti.service.pupitri.TuttiPupitriImportExportService;
import fr.ifremer.tutti.ui.swing.content.operation.EditFishingOperationAction;
-import fr.ifremer.tutti.ui.swing.content.operation.catches.species.SpeciesBatchRowModel;
-import fr.ifremer.tutti.ui.swing.content.operation.catches.species.SpeciesBatchUIHandler;
import fr.ifremer.tutti.ui.swing.content.operation.catches.species.SpeciesBatchUIModel;
-import fr.ifremer.tutti.ui.swing.content.operation.catches.species.split.SplitSpeciesBatchRowModel;
import fr.ifremer.tutti.ui.swing.util.AbstractTuttiUIHandler;
import fr.ifremer.tutti.ui.swing.util.action.AbstractTuttiAction;
import fr.ifremer.tutti.ui.swing.util.action.TuttiActionHelper;
@@ -52,7 +39,6 @@
import javax.swing.JOptionPane;
import java.io.File;
-import java.util.List;
import static org.nuiton.i18n.I18n._;
@@ -86,22 +72,21 @@
public EditFishingOperationAction getEditAction() {
if (editAction == null) {
- editAction = TuttiActionHelper.createLogicAction( getHandler().getParentHandler(),
- EditFishingOperationAction.class);
+ editAction = TuttiActionHelper.createLogicAction(getHandler().getParentHandler(),
+ EditFishingOperationAction.class);
}
return editAction;
}
@Override
protected boolean prepareAction() throws Exception {
- boolean result = true;
+ boolean result;
if (!getContext().isProtocolFilled()) {
result = false;
} else {
- String protocolId = getContext().getProtocolId();
- currentProtocol = persistenceService.getProtocol(protocolId);
+ currentProtocol = getDataContext().getProtocol();
result = currentProtocol != null && !currentProtocol.getSpecies().isEmpty();
}
@@ -133,7 +118,7 @@
importedTrunkFile = importPupitriDialog.getTrunkFile().getSelectedFile();
importedCarrouselFile = importPupitriDialog.getCarrouselFile().getSelectedFile();
importedSpeciesFile = importPupitriDialog.getSpeciesFile().getSelectedFile();
- result = importedTrunkFile != null
+ result = importedTrunkFile != null
&& importedCarrouselFile != null
&& importedSpeciesFile != null;
}
@@ -158,7 +143,7 @@
operation,
catchBatch,
getDataContext().getReferentSpeciesWithSurveyCode());
-
+
String fishingOperationText = getEditAction().getFishingOperationTitle(operation);
getEditAction().loadCatchBatch(operation, fishingOperationText, true);
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/ImportPupitriPopupUI.jaxx
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/ImportPupitriPopupUI.jaxx 2013-03-27 21:49:05 UTC (rev 693)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/ImportPupitriPopupUI.jaxx 2013-03-27 21:56:27 UTC (rev 694)
@@ -58,7 +58,7 @@
<!--<AttachmentModelAware id='bean' javaBean='null'/>-->
<ImportPupitriPopupUIHandler id='handler'
- initializer='getContextValue(ImportPupitriPopupUIHandler.class)'/>
+ initializer='getContextValue(ImportPupitriPopupUIHandler.class)'/>
<Table id='mainPanel' fill='both'>
@@ -99,5 +99,5 @@
</row>
</Table>
-
+
</JDialog>
\ No newline at end of file
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/ImportPupitriPopupUIHandler.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/ImportPupitriPopupUIHandler.java 2013-03-27 21:49:05 UTC (rev 693)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/ImportPupitriPopupUIHandler.java 2013-03-27 21:56:27 UTC (rev 694)
@@ -25,11 +25,11 @@
*/
import fr.ifremer.tutti.ui.swing.TuttiUIContext;
+import jaxx.runtime.SwingUtil;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import javax.swing.JOptionPane;
-import jaxx.runtime.SwingUtil;
import static org.nuiton.i18n.I18n._;
@@ -49,7 +49,7 @@
protected final TuttiUIContext context;
public ImportPupitriPopupUIHandler(TuttiUIContext context,
- ImportPupitriPopupUI ui) {
+ ImportPupitriPopupUI ui) {
this.context = context;
this.ui = ui;
}
@@ -83,8 +83,8 @@
public void validate() {
if (ui.getTrunkFile().getSelectedFile() != null
- && ui.getCarrouselFile().getSelectedFile() != null
- && ui.getSpeciesFile().getSelectedFile() != null) {
+ && ui.getCarrouselFile().getSelectedFile() != null
+ && ui.getSpeciesFile().getSelectedFile() != null) {
ui.dispose();
} else {
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/SampleCategoryComponent.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/SampleCategoryComponent.java 2013-03-27 21:49:05 UTC (rev 693)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/SampleCategoryComponent.java 2013-03-27 21:56:27 UTC (rev 694)
@@ -123,7 +123,7 @@
}
String label = sampleCategory == null ? "-" :
- categoryDecorator.toString(categoryValue);
+ categoryDecorator.toString(categoryValue);
editorLabel.setText(label);
return editor;
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUIModel.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUIModel.java 2013-03-27 21:49:05 UTC (rev 693)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUIModel.java 2013-03-27 21:56:27 UTC (rev 694)
@@ -46,7 +46,7 @@
* @since 0.1
*/
public class BenthosBatchUIModel extends AbstractTuttiBatchUIModel<BenthosBatchRowModel, BenthosBatchUIModel>
- implements AttachmentModelAware, TabContentModel {
+ implements AttachmentModelAware, TabContentModel {
private static final long serialVersionUID = 1L;
@@ -388,10 +388,10 @@
@Override
public boolean isEmpty() {
return CollectionUtils.isEmpty(getRows())
- && getBenthosTotalSortedWeight() == null
- && getBenthosTotalInertWeight() == null
- && getBenthosTotalLivingNotItemizedWeight() == null
- && CollectionUtils.isEmpty(getAttachment());
+ && getBenthosTotalSortedWeight() == null
+ && getBenthosTotalInertWeight() == null
+ && getBenthosTotalLivingNotItemizedWeight() == null
+ && CollectionUtils.isEmpty(getAttachment());
}
@Override
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/frequency/BenthosFrequencyCellComponent.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/frequency/BenthosFrequencyCellComponent.java 2013-03-27 21:49:05 UTC (rev 693)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/frequency/BenthosFrequencyCellComponent.java 2013-03-27 21:56:27 UTC (rev 694)
@@ -31,9 +31,6 @@
import fr.ifremer.tutti.ui.swing.content.operation.catches.benthos.BenthosBatchRowModel;
import fr.ifremer.tutti.ui.swing.content.operation.catches.benthos.BenthosBatchTableModel;
import fr.ifremer.tutti.ui.swing.content.operation.catches.benthos.BenthosBatchUI;
-import fr.ifremer.tutti.ui.swing.content.operation.catches.species.SpeciesBatchTableModel;
-import fr.ifremer.tutti.ui.swing.content.operation.catches.species.frequency.SpeciesFrequencyRowModel;
-import fr.ifremer.tutti.ui.swing.content.operation.catches.species.frequency.SpeciesFrequencyUIModel;
import fr.ifremer.tutti.ui.swing.util.TuttiComputedOrNotData;
import fr.ifremer.tutti.ui.swing.util.table.AbstractSelectTableAction;
import fr.ifremer.tutti.ui.swing.util.table.ColumnIdentifier;
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/frequency/BenthosFrequencyUI.jaxx
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/frequency/BenthosFrequencyUI.jaxx 2013-03-27 21:49:05 UTC (rev 693)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/frequency/BenthosFrequencyUI.jaxx 2013-03-27 21:56:27 UTC (rev 694)
@@ -197,8 +197,10 @@
<Table constraints='"noLengthCaracteristicPmfm"' fill='horizontal'>
<row>
<cell columns='2'>
- <JPanel id='dataInFrequenciesWarningContainer' layout='{new BorderLayout(10, 10)}'>
- <JLabel id='dataInFrequenciesWarning' constraints='BorderLayout.CENTER'/>
+ <JPanel id='dataInFrequenciesWarningContainer'
+ layout='{new BorderLayout(10, 10)}'>
+ <JLabel id='dataInFrequenciesWarning'
+ constraints='BorderLayout.CENTER'/>
</JPanel>
</cell>
</row>
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/frequency/BenthosFrequencyUIHandler.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/frequency/BenthosFrequencyUIHandler.java 2013-03-27 21:49:05 UTC (rev 693)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/frequency/BenthosFrequencyUIHandler.java 2013-03-27 21:56:27 UTC (rev 694)
@@ -37,7 +37,6 @@
import fr.ifremer.tutti.ui.swing.content.operation.catches.EditCatchesUI;
import fr.ifremer.tutti.ui.swing.content.operation.catches.EditCatchesUIHandler;
import fr.ifremer.tutti.ui.swing.content.operation.catches.benthos.BenthosBatchRowModel;
-import fr.ifremer.tutti.ui.swing.content.operation.catches.species.SpeciesBatchRowModel;
import fr.ifremer.tutti.ui.swing.util.Cancelable;
import fr.ifremer.tutti.ui.swing.util.TuttiBeanMonitor;
import fr.ifremer.tutti.ui.swing.util.TuttiUI;
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/RemoveSpeciesSubBatchAction.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/RemoveSpeciesSubBatchAction.java 2013-03-27 21:49:05 UTC (rev 693)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/RemoveSpeciesSubBatchAction.java 2013-03-27 21:56:27 UTC (rev 694)
@@ -79,7 +79,7 @@
handler.collectChildren(parentBatch, rowToRemove);
table.clearSelection();
-
+
// remove all rows from the model
getModel().getRows().removeAll(rowToRemove);
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-03-27 21:49:05 UTC (rev 693)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUIHandler.java 2013-03-27 21:56:27 UTC (rev 694)
@@ -50,7 +50,6 @@
import fr.ifremer.tutti.ui.swing.content.operation.catches.species.frequency.SpeciesFrequencyRowModel;
import fr.ifremer.tutti.ui.swing.content.operation.catches.species.split.SplitSpeciesBatchRowModel;
import fr.ifremer.tutti.ui.swing.content.operation.catches.species.split.SplitSpeciesBatchUI;
-import fr.ifremer.tutti.ui.swing.util.TabHandler;
import fr.ifremer.tutti.ui.swing.util.TuttiBeanMonitor;
import fr.ifremer.tutti.ui.swing.util.TuttiUI;
import fr.ifremer.tutti.ui.swing.util.TuttiUIUtil;
@@ -640,7 +639,7 @@
recomputeRowValidState(newRow);
saveRow(newRow);
-
+
tableModel.addNewRow(newRow);
AbstractSelectTableAction.doSelectCell(getTable(), tableModel.getRowCount() - 1, 0);
@@ -734,7 +733,7 @@
parentBatch.setChildBatch(newBatches);
//TODO Should only save parentBatch (will persist all his childs)
- //saveRow(parentBatch);
+ //saveRow(parentBatch);
// save new batches
saveRows(newBatches);
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUIModel.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUIModel.java 2013-03-27 21:49:05 UTC (rev 693)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUIModel.java 2013-03-27 21:56:27 UTC (rev 694)
@@ -46,7 +46,7 @@
* @since 0.1
*/
public class SpeciesBatchUIModel extends AbstractTuttiBatchUIModel<SpeciesBatchRowModel, SpeciesBatchUIModel>
- implements AttachmentModelAware, TabContentModel {
+ implements AttachmentModelAware, TabContentModel {
private static final long serialVersionUID = 1L;
@@ -388,10 +388,10 @@
@Override
public boolean isEmpty() {
return CollectionUtils.isEmpty(getRows())
- && getSpeciesTotalSortedWeight() == null
- && getSpeciesTotalInertWeight() == null
- && getSpeciesTotalLivingNotItemizedWeight() == null
- && CollectionUtils.isEmpty(getAttachment());
+ && getSpeciesTotalSortedWeight() == null
+ && getSpeciesTotalInertWeight() == null
+ && getSpeciesTotalLivingNotItemizedWeight() == null
+ && CollectionUtils.isEmpty(getAttachment());
}
@Override
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUI.jaxx
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUI.jaxx 2013-03-27 21:49:05 UTC (rev 693)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUI.jaxx 2013-03-27 21:56:27 UTC (rev 694)
@@ -197,8 +197,10 @@
<Table constraints='"noLengthCaracteristicPmfm"' fill='horizontal'>
<row>
<cell columns='2'>
- <JPanel id='dataInFrequenciesWarningContainer' layout='{new BorderLayout(10, 10)}'>
- <JLabel id='dataInFrequenciesWarning' constraints='BorderLayout.CENTER'/>
+ <JPanel id='dataInFrequenciesWarningContainer'
+ layout='{new BorderLayout(10, 10)}'>
+ <JLabel id='dataInFrequenciesWarning'
+ constraints='BorderLayout.CENTER'/>
</JPanel>
</cell>
</row>
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSpeciesBatchRowModel.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSpeciesBatchRowModel.java 2013-03-27 21:49:05 UTC (rev 693)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSpeciesBatchRowModel.java 2013-03-27 21:56:27 UTC (rev 694)
@@ -28,8 +28,6 @@
import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativeValue;
import fr.ifremer.tutti.ui.swing.content.operation.catches.SampleCategory;
import fr.ifremer.tutti.ui.swing.util.AbstractTuttiBeanUIModel;
-import org.nuiton.util.beans.Binder;
-import org.nuiton.util.beans.BinderFactory;
import java.io.Serializable;
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSpeciesBatchUIHandler.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSpeciesBatchUIHandler.java 2013-03-27 21:49:05 UTC (rev 693)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSpeciesBatchUIHandler.java 2013-03-27 21:56:27 UTC (rev 694)
@@ -303,8 +303,8 @@
SplitSpeciesBatchUIModel model = getModel();
if (model.isValid()) {
parent.getSpeciesTabContent().getHandler().splitBatch(
- model.getSelectedCategory(),
- model.getRows());
+ model.getSelectedCategory(),
+ model.getRows());
}
// close dialog
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/fishing/AbstractCaracteristicTabUIModel.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/fishing/AbstractCaracteristicTabUIModel.java 2013-03-27 21:49:05 UTC (rev 693)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/fishing/AbstractCaracteristicTabUIModel.java 2013-03-27 21:56:27 UTC (rev 694)
@@ -25,7 +25,6 @@
* #L%
*/
-import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import fr.ifremer.tutti.persistence.entities.CaracteristicMap;
import fr.ifremer.tutti.persistence.entities.data.FishingOperation;
@@ -38,8 +37,6 @@
import java.util.List;
import java.util.Set;
-import org.apache.commons.collections.CollectionUtils;
-
/**
* @author kmorin <kmorin(a)codelutin.com>
* @since 1.0
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/ExportPupitriAction.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/ExportPupitriAction.java 2013-03-27 21:49:05 UTC (rev 693)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/ExportPupitriAction.java 2013-03-27 21:56:27 UTC (rev 694)
@@ -27,9 +27,7 @@
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
import fr.ifremer.tutti.TuttiIOUtil;
-import fr.ifremer.tutti.persistence.entities.protocol.SpeciesProtocol;
import fr.ifremer.tutti.persistence.entities.referential.Species;
-import fr.ifremer.tutti.service.protocol.TuttiProtocolImportExportService;
import fr.ifremer.tutti.service.pupitri.TuttiPupitriImportExportService;
import fr.ifremer.tutti.ui.swing.util.TuttiUIUtil;
import fr.ifremer.tutti.ui.swing.util.action.AbstractTuttiAction;
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/AbstractTuttiUIHandler.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/AbstractTuttiUIHandler.java 2013-03-27 21:49:05 UTC (rev 693)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/AbstractTuttiUIHandler.java 2013-03-27 21:56:27 UTC (rev 694)
@@ -367,7 +367,7 @@
Component result;
TuttiActionUI actionUI = getContext().getActionUI();
// if (actionUI.isVisible()) {
- result = actionUI;
+ result = actionUI;
// } else {
// result = getContext().getMainUI();
// }
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/CustomTab.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/CustomTab.java 2013-03-27 21:49:05 UTC (rev 693)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/CustomTab.java 2013-03-27 21:56:27 UTC (rev 694)
@@ -26,20 +26,18 @@
*/
import jaxx.runtime.SwingUtil;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.util.beans.BeanUtil;
import javax.swing.JLabel;
import javax.swing.JPanel;
+import javax.swing.UIManager;
import java.awt.Color;
import java.awt.Font;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.lang.reflect.InvocationTargetException;
-import javax.swing.UIManager;
-import jaxx.runtime.JAXXUtil;
-import org.apache.commons.beanutils.MethodUtils;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.nuiton.util.beans.BeanUtil;
import static org.nuiton.i18n.I18n._;
@@ -74,11 +72,11 @@
public void propertyChange(PropertyChangeEvent evt) {
updateTitle();
}
- },this.model);
-
- } catch (NoSuchMethodException
- | IllegalAccessException
- | InvocationTargetException ex) {
+ }, this.model);
+
+ } catch (NoSuchMethodException
+ | IllegalAccessException
+ | InvocationTargetException ex) {
log.error("Error while adding the listener to the model modifications", ex);
}
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/TabContentModel.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/TabContentModel.java 2013-03-27 21:49:05 UTC (rev 693)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/TabContentModel.java 2013-03-27 21:56:27 UTC (rev 694)
@@ -2,7 +2,7 @@
/**
* Interface defining the models of the tab content UIs.
- *
+ *
* @author kmorin <kmorin(a)codelutin.com>
* @since 1.2
*/
@@ -11,7 +11,7 @@
boolean isEmpty();
boolean isValid();
-
+
boolean isModify();
String getTitle();
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/comment/CommentModelAware.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/comment/CommentModelAware.java 2013-03-27 21:49:05 UTC (rev 693)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/comment/CommentModelAware.java 2013-03-27 21:56:27 UTC (rev 694)
@@ -32,7 +32,7 @@
*/
public interface CommentModelAware {
- String PROPERTY_COMMENT= "comment";
+ String PROPERTY_COMMENT = "comment";
String getComment();
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/TuttiComputedOrNotDataEditorHandler.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/TuttiComputedOrNotDataEditorHandler.java 2013-03-27 21:49:05 UTC (rev 693)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/TuttiComputedOrNotDataEditorHandler.java 2013-03-27 21:56:27 UTC (rev 694)
@@ -40,7 +40,6 @@
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.text.DecimalFormat;
-import org.apache.commons.lang3.StringUtils;
/**
* @author kmorin <kmorin(a)codelutin.com>
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/TuttiComputedOrNotDataTableCell.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/TuttiComputedOrNotDataTableCell.java 2013-03-27 21:49:05 UTC (rev 693)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/TuttiComputedOrNotDataTableCell.java 2013-03-27 21:56:27 UTC (rev 694)
@@ -45,7 +45,6 @@
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.text.DecimalFormat;
-import org.apache.commons.lang3.StringUtils;
/**
* Editor for TuttiComputedOrNotData
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/table/CaracteristicRow.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/table/CaracteristicRow.java 2013-03-27 21:49:05 UTC (rev 693)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/table/CaracteristicRow.java 2013-03-27 21:56:27 UTC (rev 694)
@@ -24,8 +24,8 @@
* #L%
*/
+import fr.ifremer.tutti.LabelAware;
import fr.ifremer.tutti.persistence.entities.referential.Caracteristic;
-import fr.ifremer.tutti.LabelAware;
/**
* @author kmorin <kmorin(a)codelutin.com>
Modified: trunk/tutti-ui-swing/src/test/java/fr/ifremer/tutti/ui/swing/BeanValidatorDetectorTest.java
===================================================================
--- trunk/tutti-ui-swing/src/test/java/fr/ifremer/tutti/ui/swing/BeanValidatorDetectorTest.java 2013-03-27 21:49:05 UTC (rev 693)
+++ trunk/tutti-ui-swing/src/test/java/fr/ifremer/tutti/ui/swing/BeanValidatorDetectorTest.java 2013-03-27 21:56:27 UTC (rev 694)
@@ -26,11 +26,9 @@
import fr.ifremer.tutti.ui.swing.content.cruise.EditCruiseUIModel;
import fr.ifremer.tutti.ui.swing.content.operation.EditFishingOperationUIModel;
-import fr.ifremer.tutti.ui.swing.content.operation.catches.EditCatchesUIModel;
import fr.ifremer.tutti.ui.swing.content.operation.catches.benthos.create.CreateBenthosBatchUIModel;
import fr.ifremer.tutti.ui.swing.content.operation.catches.benthos.frequency.BenthosFrequencyUIModel;
import fr.ifremer.tutti.ui.swing.content.operation.catches.benthos.split.SplitBenthosBatchUIModel;
-import fr.ifremer.tutti.ui.swing.content.operation.catches.species.SpeciesBatchUIModel;
import fr.ifremer.tutti.ui.swing.content.operation.catches.species.create.CreateSpeciesBatchUIModel;
import fr.ifremer.tutti.ui.swing.content.operation.catches.species.frequency.SpeciesFrequencyUIModel;
import fr.ifremer.tutti.ui.swing.content.operation.catches.species.split.SplitSpeciesBatchUIModel;
1
0
r693 - in trunk/tutti-persistence/src: main/java/fr/ifremer/tutti/persistence main/java/fr/ifremer/tutti/persistence/entities main/java/fr/ifremer/tutti/persistence/service main/java/fr/ifremer/tutti/persistence/service/batch test/java/fr/ifremer/tutti/persistence/service test/resources
by tchemit@users.forge.codelutin.com 27 Mar '13
by tchemit@users.forge.codelutin.com 27 Mar '13
27 Mar '13
Author: tchemit
Date: 2013-03-27 22:49:05 +0100 (Wed, 27 Mar 2013)
New Revision: 693
Url: http://forge.codelutin.com/projects/tutti/repository/revisions/693
Log:
- fixes #2161: [ESPECES] affichage d'un nombre d'individus sur un lot p?\195?\168re avec des fils
- ajout de m?\195?\169thodes pour manipuler les id en tant que Integer
- resplit des service comme au d?\195?\169but : CatchBatchPS, SpeciesBatchPS, BenthosBatchPS (c'est plus simple)
- nettoyage du code de persistence
Added:
trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceService.java
trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceServiceImpl.java
trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/CatchBatchPersistenceService.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/SpeciesBatchPersistenceService.java
trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceImpl.java
trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/batch/BatchPersistenceHelper.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/SpeciesBatchPersistenceServiceReadTest.java
trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceWriteTest.java
Removed:
trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/BatchPersistenceService.java
trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/BatchPersistenceServiceImpl.java
trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/BatchPersistenceServiceReadTest.java
trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/BatchPersistenceServiceWriteTest.java
Modified:
trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistenceImpl.java
trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/entities/AbstractTuttiEntity.java
trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/TuttiPersistenceServiceLocator.java
trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/batch/ScientificCruiseCatchBatchValidator.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/FishingOperationPersistenceServiceWriteTest.java
trunk/tutti-persistence/src/test/resources/log4j.properties
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-03-27 21:44:37 UTC (rev 692)
+++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistenceImpl.java 2013-03-27 21:49:05 UTC (rev 693)
@@ -49,7 +49,8 @@
import fr.ifremer.tutti.persistence.entities.referential.Vessel;
import fr.ifremer.tutti.persistence.service.AccidentalBatchPersistenceService;
import fr.ifremer.tutti.persistence.service.AttachmentPersistenceService;
-import fr.ifremer.tutti.persistence.service.BatchPersistenceService;
+import fr.ifremer.tutti.persistence.service.CatchBatchPersistenceService;
+import fr.ifremer.tutti.persistence.service.BenthosBatchPersistenceService;
import fr.ifremer.tutti.persistence.service.CruisePersistenceService;
import fr.ifremer.tutti.persistence.service.FishingOperationPersistenceService;
import fr.ifremer.tutti.persistence.service.MacroWasteBatchPersistenceService;
@@ -57,6 +58,7 @@
import fr.ifremer.tutti.persistence.service.ProgramPersistenceService;
import fr.ifremer.tutti.persistence.service.ProtocolPersistenceService;
import fr.ifremer.tutti.persistence.service.ReferentialPersistenceService;
+import fr.ifremer.tutti.persistence.service.SpeciesBatchPersistenceService;
import fr.ifremer.tutti.persistence.service.TuttiPersistenceServiceLocator;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
@@ -91,9 +93,15 @@
protected FishingOperationPersistenceService fishingOperationService;
@Autowired
- protected BatchPersistenceService batchService;
+ protected CatchBatchPersistenceService catchBatchService;
@Autowired
+ protected SpeciesBatchPersistenceService speciesBatchService;
+
+ @Autowired
+ protected BenthosBatchPersistenceService benthosBatchService;
+
+ @Autowired
protected PlanktonBatchPersistenceService planktonBatchService;
@Autowired
@@ -130,7 +138,9 @@
programService.init();
cruiseService.init();
fishingOperationService.init();
- batchService.init();
+ catchBatchService.init();
+ speciesBatchService.init();
+ benthosBatchService.init();
planktonBatchService.init();
macroWasteBatchService.init();
accidentalBatchService.init();
@@ -148,7 +158,9 @@
programService.close();
cruiseService.close();
fishingOperationService.close();
- batchService.close();
+ catchBatchService.close();
+ speciesBatchService.close();
+ benthosBatchService.close();
planktonBatchService.close();
macroWasteBatchService.close();
accidentalBatchService.close();
@@ -506,7 +518,7 @@
@Override
public CatchBatch getCatchBatchFromFishingOperation(String id) throws InvalidBatchModelException {
try {
- return batchService.getCatchBatchFromFishingOperation(id);
+ return catchBatchService.getCatchBatchFromFishingOperation(id);
} catch (CatchBatchValidationException e) {
throw new InvalidBatchModelException(
"L'arbre d'échantillonage n'est pas compatible avec celui de Tutti.", e);
@@ -515,12 +527,12 @@
@Override
public CatchBatch createCatchBatch(CatchBatch bean) {
- return batchService.createCatchBatch(bean);
+ return catchBatchService.createCatchBatch(bean);
}
@Override
public CatchBatch saveCatchBatch(CatchBatch bean) {
- return batchService.saveCatchBatch(bean);
+ return catchBatchService.saveCatchBatch(bean);
}
//------------------------------------------------------------------------//
@@ -529,42 +541,42 @@
@Override
public BatchContainer<SpeciesBatch> getRootSpeciesBatch(String fishingOperationId) {
- return batchService.getRootSpeciesBatch(fishingOperationId);
+ return speciesBatchService.getRootSpeciesBatch(fishingOperationId);
}
@Override
public SpeciesBatch createSpeciesBatch(SpeciesBatch bean, String parentBatchId) {
- return batchService.createSpeciesBatch(bean, parentBatchId);
+ return speciesBatchService.createSpeciesBatch(bean, parentBatchId);
}
@Override
public SpeciesBatch saveSpeciesBatch(SpeciesBatch bean) {
- return batchService.saveSpeciesBatch(bean);
+ return speciesBatchService.saveSpeciesBatch(bean);
}
@Override
public void deleteSpeciesBatch(String id) {
- batchService.deleteSpeciesBatch(id);
+ speciesBatchService.deleteSpeciesBatch(id);
}
@Override
public void deleteSpeciesSubBatch(String id) {
- batchService.deleteSpeciesSubBatch(id);
+ speciesBatchService.deleteSpeciesSubBatch(id);
}
@Override
public void changeSpeciesBatchSpecies(String batchId, Species species) {
- batchService.changeSpeciesBatchSpecies(batchId, species);
+ speciesBatchService.changeSpeciesBatchSpecies(batchId, species);
}
@Override
public List<SpeciesBatchFrequency> getAllSpeciesBatchFrequency(String speciesBatchId) {
- return batchService.getAllSpeciesBatchFrequency(speciesBatchId);
+ return speciesBatchService.getAllSpeciesBatchFrequency(speciesBatchId);
}
@Override
public List<SpeciesBatchFrequency> saveSpeciesBatchFrequency(String speciesBatchId, List<SpeciesBatchFrequency> frequencies) {
- return batchService.saveSpeciesBatchFrequency(speciesBatchId, frequencies);
+ return speciesBatchService.saveSpeciesBatchFrequency(speciesBatchId, frequencies);
}
//------------------------------------------------------------------------//
@@ -573,43 +585,43 @@
@Override
public BatchContainer<SpeciesBatch> getRootBenthosBatch(String fishingOperationId) {
- return batchService.getRootBenthosBatch(fishingOperationId);
+ return benthosBatchService.getRootBenthosBatch(fishingOperationId);
}
@Override
public SpeciesBatch createBenthosBatch(SpeciesBatch bean, String parentBatchId) {
- return batchService.createBenthosBatch(bean, parentBatchId);
+ return benthosBatchService.createBenthosBatch(bean, parentBatchId);
}
@Override
public SpeciesBatch saveBenthosBatch(SpeciesBatch bean) {
- return batchService.saveBenthosBatch(bean);
+ return benthosBatchService.saveBenthosBatch(bean);
}
@Override
public void deleteBenthosBatch(String id) {
- batchService.deleteBenthosBatch(id);
+ benthosBatchService.deleteBenthosBatch(id);
}
@Override
public void deleteBenthosSubBatch(String id) {
- batchService.deleteBenthosSubBatch(id);
+ benthosBatchService.deleteBenthosSubBatch(id);
}
@Override
public void changeBenthosBatchSpecies(String batchId, Species species) {
- batchService.changeBenthosBatchSpecies(batchId, species);
+ benthosBatchService.changeBenthosBatchSpecies(batchId, species);
}
@Override
public List<SpeciesBatchFrequency> getAllBenthosBatchFrequency(String benthosBatchId) {
- return batchService.getAllBenthosBatchFrequency(benthosBatchId);
+ return benthosBatchService.getAllBenthosBatchFrequency(benthosBatchId);
}
@Override
public List<SpeciesBatchFrequency> saveBenthosBatchFrequency(String benthosBatchId,
List<SpeciesBatchFrequency> frequencies) {
- return batchService.saveBenthosBatchFrequency(benthosBatchId, frequencies);
+ return benthosBatchService.saveBenthosBatchFrequency(benthosBatchId, frequencies);
}
//------------------------------------------------------------------------//
Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/entities/AbstractTuttiEntity.java
===================================================================
--- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/entities/AbstractTuttiEntity.java 2013-03-27 21:44:37 UTC (rev 692)
+++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/entities/AbstractTuttiEntity.java 2013-03-27 21:49:05 UTC (rev 693)
@@ -45,6 +45,8 @@
protected String id;
+ protected Integer intId;
+
@Override
public String getId() {
return id;
@@ -53,8 +55,21 @@
@Override
public void setId(String id) {
this.id = id;
+ intId = null;
}
+ public void setId(Integer id) {
+ intId = id;
+ this.id = id == null ? null : String.valueOf(id);
+ }
+
+ public Integer getIdAsInt() {
+ if (intId == null && id != null) {
+ intId = Integer.valueOf(id);
+ }
+ return intId;
+ }
+
protected <B> B getChild(Collection<B> child, int index) {
return CollectionUtil.getOrNull(child, index);
}
Deleted: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/BatchPersistenceService.java
===================================================================
--- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/BatchPersistenceService.java 2013-03-27 21:44:37 UTC (rev 692)
+++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/BatchPersistenceService.java 2013-03-27 21:49:05 UTC (rev 693)
@@ -1,208 +0,0 @@
-package fr.ifremer.tutti.persistence.service;
-
-/*
- * #%L
- * Tutti :: Persistence
- * $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.adagio.core.dao.data.batch.validator.CatchBatchValidationException;
-import fr.ifremer.tutti.persistence.TuttiPersistenceServiceImplementor;
-import fr.ifremer.tutti.persistence.entities.data.BatchContainer;
-import fr.ifremer.tutti.persistence.entities.data.CatchBatch;
-import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch;
-import fr.ifremer.tutti.persistence.entities.data.SpeciesBatchFrequency;
-import fr.ifremer.tutti.persistence.entities.referential.Species;
-import org.springframework.transaction.annotation.Transactional;
-
-import java.util.List;
-
-@Transactional(readOnly = true)
-public interface BatchPersistenceService extends TuttiPersistenceServiceImplementor {
-
- //------------------------------------------------------------------------//
- //-- CatchBatch methods --//
- //------------------------------------------------------------------------//
-
- /**
- * Get the catchBatch from the fishing Operation id.
- *
- * @param fishingOperationId id of the fihsing operation
- * @return found catchBatch
- * @throws CatchBatchValidationException
- */
- CatchBatch getCatchBatchFromFishingOperation(String fishingOperationId) throws CatchBatchValidationException;
-
- /**
- * Create the given CatchBatch and return it.
- *
- * @param bean catchBatch to create
- * @return created catchBatch
- */
- @Transactional(readOnly = false)
- CatchBatch createCatchBatch(CatchBatch bean);
-
- /**
- * Save the given catchBatch and return it.
- *
- * @param bean batch to save
- * @return the saved catchBatch
- */
- @Transactional(readOnly = false)
- CatchBatch saveCatchBatch(CatchBatch bean);
-
- //------------------------------------------------------------------------//
- //-- SpeciesBatch methods --//
- //------------------------------------------------------------------------//
-
- /**
- * Get the batch parent of all root {@link SpeciesBatch} for the given
- * fishing operation.
- * <p/>
- * <strong>Note:</strong> All childs of the batch should be loaded here.
- *
- * @param fishingOperationId if of the fishing operation to seek
- * @return the list of root {@link SpeciesBatch}
- * @since 1.0.2
- */
- BatchContainer<SpeciesBatch> getRootSpeciesBatch(String fishingOperationId);
-
- @Transactional(readOnly = false)
- SpeciesBatch createSpeciesBatch(SpeciesBatch bean, String parentBatchId);
-
- @Transactional(readOnly = false)
- SpeciesBatch saveSpeciesBatch(SpeciesBatch bean);
-
- @Transactional(readOnly = false)
- void deleteSpeciesBatch(String id);
-
- @Transactional(readOnly = false)
- void deleteSpeciesSubBatch(String id);
-
- /**
- * Change the species in the given {@code batchId} and in all his
- * sub batches.
- *
- * @param batchId id of the root species batch to treat
- * @param species species to affect to all batches
- */
- @Transactional(readOnly = false)
- void changeSpeciesBatchSpecies(String batchId, Species species);
-
- //------------------------------------------------------------------------//
- //-- SpeciesBatchFrequency methods (for species) --//
- //------------------------------------------------------------------------//
-
- /**
- * Get all frequencies for the given species batch.
- *
- * @param speciesBatchId the id of the species batch to seek.
- * @return the list of frequencies for the given specues batch id
- * @since 1.0
- */
- List<SpeciesBatchFrequency> getAllSpeciesBatchFrequency(String speciesBatchId);
-
- /**
- * Save all given {@link SpeciesBatchFrequency} into the given
- * {@code speciesBatchId}. If some are not existing then creates them.
- * <p/>
- * <strong>Note:</strong> This will as a side effect remove all previous frequency for this species batch.
- *
- * @param speciesBatchId id of the {@link SpeciesBatch} to use
- * @param frequencies list of frequencies to create or update
- * @return the persisted list of frequencies
- * @since 1.0
- */
- @Transactional(readOnly = false)
- List<SpeciesBatchFrequency> saveSpeciesBatchFrequency(String speciesBatchId,
- List<SpeciesBatchFrequency> frequencies);
-
-
- //------------------------------------------------------------------------//
- //-- Benthos Batch methods --//
- //------------------------------------------------------------------------//
-
- /**
- * Get all root {@link SpeciesBatch} for the given fishing operation.
- * <p/>
- * <strong>Note:</strong> All childs of the batch should be loaded here.
- *
- *
- * @param fishingOperationId if of the fishing operation to seek
- * @return the list of root {@link SpeciesBatch}
- * @since 1.0
- */
- BatchContainer<SpeciesBatch> getRootBenthosBatch(String fishingOperationId);
-
- @Transactional(readOnly = false)
- SpeciesBatch createBenthosBatch(SpeciesBatch bean, String parentBatchId);
-
- @Transactional(readOnly = false)
- SpeciesBatch saveBenthosBatch(SpeciesBatch bean);
-
- @Transactional(readOnly = false)
- void deleteBenthosBatch(String id);
-
- @Transactional(readOnly = false)
- void deleteBenthosSubBatch(String id);
-
- /**
- * Change the species in the given {@code batchId} and in all his
- * sub batches.
- *
- * @param batchId id of the root Benthos batch to treat
- * @param species species to affect to all batches
- */
- @Transactional(readOnly = false)
- void changeBenthosBatchSpecies(String batchId, Species species);
-
- //------------------------------------------------------------------------//
- //-- SpeciesBatchFrequency methods (for benthos) --//
- //------------------------------------------------------------------------//
-
- /**
- * Get all frequencies for the given species batch.
- *
- * @param benthosBatchId the id of the species batch to seek.
- * @return the list of frequencies for the given benthos batch id
- * @since 1.0
- */
- List<SpeciesBatchFrequency> getAllBenthosBatchFrequency(String benthosBatchId);
-
- /**
- * Save all given {@link SpeciesBatchFrequency} into the given
- * {@code benthosBatchId}. If some are not existing then creates them.
- * <p/>
- * <strong>Note:</strong> This will as a side effect remove all previous
- * frequency for this benthos batch.
- *
- * @param benthosBatchId id of the {@link SpeciesBatch} to use
- * @param frequencies list of frequencies to create or update
- * @return the persisted list of frequencies
- * @since 1.0
- */
- @Transactional(readOnly = false)
- List<SpeciesBatchFrequency> saveBenthosBatchFrequency(String benthosBatchId,
- List<SpeciesBatchFrequency> frequencies);
-
-
-}
\ No newline at end of file
Deleted: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/BatchPersistenceServiceImpl.java
===================================================================
--- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/BatchPersistenceServiceImpl.java 2013-03-27 21:44:37 UTC (rev 692)
+++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/BatchPersistenceServiceImpl.java 2013-03-27 21:49:05 UTC (rev 693)
@@ -1,1630 +0,0 @@
-package fr.ifremer.tutti.persistence.service;
-
-/*
- * #%L
- * Tutti :: Persistence
- * $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.dao.data.batch.Batch;
-import fr.ifremer.adagio.core.dao.data.batch.CatchBatchExtendDao;
-import fr.ifremer.adagio.core.dao.data.batch.SortingBatch;
-import fr.ifremer.adagio.core.dao.data.batch.validator.CatchBatchValidationException;
-import fr.ifremer.adagio.core.dao.data.batch.validator.CatchBatchValidator;
-import fr.ifremer.adagio.core.dao.data.measure.Measurement;
-import fr.ifremer.adagio.core.dao.data.measure.QuantificationMeasurement;
-import fr.ifremer.adagio.core.dao.data.measure.SortingMeasurement;
-import fr.ifremer.adagio.core.dao.data.operation.FishingOperationImpl;
-import fr.ifremer.adagio.core.dao.referential.QualityFlagImpl;
-import fr.ifremer.adagio.core.dao.referential.pmfm.QualitativeValue;
-import fr.ifremer.adagio.core.dao.referential.pmfm.QualitativeValueImpl;
-import fr.ifremer.adagio.core.dao.referential.taxon.ReferenceTaxon;
-import fr.ifremer.adagio.core.dao.referential.taxon.ReferenceTaxonImpl;
-import fr.ifremer.adagio.core.dao.technical.synchronization.SynchronizationStatus;
-import fr.ifremer.tutti.persistence.entities.data.BatchContainer;
-import fr.ifremer.tutti.persistence.entities.data.CatchBatch;
-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.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.dao.DataRetrievalFailureException;
-import org.springframework.stereotype.Service;
-
-import javax.annotation.Resource;
-import java.io.Serializable;
-import java.text.MessageFormat;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-@Service("batchPersistenceService")
-public class BatchPersistenceServiceImpl
- extends AbstractPersistenceService implements BatchPersistenceService {
-
- /** Logger. */
- private static final Log log =
- LogFactory.getLog(BatchPersistenceServiceImpl.class);
-
- @Resource(name = "referentialPersistenceService")
- protected ReferentialPersistenceService referentialService;
-
- @Resource(name = "catchBatchDao")
- protected CatchBatchExtendDao catchBatchDao;
-
- @Resource(name = "scientificCruiseCatchBatchValidator")
- protected CatchBatchValidator catchBatchValidator;
-
- @Override
- public void init() {
- super.init();
- catchBatchDao.registerCatchBatchValidator(catchBatchValidator);
- }
-
- @Override
- public void close() {
- catchBatchDao.unregisterCatchBatchValidator(catchBatchValidator);
- super.close();
- }
-
- //------------------------------------------------------------------------//
- //-- CatchBatch methods --//
- //------------------------------------------------------------------------//
-
- @Override
- public CatchBatch getCatchBatchFromFishingOperation(String fishingOperationId) throws CatchBatchValidationException {
- Preconditions.checkNotNull(fishingOperationId);
-
- Integer catchBatchId = catchBatchDao.getIdByFishingOperationId(Integer.valueOf(fishingOperationId));
-
- fr.ifremer.adagio.core.dao.data.batch.CatchBatch source;
- // wenever want to repair anything from Tutti
- source = catchBatchDao.loadFullTree(catchBatchId, true, false);
-
- CatchBatch result = new CatchBatch();
- result.setId(source.getId().toString());
- result.setCatchTotalWeight(source.getWeight());
-
- // Vrac
- SortingBatch vracBatch = catchBatchDao.getSortingBatch(source.getChildBatchs(),
- "pmfmId", enumeration.PMFM_ID_SORTED_UNSORTED, enumeration.QUALITATIVE_VRAC_ID);
- result.setCatchTotalSortedCarousselWeight(vracBatch.getWeight());
- result.setCatchTotalSortedTremisWeight(vracBatch.getWeightBeforeSampling());
- {
- // Species
- SortingBatch speciesBatch = catchBatchDao.getSortingBatch(vracBatch.getChildBatchs(),
- "pmfmId", enumeration.PMFM_ID_SORTING_TYPE, enumeration.QUALITATIVE_ID_SORTING_TYPE_SPECIES);
-
- result.setSpeciesTotalSampleSortedWeight(speciesBatch.getWeight());
- result.setSpeciesTotalSortedWeight(speciesBatch.getWeightBeforeSampling());
-
- {
- // Inert
- SortingBatch inertBatch = catchBatchDao.getSortingBatch(speciesBatch.getChildBatchs(),
- "referenceTaxonId", enumeration.REFERENCE_TAXON_ID_INERT);
- if (inertBatch != null) {
- result.setSpeciesTotalInertWeight(inertBatch.getWeight());
- }
-
- // Alive no itemized
- SortingBatch livingNotItemizedBatch = catchBatchDao.getSortingBatch(speciesBatch.getChildBatchs(),
- "referenceTaxonId", enumeration.REFERENCE_TAXON_ID_LIFE);
- if (livingNotItemizedBatch != null) {
- result.setSpeciesTotalLivingNotItemizedWeight(livingNotItemizedBatch.getWeight());
- }
- }
-
- // Benthos
- SortingBatch benthosBatch = catchBatchDao.getSortingBatch(vracBatch.getChildBatchs(),
- "pmfmId", enumeration.PMFM_ID_SORTING_TYPE, enumeration.QUALITATIVE_ID_SORTING_TYPE_BENTHOS);
- if (benthosBatch != null) {
- result.setBenthosTotalSampleSortedWeight(benthosBatch.getWeight());
- result.setBenthosTotalSortedWeight(benthosBatch.getWeightBeforeSampling());
- }
-
- // TODO : Plancton...
- }
-
- // Hors Vrac
- SortingBatch horsVracBatch = catchBatchDao.getSortingBatch(source.getChildBatchs(),
- "pmfmId", enumeration.PMFM_ID_SORTED_UNSORTED, enumeration.QUALITATIVE_HORS_VRAC_ID);
- if (horsVracBatch != null) {
- result.setCatchTotalUnsortedWeight(horsVracBatch.getWeight());
- {
- // Species
- SortingBatch speciesBatch = catchBatchDao.getSortingBatch(horsVracBatch.getChildBatchs(),
- "pmfmId", enumeration.PMFM_ID_SORTING_TYPE, enumeration.QUALITATIVE_ID_SORTING_TYPE_SPECIES);
- if (speciesBatch != null) {
- result.setSpeciesTotalUnsortedWeight(speciesBatch.getWeight());
- }
-
- SortingBatch benthosBatch = catchBatchDao.getSortingBatch(horsVracBatch.getChildBatchs(),
- "pmfmId", enumeration.PMFM_ID_SORTING_TYPE, enumeration.QUALITATIVE_ID_SORTING_TYPE_BENTHOS);
- if (benthosBatch != null) {
- result.setBenthosTotalUnsortedWeight(benthosBatch.getWeight());
- }
-
- // TODO : Plancton...
- }
- }
-
- // Non trié
- SortingBatch unsortedBatch = catchBatchDao.getSortingBatch(source.getChildBatchs(),
- "pmfmId", enumeration.PMFM_ID_SORTED_UNSORTED, enumeration.QUALITATIVE_UNSORTED_ID);
- if (unsortedBatch != null) {
- result.setCatchTotalRejectedWeight(unsortedBatch.getWeight());
- }
-
- return result;
- }
-
- @Override
- public CatchBatch createCatchBatch(CatchBatch bean) {
- Preconditions.checkNotNull(bean);
- Preconditions.checkArgument(bean.getId() == null);
- Preconditions.checkNotNull(bean.getFishingOperation());
- Preconditions.checkNotNull(bean.getFishingOperation().getId());
-
- fr.ifremer.adagio.core.dao.data.batch.CatchBatch catchBatch = fr.ifremer.adagio.core.dao.data.batch.CatchBatch.Factory.newInstance();
- beanToEntity(bean, catchBatch, true);
- catchBatch = catchBatchDao.create(catchBatch);
- bean.setId(String.valueOf(catchBatch.getId()));
-
- // Link to fishing operation
- getCurrentSession().flush();
- Integer fishingOperationId = Integer.valueOf(bean.getFishingOperation().getId());
- int rowUpdated = queryUpdate("updateFishingOperationCatchBatch",
- "fishingOperationId", IntegerType.INSTANCE, fishingOperationId,
- "catchBatchId", IntegerType.INSTANCE, catchBatch.getId());
- if (rowUpdated == 0) {
- throw new DataIntegrityViolationException("Could not attach catch batch to the given operation : operation was not found.");
- }
-
- return bean;
- }
-
- @Override
- public CatchBatch saveCatchBatch(CatchBatch bean) {
-
- Preconditions.checkNotNull(bean);
- Preconditions.checkNotNull(bean.getId());
-
- getCurrentSession().enableFetchProfile("batch-with-childs");
- getCurrentSession().setFlushMode(FlushMode.COMMIT);
- fr.ifremer.adagio.core.dao.data.batch.CatchBatch catchBatch = catchBatchDao.load(Integer.valueOf(bean.getId()));
- if (catchBatch == null) {
- throw new DataRetrievalFailureException("Could not retrieve catch batch with id=" + bean.getId());
- }
-
- beanToEntity(bean, catchBatch, true);
- catchBatchDao.update(catchBatch);
- getCurrentSession().flush();
-
- return bean;
- }
-
- //------------------------------------------------------------------------//
- //-- SpeciesBatch methods --//
- //------------------------------------------------------------------------//
-
- @Override
- public BatchContainer<SpeciesBatch> getRootSpeciesBatch(String fishingOperationId) {
-
- // Load batch tree
- Integer catchBatchId = catchBatchDao.getIdByFishingOperationId(Integer.valueOf(fishingOperationId));
- fr.ifremer.adagio.core.dao.data.batch.CatchBatch catchBatch = catchBatchDao.loadFullTree(catchBatchId);
-
- // Vrac / Species
- SortingBatch vracSpeciesBatch = catchBatchDao.getSortingBatch(catchBatch.getChildBatchs(),
- "pmfmId", enumeration.PMFM_ID_SORTED_UNSORTED, enumeration.QUALITATIVE_VRAC_ID,
- "pmfmId", enumeration.PMFM_ID_SORTING_TYPE, enumeration.QUALITATIVE_ID_SORTING_TYPE_SPECIES);
-
- // container of speciesBatch is arbitraty put on vrac type (there is
- // no common ancestor for all species batch).
- BatchContainer<SpeciesBatch> result = new BatchContainer<SpeciesBatch>();
- result.setId(String.valueOf(vracSpeciesBatch.getId()));
-
- for (Batch batch1 : vracSpeciesBatch.getChildBatchs()) {
- SortingBatch source = (SortingBatch) batch1;
-
- // evict some special batches : Life (or Biota) and Inert
- if (source.getReferenceTaxon() != null
- && !enumeration.REFERENCE_TAXON_ID_LIFE.equals(source.getReferenceTaxon().getId())
- && !enumeration.REFERENCE_TAXON_ID_INERT.equals(source.getReferenceTaxon().getId())) {
- SpeciesBatch target = new SpeciesBatch();
-
- entityToBean(source, target);
- result.addChildren(target);
- }
- }
-
- // Hors-Vrac / Species
- SortingBatch horsVracSpeciesBatch = catchBatchDao.getSortingBatch(catchBatch.getChildBatchs(),
- "pmfmId", enumeration.PMFM_ID_SORTED_UNSORTED, enumeration.QUALITATIVE_HORS_VRAC_ID,
- "pmfmId", enumeration.PMFM_ID_SORTING_TYPE, enumeration.QUALITATIVE_ID_SORTING_TYPE_SPECIES);
- if (horsVracSpeciesBatch != null) {
- for (Batch batch : horsVracSpeciesBatch.getChildBatchs()) {
- SortingBatch source = (SortingBatch) batch;
-
- SpeciesBatch target = new SpeciesBatch();
-
- entityToBean(source, target);
- result.addChildren(target);
- }
- }
-
- return result;
- }
-
- @Override
- public SpeciesBatch createSpeciesBatch(SpeciesBatch bean,
- String parentBatchId) {
- Preconditions.checkNotNull(bean);
- Preconditions.checkArgument(bean.getId() == null);
- Preconditions.checkNotNull(bean.getSpecies());
- Preconditions.checkNotNull(bean.getSpecies().getId());
- Preconditions.checkNotNull(bean.getFishingOperation());
- Preconditions.checkNotNull(bean.getFishingOperation().getId());
-
- getCurrentSession().setFlushMode(FlushMode.COMMIT);
-
- // Load full batch tree
- Integer catchBatchId = catchBatchDao.getIdByFishingOperationId(Integer.valueOf(bean.getFishingOperation().getId()));
- fr.ifremer.adagio.core.dao.data.batch.CatchBatch catchBatch = catchBatchDao.loadFullTree(catchBatchId);
-
- SortingBatch batch = SortingBatch.Factory.newInstance();
- speciesBatchToEntity(bean, batch, parentBatchId, catchBatch);
- batch = catchBatchDao.createSortingBatch(batch, catchBatch);
-
- bean.setId(String.valueOf(batch.getId()));
-
- getCurrentSession().flush();
-
- return bean;
- }
-
- @Override
- public SpeciesBatch saveSpeciesBatch(SpeciesBatch bean) {
- Preconditions.checkNotNull(bean);
- Preconditions.checkNotNull(bean.getId());
-
- // Load full batch tree
- Integer catchBatchId = catchBatchDao.getIdBySortingBatchId(Integer.valueOf(bean.getId()));
- fr.ifremer.adagio.core.dao.data.batch.CatchBatch catchBatch = catchBatchDao.loadFullTree(catchBatchId);
-
- getCurrentSession().setFlushMode(FlushMode.COMMIT);
-
- SortingBatch batch = catchBatchDao.getSortingBatchById(catchBatch, Integer.valueOf(bean.getId()));
- String parentBatchId = null;
- if (bean.getParentBatch() != null) {
- parentBatchId = bean.getParentBatch().getId();
- }
- speciesBatchToEntity(bean, batch, parentBatchId, catchBatch);
- catchBatchDao.updateSortingBatch(batch, catchBatch);
- getCurrentSession().flush();
-
- return bean;
- }
-
- @Override
- public void deleteSpeciesBatch(String id) {
- Preconditions.checkNotNull(id);
-
- getCurrentSession().setFlushMode(FlushMode.COMMIT);
-
- catchBatchDao.removeWithChildren(Integer.valueOf(id));
-
- getCurrentSession().flush();
- }
-
- @Override
- public void deleteSpeciesSubBatch(String id) {
- deleteSpeciesBatch(id);
- }
-
- @Override
- public void changeSpeciesBatchSpecies(String batchId, Species species) {
- Preconditions.checkNotNull(batchId);
- Preconditions.checkNotNull(species);
- Preconditions.checkNotNull(species.getReferenceTaxonId());
-
- catchBatchDao.setSortingBatchReferenceTaxon(batchId, species.getReferenceTaxonId());
- }
-
- //------------------------------------------------------------------------//
- //-- SpeciesBatchFrequency methods --//
- //------------------------------------------------------------------------//
-
- @Override
- public List<SpeciesBatchFrequency> getAllSpeciesBatchFrequency(
- String speciesBatchId) {
- List<SpeciesBatchFrequency> results = Lists.newArrayList();
-
- Integer catchBatchId = catchBatchDao.getIdBySortingBatchId(Integer.valueOf(speciesBatchId));
- fr.ifremer.adagio.core.dao.data.batch.CatchBatch catchBatch = catchBatchDao.loadFullTree(catchBatchId);
-
- if (catchBatchId == null) {
- return results;
- }
-
- SortingBatch sortingBatch = catchBatchDao.getSortingBatchById(catchBatch, Integer.valueOf(speciesBatchId));
-
- for (Batch batch : sortingBatch.getChildBatchs()) {
- SortingBatch source = (SortingBatch) batch;
- SpeciesBatchFrequency target = new SpeciesBatchFrequency();
-
- entityToBean(source, target);
- results.add(target);
- }
- return Collections.unmodifiableList(results);
- }
-
- @Override
- public List<SpeciesBatchFrequency> saveSpeciesBatchFrequency(
- String speciesBatchId,
- List<SpeciesBatchFrequency> frequencies) {
- Preconditions.checkNotNull(speciesBatchId);
- Preconditions.checkNotNull(frequencies);
-
- List<SpeciesBatchFrequency> notNullFrequencies = Lists.newArrayList();
-
- // Check that all frequencies have the same length PMFM (before doing any db call)
- // and remove null frequencies
- String pmfmId = null;
- for (SpeciesBatchFrequency source : frequencies) {
-
- if (source.getLengthStepCaracteristic() != null) {
- if (pmfmId == null) {
- pmfmId = source.getLengthStepCaracteristic().getId();
- } else if (!pmfmId.equals(source.getLengthStepCaracteristic().getId())) {
- throw new DataIntegrityViolationException("Batch frequencies under one Speciesbatch must have all the same lengthStepCaracteristic");
- }
- notNullFrequencies.add(source);
- }
- }
-
- getCurrentSession().setFlushMode(FlushMode.COMMIT);
-
- Integer catchBatchId = catchBatchDao.getIdBySortingBatchId(Integer.valueOf(speciesBatchId));
- fr.ifremer.adagio.core.dao.data.batch.CatchBatch catchBatch = catchBatchDao.loadFullTree(catchBatchId);
-
- if (catchBatch == null) {
- return notNullFrequencies;
- }
-
- // Retrieve parent
- SortingBatch parentBatch = catchBatchDao.getSortingBatchById(catchBatch, Integer.valueOf(speciesBatchId));
-
- // Remember child ids, to remove unchanged item (see at bottom in this method)
- List<Integer> notUpdatedChildIds = Lists.newArrayList();
- for (Batch batch : parentBatch.getChildBatchs()) {
- SortingBatch sortingBatch = (SortingBatch) batch;
- notUpdatedChildIds.add(sortingBatch.getId());
- }
-
- short rankOrder = 0;
- List<SortingBatch> batchsToUpdate = Lists.newArrayList();
- for (SpeciesBatchFrequency source : notNullFrequencies) {
- rankOrder++;
-
- // Not existing batch
- SortingBatch target;
- 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
- catchBatchDao.createSortingBatch(target, catchBatch);
- source.setId(target.getId().toString());
- }
-
- // Existing batch
- else {
- target = catchBatchDao.loadSortingBatch(Integer.valueOf(source.getId()), catchBatch);
-
- // 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);
-
- notUpdatedChildIds.remove(target.getId());
- }
- }
-
- // If some batchs need to be update, do it
- if (batchsToUpdate.size() > 0) {
- catchBatchDao.updateSortingBatch(batchsToUpdate, catchBatch);
- }
-
- if (notUpdatedChildIds.size() > 0) {
- for (Integer batchId : notUpdatedChildIds) {
- catchBatchDao.removeWithChildren(batchId, catchBatch);
- }
- }
-
- getCurrentSession().flush();
-
- return Collections.unmodifiableList(notNullFrequencies);
- }
-
- //------------------------------------------------------------------------//
- //-- Benthos Batch methods --//
- //------------------------------------------------------------------------//
-
- @Override
- public BatchContainer<SpeciesBatch> getRootBenthosBatch(String fishingOperationId) {
- // Load batch tree
- Integer catchBatchId = catchBatchDao.getIdByFishingOperationId(Integer.valueOf(fishingOperationId));
- fr.ifremer.adagio.core.dao.data.batch.CatchBatch catchBatch = catchBatchDao.loadFullTree(catchBatchId);
-
- // Vrac / Benthos
- SortingBatch vracSpeciesBatch = catchBatchDao.getSortingBatch(catchBatch.getChildBatchs(),
- "pmfmId", enumeration.PMFM_ID_SORTED_UNSORTED, enumeration.QUALITATIVE_VRAC_ID,
- "pmfmId", enumeration.PMFM_ID_SORTING_TYPE, enumeration.QUALITATIVE_ID_SORTING_TYPE_BENTHOS);
-
- BatchContainer<SpeciesBatch> result = new BatchContainer<SpeciesBatch>();
- result.setId(String.valueOf(vracSpeciesBatch.getId()));
- for (Batch batch1 : vracSpeciesBatch.getChildBatchs()) {
- SortingBatch source = (SortingBatch) batch1;
-
- // evict some special batches : Life (or Biota) and Inert
- if (source.getReferenceTaxon() != null
- && !enumeration.REFERENCE_TAXON_ID_LIFE.equals(source.getReferenceTaxon().getId())
- && !enumeration.REFERENCE_TAXON_ID_INERT.equals(source.getReferenceTaxon().getId())) {
- SpeciesBatch target = new SpeciesBatch();
-
- entityToBean(source, target);
- result.addChildren(target);
- }
- }
-
- // Hors-Vrac / Benthos
- SortingBatch horsVracSpeciesBatch = catchBatchDao.getSortingBatch(catchBatch.getChildBatchs(),
- "pmfmId", enumeration.PMFM_ID_SORTED_UNSORTED, enumeration.QUALITATIVE_HORS_VRAC_ID,
- "pmfmId", enumeration.PMFM_ID_SORTING_TYPE, enumeration.QUALITATIVE_ID_SORTING_TYPE_BENTHOS);
- if (horsVracSpeciesBatch != null) {
- for (Batch batch : horsVracSpeciesBatch.getChildBatchs()) {
- SortingBatch source = (SortingBatch) batch;
-
- SpeciesBatch target = new SpeciesBatch();
-
- entityToBean(source, target);
- result.addChildren(target);
- }
- }
- return result;
- }
-
- @Override
- public SpeciesBatch createBenthosBatch(SpeciesBatch bean,
- String parentBatchId) {
- Preconditions.checkNotNull(bean);
- Preconditions.checkArgument(bean.getId() == null);
- Preconditions.checkNotNull(bean.getSpecies());
- Preconditions.checkNotNull(bean.getSpecies().getId());
- Preconditions.checkNotNull(bean.getFishingOperation());
- Preconditions.checkNotNull(bean.getFishingOperation().getId());
-
- getCurrentSession().setFlushMode(FlushMode.COMMIT);
-
- // Load full batch tree
- Integer catchBatchId = catchBatchDao.getIdByFishingOperationId(Integer.valueOf(bean.getFishingOperation().getId()));
- fr.ifremer.adagio.core.dao.data.batch.CatchBatch catchBatch = catchBatchDao.loadFullTree(catchBatchId);
-
- SortingBatch batch = SortingBatch.Factory.newInstance();
- benthosBatchToEntity(bean, batch, parentBatchId, catchBatch);
- batch = catchBatchDao.createSortingBatch(batch, catchBatch);
-
- bean.setId(String.valueOf(batch.getId()));
-
- getCurrentSession().flush();
-
- return bean;
- }
-
- @Override
- public SpeciesBatch saveBenthosBatch(SpeciesBatch bean) {
- Preconditions.checkNotNull(bean);
- Preconditions.checkNotNull(bean.getId());
-
- // Load full batch tree
- Integer catchBatchId = catchBatchDao.getIdBySortingBatchId(Integer.valueOf(bean.getId()));
- fr.ifremer.adagio.core.dao.data.batch.CatchBatch catchBatch = catchBatchDao.loadFullTree(catchBatchId);
-
- getCurrentSession().setFlushMode(FlushMode.COMMIT);
-
- SortingBatch batch = catchBatchDao.getSortingBatchById(catchBatch, Integer.valueOf(bean.getId()));
- String parentBatchId = null;
- if (bean.getParentBatch() != null) {
- parentBatchId = bean.getParentBatch().getId();
- }
- benthosBatchToEntity(bean, batch, parentBatchId, catchBatch);
- catchBatchDao.updateSortingBatch(batch, catchBatch);
- getCurrentSession().flush();
-
- return bean;
- }
-
- @Override
- public void deleteBenthosBatch(String id) {
- Preconditions.checkNotNull(id);
-
- getCurrentSession().setFlushMode(FlushMode.COMMIT);
-
- catchBatchDao.removeWithChildren(Integer.valueOf(id));
-
- getCurrentSession().flush();
- }
-
- @Override
- public void deleteBenthosSubBatch(String id) {
- deleteBenthosBatch(id);
- }
-
- @Override
- public void changeBenthosBatchSpecies(String batchId, Species species) {
-
- Preconditions.checkNotNull(batchId);
- Preconditions.checkNotNull(species);
- Preconditions.checkNotNull(species.getReferenceTaxonId());
-
- if (log.isDebugEnabled()) {
- log.debug("Changing species for batch id=" + batchId);
- }
-
- int rowUpdated = queryUpdate("updateBatchSpecies",
- "batchId", IntegerType.INSTANCE, Integer.valueOf(batchId),
- "referenceTaxonId", IntegerType.INSTANCE, species.getReferenceTaxonId());
- Preconditions.checkArgument(rowUpdated == 1, "Unable to update operation, to be linked with catch batch.");
- }
-
- //------------------------------------------------------------------------//
- //-- SpeciesBatchFrequency methods (for benthos) --//
- //------------------------------------------------------------------------//
-
- @Override
- public List<SpeciesBatchFrequency> getAllBenthosBatchFrequency(String benthosBatchId) {
- List<SpeciesBatchFrequency> results = Lists.newArrayList();
-
- Integer catchBatchId = catchBatchDao.getIdBySortingBatchId(Integer.valueOf(benthosBatchId));
- fr.ifremer.adagio.core.dao.data.batch.CatchBatch catchBatch = catchBatchDao.loadFullTree(catchBatchId);
-
- if (catchBatchId == null) {
- return results;
- }
-
- SortingBatch sortingBatch = catchBatchDao.getSortingBatchById(catchBatch, Integer.valueOf(benthosBatchId));
-
- for (Batch batch : sortingBatch.getChildBatchs()) {
- SortingBatch source = (SortingBatch) batch;
- SpeciesBatchFrequency target = new SpeciesBatchFrequency();
-
- entityToBean(source, target);
- results.add(target);
- }
- return Collections.unmodifiableList(results);
- }
-
- @Override
- public List<SpeciesBatchFrequency> saveBenthosBatchFrequency(String benthosBatchId,
- List<SpeciesBatchFrequency> frequencies) {
- Preconditions.checkNotNull(benthosBatchId);
- Preconditions.checkNotNull(frequencies);
-
- // Check that all frequencies have the same length PMFM (before doing any db call)
- String pmfmId = null;
- for (SpeciesBatchFrequency source : frequencies) {
-
- if (pmfmId == null) {
- pmfmId = source.getLengthStepCaracteristic().getId();
- } else if (!pmfmId.equals(source.getLengthStepCaracteristic().getId())) {
- throw new DataIntegrityViolationException("Batch frequencies under one Speciesbatch must have all the same lengthStepCaracteristic");
- }
- }
-
- getCurrentSession().setFlushMode(FlushMode.COMMIT);
-
- Integer catchBatchId = catchBatchDao.getIdBySortingBatchId(Integer.valueOf(benthosBatchId));
- fr.ifremer.adagio.core.dao.data.batch.CatchBatch catchBatch = catchBatchDao.loadFullTree(catchBatchId);
-
- if (catchBatch == null) {
- return frequencies;
- }
-
- // Retrieve parent
- SortingBatch parentBatch = catchBatchDao.getSortingBatchById(catchBatch, Integer.valueOf(benthosBatchId));
-
- // Remember child ids, to remove unchanged item (see at bottom in this method)
- List<Integer> notUpdatedChildIds = Lists.newArrayList();
- for (Batch batch : parentBatch.getChildBatchs()) {
- SortingBatch sortingBatch = (SortingBatch) batch;
- notUpdatedChildIds.add(sortingBatch.getId());
- }
-
- short rankOrder = 0;
- List<SortingBatch> batchsToUpdate = Lists.newArrayList();
- for (SpeciesBatchFrequency source : frequencies) {
- rankOrder++;
-
- // Not existing batch
- SortingBatch target;
- 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
- catchBatchDao.createSortingBatch(target, catchBatch);
- source.setId(target.getId().toString());
- }
-
- // Existing batch
- else {
- target = catchBatchDao.getSortingBatchById(catchBatch, 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);
-
- notUpdatedChildIds.remove(target.getId());
- }
- }
-
- // If some batchs need to be update, do it
- if (batchsToUpdate.size() > 0) {
- catchBatchDao.updateSortingBatch(batchsToUpdate, catchBatch);
- }
-
- if (notUpdatedChildIds.size() > 0) {
- for (Integer batchId : notUpdatedChildIds) {
- catchBatchDao.removeWithChildren(batchId, catchBatch);
- }
- }
-
- getCurrentSession().flush();
-
- return Collections.unmodifiableList(frequencies);
- }
-
-
- //------------------------------------------------------------------------//
- //-- Internal methods --//
- //------------------------------------------------------------------------//
-
- protected SpeciesBatch entityToBean(SortingBatch source,
- SpeciesBatch target) {
-
- target.setId(source.getId().toString());
-
- // Individual count
- target.setNumber(source.getIndividualCount());
-
- // Convert database weight (and sampling ratio) into UI weight and sampleCategoryWeight
- if (source.getWeight() != null && source.getWeightBeforeSampling() == null) {
- target.setSampleCategoryWeight(source.getWeight());
- } else {
- target.setWeight(source.getWeight());
- target.setSampleCategoryWeight(source.getWeightBeforeSampling());
- }
-
- // Comments
- target.setComment(source.getComments());
-
- // Sample category type (only one is applied)
- SortingMeasurement sm = null;
- if (source.getSortingMeasurements().size() == 1) {
- sm = source.getSortingMeasurements().iterator().next();
- } else if (source.getReferenceTaxon() != null && source.getReferenceTaxon().getId() != null) {
- sm = catchBatchDao.getInheritedSortingMeasurement(source, enumeration.PMFM_ID_SORTED_UNSORTED);
- }
- if (sm != null) {
- SampleCategoryEnum sampleCategory = enumeration.getSampleCategoryByPmfmId(sm.getPmfm().getId());
- if (sampleCategory != null) {
- Integer qualitativeId = null;
- if (sm.getQualitativeValue() != null) {
- qualitativeId = sm.getQualitativeValue().getId();
- }
- setSampleCategoryQualitative(target, sm.getPmfm().getId(), sm.getNumericalValue(), sm.getAlphanumericalValue(), qualitativeId);
- }
- }
-
- // Species
- Integer referenceTaxonId = source.getInheritedReferenceTaxonId();
- if (referenceTaxonId == null && source.getReferenceTaxon() != null) {
- referenceTaxonId = source.getReferenceTaxon().getId();
- }
- if (referenceTaxonId != null) {
- // TODO : add cache on getSpeciesByReferenceTaxonId
- Species species = referentialService.getSpeciesByReferenceTaxonId(referenceTaxonId);
- target.setSpecies(species);
- }
-
- if (target.getSampleCategoryType() != null && source.getChildBatchs().size() > 0) {
- List<SpeciesBatch> targetChilds = Lists.newArrayList();
- for (Batch batch : source.getChildBatchs()) {
- SortingBatch sourceChild = (SortingBatch) batch;
- SpeciesBatch targetChild = new SpeciesBatch();
- entityToBean(sourceChild, targetChild);
- if (targetChild.getSampleCategoryValue() != null) {
- targetChilds.add(targetChild);
- targetChild.setParentBatch(target);
- }
- }
- target.setChildBatchs(targetChilds);
- }
-
- return target;
- }
-
- protected void entityToBean(SortingBatch source,
- SpeciesBatchFrequency target) {
-
- target.setId(source.getId().toString());
-
- target.setNumber(source.getIndividualCount());
- target.setWeight(source.getWeight());
- target.setComment(source.getComments());
-
- // Length step category
- if (source.getSortingMeasurements().size() == 1) {
- SortingMeasurement sm = source.getSortingMeasurements().iterator().next();
- if (sm.getPmfm() != null && sm.getPmfm().getId() != null) {
- Caracteristic lengthStepCaracteristic = referentialService.getCaracteristic(sm.getPmfm().getId());
- target.setLengthStepCaracteristic(lengthStepCaracteristic);
- }
-
- // Length
- target.setLengthStep(sm.getNumericalValue());
- }
- }
-
- protected void speciesBatchToEntity(SpeciesBatch source,
- SortingBatch target,
- String parentBatchId,
- fr.ifremer.adagio.core.dao.data.batch.CatchBatch catchBatch) {
- sortingBatchToEntity(source, target, parentBatchId, catchBatch, enumeration.QUALITATIVE_ID_SORTING_TYPE_SPECIES);
- }
-
- protected void benthosBatchToEntity(SpeciesBatch source,
- SortingBatch target,
- String parentBatchId,
- fr.ifremer.adagio.core.dao.data.batch.CatchBatch catchBatch) {
- sortingBatchToEntity(source, target, parentBatchId, catchBatch, enumeration.QUALITATIVE_ID_SORTING_TYPE_BENTHOS);
- }
-
- protected void sortingBatchToEntity(SpeciesBatch source,
- SortingBatch target,
- String parentBatchId,
- fr.ifremer.adagio.core.dao.data.batch.CatchBatch catchBatch,
- Integer batchPmfm) {
-
- Preconditions.checkNotNull(source.getFishingOperation());
- Preconditions.checkNotNull(source.getFishingOperation().getId());
-
- // Retrieve recorder department
- Integer recorderDepartmentId = getRecorderDepartmentId();
-
- // Create lists to store all updates, then remove not updated items
- Set<QuantificationMeasurement> notChangedQuantificationMeasurements = new HashSet<QuantificationMeasurement>();
- if (target.getQuantificationMeasurements() != null) {
- notChangedQuantificationMeasurements.addAll(target.getQuantificationMeasurements());
- }
- Set<SortingMeasurement> notChangedSortingMeasurements = new HashSet<SortingMeasurement>();
- if (target.getSortingMeasurements() != null) {
- notChangedSortingMeasurements.addAll(target.getSortingMeasurements());
- }
-
- // If parent and root need to be set
- if (target.getId() == null
- || target.getRootBatch() == null
- || (target.getParentBatch() != null && !target.getParentBatch().getId().toString().equals(parentBatchId))) {
- setBatchParents(source, target, parentBatchId, catchBatch, batchPmfm);
- }
-
- // RankOrder (initialize once, at creation)
- if (target.getRankOrder() == null) {
- // Start rank order at 3, because of special batches 'Biota' and 'Inert'
- short rankOrder = (short) 3;
- if (source.getParentBatch() != null && source.getParentBatch().getChildBatchs() != null) {
- rankOrder += (short) source.getParentBatch().getChildBatchs().size();
- } else if (target.getParentBatch() != null && target.getParentBatch().getChildBatchs() != null) {
- rankOrder += (short) target.getParentBatch().getChildBatchs().size();
- }
- target.setRankOrder(rankOrder);
- }
-
- // Force subgroup count to '1', as Allegro
- target.setSubgroupCount(1f);
-
- // Weight or SampleCategoryWeight
- if (source.getWeight() == null && source.getSampleCategoryWeight() == null) {
- // Nothing to do : will be removed later, using notChangedSortingMeasurements
- } else if (source.getSampleCategoryWeight() != null && source.getWeight() == null) {
- QuantificationMeasurement quantificationMeasurement = catchBatchDao.setQuantificationMeasurement(target,
- enumeration.PMFM_ID_WEIGHT_MEASURED, recorderDepartmentId, source.getSampleCategoryWeight(), true);
- notChangedQuantificationMeasurements.remove(quantificationMeasurement);
- } else if (source.getWeight() != null && source.getSampleCategoryWeight() == null) {
- QuantificationMeasurement quantificationMeasurement = catchBatchDao.setQuantificationMeasurement(target,
- enumeration.PMFM_ID_WEIGHT_MEASURED, recorderDepartmentId, source.getWeight(), true);
- notChangedQuantificationMeasurements.remove(quantificationMeasurement);
- }
-
- // Sampling Ratio
- if (source.getSampleCategoryWeight() == null || source.getWeight() == null) {
- target.setSamplingRatio(null);
- target.setSamplingRatioText(null);
- } else if (source.getSampleCategoryWeight() != null && source.getWeight() != null) {
- String samplingRatioText = source.getWeight() + "/" + source.getSampleCategoryWeight();
- samplingRatioText = samplingRatioText.replaceAll(",", ".");
- target.setSamplingRatioText(samplingRatioText);
- target.setSamplingRatio(source.getWeight() / source.getSampleCategoryWeight());
- QuantificationMeasurement quantificationMeasurement = catchBatchDao.setQuantificationMeasurement(target,
- enumeration.PMFM_ID_WEIGHT_MEASURED, recorderDepartmentId, source.getWeight(), true);
- notChangedQuantificationMeasurements.remove(quantificationMeasurement);
- }
-
- // Sorting measurement
- if (source.getSampleCategoryType() == null || source.getSampleCategoryValue() == null) {
- // Nothing to do : will be removed later, using notChangedSortingMeasurements
- } else if (source.getSampleCategoryType() != null && source.getSampleCategoryValue() != null) {
- Integer pmfmId = sampleCategory2PmfmId(source.getSampleCategoryType());
- // Do not store sorting measurement if pmfm = SORTED (already store in an ancestor batch)
- if (!pmfmId.equals(enumeration.PMFM_ID_SORTED_UNSORTED)) {
- SortingMeasurement sortingMeasurement = setSortingMeasurement(target, recorderDepartmentId,
- source.getSampleCategoryType(), source.getSampleCategoryValue());
- notChangedSortingMeasurements.remove(sortingMeasurement);
- }
- }
-
- // Individual count
- if (source.getNumber() == null) {
- target.setIndividualCount(null);
- } else if (source.getNumber() != null) {
- target.setIndividualCount(source.getNumber());
- }
-
- // Species
- if (source.getSpecies() == null || parentBatchId != null) {
- target.setReferenceTaxon(null);
- } else if (source.getSpecies() != null && parentBatchId == null) {
- ReferenceTaxon referenceTaxon = load(ReferenceTaxonImpl.class, source.getSpecies().getReferenceTaxonId());
- target.setReferenceTaxon(referenceTaxon);
- }
-
- // QualityFlag
- if (source.isSpeciesToConfirm()) {
- target.setQualityFlag(load(QualityFlagImpl.class, enumeration.QUALITY_FLAG_CODE_DOUBTFUL));
- } else {
- target.setQualityFlag(load(QualityFlagImpl.class, enumeration.QUALITY_FLAG_CODE_NOT_QUALIFIED));
- }
-
- // Comments
- if (source.getComment() == null) {
- target.setComments(null);
- } else if (source.getComment() != null) {
- target.setComments(source.getComment());
- }
-
- // Exhaustive inventory (always true under a species batch)
- target.setExhaustiveInventory(true);
-
- // Removed not changed measurements (in sorting and quantification measurement lists)
- if (target.getQuantificationMeasurements() != null && notChangedQuantificationMeasurements.size() > 0) {
- for (QuantificationMeasurement qm : notChangedQuantificationMeasurements) {
- target.getQuantificationMeasurements().remove(qm);
- }
- }
- if (target.getSortingMeasurements() != null && notChangedSortingMeasurements.size() > 0) {
- for (SortingMeasurement sm : notChangedSortingMeasurements) {
- target.getSortingMeasurements().remove(sm);
- }
- }
- }
-
- protected void setBatchParents(SpeciesBatch source,
- SortingBatch target,
- String parentBatchIdStr,
- fr.ifremer.adagio.core.dao.data.batch.CatchBatch catchBatch,
- Integer batchPmfmId) {
-
- Preconditions.checkNotNull(target);
- Preconditions.checkNotNull(source.getFishingOperation());
- Preconditions.checkNotNull(source.getFishingOperation().getId());
-
- // Load existing parent and root
- SortingBatch parentBatch;
- if (parentBatchIdStr != null) {
- parentBatch = catchBatchDao.getSortingBatchById(catchBatch, Integer.valueOf(parentBatchIdStr));
- }
-
- // Or retrieve parent batch, from pmfm id
- else {
- // Retrieve category type
- Integer pmfmId = 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})",
- SampleCategoryEnum.sortedUnsorted.name(),
- enumeration.PMFM_ID_SORTED_UNSORTED));
- }
- Integer qualitativeValueId = convertSampleCategoryValueIntoQualitativeId(source.getSampleCategoryValue());
-
- parentBatch = catchBatchDao.getSortingBatch(catchBatch.getChildBatchs(),
- "pmfmId", pmfmId, qualitativeValueId,
- "pmfmId", enumeration.PMFM_ID_SORTING_TYPE, batchPmfmId);
-
- // Parent Batch
- target.setParentBatch(parentBatch);
- }
-
-
- if (parentBatch == null) {
- throw new DataIntegrityViolationException(
- "Could not retrieve parent batch, for a given speciesBatch : invalid batch tree structure. Please make sure CatchBatch has been saved before to create a SpeciesBatch.");
- }
-
- // Parent Batch
- target.setParentBatch(parentBatch);
- target.setRootBatch(catchBatch);
- }
-
- protected Integer convertSampleCategoryValueIntoQualitativeId(Serializable value) {
- if (value == null)
- return null;
- Integer qualitativeValueId = null;
- if (value instanceof CaracteristicQualitativeValue) {
- CaracteristicQualitativeValue cqValue = (CaracteristicQualitativeValue) value;
- qualitativeValueId = Integer.valueOf(cqValue.getId());
- } else if (value instanceof String) {
- qualitativeValueId = Integer.valueOf((String) value);
- }
- return qualitativeValueId;
- }
-
- 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.)
- if (pmfmId == null || pmfmId.equals(enumeration.PMFM_ID_SORTING_TYPE)) {
- return;
- }
-
- SampleCategoryEnum sampleCategory = enumeration.getSampleCategoryByPmfmId(pmfmId);
- Preconditions.checkNotNull(sampleCategory, "Unable to find corresponding SampleCategoryEnum for PMFM.ID : " + pmfmId);
-
- target.setSampleCategoryType(sampleCategory);
- if (numericalvalue != null) {
- target.setSampleCategoryValue(numericalvalue);
- return;
- }
- if (alphanumericalValue != null) {
- target.setSampleCategoryValue(alphanumericalValue);
- return;
- }
-
- Caracteristic caracteristic = referentialService.getCaracteristic(pmfmId);
- if (caracteristic == null || caracteristic.getCaracteristicType() != CaracteristicType.QUALITATIVE) {
- return;
- }
- CaracteristicQualitativeValue value = null;
- for (CaracteristicQualitativeValue qv : caracteristic.getQualitativeValue()) {
- if (qualitativeValueId == Integer.parseInt(qv.getId())) {
- value = qv;
- break;
- }
- }
- target.setSampleCategoryValue(value);
- }
-
- protected void beanToEntity(SpeciesBatchFrequency source, SortingBatch target, SortingBatch parentBatch, short rankOrder, boolean copyIfNull) {
- Preconditions.checkNotNull(source.getBatch());
- Preconditions.checkNotNull(source.getBatch().getId());
-
- // Retrieve recorder department
- Integer recorderDepartmentId = getRecorderDepartmentId();
-
- // Create lists to store all updates, then remove not updated items
- Set<QuantificationMeasurement> notChangedQuantificationMeasurements = new HashSet<QuantificationMeasurement>();
- if (target.getQuantificationMeasurements() != null) {
- notChangedQuantificationMeasurements.addAll(target.getQuantificationMeasurements());
- }
- Set<SortingMeasurement> notChangedSortingMeasurements = new HashSet<SortingMeasurement>();
- if (target.getSortingMeasurements() != null) {
- notChangedSortingMeasurements.addAll(target.getSortingMeasurements());
- }
-
- // If parent and root need to be set
- if (target.getId() == null
- || target.getRootBatch() == null
- || (target.getParentBatch() != null && !target.getParentBatch().getId().equals(parentBatch.getId()))) {
-
- target.setParentBatch(parentBatch);
- target.setRootBatch(parentBatch.getRootBatch());
- }
-
- // RankOrder
- target.setRankOrder(rankOrder);
-
- // Weight or SampleCategoryWeight
- if (copyIfNull && source.getWeight() == null) {
- // Nothing to do : will be removed later, using notChangedSortingMeasurements
- } else if (source.getWeight() != null) {
- QuantificationMeasurement quantificationMeasurement = catchBatchDao.setQuantificationMeasurement(target,
- enumeration.PMFM_ID_WEIGHT_MEASURED, recorderDepartmentId, source.getWeight(), true);
- notChangedQuantificationMeasurements.remove(quantificationMeasurement);
- }
-
- // Sorting measurement
- if (copyIfNull && (source.getLengthStepCaracteristic() == null || source.getLengthStep() == null)) {
- // Nothing to do : will be removed later, using notChangedSortingMeasurements
- } else if (source.getLengthStepCaracteristic() != null && source.getLengthStep() != null) {
- Integer pmfmId = Integer.valueOf(source.getLengthStepCaracteristic().getId());
- SortingMeasurement sortingMeasurement = setSortingMeasurement(target, recorderDepartmentId, pmfmId,
- source.getLengthStep());
- notChangedSortingMeasurements.remove(sortingMeasurement);
- }
-
- // Individual count
- if (copyIfNull && source.getNumber() == null) {
- target.setIndividualCount(null);
- } else if (source.getNumber() != null) {
- target.setIndividualCount(source.getNumber());
- }
-
- // Species
- target.setReferenceTaxon(null);
-
- // QualityFlag
- target.setQualityFlag(parentBatch.getQualityFlag());
-
- // Comments
- if (copyIfNull && source.getComment() == null) {
- target.setComments(null);
- } else if (source.getComment() != null) {
- target.setComments(source.getComment());
- }
-
- // Exhaustive inventory (always true under a species batch)
- target.setExhaustiveInventory(true);
-
- // Removed not changed measurements (in sorting and quantification measurement lists)
- if (target.getQuantificationMeasurements() != null && notChangedQuantificationMeasurements.size() > 0) {
- for (QuantificationMeasurement qm : notChangedQuantificationMeasurements) {
- target.getQuantificationMeasurements().remove(qm);
- }
- }
- if (target.getSortingMeasurements() != null && notChangedSortingMeasurements.size() > 0) {
- for (SortingMeasurement sm : notChangedSortingMeasurements) {
- target.getSortingMeasurements().remove(sm);
- }
- }
- }
-
- protected UIWeight convertDatabase2UI(Float weight, Float samplingRatio, String samplingRatioText) {
- UIWeight result = new UIWeight();
-
- // Weight & sampleCategory Weight
- if (samplingRatio == null) {
- result.sampleCategoryWeight = weight;
- } else if (weight != null) {
- String startStr = weight.toString().replace(',', '.') + "/";
- if (samplingRatioText != null && samplingRatioText.startsWith(startStr)) {
- String weightStr = samplingRatioText.substring(startStr.length());
- if (weightStr != null && !weightStr.isEmpty()) {
- result.sampleCategoryWeight = Float.parseFloat(weightStr);
- result.weight = weight;
- }
- } else {
- result.sampleCategoryWeight = weight;
- }
- }
- return result;
- }
-
- static class UIWeight {
- Float sampleCategoryWeight = null;
-
- Float weight = null;
- }
-
- protected void beanToEntity(CatchBatch source,
- fr.ifremer.adagio.core.dao.data.batch.CatchBatch target,
- boolean copyIfNull) {
- Preconditions.checkNotNull(source.getFishingOperation());
- Preconditions.checkNotNull(source.getFishingOperation().getId());
-
- // Retrieve recorder department
- Integer recorderDepartmentId = getRecorderDepartmentId();
-
- // First initialization (when created)
- Integer fishingOperationId = Integer.valueOf(source.getFishingOperation().getId());
- target.setFishingOperation(load(FishingOperationImpl.class, fishingOperationId));
-
- target.setQualityFlag(load(QualityFlagImpl.class, enumeration.QUALITY_FLAG_CODE_NOT_QUALIFIED));
- target.setRankOrder((short) 1);
- target.setSynchronizationStatus(SynchronizationStatus.DIRTY.getValue());
-
- // Create lists to store all updates, then remove not updated items
- Set<QuantificationMeasurement> notChangedQuantificationMeasurements = new HashSet<QuantificationMeasurement>();
- if (target.getQuantificationMeasurements() != null) {
- notChangedQuantificationMeasurements.addAll(target.getQuantificationMeasurements());
- }
-
- // Total Weight
- if (copyIfNull && source.getCatchTotalWeight() == null) {
- // Nothing to do : will be removed later, using notChangedQuantificationMeasurements
- } else if (source.getCatchTotalWeight() != null) {
- QuantificationMeasurement quantificationMeasurement = catchBatchDao.setQuantificationMeasurement(target,
- enumeration.PMFM_ID_WEIGHT_MEASURED, recorderDepartmentId, source.getCatchTotalWeight(), true);
- notChangedQuantificationMeasurements.remove(quantificationMeasurement);
- }
-
- // Removed not changed measurements (in sorting and quantification measurement lists)
- if (target.getQuantificationMeasurements() != null && notChangedQuantificationMeasurements.size() > 0) {
- for (QuantificationMeasurement qm : notChangedQuantificationMeasurements) {
- target.getQuantificationMeasurements().remove(qm);
- }
- }
- Map<Integer, SortingBatch> catchBatchChilds = getChildsMap(target, enumeration.PMFM_ID_SORTED_UNSORTED);
-
- // -----------------------------------------------------------------------------
- // Sorted Vrac
- // -----------------------------------------------------------------------------
- {
- SortingBatch batch = catchBatchChilds.get(enumeration.QUALITATIVE_VRAC_ID);
- if (batch == null) {
- batch = SortingBatch.Factory.newInstance();
- target.getChildBatchs().add(batch);
- }
- beanToEntitySortingBatch(target, target, batch, recorderDepartmentId,
- enumeration.PMFM_ID_SORTED_UNSORTED, enumeration.QUALITATIVE_VRAC_ID,
- source.getCatchTotalSortedCarousselWeight(), source.getCatchTotalSortedTremisWeight(),
- copyIfNull);
- batch.setRankOrder((short) 1);
-
- // Manage childs :
- {
- Map<Integer, SortingBatch> batchChilds = getChildsMap(batch, enumeration.PMFM_ID_SORTING_TYPE);
-
- // -----------------------------------------------------------------------------
- // Sorted Vrac / Species
- // -----------------------------------------------------------------------------
- SortingBatch speciesBatch = batchChilds.get(enumeration.QUALITATIVE_ID_SORTING_TYPE_SPECIES);
- if (speciesBatch == null) {
- speciesBatch = SortingBatch.Factory.newInstance();
- if (batch.getChildBatchs() == null) {
- batch.setChildBatchs(Lists.newArrayList((Batch) speciesBatch));
- } else {
- batch.getChildBatchs().add(speciesBatch);
- }
- }
- beanToEntitySortingBatch(target, batch, speciesBatch, recorderDepartmentId,
- enumeration.PMFM_ID_SORTING_TYPE, enumeration.QUALITATIVE_ID_SORTING_TYPE_SPECIES,
- source.getSpeciesTotalSampleSortedWeight(), source.getSpeciesTotalSortedWeight(),
- copyIfNull);
- speciesBatch.setRankOrder((short) 1);
-
- {
- // -----------------------------------------------------------------------------
- // Sorted Vrac / Species / Alive not itemized
- // -----------------------------------------------------------------------------
- SortingBatch aliveNotItemizedBatch = catchBatchDao.getSortingBatch(speciesBatch.getChildBatchs(), "referenceTaxonId", enumeration.REFERENCE_TAXON_ID_LIFE);
- if (aliveNotItemizedBatch == null) {
- aliveNotItemizedBatch = SortingBatch.Factory.newInstance();
- if (speciesBatch.getChildBatchs() == null) {
- speciesBatch.setChildBatchs(Lists.newArrayList((Batch) aliveNotItemizedBatch));
- } else {
- speciesBatch.getChildBatchs().add(aliveNotItemizedBatch);
- }
- }
- beanToEntityReferenceTaxonBatch(target, speciesBatch, aliveNotItemizedBatch, recorderDepartmentId,
- enumeration.REFERENCE_TAXON_ID_LIFE,
- source.getSpeciesTotalLivingNotItemizedWeight(), null,
- copyIfNull);
- aliveNotItemizedBatch.setRankOrder((short) 1);
-
- // -----------------------------------------------------------------------------
- // Sorted Vrac / Species / Inert (not alive)
- // -----------------------------------------------------------------------------
- SortingBatch inertBatch = catchBatchDao.getSortingBatch(speciesBatch.getChildBatchs(), "referenceTaxonId", enumeration.REFERENCE_TAXON_ID_INERT);
- if (inertBatch == null) {
- inertBatch = SortingBatch.Factory.newInstance();
- speciesBatch.getChildBatchs().add(inertBatch);
- }
- beanToEntityReferenceTaxonBatch(target, speciesBatch, inertBatch, recorderDepartmentId,
- enumeration.REFERENCE_TAXON_ID_INERT,
- source.getSpeciesTotalInertWeight(), null,
- copyIfNull);
- inertBatch.setRankOrder((short) 2);
- }
-
- // -----------------------------------------------------------------------------
- // Sorted Vrac > Benthos
- // -----------------------------------------------------------------------------
- {
- SortingBatch benthosBatch = batchChilds.get(enumeration.QUALITATIVE_ID_SORTING_TYPE_BENTHOS);
- if (benthosBatch == null) {
- benthosBatch = SortingBatch.Factory.newInstance();
- batch.getChildBatchs().add(benthosBatch);
- }
- beanToEntitySortingBatch(target, batch, benthosBatch, recorderDepartmentId,
- enumeration.PMFM_ID_SORTING_TYPE, enumeration.QUALITATIVE_ID_SORTING_TYPE_BENTHOS,
- source.getBenthosTotalSampleSortedWeight(), source.getBenthosTotalSortedWeight(),
- copyIfNull);
- benthosBatch.setRankOrder((short) 2);
- }
-
- // TODO plancton, macro déchet...
- }
- }
-
- // -----------------------------------------------------------------------------
- // Sorted Hors Vrac
- // -----------------------------------------------------------------------------
- {
- SortingBatch batch = catchBatchChilds.get(enumeration.QUALITATIVE_HORS_VRAC_ID);
- if (batch == null) {
- batch = SortingBatch.Factory.newInstance();
- target.getChildBatchs().add(batch);
- }
- beanToEntitySortingBatch(target, target, batch, recorderDepartmentId,
- enumeration.PMFM_ID_SORTED_UNSORTED, enumeration.QUALITATIVE_HORS_VRAC_ID,
- source.getCatchTotalUnsortedWeight(), null,
- copyIfNull);
- batch.setRankOrder((short) 2);
-
- // Manage childs :
- {
- Map<Integer, SortingBatch> batchChilds = getChildsMap(batch, enumeration.PMFM_ID_SORTING_TYPE);
-
- // -----------------------------------------------------------------------------
- // Hors Vrac > Species :
- // -----------------------------------------------------------------------------
- {
- SortingBatch speciesBatch = batchChilds.get(enumeration.QUALITATIVE_ID_SORTING_TYPE_SPECIES);
- if (speciesBatch == null) {
- speciesBatch = SortingBatch.Factory.newInstance();
- if (batch.getChildBatchs() == null) {
- batch.setChildBatchs(Lists.newArrayList((Batch) speciesBatch));
- } else {
- batch.getChildBatchs().add(speciesBatch);
- }
- }
- beanToEntitySortingBatch(target, batch, speciesBatch, recorderDepartmentId,
- enumeration.PMFM_ID_SORTING_TYPE, enumeration.QUALITATIVE_ID_SORTING_TYPE_SPECIES,
- source.getSpeciesTotalUnsortedWeight(), null,
- copyIfNull);
- speciesBatch.setRankOrder((short) 1);
- }
-
- // -----------------------------------------------------------------------------
- // Hors Vrac > Benthos :
- // -----------------------------------------------------------------------------
- {
- SortingBatch benthosBatch = batchChilds.get(enumeration.QUALITATIVE_ID_SORTING_TYPE_SPECIES);
- if (benthosBatch == null) {
- benthosBatch = SortingBatch.Factory.newInstance();
- batch.getChildBatchs().add(benthosBatch);
- }
- beanToEntitySortingBatch(target, batch, benthosBatch, recorderDepartmentId,
- enumeration.PMFM_ID_SORTING_TYPE, enumeration.QUALITATIVE_ID_SORTING_TYPE_BENTHOS,
- source.getBenthosTotalUnsortedWeight(), null,
- copyIfNull);
- benthosBatch.setRankOrder((short) 2);
- }
-
- // TODO : plancton, macro déchet...
- }
-
- }
-
- // -----------------------------------------------------------------------------
- // Unsorted (=rejected)
- // -----------------------------------------------------------------------------
- // Unsorted :
- SortingBatch unsortedBatch = catchBatchChilds.get(enumeration.QUALITATIVE_UNSORTED_ID);
- if (unsortedBatch == null) {
- unsortedBatch = SortingBatch.Factory.newInstance();
- target.getChildBatchs().add(unsortedBatch);
- }
- beanToEntitySortingBatch(target, target, unsortedBatch, recorderDepartmentId,
- enumeration.PMFM_ID_SORTED_UNSORTED, enumeration.QUALITATIVE_UNSORTED_ID,
- source.getCatchTotalRejectedWeight(), null,
- copyIfNull);
- unsortedBatch.setRankOrder((short) 3);
-
- }
-
- protected Map<Integer, SortingBatch> getChildsMap(Batch parentBatch, Integer pmfmId) {
- Map<Integer, SortingBatch> batchByQualitativeValueId = new HashMap<Integer, SortingBatch>();
- if (parentBatch.getChildBatchs() == null) {
- return batchByQualitativeValueId;
- }
- for (Batch childBatch : parentBatch.getChildBatchs()) {
- SortingBatch childSortingBatch = (SortingBatch) childBatch;
- SortingMeasurement sm = catchBatchDao.getSortingMeasurement((SortingBatch) childBatch, pmfmId, null, false);
- if (sm != null && sm.getQualitativeValue() != null && sm.getQualitativeValue().getId() != null) {
- batchByQualitativeValueId.put(sm.getQualitativeValue().getId(), childSortingBatch);
- }
- }
- return batchByQualitativeValueId;
- }
-
- /**
- * Retrieve child batchs if species is "Life" or "No life"
- * (need to retrieve: speciesTotalLivingNotItemizedWeight and speciesTotalInertWeight)
- *
- * @param parentBatch
- * @return
- */
- protected Map<Integer, SortingBatch> getChildAliveNotSortedOrInert(Batch parentBatch) {
- Map<Integer, SortingBatch> batchByQualitativeValueId = new HashMap<Integer, SortingBatch>();
- if (parentBatch.getChildBatchs() == null) {
- return batchByQualitativeValueId;
- }
- for (Batch childBatch : parentBatch.getChildBatchs()) {
- SortingBatch childSortingBatch = (SortingBatch) childBatch;
- if (childSortingBatch.getReferenceTaxon() != null && childSortingBatch.getId().intValue() < 0) {
- if (enumeration.REFERENCE_TAXON_ID_LIFE.equals(childSortingBatch.getId())) {
- batchByQualitativeValueId.put(enumeration.REFERENCE_TAXON_ID_LIFE, childSortingBatch);
- } else if (enumeration.REFERENCE_TAXON_ID_LIFE.equals(childSortingBatch.getId())) {
- batchByQualitativeValueId.put(enumeration.REFERENCE_TAXON_ID_LIFE, childSortingBatch);
- }
- }
- }
- return batchByQualitativeValueId;
- }
-
- protected void beanToEntitySortingBatch(
- fr.ifremer.adagio.core.dao.data.batch.CatchBatch rootBatch,
- fr.ifremer.adagio.core.dao.data.batch.Batch parentBatch,
- fr.ifremer.adagio.core.dao.data.batch.SortingBatch target,
- Integer recorderDepartmentId,
- Integer sortingPmfmId,
- Integer sortingQualitativeValueId,
- Float weight,
- Float sampleWeight,
- boolean copyIfNull) {
-
- // Create lists to store all updates, then remove not updated items
- Set<QuantificationMeasurement> notChangedQuantificationMeasurements = new HashSet<QuantificationMeasurement>();
- if (target.getQuantificationMeasurements() != null) {
- notChangedQuantificationMeasurements.addAll(target.getQuantificationMeasurements());
- }
- Set<SortingMeasurement> notChangedSortingMeasurements = new HashSet<SortingMeasurement>();
- if (target.getSortingMeasurements() != null) {
- notChangedSortingMeasurements.addAll(target.getSortingMeasurements());
- }
-
- // Some mandatory properties :
- target.setQualityFlag(load(QualityFlagImpl.class, enumeration.QUALITY_FLAG_CODE_NOT_QUALIFIED));
- target.setRootBatch(rootBatch);
- target.setParentBatch(parentBatch);
- target.setExhaustiveInventory(true);
-
- // No taxon or taxon group
- target.setReferenceTaxon(null);
- target.setTaxonGroup(null);
-
- // Sorting measurement
- if (copyIfNull && (sortingPmfmId == null || sortingQualitativeValueId == null)) {
- // Nothing to do : will be removed later, using notChangedSortingMeasurements
- } else if (sortingPmfmId != null && sortingQualitativeValueId != null) {
- SortingMeasurement sm = setSortingMeasurement(target, recorderDepartmentId, sortingPmfmId, sortingQualitativeValueId);
- notChangedSortingMeasurements.remove(sm);
- }
-
- // Sampling Ratio
- if (copyIfNull && (sampleWeight == null || weight == null)) {
- target.setSamplingRatio(null);
- target.setSamplingRatioText(null);
- } else if (sampleWeight != null && weight != null) {
- String samplingRatioText = weight + "/" + sampleWeight;
- samplingRatioText = samplingRatioText.replaceAll(",", ".");
- target.setSamplingRatioText(samplingRatioText);
- target.setSamplingRatio(weight / sampleWeight);
- }
-
- // Weight
- if (copyIfNull && (sampleWeight == null && weight == null)) {
- // Nothing to do : will be removed later, using notChangedQuantificationMeasurements
- } else if (sampleWeight != null || weight != null) {
- Float batchReferenceWeight = weight;
- if (batchReferenceWeight == null) {
- batchReferenceWeight = sampleWeight;
- }
- QuantificationMeasurement quantificationMeasurement = catchBatchDao.setQuantificationMeasurement(target,
- enumeration.PMFM_ID_WEIGHT_MEASURED, recorderDepartmentId, batchReferenceWeight, true);
- notChangedQuantificationMeasurements.remove(quantificationMeasurement);
- }
-
- // Removed not changed measurements (in sorting and quantification measurement lists)
- if (target.getQuantificationMeasurements() != null && notChangedQuantificationMeasurements.size() > 0) {
- for (QuantificationMeasurement qm : notChangedQuantificationMeasurements) {
- target.getQuantificationMeasurements().remove(qm);
- }
- }
- if (target.getSortingMeasurements() != null && notChangedSortingMeasurements.size() > 0) {
- for (SortingMeasurement sm : notChangedSortingMeasurements) {
- target.getSortingMeasurements().remove(sm);
- }
- }
- }
-
- protected void beanToEntityReferenceTaxonBatch(
- fr.ifremer.adagio.core.dao.data.batch.CatchBatch rootBatch,
- fr.ifremer.adagio.core.dao.data.batch.Batch parentBatch,
- fr.ifremer.adagio.core.dao.data.batch.SortingBatch target,
- Integer recorderDepartmentId,
- Integer referenceTaxonId,
- Float weight,
- Float sampleWeight,
- boolean copyIfNull) {
-
- // Create lists to store all updates, then remove not updated items
- Set<QuantificationMeasurement> notChangedQuantificationMeasurements = new HashSet<QuantificationMeasurement>();
- if (target.getQuantificationMeasurements() != null) {
- notChangedQuantificationMeasurements.addAll(target.getQuantificationMeasurements());
- }
- Set<SortingMeasurement> notChangedSortingMeasurements = new HashSet<SortingMeasurement>();
- if (target.getSortingMeasurements() != null) {
- notChangedSortingMeasurements.addAll(target.getSortingMeasurements());
- }
-
- // Some mandatory properties :
- target.setQualityFlag(load(QualityFlagImpl.class, enumeration.QUALITY_FLAG_CODE_NOT_QUALIFIED));
- target.setRootBatch(rootBatch);
- target.setParentBatch(parentBatch);
- target.setExhaustiveInventory(true);
-
- // Reference taxon
- target.setReferenceTaxon(load(ReferenceTaxonImpl.class, referenceTaxonId));
- target.setTaxonGroup(null);
-
- // Sampling Ratio
- if (copyIfNull && (sampleWeight == null || weight == null)) {
- target.setSamplingRatio(null);
- target.setSamplingRatioText(null);
- } else if (sampleWeight != null && weight != null) {
- String samplingRatioText = weight + "/" + sampleWeight;
- samplingRatioText = samplingRatioText.replaceAll(",", ".");
- target.setSamplingRatioText(samplingRatioText);
- target.setSamplingRatio(weight / sampleWeight);
- }
-
- // Weight
- if (copyIfNull && (sampleWeight == null && weight == null)) {
- // Nothing to do : will be removed later, using notChangedQuantificationMeasurements
- } else if (sampleWeight != null || weight != null) {
- Float batchReferenceWeight = weight;
- if (batchReferenceWeight == null) {
- batchReferenceWeight = sampleWeight;
- }
- QuantificationMeasurement quantificationMeasurement = catchBatchDao.setQuantificationMeasurement(target,
- enumeration.PMFM_ID_WEIGHT_MEASURED, recorderDepartmentId, batchReferenceWeight, true);
- notChangedQuantificationMeasurements.remove(quantificationMeasurement);
- }
-
- // Removed not changed measurements (in sorting and quantification measurement lists)
- if (target.getQuantificationMeasurements() != null && notChangedQuantificationMeasurements.size() > 0) {
- for (QuantificationMeasurement qm : notChangedQuantificationMeasurements) {
- target.getQuantificationMeasurements().remove(qm);
- }
- }
- if (target.getSortingMeasurements() != null && notChangedSortingMeasurements.size() > 0) {
- for (SortingMeasurement sm : notChangedSortingMeasurements) {
- target.getSortingMeasurements().remove(sm);
- }
- }
- }
-
- protected Integer getRecorderDepartmentId() {
- // TODO BL : voir si on peut récupérer le departement (du 1er saisisseur ?)
- return enumeration.DEPARTMENT_ID_UNKNOWN_RECORDER_DEPARTMENT;
- }
-
- protected void setMeasurement(Measurement measurement, Caracteristic caracteristic, Serializable value) {
- if (caracteristic.getCaracteristicType() == CaracteristicType.TEXT) {
- measurement.setAlphanumericalValue((String) value);
- } else if (caracteristic.getCaracteristicType() == CaracteristicType.NUMBER) {
- measurement.setNumericalValue((Float) value);
- } else if (caracteristic.getCaracteristicType() == CaracteristicType.QUALITATIVE) {
- Integer qvId;
- if (value instanceof CaracteristicQualitativeValue) {
- qvId = Integer.valueOf(((CaracteristicQualitativeValue) value).getId());
- } else if (value instanceof Integer) {
- qvId = (Integer) value;
- }
- // TODO BL : not used ? => to remove
- else {
- qvId = Integer.valueOf(value.toString());
- }
- QualitativeValue qv = load(QualitativeValueImpl.class, qvId);
- measurement.setQualitativeValue(qv);
- }
- }
-
- protected SortingMeasurement setSortingMeasurement(
- SortingBatch sortingBatch, Integer recorderDepartmentId,
- SampleCategoryEnum sampleCategory, Serializable value) {
- Preconditions.checkNotNull(sampleCategory);
- Preconditions.checkNotNull(value);
-
- Integer pmfmId = sampleCategory2PmfmId(sampleCategory);
-
- Caracteristic caracteristic = referentialService.getCaracteristic(pmfmId);
- SortingMeasurement sortingMeasurement = catchBatchDao.getSortingMeasurement(
- sortingBatch, pmfmId, recorderDepartmentId, true);
- setMeasurement(sortingMeasurement, caracteristic, value);
- return sortingMeasurement;
- }
-
- protected SortingMeasurement setSortingMeasurement(
- SortingBatch sortingBatch, Integer recorderDepartmentId,
- Integer pmfmId, Serializable value) {
- Preconditions.checkNotNull(pmfmId);
- Preconditions.checkNotNull(value);
-
- Caracteristic caracteristic = referentialService.getCaracteristic(pmfmId);
- SortingMeasurement sortingMeasurement = catchBatchDao.getSortingMeasurement(
- sortingBatch, pmfmId, recorderDepartmentId, true);
- setMeasurement(sortingMeasurement, caracteristic, value);
- return sortingMeasurement;
- }
-
- protected Integer sampleCategory2PmfmId(SampleCategoryEnum sampleCategory) {
- Integer pmfmId = null;
- if (sampleCategory == SampleCategoryEnum.sortedUnsorted) {
- pmfmId = enumeration.PMFM_ID_SORTED_UNSORTED;
- } else if (sampleCategory == SampleCategoryEnum.size) {
- pmfmId = enumeration.PMFM_ID_SIZE_CATEGORY;
- } else if (sampleCategory == SampleCategoryEnum.maturity) {
- pmfmId = enumeration.PMFM_ID_MATURITY;
- } else if (sampleCategory == SampleCategoryEnum.sex) {
- pmfmId = enumeration.PMFM_ID_SEX;
- } else if (sampleCategory == SampleCategoryEnum.age) {
- pmfmId = enumeration.PMFM_ID_AGE;
- }
- if (pmfmId == null) {
- throw new IllegalArgumentException("Unable to find corresponding PMFM.ID for sampleCategory : " + sampleCategory.name());
- }
- return pmfmId;
- }
-
-}
Added: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceService.java
===================================================================
--- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceService.java (rev 0)
+++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceService.java 2013-03-27 21:49:05 UTC (rev 693)
@@ -0,0 +1,111 @@
+package fr.ifremer.tutti.persistence.service;
+
+/*
+ * #%L
+ * Tutti :: Persistence
+ * $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.TuttiPersistenceServiceImplementor;
+import fr.ifremer.tutti.persistence.entities.data.BatchContainer;
+import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch;
+import fr.ifremer.tutti.persistence.entities.data.SpeciesBatchFrequency;
+import fr.ifremer.tutti.persistence.entities.referential.Species;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.List;
+
+/**
+ * Service to persist *benthos* {@link SpeciesBatch}.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.2
+ */
+@Transactional(readOnly = true)
+public interface BenthosBatchPersistenceService extends TuttiPersistenceServiceImplementor {
+
+ //------------------------------------------------------------------------//
+ //-- Benthos Batch methods --//
+ //------------------------------------------------------------------------//
+
+ /**
+ * Get all root {@link SpeciesBatch} for the given fishing operation.
+ * <p/>
+ * <strong>Note:</strong> All childs of the batch should be loaded here.
+ *
+ *
+ * @param fishingOperationId if of the fishing operation to seek
+ * @return the list of root {@link SpeciesBatch}
+ * @since 1.0
+ */
+ BatchContainer<SpeciesBatch> getRootBenthosBatch(String fishingOperationId);
+
+ @Transactional(readOnly = false)
+ SpeciesBatch createBenthosBatch(SpeciesBatch bean, String parentBatchId);
+
+ @Transactional(readOnly = false)
+ SpeciesBatch saveBenthosBatch(SpeciesBatch bean);
+
+ @Transactional(readOnly = false)
+ void deleteBenthosBatch(String id);
+
+ @Transactional(readOnly = false)
+ void deleteBenthosSubBatch(String id);
+
+ /**
+ * Change the species in the given {@code batchId} and in all his
+ * sub batches.
+ *
+ * @param batchId id of the root Benthos batch to treat
+ * @param species species to affect to all batches
+ */
+ @Transactional(readOnly = false)
+ void changeBenthosBatchSpecies(String batchId, Species species);
+
+ //------------------------------------------------------------------------//
+ //-- SpeciesBatchFrequency methods (for benthos) --//
+ //------------------------------------------------------------------------//
+
+ /**
+ * Get all frequencies for the given species batch.
+ *
+ * @param benthosBatchId the id of the species batch to seek.
+ * @return the list of frequencies for the given benthos batch id
+ * @since 1.0
+ */
+ List<SpeciesBatchFrequency> getAllBenthosBatchFrequency(String benthosBatchId);
+
+ /**
+ * Save all given {@link SpeciesBatchFrequency} into the given
+ * {@code benthosBatchId}. If some are not existing then creates them.
+ * <p/>
+ * <strong>Note:</strong> This will as a side effect remove all previous
+ * frequency for this benthos batch.
+ *
+ * @param benthosBatchId id of the {@link SpeciesBatch} to use
+ * @param frequencies list of frequencies to create or update
+ * @return the persisted list of frequencies
+ * @since 1.0
+ */
+ @Transactional(readOnly = false)
+ List<SpeciesBatchFrequency> saveBenthosBatchFrequency(String benthosBatchId,
+ List<SpeciesBatchFrequency> frequencies);
+}
Property changes on: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceService.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceServiceImpl.java
===================================================================
--- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceServiceImpl.java (rev 0)
+++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceServiceImpl.java 2013-03-27 21:49:05 UTC (rev 693)
@@ -0,0 +1,334 @@
+package fr.ifremer.tutti.persistence.service;
+
+/*
+ * #%L
+ * Tutti :: Persistence
+ * $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.dao.data.batch.Batch;
+import fr.ifremer.adagio.core.dao.data.batch.CatchBatchExtendDao;
+import fr.ifremer.adagio.core.dao.data.batch.SortingBatch;
+import fr.ifremer.tutti.persistence.entities.data.BatchContainer;
+import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch;
+import fr.ifremer.tutti.persistence.entities.data.SpeciesBatchFrequency;
+import fr.ifremer.tutti.persistence.entities.referential.Species;
+import fr.ifremer.tutti.persistence.service.batch.BatchPersistenceHelper;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.hibernate.FlushMode;
+import org.springframework.dao.DataIntegrityViolationException;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * Default implementation of {@link BenthosBatchPersistenceService}.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.2
+ */
+@Service("benthosBatchPersistenceService")
+public class BenthosBatchPersistenceServiceImpl extends AbstractPersistenceService
+ implements BenthosBatchPersistenceService {
+
+ /** Logger. */
+ private static final Log log =
+ LogFactory.getLog(BenthosBatchPersistenceServiceImpl.class);
+
+ @Resource(name = "referentialPersistenceService")
+ protected ReferentialPersistenceService referentialService;
+
+ @Resource(name = "catchBatchDao")
+ protected CatchBatchExtendDao catchBatchDao;
+
+ @Resource(name = "batchPersistenceHelper")
+ protected BatchPersistenceHelper batchHelper;
+
+ //------------------------------------------------------------------------//
+ //-- Benthos Batch methods --//
+ //------------------------------------------------------------------------//
+
+ @Override
+ public BatchContainer<SpeciesBatch> getRootBenthosBatch(String fishingOperationId) {
+ Preconditions.checkNotNull(fishingOperationId);
+
+ // Load batch tree
+ Integer catchBatchId = catchBatchDao.getIdByFishingOperationId(Integer.valueOf(fishingOperationId));
+ Preconditions.checkNotNull(catchBatchId);
+
+ fr.ifremer.adagio.core.dao.data.batch.CatchBatch catchBatch = catchBatchDao.loadFullTree(catchBatchId);
+ Preconditions.checkNotNull(catchBatch);
+
+ Collection<Batch> catchBatchChils = catchBatch.getChildBatchs();
+
+ // Vrac / Benthos
+ SortingBatch vracSpeciesBatch = catchBatchDao.getSortingBatch(catchBatchChils,
+ "pmfmId", enumeration.PMFM_ID_SORTED_UNSORTED, enumeration.QUALITATIVE_VRAC_ID,
+ "pmfmId", enumeration.PMFM_ID_SORTING_TYPE, enumeration.QUALITATIVE_ID_SORTING_TYPE_BENTHOS);
+
+ BatchContainer<SpeciesBatch> result = new BatchContainer<SpeciesBatch>();
+ result.setId(vracSpeciesBatch.getId());
+
+ for (Batch batch1 : vracSpeciesBatch.getChildBatchs()) {
+ SortingBatch source = (SortingBatch) batch1;
+
+ // evict some special batches : Life (or Biota) and Inert
+ if (source.getReferenceTaxon() != null
+ && !enumeration.REFERENCE_TAXON_ID_LIFE.equals(source.getReferenceTaxon().getId())
+ && !enumeration.REFERENCE_TAXON_ID_INERT.equals(source.getReferenceTaxon().getId())) {
+
+ SpeciesBatch target = new SpeciesBatch();
+ batchHelper.entityToSpeciesBatch(source, target);
+ result.addChildren(target);
+ if (log.isInfoEnabled()) {
+ log.info("Loaded CatchBatch Vrac > Benthos > " + target.getSpecies().getReferenceTaxonId() + " : " + target.getId());
+ }
+ }
+ }
+
+ // Hors-Vrac / Benthos
+ SortingBatch horsVracSpeciesBatch = catchBatchDao.getSortingBatch(catchBatchChils,
+ "pmfmId", enumeration.PMFM_ID_SORTED_UNSORTED, enumeration.QUALITATIVE_HORS_VRAC_ID,
+ "pmfmId", enumeration.PMFM_ID_SORTING_TYPE, enumeration.QUALITATIVE_ID_SORTING_TYPE_BENTHOS);
+ if (horsVracSpeciesBatch != null) {
+ for (Batch batch : horsVracSpeciesBatch.getChildBatchs()) {
+
+ SpeciesBatch target = new SpeciesBatch();
+ batchHelper.entityToSpeciesBatch((SortingBatch) batch, target);
+ result.addChildren(target);
+ if (log.isInfoEnabled()) {
+ log.info("Loaded CatchBatch Hors Vrac > Benthos > " + target.getSpecies().getReferenceTaxonId() + " : " + target.getId());
+ }
+ }
+ }
+ return result;
+ }
+
+ @Override
+ public SpeciesBatch createBenthosBatch(SpeciesBatch bean,
+ String parentBatchId) {
+ Preconditions.checkNotNull(bean);
+ Preconditions.checkArgument(bean.getId() == null);
+ Preconditions.checkNotNull(bean.getSpecies());
+ Preconditions.checkNotNull(bean.getSpecies().getId());
+ Preconditions.checkNotNull(bean.getFishingOperation());
+ Preconditions.checkNotNull(bean.getFishingOperation().getId());
+
+ getCurrentSession().setFlushMode(FlushMode.COMMIT);
+
+ // Load full batch tree
+ Integer catchBatchId = catchBatchDao.getIdByFishingOperationId(bean.getFishingOperation().getIdAsInt());
+ fr.ifremer.adagio.core.dao.data.batch.CatchBatch catchBatch = catchBatchDao.loadFullTree(catchBatchId);
+
+ SortingBatch batch = SortingBatch.Factory.newInstance();
+ benthosBatchToEntity(bean, batch, parentBatchId, catchBatch);
+ batch = catchBatchDao.createSortingBatch(batch, catchBatch);
+
+ bean.setId(batch.getId());
+
+ getCurrentSession().flush();
+
+ return bean;
+ }
+
+ @Override
+ public SpeciesBatch saveBenthosBatch(SpeciesBatch bean) {
+ Preconditions.checkNotNull(bean);
+ Preconditions.checkNotNull(bean.getId());
+
+ // Load batch tree
+ Integer catchBatchId = catchBatchDao.getIdBySortingBatchId(bean.getIdAsInt());
+ Preconditions.checkNotNull(catchBatchId);
+
+ fr.ifremer.adagio.core.dao.data.batch.CatchBatch catchBatch = catchBatchDao.loadFullTree(catchBatchId);
+ Preconditions.checkNotNull(catchBatch);
+
+ getCurrentSession().setFlushMode(FlushMode.COMMIT);
+
+ SortingBatch batch = catchBatchDao.getSortingBatchById(catchBatch, bean.getIdAsInt());
+ String parentBatchId = null;
+ if (bean.getParentBatch() != null) {
+ parentBatchId = bean.getParentBatch().getId();
+ }
+ benthosBatchToEntity(bean, batch, parentBatchId, catchBatch);
+ catchBatchDao.updateSortingBatch(batch, catchBatch);
+ getCurrentSession().flush();
+
+ return bean;
+ }
+
+ @Override
+ public void deleteBenthosBatch(String id) {
+ Preconditions.checkNotNull(id);
+
+ getCurrentSession().setFlushMode(FlushMode.COMMIT);
+
+ catchBatchDao.removeWithChildren(Integer.valueOf(id));
+
+ getCurrentSession().flush();
+ }
+
+ @Override
+ public void deleteBenthosSubBatch(String id) {
+ Preconditions.checkNotNull(id);
+ deleteBenthosBatch(id);
+ }
+
+ @Override
+ public void changeBenthosBatchSpecies(String batchId, Species species) {
+
+ Preconditions.checkNotNull(batchId);
+ Preconditions.checkNotNull(species);
+ Preconditions.checkNotNull(species.getReferenceTaxonId());
+
+ catchBatchDao.setSortingBatchReferenceTaxon(batchId, species.getReferenceTaxonId());
+ }
+
+ //------------------------------------------------------------------------//
+ //-- SpeciesBatchFrequency methods (for benthos) --//
+ //------------------------------------------------------------------------//
+
+ @Override
+ public List<SpeciesBatchFrequency> getAllBenthosBatchFrequency(String benthosBatchId) {
+ List<SpeciesBatchFrequency> results = Lists.newArrayList();
+
+ Integer catchBatchId = catchBatchDao.getIdBySortingBatchId(Integer.valueOf(benthosBatchId));
+ if (catchBatchId == null) {
+ return results;
+ }
+
+ fr.ifremer.adagio.core.dao.data.batch.CatchBatch catchBatch = catchBatchDao.loadFullTree(catchBatchId);
+
+ SortingBatch sortingBatch = catchBatchDao.getSortingBatchById(catchBatch, Integer.valueOf(benthosBatchId));
+
+ for (Batch batch : sortingBatch.getChildBatchs()) {
+ SortingBatch source = (SortingBatch) batch;
+ SpeciesBatchFrequency target = new SpeciesBatchFrequency();
+
+ batchHelper.entityToSpeciesBatchFrequency(source, target);
+ results.add(target);
+ }
+ return Collections.unmodifiableList(results);
+ }
+
+ @Override
+ public List<SpeciesBatchFrequency> saveBenthosBatchFrequency(String benthosBatchId,
+ List<SpeciesBatchFrequency> frequencies) {
+ Preconditions.checkNotNull(benthosBatchId);
+ Preconditions.checkNotNull(frequencies);
+
+ // Check that all frequencies have the same length PMFM (before doing any db call)
+ String pmfmId = null;
+ for (SpeciesBatchFrequency source : frequencies) {
+
+ if (pmfmId == null) {
+ pmfmId = source.getLengthStepCaracteristic().getId();
+ } else if (!pmfmId.equals(source.getLengthStepCaracteristic().getId())) {
+ throw new DataIntegrityViolationException("Batch frequencies under one Speciesbatch must have all the same lengthStepCaracteristic");
+ }
+ }
+
+ getCurrentSession().setFlushMode(FlushMode.COMMIT);
+
+ Integer sortingBatchId = Integer.valueOf(benthosBatchId);
+ Integer catchBatchId = catchBatchDao.getIdBySortingBatchId(sortingBatchId);
+ fr.ifremer.adagio.core.dao.data.batch.CatchBatch catchBatch = catchBatchDao.loadFullTree(catchBatchId);
+
+ if (catchBatch == null) {
+ return frequencies;
+ }
+
+ // Retrieve parent
+ SortingBatch parentBatch = catchBatchDao.getSortingBatchById(catchBatch, sortingBatchId);
+
+ // Remember child ids, to remove unchanged item (see at bottom in this method)
+ List<Integer> notUpdatedChildIds = Lists.newArrayList();
+ for (Batch batch : parentBatch.getChildBatchs()) {
+ SortingBatch sortingBatch = (SortingBatch) batch;
+ notUpdatedChildIds.add(sortingBatch.getId());
+ }
+
+ short rankOrder = 0;
+ List<SortingBatch> batchsToUpdate = Lists.newArrayList();
+ for (SpeciesBatchFrequency source : frequencies) {
+ rankOrder++;
+
+ // Not existing batch
+ SortingBatch target;
+ if (source.getId() == null) {
+ target = SortingBatch.Factory.newInstance();
+
+ // Fill the sorting batch from the source
+ batchHelper.speciesBatchFrequencyToEntity(source, target, parentBatch, rankOrder);
+
+ // Create the targeted batch, then update the source id
+ catchBatchDao.createSortingBatch(target, catchBatch);
+ source.setId(target.getId());
+ }
+
+ // Existing batch
+ else {
+ target = catchBatchDao.getSortingBatchById(catchBatch, source.getIdAsInt());
+
+ // Fill the sorting batch from the source
+ batchHelper.speciesBatchFrequencyToEntity(source, target, parentBatch, rankOrder);
+
+ // Add the batch into a list (will be update later, using this list)
+ batchsToUpdate.add(target);
+
+ notUpdatedChildIds.remove(target.getId());
+ }
+ }
+
+ // If some batchs need to be update, do it
+ if (batchsToUpdate.size() > 0) {
+ catchBatchDao.updateSortingBatch(batchsToUpdate, catchBatch);
+ }
+
+ if (notUpdatedChildIds.size() > 0) {
+ for (Integer batchId : notUpdatedChildIds) {
+ catchBatchDao.removeWithChildren(batchId, catchBatch);
+ }
+ }
+
+ getCurrentSession().flush();
+
+ return Collections.unmodifiableList(frequencies);
+ }
+
+
+ //------------------------------------------------------------------------//
+ //-- Internal methods --//
+ //------------------------------------------------------------------------//
+
+ protected void benthosBatchToEntity(SpeciesBatch source,
+ SortingBatch target,
+ String parentBatchId,
+ fr.ifremer.adagio.core.dao.data.batch.CatchBatch catchBatch) {
+ batchHelper.speciesBatchToEntity(source, target, parentBatchId, catchBatch, enumeration.QUALITATIVE_ID_SORTING_TYPE_BENTHOS);
+ }
+}
Property changes on: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceServiceImpl.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Copied: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/CatchBatchPersistenceService.java (from rev 684, trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/BatchPersistenceService.java)
===================================================================
--- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/CatchBatchPersistenceService.java (rev 0)
+++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/CatchBatchPersistenceService.java 2013-03-27 21:49:05 UTC (rev 693)
@@ -0,0 +1,67 @@
+package fr.ifremer.tutti.persistence.service;
+
+/*
+ * #%L
+ * Tutti :: Persistence
+ * $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.adagio.core.dao.data.batch.validator.CatchBatchValidationException;
+import fr.ifremer.tutti.persistence.TuttiPersistenceServiceImplementor;
+import fr.ifremer.tutti.persistence.entities.data.CatchBatch;
+import org.springframework.transaction.annotation.Transactional;
+
+@Transactional(readOnly = true)
+public interface CatchBatchPersistenceService extends TuttiPersistenceServiceImplementor {
+
+ //------------------------------------------------------------------------//
+ //-- CatchBatch methods --//
+ //------------------------------------------------------------------------//
+
+ /**
+ * Get the catchBatch from the fishing Operation id.
+ *
+ * @param fishingOperationId id of the fihsing operation
+ * @return found catchBatch
+ * @throws CatchBatchValidationException
+ */
+ CatchBatch getCatchBatchFromFishingOperation(String fishingOperationId) throws CatchBatchValidationException;
+
+ /**
+ * Create the given CatchBatch and return it.
+ *
+ * @param bean catchBatch to create
+ * @return created catchBatch
+ */
+ @Transactional(readOnly = false)
+ CatchBatch createCatchBatch(CatchBatch bean);
+
+ /**
+ * Save the given catchBatch and return it.
+ *
+ * @param bean batch to save
+ * @return the saved catchBatch
+ */
+ @Transactional(readOnly = false)
+ CatchBatch saveCatchBatch(CatchBatch bean);
+
+}
\ No newline at end of file
Copied: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/CatchBatchPersistenceServiceImpl.java (from rev 684, trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/BatchPersistenceServiceImpl.java)
===================================================================
--- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/CatchBatchPersistenceServiceImpl.java (rev 0)
+++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/CatchBatchPersistenceServiceImpl.java 2013-03-27 21:49:05 UTC (rev 693)
@@ -0,0 +1,686 @@
+package fr.ifremer.tutti.persistence.service;
+
+/*
+ * #%L
+ * Tutti :: Persistence
+ * $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 com.google.common.collect.Maps;
+import com.google.common.collect.Sets;
+import fr.ifremer.adagio.core.dao.data.batch.Batch;
+import fr.ifremer.adagio.core.dao.data.batch.CatchBatchExtendDao;
+import fr.ifremer.adagio.core.dao.data.batch.SortingBatch;
+import fr.ifremer.adagio.core.dao.data.batch.validator.CatchBatchValidationException;
+import fr.ifremer.adagio.core.dao.data.batch.validator.CatchBatchValidator;
+import fr.ifremer.adagio.core.dao.data.measure.QuantificationMeasurement;
+import fr.ifremer.adagio.core.dao.data.measure.SortingMeasurement;
+import fr.ifremer.adagio.core.dao.data.operation.FishingOperationImpl;
+import fr.ifremer.adagio.core.dao.referential.QualityFlagImpl;
+import fr.ifremer.adagio.core.dao.referential.taxon.ReferenceTaxonImpl;
+import fr.ifremer.adagio.core.dao.technical.synchronization.SynchronizationStatus;
+import fr.ifremer.tutti.persistence.entities.data.CatchBatch;
+import fr.ifremer.tutti.persistence.service.batch.BatchPersistenceHelper;
+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.dao.DataRetrievalFailureException;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.util.Collection;
+import java.util.Map;
+import java.util.Set;
+
+@Service("batchPersistenceService")
+public class CatchBatchPersistenceServiceImpl
+ extends AbstractPersistenceService implements CatchBatchPersistenceService {
+
+ /** Logger. */
+ private static final Log log =
+ LogFactory.getLog(CatchBatchPersistenceServiceImpl.class);
+
+ @Resource(name = "referentialPersistenceService")
+ protected ReferentialPersistenceService referentialService;
+
+ @Resource(name = "catchBatchDao")
+ protected CatchBatchExtendDao catchBatchDao;
+
+ @Resource(name = "scientificCruiseCatchBatchValidator")
+ protected CatchBatchValidator catchBatchValidator;
+
+ @Resource(name = "batchPersistenceHelper")
+ protected BatchPersistenceHelper batchHelper;
+
+ @Override
+ public void init() {
+ super.init();
+ catchBatchDao.registerCatchBatchValidator(catchBatchValidator);
+ }
+
+ @Override
+ public void close() {
+ catchBatchDao.unregisterCatchBatchValidator(catchBatchValidator);
+ super.close();
+ }
+
+ //------------------------------------------------------------------------//
+ //-- CatchBatch methods --//
+ //------------------------------------------------------------------------//
+
+ @Override
+ public CatchBatch getCatchBatchFromFishingOperation(String fishingOperationId) throws CatchBatchValidationException {
+ Preconditions.checkNotNull(fishingOperationId);
+
+ Integer catchBatchId = catchBatchDao.getIdByFishingOperationId(Integer.valueOf(fishingOperationId));
+ Preconditions.checkNotNull(catchBatchId);
+
+ // wenever want to repair anything from Tutti
+ fr.ifremer.adagio.core.dao.data.batch.CatchBatch source = catchBatchDao.loadFullTree(catchBatchId, true, false);
+
+ CatchBatch result = new CatchBatch();
+ result.setId(source.getId());
+ result.setCatchTotalWeight(source.getWeight());
+
+ if (log.isInfoEnabled()) {
+ log.info("Loaded CatchBatch: " + result.getId());
+ }
+
+ // Vrac
+ SortingBatch vracBatch = catchBatchDao.getSortingBatch(source.getChildBatchs(),
+ "pmfmId", enumeration.PMFM_ID_SORTED_UNSORTED, enumeration.QUALITATIVE_VRAC_ID);
+ if (log.isInfoEnabled()) {
+ log.info("Loaded CatchBatch Vrac: " + vracBatch.getId());
+ }
+ result.setCatchTotalSortedCarousselWeight(vracBatch.getWeight());
+ result.setCatchTotalSortedTremisWeight(vracBatch.getWeightBeforeSampling());
+ {
+ // Vrac > Species
+ SortingBatch speciesBatch = catchBatchDao.getSortingBatch(vracBatch.getChildBatchs(),
+ "pmfmId", enumeration.PMFM_ID_SORTING_TYPE, enumeration.QUALITATIVE_ID_SORTING_TYPE_SPECIES);
+
+ if (log.isInfoEnabled()) {
+ log.info("Loaded CatchBatch Vrac > Species : " + speciesBatch.getId());
+ }
+
+ result.setSpeciesTotalSampleSortedWeight(speciesBatch.getWeight());
+ result.setSpeciesTotalSortedWeight(speciesBatch.getWeightBeforeSampling());
+
+ {
+ // Vrac > Species > Inert
+ SortingBatch inertBatch = catchBatchDao.getSortingBatch(speciesBatch.getChildBatchs(),
+ "referenceTaxonId", enumeration.REFERENCE_TAXON_ID_INERT);
+
+ if (log.isInfoEnabled()) {
+ log.info("Loaded CatchBatch Vrac > Species > Inert: " + inertBatch.getId());
+ }
+ if (inertBatch != null) {
+ result.setSpeciesTotalInertWeight(inertBatch.getWeight());
+ }
+
+ // Vrac > Species > Alive no itemized
+ SortingBatch livingNotItemizedBatch = catchBatchDao.getSortingBatch(speciesBatch.getChildBatchs(),
+ "referenceTaxonId", enumeration.REFERENCE_TAXON_ID_LIFE);
+ if (log.isInfoEnabled()) {
+ log.info("Loaded CatchBatch Vrac > Species > Alive not itemized: " + livingNotItemizedBatch.getId());
+ }
+ if (livingNotItemizedBatch != null) {
+ result.setSpeciesTotalLivingNotItemizedWeight(livingNotItemizedBatch.getWeight());
+ }
+ }
+
+ // Vrac > Benthos
+ SortingBatch benthosBatch = catchBatchDao.getSortingBatch(vracBatch.getChildBatchs(),
+ "pmfmId", enumeration.PMFM_ID_SORTING_TYPE, enumeration.QUALITATIVE_ID_SORTING_TYPE_BENTHOS);
+
+ if (log.isInfoEnabled()) {
+ log.info("Loaded CatchBatch Vrac > Benthos: " + benthosBatch.getId());
+ }
+
+ result.setBenthosTotalSampleSortedWeight(benthosBatch.getWeight());
+ result.setBenthosTotalSortedWeight(benthosBatch.getWeightBeforeSampling());
+
+ {
+ // Vrac > Benthos > Inert
+ SortingBatch inertBatch = catchBatchDao.getSortingBatch(benthosBatch.getChildBatchs(),
+ "referenceTaxonId", enumeration.REFERENCE_TAXON_ID_INERT);
+ if (log.isInfoEnabled()) {
+ log.info("Loaded CatchBatch Vrac > Benthos > Inert: " + inertBatch.getId());
+ }
+ if (inertBatch != null) {
+ result.setBenthosTotalInertWeight(inertBatch.getWeight());
+ }
+
+ // Vrac > Benthos > Alive no itemized
+ SortingBatch livingNotItemizedBatch = catchBatchDao.getSortingBatch(benthosBatch.getChildBatchs(),
+ "referenceTaxonId", enumeration.REFERENCE_TAXON_ID_LIFE);
+ if (log.isInfoEnabled()) {
+ log.info("Loaded CatchBatch Vrac > Benthos > Alive not itemized: " + livingNotItemizedBatch.getId());
+ }
+ if (livingNotItemizedBatch != null) {
+ result.setBenthosTotalLivingNotItemizedWeight(livingNotItemizedBatch.getWeight());
+ }
+ }
+
+ // TODO : Plancton...
+ }
+
+ // Hors Vrac
+ SortingBatch horsVracBatch = catchBatchDao.getSortingBatch(source.getChildBatchs(),
+ "pmfmId", enumeration.PMFM_ID_SORTED_UNSORTED, enumeration.QUALITATIVE_HORS_VRAC_ID);
+ if (log.isInfoEnabled()) {
+ log.info("Loaded CatchBatch Hors Vrac: " + horsVracBatch.getId());
+ }
+ if (horsVracBatch != null) {
+ result.setCatchTotalUnsortedWeight(horsVracBatch.getWeight());
+ {
+ // Hors Vrac > Species
+ SortingBatch speciesBatch = catchBatchDao.getSortingBatch(horsVracBatch.getChildBatchs(),
+ "pmfmId", enumeration.PMFM_ID_SORTING_TYPE, enumeration.QUALITATIVE_ID_SORTING_TYPE_SPECIES);
+
+ if (speciesBatch != null) {
+ if (log.isInfoEnabled()) {
+ log.info("Loaded CatchBatch Hors Vrac> Species: " + speciesBatch.getId());
+ }
+ result.setSpeciesTotalUnsortedWeight(speciesBatch.getWeight());
+ }
+
+ // Hors Vrac > Benthos
+ SortingBatch benthosBatch = catchBatchDao.getSortingBatch(horsVracBatch.getChildBatchs(),
+ "pmfmId", enumeration.PMFM_ID_SORTING_TYPE, enumeration.QUALITATIVE_ID_SORTING_TYPE_BENTHOS);
+
+
+ if (benthosBatch != null) {
+ if (log.isInfoEnabled()) {
+ log.info("Loaded CatchBatch Hors Vrac> Benthos: " + benthosBatch.getId());
+ }
+ result.setBenthosTotalUnsortedWeight(benthosBatch.getWeight());
+ }
+
+ // TODO : Plancton...
+ }
+ }
+
+ // Non trié
+ SortingBatch unsortedBatch = catchBatchDao.getSortingBatch(source.getChildBatchs(),
+ "pmfmId", enumeration.PMFM_ID_SORTED_UNSORTED, enumeration.QUALITATIVE_UNSORTED_ID);
+ if (log.isInfoEnabled()) {
+ log.info("Loaded CatchBatch Unsorted: " + unsortedBatch.getId());
+ }
+ if (unsortedBatch != null) {
+ result.setCatchTotalRejectedWeight(unsortedBatch.getWeight());
+ }
+
+ return result;
+ }
+
+ @Override
+ public CatchBatch createCatchBatch(CatchBatch bean) {
+ Preconditions.checkNotNull(bean);
+ Preconditions.checkArgument(bean.getId() == null);
+ Preconditions.checkNotNull(bean.getFishingOperation());
+ Preconditions.checkNotNull(bean.getFishingOperation().getId());
+
+ fr.ifremer.adagio.core.dao.data.batch.CatchBatch catchBatch = fr.ifremer.adagio.core.dao.data.batch.CatchBatch.Factory.newInstance();
+ catchBatchToEntity(bean, catchBatch);
+ catchBatch = catchBatchDao.create(catchBatch);
+ bean.setId(catchBatch.getId());
+
+ // Link to fishing operation
+ getCurrentSession().flush();
+ Integer fishingOperationId = bean.getFishingOperation().getIdAsInt();
+ int rowUpdated = queryUpdate("updateFishingOperationCatchBatch",
+ "fishingOperationId", IntegerType.INSTANCE, fishingOperationId,
+ "catchBatchId", IntegerType.INSTANCE, catchBatch.getId());
+ if (rowUpdated == 0) {
+ throw new DataIntegrityViolationException("Could not attach catch batch to the given operation : operation was not found.");
+ }
+
+ return bean;
+ }
+
+ @Override
+ public CatchBatch saveCatchBatch(CatchBatch bean) {
+
+ Preconditions.checkNotNull(bean);
+ Preconditions.checkNotNull(bean.getId());
+ Preconditions.checkNotNull(bean.getFishingOperation());
+ Preconditions.checkNotNull(bean.getFishingOperation().getId());
+
+ getCurrentSession().enableFetchProfile("batch-with-childs");
+ getCurrentSession().setFlushMode(FlushMode.COMMIT);
+ fr.ifremer.adagio.core.dao.data.batch.CatchBatch catchBatch = catchBatchDao.load(bean.getIdAsInt());
+ if (catchBatch == null) {
+ throw new DataRetrievalFailureException("Could not retrieve catch batch with id=" + bean.getId());
+ }
+
+ catchBatchToEntity(bean, catchBatch);
+ catchBatchDao.update(catchBatch);
+ getCurrentSession().flush();
+
+ return bean;
+ }
+
+ //------------------------------------------------------------------------//
+ //-- Internal methods --//
+ //------------------------------------------------------------------------//
+
+ protected void catchBatchToEntity(CatchBatch source,
+ fr.ifremer.adagio.core.dao.data.batch.CatchBatch target) {
+ Preconditions.checkNotNull(source.getFishingOperation());
+ Preconditions.checkNotNull(source.getFishingOperation().getId());
+
+ // Retrieve recorder department
+ Integer recorderDepartmentId = getRecorderDepartmentId();
+
+ // First initialization (when created)
+ Integer fishingOperationId = source.getFishingOperation().getIdAsInt();
+ target.setFishingOperation(load(FishingOperationImpl.class, fishingOperationId));
+
+ target.setQualityFlag(load(QualityFlagImpl.class, enumeration.QUALITY_FLAG_CODE_NOT_QUALIFIED));
+ target.setRankOrder((short) 1);
+ target.setSynchronizationStatus(SynchronizationStatus.DIRTY.getValue());
+
+ // Create lists to store all updates, then remove not updated items
+ Collection<QuantificationMeasurement> quantificationMeasurements = target.getQuantificationMeasurements();
+ Set<QuantificationMeasurement> notChangedQuantificationMeasurements = Sets.newHashSet();
+ if (quantificationMeasurements != null) {
+ notChangedQuantificationMeasurements.addAll(quantificationMeasurements);
+ }
+
+ // Total Weight
+ if (source.getCatchTotalWeight() == null) {
+ // Nothing to do : will be removed later, using notChangedQuantificationMeasurements
+ } else {
+ QuantificationMeasurement quantificationMeasurement = catchBatchDao.setQuantificationMeasurement(target,
+ enumeration.PMFM_ID_WEIGHT_MEASURED, recorderDepartmentId, source.getCatchTotalWeight(), true);
+ notChangedQuantificationMeasurements.remove(quantificationMeasurement);
+ }
+
+ // Removed not changed measurements (in sorting and quantification measurement lists)
+ if (quantificationMeasurements != null) {
+ quantificationMeasurements.removeAll(notChangedQuantificationMeasurements);
+ }
+// if (target.getQuantificationMeasurements() != null && notChangedQuantificationMeasurements.size() > 0) {
+// for (QuantificationMeasurement qm : notChangedQuantificationMeasurements) {
+// target.getQuantificationMeasurements().remove(qm);
+// }
+// }
+ Map<Integer, SortingBatch> catchBatchChilds = getChildsMap(target, enumeration.PMFM_ID_SORTED_UNSORTED);
+
+ // -----------------------------------------------------------------------------
+ // Vrac
+ // -----------------------------------------------------------------------------
+ {
+ SortingBatch batch = catchBatchChilds.get(enumeration.QUALITATIVE_VRAC_ID);
+ if (batch == null) {
+ batch = SortingBatch.Factory.newInstance();
+ target.getChildBatchs().add(batch);
+ }
+ beanToEntitySortingBatch(target, target, batch, recorderDepartmentId,
+ enumeration.PMFM_ID_SORTED_UNSORTED, enumeration.QUALITATIVE_VRAC_ID,
+ source.getCatchTotalSortedCarousselWeight(), source.getCatchTotalSortedTremisWeight());
+ batch.setRankOrder((short) 1);
+
+ // Manage childs :
+ {
+ if (batch.getChildBatchs() == null) {
+ batch.setChildBatchs(Lists.<Batch>newArrayList());
+ }
+
+ Map<Integer, SortingBatch> batchChilds = getChildsMap(batch, enumeration.PMFM_ID_SORTING_TYPE);
+
+ // -----------------------------------------------------------------------------
+ // Vrac / Species
+ // -----------------------------------------------------------------------------
+ SortingBatch speciesBatch = batchChilds.get(enumeration.QUALITATIVE_ID_SORTING_TYPE_SPECIES);
+
+ if (speciesBatch == null) {
+ speciesBatch = SortingBatch.Factory.newInstance();
+ batch.getChildBatchs().add(speciesBatch);
+ }
+ beanToEntitySortingBatch(target, batch, speciesBatch, recorderDepartmentId,
+ enumeration.PMFM_ID_SORTING_TYPE, enumeration.QUALITATIVE_ID_SORTING_TYPE_SPECIES,
+ source.getSpeciesTotalSampleSortedWeight(), source.getSpeciesTotalSortedWeight());
+ speciesBatch.setRankOrder((short) 1);
+
+ {
+ if (speciesBatch.getChildBatchs() == null) {
+ speciesBatch.setChildBatchs(Lists.<Batch>newArrayList());
+ }
+ // -----------------------------------------------------------------------------
+ // Vrac / Species / Alive not itemized
+ // -----------------------------------------------------------------------------
+
+ SortingBatch aliveNotItemizedBatch = catchBatchDao.getSortingBatch(speciesBatch.getChildBatchs(), "referenceTaxonId", enumeration.REFERENCE_TAXON_ID_LIFE);
+ if (aliveNotItemizedBatch == null) {
+ aliveNotItemizedBatch = SortingBatch.Factory.newInstance();
+ speciesBatch.getChildBatchs().add(aliveNotItemizedBatch);
+ }
+ beanToEntityReferenceTaxonBatch(target, speciesBatch, aliveNotItemizedBatch, recorderDepartmentId,
+ enumeration.REFERENCE_TAXON_ID_LIFE,
+ source.getSpeciesTotalLivingNotItemizedWeight(), null);
+ aliveNotItemizedBatch.setRankOrder((short) 1);
+
+ // -----------------------------------------------------------------------------
+ // Vrac / Species / Inert (not alive)
+ // -----------------------------------------------------------------------------
+ SortingBatch inertBatch = catchBatchDao.getSortingBatch(speciesBatch.getChildBatchs(), "referenceTaxonId", enumeration.REFERENCE_TAXON_ID_INERT);
+ if (inertBatch == null) {
+ inertBatch = SortingBatch.Factory.newInstance();
+ speciesBatch.getChildBatchs().add(inertBatch);
+ }
+ beanToEntityReferenceTaxonBatch(target, speciesBatch, inertBatch, recorderDepartmentId,
+ enumeration.REFERENCE_TAXON_ID_INERT,
+ source.getSpeciesTotalInertWeight(), null);
+ inertBatch.setRankOrder((short) 2);
+ }
+
+ // -----------------------------------------------------------------------------
+ // Vrac > Benthos
+ // -----------------------------------------------------------------------------
+
+ SortingBatch benthosBatch = batchChilds.get(enumeration.QUALITATIVE_ID_SORTING_TYPE_BENTHOS);
+ if (benthosBatch == null) {
+ benthosBatch = SortingBatch.Factory.newInstance();
+ batch.getChildBatchs().add(benthosBatch);
+ }
+ beanToEntitySortingBatch(target, batch, benthosBatch, recorderDepartmentId,
+ enumeration.PMFM_ID_SORTING_TYPE, enumeration.QUALITATIVE_ID_SORTING_TYPE_BENTHOS,
+ source.getBenthosTotalSampleSortedWeight(), source.getBenthosTotalSortedWeight());
+ benthosBatch.setRankOrder((short) 2);
+
+ {
+
+ if (benthosBatch.getChildBatchs() == null) {
+ benthosBatch.setChildBatchs(Lists.<Batch>newArrayList());
+ }
+
+ // -----------------------------------------------------------------------------
+ // Vrac / Benthos / Alive not itemized
+ // -----------------------------------------------------------------------------
+
+ SortingBatch aliveNotItemizedBatch = catchBatchDao.getSortingBatch(benthosBatch.getChildBatchs(), "referenceTaxonId", enumeration.REFERENCE_TAXON_ID_LIFE);
+ if (aliveNotItemizedBatch == null) {
+ aliveNotItemizedBatch = SortingBatch.Factory.newInstance();
+ benthosBatch.getChildBatchs().add(aliveNotItemizedBatch);
+ }
+ beanToEntityReferenceTaxonBatch(target, benthosBatch, aliveNotItemizedBatch, recorderDepartmentId,
+ enumeration.REFERENCE_TAXON_ID_LIFE,
+ source.getBenthosTotalLivingNotItemizedWeight(), null);
+ aliveNotItemizedBatch.setRankOrder((short) 1);
+
+ // -----------------------------------------------------------------------------
+ // Vrac / Species / Inert (not alive)
+ // -----------------------------------------------------------------------------
+
+ SortingBatch inertBatch = catchBatchDao.getSortingBatch(benthosBatch.getChildBatchs(), "referenceTaxonId", enumeration.REFERENCE_TAXON_ID_INERT);
+ if (inertBatch == null) {
+ inertBatch = SortingBatch.Factory.newInstance();
+ benthosBatch.getChildBatchs().add(inertBatch);
+ }
+ beanToEntityReferenceTaxonBatch(target, benthosBatch, inertBatch, recorderDepartmentId,
+ enumeration.REFERENCE_TAXON_ID_INERT,
+ source.getBenthosTotalInertWeight(), null);
+ inertBatch.setRankOrder((short) 2);
+ }
+
+ // TODO plancton, macro déchet...
+ }
+ }
+
+ // -----------------------------------------------------------------------------
+ // Hors Vrac
+ // -----------------------------------------------------------------------------
+ {
+ SortingBatch batch = catchBatchChilds.get(enumeration.QUALITATIVE_HORS_VRAC_ID);
+ if (batch == null) {
+ batch = SortingBatch.Factory.newInstance();
+ target.getChildBatchs().add(batch);
+ }
+ beanToEntitySortingBatch(target, target, batch, recorderDepartmentId,
+ enumeration.PMFM_ID_SORTED_UNSORTED, enumeration.QUALITATIVE_HORS_VRAC_ID,
+ source.getCatchTotalUnsortedWeight(), null);
+ batch.setRankOrder((short) 2);
+
+ // Manage childs :
+ {
+ Map<Integer, SortingBatch> batchChilds = getChildsMap(batch, enumeration.PMFM_ID_SORTING_TYPE);
+
+ // -----------------------------------------------------------------------------
+ // Hors Vrac > Species :
+ // -----------------------------------------------------------------------------
+ {
+ SortingBatch speciesBatch = batchChilds.get(enumeration.QUALITATIVE_ID_SORTING_TYPE_SPECIES);
+ if (speciesBatch == null) {
+ speciesBatch = SortingBatch.Factory.newInstance();
+ if (batch.getChildBatchs() == null) {
+ batch.setChildBatchs(Lists.newArrayList((Batch) speciesBatch));
+ } else {
+ batch.getChildBatchs().add(speciesBatch);
+ }
+ }
+ beanToEntitySortingBatch(target, batch, speciesBatch, recorderDepartmentId,
+ enumeration.PMFM_ID_SORTING_TYPE, enumeration.QUALITATIVE_ID_SORTING_TYPE_SPECIES,
+ source.getSpeciesTotalUnsortedWeight(), null);
+ speciesBatch.setRankOrder((short) 1);
+ }
+
+ // -----------------------------------------------------------------------------
+ // Hors Vrac > Benthos :
+ // -----------------------------------------------------------------------------
+ {
+ SortingBatch benthosBatch = batchChilds.get(enumeration.QUALITATIVE_ID_SORTING_TYPE_BENTHOS);
+ if (benthosBatch == null) {
+ benthosBatch = SortingBatch.Factory.newInstance();
+ batch.getChildBatchs().add(benthosBatch);
+ }
+ beanToEntitySortingBatch(target, batch, benthosBatch, recorderDepartmentId,
+ enumeration.PMFM_ID_SORTING_TYPE, enumeration.QUALITATIVE_ID_SORTING_TYPE_BENTHOS,
+ source.getBenthosTotalUnsortedWeight(), null);
+ benthosBatch.setRankOrder((short) 2);
+ }
+
+ // TODO : plancton, macro déchet...
+ }
+
+ }
+
+ // -----------------------------------------------------------------------------
+ // Unsorted (=rejected)
+ // -----------------------------------------------------------------------------
+ // Unsorted :
+ SortingBatch unsortedBatch = catchBatchChilds.get(enumeration.QUALITATIVE_UNSORTED_ID);
+ if (unsortedBatch == null) {
+ unsortedBatch = SortingBatch.Factory.newInstance();
+ target.getChildBatchs().add(unsortedBatch);
+ }
+ beanToEntitySortingBatch(target, target, unsortedBatch, recorderDepartmentId,
+ enumeration.PMFM_ID_SORTED_UNSORTED, enumeration.QUALITATIVE_UNSORTED_ID,
+ source.getCatchTotalRejectedWeight(), null);
+ unsortedBatch.setRankOrder((short) 3);
+
+ }
+
+ protected Map<Integer, SortingBatch> getChildsMap(Batch parentBatch, Integer pmfmId) {
+ Map<Integer, SortingBatch> batchByQualitativeValueId = Maps.newHashMap();
+ if (parentBatch.getChildBatchs() == null) {
+ return batchByQualitativeValueId;
+ }
+ for (Batch childBatch : parentBatch.getChildBatchs()) {
+ SortingBatch childSortingBatch = (SortingBatch) childBatch;
+ SortingMeasurement sm = catchBatchDao.getSortingMeasurement((SortingBatch) childBatch, pmfmId, null, false);
+ if (sm != null && sm.getQualitativeValue() != null && sm.getQualitativeValue().getId() != null) {
+ batchByQualitativeValueId.put(sm.getQualitativeValue().getId(), childSortingBatch);
+ }
+ }
+ return batchByQualitativeValueId;
+ }
+
+ protected void beanToEntitySortingBatch(
+ fr.ifremer.adagio.core.dao.data.batch.CatchBatch rootBatch,
+ fr.ifremer.adagio.core.dao.data.batch.Batch parentBatch,
+ fr.ifremer.adagio.core.dao.data.batch.SortingBatch target,
+ Integer recorderDepartmentId,
+ Integer sortingPmfmId,
+ Integer sortingQualitativeValueId,
+ Float weight,
+ Float sampleWeight) {
+
+ Collection<QuantificationMeasurement> quantificationMeasurements = target.getQuantificationMeasurements();
+ Collection<SortingMeasurement> sortingMeasurements = target.getSortingMeasurements();
+
+ // Create lists to store all updates, then remove not updated items
+ Set<QuantificationMeasurement> notChangedQuantificationMeasurements = Sets.newHashSet();
+ if (quantificationMeasurements != null) {
+ notChangedQuantificationMeasurements.addAll(quantificationMeasurements);
+ }
+ Set<SortingMeasurement> notChangedSortingMeasurements = Sets.newHashSet();
+ if (sortingMeasurements != null) {
+ notChangedSortingMeasurements.addAll(sortingMeasurements);
+ }
+
+ // Some mandatory properties :
+ target.setQualityFlag(load(QualityFlagImpl.class, enumeration.QUALITY_FLAG_CODE_NOT_QUALIFIED));
+ target.setRootBatch(rootBatch);
+ target.setParentBatch(parentBatch);
+ target.setExhaustiveInventory(true);
+
+ // No taxon or taxon group
+ target.setReferenceTaxon(null);
+ target.setTaxonGroup(null);
+
+ // Sorting measurement
+ if (sortingPmfmId == null || sortingQualitativeValueId == null) {
+ // Nothing to do : will be removed later, using notChangedSortingMeasurements
+ } else {
+ SortingMeasurement sm = batchHelper.setSortingMeasurement(target, recorderDepartmentId, sortingPmfmId, sortingQualitativeValueId);
+ notChangedSortingMeasurements.remove(sm);
+ }
+
+ // Sampling Ratio
+ if (sampleWeight == null || weight == null) {
+ target.setSamplingRatio(null);
+ target.setSamplingRatioText(null);
+ } else {
+ String samplingRatioText = weight + "/" + sampleWeight;
+ samplingRatioText = samplingRatioText.replaceAll(",", ".");
+ target.setSamplingRatioText(samplingRatioText);
+ target.setSamplingRatio(weight / sampleWeight);
+ }
+
+ // Weight
+ if (sampleWeight == null && weight == null) {
+ // Nothing to do : will be removed later, using notChangedQuantificationMeasurements
+ } else {
+ Float batchReferenceWeight = weight;
+ if (batchReferenceWeight == null) {
+ batchReferenceWeight = sampleWeight;
+ }
+ QuantificationMeasurement quantificationMeasurement = catchBatchDao.setQuantificationMeasurement(target,
+ enumeration.PMFM_ID_WEIGHT_MEASURED, recorderDepartmentId, batchReferenceWeight, true);
+ notChangedQuantificationMeasurements.remove(quantificationMeasurement);
+ }
+
+ // Removed not changed measurements (in sorting and quantification measurement lists)
+ if (quantificationMeasurements != null) {
+ quantificationMeasurements.removeAll(notChangedQuantificationMeasurements);
+ }
+ if (sortingMeasurements != null) {
+ sortingMeasurements.removeAll(notChangedSortingMeasurements);
+ }
+ }
+
+ protected void beanToEntityReferenceTaxonBatch(
+ fr.ifremer.adagio.core.dao.data.batch.CatchBatch rootBatch,
+ fr.ifremer.adagio.core.dao.data.batch.Batch parentBatch,
+ fr.ifremer.adagio.core.dao.data.batch.SortingBatch target,
+ Integer recorderDepartmentId,
+ Integer referenceTaxonId,
+ Float weight,
+ Float sampleWeight) {
+
+ Collection<QuantificationMeasurement> quantificationMeasurements = target.getQuantificationMeasurements();
+ Collection<SortingMeasurement> sortingMeasurements = target.getSortingMeasurements();
+
+ // Create lists to store all updates, then remove not updated items
+ Set<QuantificationMeasurement> notChangedQuantificationMeasurements = Sets.newHashSet();
+ if (quantificationMeasurements != null) {
+ notChangedQuantificationMeasurements.addAll(quantificationMeasurements);
+ }
+ Set<SortingMeasurement> notChangedSortingMeasurements = Sets.newHashSet();
+ if (sortingMeasurements != null) {
+ notChangedSortingMeasurements.addAll(sortingMeasurements);
+ }
+
+ // Some mandatory properties :
+ target.setQualityFlag(load(QualityFlagImpl.class, enumeration.QUALITY_FLAG_CODE_NOT_QUALIFIED));
+ target.setRootBatch(rootBatch);
+ target.setParentBatch(parentBatch);
+ target.setExhaustiveInventory(true);
+
+ // Reference taxon
+ target.setReferenceTaxon(load(ReferenceTaxonImpl.class, referenceTaxonId));
+ target.setTaxonGroup(null);
+
+ // Sampling Ratio
+ if ((sampleWeight == null || weight == null)) {
+ target.setSamplingRatio(null);
+ target.setSamplingRatioText(null);
+ } else {
+ String samplingRatioText = weight + "/" + sampleWeight;
+ samplingRatioText = samplingRatioText.replaceAll(",", ".");
+ target.setSamplingRatioText(samplingRatioText);
+ target.setSamplingRatio(weight / sampleWeight);
+ }
+
+ // Weight
+ if ((sampleWeight == null && weight == null)) {
+ // Nothing to do : will be removed later, using notChangedQuantificationMeasurements
+ } else {
+ Float batchReferenceWeight = weight;
+ if (batchReferenceWeight == null) {
+ batchReferenceWeight = sampleWeight;
+ }
+ QuantificationMeasurement quantificationMeasurement = catchBatchDao.setQuantificationMeasurement(target,
+ enumeration.PMFM_ID_WEIGHT_MEASURED, recorderDepartmentId, batchReferenceWeight, true);
+ notChangedQuantificationMeasurements.remove(quantificationMeasurement);
+ }
+
+ // Removed not changed measurements (in sorting and quantification measurement lists)
+ if (quantificationMeasurements != null) {
+ quantificationMeasurements.removeAll(notChangedQuantificationMeasurements);
+ }
+ if (sortingMeasurements != null) {
+ sortingMeasurements.removeAll(notChangedSortingMeasurements);
+ }
+ }
+
+ protected Integer getRecorderDepartmentId() {
+ // TODO BL : voir si on peut récupérer le departement (du 1er saisisseur ?)
+ return enumeration.DEPARTMENT_ID_UNKNOWN_RECORDER_DEPARTMENT;
+ }
+}
Added: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceService.java
===================================================================
--- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceService.java (rev 0)
+++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceService.java 2013-03-27 21:49:05 UTC (rev 693)
@@ -0,0 +1,111 @@
+package fr.ifremer.tutti.persistence.service;
+
+/*
+ * #%L
+ * Tutti :: Persistence
+ * $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.TuttiPersistenceServiceImplementor;
+import fr.ifremer.tutti.persistence.entities.data.BatchContainer;
+import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch;
+import fr.ifremer.tutti.persistence.entities.data.SpeciesBatchFrequency;
+import fr.ifremer.tutti.persistence.entities.referential.Species;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.List;
+
+/**
+ * Service to persist *species* {@link SpeciesBatch}.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.2
+ */
+@Transactional(readOnly = true)
+public interface SpeciesBatchPersistenceService extends TuttiPersistenceServiceImplementor {
+
+ //------------------------------------------------------------------------//
+ //-- SpeciesBatch methods --//
+ //------------------------------------------------------------------------//
+
+ /**
+ * Get the batch parent of all root {@link SpeciesBatch} for the given
+ * fishing operation.
+ * <p/>
+ * <strong>Note:</strong> All childs of the batch should be loaded here.
+ *
+ * @param fishingOperationId if of the fishing operation to seek
+ * @return the list of root {@link SpeciesBatch}
+ * @since 1.0.2
+ */
+ BatchContainer<SpeciesBatch> getRootSpeciesBatch(String fishingOperationId);
+
+ @Transactional(readOnly = false)
+ SpeciesBatch createSpeciesBatch(SpeciesBatch bean, String parentBatchId);
+
+ @Transactional(readOnly = false)
+ SpeciesBatch saveSpeciesBatch(SpeciesBatch bean);
+
+ @Transactional(readOnly = false)
+ void deleteSpeciesBatch(String id);
+
+ @Transactional(readOnly = false)
+ void deleteSpeciesSubBatch(String id);
+
+ /**
+ * Change the species in the given {@code batchId} and in all his
+ * sub batches.
+ *
+ * @param batchId id of the root species batch to treat
+ * @param species species to affect to all batches
+ */
+ @Transactional(readOnly = false)
+ void changeSpeciesBatchSpecies(String batchId, Species species);
+
+ //------------------------------------------------------------------------//
+ //-- SpeciesBatchFrequency methods (for species) --//
+ //------------------------------------------------------------------------//
+
+ /**
+ * Get all frequencies for the given species batch.
+ *
+ * @param speciesBatchId the id of the species batch to seek.
+ * @return the list of frequencies for the given specues batch id
+ * @since 1.0
+ */
+ List<SpeciesBatchFrequency> getAllSpeciesBatchFrequency(String speciesBatchId);
+
+ /**
+ * Save all given {@link SpeciesBatchFrequency} into the given
+ * {@code speciesBatchId}. If some are not existing then creates them.
+ * <p/>
+ * <strong>Note:</strong> This will as a side effect remove all previous frequency for this species batch.
+ *
+ * @param speciesBatchId id of the {@link SpeciesBatch} to use
+ * @param frequencies list of frequencies to create or update
+ * @return the persisted list of frequencies
+ * @since 1.0
+ */
+ @Transactional(readOnly = false)
+ List<SpeciesBatchFrequency> saveSpeciesBatchFrequency(String speciesBatchId,
+ List<SpeciesBatchFrequency> frequencies);
+
+}
Property changes on: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceService.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: 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 (rev 0)
+++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceImpl.java 2013-03-27 21:49:05 UTC (rev 693)
@@ -0,0 +1,369 @@
+package fr.ifremer.tutti.persistence.service;
+
+/*
+ * #%L
+ * Tutti :: Persistence
+ * $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.dao.data.batch.Batch;
+import fr.ifremer.adagio.core.dao.data.batch.CatchBatchExtendDao;
+import fr.ifremer.adagio.core.dao.data.batch.SortingBatch;
+import fr.ifremer.tutti.persistence.entities.data.BatchContainer;
+import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch;
+import fr.ifremer.tutti.persistence.entities.data.SpeciesBatchFrequency;
+import fr.ifremer.tutti.persistence.entities.referential.Species;
+import fr.ifremer.tutti.persistence.service.batch.BatchPersistenceHelper;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.hibernate.FlushMode;
+import org.springframework.dao.DataIntegrityViolationException;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * Default implementation of {@link SpeciesBatchPersistenceService}.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.2
+ */
+@Service("speciesBatchPersistenceService")
+public class SpeciesBatchPersistenceServiceImpl extends AbstractPersistenceService
+ implements SpeciesBatchPersistenceService {
+
+ /** Logger. */
+ private static final Log log =
+ LogFactory.getLog(SpeciesBatchPersistenceServiceImpl.class);
+
+ @Resource(name = "catchBatchDao")
+ protected CatchBatchExtendDao catchBatchDao;
+
+ @Resource(name = "batchPersistenceHelper")
+ protected BatchPersistenceHelper batchHelper;
+
+ //------------------------------------------------------------------------//
+ //-- SpeciesBatch methods --//
+ //------------------------------------------------------------------------//
+
+ @Override
+ public BatchContainer<SpeciesBatch> getRootSpeciesBatch(String fishingOperationId) {
+ Preconditions.checkNotNull(fishingOperationId);
+
+ // Load batch tree
+ Integer catchBatchId = catchBatchDao.getIdByFishingOperationId(Integer.valueOf(fishingOperationId));
+ Preconditions.checkNotNull(catchBatchId);
+
+ fr.ifremer.adagio.core.dao.data.batch.CatchBatch catchBatch = catchBatchDao.loadFullTree(catchBatchId);
+ Preconditions.checkNotNull(catchBatch);
+
+ Collection<Batch> catchBatchChilds = catchBatch.getChildBatchs();
+ // Vrac / Species
+ SortingBatch vracSpeciesBatch = catchBatchDao.getSortingBatch(catchBatchChilds,
+ "pmfmId", enumeration.PMFM_ID_SORTED_UNSORTED, enumeration.QUALITATIVE_VRAC_ID,
+ "pmfmId", enumeration.PMFM_ID_SORTING_TYPE, enumeration.QUALITATIVE_ID_SORTING_TYPE_SPECIES);
+
+ // container of speciesBatch is arbitraty put on vrac type (there is
+ // no common ancestor for all species batch).
+ BatchContainer<SpeciesBatch> result = new BatchContainer<SpeciesBatch>();
+ result.setId(vracSpeciesBatch.getId());
+
+ for (Batch batch1 : vracSpeciesBatch.getChildBatchs()) {
+ SortingBatch source = (SortingBatch) batch1;
+
+ // evict some special batches : Life (or Biota) and Inert
+ if (source.getReferenceTaxon() != null
+ && !enumeration.REFERENCE_TAXON_ID_LIFE.equals(source.getReferenceTaxon().getId())
+ && !enumeration.REFERENCE_TAXON_ID_INERT.equals(source.getReferenceTaxon().getId())) {
+
+ SpeciesBatch target = new SpeciesBatch();
+ batchHelper.entityToSpeciesBatch(source, target);
+ result.addChildren(target);
+
+ if (log.isInfoEnabled()) {
+ log.info("Loaded CatchBatch Vrac > Species > " + target.getSpecies().getReferenceTaxonId() + " : " + target.getId());
+ }
+ }
+ }
+
+ // Hors-Vrac / Species
+ SortingBatch horsVracSpeciesBatch = catchBatchDao.getSortingBatch(catchBatchChilds,
+ "pmfmId", enumeration.PMFM_ID_SORTED_UNSORTED, enumeration.QUALITATIVE_HORS_VRAC_ID,
+ "pmfmId", enumeration.PMFM_ID_SORTING_TYPE, enumeration.QUALITATIVE_ID_SORTING_TYPE_SPECIES);
+ if (horsVracSpeciesBatch != null) {
+ for (Batch batch : horsVracSpeciesBatch.getChildBatchs()) {
+
+ SpeciesBatch target = new SpeciesBatch();
+ batchHelper.entityToSpeciesBatch((SortingBatch) batch, target);
+ result.addChildren(target);
+ if (log.isInfoEnabled()) {
+ log.info("Loaded CatchBatch Hors Vrac > Species > " + target.getSpecies().getReferenceTaxonId() + " : " + target.getId());
+ }
+ }
+ }
+
+ return result;
+ }
+
+ @Override
+ public SpeciesBatch createSpeciesBatch(SpeciesBatch bean,
+ String parentBatchId) {
+ Preconditions.checkNotNull(bean);
+ Preconditions.checkArgument(bean.getId() == null);
+ Preconditions.checkNotNull(bean.getSpecies());
+ Preconditions.checkNotNull(bean.getSpecies().getId());
+ Preconditions.checkNotNull(bean.getFishingOperation());
+ Preconditions.checkNotNull(bean.getFishingOperation().getId());
+
+ getCurrentSession().setFlushMode(FlushMode.COMMIT);
+
+ // Load full batch tree
+ Integer catchBatchId = catchBatchDao.getIdByFishingOperationId(bean.getFishingOperation().getIdAsInt());
+ fr.ifremer.adagio.core.dao.data.batch.CatchBatch catchBatch = catchBatchDao.loadFullTree(catchBatchId);
+
+ SortingBatch batch = SortingBatch.Factory.newInstance();
+ speciesBatchToEntity(bean, batch, parentBatchId, catchBatch);
+ batch = catchBatchDao.createSortingBatch(batch, catchBatch);
+
+ bean.setId(batch.getId());
+
+ getCurrentSession().flush();
+
+ return bean;
+ }
+
+ @Override
+ public SpeciesBatch saveSpeciesBatch(SpeciesBatch bean) {
+ Preconditions.checkNotNull(bean);
+ Preconditions.checkNotNull(bean.getId());
+
+ // Load batch tree
+ Integer catchBatchId = catchBatchDao.getIdBySortingBatchId(bean.getIdAsInt());
+ Preconditions.checkNotNull(catchBatchId);
+
+ fr.ifremer.adagio.core.dao.data.batch.CatchBatch catchBatch = catchBatchDao.loadFullTree(catchBatchId);
+ Preconditions.checkNotNull(catchBatch);
+
+ getCurrentSession().setFlushMode(FlushMode.COMMIT);
+
+ SortingBatch batch = catchBatchDao.getSortingBatchById(catchBatch, bean.getIdAsInt());
+ String parentBatchId = null;
+ if (bean.getParentBatch() != null) {
+ parentBatchId = bean.getParentBatch().getId();
+ }
+ speciesBatchToEntity(bean, batch, parentBatchId, catchBatch);
+ catchBatchDao.updateSortingBatch(batch, catchBatch);
+ getCurrentSession().flush();
+
+ return bean;
+ }
+
+ @Override
+ public void deleteSpeciesBatch(String id) {
+ Preconditions.checkNotNull(id);
+
+ getCurrentSession().setFlushMode(FlushMode.COMMIT);
+
+ catchBatchDao.removeWithChildren(Integer.valueOf(id));
+
+ getCurrentSession().flush();
+ }
+
+ @Override
+ public void deleteSpeciesSubBatch(String id) {
+ Preconditions.checkNotNull(id);
+ deleteSpeciesBatch(id);
+ }
+
+ @Override
+ public void changeSpeciesBatchSpecies(String batchId, Species species) {
+
+ Preconditions.checkNotNull(batchId);
+ Preconditions.checkNotNull(species);
+ Preconditions.checkNotNull(species.getReferenceTaxonId());
+
+ catchBatchDao.setSortingBatchReferenceTaxon(batchId, species.getReferenceTaxonId());
+ }
+
+ //------------------------------------------------------------------------//
+ //-- SpeciesBatchFrequency methods --//
+ //------------------------------------------------------------------------//
+
+ @Override
+ public List<SpeciesBatchFrequency> getAllSpeciesBatchFrequency(
+ String speciesBatchId) {
+ Preconditions.checkNotNull(speciesBatchId);
+
+ List<SpeciesBatchFrequency> results = Lists.newArrayList();
+
+ Integer sortingBatchId = Integer.valueOf(speciesBatchId);
+ Integer catchBatchId = catchBatchDao.getIdBySortingBatchId(sortingBatchId);
+ Preconditions.checkNotNull(
+ catchBatchId,
+ "Could not find catchBatch for speciesBatch: " + speciesBatchId);
+
+ fr.ifremer.adagio.core.dao.data.batch.CatchBatch catchBatch =
+ catchBatchDao.loadFullTree(catchBatchId);
+
+ SortingBatch sortingBatch = catchBatchDao.getSortingBatchById(
+ catchBatch, sortingBatchId);
+
+ List<SortingBatch> frequencyChilds = batchHelper.getFrequencyChilds(sortingBatch);
+ for (SortingBatch child : frequencyChilds) {
+ SpeciesBatchFrequency target = new SpeciesBatchFrequency();
+
+ batchHelper.entityToSpeciesBatchFrequency(child, target);
+ results.add(target);
+ }
+ return Collections.unmodifiableList(results);
+ }
+
+ @Override
+ public List<SpeciesBatchFrequency> saveSpeciesBatchFrequency(
+ String speciesBatchId,
+ List<SpeciesBatchFrequency> frequencies) {
+ Preconditions.checkNotNull(speciesBatchId);
+ Preconditions.checkNotNull(frequencies);
+
+ List<SpeciesBatchFrequency> notNullFrequencies = Lists.newArrayList();
+
+ // Check that all frequencies have the same length PMFM (before doing any db call)
+ // and remove null frequencies
+ String pmfmId = null;
+ for (SpeciesBatchFrequency source : frequencies) {
+
+ if (source.getLengthStepCaracteristic() != null) {
+ if (pmfmId == null) {
+ pmfmId = source.getLengthStepCaracteristic().getId();
+ } else if (!pmfmId.equals(source.getLengthStepCaracteristic().getId())) {
+ throw new DataIntegrityViolationException("Batch frequencies under one SpeciesBatch must have all the same lengthStepCaracteristic");
+ }
+ notNullFrequencies.add(source);
+ }
+ }
+
+ getCurrentSession().setFlushMode(FlushMode.COMMIT);
+
+ Integer sortingBatchId = Integer.valueOf(speciesBatchId);
+ Integer catchBatchId = catchBatchDao.getIdBySortingBatchId(sortingBatchId);
+ fr.ifremer.adagio.core.dao.data.batch.CatchBatch catchBatch = catchBatchDao.loadFullTree(catchBatchId);
+
+ if (catchBatch == null) {
+ return notNullFrequencies;
+ }
+
+ // Retrieve parent
+ SortingBatch parentBatch = catchBatchDao.getSortingBatchById(catchBatch, sortingBatchId);
+
+ // Remember child ids, to remove unchanged item (see at bottom in this method)
+ List<Integer> notUpdatedChildIds = Lists.newArrayList();
+ List<SortingBatch> frequencyChilds = batchHelper.getFrequencyChilds(parentBatch);
+ for (SortingBatch child : frequencyChilds) {
+ notUpdatedChildIds.add(child.getId());
+ }
+// for (Batch batch : parentBatch.getChildBatchs()) {
+// SortingBatch sortingBatch = (SortingBatch) batch;
+// notUpdatedChildIds.add(sortingBatch.getId());
+// }
+
+ short rankOrder = 0;
+ List<SortingBatch> batchsToUpdate = Lists.newArrayList();
+ for (SpeciesBatchFrequency source : notNullFrequencies) {
+ rankOrder++;
+
+ SortingBatch target;
+ if (source.getId() == null) {
+
+ // Not existing batch
+ target = SortingBatch.Factory.newInstance();
+
+ // Fill the sorting batch from the source
+ batchHelper.speciesBatchFrequencyToEntity(source, target, parentBatch, rankOrder);
+
+ // Create the targeted batch, then update the source id
+ catchBatchDao.createSortingBatch(target, catchBatch);
+
+ // push back id of created sortingBatch
+ source.setId(target.getId());
+
+ if (log.isInfoEnabled()) {
+ log.info("Create frequency sortingBatch(" + rankOrder + "): " + target.getId());
+ }
+ } else {
+
+ // Existing batch
+ target = catchBatchDao.loadSortingBatch(source.getIdAsInt(), catchBatch);
+
+ // Fill the sorting batch from the source
+ batchHelper.speciesBatchFrequencyToEntity(source, target, parentBatch, rankOrder);
+
+ // Add the batch into a list (will be update later, using this list)
+ batchsToUpdate.add(target);
+
+ // Remove id from id to remove
+ notUpdatedChildIds.remove(target.getId());
+
+ if (log.isInfoEnabled()) {
+ log.info("Update frequency sortingBatch(" + rankOrder + "): " + target.getId());
+ }
+ }
+ }
+
+ if (batchsToUpdate.size() > 0) {
+
+ // update some batchs
+ catchBatchDao.updateSortingBatch(batchsToUpdate, catchBatch);
+ }
+
+ if (notUpdatedChildIds.size() > 0) {
+
+ // Remove obsolete frequencies
+ for (Integer batchId : notUpdatedChildIds) {
+
+ if (log.isInfoEnabled()) {
+ log.info("Remove obsolete frequency sortingBatch: " + batchId);
+ }
+ catchBatchDao.removeWithChildren(batchId, catchBatch);
+ }
+ }
+
+ getCurrentSession().flush();
+
+ return Collections.unmodifiableList(notNullFrequencies);
+ }
+
+ //------------------------------------------------------------------------//
+ //-- Internal methods --//
+ //------------------------------------------------------------------------//
+
+ protected void speciesBatchToEntity(SpeciesBatch source,
+ SortingBatch target,
+ String parentBatchId,
+ fr.ifremer.adagio.core.dao.data.batch.CatchBatch catchBatch) {
+ batchHelper.speciesBatchToEntity(source, target, parentBatchId, catchBatch, enumeration.QUALITATIVE_ID_SORTING_TYPE_SPECIES);
+ }
+
+}
Property changes on: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceImpl.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/TuttiPersistenceServiceLocator.java
===================================================================
--- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/TuttiPersistenceServiceLocator.java 2013-03-27 21:44:37 UTC (rev 692)
+++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/TuttiPersistenceServiceLocator.java 2013-03-27 21:49:05 UTC (rev 693)
@@ -80,11 +80,21 @@
FishingOperationPersistenceService.class);
}
- public static BatchPersistenceService getBatchPersistenceService() {
+ public static CatchBatchPersistenceService getCatchBatchPersistenceService() {
return getPersistenceService("batchPersistenceService",
- BatchPersistenceService.class);
+ CatchBatchPersistenceService.class);
}
+ public static SpeciesBatchPersistenceService getSpeciesBatchPersistenceService() {
+ return getPersistenceService("speciesBatchPersistenceService",
+ SpeciesBatchPersistenceService.class);
+ }
+
+ public static BenthosBatchPersistenceService getBenthosBatchPersistenceService() {
+ return getPersistenceService("benthosBatchPersistenceService",
+ BenthosBatchPersistenceService.class);
+ }
+
public static PlanktonBatchPersistenceService getPlanktonBatchPersistenceService() {
return getPersistenceService("planktonBatchPersistenceService",
PlanktonBatchPersistenceService.class);
Added: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/batch/BatchPersistenceHelper.java
===================================================================
--- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/batch/BatchPersistenceHelper.java (rev 0)
+++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/batch/BatchPersistenceHelper.java 2013-03-27 21:49:05 UTC (rev 693)
@@ -0,0 +1,603 @@
+package fr.ifremer.tutti.persistence.service.batch;
+
+/*
+ * #%L
+ * Tutti :: Persistence
+ * $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 com.google.common.collect.Sets;
+import fr.ifremer.adagio.core.dao.data.batch.Batch;
+import fr.ifremer.adagio.core.dao.data.batch.CatchBatchExtendDao;
+import fr.ifremer.adagio.core.dao.data.batch.SortingBatch;
+import fr.ifremer.adagio.core.dao.data.measure.Measurement;
+import fr.ifremer.adagio.core.dao.data.measure.QuantificationMeasurement;
+import fr.ifremer.adagio.core.dao.data.measure.SortingMeasurement;
+import fr.ifremer.adagio.core.dao.referential.QualityFlagImpl;
+import fr.ifremer.adagio.core.dao.referential.pmfm.Pmfm;
+import fr.ifremer.adagio.core.dao.referential.pmfm.QualitativeValue;
+import fr.ifremer.adagio.core.dao.referential.pmfm.QualitativeValueImpl;
+import fr.ifremer.adagio.core.dao.referential.taxon.ReferenceTaxon;
+import fr.ifremer.adagio.core.dao.referential.taxon.ReferenceTaxonImpl;
+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 fr.ifremer.tutti.persistence.service.AbstractPersistenceService;
+import fr.ifremer.tutti.persistence.service.ReferentialPersistenceService;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.springframework.dao.DataIntegrityViolationException;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.Resource;
+import java.io.Serializable;
+import java.text.MessageFormat;
+import java.util.Collection;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * Helper around batches.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.2
+ */
+@Component("batchPersistenceHelper")
+public class BatchPersistenceHelper extends AbstractPersistenceService {
+
+ /** Logger. */
+ private static final Log log =
+ LogFactory.getLog(BatchPersistenceHelper.class);
+
+ @Resource(name = "referentialPersistenceService")
+ protected ReferentialPersistenceService referentialService;
+
+ @Resource(name = "catchBatchDao")
+ protected CatchBatchExtendDao catchBatchDao;
+
+ public List<SortingBatch> getFrequencyChilds(SortingBatch sortingBatch) {
+ List<SortingBatch> result = Lists.newArrayList();
+
+ for (Batch batch : sortingBatch.getChildBatchs()) {
+ SortingBatch child = (SortingBatch) batch;
+ if (isFrequencyBatch(child)) {
+ result.add(child);
+ }
+ }
+ return result;
+ }
+
+ public List<SortingBatch> getNotFrequencyChilds(SortingBatch sortingBatch) {
+ List<SortingBatch> result = Lists.newArrayList();
+
+ for (Batch batch : sortingBatch.getChildBatchs()) {
+ SortingBatch child = (SortingBatch) batch;
+ if (isFrequencyBatch(child)) {
+ result.add(child);
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Check if the given {@code sortingBatch} is a frequency one.
+ * <p/>
+ * We test that:
+ * <ul>
+ * <li>batch has exactly one measurement</li>
+ * <li>the measurement pmfm is not a sample category</li>
+ * </ul>
+ *
+ * @param sortingBatch batch to check
+ * @return {@code true} if given batch is a frequency batch,
+ * {@code false} otherwise.
+ */
+ protected boolean isFrequencyBatch(SortingBatch sortingBatch) {
+ boolean result = false;
+ if (sortingBatch.getSortingMeasurements().size() == 1) {
+ SortingMeasurement sm
+ = sortingBatch.getSortingMeasurements().iterator().next();
+ Pmfm pmfm = sm.getPmfm();
+ SampleCategoryEnum sampleCategoryByPmfmId =
+ enumeration.getSampleCategoryByPmfmId(pmfm.getId());
+ result = sampleCategoryByPmfmId == null;
+
+ }
+ return result;
+ }
+
+ public SpeciesBatch entityToSpeciesBatch(SortingBatch source,
+ SpeciesBatch target) {
+
+ target.setId(source.getId().toString());
+
+ // Individual count
+ target.setNumber(source.getIndividualCount());
+
+ // Convert database weight (and sampling ratio) into UI weight and sampleCategoryWeight
+ if (source.getWeight() != null && source.getWeightBeforeSampling() == null) {
+ target.setSampleCategoryWeight(source.getWeight());
+ } else {
+ target.setWeight(source.getWeight());
+ target.setSampleCategoryWeight(source.getWeightBeforeSampling());
+ }
+
+ // Comments
+ target.setComment(source.getComments());
+
+ // Sample category type (only one is applied)
+ SortingMeasurement sm = null;
+ if (source.getSortingMeasurements().size() == 1) {
+ sm = source.getSortingMeasurements().iterator().next();
+ } else if (source.getReferenceTaxon() != null && source.getReferenceTaxon().getId() != null) {
+ sm = catchBatchDao.getInheritedSortingMeasurement(source, enumeration.PMFM_ID_SORTED_UNSORTED);
+ }
+ if (sm != null) {
+ SampleCategoryEnum sampleCategory = enumeration.getSampleCategoryByPmfmId(sm.getPmfm().getId());
+ if (sampleCategory != null) {
+ Integer qualitativeId = null;
+ if (sm.getQualitativeValue() != null) {
+ qualitativeId = sm.getQualitativeValue().getId();
+ }
+ setSampleCategoryQualitative(target, sm.getPmfm().getId(), sm.getNumericalValue(), sm.getAlphanumericalValue(), qualitativeId);
+ }
+ }
+
+ // Species
+ Integer referenceTaxonId = source.getInheritedReferenceTaxonId();
+ if (referenceTaxonId == null && source.getReferenceTaxon() != null) {
+ referenceTaxonId = source.getReferenceTaxon().getId();
+ }
+ if (referenceTaxonId != null) {
+ // TODO : add cache on getSpeciesByReferenceTaxonId
+ Species species = referentialService.getSpeciesByReferenceTaxonId(referenceTaxonId);
+ target.setSpecies(species);
+ }
+ //FIXME-TC Check the test is still ok?
+ //FIXME-TC We should a stronger test
+// if (target.getSampleCategoryType() != null && source.getChildBatchs().size() > 0) {
+ if (target.getSampleCategoryType() != null) {
+ List<SpeciesBatch> targetChilds = Lists.newArrayList();
+ for (Batch batch : source.getChildBatchs()) {
+ SortingBatch sourceChild = (SortingBatch) batch;
+ SpeciesBatch targetChild = new SpeciesBatch();
+ entityToSpeciesBatch(sourceChild, targetChild);
+ if (log.isInfoEnabled()) {
+ log.info("Loaded CatchBatch Hors Vrac > Benthos > " + target.getSpecies().getReferenceTaxonId() + " : " + target.getId());
+ }
+ if (targetChild.getSampleCategoryValue() != null) {
+ targetChilds.add(targetChild);
+ targetChild.setParentBatch(target);
+ }
+ }
+ target.setChildBatchs(targetChilds);
+ }
+
+ return target;
+ }
+
+ public void entityToSpeciesBatchFrequency(SortingBatch source,
+ SpeciesBatchFrequency target) {
+
+ target.setId(source.getId());
+
+ target.setNumber(source.getIndividualCount());
+ target.setWeight(source.getWeight());
+ target.setComment(source.getComments());
+
+ Preconditions.checkState(source.getSortingMeasurements().size() == 1, "SortingBatch [" + source.getId() + "] need exactly one sortingMeasurement (to store the length step category), but had " + source.getSortingMeasurements().size());
+ SortingMeasurement sm = source.getSortingMeasurements().iterator().next();
+ Preconditions.checkNotNull(sm.getPmfm(), "SortingMeasurement [" + sm.getId() + "] can not have a null pmfm");
+ Preconditions.checkNotNull(sm.getPmfm().getId(), "SortingMeasurement [" + sm.getId() + "] can not have a pmfm with null id");
+
+ // Length step category
+ Caracteristic lengthStepCaracteristic =
+ referentialService.getCaracteristic(sm.getPmfm().getId());
+ target.setLengthStepCaracteristic(lengthStepCaracteristic);
+
+ // Length
+ target.setLengthStep(sm.getNumericalValue());
+ }
+
+ public void speciesBatchToEntity(SpeciesBatch source,
+ SortingBatch target,
+ String parentBatchId,
+ fr.ifremer.adagio.core.dao.data.batch.CatchBatch catchBatch,
+ Integer batchPmfm) {
+
+ Preconditions.checkNotNull(source.getFishingOperation());
+ Preconditions.checkNotNull(source.getFishingOperation().getId());
+
+ // Retrieve recorder department
+ Integer recorderDepartmentId = getRecorderDepartmentId();
+
+ Collection<QuantificationMeasurement> quantificationMeasurements = target.getQuantificationMeasurements();
+ Collection<SortingMeasurement> sortingMeasurements = target.getSortingMeasurements();
+
+ // Create lists to store all updates, then remove not updated items
+
+ Set<QuantificationMeasurement> notChangedQuantificationMeasurements = Sets.newHashSet();
+ if (quantificationMeasurements != null) {
+ notChangedQuantificationMeasurements.addAll(quantificationMeasurements);
+ }
+ Set<SortingMeasurement> notChangedSortingMeasurements = Sets.newHashSet();
+ if (sortingMeasurements != null) {
+ notChangedSortingMeasurements.addAll(sortingMeasurements);
+ }
+
+ // If parent and root need to be set
+ if (target.getId() == null
+ || target.getRootBatch() == null
+ || (target.getParentBatch() != null && !target.getParentBatch().getId().toString().equals(parentBatchId))) {
+ setBatchParents(source, target, parentBatchId, catchBatch, batchPmfm);
+ }
+
+ // RankOrder (initialize once, at creation)
+ if (target.getRankOrder() == null) {
+ // Start rank order at 3, because of special batches 'Biota' and 'Inert'
+ short rankOrder = (short) 3;
+ if (source.getParentBatch() != null && source.getParentBatch().getChildBatchs() != null) {
+ rankOrder += (short) source.getParentBatch().getChildBatchs().size();
+ } else if (target.getParentBatch() != null && target.getParentBatch().getChildBatchs() != null) {
+ rankOrder += (short) target.getParentBatch().getChildBatchs().size();
+ }
+ target.setRankOrder(rankOrder);
+ }
+
+ // Force subgroup count to '1', as Allegro
+ target.setSubgroupCount(1f);
+
+ // Weight or SampleCategoryWeight
+ if (source.getWeight() == null && source.getSampleCategoryWeight() == null) {
+ // Nothing to do : will be removed later, using notChangedSortingMeasurements
+ } else if (source.getSampleCategoryWeight() != null && source.getWeight() == null) {
+ QuantificationMeasurement quantificationMeasurement = catchBatchDao.setQuantificationMeasurement(target,
+ enumeration.PMFM_ID_WEIGHT_MEASURED, recorderDepartmentId, source.getSampleCategoryWeight(), true);
+ notChangedQuantificationMeasurements.remove(quantificationMeasurement);
+ } else if (source.getWeight() != null && source.getSampleCategoryWeight() == null) {
+ QuantificationMeasurement quantificationMeasurement = catchBatchDao.setQuantificationMeasurement(target,
+ enumeration.PMFM_ID_WEIGHT_MEASURED, recorderDepartmentId, source.getWeight(), true);
+ notChangedQuantificationMeasurements.remove(quantificationMeasurement);
+ }
+
+ // Sampling Ratio
+ if (source.getSampleCategoryWeight() == null || source.getWeight() == null) {
+ target.setSamplingRatio(null);
+ target.setSamplingRatioText(null);
+ } else {
+ String samplingRatioText = source.getWeight() + "/" + source.getSampleCategoryWeight();
+ samplingRatioText = samplingRatioText.replaceAll(",", ".");
+ target.setSamplingRatioText(samplingRatioText);
+ target.setSamplingRatio(source.getWeight() / source.getSampleCategoryWeight());
+ QuantificationMeasurement quantificationMeasurement = catchBatchDao.setQuantificationMeasurement(target,
+ enumeration.PMFM_ID_WEIGHT_MEASURED, recorderDepartmentId, source.getWeight(), true);
+ notChangedQuantificationMeasurements.remove(quantificationMeasurement);
+ }
+
+ // Sorting measurement
+ if ((source.getSampleCategoryType() == null || source.getSampleCategoryValue() == null)) {
+ // Nothing to do : will be removed later, using notChangedSortingMeasurements
+ } else {
+ Integer pmfmId = source.getSampleCategoryType().getFieldValue();
+ // Do not store sorting measurement if pmfm = SORTED (already store in an ancestor batch)
+ if (!pmfmId.equals(enumeration.PMFM_ID_SORTED_UNSORTED)) {
+ SortingMeasurement sortingMeasurement = setSortingMeasurement(target, recorderDepartmentId,
+ source.getSampleCategoryType(), source.getSampleCategoryValue());
+ notChangedSortingMeasurements.remove(sortingMeasurement);
+ }
+ }
+
+ // Individual count
+ target.setIndividualCount(source.getNumber());
+
+ // Species
+ ReferenceTaxon referenceTaxon;
+ if (source.getSpecies() == null || parentBatchId != null) {
+ referenceTaxon = null;
+ } else {
+ referenceTaxon = load(ReferenceTaxonImpl.class, source.getSpecies().getReferenceTaxonId());
+ }
+ target.setReferenceTaxon(referenceTaxon);
+
+ // QualityFlag
+ String qualityFlag;
+ if (source.isSpeciesToConfirm()) {
+ qualityFlag = enumeration.QUALITY_FLAG_CODE_DOUBTFUL;
+ } else {
+ qualityFlag = enumeration.QUALITY_FLAG_CODE_NOT_QUALIFIED;
+ }
+ target.setQualityFlag(load(QualityFlagImpl.class, qualityFlag));
+
+ // Comments
+ target.setComments(source.getComment());
+
+ // Exhaustive inventory (always true under a species batch)
+ target.setExhaustiveInventory(true);
+
+ // Removed not changed measurements (in sorting and quantification measurement lists)
+ if (quantificationMeasurements != null) {
+ quantificationMeasurements.removeAll(notChangedQuantificationMeasurements);
+ }
+ if (sortingMeasurements != null) {
+ sortingMeasurements.removeAll(notChangedSortingMeasurements);
+ }
+// if (target.getQuantificationMeasurements() != null && notChangedQuantificationMeasurements.size() > 0) {
+// for (QuantificationMeasurement qm : notChangedQuantificationMeasurements) {
+// target.getQuantificationMeasurements().remove(qm);
+// }
+// }
+//
+// if (target.getSortingMeasurements() != null && notChangedSortingMeasurements.size() > 0) {
+// for (SortingMeasurement sm : notChangedSortingMeasurements) {
+// target.getSortingMeasurements().remove(sm);
+// }
+// }
+ }
+
+ public void setBatchParents(SpeciesBatch source,
+ SortingBatch target,
+ String parentBatchIdStr,
+ fr.ifremer.adagio.core.dao.data.batch.CatchBatch catchBatch,
+ Integer batchPmfmId) {
+
+ Preconditions.checkNotNull(target);
+ Preconditions.checkNotNull(source.getFishingOperation());
+ Preconditions.checkNotNull(source.getFishingOperation().getId());
+
+ // Load existing parent and root
+ SortingBatch parentBatch;
+ if (parentBatchIdStr != null) {
+ parentBatch = catchBatchDao.getSortingBatchById(catchBatch, Integer.valueOf(parentBatchIdStr));
+ }
+
+ // Or retrieve parent batch, from pmfm id
+ else {
+ // Retrieve category type
+ Integer pmfmId = source.getSampleCategoryType().getFieldValue();
+ 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})",
+ SampleCategoryEnum.sortedUnsorted.name(),
+ enumeration.PMFM_ID_SORTED_UNSORTED));
+ }
+ Integer qualitativeValueId = convertSampleCategoryValueIntoQualitativeId(source.getSampleCategoryValue());
+
+ parentBatch = catchBatchDao.getSortingBatch(catchBatch.getChildBatchs(),
+ "pmfmId", pmfmId, qualitativeValueId,
+ "pmfmId", enumeration.PMFM_ID_SORTING_TYPE, batchPmfmId);
+
+ // Parent Batch
+ target.setParentBatch(parentBatch);
+ }
+
+
+ if (parentBatch == null) {
+ throw new DataIntegrityViolationException(
+ "Could not retrieve parent batch, for a given speciesBatch : invalid batch tree structure. Please make sure CatchBatch has been saved before to create a SpeciesBatch.");
+ }
+
+ // Parent Batch
+ target.setParentBatch(parentBatch);
+ target.setRootBatch(catchBatch);
+ }
+
+ public Integer convertSampleCategoryValueIntoQualitativeId(Serializable value) {
+ if (value == null)
+ return null;
+ Integer qualitativeValueId = null;
+ if (value instanceof CaracteristicQualitativeValue) {
+ CaracteristicQualitativeValue cqValue = (CaracteristicQualitativeValue) value;
+ qualitativeValueId = cqValue.getIdAsInt();
+ } else if (value instanceof String) {
+ qualitativeValueId = Integer.valueOf((String) value);
+ }
+ return qualitativeValueId;
+ }
+
+ public 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.)
+ if (pmfmId == null || pmfmId.equals(enumeration.PMFM_ID_SORTING_TYPE)) {
+ return;
+ }
+
+ SampleCategoryEnum sampleCategory = enumeration.getSampleCategoryByPmfmId(pmfmId);
+ Preconditions.checkNotNull(sampleCategory, "Unable to find corresponding SampleCategoryEnum for PMFM.ID : " + pmfmId);
+
+ target.setSampleCategoryType(sampleCategory);
+ if (numericalvalue != null) {
+ target.setSampleCategoryValue(numericalvalue);
+ return;
+ }
+ if (alphanumericalValue != null) {
+ target.setSampleCategoryValue(alphanumericalValue);
+ return;
+ }
+
+ Caracteristic caracteristic = referentialService.getCaracteristic(pmfmId);
+ if (caracteristic == null || caracteristic.getCaracteristicType() != CaracteristicType.QUALITATIVE) {
+ return;
+ }
+ CaracteristicQualitativeValue value = null;
+ for (CaracteristicQualitativeValue qv : caracteristic.getQualitativeValue()) {
+ if (qualitativeValueId.equals(qv.getIdAsInt())) {
+ value = qv;
+ break;
+ }
+ }
+ target.setSampleCategoryValue(value);
+ }
+
+ public void speciesBatchFrequencyToEntity(SpeciesBatchFrequency source,
+ SortingBatch target,
+ SortingBatch parentBatch,
+ short rankOrder) {
+ Preconditions.checkNotNull(source.getBatch());
+ Preconditions.checkNotNull(source.getBatch().getId());
+
+ // Retrieve recorder department
+ Integer recorderDepartmentId = getRecorderDepartmentId();
+
+ Collection<QuantificationMeasurement> quantificationMeasurements = target.getQuantificationMeasurements();
+ Collection<SortingMeasurement> sortingMeasurements = target.getSortingMeasurements();
+
+ // Create lists to store all updates, then remove not updated items
+ Set<QuantificationMeasurement> notChangedQuantificationMeasurements = Sets.newHashSet();
+ if (quantificationMeasurements != null) {
+ notChangedQuantificationMeasurements.addAll(quantificationMeasurements);
+ }
+ Set<SortingMeasurement> notChangedSortingMeasurements = Sets.newHashSet();
+ if (sortingMeasurements != null) {
+ notChangedSortingMeasurements.addAll(sortingMeasurements);
+ }
+
+ // If parent and root need to be set
+ if (target.getId() == null
+ || target.getRootBatch() == null
+ || (target.getParentBatch() != null && !target.getParentBatch().getId().equals(parentBatch.getId()))) {
+
+ target.setParentBatch(parentBatch);
+ target.setRootBatch(parentBatch.getRootBatch());
+ }
+
+ // RankOrder
+ target.setRankOrder(rankOrder);
+
+ // Weight or SampleCategoryWeight
+ if (source.getWeight() == null) {
+ // Nothing to do : will be removed later, using notChangedSortingMeasurements
+ } else {
+ QuantificationMeasurement quantificationMeasurement = catchBatchDao.setQuantificationMeasurement(
+ target,
+ enumeration.PMFM_ID_WEIGHT_MEASURED, recorderDepartmentId, source.getWeight(), true);
+ notChangedQuantificationMeasurements.remove(quantificationMeasurement);
+ }
+
+ // Sorting measurement
+ if ((source.getLengthStepCaracteristic() == null || source.getLengthStep() == null)) {
+ // Nothing to do : will be removed later, using notChangedSortingMeasurements
+ } else {
+ Integer pmfmId = source.getLengthStepCaracteristic().getIdAsInt();
+ SortingMeasurement sortingMeasurement = setSortingMeasurement(target, recorderDepartmentId, pmfmId,
+ source.getLengthStep());
+ notChangedSortingMeasurements.remove(sortingMeasurement);
+ }
+
+ // Individual count
+ target.setIndividualCount(source.getNumber());
+
+ // Species
+ target.setReferenceTaxon(null);
+
+ // QualityFlag
+ target.setQualityFlag(parentBatch.getQualityFlag());
+
+ // Comments
+ target.setComments(source.getComment());
+
+ // Exhaustive inventory (always true under a species batch)
+ target.setExhaustiveInventory(true);
+
+ // Removed not changed measurements (in sorting and quantification measurement lists)
+ if (quantificationMeasurements != null) {
+ quantificationMeasurements.removeAll(notChangedQuantificationMeasurements);
+ }
+ if (sortingMeasurements != null) {
+ sortingMeasurements.removeAll(notChangedSortingMeasurements);
+ }
+
+// if (target.getQuantificationMeasurements() != null && notChangedQuantificationMeasurements.size() > 0) {
+// for (QuantificationMeasurement qm : notChangedQuantificationMeasurements) {
+// target.getQuantificationMeasurements().remove(qm);
+// }
+// }
+// if (target.getSortingMeasurements() != null && notChangedSortingMeasurements.size() > 0) {
+// for (SortingMeasurement sm : notChangedSortingMeasurements) {
+// target.getSortingMeasurements().remove(sm);
+// }
+// }
+ }
+
+ public Integer getRecorderDepartmentId() {
+ // TODO BL : voir si on peut récupérer le departement (du 1er saisisseur ?)
+ return enumeration.DEPARTMENT_ID_UNKNOWN_RECORDER_DEPARTMENT;
+ }
+
+ public void setMeasurement(Measurement measurement,
+ Caracteristic caracteristic,
+ Serializable value) {
+ if (caracteristic.getCaracteristicType() == CaracteristicType.TEXT) {
+ measurement.setAlphanumericalValue((String) value);
+ } else if (caracteristic.getCaracteristicType() == CaracteristicType.NUMBER) {
+ measurement.setNumericalValue((Float) value);
+ } else if (caracteristic.getCaracteristicType() == CaracteristicType.QUALITATIVE) {
+ Integer qvId;
+ if (value instanceof CaracteristicQualitativeValue) {
+ qvId = ((CaracteristicQualitativeValue) value).getIdAsInt();
+ } else if (value instanceof Integer) {
+ qvId = (Integer) value;
+ }
+ // TODO BL : not used ? => to remove
+ else {
+ qvId = Integer.valueOf(value.toString());
+ }
+ QualitativeValue qv = load(QualitativeValueImpl.class, qvId);
+ measurement.setQualitativeValue(qv);
+ }
+ }
+
+ public SortingMeasurement setSortingMeasurement(
+ SortingBatch sortingBatch, Integer recorderDepartmentId,
+ SampleCategoryEnum sampleCategory, Serializable value) {
+ Preconditions.checkNotNull(sampleCategory);
+ Preconditions.checkNotNull(value);
+
+ Integer pmfmId = sampleCategory.getFieldValue();
+
+ Caracteristic caracteristic = referentialService.getCaracteristic(pmfmId);
+ SortingMeasurement sortingMeasurement = catchBatchDao.getSortingMeasurement(
+ sortingBatch, pmfmId, recorderDepartmentId, true);
+ setMeasurement(sortingMeasurement, caracteristic, value);
+ return sortingMeasurement;
+ }
+
+ public SortingMeasurement setSortingMeasurement(
+ SortingBatch sortingBatch, Integer recorderDepartmentId,
+ Integer pmfmId, Serializable value) {
+ Preconditions.checkNotNull(pmfmId);
+ Preconditions.checkNotNull(value);
+
+ Caracteristic caracteristic = referentialService.getCaracteristic(pmfmId);
+ SortingMeasurement sortingMeasurement = catchBatchDao.getSortingMeasurement(
+ sortingBatch, pmfmId, recorderDepartmentId, true);
+ setMeasurement(sortingMeasurement, caracteristic, value);
+ return sortingMeasurement;
+ }
+}
Property changes on: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/batch/BatchPersistenceHelper.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/batch/ScientificCruiseCatchBatchValidator.java
===================================================================
--- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/batch/ScientificCruiseCatchBatchValidator.java 2013-03-27 21:44:37 UTC (rev 692)
+++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/batch/ScientificCruiseCatchBatchValidator.java 2013-03-27 21:49:05 UTC (rev 693)
@@ -33,7 +33,7 @@
import fr.ifremer.adagio.core.dao.data.batch.validator.CatchBatchValidationError;
import fr.ifremer.adagio.core.dao.data.batch.validator.CatchBatchValidator;
import fr.ifremer.adagio.core.dao.data.measure.SortingMeasurement;
-import fr.ifremer.tutti.persistence.service.BatchPersistenceService;
+import fr.ifremer.tutti.persistence.service.CatchBatchPersistenceService;
import fr.ifremer.tutti.persistence.service.TuttiEnumerationFile;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -54,7 +54,7 @@
LogFactory.getLog(ScientificCruiseCatchBatchValidator.class);
@Autowired
- protected BatchPersistenceService batchService;
+ protected CatchBatchPersistenceService batchService;
@Autowired
protected CatchBatchExtendDao catchBatchDao;
Deleted: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/BatchPersistenceServiceReadTest.java
===================================================================
--- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/BatchPersistenceServiceReadTest.java 2013-03-27 21:44:37 UTC (rev 692)
+++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/BatchPersistenceServiceReadTest.java 2013-03-27 21:49:05 UTC (rev 693)
@@ -1,201 +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.Maps;
-import fr.ifremer.adagio.core.dao.data.batch.validator.CatchBatchValidationException;
-import fr.ifremer.tutti.persistence.DatabaseResource;
-import fr.ifremer.tutti.persistence.entities.data.BatchContainer;
-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.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;
-import static org.junit.Assert.assertTrue;
-
-/**
- * To test {@link BatchPersistenceService} for read operation.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 1.0
- */
-public class BatchPersistenceServiceReadTest {
-
- @ClassRule
- public static final DatabaseResource dbResource = DatabaseResource.writeDb();
-
- protected BatchPersistenceService service;
-
- protected FishingOperationPersistenceService fishingOperationService;
-
- protected FishingOperation fishingOperation;
-
- @Before
- public void setUp() throws Exception {
- service = TuttiPersistenceServiceLocator.getBatchPersistenceService();
- fishingOperationService = TuttiPersistenceServiceLocator.getFishingOperationPersistenceService();
-
- List<FishingOperation> fishingOperations = fishingOperationService.getAllFishingOperation(dbResource.getFixtures().cruiseId());
- assertNotNull(fishingOperations);
- assertTrue(fishingOperations.size() > 0);
- fishingOperation = fishingOperations.get(0);
- assertNotNull(fishingOperation);
- assertNotNull(fishingOperation.getId());
- }
-
- @Test(expected = CatchBatchValidationException.class)
- public void getCatchBatchFromFishingOperation() throws Exception {
-
- //TODO-TC Change test when data will be Tutti-aware
- // old CGFS tree structure is still not valid
- service.getCatchBatchFromFishingOperation(fishingOperation.getId());
- }
-
- @Ignore
- @Test
- public void getRootSpeciesBatch(/*String fishingOperationId*/) {
- //TODO Do me!
- service.getRootSpeciesBatch(fishingOperation.getId());
- }
-
- @Ignore
- @Test
- public void getAllSpeciesBatchFrequency(/*String speciesBatchId*/) {
- //TODO Do me!
- }
-
- @Ignore
- @Test
- public void getRootBenthosBatch(/*String fishingOperationId*/) {
- //TODO Do me!
- }
-
-
- public static 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());
- }
- }
-
- public static 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());
- }
- }
-
- public static SpeciesBatch getSpeciesBatch(String fishingOperationId,
- String speciesBatchId) {
- BatchContainer<SpeciesBatch> rootSpeciesBatch = TuttiPersistenceServiceLocator.getBatchPersistenceService().getRootSpeciesBatch(fishingOperationId);
- return getSpeciesBatch(speciesBatchId, rootSpeciesBatch.getChildren());
- }
-
- public static 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/BatchPersistenceServiceWriteTest.java
===================================================================
--- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/BatchPersistenceServiceWriteTest.java 2013-03-27 21:44:37 UTC (rev 692)
+++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/BatchPersistenceServiceWriteTest.java 2013-03-27 21:49:05 UTC (rev 693)
@@ -1,884 +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 com.google.common.collect.Maps;
-import fr.ifremer.adagio.core.dao.data.batch.validator.CatchBatchValidationException;
-import fr.ifremer.tutti.persistence.DatabaseResource;
-import fr.ifremer.tutti.persistence.entities.data.BatchContainer;
-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 fr.ifremer.tutti.persistence.entities.referential.TuttiLocation;
-import org.junit.Assert;
-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 BatchPersistenceService} for write operation.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 1.0
- */
-public class BatchPersistenceServiceWriteTest {
-
- @ClassRule
- public static final DatabaseResource dbResource = DatabaseResource.writeDb();
-
- protected BatchPersistenceService service;
-
- protected CruisePersistenceService cruiseService;
-
- protected FishingOperationPersistenceService fishingOperationService;
-
- protected ReferentialPersistenceService referentialService;
-
- /*
- * Entities prepared in setUp() :
- * */
- protected Cruise cruise;
-
- protected FishingOperation fishingOperationNoCatchBatch;
-
- protected FishingOperation fishingOperationWithEmptyBatch;
-
- 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;
-
- @Before
- public void setUp() throws Exception {
- service = TuttiPersistenceServiceLocator.getBatchPersistenceService();
- cruiseService = TuttiPersistenceServiceLocator.getCruisePersistenceService();
- fishingOperationService = TuttiPersistenceServiceLocator.getFishingOperationPersistenceService();
- referentialService = TuttiPersistenceServiceLocator.getReferentialPersistenceService();
-
- species = referentialService.getAllSpecies();
- assertNotNull(species);
- assertTrue(species.size() > 2);
-
- cruise = cruiseService.getCruise(dbResource.getFixtures().cruiseId());
- cruise.setId(null);
- Calendar calendar = new GregorianCalendar();
- cruise.setBeginDate(calendar.getTime());
- calendar.add(Calendar.MONTH, 1); // add one month
- cruise.setEndDate(calendar.getTime());
- List<TuttiLocation> allHarbour = referentialService.getAllHarbour();
- Assert.assertNotNull(allHarbour);
- Assert.assertTrue(allHarbour.size() > 1);
- cruise.setDepartureLocation(allHarbour.get(0));
- cruise.setReturnLocation(allHarbour.get(1));
-
- cruise = cruiseService.createCruise(cruise);
-
- // Create a first operation, with no cacth batch : to test CatchBatch insert/update :
- List<FishingOperation> fishingOperations = fishingOperationService.getAllFishingOperation(dbResource.getFixtures().cruiseId());
- assertNotNull(fishingOperations);
- assertTrue(fishingOperations.size() > 0);
- fishingOperationNoCatchBatch = fishingOperations.get(0);
- fishingOperationNoCatchBatch = fishingOperationService.getFishingOperation(fishingOperationNoCatchBatch.getId());
- fishingOperationNoCatchBatch.setId(null);
- fishingOperationNoCatchBatch.setCruise(cruise);
- calendar.setTime(new Date());
- calendar.set(Calendar.HOUR_OF_DAY, 1);
- calendar.set(Calendar.MILLISECOND, 0);
- fishingOperationNoCatchBatch.setGearShootingStartDate(calendar.getTime());
- calendar.setTime(new Date());
- calendar.set(Calendar.HOUR_OF_DAY, 10);
- calendar.set(Calendar.MILLISECOND, 0);
- fishingOperationNoCatchBatch.setGearShootingEndDate(calendar.getTime());
- fishingOperationNoCatchBatch = fishingOperationService.createFishingOperation(fishingOperationNoCatchBatch);
-
- // Create a second operation, with no cacth batch : to test CatchBatch insert/update :
- fishingOperationWithEmptyBatch = fishingOperations.get(1);
- fishingOperationWithEmptyBatch = fishingOperationService.getFishingOperation(fishingOperationWithEmptyBatch.getId());
- fishingOperationWithEmptyBatch.setId(null);
- fishingOperationWithEmptyBatch.setCruise(cruise);
- calendar.setTime(new Date());
- calendar.set(Calendar.HOUR_OF_DAY, 11);
- calendar.set(Calendar.MILLISECOND, 0);
- fishingOperationWithEmptyBatch.setGearShootingStartDate(calendar.getTime());
- calendar.setTime(new Date());
- calendar.set(Calendar.HOUR_OF_DAY, 12);
- calendar.set(Calendar.MILLISECOND, 0);
- fishingOperationWithEmptyBatch.setGearShootingEndDate(calendar.getTime());
- fishingOperationWithEmptyBatch = fishingOperationService.createFishingOperation(fishingOperationWithEmptyBatch);
-
- catchBacth = new CatchBatch();
- catchBacth.setFishingOperation(fishingOperationWithEmptyBatch);
- catchBacth = service.createCatchBatch(catchBacth);
-
- 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 createAndSaveCatchBatch() throws Exception {
- CatchBatch catchBatch;
-
- catchBatch = new CatchBatch();
- catchBatch.setFishingOperation(fishingOperationNoCatchBatch);
-
- // -----------------------------------------------------------------------------
- // 1. Test with only mandatory properties
- // -----------------------------------------------------------------------------
-
- // Create and reload (test round trip)
- assertCreateAndReloadCatchBatch(catchBatch, fishingOperationNoCatchBatch.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);
- catchBatch.setSpeciesTotalLivingNotItemizedWeight(0.2f);
- catchBatch.setSpeciesTotalInertWeight(0.1f);
- }
- }
- // Hors Vrac : 10kg
- {
- catchBatch.setCatchTotalUnsortedWeight(10f);
-
- // Species
- {
- catchBatch.setSpeciesTotalUnsortedWeight(10f);
- }
- }
- // Rejet : 15kg
- catchBatch.setCatchTotalRejectedWeight(15f);
-
- // Create and reload (test round trip)
- assertCreateAndReloadCatchBatch(catchBatch, fishingOperationNoCatchBatch.getId());
-
- // -----------------------------------------------------------------------------
- // 2. Test save after modification
- // -----------------------------------------------------------------------------
- catchBatch.setCatchTotalSortedTremisWeight(null);
- catchBatch.setCatchTotalSortedCarousselWeight(null);
- catchBatch.setSpeciesTotalSortedWeight(null);
- catchBatch.setSpeciesTotalSampleSortedWeight(null);
- catchBatch.setCatchTotalUnsortedWeight(null);
- catchBatch.setSpeciesTotalUnsortedWeight(null);
-
- assertSaveAndReloadCatchBatch(catchBatch, fishingOperationNoCatchBatch.getId());
- }
-
- @Test
- public void createAndSaveSpeciesBatchAndFrequencies() {
- SpeciesBatch esp1Batch;
- SpeciesBatch esp2Batch;
- SpeciesBatch frequenciesParentBatch;
- SpeciesBatch batch;
- 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(fishingOperationNoCatchBatch);
- batch.setSpecies(taxon1);
- batch.setSampleCategoryType(SampleCategoryEnum.sortedUnsorted);
- batch.setSampleCategoryValue(vracQualitativeValue);
- batch.setSampleCategoryWeight(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.setSampleCategoryType(SampleCategoryEnum.sex);
- batch.setSampleCategoryValue(maleQualitativeValue);
- batch.setSampleCategoryWeight(2f);
- batch.setWeight(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.setSampleCategoryType(SampleCategoryEnum.sex);
- batch.setSampleCategoryValue(femaleQualitativeValue);
- batch.setSampleCategoryWeight(3f);
- batch.setWeight(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);
- batch.setSpecies(taxon2);
- batch.setSampleCategoryType(SampleCategoryEnum.sortedUnsorted);
- batch.setSampleCategoryValue(vracQualitativeValue);
- batch.setSampleCategoryWeight(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.setSampleCategoryWeight(2f);
- batch.setWeight(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.setComment("ESP2 - Vrac/7 UNK/1.75 ss-ech/1.11 Nombre/99");
- batch.setSampleCategoryType(SampleCategoryEnum.sex);
- batch.setSampleCategoryValue(unkQualitativeValue);
- batch.setSampleCategoryWeight(1.75f);
- batch.setWeight(1.11f);
- batch.setFishingOperation(fishingOperationWithEmptyBatch);
- batch.setNumber(99);
-
- // Save and reload, then check
- SpeciesBatch savedBatch = service.saveSpeciesBatch(batch);
- assertSpeciesBatch(savedBatch, batch, false);
- SpeciesBatch reloadedBatch = getSpeciesBatch(fishingOperationWithEmptyBatch.getId(), savedBatch.getId());
- assertSpeciesBatch(savedBatch, reloadedBatch, true);
-
- // Save batch for later
- frequenciesParentBatch = batch;
-
- // -----------------------------------------------------------------------------
- // 6. Test change species
- // -----------------------------------------------------------------------------
- esp2Batch.setSpecies(taxon1);
- service.changeSpeciesBatchSpecies(esp2Batch.getId(), taxon1);
- assertSpeciesBatch(savedBatch, batch, false);
- reloadedBatch = getSpeciesBatch(fishingOperationWithEmptyBatch.getId(), esp2Batch.getId());
- assertSpeciesBatch(esp2Batch, reloadedBatch, true);
-
- // -----------------------------------------------------------------------------
- // 7. Test get all root species
- // -----------------------------------------------------------------------------
- BatchContainer<SpeciesBatch> rootSpeciesBatc = service.getRootSpeciesBatch(fishingOperationWithEmptyBatch.getId());
- List<SpeciesBatch> rootSpeciesBatch = rootSpeciesBatc.getChildren();
- 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);
- }
- }
- // And remove the last item (should be deleted in DB)
- // Note: use a new list (everything list coming from service are not modifiable)
- createdFrequencies = Lists.newArrayList(createdFrequencies);
- createdFrequencies.remove(createdFrequencies.size() - 1);
-
- List<SpeciesBatchFrequency> savedFrequencies = service.saveSpeciesBatchFrequency(frequenciesParentBatch.getId(), createdFrequencies);
- assertBatchFrequencies(createdFrequencies, savedFrequencies, true);
- }
-
- @Test
- public void deleteSpeciesBatch(/* String id */) {
- SpeciesBatch esp1Batch;
- 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(fishingOperationWithEmptyBatch);
- batch.setSpecies(taxon1);
- batch.setSampleCategoryType(SampleCategoryEnum.sortedUnsorted);
- batch.setSampleCategoryValue(vracQualitativeValue);
- batch.setSampleCategoryWeight(5f);
- assertCreateAndReloadSpeciesBatch(batch, null);
- esp1Batch = batch;
-
- // batch : ESP1 Vrac/5 Male/2
- batch = new SpeciesBatch();
- batch.setParentBatch(esp1Batch);
- batch.setFishingOperation(fishingOperationWithEmptyBatch);
- batch.setSpecies(taxon1);
- batch.setSampleCategoryType(SampleCategoryEnum.sex);
- batch.setSampleCategoryValue(maleQualitativeValue);
- batch.setSampleCategoryWeight(2f);
- assertCreateAndReloadSpeciesBatch(batch, esp1Batch.getId());
-
- // Try to remove
- service.deleteSpeciesBatch(esp1Batch.getId());
-
- // Check if remove
- try {
- batch = getSpeciesBatch(fishingOperationWithEmptyBatch.getId(), esp1Batch.getId());
- assertNull(batch);
- } catch (DataRetrievalFailureException drfe) {
- assertNotNull(drfe);
- }
- }
-
-
- @Ignore
- @Test
- public void createAndSaveBenthosBatchAndFrequencies() {
- SpeciesBatch esp1Batch;
- SpeciesBatch esp2Batch;
- SpeciesBatch frequenciesParentBatch;
- SpeciesBatch batch;
- 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(fishingOperationNoCatchBatch);
- batch.setSpecies(taxon1);
- batch.setSampleCategoryType(SampleCategoryEnum.sortedUnsorted);
- batch.setSampleCategoryValue(vracQualitativeValue);
- batch.setSampleCategoryWeight(5f);
-
- assertCreateAndReloadBenthosBatch(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.setSampleCategoryType(SampleCategoryEnum.sex);
- batch.setSampleCategoryValue(maleQualitativeValue);
- batch.setSampleCategoryWeight(2f);
- batch.setWeight(1f);
- batch.setNumber(7);
-
- assertCreateAndReloadBenthosBatch(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.setSampleCategoryType(SampleCategoryEnum.sex);
- batch.setSampleCategoryValue(femaleQualitativeValue);
- batch.setSampleCategoryWeight(3f);
- batch.setWeight(null);
- batch.setNumber(14);
-
- assertCreateAndReloadBenthosBatch(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);
- batch.setSpecies(taxon2);
- batch.setSampleCategoryType(SampleCategoryEnum.sortedUnsorted);
- batch.setSampleCategoryValue(vracQualitativeValue);
- batch.setSampleCategoryWeight(7f);
-
- assertCreateAndReloadBenthosBatch(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.setSampleCategoryWeight(2f);
- batch.setWeight(1f);
- batch.setNumber(11);
-
- assertCreateAndReloadBenthosBatch(batch, batch.getParentBatch().getId());
-
- // -----------------------------------------------------------------------------
- // 5. Test save after modifications
- // -----------------------------------------------------------------------------
- // Batch : ESP2 - Vrac/7 UNK/1.75 ss-ech/1.11 Nombre/99
- batch.setComment("ESP2 - Vrac/7 UNK/1.75 ss-ech/1.11 Nombre/99");
- batch.setSampleCategoryType(SampleCategoryEnum.sex);
- batch.setSampleCategoryValue(unkQualitativeValue);
- batch.setSampleCategoryWeight(1.75f);
- batch.setWeight(1.11f);
- batch.setFishingOperation(fishingOperationWithEmptyBatch);
- batch.setNumber(99);
-
- // Save and reload, then check
- SpeciesBatch savedBatch = service.saveBenthosBatch(batch);
- assertSpeciesBatch(savedBatch, batch, false);
- SpeciesBatch reloadedBatch = getBenthosBatch(fishingOperationWithEmptyBatch.getId(), savedBatch.getId());
- assertSpeciesBatch(savedBatch, reloadedBatch, true);
-
- // Save batch for later
- frequenciesParentBatch = batch;
-
- // -----------------------------------------------------------------------------
- // 6. Test change species
- // -----------------------------------------------------------------------------
- esp2Batch.setSpecies(taxon1);
- service.changeSpeciesBatchSpecies(esp2Batch.getId(), taxon1);
- assertSpeciesBatch(savedBatch, batch, false);
- reloadedBatch = getSpeciesBatch(fishingOperationWithEmptyBatch.getId(), esp2Batch.getId());
- assertSpeciesBatch(esp2Batch, reloadedBatch, true);
-
- // -----------------------------------------------------------------------------
- // 7. Test get all root species
- // -----------------------------------------------------------------------------
- List<SpeciesBatch> rootSpeciesBatch = service.getRootSpeciesBatch(fishingOperationWithEmptyBatch.getId()).getChildren();
- 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);
- }
- }
- // And remove the last item (should be deleted in DB)
- createdFrequencies.remove(createdFrequencies.size() - 1);
- List<SpeciesBatchFrequency> savedFrequencies = service.saveSpeciesBatchFrequency(frequenciesParentBatch.getId(), frequencies);
- assertBatchFrequencies(createdFrequencies, savedFrequencies, true);
- }
-
- @Ignore
- @Test
- public void deleteBenthosBatch(/* String id */) {
- SpeciesBatch esp1Batch;
- 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(fishingOperationWithEmptyBatch);
- batch.setSpecies(taxon1);
- batch.setSampleCategoryType(SampleCategoryEnum.sortedUnsorted);
- batch.setSampleCategoryValue(vracQualitativeValue);
- batch.setSampleCategoryWeight(5f);
- assertCreateAndReloadBenthosBatch(batch, null);
- esp1Batch = batch;
-
- // batch : ESP1 Vrac/5 Male/2
- batch = new SpeciesBatch();
- batch.setParentBatch(esp1Batch);
- batch.setFishingOperation(fishingOperationWithEmptyBatch);
- batch.setSpecies(taxon1);
- batch.setSampleCategoryType(SampleCategoryEnum.sex);
- batch.setSampleCategoryValue(maleQualitativeValue);
- batch.setSampleCategoryWeight(2f);
- assertCreateAndReloadBenthosBatch(batch, esp1Batch.getId());
-
- // Try to remove
- service.deleteBenthosBatch(esp1Batch.getId());
-
- // Check if remove
- try {
- batch = getBenthosBatch(fishingOperationWithEmptyBatch.getId(), esp1Batch.getId());
- assertNull(batch);
- } catch (DataRetrievalFailureException drfe) {
- assertNotNull(drfe);
- }
- }
-
- protected void assertCreateAndReloadSpeciesBatch(SpeciesBatch batch, String parentBatchId) {
- batch.setFishingOperation(fishingOperationWithEmptyBatch);
-
- // Create batch
- SpeciesBatch createdBatch = service.createSpeciesBatch(batch, parentBatchId);
- assertSpeciesBatch(batch, createdBatch, false);
-
- // then reload (for round trip check)
- SpeciesBatch reloadedBatch = getSpeciesBatch(fishingOperationWithEmptyBatch.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 assertCreateAndReloadBenthosBatch(SpeciesBatch batch, String parentBatchId) {
- batch.setFishingOperation(fishingOperationWithEmptyBatch);
-
- // Create batch
- SpeciesBatch createdBatch = service.createBenthosBatch(batch, parentBatchId);
- assertSpeciesBatch(batch, createdBatch, false);
-
- // then reload (for round trip check)
- SpeciesBatch reloadedBatch = getBenthosBatch(fishingOperationWithEmptyBatch.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 assertCreateAndReloadCatchBatch(CatchBatch catchBatch, String fishingOperationId) {
- CatchBatch createdCatchBatch = service.createCatchBatch(catchBatch);
- assertNotNull(createdCatchBatch);
- assertNotNull(createdCatchBatch.getId());
- assertCatchBatch(catchBatch, createdCatchBatch, false);
-
- CatchBatch reloadedCatchBatch = null;
- try {
- reloadedCatchBatch = service.getCatchBatchFromFishingOperation(fishingOperationId);
- } catch (CatchBatchValidationException e) {
- Assert.fail(e.getMessage());
- }
- assertCatchBatch(createdCatchBatch, reloadedCatchBatch, true);
-
- catchBatch.setId(createdCatchBatch.getId());
- }
-
- protected void assertSaveAndReloadCatchBatch(CatchBatch catchBatch, String fishingOperationId) {
- CatchBatch savedCatchBatch = service.saveCatchBatch(catchBatch);
- assertNotNull(savedCatchBatch);
- assertNotNull(savedCatchBatch.getId());
- assertCatchBatch(catchBatch, savedCatchBatch, false);
-
- CatchBatch reloadedCatchBatch = null;
- try {
- reloadedCatchBatch = service.getCatchBatchFromFishingOperation(fishingOperationId);
- } catch (CatchBatchValidationException e) {
- Assert.fail(e.getMessage());
- }
- assertCatchBatch(savedCatchBatch, reloadedCatchBatch, true);
- }
-
- protected void assertCatchBatch(CatchBatch expectedCatchBatch, CatchBatch actualCatchBatch, boolean assertIdEquals) {
- if (expectedCatchBatch == null) {
- assertNull(actualCatchBatch);
- return;
- }
-
- assertNotNull(actualCatchBatch);
- if (assertIdEquals) {
- assertEquals(expectedCatchBatch.getId(), actualCatchBatch.getId());
- }
- assertEquals(expectedCatchBatch.getCatchTotalWeight(), actualCatchBatch.getCatchTotalWeight());
- assertEquals(expectedCatchBatch.getCatchTotalSortedCarousselWeight(), actualCatchBatch.getCatchTotalSortedCarousselWeight());
- assertEquals(expectedCatchBatch.getCatchTotalSortedTremisWeight(), actualCatchBatch.getCatchTotalSortedTremisWeight());
- assertEquals(expectedCatchBatch.getCatchTotalUnsortedWeight(), actualCatchBatch.getCatchTotalUnsortedWeight());
-
- assertEquals(expectedCatchBatch.getSpeciesTotalSampleSortedWeight(), actualCatchBatch.getSpeciesTotalSampleSortedWeight());
- assertEquals(expectedCatchBatch.getSpeciesTotalSortedWeight(), actualCatchBatch.getSpeciesTotalSortedWeight());
- assertEquals(expectedCatchBatch.getSpeciesTotalUnsortedWeight(), actualCatchBatch.getSpeciesTotalUnsortedWeight());
- assertEquals(expectedCatchBatch.getSpeciesTotalInertWeight(), actualCatchBatch.getSpeciesTotalInertWeight());
- assertEquals(expectedCatchBatch.getSpeciesTotalLivingNotItemizedWeight(), actualCatchBatch.getSpeciesTotalLivingNotItemizedWeight());
- }
-
- 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.getRootSpeciesBatch(fishingOperationId).getChildren());
- }
-
- protected SpeciesBatch getBenthosBatch(String fishingOperationId, String speciesBatchId) {
- return getSpeciesBatch(speciesBatchId, service.getRootBenthosBatch(fishingOperationId).getChildren());
- }
-
- 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;
- }
-}
Added: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceServiceReadTest.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-03-27 21:49:05 UTC (rev 693)
@@ -0,0 +1,188 @@
+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.BatchContainer;
+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.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;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * To test {@link BenthosBatchPersistenceService} for read operation.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.0
+ */
+@Ignore
+public class BenthosBatchPersistenceServiceReadTest {
+
+ @ClassRule
+ public static final DatabaseResource dbResource = DatabaseResource.writeDb();
+
+ protected BenthosBatchPersistenceService service;
+
+ protected FishingOperationPersistenceService fishingOperationService;
+
+ protected FishingOperation fishingOperation;
+
+ @Before
+ public void setUp() throws Exception {
+ service = TuttiPersistenceServiceLocator.getBenthosBatchPersistenceService();
+ fishingOperationService = TuttiPersistenceServiceLocator.getFishingOperationPersistenceService();
+
+ List<FishingOperation> fishingOperations = fishingOperationService.getAllFishingOperation(dbResource.getFixtures().cruiseId());
+ assertNotNull(fishingOperations);
+ assertTrue(fishingOperations.size() > 0);
+ fishingOperation = fishingOperations.get(0);
+ assertNotNull(fishingOperation);
+ assertNotNull(fishingOperation.getId());
+ }
+
+ @Ignore
+ @Test
+ public void getRootBenthosBatch(/*String fishingOperationId*/) {
+ //TODO Do me!
+ service.getRootBenthosBatch(fishingOperation.getId());
+ }
+
+ @Ignore
+ @Test
+ public void getAllBenthosBatchFrequency(/*String speciesBatchId*/) {
+ //TODO Do me!
+ service.getAllBenthosBatchFrequency(fishingOperation.getId());
+ }
+
+
+ public static 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());
+ }
+ }
+
+ public static 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());
+ }
+ }
+
+ public SpeciesBatch getSpeciesBatch(String fishingOperationId,
+ String speciesBatchId) {
+ BatchContainer<SpeciesBatch> rootSpeciesBatch = service.getRootBenthosBatch(fishingOperationId);
+ return getSpeciesBatch(speciesBatchId, rootSpeciesBatch.getChildren());
+ }
+
+ public static 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;
+ }
+
+}
Property changes on: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceServiceReadTest.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceServiceWriteTest.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-03-27 21:49:05 UTC (rev 693)
@@ -0,0 +1,533 @@
+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 fr.ifremer.tutti.persistence.entities.referential.TuttiLocation;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.ClassRule;
+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 BenthosBatchPersistenceService} for write operation.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.0
+ */
+public class BenthosBatchPersistenceServiceWriteTest {
+
+ @ClassRule
+ public static final DatabaseResource dbResource = DatabaseResource.writeDb();
+
+ protected BenthosBatchPersistenceService service;
+
+ protected CatchBatchPersistenceService catchBatchService;
+
+ protected CruisePersistenceService cruiseService;
+
+ protected FishingOperationPersistenceService fishingOperationService;
+
+ protected ReferentialPersistenceService referentialService;
+
+ /*
+ * Entities prepared in setUp() :
+ * */
+ protected Cruise cruise;
+
+ protected FishingOperation fishingOperationNoCatchBatch;
+
+ protected FishingOperation fishingOperationWithEmptyBatch;
+
+ 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;
+
+ @Before
+ public void setUp() throws Exception {
+
+ service = TuttiPersistenceServiceLocator.getBenthosBatchPersistenceService();
+ cruiseService = TuttiPersistenceServiceLocator.getCruisePersistenceService();
+ catchBatchService = TuttiPersistenceServiceLocator.getCatchBatchPersistenceService();
+ fishingOperationService = TuttiPersistenceServiceLocator.getFishingOperationPersistenceService();
+ referentialService = TuttiPersistenceServiceLocator.getReferentialPersistenceService();
+
+ species = referentialService.getAllSpecies();
+ assertNotNull(species);
+ assertTrue(species.size() > 2);
+
+ cruise = cruiseService.getCruise(dbResource.getFixtures().cruiseId());
+ cruise.setId((String) null);
+ Calendar calendar = new GregorianCalendar();
+ cruise.setBeginDate(calendar.getTime());
+ calendar.add(Calendar.MONTH, 1); // add one month
+ cruise.setEndDate(calendar.getTime());
+ List<TuttiLocation> allHarbour = referentialService.getAllHarbour();
+ Assert.assertNotNull(allHarbour);
+ Assert.assertTrue(allHarbour.size() > 1);
+ cruise.setDepartureLocation(allHarbour.get(0));
+ cruise.setReturnLocation(allHarbour.get(1));
+
+ cruise = cruiseService.createCruise(cruise);
+
+ // Create a first operation, with no cacth batch : to test CatchBatch insert/update :
+ List<FishingOperation> fishingOperations = fishingOperationService.getAllFishingOperation(dbResource.getFixtures().cruiseId());
+ assertNotNull(fishingOperations);
+ assertTrue(fishingOperations.size() > 0);
+ fishingOperationNoCatchBatch = fishingOperations.get(0);
+ fishingOperationNoCatchBatch = fishingOperationService.getFishingOperation(fishingOperationNoCatchBatch.getId());
+ fishingOperationNoCatchBatch.setId((String) null);
+ fishingOperationNoCatchBatch.setCruise(cruise);
+ calendar.setTime(new Date());
+ calendar.set(Calendar.HOUR_OF_DAY, 1);
+ calendar.set(Calendar.MILLISECOND, 0);
+ fishingOperationNoCatchBatch.setGearShootingStartDate(calendar.getTime());
+ calendar.setTime(new Date());
+ calendar.set(Calendar.HOUR_OF_DAY, 10);
+ calendar.set(Calendar.MILLISECOND, 0);
+ fishingOperationNoCatchBatch.setGearShootingEndDate(calendar.getTime());
+ fishingOperationNoCatchBatch = fishingOperationService.createFishingOperation(fishingOperationNoCatchBatch);
+
+ // Create a second operation, with no cacth batch : to test CatchBatch insert/update :
+ fishingOperationWithEmptyBatch = fishingOperations.get(1);
+ fishingOperationWithEmptyBatch = fishingOperationService.getFishingOperation(fishingOperationWithEmptyBatch.getId());
+ fishingOperationWithEmptyBatch.setId((String) null);
+ fishingOperationWithEmptyBatch.setCruise(cruise);
+ calendar.setTime(new Date());
+ calendar.set(Calendar.HOUR_OF_DAY, 11);
+ calendar.set(Calendar.MILLISECOND, 0);
+ fishingOperationWithEmptyBatch.setGearShootingStartDate(calendar.getTime());
+ calendar.setTime(new Date());
+ calendar.set(Calendar.HOUR_OF_DAY, 12);
+ calendar.set(Calendar.MILLISECOND, 0);
+ fishingOperationWithEmptyBatch.setGearShootingEndDate(calendar.getTime());
+ fishingOperationWithEmptyBatch = fishingOperationService.createFishingOperation(fishingOperationWithEmptyBatch);
+
+ catchBacth = new CatchBatch();
+ catchBacth.setFishingOperation(fishingOperationWithEmptyBatch);
+ catchBacth = catchBatchService.createCatchBatch(catchBacth);
+
+ 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 createAndSaveBenthosBatchAndFrequencies() {
+ SpeciesBatch esp1Batch;
+ SpeciesBatch esp2Batch;
+ SpeciesBatch frequenciesParentBatch;
+ SpeciesBatch batch;
+ 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(fishingOperationNoCatchBatch);
+ batch.setSpecies(taxon1);
+ batch.setSampleCategoryType(SampleCategoryEnum.sortedUnsorted);
+ batch.setSampleCategoryValue(vracQualitativeValue);
+ batch.setSampleCategoryWeight(5f);
+
+ assertCreateAndReloadBenthosBatch(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((String) null);
+ batch.setParentBatch(esp1Batch);
+ batch.setSpecies(taxon1);
+ batch.setComment("ESP1 - Vrac/5 Male/2 ss-ech/1 Nombre/7");
+ batch.setSampleCategoryType(SampleCategoryEnum.sex);
+ batch.setSampleCategoryValue(maleQualitativeValue);
+ batch.setSampleCategoryWeight(2f);
+ batch.setWeight(1f);
+ batch.setNumber(7);
+
+ assertCreateAndReloadBenthosBatch(batch, batch.getParentBatch().getId());
+
+ // -----------------------------------------------------------------------------
+ // 3. Test child "Female/2"
+ // -----------------------------------------------------------------------------
+ // Batch : ESP1 - Vrac/5 Female/3 Nombre/14
+ batch = new SpeciesBatch();
+ batch.setId((String) null);
+ batch.setParentBatch(esp1Batch);
+ batch.setSpecies(taxon1);
+ batch.setComment("ESP1 - Vrac/5 Female/3 Nombre/14");
+ batch.setSampleCategoryType(SampleCategoryEnum.sex);
+ batch.setSampleCategoryValue(femaleQualitativeValue);
+ batch.setSampleCategoryWeight(3f);
+ batch.setWeight(null);
+ batch.setNumber(14);
+
+ assertCreateAndReloadBenthosBatch(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);
+ batch.setSpecies(taxon2);
+ batch.setSampleCategoryType(SampleCategoryEnum.sortedUnsorted);
+ batch.setSampleCategoryValue(vracQualitativeValue);
+ batch.setSampleCategoryWeight(7f);
+
+ assertCreateAndReloadBenthosBatch(batch, null);
+ esp2Batch = batch;
+
+ // Batch : ESP2 - Vrac/7 UNK/2 ss-ech/1 Nombre/11
+ batch = new SpeciesBatch();
+ batch.setId((String) 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.setSampleCategoryWeight(2f);
+ batch.setWeight(1f);
+ batch.setNumber(11);
+
+ assertCreateAndReloadBenthosBatch(batch, batch.getParentBatch().getId());
+
+ // -----------------------------------------------------------------------------
+ // 5. Test save after modifications
+ // -----------------------------------------------------------------------------
+ // Batch : ESP2 - Vrac/7 UNK/1.75 ss-ech/1.11 Nombre/99
+ batch.setComment("ESP2 - Vrac/7 UNK/1.75 ss-ech/1.11 Nombre/99");
+ batch.setSampleCategoryType(SampleCategoryEnum.sex);
+ batch.setSampleCategoryValue(unkQualitativeValue);
+ batch.setSampleCategoryWeight(1.75f);
+ batch.setWeight(1.11f);
+ batch.setFishingOperation(fishingOperationWithEmptyBatch);
+ batch.setNumber(99);
+
+ // Save and reload, then check
+ SpeciesBatch savedBatch = service.saveBenthosBatch(batch);
+ assertSpeciesBatch(savedBatch, batch, false);
+ SpeciesBatch reloadedBatch = getBenthosBatch(fishingOperationWithEmptyBatch.getId(), savedBatch.getId());
+ assertSpeciesBatch(savedBatch, reloadedBatch, true);
+
+ // Save batch for later
+ frequenciesParentBatch = batch;
+
+ // -----------------------------------------------------------------------------
+ // 6. Test change species
+ // -----------------------------------------------------------------------------
+ esp2Batch.setSpecies(taxon1);
+ service.changeBenthosBatchSpecies(esp2Batch.getId(), taxon1);
+ assertSpeciesBatch(savedBatch, batch, false);
+ reloadedBatch = getBenthosBatch(fishingOperationWithEmptyBatch.getId(), esp2Batch.getId());
+ assertSpeciesBatch(esp2Batch, reloadedBatch, true);
+
+ // -----------------------------------------------------------------------------
+ // 7. Test get all root species
+ // -----------------------------------------------------------------------------
+ List<SpeciesBatch> rootSpeciesBatch = service.getRootBenthosBatch(fishingOperationWithEmptyBatch.getId()).getChildren();
+ 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 = assertCreateAndReloadBenthosBatchFrequency(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);
+ }
+ }
+ // And remove the last item (should be deleted in DB)
+ // Note: use a new list (everything list coming from service are not modifiable)
+ createdFrequencies = Lists.newArrayList(createdFrequencies);
+ createdFrequencies.remove(createdFrequencies.size() - 1);
+
+ List<SpeciesBatchFrequency> savedFrequencies = service.saveBenthosBatchFrequency(frequenciesParentBatch.getId(), createdFrequencies);
+ assertBatchFrequencies(createdFrequencies, savedFrequencies, true);
+ }
+
+ @Test
+ public void deleteBenthosBatch(/* String id */) {
+ SpeciesBatch esp1Batch;
+ 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(fishingOperationWithEmptyBatch);
+ batch.setSpecies(taxon1);
+ batch.setSampleCategoryType(SampleCategoryEnum.sortedUnsorted);
+ batch.setSampleCategoryValue(vracQualitativeValue);
+ batch.setSampleCategoryWeight(5f);
+ assertCreateAndReloadBenthosBatch(batch, null);
+ esp1Batch = batch;
+
+ // batch : ESP1 Vrac/5 Male/2
+ batch = new SpeciesBatch();
+ batch.setParentBatch(esp1Batch);
+ batch.setFishingOperation(fishingOperationWithEmptyBatch);
+ batch.setSpecies(taxon1);
+ batch.setSampleCategoryType(SampleCategoryEnum.sex);
+ batch.setSampleCategoryValue(maleQualitativeValue);
+ batch.setSampleCategoryWeight(2f);
+ assertCreateAndReloadBenthosBatch(batch, esp1Batch.getId());
+
+ // Try to remove
+ service.deleteBenthosBatch(esp1Batch.getId());
+
+ // Check if remove
+ try {
+ batch = getBenthosBatch(fishingOperationWithEmptyBatch.getId(), esp1Batch.getId());
+ assertNull(batch);
+ } catch (DataRetrievalFailureException drfe) {
+ assertNotNull(drfe);
+ }
+ }
+
+ protected void assertCreateAndReloadBenthosBatch(SpeciesBatch batch, String parentBatchId) {
+ batch.setFishingOperation(fishingOperationWithEmptyBatch);
+
+ // Create batch
+ SpeciesBatch createdBatch = service.createBenthosBatch(batch, parentBatchId);
+ assertSpeciesBatch(batch, createdBatch, false);
+
+ // then reload (for round trip check)
+ SpeciesBatch reloadedBatch = getBenthosBatch(fishingOperationWithEmptyBatch.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> assertCreateAndReloadBenthosBatchFrequency(List<SpeciesBatchFrequency> frequencies, String parentBatchId) {
+
+ // Create batch
+ List<SpeciesBatchFrequency> createdFrequencies = service.saveBenthosBatchFrequency(parentBatchId, frequencies);
+ assertBatchFrequencies(frequencies, createdFrequencies, false);
+
+ // then reload (for round trip check)
+ List<SpeciesBatchFrequency> reloadedFrequencies = service.getAllBenthosBatchFrequency(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 getBenthosBatch(String fishingOperationId, String speciesBatchId) {
+ return getSpeciesBatch(speciesBatchId, service.getRootBenthosBatch(fishingOperationId).getChildren());
+ }
+
+ 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;
+ }
+}
Property changes on: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceServiceWriteTest.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Copied: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/CatchBatchPersistenceServiceReadTest.java (from rev 684, trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/BatchPersistenceServiceReadTest.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-03-27 21:49:05 UTC (rev 693)
@@ -0,0 +1,77 @@
+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.adagio.core.dao.data.batch.validator.CatchBatchValidationException;
+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.Test;
+
+import java.util.List;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * To test {@link CatchBatchPersistenceService} for read operation.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.0
+ */
+public class CatchBatchPersistenceServiceReadTest {
+
+ @ClassRule
+ public static final DatabaseResource dbResource = DatabaseResource.writeDb();
+
+ protected CatchBatchPersistenceService service;
+
+ protected FishingOperationPersistenceService fishingOperationService;
+
+ protected FishingOperation fishingOperation;
+
+ @Before
+ public void setUp() throws Exception {
+ service = TuttiPersistenceServiceLocator.getCatchBatchPersistenceService();
+ fishingOperationService = TuttiPersistenceServiceLocator.getFishingOperationPersistenceService();
+
+ List<FishingOperation> fishingOperations = fishingOperationService.getAllFishingOperation(dbResource.getFixtures().cruiseId());
+ assertNotNull(fishingOperations);
+ assertTrue(fishingOperations.size() > 0);
+ fishingOperation = fishingOperations.get(0);
+ assertNotNull(fishingOperation);
+ assertNotNull(fishingOperation.getId());
+ }
+
+ @Test(expected = CatchBatchValidationException.class)
+ public void getCatchBatchFromFishingOperation() throws Exception {
+
+ //TODO-TC Change test when data will be Tutti-aware
+ // old CGFS tree structure is still not valid
+ service.getCatchBatchFromFishingOperation(fishingOperation.getId());
+ }
+
+}
Copied: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/CatchBatchPersistenceServiceWriteTest.java (from rev 684, trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/BatchPersistenceServiceWriteTest.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-03-27 21:49:05 UTC (rev 693)
@@ -0,0 +1,323 @@
+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.adagio.core.dao.data.batch.validator.CatchBatchValidationException;
+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.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 fr.ifremer.tutti.persistence.entities.referential.TuttiLocation;
+import org.junit.Assert;
+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.assertNull;
+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;
+
+ /*
+ * Entities prepared in setUp() :
+ * */
+ protected Cruise cruise;
+
+ protected FishingOperation fishingOperationNoCatchBatch;
+
+ protected FishingOperation fishingOperationWithEmptyBatch;
+
+ 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;
+
+ @Before
+ public void setUp() throws Exception {
+ service = TuttiPersistenceServiceLocator.getCatchBatchPersistenceService();
+ cruiseService = TuttiPersistenceServiceLocator.getCruisePersistenceService();
+ fishingOperationService = TuttiPersistenceServiceLocator.getFishingOperationPersistenceService();
+ referentialService = TuttiPersistenceServiceLocator.getReferentialPersistenceService();
+
+ species = referentialService.getAllSpecies();
+ assertNotNull(species);
+ assertTrue(species.size() > 2);
+
+ cruise = cruiseService.getCruise(dbResource.getFixtures().cruiseId());
+ cruise.setId((String) null);
+ Calendar calendar = new GregorianCalendar();
+ cruise.setBeginDate(calendar.getTime());
+ calendar.add(Calendar.MONTH, 1); // add one month
+ cruise.setEndDate(calendar.getTime());
+ List<TuttiLocation> allHarbour = referentialService.getAllHarbour();
+ Assert.assertNotNull(allHarbour);
+ Assert.assertTrue(allHarbour.size() > 1);
+ cruise.setDepartureLocation(allHarbour.get(0));
+ cruise.setReturnLocation(allHarbour.get(1));
+
+ cruise = cruiseService.createCruise(cruise);
+
+ // Create a first operation, with no cacth batch : to test CatchBatch insert/update :
+ List<FishingOperation> fishingOperations = fishingOperationService.getAllFishingOperation(dbResource.getFixtures().cruiseId());
+ assertNotNull(fishingOperations);
+ assertTrue(fishingOperations.size() > 0);
+ fishingOperationNoCatchBatch = fishingOperations.get(0);
+ fishingOperationNoCatchBatch = fishingOperationService.getFishingOperation(fishingOperationNoCatchBatch.getId());
+ fishingOperationNoCatchBatch.setId((String) null);
+ fishingOperationNoCatchBatch.setCruise(cruise);
+ calendar.setTime(new Date());
+ calendar.set(Calendar.HOUR_OF_DAY, 1);
+ calendar.set(Calendar.MILLISECOND, 0);
+ fishingOperationNoCatchBatch.setGearShootingStartDate(calendar.getTime());
+ calendar.setTime(new Date());
+ calendar.set(Calendar.HOUR_OF_DAY, 10);
+ calendar.set(Calendar.MILLISECOND, 0);
+ fishingOperationNoCatchBatch.setGearShootingEndDate(calendar.getTime());
+ fishingOperationNoCatchBatch = fishingOperationService.createFishingOperation(fishingOperationNoCatchBatch);
+
+ // Create a second operation, with no cacth batch : to test CatchBatch insert/update :
+ fishingOperationWithEmptyBatch = fishingOperations.get(1);
+ fishingOperationWithEmptyBatch = fishingOperationService.getFishingOperation(fishingOperationWithEmptyBatch.getId());
+ fishingOperationWithEmptyBatch.setId((String) null);
+ fishingOperationWithEmptyBatch.setCruise(cruise);
+ calendar.setTime(new Date());
+ calendar.set(Calendar.HOUR_OF_DAY, 11);
+ calendar.set(Calendar.MILLISECOND, 0);
+ fishingOperationWithEmptyBatch.setGearShootingStartDate(calendar.getTime());
+ calendar.setTime(new Date());
+ calendar.set(Calendar.HOUR_OF_DAY, 12);
+ calendar.set(Calendar.MILLISECOND, 0);
+ fishingOperationWithEmptyBatch.setGearShootingEndDate(calendar.getTime());
+ fishingOperationWithEmptyBatch = fishingOperationService.createFishingOperation(fishingOperationWithEmptyBatch);
+
+ catchBacth = new CatchBatch();
+ catchBacth.setFishingOperation(fishingOperationWithEmptyBatch);
+ catchBacth = service.createCatchBatch(catchBacth);
+
+ 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 createAndSaveCatchBatch() throws Exception {
+ CatchBatch catchBatch;
+
+ catchBatch = new CatchBatch();
+ catchBatch.setFishingOperation(fishingOperationNoCatchBatch);
+
+ // -----------------------------------------------------------------------------
+ // 1. Test with only mandatory properties
+ // -----------------------------------------------------------------------------
+
+ // Create and reload (test round trip)
+ assertCreateAndReloadCatchBatch(catchBatch, fishingOperationNoCatchBatch.getId());
+
+ // -----------------------------------------------------------------------------
+ // 2. Test with all properties
+ // -----------------------------------------------------------------------------
+ catchBatch.setId((String) 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);
+ catchBatch.setSpeciesTotalLivingNotItemizedWeight(0.2f);
+ catchBatch.setSpeciesTotalInertWeight(0.1f);
+ }
+
+ // Benthos
+ {
+ catchBatch.setBenthosTotalSortedWeight(24f);
+ catchBatch.setBenthosTotalSampleSortedWeight(16f);
+ catchBatch.setBenthosTotalLivingNotItemizedWeight(0.4f);
+ catchBatch.setBenthosTotalInertWeight(0.2f);
+ }
+ }
+ // Hors Vrac : 10kg
+ {
+ catchBatch.setCatchTotalUnsortedWeight(10f);
+
+ // Species
+ {
+ catchBatch.setSpeciesTotalUnsortedWeight(10f);
+ }
+ // Benthos
+ {
+ catchBatch.setBenthosTotalUnsortedWeight(20f);
+ }
+ }
+ // Rejet : 15kg
+ catchBatch.setCatchTotalRejectedWeight(15f);
+
+ // Create and reload (test round trip)
+ assertCreateAndReloadCatchBatch(catchBatch, fishingOperationNoCatchBatch.getId());
+
+ // -----------------------------------------------------------------------------
+ // 2. Test save after modification
+ // -----------------------------------------------------------------------------
+ catchBatch.setCatchTotalSortedTremisWeight(null);
+ catchBatch.setCatchTotalSortedCarousselWeight(null);
+ catchBatch.setSpeciesTotalSortedWeight(null);
+ catchBatch.setSpeciesTotalSampleSortedWeight(null);
+ catchBatch.setCatchTotalUnsortedWeight(null);
+ catchBatch.setSpeciesTotalUnsortedWeight(null);
+
+ assertSaveAndReloadCatchBatch(catchBatch, fishingOperationNoCatchBatch.getId());
+ }
+
+ protected void assertCreateAndReloadCatchBatch(CatchBatch catchBatch, String fishingOperationId) {
+ CatchBatch createdCatchBatch = service.createCatchBatch(catchBatch);
+ assertNotNull(createdCatchBatch);
+ assertNotNull(createdCatchBatch.getId());
+ assertCatchBatch(catchBatch, createdCatchBatch, false);
+
+ CatchBatch reloadedCatchBatch = null;
+ try {
+ reloadedCatchBatch = service.getCatchBatchFromFishingOperation(fishingOperationId);
+ } catch (CatchBatchValidationException e) {
+ Assert.fail(e.getMessage());
+ }
+ assertCatchBatch(createdCatchBatch, reloadedCatchBatch, true);
+
+ catchBatch.setId(createdCatchBatch.getId());
+ }
+
+ protected void assertSaveAndReloadCatchBatch(CatchBatch catchBatch, String fishingOperationId) {
+ CatchBatch savedCatchBatch = service.saveCatchBatch(catchBatch);
+ assertNotNull(savedCatchBatch);
+ assertNotNull(savedCatchBatch.getId());
+ assertCatchBatch(catchBatch, savedCatchBatch, false);
+
+ CatchBatch reloadedCatchBatch = null;
+ try {
+ reloadedCatchBatch = service.getCatchBatchFromFishingOperation(fishingOperationId);
+ } catch (CatchBatchValidationException e) {
+ Assert.fail(e.getMessage());
+ }
+ assertCatchBatch(savedCatchBatch, reloadedCatchBatch, true);
+ }
+
+ protected void assertCatchBatch(CatchBatch expectedCatchBatch, CatchBatch actualCatchBatch, boolean assertIdEquals) {
+ if (expectedCatchBatch == null) {
+ assertNull(actualCatchBatch);
+ return;
+ }
+
+ assertNotNull(actualCatchBatch);
+ if (assertIdEquals) {
+ assertEquals(expectedCatchBatch.getId(), actualCatchBatch.getId());
+ }
+ assertEquals(expectedCatchBatch.getCatchTotalWeight(), actualCatchBatch.getCatchTotalWeight());
+ assertEquals(expectedCatchBatch.getCatchTotalSortedCarousselWeight(), actualCatchBatch.getCatchTotalSortedCarousselWeight());
+ assertEquals(expectedCatchBatch.getCatchTotalSortedTremisWeight(), actualCatchBatch.getCatchTotalSortedTremisWeight());
+ assertEquals(expectedCatchBatch.getCatchTotalUnsortedWeight(), actualCatchBatch.getCatchTotalUnsortedWeight());
+
+ assertEquals(expectedCatchBatch.getSpeciesTotalSampleSortedWeight(), actualCatchBatch.getSpeciesTotalSampleSortedWeight());
+ assertEquals(expectedCatchBatch.getSpeciesTotalSortedWeight(), actualCatchBatch.getSpeciesTotalSortedWeight());
+ assertEquals(expectedCatchBatch.getSpeciesTotalUnsortedWeight(), actualCatchBatch.getSpeciesTotalUnsortedWeight());
+ assertEquals(expectedCatchBatch.getSpeciesTotalInertWeight(), actualCatchBatch.getSpeciesTotalInertWeight());
+ assertEquals(expectedCatchBatch.getSpeciesTotalLivingNotItemizedWeight(), actualCatchBatch.getSpeciesTotalLivingNotItemizedWeight());
+
+ assertEquals(expectedCatchBatch.getBenthosTotalSampleSortedWeight(), actualCatchBatch.getBenthosTotalSampleSortedWeight());
+ assertEquals(expectedCatchBatch.getBenthosTotalSortedWeight(), actualCatchBatch.getBenthosTotalSortedWeight());
+ assertEquals(expectedCatchBatch.getBenthosTotalUnsortedWeight(), actualCatchBatch.getBenthosTotalUnsortedWeight());
+ assertEquals(expectedCatchBatch.getBenthosTotalInertWeight(), actualCatchBatch.getBenthosTotalInertWeight());
+ assertEquals(expectedCatchBatch.getBenthosTotalLivingNotItemizedWeight(), actualCatchBatch.getBenthosTotalLivingNotItemizedWeight());
+ }
+}
Modified: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/CruisePersistenceServiceWriteTest.java
===================================================================
--- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/CruisePersistenceServiceWriteTest.java 2013-03-27 21:44:37 UTC (rev 692)
+++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/CruisePersistenceServiceWriteTest.java 2013-03-27 21:49:05 UTC (rev 693)
@@ -82,7 +82,7 @@
// -----------------------------------------------------------------------------
// 1. Test with all properties filled
// -----------------------------------------------------------------------------
- cruise.setId(null);
+ cruise.setId((String)null);
cruise.setName("Unit-test-" + System.currentTimeMillis());
@@ -148,7 +148,7 @@
// -----------------------------------------------------------------------------
// 2. Test with only mandatory properties
// -----------------------------------------------------------------------------
- createdCruise.setId(null);
+ createdCruise.setId((String)null);
createdCruise.setHeadOfMission(null);
// createdCruise.setBeginDate(cruise.getBeginDate());
// createdCruise.setEndDate(cruise.getEndDate());
@@ -203,7 +203,7 @@
// -----------------------------------------------------------------------------
Cruise cruise = service.getCruise(dbResource.getFixtures().cruiseId());
- cruise.setId(null);
+ cruise.setId((String)null);
Calendar calendar = new GregorianCalendar();
cruise.setBeginDate(calendar.getTime());
Modified: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceServiceWriteTest.java
===================================================================
--- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceServiceWriteTest.java 2013-03-27 21:44:37 UTC (rev 692)
+++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceServiceWriteTest.java 2013-03-27 21:49:05 UTC (rev 693)
@@ -87,7 +87,7 @@
// Duplicate an existing cruise, to attach new fishing operations
cruise = cruiseService.getCruise(dbResource.getFixtures().cruiseId());
- cruise.setId(null);
+ cruise.setId((String)null);
cruise.setName("Unit-test-" + System.currentTimeMillis());
Calendar calendar = new GregorianCalendar();
cruise.setBeginDate(calendar.getTime());
@@ -206,7 +206,7 @@
// 2. Test with all properties set
// -----------------------------------------------------------------------------
// Set properties
- fishingOperation.setId(null);
+ fishingOperation.setId((String)null);
fishingOperation.setStationNumber("STA2");
fishingOperation.setFishingOperationNumber(2);
fishingOperation.setMultirigAggregation("1");
@@ -319,7 +319,7 @@
// - 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);
+ fishingOperation.setId((String)null);
// Find and set a gear not used in the cruise
List<Gear> gears = referentialService.getAllFishingGear();
Copied: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceReadTest.java (from rev 684, trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/BatchPersistenceServiceReadTest.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-03-27 21:49:05 UTC (rev 693)
@@ -0,0 +1,193 @@
+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.BatchContainer;
+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.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;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * To test {@link SpeciesBatchPersistenceService} for read operation.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.0
+ */
+@Ignore
+public class SpeciesBatchPersistenceServiceReadTest {
+
+ @ClassRule
+ public static final DatabaseResource dbResource = DatabaseResource.writeDb();
+
+ protected SpeciesBatchPersistenceService service;
+
+ protected FishingOperationPersistenceService fishingOperationService;
+
+ protected FishingOperation fishingOperation;
+
+ @Before
+ public void setUp() throws Exception {
+ service = TuttiPersistenceServiceLocator.getSpeciesBatchPersistenceService();
+ fishingOperationService = TuttiPersistenceServiceLocator.getFishingOperationPersistenceService();
+
+ List<FishingOperation> fishingOperations = fishingOperationService.getAllFishingOperation(dbResource.getFixtures().cruiseId());
+ assertNotNull(fishingOperations);
+ assertTrue(fishingOperations.size() > 0);
+ fishingOperation = fishingOperations.get(0);
+ assertNotNull(fishingOperation);
+ assertNotNull(fishingOperation.getId());
+ }
+
+ @Ignore
+ @Test
+ public void getRootSpeciesBatch(/*String fishingOperationId*/) {
+ //TODO Do me!
+ service.getRootSpeciesBatch(fishingOperation.getId());
+ }
+
+ @Ignore
+ @Test
+ public void getAllSpeciesBatchFrequency(/*String speciesBatchId*/) {
+ //TODO Do me!
+ }
+
+ @Ignore
+ @Test
+ public void getRootBenthosBatch(/*String fishingOperationId*/) {
+ //TODO Do me!
+ }
+
+
+ public static 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());
+ }
+ }
+
+ public static 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());
+ }
+ }
+
+ public SpeciesBatch getSpeciesBatch(String fishingOperationId,
+ String speciesBatchId) {
+ BatchContainer<SpeciesBatch> rootSpeciesBatch = service.getRootSpeciesBatch(fishingOperationId);
+ return getSpeciesBatch(speciesBatchId, rootSpeciesBatch.getChildren());
+ }
+
+ public static 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;
+ }
+
+}
Copied: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceWriteTest.java (from rev 684, trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/BatchPersistenceServiceWriteTest.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-03-27 21:49:05 UTC (rev 693)
@@ -0,0 +1,534 @@
+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.BatchContainer;
+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 fr.ifremer.tutti.persistence.entities.referential.TuttiLocation;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.ClassRule;
+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 1.0
+ */
+public class SpeciesBatchPersistenceServiceWriteTest {
+
+ @ClassRule
+ public static final DatabaseResource dbResource = DatabaseResource.writeDb();
+
+ protected SpeciesBatchPersistenceService service;
+
+ protected CatchBatchPersistenceService catchBatchService;
+
+ protected CruisePersistenceService cruiseService;
+
+ protected FishingOperationPersistenceService fishingOperationService;
+
+ protected ReferentialPersistenceService referentialService;
+
+ /*
+ * Entities prepared in setUp() :
+ * */
+ protected Cruise cruise;
+
+ protected FishingOperation fishingOperationNoCatchBatch;
+
+ protected FishingOperation fishingOperationWithEmptyBatch;
+
+ 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;
+
+ @Before
+ public void setUp() throws Exception {
+
+ service = TuttiPersistenceServiceLocator.getSpeciesBatchPersistenceService();
+ cruiseService = TuttiPersistenceServiceLocator.getCruisePersistenceService();
+ catchBatchService = TuttiPersistenceServiceLocator.getCatchBatchPersistenceService();
+ fishingOperationService = TuttiPersistenceServiceLocator.getFishingOperationPersistenceService();
+ referentialService = TuttiPersistenceServiceLocator.getReferentialPersistenceService();
+
+ species = referentialService.getAllSpecies();
+ assertNotNull(species);
+ assertTrue(species.size() > 2);
+
+ cruise = cruiseService.getCruise(dbResource.getFixtures().cruiseId());
+ cruise.setId((String) null);
+ Calendar calendar = new GregorianCalendar();
+ cruise.setBeginDate(calendar.getTime());
+ calendar.add(Calendar.MONTH, 1); // add one month
+ cruise.setEndDate(calendar.getTime());
+ List<TuttiLocation> allHarbour = referentialService.getAllHarbour();
+ Assert.assertNotNull(allHarbour);
+ Assert.assertTrue(allHarbour.size() > 1);
+ cruise.setDepartureLocation(allHarbour.get(0));
+ cruise.setReturnLocation(allHarbour.get(1));
+
+ cruise = cruiseService.createCruise(cruise);
+
+ // Create a first operation, with no cacth batch : to test CatchBatch insert/update :
+ List<FishingOperation> fishingOperations = fishingOperationService.getAllFishingOperation(dbResource.getFixtures().cruiseId());
+ assertNotNull(fishingOperations);
+ assertTrue(fishingOperations.size() > 0);
+ fishingOperationNoCatchBatch = fishingOperations.get(0);
+ fishingOperationNoCatchBatch = fishingOperationService.getFishingOperation(fishingOperationNoCatchBatch.getId());
+ fishingOperationNoCatchBatch.setId((String) null);
+ fishingOperationNoCatchBatch.setCruise(cruise);
+ calendar.setTime(new Date());
+ calendar.set(Calendar.HOUR_OF_DAY, 1);
+ calendar.set(Calendar.MILLISECOND, 0);
+ fishingOperationNoCatchBatch.setGearShootingStartDate(calendar.getTime());
+ calendar.setTime(new Date());
+ calendar.set(Calendar.HOUR_OF_DAY, 10);
+ calendar.set(Calendar.MILLISECOND, 0);
+ fishingOperationNoCatchBatch.setGearShootingEndDate(calendar.getTime());
+ fishingOperationNoCatchBatch = fishingOperationService.createFishingOperation(fishingOperationNoCatchBatch);
+
+ // Create a second operation, with no cacth batch : to test CatchBatch insert/update :
+ fishingOperationWithEmptyBatch = fishingOperations.get(1);
+ fishingOperationWithEmptyBatch = fishingOperationService.getFishingOperation(fishingOperationWithEmptyBatch.getId());
+ fishingOperationWithEmptyBatch.setId((String) null);
+ fishingOperationWithEmptyBatch.setCruise(cruise);
+ calendar.setTime(new Date());
+ calendar.set(Calendar.HOUR_OF_DAY, 11);
+ calendar.set(Calendar.MILLISECOND, 0);
+ fishingOperationWithEmptyBatch.setGearShootingStartDate(calendar.getTime());
+ calendar.setTime(new Date());
+ calendar.set(Calendar.HOUR_OF_DAY, 12);
+ calendar.set(Calendar.MILLISECOND, 0);
+ fishingOperationWithEmptyBatch.setGearShootingEndDate(calendar.getTime());
+ fishingOperationWithEmptyBatch = fishingOperationService.createFishingOperation(fishingOperationWithEmptyBatch);
+
+ catchBacth = new CatchBatch();
+ catchBacth.setFishingOperation(fishingOperationWithEmptyBatch);
+ catchBacth = catchBatchService.createCatchBatch(catchBacth);
+
+ 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 createAndSaveSpeciesBatchAndFrequencies() {
+ SpeciesBatch esp1Batch;
+ SpeciesBatch esp2Batch;
+ SpeciesBatch frequenciesParentBatch;
+ SpeciesBatch batch;
+ 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(fishingOperationNoCatchBatch);
+ batch.setSpecies(taxon1);
+ batch.setSampleCategoryType(SampleCategoryEnum.sortedUnsorted);
+ batch.setSampleCategoryValue(vracQualitativeValue);
+ batch.setSampleCategoryWeight(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((String) null);
+ batch.setParentBatch(esp1Batch);
+ batch.setSpecies(taxon1);
+ batch.setComment("ESP1 - Vrac/5 Male/2 ss-ech/1 Nombre/7");
+ batch.setSampleCategoryType(SampleCategoryEnum.sex);
+ batch.setSampleCategoryValue(maleQualitativeValue);
+ batch.setSampleCategoryWeight(2f);
+ batch.setWeight(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((String) null);
+ batch.setParentBatch(esp1Batch);
+ batch.setSpecies(taxon1);
+ batch.setComment("ESP1 - Vrac/5 Female/3 Nombre/14");
+ batch.setSampleCategoryType(SampleCategoryEnum.sex);
+ batch.setSampleCategoryValue(femaleQualitativeValue);
+ batch.setSampleCategoryWeight(3f);
+ batch.setWeight(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);
+ batch.setSpecies(taxon2);
+ batch.setSampleCategoryType(SampleCategoryEnum.sortedUnsorted);
+ batch.setSampleCategoryValue(vracQualitativeValue);
+ batch.setSampleCategoryWeight(7f);
+
+ assertCreateAndReloadSpeciesBatch(batch, null);
+ esp2Batch = batch;
+
+ // Batch : ESP2 - Vrac/7 UNK/2 ss-ech/1 Nombre/11
+ batch = new SpeciesBatch();
+ batch.setId((String) 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.setSampleCategoryWeight(2f);
+ batch.setWeight(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.setComment("ESP2 - Vrac/7 UNK/1.75 ss-ech/1.11 Nombre/99");
+ batch.setSampleCategoryType(SampleCategoryEnum.sex);
+ batch.setSampleCategoryValue(unkQualitativeValue);
+ batch.setSampleCategoryWeight(1.75f);
+ batch.setWeight(1.11f);
+ batch.setFishingOperation(fishingOperationWithEmptyBatch);
+ batch.setNumber(99);
+
+ // Save and reload, then check
+ SpeciesBatch savedBatch = service.saveSpeciesBatch(batch);
+ assertSpeciesBatch(savedBatch, batch, false);
+ SpeciesBatch reloadedBatch = getSpeciesBatch(fishingOperationWithEmptyBatch.getId(), savedBatch.getId());
+ assertSpeciesBatch(savedBatch, reloadedBatch, true);
+
+ // Save batch for later
+ frequenciesParentBatch = batch;
+
+ // -----------------------------------------------------------------------------
+ // 6. Test change species
+ // -----------------------------------------------------------------------------
+ esp2Batch.setSpecies(taxon1);
+ service.changeSpeciesBatchSpecies(esp2Batch.getId(), taxon1);
+ assertSpeciesBatch(savedBatch, batch, false);
+ reloadedBatch = getSpeciesBatch(fishingOperationWithEmptyBatch.getId(), esp2Batch.getId());
+ assertSpeciesBatch(esp2Batch, reloadedBatch, true);
+
+ // -----------------------------------------------------------------------------
+ // 7. Test get all root species
+ // -----------------------------------------------------------------------------
+ BatchContainer<SpeciesBatch> rootSpeciesBatc = service.getRootSpeciesBatch(fishingOperationWithEmptyBatch.getId());
+ List<SpeciesBatch> rootSpeciesBatch = rootSpeciesBatc.getChildren();
+ 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);
+ }
+ }
+ // And remove the last item (should be deleted in DB)
+ // Note: use a new list (everything list coming from service are not modifiable)
+ createdFrequencies = Lists.newArrayList(createdFrequencies);
+ createdFrequencies.remove(createdFrequencies.size() - 1);
+
+ List<SpeciesBatchFrequency> savedFrequencies = service.saveSpeciesBatchFrequency(frequenciesParentBatch.getId(), createdFrequencies);
+ assertBatchFrequencies(createdFrequencies, savedFrequencies, true);
+ }
+
+ @Test
+ public void deleteSpeciesBatch(/* String id */) {
+ SpeciesBatch esp1Batch;
+ 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(fishingOperationWithEmptyBatch);
+ batch.setSpecies(taxon1);
+ batch.setSampleCategoryType(SampleCategoryEnum.sortedUnsorted);
+ batch.setSampleCategoryValue(vracQualitativeValue);
+ batch.setSampleCategoryWeight(5f);
+ assertCreateAndReloadSpeciesBatch(batch, null);
+ esp1Batch = batch;
+
+ // batch : ESP1 Vrac/5 Male/2
+ batch = new SpeciesBatch();
+ batch.setParentBatch(esp1Batch);
+ batch.setFishingOperation(fishingOperationWithEmptyBatch);
+ batch.setSpecies(taxon1);
+ batch.setSampleCategoryType(SampleCategoryEnum.sex);
+ batch.setSampleCategoryValue(maleQualitativeValue);
+ batch.setSampleCategoryWeight(2f);
+ assertCreateAndReloadSpeciesBatch(batch, esp1Batch.getId());
+
+ // Try to remove
+ service.deleteSpeciesBatch(esp1Batch.getId());
+
+ // Check if remove
+ try {
+ batch = getSpeciesBatch(fishingOperationWithEmptyBatch.getId(), esp1Batch.getId());
+ assertNull(batch);
+ } catch (DataRetrievalFailureException drfe) {
+ assertNotNull(drfe);
+ }
+ }
+
+ protected void assertCreateAndReloadSpeciesBatch(SpeciesBatch batch, String parentBatchId) {
+ batch.setFishingOperation(fishingOperationWithEmptyBatch);
+
+ // Create batch
+ SpeciesBatch createdBatch = service.createSpeciesBatch(batch, parentBatchId);
+ assertSpeciesBatch(batch, createdBatch, false);
+
+ // then reload (for round trip check)
+ SpeciesBatch reloadedBatch = getSpeciesBatch(fishingOperationWithEmptyBatch.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.getRootSpeciesBatch(fishingOperationId).getChildren());
+ }
+
+ 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/resources/log4j.properties
===================================================================
--- trunk/tutti-persistence/src/test/resources/log4j.properties 2013-03-27 21:44:37 UTC (rev 692)
+++ trunk/tutti-persistence/src/test/resources/log4j.properties 2013-03-27 21:49:05 UTC (rev 693)
@@ -37,6 +37,6 @@
#log4j.logger.net.sf.ehcache=WARN
-log4j.logger.fr.ifremer.adagio.core=DEBUG
+log4j.logger.fr.ifremer.adagio.core=ERROR
log4j.logger.fr.ifremer.tutti=INFO
#log4j.logger.org.nuiton=INFO
1
0
r692 - in trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing: content/operation/catches content/operation/catches/benthos content/operation/catches/species util
by tchemit@users.forge.codelutin.com 27 Mar '13
by tchemit@users.forge.codelutin.com 27 Mar '13
27 Mar '13
Author: tchemit
Date: 2013-03-27 22:44:37 +0100 (Wed, 27 Mar 2013)
New Revision: 692
Url: http://forge.codelutin.com/projects/tutti/repository/revisions/692
Log:
fixes #2224: [CAPUTRE] Donn?\195?\169es non sauvegard?\195?\169es
Modified:
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUI.css
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUIHandler.java
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUIModel.java
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchRowModel.java
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchRowModel.java
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/AbstractTuttiBeanUIModel.java
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/TuttiComputedOrNotData.java
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUI.css
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUI.css 2013-03-27 19:09:49 UTC (rev 691)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUI.css 2013-03-27 21:44:37 UTC (rev 692)
@@ -317,6 +317,7 @@
text: "tutti.editCatchBatch.action.saveCatchBatch";
toolTipText: "tutti.editCatchBatch.action.saveCatchBatch.tip";
i18nMnemonic: "tutti.editCatchBatch.action.saveCatchBatch.mnemonic";
+ enabled: {model.isModify()};
_tuttiAction: {SaveCatchBatchAction.class};
_help: {"tutti.editCatchBatch.action.saveCatchBatch.help"};
}
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUIHandler.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUIHandler.java 2013-03-27 19:09:49 UTC (rev 691)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUIHandler.java 2013-03-27 21:44:37 UTC (rev 692)
@@ -87,7 +87,11 @@
this.parentUi = parentUi;
this.catchBatchMonitor = new TuttiBeanMonitor<EditCatchesUIModel>(
EditCatchesUIModel.PROPERTY_SPECIES_TOTAL_SORTED_WEIGHT,
- EditCatchesUIModel.PROPERTY_BENTHOS_TOTAL_SORTED_WEIGHT);
+ EditCatchesUIModel.PROPERTY_SPECIES_TOTAL_INERT_WEIGHT,
+ EditCatchesUIModel.PROPERTY_SPECIES_TOTAL_LIVING_NOT_ITEMIZED_WEIGHT,
+ EditCatchesUIModel.PROPERTY_BENTHOS_TOTAL_SORTED_WEIGHT,
+ EditCatchesUIModel.PROPERTY_BENTHOS_TOTAL_INERT_WEIGHT,
+ EditCatchesUIModel.PROPERTY_BENTHOS_TOTAL_LIVING_NOT_ITEMIZED_WEIGHT);
}
//------------------------------------------------------------------------//
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUIModel.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUIModel.java 2013-03-27 19:09:49 UTC (rev 691)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUIModel.java 2013-03-27 21:44:37 UTC (rev 692)
@@ -41,8 +41,6 @@
import org.nuiton.util.beans.Binder;
import org.nuiton.util.beans.BinderFactory;
-import java.beans.PropertyChangeEvent;
-import java.beans.PropertyChangeListener;
import java.util.Collection;
import java.util.List;
@@ -182,43 +180,24 @@
public EditCatchesUIModel() {
super(CatchBatch.class, fromBeanBinder, toBeanBinder);
- speciesTotalSortedComputedOrNotWeight.addPropertyChangeListener(
- TuttiComputedOrNotData.PROPERTY_DATA,
- new PropertyChangeListener() {
+ speciesTotalSortedComputedOrNotWeight.addPropagateListener(
+ PROPERTY_SPECIES_TOTAL_SORTED_WEIGHT, this);
+ speciesTotalInertComputedOrNotWeight.addPropagateListener(
+ PROPERTY_SPECIES_TOTAL_INERT_WEIGHT, this);
+ speciesTotalLivingNotItemizedComputedOrNotWeight.addPropagateListener(
+ PROPERTY_SPECIES_TOTAL_LIVING_NOT_ITEMIZED_WEIGHT, this);
- public void propertyChange(PropertyChangeEvent evt) {
- firePropertyChange(PROPERTY_SPECIES_TOTAL_SORTED_WEIGHT,
- evt.getOldValue(), evt.getNewValue());
- }
- });
- benthosTotalSortedComputedOrNotWeight.addPropertyChangeListener(
- TuttiComputedOrNotData.PROPERTY_DATA,
- new PropertyChangeListener() {
+ benthosTotalSortedComputedOrNotWeight.addPropagateListener(
+ PROPERTY_BENTHOS_TOTAL_SORTED_WEIGHT, this);
+ benthosTotalInertComputedOrNotWeight.addPropagateListener(
+ PROPERTY_BENTHOS_TOTAL_INERT_WEIGHT, this);
+ benthosTotalLivingNotItemizedComputedOrNotWeight.addPropagateListener(
+ PROPERTY_BENTHOS_TOTAL_LIVING_NOT_ITEMIZED_WEIGHT, this);
- public void propertyChange(PropertyChangeEvent evt) {
- firePropertyChange(PROPERTY_BENTHOS_TOTAL_SORTED_WEIGHT,
- evt.getOldValue(), evt.getNewValue());
- }
- });
-
- catchTotalComputedOrNotWeight.addPropertyChangeListener(
- TuttiComputedOrNotData.PROPERTY_DATA,
- new PropertyChangeListener() {
-
- public void propertyChange(PropertyChangeEvent evt) {
- firePropertyChange(PROPERTY_CATCH_TOTAL_WEIGHT,
- evt.getOldValue(), evt.getNewValue());
- }
- });
- catchTotalRejectedComputedOrNotWeight.addPropertyChangeListener(
- TuttiComputedOrNotData.PROPERTY_DATA,
- new PropertyChangeListener() {
-
- public void propertyChange(PropertyChangeEvent evt) {
- firePropertyChange(PROPERTY_CATCH_TOTAL_COMPUTED_WEIGHT,
- evt.getOldValue(), evt.getNewValue());
- }
- });
+ catchTotalComputedOrNotWeight.addPropagateListener(
+ PROPERTY_CATCH_TOTAL_WEIGHT, this);
+ catchTotalRejectedComputedOrNotWeight.addPropagateListener(
+ PROPERTY_CATCH_TOTAL_REJECTED_WEIGHT, this);
}
@Override
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchRowModel.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchRowModel.java 2013-03-27 19:09:49 UTC (rev 691)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchRowModel.java 2013-03-27 21:44:37 UTC (rev 692)
@@ -42,8 +42,6 @@
import org.nuiton.util.beans.Binder;
import org.nuiton.util.beans.BinderFactory;
-import java.beans.PropertyChangeEvent;
-import java.beans.PropertyChangeListener;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
@@ -242,39 +240,10 @@
maturityCategory = SampleCategory.newSample(SampleCategoryEnum.maturity);
ageCategory = SampleCategory.newSample(SampleCategoryEnum.age);
- computedOrNotWeight.addPropertyChangeListener(
- TuttiComputedOrNotData.PROPERTY_DATA,
- new PropertyChangeListener() {
-
- public void propertyChange(PropertyChangeEvent evt) {
- firePropertyChange(PROPERTY_WEIGHT, evt.getOldValue(), evt.getNewValue());
- }
- });
- computedOrNotWeight.addPropertyChangeListener(
- TuttiComputedOrNotData.PROPERTY_COMPUTED_DATA,
- new PropertyChangeListener() {
-
- public void propertyChange(PropertyChangeEvent evt) {
- firePropertyChange(PROPERTY_COMPUTED_WEIGHT, evt.getOldValue(), evt.getNewValue());
- }
- });
-
- computedOrNotNumber.addPropertyChangeListener(
- TuttiComputedOrNotData.PROPERTY_DATA,
- new PropertyChangeListener() {
-
- public void propertyChange(PropertyChangeEvent evt) {
- firePropertyChange(PROPERTY_NUMBER, evt.getOldValue(), evt.getNewValue());
- }
- });
- computedOrNotNumber.addPropertyChangeListener(
- TuttiComputedOrNotData.PROPERTY_COMPUTED_DATA,
- new PropertyChangeListener() {
-
- public void propertyChange(PropertyChangeEvent evt) {
- firePropertyChange(PROPERTY_COMPUTED_NUMBER, evt.getOldValue(), evt.getNewValue());
- }
- });
+ computedOrNotWeight.addPropagateListener(PROPERTY_WEIGHT, this);
+ computedOrNotWeight.addPropagateListener(PROPERTY_COMPUTED_WEIGHT, this);
+ computedOrNotNumber.addPropagateListener(PROPERTY_NUMBER, this);
+ computedOrNotNumber.addPropagateListener(PROPERTY_COMPUTED_NUMBER, this);
}
public BenthosBatchRowModel(SpeciesBatch aBatch,
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchRowModel.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchRowModel.java 2013-03-27 19:09:49 UTC (rev 691)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchRowModel.java 2013-03-27 21:44:37 UTC (rev 692)
@@ -42,8 +42,6 @@
import org.nuiton.util.beans.Binder;
import org.nuiton.util.beans.BinderFactory;
-import java.beans.PropertyChangeEvent;
-import java.beans.PropertyChangeListener;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
@@ -242,39 +240,10 @@
maturityCategory = SampleCategory.newSample(SampleCategoryEnum.maturity);
ageCategory = SampleCategory.newSample(SampleCategoryEnum.age);
- computedOrNotWeight.addPropertyChangeListener(
- TuttiComputedOrNotData.PROPERTY_DATA,
- new PropertyChangeListener() {
-
- public void propertyChange(PropertyChangeEvent evt) {
- firePropertyChange(PROPERTY_WEIGHT, evt.getOldValue(), evt.getNewValue());
- }
- });
- computedOrNotWeight.addPropertyChangeListener(
- TuttiComputedOrNotData.PROPERTY_COMPUTED_DATA,
- new PropertyChangeListener() {
-
- public void propertyChange(PropertyChangeEvent evt) {
- firePropertyChange(PROPERTY_COMPUTED_WEIGHT, evt.getOldValue(), evt.getNewValue());
- }
- });
-
- computedOrNotNumber.addPropertyChangeListener(
- TuttiComputedOrNotData.PROPERTY_DATA,
- new PropertyChangeListener() {
-
- public void propertyChange(PropertyChangeEvent evt) {
- firePropertyChange(PROPERTY_NUMBER, evt.getOldValue(), evt.getNewValue());
- }
- });
- computedOrNotNumber.addPropertyChangeListener(
- TuttiComputedOrNotData.PROPERTY_COMPUTED_DATA,
- new PropertyChangeListener() {
-
- public void propertyChange(PropertyChangeEvent evt) {
- firePropertyChange(PROPERTY_COMPUTED_NUMBER, evt.getOldValue(), evt.getNewValue());
- }
- });
+ computedOrNotWeight.addPropagateListener(PROPERTY_WEIGHT, this);
+ computedOrNotWeight.addPropagateListener(PROPERTY_COMPUTED_WEIGHT, this);
+ computedOrNotNumber.addPropagateListener(PROPERTY_NUMBER, this);
+ computedOrNotNumber.addPropagateListener(PROPERTY_COMPUTED_NUMBER, this);
}
public SpeciesBatchRowModel(SpeciesBatch aBatch,
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/AbstractTuttiBeanUIModel.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/AbstractTuttiBeanUIModel.java 2013-03-27 19:09:49 UTC (rev 691)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/AbstractTuttiBeanUIModel.java 2013-03-27 21:44:37 UTC (rev 692)
@@ -119,4 +119,12 @@
public boolean isCreate() {
return id == null;
}
+
+ public void firePropertyChanged(String propertyName,
+ Object oldValue,
+ Object newValue) {
+ firePropertyChange(propertyName, oldValue, newValue);
+ }
+
+
}
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/TuttiComputedOrNotData.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/TuttiComputedOrNotData.java 2013-03-27 19:09:49 UTC (rev 691)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/TuttiComputedOrNotData.java 2013-03-27 21:44:37 UTC (rev 692)
@@ -1,8 +1,5 @@
-
package fr.ifremer.tutti.ui.swing.util;
-import org.jdesktop.beans.AbstractSerializableBean;
-
/*
* #%L
* Tutti :: UI
@@ -13,20 +10,26 @@
* %%
* 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
+ * 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
+ *
+ * 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 org.jdesktop.beans.AbstractSerializableBean;
+
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+
+
/** @author kmorin <kmorin(a)codelutin.com> */
public class TuttiComputedOrNotData<N extends Number> extends AbstractSerializableBean {
@@ -81,4 +84,33 @@
return result;
}
+ /**
+ * Add a listener to propagate the modification of the
+ * {@link #PROPERTY_DATA} property to a given {@code propertyName}.
+ *
+ * @param propertyName name of the property to fire on given bean
+ * @param otherBean bean that will fires
+ * @since 1.2
+ */
+ public void addPropagateListener(String propertyName, AbstractTuttiBeanUIModel otherBean) {
+ PropagatePropertyChangeListener listener = new PropagatePropertyChangeListener(propertyName, otherBean);
+ addPropertyChangeListener(PROPERTY_DATA, listener);
+ }
+
+ private static class PropagatePropertyChangeListener implements PropertyChangeListener {
+
+ private String propertyName;
+
+ private AbstractTuttiBeanUIModel otherBean;
+
+ public PropagatePropertyChangeListener(String propertyName, AbstractTuttiBeanUIModel otherBean) {
+ this.propertyName = propertyName;
+ this.otherBean = otherBean;
+ }
+
+ @Override
+ public void propertyChange(PropertyChangeEvent evt) {
+ otherBean.firePropertyChanged(propertyName, evt.getOldValue(), evt.getNewValue());
+ }
+ }
}
1
0
r691 - in trunk/tutti-ui-swing/src/main: java/fr/ifremer/tutti/ui/swing/content resources/i18n
by kmorin@users.forge.codelutin.com 27 Mar '13
by kmorin@users.forge.codelutin.com 27 Mar '13
27 Mar '13
Author: kmorin
Date: 2013-03-27 20:09:49 +0100 (Wed, 27 Mar 2013)
New Revision: 691
Url: http://forge.codelutin.com/projects/tutti/repository/revisions/691
Log:
refs #1840 [REFERENTIEL] - Gestion des fonctionnalit?\195?\169s administrateur
Modified:
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/ImportTemporaryReferentialAction.java
trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_en_GB.properties
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/content/ImportTemporaryReferentialAction.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/ImportTemporaryReferentialAction.java 2013-03-27 18:06:33 UTC (rev 690)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/ImportTemporaryReferentialAction.java 2013-03-27 19:09:49 UTC (rev 691)
@@ -25,9 +25,14 @@
*/
import fr.ifremer.tutti.ui.swing.TuttiScreen;
+import org.apache.commons.lang.StringUtils;
+import org.springframework.util.DigestUtils;
-import javax.swing.SwingUtilities;
+import javax.swing.*;
+import java.security.MessageDigest;
+import static org.nuiton.i18n.I18n._;
+
/**
* Open screen to import referential
*
@@ -41,6 +46,27 @@
}
@Override
+ protected boolean prepareAction() throws Exception {
+ boolean result = super.prepareAction();
+ if (result) {
+ String answer = JOptionPane.showInputDialog(getContext().getActionUI(),
+ _("tutti.manageTemporaryReferential.passwordDialog.message"),
+ _("tutti.manageTemporaryReferential.passwordDialog.title"),
+ JOptionPane.WARNING_MESSAGE);
+ if (answer != null) {
+ String cryptedAnswer = DigestUtils.md5DigestAsHex(answer.getBytes());
+ String correctAnswer = DigestUtils.md5DigestAsHex("test".getBytes());
+ //TODO kmorin 20130327 error message if wrong password
+ result = StringUtils.equals(cryptedAnswer, correctAnswer);
+
+ } else {
+ result = false;
+ }
+ }
+ return result;
+ }
+
+ @Override
protected void doAction() throws Exception {
super.doAction();
SwingUtilities.invokeLater(new Runnable() {
Modified: trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_en_GB.properties
===================================================================
--- trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_en_GB.properties 2013-03-27 18:06:33 UTC (rev 690)
+++ trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_en_GB.properties 2013-03-27 19:09:49 UTC (rev 691)
@@ -856,6 +856,8 @@
tutti.manageTemporaryReferential.field.species.tip=
tutti.manageTemporaryReferential.field.vessel=
tutti.manageTemporaryReferential.field.vessel.tip=
+tutti.manageTemporaryReferential.passwordDialog.message=
+tutti.manageTemporaryReferential.passwordDialog.title=
tutti.manageTemporaryReferential.title=
tutti.manageTemporaryReferential.title.choose.exportTemporaryGearExampleFile=
tutti.manageTemporaryReferential.title.choose.exportTemporaryPersonExampleFile=
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-03-27 18:06:33 UTC (rev 690)
+++ trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_fr_FR.properties 2013-03-27 19:09:49 UTC (rev 691)
@@ -860,6 +860,8 @@
tutti.manageTemporaryReferential.field.species.tip=
tutti.manageTemporaryReferential.field.vessel=Référentiel Navire
tutti.manageTemporaryReferential.field.vessel.tip=
+tutti.manageTemporaryReferential.passwordDialog.message=Vous souhaitez entrer dans une partie sensible de l'application.\nVous devez entrer le mot de passe pour entrer.
+tutti.manageTemporaryReferential.passwordDialog.title=Zone sensible
tutti.manageTemporaryReferential.title=importer des référentiels temporaires
tutti.manageTemporaryReferential.title.choose.exportTemporaryGearExampleFile=Exporter un exemple de référentiel Engin
tutti.manageTemporaryReferential.title.choose.exportTemporaryPersonExampleFile=Exporter un exemple de référentiel Personne
1
0