Tony CHEMIT pushed to branch develop at ultreiaio / ird-observe Commits: b4583d98 by Tony Chemit at 2021-01-21T17:01:28+01:00 Suppression en cade des libérations de capture accessoire - See #1768 - - - - - 11 changed files: - client/datasource/editor/ps/src/main/i18n/getters/java.getter - client/datasource/editor/ps/src/main/i18n/getters/jaxx.getter - client/datasource/editor/ps/src/main/java/fr/ird/observe/client/datasource/editor/ps/data/observation/SetNonTargetCatchReleaseUI.jcss - client/datasource/editor/ps/src/main/java/fr/ird/observe/client/datasource/editor/ps/data/observation/SetNonTargetCatchReleaseUIModelStates.java - client/datasource/editor/ps/src/main/java/fr/ird/observe/client/datasource/editor/ps/data/observation/SetNonTargetCatchReleaseUITableModel.java - client/i18n/src/main/i18n/translations/observe_en_GB.properties - client/i18n/src/main/i18n/translations/observe_es_ES.properties - client/i18n/src/main/i18n/translations/observe_fr_FR.properties - models/dto-definition/src/main/models/Observe-20-data-ps-observation.model - + models/dto/src/main/java/fr/ird/observe/dto/data/ps/observation/SetNonTargetCatchReleaseDto.java - models/persistence/src/main/java/fr/ird/observe/entities/data/ps/observation/SetImpl.java Changes: ===================================== client/datasource/editor/ps/src/main/i18n/getters/java.getter ===================================== @@ -32,6 +32,8 @@ observe.data.ps.observation.NonTargetCatch.message.will.delete.sub.data observe.data.ps.observation.NonTargetCatch.message.will.delete.sub.data.for.species observe.data.ps.observation.NonTargetCatch.totalCountComputed.computed.tip observe.data.ps.observation.NonTargetCatch.totalCountComputed.observed.tip +observe.data.ps.observation.NonTargetCatchRelease.message.will.delete.sub.data +observe.data.ps.observation.NonTargetCatchRelease.message.will.delete.sub.data.for.species observe.data.ps.observation.Route.choice.create.fin.veille.activity observe.data.ps.observation.Route.choice.not.create.fin.veille.activity.and.continue observe.data.ps.observation.Route.message.need.fin.veille.activity ===================================== client/datasource/editor/ps/src/main/i18n/getters/jaxx.getter ===================================== @@ -89,7 +89,6 @@ observe.data.ps.observation.NonTargetCatchRelease.length observe.data.ps.observation.NonTargetCatchRelease.message.cantAdd observe.data.ps.observation.NonTargetCatchRelease.releasingTime observe.data.ps.observation.NonTargetCatchRelease.speciesGroupReleaseMode -observe.data.ps.observation.NonTargetCatchRelease.table.deleteExtraMessage observe.data.ps.observation.NonTargetLength.count observe.data.ps.observation.NonTargetLength.length observe.data.ps.observation.NonTargetLength.picturesReferences ===================================== client/datasource/editor/ps/src/main/java/fr/ird/observe/client/datasource/editor/ps/data/observation/SetNonTargetCatchReleaseUI.jcss ===================================== @@ -20,10 +20,6 @@ * #L% */ -#tableModel { - deleteExtraMessage:{t("observe.data.ps.observation.NonTargetCatchRelease.table.deleteExtraMessage")}; -} - #editorPanel { _focusComponent:{species}; } ===================================== client/datasource/editor/ps/src/main/java/fr/ird/observe/client/datasource/editor/ps/data/observation/SetNonTargetCatchReleaseUIModelStates.java ===================================== @@ -26,12 +26,17 @@ import fr.ird.observe.client.configuration.ClientConfig; import fr.ird.observe.client.constants.AcquisitionMode; import fr.ird.observe.client.datasource.api.cache.ReferencesCache; import fr.ird.observe.client.datasource.api.cache.ReferencesFilterHelper; +import fr.ird.observe.client.datasource.editor.api.content.data.table.AskToDelete; import fr.ird.observe.dto.data.ps.observation.NonTargetCatchReleaseDto; +import fr.ird.observe.dto.data.ps.observation.SetNonTargetCatchReleaseDto; import fr.ird.observe.dto.referential.common.SpeciesGroupDto; +import fr.ird.observe.dto.referential.common.SpeciesReference; import fr.ird.observe.navigation.select.ProjectSelectModel; import fr.ird.observe.services.ObserveServicesProvider; import io.ultreia.java4all.bean.spi.GenerateJavaBeanDefinition; +import io.ultreia.java4all.i18n.I18n; +import java.util.List; import java.util.Map; import java.util.TreeMap; @@ -47,7 +52,7 @@ public class SetNonTargetCatchReleaseUIModelStates extends GeneratedSetNonTarget @Override public void onAfterInitAddReferentialFilters(ClientConfig clientConfig, ProjectSelectModel observeSelectModel, ObserveServicesProvider servicesProvider, ReferencesCache referenceCache) { - referenceCache.addReferentialFilter(NonTargetCatchReleaseDto.PROPERTY_SPECIES, ReferencesFilterHelper.newSubList(getBean().getAvailableSpeciesIds())); + referenceCache.addReferentialFilter(NonTargetCatchReleaseDto.PROPERTY_SPECIES, ReferencesFilterHelper.<SetNonTargetCatchReleaseDto, SpeciesReference>newSubList(SetNonTargetCatchReleaseDto::getAvailableSpeciesIds)); } public Map<String, SpeciesGroupDto> getSpeciesGroupDtoMap() { @@ -59,4 +64,11 @@ public class SetNonTargetCatchReleaseUIModelStates extends GeneratedSetNonTarget newTableBean.setAcquisitionMode(AcquisitionMode.individual.ordinal()); } + @Override + public boolean canSave(SetNonTargetCatchReleaseDto originalBean, SetNonTargetCatchReleaseDto bean, List<NonTargetCatchReleaseDto> data) { + AskToDelete<SetNonTargetCatchReleaseDto> ask = new AskToDelete<>( + SetNonTargetCatchReleaseDto::getRemovedUnsafeSpecies, + I18n.n("observe.data.ps.observation.NonTargetCatchRelease.message.will.delete.sub.data")); + return ask.needDelete(this.getClientUIContext().getDecoratorService(), originalBean, bean); + } } ===================================== client/datasource/editor/ps/src/main/java/fr/ird/observe/client/datasource/editor/ps/data/observation/SetNonTargetCatchReleaseUITableModel.java ===================================== @@ -31,6 +31,8 @@ import fr.ird.observe.dto.referential.ps.observation.NonTargetCatchReleaseStatus import javax.swing.JTable; import java.util.List; +import static io.ultreia.java4all.i18n.I18n.t; + /** * Created on 12/4/14. * @@ -78,4 +80,17 @@ public class SetNonTargetCatchReleaseUITableModel extends GeneratedSetNonTargetC super.onSelectedRowChanged(ui, editingRow, tableEditBean, previousRowBean, notPersisted, newRow); } + + @Override + protected String getDeleteExtraMessage(NonTargetCatchReleaseDto bean) { + if (bean.isHasSample()) { + int count = getBean().getUnsafeSpeciesUsageCount(bean.getSpecies()); + if (count == 1) { + // while deleting this one, this species won't be available on sample + return t("observe.data.ps.observation.NonTargetCatchRelease.message.will.delete.sub.data.for.species", bean.getSpecies()); + } + } + // No specific message + return null; + } } ===================================== client/i18n/src/main/i18n/translations/observe_en_GB.properties ===================================== @@ -939,11 +939,12 @@ observe.data.ps.observation.NonTargetCatchRelease.comment.short=Com observe.data.ps.observation.NonTargetCatchRelease.conformity.short=Conformity observe.data.ps.observation.NonTargetCatchRelease.length.short=Length observe.data.ps.observation.NonTargetCatchRelease.message.cantAdd=<html><body><strong>Can not add non target catch release</strong>(no sensible non target catch)</body></html> +observe.data.ps.observation.NonTargetCatchRelease.message.will.delete.sub.data=If you confirm save, some data could be deleted\!\n\nFollowing species won't be useable in samples \:\n%1$s\nAll samples of those species will be deleted. +observe.data.ps.observation.NonTargetCatchRelease.message.will.delete.sub.data.for.species=\nIf you delete this non target catch release, the species (%s) will not be available for samples.\nSamples using this species (%s) will also be deleted. observe.data.ps.observation.NonTargetCatchRelease.releasingTime.short=Releasing time observe.data.ps.observation.NonTargetCatchRelease.sex.short=Sex observe.data.ps.observation.NonTargetCatchRelease.species.short=Species observe.data.ps.observation.NonTargetCatchRelease.speciesGroupReleaseMode.short=Mode -observe.data.ps.observation.NonTargetCatchRelease.table.deleteExtraMessage=\nIf you delete this catches released, samples using this species will also be deleted. observe.data.ps.observation.NonTargetLength.count.short=Count observe.data.ps.observation.NonTargetLength.length.short=Length observe.data.ps.observation.NonTargetLength.picturesReferences=Pictures references ===================================== client/i18n/src/main/i18n/translations/observe_es_ES.properties ===================================== @@ -939,11 +939,12 @@ observe.data.ps.observation.NonTargetCatchRelease.comment.short=Observaciones observe.data.ps.observation.NonTargetCatchRelease.conformity.short=Conformidad observe.data.ps.observation.NonTargetCatchRelease.length.short=Talla observe.data.ps.observation.NonTargetCatchRelease.message.cantAdd=<html><body><strong>Impossible d'ajouter des libération</strong>(pas de faune accessoire sensible)</body></html> \#TODO +observe.data.ps.observation.NonTargetCatchRelease.message.will.delete.sub.data=If you confirm save, some data could be deleted\!\n\nFollowing species won't be useable in samples \:\n%1$s\nAll samples of those species will be deleted. \#TODO +observe.data.ps.observation.NonTargetCatchRelease.message.will.delete.sub.data.for.species=\nIf you delete this non target catch release, the species (%s) will not be available for samples.\nSamples using this species (%s) will also be deleted. \#TODO observe.data.ps.observation.NonTargetCatchRelease.releasingTime.short=Tiempo de liberación observe.data.ps.observation.NonTargetCatchRelease.sex.short=Sexo observe.data.ps.observation.NonTargetCatchRelease.species.short=Especie observe.data.ps.observation.NonTargetCatchRelease.speciesGroupReleaseMode.short=Modo -observe.data.ps.observation.NonTargetCatchRelease.table.deleteExtraMessage=\nLa eliminación de una captura de fauna puede tener como consecuencia la eliminación de muestreo(s) de la especie. \#TODO observe.data.ps.observation.NonTargetLength.count.short=Grupo de tallas observe.data.ps.observation.NonTargetLength.length.short=Talla observe.data.ps.observation.NonTargetLength.picturesReferences=Referencia foto ===================================== client/i18n/src/main/i18n/translations/observe_fr_FR.properties ===================================== @@ -925,11 +925,11 @@ observe.data.ps.observation.NonTargetCatch.meanLengthComputed.observed.tip=La ta observe.data.ps.observation.NonTargetCatch.meanWeight.short=Poids moy observe.data.ps.observation.NonTargetCatch.meanWeightComputed.computed.tip=Le poids moyen a été calculé (%s) observe.data.ps.observation.NonTargetCatch.meanWeightComputed.observed.tip=Le poids moyen a été observé -observe.data.ps.observation.NonTargetCatch.message.table.will.delete.nonTargetSample=En confirmant la sauvegarde des objets vont être supprimés\!\n\nLes espèces suivantes ne seront plus utilisables dans des échantillonages ou les espèces libérées \:\n%1$s\nCela entrainera la suppression des données saisies liées à ces espèces +observe.data.ps.observation.NonTargetCatch.message.will.delete.sub.data=En confirmant la sauvegarde des objets vont être supprimés\!\n\nLes espèces suivantes ne seront plus utilisables dans des échantillonnages ou les espèces libérées \:\n%1$s\nCela entrainera la suppression des données saisies liées à ces espèces +observe.data.ps.observation.NonTargetCatch.message.will.delete.sub.data.for.species=\nLe fait de supprimer cette capture rend indisponible l'espèce (%s) sur les libérations ou les échantillons.\nLes libérations ou échantillons utilisant cette espèce seront alors supprimer. observe.data.ps.observation.NonTargetCatch.reasonForDiscard.short=Raison rejet observe.data.ps.observation.NonTargetCatch.species.short=Espèce de faune observe.data.ps.observation.NonTargetCatch.speciesFate.short=Devenir -observe.data.ps.observation.NonTargetCatch.table.deleteExtraMessage=\nLe fait de supprimer une capture de faune peut entrainer la suppression d'échantillonnage(s) sur l'espèce. observe.data.ps.observation.NonTargetCatch.totalCount.short=Nombre observe.data.ps.observation.NonTargetCatch.totalCountComputed.computed.tip=Le nombre estimé a été calculé (%s) observe.data.ps.observation.NonTargetCatch.totalCountComputed.observed.tip=Le nombre estimé a été observé @@ -939,11 +939,12 @@ observe.data.ps.observation.NonTargetCatchRelease.comment.short=Com observe.data.ps.observation.NonTargetCatchRelease.conformity.short=Conformité observe.data.ps.observation.NonTargetCatchRelease.length.short=Longueur observe.data.ps.observation.NonTargetCatchRelease.message.cantAdd=<html><body><strong>Impossible d'ajouter des libérations</strong>(pas de faune accessoire sensible)</body></html> +observe.data.ps.observation.NonTargetCatchRelease.message.will.delete.sub.data=En confirmant la sauvegarde des objets vont être supprimés\!\n\nLes espèces suivantes ne seront plus utilisables dans des échantillonages \:\n%1$s\nCela entrainera la suppression des données saisies liées à ces espèces +observe.data.ps.observation.NonTargetCatchRelease.message.will.delete.sub.data.for.species=\nLe fait de supprimer cette libération rend indisponible l'espèce (%s) sur les échantillons.\nLes échantillons utilisant cette espèce seront alors supprimer. observe.data.ps.observation.NonTargetCatchRelease.releasingTime.short=Moment observe.data.ps.observation.NonTargetCatchRelease.sex.short=Sexe observe.data.ps.observation.NonTargetCatchRelease.species.short=Espèce observe.data.ps.observation.NonTargetCatchRelease.speciesGroupReleaseMode.short=Mode -observe.data.ps.observation.NonTargetCatchRelease.table.deleteExtraMessage=\nLe fait de supprimer une capture de faune peut entrainer la suppression d'échantillonnage(s) sur l'espèce. \#TODO observe.data.ps.observation.NonTargetLength.count.short=Effectif observe.data.ps.observation.NonTargetLength.length.short=Longueur observe.data.ps.observation.NonTargetLength.picturesReferences=référence photo ===================================== models/dto-definition/src/main/models/Observe-20-data-ps-observation.model ===================================== @@ -81,6 +81,7 @@ comment + {*:1} String length + {*:1} Float | positiveNumber count + {*:1} Integer | notNull strictlyPositiveNumber acquisitionMode + {*:1} int +hasSample + {*:1} boolean status {*:1} !fr.ird.observe.dto.referential.ps.observation.NonTargetCatchReleaseStatusReference | notNull species {*:1} fr.ird.observe.dto.referential.common.SpeciesReference | notNull sex {*:1} fr.ird.observe.dto.referential.common.SexReference | notNull ===================================== models/dto/src/main/java/fr/ird/observe/dto/data/ps/observation/SetNonTargetCatchReleaseDto.java ===================================== @@ -0,0 +1,68 @@ +package fr.ird.observe.dto.data.ps.observation; + +/*- + * #%L + * ObServe Models :: Dto + * %% + * Copyright (C) 2008 - 2021 IRD, Code Lutin, Ultreia.io + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import fr.ird.observe.dto.referential.common.SpeciesReference; +import io.ultreia.java4all.bean.spi.GenerateJavaBeanDefinition; + +import java.util.Objects; +import java.util.Set; +import java.util.stream.Collectors; + +@GenerateJavaBeanDefinition +public class SetNonTargetCatchReleaseDto extends GeneratedSetNonTargetCatchReleaseDto { + + private static final long serialVersionUID = 1L; + + /** + * Get the set of unsafe species no more used in the {@code incoming} dto. + * + * @param incoming the dto to compare this + * @return the set of unsafe species no more used in incoming dto + */ + public Set<SpeciesReference> getRemovedUnsafeSpecies(SetNonTargetCatchReleaseDto incoming) { + // Get all unsafe species + Set<SpeciesReference> allUnsafeSpecies = getUnsafeSpecies(); + // Get incoming used unsafe species + Set<SpeciesReference> incomingUsedUnsafeSpecies = incoming.getUnsafeSpecies(); + // Remove for all the used + allUnsafeSpecies.removeAll(incomingUsedUnsafeSpecies); + // This will return the set of no more used unsafe species + return allUnsafeSpecies; + } + + /** + * @return set of unsafe species used in catches + */ + public Set<SpeciesReference> getUnsafeSpecies() { + return getNonTargetCatchRelease().stream().filter(NonTargetCatchReleaseDto::isHasSample).map(NonTargetCatchReleaseDto::getSpecies).collect(Collectors.toSet()); + } + + /** + * @param species species to test + * @return count of usage of this species in catches + */ + public int getUnsafeSpeciesUsageCount(SpeciesReference species) { + return (int) getNonTargetCatchRelease().stream().filter(d -> Objects.equals(species, d.getSpecies())).count(); + } +} ===================================== models/persistence/src/main/java/fr/ird/observe/entities/data/ps/observation/SetImpl.java ===================================== @@ -28,6 +28,7 @@ import fr.ird.observe.dto.data.ps.observation.DiscardedTargetCatchDto; import fr.ird.observe.dto.data.ps.observation.DiscardedTargetSampleDto; import fr.ird.observe.dto.data.ps.observation.KeptTargetCatchDto; import fr.ird.observe.dto.data.ps.observation.KeptTargetSampleDto; +import fr.ird.observe.dto.data.ps.observation.NonTargetCatchReleaseDto; import fr.ird.observe.dto.data.ps.observation.NonTargetSampleDto; import fr.ird.observe.dto.data.ps.observation.SetDiscardedTargetCatchDto; import fr.ird.observe.dto.data.ps.observation.SetDto; @@ -100,7 +101,7 @@ public class SetImpl extends SetAbstract { @Override public boolean canUseNonTargetCatchRelease() { - return isNonTargetCatchReleaseNotEmpty() && getNonTargetCatch().stream().anyMatch(t -> isSpeciesGroupRelease(t.getSpecies())); + return isNonTargetCatchNotEmpty() && getNonTargetCatch().stream().anyMatch(t -> isSpeciesGroupRelease(t.getSpecies())); } public boolean isSpeciesGroupRelease(Species species) { @@ -136,6 +137,10 @@ public class SetImpl extends SetAbstract { toSetNonTargetCatchDto(referentialLocale, (SetNonTargetCatchDto) dto); return; } + if (dto instanceof SetNonTargetCatchReleaseDto) { + toSetNonTargetCatchReleaseDto(referentialLocale, (SetNonTargetCatchReleaseDto) dto); + return; + } super.toDto(referentialLocale, dto); if (dto instanceof SetDto) { ((SetDto) dto).setDiscardedTargetSampleEnabled(canUseDiscardedTargetSample()); @@ -143,9 +148,6 @@ public class SetImpl extends SetAbstract { ((SetDto) dto).setNonTargetSampleEnabled(canUseNonTargetSample()); ((SetDto) dto).setSetNonTargetCatchReleaseEnabled(canUseNonTargetCatchRelease()); } - if (dto instanceof SetNonTargetCatchReleaseDto) { - ((SetNonTargetCatchReleaseDto) dto).setAvailableSpeciesIds(getNonTargetCatch().stream().map(NonTargetCatch::getSpecies).filter(this::isSpeciesGroupRelease).map(Species::getTopiaId).distinct().collect(ImmutableSet.toImmutableSet())); - } if (dto instanceof NonTargetSampleDto) { ((NonTargetSampleDto) dto).setAvailableSpeciesIds(getNonTargetCatch().stream().map(NonTargetCatch::getSpecies).map(Species::getTopiaId).distinct().collect(ImmutableSet.toImmutableSet())); ((NonTargetSampleDto) dto).setAvailableSpeciesFateIds(getNonTargetCatch().stream().map(NonTargetCatch::getSpeciesFate).map(SpeciesFate::getTopiaId).distinct().collect(ImmutableSet.toImmutableSet())); @@ -172,6 +174,10 @@ public class SetImpl extends SetAbstract { fromSetNonTargetCatchDto(referentialLocale, (SetNonTargetCatchDto) dto); return; } + if (dto instanceof SetNonTargetCatchReleaseDto) { + fromSetNonTargetCatchReleaseDto(referentialLocale, (SetNonTargetCatchReleaseDto) dto); + return; + } super.fromDto(referentialLocale, dto); } @@ -206,7 +212,7 @@ public class SetImpl extends SetAbstract { dtoList.forEach(catchDto -> { SpeciesReference species = catchDto.getSpecies(); boolean hasSample = speciesId.contains(species.getId()); - catchDto.set(KeptTargetCatchDto.PROPERTY_HAS_SAMPLE, hasSample); + catchDto.setHasSample(hasSample); }); } } @@ -224,7 +230,7 @@ public class SetImpl extends SetAbstract { dtoList.forEach(catchDto -> { SpeciesReference species = catchDto.getSpecies(); boolean hasSample = speciesId.contains(species.getId()); - catchDto.set(KeptTargetCatchDto.PROPERTY_HAS_SAMPLE, hasSample); + catchDto.setHasSample(hasSample); }); } } @@ -255,6 +261,23 @@ public class SetImpl extends SetAbstract { } } + private void toSetNonTargetCatchReleaseDto(ReferentialLocale referentialLocale, SetNonTargetCatchReleaseDto dto) { + // do normal copy + super.toDto(referentialLocale, dto); + // is there some sample? + if (isNonTargetSampleNotEmpty()) { + NonTargetSample targetSample = getNonTargetSample().iterator().next(); + // get usable species ids + java.util.Set<String> speciesId = DtoReferenceAware.ids(targetSample.getNonTargetLength().stream().map(NonTargetLength::getSpecies)); + // mark catch if there is associated samples to it + dto.getNonTargetCatchRelease().forEach(childDto -> { + boolean hasSample = speciesId.contains(childDto.getSpecies().getId()); + childDto.setHasSample(hasSample); + }); + } + dto.setAvailableSpeciesIds(getNonTargetCatch().stream().map(NonTargetCatch::getSpecies).filter(this::isSpeciesGroupRelease).map(Species::getTopiaId).distinct().collect(ImmutableSet.toImmutableSet())); + } + private void fromSetKeptTargetCatchDto(ReferentialLocale referentialLocale, SetKeptTargetCatchDto dto) { // keep other catches List<TargetCatch> otherTargetCatches = getTargetCatch(true); @@ -289,6 +312,20 @@ public class SetImpl extends SetAbstract { otherTargetCatches.forEach(this::addTargetCatch); } + private void fromSetNonTargetCatchReleaseDto(ReferentialLocale referentialLocale, SetNonTargetCatchReleaseDto dto) { + // do normal copy + super.fromDto(referentialLocale, dto); + // delete any discarded sample which not using the given species ids + //FIXME should we also check in non target catches ??? +// TargetSample targetSample = getTargetSample(true); +// if (targetSample != null) { +// List<NonTargetCatchReleaseDto> targetCatch = dto.getNonTargetCatchRelease(); +// Set<String> speciesIds = DtoReferenceAware.ids(targetCatch.stream().map(NonTargetCatchReleaseDto::getSpecies)); +// // remove sample from species ids +// targetSample.getTargetLength().removeIf(targetLength -> !speciesIds.contains(targetLength.getSpecies().getTopiaId())); +// } + } + private List<TargetCatch> getTargetCatch(boolean discarded) { return super.getTargetCatch().stream().filter(c -> c != null && Objects.equals(discarded, c.isDiscarded())).collect(Collectors.toList()); } View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/-/commit/b4583d98931b764c7945eab951... -- View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/-/commit/b4583d98931b764c7945eab951... You're receiving this email because of your account on gitlab.com.