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
January 2013
- 4 participants
- 143 discussions
r279 - trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/service
by blavenier@users.forge.codelutin.com 31 Jan '13
by blavenier@users.forge.codelutin.com 31 Jan '13
31 Jan '13
Author: blavenier
Date: 2013-01-31 16:40:58 +0100 (Thu, 31 Jan 2013)
New Revision: 279
Url: http://forge.codelutin.com/projects/tutti/repository/revisions/279
Log:
Modified:
trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/service/TuttiPersistenceServiceLocator.java
Modified: trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/service/TuttiPersistenceServiceLocator.java
===================================================================
--- trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/service/TuttiPersistenceServiceLocator.java 2013-01-31 15:37:38 UTC (rev 278)
+++ trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/service/TuttiPersistenceServiceLocator.java 2013-01-31 15:40:58 UTC (rev 279)
@@ -25,7 +25,6 @@
*/
import fr.ifremer.adagio.core.service.ServiceLocator;
-import fr.ifremer.adagio.core.service.technical.CacheService;
import fr.ifremer.tutti.persistence.TuttiPersistence;
import fr.ifremer.tutti.persistence.service.synchro.ReferentialSynchronizeService;
1
0
r278 - in trunk/tutti-persistence-adagio/src: main/java/fr/ifremer/tutti/persistence/service main/resources test/java/fr/ifremer/tutti/persistence/service
by blavenier@users.forge.codelutin.com 31 Jan '13
by blavenier@users.forge.codelutin.com 31 Jan '13
31 Jan '13
Author: blavenier
Date: 2013-01-31 16:37:38 +0100 (Thu, 31 Jan 2013)
New Revision: 278
Url: http://forge.codelutin.com/projects/tutti/repository/revisions/278
Log:
ref refs #1920: [Persistence] Adagio Donnees thematiques
- Configure cache on getAllFishingVessels as eternal (disk persistence)
- Add impl in SpeciesBatchPersistenceService : getAllRootSpeciesbatch, getAllSpeciesBatch and saveSpeciesBatch
- Remove ehcache.xml : now additional cache are include into applicationContext-service-tutti.xml
Removed:
trunk/tutti-persistence-adagio/src/main/resources/ehcache.xml
Modified:
trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceServiceImpl.java
trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceImpl.java
trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/service/TuttiPersistenceServiceLocator.java
trunk/tutti-persistence-adagio/src/main/resources/applicationContext-service-tutti.xml
trunk/tutti-persistence-adagio/src/main/resources/queries-override.hbm.xml
trunk/tutti-persistence-adagio/src/test/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceServiceTest.java
trunk/tutti-persistence-adagio/src/test/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceTest.java
Modified: trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceServiceImpl.java
===================================================================
--- trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceServiceImpl.java 2013-01-31 15:26:25 UTC (rev 277)
+++ trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceServiceImpl.java 2013-01-31 15:37:38 UTC (rev 278)
@@ -213,7 +213,7 @@
}
@Override
- @Cacheable(value = "allFishingVessel")
+ @Cacheable(value = "tuttiAllFishingVessel")
public List<Vessel> getAllFishingVessel() {
Iterator<Object[]> list = queryListWithStatus(
"allVessels",
Modified: trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceImpl.java
===================================================================
--- trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceImpl.java 2013-01-31 15:26:25 UTC (rev 277)
+++ trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceImpl.java 2013-01-31 15:37:38 UTC (rev 278)
@@ -25,10 +25,15 @@
*/
import java.io.Serializable;
+import java.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import java.util.Set;
+import java.util.logging.SimpleFormatter;
import javax.annotation.Resource;
@@ -41,6 +46,7 @@
import org.springframework.stereotype.Service;
import com.google.common.base.Preconditions;
+import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import fr.ifremer.adagio.core.dao.administration.user.DepartmentImpl;
@@ -51,6 +57,7 @@
import fr.ifremer.adagio.core.dao.data.batch.CatchBatchImpl;
import fr.ifremer.adagio.core.dao.data.batch.SortingBatch;
import fr.ifremer.adagio.core.dao.data.batch.SortingBatchDao;
+import fr.ifremer.adagio.core.dao.data.batch.SortingBatchImpl;
import fr.ifremer.adagio.core.dao.data.batch.denormalized.DenormalizedBatch;
import fr.ifremer.adagio.core.dao.data.batch.denormalized.DenormalizedBatchDao;
import fr.ifremer.adagio.core.dao.data.batch.denormalized.DenormalizedBatchImpl;
@@ -106,12 +113,71 @@
@Override
public List<SpeciesBatch> getAllRootSpeciesBatch(String fishingOperationId) {
- return null;
+ Iterator<Object[]> list = queryList("allRootSpeciesBatch",
+ "fishingOperationId", IntegerType.INSTANCE, Integer.valueOf(fishingOperationId),
+ "qualitativeIdSortingType", IntegerType.INSTANCE, enumeration.QUALITATIVE_ID_SORTING_TYPE_SPECIES);
+
+ List<SpeciesBatch> result = new ArrayList<SpeciesBatch>();
+ while (list.hasNext()) {
+ Object[] source = list.next();
+ SpeciesBatch speciesBatch = loadSpeciesBatch(source, true);
+ result.add(speciesBatch);
+ }
+
+ return result;
}
@Override
public List<SpeciesBatch> getAllSpeciesBatch(String fishingOperationId) {
- return null;
+ Iterator<Object[]> list = queryList("allSpeciesBatch",
+ "fishingOperationId", IntegerType.INSTANCE, Integer.valueOf(fishingOperationId));
+
+ List<SpeciesBatch> result = new ArrayList<SpeciesBatch>();
+ List<SpeciesBatch> rootBatchs = new ArrayList<SpeciesBatch>();
+
+ Map<String, SpeciesBatch> batchMapById = new HashMap<String, SpeciesBatch>();
+ Map<String, String> parentBatchMapById = new HashMap<String, String>();
+ while (list.hasNext()) {
+ Object[] source = list.next();
+ SpeciesBatch speciesBatch = loadSpeciesBatch(source, false);
+ batchMapById.put(speciesBatch.getId(), speciesBatch);
+
+ Integer parentbatchId = (Integer)source[11];
+ if (parentbatchId != null) {
+ parentBatchMapById.put(speciesBatch.getId(), parentbatchId.toString());
+ }
+ }
+
+ for (Iterator iterator = batchMapById.values().iterator(); iterator.hasNext();) {
+ SpeciesBatch speciesBatch = (SpeciesBatch) iterator.next();
+
+ // Retrieve the parent SpeciesBatch
+ String parentbatchId = parentBatchMapById.get(speciesBatch.getId());
+ if (parentbatchId != null) {
+ SpeciesBatch parentSpeciesBatch = batchMapById.get(parentbatchId);
+
+ // If found, link the batch with its parent :
+ if (parentSpeciesBatch != null) {
+ speciesBatch.setParentBatch(parentSpeciesBatch);
+ if (parentSpeciesBatch.getChildBatchs() == null) {
+ parentSpeciesBatch.setChildBatchs(Lists.newArrayList(speciesBatch));
+ }
+ else {
+ parentSpeciesBatch.addChildBatchs(speciesBatch);
+ }
+ }
+
+ // If no parent found = batch is a child of the catch batch
+ else {
+ rootBatchs.add(speciesBatch);
+ }
+ }
+ }
+
+ // Apply inheritance, starting with the catch batch children
+ applyInheritedProperties(rootBatchs, null, null, result);
+
+ return result;
}
@Override
@@ -122,56 +188,8 @@
if (source == null) {
throw new DataRetrievalFailureException("Could not retrieve speciesBatch with id=" + id);
}
- SpeciesBatch result = new SpeciesBatch();
- result.setId(id);
-
- int colIndex = 0;
- // Individual count
- result.setNumber((Integer)source[colIndex++]);
-
- // Weight & sampleCategory Weight
- Float sampleWeight = (Float)source[colIndex++];
- Float samplingRatio = (Float)source[colIndex++];
- String samplingRatioText = (String)source[colIndex++];
- if (samplingRatio == null) {
- result.setWeight(sampleWeight);
- }
- else {
- String startStr = sampleWeight.toString().replace(',', '.') + "/";
- if (samplingRatioText != null && samplingRatioText.startsWith(startStr)) {
- String weightStr = samplingRatioText.substring(startStr.length());
- if (weightStr != null && !weightStr.isEmpty()) {
- result.setSampleCategoryWeight(sampleWeight);
- result.setWeight(Float.parseFloat(weightStr));
- }
- }
- }
-
- // Comments
- result.setComment((String)source[colIndex++]);
-
- // Sample category type
- Integer pmfmId = (Integer)source[colIndex++];
- if (pmfmId != null) {
- SampleCategoryEnum sampleCategory = measurementHelper.pmfmId2SampleCategory(pmfmId);
- result.setSampleCategoryType(sampleCategory);
- }
-
- // Sample category value
- Integer qvValue = (Integer)source[colIndex++];
- Float numValue = (Float)source[colIndex++];
- String alphaValue = (String)source[colIndex++];
- Serializable value = (qvValue!=null)?qvValue.toString():((numValue!=null)?numValue:alphaValue);
- result.setSampleCategoryValue(value);
-
- // Species
- Integer referenceTaxonId = (Integer)source[colIndex++];
- if (referenceTaxonId !=null) {
- Species species = new Species();
- species.setId(referenceTaxonId.toString());
- result.setSpecies(species);
- }
-
+
+ SpeciesBatch result = loadSpeciesBatch(source, true);
return result;
}
@@ -182,6 +200,10 @@
Preconditions.checkArgument(bean.getId() == null);
Preconditions.checkNotNull(bean.getSpecies());
Preconditions.checkNotNull(bean.getSpecies().getId());
+ Preconditions.checkNotNull(bean.getFishingOperation());
+ Preconditions.checkNotNull(bean.getFishingOperation().getId());
+ // TODO BLA uncomment this after v1.0 :
+ // Preconditions.checkNotNull(bean.getCatchBatch());
SortingBatch batch = SortingBatch.Factory.newInstance();
beanToEntity(bean, batch, parentBatchId, true);
@@ -241,48 +263,23 @@
// TODO BLA : prendre le service du 1er saisisseur ?
Integer recorderDepartmentId = enumeration.DEPARTMENT_ID_UNKNOWN_RECORDER_DEPARTMENT;
- // Retrieve entity Root batch
- //source.getFishingOperation().get
- Integer fishingOperationId = Integer.valueOf(source.getFishingOperation().getId());
- Integer rootBatchId = getRootBatchId(fishingOperationId);
- if (rootBatchId == null) {
- CatchBatch rootBatch = CatchBatch.Factory.newInstance();
- rootBatch.setFishingOperation(load(FishingOperationImpl.class, fishingOperationId));
- rootBatch.setQualityFlag(load(QualityFlagImpl.class, enumeration.QUALITY_FLAG_CODE_NOT_QUALIFIED));
- rootBatch.setRankOrder((short)1);
- rootBatch.setSynchronizationStatus(SynchronizationStatus.DIRTY.getValue());
- rootBatch = catchBatchDao.create(rootBatch);
- rootBatchId = rootBatch.getId();
- target.setRootBatch(rootBatch);
-
- //fr.ifremer.adagio.core.dao.data.operation.FishingOperation operation = load(FishingOperationImpl.class, fishingOperationId);
- //operation.setCatchBatch(rootBatch);
- getCurrentSession().flush();
- int rowUpdated = queryUpdate("updateFishingOperationCatchBatch",
- "fishingOperationId", IntegerType.INSTANCE, fishingOperationId,
- "catchBatchId", IntegerType.INSTANCE, rootBatchId);
- if (rowUpdated == 0) {
- throw new DataIntegrityViolationException("Could not attach catch batch to the given operation : operation was not found.");
- }
- }
- else {
- target.setRootBatch(load(CatchBatchImpl.class, Integer.valueOf(rootBatchId)));
- }
- // Parent batch
- Integer targetParentBatchId = null;;
- if (parentBatchId == null || parentBatchId.isEmpty()) {
- targetParentBatchId = rootBatchId;
- }
- else {
- targetParentBatchId = Integer.valueOf(parentBatchId);
+ // 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(parentBatchId))) {
+ setBatchParents(source, target, parentBatchId, notChangedSortingMeasurements);
}
- if (copyIfNull && targetParentBatchId == null) {
- target.setParentBatch(null);
- }
- else if (targetParentBatchId != null){
- target.setParentBatch(load(BatchImpl.class, targetParentBatchId));
- }
// RankOrder
if (target.getRankOrder() == null) {
@@ -293,16 +290,6 @@
}
target.setRankOrder(rankOrder);
}
-
- // 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());
- }
// Weight or SampleCategoryWeight
if (copyIfNull && source.getWeight() == null) {
@@ -329,13 +316,17 @@
target.setSamplingRatio(source.getSampleCategoryWeight().floatValue() / source.getWeight().floatValue());
}
- // SampleCategoryWeight
+ // Sorting measurement
if (copyIfNull && (source.getSampleCategoryType() == null || source.getSampleCategoryValue() == null)) {
// Nothing to do : will be removed later, using notChangedSortingMeasurements
}
else if (source.getSampleCategoryType() != null && source.getSampleCategoryValue() != null) {
- SortingMeasurement sortingMeasurement = measurementHelper.setSortingMeasurement(target, recorderDepartmentId, source.getSampleCategoryType(), source.getSampleCategoryValue());
- notChangedSortingMeasurements.remove(sortingMeasurement);
+ Integer pmfmId = measurementHelper.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 = measurementHelper.setSortingMeasurement(target, recorderDepartmentId, source.getSampleCategoryType(), source.getSampleCategoryValue());
+ notChangedSortingMeasurements.remove(sortingMeasurement);
+ }
}
// Individual count
@@ -384,11 +375,153 @@
}
}
- public Integer getRootBatchId(Integer fishingOperationId) {
- Integer catchBatchId = queryUniqueTyped("fishingOperationCatchBatch",
- "fishingOperationId", IntegerType.INSTANCE, fishingOperationId);
- return catchBatchId;
+ public void setBatchParents(SpeciesBatch source, SortingBatch target, String parentBatchIdStr,
+ Set<SortingMeasurement> notChangedSortingMeasurements) {
+
+ Preconditions.checkNotNull(target);
+ Preconditions.checkNotNull(source.getFishingOperation());
+ Preconditions.checkNotNull(source.getFishingOperation().getId());
+
+ // Retrieve parent and root batch
+ if (parentBatchIdStr == null) {
+ // Retrieve category type
+ Integer pmfmId = measurementHelper.sampleCategory2PmfmId(source.getSampleCategoryType());
+ if (pmfmId == null || !pmfmId.equals(enumeration.PMFM_ID_SORTED_UNSORTED)) {
+ throw new DataIntegrityViolationException(MessageFormat.format("A species batch with no parent should have a sampleCategoryType with id={0}.",
+ new Object[]{enumeration.PMFM_ID_SORTED_UNSORTED}));
+ }
+ Integer qualitativeValueId = Integer.valueOf(source.getSampleCategoryValue().toString());
+
+ Object[] cols = queryUnique("parentBatch",
+ "fishingOperationId", IntegerType.INSTANCE, Integer.valueOf(source.getFishingOperation().getId()),
+ "pmfmIdSorted", IntegerType.INSTANCE, enumeration.PMFM_ID_SORTED_UNSORTED,
+ "qualitativeIdSorted", IntegerType.INSTANCE, qualitativeValueId,
+ "pmfmIdSortingType", IntegerType.INSTANCE, enumeration.PMFM_ID_SORTING_TYPE,
+ "qualitativeIdSortingType", IntegerType.INSTANCE, enumeration.QUALITATIVE_ID_SORTING_TYPE_SPECIES);
+
+ // Parent Batch
+ Integer parentBatchId = (Integer)cols[0];
+ SortingBatch parentBatch = load(SortingBatchImpl.class, parentBatchId);
+ target.setParentBatch(parentBatch);
+
+ // Root Batch
+ Integer rootBatchId = (Integer)cols[1];
+ target.setRootBatch(load(CatchBatchImpl.class, rootBatchId));
+ }
+
+ // Load existing parent and root
+ else {
+ SortingBatch parentBatch = load(SortingBatchImpl.class, Integer.valueOf(parentBatchIdStr));
+ target.setParentBatch(parentBatch);
+ target.setRootBatch(parentBatch.getRootBatch());
+ }
}
+
+ protected SpeciesBatch loadSpeciesBatch(Object[] source, boolean sourceHasPmfmGrandParent) {
+ int colIndex = 0;
+
+ SpeciesBatch result = new SpeciesBatch();
+ result.setId(source[colIndex++].toString());
+
+ // Individual count
+ result.setNumber((Integer)source[colIndex++]);
+
+ // Weight & sampleCategory Weight
+ Float sampleWeight = (Float)source[colIndex++];
+ Float samplingRatio = (Float)source[colIndex++];
+ String samplingRatioText = (String)source[colIndex++];
+ if (samplingRatio == null) {
+ result.setWeight(sampleWeight);
+ }
+ else if (sampleWeight != null){
+ String startStr = sampleWeight.toString().replace(',', '.') + "/";
+ if (samplingRatioText != null && samplingRatioText.startsWith(startStr)) {
+ String weightStr = samplingRatioText.substring(startStr.length());
+ if (weightStr != null && !weightStr.isEmpty()) {
+ result.setSampleCategoryWeight(sampleWeight);
+ result.setWeight(Float.parseFloat(weightStr));
+ }
+ }
+ }
+ // Comments
+ result.setComment((String)source[colIndex++]);
+
+ // Sample category type
+ Integer pmfmId = (Integer)source[colIndex++];
+
+ // Sample category value
+ Integer qvValue = (Integer)source[colIndex++];
+ Float numValue = (Float)source[colIndex++];
+ String alphaValue = (String)source[colIndex++];
+ Serializable value = (qvValue!=null)?qvValue.toString():((numValue!=null)?numValue:alphaValue);
+ // Species
+ Integer referenceTaxonId = (Integer)source[colIndex++];
+ if (referenceTaxonId !=null) {
+ Species species = new Species();
+ species.setId(referenceTaxonId.toString());
+ result.setSpecies(species);
+ }
+
+ if (sourceHasPmfmGrandParent && colIndex == source.length-2) {
+ Integer pmfmIdGrandFather = (Integer)source[colIndex++];
+ Integer qualitativeIdGrandFather = (Integer)source[colIndex++];
+
+ if (pmfmId != null && value != null) {
+ SampleCategoryEnum sampleCategory = measurementHelper.pmfmId2SampleCategory(pmfmId);
+ result.setSampleCategoryType(sampleCategory);
+ result.setSampleCategoryValue(value);
+ }
+
+ // When no sorting measurement found, retrieve the sorted/unsorted from an ancestor batch
+ else {
+ if (referenceTaxonId != null
+ && enumeration.PMFM_ID_SORTED_UNSORTED.equals(pmfmIdGrandFather)
+ && qualitativeIdGrandFather != null){
+ result.setSampleCategoryType(SampleCategoryEnum.sortedUnsorted);
+ result.setSampleCategoryValue(qualitativeIdGrandFather.toString());
+ }
+ else {
+ // TODO TC : manage this exception in the UI => 'format des captures incompatibles avec tutti...'
+ // TODO TC : add a throws 'InvalidBatchTreeException' in the interface method ?
+ throw new DataRetrievalFailureException("Invalid batch tree found in database (no sample category Vrac/HorsVrac found in parents) : could not be load batch with id=" + result.getId());
+ }
+ }
+ }
+
+ return result;
+ }
+
+ protected void applyInheritedProperties(List<SpeciesBatch> speciesBatchs, Serializable inheritedSampleCategoryValue, Species inheritedSpecies, List<SpeciesBatch> result) {
+ if (speciesBatchs == null || speciesBatchs.size() == 0) {
+ return;
+ }
+ boolean hasAppliedCategoryValue = false;
+ for (Iterator iterator = speciesBatchs.iterator(); iterator.hasNext();) {
+ SpeciesBatch speciesBatch = (SpeciesBatch) iterator.next();
+
+ if (speciesBatch.getSpecies() != null && speciesBatch.getSampleCategoryType() == null) {
+ speciesBatch.setSampleCategoryType(SampleCategoryEnum.sortedUnsorted);
+ speciesBatch.setSampleCategoryValue(inheritedSampleCategoryValue);
+ hasAppliedCategoryValue = true;
+
+ // Remove the link to the parent (not need after inheritance)
+ speciesBatch.setParentBatch(null);
+ }
+ else if (speciesBatch.getSpecies() == null && inheritedSpecies != null) {
+ speciesBatch.setSpecies(inheritedSpecies);
+ }
+
+ // Store into result list only if species has been set (ignore upper batch)
+ if (speciesBatch.getSpecies() != null) {
+ result.add(speciesBatch);
+ }
+
+ // Recursive call : propage species but not category if already applied
+ applyInheritedProperties(speciesBatch.getChildBatchs(),
+ (hasAppliedCategoryValue ? null : inheritedSampleCategoryValue),
+ speciesBatch.getSpecies(), result);
+ }
+ }
}
Modified: trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/service/TuttiPersistenceServiceLocator.java
===================================================================
--- trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/service/TuttiPersistenceServiceLocator.java 2013-01-31 15:26:25 UTC (rev 277)
+++ trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/service/TuttiPersistenceServiceLocator.java 2013-01-31 15:37:38 UTC (rev 278)
@@ -25,6 +25,7 @@
*/
import fr.ifremer.adagio.core.service.ServiceLocator;
+import fr.ifremer.adagio.core.service.technical.CacheService;
import fr.ifremer.tutti.persistence.TuttiPersistence;
import fr.ifremer.tutti.persistence.service.synchro.ReferentialSynchronizeService;
@@ -118,7 +119,7 @@
return instance().getService("referentialSynchronizeService",
ReferentialSynchronizeService.class);
}
-
+
public static void close() {
instance().shutdown();
}
Modified: trunk/tutti-persistence-adagio/src/main/resources/applicationContext-service-tutti.xml
===================================================================
--- trunk/tutti-persistence-adagio/src/main/resources/applicationContext-service-tutti.xml 2013-01-31 15:26:25 UTC (rev 277)
+++ trunk/tutti-persistence-adagio/src/main/resources/applicationContext-service-tutti.xml 2013-01-31 15:37:38 UTC (rev 278)
@@ -37,4 +37,30 @@
<bean id="tuttiEnumerationFile" init-method="init"
class="fr.ifremer.tutti.persistence.service.TuttiEnumerationFile"/>
+ <!-- Specific caches for tutti (not defined in ehcache.xml) -->
+ <bean id="tuttiAbstractCache" abstract="true" class="org.springframework.cache.ehcache.EhCacheFactoryBean">
+ <property name="cacheManager" ref="ehcache"/>
+ <property name="maxElementsInMemory" value="5000"/>
+ <property name="eternal" value="false"/>
+ <property name="timeToLive" value="300"/>
+ <property name="timeToIdle" value="300"/>
+ <property name="overflowToDisk" value="false"/>
+ <property name="diskPersistent" value="false"/>
+ <property name="diskExpiryThreadIntervalSeconds" value="300"/>
+ </bean>
+
+ <bean id="tuttiAllFishingVesselCache" parent="tuttiAbstractCache">
+ <property name="cacheName" value="tuttiAllFishingVessel" />
+ <property name="eternal" value="true"/>
+ <property name="overflowToDisk" value="true"/>
+ <property name="diskPersistent" value="true"/>
+ <!-- removed inherited properties -->
+ <property name="timeToLive" value="0"/>
+ <property name="timeToIdle" value="0"/>
+ </bean>
+
+ <!-- Example to use to create a new cache area :
+ <bean id="tuttiOtherCache" parent="tuttiPersistenceDefaultCache">
+ </bean> -->
+
</beans>
\ No newline at end of file
Deleted: trunk/tutti-persistence-adagio/src/main/resources/ehcache.xml
===================================================================
--- trunk/tutti-persistence-adagio/src/main/resources/ehcache.xml 2013-01-31 15:26:25 UTC (rev 277)
+++ trunk/tutti-persistence-adagio/src/main/resources/ehcache.xml 2013-01-31 15:37:38 UTC (rev 278)
@@ -1,86 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- #%L
- Tutti :: Persistence Adagio (impl)
- $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%
- -->
-
-<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://ehcache.org/ehcache.xsd"
- updateCheck="false">
-
- <!-- Sets the path to the directory where cache .data files are created.
-
- If the path is a Java System Property it is replaced by
- its value in the running VM.
-
- The following properties are translated:
- user.home - User's home directory
- user.dir - User's current working directory
- java.io.tmpdir - Default temp file path -->
- <diskStore path="java.io.tmpdir/ehcache"/>
-
- <!--Default Cache configuration. These will applied to caches programmatically created through
- the CacheManager.
-
- The following attributes are required for defaultCache:
-
- maxInMemory - Sets the maximum number of objects that will be created in memory
- eternal - Sets whether elements are eternal. If eternal, timeouts are ignored and the element
- is never expired.
- timeToIdleSeconds - Sets the time to idle for an element before it expires.
- i.e. The maximum amount of time between accesses before an element expires
- Is only used if the element is not eternal.
- Optional attribute. A value of 0 means that an Element can idle for infinity
- timeToLiveSeconds - Sets the time to live for an element before it expires.
- i.e. The maximum time between creation time and when an element expires.
- Is only used if the element is not eternal.
- overflowToDisk - Sets whether elements can overflow to disk when the in-memory cache
- has reached the maxInMemory limit.
-
- -->
- <defaultCache
- maxElementsInMemory="10000"
- eternal="false"
- timeToIdleSeconds="120"
- timeToLiveSeconds="120"
- overflowToDisk="true" />
-
- <!-- memoryStoreEvictionPolicy :
- LRU - least recently used
- LFU - least frequently used
- FIFO - first in first out, the oldest element by creation time
- -->
- <cache name="allFishingVessel" eternal="true"
- maxElementsInMemory="1"
- memoryStoreEvictionPolicy="LFU"/>
-
- <cache name="org.hibernate.cache.UpdateTimestampsCache"
- maxElementsInMemory="5000" timeToIdleSeconds="300"
- timeToLiveSeconds="300" overflowToDisk="true" diskPersistent="false"
- diskExpiryThreadIntervalSeconds="300" memoryStoreEvictionPolicy="LRU" />
-
- <cache name="org.hibernate.cache.StandardQueryCache"
- maxElementsInMemory="10000" eternal="false" timeToIdleSeconds="300"
- timeToLiveSeconds="300" overflowToDisk="true" diskPersistent="false"
- diskExpiryThreadIntervalSeconds="300" memoryStoreEvictionPolicy="LRU" />
-
-</ehcache>
\ No newline at end of file
Modified: trunk/tutti-persistence-adagio/src/main/resources/queries-override.hbm.xml
===================================================================
--- trunk/tutti-persistence-adagio/src/main/resources/queries-override.hbm.xml 2013-01-31 15:26:25 UTC (rev 277)
+++ trunk/tutti-persistence-adagio/src/main/resources/queries-override.hbm.xml 2013-01-31 15:37:38 UTC (rev 278)
@@ -46,7 +46,7 @@
</query>
<!-- [DAT-02] Get all cruises for a given program (to list with no detail) -->
- <query cacheable="true" name="allCruises">
+ <query name="allCruises">
<![CDATA[
SELECT
c.id,
@@ -63,7 +63,7 @@
</query>
<!-- [DAT-03] Get a detail program -->
- <query cacheable="true" name="program">
+ <query name="program">
<![CDATA[
SELECT
p.code,
@@ -78,7 +78,7 @@
</query>
<!-- [DAT-03-1] Get a program locations -->
- <query cacheable="true" name="allProgramLocations">
+ <query name="allProgramLocations">
<![CDATA[
SELECT
l.id,
@@ -94,7 +94,7 @@
</query>
<!-- [DAT-04] Get a detail cruise -->
- <query cacheable="true" name="cruise">
+ <query name="cruise">
<![CDATA[
SELECT
sc.program.code AS programCode,
@@ -123,7 +123,7 @@
<query-param name="countryLocationLevelId" type="java.lang.Integer"/>
</query>
- <query cacheable="true" name="allCruiseGears">
+ <query name="allCruiseGears">
<![CDATA[
SELECT
gpf.gear.id AS gearId,
@@ -148,7 +148,7 @@
<query-param name="pmfmIdTrawlNet" type="java.lang.Integer"/>
</query>
- <query cacheable="true" name="allCruiseSecondaryVessels">
+ <query name="allCruiseSecondaryVessels">
<![CDATA[
SELECT
va.operationVesselAssociationPk.vessel.code AS associatedVesselCode
@@ -165,7 +165,7 @@
<query-param name="cruiseId" type="java.lang.Integer"/>
</query>
- <query cacheable="true" name="allFishingOperations">
+ <query name="allFishingOperations">
<![CDATA[
SELECT
o.id AS id,
@@ -188,7 +188,7 @@
<query-param name="pmfmIdMultirigAggregation" type="java.lang.Integer"/>
</query>
- <query cacheable="true" name="fishingOperation">
+ <query name="fishingOperation">
<![CDATA[
SELECT
o.name AS name,
@@ -218,7 +218,7 @@
<query-param name="locationLevelIdLocalite" type="java.lang.Integer"/>
</query>
- <query cacheable="true" name="fishingOperationRankOrder">
+ <query name="fishingOperationRankOrder">
<![CDATA[
SELECT
count(o1.id)+1 as fishingOperationRankOrder
@@ -235,7 +235,7 @@
- <query cacheable="true" name="fishingOperationEnvironment">
+ <query name="fishingOperationEnvironment">
<![CDATA[
SELECT
vum.pmfm.id as pmfmId,
@@ -251,7 +251,7 @@
<query-param name="fishingOperationId" type="java.lang.Integer"/>
</query>
- <query cacheable="true" name="fishingOperationGearShooting">
+ <query name="fishingOperationGearShooting">
<![CDATA[
SELECT
gum.pmfm.id as pmfmId,
@@ -278,7 +278,7 @@
<query-param name="catchBatchId" type="java.lang.Integer"/>
</query>
- <query cacheable="true" name="catchBatch">
+ <query name="catchBatch">
<![CDATA[
SELECT
cb.id AS catchBatchId,
@@ -304,83 +304,130 @@
)
ORDER BY b1.id, b2.id
]]>
- <!-- Other equivalente query (but slower)
+ <query-param name="fishingOperationId" type="java.lang.Integer"/>
+ <query-param name="pmfmIdSorted" type="java.lang.Integer"/>
+ <query-param name="pmfmIdSortingType" type="java.lang.Integer"/>
+ </query>
+
+ <query name="allRootSpeciesBatch">
+ <![CDATA[
SELECT
- cb.id AS catchBatchId,
- cbQm.numericalValue as totalWeight,
- b1.id AS id1,
- b1.samplingRatioText as samplingRatioText1,
- qm2.numericalValue AS weight1,
- sm1.qualitativeValue.id AS qv2,
- b2.id AS id2,
- b2.samplingRatioText AS samplingRatioText2,
- qm1.numericalValue AS weight2,
- sm2.qualitativeValue.id AS qv2
+ b.id as batchId,
+ b.individualCount AS individualCount,
+ qm.numericalValue AS weight,
+ b.samplingRatio AS samplingRatio,
+ b.samplingRatioText AS samplingRatioText,
+ b.comments AS comments,
+ sm.pmfm.id AS pmfmId,
+ sm.qualitativeValue.id as qvValue,
+ sm.numericalValue AS numValue,
+ sm.alphanumericalValue AS alphaValue,
+ b.referenceTaxon.id AS referenceTaxonId,
+ smSorted.pmfm.id AS pmfmIdGrandFather,
+ smSorted.qualitativeValue.id AS qualitativeIdGrandFather
+ FROM
+ CatchBatchImpl cb
+ INNER JOIN cb.childBatchs batchSorted
+ INNER JOIN batchSorted.childBatchs batchSortingType
+ INNER JOIN batchSortingType.childBatchs b
+ INNER JOIN batchSortingType.sortingMeasurements smSortingType
+ LEFT OUTER JOIN batchSorted.sortingMeasurements smSorted
+ LEFT OUTER JOIN b.sortingMeasurements sm
+ LEFT OUTER JOIN b.quantificationMeasurements qm
+ WHERE
+ cb.fishingOperation.id=:fishingOperationId
+ AND (
+ qm is null
+ OR qm.isReferenceQuantification=true
+ )
+ AND smSortingType.qualitativeValue.id=:qualitativeIdSortingType
+ ORDER BY b.id
+ ]]>
+ <query-param name="fishingOperationId" type="java.lang.Integer"/>
+ <query-param name="qualitativeIdSortingType" type="java.lang.Integer"/>
+ </query>
+
+ <query name="allSpeciesBatch">
+ <![CDATA[
+ SELECT
+ b.id as batchId,
+ b.individualCount AS individualCount,
+ qm.numericalValue AS weight,
+ b.samplingRatio AS samplingRatio,
+ b.samplingRatioText AS samplingRatioText,
+ b.comments AS comments,
+ sm.pmfm.id AS pmfmId,
+ sm.qualitativeValue.id as qvValue,
+ sm.numericalValue AS numValue,
+ sm.alphanumericalValue AS alphaValue,
+ b.referenceTaxon.id as referenceTaxonId,
+ b.parentBatch.id as parentBatchId
+ FROM
+ SortingBatchImpl b
+ INNER JOIN b.rootBatch cb
+ LEFT OUTER JOIN b.sortingMeasurements sm
+ LEFT OUTER JOIN b.quantificationMeasurements qm
+ WHERE
+ cb.fishingOperation.id=:fishingOperationId
+ AND (
+ qm is null
+ OR qm.isReferenceQuantification=true
+ )
+ ORDER BY b.id
+ ]]>
+ <query-param name="fishingOperationId" type="java.lang.Integer"/>
+ </query>
+
+ <query name="parentBatch">
+ <![CDATA[
+ SELECT
+ b2.id as parentBatchId,
+ cb.id as rootBatchId
FROM
- CatchBatchImpl cb
+ CatchBatchImpl cb
INNER JOIN cb.childBatchs b1
- INNER JOIN b1.childBatchs b2
- LEFT OUTER JOIN cb.quantificationMeasurements cbQm
- LEFT OUTER JOIN b1.quantificationMeasurements qm1
- LEFT OUTER JOIN b2.quantificationMeasurements qm2,
+ INNER JOIN b1.childBatchs b2,
SortingMeasurementImpl sm1,
SortingMeasurementImpl sm2
WHERE
cb.fishingOperation.id = :fishingOperationId
- AND (
- cbQm is null
- OR cbQm.isReferenceQuantification=true
- )
- AND sm1.sortingBatch.id=b1.id
+ AND sm1.sortingBatch.id=b1.id
AND sm1.pmfm.id=:pmfmIdSorted
- AND (
- qm2 is null
- OR qm2.isReferenceQuantification=true
- )
+ AND sm1.qualitativeValue.id=:qualitativeIdSorted
AND sm2.sortingBatch.id=b2.id
AND sm2.pmfm.id=:pmfmIdSortingType
- AND (
- qm1 is null
- OR qm1.isReferenceQuantification=true
- )
- ORDER BY b1.id, b2.id
- -->
+ AND sm2.qualitativeValue.id=:qualitativeIdSortingType
+ ]]>
<query-param name="fishingOperationId" type="java.lang.Integer"/>
<query-param name="pmfmIdSorted" type="java.lang.Integer"/>
+ <query-param name="qualitativeIdSorted" type="java.lang.Integer"/>
<query-param name="pmfmIdSortingType" type="java.lang.Integer"/>
- </query>
+ <query-param name="qualitativeIdSortingType" type="java.lang.Integer"/>
+ </query>
- <!--query cacheable="true" name="allFishingOperationBatchs">
+ <query name="speciesBatch">
<![CDATA[
- select
- db.id
- from
- BatchImpl db
- WHERE
- db.id = :fishingOperationId
- ORDER BY
- db.flatRankOrder
- ]]>
- <query-param name="fishingOperationId" type="java.lang.Integer"/>
- </query-->
-
- <query cacheable="true" name="speciesBatch">
- <![CDATA[
SELECT
+ b.id AS batchId,
b.individualCount AS individualCount,
qm.numericalValue AS weight,
b.samplingRatio AS samplingRatio,
b.samplingRatioText AS samplingRatioText,
b.comments AS comments,
- sm.pmfm.id as pmfmId,
+ sm.pmfm.id AS pmfmId,
sm.qualitativeValue.id as qvValue,
sm.numericalValue AS numValue,
sm.alphanumericalValue AS alphaValue,
- b.referenceTaxon.id as referenceTaxonId
+ b.referenceTaxon.id AS referenceTaxonId,
+ smSorted.pmfm.id AS pmfmIdGrandFather,
+ smSorted.qualitativeValue.id AS qualitativeIdGrandFather
FROM
- SortingBatchImpl b
- LEFT OUTER JOIN b.sortingMeasurements sm
- LEFT OUTER JOIN b.quantificationMeasurements qm
+ SortingBatchImpl b
+ INNER JOIN b.parentBatch batchSortingType
+ INNER JOIN batchSortingType.parentBatch batchSorted
+ LEFT OUTER JOIN batchSorted.sortingMeasurements smSorted
+ LEFT OUTER JOIN b.sortingMeasurements sm
+ LEFT OUTER JOIN b.quantificationMeasurements qm
WHERE
b.id = :batchId
AND (
Modified: trunk/tutti-persistence-adagio/src/test/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceServiceTest.java
===================================================================
--- trunk/tutti-persistence-adagio/src/test/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceServiceTest.java 2013-01-31 15:26:25 UTC (rev 277)
+++ trunk/tutti-persistence-adagio/src/test/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceServiceTest.java 2013-01-31 15:37:38 UTC (rev 278)
@@ -25,6 +25,8 @@
*/
import com.google.common.base.Preconditions;
+
+import fr.ifremer.adagio.core.service.technical.CacheService;
import fr.ifremer.tutti.persistence.DatabaseResource;
import fr.ifremer.tutti.persistence.TuttiPersistenceDevImpl;
import fr.ifremer.tutti.persistence.config.TuttiPersistenceDevConfig;
@@ -68,6 +70,8 @@
protected static TuttiPersistenceDevImpl storage;
protected ReferentialPersistenceService service;
+
+ protected CacheService cacheService;
@BeforeClass
public static void beforeClass() throws IOException {
@@ -114,6 +118,10 @@
@Before
public void setUp() throws Exception {
service = TuttiPersistenceServiceLocator.getReferentialPersistenceService();
+ cacheService = TuttiPersistenceServiceLocator.instance().getCacheService();
+
+ // This is need for test : getAllFishingVessel()
+ cacheService.clearAllCaches();
}
@Test
@@ -199,13 +207,23 @@
assertSize(result, storage.getAllScientificVessel());
}
- //FIXME : requete trop longue (index manquant, trop de jointures?)
@Test
- @Ignore
public void getAllFishingVessel() {
+ long time = System.currentTimeMillis();
List<Vessel> result = service.getAllFishingVessel();
+ long delta1 = System.currentTimeMillis() - time;
+
Assert.assertNotNull(result);
- Assert.assertEquals(31620, result.size());
+ Assert.assertEquals(24805, result.size());
+
+ // try again, to check cache is enable
+ time = System.currentTimeMillis();
+ result = service.getAllFishingVessel();
+ long delta2 = System.currentTimeMillis() - time;
+
+ float reduceFactor = delta2 * 100 / delta1;
+ Assert.assertTrue("The cache on getAllFishingVessel() should have speed up more than factor 10. Make sure EhCache is well configured.", reduceFactor < 0.1);
+
persistList(Vessel.class, "Fishing", result);
assertSize(result, storage.getAllFishingVessel());
}
Modified: trunk/tutti-persistence-adagio/src/test/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceTest.java
===================================================================
--- trunk/tutti-persistence-adagio/src/test/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceTest.java 2013-01-31 15:26:25 UTC (rev 277)
+++ trunk/tutti-persistence-adagio/src/test/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceTest.java 2013-01-31 15:37:38 UTC (rev 278)
@@ -30,6 +30,7 @@
import java.util.List;
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;
@@ -47,7 +48,6 @@
* @author tchemit <chemit(a)codelutin.com>
* @since 0.3
*/
-@Ignore
public class SpeciesBatchPersistenceServiceTest {
@ClassRule
@@ -57,18 +57,23 @@
protected CruisePersistenceService cruiseService;
protected FishingOperationPersistenceService fishingOperationService;
+ protected CatchBatchPersistenceService catchBatchService;
protected ReferentialPersistenceService referentialService;
protected Cruise cruise;
protected FishingOperation fishingOperation;
+ protected CatchBatch catchBacth;
protected List<Species> species;
+ protected String speciesBacthId = null;
+
@Before
public void setUp() throws Exception {
service = TuttiPersistenceServiceLocator.getSpeciesBatchPersistenceService();
cruiseService = TuttiPersistenceServiceLocator.getCruisePersistenceService();
fishingOperationService = TuttiPersistenceServiceLocator.getFishingOperationPersistenceService();
referentialService = TuttiPersistenceServiceLocator.getReferentialPersistenceService();
+ catchBatchService = TuttiPersistenceServiceLocator.getCatchBatchPersistenceService();
cruise = cruiseService.getCruise(dbResource.getFixtures().cruiseId());
cruise.setId(null);
@@ -96,6 +101,10 @@
fishingOperation.setGearShootingEndDate(calendar.getTime());
fishingOperation = fishingOperationService.createFishingOperation(fishingOperation);
+
+ catchBacth = new CatchBatch();
+ catchBacth.setFishingOperation(fishingOperation);
+ catchBacth = catchBatchService.createCatchBatch(catchBacth);
species = referentialService.getAllSpecies();
assertNotNull(species);
@@ -103,73 +112,46 @@
}
@Test
- @Ignore
- public void getAllRootSpeciesBatch(/*String fishingOperationId*/) {
-
- List<SpeciesBatch> speciesBatch = service.getAllRootSpeciesBatch(fishingOperation.getId());
- assertNotNull(speciesBatch);
- assertTrue(speciesBatch.size() > 0);
-
- }
-
- @Test
- public void getAllSpeciesBatch(/*String fishingOperationId*/) {
-
- }
-
- @Test
- public void getSpeciesBatch(/*String id*/) {
-
- }
-
- @Test
public void createSpeciesBatch(/*SpeciesBatch bean, String parentBatchId*/) {
Caracteristic sortedUnsortedPMFM = referentialService.getSortedUnsortedCaracteristic();
String horsVracQualitativeValueId = sortedUnsortedPMFM.getQualitativeValue(0).getId();
String vracQualitativeValueId = sortedUnsortedPMFM.getQualitativeValue(1).getId();
+ Caracteristic maturityPMFM = referentialService.getMaturityCaracteristic();
+ String firstMaturityQualitativeValueId = maturityPMFM.getQualitativeValue(0).getId();
Species taxon1 = species.get(0);
Species taxon2 = species.get(1);
Caracteristic sexPMFM = referentialService.getSexCaracteristic();
String maleQualitativeValueId = sexPMFM.getQualitativeValue(1).getId();
String femaleQualitativeValueId = sexPMFM.getQualitativeValue(2).getId();
+ String unkQualitativeValueId = sexPMFM.getQualitativeValue(3).getId();
SpeciesBatch esp1Batch = null;
+ SpeciesBatch esp2Batch = null;
SpeciesBatch batch = null;
- SpeciesBatch createdBatch = null;
- SpeciesBatch reloadedBatch = null;
// -----------------------------------------------------------------------------
// 1. Test with only mandatory properties
// -----------------------------------------------------------------------------
// batch : "ESP1 - Vrac/5"
batch = new SpeciesBatch();
+ batch.setParentBatch(null);
batch.setFishingOperation(fishingOperation);
+ // TODO TC : add link between Speciesbatch and CatchBatch
+ //batch.setCatchBatch(catchBatch);
batch.setSpecies(taxon1);
batch.setSampleCategoryType(SampleCategoryEnum.sortedUnsorted);
batch.setSampleCategoryValue(vracQualitativeValueId);
batch.setWeight(5f);
- createdBatch = service.createSpeciesBatch(batch, null);
- assertNotNull(createdBatch);
- assertNotNull(createdBatch.getId());
- reloadedBatch = service.getSpeciesBatch(createdBatch.getId());
- assertNotNull(reloadedBatch);
- assertNull(reloadedBatch.getFishingOperation());
- assertEquals(createdBatch.getId(), reloadedBatch.getId());
- assertEquals(batch.getWeight(), reloadedBatch.getWeight());
- assertEquals(batch.getNumber(), reloadedBatch.getNumber());
- assertEquals(batch.getComment(), reloadedBatch.getComment());
- assertEquals(batch.getSampleCategoryType(), reloadedBatch.getSampleCategoryType());
- assertEquals(batch.getSampleCategoryValue(), reloadedBatch.getSampleCategoryValue());
- assertNotNull(reloadedBatch.getSpecies());
- assertEquals(batch.getSpecies().getId(), reloadedBatch.getSpecies().getId());
+ assertCreateAndReloadSpeciesBatch(batch, null);
// Save ESP1 batch
- esp1Batch = reloadedBatch;
+ 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);
@@ -180,22 +162,13 @@
batch.setSampleCategoryWeight(1f);
batch.setNumber(7);
- createdBatch = service.createSpeciesBatch(batch, batch.getParentBatch().getId());
- assertNotNull(createdBatch);
- assertNotNull(createdBatch.getId());
- reloadedBatch = service.getSpeciesBatch(createdBatch.getId());
- assertNotNull(reloadedBatch);
- assertNull(reloadedBatch.getParentBatch());
- assertEquals(batch.getNumber(), reloadedBatch.getNumber());
- assertEquals(batch.getSampleCategoryType(), reloadedBatch.getSampleCategoryType());
- assertEquals(batch.getSampleCategoryValue(), reloadedBatch.getSampleCategoryValue());
- assertEquals(batch.getWeight(), reloadedBatch.getWeight());
- assertEquals(batch.getSampleCategoryWeight(), reloadedBatch.getSampleCategoryWeight());
+ 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);
@@ -206,42 +179,144 @@
batch.setSampleCategoryWeight(null);
batch.setNumber(14);
- createdBatch = service.createSpeciesBatch(batch, batch.getParentBatch().getId());
- assertNotNull(createdBatch);
- assertNotNull(createdBatch.getId());
- reloadedBatch = service.getSpeciesBatch(createdBatch.getId());
- assertNotNull(reloadedBatch);
- assertNull(reloadedBatch.getParentBatch());
- assertEquals(batch.getNumber(), reloadedBatch.getNumber());
- assertEquals(batch.getSampleCategoryType(), reloadedBatch.getSampleCategoryType());
- assertEquals(batch.getSampleCategoryValue(), reloadedBatch.getSampleCategoryValue());
- assertEquals(batch.getWeight(), reloadedBatch.getWeight());
- assertEquals(batch.getSampleCategoryWeight(), reloadedBatch.getSampleCategoryWeight());
+ assertCreateAndReloadSpeciesBatch(batch, batch.getParentBatch().getId());
+
+ // -----------------------------------------------------------------------------
+ // 4. Test : ESP2 - Vrac/7
+ // \- ESP2 - Vrac/7 UNK/2 ss-ech/1 Nombre/11
+ // -----------------------------------------------------------------------------
+ // batch : "ESP2 - Vrac/7 "
+ batch = new SpeciesBatch();
+ batch.setParentBatch(null);
+ // TODO TC : add link between Speciesbatch and CatchBatch
+ //batch.setCatchBatch(catchBatch);
+ batch.setSpecies(taxon2);
+ batch.setSampleCategoryType(SampleCategoryEnum.sortedUnsorted);
+ batch.setSampleCategoryValue(vracQualitativeValueId);
+ batch.setWeight(7f);
+ assertCreateAndReloadSpeciesBatch(batch, null);
+ esp2Batch = batch;
- /*
- reloadedBatch.setSampleCategoryWeight(1.5f);
- reloadedBatch.setParentBatch(createdBatch.getParentBatch());
- reloadedBatch.setFishingOperation(fishingOperation);
- service.saveSpeciesBatch(reloadedBatch);
- */
+ // Batch : ESP2 - Vrac/7 UNK/2 ss-ech/1 Nombre/11
+ batch = new SpeciesBatch();
+ batch.setId(null);
+ batch.setParentBatch(esp2Batch);
+ batch.setSpecies(taxon1);
+ batch.setComment("ESP2 - Vrac/7 UNK/2 ss-ech/1 Nombre/11");
+ batch.setSampleCategoryType(SampleCategoryEnum.maturity);
+ batch.setSampleCategoryValue(firstMaturityQualitativeValueId);
+ batch.setWeight(2f);
+ batch.setSampleCategoryWeight(1f);
+ batch.setNumber(11);
+
+ assertCreateAndReloadSpeciesBatch(batch, batch.getParentBatch().getId());
+
+ // -----------------------------------------------------------------------------
+ // 5. Test save after modifications
+ // -----------------------------------------------------------------------------
+ // Batch : ESP2 - Vrac/7 UNK/1.75 ss-ech/1.11 Nombre/99
+ batch.setSampleCategoryType(SampleCategoryEnum.sex);
+ batch.setSampleCategoryValue(unkQualitativeValueId);
+ batch.setComment("ESP2 - Vrac/7 UNK/1.75 ss-ech/1.11 Nombre/99");
+ batch.setWeight(1.75f);
+ batch.setSampleCategoryWeight(1.11f);
+ batch.setFishingOperation(fishingOperation);
+ batch.setNumber(99);
+
+ // Save and reload, then check
+ SpeciesBatch savedBatch = service.saveSpeciesBatch(batch);
+ assertSpeciesBatch(savedBatch, batch, false);
+ SpeciesBatch reloadedBatch = service.getSpeciesBatch(savedBatch.getId());
+ assertSpeciesBatch(reloadedBatch, savedBatch, true);
+
+ // -----------------------------------------------------------------------------
+ // 6. Test get all root species
+ // -----------------------------------------------------------------------------
+ List<SpeciesBatch> rootSpeciesBatch = service.getAllRootSpeciesBatch(fishingOperation.getId());
+ assertNotNull(rootSpeciesBatch);
+ assertEquals(2, rootSpeciesBatch.size());
+
+ // -----------------------------------------------------------------------------
+ // 4. Test get all species
+ // -----------------------------------------------------------------------------
+ List<SpeciesBatch> allSpeciesBatch = service.getAllSpeciesBatch(fishingOperation.getId());
+ assertNotNull(allSpeciesBatch);
+ assertEquals(5, allSpeciesBatch.size());
}
@Test
+ @Ignore
public void saveSpeciesBatch(/*SpeciesBatch bean*/) {
+
+ }
+
+ @Test
+ @Ignore
+ public void getSpeciesBatch(/*String id*/) {
+ if (speciesBacthId == null) return;
+ SpeciesBatch batch = service.getSpeciesBatch(speciesBacthId);
+ assertNotNull(batch);
}
@Test
+ @Ignore
+ public void getAllSpeciesBatch(/*String fishingOperationId*/) {
+
+ }
+ @Test
+ @Ignore
+ public void getAllRootSpeciesBatch(/*String fishingOperationId*/) {
+ }
+
+ @Test
+ @Ignore
public void deleteSpeciesBatch(/*String id*/) {
}
@Test
+ @Ignore
public void deleteSpeciesSubBatch(/*String id*/) {
}
@Test
+ @Ignore
public void getAllSpeciesBatchFrequency(/*String speciesBatchId*/) {
}
+
+ protected void assertCreateAndReloadSpeciesBatch(SpeciesBatch batch, String parentBatchId) {
+ batch.setFishingOperation(fishingOperation);
+
+ // Create batch
+ SpeciesBatch createdBatch = service.createSpeciesBatch(batch, parentBatchId);
+ assertSpeciesBatch(createdBatch, batch, false);
+
+ // then reload (for round trip check)
+ SpeciesBatch reloadedBatch = service.getSpeciesBatch(createdBatch.getId());
+ assertNull(reloadedBatch.getParentBatch());
+ assertSpeciesBatch(reloadedBatch, batch, 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());
+ assertEquals(expectedBatch.getSampleCategoryValue(), actualBatch.getSampleCategoryValue());
+ assertEquals(expectedBatch.getSampleCategoryWeight(), actualBatch.getSampleCategoryWeight());
+ assertEquals(expectedBatch.getNumber(), actualBatch.getNumber());
+ assertEquals(expectedBatch.getComment(), actualBatch.getComment());
+ if (expectedBatch.getSpecies() != null){
+ assertNotNull(actualBatch.getSpecies());
+ assertEquals(expectedBatch.getSpecies().getId(), actualBatch.getSpecies().getId());
+ }
+ }
+
}
1
0
31 Jan '13
Author: tchemit
Date: 2013-01-31 16:26:25 +0100 (Thu, 31 Jan 2013)
New Revision: 277
Url: http://forge.codelutin.com/projects/tutti/repository/revisions/277
Log:
refs #1819: [PROTOCOLE] - Gestion des listes pr?\195?\169f?\195?\169r?\195?\169es / r?\195?\169f?\195?\169rentiel (import / export des caract?\195?\169ristiques)
Added:
trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/protocol/
trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/protocol/CaracteristicRow.java
trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/protocol/CaracteristicType.java
trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/protocol/ProtocolCaracteristicExportModel.java
trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/protocol/ProtocolCaracteristicImportModel.java
trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/protocol/TuttiProtocolImportExportService.java
trunk/tutti-service/src/test/java/fr/ifremer/tutti/service/protocol/
trunk/tutti-service/src/test/java/fr/ifremer/tutti/service/protocol/TuttiProtocolImportExportServiceTest.java
trunk/tutti-service/src/test/resources/log4j.properties
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/ExportAllCaracteristicAction.java
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/ExportProtocolCaracteristicAction.java
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/ImportProtocolCaracteristicAction.java
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/ImportProtocolSpeciesAction.java
Removed:
trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/TuttiProtocolImportExportService.java
trunk/tutti-service/src/test/java/fr/ifremer/tutti/service/TuttiProtocolImportExportServiceTest.java
Modified:
trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/service/measure/MeasurementPersistenceHelper.java
trunk/tutti-persistence-adagio/src/main/resources/ehcache.xml
trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/entities/TuttiEntities.java
trunk/tutti-service/pom.xml
trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/config/TuttiServiceConfig.java
trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/config/TuttiServiceConfigOption.java
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/home/ExportProtocolAction.java
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/home/ImportProtocolAction.java
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolUI.css
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolUI.jaxx
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolUIHandler.java
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolUIModel.java
trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_fr_FR.properties
trunk/tutti-ui-swing/src/main/resources/icons/action-alert-error.png
trunk/tutti-ui-swing/src/main/resources/icons/action-alert-info.png
trunk/tutti-ui-swing/src/main/resources/icons/action-alert-none.png
trunk/tutti-ui-swing/src/main/resources/icons/action-alert-warning.png
trunk/tutti-ui-swing/src/main/resources/icons/action-protocol.png
Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/entities/TuttiEntities.java
===================================================================
--- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/entities/TuttiEntities.java 2013-01-31 08:47:56 UTC (rev 276)
+++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/entities/TuttiEntities.java 2013-01-31 15:26:25 UTC (rev 277)
@@ -187,6 +187,11 @@
return connection;
}
+ public static <B extends IdAware> List<String> collecIds(List<B> list) {
+ List<String> result = Lists.transform(list, GET_ID);
+ return result;
+ }
+
protected static class IdPredicate<B extends IdAware> implements Predicate<B> {
private final String id;
Modified: trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/service/measure/MeasurementPersistenceHelper.java
===================================================================
--- trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/service/measure/MeasurementPersistenceHelper.java 2013-01-31 08:47:56 UTC (rev 276)
+++ trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/service/measure/MeasurementPersistenceHelper.java 2013-01-31 15:26:25 UTC (rev 277)
@@ -1,345 +1,370 @@
-package fr.ifremer.tutti.persistence.service.measure;
-
-import java.io.Serializable;
-import java.util.Iterator;
-
-import javax.annotation.Resource;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Component;
-
-import com.google.common.base.Preconditions;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Sets;
-
-import fr.ifremer.adagio.core.dao.administration.user.DepartmentImpl;
-import fr.ifremer.adagio.core.dao.data.batch.Batch;
-import fr.ifremer.adagio.core.dao.data.batch.SortingBatch;
-import fr.ifremer.adagio.core.dao.data.measure.GearPhysicalMeasurement;
-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.survey.fishingTrip.FishingTrip;
-import fr.ifremer.adagio.core.dao.data.survey.scientificCruise.ScientificCruise;
-import fr.ifremer.adagio.core.dao.data.vessel.feature.physical.GearPhysicalFeatures;
-import fr.ifremer.adagio.core.dao.referential.QualityFlagDao;
-import fr.ifremer.adagio.core.dao.referential.QualityFlagImpl;
-import fr.ifremer.adagio.core.dao.referential.gear.GearImpl;
-import fr.ifremer.adagio.core.dao.referential.pmfm.Pmfm;
-import fr.ifremer.adagio.core.dao.referential.pmfm.PmfmImpl;
-import fr.ifremer.adagio.core.dao.referential.pmfm.QualitativeValue;
-import fr.ifremer.adagio.core.dao.referential.pmfm.QualitativeValueImpl;
-import fr.ifremer.tutti.persistence.entities.data.SampleCategoryEnum;
-import fr.ifremer.tutti.persistence.entities.referential.Caracteristic;
-import fr.ifremer.tutti.persistence.entities.referential.CaracteristicType;
-import fr.ifremer.tutti.persistence.service.AbstractPersistenceService;
-import fr.ifremer.tutti.persistence.service.ReferentialPersistenceService;
-import fr.ifremer.tutti.persistence.service.TuttiEnumerationFile;
-
-@Component("measurementPersistenceHelper")
-public class MeasurementPersistenceHelper extends AbstractPersistenceService {
-
- @Autowired(required=true)
- protected TuttiEnumerationFile enumeration;
-
- @Resource(name = "referentialPersistenceService")
- protected ReferentialPersistenceService referentialService;
-
- @Resource(name = "qualityFlagDao")
- protected QualityFlagDao qualityFlagDao;
-
- public MeasurementPersistenceHelper() {
- }
-
- public QuantificationMeasurement setQuantificationMeasurement(
- Batch batch, Integer pmfmId, Integer recorderDepartmentId,
- Float weightValue, boolean isReferenceSorting) {
- QuantificationMeasurement quantificationMeasurement = getQuantificationMeasurement(
- batch, pmfmId, recorderDepartmentId, true);
-
- quantificationMeasurement.setNumericalValue(weightValue);
- quantificationMeasurement
- .setIsReferenceQuantification(isReferenceSorting);
- return quantificationMeasurement;
- }
-
- public QuantificationMeasurement getQuantificationMeasurement(
- Batch batch, Integer pmfmId, Integer recorderDepartmentId,
- boolean createIfNotExists) {
- QuantificationMeasurement quantificationMeasurement = null;
- if (batch.getQuantificationMeasurements() != null) {
- for (Iterator iterator = batch
- .getQuantificationMeasurements().iterator(); iterator
- .hasNext();) {
- QuantificationMeasurement qm = (QuantificationMeasurement) iterator
- .next();
- if (pmfmId.equals(qm.getPmfm().getId())) {
- quantificationMeasurement = qm;
- break;
- }
- }
- }
- if (quantificationMeasurement == null) {
- if (!createIfNotExists) {
- return null;
- }
- quantificationMeasurement = QuantificationMeasurement.Factory
- .newInstance();
- quantificationMeasurement.setBatch(batch);
- if (batch.getQuantificationMeasurements() == null) {
- batch.setQuantificationMeasurements(Sets
- .newHashSet(quantificationMeasurement));
- } else {
- batch.getQuantificationMeasurements().add(
- quantificationMeasurement);
- }
- quantificationMeasurement.setQualityFlag(load(
- QualityFlagImpl.class,
- enumeration.QUALITY_FLAG_CODE_NOT_QUALIFIED));
- quantificationMeasurement.setDepartment(load(DepartmentImpl.class,
- recorderDepartmentId));
- quantificationMeasurement.setPmfm(load(PmfmImpl.class, pmfmId));
- }
-
- return quantificationMeasurement;
- }
-
- 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 = null;
- if (value instanceof Integer) {
- qvId = (Integer)value;
- }
- 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 = sampleCategory2PmfmId(sampleCategory);
-
- Caracteristic caracteristic = referentialService.getCaracteristic(pmfmId);
- SortingMeasurement sortingMeasurement = 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 = getSortingMeasurement(
- sortingBatch, pmfmId, recorderDepartmentId, true);
- setMeasurement(sortingMeasurement, caracteristic, value);
- return sortingMeasurement;
- }
-
- public SortingMeasurement getSortingMeasurement(
- SortingBatch sortingBatch, Integer pmfmId, Integer recorderDepartmentId,
- boolean createIfNotExists) {
- SortingMeasurement sortingMeasurement = null;
- if (sortingBatch.getSortingMeasurements() != null) {
- for (Iterator iterator = sortingBatch
- .getSortingMeasurements().iterator(); iterator
- .hasNext();) {
- SortingMeasurement qm = (SortingMeasurement) iterator
- .next();
- if (pmfmId.equals(qm.getPmfm().getId())) {
- sortingMeasurement = qm;
- break;
- }
- }
- }
- if (sortingMeasurement == null) {
- if (!createIfNotExists) {
- return null;
- }
- sortingMeasurement = SortingMeasurement.Factory
- .newInstance();
- sortingMeasurement.setSortingBatch(sortingBatch);
- if (sortingBatch.getSortingMeasurements() == null) {
- sortingBatch.setSortingMeasurements(Sets
- .newHashSet(sortingMeasurement));
- sortingMeasurement.setRankOrder(1);
- } else {
- sortingBatch.getSortingMeasurements().add(
- sortingMeasurement);
- sortingMeasurement.setRankOrder(sortingBatch.getSortingMeasurements().size());
- }
- sortingMeasurement.setQualityFlag(load(
- QualityFlagImpl.class,
- enumeration.QUALITY_FLAG_CODE_NOT_QUALIFIED));
- sortingMeasurement.setDepartment(load(DepartmentImpl.class,
- recorderDepartmentId));
- sortingMeasurement.setPmfm(load(PmfmImpl.class, pmfmId));
- }
-
- return sortingMeasurement;
- }
-
- public 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;
- }
-
- public SampleCategoryEnum pmfmId2SampleCategory(Integer pmfmId) {
- SampleCategoryEnum sampleCategory = null;
- if (pmfmId.intValue() == enumeration.PMFM_ID_SORTED_UNSORTED.intValue()) {
- sampleCategory = SampleCategoryEnum.sortedUnsorted;
- }
- else if (enumeration.PMFM_ID_SIZE_CATEGORY.equals(pmfmId)) {
- sampleCategory = SampleCategoryEnum.size;
- }
- else if (enumeration.PMFM_ID_MATURITY.equals(pmfmId)) {
- sampleCategory = SampleCategoryEnum.maturity;
- }
- else if (enumeration.PMFM_ID_SEX.equals(pmfmId)) {
- sampleCategory = SampleCategoryEnum.sex;
- }
- else if (enumeration.PMFM_ID_AGE.equals(pmfmId)) {
- sampleCategory = SampleCategoryEnum.age;
- }
- if (sampleCategory == null) {
- throw new IllegalArgumentException("Unable to find corresponding SampleCategoryEnum for PMFM.ID : " + pmfmId);
- }
- return sampleCategory;
- }
-
- public GearPhysicalFeatures getGearPhysicalfeatures(FishingTrip fishingTrip, Integer gearId) {
- return getGearPhysicalfeatures(fishingTrip, gearId, false);
- }
-
- public GearPhysicalFeatures getGearPhysicalfeatures(FishingTrip fishingTrip, Integer gearId, boolean createIfNotExists) {
- // Retrieve entities : Gear Physical Features
- if (fishingTrip.getGearPhysicalFeatures() != null && fishingTrip.getGearPhysicalFeatures().size() >= 0) {
- for (Iterator iterator = fishingTrip.getGearPhysicalFeatures().iterator(); iterator.hasNext();) {
- GearPhysicalFeatures guf = (GearPhysicalFeatures) iterator.next();
- if (gearId.equals(guf.getGear().getId())) {
- return guf;
- }
- }
- }
- if (!createIfNotExists) {
- return null;
- }
-
- GearPhysicalFeatures gearPhysicalFeature = GearPhysicalFeatures.Factory.newInstance();
- gearPhysicalFeature.setFishingTrip(fishingTrip);
-
- fr.ifremer.adagio.core.dao.referential.gear.Gear gear = (fr.ifremer.adagio.core.dao.referential.gear.Gear)getCurrentSession().load(GearImpl.class, gearId);
- gearPhysicalFeature.setGear(gear);
- if (fishingTrip.getGearPhysicalFeatures() == null) {
- fishingTrip.setGearPhysicalFeatures(Lists.newArrayList(gearPhysicalFeature));
- } else {
- fishingTrip.getGearPhysicalFeatures().add(gearPhysicalFeature);
- }
-
- return gearPhysicalFeature;
- }
-
- public GearPhysicalMeasurement getGearPhysicalMeasurement(GearPhysicalFeatures gearPhysicalFeatures, Integer pmfmId) {
- return getGearPhysicalMeasurement(null, gearPhysicalFeatures, pmfmId, false);
- }
-
- protected GearPhysicalMeasurement getGearPhysicalMeasurement(ScientificCruise scientificCruise, GearPhysicalFeatures gearPhysicalFeatures,
- Integer pmfmId, boolean createIfNotExists) {
- GearPhysicalMeasurement gearPhysicalMeasurement = null;
- if (gearPhysicalFeatures.getGearPhysicalMeasurements() != null) {
- for (Iterator iterator = gearPhysicalFeatures.getGearPhysicalMeasurements().iterator(); iterator.hasNext();) {
- GearPhysicalMeasurement vum = (GearPhysicalMeasurement) iterator.next();
- if (pmfmId.equals(vum.getPmfm().getId())) {
- gearPhysicalMeasurement = vum;
- break;
- }
- }
- }
- if (gearPhysicalMeasurement == null) {
- if (!createIfNotExists) {
- return null;
- }
- gearPhysicalMeasurement = GearPhysicalMeasurement.Factory.newInstance();
- gearPhysicalMeasurement.setGearPhysicalFeatures(gearPhysicalFeatures);
- if (gearPhysicalFeatures.getGearPhysicalMeasurements() == null) {
- gearPhysicalFeatures.setGearPhysicalMeasurements(Lists.newArrayList(gearPhysicalMeasurement));
- }
- else {
- gearPhysicalFeatures.getGearPhysicalMeasurements().add(gearPhysicalMeasurement);
- }
- gearPhysicalMeasurement.setQualityFlag(qualityFlagDao.load(enumeration.QUALITY_FLAG_CODE_NOT_QUALIFIED));
- gearPhysicalMeasurement.setDepartment(scientificCruise.getRecorderDepartment());
- Pmfm pmfm = (Pmfm)getCurrentSession().load(PmfmImpl.class, pmfmId);
- gearPhysicalMeasurement.setPmfm(pmfm);
- //gearPhysicalMeasurement.setPmfm(pmfmDao.load(pmfmId));
- }
-
- return gearPhysicalMeasurement;
- }
-
- public void removeGearPhysicalMeasurement(GearPhysicalFeatures gearPhysicalFeatures,
- Integer pmfmId) {
- GearPhysicalMeasurement gearPhysicalMeasurement = getGearPhysicalMeasurement(null, gearPhysicalFeatures, pmfmId, false);
- if (gearPhysicalMeasurement == null) {
- return;
- }
- gearPhysicalFeatures.getGearPhysicalMeasurements().remove(gearPhysicalMeasurement);
- // TOBO BLa : vérifier qu'il ne faut pas dao.delete() en plus
- }
-
- public GearPhysicalMeasurement setGearPhysicalMeasurement(ScientificCruise scientificCruise, GearPhysicalFeatures gearPhysicalFeatures,
- Integer pmfmId,
- Float numericalValue,
- String alphanumericalValue,
- Integer qualitativevalueId) {
- GearPhysicalMeasurement gearPhysicalMeasurement = getGearPhysicalMeasurement(scientificCruise, gearPhysicalFeatures, pmfmId, true);
-
- if (alphanumericalValue != null) {
- gearPhysicalMeasurement.setAlphanumericalValue(alphanumericalValue);
- }
- else if (numericalValue != null) {
- gearPhysicalMeasurement.setNumericalValue(numericalValue);
- }
- else if (qualitativevalueId != null) {
- QualitativeValue qv = (QualitativeValue)getCurrentSession().load(QualitativeValueImpl.class, qualitativevalueId);
- gearPhysicalMeasurement.setQualitativeValue(qv);
- //gearPhysicalMeasurement.setQualitativeValue(qualitativeValueDao.load(qualitativevalueId));
- }
-
- return gearPhysicalMeasurement;
- }
-}
+package fr.ifremer.tutti.persistence.service.measure;
+
+/*
+ * #%L
+ * Tutti :: Persistence Adagio (impl)
+ * $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;
+import java.util.Iterator;
+
+import javax.annotation.Resource;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Sets;
+
+import fr.ifremer.adagio.core.dao.administration.user.DepartmentImpl;
+import fr.ifremer.adagio.core.dao.data.batch.Batch;
+import fr.ifremer.adagio.core.dao.data.batch.SortingBatch;
+import fr.ifremer.adagio.core.dao.data.measure.GearPhysicalMeasurement;
+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.survey.fishingTrip.FishingTrip;
+import fr.ifremer.adagio.core.dao.data.survey.scientificCruise.ScientificCruise;
+import fr.ifremer.adagio.core.dao.data.vessel.feature.physical.GearPhysicalFeatures;
+import fr.ifremer.adagio.core.dao.referential.QualityFlagDao;
+import fr.ifremer.adagio.core.dao.referential.QualityFlagImpl;
+import fr.ifremer.adagio.core.dao.referential.gear.GearImpl;
+import fr.ifremer.adagio.core.dao.referential.pmfm.Pmfm;
+import fr.ifremer.adagio.core.dao.referential.pmfm.PmfmImpl;
+import fr.ifremer.adagio.core.dao.referential.pmfm.QualitativeValue;
+import fr.ifremer.adagio.core.dao.referential.pmfm.QualitativeValueImpl;
+import fr.ifremer.tutti.persistence.entities.data.SampleCategoryEnum;
+import fr.ifremer.tutti.persistence.entities.referential.Caracteristic;
+import fr.ifremer.tutti.persistence.entities.referential.CaracteristicType;
+import fr.ifremer.tutti.persistence.service.AbstractPersistenceService;
+import fr.ifremer.tutti.persistence.service.ReferentialPersistenceService;
+import fr.ifremer.tutti.persistence.service.TuttiEnumerationFile;
+
+@Component("measurementPersistenceHelper")
+public class MeasurementPersistenceHelper extends AbstractPersistenceService {
+
+ @Autowired(required=true)
+ protected TuttiEnumerationFile enumeration;
+
+ @Resource(name = "referentialPersistenceService")
+ protected ReferentialPersistenceService referentialService;
+
+ @Resource(name = "qualityFlagDao")
+ protected QualityFlagDao qualityFlagDao;
+
+ public MeasurementPersistenceHelper() {
+ }
+
+ public QuantificationMeasurement setQuantificationMeasurement(
+ Batch batch, Integer pmfmId, Integer recorderDepartmentId,
+ Float weightValue, boolean isReferenceSorting) {
+ QuantificationMeasurement quantificationMeasurement = getQuantificationMeasurement(
+ batch, pmfmId, recorderDepartmentId, true);
+
+ quantificationMeasurement.setNumericalValue(weightValue);
+ quantificationMeasurement
+ .setIsReferenceQuantification(isReferenceSorting);
+ return quantificationMeasurement;
+ }
+
+ public QuantificationMeasurement getQuantificationMeasurement(
+ Batch batch, Integer pmfmId, Integer recorderDepartmentId,
+ boolean createIfNotExists) {
+ QuantificationMeasurement quantificationMeasurement = null;
+ if (batch.getQuantificationMeasurements() != null) {
+ for (Iterator iterator = batch
+ .getQuantificationMeasurements().iterator(); iterator
+ .hasNext();) {
+ QuantificationMeasurement qm = (QuantificationMeasurement) iterator
+ .next();
+ if (pmfmId.equals(qm.getPmfm().getId())) {
+ quantificationMeasurement = qm;
+ break;
+ }
+ }
+ }
+ if (quantificationMeasurement == null) {
+ if (!createIfNotExists) {
+ return null;
+ }
+ quantificationMeasurement = QuantificationMeasurement.Factory
+ .newInstance();
+ quantificationMeasurement.setBatch(batch);
+ if (batch.getQuantificationMeasurements() == null) {
+ batch.setQuantificationMeasurements(Sets
+ .newHashSet(quantificationMeasurement));
+ } else {
+ batch.getQuantificationMeasurements().add(
+ quantificationMeasurement);
+ }
+ quantificationMeasurement.setQualityFlag(load(
+ QualityFlagImpl.class,
+ enumeration.QUALITY_FLAG_CODE_NOT_QUALIFIED));
+ quantificationMeasurement.setDepartment(load(DepartmentImpl.class,
+ recorderDepartmentId));
+ quantificationMeasurement.setPmfm(load(PmfmImpl.class, pmfmId));
+ }
+
+ return quantificationMeasurement;
+ }
+
+ 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 = null;
+ if (value instanceof Integer) {
+ qvId = (Integer)value;
+ }
+ 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 = sampleCategory2PmfmId(sampleCategory);
+
+ Caracteristic caracteristic = referentialService.getCaracteristic(pmfmId);
+ SortingMeasurement sortingMeasurement = 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 = getSortingMeasurement(
+ sortingBatch, pmfmId, recorderDepartmentId, true);
+ setMeasurement(sortingMeasurement, caracteristic, value);
+ return sortingMeasurement;
+ }
+
+ public SortingMeasurement getSortingMeasurement(
+ SortingBatch sortingBatch, Integer pmfmId, Integer recorderDepartmentId,
+ boolean createIfNotExists) {
+ SortingMeasurement sortingMeasurement = null;
+ if (sortingBatch.getSortingMeasurements() != null) {
+ for (Iterator iterator = sortingBatch
+ .getSortingMeasurements().iterator(); iterator
+ .hasNext();) {
+ SortingMeasurement qm = (SortingMeasurement) iterator
+ .next();
+ if (pmfmId.equals(qm.getPmfm().getId())) {
+ sortingMeasurement = qm;
+ break;
+ }
+ }
+ }
+ if (sortingMeasurement == null) {
+ if (!createIfNotExists) {
+ return null;
+ }
+ sortingMeasurement = SortingMeasurement.Factory
+ .newInstance();
+ sortingMeasurement.setSortingBatch(sortingBatch);
+ if (sortingBatch.getSortingMeasurements() == null) {
+ sortingBatch.setSortingMeasurements(Sets
+ .newHashSet(sortingMeasurement));
+ sortingMeasurement.setRankOrder(1);
+ } else {
+ sortingBatch.getSortingMeasurements().add(
+ sortingMeasurement);
+ sortingMeasurement.setRankOrder(sortingBatch.getSortingMeasurements().size());
+ }
+ sortingMeasurement.setQualityFlag(load(
+ QualityFlagImpl.class,
+ enumeration.QUALITY_FLAG_CODE_NOT_QUALIFIED));
+ sortingMeasurement.setDepartment(load(DepartmentImpl.class,
+ recorderDepartmentId));
+ sortingMeasurement.setPmfm(load(PmfmImpl.class, pmfmId));
+ }
+
+ return sortingMeasurement;
+ }
+
+ public 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;
+ }
+
+ public SampleCategoryEnum pmfmId2SampleCategory(Integer pmfmId) {
+ SampleCategoryEnum sampleCategory = null;
+ if (pmfmId.intValue() == enumeration.PMFM_ID_SORTED_UNSORTED.intValue()) {
+ sampleCategory = SampleCategoryEnum.sortedUnsorted;
+ }
+ else if (enumeration.PMFM_ID_SIZE_CATEGORY.equals(pmfmId)) {
+ sampleCategory = SampleCategoryEnum.size;
+ }
+ else if (enumeration.PMFM_ID_MATURITY.equals(pmfmId)) {
+ sampleCategory = SampleCategoryEnum.maturity;
+ }
+ else if (enumeration.PMFM_ID_SEX.equals(pmfmId)) {
+ sampleCategory = SampleCategoryEnum.sex;
+ }
+ else if (enumeration.PMFM_ID_AGE.equals(pmfmId)) {
+ sampleCategory = SampleCategoryEnum.age;
+ }
+ if (sampleCategory == null) {
+ throw new IllegalArgumentException("Unable to find corresponding SampleCategoryEnum for PMFM.ID : " + pmfmId);
+ }
+ return sampleCategory;
+ }
+
+ public GearPhysicalFeatures getGearPhysicalfeatures(FishingTrip fishingTrip, Integer gearId) {
+ return getGearPhysicalfeatures(fishingTrip, gearId, false);
+ }
+
+ public GearPhysicalFeatures getGearPhysicalfeatures(FishingTrip fishingTrip, Integer gearId, boolean createIfNotExists) {
+ // Retrieve entities : Gear Physical Features
+ if (fishingTrip.getGearPhysicalFeatures() != null && fishingTrip.getGearPhysicalFeatures().size() >= 0) {
+ for (Iterator iterator = fishingTrip.getGearPhysicalFeatures().iterator(); iterator.hasNext();) {
+ GearPhysicalFeatures guf = (GearPhysicalFeatures) iterator.next();
+ if (gearId.equals(guf.getGear().getId())) {
+ return guf;
+ }
+ }
+ }
+ if (!createIfNotExists) {
+ return null;
+ }
+
+ GearPhysicalFeatures gearPhysicalFeature = GearPhysicalFeatures.Factory.newInstance();
+ gearPhysicalFeature.setFishingTrip(fishingTrip);
+
+ fr.ifremer.adagio.core.dao.referential.gear.Gear gear = (fr.ifremer.adagio.core.dao.referential.gear.Gear)getCurrentSession().load(GearImpl.class, gearId);
+ gearPhysicalFeature.setGear(gear);
+ if (fishingTrip.getGearPhysicalFeatures() == null) {
+ fishingTrip.setGearPhysicalFeatures(Lists.newArrayList(gearPhysicalFeature));
+ } else {
+ fishingTrip.getGearPhysicalFeatures().add(gearPhysicalFeature);
+ }
+
+ return gearPhysicalFeature;
+ }
+
+ public GearPhysicalMeasurement getGearPhysicalMeasurement(GearPhysicalFeatures gearPhysicalFeatures, Integer pmfmId) {
+ return getGearPhysicalMeasurement(null, gearPhysicalFeatures, pmfmId, false);
+ }
+
+ protected GearPhysicalMeasurement getGearPhysicalMeasurement(ScientificCruise scientificCruise, GearPhysicalFeatures gearPhysicalFeatures,
+ Integer pmfmId, boolean createIfNotExists) {
+ GearPhysicalMeasurement gearPhysicalMeasurement = null;
+ if (gearPhysicalFeatures.getGearPhysicalMeasurements() != null) {
+ for (Iterator iterator = gearPhysicalFeatures.getGearPhysicalMeasurements().iterator(); iterator.hasNext();) {
+ GearPhysicalMeasurement vum = (GearPhysicalMeasurement) iterator.next();
+ if (pmfmId.equals(vum.getPmfm().getId())) {
+ gearPhysicalMeasurement = vum;
+ break;
+ }
+ }
+ }
+ if (gearPhysicalMeasurement == null) {
+ if (!createIfNotExists) {
+ return null;
+ }
+ gearPhysicalMeasurement = GearPhysicalMeasurement.Factory.newInstance();
+ gearPhysicalMeasurement.setGearPhysicalFeatures(gearPhysicalFeatures);
+ if (gearPhysicalFeatures.getGearPhysicalMeasurements() == null) {
+ gearPhysicalFeatures.setGearPhysicalMeasurements(Lists.newArrayList(gearPhysicalMeasurement));
+ }
+ else {
+ gearPhysicalFeatures.getGearPhysicalMeasurements().add(gearPhysicalMeasurement);
+ }
+ gearPhysicalMeasurement.setQualityFlag(qualityFlagDao.load(enumeration.QUALITY_FLAG_CODE_NOT_QUALIFIED));
+ gearPhysicalMeasurement.setDepartment(scientificCruise.getRecorderDepartment());
+ Pmfm pmfm = (Pmfm)getCurrentSession().load(PmfmImpl.class, pmfmId);
+ gearPhysicalMeasurement.setPmfm(pmfm);
+ //gearPhysicalMeasurement.setPmfm(pmfmDao.load(pmfmId));
+ }
+
+ return gearPhysicalMeasurement;
+ }
+
+ public void removeGearPhysicalMeasurement(GearPhysicalFeatures gearPhysicalFeatures,
+ Integer pmfmId) {
+ GearPhysicalMeasurement gearPhysicalMeasurement = getGearPhysicalMeasurement(null, gearPhysicalFeatures, pmfmId, false);
+ if (gearPhysicalMeasurement == null) {
+ return;
+ }
+ gearPhysicalFeatures.getGearPhysicalMeasurements().remove(gearPhysicalMeasurement);
+ // TOBO BLa : vérifier qu'il ne faut pas dao.delete() en plus
+ }
+
+ public GearPhysicalMeasurement setGearPhysicalMeasurement(ScientificCruise scientificCruise, GearPhysicalFeatures gearPhysicalFeatures,
+ Integer pmfmId,
+ Float numericalValue,
+ String alphanumericalValue,
+ Integer qualitativevalueId) {
+ GearPhysicalMeasurement gearPhysicalMeasurement = getGearPhysicalMeasurement(scientificCruise, gearPhysicalFeatures, pmfmId, true);
+
+ if (alphanumericalValue != null) {
+ gearPhysicalMeasurement.setAlphanumericalValue(alphanumericalValue);
+ }
+ else if (numericalValue != null) {
+ gearPhysicalMeasurement.setNumericalValue(numericalValue);
+ }
+ else if (qualitativevalueId != null) {
+ QualitativeValue qv = (QualitativeValue)getCurrentSession().load(QualitativeValueImpl.class, qualitativevalueId);
+ gearPhysicalMeasurement.setQualitativeValue(qv);
+ //gearPhysicalMeasurement.setQualitativeValue(qualitativeValueDao.load(qualitativevalueId));
+ }
+
+ return gearPhysicalMeasurement;
+ }
+}
\ No newline at end of file
Property changes on: trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/service/measure/MeasurementPersistenceHelper.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: trunk/tutti-persistence-adagio/src/main/resources/ehcache.xml
===================================================================
--- trunk/tutti-persistence-adagio/src/main/resources/ehcache.xml 2013-01-31 08:47:56 UTC (rev 276)
+++ trunk/tutti-persistence-adagio/src/main/resources/ehcache.xml 2013-01-31 15:26:25 UTC (rev 277)
@@ -1,62 +1,86 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://ehcache.org/ehcache.xsd"
- updateCheck="false">
-
- <!-- Sets the path to the directory where cache .data files are created.
-
- If the path is a Java System Property it is replaced by
- its value in the running VM.
-
- The following properties are translated:
- user.home - User's home directory
- user.dir - User's current working directory
- java.io.tmpdir - Default temp file path -->
- <diskStore path="java.io.tmpdir/ehcache"/>
-
- <!--Default Cache configuration. These will applied to caches programmatically created through
- the CacheManager.
-
- The following attributes are required for defaultCache:
-
- maxInMemory - Sets the maximum number of objects that will be created in memory
- eternal - Sets whether elements are eternal. If eternal, timeouts are ignored and the element
- is never expired.
- timeToIdleSeconds - Sets the time to idle for an element before it expires.
- i.e. The maximum amount of time between accesses before an element expires
- Is only used if the element is not eternal.
- Optional attribute. A value of 0 means that an Element can idle for infinity
- timeToLiveSeconds - Sets the time to live for an element before it expires.
- i.e. The maximum time between creation time and when an element expires.
- Is only used if the element is not eternal.
- overflowToDisk - Sets whether elements can overflow to disk when the in-memory cache
- has reached the maxInMemory limit.
-
- -->
- <defaultCache
- maxElementsInMemory="10000"
- eternal="false"
- timeToIdleSeconds="120"
- timeToLiveSeconds="120"
- overflowToDisk="true" />
-
- <!-- memoryStoreEvictionPolicy :
- LRU - least recently used
- LFU - least frequently used
- FIFO - first in first out, the oldest element by creation time
- -->
- <cache name="allFishingVessel" eternal="true"
- maxElementsInMemory="1"
- memoryStoreEvictionPolicy="LFU"/>
-
- <cache name="org.hibernate.cache.UpdateTimestampsCache"
- maxElementsInMemory="5000" timeToIdleSeconds="300"
- timeToLiveSeconds="300" overflowToDisk="true" diskPersistent="false"
- diskExpiryThreadIntervalSeconds="300" memoryStoreEvictionPolicy="LRU" />
-
- <cache name="org.hibernate.cache.StandardQueryCache"
- maxElementsInMemory="10000" eternal="false" timeToIdleSeconds="300"
- timeToLiveSeconds="300" overflowToDisk="true" diskPersistent="false"
- diskExpiryThreadIntervalSeconds="300" memoryStoreEvictionPolicy="LRU" />
-
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ #%L
+ Tutti :: Persistence Adagio (impl)
+ $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%
+ -->
+
+<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://ehcache.org/ehcache.xsd"
+ updateCheck="false">
+
+ <!-- Sets the path to the directory where cache .data files are created.
+
+ If the path is a Java System Property it is replaced by
+ its value in the running VM.
+
+ The following properties are translated:
+ user.home - User's home directory
+ user.dir - User's current working directory
+ java.io.tmpdir - Default temp file path -->
+ <diskStore path="java.io.tmpdir/ehcache"/>
+
+ <!--Default Cache configuration. These will applied to caches programmatically created through
+ the CacheManager.
+
+ The following attributes are required for defaultCache:
+
+ maxInMemory - Sets the maximum number of objects that will be created in memory
+ eternal - Sets whether elements are eternal. If eternal, timeouts are ignored and the element
+ is never expired.
+ timeToIdleSeconds - Sets the time to idle for an element before it expires.
+ i.e. The maximum amount of time between accesses before an element expires
+ Is only used if the element is not eternal.
+ Optional attribute. A value of 0 means that an Element can idle for infinity
+ timeToLiveSeconds - Sets the time to live for an element before it expires.
+ i.e. The maximum time between creation time and when an element expires.
+ Is only used if the element is not eternal.
+ overflowToDisk - Sets whether elements can overflow to disk when the in-memory cache
+ has reached the maxInMemory limit.
+
+ -->
+ <defaultCache
+ maxElementsInMemory="10000"
+ eternal="false"
+ timeToIdleSeconds="120"
+ timeToLiveSeconds="120"
+ overflowToDisk="true" />
+
+ <!-- memoryStoreEvictionPolicy :
+ LRU - least recently used
+ LFU - least frequently used
+ FIFO - first in first out, the oldest element by creation time
+ -->
+ <cache name="allFishingVessel" eternal="true"
+ maxElementsInMemory="1"
+ memoryStoreEvictionPolicy="LFU"/>
+
+ <cache name="org.hibernate.cache.UpdateTimestampsCache"
+ maxElementsInMemory="5000" timeToIdleSeconds="300"
+ timeToLiveSeconds="300" overflowToDisk="true" diskPersistent="false"
+ diskExpiryThreadIntervalSeconds="300" memoryStoreEvictionPolicy="LRU" />
+
+ <cache name="org.hibernate.cache.StandardQueryCache"
+ maxElementsInMemory="10000" eternal="false" timeToIdleSeconds="300"
+ timeToLiveSeconds="300" overflowToDisk="true" diskPersistent="false"
+ diskExpiryThreadIntervalSeconds="300" memoryStoreEvictionPolicy="LRU" />
+
</ehcache>
\ No newline at end of file
Property changes on: trunk/tutti-persistence-adagio/src/main/resources/ehcache.xml
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: trunk/tutti-service/pom.xml
===================================================================
--- trunk/tutti-service/pom.xml 2013-01-31 08:47:56 UTC (rev 276)
+++ trunk/tutti-service/pom.xml 2013-01-31 15:26:25 UTC (rev 277)
@@ -72,6 +72,11 @@
</dependency>
<dependency>
+ <groupId>org.nuiton</groupId>
+ <artifactId>nuiton-csv</artifactId>
+ </dependency>
+
+ <dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
Deleted: trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/TuttiProtocolImportExportService.java
===================================================================
--- trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/TuttiProtocolImportExportService.java 2013-01-31 08:47:56 UTC (rev 276)
+++ trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/TuttiProtocolImportExportService.java 2013-01-31 15:26:25 UTC (rev 277)
@@ -1,107 +0,0 @@
-package fr.ifremer.tutti.service;
-
-/*
- * #%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.esotericsoftware.yamlbeans.YamlConfig;
-import com.esotericsoftware.yamlbeans.YamlException;
-import com.esotericsoftware.yamlbeans.YamlReader;
-import com.esotericsoftware.yamlbeans.YamlWriter;
-import com.google.common.base.Charsets;
-import com.google.common.io.Closeables;
-import com.google.common.io.Files;
-import fr.ifremer.tutti.persistence.entities.protocol.SpeciesProtocol;
-import fr.ifremer.tutti.persistence.entities.protocol.TuttiProtocol;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.IOException;
-import java.io.Reader;
-
-/**
- * To import / export {@link TuttiProtocol} to {@code Yaml} file formats.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 1.0
- */
-public class TuttiProtocolImportExportService extends AbstractTuttiService {
-
- /** Logger. */
- private static final Log log =
- LogFactory.getLog(TuttiProtocolImportExportService.class);
-
- public void exportProtocol(TuttiProtocol protocol, File file) throws IOException {
-
- YamlConfig config = createConfig();
-
- String id = protocol.getId();
-
- if (log.isInfoEnabled()) {
- log.info("Will export protocol: " + id + " to file: " + file);
- }
-
- BufferedWriter fileWriter = Files.newWriter(file, Charsets.UTF_8);
- try {
- YamlWriter writer = new YamlWriter(fileWriter, config);
- writer.write(protocol);
- writer.close();
- fileWriter.close();
- } catch (YamlException e) {
- throw new IOException("Could not export protocol " + id, e);
- } finally {
- Closeables.closeQuietly(fileWriter);
- }
- }
-
- protected YamlConfig createConfig() {
- YamlConfig config = new YamlConfig();
- config.setClassTag(SpeciesProtocol.class.getSimpleName(),
- SpeciesProtocol.class);
- config.writeConfig.setAlwaysWriteClassname(false);
- config.writeConfig.setWriteRootTags(false);
- return config;
- }
-
- public TuttiProtocol importProtocol(File file) throws IOException {
- if (log.isInfoEnabled()) {
- log.info("Will import protocol from file: " + file);
- }
-
- YamlConfig config = createConfig();
-
- Reader fileReader = Files.newReader(file, Charsets.UTF_8);
- try {
- YamlReader reader = new YamlReader(fileReader, config);
- TuttiProtocol result = reader.read(TuttiProtocol.class);
- fileReader.close();
- return result;
- } catch (YamlException e) {
- throw new IOException("Could not import protocol from file " + file, e);
- } finally {
- Closeables.closeQuietly(fileReader);
- }
- }
-}
Modified: trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/config/TuttiServiceConfig.java
===================================================================
--- trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/config/TuttiServiceConfig.java 2013-01-31 08:47:56 UTC (rev 276)
+++ trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/config/TuttiServiceConfig.java 2013-01-31 15:26:25 UTC (rev 277)
@@ -107,6 +107,10 @@
return result;
}
+ public char getCsvSeparator() {
+ return applicationConfig.getOption(TuttiServiceConfigOption.CSV_SEPARATOR.getKey()).charAt(0);
+ }
+
public void prepareDirectories() throws IOException {
getOrCreateDirectory(TuttiServiceConfigOption.DATA_DIRECTORY);
Modified: trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/config/TuttiServiceConfigOption.java
===================================================================
--- trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/config/TuttiServiceConfigOption.java 2013-01-31 08:47:56 UTC (rev 276)
+++ trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/config/TuttiServiceConfigOption.java 2013-01-31 15:26:25 UTC (rev 277)
@@ -49,7 +49,10 @@
n_("tutti.config.tmp.directory"),
"${java.io.tmpdir}/tutti",
File.class),
-
+ CSV_SEPARATOR("tutti.csv.separator",
+ n_("tutti.csv.separator"),
+ ";",
+ char.class),
// TRANSIENT CONFIG
VERSION("tutti.version",
n_("tutti.config.application.version"),
Added: trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/protocol/CaracteristicRow.java
===================================================================
--- trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/protocol/CaracteristicRow.java (rev 0)
+++ trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/protocol/CaracteristicRow.java 2013-01-31 15:26:25 UTC (rev 277)
@@ -0,0 +1,96 @@
+/*
+ * #%L
+ * EchoBase :: Services
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 - 2012 Ifremer, Codelutin
+ * %%
+ * 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%
+ */
+package fr.ifremer.tutti.service.protocol;
+
+import fr.ifremer.tutti.persistence.entities.referential.Caracteristic;
+
+import java.io.Serializable;
+
+/**
+ * Bean used as a row for import of {@link Caracteristic}.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 0.3
+ */
+public class CaracteristicRow implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ public static final String PROPERTY_ID = "id";
+
+ public static final String PROPERTY_TYPE = "type";
+
+ public static final String PROPERTY_PARAMETER = "parameter";
+
+ public static final String PROPERTY_MATRIX = "matrix";
+
+ public static final String PROPERTY_FRACTION = "fraction";
+
+ public static final String PROPERTY_METHOD = "method";
+
+ public static final String PROPERTY_CARACTERISTIC = "caracteristic";
+
+ protected CaracteristicType type;
+
+ protected Caracteristic caracteristic;
+
+ public Caracteristic getCaracteristic() {
+ return caracteristic;
+ }
+
+ public void setCaracteristic(Caracteristic caracteristic) {
+ this.caracteristic = caracteristic;
+ }
+
+ public CaracteristicType getType() {
+ return type;
+ }
+
+ public void setType(CaracteristicType type) {
+ this.type = type;
+ }
+
+ public String getId() {
+ return getCaracteristic().getId();
+ }
+
+ public String getParameter() {
+ return getCaracteristic().getParameterName();
+ }
+
+ public String getMatrix() {
+ return getCaracteristic().getMatrixName();
+ }
+
+ public String getMethod() {
+ return getCaracteristic().getMethodName();
+ }
+
+ public String getFraction() {
+ return getCaracteristic().getFractionName();
+ }
+
+
+}
Property changes on: trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/protocol/CaracteristicRow.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/protocol/CaracteristicType.java
===================================================================
--- trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/protocol/CaracteristicType.java (rev 0)
+++ trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/protocol/CaracteristicType.java 2013-01-31 15:26:25 UTC (rev 277)
@@ -0,0 +1,39 @@
+package fr.ifremer.tutti.service.protocol;
+
+/*
+ * #%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%
+ */
+
+/**
+ * To define which caracteristic can be imported.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.0
+ */
+public enum CaracteristicType {
+
+ LENGTH_CLASS,
+ ENVIRONMENT,
+ HYDROLOGY,
+ GEAR
+}
Property changes on: trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/protocol/CaracteristicType.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/protocol/ProtocolCaracteristicExportModel.java
===================================================================
--- trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/protocol/ProtocolCaracteristicExportModel.java (rev 0)
+++ trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/protocol/ProtocolCaracteristicExportModel.java 2013-01-31 15:26:25 UTC (rev 277)
@@ -0,0 +1,52 @@
+/*
+ * #%L
+ * EchoBase :: Services
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 - 2012 Ifremer, Codelutin
+ * %%
+ * 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%
+ */
+package fr.ifremer.tutti.service.protocol;
+
+
+import fr.ifremer.tutti.persistence.entities.referential.CaracteristicType;
+import org.nuiton.util.csv.Common;
+import org.nuiton.util.csv.ext.AbstractExportModel;
+
+/**
+ * Model to export caracteristics (from a protocol or not).
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.0
+ */
+public class ProtocolCaracteristicExportModel extends AbstractExportModel<CaracteristicRow> {
+
+ public ProtocolCaracteristicExportModel(char separator) {
+ super(separator);
+
+ newColumnForExport(CaracteristicRow.PROPERTY_ID);
+ newColumnForExport(CaracteristicRow.PROPERTY_TYPE, Common.newEnumByNameParserFormatter(CaracteristicType.class));
+ newColumnForExport(CaracteristicRow.PROPERTY_PARAMETER);
+ newColumnForExport(CaracteristicRow.PROPERTY_MATRIX);
+ newColumnForExport(CaracteristicRow.PROPERTY_FRACTION);
+ newColumnForExport(CaracteristicRow.PROPERTY_METHOD);
+ }
+
+
+}
Property changes on: trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/protocol/ProtocolCaracteristicExportModel.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/protocol/ProtocolCaracteristicImportModel.java
===================================================================
--- trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/protocol/ProtocolCaracteristicImportModel.java (rev 0)
+++ trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/protocol/ProtocolCaracteristicImportModel.java 2013-01-31 15:26:25 UTC (rev 277)
@@ -0,0 +1,132 @@
+/*
+ * #%L
+ * EchoBase :: Services
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 - 2012 Ifremer, Codelutin
+ * %%
+ * 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%
+ */
+package fr.ifremer.tutti.service.protocol;
+
+
+import fr.ifremer.tutti.persistence.entities.IdAware;
+import fr.ifremer.tutti.persistence.entities.referential.Caracteristic;
+import org.apache.commons.lang3.StringUtils;
+import org.nuiton.util.csv.Common;
+import org.nuiton.util.csv.ValueParserFormatter;
+import org.nuiton.util.csv.ext.AbstractImportModel;
+
+import java.text.ParseException;
+import java.util.Map;
+
+/**
+ * Model to import protocol caracteristics.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.0
+ */
+public class ProtocolCaracteristicImportModel extends AbstractImportModel<CaracteristicRow> {
+
+ public ProtocolCaracteristicImportModel(char separator, Map<String, Caracteristic> caracteristicMap) {
+ super(separator);
+
+ newForeignKeyColumn(CaracteristicRow.PROPERTY_ID,
+ CaracteristicRow.PROPERTY_CARACTERISTIC,
+ Caracteristic.class,
+ Caracteristic.PROPERTY_ID,
+ caracteristicMap);
+
+ newMandatoryColumn(CaracteristicRow.PROPERTY_TYPE,
+ CaracteristicRow.PROPERTY_TYPE,
+ Common.newEnumByNameParserFormatter(CaracteristicType.class));
+
+ newIgnoredColumn(CaracteristicRow.PROPERTY_PARAMETER);
+ newIgnoredColumn(CaracteristicRow.PROPERTY_MATRIX);
+ newIgnoredColumn(CaracteristicRow.PROPERTY_FRACTION);
+ newIgnoredColumn(CaracteristicRow.PROPERTY_METHOD);
+ }
+
+ @Override
+ public CaracteristicRow newEmptyInstance() {
+ return new CaracteristicRow();
+ }
+
+ public <E extends IdAware> void newForeignKeyColumn(String headerName, String propertyName, Class<E> entityType, String foreignKeyName, Map<String, E> universe) {
+ newMandatoryColumn(headerName, propertyName, newForeignKeyValue(entityType, foreignKeyName, universe));
+ }
+
+ public <E extends IdAware> void newForeignKeyColumn(String propertyName, Class<E> entityType, String foreignKeyName, Map<String, E> universe) {
+ newMandatoryColumn(propertyName, propertyName, newForeignKeyValue(entityType, foreignKeyName, universe));
+ }
+
+ public static <E extends IdAware> ForeignKeyValue<E> newForeignKeyValue(Class<E> type, String propertyName, Map<String, E> universe) {
+ return new ForeignKeyValue<E>(type, propertyName, universe);
+ }
+
+ /**
+ * @param <E>
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.6.12
+ */
+ public static class ForeignKeyValue<E extends IdAware> implements ValueParserFormatter<E> {
+
+ protected final String propertyName;
+
+ protected final Class<E> entityType;
+
+ protected final Map<String, E> universe;
+
+ public ForeignKeyValue(Class<E> entityType,
+ String propertyName,
+ Map<String, E> universe) {
+ this.entityType = entityType;
+ this.propertyName = propertyName;
+ this.universe = universe;
+ }
+
+ @Override
+ public E parse(String value) throws ParseException {
+ E result = null;
+ if (StringUtils.isNotBlank(value)) {
+
+ // get entity from universe
+ result = universe.get(value);
+
+ if (result == null) {
+
+ // can not find entity this is a big problem for us...
+ throw new RuntimeException(
+ "Could not find entity of type " +
+ entityType.getSimpleName() + " with '" +
+ propertyName + "' = " + value);
+ }
+ }
+ return result;
+ }
+
+ @Override
+ public String format(E e) {
+ String value = "";
+ if (e != null) {
+ value = e.getId();
+ }
+ return value;
+ }
+ }
+}
Property changes on: trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/protocol/ProtocolCaracteristicImportModel.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Copied: trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/protocol/TuttiProtocolImportExportService.java (from rev 271, trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/TuttiProtocolImportExportService.java)
===================================================================
--- trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/protocol/TuttiProtocolImportExportService.java (rev 0)
+++ trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/protocol/TuttiProtocolImportExportService.java 2013-01-31 15:26:25 UTC (rev 277)
@@ -0,0 +1,323 @@
+package fr.ifremer.tutti.service.protocol;
+
+/*
+ * #%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.esotericsoftware.yamlbeans.YamlConfig;
+import com.esotericsoftware.yamlbeans.YamlException;
+import com.esotericsoftware.yamlbeans.YamlReader;
+import com.esotericsoftware.yamlbeans.YamlWriter;
+import com.google.common.base.Charsets;
+import com.google.common.base.Function;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Multimap;
+import com.google.common.collect.TreeMultimap;
+import com.google.common.io.Closeables;
+import com.google.common.io.Files;
+import fr.ifremer.tutti.persistence.entities.protocol.SpeciesProtocol;
+import fr.ifremer.tutti.persistence.entities.protocol.TuttiProtocol;
+import fr.ifremer.tutti.persistence.entities.referential.Caracteristic;
+import fr.ifremer.tutti.service.AbstractTuttiService;
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.util.csv.Export;
+import org.nuiton.util.csv.Import2;
+import org.nuiton.util.csv.ImportRow;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.IOException;
+import java.io.Reader;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * To import / export {@link TuttiProtocol} to {@code Yaml} file formats.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.0
+ */
+public class TuttiProtocolImportExportService extends AbstractTuttiService {
+
+ /** Logger. */
+ private static final Log log =
+ LogFactory.getLog(TuttiProtocolImportExportService.class);
+
+ public void exportProtocol(TuttiProtocol protocol, File file) throws IOException {
+
+ YamlConfig config = createConfig();
+
+ String id = protocol.getId();
+
+ if (log.isInfoEnabled()) {
+ log.info("Will export protocol: " + id + " to file: " + file);
+ }
+
+ BufferedWriter fileWriter = Files.newWriter(file, Charsets.UTF_8);
+ try {
+ YamlWriter writer = new YamlWriter(fileWriter, config);
+ writer.write(protocol);
+ writer.close();
+ fileWriter.close();
+ } catch (YamlException e) {
+ throw new IOException("Could not export protocol " + id, e);
+ } finally {
+ Closeables.closeQuietly(fileWriter);
+ }
+ }
+
+ public TuttiProtocol importProtocol(File file) throws IOException {
+ if (log.isInfoEnabled()) {
+ log.info("Will import protocol from file: " + file);
+ }
+
+ YamlConfig config = createConfig();
+
+ Reader fileReader = Files.newReader(file, Charsets.UTF_8);
+ try {
+ YamlReader reader = new YamlReader(fileReader, config);
+ TuttiProtocol result = reader.read(TuttiProtocol.class);
+ fileReader.close();
+ return result;
+ } catch (YamlException e) {
+ throw new IOException("Could not import protocol from file " + file, e);
+ } finally {
+ Closeables.closeQuietly(fileReader);
+ }
+ }
+
+ public void importProtocolCaracteristic(File file,
+ TuttiProtocol protocol,
+ Map<String, Caracteristic> caracteristicMap) throws IOException {
+ if (log.isInfoEnabled()) {
+ log.info("Will import protocol [" + protocol.getName() + "] caracteristic from file: " + file);
+ }
+
+ Multimap<CaracteristicType, String> ids = TreeMultimap.create();
+
+ ProtocolCaracteristicImportModel csvModel =
+ new ProtocolCaracteristicImportModel(getCsvSeparator(),
+ caracteristicMap);
+
+ Reader reader = Files.newReader(file, Charsets.UTF_8);
+ try {
+
+ Import2<CaracteristicRow> importer =
+ Import2.newImport(csvModel, reader);
+
+ try {
+
+ for (ImportRow<CaracteristicRow> row : importer) {
+
+ if (!row.isValid()) {
+
+ //TODO deal with line error
+ if (log.isErrorEnabled()) {
+ log.error("there is some error on line " + row.getLineNumber() + ":\n" + row.getErrors());
+ }
+ } else {
+
+ // treat row
+ CaracteristicRow bean = row.getBean();
+
+ CaracteristicType caracteristicType = bean.getType();
+
+ Caracteristic caracteristic = bean.getCaracteristic();
+ String id = caracteristic.getId();
+ ids.put(caracteristicType, id);
+ }
+ }
+ importer.close();
+ } finally {
+ Closeables.closeQuietly(importer);
+ }
+ reader.close();
+ } catch (YamlException e) {
+ throw new IOException("Could not import protocol [" + protocol.getName() + "] caracteristic from file " + file, e);
+ } finally {
+
+ Closeables.closeQuietly(reader);
+ }
+
+ protocol.setLengthClassesPmfmId(
+ mergeIds(protocol.getLengthClassesPmfmId(),
+ ids.get(CaracteristicType.LENGTH_CLASS)));
+
+ protocol.setEnvironmentPmfmId(
+ mergeIds(protocol.getEnvironmentPmfmId(),
+ ids.get(CaracteristicType.ENVIRONMENT)));
+
+ protocol.setGearPmfmId(
+ mergeIds(protocol.getGearPmfmId(),
+ ids.get(CaracteristicType.GEAR)));
+
+ protocol.setHydrologyPmfmId(
+ mergeIds(protocol.getHydrologyPmfmId(),
+ ids.get(CaracteristicType.HYDROLOGY)));
+ }
+
+ public void exportAllCaracteristic(File file,
+
+ Map<String, Caracteristic> caracteristicMap) throws Exception {
+
+ if (log.isInfoEnabled()) {
+ log.info("Will export all caracteristics to file: " + file);
+ }
+
+ PmfmIdToCaracteristicRowFunction function =
+ new PmfmIdToCaracteristicRowFunction(caracteristicMap);
+
+ List<CaracteristicRow> rows = Lists.transform(
+ Lists.newArrayList(caracteristicMap.keySet()), function);
+
+
+ ProtocolCaracteristicExportModel csvModel =
+ new ProtocolCaracteristicExportModel(getCsvSeparator());
+
+ BufferedWriter writer = Files.newWriter(file, Charsets.UTF_8);
+ try {
+ Export export = Export.newExport(csvModel, rows);
+ export.write(writer);
+ writer.close();
+ } finally {
+ Closeables.closeQuietly(writer);
+ }
+ }
+
+ public void exportProtocolCaracteristic(File file, TuttiProtocol protocol,
+ Map<String, Caracteristic> caracteristicMap) throws Exception {
+
+ if (log.isInfoEnabled()) {
+ log.info("Will export all caracteristics to file: " + file);
+ }
+
+ PmfmIdToCaracteristicRowFunction function =
+ new PmfmIdToCaracteristicRowFunction(caracteristicMap);
+
+ List<CaracteristicRow> rows = Lists.newArrayList();
+
+ function.setType(CaracteristicType.LENGTH_CLASS);
+ rows.addAll(Lists.transform(protocol.getLengthClassesPmfmId(), function));
+
+ function.setType(CaracteristicType.ENVIRONMENT);
+ rows.addAll(Lists.transform(protocol.getEnvironmentPmfmId(), function));
+
+ function.setType(CaracteristicType.GEAR);
+ rows.addAll(Lists.transform(protocol.getGearPmfmId(), function));
+
+ function.setType(CaracteristicType.HYDROLOGY);
+ rows.addAll(Lists.transform(protocol.getHydrologyPmfmId(), function));
+
+ ProtocolCaracteristicExportModel csvModel =
+ new ProtocolCaracteristicExportModel(getCsvSeparator());
+
+ BufferedWriter writer = Files.newWriter(file, Charsets.UTF_8);
+ try {
+ Export export = Export.newExport(csvModel, rows);
+ export.write(writer);
+ writer.close();
+ } finally {
+ Closeables.closeQuietly(writer);
+ }
+ }
+
+ public void importProtocolSpecies(File file,
+ TuttiProtocol protocol) throws IOException {
+ if (log.isInfoEnabled()) {
+ log.info("Will import protocol [" + protocol.getName() + "] species from file: " + file);
+ }
+ Reader fileReader = Files.newReader(file, Charsets.UTF_8);
+ try {
+ if (log.isInfoEnabled()) {
+ log.info("TODO");
+ }
+ fileReader.close();
+ } catch (YamlException e) {
+ throw new IOException("Could not import protocol [" + protocol.getName() + "] species from file " + file, e);
+ } finally {
+ Closeables.closeQuietly(fileReader);
+ }
+ }
+
+ protected YamlConfig createConfig() {
+ YamlConfig config = new YamlConfig();
+ config.setClassTag(SpeciesProtocol.class.getSimpleName(),
+ SpeciesProtocol.class);
+ config.writeConfig.setAlwaysWriteClassname(false);
+ config.writeConfig.setWriteRootTags(false);
+ return config;
+ }
+
+ protected char getCsvSeparator() {
+ return context.getConfig().getCsvSeparator();
+ }
+
+ protected List<String> mergeIds(Collection<String> fromProtocol,
+ Collection<String> fromImport) {
+ List<String> result = Lists.newArrayList();
+
+ if (CollectionUtils.isNotEmpty(fromProtocol)) {
+ for (String s : fromProtocol) {
+ if (!result.contains(s)) {
+ result.add(s);
+ }
+ }
+
+ }
+ for (String s : fromImport) {
+ if (!result.contains(s)) {
+ result.add(s);
+ }
+ }
+ return result;
+ }
+
+ private static class PmfmIdToCaracteristicRowFunction implements Function<String, CaracteristicRow> {
+
+ private CaracteristicType type;
+
+ private final Map<String, Caracteristic> caracteristicMap;
+
+ public PmfmIdToCaracteristicRowFunction(Map<String, Caracteristic> caracteristicMap) {
+ this.caracteristicMap = caracteristicMap;
+ }
+
+ @Override
+ public CaracteristicRow apply(String input) {
+ Caracteristic caracteristic = caracteristicMap.get(input);
+ Preconditions.checkNotNull(caracteristic, "Could not find a caracteristic with id: " + input);
+ CaracteristicRow result = new CaracteristicRow();
+ result.setCaracteristic(caracteristic);
+ result.setType(type);
+ return result;
+ }
+
+ public void setType(CaracteristicType type) {
+ this.type = type;
+ }
+ }
+}
Deleted: trunk/tutti-service/src/test/java/fr/ifremer/tutti/service/TuttiProtocolImportExportServiceTest.java
===================================================================
--- trunk/tutti-service/src/test/java/fr/ifremer/tutti/service/TuttiProtocolImportExportServiceTest.java 2013-01-31 08:47:56 UTC (rev 276)
+++ trunk/tutti-service/src/test/java/fr/ifremer/tutti/service/TuttiProtocolImportExportServiceTest.java 2013-01-31 15:26:25 UTC (rev 277)
@@ -1,222 +0,0 @@
-package fr.ifremer.tutti.service;
-
-/*
- * #%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.base.Charsets;
-import com.google.common.collect.Lists;
-import com.google.common.io.Files;
-import fr.ifremer.tutti.persistence.entities.protocol.SpeciesProtocol;
-import fr.ifremer.tutti.persistence.entities.protocol.TuttiProtocol;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.commons.lang3.SystemUtils;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TestName;
-
-import java.io.File;
-
-/**
- * @author tchemit <chemit(a)codelutin.com>
- * @since 1.0
- */
-public class TuttiProtocolImportExportServiceTest {
-
- /** Logger. */
- private static final Log log =
- LogFactory.getLog(TuttiProtocolImportExportServiceTest.class);
-
- public static final long TIMESTAMP = System.nanoTime();
-
- @Rule
- public final TestName name = new TestName();
-
- protected File datadirectory;
-
- protected TuttiProtocolImportExportService service;
-
- public static final String PROTOCOL_FILE_CONTENT =
- "id: 1\n" +
- "name: protocolName\n" +
- "comment: Commentaire\n" +
- "environmentPmfmId: \n" +
- "- 114\n" +
- "- 228\n" +
- "- 821\n" +
- "gearPmfmId: \n" +
- "- 21\n" +
- "- 22\n" +
- "hydrologyPmfmId: []\n" +
- "species: \n" +
- "- !SpeciesProtocol\n" +
- " calcifySampleEnabled: true\n" +
- " lengthStepPmfmId: 1394\n" +
- " maturityEnabled: true\n" +
- " sexEnabled: true\n" +
- " speciesId: 11242\n" +
- " weightEnabled: true\n" +
- "- !SpeciesProtocol\n" +
- " ageEnabled: true\n" +
- " calcifySampleEnabled: true\n" +
- " countIfNoFrequencyEnabled: true\n" +
- " lengthStepPmfmId: 323\n" +
- " maturityEnabled: true\n" +
- " sexEnabled: true\n" +
- " sizeEnabled: true\n" +
- " speciesId: 3835\n" +
- " weightEnabled: true";
-
- @Before
- public void setUp() throws Exception {
- datadirectory = getTestSpecificDirectory(getClass(),
- name.getMethodName(),
- null);
-
- service = new TuttiProtocolImportExportService();
- }
-
- @Test
- public void testExportProtocol() throws Exception {
-
- File exportFile = new File(datadirectory, "exportProtocol.yaml");
-
- Files.createParentDirs(exportFile);
-
- Assert.assertFalse(exportFile.exists());
- TuttiProtocol protocol = new TuttiProtocol();
- protocol.setId("1");
- protocol.setName("protocolName");
- protocol.setComment("Commentaire");
- protocol.setEnvironmentPmfmId(Lists.newArrayList("114", "228", "821"));
- protocol.setGearPmfmId(Lists.newArrayList("21", "22"));
- protocol.setHydrologyPmfmId(Lists.<String>newArrayList());
-
- protocol.setSpecies(Lists.<SpeciesProtocol>newArrayList());
- SpeciesProtocol sp1 = new SpeciesProtocol();
- sp1.setSpeciesId("11242");
- sp1.setLengthStepPmfmId("1394");
- sp1.setCalcifySampleEnabled(true);
- sp1.setMaturityEnabled(true);
- sp1.setSexEnabled(true);
- sp1.setWeightEnabled(true);
- protocol.addSpecies(sp1);
-
- SpeciesProtocol sp2 = new SpeciesProtocol();
- sp2.setSpeciesId("3835");
- sp2.setLengthStepPmfmId("323");
- sp2.setAgeEnabled(true);
- sp2.setCalcifySampleEnabled(true);
- sp2.setCountIfNoFrequencyEnabled(true);
- sp2.setMaturityEnabled(true);
- sp2.setSexEnabled(true);
- sp2.setSizeEnabled(true);
- sp2.setWeightEnabled(true);
- protocol.addSpecies(sp2);
-
- service.exportProtocol(protocol, exportFile);
- Assert.assertTrue(exportFile.exists());
-
- String exportFileToString = Files.toString(exportFile, Charsets.UTF_8).trim();
- Assert.assertEquals(PROTOCOL_FILE_CONTENT, exportFileToString);
- }
-
- @Test
- public void testImportProtocol() throws Exception {
-
- File importfile = new File(datadirectory, "importProtocol.yaml");
-
- Files.createParentDirs(importfile);
-
- Files.write(PROTOCOL_FILE_CONTENT, importfile, Charsets.UTF_8);
-
- TuttiProtocol protocol = service.importProtocol(importfile);
-
- Assert.assertNotNull(protocol);
- Assert.assertEquals("1", protocol.getId());
- Assert.assertEquals("protocolName", protocol.getName());
- Assert.assertEquals("Commentaire", protocol.getComment());
- Assert.assertEquals(Lists.newArrayList("114", "228", "821"), protocol.getEnvironmentPmfmId());
- Assert.assertEquals(Lists.newArrayList("21", "22"), protocol.getGearPmfmId());
- Assert.assertEquals(Lists.<String>newArrayList(), protocol.getHydrologyPmfmId());
- Assert.assertNotNull(protocol.getSpecies());
- Assert.assertEquals(2, protocol.getSpecies().size());
- SpeciesProtocol sp1 = protocol.getSpecies().get(0);
- Assert.assertNotNull(sp1);
- Assert.assertEquals("11242", sp1.getSpeciesId());
- Assert.assertEquals("1394", sp1.getLengthStepPmfmId());
- Assert.assertFalse(sp1.isAgeEnabled());
- Assert.assertTrue(sp1.isCalcifySampleEnabled());
- Assert.assertFalse(sp1.isCountIfNoFrequencyEnabled());
- Assert.assertTrue(sp1.isMaturityEnabled());
- Assert.assertTrue(sp1.isSexEnabled());
- Assert.assertFalse(sp1.isSizeEnabled());
- Assert.assertTrue(sp1.isWeightEnabled());
-
- SpeciesProtocol sp2 = protocol.getSpecies().get(1);
- Assert.assertNotNull(sp2);
- Assert.assertEquals("3835", sp2.getSpeciesId());
- Assert.assertEquals("323", sp2.getLengthStepPmfmId());
- Assert.assertTrue(sp2.isAgeEnabled());
- Assert.assertTrue(sp2.isCalcifySampleEnabled());
- Assert.assertTrue(sp2.isCountIfNoFrequencyEnabled());
- Assert.assertTrue(sp2.isMaturityEnabled());
- Assert.assertTrue(sp2.isSexEnabled());
- Assert.assertTrue(sp2.isSizeEnabled());
- Assert.assertTrue(sp2.isWeightEnabled());
-
-
- }
-
- public static File getTestSpecificDirectory(Class<?> testClassName,
- String methodName,
- String classifier) {
- // Trying to look for the temporary folder to store data for the test
- String tempDirPath = System.getProperty("java.io.tmpdir");
- if (tempDirPath == null) {
- // can this really occur ?
- tempDirPath = "";
- if (log.isWarnEnabled()) {
- log.warn("'\"java.io.tmpdir\" not defined");
- }
- }
- File tempDirFile = SystemUtils.getJavaIoTmpDir();
-
- // create the directory to store database data
- String dataBasePath = testClassName.getName()
- + File.separator // a directory with the test class name
- + methodName; // a sub-directory with the method name
-
- if (StringUtils.isNotBlank(classifier)) {
- dataBasePath += classifier;
- }
- dataBasePath += '_'
- + TIMESTAMP; // and a timestamp
- File databaseFile = new File(tempDirFile, dataBasePath);
- return databaseFile;
- }
-}
Copied: trunk/tutti-service/src/test/java/fr/ifremer/tutti/service/protocol/TuttiProtocolImportExportServiceTest.java (from rev 276, trunk/tutti-service/src/test/java/fr/ifremer/tutti/service/TuttiProtocolImportExportServiceTest.java)
===================================================================
--- trunk/tutti-service/src/test/java/fr/ifremer/tutti/service/protocol/TuttiProtocolImportExportServiceTest.java (rev 0)
+++ trunk/tutti-service/src/test/java/fr/ifremer/tutti/service/protocol/TuttiProtocolImportExportServiceTest.java 2013-01-31 15:26:25 UTC (rev 277)
@@ -0,0 +1,335 @@
+package fr.ifremer.tutti.service.protocol;
+
+/*
+ * #%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.base.Charsets;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import com.google.common.io.Files;
+import fr.ifremer.tutti.persistence.entities.protocol.SpeciesProtocol;
+import fr.ifremer.tutti.persistence.entities.protocol.TuttiProtocol;
+import fr.ifremer.tutti.persistence.entities.referential.Caracteristic;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.lang3.SystemUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TestName;
+
+import java.io.File;
+import java.util.Map;
+
+/**
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.0
+ */
+public class TuttiProtocolImportExportServiceTest {
+
+ /** Logger. */
+ private static final Log log =
+ LogFactory.getLog(TuttiProtocolImportExportServiceTest.class);
+
+ public static final long TIMESTAMP = System.nanoTime();
+
+ @Rule
+ public final TestName name = new TestName();
+
+ protected File datadirectory;
+
+ protected TuttiProtocolImportExportService service;
+
+ public static final String PROTOCOL_FILE_CONTENT =
+ "id: 1\n" +
+ "name: protocolName\n" +
+ "comment: Commentaire\n" +
+ "environmentPmfmId: \n" +
+ "- 114\n" +
+ "- 228\n" +
+ "- 821\n" +
+ "gearPmfmId: \n" +
+ "- 21\n" +
+ "- 22\n" +
+ "hydrologyPmfmId: []\n" +
+ "lengthClassesPmfmId: \n" +
+ "- 14\n" +
+ "- 18\n" +
+ "species: \n" +
+ "- !SpeciesProtocol\n" +
+ " calcifySampleEnabled: true\n" +
+ " lengthStepPmfmId: 1394\n" +
+ " maturityEnabled: true\n" +
+ " sexEnabled: true\n" +
+ " speciesId: 11242\n" +
+ " weightEnabled: true\n" +
+ "- !SpeciesProtocol\n" +
+ " ageEnabled: true\n" +
+ " calcifySampleEnabled: true\n" +
+ " countIfNoFrequencyEnabled: true\n" +
+ " lengthStepPmfmId: 323\n" +
+ " maturityEnabled: true\n" +
+ " sexEnabled: true\n" +
+ " sizeEnabled: true\n" +
+ " speciesId: 3835\n" +
+ " weightEnabled: true";
+
+ public static final String PROTOCOL_CARACTERISTIC_FILE_CONTENT =
+ "id;type;parameter;matrix;fraction;method\n" +
+ "1;LENGTH_CLASS;parameterName1;matrixName1;fractionName1;methodName1;\n" +
+ "2;ENVIRONMENT;parameterName2;matrixName2;fractionName2;methodName2;\n" +
+ "3;GEAR;parameterName3;matrixName3;fractionName3;methodName3;\n" +
+ "4;HYDROLOGY;parameterName4;matrixName4;fractionName4;methodName4;\n" +
+ "5;HYDROLOGY;parameterName5;matrixName5;fractionName5;methodName5;";
+
+ public static final String ALL_CARACTERISTIC_FILE_CONTENT =
+ "id;type;parameter;matrix;fraction;method\n" +
+ "1;;parameterName1;matrixName1;fractionName1;methodName1;\n" +
+ "2;;parameterName2;matrixName2;fractionName2;methodName2;\n" +
+ "3;;parameterName3;matrixName3;fractionName3;methodName3;\n" +
+ "4;;parameterName4;matrixName4;fractionName4;methodName4;\n" +
+ "5;;parameterName5;matrixName5;fractionName5;methodName5;";
+
+
+ @Before
+ public void setUp() throws Exception {
+ datadirectory = getTestSpecificDirectory(getClass(),
+ name.getMethodName(),
+ null);
+
+ service = new TuttiProtocolImportExportService() {
+
+ @Override
+ protected char getCsvSeparator() {
+ return ';';
+ }
+ };
+ }
+
+ @Test
+ public void exportProtocol() throws Exception {
+
+ File exportFile = new File(datadirectory, "exportProtocol.yaml");
+
+ Files.createParentDirs(exportFile);
+
+ Assert.assertFalse(exportFile.exists());
+ TuttiProtocol protocol = new TuttiProtocol();
+ protocol.setId("1");
+ protocol.setName("protocolName");
+ protocol.setComment("Commentaire");
+ protocol.setLengthClassesPmfmId(Lists.newArrayList("14", "18"));
+ protocol.setEnvironmentPmfmId(Lists.newArrayList("114", "228", "821"));
+ protocol.setGearPmfmId(Lists.newArrayList("21", "22"));
+ protocol.setHydrologyPmfmId(Lists.<String>newArrayList());
+
+ protocol.setSpecies(Lists.<SpeciesProtocol>newArrayList());
+ SpeciesProtocol sp1 = new SpeciesProtocol();
+ sp1.setSpeciesId("11242");
+ sp1.setLengthStepPmfmId("1394");
+ sp1.setCalcifySampleEnabled(true);
+ sp1.setMaturityEnabled(true);
+ sp1.setSexEnabled(true);
+ sp1.setWeightEnabled(true);
+ protocol.addSpecies(sp1);
+
+ SpeciesProtocol sp2 = new SpeciesProtocol();
+ sp2.setSpeciesId("3835");
+ sp2.setLengthStepPmfmId("323");
+ sp2.setAgeEnabled(true);
+ sp2.setCalcifySampleEnabled(true);
+ sp2.setCountIfNoFrequencyEnabled(true);
+ sp2.setMaturityEnabled(true);
+ sp2.setSexEnabled(true);
+ sp2.setSizeEnabled(true);
+ sp2.setWeightEnabled(true);
+ protocol.addSpecies(sp2);
+
+ service.exportProtocol(protocol, exportFile);
+ Assert.assertTrue(exportFile.exists());
+
+ String exportFileToString = Files.toString(exportFile, Charsets.UTF_8).trim();
+ Assert.assertEquals(PROTOCOL_FILE_CONTENT, exportFileToString);
+ }
+
+ @Test
+ public void importProtocol() throws Exception {
+
+ File importfile = new File(datadirectory, "importProtocol.yaml");
+
+ Files.createParentDirs(importfile);
+
+ Files.write(PROTOCOL_FILE_CONTENT, importfile, Charsets.UTF_8);
+
+ TuttiProtocol protocol = service.importProtocol(importfile);
+
+ Assert.assertNotNull(protocol);
+ Assert.assertEquals("1", protocol.getId());
+ Assert.assertEquals("protocolName", protocol.getName());
+ Assert.assertEquals("Commentaire", protocol.getComment());
+ Assert.assertEquals(Lists.newArrayList("14", "18"), protocol.getLengthClassesPmfmId());
+ Assert.assertEquals(Lists.newArrayList("114", "228", "821"), protocol.getEnvironmentPmfmId());
+ Assert.assertEquals(Lists.newArrayList("21", "22"), protocol.getGearPmfmId());
+ Assert.assertEquals(Lists.<String>newArrayList(), protocol.getHydrologyPmfmId());
+ Assert.assertNotNull(protocol.getSpecies());
+ Assert.assertEquals(2, protocol.getSpecies().size());
+ SpeciesProtocol sp1 = protocol.getSpecies().get(0);
+ Assert.assertNotNull(sp1);
+ Assert.assertEquals("11242", sp1.getSpeciesId());
+ Assert.assertEquals("1394", sp1.getLengthStepPmfmId());
+ Assert.assertFalse(sp1.isAgeEnabled());
+ Assert.assertTrue(sp1.isCalcifySampleEnabled());
+ Assert.assertFalse(sp1.isCountIfNoFrequencyEnabled());
+ Assert.assertTrue(sp1.isMaturityEnabled());
+ Assert.assertTrue(sp1.isSexEnabled());
+ Assert.assertFalse(sp1.isSizeEnabled());
+ Assert.assertTrue(sp1.isWeightEnabled());
+
+ SpeciesProtocol sp2 = protocol.getSpecies().get(1);
+ Assert.assertNotNull(sp2);
+ Assert.assertEquals("3835", sp2.getSpeciesId());
+ Assert.assertEquals("323", sp2.getLengthStepPmfmId());
+ Assert.assertTrue(sp2.isAgeEnabled());
+ Assert.assertTrue(sp2.isCalcifySampleEnabled());
+ Assert.assertTrue(sp2.isCountIfNoFrequencyEnabled());
+ Assert.assertTrue(sp2.isMaturityEnabled());
+ Assert.assertTrue(sp2.isSexEnabled());
+ Assert.assertTrue(sp2.isSizeEnabled());
+ Assert.assertTrue(sp2.isWeightEnabled());
+ }
+
+ @Test
+ public void importProtocolCaracteristic() throws Exception {
+
+ File importfile = new File(datadirectory, "importProtocolCaracteristic.csv");
+
+ Files.createParentDirs(importfile);
+
+ Files.write(PROTOCOL_CARACTERISTIC_FILE_CONTENT, importfile, Charsets.UTF_8);
+
+ TuttiProtocol protocol = new TuttiProtocol();
+ Map<String, Caracteristic> caracteristicMap = createCaracteristics();
+
+ service.importProtocolCaracteristic(importfile,
+ protocol,
+ caracteristicMap);
+
+ Assert.assertEquals(Lists.newArrayList("1"),
+ protocol.getLengthClassesPmfmId());
+ Assert.assertEquals(Lists.newArrayList("2"),
+ protocol.getEnvironmentPmfmId());
+ Assert.assertEquals(Lists.newArrayList("3"),
+ protocol.getGearPmfmId());
+ Assert.assertEquals(Lists.newArrayList("4", "5"),
+ protocol.getHydrologyPmfmId());
+ }
+
+ @Test
+ public void exportProtocolCaracteristic() throws Exception {
+
+ File file = new File(datadirectory, "exportProtocolCaracteristic.csv");
+
+ Files.createParentDirs(file);
+
+ Map<String, Caracteristic> caracteristicMap = createCaracteristics();
+ TuttiProtocol protocol = new TuttiProtocol();
+
+ protocol.setLengthClassesPmfmId(Lists.newArrayList("1"));
+ protocol.setEnvironmentPmfmId(Lists.newArrayList("2"));
+ protocol.setGearPmfmId(Lists.newArrayList("3"));
+ protocol.setHydrologyPmfmId(Lists.newArrayList("4", "5"));
+
+ Assert.assertFalse(file.exists());
+ service.exportProtocolCaracteristic(file,
+ protocol,
+ caracteristicMap);
+
+ Assert.assertTrue(file.exists());
+
+ String exportFileToString = Files.toString(file, Charsets.UTF_8).trim();
+ Assert.assertEquals(PROTOCOL_CARACTERISTIC_FILE_CONTENT, exportFileToString);
+ }
+
+ @Test
+ public void exportAllCaracteristic() throws Exception {
+
+ File file = new File(datadirectory, "exportAllCaracteristic.csv");
+
+ Files.createParentDirs(file);
+
+ Map<String, Caracteristic> caracteristicMap = createCaracteristics();
+
+ Assert.assertFalse(file.exists());
+ service.exportAllCaracteristic(file, caracteristicMap);
+
+ Assert.assertTrue(file.exists());
+
+ String exportFileToString = Files.toString(file, Charsets.UTF_8).trim();
+ Assert.assertEquals(ALL_CARACTERISTIC_FILE_CONTENT, exportFileToString);
+ }
+
+ public static File getTestSpecificDirectory(Class<?> testClassName,
+ String methodName,
+ String classifier) {
+ // Trying to look for the temporary folder to store data for the test
+ String tempDirPath = System.getProperty("java.io.tmpdir");
+ if (tempDirPath == null) {
+ // can this really occur ?
+ tempDirPath = "";
+ if (log.isWarnEnabled()) {
+ log.warn("'\"java.io.tmpdir\" not defined");
+ }
+ }
+ File tempDirFile = SystemUtils.getJavaIoTmpDir();
+
+ // create the directory to store database data
+ String dataBasePath = testClassName.getName()
+ + File.separator // a directory with the test class name
+ + methodName; // a sub-directory with the method name
+
+ if (StringUtils.isNotBlank(classifier)) {
+ dataBasePath += classifier;
+ }
+ dataBasePath += '_'
+ + TIMESTAMP; // and a timestamp
+ File databaseFile = new File(tempDirFile, dataBasePath);
+ return databaseFile;
+ }
+
+ protected Map<String, Caracteristic> createCaracteristics() {
+ Map<String, Caracteristic> caracteristicMap = Maps.newTreeMap();
+ for (int i = 1; i < 6; i++) {
+ Caracteristic c = new Caracteristic();
+ c.setId("" + i);
+ c.setParameterName("parameterName" + i);
+ c.setMatrixName("matrixName" + i);
+ c.setFractionName("fractionName" + i);
+ c.setMethodName("methodName" + i);
+ caracteristicMap.put(i + "", c);
+ }
+ return caracteristicMap;
+ }
+}
Added: trunk/tutti-service/src/test/resources/log4j.properties
===================================================================
--- trunk/tutti-service/src/test/resources/log4j.properties (rev 0)
+++ trunk/tutti-service/src/test/resources/log4j.properties 2013-01-31 15:26:25 UTC (rev 277)
@@ -0,0 +1,32 @@
+###
+# #%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%
+###
+
+log4j.rootCategory=WARN, A1
+log4j.logger.no.api=DEBUG
+log4j.appender.A1=org.apache.log4j.ConsoleAppender
+log4j.appender.A1.layout=org.apache.log4j.PatternLayout
+log4j.appender.A1.layout.ConversionPattern=%d %-4r [%t] %-5p %c %x - %m%n
+
+log4j.logger.fr.ifremer.tutti=INFO
+log4j.logger.org.nuiton=INFO
\ No newline at end of file
Property changes on: trunk/tutti-service/src/test/resources/log4j.properties
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/home/ExportProtocolAction.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/home/ExportProtocolAction.java 2013-01-31 08:47:56 UTC (rev 276)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/home/ExportProtocolAction.java 2013-01-31 15:26:25 UTC (rev 277)
@@ -26,7 +26,7 @@
import com.ezware.oxbow.swingbits.util.Preconditions;
import fr.ifremer.tutti.persistence.entities.protocol.TuttiProtocol;
-import fr.ifremer.tutti.service.TuttiProtocolImportExportService;
+import fr.ifremer.tutti.service.protocol.TuttiProtocolImportExportService;
import fr.ifremer.tutti.ui.swing.AbstractTuttiAction;
import fr.ifremer.tutti.ui.swing.util.TuttiUIUtil;
import org.apache.commons.logging.Log;
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-01-31 08:47:56 UTC (rev 276)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/home/ImportProtocolAction.java 2013-01-31 15:26:25 UTC (rev 277)
@@ -25,7 +25,7 @@
*/
import fr.ifremer.tutti.persistence.entities.protocol.TuttiProtocol;
-import fr.ifremer.tutti.service.TuttiProtocolImportExportService;
+import fr.ifremer.tutti.service.protocol.TuttiProtocolImportExportService;
import fr.ifremer.tutti.ui.swing.AbstractTuttiAction;
import fr.ifremer.tutti.ui.swing.TuttiScreen;
import fr.ifremer.tutti.ui.swing.util.TuttiUIUtil;
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolUI.css
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolUI.css 2013-01-31 08:47:56 UTC (rev 276)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolUI.css 2013-01-31 15:26:25 UTC (rev 277)
@@ -99,20 +99,51 @@
sortable: false;
}
+#caracteristicPane {
+ tabPlacement: {JTabbedPane.LEFT};
+}
+
+#importSpecies{
+ actionIcon: import;
+ action: {importProtocolSpeciesAction};
+}
+
+#importCaracteristic {
+ actionIcon: import;
+ action: {importProtocolCaracteristicAction};
+}
+
+#exportCaracteristic {
+ actionIcon: export;
+ action: {exportProtocolCaracteristicAction};
+}
+
+#exportAllCaracteristic {
+ actionIcon: export;
+ action: {exportAllCaracteristicAction};
+}
+
#gearList {
property: gearPmfm;
beanType: {Caracteristic.class};
- border: {BorderFactory.createTitledBorder(_("tutti.label.tab.fishingOperation.gearShooting"))};
+ /*border: {BorderFactory.createTitledBorder(_("tutti.label.tab.fishingOperation.gearShooting"))};*/
}
#environmentList {
property: environmentPmfm;
beanType: {Caracteristic.class};
- border: {BorderFactory.createTitledBorder(_("tutti.label.tab.fishingOperation.environment"))};
+ /*border: {BorderFactory.createTitledBorder(_("tutti.label.tab.fishingOperation.environment"))};*/
}
#hydrologyList {
property: hydrologyPmfm;
beanType: {Caracteristic.class};
- border: {BorderFactory.createTitledBorder(_("tutti.label.tab.fishingOperation.hydrology"))};
+ /*border: {BorderFactory.createTitledBorder(_("tutti.label.tab.fishingOperation.hydrology"))};*/
}
+
+#lengthClassesList {
+ property: lengthClassesPmfm;
+ beanType: {Caracteristic.class};
+ /*border: {BorderFactory.createTitledBorder(_("tutti.label.tab.fishingOperation.lengthClasses"))};*/
+}
+
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolUI.jaxx
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolUI.jaxx 2013-01-31 08:47:56 UTC (rev 276)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolUI.jaxx 2013-01-31 15:26:25 UTC (rev 277)
@@ -68,9 +68,21 @@
<EditProtocolUIModel id='model'
initializer='getContextValue(EditProtocolUIModel.class)'/>
- <CancelEditProtocolAction id='cancelEditProtocolAction' constructorParams='handler'/>
+ <CancelEditProtocolAction id='cancelEditProtocolAction'
+ constructorParams='handler'/>
<SaveProtocolAction id='saveProtocolAction' constructorParams='handler'/>
+ <ImportProtocolCaracteristicAction id='importProtocolCaracteristicAction'
+ constructorParams='handler'/>
+ <ExportProtocolCaracteristicAction id='exportProtocolCaracteristicAction'
+ constructorParams='handler'/>
+
+ <ExportAllCaracteristicAction id='exportAllCaracteristicAction'
+ constructorParams='handler'/>
+
+ <ImportProtocolSpeciesAction id='importProtocolSpeciesAction'
+ constructorParams='handler'/>
+
<SwingValidatorMessageTableModel id='errorTableModel'/>
<BeanValidator id='validator' bean='model' errorTableModel='errorTableModel'
@@ -113,7 +125,31 @@
</tab>
<tab title='tutti.label.tab.protocol.fishingOperation'>
- <Table fill='both' weightx='1'>
+ <JPanel id='caracteristicPanel' layout="{new BorderLayout()}">
+ <JPanel id='caracteristicActions' layout="{new GridLayout()}"
+ constraints='BorderLayout.NORTH'>
+
+ <JButton id='importCaracteristic'/>
+ <JButton id='exportCaracteristic'/>
+ <JButton id='exportAllCaracteristic'/>
+ </JPanel>
+ <JTabbedPane id='caracteristicPane' constraints='BorderLayout.CENTER'>
+ <tab title='tutti.label.tab.protocol.caracteristic.lengthClasses'>
+ <BeanDoubleList id='lengthClassesList' genericType='Caracteristic'/>
+ </tab>
+ <tab title='tutti.label.tab.protocol.caracteristic.gear'>
+ <BeanDoubleList id='gearList' genericType='Caracteristic'/>
+ </tab>
+ <tab title='tutti.label.tab.protocol.caracteristic.environment'>
+ <BeanDoubleList id='environmentList' genericType='Caracteristic'/>
+ </tab>
+ <tab title='tutti.label.tab.protocol.caracteristic.hydrology'>
+ <BeanDoubleList id='hydrologyList' genericType='Caracteristic'/>
+ </tab>
+ </JTabbedPane>
+ </JPanel>
+
+ <!--Table fill='both' weightx='1'>
<row fill='both' weighty='1'>
<cell fill='both'>
<BeanDoubleList id='gearList' genericType='Caracteristic'/>
@@ -129,46 +165,50 @@
<BeanDoubleList id='hydrologyList' genericType='Caracteristic'/>
</cell>
</row>
- </Table>
+ </Table-->
</tab>
<tab title='tutti.label.tab.protocol.species'>
- <Table fill='both'>
- <row fill='both'>
- <cell fill='both' weightx='1'>
- <BeanComboBox id='speciesComboBox' constructorParams='this'
- genericType='Species'/>
- </cell>
- <cell fill='both'>
- <JButton id='addRow' onActionPerformed='handler.addRow()'/>
- </cell>
- </row>
- <row fill='both' weighty='1'>
- <cell fill='both' columns='2'>
- <JScrollPane>
- <JXTable id='speciesTable'
- onMouseClicked='handler.autoSelectRowInTable(event, tablePopup)'/>
- </JScrollPane>
- </cell>
- </row>
- </Table>
+ <JPanel id='speciesPanel' layout="{new BorderLayout()}">
+ <JButton id='importSpecies' constraints='BorderLayout.NORTH'/>
+ <Table fill='both' constraints='BorderLayout.CENTER'>
+
+ <row fill='both'>
+ <cell fill='both' weightx='1'>
+ <BeanComboBox id='speciesComboBox' constructorParams='this'
+ genericType='Species'/>
+ </cell>
+ <cell fill='both'>
+ <JButton id='addRow' onActionPerformed='handler.addRow()'/>
+ </cell>
+ </row>
+ <row fill='both' weighty='1'>
+ <cell fill='both' columns='2'>
+ <JScrollPane>
+ <JXTable id='speciesTable'
+ onMouseClicked='handler.autoSelectRowInTable(event, tablePopup)'/>
+ </JScrollPane>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
</tab>
- <tab title='tutti.label.tab.protocol.benthos'>
+ <tab title='tutti.label.tab.protocol.benthos' enabled='false'>
<JLabel text='tutti.to.be.done' enabled='false'
horizontalAlignment="{JLabel.CENTER}"/>
</tab>
- <tab title='tutti.label.tab.protocol.plankton'>
+ <tab title='tutti.label.tab.protocol.plankton' enabled='false'>
<JLabel text='tutti.to.be.done' enabled='false'
horizontalAlignment="{JLabel.CENTER}"/>
</tab>
- <tab title='tutti.label.tab.protocol.accidental'>
+ <tab title='tutti.label.tab.protocol.accidental' enabled='false'>
<JLabel text='tutti.to.be.done' enabled='false'
horizontalAlignment="{JLabel.CENTER}"/>
</tab>
-
</JTabbedPane>
- <JPanel id='warningContainer' layout='{new BorderLayout(10, 10)}' constraints='BorderLayout.NORTH'>
+ <JPanel id='warningContainer' layout='{new BorderLayout(10, 10)}'
+ constraints='BorderLayout.NORTH'>
<JLabel id='importWarning' constraints='BorderLayout.CENTER'/>
</JPanel>
<JPanel layout='{new GridLayout(1, 0)}' constraints='BorderLayout.SOUTH'>
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolUIHandler.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolUIHandler.java 2013-01-31 08:47:56 UTC (rev 276)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolUIHandler.java 2013-01-31 15:26:25 UTC (rev 277)
@@ -70,6 +70,8 @@
protected Map<String, Caracteristic> allLengthStepPmfm;
+ protected List<Caracteristic> allCaracteristic;
+
// protected Multimap<String, String> hydroCaracteristics;
public EditProtocolUIHandler(TuttiUI parentUi, EditProtocolUI ui) {
@@ -166,6 +168,8 @@
allLengthStepPmfm = TuttiEntities.splitById(
persistenceService.getAllCaracteristic());
+ allCaracteristic = persistenceService.getAllCaracteristic();
+
// hydroCaracteristics = ArrayListMultimap.create();
// for (Caracteristic caracteristic :
// persistenceService.getAllCaracteristic()) {
@@ -174,6 +178,10 @@
// }
}
+ public List<Caracteristic> getAllCaracteristic() {
+ return allCaracteristic;
+ }
+
@Override
public void afterInitUI() {
@@ -291,27 +299,23 @@
// set to model ( will propagate to tableModel)
model.setRows(rows);
- // init species combo box
initBeanComboBox(ui.getSpeciesComboBox(), speciesList, null);
selectFirstInCombo(ui.getSpeciesComboBox());
- // init gear pmfm double list
- List<Caracteristic> gearPmfm =
- persistenceService.getAllCaracteristic();
- initDoubleList(ui.getGearList(), gearPmfm, model.getGearPmfmId());
+ initDoubleList(ui.getLengthClassesList(),
+ Lists.newArrayList(allCaracteristic),
+ model.getHydrologyPmfmId());
- // init environement pmfm double list
- List<Caracteristic> environmentPmfm =
- persistenceService.getAllCaracteristic();
+ initDoubleList(ui.getGearList(),
+ Lists.newArrayList(allCaracteristic),
+ model.getGearPmfmId());
+
initDoubleList(ui.getEnvironmentList(),
- environmentPmfm,
+ Lists.newArrayList(allCaracteristic),
model.getEnvironmentPmfmId());
- // init hydro pmfm double list
- List<Caracteristic> hydroPmfm =
- persistenceService.getAllCaracteristic();
initDoubleList(ui.getHydrologyList(),
- hydroPmfm,
+ Lists.newArrayList(allCaracteristic),
model.getHydrologyPmfmId());
// List<Caracteristic> selection = Lists.newArrayList();
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolUIModel.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolUIModel.java 2013-01-31 08:47:56 UTC (rev 276)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolUIModel.java 2013-01-31 15:26:25 UTC (rev 277)
@@ -24,7 +24,7 @@
* #L%
*/
-import com.google.common.collect.Lists;
+import fr.ifremer.tutti.persistence.entities.TuttiEntities;
import fr.ifremer.tutti.persistence.entities.protocol.TuttiProtocol;
import fr.ifremer.tutti.persistence.entities.referential.Caracteristic;
import fr.ifremer.tutti.ui.swing.util.table.AbstractTuttiTableUIModel;
@@ -121,6 +121,11 @@
firePropertyChange(PROPERTY_LENGTH_CLASSES_PMFM_ID, oldValue, lengthClassesPmfmId);
}
+ public void setLengthClassesPmfm(List<Caracteristic> lengthClassesPmfm) {
+ List<String> ids = TuttiEntities.collecIds(lengthClassesPmfm);
+ setLengthClassesPmfmId(ids);
+ }
+
public List<String> getGearPmfmId() {
return gearPmfmId;
}
@@ -132,10 +137,7 @@
}
public void setGearPmfm(List<Caracteristic> gearPmfm) {
- List<String> ids = Lists.newArrayList();
- for (Caracteristic caracteristic : gearPmfm) {
- ids.add(caracteristic.getId());
- }
+ List<String> ids = TuttiEntities.collecIds(gearPmfm);
setGearPmfmId(ids);
}
@@ -150,10 +152,7 @@
}
public void setEnvironmentPmfm(List<Caracteristic> environmentPmfm) {
- List<String> ids = Lists.newArrayList();
- for (Caracteristic caracteristic : environmentPmfm) {
- ids.add(caracteristic.getId());
- }
+ List<String> ids = TuttiEntities.collecIds(environmentPmfm);
setEnvironmentPmfmId(ids);
}
@@ -168,10 +167,7 @@
}
public void setHydrologyPmfm(List<Caracteristic> hydrologyPmfm) {
- List<String> ids = Lists.newArrayList();
- for (Caracteristic caracteristic : hydrologyPmfm) {
- ids.add(caracteristic.getId());
- }
+ List<String> ids = TuttiEntities.collecIds(hydrologyPmfm);
setHydrologyPmfmId(ids);
}
Added: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/ExportAllCaracteristicAction.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/ExportAllCaracteristicAction.java (rev 0)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/ExportAllCaracteristicAction.java 2013-01-31 15:26:25 UTC (rev 277)
@@ -0,0 +1,86 @@
+package fr.ifremer.tutti.ui.swing.content.protocol;
+
+import fr.ifremer.tutti.persistence.entities.TuttiEntities;
+import fr.ifremer.tutti.persistence.entities.referential.Caracteristic;
+import fr.ifremer.tutti.service.protocol.TuttiProtocolImportExportService;
+import fr.ifremer.tutti.ui.swing.AbstractTuttiAction;
+import fr.ifremer.tutti.ui.swing.util.TuttiUIUtil;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.awt.event.ActionEvent;
+import java.io.File;
+import java.util.List;
+import java.util.Map;
+
+import static org.nuiton.i18n.I18n._;
+
+/**
+ * To export all caracteristics.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.0
+ */
+public class ExportAllCaracteristicAction extends AbstractTuttiAction<EditProtocolUIModel, EditProtocolUIHandler> {
+
+ private static final long serialVersionUID = 1L;
+
+ /** Logger. */
+ private static final Log log =
+ LogFactory.getLog(ExportAllCaracteristicAction.class);
+
+ private File file;
+
+ public ExportAllCaracteristicAction(EditProtocolUIHandler handler) {
+ super(handler,
+ "exportAllCaracteristic",
+ "export",
+ _("tutti.action.exportAllCaracteristic"),
+ _("tutti.action.exportAllCaracteristic.tip"),
+ true
+ );
+ }
+
+ @Override
+ protected boolean prepareAction(ActionEvent event) {
+
+ // choose file to import
+ file = TuttiUIUtil.chooseFile(
+ getContext().getMainUI(),
+ _("tutti.title.choose.protocolCaracteristicExportFile"),
+ _("tutti.action.chooseProtocolCaracteristicFile"),
+ null,
+ "^.*\\.csv", _("tutti.file.csv")
+ );
+ boolean doAction = file != null;
+ if (doAction) {
+ super.prepareAction(event);
+ }
+ return doAction;
+ }
+
+ @Override
+ protected void releaseAction(ActionEvent event) {
+ super.releaseAction(event);
+ file = null;
+ }
+
+ @Override
+ protected void doAction(ActionEvent e) throws Exception {
+
+ if (log.isInfoEnabled()) {
+ log.info("Will export all caracteristic to file: " + file);
+ }
+
+ // export protocol caracteristics
+ TuttiProtocolImportExportService service =
+ getContext().getService(TuttiProtocolImportExportService.class);
+
+ List<Caracteristic> allCaracteristic = getHandler().getAllCaracteristic();
+ Map<String, Caracteristic> caracteristicMap = TuttiEntities.splitById(allCaracteristic);
+
+ service.exportAllCaracteristic(file, caracteristicMap);
+
+ sendMessage("Caractéristiques exportées dans le fichier.");
+ }
+}
\ No newline at end of file
Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/ExportAllCaracteristicAction.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/ExportProtocolCaracteristicAction.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/ExportProtocolCaracteristicAction.java (rev 0)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/ExportProtocolCaracteristicAction.java 2013-01-31 15:26:25 UTC (rev 277)
@@ -0,0 +1,90 @@
+package fr.ifremer.tutti.ui.swing.content.protocol;
+
+import fr.ifremer.tutti.persistence.entities.TuttiEntities;
+import fr.ifremer.tutti.persistence.entities.protocol.TuttiProtocol;
+import fr.ifremer.tutti.persistence.entities.referential.Caracteristic;
+import fr.ifremer.tutti.service.protocol.TuttiProtocolImportExportService;
+import fr.ifremer.tutti.ui.swing.AbstractTuttiAction;
+import fr.ifremer.tutti.ui.swing.util.TuttiUIUtil;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.awt.event.ActionEvent;
+import java.io.File;
+import java.util.List;
+import java.util.Map;
+
+import static org.nuiton.i18n.I18n._;
+
+/**
+ * To import protocol caracteristics.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.0
+ */
+public class ExportProtocolCaracteristicAction extends AbstractTuttiAction<EditProtocolUIModel, EditProtocolUIHandler> {
+
+ private static final long serialVersionUID = 1L;
+
+ /** Logger. */
+ private static final Log log =
+ LogFactory.getLog(ExportProtocolCaracteristicAction.class);
+
+ private File file;
+
+ public ExportProtocolCaracteristicAction(EditProtocolUIHandler handler) {
+ super(handler,
+ "exportProtocolCaracteristic",
+ "export",
+ _("tutti.action.exportProtocolCaracteristic"),
+ _("tutti.action.exportProtocolCaracteristic.tip"),
+ true
+ );
+ }
+
+ @Override
+ protected boolean prepareAction(ActionEvent event) {
+
+ // choose file to import
+ file = TuttiUIUtil.chooseFile(
+ getContext().getMainUI(),
+ _("tutti.title.choose.protocolCaracteristicExportFile"),
+ _("tutti.action.chooseProtocolCaracteristicFile"),
+ null,
+ "^.*\\.csv", _("tutti.file.csv")
+ );
+ boolean doAction = file != null;
+ if (doAction) {
+ super.prepareAction(event);
+ }
+ return doAction;
+ }
+
+ @Override
+ protected void releaseAction(ActionEvent event) {
+ super.releaseAction(event);
+ file = null;
+ }
+
+ @Override
+ protected void doAction(ActionEvent e) throws Exception {
+
+ if (log.isInfoEnabled()) {
+ log.info("Will export protocol caracteristic to file: " + file);
+ }
+
+ // bind to a protocol
+ TuttiProtocol protocol = getModel().toBean();
+
+ // export protocol caracteristics
+ TuttiProtocolImportExportService service =
+ getContext().getService(TuttiProtocolImportExportService.class);
+
+ List<Caracteristic> allCaracteristic = getHandler().getAllCaracteristic();
+ Map<String, Caracteristic> caracteristicMap = TuttiEntities.splitById(allCaracteristic);
+
+ service.exportProtocolCaracteristic(file, protocol, caracteristicMap);
+
+ sendMessage("Caractéristiques du Protocole [" + protocol.getName() + "] exportées dans le fichier.");
+ }
+}
\ No newline at end of file
Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/ExportProtocolCaracteristicAction.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/ImportProtocolCaracteristicAction.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/ImportProtocolCaracteristicAction.java (rev 0)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/ImportProtocolCaracteristicAction.java 2013-01-31 15:26:25 UTC (rev 277)
@@ -0,0 +1,93 @@
+package fr.ifremer.tutti.ui.swing.content.protocol;
+
+import fr.ifremer.tutti.persistence.entities.TuttiEntities;
+import fr.ifremer.tutti.persistence.entities.protocol.TuttiProtocol;
+import fr.ifremer.tutti.persistence.entities.referential.Caracteristic;
+import fr.ifremer.tutti.service.protocol.TuttiProtocolImportExportService;
+import fr.ifremer.tutti.ui.swing.AbstractTuttiAction;
+import fr.ifremer.tutti.ui.swing.util.TuttiUIUtil;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.awt.event.ActionEvent;
+import java.io.File;
+import java.util.List;
+import java.util.Map;
+
+import static org.nuiton.i18n.I18n._;
+
+/**
+ * To import protocol caracteristics.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.0
+ */
+public class ImportProtocolCaracteristicAction extends AbstractTuttiAction<EditProtocolUIModel, EditProtocolUIHandler> {
+
+ private static final long serialVersionUID = 1L;
+
+ /** Logger. */
+ private static final Log log =
+ LogFactory.getLog(ImportProtocolCaracteristicAction.class);
+
+ private File file;
+
+ public ImportProtocolCaracteristicAction(EditProtocolUIHandler handler) {
+ super(handler,
+ "importProtocolCaracteristic",
+ "import",
+ _("tutti.action.importProtocolCaracteristic"),
+ _("tutti.action.importProtocolCaracteristic.tip"),
+ true
+ );
+ }
+
+ @Override
+ protected boolean prepareAction(ActionEvent event) {
+
+ // choose file to import
+ file = TuttiUIUtil.chooseFile(
+ getContext().getMainUI(),
+ _("tutti.title.choose.protocolCaracteristicImportFile"),
+ _("tutti.action.chooseProtocolCaracteristicFile"),
+ null,
+ "^.*\\.csv", _("tutti.file.csv")
+ );
+ boolean doAction = file != null;
+ if (doAction) {
+ super.prepareAction(event);
+ }
+ return doAction;
+ }
+
+ @Override
+ protected void releaseAction(ActionEvent event) {
+ super.releaseAction(event);
+ file = null;
+ }
+
+ @Override
+ protected void doAction(ActionEvent e) throws Exception {
+
+ if (log.isInfoEnabled()) {
+ log.info("Will import protocol caracteristic file: " + file);
+ }
+
+ // bind to a protocol
+ TuttiProtocol protocol = getModel().toBean();
+
+ // import protocol caracteristics
+ TuttiProtocolImportExportService service =
+ getContext().getService(TuttiProtocolImportExportService.class);
+
+ List<Caracteristic> allCaracteristic = getHandler().getAllCaracteristic();
+ Map<String,Caracteristic> caracteristicMap = TuttiEntities.splitById(allCaracteristic);
+
+ service.importProtocolCaracteristic(file, protocol, caracteristicMap);
+
+ // rebind to model
+ getModel().fromBean(protocol);
+
+ sendMessage("Caractéristiques du Protocole [" + protocol.getName() + "] lu depuis le fichier.");
+ }
+}
\ No newline at end of file
Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/ImportProtocolCaracteristicAction.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/ImportProtocolSpeciesAction.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/ImportProtocolSpeciesAction.java (rev 0)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/ImportProtocolSpeciesAction.java 2013-01-31 15:26:25 UTC (rev 277)
@@ -0,0 +1,86 @@
+package fr.ifremer.tutti.ui.swing.content.protocol;
+
+import fr.ifremer.tutti.persistence.entities.protocol.TuttiProtocol;
+import fr.ifremer.tutti.service.protocol.TuttiProtocolImportExportService;
+import fr.ifremer.tutti.ui.swing.AbstractTuttiAction;
+import fr.ifremer.tutti.ui.swing.util.TuttiUIUtil;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.awt.event.ActionEvent;
+import java.io.File;
+
+import static org.nuiton.i18n.I18n._;
+
+/**
+ * To import protocol species.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.0
+ */
+public class ImportProtocolSpeciesAction extends AbstractTuttiAction<EditProtocolUIModel, EditProtocolUIHandler> {
+
+ private static final long serialVersionUID = 1L;
+
+ /** Logger. */
+ private static final Log log =
+ LogFactory.getLog(ImportProtocolSpeciesAction.class);
+
+ private File file;
+
+ public ImportProtocolSpeciesAction(EditProtocolUIHandler handler) {
+ super(handler,
+ "importProtocolSpecies",
+ "import",
+ _("tutti.action.importProtocolSpecies"),
+ _("tutti.action.importProtocolSpecies.tip"),
+ true
+ );
+ }
+
+ @Override
+ protected boolean prepareAction(ActionEvent event) {
+
+ // choose file to import
+ file = TuttiUIUtil.chooseFile(
+ getContext().getMainUI(),
+ _("tutti.title.choose.protocolSpeciesImportFile"),
+ _("tutti.action.chooseProtocolSpeciesFile"),
+ null,
+ "^.*\\.csv", _("tutti.file.csv")
+ );
+ boolean doAction = file != null;
+ if (doAction) {
+ super.prepareAction(event);
+ }
+ return doAction;
+ }
+
+ @Override
+ protected void releaseAction(ActionEvent event) {
+ super.releaseAction(event);
+ file = null;
+ }
+
+ @Override
+ protected void doAction(ActionEvent e) throws Exception {
+
+ if (log.isInfoEnabled()) {
+ log.info("Will import protocol species file: " + file);
+ }
+
+ // bind to a protocol
+ TuttiProtocol protocol = getModel().toBean();
+
+ // import
+ TuttiProtocolImportExportService service =
+ getContext().getService(TuttiProtocolImportExportService.class);
+
+ service.importProtocolSpecies(file, protocol);
+
+ // rebind to model
+ getModel().fromBean(protocol);
+
+ sendMessage("Espèces du Protocole [" + protocol.getName() + "] importées depuis le fichier.");
+ }
+}
\ No newline at end of file
Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/ImportProtocolSpeciesAction.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
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-01-31 08:47:56 UTC (rev 276)
+++ trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_fr_FR.properties 2013-01-31 15:26:25 UTC (rev 277)
@@ -10,9 +10,10 @@
tutti.action.cancel.editProgram.tip=Annuler l'édition (ou la création) de la série de campagne
tutti.action.cancel.editProtocol=Annuler
tutti.action.cancel.editProtocol.tip=Annuler l'édition (ou la création) du protocole
-tutti.action.cancel.editcruise=
tutti.action.casino-import=Import Casino
+tutti.action.chooseProtocolCaracteristicFile=Choisir le fichier des caractéristiques
tutti.action.chooseProtocolFile=Choisir le fichier de protocole
+tutti.action.chooseProtocolSpeciesFile=Choisir le fichier des espèces
tutti.action.cloneProtocol=Cloner
tutti.action.cloneProtocol.tip=Dupliquer le protocole sélectionné
tutti.action.close=Fermer
@@ -35,12 +36,20 @@
tutti.action.editSelectedProtocol.tip=Éditer le protocole sélectionnée
tutti.action.exit=Quitter
tutti.action.exit.tip=Quitter l'application
+tutti.action.exportAllCaracteristic=Exporter toutes les caractéristiques
+tutti.action.exportAllCaracteristic.tip=Exporter toutes les caractéristiques (sans les affecter à un écran)
tutti.action.exportProtocol=Exporter
tutti.action.exportProtocol.tip=Exporter le protocole sélectionné
+tutti.action.exportProtocolCaracteristic=Exporter les caractéristiques
+tutti.action.exportProtocolCaracteristic.tip=Exporter les caractéristiques du protocole
tutti.action.generate=Générer
tutti.action.generateCampaignName=Générer le nom
tutti.action.importProtocol=Importer
tutti.action.importProtocol.tip=Importer un protocole
+tutti.action.importProtocolCaracteristic=Importer les caractéristiques
+tutti.action.importProtocolCaracteristic.tip=importer les caractéristiques dans le protocole
+tutti.action.importProtocolSpecies=Importer les espèces
+tutti.action.importProtocolSpecies.tip=importer les espèces dans le protocole
tutti.action.new=Nouveau
tutti.action.newCruise=Nouveau
tutti.action.newCruise.tip=Créer une nouvelle campagne
@@ -103,9 +112,10 @@
tutti.dialog.askSaveBeforeLeaving.message=Vous avez fait des modifications qu vous n'avez pas enregistrées. Voulez-vous les enregistrer ?
tutti.dialog.askSaveBeforeLeaving.title=Modifications non enregistrées
tutti.duration.format=dj Hh m'm'
-tutti.errorTable.title=Table d'erreurs
+tutti.errorTable.title=Rapport de contrôles
+tutti.file.csv=Extension d'un fichier csv
tutti.file.protocol=Extension d'un fichier de protocole Tutti
-tutti.jre.directory.description=
+tutti.jre.directory.description=Répertoire de la jre
tutti.label.attachmentEditor.file=Fichier
tutti.label.attachmentEditor.fileComment=Commentaire
tutti.label.attachmentEditor.fileName=Nom
@@ -214,11 +224,16 @@
tutti.label.tab.fishingOperation.gearShooting=Mise en oeuvre de l'engin
tutti.label.tab.fishingOperation.general=Trait
tutti.label.tab.fishingOperation.hydrology=Paramètres hydrologiques
+tutti.label.tab.fishingOperation.lengthClasses=Classes de taille
tutti.label.tab.macroDechet=Macro déchets
tutti.label.tab.observationIndividuel=Observations individuelles
tutti.label.tab.plancton=Plancton
tutti.label.tab.protocol.accidental=Accidental
tutti.label.tab.protocol.benthos=Benthos
+tutti.label.tab.protocol.caracteristic.environment=Environnement
+tutti.label.tab.protocol.caracteristic.gear=Mise en oeuvre de l'engin
+tutti.label.tab.protocol.caracteristic.hydrology=Paramètres hydrologiques
+tutti.label.tab.protocol.caracteristic.lengthClasses=Classes de taille
tutti.label.tab.protocol.fishingOperation=Trait
tutti.label.tab.protocol.info=Informations générales
tutti.label.tab.protocol.plankton=Plancton
@@ -317,8 +332,10 @@
tutti.table.species.sampleCategory.header.weight=Poids (kg)
tutti.timeeditor.H=H
tutti.title.about=À propos de Tutti
+tutti.title.choose.protocolCaracteristicImportFile=Choisir le fichier des caractéristiques à importer
tutti.title.choose.protocolExportFile=Choisir le fichier où exporter le protocole
tutti.title.choose.protocolImportFile=Choisir le fichier du protocole à importer
+tutti.title.choose.protocolSpeciesImportFile=
tutti.title.create.cruise=Créer une nouvelle campagne
tutti.title.create.program=Créer une nouvelle série de campagne
tutti.title.create.protocol=Créer un nouveau protocol de saisie
Property changes on: trunk/tutti-ui-swing/src/main/resources/icons/action-alert-error.png
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Property changes on: trunk/tutti-ui-swing/src/main/resources/icons/action-alert-info.png
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Property changes on: trunk/tutti-ui-swing/src/main/resources/icons/action-alert-none.png
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Property changes on: trunk/tutti-ui-swing/src/main/resources/icons/action-alert-warning.png
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Property changes on: trunk/tutti-ui-swing/src/main/resources/icons/action-protocol.png
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
1
0
31 Jan '13
Author: kmorin
Date: 2013-01-31 09:47:56 +0100 (Thu, 31 Jan 2013)
New Revision: 276
Url: http://forge.codelutin.com/projects/tutti/repository/revisions/276
Log:
- change icons
- display the alert number in the validator message widget tooltip + change the icon accroding to the alert types
- replace popups by cardlayouts
- add fileds to the species catch
Added:
trunk/tutti-ui-swing/src/main/resources/icons/action-alert-error.png
trunk/tutti-ui-swing/src/main/resources/icons/action-alert-info.png
trunk/tutti-ui-swing/src/main/resources/icons/action-alert-none.png
trunk/tutti-ui-swing/src/main/resources/icons/action-alert-warning.png
trunk/tutti-ui-swing/src/main/resources/icons/action-protocol.png
Modified:
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/AbstractTuttiBeanUIModel.java
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/AbstractTuttiUIHandler.java
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/EditSelectedProtocolAction.java
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/MainUIHandler.java
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/cruise/EditCruiseUIHandler.java
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/home/EditCatchesAction.java
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/home/SelectCruiseUI.css
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/home/SelectCruiseUIHandler.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/FishingOperationsUIHandler.java
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.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/accidental/AccidentalBatchUIHandler.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/macrowaste/MacroWasteBatchUIHandler.java
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/plankton/PlanktonBatchUIHandler.java
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUI.css
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUI.jaxx
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/FrequencyCellComponent.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/frequency/SpeciesFrequencyUIHandler.java
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/AddSpeciesAction.java
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/AddSpeciesUIHandler.java
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/CreateSpeciesBatchUIHandler.java
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSpeciesBatchUI.jaxx
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/CaracteristicTabUIHandler.java
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/fishing/gearshooting/GearShootingTabUIHandler.java
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/fishing/hydrology/HydrologyTabUIHandler.java
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/program/EditProgramUIHandler.java
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolSpeciesTableModel.java
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolUIHandler.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
trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/SwingValidatorMessageWidget.java
trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_fr_FR.properties
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/AbstractTuttiBeanUIModel.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/AbstractTuttiBeanUIModel.java 2013-01-31 08:45:23 UTC (rev 275)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/AbstractTuttiBeanUIModel.java 2013-01-31 08:47:56 UTC (rev 276)
@@ -97,8 +97,12 @@
}
public String getTitle() {
- return "test title";
+ 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/AbstractTuttiUIHandler.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/AbstractTuttiUIHandler.java 2013-01-31 08:45:23 UTC (rev 275)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/AbstractTuttiUIHandler.java 2013-01-31 08:47:56 UTC (rev 276)
@@ -100,6 +100,8 @@
public abstract void onCloseUI();
public abstract M getModel();
+
+ public abstract SwingValidator<M> getValidator();
protected final TuttiUIContext context;
@@ -286,6 +288,10 @@
Decorator<E> decorator = getDecorator(beanType, null);
+ if (data == null) {
+ data = Lists.newArrayList();
+ }
+
if (log.isInfoEnabled()) {
log.info("entity comboBox list [" + beanType.getName() + "] : " +
(data == null ? 0 : data.size()));
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/EditSelectedProtocolAction.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/EditSelectedProtocolAction.java 2013-01-31 08:45:23 UTC (rev 275)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/EditSelectedProtocolAction.java 2013-01-31 08:47:56 UTC (rev 276)
@@ -48,7 +48,7 @@
public EditSelectedProtocolAction(MainUIHandler handler) {
super(handler,
"editProtocol",
- "edit",
+ "protocol",
_("tutti.action.editSelectedProtocol"),
_("tutti.action.editSelectedProtocol.tip"),
true
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/MainUIHandler.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/MainUIHandler.java 2013-01-31 08:45:23 UTC (rev 275)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/MainUIHandler.java 2013-01-31 08:47:56 UTC (rev 276)
@@ -138,6 +138,11 @@
return ui.getModel();
}
+ @Override
+ public SwingValidator<TuttiUIContext> getValidator() {
+ return null;
+ }
+
//------------------------------------------------------------------------//
//-- Public methods --//
//------------------------------------------------------------------------//
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/cruise/EditCruiseUIHandler.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/cruise/EditCruiseUIHandler.java 2013-01-31 08:45:23 UTC (rev 275)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/cruise/EditCruiseUIHandler.java 2013-01-31 08:47:56 UTC (rev 276)
@@ -269,6 +269,11 @@
return ui.getModel();
}
+ @Override
+ public SwingValidator<EditCruiseUIModel> getValidator() {
+ return ui.getValidator();
+ }
+
public static final String cruiseNameFormat = "%1$s_%2$s";
public void generateCampaignName() {
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/home/EditCatchesAction.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/home/EditCatchesAction.java 2013-01-31 08:45:23 UTC (rev 275)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/home/EditCatchesAction.java 2013-01-31 08:47:56 UTC (rev 276)
@@ -30,6 +30,7 @@
import fr.ifremer.tutti.ui.swing.TuttiUIContext;
import java.awt.event.ActionEvent;
+import org.apache.commons.logging.LogFactory;
import static org.nuiton.i18n.I18n._;
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/home/SelectCruiseUI.css
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/home/SelectCruiseUI.css 2013-01-31 08:45:23 UTC (rev 275)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/home/SelectCruiseUI.css 2013-01-31 08:47:56 UTC (rev 276)
@@ -30,6 +30,7 @@
#programLabel {
text: "tutti.label.program";
+ actionIcon: program;
}
#programCombobox {
@@ -51,6 +52,7 @@
#cruiseLabel {
text: "tutti.label.cruise";
labelFor: {cruiseCombobox};
+ actionIcon: cruise;
}
#cruiseCombobox {
@@ -72,6 +74,7 @@
#protocolLabel {
text: "tutti.label.protocol";
labelFor: {protocolCombobox};
+ actionIcon: protocol;
}
#protocolCombobox {
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/home/SelectCruiseUIHandler.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/home/SelectCruiseUIHandler.java 2013-01-31 08:45:23 UTC (rev 275)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/home/SelectCruiseUIHandler.java 2013-01-31 08:47:56 UTC (rev 276)
@@ -43,6 +43,7 @@
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.List;
+import jaxx.runtime.validator.swing.SwingValidator;
/**
* Main ui content to select cruise.
@@ -72,6 +73,11 @@
}
@Override
+ public SwingValidator<SelectCruiseUIModel> getValidator() {
+ return null;
+ }
+
+ @Override
public void beforeInitUI() {
SelectCruiseUIModel model = new SelectCruiseUIModel();
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-01-31 08:45:23 UTC (rev 275)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationUIHandler.java 2013-01-31 08:47:56 UTC (rev 276)
@@ -66,6 +66,8 @@
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.List;
+import jaxx.runtime.SwingUtil;
+import jaxx.runtime.validator.swing.SwingValidator;
/**
* Handler for UI {@link EditFishingOperationUI}.
@@ -330,10 +332,6 @@
});
}
- MainUI main = ui.getContextValue(MainUI.class, MainUI.class.getName());
- main.clearValidators();
- main.registerValidator(ui.getValidator());
-
}
@Override
@@ -374,6 +372,9 @@
@Override
public void onShowTab() {
+ MainUI main = ui.getContextValue(MainUI.class, MainUI.class.getName());
+ main.clearValidators();
+ main.registerValidator(ui.getValidator());
}
@Override
@@ -386,6 +387,11 @@
return ui.getModel();
}
+ @Override
+ public SwingValidator<EditFishingOperationUIModel> getValidator() {
+ return ui.getValidator();
+ }
+
//------------------------------------------------------------------------//
//-- Public methods --//
//------------------------------------------------------------------------//
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-01-31 08:45:23 UTC (rev 275)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationUIModel.java 2013-01-31 08:47:56 UTC (rev 276)
@@ -54,9 +54,8 @@
private static final long serialVersionUID = 1L;
- public static final String TITLE =
- n_("tutti.label.tab.fishingOperation.general");
-
+ public static final String TITLE = n_("tutti.label.tab.fishingOperation.general");
+
public static final String PROPERTY_PERSISTED = "persisted";
public static final String PROPERTY_EMPTY = "empty";
@@ -209,6 +208,7 @@
gearShootingEndLongitudeAsSexagecimal = SexagecimalPosition.valueOf(gearShootingEndLongitude);
}
+ @Override
public String getTitle() {
return TITLE;
}
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-01-31 08:45:23 UTC (rev 275)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/FishingOperationsUIHandler.java 2013-01-31 08:47:56 UTC (rev 276)
@@ -43,6 +43,7 @@
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.List;
+import jaxx.runtime.validator.swing.SwingValidator;
import static org.nuiton.i18n.I18n._;
@@ -181,6 +182,11 @@
}
@Override
+ public SwingValidator<FishingOperationsUIModel> getValidator() {
+ return null;
+ }
+
+ @Override
protected JTabbedPane getTabPanel() {
return ui.getTabPane();
}
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-01-31 08:45:23 UTC (rev 275)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUI.css 2013-01-31 08:47:56 UTC (rev 276)
@@ -238,6 +238,22 @@
text: "tutti.action.pupitri-import";
}
+#benthosTab {
+ enabled: {false};
+}
+
+#planktonTab {
+ enabled: {false};
+}
+
+#macroWasteTab {
+ enabled: {false};
+}
+
+#accidentalTab {
+ enabled: {false};
+}
+
#observationIndividuelTab {
enabled: {false};
}
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-01-31 08:45:23 UTC (rev 275)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUI.jaxx 2013-01-31 08:47:56 UTC (rev 276)
@@ -31,7 +31,9 @@
fr.ifremer.tutti.ui.swing.content.operation.catches.macrowaste.MacroWasteBatchUI
fr.ifremer.tutti.ui.swing.content.operation.catches.plankton.PlanktonBatchUI
fr.ifremer.tutti.ui.swing.content.operation.catches.species.SpeciesBatchUI
+ fr.ifremer.tutti.ui.swing.content.operation.catches.species.frequency.SpeciesFrequencyUI
fr.ifremer.tutti.ui.swing.content.operation.catches.species.split.CreateSpeciesBatchUI
+ fr.ifremer.tutti.ui.swing.content.operation.catches.species.split.SplitSpeciesBatchUI
fr.ifremer.tutti.ui.swing.content.operation.catches.EditCatchesUI
org.jdesktop.swingx.JXTitledPanel
@@ -294,12 +296,18 @@
</tab>
<tab id='speciesTab' title='tutti.label.tab.species'>
<JPanel id='speciesTabPanel'>
- <JXTitledPanel id='speciesTabFishingOperationReminderLabel' constraints='"main"'>
+ <JXTitledPanel id='speciesTabFishingOperationReminderLabel' constraints='EditCatchesUIHandler.MAIN_CARD'>
<SpeciesBatchUI id='speciesTabContent' constructorParams='this'/>
</JXTitledPanel>
- <JXTitledPanel id='speciesTabCreateBatchReminderLabel' constraints='"createBatch"'>
+ <JXTitledPanel id='speciesTabCreateBatchReminderLabel' constraints='EditCatchesUIHandler.CREATE_BATCH_CARD'>
<CreateSpeciesBatchUI id='speciesTabCreateBatch' constructorParams='this'/>
</JXTitledPanel>
+ <JXTitledPanel id='speciesTabSplitBatchReminderLabel' constraints='EditCatchesUIHandler.SPLIT_BATCH_CARD'>
+ <SplitSpeciesBatchUI id='speciesTabSplitBatch' constructorParams='this'/>
+ </JXTitledPanel>
+ <JXTitledPanel id='speciesTabFrequencyEditorLabel' constraints='EditCatchesUIHandler.EDIT_FREQUENCY_CARD'>
+ <SpeciesFrequencyUI id='speciesTabFrequencyEditor' constructorParams='speciesTabContent'/>
+ </JXTitledPanel>
</JPanel>
</tab>
<tab id='benthosTab' title='tutti.label.tab.benthos'>
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-01-31 08:45:23 UTC (rev 275)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUIHandler.java 2013-01-31 08:47:56 UTC (rev 276)
@@ -28,11 +28,19 @@
import fr.ifremer.tutti.persistence.entities.data.FishingOperation;
import fr.ifremer.tutti.service.PersistenceService;
import fr.ifremer.tutti.ui.swing.AbstractTuttiBeanUIModel;
+import fr.ifremer.tutti.ui.swing.MainUI;
+import fr.ifremer.tutti.ui.swing.TuttiUI;
import fr.ifremer.tutti.ui.swing.content.operation.FishingOperationsUI;
import fr.ifremer.tutti.ui.swing.util.AbstractTuttiTabContainerUIHandler;
import fr.ifremer.tutti.ui.swing.util.TabHandler;
import fr.ifremer.tutti.ui.swing.util.TuttiBeanMonitor;
+import java.awt.Component;
+import java.awt.Container;
+import java.awt.LayoutManager;
+import javax.swing.JPanel;
import javax.swing.JTabbedPane;
+import jaxx.runtime.swing.CardLayout2Ext;
+import jaxx.runtime.validator.swing.SwingValidator;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -43,6 +51,14 @@
public class EditCatchesUIHandler extends AbstractTuttiTabContainerUIHandler<EditCatchesUIModel>
implements TabHandler {
+ public static final String MAIN_CARD = "main";
+
+ public static final String CREATE_BATCH_CARD = "createBatch";
+
+ public static final String SPLIT_BATCH_CARD = "splitBatch";
+
+ public static final String EDIT_FREQUENCY_CARD = "editFrequency";
+
/** Logger. */
private static final Log log =
LogFactory.getLog(EditCatchesUIHandler.class);
@@ -131,6 +147,11 @@
}
@Override
+ public SwingValidator<EditCatchesUIModel> getValidator() {
+ return ui.getValidator();
+ }
+
+ @Override
protected JTabbedPane getTabPanel() {
return ui.getTabPane();
}
@@ -147,7 +168,7 @@
@Override
public void onShowTab() {
-
+ registerValidators();
}
//------------------------------------------------------------------------//
@@ -240,8 +261,51 @@
persistenceService.saveCatchBatch(catchBatch);
}
+ protected void registerValidators() {
+ MainUI main = ui.getContextValue(MainUI.class, MainUI.class.getName());
+ main.clearValidators();
+ main.registerValidator(getValidator());
+ main.registerValidator(ui.getSpeciesTabContent().getHandler().getValidator());
+ }
+
public void importPupitri() {
//TODO
}
+
+ public void setSelectedCard(String card) {
+ Component selectedComponent = getTabPanel().getSelectedComponent();
+ if (selectedComponent.getClass().isAssignableFrom(JPanel.class)) {
+ JPanel panel = (JPanel) selectedComponent;
+ LayoutManager layoutManager = panel.getLayout();
+ if (layoutManager.getClass().isAssignableFrom(CardLayout2Ext.class)) {
+ CardLayout2Ext layout = (CardLayout2Ext) layoutManager;
+ layout.setSelected(card);
+
+ if (MAIN_CARD.equals(card)) {
+ registerValidators();
+
+ } else {
+ Container cardContainer = (Container)layout.getComponent(panel, card);
+ TuttiUI tuttiUi = null;
+ if (TuttiUI.class.isInstance(cardContainer)) {
+ tuttiUi = (TuttiUI) cardContainer;
+
+ } else {
+ for (Component comp : cardContainer.getComponents()) {
+ if (TuttiUI.class.isInstance(comp)) {
+ tuttiUi = (TuttiUI) comp;
+ }
+ }
+ }
+ if (tuttiUi != null) {
+ MainUI main = ui.getContextValue(MainUI.class, MainUI.class.getName());
+ main.clearValidators();
+ main.registerValidator(tuttiUi.getHandler().getValidator());
+ }
+ }
+ }
+ }
+
+ }
}
\ No newline at end of file
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-01-31 08:45:23 UTC (rev 275)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUIModel.java 2013-01-31 08:47:56 UTC (rev 276)
@@ -57,6 +57,10 @@
public static final String PROPERTY_SPECIES_TOTAL_SAMPLE_SORTED_WEIGHT = "speciesTotalSampleSortedWeight";
public static final String PROPERTY_SPECIES_TOTAL_UNSORTED_WEIGHT = "speciesTotalUnsortedWeight";
+
+ public static final String PROPERTY_SPECIES_TOTAL_INERT_WEIGHT = "speciesTotalInertWeight";
+
+ public static final String PROPERTY_SPECIES_TOTAL_LIVING_NOT_ITEMIZED_WEIGHT = "speciesTotalLivingNotItemizedWeight";
public static final String PROPERTY_BENTHOS_TOTAL_WEIGHT = "benthosTotalWeight";
@@ -82,6 +86,8 @@
PROPERTY_SPECIES_TOTAL_SORTED_WEIGHT,
PROPERTY_SPECIES_TOTAL_UNSORTED_WEIGHT,
PROPERTY_SPECIES_TOTAL_SAMPLE_SORTED_WEIGHT,
+ PROPERTY_SPECIES_TOTAL_INERT_WEIGHT,
+ PROPERTY_SPECIES_TOTAL_LIVING_NOT_ITEMIZED_WEIGHT,
PROPERTY_BENTHOS_TOTAL_WEIGHT,
PROPERTY_BENTHOS_TOTAL_SORTED_WEIGHT,
PROPERTY_BENTHOS_TOTAL_UNSORTED_WEIGHT,
@@ -97,6 +103,8 @@
PROPERTY_SPECIES_TOTAL_SORTED_WEIGHT,
PROPERTY_SPECIES_TOTAL_UNSORTED_WEIGHT,
PROPERTY_SPECIES_TOTAL_SAMPLE_SORTED_WEIGHT,
+ PROPERTY_SPECIES_TOTAL_INERT_WEIGHT,
+ PROPERTY_SPECIES_TOTAL_LIVING_NOT_ITEMIZED_WEIGHT,
PROPERTY_BENTHOS_TOTAL_WEIGHT,
PROPERTY_BENTHOS_TOTAL_SORTED_WEIGHT,
PROPERTY_BENTHOS_TOTAL_UNSORTED_WEIGHT,
@@ -114,6 +122,10 @@
protected Float speciesTotalUnsortedWeight;
+ protected Float speciesTotalInertWeight;
+
+ protected Float speciesTotalLivingNotItemizedWeight;
+
protected Float benthosTotalWeight;
protected Float benthosTotalSortedWeight;
@@ -260,7 +272,27 @@
this.speciesTotalUnsortedWeight = speciesTotalUnsortedWeight;
firePropertyChange(PROPERTY_SPECIES_TOTAL_UNSORTED_WEIGHT, oldValue, speciesTotalUnsortedWeight);
}
+
+ public Float getSpeciesTotalInertWeight() {
+ return speciesTotalInertWeight;
+ }
+ public void setSpeciesTotalInertWeight(Float speciesTotalInertWeight) {
+ Object oldValue = getSpeciesTotalInertWeight();
+ this.speciesTotalInertWeight = speciesTotalInertWeight;
+ firePropertyChange(PROPERTY_SPECIES_TOTAL_INERT_WEIGHT, oldValue, speciesTotalInertWeight);
+ }
+
+ public Float getSpeciesTotalLivingNotItemizedWeight() {
+ return speciesTotalLivingNotItemizedWeight;
+ }
+
+ public void setSpeciesTotalLivingNotItemizedWeight(Float speciesTotalLivingNotItemizedWeight) {
+ Object oldValue = getSpeciesTotalLivingNotItemizedWeight();
+ this.speciesTotalLivingNotItemizedWeight = speciesTotalLivingNotItemizedWeight;
+ firePropertyChange(PROPERTY_SPECIES_TOTAL_LIVING_NOT_ITEMIZED_WEIGHT, oldValue, speciesTotalLivingNotItemizedWeight);
+ }
+
public Float getBenthosTotalWeight() {
return benthosTotalWeight;
}
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/accidental/AccidentalBatchUIHandler.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/accidental/AccidentalBatchUIHandler.java 2013-01-31 08:45:23 UTC (rev 275)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/accidental/AccidentalBatchUIHandler.java 2013-01-31 08:47:56 UTC (rev 276)
@@ -44,6 +44,7 @@
import org.nuiton.util.decorator.Decorator;
import java.util.List;
+import jaxx.runtime.validator.swing.SwingValidator;
import static org.nuiton.i18n.I18n.n_;
@@ -181,6 +182,11 @@
}
@Override
+ public SwingValidator<AccidentalBatchUIModel> getValidator() {
+ return null;
+ }
+
+ @Override
public void beforeInitUI() {
if (log.isInfoEnabled()) {
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-01-31 08:45:23 UTC (rev 275)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUIHandler.java 2013-01-31 08:47:56 UTC (rev 276)
@@ -44,6 +44,7 @@
import org.nuiton.util.decorator.Decorator;
import java.util.List;
+import jaxx.runtime.validator.swing.SwingValidator;
import static org.nuiton.i18n.I18n.n_;
@@ -184,6 +185,11 @@
}
@Override
+ public SwingValidator<BenthosBatchUIModel> getValidator() {
+ return ui.getValidator();
+ }
+
+ @Override
public void beforeInitUI() {
if (log.isInfoEnabled()) {
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/macrowaste/MacroWasteBatchUIHandler.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/macrowaste/MacroWasteBatchUIHandler.java 2013-01-31 08:45:23 UTC (rev 275)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/macrowaste/MacroWasteBatchUIHandler.java 2013-01-31 08:47:56 UTC (rev 276)
@@ -43,6 +43,7 @@
import org.nuiton.util.decorator.Decorator;
import java.util.List;
+import jaxx.runtime.validator.swing.SwingValidator;
import static org.nuiton.i18n.I18n.n_;
@@ -186,6 +187,11 @@
}
@Override
+ public SwingValidator<MacroWasteBatchUIModel> getValidator() {
+ return ui.getValidator();
+ }
+
+ @Override
public void beforeInitUI() {
if (log.isInfoEnabled()) {
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/plankton/PlanktonBatchUIHandler.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/plankton/PlanktonBatchUIHandler.java 2013-01-31 08:45:23 UTC (rev 275)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/plankton/PlanktonBatchUIHandler.java 2013-01-31 08:47:56 UTC (rev 276)
@@ -44,6 +44,7 @@
import org.nuiton.util.decorator.Decorator;
import java.util.List;
+import jaxx.runtime.validator.swing.SwingValidator;
import static org.nuiton.i18n.I18n.n_;
@@ -182,6 +183,11 @@
}
@Override
+ public SwingValidator<PlanktonBatchUIModel> getValidator() {
+ return ui.getValidator();
+ }
+
+ @Override
public void beforeInitUI() {
if (log.isInfoEnabled()) {
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUI.css
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUI.css 2013-01-31 08:45:23 UTC (rev 275)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUI.css 2013-01-31 08:47:56 UTC (rev 276)
@@ -37,7 +37,6 @@
#speciesTotalWeightField {
property: speciesTotalWeight;
model: {model.getSpeciesTotalWeight()};
- useFloat: false;
numberPattern: {INT_6_DIGITS_PATTERN};
}
@@ -49,7 +48,6 @@
#speciesTotalSortedWeightField {
property: speciesTotalSortedWeight;
model: {model.getSpeciesTotalSortedWeight()};
- useFloat: false;
numberPattern: {INT_6_DIGITS_PATTERN};
}
@@ -61,7 +59,6 @@
#speciesTotalSampleSortedWeightField {
property: speciesTotalSampleSortedWeight;
model: {model.getSpeciesTotalSampleSortedWeight()};
- useFloat: false;
numberPattern: {INT_6_DIGITS_PATTERN};
}
@@ -76,6 +73,29 @@
enabled: false;
}
+#speciesTotalInertWeightLabel {
+ text: "tutti.label.catches.speciesTotalInertWeight";
+ labelFor: {speciesTotalInertWeightField};
+}
+
+#speciesTotalInertWeightField {
+ property: speciesTotalInertWeight;
+ model: {model.getSpeciesTotalInertWeight()};
+ numberPattern: {INT_6_DIGITS_PATTERN};
+}
+
+#speciesTotalLivingNotItemizedWeightLabel {
+ text: "tutti.label.catches.speciesTotalLivingNotItemizedWeight";
+ labelFor: {speciesTotalLivingNotItemizedWeightField};
+}
+
+#speciesTotalLivingNotItemizedWeightField {
+ property: speciesTotalLivingNotItemizedWeight;
+ model: {model.getSpeciesTotalLivingNotItemizedWeight()};
+ numberPattern: {INT_6_DIGITS_PATTERN};
+}
+
+
#tablePopup {
label: "tutti.title.batchActions";
}
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUI.jaxx
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUI.jaxx 2013-01-31 08:45:23 UTC (rev 275)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUI.jaxx 2013-01-31 08:47:56 UTC (rev 276)
@@ -124,6 +124,24 @@
<JTextField id='speciesTotalUnsortedWeightField'/>
</cell>
</row>
+
+ <!-- Poids inerte / Poids vivant non détaillé -->
+ <row>
+ <cell>
+ <JLabel id='speciesTotalInertWeightLabel'/>
+ </cell>
+ <cell>
+ <NumberEditor id='speciesTotalInertWeightField'
+ constructorParams='this'/>
+ </cell>
+ <cell>
+ <JLabel id='speciesTotalLivingNotItemizedWeightLabel'/>
+ </cell>
+ <cell>
+ <NumberEditor id='speciesTotalLivingNotItemizedWeightField'
+ constructorParams='this'/>
+ </cell>
+ </row>
<!-- Toolbar / Filter -->
<row>
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-01-31 08:45:23 UTC (rev 275)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUIHandler.java 2013-01-31 08:47:56 UTC (rev 276)
@@ -44,10 +44,10 @@
import fr.ifremer.tutti.ui.swing.TuttiUI;
import fr.ifremer.tutti.ui.swing.content.operation.AbstractTuttiBatchTableUIHandler;
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.EditCatchesUIModel;
import fr.ifremer.tutti.ui.swing.content.operation.catches.species.frequency.FrequencyCellComponent;
import fr.ifremer.tutti.ui.swing.content.operation.catches.species.frequency.SpeciesFrequencyRowModel;
-import fr.ifremer.tutti.ui.swing.content.operation.catches.species.frequency.SpeciesFrequencyUI;
import fr.ifremer.tutti.ui.swing.content.operation.catches.species.split.CreateSpeciesBatchUI;
import fr.ifremer.tutti.ui.swing.content.operation.catches.species.split.CreateSpeciesBatchUIModel;
import fr.ifremer.tutti.ui.swing.content.operation.catches.species.split.SplitSpeciesBatchRowModel;
@@ -79,9 +79,8 @@
import java.util.List;
import java.util.Set;
import jaxx.runtime.SwingUtil;
-import jaxx.runtime.swing.CardLayout2Ext;
+import jaxx.runtime.validator.swing.SwingValidator;
-import static org.nuiton.i18n.I18n._;
import static org.nuiton.i18n.I18n.n_;
/**
@@ -118,12 +117,6 @@
*/
private final SpeciesBatchUI ui;
- private SplitSpeciesBatchUI splitSpeciesBatchEditor;
-
- private CreateSpeciesBatchUI createSpeciesBatchEditor;
-
- private SpeciesFrequencyUI speciesFrequencyEditor;
-
private final EnumMap<TableViewMode, RowFilter<SpeciesBatchTableModel, Integer>> tableFilters;
public SpeciesBatchUIHandler(TuttiUI<?, ?> parentUi,
@@ -381,6 +374,11 @@
}
@Override
+ public SwingValidator<SpeciesBatchUIModel> getValidator() {
+ return ui.getValidator();
+ }
+
+ @Override
public void beforeInitUI() {
if (log.isInfoEnabled()) {
@@ -625,27 +623,11 @@
}
-
@Override
public void onCloseUI() {
if (log.isInfoEnabled()) {
log.info("Closing: " + ui);
}
-
- if (splitSpeciesBatchEditor != null) {
- getContext().getSwingSession().add(splitSpeciesBatchEditor);
- closeUI(splitSpeciesBatchEditor);
- }
-
- if (createSpeciesBatchEditor != null) {
- getContext().getSwingSession().add(createSpeciesBatchEditor);
- closeUI(createSpeciesBatchEditor);
- }
-
- if (speciesFrequencyEditor != null) {
- getContext().getSwingSession().add(speciesFrequencyEditor);
- closeUI(speciesFrequencyEditor);
- }
}
//------------------------------------------------------------------------//
@@ -658,9 +640,7 @@
CreateSpeciesBatchUI createBatchEditor = parent.getSpeciesTabCreateBatch();
createBatchEditor.getHandler().openUI(getModel());
-
- CardLayout2Ext card = (CardLayout2Ext) parent.getSpeciesTabPanel().getLayout();
- card.setSelected("createBatch");
+ parent.getHandler().setSelectedCard(EditCatchesUIHandler.CREATE_BATCH_CARD);
}
public void addSpeciesBatch(CreateSpeciesBatchUIModel createModel) {
@@ -708,23 +688,27 @@
if (log.isInfoEnabled()) {
log.info("Open split batch ui for row [" + rowIndex + ']');
}
- SplitSpeciesBatchUI splitBatchEditor = getSplitSpeciesBatchEditor();
+
+ EditCatchesUI parent = SwingUtil.getParentContainer(ui, EditCatchesUI.class);
+ SplitSpeciesBatchUI splitBatchEditor = parent.getSpeciesTabSplitBatch();
+
splitBatchEditor.getHandler().editBatch(parentBatch);
+ parent.getHandler().setSelectedCard(EditCatchesUIHandler.SPLIT_BATCH_CARD);
+ }
- openDialog(ui,
- splitBatchEditor,
- _("tutti.title.splitBatch"),
- ui.getPreferredSize());
+ public void splitBatch(SplitSpeciesBatchUIModel splitModel) {
+ if (splitModel.isValid()) {
- // at close, synch back batches ?
- SplitSpeciesBatchUIModel splitModel = splitBatchEditor.getModel();
+ JXTable table = getTable();
- if (splitModel.isValid()) {
+ // get selected row
+ int insertRow = table.getSelectedRow();
+
+ SpeciesBatchTableModel tableModel = getTableModel();
+ SpeciesBatchRowModel parentBatch = tableModel.getEntry(insertRow);
// create batch rows
- int insertRow = rowIndex;
-
SampleCategoryType selectedCategory = splitModel.getSelectedCategory();
SampleCategoryEnum sampleCategoryEnum = selectedCategory.getType();
@@ -760,9 +744,6 @@
saveRows(newBatches);
}
- // reset split ui
- splitBatchEditor.getHandler().editBatch(null);
-
recomputeBatchActionEnable();
// // reselect this cell
@@ -898,27 +879,6 @@
}
- public SplitSpeciesBatchUI getSplitSpeciesBatchEditor() {
- if (splitSpeciesBatchEditor == null) {
- splitSpeciesBatchEditor = new SplitSpeciesBatchUI(ui);
- }
- return splitSpeciesBatchEditor;
- }
-
- public CreateSpeciesBatchUI getCreateSpeciesBatchEditor() {
- if (createSpeciesBatchEditor == null) {
- createSpeciesBatchEditor = new CreateSpeciesBatchUI(ui);
- }
- return createSpeciesBatchEditor;
- }
-
- public SpeciesFrequencyUI getSpeciesFrequencyEditor() {
- if (speciesFrequencyEditor == null) {
- speciesFrequencyEditor = new SpeciesFrequencyUI(ui);
- }
- return speciesFrequencyEditor;
- }
-
public void updateTotalFromFrequencies(SpeciesBatchRowModel row) {
Float totalNumber = null;
Float totalWeight = null;
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-01-31 08:45:23 UTC (rev 275)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUIModel.java 2013-01-31 08:47:56 UTC (rev 276)
@@ -121,7 +121,9 @@
EditCatchesUIModel.PROPERTY_SPECIES_TOTAL_WEIGHT,
EditCatchesUIModel.PROPERTY_SPECIES_TOTAL_SORTED_WEIGHT,
EditCatchesUIModel.PROPERTY_SPECIES_TOTAL_UNSORTED_WEIGHT,
- EditCatchesUIModel.PROPERTY_SPECIES_TOTAL_SAMPLE_SORTED_WEIGHT);
+ EditCatchesUIModel.PROPERTY_SPECIES_TOTAL_SAMPLE_SORTED_WEIGHT,
+ EditCatchesUIModel.PROPERTY_SPECIES_TOTAL_INERT_WEIGHT,
+ EditCatchesUIModel.PROPERTY_SPECIES_TOTAL_LIVING_NOT_ITEMIZED_WEIGHT);
}
public Float getSpeciesTotalWeight() {
@@ -156,6 +158,22 @@
catchesUIModel.setSpeciesTotalUnsortedWeight(speciesTotalUnsortedWeight);
}
+ public Float getSpeciesTotalInertWeight() {
+ return catchesUIModel.getSpeciesTotalInertWeight();
+ }
+
+ public void setSpeciesTotalInertWeight(Float speciesTotalInertWeight) {
+ catchesUIModel.setSpeciesTotalInertWeight(speciesTotalInertWeight);
+ }
+
+ public Float getSpeciesTotalLivingNotItemizedWeight() {
+ return catchesUIModel.getSpeciesTotalLivingNotItemizedWeight();
+ }
+
+ public void setSpeciesTotalLivingNotItemizedWeight(Float speciesTotalLivingNotItemizedWeight) {
+ catchesUIModel.setSpeciesTotalLivingNotItemizedWeight(speciesTotalLivingNotItemizedWeight);
+ }
+
public List<SampleCategoryType> getSamplingOrder() {
return samplingOrder;
}
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/FrequencyCellComponent.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/FrequencyCellComponent.java 2013-01-31 08:45:23 UTC (rev 275)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/FrequencyCellComponent.java 2013-01-31 08:47:56 UTC (rev 276)
@@ -26,10 +26,13 @@
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
+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.species.SpeciesBatchRowModel;
import fr.ifremer.tutti.ui.swing.content.operation.catches.species.SpeciesBatchTableModel;
import fr.ifremer.tutti.ui.swing.content.operation.catches.species.SpeciesBatchUI;
import fr.ifremer.tutti.ui.swing.content.operation.catches.species.SpeciesBatchUIHandler;
+import fr.ifremer.tutti.ui.swing.content.operation.catches.species.split.CreateSpeciesBatchUI;
import fr.ifremer.tutti.ui.swing.util.table.AbstractSelectTableAction;
import fr.ifremer.tutti.ui.swing.util.table.ColumnIdentifier;
import jaxx.runtime.SwingUtil;
@@ -49,6 +52,7 @@
import java.awt.event.MouseEvent;
import java.util.List;
import javax.swing.table.DefaultTableCellRenderer;
+import jaxx.runtime.swing.CardLayout2Ext;
import static org.nuiton.i18n.I18n._;
@@ -137,19 +141,16 @@
log.info("Will edit frequencies for row: " + rowIndex);
}
- SpeciesBatchUIHandler handler = ui.getHandler();
- SpeciesFrequencyUI frequencyEditor =
- handler.getSpeciesFrequencyEditor();
- frequencyEditor.editBatch(editRow);
+ EditCatchesUI parent = SwingUtil.getParentContainer(ui, EditCatchesUI.class);
+ SpeciesFrequencyUI frequencyEditor = parent.getSpeciesTabFrequencyEditor();
- // open frequency dialog
- handler.openDialog(ui,
- frequencyEditor,
- _("tutti.title.frequency"),
- ui.getPreferredSize());
+ frequencyEditor.getHandler().editBatch(editRow, this);
- SpeciesFrequencyUIModel frequencyModel = frequencyEditor.getModel();
-
+ // open frequency editor
+ parent.getHandler().setSelectedCard(EditCatchesUIHandler.EDIT_FREQUENCY_CARD);
+ }
+
+ public void validateEdition(SpeciesFrequencyUIModel frequencyModel) {
if (frequencyModel.isValid()) {
// at close, synch back frequencies
@@ -173,11 +174,9 @@
editRow.setFrequency(frequency);
// update frequencies total
- handler.updateTotalFromFrequencies(editRow);
+ ui.getHandler().updateTotalFromFrequencies(editRow);
}
- frequencyEditor.editBatch(null);
-
int r = rowIndex;
int c = columnIndex;
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-01-31 08:45:23 UTC (rev 275)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUI.jaxx 2013-01-31 08:47:56 UTC (rev 276)
@@ -26,10 +26,11 @@
<import>
fr.ifremer.tutti.persistence.entities.referential.Caracteristic
-
+
+ fr.ifremer.tutti.ui.swing.TuttiUI
fr.ifremer.tutti.ui.swing.TuttiUIContext
+ fr.ifremer.tutti.ui.swing.content.operation.catches.EditCatchesUI
fr.ifremer.tutti.ui.swing.content.operation.catches.species.SpeciesBatchRowModel
- fr.ifremer.tutti.ui.swing.content.operation.catches.species.SpeciesBatchUI
jaxx.runtime.swing.CardLayout2Ext
jaxx.runtime.swing.editor.bean.BeanComboBox
@@ -52,17 +53,13 @@
<script><![CDATA[
- public SpeciesFrequencyUI(SpeciesBatchUI parentUI) {
+ public SpeciesFrequencyUI(TuttiUI parentUI) {
JAXXUtil.initContext(this, parentUI);
SpeciesFrequencyUIHandler handler = new SpeciesFrequencyUIHandler(parentUI.getHandler().getContext(), this);
setContextValue(handler);
handler.beforeInitUI();
}
- public void editBatch(SpeciesBatchRowModel row) {
- handler.editBatch(row);
- }
-
protected void $afterCompleteSetup() {
handler.afterInitUI();
}
@@ -85,124 +82,112 @@
<CardLayout2Ext id='modeConfigurationLayout'
constructorParams='this, "modeConfigurationPanel"'/>
- <JSplitPane id='splitPane' constraints='BorderLayout.CENTER'>
+ <JPanel id='configurationPanel' layout='{new BorderLayout()}'
+ constraints='BorderLayout.NORTH'>
- <JPanel layout='{new BorderLayout()}'>
+ <JPanel layout='{new BorderLayout()}' constraints='BorderLayout.CENTER'>
+ <VBox id='modePanel' constraints='BorderLayout.WEST'
+ verticalAlignment='{SwingConstants.CENTER}'>
+ <JRadioButton id='simpleModeButton'
+ onActionPerformed='model.setConfigurationMode(SpeciesFrequencyUIModel.ConfigurationMode.SIMPLE)'/>
+ <JRadioButton id='autoGenModeButton'
+ onActionPerformed='model.setConfigurationMode(SpeciesFrequencyUIModel.ConfigurationMode.AUTO_GEN)'/>
+ <JRadioButton id='rafaleModeButton'
+ onActionPerformed='model.setConfigurationMode(SpeciesFrequencyUIModel.ConfigurationMode.RAFALE)'/>
+ </VBox>
- <JPanel id='configurationPanel' layout='{new BorderLayout()}'
- constraints='BorderLayout.NORTH'>
-
- <JPanel layout='{new BorderLayout()}' constraints='BorderLayout.CENTER'>
- <VBox id='modePanel' constraints='BorderLayout.WEST'
- verticalAlignment='{SwingConstants.CENTER}'>
- <JRadioButton id='simpleModeButton'
- onActionPerformed='model.setConfigurationMode(SpeciesFrequencyUIModel.ConfigurationMode.SIMPLE)'/>
- <JRadioButton id='autoGenModeButton'
- onActionPerformed='model.setConfigurationMode(SpeciesFrequencyUIModel.ConfigurationMode.AUTO_GEN)'/>
- <JRadioButton id='rafaleModeButton'
- onActionPerformed='model.setConfigurationMode(SpeciesFrequencyUIModel.ConfigurationMode.RAFALE)'/>
- </VBox>
-
- <JPanel id='modeConfigurationPanel' constraints='BorderLayout.CENTER'>
- <JPanel id='simpleModePanel' constraints='"simpleMode"'
- layout='{new BorderLayout()}'>
- <JLabel id='simpleModeLabel' constraints='BorderLayout.CENTER'/>
- </JPanel>
- <JPanel id='autoGenModePanel' constraints='"autoGenMode"'>
- <Table fill='both' constraints='BorderLayout.SOUTH'>
- <!-- Min step-->
- <row>
- <cell anchor='west'>
- <JLabel id='minStepLabel'/>
- </cell>
- <cell weightx='1.0'>
- <NumberEditor id='minStepField' constructorParams='this'/>
- </cell>
- </row>
- <!-- Max step-->
- <row>
- <cell anchor='west'>
- <JLabel id='maxStepLabel'/>
- </cell>
- <cell weightx='1.0'>
- <NumberEditor id='maxStepField' constructorParams='this'/>
- </cell>
- </row>
- <!-- Actions -->
- <row>
- <cell columns='2'>
- <JPanel layout='{new GridLayout(1, 0)}'>
- <JButton id='generateButton'
- onActionPerformed='handler.generateLengthSteps()'/>
- </JPanel>
- </cell>
- </row>
- </Table>
- </JPanel>
- <JPanel id='rafaleModePanel' constraints='"rafaleMode"'>
- <Table fill='both' constraints='BorderLayout.SOUTH'>
- <!-- Rafale step-->
- <row>
- <cell weightx='1.0'>
- <JLabel id='rafaleStepLabel'/>
- </cell>
- </row>
- <row>
- <cell weightx='1.0'>
- <NumberEditor id='rafaleStepField'
- constructorParams='this'/>
- </cell>
- </row>
- </Table>
- </JPanel>
- </JPanel>
+ <JPanel id='modeConfigurationPanel' constraints='BorderLayout.CENTER'>
+ <JPanel id='simpleModePanel' constraints='"simpleMode"'
+ layout='{new BorderLayout()}'>
+ <JLabel id='simpleModeLabel' constraints='BorderLayout.CENTER'/>
</JPanel>
- <Table fill='both' constraints='BorderLayout.SOUTH'>
- <row>
- <cell columns='2'>
- <JSeparator/>
- </cell>
- </row>
- <!-- length step caracteristic -->
- <row>
- <cell anchor='west'>
- <JLabel id='lengthStepCaracteristicLabel'/>
- </cell>
- <cell weightx='1.0'>
- <BeanComboBox id='lengthStepCaracteristicComboBox'
- constructorParams='this'
- genericType='Caracteristic'/>
- </cell>
- </row>
- <!-- Step -->
- <row>
- <cell anchor='west'>
- <JLabel id='stepLabel'/>
- </cell>
- <cell weightx='1.0'>
- <NumberEditor id='stepField' constructorParams='this'/>
- </cell>
- </row>
- </Table>
+ <JPanel id='autoGenModePanel' constraints='"autoGenMode"'>
+ <Table fill='both' constraints='BorderLayout.SOUTH'>
+ <!-- Min step-->
+ <row>
+ <cell anchor='west'>
+ <JLabel id='minStepLabel'/>
+ </cell>
+ <cell weightx='1.0'>
+ <NumberEditor id='minStepField' constructorParams='this'/>
+ </cell>
+ </row>
+ <!-- Max step-->
+ <row>
+ <cell anchor='west'>
+ <JLabel id='maxStepLabel'/>
+ </cell>
+ <cell weightx='1.0'>
+ <NumberEditor id='maxStepField' constructorParams='this'/>
+ </cell>
+ </row>
+ <!-- Actions -->
+ <row>
+ <cell columns='2'>
+ <JPanel layout='{new GridLayout(1, 0)}'>
+ <JButton id='generateButton'
+ onActionPerformed='handler.generateLengthSteps()'/>
+ </JPanel>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ <JPanel id='rafaleModePanel' constraints='"rafaleMode"'>
+ <Table fill='both' constraints='BorderLayout.SOUTH'>
+ <!-- Rafale step-->
+ <row>
+ <cell weightx='1.0'>
+ <JLabel id='rafaleStepLabel'/>
+ </cell>
+ </row>
+ <row>
+ <cell weightx='1.0'>
+ <NumberEditor id='rafaleStepField'
+ constructorParams='this'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
</JPanel>
+ </JPanel>
+ <Table fill='both' constraints='BorderLayout.SOUTH'>
+ <row>
+ <cell columns='2'>
+ <JSeparator/>
+ </cell>
+ </row>
+ <!-- length step caracteristic -->
+ <row>
+ <cell anchor='west'>
+ <JLabel id='lengthStepCaracteristicLabel'/>
+ </cell>
+ <cell weightx='1.0'>
+ <BeanComboBox id='lengthStepCaracteristicComboBox'
+ constructorParams='this'
+ genericType='Caracteristic'/>
+ </cell>
+ </row>
+ <!-- Step -->
+ <row>
+ <cell anchor='west'>
+ <JLabel id='stepLabel'/>
+ </cell>
+ <cell weightx='1.0'>
+ <NumberEditor id='stepField' constructorParams='this'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
- <JScrollPane id='tableScrollPane' constraints='BorderLayout.CENTER'>
- <JXTable id='table'/>
- </JScrollPane>
+ <JScrollPane id='tableScrollPane' constraints='BorderLayout.CENTER'>
+ <JXTable id='table'/>
+ </JScrollPane>
- <!-- actions -->
- <JPanel id='actionPanel' layout='{new GridLayout(1, 0)}'
- constraints='BorderLayout.SOUTH'>
- <JButton id='cancelButton' onActionPerformed='handler.cancel()'/>
- <JButton id='saveButton' onActionPerformed='handler.save()'/>
- </JPanel>
+ <!-- actions -->
+ <JPanel id='actionPanel' layout='{new GridLayout(1, 0)}'
+ constraints='BorderLayout.SOUTH'>
+ <JButton id='cancelButton' onActionPerformed='handler.cancel()'/>
+ <JButton id='saveButton' onActionPerformed='handler.save()'/>
+ </JPanel>
- </JPanel>
- <!-- Messages report -->
- <JPanel id='messagePanel' layout='{new GridLayout()}'>
- <JScrollPane columnHeaderView='{errorTable.getTableHeader()}'>
- <JTable id='errorTable'/>
- </JScrollPane>
- </JPanel>
- </JSplitPane>
</JPanel>
\ No newline at end of file
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-01-31 08:45:23 UTC (rev 275)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUIHandler.java 2013-01-31 08:47:56 UTC (rev 276)
@@ -34,8 +34,11 @@
import fr.ifremer.tutti.persistence.entities.referential.Species;
import fr.ifremer.tutti.ui.swing.TuttiUI;
import fr.ifremer.tutti.ui.swing.TuttiUIContext;
+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.species.SpeciesBatchRowModel;
import fr.ifremer.tutti.ui.swing.content.operation.catches.species.SpeciesBatchUIHandler;
+import fr.ifremer.tutti.ui.swing.content.operation.catches.species.frequency.FrequencyCellComponent.FrequencyCellEditor;
import fr.ifremer.tutti.ui.swing.util.Cancelable;
import fr.ifremer.tutti.ui.swing.util.TuttiBeanMonitor;
import fr.ifremer.tutti.ui.swing.util.TuttiUIUtil;
@@ -55,6 +58,9 @@
import java.util.Collections;
import java.util.List;
import java.util.Map;
+import jaxx.runtime.SwingUtil;
+import jaxx.runtime.swing.CardLayout2Ext;
+import jaxx.runtime.validator.swing.SwingValidator;
/**
* @author tchemit <chemit(a)codelutin.com>
@@ -72,12 +78,14 @@
* @since 0.2
*/
private final SpeciesFrequencyUI ui;
+
+ private FrequencyCellEditor frequencyEditor;
private TuttiProtocol protocol;
private Map<String, SpeciesProtocol> speciesProtocol;
- private Map<String, Caracteristic> lengthSteCaracteristic;
+ private Map<String, Caracteristic> lengthStepCaracteristics;
public SpeciesFrequencyUIHandler(TuttiUIContext context,
SpeciesFrequencyUI ui) {
@@ -150,6 +158,11 @@
}
@Override
+ public SwingValidator<SpeciesFrequencyUIModel> getValidator() {
+ return ui.getValidator();
+ }
+
+ @Override
public void beforeInitUI() {
SpeciesFrequencyUIModel model = new SpeciesFrequencyUIModel();
@@ -166,7 +179,7 @@
SpeciesBatchUIHandler.FREQUENCY_LENGTH_CONTEXT_ENTRY.getContextValue(ui);
Preconditions.checkNotNull(lengthStepCaracterics);
- lengthSteCaracteristic = TuttiEntities.splitById(lengthStepCaracterics);
+ lengthStepCaracteristics = TuttiEntities.splitById(lengthStepCaracterics);
SpeciesFrequencyUIModel model = getModel();
@@ -270,9 +283,6 @@
initTable(table);
- SwingValidatorUtil.installUI(ui.getErrorTable(),
- new SwingValidatorMessageTableRenderer());
-
listenValidatorValid(ui.getValidator(), model);
}
@@ -281,6 +291,17 @@
if (log.isInfoEnabled()) {
log.info("closing: " + ui);
}
+
+ frequencyEditor = null;
+
+ // evict model from validator
+ ui.getValidator().setBean(null);
+
+ // when canceling always invalid model (in that way)
+ getModel().setValid(false);
+
+ EditCatchesUI parent = SwingUtil.getParentContainer(ui, EditCatchesUI.class);
+ parent.getHandler().setSelectedCard(EditCatchesUIHandler.MAIN_CARD);
}
//------------------------------------------------------------------------//
@@ -294,14 +315,8 @@
log.info("Cancel UI " + ui);
}
- // evict model from validator
- ui.getValidator().setBean(null);
-
- // when canceling always invalid model (in that way)
- getModel().setValid(false);
-
// close dialog
- closeDialog(ui);
+ closeUI(ui);
}
//------------------------------------------------------------------------//
@@ -380,8 +395,10 @@
getTable().scrollRowToVisible(rowIndex);
}
- public void editBatch(SpeciesBatchRowModel speciesBatch) {
+ public void editBatch(SpeciesBatchRowModel speciesBatch, FrequencyCellEditor editor) {
+ frequencyEditor = editor;
+
Caracteristic lengthStepCaracteristic = null;
Float lengthStep = 1f;
@@ -440,7 +457,7 @@
String lengthStepPmfmId = sProtocol.getLengthStepPmfmId();
lengthStepCaracteristic =
- lengthSteCaracteristic.get(lengthStepPmfmId);
+ this.lengthStepCaracteristics.get(lengthStepPmfmId);
lengthStep = sProtocol.getLengthStep();
if (log.isInfoEnabled()) {
@@ -478,7 +495,9 @@
log.info("Save UI " + ui);
}
- closeDialog(ui);
+ frequencyEditor.validateEdition(getModel());
+
+ closeUI(ui);
}
//------------------------------------------------------------------------//
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/AddSpeciesAction.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/AddSpeciesAction.java 2013-01-31 08:45:23 UTC (rev 275)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/AddSpeciesAction.java 2013-01-31 08:47:56 UTC (rev 276)
@@ -31,6 +31,7 @@
import fr.ifremer.tutti.service.PersistenceService;
import fr.ifremer.tutti.ui.swing.AbstractTuttiAction;
import fr.ifremer.tutti.ui.swing.TuttiUIContext;
+import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;
@@ -51,7 +52,7 @@
/** Logger. */
private static final Log log = LogFactory.getLog(AddSpeciesAction.class);
- protected AddSpeciesUI popup;
+// protected AddSpeciesUI popup;
protected List<Species> allSpecies;
@@ -64,15 +65,6 @@
false
);
- popup = new AddSpeciesUI(getHandler().getUi());
- popup.getValidateButton().addActionListener(new ActionListener() {
-
- @Override
- public void actionPerformed(ActionEvent e) {
- getHandler().closeDialog(popup);
- }
- });
-
TuttiPersistence persistenceService = getContext().getService(PersistenceService.class);
allSpecies = persistenceService.getAllSpecies();
}
@@ -80,30 +72,25 @@
@Override
protected void doAction(ActionEvent event) {
CreateSpeciesBatchUIHandler handler = getHandler();
- AddSpeciesUIModel model = popup.getModel();
- model.setSelectedSpecies(null);
List<Species> availableSpecies = handler.getModel().getAvailableSpecies();
- List<Species> species = Lists.newArrayList(allSpecies);
+ final List<Species> species = Lists.newArrayList(allSpecies);
species.removeAll(availableSpecies);
- model.setSpecies(species);
// open the popup asynchronously because the setVisible(true) method returns
// only after setVisible(false) has been called and this prevents the loading to hide.
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
-// getHandler().openDialog(popup, _("tutti.title.createBatch"));
-
- Species species = popup.getModel().getSelectedSpecies();
+ Species selectedSpecies = getHandler().openAddSpeciesDialog( _("tutti.title.createBatch"), species);
if (species != null) {
CreateSpeciesBatchUIHandler handler = getHandler();
CreateSpeciesBatchUIModel model = handler.getModel();
List<Species> availableSpecies = Lists.newArrayList(model.getAvailableSpecies());
- availableSpecies.add(species);
+ availableSpecies.add(selectedSpecies);
model.setAvailableSpecies(availableSpecies);
- model.setSpecies(species);
+ model.setSpecies(selectedSpecies);
}
}
});
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/AddSpeciesUIHandler.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/AddSpeciesUIHandler.java 2013-01-31 08:45:23 UTC (rev 275)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/AddSpeciesUIHandler.java 2013-01-31 08:47:56 UTC (rev 276)
@@ -39,6 +39,7 @@
import java.util.List;
import javax.swing.JDialog;
import jaxx.runtime.SwingUtil;
+import jaxx.runtime.validator.swing.SwingValidator;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -80,5 +81,10 @@
public AddSpeciesUIModel getModel() {
return ui.getModel();
}
+
+ @Override
+ public SwingValidator<AddSpeciesUIModel> getValidator() {
+ return null;
+ }
}
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/CreateSpeciesBatchUIHandler.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/CreateSpeciesBatchUIHandler.java 2013-01-31 08:45:23 UTC (rev 275)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/CreateSpeciesBatchUIHandler.java 2013-01-31 08:47:56 UTC (rev 276)
@@ -34,12 +34,10 @@
import fr.ifremer.tutti.ui.swing.AbstractTuttiUIHandler;
import fr.ifremer.tutti.ui.swing.TuttiUI;
import fr.ifremer.tutti.ui.swing.content.operation.catches.EditCatchesUI;
-import fr.ifremer.tutti.ui.swing.content.operation.catches.species.SpeciesBatchUI;
+import fr.ifremer.tutti.ui.swing.content.operation.catches.EditCatchesUIHandler;
import fr.ifremer.tutti.ui.swing.content.operation.catches.species.SpeciesBatchUIModel;
import fr.ifremer.tutti.ui.swing.util.Cancelable;
import java.awt.Dimension;
-import jaxx.runtime.validator.swing.SwingValidatorMessageTableRenderer;
-import jaxx.runtime.validator.swing.SwingValidatorUtil;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -48,6 +46,7 @@
import java.util.List;
import jaxx.runtime.SwingUtil;
import jaxx.runtime.swing.CardLayout2Ext;
+import jaxx.runtime.validator.swing.SwingValidator;
/**
* Handler of {@link CreateSpeciesBatchUI}.
@@ -178,9 +177,7 @@
getModel().setValid(false);
EditCatchesUI parent = SwingUtil.getParentContainer(ui, EditCatchesUI.class);
-
- CardLayout2Ext card = (CardLayout2Ext) parent.getSpeciesTabPanel().getLayout();
- card.setSelected("main");
+ parent.getHandler().setSelectedCard(EditCatchesUIHandler.MAIN_CARD);
}
@@ -189,6 +186,11 @@
return ui.getModel();
}
+ @Override
+ public SwingValidator<CreateSpeciesBatchUIModel> getValidator() {
+ return ui.getValidator();
+ }
+
//------------------------------------------------------------------------//
//-- Cancelable methods --//
//------------------------------------------------------------------------//
@@ -249,8 +251,15 @@
closeUI(ui);
}
- public CreateSpeciesBatchUI getUi() {
- return ui;
+ public Species openAddSpeciesDialog(String title, List<Species> species) {
+ AddSpeciesUI dialog = new AddSpeciesUI(ui);
+ AddSpeciesUIModel model = dialog.getModel();
+ model.setSelectedSpecies(null);
+ model.setSpecies(species);
+
+ openDialog(ui, dialog, title, new Dimension(400, 130));
+
+ return model.getSelectedSpecies();
}
}
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSpeciesBatchUI.jaxx
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSpeciesBatchUI.jaxx 2013-01-31 08:45:23 UTC (rev 275)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSpeciesBatchUI.jaxx 2013-01-31 08:47:56 UTC (rev 276)
@@ -25,6 +25,7 @@
implements='fr.ifremer.tutti.ui.swing.TuttiUI<SplitSpeciesBatchUIModel, SplitSpeciesBatchUIHandler>'>
<import>
+ fr.ifremer.tutti.ui.swing.content.operation.catches.EditCatchesUI
fr.ifremer.tutti.ui.swing.content.operation.catches.species.SampleCategoryType
fr.ifremer.tutti.ui.swing.content.operation.catches.species.SpeciesBatchUI
@@ -47,7 +48,7 @@
<script><![CDATA[
-public SplitSpeciesBatchUI(SpeciesBatchUI parentUI) {
+public SplitSpeciesBatchUI(EditCatchesUI parentUI) {
JAXXUtil.initContext(this, parentUI);
SplitSpeciesBatchUIHandler handler = new SplitSpeciesBatchUIHandler(parentUI, this);
setContextValue(handler);
@@ -72,89 +73,75 @@
<field name='sampleWeight' component='sampleWeightField'/>
</BeanValidator>
- <JSplitPane id='splitPane' constraints='BorderLayout.CENTER'>
+ <Table id='configurationPanel' fill='both'
+ constraints='BorderLayout.NORTH'>
- <JPanel layout='{new BorderLayout()}'>
+ <!-- SampleCategory choice -->
+ <row>
+ <cell anchor='west'>
+ <JLabel id='categoryLabel'/>
+ </cell>
+ <cell weightx='1.0'>
+ <BeanComboBox id='categoryComboBox' constructorParams='this'
+ genericType='SampleCategoryType'/>
+ </cell>
+ </row>
- <Table id='configurationPanel' fill='both'
- constraints='BorderLayout.NORTH'>
+ <!-- Split as a sample or not ? -->
+ <row>
+ <cell columns='2'>
+ <JCheckBox id='sampleCheckBox'
+ onItemStateChanged='handler.setBoolean(event, "sample")'/>
+ </cell>
+ </row>
- <!-- SampleCategory choice -->
- <row>
- <cell anchor='west'>
- <JLabel id='categoryLabel'/>
- </cell>
- <cell weightx='1.0'>
- <BeanComboBox id='categoryComboBox' constructorParams='this'
- genericType='SampleCategoryType'/>
- </cell>
- </row>
+ <row>
+ <cell columns="2">
+ <JSeparator/>
+ </cell>
+ </row>
- <!-- Split as a sample or not ? -->
- <row>
- <cell columns='2'>
- <JCheckBox id='sampleCheckBox'
- onItemStateChanged='handler.setBoolean(event, "sample")'/>
- </cell>
- </row>
+ <!-- Incoming Batch Species -->
+ <row>
+ <cell anchor='west'>
+ <JLabel id='speciesLabel'/>
+ </cell>
+ <cell weightx='1.0'>
+ <JTextField id='speciesField'/>
+ </cell>
+ </row>
- <row>
- <cell columns="2">
- <JSeparator/>
- </cell>
- </row>
+ <!-- Incoming Batch Total weight -->
+ <row>
+ <cell anchor='west'>
+ <JLabel id='batchWeightLabel'/>
+ </cell>
+ <cell weightx='1.0'>
+ <JTextField id='batchWeightField'/>
+ </cell>
+ </row>
- <!-- Incoming Batch Species -->
- <row>
- <cell anchor='west'>
- <JLabel id='speciesLabel'/>
- </cell>
- <cell weightx='1.0'>
- <JTextField id='speciesField'/>
- </cell>
- </row>
+ <!-- Sample Total weight -->
+ <row>
+ <cell anchor='west'>
+ <JLabel id='sampleWeightLabel'/>
+ </cell>
+ <cell weightx='1.0'>
+ <JTextField id='sampleWeightField'/>
+ </cell>
+ </row>
- <!-- Incoming Batch Total weight -->
- <row>
- <cell anchor='west'>
- <JLabel id='batchWeightLabel'/>
- </cell>
- <cell weightx='1.0'>
- <JTextField id='batchWeightField'/>
- </cell>
- </row>
+ </Table>
- <!-- Sample Total weight -->
- <row>
- <cell anchor='west'>
- <JLabel id='sampleWeightLabel'/>
- </cell>
- <cell weightx='1.0'>
- <JTextField id='sampleWeightField'/>
- </cell>
- </row>
+ <JScrollPane id='tableScrollPane' constraints='BorderLayout.CENTER'>
+ <JXTable id='table'/>
+ </JScrollPane>
- </Table>
-
- <JScrollPane id='tableScrollPane' constraints='BorderLayout.CENTER'>
- <JXTable id='table'/>
- </JScrollPane>
-
- <!-- actions -->
- <JPanel id='actionPanel' layout='{new GridLayout(1, 0)}'
- constraints='BorderLayout.SOUTH'>
- <JButton id='cancelButton' onActionPerformed='handler.cancel()'/>
- <JButton id='saveButton' onActionPerformed='handler.save()'/>
- </JPanel>
-
+ <!-- actions -->
+ <JPanel id='actionPanel' layout='{new GridLayout(1, 0)}'
+ constraints='BorderLayout.SOUTH'>
+ <JButton id='cancelButton' onActionPerformed='handler.cancel()'/>
+ <JButton id='saveButton' onActionPerformed='handler.save()'/>
</JPanel>
- <!-- Messages report -->
- <JPanel id='messagePanel' layout='{new GridLayout()}'>
- <JScrollPane columnHeaderView='{errorTable.getTableHeader()}'>
- <JTable id='errorTable'/>
- </JScrollPane>
- </JPanel>
- </JSplitPane>
-
</JPanel>
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-01-31 08:45:23 UTC (rev 275)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSpeciesBatchUIHandler.java 2013-01-31 08:47:56 UTC (rev 276)
@@ -30,6 +30,8 @@
import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativeValue;
import fr.ifremer.tutti.persistence.entities.referential.Species;
import fr.ifremer.tutti.ui.swing.TuttiUI;
+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.species.SampleCategory;
import fr.ifremer.tutti.ui.swing.content.operation.catches.species.SampleCategoryType;
import fr.ifremer.tutti.ui.swing.content.operation.catches.species.SpeciesBatchRowModel;
@@ -47,6 +49,9 @@
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.List;
+import jaxx.runtime.SwingUtil;
+import jaxx.runtime.swing.CardLayout2Ext;
+import jaxx.runtime.validator.swing.SwingValidator;
/**
* Handler of {@link SplitSpeciesBatchUI}.
@@ -75,12 +80,12 @@
*/
private final SplitSpeciesBatchUI ui;
- public SplitSpeciesBatchUIHandler(SpeciesBatchUI parentUi,
+ public SplitSpeciesBatchUIHandler(EditCatchesUI parentUi,
SplitSpeciesBatchUI ui) {
super(parentUi.getHandler().getContext(),
SplitSpeciesBatchRowModel.PROPERTY_CATEGORY_VALUE,
SplitSpeciesBatchRowModel.PROPERTY_WEIGHT);
- this.parentUi = parentUi;
+ this.parentUi = parentUi.getSpeciesTabContent();
this.ui = ui;
}
@@ -145,6 +150,11 @@
}
@Override
+ public SwingValidator<SplitSpeciesBatchUIModel> getValidator() {
+ return ui.getValidator();
+ }
+
+ @Override
public void beforeInitUI() {
SplitSpeciesBatchUIModel model = new SplitSpeciesBatchUIModel();
@@ -200,9 +210,6 @@
initTable(getTable());
- SwingValidatorUtil.installUI(ui.getErrorTable(),
- new SwingValidatorMessageTableRenderer());
-
listenValidatorValid(ui.getValidator(), model);
}
@@ -211,6 +218,15 @@
if (log.isInfoEnabled()) {
log.info("closing: " + ui);
}
+
+ // evict model from validator
+ ui.getValidator().setBean(null);
+
+ // when canceling always invalid model
+ getModel().setValid(false);
+
+ EditCatchesUI parent = SwingUtil.getParentContainer(ui, EditCatchesUI.class);
+ parent.getHandler().setSelectedCard(EditCatchesUIHandler.MAIN_CARD);
}
//------------------------------------------------------------------------//
@@ -223,15 +239,7 @@
if (log.isInfoEnabled()) {
log.info("Cancel UI " + ui);
}
-
- // evict model from validator
- ui.getValidator().setBean(null);
-
- // when canceling always invalid model
- getModel().setValid(false);
-
- // close dialog
- closeDialog(ui);
+ closeUI(ui);
}
//------------------------------------------------------------------------//
@@ -299,7 +307,11 @@
log.info("Save UI " + ui);
}
- closeDialog(ui);
+ EditCatchesUI parent = SwingUtil.getParentContainer(ui, EditCatchesUI.class);
+ parent.getSpeciesTabContent().getHandler().splitBatch(getModel());
+
+ // close dialog
+ closeUI(ui);
}
//------------------------------------------------------------------------//
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/fishing/CaracteristicTabUIHandler.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/fishing/CaracteristicTabUIHandler.java 2013-01-31 08:45:23 UTC (rev 275)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/fishing/CaracteristicTabUIHandler.java 2013-01-31 08:47:56 UTC (rev 276)
@@ -40,6 +40,7 @@
import fr.ifremer.tutti.ui.swing.util.table.AbstractTuttiTableUIHandler;
import java.util.List;
import jaxx.runtime.swing.editor.bean.BeanComboBox;
+import jaxx.runtime.validator.swing.SwingValidator;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -106,6 +107,11 @@
public M getModel() {
return (M) getUI().getModel();
}
+
+ @Override
+ public SwingValidator<M> getValidator() {
+ return null;
+ }
@Override
protected void onAfterSelectedRowChanged(int oldRowIndex,
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/fishing/gearshooting/GearShootingTabUIHandler.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/fishing/gearshooting/GearShootingTabUIHandler.java 2013-01-31 08:45:23 UTC (rev 275)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/fishing/gearshooting/GearShootingTabUIHandler.java 2013-01-31 08:47:56 UTC (rev 276)
@@ -37,6 +37,7 @@
import fr.ifremer.tutti.ui.swing.util.editor.CaracteristicValueRenderer;
import java.util.List;
import jaxx.runtime.swing.editor.bean.BeanComboBox;
+import jaxx.runtime.validator.swing.SwingValidator;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jdesktop.swingx.JXTable;
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/fishing/hydrology/HydrologyTabUIHandler.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/fishing/hydrology/HydrologyTabUIHandler.java 2013-01-31 08:45:23 UTC (rev 275)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/fishing/hydrology/HydrologyTabUIHandler.java 2013-01-31 08:47:56 UTC (rev 276)
@@ -36,6 +36,7 @@
import fr.ifremer.tutti.ui.swing.util.editor.CaracteristicValueEditor;
import fr.ifremer.tutti.ui.swing.util.editor.CaracteristicValueRenderer;
import jaxx.runtime.swing.editor.bean.BeanComboBox;
+import jaxx.runtime.validator.swing.SwingValidator;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jdesktop.swingx.JXTable;
@@ -207,7 +208,7 @@
table.setColumnModel(columnModel);
initTable(table);
}
-
+
//------------------------------------------------------------------------//
//-- Public methods --//
//------------------------------------------------------------------------//
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/program/EditProgramUIHandler.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/program/EditProgramUIHandler.java 2013-01-31 08:45:23 UTC (rev 275)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/program/EditProgramUIHandler.java 2013-01-31 08:47:56 UTC (rev 276)
@@ -125,4 +125,9 @@
return ui.getModel();
}
+ @Override
+ public SwingValidator<EditProgramUIModel> getValidator() {
+ return ui.getValidator();
+ }
+
}
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolSpeciesTableModel.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolSpeciesTableModel.java 2013-01-31 08:45:23 UTC (rev 275)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolSpeciesTableModel.java 2013-01-31 08:47:56 UTC (rev 276)
@@ -101,7 +101,6 @@
result.setWeightEnabled(true);
result.setCountIfNoFrequencyEnabled(true);
result.setCalcifySampleEnabled(true);
- result.setValid(false);
return result;
}
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolUIHandler.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolUIHandler.java 2013-01-31 08:45:23 UTC (rev 275)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolUIHandler.java 2013-01-31 08:47:56 UTC (rev 276)
@@ -140,6 +140,11 @@
}
@Override
+ public SwingValidator<EditProtocolUIModel> getValidator() {
+ return ui.getValidator();
+ }
+
+ @Override
public void beforeInitUI() {
EditProtocolUIModel model = new EditProtocolUIModel();
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-01-31 08:45:23 UTC (rev 275)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/AbstractTuttiTabContainerUIHandler.java 2013-01-31 08:47:56 UTC (rev 276)
@@ -31,6 +31,7 @@
import fr.ifremer.tutti.ui.swing.TuttiUIContext;
import java.awt.Component;
import javax.swing.DefaultSingleSelectionModel;
+import javax.swing.Icon;
import javax.swing.JTabbedPane;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
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-01-31 08:45:23 UTC (rev 275)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/CustomTab.java 2013-01-31 08:47:56 UTC (rev 276)
@@ -32,6 +32,7 @@
import java.beans.PropertyChangeListener;
import javax.swing.JLabel;
import javax.swing.JPanel;
+import jaxx.runtime.SwingUtil;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -58,8 +59,6 @@
public CustomTab(AbstractTuttiBeanUIModel model) {
this.model = model;
- title.setText(_(model.getTitle()));
- setBackground(null);
this.model.addPropertyChangeListener(AbstractTuttiBeanUIModel.PROPERTY_MODIFY, new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent evt) {
@@ -71,6 +70,14 @@
CustomTab.this.title.setText(title);
}
});
+
+ setBackground(null);
+
+ title.setText(_(model.getTitle()));
+ String actionIcon = model.getIcon();
+ if (actionIcon != null) {
+ title.setIcon(SwingUtil.createActionIcon(actionIcon));
+ }
add(title);
}
Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/SwingValidatorMessageWidget.java
===================================================================
--- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/SwingValidatorMessageWidget.java 2013-01-31 08:45:23 UTC (rev 275)
+++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/SwingValidatorMessageWidget.java 2013-01-31 08:47:56 UTC (rev 276)
@@ -45,6 +45,8 @@
import javax.swing.JToggleButton;
import javax.swing.KeyStroke;
import javax.swing.ListSelectionModel;
+import javax.swing.event.TableModelEvent;
+import javax.swing.event.TableModelListener;
import jaxx.runtime.SwingUtil;
import jaxx.runtime.validator.swing.SwingValidator;
import jaxx.runtime.validator.swing.SwingValidatorMessageTableModel;
@@ -55,6 +57,7 @@
import org.jdesktop.swingx.JXTitledPanel;
import static org.nuiton.i18n.I18n._;
+import org.nuiton.validator.NuitonValidatorScope;
/**
* Button which opens a popup containing a table with the errors found
@@ -76,8 +79,58 @@
protected Point popupPosition = null;
public SwingValidatorMessageWidget() {
- super(SwingUtil.createActionIcon("table-error"));
+ super(SwingUtil.createActionIcon("alert-none"));
+ setToolTipText(_("tutti.validator.alert.none"));
+ errorTableModel.addTableModelListener(new TableModelListener() {
+
+ public void tableChanged(TableModelEvent e) {
+ int alerts = errorTableModel.getRowCount();
+ String label;
+ switch (alerts) {
+ case 0:
+ label = "tutti.validator.alert.none";
+ break;
+ case 1:
+ label = "tutti.validator.alert.one";
+ break;
+ default:
+ label = "tutti.validator.alert.several";
+ }
+
+ NuitonValidatorScope maxScope;
+ String icon;
+ if (alerts == 0) {
+ maxScope = null;
+ icon = "alert-none";
+
+ } else {
+ maxScope = NuitonValidatorScope.INFO;
+ for (int i = 0 ; i < alerts ; i++) {
+ NuitonValidatorScope scope = errorTableModel.getRow(i).getScope();
+ int diff = scope.compareTo(maxScope);
+ if (diff < 0) {
+ maxScope = scope;
+ }
+ }
+ switch (maxScope) {
+ case INFO:
+ icon = "alert-info";
+ break;
+ case WARNING:
+ icon = "alert-warning";
+ break;
+ default:
+ icon = "alert-error";
+
+ }
+ }
+
+ setToolTipText(_(label, alerts));
+ setIcon(SwingUtil.createActionIcon(icon));
+ }
+ });
+
errorTable.setModel(errorTableModel);
errorTable.setRowSelectionAllowed(true);
errorTable.setAutoCreateRowSorter(true);
@@ -105,18 +158,6 @@
cm.setDragInsets(cr.getDragInsets());
cm.registerComponent(popup);
- addActionListener(new ActionListener() {
-
- @Override
- public void actionPerformed(ActionEvent e) {
- if(isSelected()) {
- popup.setVisible(true);
- } else {
- popup.dispose();
- }
- }
- });
-
popup.addWindowListener(new WindowAdapter() {
@Override
@@ -138,6 +179,18 @@
});
+ addActionListener(new ActionListener() {
+
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ if(isSelected()) {
+ popup.setVisible(true);
+ } else {
+ popup.dispose();
+ }
+ }
+ });
+
addHierarchyBoundsListener(new HierarchyBoundsAdapter() {
@Override
@@ -184,5 +237,5 @@
errorTableModel.clearValidators();
errorTableModel.clear();
}
-
+
}
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-01-31 08:45:23 UTC (rev 275)
+++ trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_fr_FR.properties 2013-01-31 08:47:56 UTC (rev 276)
@@ -123,12 +123,14 @@
tutti.label.catches.macroWasteTotalWeight=Poids TOTAL (kg)
tutti.label.catches.planktonTotalSampleWeight=Poids total échantillonné
tutti.label.catches.planktonTotalWeight=Poids total
+tutti.label.catches.speciesTotalInertWeight=Poids inerte (kg)
+tutti.label.catches.speciesTotalLivingNotItemizedWeight=Poids vivant non détaillé (kg)
tutti.label.catches.speciesTotalSampleSortedWeight=Poids VRAC trié (kg)
tutti.label.catches.speciesTotalSortedWeight=Poids total VRAC (kg)
tutti.label.catches.speciesTotalUnsortedWeight=Poids total HORS VRAC (kg)
tutti.label.catches.speciesTotalWeight=Poids TOTAL (kg)
tutti.label.comment=Commentaire
-tutti.label.createSpeciesBatch.batchWeight=Poids du lot
+tutti.label.createSpeciesBatch.batchWeight=Poids du lot (kg)
tutti.label.createSpeciesBatch.sortedUnsortedCategory=V / HV
tutti.label.createSpeciesBatch.species=Espèce du lot
tutti.label.cruise=Campagne
@@ -303,16 +305,16 @@
tutti.table.species.batch.header.number=Nombre
tutti.table.species.batch.header.sexCategory=Sexe
tutti.table.species.batch.header.sizeCategory=Class. Tri
-tutti.table.species.batch.header.sortedUnsortedCategory=V/HV
+tutti.table.species.batch.header.sortedUnsortedCategory=V/HV (kg)
tutti.table.species.batch.header.species=Espèce
tutti.table.species.batch.header.toConfirm=A Confirmer
-tutti.table.species.batch.header.weight=Poids sous-échantillonné
-tutti.table.species.frequency.header.computedWeight=Poids calculé
+tutti.table.species.batch.header.weight=Poids sous-échantillonné (kg)
+tutti.table.species.frequency.header.computedWeight=Poids calculé (kg)
tutti.table.species.frequency.header.lengthStep=Classe de taille
tutti.table.species.frequency.header.number=Nombre
-tutti.table.species.frequency.header.weight=Poids observé
+tutti.table.species.frequency.header.weight=Poids observé (kg)
tutti.table.species.sampleCategory.header.category=Catégorie
-tutti.table.species.sampleCategory.header.weight=Poids
+tutti.table.species.sampleCategory.header.weight=Poids (kg)
tutti.timeeditor.H=H
tutti.title.about=À propos de Tutti
tutti.title.choose.protocolExportFile=Choisir le fichier où exporter le protocole
@@ -333,7 +335,7 @@
tutti.title.noSelectedProtocol=Pas de protocol sélectionné
tutti.title.selectedCruise=Campagne %s
tutti.title.selectedProgram=Série de campagne %s
-tutti.title.selectedProtocol=Protocol %s
+tutti.title.selectedProtocol=Protocole %s
tutti.title.splitBatch=Catégoriser un lot
tutti.title.validate.operations=Validation des opérations de pêches (%s)
tutti.to.be.done=< A FAIRE >
@@ -342,10 +344,13 @@
tutti.update.application.url.description=
tutti.update.database.url.description=
tutti.update.location.description=
+tutti.validator.alert.none=Aucune alerte
+tutti.validator.alert.one=1 alerte
+tutti.validator.alert.several=%s alertes
tutti.validator.error.comment.too.long=Taille de commentaire trop longue (limitée à %s caractères)
tutti.validator.error.createSpeciesBatch.batchWeight.invalidValue=Le poids du lot doit être strictement positif
tutti.validator.error.createSpeciesBatch.batchWeight.required=Le poids du lot est obligatoire
-tutti.validator.error.createSpeciesBatch.sortedUnsortedCategory.required=LA catégorie Vrac / Hors Vrac est obligatoire
+tutti.validator.error.createSpeciesBatch.sortedUnsortedCategory.required=La catégorie Vrac / Hors Vrac est obligatoire
tutti.validator.error.createSpeciesBatch.species.required=L'espèce est obligatoire
tutti.validator.error.createSpeciesBatch.speciesAndCategory.notAvailable=Couple (espèce - Vrac/Hors Vrac) déjà utilisée
tutti.validator.error.cruise.beginDate.required=La date de début est obligatoire
Added: trunk/tutti-ui-swing/src/main/resources/icons/action-alert-error.png
===================================================================
(Binary files differ)
Property changes on: trunk/tutti-ui-swing/src/main/resources/icons/action-alert-error.png
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: trunk/tutti-ui-swing/src/main/resources/icons/action-alert-info.png
===================================================================
(Binary files differ)
Property changes on: trunk/tutti-ui-swing/src/main/resources/icons/action-alert-info.png
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: trunk/tutti-ui-swing/src/main/resources/icons/action-alert-none.png
===================================================================
(Binary files differ)
Property changes on: trunk/tutti-ui-swing/src/main/resources/icons/action-alert-none.png
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: trunk/tutti-ui-swing/src/main/resources/icons/action-alert-warning.png
===================================================================
(Binary files differ)
Property changes on: trunk/tutti-ui-swing/src/main/resources/icons/action-alert-warning.png
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: trunk/tutti-ui-swing/src/main/resources/icons/action-protocol.png
===================================================================
(Binary files differ)
Property changes on: trunk/tutti-ui-swing/src/main/resources/icons/action-protocol.png
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
1
0
31 Jan '13
Author: kmorin
Date: 2013-01-31 09:45:23 +0100 (Thu, 31 Jan 2013)
New Revision: 275
Url: http://forge.codelutin.com/projects/tutti/repository/revisions/275
Log:
add properties to catchbatch
Modified:
trunk/tutti-persistence/src/main/xmi/tutti-persistence.zargo
Modified: trunk/tutti-persistence/src/main/xmi/tutti-persistence.zargo
===================================================================
(Binary files differ)
1
0
r274 - in trunk/tutti-persistence-adagio/src: main/java/fr/ifremer/tutti/persistence/service main/java/fr/ifremer/tutti/persistence/service/measure main/resources test/java/fr/ifremer/tutti/persistence/service
by blavenier@users.forge.codelutin.com 31 Jan '13
by blavenier@users.forge.codelutin.com 31 Jan '13
31 Jan '13
Author: blavenier
Date: 2013-01-31 01:04:37 +0100 (Thu, 31 Jan 2013)
New Revision: 274
Url: http://forge.codelutin.com/projects/tutti/repository/revisions/274
Log:
ref refs #1920: [Persistence] Adagio Donnees thematiques
- Add persistence for CatchBatch
- Add a helper for persistence on *Measurement entities
- Fix ReferentialPersistenceService.getSortedUnsortedCaracteristic() to ignore "rejected" qualitative value
- Add some enumeration
Added:
trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/service/measure/
trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/service/measure/MeasurementPersistenceHelper.java
trunk/tutti-persistence-adagio/src/main/resources/ehcache.xml
Removed:
trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/service/MeasurementService.java
Modified:
trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/service/CatchBatchPersistenceServiceImpl.java
trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/service/CruisePersistenceServiceImpl.java
trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceServiceImpl.java
trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceServiceImpl.java
trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceImpl.java
trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/service/TuttiEnumerationFile.java
trunk/tutti-persistence-adagio/src/main/resources/queries-override.hbm.xml
trunk/tutti-persistence-adagio/src/main/resources/tutti-db-enumerations.properties
trunk/tutti-persistence-adagio/src/test/java/fr/ifremer/tutti/persistence/service/CatchBatchPersistenceServiceImplTest.java
trunk/tutti-persistence-adagio/src/test/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceTest.java
Modified: trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/service/CatchBatchPersistenceServiceImpl.java
===================================================================
--- trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/service/CatchBatchPersistenceServiceImpl.java 2013-01-30 17:17:46 UTC (rev 273)
+++ trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/service/CatchBatchPersistenceServiceImpl.java 2013-01-31 00:04:37 UTC (rev 274)
@@ -24,11 +24,44 @@
* #L%
*/
-import fr.ifremer.tutti.persistence.entities.data.CatchBatch;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.annotation.Resource;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.hibernate.FlushMode;
+import org.hibernate.type.IntegerType;
+import org.springframework.dao.DataIntegrityViolationException;
+import org.springframework.dao.DataRetrievalFailureException;
import org.springframework.stereotype.Service;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Lists;
+
+import fr.ifremer.adagio.core.dao.data.batch.Batch;
+import fr.ifremer.adagio.core.dao.data.batch.CatchBatchDao;
+import fr.ifremer.adagio.core.dao.data.batch.CatchBatchImpl;
+import fr.ifremer.adagio.core.dao.data.batch.SortingBatch;
+import fr.ifremer.adagio.core.dao.data.batch.SortingBatchDao;
+import fr.ifremer.adagio.core.dao.data.batch.denormalized.DenormalizedBatchDao;
+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.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.CatchBatch;
+import fr.ifremer.tutti.persistence.entities.data.FishingOperation;
+import fr.ifremer.tutti.persistence.service.measure.MeasurementPersistenceHelper;
+
/**
* @author tchemit <chemit(a)codelutin.com>
* @since 1.0
@@ -40,18 +73,386 @@
private static final Log log =
LogFactory.getLog(CatchBatchPersistenceServiceImpl.class);
+ @Resource(name = "referentialPersistenceService")
+ protected ReferentialPersistenceService referentialService;
+
+ @Resource(name = "denormalizedBatchDao")
+ protected DenormalizedBatchDao denormalizedBatchDao;
+
+ @Resource(name = "sortingBatchDao")
+ protected SortingBatchDao sortingBatchDao;
+
+ @Resource(name = "catchBatchDao")
+ protected CatchBatchDao catchBatchDao;
+
+ @Resource(name = "measurementPersistenceHelper")
+ protected MeasurementPersistenceHelper measurementHelper;
+
+
@Override
public CatchBatch getCatchBatchFromFishingOperation(String id) {
- return null;
+ Preconditions.checkNotNull(id);
+
+ Iterator<Object[]> list = queryList("catchBatch",
+ "fishingOperationId", IntegerType.INSTANCE, Integer.valueOf(id),
+ "pmfmIdSorted", IntegerType.INSTANCE, enumeration.PMFM_ID_SORTED_UNSORTED,
+ "pmfmIdSortingType", IntegerType.INSTANCE, enumeration.PMFM_ID_SORTING_TYPE);
+
+ int rowCount = 0;
+ CatchBatch result = new CatchBatch();
+ Integer previousSortedBatchId = null;
+ while (list.hasNext()) {
+ Object[] source = list.next();
+ rowCount++;
+
+ if (rowCount == 1) {
+ // Id
+ result.setId(source[0].toString());
+
+ // Total weight
+ Float totalWeight = (Float)source[1];
+ result.setCatchTotalWeight(totalWeight);
+ }
+
+ Integer sortedBatchId = (Integer)source[2];
+ Integer sortedQualitativeValueId = (Integer)source[5];
+ if (sortedBatchId != null && !sortedBatchId.equals(previousSortedBatchId)) {
+ // TODO BL : retrieve QV
+ String samplingRatioText = (String)source[3];
+ Float weight = (Float)source[4];
+ if (weight != null && enumeration.QUALITATIVE_VRAC_ID.equals(sortedQualitativeValueId)) {
+ result.setCatchTotalSortedCarousselWeight(weight);
+ result.setCatchTotalSortedTremisWeight(getTotalWeight(weight, samplingRatioText));
+ }
+ else if (weight != null && enumeration.QUALITATIVE_HORS_VRAC_ID.equals(sortedQualitativeValueId)) {
+ result.setCatchTotalUnsortedWeight(weight);
+ if (samplingRatioText != null && !samplingRatioText.isEmpty()) {
+ // TODO BL : throw error because baths are not compatible with tutti ??
+ }
+ }
+ else if (weight != null && enumeration.QUALITATIVE_UNSORTED_ID.equals(sortedQualitativeValueId)) {
+ result.setCatchTotalRejectedWeight(weight);
+ if (samplingRatioText != null && !samplingRatioText.isEmpty()) {
+ // TODO BL : throw error because baths are not compatible with tutti ??
+ }
+ }
+ }
+
+ Integer sortingTypeBatchId = (Integer)source[6];
+ {
+ String samplingRatioText = (String)source[7];
+ Float weight = (Float)source[8];
+ Integer qualitativeValueId = (Integer)source[9];
+ if (weight != null) {
+ if (enumeration.QUALITATIVE_VRAC_ID.equals(sortedQualitativeValueId)
+ && enumeration.QUALITATIVE_ID_SORTING_TYPE_SPECIES.equals(qualitativeValueId)) {
+ result.setSpeciesTotalSampleSortedWeight(weight);
+ result.setSpeciesTotalSortedWeight(getTotalWeight(weight, samplingRatioText));
+ }
+ else if (enumeration.QUALITATIVE_HORS_VRAC_ID.equals(sortedQualitativeValueId)
+ && enumeration.QUALITATIVE_ID_SORTING_TYPE_SPECIES.equals(qualitativeValueId)) {
+ result.setSpeciesTotalUnsortedWeight(weight);
+ // TODO error si samplingRatio not null
+ }
+ // TOBO BL : add benthos, plancton, etc.
+ }
+ }
+
+
+ previousSortedBatchId = sortedBatchId;
+ }
+
+ return result;
}
@Override
public CatchBatch createCatchBatch(CatchBatch bean) {
- return null;
+ 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) {
- return null;
+
+ 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;
}
+
+ // ------------------------------------------------------------------------//
+ // -- Internal methods --//
+ // ------------------------------------------------------------------------//
+ 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
+ // TODO BLA : prendre le service du 1er saisisseur sur l'OP ?
+ Integer recorderDepartmentId = enumeration.DEPARTMENT_ID_UNKNOWN_RECORDER_DEPARTMENT;
+
+ // 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 = measurementHelper.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.getCatchTotalSortedTremisWeight(), source.getCatchTotalSortedCarousselWeight(),
+ copyIfNull);
+ batch.setRankOrder((short)1);
+
+ // Manage childs :
+ {
+ Map<Integer, SortingBatch> batchChilds = getChildsMap(batch, enumeration.PMFM_ID_SORTING_TYPE);
+
+ // 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.getSpeciesTotalSortedWeight(), source.getSpeciesTotalSampleSortedWeight(),
+ copyIfNull);
+ speciesBatch.setRankOrder((short)1);
+ }
+ // TODO BL : benthos, 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);
+
+ // 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);
+ }
+
+ // TODO BL : benthos, 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 (Iterator iterator = parentBatch.getChildBatchs()
+ .iterator(); iterator.hasNext();) {
+ Batch childBatch = (Batch) iterator.next();
+ SortingMeasurement sm = measurementHelper.getSortingMeasurement((SortingBatch)childBatch, pmfmId, null, false);
+ if (sm != null && sm.getQualitativeValue() != null && sm.getQualitativeValue().getId() != null){
+ batchByQualitativeValueId.put(sm.getQualitativeValue().getId(), (SortingBatch)childBatch);
+ }
+ }
+ 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);
+
+ // 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 = measurementHelper.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 = sampleWeight + "/" + weight;
+ samplingRatioText = samplingRatioText.replaceAll(",", ".");
+ target.setSamplingRatioText(samplingRatioText);
+ target.setSamplingRatio(sampleWeight.floatValue() / weight.floatValue());
+ }
+
+ // Weight
+ if (copyIfNull && (sampleWeight == null && weight == null)) {
+ // Nothing to do : will be removed later, using notChangedQuantificationMeasurements
+ }
+ else if (sampleWeight != null || weight != null) {
+ Float batchReferenceWeight = sampleWeight;
+ if (batchReferenceWeight == null) {
+ batchReferenceWeight = weight;
+ }
+ QuantificationMeasurement quantificationMeasurement = measurementHelper.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 Float getTotalWeight(Float weight, String samplingRatioText) {
+ if (weight == null) {
+ return null;
+ }
+ String startStr = weight.toString().replace(',', '.') + "/";
+ if (samplingRatioText != null && samplingRatioText.startsWith(startStr)) {
+ String weightStr = samplingRatioText.substring(startStr.length());
+ if (weightStr != null && !weightStr.isEmpty()) {
+ return Float.parseFloat(weightStr);
+ }
+ }
+ // TODO BL : attention au saise "1/2" qui ne seront pas pris (mais "1.0/2.0" oui)
+ return null;
+ }
+
}
Modified: trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/service/CruisePersistenceServiceImpl.java
===================================================================
--- trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/service/CruisePersistenceServiceImpl.java 2013-01-30 17:17:46 UTC (rev 273)
+++ trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/service/CruisePersistenceServiceImpl.java 2013-01-31 00:04:37 UTC (rev 274)
@@ -72,13 +72,14 @@
import fr.ifremer.tutti.persistence.entities.referential.Gear;
import fr.ifremer.tutti.persistence.entities.referential.Person;
import fr.ifremer.tutti.persistence.entities.referential.Vessel;
+import fr.ifremer.tutti.persistence.service.measure.MeasurementPersistenceHelper;
/**
* @author tchemit <chemit(a)codelutin.com>
* @since 0.3
*/
@Service("cruisePersistenceService")
-public class CruisePersistenceServiceImpl extends AbstractPersistenceService implements CruisePersistenceService, MeasurementService {
+public class CruisePersistenceServiceImpl extends AbstractPersistenceService implements CruisePersistenceService {
/** Logger. */
private static final Log log =
@@ -119,6 +120,9 @@
@Resource(name = "gearDao")
protected GearDao gearDao;
+
+ @Resource(name = "measurementPersistenceHelper")
+ protected MeasurementPersistenceHelper measurementHelper;
protected Calendar calendar = new GregorianCalendar();
@@ -488,7 +492,7 @@
} else if (!source.isGearEmpty()) {
for (int i = 0; i < source.getGear().size(); i++) {
Gear gear = source.getGear().get(i);
- GearPhysicalFeatures guf = getGearPhysicalfeatures(fishingTrip, Integer.valueOf(gear.getId()), true);
+ GearPhysicalFeatures guf = measurementHelper.getGearPhysicalfeatures(fishingTrip, Integer.valueOf(gear.getId()), true);
guf.setStartDate(fishingTrip.getDepartureDateTime());
guf.setEndDate(fishingTrip.getReturnDateTime());
guf.setVessel(fishingTrip.getVessel());
@@ -499,10 +503,10 @@
// Trawl net (store in Gear Physical features)
if (copyIfNull && source.getMultirigNumber() == null) {
- removeGearPhysicalMeasurement(guf, enumeration.PMFM_ID_MULTIRIG_NUMBER);
+ measurementHelper.removeGearPhysicalMeasurement(guf, enumeration.PMFM_ID_MULTIRIG_NUMBER);
}
else {
- setGearPhysicalMeasurement(target, guf, enumeration.PMFM_ID_MULTIRIG_NUMBER, Float.valueOf(source.getMultirigNumber()), null, null);
+ measurementHelper.setGearPhysicalMeasurement(target, guf, enumeration.PMFM_ID_MULTIRIG_NUMBER, Float.valueOf(source.getMultirigNumber()), null, null);
}
}
}
@@ -511,110 +515,6 @@
fishingTrip.setComments(miscDataBuffer.toString());
}
- @Override
- public GearPhysicalFeatures getGearPhysicalfeatures(FishingTrip fishingTrip, Integer gearId) {
- return getGearPhysicalfeatures(fishingTrip, gearId, false);
- }
-
- protected GearPhysicalFeatures getGearPhysicalfeatures(FishingTrip fishingTrip, Integer gearId, boolean createIfNotExists) {
- // Retrieve entities : Gear Physical Features
- if (fishingTrip.getGearPhysicalFeatures() != null && fishingTrip.getGearPhysicalFeatures().size() >= 0) {
- for (Iterator iterator = fishingTrip.getGearPhysicalFeatures().iterator(); iterator.hasNext();) {
- GearPhysicalFeatures guf = (GearPhysicalFeatures) iterator.next();
- if (gearId.equals(guf.getGear().getId())) {
- return guf;
- }
- }
- }
- if (!createIfNotExists) {
- return null;
- }
-
- GearPhysicalFeatures gearPhysicalFeature = GearPhysicalFeatures.Factory.newInstance();
- gearPhysicalFeature.setFishingTrip(fishingTrip);
-
- fr.ifremer.adagio.core.dao.referential.gear.Gear gear = (fr.ifremer.adagio.core.dao.referential.gear.Gear)getCurrentSession().load(GearImpl.class, gearId);
- gearPhysicalFeature.setGear(gear);
- if (fishingTrip.getGearPhysicalFeatures() == null) {
- fishingTrip.setGearPhysicalFeatures(Lists.newArrayList(gearPhysicalFeature));
- } else {
- fishingTrip.getGearPhysicalFeatures().add(gearPhysicalFeature);
- }
-
- return gearPhysicalFeature;
- }
-
- @Override
- public GearPhysicalMeasurement getGearPhysicalMeasurement(GearPhysicalFeatures gearPhysicalFeatures, Integer pmfmId) {
- return getGearPhysicalMeasurement(null, gearPhysicalFeatures, pmfmId, false);
- }
-
- protected GearPhysicalMeasurement getGearPhysicalMeasurement(ScientificCruise scientificCruise, GearPhysicalFeatures gearPhysicalFeatures,
- Integer pmfmId, boolean createIfNotExists) {
- GearPhysicalMeasurement gearPhysicalMeasurement = null;
- if (gearPhysicalFeatures.getGearPhysicalMeasurements() != null) {
- for (Iterator iterator = gearPhysicalFeatures.getGearPhysicalMeasurements().iterator(); iterator.hasNext();) {
- GearPhysicalMeasurement vum = (GearPhysicalMeasurement) iterator.next();
- if (pmfmId.equals(vum.getPmfm().getId())) {
- gearPhysicalMeasurement = vum;
- break;
- }
- }
- }
- if (gearPhysicalMeasurement == null) {
- if (!createIfNotExists) {
- return null;
- }
- gearPhysicalMeasurement = GearPhysicalMeasurement.Factory.newInstance();
- gearPhysicalMeasurement.setGearPhysicalFeatures(gearPhysicalFeatures);
- if (gearPhysicalFeatures.getGearPhysicalMeasurements() == null) {
- gearPhysicalFeatures.setGearPhysicalMeasurements(Lists.newArrayList(gearPhysicalMeasurement));
- }
- else {
- gearPhysicalFeatures.getGearPhysicalMeasurements().add(gearPhysicalMeasurement);
- }
- gearPhysicalMeasurement.setQualityFlag(qualityFlagDao.load(enumeration.QUALITY_FLAG_CODE_NOT_QUALIFIED));
- gearPhysicalMeasurement.setDepartment(scientificCruise.getRecorderDepartment());
- Pmfm pmfm = (Pmfm)getCurrentSession().load(PmfmImpl.class, pmfmId);
- gearPhysicalMeasurement.setPmfm(pmfm);
- //gearPhysicalMeasurement.setPmfm(pmfmDao.load(pmfmId));
- }
-
- return gearPhysicalMeasurement;
- }
-
- protected void removeGearPhysicalMeasurement(GearPhysicalFeatures gearPhysicalFeatures,
- Integer pmfmId) {
- GearPhysicalMeasurement gearPhysicalMeasurement = getGearPhysicalMeasurement(null, gearPhysicalFeatures, pmfmId, false);
- if (gearPhysicalMeasurement == null) {
- return;
- }
- gearPhysicalFeatures.getGearPhysicalMeasurements().remove(gearPhysicalMeasurement);
- // TOBO BLa : vérifier qu'il ne faut pas dao.delete() en plus
- }
-
- protected GearPhysicalMeasurement setGearPhysicalMeasurement(ScientificCruise scientificCruise, GearPhysicalFeatures gearPhysicalFeatures,
- Integer pmfmId,
- Float numericalValue,
- String alphanumericalValue,
- Integer qualitativevalueId) {
- GearPhysicalMeasurement gearPhysicalMeasurement = getGearPhysicalMeasurement(scientificCruise, gearPhysicalFeatures, pmfmId, true);
-
- if (alphanumericalValue != null) {
- gearPhysicalMeasurement.setAlphanumericalValue(alphanumericalValue);
- }
- else if (numericalValue != null) {
- gearPhysicalMeasurement.setNumericalValue(numericalValue);
- }
- else if (qualitativevalueId != null) {
- QualitativeValue qv = (QualitativeValue)getCurrentSession().load(QualitativeValueImpl.class, qualitativevalueId);
- gearPhysicalMeasurement.setQualitativeValue(qv);
- //gearPhysicalMeasurement.setQualitativeValue(qualitativeValueDao.load(qualitativevalueId));
- }
-
- return gearPhysicalMeasurement;
- }
-
protected List<Person> getCruisePersonsByRole(String cruiseId, Integer vesselPersonRole) {
Iterator<Object[]> list = queryList(
"allCruiseManagers",
Modified: trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceServiceImpl.java
===================================================================
--- trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceServiceImpl.java 2013-01-30 17:17:46 UTC (rev 273)
+++ trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceServiceImpl.java 2013-01-31 00:04:37 UTC (rev 274)
@@ -83,6 +83,7 @@
import fr.ifremer.tutti.persistence.entities.referential.CaracteristicType;
import fr.ifremer.tutti.persistence.entities.referential.FishingOperationLocation;
import fr.ifremer.tutti.persistence.entities.referential.Person;
+import fr.ifremer.tutti.persistence.service.measure.MeasurementPersistenceHelper;
/**
* @author tchemit <chemit(a)codelutin.com>
@@ -95,8 +96,9 @@
private static final Log log =
LogFactory.getLog(FishingOperationPersistenceServiceImpl.class);
- @Resource(name = "cruisePersistenceService")
- protected MeasurementService measurementService;
+
+ @Resource(name = "measurementPersistenceHelper")
+ protected MeasurementPersistenceHelper measurementHelper;
@Autowired(required = true)
protected ReferentialPersistenceService referentialService;
@@ -551,7 +553,7 @@
// Retrieve entities : Gear Physical Features
GearPhysicalFeatures gearPhysicalFeatures = target.getGearPhysicalFeatures();
if (gearPhysicalFeatures == null && source.getGear() != null && source.getGear().getId() != null) {
- gearPhysicalFeatures = measurementService.getGearPhysicalfeatures(fishingTrip, Integer.valueOf(source.getGear().getId()));
+ gearPhysicalFeatures = measurementHelper.getGearPhysicalfeatures(fishingTrip, Integer.valueOf(source.getGear().getId()));
if (gearPhysicalFeatures == null) {
throw new DataIntegrityViolationException("An operation could not use a gear that is not declared in the cruise.");
}
@@ -590,7 +592,7 @@
// Retrieve multirig number, from Gear physical features
int cruiseMultirigCount = 1; // default value
- GearPhysicalMeasurement gpmMultirigCount = measurementService.getGearPhysicalMeasurement(gearPhysicalFeatures, enumeration.PMFM_ID_MULTIRIG_NUMBER);
+ GearPhysicalMeasurement gpmMultirigCount = measurementHelper.getGearPhysicalMeasurement(gearPhysicalFeatures, enumeration.PMFM_ID_MULTIRIG_NUMBER);
if (gpmMultirigCount != null && gpmMultirigCount.getNumericalValue() != null) {
cruiseMultirigCount = gpmMultirigCount.getNumericalValue().intValue();
}
Deleted: trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/service/MeasurementService.java
===================================================================
--- trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/service/MeasurementService.java 2013-01-30 17:17:46 UTC (rev 273)
+++ trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/service/MeasurementService.java 2013-01-31 00:04:37 UTC (rev 274)
@@ -1,38 +0,0 @@
-package fr.ifremer.tutti.persistence.service;
-
-/*
- * #%L
- * Tutti :: Persistence Adagio (impl)
- * $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.measure.GearPhysicalMeasurement;
-import fr.ifremer.adagio.core.dao.data.survey.fishingTrip.FishingTrip;
-import fr.ifremer.adagio.core.dao.data.vessel.feature.physical.GearPhysicalFeatures;
-
-public interface MeasurementService {
-
- GearPhysicalFeatures getGearPhysicalfeatures(FishingTrip fishingTrip, Integer gearId);
-
- GearPhysicalMeasurement getGearPhysicalMeasurement(GearPhysicalFeatures gearPhysicalFeatures, Integer pmfmId);
-
-}
\ No newline at end of file
Modified: trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceServiceImpl.java
===================================================================
--- trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceServiceImpl.java 2013-01-30 17:17:46 UTC (rev 273)
+++ trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceServiceImpl.java 2013-01-31 00:04:37 UTC (rev 274)
@@ -420,6 +420,16 @@
public Caracteristic getSortedUnsortedCaracteristic() {
Integer pmfmId = enumeration.PMFM_ID_SORTED_UNSORTED;
Caracteristic result = getCaracteristic(pmfmId);
+
+ // Search the qualitative value to skip
+ for (Iterator iterator = result.getQualitativeValue().iterator(); iterator.hasNext();) {
+ CaracteristicQualitativeValue qv = (CaracteristicQualitativeValue) iterator.next();
+ if (qv != null && qv.getId() != null
+ && enumeration.QUALITATIVE_UNSORTED_ID.equals(Integer.valueOf(qv.getId()))) {
+ result.removeQualitativeValue(qv);
+ break;
+ }
+ }
return result;
}
Modified: trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceImpl.java
===================================================================
--- trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceImpl.java 2013-01-30 17:17:46 UTC (rev 273)
+++ trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceImpl.java 2013-01-31 00:04:37 UTC (rev 274)
@@ -75,6 +75,7 @@
import fr.ifremer.tutti.persistence.entities.referential.Caracteristic;
import fr.ifremer.tutti.persistence.entities.referential.CaracteristicType;
import fr.ifremer.tutti.persistence.entities.referential.Species;
+import fr.ifremer.tutti.persistence.service.measure.MeasurementPersistenceHelper;
/**
* @author tchemit <chemit(a)codelutin.com>
@@ -99,6 +100,9 @@
@Resource(name = "catchBatchDao")
protected CatchBatchDao catchBatchDao;
+
+ @Resource(name = "measurementPersistenceHelper")
+ protected MeasurementPersistenceHelper measurementHelper;
@Override
public List<SpeciesBatch> getAllRootSpeciesBatch(String fishingOperationId) {
@@ -149,7 +153,7 @@
// Sample category type
Integer pmfmId = (Integer)source[colIndex++];
if (pmfmId != null) {
- SampleCategoryEnum sampleCategory = pmfmId2SampleCategory(pmfmId);
+ SampleCategoryEnum sampleCategory = measurementHelper.pmfmId2SampleCategory(pmfmId);
result.setSampleCategoryType(sampleCategory);
}
@@ -183,12 +187,6 @@
beanToEntity(bean, batch, parentBatchId, true);
batch = sortingBatchDao.create(batch);
- // DenormalizedBatch denormalizedBatch =
- // DenormalizedBatch.Factory.newInstance();
- // denormalizedBatch.setId((long)batch.getId());
- // beanToEntity(bean, denormalizedBatch, parentBatchId, true);
- // denormalizedBatchDao.create(denormalizedBatch);
-
bean.setId(String.valueOf(batch.getId()));
return bean;
}
@@ -244,6 +242,7 @@
Integer recorderDepartmentId = enumeration.DEPARTMENT_ID_UNKNOWN_RECORDER_DEPARTMENT;
// Retrieve entity Root batch
+ //source.getFishingOperation().get
Integer fishingOperationId = Integer.valueOf(source.getFishingOperation().getId());
Integer rootBatchId = getRootBatchId(fishingOperationId);
if (rootBatchId == null) {
@@ -310,11 +309,11 @@
// Nothing to do : will be removed later, using notChangedSortingMeasurements
}
else if (source.getSampleCategoryWeight() != null){
- QuantificationMeasurement quantificationMeasurement = setQuantificationMeasurement(target, enumeration.PMFM_ID_WEIGHT_MEASURED, recorderDepartmentId, source.getSampleCategoryWeight(), true);
+ QuantificationMeasurement quantificationMeasurement = measurementHelper.setQuantificationMeasurement(target, enumeration.PMFM_ID_WEIGHT_MEASURED, recorderDepartmentId, source.getSampleCategoryWeight(), true);
notChangedQuantificationMeasurements.remove(quantificationMeasurement);
}
else if (source.getWeight() != null){
- QuantificationMeasurement quantificationMeasurement = setQuantificationMeasurement(target, enumeration.PMFM_ID_WEIGHT_MEASURED, recorderDepartmentId, source.getWeight(), true);
+ QuantificationMeasurement quantificationMeasurement = measurementHelper.setQuantificationMeasurement(target, enumeration.PMFM_ID_WEIGHT_MEASURED, recorderDepartmentId, source.getWeight(), true);
notChangedQuantificationMeasurements.remove(quantificationMeasurement);
}
@@ -335,7 +334,7 @@
// Nothing to do : will be removed later, using notChangedSortingMeasurements
}
else if (source.getSampleCategoryType() != null && source.getSampleCategoryValue() != null) {
- SortingMeasurement sortingMeasurement = setSortingMeasurement(target, recorderDepartmentId, source.getSampleCategoryType(), source.getSampleCategoryValue());
+ SortingMeasurement sortingMeasurement = measurementHelper.setSortingMeasurement(target, recorderDepartmentId, source.getSampleCategoryType(), source.getSampleCategoryValue());
notChangedSortingMeasurements.remove(sortingMeasurement);
}
@@ -383,288 +382,13 @@
target.getSortingMeasurements().remove(sm);
}
}
- }
+ }
- protected void beanToEntity(SpeciesBatch source, DenormalizedBatch target,
- String parentBatchId, boolean copyIfNull) {
-
- // Parent batch
- if (copyIfNull && parentBatchId == null) {
- target.setParentBatch(null);
- ;
- } else if (parentBatchId != null) {
- target.setParentBatch(load(DenormalizedBatchImpl.class,
- Integer.valueOf(parentBatchId)));
- }
-
- // Weight
- if (copyIfNull && source.getWeight() == null) {
- target.setWeight(null);
- } else if (source.getWeight() != null) {
- target.setWeight(source.getWeight());
- }
-
- // SampleCategoryWeight
- if (copyIfNull
- && (source.getSampleCategoryWeight() == null || source
- .getWeight() == null)) {
- target.setSamplingRatio(null);
- target.setSamplingRatioText(null);
- } else if (source.getSampleCategoryWeight() != null
- && source.getWeight() != null) {
- String samplingRatioText = source.getSampleCategoryWeight() + "/"
- + source.getWeight();
- samplingRatioText = samplingRatioText.replaceAll(",", ".");
- target.setSamplingRatioText(samplingRatioText);
- target.setSamplingRatio(source.getSampleCategoryWeight()
- .floatValue() / source.getWeight().floatValue());
- }
-
- // Rank order
- if (copyIfNull && source.getNumber() == null) {
- target.setRankOrder(null);
- target.setFlatRankOrder(null);
- } else if (source.getNumber() != null) {
- target.setRankOrder(Short.valueOf(source.getNumber().toString()));
- }
-
- // Flat rank order
- target.setFlatRankOrder(target.getRankOrder());
-
- // Tree level
- if (parentBatchId == null) {
- // TODO BLA : à confirmer une fois l'arbre d'échantillonnage créé
- target.setTreeLevel((short) 2);
- } else {
- short treeLevel = 1;
- SpeciesBatch item = source;
- do {
- treeLevel++;
- item = item.getParentBatch();
- } while (item != null);
- target.setTreeLevel(treeLevel);
- }
-
- // Species
- if (copyIfNull && source.getSpecies() == null) {
- target.setReferenceTaxon(null);
- target.setInheritedReferenceTaxon(null);
- } else if (source.getSpecies() != null) {
- ReferenceTaxon referenceTaxon = load(ReferenceTaxonImpl.class,
- Integer.valueOf(source.getSpecies().getId()));
- if (source.getParentBatch() == null) {
- target.setReferenceTaxon(referenceTaxon);
- // TODO BLA : vérifier que sous Allegro on affecte aussi
- // inherited quand
- // une valeur non héritée a été saisie.
- target.setInheritedReferenceTaxon(referenceTaxon);
- } else {
- target.setInheritedReferenceTaxon(referenceTaxon);
- target.setReferenceTaxon(null);
- }
- }
-
- // QualityFlag (using SpeciesToConfirm)
- 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 (copyIfNull && source.getComment() == null) {
- target.setComments(null);
- } else if (source.getComment() != null) {
- target.setComments(source.getComment());
- }
-
- // Other mandatory properties :
- target.setIsLanding(false);
- target.setIsDiscard(false);
- }
-
public Integer getRootBatchId(Integer fishingOperationId) {
Integer catchBatchId = queryUniqueTyped("fishingOperationCatchBatch",
"fishingOperationId", IntegerType.INSTANCE, fishingOperationId);
return catchBatchId;
}
- protected QuantificationMeasurement setQuantificationMeasurement(
- Batch batch, Integer pmfmId, Integer recorderDepartmentId,
- Float weightValue, boolean isReferenceSorting) {
- QuantificationMeasurement quantificationMeasurement = getQuantificationMeasurement(
- batch, pmfmId, recorderDepartmentId, true);
- quantificationMeasurement.setNumericalValue(weightValue);
- quantificationMeasurement
- .setIsReferenceQuantification(isReferenceSorting);
- return quantificationMeasurement;
- }
-
- protected QuantificationMeasurement getQuantificationMeasurement(
- Batch batch, Integer pmfmId, Integer recorderDepartmentId,
- boolean createIfNotExists) {
- QuantificationMeasurement quantificationMeasurement = null;
- if (batch.getQuantificationMeasurements() != null) {
- for (Iterator iterator = batch
- .getQuantificationMeasurements().iterator(); iterator
- .hasNext();) {
- QuantificationMeasurement qm = (QuantificationMeasurement) iterator
- .next();
- if (pmfmId.equals(qm.getPmfm().getId())) {
- quantificationMeasurement = qm;
- break;
- }
- }
- }
- if (quantificationMeasurement == null) {
- if (!createIfNotExists) {
- return null;
- }
- quantificationMeasurement = QuantificationMeasurement.Factory
- .newInstance();
- quantificationMeasurement.setBatch(batch);
- if (batch.getQuantificationMeasurements() == null) {
- batch.setQuantificationMeasurements(Sets
- .newHashSet(quantificationMeasurement));
- } else {
- batch.getQuantificationMeasurements().add(
- quantificationMeasurement);
- }
- quantificationMeasurement.setQualityFlag(load(
- QualityFlagImpl.class,
- enumeration.QUALITY_FLAG_CODE_NOT_QUALIFIED));
- quantificationMeasurement.setDepartment(load(DepartmentImpl.class,
- recorderDepartmentId));
- quantificationMeasurement.setPmfm(load(PmfmImpl.class, pmfmId));
- }
-
- return quantificationMeasurement;
- }
-
- 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 = null;
- if (value instanceof Integer) {
- qvId = (Integer)value;
- }
- 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 = getSortingMeasurement(
- sortingBatch, pmfmId, recorderDepartmentId, true);
- setMeasurement(sortingMeasurement, caracteristic, value);
- return sortingMeasurement;
- }
-
- protected SortingMeasurement getSortingMeasurement(
- SortingBatch sortingBatch, Integer pmfmId, Integer recorderDepartmentId,
- boolean createIfNotExists) {
- SortingMeasurement sortingMeasurement = null;
- if (sortingBatch.getSortingMeasurements() != null) {
- for (Iterator iterator = sortingBatch
- .getSortingMeasurements().iterator(); iterator
- .hasNext();) {
- SortingMeasurement qm = (SortingMeasurement) iterator
- .next();
- if (pmfmId.equals(qm.getPmfm().getId())) {
- sortingMeasurement = qm;
- break;
- }
- }
- }
- if (sortingMeasurement == null) {
- if (!createIfNotExists) {
- return null;
- }
- sortingMeasurement = SortingMeasurement.Factory
- .newInstance();
- sortingMeasurement.setSortingBatch(sortingBatch);
- if (sortingBatch.getSortingMeasurements() == null) {
- sortingBatch.setSortingMeasurements(Sets
- .newHashSet(sortingMeasurement));
- sortingMeasurement.setRankOrder(1);
- } else {
- sortingBatch.getSortingMeasurements().add(
- sortingMeasurement);
- sortingMeasurement.setRankOrder(sortingBatch.getSortingMeasurements().size());
- }
- sortingMeasurement.setQualityFlag(load(
- QualityFlagImpl.class,
- enumeration.QUALITY_FLAG_CODE_NOT_QUALIFIED));
- sortingMeasurement.setDepartment(load(DepartmentImpl.class,
- recorderDepartmentId));
- sortingMeasurement.setPmfm(load(PmfmImpl.class, pmfmId));
- }
-
- 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;
- }
-
- protected SampleCategoryEnum pmfmId2SampleCategory(Integer pmfmId) {
- SampleCategoryEnum sampleCategory = null;
- if (pmfmId.intValue() == enumeration.PMFM_ID_SORTED_UNSORTED.intValue()) {
- sampleCategory = SampleCategoryEnum.sortedUnsorted;
- }
- else if (enumeration.PMFM_ID_SIZE_CATEGORY.equals(pmfmId)) {
- sampleCategory = SampleCategoryEnum.size;
- }
- else if (enumeration.PMFM_ID_MATURITY.equals(pmfmId)) {
- sampleCategory = SampleCategoryEnum.maturity;
- }
- else if (enumeration.PMFM_ID_SEX.equals(pmfmId)) {
- sampleCategory = SampleCategoryEnum.sex;
- }
- else if (enumeration.PMFM_ID_AGE.equals(pmfmId)) {
- sampleCategory = SampleCategoryEnum.age;
- }
- if (sampleCategory == null) {
- throw new IllegalArgumentException("Unable to find corresponding SampleCategoryEnum for PMFM.ID : " + pmfmId);
- }
- return sampleCategory;
- }
}
Modified: trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/service/TuttiEnumerationFile.java
===================================================================
--- trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/service/TuttiEnumerationFile.java 2013-01-30 17:17:46 UTC (rev 273)
+++ trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/service/TuttiEnumerationFile.java 2013-01-31 00:04:37 UTC (rev 274)
@@ -85,6 +85,9 @@
@Value("${PmfmId.MARINE_LITTER_SIZE_CATEGORY}")
public final Integer PMFM_ID_MARINE_LITTER_SIZE_CATEGORY = null;
+
+ @Value("${PmfmId.SCIENTIFIC_CRUISE_SORTING_TYPE}")
+ public final Integer PMFM_ID_SORTING_TYPE = null;
@Value("${UnitId.NONE}")
public final Integer UNIT_ID_NONE = null;
@@ -110,9 +113,18 @@
@Value("${LocationLevelId.RECTANGLE_STATISTIQUE}")
public final Integer RECTANGLE_STATISTIQUE = null;
- @Value("${QualitativeValueId.VRAC}")
+ @Value("${QualitativeValueId.SORTED_VRAC}")
public final Integer QUALITATIVE_VRAC_ID = null;
+ @Value("${QualitativeValueId.SORTED_HORS_VRAC}")
+ public final Integer QUALITATIVE_HORS_VRAC_ID = null;
+
+ @Value("${QualitativeValueId.UNSORTED}")
+ public final Integer QUALITATIVE_UNSORTED_ID = null;
+
+ @Value("${QualitativeValueId.SORTING_TYPE_SPECIES}")
+ public final Integer QUALITATIVE_ID_SORTING_TYPE_SPECIES= null;
+
@Value("${StatusCode.ENABLE}")
public final String STATUS_VALID_CODE = null;
Added: trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/service/measure/MeasurementPersistenceHelper.java
===================================================================
--- trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/service/measure/MeasurementPersistenceHelper.java (rev 0)
+++ trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/service/measure/MeasurementPersistenceHelper.java 2013-01-31 00:04:37 UTC (rev 274)
@@ -0,0 +1,345 @@
+package fr.ifremer.tutti.persistence.service.measure;
+
+import java.io.Serializable;
+import java.util.Iterator;
+
+import javax.annotation.Resource;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Sets;
+
+import fr.ifremer.adagio.core.dao.administration.user.DepartmentImpl;
+import fr.ifremer.adagio.core.dao.data.batch.Batch;
+import fr.ifremer.adagio.core.dao.data.batch.SortingBatch;
+import fr.ifremer.adagio.core.dao.data.measure.GearPhysicalMeasurement;
+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.survey.fishingTrip.FishingTrip;
+import fr.ifremer.adagio.core.dao.data.survey.scientificCruise.ScientificCruise;
+import fr.ifremer.adagio.core.dao.data.vessel.feature.physical.GearPhysicalFeatures;
+import fr.ifremer.adagio.core.dao.referential.QualityFlagDao;
+import fr.ifremer.adagio.core.dao.referential.QualityFlagImpl;
+import fr.ifremer.adagio.core.dao.referential.gear.GearImpl;
+import fr.ifremer.adagio.core.dao.referential.pmfm.Pmfm;
+import fr.ifremer.adagio.core.dao.referential.pmfm.PmfmImpl;
+import fr.ifremer.adagio.core.dao.referential.pmfm.QualitativeValue;
+import fr.ifremer.adagio.core.dao.referential.pmfm.QualitativeValueImpl;
+import fr.ifremer.tutti.persistence.entities.data.SampleCategoryEnum;
+import fr.ifremer.tutti.persistence.entities.referential.Caracteristic;
+import fr.ifremer.tutti.persistence.entities.referential.CaracteristicType;
+import fr.ifremer.tutti.persistence.service.AbstractPersistenceService;
+import fr.ifremer.tutti.persistence.service.ReferentialPersistenceService;
+import fr.ifremer.tutti.persistence.service.TuttiEnumerationFile;
+
+@Component("measurementPersistenceHelper")
+public class MeasurementPersistenceHelper extends AbstractPersistenceService {
+
+ @Autowired(required=true)
+ protected TuttiEnumerationFile enumeration;
+
+ @Resource(name = "referentialPersistenceService")
+ protected ReferentialPersistenceService referentialService;
+
+ @Resource(name = "qualityFlagDao")
+ protected QualityFlagDao qualityFlagDao;
+
+ public MeasurementPersistenceHelper() {
+ }
+
+ public QuantificationMeasurement setQuantificationMeasurement(
+ Batch batch, Integer pmfmId, Integer recorderDepartmentId,
+ Float weightValue, boolean isReferenceSorting) {
+ QuantificationMeasurement quantificationMeasurement = getQuantificationMeasurement(
+ batch, pmfmId, recorderDepartmentId, true);
+
+ quantificationMeasurement.setNumericalValue(weightValue);
+ quantificationMeasurement
+ .setIsReferenceQuantification(isReferenceSorting);
+ return quantificationMeasurement;
+ }
+
+ public QuantificationMeasurement getQuantificationMeasurement(
+ Batch batch, Integer pmfmId, Integer recorderDepartmentId,
+ boolean createIfNotExists) {
+ QuantificationMeasurement quantificationMeasurement = null;
+ if (batch.getQuantificationMeasurements() != null) {
+ for (Iterator iterator = batch
+ .getQuantificationMeasurements().iterator(); iterator
+ .hasNext();) {
+ QuantificationMeasurement qm = (QuantificationMeasurement) iterator
+ .next();
+ if (pmfmId.equals(qm.getPmfm().getId())) {
+ quantificationMeasurement = qm;
+ break;
+ }
+ }
+ }
+ if (quantificationMeasurement == null) {
+ if (!createIfNotExists) {
+ return null;
+ }
+ quantificationMeasurement = QuantificationMeasurement.Factory
+ .newInstance();
+ quantificationMeasurement.setBatch(batch);
+ if (batch.getQuantificationMeasurements() == null) {
+ batch.setQuantificationMeasurements(Sets
+ .newHashSet(quantificationMeasurement));
+ } else {
+ batch.getQuantificationMeasurements().add(
+ quantificationMeasurement);
+ }
+ quantificationMeasurement.setQualityFlag(load(
+ QualityFlagImpl.class,
+ enumeration.QUALITY_FLAG_CODE_NOT_QUALIFIED));
+ quantificationMeasurement.setDepartment(load(DepartmentImpl.class,
+ recorderDepartmentId));
+ quantificationMeasurement.setPmfm(load(PmfmImpl.class, pmfmId));
+ }
+
+ return quantificationMeasurement;
+ }
+
+ 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 = null;
+ if (value instanceof Integer) {
+ qvId = (Integer)value;
+ }
+ 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 = sampleCategory2PmfmId(sampleCategory);
+
+ Caracteristic caracteristic = referentialService.getCaracteristic(pmfmId);
+ SortingMeasurement sortingMeasurement = 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 = getSortingMeasurement(
+ sortingBatch, pmfmId, recorderDepartmentId, true);
+ setMeasurement(sortingMeasurement, caracteristic, value);
+ return sortingMeasurement;
+ }
+
+ public SortingMeasurement getSortingMeasurement(
+ SortingBatch sortingBatch, Integer pmfmId, Integer recorderDepartmentId,
+ boolean createIfNotExists) {
+ SortingMeasurement sortingMeasurement = null;
+ if (sortingBatch.getSortingMeasurements() != null) {
+ for (Iterator iterator = sortingBatch
+ .getSortingMeasurements().iterator(); iterator
+ .hasNext();) {
+ SortingMeasurement qm = (SortingMeasurement) iterator
+ .next();
+ if (pmfmId.equals(qm.getPmfm().getId())) {
+ sortingMeasurement = qm;
+ break;
+ }
+ }
+ }
+ if (sortingMeasurement == null) {
+ if (!createIfNotExists) {
+ return null;
+ }
+ sortingMeasurement = SortingMeasurement.Factory
+ .newInstance();
+ sortingMeasurement.setSortingBatch(sortingBatch);
+ if (sortingBatch.getSortingMeasurements() == null) {
+ sortingBatch.setSortingMeasurements(Sets
+ .newHashSet(sortingMeasurement));
+ sortingMeasurement.setRankOrder(1);
+ } else {
+ sortingBatch.getSortingMeasurements().add(
+ sortingMeasurement);
+ sortingMeasurement.setRankOrder(sortingBatch.getSortingMeasurements().size());
+ }
+ sortingMeasurement.setQualityFlag(load(
+ QualityFlagImpl.class,
+ enumeration.QUALITY_FLAG_CODE_NOT_QUALIFIED));
+ sortingMeasurement.setDepartment(load(DepartmentImpl.class,
+ recorderDepartmentId));
+ sortingMeasurement.setPmfm(load(PmfmImpl.class, pmfmId));
+ }
+
+ return sortingMeasurement;
+ }
+
+ public 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;
+ }
+
+ public SampleCategoryEnum pmfmId2SampleCategory(Integer pmfmId) {
+ SampleCategoryEnum sampleCategory = null;
+ if (pmfmId.intValue() == enumeration.PMFM_ID_SORTED_UNSORTED.intValue()) {
+ sampleCategory = SampleCategoryEnum.sortedUnsorted;
+ }
+ else if (enumeration.PMFM_ID_SIZE_CATEGORY.equals(pmfmId)) {
+ sampleCategory = SampleCategoryEnum.size;
+ }
+ else if (enumeration.PMFM_ID_MATURITY.equals(pmfmId)) {
+ sampleCategory = SampleCategoryEnum.maturity;
+ }
+ else if (enumeration.PMFM_ID_SEX.equals(pmfmId)) {
+ sampleCategory = SampleCategoryEnum.sex;
+ }
+ else if (enumeration.PMFM_ID_AGE.equals(pmfmId)) {
+ sampleCategory = SampleCategoryEnum.age;
+ }
+ if (sampleCategory == null) {
+ throw new IllegalArgumentException("Unable to find corresponding SampleCategoryEnum for PMFM.ID : " + pmfmId);
+ }
+ return sampleCategory;
+ }
+
+ public GearPhysicalFeatures getGearPhysicalfeatures(FishingTrip fishingTrip, Integer gearId) {
+ return getGearPhysicalfeatures(fishingTrip, gearId, false);
+ }
+
+ public GearPhysicalFeatures getGearPhysicalfeatures(FishingTrip fishingTrip, Integer gearId, boolean createIfNotExists) {
+ // Retrieve entities : Gear Physical Features
+ if (fishingTrip.getGearPhysicalFeatures() != null && fishingTrip.getGearPhysicalFeatures().size() >= 0) {
+ for (Iterator iterator = fishingTrip.getGearPhysicalFeatures().iterator(); iterator.hasNext();) {
+ GearPhysicalFeatures guf = (GearPhysicalFeatures) iterator.next();
+ if (gearId.equals(guf.getGear().getId())) {
+ return guf;
+ }
+ }
+ }
+ if (!createIfNotExists) {
+ return null;
+ }
+
+ GearPhysicalFeatures gearPhysicalFeature = GearPhysicalFeatures.Factory.newInstance();
+ gearPhysicalFeature.setFishingTrip(fishingTrip);
+
+ fr.ifremer.adagio.core.dao.referential.gear.Gear gear = (fr.ifremer.adagio.core.dao.referential.gear.Gear)getCurrentSession().load(GearImpl.class, gearId);
+ gearPhysicalFeature.setGear(gear);
+ if (fishingTrip.getGearPhysicalFeatures() == null) {
+ fishingTrip.setGearPhysicalFeatures(Lists.newArrayList(gearPhysicalFeature));
+ } else {
+ fishingTrip.getGearPhysicalFeatures().add(gearPhysicalFeature);
+ }
+
+ return gearPhysicalFeature;
+ }
+
+ public GearPhysicalMeasurement getGearPhysicalMeasurement(GearPhysicalFeatures gearPhysicalFeatures, Integer pmfmId) {
+ return getGearPhysicalMeasurement(null, gearPhysicalFeatures, pmfmId, false);
+ }
+
+ protected GearPhysicalMeasurement getGearPhysicalMeasurement(ScientificCruise scientificCruise, GearPhysicalFeatures gearPhysicalFeatures,
+ Integer pmfmId, boolean createIfNotExists) {
+ GearPhysicalMeasurement gearPhysicalMeasurement = null;
+ if (gearPhysicalFeatures.getGearPhysicalMeasurements() != null) {
+ for (Iterator iterator = gearPhysicalFeatures.getGearPhysicalMeasurements().iterator(); iterator.hasNext();) {
+ GearPhysicalMeasurement vum = (GearPhysicalMeasurement) iterator.next();
+ if (pmfmId.equals(vum.getPmfm().getId())) {
+ gearPhysicalMeasurement = vum;
+ break;
+ }
+ }
+ }
+ if (gearPhysicalMeasurement == null) {
+ if (!createIfNotExists) {
+ return null;
+ }
+ gearPhysicalMeasurement = GearPhysicalMeasurement.Factory.newInstance();
+ gearPhysicalMeasurement.setGearPhysicalFeatures(gearPhysicalFeatures);
+ if (gearPhysicalFeatures.getGearPhysicalMeasurements() == null) {
+ gearPhysicalFeatures.setGearPhysicalMeasurements(Lists.newArrayList(gearPhysicalMeasurement));
+ }
+ else {
+ gearPhysicalFeatures.getGearPhysicalMeasurements().add(gearPhysicalMeasurement);
+ }
+ gearPhysicalMeasurement.setQualityFlag(qualityFlagDao.load(enumeration.QUALITY_FLAG_CODE_NOT_QUALIFIED));
+ gearPhysicalMeasurement.setDepartment(scientificCruise.getRecorderDepartment());
+ Pmfm pmfm = (Pmfm)getCurrentSession().load(PmfmImpl.class, pmfmId);
+ gearPhysicalMeasurement.setPmfm(pmfm);
+ //gearPhysicalMeasurement.setPmfm(pmfmDao.load(pmfmId));
+ }
+
+ return gearPhysicalMeasurement;
+ }
+
+ public void removeGearPhysicalMeasurement(GearPhysicalFeatures gearPhysicalFeatures,
+ Integer pmfmId) {
+ GearPhysicalMeasurement gearPhysicalMeasurement = getGearPhysicalMeasurement(null, gearPhysicalFeatures, pmfmId, false);
+ if (gearPhysicalMeasurement == null) {
+ return;
+ }
+ gearPhysicalFeatures.getGearPhysicalMeasurements().remove(gearPhysicalMeasurement);
+ // TOBO BLa : vérifier qu'il ne faut pas dao.delete() en plus
+ }
+
+ public GearPhysicalMeasurement setGearPhysicalMeasurement(ScientificCruise scientificCruise, GearPhysicalFeatures gearPhysicalFeatures,
+ Integer pmfmId,
+ Float numericalValue,
+ String alphanumericalValue,
+ Integer qualitativevalueId) {
+ GearPhysicalMeasurement gearPhysicalMeasurement = getGearPhysicalMeasurement(scientificCruise, gearPhysicalFeatures, pmfmId, true);
+
+ if (alphanumericalValue != null) {
+ gearPhysicalMeasurement.setAlphanumericalValue(alphanumericalValue);
+ }
+ else if (numericalValue != null) {
+ gearPhysicalMeasurement.setNumericalValue(numericalValue);
+ }
+ else if (qualitativevalueId != null) {
+ QualitativeValue qv = (QualitativeValue)getCurrentSession().load(QualitativeValueImpl.class, qualitativevalueId);
+ gearPhysicalMeasurement.setQualitativeValue(qv);
+ //gearPhysicalMeasurement.setQualitativeValue(qualitativeValueDao.load(qualitativevalueId));
+ }
+
+ return gearPhysicalMeasurement;
+ }
+}
Added: trunk/tutti-persistence-adagio/src/main/resources/ehcache.xml
===================================================================
--- trunk/tutti-persistence-adagio/src/main/resources/ehcache.xml (rev 0)
+++ trunk/tutti-persistence-adagio/src/main/resources/ehcache.xml 2013-01-31 00:04:37 UTC (rev 274)
@@ -0,0 +1,62 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://ehcache.org/ehcache.xsd"
+ updateCheck="false">
+
+ <!-- Sets the path to the directory where cache .data files are created.
+
+ If the path is a Java System Property it is replaced by
+ its value in the running VM.
+
+ The following properties are translated:
+ user.home - User's home directory
+ user.dir - User's current working directory
+ java.io.tmpdir - Default temp file path -->
+ <diskStore path="java.io.tmpdir/ehcache"/>
+
+ <!--Default Cache configuration. These will applied to caches programmatically created through
+ the CacheManager.
+
+ The following attributes are required for defaultCache:
+
+ maxInMemory - Sets the maximum number of objects that will be created in memory
+ eternal - Sets whether elements are eternal. If eternal, timeouts are ignored and the element
+ is never expired.
+ timeToIdleSeconds - Sets the time to idle for an element before it expires.
+ i.e. The maximum amount of time between accesses before an element expires
+ Is only used if the element is not eternal.
+ Optional attribute. A value of 0 means that an Element can idle for infinity
+ timeToLiveSeconds - Sets the time to live for an element before it expires.
+ i.e. The maximum time between creation time and when an element expires.
+ Is only used if the element is not eternal.
+ overflowToDisk - Sets whether elements can overflow to disk when the in-memory cache
+ has reached the maxInMemory limit.
+
+ -->
+ <defaultCache
+ maxElementsInMemory="10000"
+ eternal="false"
+ timeToIdleSeconds="120"
+ timeToLiveSeconds="120"
+ overflowToDisk="true" />
+
+ <!-- memoryStoreEvictionPolicy :
+ LRU - least recently used
+ LFU - least frequently used
+ FIFO - first in first out, the oldest element by creation time
+ -->
+ <cache name="allFishingVessel" eternal="true"
+ maxElementsInMemory="1"
+ memoryStoreEvictionPolicy="LFU"/>
+
+ <cache name="org.hibernate.cache.UpdateTimestampsCache"
+ maxElementsInMemory="5000" timeToIdleSeconds="300"
+ timeToLiveSeconds="300" overflowToDisk="true" diskPersistent="false"
+ diskExpiryThreadIntervalSeconds="300" memoryStoreEvictionPolicy="LRU" />
+
+ <cache name="org.hibernate.cache.StandardQueryCache"
+ maxElementsInMemory="10000" eternal="false" timeToIdleSeconds="300"
+ timeToLiveSeconds="300" overflowToDisk="true" diskPersistent="false"
+ diskExpiryThreadIntervalSeconds="300" memoryStoreEvictionPolicy="LRU" />
+
+</ehcache>
\ No newline at end of file
Modified: trunk/tutti-persistence-adagio/src/main/resources/queries-override.hbm.xml
===================================================================
--- trunk/tutti-persistence-adagio/src/main/resources/queries-override.hbm.xml 2013-01-30 17:17:46 UTC (rev 273)
+++ trunk/tutti-persistence-adagio/src/main/resources/queries-override.hbm.xml 2013-01-31 00:04:37 UTC (rev 274)
@@ -278,16 +278,76 @@
<query-param name="catchBatchId" type="java.lang.Integer"/>
</query>
- <query cacheable="true" name="fishingOperationCatchBatch">
+ <query cacheable="true" name="catchBatch">
<![CDATA[
SELECT
- cb.id
+ cb.id AS catchBatchId,
+ cbQm.numericalValue as totalWeight,
+ b1.id AS id1,
+ b1.samplingRatioText as samplingRatioText1,
+ (select qm.numericalValue from QuantificationMeasurementImpl qm where qm.batch.id=b1.id and qm.isReferenceQuantification=true) AS weight1,
+ (select sm.qualitativeValue.id from SortingMeasurementImpl sm where sm.sortingBatch.id=b1.id and sm.pmfm.id=:pmfmIdSorted) AS qv2,
+ b2.id AS id2,
+ b2.samplingRatioText AS samplingRatioText2,
+ (select qm.numericalValue from QuantificationMeasurementImpl qm where qm.batch.id=b2.id and qm.isReferenceQuantification=true) AS weight2,
+ (select sm.qualitativeValue.id from SortingMeasurementImpl sm where sm.sortingBatch.id=b2.id and sm.pmfm.id=:pmfmIdSortingType) AS qv2
FROM
CatchBatchImpl cb
+ INNER JOIN cb.childBatchs b1
+ LEFT OUTER JOIN b1.childBatchs b2
+ LEFT OUTER JOIN cb.quantificationMeasurements cbQm
WHERE
cb.fishingOperation.id = :fishingOperationId
+ AND (
+ cbQm is null
+ OR cbQm.isReferenceQuantification=true
+ )
+ ORDER BY b1.id, b2.id
]]>
+ <!-- Other equivalente query (but slower)
+ SELECT
+ cb.id AS catchBatchId,
+ cbQm.numericalValue as totalWeight,
+ b1.id AS id1,
+ b1.samplingRatioText as samplingRatioText1,
+ qm2.numericalValue AS weight1,
+ sm1.qualitativeValue.id AS qv2,
+ b2.id AS id2,
+ b2.samplingRatioText AS samplingRatioText2,
+ qm1.numericalValue AS weight2,
+ sm2.qualitativeValue.id AS qv2
+ FROM
+ CatchBatchImpl cb
+ INNER JOIN cb.childBatchs b1
+ INNER JOIN b1.childBatchs b2
+ LEFT OUTER JOIN cb.quantificationMeasurements cbQm
+ LEFT OUTER JOIN b1.quantificationMeasurements qm1
+ LEFT OUTER JOIN b2.quantificationMeasurements qm2,
+ SortingMeasurementImpl sm1,
+ SortingMeasurementImpl sm2
+ WHERE
+ cb.fishingOperation.id = :fishingOperationId
+ AND (
+ cbQm is null
+ OR cbQm.isReferenceQuantification=true
+ )
+ AND sm1.sortingBatch.id=b1.id
+ AND sm1.pmfm.id=:pmfmIdSorted
+ AND (
+ qm2 is null
+ OR qm2.isReferenceQuantification=true
+ )
+ AND sm2.sortingBatch.id=b2.id
+ AND sm2.pmfm.id=:pmfmIdSortingType
+ AND (
+ qm1 is null
+ OR qm1.isReferenceQuantification=true
+ )
+ ORDER BY b1.id, b2.id
+ -->
<query-param name="fishingOperationId" type="java.lang.Integer"/>
+ <query-param name="pmfmIdSorted" type="java.lang.Integer"/>
+ <query-param name="pmfmIdSortingType" type="java.lang.Integer"/>
</query>
<!--query cacheable="true" name="allFishingOperationBatchs">
@@ -714,10 +774,14 @@
<!--</fetch-profile>-->
<fetch-profile name="batch-with-measurements">
+ <fetch entity="BatchImpl" association="quantificationMeasurements" style="join"/>
<fetch entity="CatchBatchImpl" association="quantificationMeasurements" style="join"/>
<fetch entity="SortingBatchImpl" association="sortingMeasurements" style="join"/>
<fetch entity="SortingBatchImpl" association="quantificationMeasurements" style="join"/>
</fetch-profile>
+ <fetch-profile name="batch-with-childs">
+ <fetch entity="BatchImpl" association="childBatchs" style="join"/>
+ </fetch-profile>
</hibernate-mapping>
Modified: trunk/tutti-persistence-adagio/src/main/resources/tutti-db-enumerations.properties
===================================================================
--- trunk/tutti-persistence-adagio/src/main/resources/tutti-db-enumerations.properties 2013-01-30 17:17:46 UTC (rev 273)
+++ trunk/tutti-persistence-adagio/src/main/resources/tutti-db-enumerations.properties 2013-01-31 00:04:37 UTC (rev 274)
@@ -317,7 +317,6 @@
PmfmId.SEX=196
PmfmId.SIZE_CATEGORY=198
-PmfmId.SORTED_UNSORTED=200
PmfmId.AGE=1430
# Catégorie maturité
@@ -352,6 +351,21 @@
# PSFM "Poids - observation par une observateur" (écran captures, onglet espèce, benthos, etc)
PmfmId.WEIGHT_MEASURED=220
+# TODO A creer (dans les enumerations Allegro)
+# PSFM "Vaac/Hors Vrac" - "Organisation des données campagnes"
+PmfmId.SORTED_UNSORTED=1428
+QualitativeValueId.SORTED_VRAC=311
+QualitativeValueId.SORTED_HORS_VRAC=310
+QualitativeValueId.UNSORTED=2146
+
+PmfmId.SCIENTIFIC_CRUISE_SORTING_TYPE=1429
+QualitativeValueId.SORTING_TYPE_SPECIES=2147
+QualitativeValueId.SORTING_TYPE_BENTHOS=2148
+QualitativeValueId.SORTING_TYPE_PLANCTON=2149
+QualitativeValueId.SORTING_TYPE_MACRO_WASTE=2150
+QualitativeValueId.SORTING_TYPE_ACCIDENTAL_CATCH=2151
+
+
#TODO A creer (dans les enumerations Allegro)
# (20=observateur volant, 95=Administrateur SIH) -> L'avantage du 20 est qu'il est inactif (=20), donc plus facilement detectable
PersonId.UNKNOWN_RECORDER_PERSON=20
Modified: trunk/tutti-persistence-adagio/src/test/java/fr/ifremer/tutti/persistence/service/CatchBatchPersistenceServiceImplTest.java
===================================================================
--- trunk/tutti-persistence-adagio/src/test/java/fr/ifremer/tutti/persistence/service/CatchBatchPersistenceServiceImplTest.java 2013-01-30 17:17:46 UTC (rev 273)
+++ trunk/tutti-persistence-adagio/src/test/java/fr/ifremer/tutti/persistence/service/CatchBatchPersistenceServiceImplTest.java 2013-01-31 00:04:37 UTC (rev 274)
@@ -24,7 +24,19 @@
* #L%
*/
+import static org.junit.Assert.*;
+
+import java.util.Calendar;
+import java.util.Date;
+import java.util.GregorianCalendar;
+import java.util.List;
+
import fr.ifremer.tutti.persistence.DatabaseResource;
+import fr.ifremer.tutti.persistence.entities.data.CatchBatch;
+import fr.ifremer.tutti.persistence.entities.data.Cruise;
+import fr.ifremer.tutti.persistence.entities.data.FishingOperation;
+import fr.ifremer.tutti.persistence.entities.referential.Species;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Before;
@@ -46,9 +58,47 @@
protected CatchBatchPersistenceService service;
+ protected CruisePersistenceService cruiseService;
+ protected FishingOperationPersistenceService fishingOperationService;
+ protected ReferentialPersistenceService referentialService;
+
+ protected Cruise cruise;
+ protected FishingOperation fishingOperation;
+ protected List<Species> species;
+
@Before
public void setUp() throws Exception {
service = TuttiPersistenceServiceLocator.getCatchBatchPersistenceService();
+ cruiseService = TuttiPersistenceServiceLocator.getCruisePersistenceService();
+ fishingOperationService = TuttiPersistenceServiceLocator.getFishingOperationPersistenceService();
+ referentialService = TuttiPersistenceServiceLocator.getReferentialPersistenceService();
+
+ cruise = cruiseService.getCruise(dbResource.getFixtures().cruiseId());
+ cruise.setId(null);
+ Calendar calendar = new GregorianCalendar();
+ cruise.setBeginDate(calendar.getTime());
+ cruise.setYear(calendar.get(Calendar.YEAR));
+ calendar.add(Calendar.MONTH, 1); // add one month
+ cruise.setEndDate(calendar.getTime());
+ cruise = cruiseService.createCruise(cruise);
+
+ List<FishingOperation> fishingOperations = fishingOperationService.getAllFishingOperation(dbResource.getFixtures().cruiseId());
+ assertNotNull(fishingOperations);
+ assertTrue(fishingOperations.size() > 0);
+ fishingOperation = fishingOperations.get(0);
+ fishingOperation = fishingOperationService.getFishingOperation(fishingOperation.getId());
+ fishingOperation.setId(null);
+ fishingOperation.setCruise(cruise);
+ calendar.setTime(new Date());
+ calendar.set(Calendar.HOUR_OF_DAY, 1);
+ calendar.set(Calendar.MILLISECOND, 0);
+ fishingOperation.setGearShootingStartDate(calendar.getTime());
+ calendar.setTime(new Date());
+ calendar.set(Calendar.HOUR_OF_DAY, 10);
+ calendar.set(Calendar.MILLISECOND, 0);
+ fishingOperation.setGearShootingEndDate(calendar.getTime());
+
+ fishingOperation = fishingOperationService.createFishingOperation(fishingOperation);
}
@Test
@@ -57,14 +107,98 @@
//TODO
}
- @Test
- public void createCatchBatch() throws Exception {
- //TODO
- }
+ @Test
+ public void createAndSaveCatchBatch() throws Exception {
+ CatchBatch catchBatch = null;
+ CatchBatch createdCatchBatch = null;
+ CatchBatch reloadedCatchBatch = null;
+
+ catchBatch = new CatchBatch();
+ catchBatch.setFishingOperation(fishingOperation);
+
+ // -----------------------------------------------------------------------------
+ // 1. Test with only mandatory properties
+ // -----------------------------------------------------------------------------
- @Test
- public void saveCatchBatch() throws Exception {
+ // Create and reload (test round trip)
+ createdCatchBatch = service.createCatchBatch(catchBatch);
+ assertNotNull(createdCatchBatch);
+ assertNotNull(createdCatchBatch.getId());
+
+ reloadedCatchBatch = service.getCatchBatchFromFishingOperation(fishingOperation.getId());
+ assertNotNull(reloadedCatchBatch);
+ assertEquals(createdCatchBatch.getId(), reloadedCatchBatch.getId());
+
+ // -----------------------------------------------------------------------------
+ // 2. Test with all properties
+ // -----------------------------------------------------------------------------
+ catchBatch.setId(null);
+ // total weight : 100kg
+ catchBatch.setCatchTotalWeight(75f);
+ // Vrac :
+ {
+ // note : poids trie par la balance tremis (thalassa) (init par pupitri)
+ catchBatch.setCatchTotalSortedTremisWeight(50f);
+ // note : poids vrac caroussel (thalassa) (init par pupitri) (vrac trie) ou bien "poids trié fournie par la table de tri (Sum(Si)
+ catchBatch.setCatchTotalSortedCarousselWeight(45f);
+
+ // Species
+ {
+ catchBatch.setSpeciesTotalSortedWeight(12f);
+ catchBatch.setSpeciesTotalSampleSortedWeight(8f);
+ }
+ }
+ // Hors Vrac : 10kg
+ {
+ catchBatch.setCatchTotalUnsortedWeight(10f);
+
+ // Species
+ {
+ catchBatch.setSpeciesTotalUnsortedWeight(10f);
+ }
+ }
+ // Rejet : 15kg
+ catchBatch.setCatchTotalRejectedWeight(15f);
- //TODO
+ // Create and reload (test round trip)
+ createdCatchBatch = service.createCatchBatch(catchBatch);
+ assertNotNull(createdCatchBatch);
+ assertNotNull(createdCatchBatch.getId());
+
+ reloadedCatchBatch = service.getCatchBatchFromFishingOperation(fishingOperation.getId());
+ assertNotNull(reloadedCatchBatch);
+ assertEquals(createdCatchBatch.getCatchTotalWeight(), reloadedCatchBatch.getCatchTotalWeight());
+ assertEquals(createdCatchBatch.getCatchTotalSortedCarousselWeight(), reloadedCatchBatch.getCatchTotalSortedCarousselWeight());
+ assertEquals(createdCatchBatch.getCatchTotalSortedTremisWeight(), reloadedCatchBatch.getCatchTotalSortedTremisWeight());
+ assertEquals(createdCatchBatch.getCatchTotalUnsortedWeight(), reloadedCatchBatch.getCatchTotalUnsortedWeight());
+
+ assertEquals(createdCatchBatch.getSpeciesTotalSampleSortedWeight(), reloadedCatchBatch.getSpeciesTotalSampleSortedWeight());
+ assertEquals(createdCatchBatch.getSpeciesTotalSortedWeight(), reloadedCatchBatch.getSpeciesTotalSortedWeight());
+ assertEquals(createdCatchBatch.getSpeciesTotalUnsortedWeight(), reloadedCatchBatch.getSpeciesTotalUnsortedWeight());
+
+ // -----------------------------------------------------------------------------
+ // 2. Test save after modification
+ // -----------------------------------------------------------------------------
+ catchBatch.setCatchTotalSortedTremisWeight(null);
+ catchBatch.setCatchTotalSortedCarousselWeight(null);
+ catchBatch.setSpeciesTotalSortedWeight(null);
+ catchBatch.setSpeciesTotalSampleSortedWeight(null);
+ catchBatch.setCatchTotalUnsortedWeight(null);
+ catchBatch.setSpeciesTotalUnsortedWeight(null);
+ CatchBatch savedCatchBatch = service.saveCatchBatch(catchBatch);
+ assertNotNull(savedCatchBatch);
+ assertNotNull(savedCatchBatch.getId());
+
+ reloadedCatchBatch = service.getCatchBatchFromFishingOperation(fishingOperation.getId());
+ assertNotNull(reloadedCatchBatch);
+ assertEquals(createdCatchBatch.getCatchTotalWeight(), reloadedCatchBatch.getCatchTotalWeight());
+ assertEquals(createdCatchBatch.getCatchTotalSortedCarousselWeight(), reloadedCatchBatch.getCatchTotalSortedCarousselWeight());
+ assertEquals(createdCatchBatch.getCatchTotalSortedTremisWeight(), reloadedCatchBatch.getCatchTotalSortedTremisWeight());
+ assertEquals(createdCatchBatch.getCatchTotalUnsortedWeight(), reloadedCatchBatch.getCatchTotalUnsortedWeight());
+
+ assertEquals(createdCatchBatch.getSpeciesTotalSampleSortedWeight(), reloadedCatchBatch.getSpeciesTotalSampleSortedWeight());
+ assertEquals(createdCatchBatch.getSpeciesTotalSortedWeight(), reloadedCatchBatch.getSpeciesTotalSortedWeight());
+ assertEquals(createdCatchBatch.getSpeciesTotalUnsortedWeight(), reloadedCatchBatch.getSpeciesTotalUnsortedWeight());
}
+
}
Modified: trunk/tutti-persistence-adagio/src/test/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceTest.java
===================================================================
--- trunk/tutti-persistence-adagio/src/test/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceTest.java 2013-01-30 17:17:46 UTC (rev 273)
+++ trunk/tutti-persistence-adagio/src/test/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceTest.java 2013-01-31 00:04:37 UTC (rev 274)
@@ -47,6 +47,7 @@
* @author tchemit <chemit(a)codelutin.com>
* @since 0.3
*/
+@Ignore
public class SpeciesBatchPersistenceServiceTest {
@ClassRule
1
0
r273 - trunk/tutti-persistence-adagio/src/test/java/fr/ifremer/tutti/persistence/service
by blavenier@users.forge.codelutin.com 30 Jan '13
by blavenier@users.forge.codelutin.com 30 Jan '13
30 Jan '13
Author: blavenier
Date: 2013-01-30 18:17:46 +0100 (Wed, 30 Jan 2013)
New Revision: 273
Url: http://forge.codelutin.com/projects/tutti/repository/revisions/273
Log:
Ignore one TU
Modified:
trunk/tutti-persistence-adagio/src/test/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceServiceTest.java
Modified: trunk/tutti-persistence-adagio/src/test/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceServiceTest.java
===================================================================
--- trunk/tutti-persistence-adagio/src/test/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceServiceTest.java 2013-01-30 17:13:52 UTC (rev 272)
+++ trunk/tutti-persistence-adagio/src/test/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceServiceTest.java 2013-01-30 17:17:46 UTC (rev 273)
@@ -95,6 +95,7 @@
}
@Test
+ @Ignore
public void createFishingOperation(/*FishingOperation bean*/) {
// -----------------------------------------------------------------------------
// Prepare data and other entities
1
0
r272 - in trunk/tutti-persistence-adagio/src: main/java/fr/ifremer/tutti/persistence/config main/java/fr/ifremer/tutti/persistence/service main/resources test/java/fr/ifremer/tutti/persistence/service
by blavenier@users.forge.codelutin.com 30 Jan '13
by blavenier@users.forge.codelutin.com 30 Jan '13
30 Jan '13
Author: blavenier
Date: 2013-01-30 18:13:52 +0100 (Wed, 30 Jan 2013)
New Revision: 272
Url: http://forge.codelutin.com/projects/tutti/repository/revisions/272
Log:
ref refs #1920: [Persistence] Adagio Donnees thematiques
- Add cache on getAllFishingVessels
- Add persistence for program
- Fix TU on Cruise and FishingOperation
Modified:
trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/config/TuttiPersistenceAdagioConfig.java
trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/service/CruisePersistenceServiceImpl.java
trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceServiceImpl.java
trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/service/ProgramPersistenceServiceImpl.java
trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceServiceImpl.java
trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/service/TuttiEnumerationFile.java
trunk/tutti-persistence-adagio/src/main/resources/queries-override.hbm.xml
trunk/tutti-persistence-adagio/src/main/resources/tutti-db-enumerations.properties
trunk/tutti-persistence-adagio/src/test/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceServiceTest.java
trunk/tutti-persistence-adagio/src/test/java/fr/ifremer/tutti/persistence/service/ProgramPersistenceServiceTest.java
Modified: trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/config/TuttiPersistenceAdagioConfig.java
===================================================================
--- trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/config/TuttiPersistenceAdagioConfig.java 2013-01-30 15:26:14 UTC (rev 271)
+++ trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/config/TuttiPersistenceAdagioConfig.java 2013-01-30 17:13:52 UTC (rev 272)
@@ -112,7 +112,7 @@
}
public boolean isDbExists() {
- File f = new File(getDbDirectory(), getDbName() + ".data");
+ File f = new File(getDbDirectory(), /*TODO TC getDbName() not working*/"allegro" + ".data");
return f.exists();
}
Modified: trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/service/CruisePersistenceServiceImpl.java
===================================================================
--- trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/service/CruisePersistenceServiceImpl.java 2013-01-30 15:26:14 UTC (rev 271)
+++ trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/service/CruisePersistenceServiceImpl.java 2013-01-30 17:13:52 UTC (rev 272)
@@ -42,6 +42,7 @@
import org.springframework.dao.DataRetrievalFailureException;
import org.springframework.stereotype.Service;
+import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
import fr.ifremer.adagio.core.dao.administration.user.PersonDao;
@@ -147,7 +148,9 @@
"countryLocationLevelId", IntegerType.INSTANCE, enumeration.LOCATION_LEVEL_ID_COUNTRY);
if (source == null) {
- throw new DataRetrievalFailureException("Could not retrieve cruise with id=" + id);
+ return null;
+ // TODo TC : manage exception in the UI ?
+ //throw new DataRetrievalFailureException("Could not retrieve cruise with id=" + id);
}
Cruise result = new Cruise();
result.setId(id);
@@ -275,6 +278,9 @@
@Override
public Cruise createCruise(Cruise bean) {
+ Preconditions.checkNotNull(bean);
+ Preconditions.checkArgument(bean.getId() == null, "Cruise 'id' must be null to call createCruise().");
+
ScientificCruise scientificCruise = ScientificCruise.Factory.newInstance();
cruiseToEntity(bean, scientificCruise, true);
scientificCruiseDao.create(scientificCruise);
@@ -285,15 +291,17 @@
@Override
public Cruise saveCruise(Cruise bean) {
- if (bean.getId() == null || bean.getId().isEmpty()) {
- throw new IllegalArgumentException("Cruise 'id' must not be null or empty to be saved.");
- }
+ Preconditions.checkNotNull(bean);
+ Preconditions.checkNotNull(bean.getId(), "Cruise 'id' must not be null or empty to be saved.");
+
ScientificCruise scientificCruise = scientificCruiseDao.load(Integer.valueOf(bean.getId()));
if (scientificCruise == null) {
throw new DataRetrievalFailureException("Could not retrieve cruise with id=" + bean.getId());
}
cruiseToEntity(bean, scientificCruise, true);
+ scientificCruiseDao.update(scientificCruise);
+
return bean;
}
Modified: trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceServiceImpl.java
===================================================================
--- trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceServiceImpl.java 2013-01-30 15:26:14 UTC (rev 271)
+++ trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceServiceImpl.java 2013-01-30 17:13:52 UTC (rev 272)
@@ -127,7 +127,9 @@
Iterator<Object[]> list = queryList(
"allFishingOperations",
- "cruiseId", IntegerType.INSTANCE, Integer.valueOf(cruiseId)
+ "cruiseId", IntegerType.INSTANCE, Integer.valueOf(cruiseId),
+ "pmfmIdStationNumber", IntegerType.INSTANCE, enumeration.PMFM_ID_STATION_NUMBER,
+ "pmfmIdMultirigAggregation", IntegerType.INSTANCE, enumeration.PMFM_ID_MULTIRIG_AGGREGATION
);
List<FishingOperation> fishingOperations = new ArrayList<FishingOperation>();
@@ -177,10 +179,10 @@
fishingOperation.setStationNumber(stationNumber);
}
- // Trawl number net
- String trawlNetNumber = (String)source[colIndex++];
- if (trawlNetNumber != null) {
- fishingOperation.setMultirigAggregation(trawlNetNumber);
+ // Multirig Aggregation
+ String multirigAggregation = (String)source[colIndex++];
+ if (multirigAggregation != null) {
+ fishingOperation.setMultirigAggregation(multirigAggregation);
}
fishingOperations.add(fishingOperation);
@@ -359,7 +361,10 @@
getCurrentSession().clear();
getCurrentSession().setFlushMode(FlushMode.COMMIT);
fr.ifremer.adagio.core.dao.data.operation.FishingOperation fishingOperation = fishingOperationDao.load(Integer.valueOf(bean.getId()));
- beanToEntity(bean, fishingOperation, true);
+ if (fishingOperation == null) {
+ throw new DataRetrievalFailureException("Could not retrieve fishing operation with id="+bean.getId());
+ }
+ beanToEntity(bean, fishingOperation, true);
fishingOperationDao.update(fishingOperation);
getCurrentSession().flush();
return bean;
@@ -583,12 +588,12 @@
target.setCatchBatch(catchBatch);
}*/
- // Retrieve trawl net, from Gear physical features
- int trawlNet = 1; // default value
- GearPhysicalMeasurement gpmTrawlNet = measurementService.getGearPhysicalMeasurement(gearPhysicalFeatures, enumeration.PMFM_ID_MULTIRIG_NUMBER);
- if (gpmTrawlNet != null && gpmTrawlNet.getNumericalValue() != null) {
- trawlNet = gpmTrawlNet.getNumericalValue().intValue();
- }
+ // Retrieve multirig number, from Gear physical features
+ int cruiseMultirigCount = 1; // default value
+ GearPhysicalMeasurement gpmMultirigCount = measurementService.getGearPhysicalMeasurement(gearPhysicalFeatures, enumeration.PMFM_ID_MULTIRIG_NUMBER);
+ if (gpmMultirigCount != null && gpmMultirigCount.getNumericalValue() != null) {
+ cruiseMultirigCount = gpmMultirigCount.getNumericalValue().intValue();
+ }
// StationNumber
if (copyIfNull && source.getStationNumber() == null) {
@@ -606,16 +611,23 @@
}
target.setName(nameBuffer.toString());
- // Trawl net number
+ // Multirig Aggregation
if (copyIfNull && source.getMultirigAggregation() == null) {
// Nothing to do : will be removed later, using notChangedGearUseMeasurements
} else if (source.getMultirigAggregation() != null) {
- // TODO BLA : Then parse the String and validate content
-// if (source.getMultirigAggregation() > multirigNumber) {
-// throw new DataIntegrityViolationException("An operation could not have a 'trawl net number' greater than 'trawl net' defined in the cruise.");
-// }
+ if (source.getMultirigAggregation().matches("\\d+")) {
+ int mutlirigNumber = Integer.valueOf(source.getMultirigAggregation());
+ if (mutlirigNumber > cruiseMultirigCount) {
+ throw new DataIntegrityViolationException("An operation could not have a 'multirig number' greater than 'multirig count' defined in the cruise.");
+ }
+ }
+ else {
+ // TODO BLA : Then parse the String when more than one number (ie "1,3")
+ // then and validate content
+ }
+
// Store into Gear Use Features
- GearUseMeasurement gum = setGearUseMeasurement(scientificCruise, gearUseFeatures, enumeration.PMFM_ID_MULTIRIG_AGGREGATION, null, source.getMultirigAggregation().toString(), null);
+ GearUseMeasurement gum = setGearUseMeasurement(scientificCruise, gearUseFeatures, enumeration.PMFM_ID_MULTIRIG_AGGREGATION, null, source.getMultirigAggregation(), null);
notChangedGearUseMeasurements.remove(gum);
}
@@ -1098,6 +1110,9 @@
}
protected void setMeasurement(Measurement measurement, Caracteristic caracteristic, Serializable value) {
+ if (value == null) {
+ return;
+ }
if (caracteristic.getCaracteristicType() == CaracteristicType.TEXT) {
measurement.setAlphanumericalValue((String)value);
}
Modified: trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/service/ProgramPersistenceServiceImpl.java
===================================================================
--- trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/service/ProgramPersistenceServiceImpl.java 2013-01-30 15:26:14 UTC (rev 271)
+++ trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/service/ProgramPersistenceServiceImpl.java 2013-01-30 17:13:52 UTC (rev 272)
@@ -24,17 +24,35 @@
* #L%
*/
+import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
+
+import fr.ifremer.adagio.core.dao.administration.programStrategy.ProgramDao;
+import fr.ifremer.adagio.core.dao.data.survey.scientificCruise.ScientificCruiseDao;
+import fr.ifremer.adagio.core.dao.referential.gear.GearClassificationImpl;
+import fr.ifremer.adagio.core.dao.referential.location.Location;
+import fr.ifremer.adagio.core.dao.referential.location.LocationDao;
+import fr.ifremer.adagio.core.dao.referential.taxon.TaxonGroupTypeImpl;
+import fr.ifremer.tutti.persistence.entities.data.CatchBatch;
import fr.ifremer.tutti.persistence.entities.data.Program;
import fr.ifremer.tutti.persistence.entities.referential.Zone;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.hibernate.type.IntegerType;
import org.hibernate.type.StringType;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.dao.DataIntegrityViolationException;
+import org.springframework.dao.DataRetrievalFailureException;
import org.springframework.stereotype.Service;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.GregorianCalendar;
import java.util.Iterator;
import java.util.List;
+import javax.annotation.Resource;
+
/**
* @author tchemit <chemit(a)codelutin.com>
* @since 0.3
@@ -45,10 +63,27 @@
/** Logger. */
private static final Log log =
LogFactory.getLog(ProgramPersistenceServiceImpl.class);
+
+ @Autowired(required = true)
+ protected ReferentialPersistenceService referentialService;
+ @Resource(name = "programDao")
+ protected ProgramDao programDao;
+
+ @Resource(name = "locationDao")
+ protected LocationDao locationDao;
+
+ protected final int maxCodeLengthInDatabase = 40;
+
@Override
public List<Program> getAllProgram() {
- Iterator<Object[]> list = queryList("allPrograms");
+ String codePattern = "%";
+ if (enumeration.PROGRAM_CODE_SCIENTIFIC_CRUISE_PREFIX != null) {
+ codePattern = enumeration.PROGRAM_CODE_SCIENTIFIC_CRUISE_PREFIX + codePattern;
+ }
+ Iterator<Object[]> list = queryList("allPrograms",
+ "codePattern", StringType.INSTANCE, codePattern
+ );
List<Program> result = Lists.newArrayList();
while (list.hasNext()) {
@@ -56,6 +91,7 @@
Program target = new Program();
target.setId((String) source[0]);
target.setName((String) source[1]);
+ target.setComment((String) source[2]);
result.add(target);
}
return result;
@@ -72,6 +108,7 @@
Program result = new Program();
result.setId((String) source[0]);
result.setName((String) source[1]);
+ result.setComment((String) source[2]);
// get program locations
Iterator<Object[]> list = queryList(
@@ -96,11 +133,128 @@
@Override
public Program createProgram(Program bean) {
- throw new UnsupportedOperationException();
+ Preconditions.checkNotNull(bean);
+ Preconditions.checkNotNull(bean.getName());
+ Preconditions.checkArgument(bean.getId() == null);
+
+ fr.ifremer.adagio.core.dao.administration.programStrategy.Program program = fr.ifremer.adagio.core.dao.administration.programStrategy.Program.Factory.newInstance();
+ beanToEntity(bean, program, true);
+ program = programDao.create(program);
+ bean.setId(String.valueOf(program.getCode()));
+
+ return bean;
}
@Override
public Program saveProgram(Program bean) {
- throw new UnsupportedOperationException();
+ Preconditions.checkNotNull(bean);
+ Preconditions.checkNotNull(bean.getName());
+ Preconditions.checkNotNull(bean.getId());
+
+ fr.ifremer.adagio.core.dao.administration.programStrategy.Program program = programDao.load(bean.getId());
+ if (program == null) {
+ throw new DataRetrievalFailureException("Could not retrieve program with code=" + bean.getId());
+ }
+
+ beanToEntity(bean, program, true);
+ programDao.update(program);
+
+ return bean;
}
+
+ // ------------------------------------------------------------------------//
+ // -- Internal methods --//
+ // ------------------------------------------------------------------------//
+ protected void beanToEntity(Program source,
+ fr.ifremer.adagio.core.dao.administration.programStrategy.Program target,
+ boolean copyIfNull) {
+
+ // Code : compute with : <prefixe><name>
+ if (target.getCode() == null && source.getName() != null) {
+ // Compute a program code (remove spaces, and capitalize the name)
+ String programCode = source.getName().toUpperCase().replaceAll(" ", "_");
+ // Add a prefix
+ if (enumeration.PROGRAM_CODE_SCIENTIFIC_CRUISE_PREFIX != null) {
+ programCode = enumeration.PROGRAM_CODE_SCIENTIFIC_CRUISE_PREFIX + programCode;
+ }
+ // Trunc the code if too long
+ if (programCode.length() > maxCodeLengthInDatabase) {
+ programCode = programCode.substring(0, maxCodeLengthInDatabase-1);
+ }
+ target.setCode(programCode);
+
+ // Mandatory properties :
+ // Gear classification :
+ target.setGearClassification(load(GearClassificationImpl.class, enumeration.GEAR_CLASSIFICIATION_ID_SCIENTIFIC));
+
+ // taxon group type
+ target.setTaxonGroupType(load(TaxonGroupTypeImpl.class, enumeration.TAXON_GROUP_TYPE_ID_COMMERCIAL_SPECIES));
+
+ // Creation date
+ Calendar calendar = new GregorianCalendar();
+ calendar.set(Calendar.HOUR_OF_DAY, 0);
+ calendar.set(Calendar.MINUTE, 0);
+ calendar.set(Calendar.SECOND, 0);
+ calendar.set(Calendar.MILLISECOND, 0);
+ target.setCreationDate(calendar.getTime());
+ }
+
+ // Name
+ if (copyIfNull && source.getName() == null) {
+ target.setName(null);
+ } else if (source.getName() != null) {
+ target.setName(source.getName());
+ }
+
+ // Description (=source.comment)
+ if (copyIfNull && source.getComment() == null) {
+ target.setDescription(null);
+ } else if (source.getComment() != null) {
+ target.setDescription(source.getComment());
+ }
+
+
+
+
+ // Zone
+ if (copyIfNull && source.getZone() == null) {
+ // Remove program location classifications :
+ if (target.getLocationClassifications() != null) {
+ target.getLocationClassifications().clear();
+ }
+ // Remove program locations :
+ if (target.getLocations() != null) {
+ target.getLocations().clear();
+ }
+ } else if (source.getZone() != null && source.getZone().getId() != null) {
+ Location location = locationDao.load(Integer.valueOf(source.getZone().getId()));
+
+ // Program location classifications :
+ if (target.getLocationClassifications() == null) {
+ target.setLocationClassifications(Lists.newArrayList(location.getLocationClassification()));
+ }
+ else {
+ target.getLocationClassifications().clear();
+ target.getLocationClassifications().add(location.getLocationClassification());
+ }
+
+ // Program locations :
+ if (target.getLocations() == null) {
+ target.setLocations(Lists.newArrayList(location));
+ }
+ else {
+ target.getLocations().clear();
+ target.getLocations().add(location);
+ }
+ }
+ }
+
+ public int getProgramNameMaxLength() {
+ int maxCodeLengthInDatabase = 40;
+ if (enumeration.PROGRAM_CODE_SCIENTIFIC_CRUISE_PREFIX == null
+ || enumeration.PROGRAM_CODE_SCIENTIFIC_CRUISE_PREFIX.trim().isEmpty()) {
+ return maxCodeLengthInDatabase;
+ }
+ return (maxCodeLengthInDatabase - enumeration.PROGRAM_CODE_SCIENTIFIC_CRUISE_PREFIX.length());
+ }
}
Modified: trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceServiceImpl.java
===================================================================
--- trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceServiceImpl.java 2013-01-30 15:26:14 UTC (rev 271)
+++ trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceServiceImpl.java 2013-01-30 17:13:52 UTC (rev 272)
@@ -46,9 +46,11 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.Query;
+import org.hibernate.type.BooleanType;
import org.hibernate.type.DateType;
import org.hibernate.type.IntegerType;
import org.hibernate.type.StringType;
+import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@@ -122,7 +124,8 @@
@Override
public List<FishingOperationLocation> getAllFishingOperationStrata(String zoneId) {
- List<FishingOperationLocation> result = getFishingOperationLocations(
+ Preconditions.checkNotNull(zoneId);
+ List<FishingOperationLocation> result = getFishingOperationLocationsByParent(
enumeration.LOCATION_LEVEL_ID_STRATA,
Integer.valueOf(zoneId),
enumeration.LOCATION_LEVEL_ID_PROGRAM);
@@ -150,7 +153,7 @@
}
Preconditions.checkNotNull(parentId);
- List<FishingOperationLocation> result = getFishingOperationLocations(
+ List<FishingOperationLocation> result = getFishingOperationLocationsByParent(
enumeration.LOCATION_LEVEL_ID_SUB_STRATA,
Integer.valueOf(parentId),
parentLocationLevelId);
@@ -185,7 +188,7 @@
}
Preconditions.checkNotNull(parentId);
- List<FishingOperationLocation> result = getFishingOperationLocations(
+ List<FishingOperationLocation> result = getFishingOperationLocationsByParent(
enumeration.LOCATION_LEVEL_ID_LOCALITE,
Integer.valueOf(parentId),
parentLocationLevelId);
@@ -210,11 +213,13 @@
}
@Override
+ @Cacheable(value = "allFishingVessel")
public List<Vessel> getAllFishingVessel() {
Iterator<Object[]> list = queryListWithStatus(
- "allVessels",
+ "allVessels",
"refDate", DateType.INSTANCE, new Date(),
- "vesselTypeId", IntegerType.INSTANCE, enumeration.VESSEL_TYPE_ID_FISHING);
+ "vesselTypeId", IntegerType.INSTANCE, enumeration.VESSEL_TYPE_ID_FISHING
+ );
List<Vessel> result = Lists.newArrayList();
while (list.hasNext()) {
@@ -452,9 +457,31 @@
//-- Internal methods --//
//------------------------------------------------------------------------//
- protected List<FishingOperationLocation> getFishingOperationLocations(Integer locationLevelId, Integer parentId, Integer parentLocationLevelId) {
+ protected List<FishingOperationLocation> getFishingOperationLocations(Integer locationLevelId) {
Iterator<Object[]> sources = queryListWithStatus(
"allFishingOperationLocation",
+ "locationClassificationId", IntegerType.INSTANCE, enumeration.LOCATION_CLASSIFICATION_ID_SECTOR,
+ "locationLevelId", IntegerType.INSTANCE, locationLevelId
+ );
+ List<FishingOperationLocation> result = Lists.newArrayList();
+ while (sources.hasNext()) {
+ Object[] source = sources.next();
+ FishingOperationLocation target = new FishingOperationLocation();
+ target.setId(String.valueOf(source[0]));
+ target.setLabel((String) source[1]);
+ target.setName((String) source[2]);
+// target.setDescription((String)source[3]);
+ target.setLocationLevel((Integer) source[3]);
+
+ setStatus((fr.ifremer.adagio.core.dao.referential.Status) source[4], target);
+ result.add(target);
+ }
+ return result;
+ }
+
+ protected List<FishingOperationLocation> getFishingOperationLocationsByParent(Integer locationLevelId, Integer parentId, Integer parentLocationLevelId) {
+ Iterator<Object[]> sources = queryListWithStatus(
+ "allFishingOperationLocationByParent",
"parentId", IntegerType.INSTANCE, parentId,
"parentLocationLevelId", IntegerType.INSTANCE, parentLocationLevelId,
"locationClassificationId", IntegerType.INSTANCE, enumeration.LOCATION_CLASSIFICATION_ID_SECTOR,
@@ -474,7 +501,7 @@
result.add(target);
}
return result;
- }
+ }
protected Caracteristic loadCaracteristic(Object[] source) {
@@ -555,7 +582,7 @@
setStatus((fr.ifremer.adagio.core.dao.referential.Status) source[3], result);
return result;
}
-
+
protected Iterator<Object[]> queryListWithStatus(String queryName,
Object... params) {
Query query = createQuery(queryName, params);
Modified: trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/service/TuttiEnumerationFile.java
===================================================================
--- trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/service/TuttiEnumerationFile.java 2013-01-30 15:26:14 UTC (rev 271)
+++ trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/service/TuttiEnumerationFile.java 2013-01-30 17:13:52 UTC (rev 272)
@@ -166,6 +166,12 @@
@Value("${PmfmId.AGE}")
public final Integer PMFM_ID_AGE = null;
+
+ @Value("${ProgramCode.SCIENTIFIC_CRUISE_PREFIX}")
+ public final String PROGRAM_CODE_SCIENTIFIC_CRUISE_PREFIX = null;
+
+ @Value("${TaxonGroupTypeCode.COMMERCIAL_SPECIES}")
+ public final String TAXON_GROUP_TYPE_ID_COMMERCIAL_SPECIES = null;
public void init() {
Modified: trunk/tutti-persistence-adagio/src/main/resources/queries-override.hbm.xml
===================================================================
--- trunk/tutti-persistence-adagio/src/main/resources/queries-override.hbm.xml 2013-01-30 15:26:14 UTC (rev 271)
+++ trunk/tutti-persistence-adagio/src/main/resources/queries-override.hbm.xml 2013-01-30 17:13:52 UTC (rev 272)
@@ -36,11 +36,12 @@
<![CDATA[
SELECT
p.code,
- p.name
+ p.name,
+ p.description
FROM
ProgramImpl p
WHERE
- p.code LIKE 'CAM-%'
+ p.code LIKE :codePattern
]]>
</query>
@@ -171,8 +172,8 @@
o.name AS name,
guf.gear.label AS gearLabel,
o.startDateTime AS startDateTime,
- (select vum.alphanumericalValue from VesselUseMeasurementImpl vum where vum.vesselUseFeatures.id = vuf.id and vum.pmfm.id=1243) AS stationNumber,
- (select gum.numericalValue from GearUseMeasurementImpl gum where gum.gearUseFeatures.id = guf.id and gum.pmfm.id=953) AS trawNetNumber
+ (select vum.alphanumericalValue from VesselUseMeasurementImpl vum where vum.vesselUseFeatures.id = vuf.id and vum.pmfm.id=:pmfmIdStationNumber) AS stationNumber,
+ (select gum.numericalValue from GearUseMeasurementImpl gum where gum.gearUseFeatures.id = guf.id and gum.pmfm.id=:pmfmIdMultirigAggregation) AS trawNetNumber
FROM
FishingOperationImpl o
LEFT OUTER JOIN o.gearUseFeatures guf
@@ -183,6 +184,8 @@
o.startDateTime
]]>
<query-param name="cruiseId" type="java.lang.Integer"/>
+ <query-param name="pmfmIdStationNumber" type="java.lang.Integer"/>
+ <query-param name="pmfmIdMultirigAggregation" type="java.lang.Integer"/>
</query>
<query cacheable="true" name="fishingOperation">
@@ -449,7 +452,7 @@
</query>
<!-- [REF-03] Get all fishing operation strata / substrata / localite -->
- <query cacheable="true" name="allFishingOperationLocation">
+ <query cacheable="true" name="allFishingOperationLocationByParent">
<![CDATA[
SELECT
l.id as locationId,
@@ -475,6 +478,27 @@
<query-param name="statusValidCode" type="java.lang.String"/>
<query-param name="statusTemporaryCode" type="java.lang.String"/>
</query>
+
+ <query cacheable="true" name="allFishingOperationLocation">
+ <![CDATA[
+ SELECT
+ l.id as locationId,
+ l.label as locationLabel,
+ l.name as locationName,
+ l.locationLevel.id as locationLevelId,
+ l.status as status
+ FROM
+ LocationImpl l
+ WHERE
+ l.status.code IN (:statusValidCode, :statusTemporaryCode)
+ AND l.locationLevel.id = :locationLevelId
+ AND l.locationClassification.id = :locationClassificationId
+ ]]>
+ <query-param name="locationLevelId" type="java.lang.Integer"/>
+ <query-param name="locationClassificationId" type="java.lang.Integer"/>
+ <query-param name="statusValidCode" type="java.lang.String"/>
+ <query-param name="statusTemporaryCode" type="java.lang.String"/>
+ </query>
<!-- [REF-04] et [REF-05] Get all vessel for a given vesselType -->
<query cacheable="true" name="allVessels">
Modified: trunk/tutti-persistence-adagio/src/main/resources/tutti-db-enumerations.properties
===================================================================
--- trunk/tutti-persistence-adagio/src/main/resources/tutti-db-enumerations.properties 2013-01-30 15:26:14 UTC (rev 271)
+++ trunk/tutti-persistence-adagio/src/main/resources/tutti-db-enumerations.properties 2013-01-30 17:13:52 UTC (rev 272)
@@ -359,3 +359,6 @@
#TODO A creer (dans les enumerations Allegro)
# 181=PDG-RBE (à confirmer par Vincent)
DepartmentId.UNKNOWN_RECORDER_DEPARTMENT=181
+
+#TODO A creer (dans les enumerations Allegro)
+ProgramCode.SCIENTIFIC_CRUISE_PREFIX=CAM-
\ No newline at end of file
Modified: trunk/tutti-persistence-adagio/src/test/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceServiceTest.java
===================================================================
--- trunk/tutti-persistence-adagio/src/test/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceServiceTest.java 2013-01-30 15:26:14 UTC (rev 271)
+++ trunk/tutti-persistence-adagio/src/test/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceServiceTest.java 2013-01-30 17:13:52 UTC (rev 272)
@@ -191,7 +191,7 @@
fishingOperation.setComment(null);
// Store fishing operation into database :
- /*createdFishingOperation = service.createFishingOperation(fishingOperation);
+ createdFishingOperation = service.createFishingOperation(fishingOperation);
assertNotNull("Fishing operation ID must not be null after creation in database", createdFishingOperation);
assertNotNull(createdFishingOperation.getId());
@@ -199,7 +199,6 @@
reloadedFishingOperation = service.getFishingOperation(createdFishingOperation.getId());
assertNotNull(reloadedFishingOperation);
assertNull(reloadedFishingOperation.getGearShootingStartDate());
- */
// -----------------------------------------------------------------------------
// 2. Test with all properties set
@@ -312,7 +311,7 @@
// -----------------------------------------------------------------------------
// 4. Test exceptions :
// - try to save a operation using a gear not declared in the cruise
- // - try to save a operation using a trawl net number bigger than the cruise trawl net
+ // - try to save a operation using a multirig aggregation greater than the cruise multirig number
// -----------------------------------------------------------------------------
fishingOperation.setId(null);
@@ -327,25 +326,24 @@
}
}
- //TODO TC : remove comment when adagio will build
-// try {
-// createdFishingOperation = service.createFishingOperation(fishingOperation);
-// fail("A fishing operation must not be saved if the gear is not declared in the cruise.");
-// }
-// catch(DataIntegrityViolationException dive) {
-// assertNotNull(dive);
-// fishingOperation.setGear(cruiseGear);
-// }
+ try {
+ createdFishingOperation = service.createFishingOperation(fishingOperation);
+ fail("A fishing operation must not be saved if the gear is not declared in the cruise.");
+ }
+ catch(DataIntegrityViolationException dive) {
+ assertNotNull(dive);
+ fishingOperation.setGear(cruiseGear);
+ }
-// fishingOperation.setMultirigAggregation("3");
-// try {
-// createdFishingOperation = service.createFishingOperation(fishingOperation);
-// fail("A fishing operation must not be saved if the 'trawl net number' > 'cruise trawl net'.");
-// }
-// catch(DataIntegrityViolationException dive) {
-// assertNotNull(dive);
-// fishingOperation.setMultirigAggregation("1");
-// }
+ fishingOperation.setMultirigAggregation("3");
+ try {
+ createdFishingOperation = service.createFishingOperation(fishingOperation);
+ fail("A fishing operation must not be saved if the 'multirig aggregation' > 'cruise multirig number'.");
+ }
+ catch(DataIntegrityViolationException dive) {
+ assertNotNull(dive);
+ fishingOperation.setMultirigAggregation("1");
+ }
// -----------------------------------------------------------------------------
// 5. Test update (delete unecessary data)
Modified: trunk/tutti-persistence-adagio/src/test/java/fr/ifremer/tutti/persistence/service/ProgramPersistenceServiceTest.java
===================================================================
--- trunk/tutti-persistence-adagio/src/test/java/fr/ifremer/tutti/persistence/service/ProgramPersistenceServiceTest.java 2013-01-30 15:26:14 UTC (rev 271)
+++ trunk/tutti-persistence-adagio/src/test/java/fr/ifremer/tutti/persistence/service/ProgramPersistenceServiceTest.java 2013-01-30 17:13:52 UTC (rev 272)
@@ -24,16 +24,22 @@
* #L%
*/
+import static org.junit.Assert.*;
import fr.ifremer.tutti.persistence.DatabaseResource;
import fr.ifremer.tutti.persistence.entities.data.Program;
+import fr.ifremer.tutti.persistence.entities.referential.Zone;
+
import org.junit.Assert;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Ignore;
import org.junit.Test;
+import java.util.Iterator;
import java.util.List;
+import javax.annotation.Resource;
+
/**
* @author tchemit <chemit(a)codelutin.com>
* @since 0.3
@@ -42,19 +48,27 @@
@ClassRule
public static final DatabaseResource dbResource = new DatabaseResource();
-
+
protected ProgramPersistenceService service;
+ protected ReferentialPersistenceService referentialService;
@Before
public void setUp() throws Exception {
service = TuttiPersistenceServiceLocator.getProgramPersistenceService();
+ referentialService = TuttiPersistenceServiceLocator.getReferentialPersistenceService();
}
@Test
public void getAllProgram() {
List<Program> result = service.getAllProgram();
Assert.assertNotNull(result);
- Assert.assertEquals(1, result.size());
+ Assert.assertTrue("More than one program must be found", result.size() > 0);
+ for (Iterator iterator = result.iterator(); iterator.hasNext();) {
+ Program program = (Program) iterator.next();
+ Assert.assertNotNull(program.getId());
+ Assert.assertNotEquals("SIH-OBSMER", program.getId());
+ Assert.assertNotEquals("SIH-ACTIFLOT", program.getId());
+ }
}
@Test
@@ -69,14 +83,55 @@
}
@Test
- @Ignore
- public void createProgram(/*Program bean*/) {
+ public void createAndSaveProgram(/*Program bean*/) {
+ List<Zone> zones = referentialService.getAllProgramZone();
+ assertNotNull(zones);
+ assertTrue(zones.size() > 0);
+
+ Program program = new Program();
+ String name = "UniTest" + System.currentTimeMillis();
+ if (name.length() > 40) {
+ name = name.substring(0, 39);
+ }
+ program.setName(name);
+
+ program.setComment("Comments on " + name);
+ program.setZone(zones.get(0));
+
+ // Create program
+ Program createdProgram = service.createProgram(program);
+ assertNotNull(createdProgram);
+ assertNotNull(createdProgram.getId());
+
+ // Reload program and compare
+ Program reloadedProgram = service.getProgram(createdProgram.getId());
+ assertNotNull(reloadedProgram);
+ assertEquals(createdProgram.getId(), reloadedProgram.getId());
+ assertEquals(program.getName(), reloadedProgram.getName());
+ assertEquals(program.getComment(), reloadedProgram.getComment());
+ assertNotNull(program.getZone());
+ assertEquals(program.getZone().getId(), reloadedProgram.getZone().getId());
+
+ // Modify program
+ program.setId(createdProgram.getId());
+ program.setName("NEW_NAME");
+ program.setComment(program.getComment() + "\nAdd some modification");
+ program.setZone(zones.get(1));
+
+ // Create program
+ Program savedProgram = service.saveProgram(program);
+ assertNotNull(savedProgram);
+ assertNotNull(savedProgram.getId());
+
+ // Reload program and compare
+ reloadedProgram = service.getProgram(savedProgram.getId());
+ assertNotNull(reloadedProgram);
+ assertEquals(program.getId(), reloadedProgram.getId());
+ assertEquals(program.getName(), reloadedProgram.getName());
+ assertEquals(program.getComment(), reloadedProgram.getComment());
+ assertNotNull(program.getZone());
+ assertEquals(program.getZone().getId(), reloadedProgram.getZone().getId());
}
- @Test
- @Ignore
- public void saveProgram(/*Program bean*/) {
-
- }
}
1
0
Author: tchemit
Date: 2013-01-30 16:26:14 +0100 (Wed, 30 Jan 2013)
New Revision: 271
Url: http://forge.codelutin.com/projects/tutti/repository/revisions/271
Log:
remove hardcoded java version (thank u netbeans\!)
Modified:
trunk/pom.xml
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2013-01-30 13:31:37 UTC (rev 270)
+++ trunk/pom.xml 2013-01-30 15:26:14 UTC (rev 271)
@@ -138,7 +138,7 @@
<slf4jVersion>1.7.2</slf4jVersion>
- <adagioVersion>3.3.1-rev-401</adagioVersion>
+ <adagioVersion>3.3.1-SNAPSHOT</adagioVersion>
<msaccessImporterVersion>1.4.1</msaccessImporterVersion>
@@ -490,17 +490,7 @@
</plugins>
</pluginManagement>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <version>2.3.2</version>
- <configuration>
- <source>1.7</source>
- <target>1.7</target>
- </configuration>
- </plugin>
- </plugins>
+
</build>
<!-- Repositories needed to find the dependencies -->
1
0
r270 - in trunk/tutti-service/src: main/java/fr/ifremer/tutti/service test/java/fr/ifremer/tutti/service
by tchemit@users.forge.codelutin.com 30 Jan '13
by tchemit@users.forge.codelutin.com 30 Jan '13
30 Jan '13
Author: tchemit
Date: 2013-01-30 14:31:37 +0100 (Wed, 30 Jan 2013)
New Revision: 270
Url: http://forge.codelutin.com/projects/tutti/repository/revisions/270
Log:
fix import / export of protocol
Modified:
trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/TuttiProtocolImportExportService.java
trunk/tutti-service/src/test/java/fr/ifremer/tutti/service/TuttiProtocolImportExportServiceTest.java
Modified: trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/TuttiProtocolImportExportService.java
===================================================================
--- trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/TuttiProtocolImportExportService.java 2013-01-30 13:17:23 UTC (rev 269)
+++ trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/TuttiProtocolImportExportService.java 2013-01-30 13:31:37 UTC (rev 270)
@@ -31,7 +31,6 @@
import com.google.common.base.Charsets;
import com.google.common.io.Closeables;
import com.google.common.io.Files;
-import fr.ifremer.tutti.persistence.entities.data.SampleCategoryEnum;
import fr.ifremer.tutti.persistence.entities.protocol.SpeciesProtocol;
import fr.ifremer.tutti.persistence.entities.protocol.TuttiProtocol;
import org.apache.commons.logging.Log;
@@ -79,9 +78,6 @@
protected YamlConfig createConfig() {
YamlConfig config = new YamlConfig();
- config.setPropertyElementType(TuttiProtocol.class,
- "sampleCategoryOrder",
- SampleCategoryEnum.class);
config.setClassTag(SpeciesProtocol.class.getSimpleName(),
SpeciesProtocol.class);
config.writeConfig.setAlwaysWriteClassname(false);
Modified: trunk/tutti-service/src/test/java/fr/ifremer/tutti/service/TuttiProtocolImportExportServiceTest.java
===================================================================
--- trunk/tutti-service/src/test/java/fr/ifremer/tutti/service/TuttiProtocolImportExportServiceTest.java 2013-01-30 13:17:23 UTC (rev 269)
+++ trunk/tutti-service/src/test/java/fr/ifremer/tutti/service/TuttiProtocolImportExportServiceTest.java 2013-01-30 13:31:37 UTC (rev 270)
@@ -27,7 +27,6 @@
import com.google.common.base.Charsets;
import com.google.common.collect.Lists;
import com.google.common.io.Files;
-import fr.ifremer.tutti.persistence.entities.data.SampleCategoryEnum;
import fr.ifremer.tutti.persistence.entities.protocol.SpeciesProtocol;
import fr.ifremer.tutti.persistence.entities.protocol.TuttiProtocol;
import org.apache.commons.lang3.StringUtils;
@@ -73,8 +72,6 @@
"- 21\n" +
"- 22\n" +
"hydrologyPmfmId: []\n" +
- "sampleCategoryOrder: \n" +
- "- age\n" +
"species: \n" +
"- !SpeciesProtocol\n" +
" calcifySampleEnabled: true\n" +
@@ -115,7 +112,6 @@
protocol.setId("1");
protocol.setName("protocolName");
protocol.setComment("Commentaire");
- protocol.setSampleCategoryOrder(Lists.newArrayList(SampleCategoryEnum.age));
protocol.setEnvironmentPmfmId(Lists.newArrayList("114", "228", "821"));
protocol.setGearPmfmId(Lists.newArrayList("21", "22"));
protocol.setHydrologyPmfmId(Lists.<String>newArrayList());
@@ -164,9 +160,6 @@
Assert.assertEquals("1", protocol.getId());
Assert.assertEquals("protocolName", protocol.getName());
Assert.assertEquals("Commentaire", protocol.getComment());
- Assert.assertNotNull(protocol.getSampleCategoryOrder());
- Assert.assertEquals(1, protocol.getSampleCategoryOrder().size());
- Assert.assertEquals(SampleCategoryEnum.age, protocol.getSampleCategoryOrder().get(0));
Assert.assertEquals(Lists.newArrayList("114", "228", "821"), protocol.getEnvironmentPmfmId());
Assert.assertEquals(Lists.newArrayList("21", "22"), protocol.getGearPmfmId());
Assert.assertEquals(Lists.<String>newArrayList(), protocol.getHydrologyPmfmId());
1
0