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
March 2013
- 5 participants
- 242 discussions
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
r690 - trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util
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 19:06:33 +0100 (Wed, 27 Mar 2013)
New Revision: 690
Url: http://forge.codelutin.com/projects/tutti/repository/revisions/690
Log:
Java 7 power ! \o/
refs #1868 [CAPTURE] - Import/Export PUPITRI
refs #1972 [ERGO] - Symbologie des onglets sans donn?\195?\169es
Added:
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/TabContentModel.java
Added: 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 (rev 0)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/TabContentModel.java 2013-03-27 18:06:33 UTC (rev 690)
@@ -0,0 +1,20 @@
+package fr.ifremer.tutti.ui.swing.util;
+
+/**
+ * Interface defining the models of the tab content UIs.
+ *
+ * @author kmorin <kmorin(a)codelutin.com>
+ * @since 1.2
+ */
+public interface TabContentModel {
+
+ boolean isEmpty();
+
+ boolean isValid();
+
+ boolean isModify();
+
+ String getTitle();
+
+ String getIcon();
+}
1
0
27 Mar '13
Author: kmorin
Date: 2013-03-27 19:06:07 +0100 (Wed, 27 Mar 2013)
New Revision: 689
Url: http://forge.codelutin.com/projects/tutti/repository/revisions/689
Log:
Java 7 power ! \o/
refs #1868 [CAPTURE] - Import/Export PUPITRI
refs #1972 [ERGO] - Symbologie des onglets sans donn?\195?\169es
Modified:
trunk/pom.xml
trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/pupitri/TuttiPupitriImportExportService.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/EditFishingOperationUIHandler.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/SaveFishingOperationAction.java
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUI.jaxx
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/BenthosBatchUIModel.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/fishing/AbstractCaracteristicTabUIModel.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/AbstractTuttiTabContainerUIHandler.java
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/CustomTab.java
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2013-03-27 13:59:54 UTC (rev 688)
+++ trunk/pom.xml 2013-03-27 18:06:07 UTC (rev 689)
@@ -118,6 +118,12 @@
<platform>forge.codelutin.com</platform>
<projectId>tutti</projectId>
+ <!-- Java version -->
+ <maven.compiler.source>1.7</maven.compiler.source>
+ <maven.compiler.target>1.7</maven.compiler.target>
+ <signatureArtifactId>java17</signatureArtifactId>
+ <signatureVersion>1.0</signatureVersion>
+
<!-- libraries version -->
<nuitonUtilsVersion>2.6.12</nuitonUtilsVersion>
@@ -166,7 +172,7 @@
<!-- Last tutti db version -->
<!--<dbVersion>2013.02.27</dbVersion>-->
-
+
</properties>
<dependencyManagement>
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 13:59:54 UTC (rev 688)
+++ trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/pupitri/TuttiPupitriImportExportService.java 2013-03-27 18:06:07 UTC (rev 689)
@@ -130,7 +130,7 @@
addFileAsAttachment(trunkFile, catchBatch);
addFileAsAttachment(carrouselFile, catchBatch);
addFileAsAttachment(speciesFile, catchBatch);
-
+
persistenceService.saveCatchBatch(catchBatch);
}
@@ -394,7 +394,7 @@
childBatch.setSampleCategoryValue(splitCqv);
childBatch.setSpecies(pupitriCatch.getSpecies());
childBatch.setSampleCategoryWeight(pupitriCatch.getWeightBySign().get(s));
-
+
persistenceService.createSpeciesBatch(childBatch, batch.getId());
}
}
@@ -405,7 +405,7 @@
reader.close();
} catch (Exception e) {
- throw new TuttiTechnicalException("Could not import protocol [" + operation.toString() + "] caracteristic from file " + carrouselFile, e);
+ throw new TuttiTechnicalException("Could not import carrousel data [" + operation.toString() + "] from file " + carrouselFile, e);
} finally {
IOUtils.closeQuietly(carrouselImporter);
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 13:59:54 UTC (rev 688)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationAction.java 2013-03-27 18:06:07 UTC (rev 689)
@@ -435,9 +435,6 @@
List<Person> saisisseur = editFishingOperationUIModel.getRecorderPerson();
ui.getRecorderPersonList().getHandler().setSelected(saisisseur);
- // update model empty property
- editFishingOperationUIModel.setEmpty(false);
-
//reset gear use feature tab
GearUseFeatureTabUI gearUseFeatureTabContent = ui.getGearUseFeatureTabContent();
gearUseFeatureTabContent.getHandler().reset(bean);
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationUIHandler.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationUIHandler.java 2013-03-27 13:59:54 UTC (rev 688)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationUIHandler.java 2013-03-27 18:06:07 UTC (rev 689)
@@ -288,8 +288,6 @@
initBeanFilterableComboBox(ui.getLocationComboBox(), locations, location);
- model.setEmpty(true);
-
changeValidatorContext(model.getValidationContext(), ui.getValidator());
listenValidatorValid(ui.getValidator(), model);
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 13:59:54 UTC (rev 688)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationUIModel.java 2013-03-27 18:06:07 UTC (rev 689)
@@ -36,9 +36,12 @@
import fr.ifremer.tutti.persistence.entities.referential.Vessel;
import fr.ifremer.tutti.persistence.spatial.SexagecimalPosition;
import fr.ifremer.tutti.ui.swing.util.AbstractTuttiBeanUIModel;
+import fr.ifremer.tutti.ui.swing.util.TabContentModel;
import fr.ifremer.tutti.ui.swing.util.TuttiUIUtil;
import fr.ifremer.tutti.ui.swing.util.attachment.AttachmentModelAware;
import fr.ifremer.tutti.ui.swing.util.editor.CoordinateEditorType;
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.lang3.StringUtils;
import org.nuiton.util.DateUtil;
import org.nuiton.util.beans.Binder;
import org.nuiton.util.beans.BinderFactory;
@@ -56,7 +59,8 @@
* @author tchemit <chemit(a)codelutin.com>
* @since 0.1
*/
-public class EditFishingOperationUIModel extends AbstractTuttiBeanUIModel<FishingOperation, EditFishingOperationUIModel> implements AttachmentModelAware {
+public class EditFishingOperationUIModel extends AbstractTuttiBeanUIModel<FishingOperation, EditFishingOperationUIModel>
+ implements AttachmentModelAware, TabContentModel {
private static final long serialVersionUID = 1L;
@@ -64,8 +68,6 @@
public static final String PROPERTY_PERSISTED = "persisted";
- public static final String PROPERTY_EMPTY = "empty";
-
public static final String PROPERTY_STATION_NUMBER = "stationNumber";
public static final String PROPERTY_FISHING_OPERATION_NUMBER = "fishingOperationNumber";
@@ -140,13 +142,6 @@
public static final String PROPERTY_VALIDATION_CONTEXT = "validationContext";
- /**
- * Flag when there is no fishing operation selected.
- *
- * @since 0.2
- */
- protected boolean empty;
-
protected Cruise cruise;
protected String stationNumber;
@@ -225,6 +220,31 @@
return TITLE;
}
+ @Override
+ public String getIcon() {
+ return null;
+ }
+
+ 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());
+
+ // TODO add the otehr ones
+ }
+
public FishingOperation getFishingOperation() {
return fishingOperation;
}
@@ -238,16 +258,6 @@
return fishingOperation != null && !TuttiEntities.isNew(fishingOperation);
}
- public boolean isEmpty() {
- return empty;
- }
-
- public void setEmpty(boolean empty) {
- Object oldValue = isEmpty();
- this.empty = empty;
- firePropertyChange(PROPERTY_EMPTY, oldValue, empty);
- }
-
public Cruise getCruise() {
return cruise;
}
@@ -839,16 +849,16 @@
public void convertGearShootingCoordinatesDMSToDD() {
Float decimalValue = gearShootingStartLatitudeAsSexagecimal.toDecimal();
- setGearShootingStartLatitude(decimalValue);
+ gearShootingStartLatitude = decimalValue;
decimalValue = gearShootingStartLongitudeAsSexagecimal.toDecimal();
- setGearShootingStartLongitude(decimalValue);
+ gearShootingStartLongitude = decimalValue;
decimalValue = gearShootingEndLatitudeAsSexagecimal.toDecimal();
- setGearShootingEndLatitude(decimalValue);
+ gearShootingEndLatitude = decimalValue;
decimalValue = gearShootingEndLongitudeAsSexagecimal.toDecimal();
- setGearShootingEndLongitude(decimalValue);
+ gearShootingEndLongitude = decimalValue;
}
public void computeDistance() {
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/SaveFishingOperationAction.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/SaveFishingOperationAction.java 2013-03-27 13:59:54 UTC (rev 688)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/SaveFishingOperationAction.java 2013-03-27 18:06:07 UTC (rev 689)
@@ -83,8 +83,8 @@
EditFishingOperationUIModel beanToSave = monitor.getBean();
// must save when bean is new or was modifiy and is valid
- boolean mustSave = (beanToSave.isCreate() || !beanToSave.isEmpty()) &&
- beanToSave.isValid();
+ boolean mustSave = beanToSave.getFishingOperation() != null
+ && beanToSave.isValid();
if (mustSave) {
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUI.jaxx
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUI.jaxx 2013-03-27 13:59:54 UTC (rev 688)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUI.jaxx 2013-03-27 18:06:07 UTC (rev 689)
@@ -297,7 +297,7 @@
</JScrollPane>
</JXTitledPanel>
</tab>
- <tab id='speciesTab' title='tutti.label.tab.species'>
+ <tab id='speciesTab'>
<JPanel id='speciesTabPanel'>
<JXTitledPanel id='speciesTabFishingOperationReminderLabel'
constraints='EditCatchesUIHandler.MAIN_CARD'>
@@ -320,7 +320,7 @@
</JXTitledPanel>
</JPanel>
</tab>
- <tab id='benthosTab' title='tutti.label.tab.benthos'>
+ <tab id='benthosTab'>
<JPanel id='benthosTabPanel'>
<JXTitledPanel id='benthosTabFishingOperationReminderLabel'
constraints='EditCatchesUIHandler.MAIN_CARD'>
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 13:59:54 UTC (rev 688)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUIHandler.java 2013-03-27 18:06:07 UTC (rev 689)
@@ -114,6 +114,8 @@
listenValidatorValid(getValidator(), model);
setCustomTab(0, model);
+ setCustomTab(1, ui.getSpeciesTabContent().getModel());
+ setCustomTab(2, ui.getBenthosTabContent().getModel());
getParentUi().getFishingOperationTabContent().getModel()
.addPropertyChangeListener(EditFishingOperationUIModel.PROPERTY_VESSEL, new PropertyChangeListener() {
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 13:59:54 UTC (rev 688)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUIModel.java 2013-03-27 18:06:07 UTC (rev 689)
@@ -34,8 +34,10 @@
import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativeValue;
import fr.ifremer.tutti.persistence.entities.referential.Species;
import fr.ifremer.tutti.ui.swing.util.AbstractTuttiBeanUIModel;
+import fr.ifremer.tutti.ui.swing.util.TabContentModel;
import fr.ifremer.tutti.ui.swing.util.TuttiComputedOrNotData;
import fr.ifremer.tutti.ui.swing.util.attachment.AttachmentModelAware;
+import org.apache.commons.collections.CollectionUtils;
import org.nuiton.util.beans.Binder;
import org.nuiton.util.beans.BinderFactory;
@@ -50,7 +52,7 @@
* @author tchemit <chemit(a)codelutin.com>
* @since 0.3
*/
-public class EditCatchesUIModel extends AbstractTuttiBeanUIModel<CatchBatch, EditCatchesUIModel> implements AttachmentModelAware {
+public class EditCatchesUIModel extends AbstractTuttiBeanUIModel<CatchBatch, EditCatchesUIModel> implements AttachmentModelAware, TabContentModel {
private static final long serialVersionUID = 1L;
@@ -662,4 +664,16 @@
return catchBatch;
}
+ @Override
+ public boolean isEmpty() {
+ return getCatchTotalWeight() == null
+ && getCatchTotalRejectedWeight() == null
+ && CollectionUtils.isEmpty(getAttachment());
+ }
+
+ @Override
+ public String getIcon() {
+ return null;
+ }
+
}
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 13:59:54 UTC (rev 688)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUIModel.java 2013-03-27 18:06:07 UTC (rev 689)
@@ -33,8 +33,10 @@
import fr.ifremer.tutti.ui.swing.content.operation.AbstractTuttiBatchUIModel;
import fr.ifremer.tutti.ui.swing.content.operation.catches.EditCatchesUIModel;
import fr.ifremer.tutti.ui.swing.content.operation.catches.TableViewMode;
+import fr.ifremer.tutti.ui.swing.util.TabContentModel;
import fr.ifremer.tutti.ui.swing.util.TuttiComputedOrNotData;
import fr.ifremer.tutti.ui.swing.util.attachment.AttachmentModelAware;
+import org.apache.commons.collections.CollectionUtils;
import java.util.Collection;
import java.util.List;
@@ -43,7 +45,8 @@
* @author tchemit <chemit(a)codelutin.com>
* @since 0.1
*/
-public class BenthosBatchUIModel extends AbstractTuttiBatchUIModel<BenthosBatchRowModel, BenthosBatchUIModel> implements AttachmentModelAware {
+public class BenthosBatchUIModel extends AbstractTuttiBatchUIModel<BenthosBatchRowModel, BenthosBatchUIModel>
+ implements AttachmentModelAware, TabContentModel {
private static final long serialVersionUID = 1L;
@@ -382,4 +385,22 @@
firePropertyChange(PROPERTY_ATTACHMENT, null, getAttachment());
}
+ @Override
+ public boolean isEmpty() {
+ return CollectionUtils.isEmpty(getRows())
+ && getBenthosTotalSortedWeight() == null
+ && getBenthosTotalInertWeight() == null
+ && getBenthosTotalLivingNotItemizedWeight() == null
+ && CollectionUtils.isEmpty(getAttachment());
+ }
+
+ @Override
+ public String getTitle() {
+ return "tutti.label.tab.benthos";
+ }
+
+ @Override
+ public String getIcon() {
+ return null;
+ }
}
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 13:59:54 UTC (rev 688)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUIHandler.java 2013-03-27 18:06:07 UTC (rev 689)
@@ -50,6 +50,7 @@
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;
@@ -1101,5 +1102,4 @@
return model.getSelectedSpecies();
}
-
}
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 13:59:54 UTC (rev 688)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUIModel.java 2013-03-27 18:06:07 UTC (rev 689)
@@ -33,8 +33,10 @@
import fr.ifremer.tutti.ui.swing.content.operation.AbstractTuttiBatchUIModel;
import fr.ifremer.tutti.ui.swing.content.operation.catches.EditCatchesUIModel;
import fr.ifremer.tutti.ui.swing.content.operation.catches.TableViewMode;
+import fr.ifremer.tutti.ui.swing.util.TabContentModel;
import fr.ifremer.tutti.ui.swing.util.TuttiComputedOrNotData;
import fr.ifremer.tutti.ui.swing.util.attachment.AttachmentModelAware;
+import org.apache.commons.collections.CollectionUtils;
import java.util.Collection;
import java.util.List;
@@ -43,7 +45,8 @@
* @author tchemit <chemit(a)codelutin.com>
* @since 0.1
*/
-public class SpeciesBatchUIModel extends AbstractTuttiBatchUIModel<SpeciesBatchRowModel, SpeciesBatchUIModel> implements AttachmentModelAware {
+public class SpeciesBatchUIModel extends AbstractTuttiBatchUIModel<SpeciesBatchRowModel, SpeciesBatchUIModel>
+ implements AttachmentModelAware, TabContentModel {
private static final long serialVersionUID = 1L;
@@ -382,4 +385,22 @@
firePropertyChange(PROPERTY_ATTACHMENT, null, getAttachment());
}
+ @Override
+ public boolean isEmpty() {
+ return CollectionUtils.isEmpty(getRows())
+ && getSpeciesTotalSortedWeight() == null
+ && getSpeciesTotalInertWeight() == null
+ && getSpeciesTotalLivingNotItemizedWeight() == null
+ && CollectionUtils.isEmpty(getAttachment());
+ }
+
+ @Override
+ public String getTitle() {
+ return "tutti.label.tab.species";
+ }
+
+ @Override
+ public String getIcon() {
+ return null;
+ }
}
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 13:59:54 UTC (rev 688)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/fishing/AbstractCaracteristicTabUIModel.java 2013-03-27 18:06:07 UTC (rev 689)
@@ -25,21 +25,27 @@
* #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;
import fr.ifremer.tutti.persistence.entities.referential.Caracteristic;
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 java.io.Serializable;
import java.util.List;
+import java.util.Set;
+import org.apache.commons.collections.CollectionUtils;
+
/**
* @author kmorin <kmorin(a)codelutin.com>
* @since 1.0
*/
public abstract class AbstractCaracteristicTabUIModel<RM extends AbstractTuttiBeanUIModel<Serializable, RM>, M extends AbstractCaracteristicTabUIModel<RM, M>>
- extends AbstractTuttiTableUIModel<FishingOperation, RM, M> {
+ extends AbstractTuttiTableUIModel<FishingOperation, RM, M> implements TabContentModel {
public static final String PROPERTY_CARACTERISTIC_MAP = "caracteristicMap";
@@ -98,4 +104,21 @@
this.removeCaracteristicEnabled = removeCaracteristicEnabled;
firePropertyChange(PROPERTY_REMOVE_CARACTERISTIC_ENABLED, oldValue, removeCaracteristicEnabled);
}
+
+ @Override
+ public boolean isEmpty() {
+ boolean result = caracteristicMap == null;
+ if (!result) {
+ Set s = Sets.newHashSet(caracteristicMap.values());
+ s.remove(null);
+ result = s.isEmpty();
+ }
+ return result;
+ }
+
+ @Override
+ public String getIcon() {
+ return null;
+ }
+
}
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 13:59:54 UTC (rev 688)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/AbstractTuttiBeanUIModel.java 2013-03-27 18:06:07 UTC (rev 689)
@@ -96,14 +96,6 @@
firePropertyChange(PROPERTY_ID, oldValue, id);
}
- public String getTitle() {
- return null;
- }
-
- public String getIcon() {
- return null;
- }
-
public boolean isModify() {
return modify;
}
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/AbstractTuttiTabContainerUIHandler.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/AbstractTuttiTabContainerUIHandler.java 2013-03-27 13:59:54 UTC (rev 688)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/AbstractTuttiTabContainerUIHandler.java 2013-03-27 18:06:07 UTC (rev 689)
@@ -125,7 +125,7 @@
* @param index
* @param model
*/
- protected void setCustomTab(int index, AbstractTuttiBeanUIModel model) {
+ protected void setCustomTab(int index, TabContentModel model) {
getTabPanel().setTabComponentAt(index, new CustomTab(model));
}
}
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 13:59:54 UTC (rev 688)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/CustomTab.java 2013-03-27 18:06:07 UTC (rev 689)
@@ -30,8 +30,16 @@
import javax.swing.JLabel;
import javax.swing.JPanel;
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._;
@@ -46,31 +54,37 @@
private static final long serialVersionUID = 1L;
- protected AbstractTuttiBeanUIModel model;
+ private static final Log log = LogFactory.getLog(CustomTab.class);
+ protected TabContentModel model;
+
protected JLabel title = new JLabel();
- public AbstractTuttiBeanUIModel getModel() {
+ public TabContentModel getModel() {
return model;
}
- public CustomTab(AbstractTuttiBeanUIModel model) {
+ public CustomTab(TabContentModel model) {
this.model = model;
- this.model.addPropertyChangeListener(AbstractTuttiBeanUIModel.PROPERTY_MODIFY, new PropertyChangeListener() {
+ try {
+ BeanUtil.addPropertyChangeListener(
+ new PropertyChangeListener() {
- public void propertyChange(PropertyChangeEvent evt) {
- Boolean modified = (Boolean) evt.getNewValue();
- String title = _(CustomTab.this.model.getTitle());
- if (modified) {
- title = "<html><strong>" + title + "*</strong></html>";
- }
- CustomTab.this.title.setText(title);
- }
- });
+ @Override
+ public void propertyChange(PropertyChangeEvent evt) {
+ updateTitle();
+ }
+ },this.model);
+
+ } catch (NoSuchMethodException
+ | IllegalAccessException
+ | InvocationTargetException ex) {
+ log.error("Error while adding the listener to the model modifications", ex);
+ }
setBackground(null);
- title.setText(_(model.getTitle()));
+ updateTitle();
String actionIcon = model.getIcon();
if (actionIcon != null) {
title.setIcon(SwingUtil.createActionIcon(actionIcon));
@@ -95,4 +109,24 @@
}
}
+ protected void updateTitle() {
+ Font f = UIManager.getDefaults().getFont("Label.font");
+ String titleValue = _(model.getTitle());
+
+ int style;
+ if (model.isModify()) {
+ style = Font.BOLD;
+ titleValue += "*";
+
+ } else if (model.isEmpty()) {
+ style = Font.ITALIC;
+
+ } else {
+ style = Font.PLAIN;
+ }
+
+ title.setText(titleValue);
+ title.setFont(f.deriveFont(style));
+ }
+
}
1
0
r688 - trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency
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 14:59:54 +0100 (Wed, 27 Mar 2013)
New Revision: 688
Url: http://forge.codelutin.com/projects/tutti/repository/revisions/688
Log:
fixes#2170 [ESPECES] - Mensurations - Taille : vider champs ?\195?\160 l'ouverture ou entre deux saisies
Modified:
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUIHandler.java
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUIHandler.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUIHandler.java 2013-03-27 13:53:21 UTC (rev 687)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUIHandler.java 2013-03-27 13:59:54 UTC (rev 688)
@@ -214,8 +214,8 @@
}
model.setStep(precision);
- model.setMinStep(10f);
- model.setMaxStep(20f);
+ model.setMinStep(null);
+ model.setMaxStep(null);
ui.getRafaleStepField().getTextField().addKeyListener(new KeyAdapter() {
1
0
r687 - in trunk/tutti-ui-swing/src/main: java/fr/ifremer/tutti/ui/swing/content/operation java/fr/ifremer/tutti/ui/swing/content/operation/catches java/fr/ifremer/tutti/ui/swing/util resources/fr/ifremer/tutti/ui/swing/content/operation 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 14:53:21 +0100 (Wed, 27 Mar 2013)
New Revision: 687
Url: http://forge.codelutin.com/projects/tutti/repository/revisions/687
Log:
fixes #2219 [TRAIT] - Saisie des coordonn?\195?\169es : probl?\195?\168mes sur les valeurs accept?\195?\169es
Modified:
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationUI.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/util/TuttiUI.java
trunk/tutti-ui-swing/src/main/resources/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationUIModel-edit-warning-validation.xml
trunk/tutti-ui-swing/src/main/resources/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationUIModel-validate-error-validation.xml
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/operation/EditFishingOperationUI.css
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationUI.css 2013-03-26 18:15:51 UTC (rev 686)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationUI.css 2013-03-27 13:53:21 UTC (rev 687)
@@ -250,7 +250,7 @@
showReset: false;
useFloat: true;
useSign: false;
- numberPattern: {DECIMAL2_3_PATTERN};
+ numberPattern: {DECIMAL2_DIGITS_PATTERN};
}
.second {
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-26 18:15:51 UTC (rev 686)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUIHandler.java 2013-03-27 13:53:21 UTC (rev 687)
@@ -178,7 +178,9 @@
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);
}
@@ -275,78 +277,82 @@
public void setSpeciesSelectedCard(String card) {
JPanel panel = ui.getSpeciesTabPanel();
CardLayout2Ext layout = (CardLayout2Ext) panel.getLayout();
- layout.setSelected(card);
+ if (!card.equals(layout.getSelected())) {
+ layout.setSelected(card);
- JPanel actionPanel = getUI().getCreateFishingOperationActions();
- if (MAIN_CARD.equals(card)) {
- registerValidators();
- actionPanel.setVisible(true);
- } else {
- actionPanel.setVisible(false);
- TuttiUI tuttiUi = null;
- JXTitledPanel titlePanel = null;
- String title = "";
- if (CREATE_BATCH_CARD.equals(card)) {
- tuttiUi = ui.getSpeciesTabCreateBatch();
- titlePanel = ui.getSpeciesTabCreateBatchReminderLabel();
- title = n_("tutti.createSpeciesBatch.title");
+ JPanel actionPanel = getUI().getCreateFishingOperationActions();
+ if (MAIN_CARD.equals(card)) {
+ registerValidators();
+ actionPanel.setVisible(true);
+ } else {
+ actionPanel.setVisible(false);
+ TuttiUI tuttiUi = null;
+ JXTitledPanel titlePanel = null;
+ String title = "";
+ if (CREATE_BATCH_CARD.equals(card)) {
+ tuttiUi = ui.getSpeciesTabCreateBatch();
+ titlePanel = ui.getSpeciesTabCreateBatchReminderLabel();
+ title = n_("tutti.createSpeciesBatch.title");
- } else if (SPLIT_BATCH_CARD.equals(card)) {
- tuttiUi = ui.getSpeciesTabSplitBatch();
- titlePanel = ui.getSpeciesTabSplitBatchReminderLabel();
- title = n_("tutti.splitSpeciesBatch.title");
+ } else if (SPLIT_BATCH_CARD.equals(card)) {
+ tuttiUi = ui.getSpeciesTabSplitBatch();
+ titlePanel = ui.getSpeciesTabSplitBatchReminderLabel();
+ title = n_("tutti.splitSpeciesBatch.title");
- } else if (EDIT_FREQUENCY_CARD.equals(card)) {
- tuttiUi = ui.getSpeciesTabFrequencyEditor();
- titlePanel = ui.getSpeciesTabFrequencyEditorReminderLabel();
- title = n_("tutti.editSpeciesFrequencies.title");
- }
+ } else if (EDIT_FREQUENCY_CARD.equals(card)) {
+ tuttiUi = ui.getSpeciesTabFrequencyEditor();
+ titlePanel = ui.getSpeciesTabFrequencyEditorReminderLabel();
+ title = n_("tutti.editSpeciesFrequencies.title");
+ }
- if (tuttiUi != null) {
- registerValidators(tuttiUi.getHandler().getValidator());
+ if (tuttiUi != null) {
+ registerValidators(tuttiUi.getHandler().getValidator());
+ }
+ if (titlePanel != null) {
+ titlePanel.setTitle(ui.getSpeciesTabFishingOperationReminderLabel().getTitle() + " - " + _(title));
+ }
}
- if (titlePanel != null) {
- titlePanel.setTitle(ui.getSpeciesTabFishingOperationReminderLabel().getTitle() + " - " + _(title));
- }
}
}
public void setBenthosSelectedCard(String card) {
JPanel panel = ui.getBenthosTabPanel();
CardLayout2Ext layout = (CardLayout2Ext) panel.getLayout();
- layout.setSelected(card);
+ if (!card.equals(layout.getSelected())) {
+ layout.setSelected(card);
- JPanel actionPanel = getUI().getCreateFishingOperationActions();
- if (MAIN_CARD.equals(card)) {
- registerValidators();
- actionPanel.setVisible(true);
- } else {
- actionPanel.setVisible(false);
- TuttiUI tuttiUi = null;
- JXTitledPanel titlePanel = null;
- String title = "";
- if (CREATE_BATCH_CARD.equals(card)) {
- tuttiUi = ui.getBenthosTabCreateBatch();
- titlePanel = ui.getBenthosTabCreateBatchReminderLabel();
- title = n_("tutti.createBenthosBatch.title");
+ JPanel actionPanel = getUI().getCreateFishingOperationActions();
+ if (MAIN_CARD.equals(card)) {
+ registerValidators();
+ actionPanel.setVisible(true);
+ } else {
+ actionPanel.setVisible(false);
+ TuttiUI tuttiUi = null;
+ JXTitledPanel titlePanel = null;
+ String title = "";
+ if (CREATE_BATCH_CARD.equals(card)) {
+ tuttiUi = ui.getBenthosTabCreateBatch();
+ titlePanel = ui.getBenthosTabCreateBatchReminderLabel();
+ title = n_("tutti.createBenthosBatch.title");
- } else if (SPLIT_BATCH_CARD.equals(card)) {
- tuttiUi = ui.getBenthosTabSplitBatch();
- titlePanel = ui.getBenthosTabSplitBatchReminderLabel();
- title = n_("tutti.splitBenthosBatch.title");
+ } else if (SPLIT_BATCH_CARD.equals(card)) {
+ tuttiUi = ui.getBenthosTabSplitBatch();
+ titlePanel = ui.getBenthosTabSplitBatchReminderLabel();
+ title = n_("tutti.splitBenthosBatch.title");
- } else if (EDIT_FREQUENCY_CARD.equals(card)) {
- tuttiUi = ui.getBenthosTabFrequencyEditor();
- titlePanel = ui.getBenthosTabFrequencyEditorReminderLabel();
- title = n_("tutti.editBenthosFrequencies.title");
- }
+ } else if (EDIT_FREQUENCY_CARD.equals(card)) {
+ tuttiUi = ui.getBenthosTabFrequencyEditor();
+ titlePanel = ui.getBenthosTabFrequencyEditorReminderLabel();
+ title = n_("tutti.editBenthosFrequencies.title");
+ }
- if (tuttiUi != null) {
- registerValidators(tuttiUi.getHandler().getValidator());
+ if (tuttiUi != null) {
+ registerValidators(tuttiUi.getHandler().getValidator());
+ }
+ if (titlePanel != null) {
+ titlePanel.setTitle(ui.getBenthosTabFishingOperationReminderLabel().getTitle() + " - " + _(title));
+ }
}
- if (titlePanel != null) {
- titlePanel.setTitle(ui.getBenthosTabFishingOperationReminderLabel().getTitle() + " - " + _(title));
- }
}
}
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/TuttiUI.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/TuttiUI.java 2013-03-26 18:15:51 UTC (rev 686)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/TuttiUI.java 2013-03-27 13:53:21 UTC (rev 687)
@@ -127,7 +127,7 @@
*
* @since 1.0
*/
- public static final String DECIMAL2_3_PATTERN = "\\d{0,2}|\\d{1,2}\\.\\d{0,3}";
+ public static final String DECIMAL2_DIGITS_PATTERN = "\\d{0,2}|\\d{1,2}\\.\\d*";
public static final Font TEXTFIELD_NORMAL_FONT = UIManager.getDefaults().getFont("TextField.font");
Modified: trunk/tutti-ui-swing/src/main/resources/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationUIModel-edit-warning-validation.xml
===================================================================
--- trunk/tutti-ui-swing/src/main/resources/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationUIModel-edit-warning-validation.xml 2013-03-26 18:15:51 UTC (rev 686)
+++ trunk/tutti-ui-swing/src/main/resources/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationUIModel-edit-warning-validation.xml 2013-03-27 13:53:21 UTC (rev 687)
@@ -149,7 +149,8 @@
( -ints.min < getGearShootingStartLatitudeDegree() && getGearShootingStartLatitudeDegree() < ints.max )
|| (
( getGearShootingStartLatitudeDegree() == ints.max || getGearShootingStartLatitudeDegree() == -ints.min )
- && getGearShootingStartLatitudeMinute() == 0 && getGearShootingStartLatitudeSecond() == 0
+ && ( getGearShootingStartLatitudeMinute() == null || getGearShootingStartLatitudeMinute() == 0 )
+ && ( getGearShootingStartLatitudeSecond() == null || getGearShootingStartLatitudeSecond() == 0 )
)
)
]]>
@@ -181,7 +182,7 @@
( -ints.min < getGearShootingStartLatitudeDecimalDegree() && getGearShootingStartLatitudeDecimalDegree() < ints.max )
|| (
( getGearShootingStartLatitudeDecimalDegree() == ints.max || getGearShootingStartLatitudeDecimalDegree() == -ints.min )
- && getGearShootingStartLatitudeDecimalMinute() == 0.0
+ && ( getGearShootingStartLatitudeDecimalMinute() == null || getGearShootingStartLatitudeDecimalMinute() == 0.0 )
)
)
]]>
@@ -322,7 +323,8 @@
(-ints.min < getGearShootingStartLongitudeDegree() && getGearShootingStartLongitudeDegree() < ints.max)
|| (
( getGearShootingStartLongitudeDegree() == ints.max || getGearShootingStartLongitudeDegree() == -ints.min )
- && getGearShootingStartLongitudeMinute() == 0 && getGearShootingStartLongitudeSecond() == 0
+ && ( getGearShootingStartLongitudeMinute() == null || getGearShootingStartLongitudeMinute() == 0 )
+ && ( getGearShootingStartLongitudeSecond() == null || getGearShootingStartLongitudeSecond() == 0 )
)
)
]]>
@@ -354,7 +356,7 @@
(-ints.min < getGearShootingStartLongitudeDecimalDegree() && getGearShootingStartLongitudeDecimalDegree() < ints.max)
|| (
( getGearShootingStartLongitudeDecimalDegree() == ints.max || getGearShootingStartLongitudeDecimalDegree() == -ints.min )
- && getGearShootingStartLongitudeDecimalMinute() == 0.0
+ && ( getGearShootingStartLongitudeDecimalMinute() == null || getGearShootingStartLongitudeDecimalMinute() == 0.0 )
)
)
]]>
@@ -496,7 +498,8 @@
(-ints.min < getGearShootingEndLatitudeDegree() && getGearShootingEndLatitudeDegree() < ints.max)
|| (
( getGearShootingEndLatitudeDegree() == ints.max || getGearShootingEndLatitudeDegree() == -ints.min )
- && getGearShootingEndLatitudeMinute() == 0 && getGearShootingEndLatitudeSecond() == 0
+ && ( getGearShootingEndLatitudeMinute() == null || getGearShootingEndLatitudeMinute() == 0 )
+ && ( getGearShootingEndLatitudeSecond() == null || getGearShootingEndLatitudeSecond() == 0 )
)
)
]]>
@@ -528,7 +531,7 @@
(-ints.min < getGearShootingEndLatitudeDecimalDegree() && getGearShootingEndLatitudeDecimalDegree() < ints.max)
|| (
( getGearShootingEndLatitudeDecimalDegree() == ints.max || getGearShootingEndLatitudeDecimalDegree() == -ints.min )
- && getGearShootingEndLatitudeDecimalMinute() == 0.0
+ && ( getGearShootingEndLatitudeDecimalMinute() == null || getGearShootingEndLatitudeDecimalMinute() == 0.0 )
)
)
]]>
@@ -669,7 +672,8 @@
(-ints.min < getGearShootingEndLongitudeDegree() && getGearShootingEndLongitudeDegree() < ints.max)
|| (
( getGearShootingEndLongitudeDegree() == ints.max || getGearShootingEndLongitudeDegree() == -ints.min )
- && getGearShootingEndLongitudeMinute() == 0 && getGearShootingEndLongitudeSecond() == 0
+ && ( getGearShootingEndLongitudeMinute() == null || getGearShootingEndLongitudeMinute() == 0 )
+ && ( getGearShootingEndLongitudeSecond() == null || getGearShootingEndLongitudeSecond() == 0 )
)
)
]]>
@@ -701,7 +705,7 @@
(-ints.min < getGearShootingEndLongitudeDecimalDegree() && getGearShootingEndLongitudeDecimalDegree() < ints.max)
|| (
( getGearShootingEndLongitudeDecimalDegree() == ints.max || getGearShootingEndLongitudeDecimalDegree() == -ints.min )
- && getGearShootingEndLongitudeDecimalMinute() == 0.0
+ && ( getGearShootingEndLongitudeDecimalMinute() == null || getGearShootingEndLongitudeDecimalMinute() == 0.0 )
)
)
]]>
Modified: trunk/tutti-ui-swing/src/main/resources/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationUIModel-validate-error-validation.xml
===================================================================
--- trunk/tutti-ui-swing/src/main/resources/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationUIModel-validate-error-validation.xml 2013-03-26 18:15:51 UTC (rev 686)
+++ trunk/tutti-ui-swing/src/main/resources/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationUIModel-validate-error-validation.xml 2013-03-27 13:53:21 UTC (rev 687)
@@ -211,7 +211,8 @@
(( -ints.min < getGearShootingStartLatitudeDegree() && getGearShootingStartLatitudeDegree() < ints.max )
|| (
( getGearShootingStartLatitudeDegree() == ints.max || getGearShootingStartLatitudeDegree() == -ints.min )
- && getGearShootingStartLatitudeMinute() == 0 && getGearShootingStartLatitudeSecond() == 0
+ && ( getGearShootingStartLatitudeMinute() == null || getGearShootingStartLatitudeMinute() == 0 )
+ && ( getGearShootingStartLatitudeSecond() == null || getGearShootingStartLatitudeSecond() == 0 )
))
)
]]>
@@ -244,7 +245,7 @@
(( -ints.min < getGearShootingStartLatitudeDecimalDegree() && getGearShootingStartLatitudeDecimalDegree() < ints.max )
|| (
( getGearShootingStartLatitudeDecimalDegree() == ints.max || getGearShootingStartLatitudeDecimalDegree() == -ints.min )
- && getGearShootingStartLatitudeDecimalMinute() == 0.0
+ && ( getGearShootingStartLatitudeDecimalMinute() == null || getGearShootingStartLatitudeDecimalMinute() == 0.0 )
))
)
]]>
@@ -394,7 +395,8 @@
((-ints.min < getGearShootingStartLongitudeDegree() && getGearShootingStartLongitudeDegree() < ints.max)
|| (
( getGearShootingStartLongitudeDegree() == ints.max || getGearShootingStartLongitudeDegree() == -ints.min )
- && getGearShootingStartLongitudeMinute() == 0 && getGearShootingStartLongitudeSecond() == 0
+ && ( getGearShootingStartLongitudeMinute() == null || getGearShootingStartLongitudeMinute() == 0 )
+ && ( getGearShootingStartLongitudeSecond() == null || getGearShootingStartLongitudeSecond() == 0 )
))
)
]]>
@@ -427,7 +429,7 @@
(( -ints.min < getGearShootingStartLongitudeDecimalDegree() && getGearShootingStartLongitudeDecimalDegree() < ints.max)
|| (
( getGearShootingStartLongitudeDecimalDegree() == ints.max || getGearShootingStartLongitudeDecimalDegree() == -ints.min )
- && getGearShootingStartLongitudeDecimalMinute() == 0.0
+ && ( getGearShootingStartLongitudeDecimalMinute() == null || getGearShootingStartLongitudeDecimalMinute() == 0.0 )
))
)
]]>
@@ -578,7 +580,8 @@
(( -ints.min < getGearShootingEndLatitudeDegree() && getGearShootingEndLatitudeDegree() < ints.max)
|| (
( getGearShootingEndLatitudeDegree() == ints.max || getGearShootingEndLatitudeDegree() == -ints.min )
- && getGearShootingEndLatitudeMinute() == 0 && getGearShootingEndLatitudeSecond() == 0
+ && ( getGearShootingEndLatitudeMinute() == null || getGearShootingEndLatitudeMinute() == 0 )
+ && ( getGearShootingEndLatitudeSecond() == null || getGearShootingEndLatitudeSecond() == 0 )
))
)
]]>
@@ -611,7 +614,7 @@
(( -ints.min < getGearShootingEndLatitudeDecimalDegree() && getGearShootingEndLatitudeDecimalDegree() < ints.max)
|| (
( getGearShootingEndLatitudeDecimalDegree() == ints.max || getGearShootingEndLatitudeDecimalDegree() == -ints.min )
- && getGearShootingEndLatitudeDecimalMinute() == 0.0
+ && ( getGearShootingEndLatitudeDecimalMinute() == null || getGearShootingEndLatitudeDecimalMinute() == 0.0 )
))
)
]]>
@@ -761,7 +764,8 @@
((-ints.min < getGearShootingEndLongitudeDegree() && getGearShootingEndLongitudeDegree() < ints.max)
|| (
( getGearShootingEndLongitudeDegree() == ints.max || getGearShootingEndLongitudeDegree() == -ints.min )
- && getGearShootingEndLongitudeMinute() == 0 && getGearShootingEndLongitudeSecond() == 0
+ && ( getGearShootingEndLongitudeMinute() == null || getGearShootingEndLongitudeMinute() == 0 )
+ && ( getGearShootingEndLongitudeSecond() == null || getGearShootingEndLongitudeSecond() == 0 )
))
)
]]>
@@ -794,7 +798,7 @@
(( -ints.min < getGearShootingEndLongitudeDecimalDegree() && getGearShootingEndLongitudeDecimalDegree() < ints.max)
|| (
( getGearShootingEndLongitudeDecimalDegree() == ints.max || getGearShootingEndLongitudeDecimalDegree() == -ints.min )
- && getGearShootingEndLongitudeDecimalMinute() == 0.0
+ && ( getGearShootingEndLongitudeDecimalMinute() == null || getGearShootingEndLongitudeDecimalMinute() == 0.0 )
))
)
]]>
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-26 18:15:51 UTC (rev 686)
+++ trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_fr_FR.properties 2013-03-27 13:53:21 UTC (rev 687)
@@ -1031,13 +1031,13 @@
tutti.validator.error.splitSpeciesBatch.selectedCategory.required=La catégorie est obligatoire
tutti.validator.warning.cruise.name.format=Le format n'est pas celui ...
tutti.validator.warning.latitude.degree.outOfBounds=Le degré de la latitude doit être compris entre -90 et 90
-tutti.validator.warning.latitude.minute.outOfBounds=La minute de la latitude doit être comprise entre 0 et 60
+tutti.validator.warning.latitude.minute.outOfBounds=La minute de la latitude doit être comprise entre 0 et 59
tutti.validator.warning.latitude.outOfBounds=La Latitude doit être comprise entre -90.0 et 90.0
-tutti.validator.warning.latitude.second.outOfBounds=La seconde de la latitude doit être comprise entre 0 et 60
-tutti.validator.warning.longitude.degree.outOfBounds=Le degré de la latitude doit être compris entre -180 et 180
-tutti.validator.warning.longitude.minute.outOfBounds=La minute de la latitude doit être comprise entre 0 et 60
-tutti.validator.warning.longitude.outOfBounds=La Latitude doit être comprise entre -180.0 et 180.0
-tutti.validator.warning.longitude.second.outOfBounds=La seconde de la longitude doit être comprise entre 0 et 60
+tutti.validator.warning.latitude.second.outOfBounds=La seconde de la latitude doit être comprise entre 0 et 59
+tutti.validator.warning.longitude.degree.outOfBounds=Le degré de la longitude doit être compris entre -180 et 180
+tutti.validator.warning.longitude.minute.outOfBounds=La minute de la longitude doit être comprise entre 0 et 59
+tutti.validator.warning.longitude.outOfBounds=La longitude doit être comprise entre -180.0 et 180.0
+tutti.validator.warning.longitude.second.outOfBounds=La seconde de la longitude doit être comprise entre 0 et 59
tutti.vesselUseFeatureTable.action.removeCaracteristic=Supprimer
tutti.vesselUseFeatureTable.action.removeCaracteristic.mnemonic=S
tutti.vesselUseFeatureTable.action.removeCaracteristic.tip=Supprimer la caractéristique
1
0
26 Mar '13
Author: kmorin
Date: 2013-03-26 19:15:51 +0100 (Tue, 26 Mar 2013)
New Revision: 686
Url: http://forge.codelutin.com/projects/tutti/repository/revisions/686
Log:
refs #1868 [CAPTURE] - Import/Export PUPITRI
Removed:
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/SpeciesBatchRootRowModel.java
Modified:
trunk/tutti-ui-swing/src/main/filtered-resources/tutti-help-en.properties
trunk/tutti-ui-swing/src/main/filtered-resources/tutti-help-fr.properties
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/catches/ImportPupitriAction.java
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUIHandler.java
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/create/CreateBenthosBatchUIModel.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/create/CreateSpeciesBatchUIModel.java
Modified: trunk/tutti-ui-swing/src/main/filtered-resources/tutti-help-en.properties
===================================================================
--- trunk/tutti-ui-swing/src/main/filtered-resources/tutti-help-en.properties 2013-03-26 18:15:28 UTC (rev 685)
+++ trunk/tutti-ui-swing/src/main/filtered-resources/tutti-help-en.properties 2013-03-26 18:15:51 UTC (rev 686)
@@ -1,5 +1,5 @@
#Generated by org.nuiton.jaxx.plugin.GenerateHelpIdsMojo
-#Tue Mar 26 16:11:47 CET 2013
+#Tue Mar 26 18:46:47 CET 2013
tutti.createBenthosBatch.action.addSpecies.help=createBenthosBatch.html\#actions
tutti.createBenthosBatch.action.cancel.help=createBenthosBatch.html\#actions
tutti.createBenthosBatch.action.save.help=createBenthosBatch.html\#actions
@@ -130,6 +130,7 @@
tutti.editProtocol.action.exportProtocolBenthos.help=editProtocol.html\#actions
tutti.editProtocol.action.exportProtocolCaracteristic.tip=editProtocol.html\#actions
tutti.editProtocol.action.exportProtocolSpecies.help=editProtocol.html\#actions
+tutti.editProtocol.action.exportPupitri.help=
tutti.editProtocol.action.importProtocolBenthos.help=editProtocol.html\#actions
tutti.editProtocol.action.importProtocolCaracteristic.help=editProtocol.html\#actions
tutti.editProtocol.action.importProtocolSpecies.help=editProtocol.html\#actions
Modified: trunk/tutti-ui-swing/src/main/filtered-resources/tutti-help-fr.properties
===================================================================
--- trunk/tutti-ui-swing/src/main/filtered-resources/tutti-help-fr.properties 2013-03-26 18:15:28 UTC (rev 685)
+++ trunk/tutti-ui-swing/src/main/filtered-resources/tutti-help-fr.properties 2013-03-26 18:15:51 UTC (rev 686)
@@ -1,5 +1,5 @@
#Generated by org.nuiton.jaxx.plugin.GenerateHelpIdsMojo
-#Tue Mar 26 16:11:47 CET 2013
+#Tue Mar 26 18:46:47 CET 2013
tutti.createBenthosBatch.action.addSpecies.help=createBenthosBatch.html\#actions
tutti.createBenthosBatch.action.cancel.help=createBenthosBatch.html\#actions
tutti.createBenthosBatch.action.save.help=createBenthosBatch.html\#actions
@@ -139,6 +139,7 @@
tutti.editProtocol.action.exportProtocolBenthos.help=editProtocol.html\#actions
tutti.editProtocol.action.exportProtocolCaracteristic.tip=editProtocol.html\#actions
tutti.editProtocol.action.exportProtocolSpecies.help=editProtocol.html\#actions
+tutti.editProtocol.action.exportPupitri.help=
tutti.editProtocol.action.importProtocolBenthos.help=editProtocol.html\#actions
tutti.editProtocol.action.importProtocolCaracteristic.help=editProtocol.html\#actions
tutti.editProtocol.action.importProtocolSpecies.help=editProtocol.html\#actions
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-26 18:15:28 UTC (rev 685)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationAction.java 2013-03-26 18:15:51 UTC (rev 686)
@@ -536,7 +536,7 @@
attachments = persistenceService.getAllAttachments(objectId);
getModel().setCatchEnabled(true);
- } catch (Exception e) {
+ } catch (InvalidBatchModelException e) {
// batch is not compatible with Tutti
if (log.isDebugEnabled()) {
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-26 18:15:28 UTC (rev 685)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/ImportPupitriAction.java 2013-03-26 18:15:51 UTC (rev 686)
@@ -39,12 +39,14 @@
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;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -74,41 +76,20 @@
protected PersistenceService persistenceService;
- protected CaracteristicQualitativeValue sortedCaracteristic;
+ protected EditFishingOperationAction editAction;
- protected CaracteristicQualitativeValue unsortedCaracteristic;
-
- protected CaracteristicQualitativeValue maleCaracteristic;
-
- protected CaracteristicQualitativeValue femaleCaracteristic;
-
- protected CaracteristicQualitativeValue smallCaracteristic;
-
- protected CaracteristicQualitativeValue mediumCaracteristic;
-
- protected CaracteristicQualitativeValue bigCaracteristic;
-
public ImportPupitriAction(EditCatchesUIHandler handler) {
super(handler, false);
persistenceService = getContext().getPersistenceService();
importPupitriDialog = new ImportPupitriPopupUI(handler.getContext());
+ }
- // get the sorted/unsorted caracteristics
- Caracteristic sortedUnsortedcaracteristic =
- persistenceService.getSortedUnsortedCaracteristic();
- sortedCaracteristic =
- SortedUnsortedEnum.SORTED.getValue(sortedUnsortedcaracteristic);
- unsortedCaracteristic =
- SortedUnsortedEnum.UNSORTED.getValue(sortedUnsortedcaracteristic);
-
- Caracteristic sexCaracteristic = persistenceService.getSexCaracteristic();
- maleCaracteristic = SexEnum.MALE.getValue(sexCaracteristic);
- femaleCaracteristic = SexEnum.FEMALE.getValue(sexCaracteristic);
-
- Caracteristic sizeCaracteristic = persistenceService.getSizeCategoryCaracteristic();
- smallCaracteristic = SizeEnum.SMALL.getValue(sizeCaracteristic);
- mediumCaracteristic = SizeEnum.MEDIUM.getValue(sizeCaracteristic);
- bigCaracteristic = SizeEnum.BIG.getValue(sizeCaracteristic);
+ public EditFishingOperationAction getEditAction() {
+ if (editAction == null) {
+ editAction = TuttiActionHelper.createLogicAction( getHandler().getParentHandler(),
+ EditFishingOperationAction.class);
+ }
+ return editAction;
}
@Override
@@ -170,108 +151,20 @@
FishingOperation operation = model.getFishingOperation();
CatchBatch catchBatch = model.getCatchBatch();
-
// import trunk
- pupitriImportExportService.importPupitriTrunk(importedTrunkFile, operation, catchBatch);
+ pupitriImportExportService.importPupitri(importedTrunkFile,
+ importedCarrouselFile,
+ importedSpeciesFile,
+ operation,
+ catchBatch,
+ getDataContext().getReferentSpeciesWithSurveyCode());
+
+ String fishingOperationText = getEditAction().getFishingOperationTitle(operation);
- model.setCatchTotalRejectedWeight(catchBatch.getCatchTotalRejectedWeight());
- model.setCatchTotalSortedTremisWeight(catchBatch.getCatchTotalSortedTremisWeight());
+ getEditAction().loadCatchBatch(operation, fishingOperationText, true);
- // import carrousel
- List<PupitriCatch> catches =
- pupitriImportExportService.importPupitriCarrousel(importedCarrouselFile,
- importedSpeciesFile,
- operation,
- catchBatch,
- getDataContext().getReferentSpeciesWithSurveyCode());
-
- // remove existing species
- SpeciesBatchUIModel speciesBatchUIModel = getUI().getSpeciesTabContent().getModel();
- List<SpeciesBatchRowModel> rows = speciesBatchUIModel.getRows();
- for (SpeciesBatchRowModel row : rows) {
- if (row.isBatchRoot()) {
- persistenceService.deleteSpeciesBatch(row.getId());
- }
- }
- speciesBatchUIModel.setRows(null);
-
- // add the valid species in the species table
- SpeciesBatchUIHandler speciesBatchUIHandler = getUI().getSpeciesTabContent().getHandler();
- for (PupitriCatch pupitriCatch : catches) {
- Float catchWeight = pupitriCatch.getWeightBySign().get(PupitriCatch.Signs.DEFAULT);
- CaracteristicQualitativeValue cqv = pupitriCatch.isSorted() ?
- sortedCaracteristic : unsortedCaracteristic;
-
- ImportPupitriSpeciesBatchRootRowModel rowModel =
- new ImportPupitriSpeciesBatchRootRowModel(
- pupitriCatch.getSpecies(), cqv, catchWeight);
-
- speciesBatchUIHandler.addBatch(rowModel);
-
- if (catchWeight == null) {
- SampleCategoryEnum category = null;
- List<SplitSpeciesBatchRowModel> splitRows = Lists.newArrayList();
- for (PupitriCatch.Signs s : pupitriCatch.getWeightBySign().keySet()) {
- CaracteristicQualitativeValue splitCqv = null;
- switch (s) {
- case MALE:
- splitCqv = maleCaracteristic;
- category = SampleCategoryEnum.sex;
- break;
-
- case FEMALE:
- splitCqv = femaleCaracteristic;
- category = SampleCategoryEnum.sex;
- break;
-
- case SMALL:
- splitCqv = smallCaracteristic;
- category = SampleCategoryEnum.size;
- break;
-
- case MEDIUM:
- splitCqv = mediumCaracteristic;
- category = SampleCategoryEnum.size;
- break;
-
- case BIG:
- splitCqv = bigCaracteristic;
- category = SampleCategoryEnum.size;
- break;
- }
- SplitSpeciesBatchRowModel row = new SplitSpeciesBatchRowModel();
- row.setCategoryType(category);
- row.setCategoryValue(splitCqv);
- row.setWeight(pupitriCatch.getWeightBySign().get(s));
- row.setValid(true);
- splitRows.add(row);
- }
- speciesBatchUIHandler.splitBatch(category, splitRows);
- }
- }
-
- model.setCatchTotalSortedCarousselWeight(catchBatch.getCatchTotalSortedCarousselWeight());
-
- // add attachments
- addFileAsAttachment(importedTrunkFile);
- addFileAsAttachment(importedCarrouselFile);
- addFileAsAttachment(importedSpeciesFile);
-
}
- protected void addFileAsAttachment(File f) {
- EditCatchesUIModel model = getModel();
-
- Attachment attachment = new Attachment();
- attachment.setObjectType(model.getObjectType());
- attachment.setObjectId(Integer.valueOf(model.getObjectId()));
- attachment.setName(f.getName());
- attachment.setComment("import pupitri");
- attachment = persistenceService.createAttachment(attachment, f);
-
- model.addAttachment(attachment);
- }
-
@Override
public void postSuccessAction() {
super.postSuccessAction();
@@ -286,38 +179,4 @@
currentProtocol = null;
}
- class ImportPupitriSpeciesBatchRootRowModel implements SpeciesBatchRootRowModel {
-
- Species species;
-
- CaracteristicQualitativeValue sortedUnsortedCategory;
-
- Float batchWeight;
-
- public ImportPupitriSpeciesBatchRootRowModel(Species species,
- CaracteristicQualitativeValue sortedUnsortedCategory,
- Float batchWeight) {
-
- this.species = species;
- this.sortedUnsortedCategory = sortedUnsortedCategory;
- this.batchWeight = batchWeight;
- }
-
- public Species getSpecies() {
- return species;
- }
-
- public CaracteristicQualitativeValue getSortedUnsortedCategory() {
- return sortedUnsortedCategory;
- }
-
- public Float getBatchWeight() {
- return batchWeight;
- }
-
- public boolean isValid() {
- return species != null && sortedUnsortedCategory != null;
- }
-
- }
}
Deleted: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/SpeciesBatchRootRowModel.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/SpeciesBatchRootRowModel.java 2013-03-26 18:15:28 UTC (rev 685)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/SpeciesBatchRootRowModel.java 2013-03-26 18:15:51 UTC (rev 686)
@@ -1,44 +0,0 @@
-package fr.ifremer.tutti.ui.swing.content.operation.catches;
-
-/*
- * #%L
- * Tutti :: UI
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2012 - 2013 Ifremer
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/gpl-3.0.html>.
- * #L%
- */
-
-import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativeValue;
-import fr.ifremer.tutti.persistence.entities.referential.Species;
-
-/**
- * TODO explain why ?
- * @author kmorin <kmorin(a)codelutin.com>
- * @since 1.2
- */
-public interface SpeciesBatchRootRowModel {
-
- Species getSpecies();
-
- CaracteristicQualitativeValue getSortedUnsortedCategory();
-
- Float getBatchWeight();
-
- boolean isValid();
-}
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUIHandler.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUIHandler.java 2013-03-26 18:15:28 UTC (rev 685)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUIHandler.java 2013-03-26 18:15:51 UTC (rev 686)
@@ -43,9 +43,9 @@
import fr.ifremer.tutti.ui.swing.content.operation.catches.EditCatchesUIModel;
import fr.ifremer.tutti.ui.swing.content.operation.catches.SampleCategory;
import fr.ifremer.tutti.ui.swing.content.operation.catches.SampleCategoryComponent;
-import fr.ifremer.tutti.ui.swing.content.operation.catches.SpeciesBatchRootRowModel;
import fr.ifremer.tutti.ui.swing.content.operation.catches.TableViewMode;
import fr.ifremer.tutti.ui.swing.content.operation.catches.benthos.create.CreateBenthosBatchUI;
+import fr.ifremer.tutti.ui.swing.content.operation.catches.benthos.create.CreateBenthosBatchUIModel;
import fr.ifremer.tutti.ui.swing.content.operation.catches.benthos.frequency.BenthosFrequencyCellComponent;
import fr.ifremer.tutti.ui.swing.content.operation.catches.benthos.frequency.BenthosFrequencyRowModel;
import fr.ifremer.tutti.ui.swing.content.operation.catches.benthos.split.SplitBenthosBatchRowModel;
@@ -614,7 +614,7 @@
parent.getHandler().setBenthosSelectedCard(EditCatchesUIHandler.CREATE_BATCH_CARD);
}
- public void addBatch(SpeciesBatchRootRowModel speciesBatchRootRowModel) {
+ public void addBatch(CreateBenthosBatchUIModel speciesBatchRootRowModel) {
if (speciesBatchRootRowModel.isValid()) {
BenthosBatchTableModel tableModel = getTableModel();
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/create/CreateBenthosBatchUIModel.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/create/CreateBenthosBatchUIModel.java 2013-03-26 18:15:28 UTC (rev 685)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/create/CreateBenthosBatchUIModel.java 2013-03-26 18:15:51 UTC (rev 686)
@@ -28,7 +28,6 @@
import com.google.common.collect.Multimap;
import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativeValue;
import fr.ifremer.tutti.persistence.entities.referential.Species;
-import fr.ifremer.tutti.ui.swing.content.operation.catches.SpeciesBatchRootRowModel;
import fr.ifremer.tutti.ui.swing.content.operation.catches.species.create.CreateSpeciesBatchUI;
import fr.ifremer.tutti.ui.swing.util.AbstractTuttiBeanUIModel;
import org.apache.commons.logging.Log;
@@ -42,8 +41,7 @@
* @author tchemit <chemit(a)codelutin.com>
* @since 0.3
*/
-public class CreateBenthosBatchUIModel extends AbstractTuttiBeanUIModel<CreateBenthosBatchUIModel, CreateBenthosBatchUIModel>
- implements SpeciesBatchRootRowModel {
+public class CreateBenthosBatchUIModel extends AbstractTuttiBeanUIModel<CreateBenthosBatchUIModel, CreateBenthosBatchUIModel> {
private final static Log log = LogFactory.getLog(CreateBenthosBatchUIModel.class);
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-26 18:15:28 UTC (rev 685)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUIHandler.java 2013-03-26 18:15:51 UTC (rev 686)
@@ -43,9 +43,9 @@
import fr.ifremer.tutti.ui.swing.content.operation.catches.EditCatchesUIModel;
import fr.ifremer.tutti.ui.swing.content.operation.catches.SampleCategory;
import fr.ifremer.tutti.ui.swing.content.operation.catches.SampleCategoryComponent;
-import fr.ifremer.tutti.ui.swing.content.operation.catches.SpeciesBatchRootRowModel;
import fr.ifremer.tutti.ui.swing.content.operation.catches.TableViewMode;
import fr.ifremer.tutti.ui.swing.content.operation.catches.species.create.CreateSpeciesBatchUI;
+import fr.ifremer.tutti.ui.swing.content.operation.catches.species.create.CreateSpeciesBatchUIModel;
import fr.ifremer.tutti.ui.swing.content.operation.catches.species.frequency.SpeciesFrequencyCellComponent;
import fr.ifremer.tutti.ui.swing.content.operation.catches.species.frequency.SpeciesFrequencyRowModel;
import fr.ifremer.tutti.ui.swing.content.operation.catches.species.split.SplitSpeciesBatchRowModel;
@@ -621,7 +621,7 @@
parent.getHandler().setSpeciesSelectedCard(EditCatchesUIHandler.CREATE_BATCH_CARD);
}
- public void addBatch(SpeciesBatchRootRowModel speciesBatchRootRowModel) {
+ public void addBatch(CreateSpeciesBatchUIModel speciesBatchRootRowModel) {
if (speciesBatchRootRowModel.isValid()) {
SpeciesBatchTableModel tableModel = getTableModel();
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/create/CreateSpeciesBatchUIModel.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/create/CreateSpeciesBatchUIModel.java 2013-03-26 18:15:28 UTC (rev 685)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/create/CreateSpeciesBatchUIModel.java 2013-03-26 18:15:51 UTC (rev 686)
@@ -28,7 +28,6 @@
import com.google.common.collect.Multimap;
import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativeValue;
import fr.ifremer.tutti.persistence.entities.referential.Species;
-import fr.ifremer.tutti.ui.swing.content.operation.catches.SpeciesBatchRootRowModel;
import fr.ifremer.tutti.ui.swing.util.AbstractTuttiBeanUIModel;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -41,8 +40,7 @@
* @author tchemit <chemit(a)codelutin.com>
* @since 0.3
*/
-public class CreateSpeciesBatchUIModel extends AbstractTuttiBeanUIModel<CreateSpeciesBatchUIModel, CreateSpeciesBatchUIModel>
- implements SpeciesBatchRootRowModel {
+public class CreateSpeciesBatchUIModel extends AbstractTuttiBeanUIModel<CreateSpeciesBatchUIModel, CreateSpeciesBatchUIModel> {
private final static Log log = LogFactory.getLog(CreateSpeciesBatchUIModel.class);
1
0
r685 - trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/pupitri
by kmorin@users.forge.codelutin.com 26 Mar '13
by kmorin@users.forge.codelutin.com 26 Mar '13
26 Mar '13
Author: kmorin
Date: 2013-03-26 19:15:28 +0100 (Tue, 26 Mar 2013)
New Revision: 685
Url: http://forge.codelutin.com/projects/tutti/repository/revisions/685
Log:
refs #1868 [CAPTURE] - Import/Export PUPITRI
Modified:
trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/pupitri/TuttiPupitriImportExportService.java
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-26 17:14:14 UTC (rev 684)
+++ trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/pupitri/TuttiPupitriImportExportService.java 2013-03-26 18:15:28 UTC (rev 685)
@@ -33,11 +33,23 @@
import com.google.common.collect.Multimaps;
import com.google.common.io.Files;
import fr.ifremer.tutti.TuttiTechnicalException;
+import fr.ifremer.tutti.persistence.entities.data.AttachementObjectTypeEnum;
+import fr.ifremer.tutti.persistence.entities.data.Attachment;
+import fr.ifremer.tutti.persistence.entities.data.BatchContainer;
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.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.io.FileUtils;
@@ -67,8 +79,72 @@
private static final Log log =
LogFactory.getLog(TuttiPupitriImportExportService.class);
- public void importPupitriTrunk(File file, FishingOperation operation, CatchBatch catchBatch) {
+ protected PersistenceService persistenceService;
+ protected CaracteristicQualitativeValue sortedCaracteristic;
+
+ protected CaracteristicQualitativeValue unsortedCaracteristic;
+
+ protected CaracteristicQualitativeValue maleCaracteristic;
+
+ protected CaracteristicQualitativeValue femaleCaracteristic;
+
+ protected CaracteristicQualitativeValue smallCaracteristic;
+
+ protected CaracteristicQualitativeValue mediumCaracteristic;
+
+ protected CaracteristicQualitativeValue bigCaracteristic;
+
+ @Override
+ public void setServiceContext(TuttiServiceContext context) {
+ super.setServiceContext(context);
+ persistenceService = getService(PersistenceService.class);
+
+ // get the sorted/unsorted caracteristics
+ Caracteristic sortedUnsortedcaracteristic =
+ persistenceService.getSortedUnsortedCaracteristic();
+ sortedCaracteristic = SortedUnsortedEnum.SORTED.getValue(sortedUnsortedcaracteristic);
+ unsortedCaracteristic = SortedUnsortedEnum.UNSORTED.getValue(sortedUnsortedcaracteristic);
+
+ Caracteristic sexCaracteristic = persistenceService.getSexCaracteristic();
+ maleCaracteristic = SexEnum.MALE.getValue(sexCaracteristic);
+ femaleCaracteristic = SexEnum.FEMALE.getValue(sexCaracteristic);
+
+ Caracteristic sizeCaracteristic = persistenceService.getSizeCategoryCaracteristic();
+ smallCaracteristic = SizeEnum.SMALL.getValue(sizeCaracteristic);
+ mediumCaracteristic = SizeEnum.MEDIUM.getValue(sizeCaracteristic);
+ bigCaracteristic = SizeEnum.BIG.getValue(sizeCaracteristic);
+ }
+
+ public void importPupitri(File trunkFile,
+ File carrouselFile,
+ File speciesFile,
+ FishingOperation operation,
+ CatchBatch catchBatch,
+ List<Species> referentSpecies) {
+
+ importPupitriTrunk(trunkFile, operation, catchBatch);
+
+ importPupitriCarrousel(carrouselFile, speciesFile, operation, catchBatch, referentSpecies);
+
+ addFileAsAttachment(trunkFile, catchBatch);
+ addFileAsAttachment(carrouselFile, catchBatch);
+ addFileAsAttachment(speciesFile, catchBatch);
+
+ persistenceService.saveCatchBatch(catchBatch);
+ }
+
+ protected void addFileAsAttachment(File f, CatchBatch catchBatch) {
+ Attachment attachment = new Attachment();
+ attachment.setObjectType(AttachementObjectTypeEnum.CATCH_BATCH);
+ attachment.setObjectId(Integer.valueOf(catchBatch.getId()));
+ attachment.setName(f.getName());
+ attachment.setComment("import pupitri");
+ persistenceService.createAttachment(attachment, f);
+ }
+
+ protected void importPupitriTrunk(File file, FishingOperation operation, CatchBatch catchBatch) {
+
if (log.isInfoEnabled()) {
log.info("Will import pupitri operation [" + operation.toString() +
"] trunk from file: " + file);
@@ -140,7 +216,7 @@
}
- public List<PupitriCatch> importPupitriCarrousel(File carrouselFile,
+ protected void importPupitriCarrousel(File carrouselFile,
File speciesFile,
FishingOperation operation,
CatchBatch catchBatch,
@@ -151,7 +227,6 @@
"] carrousel from file: " + carrouselFile);
}
- List<PupitriCatch> result = Lists.newArrayList();
Reader reader = null;
File fileWithHeaders = null;
@@ -223,6 +298,7 @@
Float carrouselSortedWeight = 0f;
+ List<PupitriCatch> catches = Lists.newArrayList();
for (CarrouselRow bean : carrouselImporter) {
// is the bean from the current operation and rig ?
if (bean.getOperationCode().equals(operationNumber)
@@ -248,11 +324,11 @@
if (species != null) {
PupitriCatch pupitriCatch = new PupitriCatch(species, sorted);
- int catchIndex = result.indexOf(pupitriCatch);
+ int catchIndex = catches.indexOf(pupitriCatch);
if (catchIndex >= 0) {
- pupitriCatch = result.get(catchIndex);
+ pupitriCatch = catches.get(catchIndex);
} else {
- result.add(pupitriCatch);
+ catches.add(pupitriCatch);
}
pupitriCatch.addToSign(bean.getSign(), beanWeight);
}
@@ -260,6 +336,70 @@
}
catchBatch.setCatchTotalSortedCarousselWeight(carrouselSortedWeight);
+ BatchContainer<SpeciesBatch> rootSpeciesBatch = persistenceService.getRootSpeciesBatch(operation.getId());
+ for (SpeciesBatch batch : rootSpeciesBatch.getChildren()) {
+ persistenceService.deleteSpeciesBatch(batch.getId());
+ }
+
+ for (PupitriCatch pupitriCatch : catches) {
+
+ Float catchWeight = pupitriCatch.getWeightBySign().get(PupitriCatch.Signs.DEFAULT);
+ CaracteristicQualitativeValue cqv = pupitriCatch.isSorted() ?
+ sortedCaracteristic : unsortedCaracteristic;
+
+ SpeciesBatch batch = new SpeciesBatch();
+ batch.setFishingOperation(operation);
+ batch.setSampleCategoryType(SampleCategoryEnum.sortedUnsorted);
+ batch.setSampleCategoryValue(cqv);
+ batch.setSpecies(pupitriCatch.getSpecies());
+ batch.setSampleCategoryWeight(catchWeight);
+
+ batch = persistenceService.createSpeciesBatch(batch, null);
+
+ // if the batch is splitted
+ if (catchWeight == null) {
+ SampleCategoryEnum category = null;
+ for (PupitriCatch.Signs s : pupitriCatch.getWeightBySign().keySet()) {
+ CaracteristicQualitativeValue splitCqv = null;
+ switch (s) {
+ case MALE:
+ splitCqv = maleCaracteristic;
+ category = SampleCategoryEnum.sex;
+ break;
+
+ case FEMALE:
+ splitCqv = femaleCaracteristic;
+ category = SampleCategoryEnum.sex;
+ break;
+
+ case SMALL:
+ splitCqv = smallCaracteristic;
+ category = SampleCategoryEnum.size;
+ break;
+
+ case MEDIUM:
+ splitCqv = mediumCaracteristic;
+ category = SampleCategoryEnum.size;
+ break;
+
+ case BIG:
+ splitCqv = bigCaracteristic;
+ category = SampleCategoryEnum.size;
+ break;
+ }
+
+ SpeciesBatch childBatch = new SpeciesBatch();
+ childBatch.setFishingOperation(operation);
+ childBatch.setSampleCategoryType(category);
+ childBatch.setSampleCategoryValue(splitCqv);
+ childBatch.setSpecies(pupitriCatch.getSpecies());
+ childBatch.setSampleCategoryWeight(pupitriCatch.getWeightBySign().get(s));
+
+ persistenceService.createSpeciesBatch(childBatch, batch.getId());
+ }
+ }
+ }
+
carrouselImporter.close();
speciesImporter.close();
reader.close();
@@ -273,8 +413,6 @@
IOUtils.closeQuietly(reader);
FileUtils.deleteQuietly(fileWithHeaders);
}
-
- return result;
}
1
0