r277 - in trunk: tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/entities tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/service/measure tutti-persistence-adagio/src/main/resources tutti-service tutti-service/src/main/java/fr/ifremer/tutti/service tutti-service/src/main/java/fr/ifremer/tutti/service/config tutti-service/src/main/java/fr/ifremer/tutti/service/protocol tutti-service/src/test/java/fr/ifremer/tutti/service tutti-service/src/test/java/fr/ifremer/
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@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@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@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@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@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@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@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@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@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@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@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@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@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
participants (1)
-
tchemit@users.forge.codelutin.com