[Git][ultreiaio/ird-t3][develop] [N0.3] Conversion des catégories logbook - rendre générique la codification des…
Tony CHEMIT pushed to branch develop at ultreiaio / ird-t3 Commits: 9b358873 by Tony CHEMIT at 2018-03-07T08:33:00Z [N0.3] Conversion des catégories logbook - rendre générique la codification des catégories inconnues (Closes ultreiaio/ird-t3#287) - - - - - 7 changed files: - t3-actions/src/main/java/fr/ird/t3/actions/data/level0/ConvertCatchesWeightCategoriesAction.java - t3-actions/src/main/resources/i18n/t3-actions_en_GB.properties - t3-actions/src/main/resources/i18n/t3-actions_fr_FR.properties - t3-domain/src/main/java/fr/ird/t3/entities/conversion/WeightCategoryLogBookConverter.java - t3-domain/src/main/java/fr/ird/t3/services/migration/T3MigrationCallbackV2_3.java - + t3-domain/src/main/resources/db/migration/V_2_3_04-add-WeightCategoryLogbook-unknown.sql - t3-domain/src/main/xmi/t3-persistence.zargo Changes: ===================================== t3-actions/src/main/java/fr/ird/t3/actions/data/level0/ConvertCatchesWeightCategoriesAction.java ===================================== --- a/t3-actions/src/main/java/fr/ird/t3/actions/data/level0/ConvertCatchesWeightCategoriesAction.java +++ b/t3-actions/src/main/java/fr/ird/t3/actions/data/level0/ConvertCatchesWeightCategoriesAction.java @@ -8,12 +8,12 @@ * it under the terms of the GNU Affero 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 Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * #L% @@ -109,74 +109,49 @@ public class ConvertCatchesWeightCategoriesAction extends AbstractLevel0Action<C } private boolean executeForTrip(Trip trip) throws TopiaException { - incrementsProgression(); - String tripStr = decorate(trip); - String message = l(locale, "t3.level0.convertCatchesWeightCategories.treat.trip", tripStr); log.info(message); addInfoMessage(message); - Map<Species, CatchWeightResult> tripResult = new HashMap<>(); - - if (!trip.isActivityEmpty()) { - + if (trip.isActivityNotEmpty()) { // must remove previous corrected elementary catches for (Activity activity : trip.getActivity()) { activity.clearCorrectedElementaryCatch(); } - for (Activity activity : trip.getActivity()) { if (activity.isElementaryCatchEmpty()) { // no catches continue; } - log.info(String.format("Treat activity %s with %d", activity.getDate(), activity.sizeElementaryCatch())); Ocean currentOcean = activity.getOcean(); SchoolType schoolType = activity.getSchoolType(); - // get converter for this ocean and school type WeightCategoryLogBookConverter converter = converterProvider.getConverter(currentOcean, schoolType); - if (converter == null) { - // can not redistribute if no weight categories found - message = l(locale, "t3.level0.convertCatchesWeightCategories.warning.noconverter.found", + message = l(locale, "t3.level0.convertCatchesWeightCategories.warning.no.converter.found", currentOcean.getLabel1(), schoolType.getLabel1()); - if (log.isWarnEnabled()) { - log.warn(message); - } + log.warn(message); addWarningMessage(message); continue; } - // split catches by species Multimap<Species, ElementaryCatch> catchesBySpecie = SpeciesTopiaDao.groupBySpecies(activity.getElementaryCatch()); - for (Species species : catchesBySpecie.keySet()) { - CatchWeightResult catchWeightResult = getCatchWeightResult(tripResult, species); - Collection<ElementaryCatch> catches = catchesBySpecie.get(species); - catchWeightResult.addLogBookWeight(catches); - log.info(String.format("Treat species %d with %d catches", species.getCode(), catches.size())); - // converts to weight category treatment for this species - Map<WeightCategoryTreatment, Float> distribution = converter.distribute(species, catches); - if (MapUtils.isEmpty(distribution)) { - // nothing to create continue; } - Collection<CorrectedElementaryCatch> newCatches = new ArrayList<>(); - // create new catches for (Map.Entry<WeightCategoryTreatment, Float> e2 : distribution.entrySet()) { WeightCategoryTreatment weightCategoryTreatment = e2.getKey(); @@ -193,10 +168,7 @@ public class ConvertCatchesWeightCategoriesAction extends AbstractLevel0Action<C } } } - - addInfoMessage(l(locale, "t3.level0.convertCatchesWeightCategories.resume.for.trip", - tripStr, tripResult.size())); - + addInfoMessage(l(locale, "t3.level0.convertCatchesWeightCategories.resume.for.trip", tripStr, tripResult.size())); for (Map.Entry<Species, CatchWeightResult> e : tripResult.entrySet()) { Species species = e.getKey(); CatchWeightResult r = e.getValue(); ===================================== t3-actions/src/main/resources/i18n/t3-actions_en_GB.properties ===================================== --- a/t3-actions/src/main/resources/i18n/t3-actions_en_GB.properties +++ b/t3-actions/src/main/resources/i18n/t3-actions_en_GB.properties @@ -49,7 +49,7 @@ t3.level0.computeWellPlanWeightCategoriesProportions.well.withWellPlan=Well (%s) t3.level0.convertCatchesWeightCategories.resume.for.species=Species %s < logBook total weight \= %s , converted total weight \= %s> t3.level0.convertCatchesWeightCategories.resume.for.trip=Trip %s converted for %s species t3.level0.convertCatchesWeightCategories.treat.trip=Will treat trip %s -t3.level0.convertCatchesWeightCategories.warning.noconverter.found=No converter found for ocean %s and schoolType %s +t3.level0.convertCatchesWeightCategories.warning.no.converter.found=No converter found for ocean %s and schoolType %s t3.level0.step.computeRf1=Compute RF1 t3.level0.step.computeRf2=Compute RF2 t3.level0.step.computeSetDurationAndPositiveSetCount=Compute Set Duration and positive set count ===================================== t3-actions/src/main/resources/i18n/t3-actions_fr_FR.properties ===================================== --- a/t3-actions/src/main/resources/i18n/t3-actions_fr_FR.properties +++ b/t3-actions/src/main/resources/i18n/t3-actions_fr_FR.properties @@ -49,7 +49,7 @@ t3.level0.computeWellPlanWeightCategoriesProportions.well.withWellPlan=Cuve avec t3.level0.convertCatchesWeightCategories.resume.for.species=Espèce %s < poids total des captures du livre de bord \= %s , poids total converti \= %s> t3.level0.convertCatchesWeightCategories.resume.for.trip=Marée %s convertie pour %s espèce(s) t3.level0.convertCatchesWeightCategories.treat.trip=Traitement de la marée %s -t3.level0.convertCatchesWeightCategories.warning.noconverter.found=Pas de converteur trouvé pour l'océan %s et le type de banc %s +t3.level0.convertCatchesWeightCategories.warning.no.converter.found=Pas de converteur trouvé pour l'océan %s et le type de banc %s t3.level0.step.computeRf1=Calcul du rf1 t3.level0.step.computeRf2=Calcul du rf2 t3.level0.step.computeSetDurationAndPositiveSetCount=Calcul de la durée d'une calée et de positive Set count ===================================== t3-domain/src/main/java/fr/ird/t3/entities/conversion/WeightCategoryLogBookConverter.java ===================================== --- a/t3-domain/src/main/java/fr/ird/t3/entities/conversion/WeightCategoryLogBookConverter.java +++ b/t3-domain/src/main/java/fr/ird/t3/entities/conversion/WeightCategoryLogBookConverter.java @@ -24,6 +24,7 @@ import fr.ird.t3.entities.data.ElementaryCatch; import fr.ird.t3.entities.reference.Ocean; import fr.ird.t3.entities.reference.SchoolType; import fr.ird.t3.entities.reference.Species; +import fr.ird.t3.entities.reference.WeightCategoryLogBook; import fr.ird.t3.entities.reference.WeightCategoryTreatment; import org.apache.commons.collections.CollectionUtils; @@ -40,16 +41,17 @@ import java.util.Map; public interface WeightCategoryLogBookConverter { /** - * Obtains the total weight of given {@code catches} which are in {@code unknown} weight category (with a code 9). + * Obtains the total weight of given {@code catches} which are in {@code unknown} weight category. * * @param catches catches to use * @return the total weight of given catches which uses the unknown weight category + * @see WeightCategoryLogBook#isUnknown() */ static float getUnknownWeight(Collection<ElementaryCatch> catches) { float result = 0; if (CollectionUtils.isNotEmpty(catches)) { for (ElementaryCatch aCatch : catches) { - if (aCatch.getWeightCategoryLogBook().getCode() == 9) { + if (aCatch.getWeightCategoryLogBook().isUnknown()) { result += aCatch.getCatchWeightRf2(); } } ===================================== t3-domain/src/main/java/fr/ird/t3/services/migration/T3MigrationCallbackV2_3.java ===================================== --- a/t3-domain/src/main/java/fr/ird/t3/services/migration/T3MigrationCallbackV2_3.java +++ b/t3-domain/src/main/java/fr/ird/t3/services/migration/T3MigrationCallbackV2_3.java @@ -48,7 +48,9 @@ public class T3MigrationCallbackV2_3 extends T3MigrationCallbackSupport { @Override protected void prepareMigrationScript(TopiaSqlSupport sqlSupport, List<String> queries, boolean showSql, boolean showProgression) throws TopiaException { addScript("01", "add-Trip-tripType", queries); + addScript("02", "add-VesselActivity-row", queries); addScript("03", "spatialize-ocean", queries); + addScript("04", "add-WeightCategoryLogbook-unknown", queries); } } ===================================== t3-domain/src/main/resources/db/migration/V_2_3_04-add-WeightCategoryLogbook-unknown.sql ===================================== --- /dev/null +++ b/t3-domain/src/main/resources/db/migration/V_2_3_04-add-WeightCategoryLogbook-unknown.sql @@ -0,0 +1,22 @@ +--- +-- #%L +-- T3 :: Domain +-- %% +-- Copyright (C) 2010 - 2018 IRD, Code Lutin, Ultreia.io +-- %% +-- This program is free software: you can redistribute it and/or modify +-- it under the terms of the GNU Affero 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 Affero General Public License +-- along with this program. If not, see <http://www.gnu.org/licenses/>. +-- #L% +--- +ALTER TABLE WeightCategoryLogbook ADD COLUMN unknown BOOLEAN DEFAULT FALSE NOT NULL; +UPDATE WeightCategoryLogbook SET unknown = TRUE WHERE code=9; \ No newline at end of file ===================================== t3-domain/src/main/xmi/t3-persistence.zargo ===================================== Binary files a/t3-domain/src/main/xmi/t3-persistence.zargo and b/t3-domain/src/main/xmi/t3-persistence.zargo differ View it on GitLab: https://gitlab.com/ultreiaio/ird-t3/commit/9b358873bc52532b61c1b78c480f64533... --- View it on GitLab: https://gitlab.com/ultreiaio/ird-t3/commit/9b358873bc52532b61c1b78c480f64533... You're receiving this email because of your account on gitlab.com.
participants (1)
-
Tony CHEMIT