Tony CHEMIT pushed to branch develop at ultreiaio / ird-t3

Commits:

8 changed files:

Changes:

  • t3-actions/src/main/java/fr/ird/t3/actions/data/level2/L2CatchStratum.java
    ... ... @@ -8,12 +8,12 @@
    8 8
      * it under the terms of the GNU Affero General Public License as published by
    
    9 9
      * the Free Software Foundation, either version 3 of the License, or
    
    10 10
      * (at your option) any later version.
    
    11
    - * 
    
    11
    + *
    
    12 12
      * This program is distributed in the hope that it will be useful,
    
    13 13
      * but WITHOUT ANY WARRANTY; without even the implied warranty of
    
    14 14
      * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    
    15 15
      * GNU General Public License for more details.
    
    16
    - * 
    
    16
    + *
    
    17 17
      * You should have received a copy of the GNU Affero General Public License
    
    18 18
      * along with this program.  If not, see <http://www.gnu.org/licenses/>.
    
    19 19
      * #L%
    
    ... ... @@ -37,6 +37,8 @@ import fr.ird.t3.models.WeightCompositionModel;
    37 37
     import fr.ird.t3.models.WeightCompositionModelHelper;
    
    38 38
     import fr.ird.t3.services.DecoratorService;
    
    39 39
     import fr.ird.t3.services.T3ServiceContext;
    
    40
    +import org.apache.commons.logging.Log;
    
    41
    +import org.apache.commons.logging.LogFactory;
    
    40 42
     
    
    41 43
     import java.io.IOException;
    
    42 44
     import java.util.Collection;
    
    ... ... @@ -55,6 +57,7 @@ import static org.nuiton.i18n.I18n.l;
    55 57
      */
    
    56 58
     public class L2CatchStratum extends CatchStratum<Level2Configuration, Level2Action> {
    
    57 59
     
    
    60
    +    private static final Log log = LogFactory.getLog(L2CatchStratum.class);
    
    58 61
         /**
    
    59 62
          * All species used by all weight categories found in all catches
    
    60 63
          * for this stratum.
    
    ... ... @@ -100,13 +103,38 @@ public class L2CatchStratum extends CatchStratum<Level2Configuration, Level2Acti
    100 103
          */
    
    101 104
         private WeightCompositionAggregateModel inputModelForSpeciesToFix;
    
    102 105
     
    
    103
    -    L2CatchStratum(StratumConfiguration<Level2Configuration> stratumConfiguration, Collection<Species> speciesToFix) {
    
    106
    +    private L2CatchStratum(StratumConfiguration<Level2Configuration> stratumConfiguration, Collection<Species> speciesToFix) {
    
    104 107
             super(stratumConfiguration, speciesToFix);
    
    105 108
             weightCategoriesForSpecies = HashMultimap.create();
    
    106 109
             inputModelForAllSpecies = new WeightCompositionAggregateModel();
    
    107 110
             outputModelForAllSpecies = new WeightCompositionAggregateModel();
    
    108 111
         }
    
    109 112
     
    
    113
    +    static L2CatchStratum newCatchStratum(StratumConfiguration<Level2Configuration> stratumConfiguration,
    
    114
    +                                          List<WeightCategoryTreatment> weightCategories,
    
    115
    +                                          Collection<Species> species,
    
    116
    +                                          Level2Action action) throws Exception {
    
    117
    +        L2CatchStratum catchStratum = new L2CatchStratum(stratumConfiguration, species);
    
    118
    +        T3ServiceContext serviceContext = action.getServiceContext();
    
    119
    +        catchStratum.init(serviceContext, weightCategories, action);
    
    120
    +        // get the total weight of the catch stratum
    
    121
    +        float catchStratumWeight = catchStratum.getTotalCatchWeightForSpeciesToFix();
    
    122
    +        if (catchStratumWeight == 0) {
    
    123
    +            // no catch in this stratum, skip it
    
    124
    +            String message = l(serviceContext.getLocale(), "t3.level2.message.noCatch.in.stratum");
    
    125
    +            log.info(message);
    
    126
    +            action.addInfoMessage(message);
    
    127
    +            // let's nullify the catch stratum (make it no more available)
    
    128
    +            catchStratum = null;
    
    129
    +        } else {
    
    130
    +            // log it
    
    131
    +            String message = catchStratum.logCatchStratum(action.getDecoratorService());
    
    132
    +            log.info(message);
    
    133
    +            action.addInfoMessage(message);
    
    134
    +        }
    
    135
    +        return catchStratum;
    
    136
    +    }
    
    137
    +
    
    110 138
         @Override
    
    111 139
         public void close() throws IOException {
    
    112 140
             super.close();
    
    ... ... @@ -130,11 +158,13 @@ public class L2CatchStratum extends CatchStratum<Level2Configuration, Level2Acti
    130 158
                 Integer nbZones = e.getValue();
    
    131 159
     
    
    132 160
                 if (activity.isCorrectedElementaryCatchNotEmpty()) {
    
    161
    +                //FIXME-263 si la categorie de poids est dans la strate alors on ne doit que traiter cette catégorie
    
    133 162
                     for (CorrectedElementaryCatch aCatch : activity.getCorrectedElementaryCatch()) {
    
    134 163
                         weightCategoriesForSpecies.put(aCatch.getWeightCategoryTreatment(), aCatch.getSpecies());
    
    135 164
                     }
    
    136 165
                 }
    
    137 166
     
    
    167
    +            //FIXME-263 si la categorie de poids est dans la strate alors on ne doit que traiter cette catégorie
    
    138 168
                 Multimap<WeightCategoryTreatment, CorrectedElementaryCatch> correctedElementaryCatchesByCategory =
    
    139 169
                         ActivityTopiaDao.groupByWeightCategoryTreatment(activity.getCorrectedElementaryCatch());
    
    140 170
     
    

  • t3-actions/src/main/java/fr/ird/t3/actions/data/level2/L2CatchStratumLoader.java
    ... ... @@ -25,8 +25,10 @@ import fr.ird.t3.actions.stratum.CatchStratumLoader;
    25 25
     import fr.ird.t3.actions.stratum.StratumConfiguration;
    
    26 26
     import fr.ird.t3.entities.data.Activity;
    
    27 27
     import fr.ird.t3.entities.data.ActivityTopiaDao;
    
    28
    +import fr.ird.t3.entities.data.CorrectedElementaryCatch;
    
    28 29
     import fr.ird.t3.entities.data.Trip;
    
    29 30
     import fr.ird.t3.entities.reference.Vessel;
    
    31
    +import fr.ird.t3.entities.reference.WeightCategoryTreatment;
    
    30 32
     import fr.ird.t3.services.ioc.InjectDAO;
    
    31 33
     
    
    32 34
     import java.util.HashMap;
    
    ... ... @@ -71,6 +73,7 @@ public class L2CatchStratumLoader extends CatchStratumLoader<Level2Configuration
    71 73
             Map<Activity, Integer> result = new HashMap<>();
    
    72 74
             if (activityIds != null && activityIds.size() > 0) {
    
    73 75
                 Set<Vessel> possibleVessels = configuration.getPossibleCatchVessels();
    
    76
    +            WeightCategoryTreatment weightCategoryTreatment = configuration.getWeightCategoryTreatment();
    
    74 77
                 for (Map.Entry<String, Integer> e : activityIds.entrySet()) {
    
    75 78
                     String activityId = e.getKey();
    
    76 79
                     // get activity
    
    ... ... @@ -84,6 +87,14 @@ public class L2CatchStratumLoader extends CatchStratumLoader<Level2Configuration
    84 87
                     // recheck activity have some catches.
    
    85 88
                     Preconditions.checkState(activity.isCorrectedElementaryCatchNotEmpty(),
    
    86 89
                             String.format("Can not accept an activity (%s) with no catch", activity.getTopiaId()));
    
    90
    +                if (weightCategoryTreatment != null) {
    
    91
    +                    // weight category is in stratum, check there is catch using this category
    
    92
    +                    boolean foundWeightCategory = activity.getCorrectedElementaryCatch().stream().map(CorrectedElementaryCatch::getWeightCategoryTreatment).anyMatch(c -> c.equals(weightCategoryTreatment));
    
    93
    +                    if (!foundWeightCategory) {
    
    94
    +                        // reject - the stratum weight category not found for this activity
    
    95
    +                        continue;
    
    96
    +                    }
    
    97
    +                }
    
    87 98
                     result.put(activity, e.getValue());
    
    88 99
                 }
    
    89 100
             }
    

  • t3-actions/src/main/java/fr/ird/t3/actions/data/level2/L2SampleStratum.java
    ... ... @@ -26,11 +26,12 @@ import fr.ird.t3.entities.data.Activity;
    26 26
     import fr.ird.t3.entities.data.ActivityTopiaDao;
    
    27 27
     import fr.ird.t3.entities.data.SetSpeciesFrequency;
    
    28 28
     import fr.ird.t3.entities.reference.Species;
    
    29
    +import fr.ird.t3.entities.reference.WeightCategory;
    
    29 30
     import fr.ird.t3.entities.reference.WeightCategorySample;
    
    31
    +import fr.ird.t3.entities.reference.WeightCategoryTreatment;
    
    30 32
     import fr.ird.t3.models.WeightCompositionAggregateModel;
    
    31 33
     import fr.ird.t3.models.WeightCompositionModelHelper;
    
    32 34
     import fr.ird.t3.services.T3ServiceContext;
    
    33
    -import org.apache.commons.collections.CollectionUtils;
    
    34 35
     import org.apache.commons.logging.Log;
    
    35 36
     import org.apache.commons.logging.LogFactory;
    
    36 37
     import org.nuiton.topia.persistence.TopiaException;
    
    ... ... @@ -38,6 +39,7 @@ import org.nuiton.topia.persistence.TopiaException;
    38 39
     import java.io.IOException;
    
    39 40
     import java.util.Collection;
    
    40 41
     import java.util.HashMap;
    
    42
    +import java.util.List;
    
    41 43
     import java.util.Locale;
    
    42 44
     import java.util.Map;
    
    43 45
     import java.util.Set;
    
    ... ... @@ -81,12 +83,22 @@ public class L2SampleStratum extends SampleStratum<Level2Configuration, Level2Ac
    81 83
          */
    
    82 84
         private float sampleStratumTotalWeight;
    
    83 85
     
    
    84
    -    L2SampleStratum(StratumConfiguration<Level2Configuration> configuration, Collection<Species> speciesToFix, float catchStratumTotalWeight) {
    
    86
    +    private L2SampleStratum(StratumConfiguration<Level2Configuration> configuration, Collection<Species> speciesToFix, float catchStratumTotalWeight) {
    
    85 87
             super(configuration, speciesToFix);
    
    86 88
             this.catchStratumTotalWeight = catchStratumTotalWeight;
    
    87 89
             modelsForAllSpecies = new WeightCompositionAggregateModel();
    
    88 90
         }
    
    89 91
     
    
    92
    +    static L2SampleStratum newSampleStratum(StratumConfiguration<Level2Configuration> stratumConfiguration,
    
    93
    +                                            List<WeightCategoryTreatment> weightCategories,
    
    94
    +                                            float totalCatchWeight,
    
    95
    +                                            Collection<Species> species,
    
    96
    +                                            Level2Action action) throws Exception {
    
    97
    +        L2SampleStratum sampleStratum = new L2SampleStratum(stratumConfiguration, species, totalCatchWeight);
    
    98
    +        sampleStratum.init(action.getServiceContext(), weightCategories, action);
    
    99
    +        return sampleStratum;
    
    100
    +    }
    
    101
    +
    
    90 102
         @Override
    
    91 103
         public void close() throws IOException {
    
    92 104
             super.close();
    
    ... ... @@ -97,18 +109,14 @@ public class L2SampleStratum extends SampleStratum<Level2Configuration, Level2Ac
    97 109
         @Override
    
    98 110
         protected L2SampleStratumLoader newLoader() {
    
    99 111
             int oceanCode = getConfiguration().getZone().getOcean().getCode();
    
    100
    -        L2SampleStratumLoader result;
    
    101 112
             switch (oceanCode) {
    
    102 113
                 case 1:
    
    103
    -                result = new L2SampleStratumLoaderAtlantic(this);
    
    104
    -                break;
    
    114
    +                return new L2SampleStratumLoaderAtlantic(this);
    
    105 115
                 case 2:
    
    106
    -                result = new L2SampleStratumLoaderIndian(this);
    
    107
    -                break;
    
    116
    +                return new L2SampleStratumLoaderIndian(this);
    
    108 117
                 default:
    
    109 118
                     throw new IllegalStateException("Not implemented for ocean with code " + oceanCode);
    
    110 119
             }
    
    111
    -        return result;
    
    112 120
         }
    
    113 121
     
    
    114 122
         public WeightCompositionAggregateModel getModelsForSpeciesToFix() {
    
    ... ... @@ -137,7 +145,7 @@ public class L2SampleStratum extends SampleStratum<Level2Configuration, Level2Ac
    137 145
                 ActivityTopiaDao.fillWeightsFromSetSpeciesCatWeight(activity, weights, null);
    
    138 146
                 // obtain the set species frequencies for the current activity
    
    139 147
                 Collection<SetSpeciesFrequency> setSpeciesFrequencies = activity.getSetSpeciesFrequency();
    
    140
    -            if (CollectionUtils.isNotEmpty(setSpeciesFrequencies)) {
    
    148
    +            if (activity.isSetSpeciesFrequencyNotEmpty()) {
    
    141 149
                     // compute sample count for this activity
    
    142 150
                     int newCount = computeSampleCount(setSpeciesFrequencies, species);
    
    143 151
                     // merge it with final total count
    
    ... ... @@ -145,24 +153,25 @@ public class L2SampleStratum extends SampleStratum<Level2Configuration, Level2Ac
    145 153
                 }
    
    146 154
             }
    
    147 155
             // add all weights to model
    
    148
    -        for (WeightCategorySample weightCategoryTreatment : weights.keySet()) {
    
    149
    -            Map<Species, Float> speciesFloatMap = weights.get(weightCategoryTreatment);
    
    150
    -            modelsForAllSpecies.addModel(weightCategoryTreatment, speciesFloatMap);
    
    156
    +        for (Map.Entry<WeightCategorySample, Map<Species, Float>> e : weights.entrySet()) {
    
    157
    +            Map<Species, Float> speciesFloatMap = e.getValue();
    
    158
    +            WeightCategory weightCategorySample = e.getKey();
    
    159
    +            modelsForAllSpecies.addModel(weightCategorySample, speciesFloatMap);
    
    151 160
             }
    
    152 161
             // recompute the weight model for species to fix
    
    153 162
             modelsForSpeciesToFix = modelsForAllSpecies.extractForSpecies(species);
    
    154 163
             // recompute the total sample weight (for species to fix)
    
    155 164
             sampleStratumTotalWeight = modelsForSpeciesToFix.getTotalModel().getTotalWeight();
    
    156
    -        addMergedActivitesCount(activities.size());
    
    165
    +        addMergedActivitiesCount(activities.size());
    
    157 166
             log.info(String.format("sampleStratumTotalCount  = %d / sampleStratumTotalWeight = %f", getSampleStratumTotalCount(), getSampleStratumTotalWeight()));
    
    158 167
         }
    
    159 168
     
    
    160
    -    private int computeSampleCount(Collection<SetSpeciesFrequency> newDatas, Collection<Species> speciesToFix) {
    
    169
    +    private int computeSampleCount(Collection<SetSpeciesFrequency> setSpeciesFrequencies, Collection<Species> speciesToFix) {
    
    161 170
             int newCount = 0;
    
    162
    -        for (SetSpeciesFrequency newData : newDatas) {
    
    163
    -            Species species = newData.getSpecies();
    
    171
    +        for (SetSpeciesFrequency setSpeciesFrequency : setSpeciesFrequencies) {
    
    172
    +            Species species = setSpeciesFrequency.getSpecies();
    
    164 173
                 if (speciesToFix.contains(species)) {
    
    165
    -                newCount += newData.getNumber();
    
    174
    +                newCount += setSpeciesFrequency.getNumber();
    
    166 175
                 }
    
    167 176
             }
    
    168 177
             return newCount;
    

  • t3-actions/src/main/java/fr/ird/t3/actions/data/level2/Level2Action.java
    ... ... @@ -51,6 +51,7 @@ import fr.ird.t3.models.WeightCompositionAggregateModel;
    51 51
     import fr.ird.t3.models.WeightCompositionModel;
    
    52 52
     import fr.ird.t3.models.WeightCompositionModelHelper;
    
    53 53
     import fr.ird.t3.services.DecoratorService;
    
    54
    +import fr.ird.t3.services.T3ServiceContext;
    
    54 55
     import fr.ird.t3.services.ZoneStratumService;
    
    55 56
     import fr.ird.t3.services.ioc.InjectDAO;
    
    56 57
     import fr.ird.t3.services.ioc.InjectEntitiesById;
    
    ... ... @@ -113,7 +114,7 @@ public class Level2Action extends T3Action<Level2Configuration> {
    113 114
          *
    
    114 115
          * @since 1.3
    
    115 116
          */
    
    116
    -    private Collection<L2StratumResult> stratumsResult;
    
    117
    +    private Collection<L2StratumResult> stratumResultSet;
    
    117 118
         @InjectDAO(entityType = Activity.class)
    
    118 119
         private ActivityTopiaDao activityDAO;
    
    119 120
         @InjectDAO(entityType = WeightCategoryTreatment.class)
    
    ... ... @@ -179,7 +180,7 @@ public class Level2Action extends T3Action<Level2Configuration> {
    179 180
             this.possibleCatchVessels = vesselDAO.getPossibleCatchVessels(catchFleets);
    
    180 181
             // get possible vessels for sample stratum
    
    181 182
             this.possibleSampleVessels = vesselDAO.getPossibleSampleVessels(sampleFleets, sampleFlags);
    
    182
    -        this.stratumsResult = new LinkedHashSet<>();
    
    183
    +        this.stratumResultSet = new LinkedHashSet<>();
    
    183 184
             this.inputCatchModelForAllSpecies = new WeightCompositionAggregateModel();
    
    184 185
             this.outputCatchModelForAllSpecies = new WeightCompositionAggregateModel();
    
    185 186
         }
    
    ... ... @@ -278,7 +279,7 @@ public class Level2Action extends T3Action<Level2Configuration> {
    278 279
                                 activityCache);
    
    279 280
                 try {
    
    280 281
                     L2StratumResult result = doExecuteStratum(stratumConfiguration, weightCategories, stratumIndex, usedActivityIds);
    
    281
    -                stratumsResult.add(result);
    
    282
    +                stratumResultSet.add(result);
    
    282 283
                 } finally {
    
    283 284
                     flushTransaction("After stratum " + stratumIndex);
    
    284 285
                 }
    
    ... ... @@ -319,7 +320,7 @@ public class Level2Action extends T3Action<Level2Configuration> {
    319 320
             addInfoMessage(message);
    
    320 321
             addInfoMessage("==============================================================================================");
    
    321 322
             // compute the catch stratum
    
    322
    -        try (L2CatchStratum catchStratum = newCatchStratum(stratumConfiguration, weightCategories)) {
    
    323
    +        try (L2CatchStratum catchStratum = L2CatchStratum.newCatchStratum(stratumConfiguration, weightCategories, species, this)) {
    
    323 324
                 incrementsProgression();
    
    324 325
                 if (catchStratum == null) {
    
    325 326
                     // no catch in this stratum
    
    ... ... @@ -328,7 +329,7 @@ public class Level2Action extends T3Action<Level2Configuration> {
    328 329
                     incrementsProgression();
    
    329 330
                 } else {
    
    330 331
                     // compute sample stratum
    
    331
    -                try (L2SampleStratum sampleStratum = newSampleStratum(stratumConfiguration, weightCategories, catchStratum.getTotalCatchWeightForSpeciesToFix())) {
    
    332
    +                try (L2SampleStratum sampleStratum = L2SampleStratum.newSampleStratum(stratumConfiguration, weightCategories, catchStratum.getTotalCatchWeightForSpeciesToFix(), species, this)) {
    
    332 333
                         incrementsProgression();
    
    333 334
                         // get the substitution level for the sample stratum
    
    334 335
                         Integer level = sampleStratum.getSubstitutionLevel();
    
    ... ... @@ -349,7 +350,7 @@ public class Level2Action extends T3Action<Level2Configuration> {
    349 350
     //                                int nbZones = e.getValue();
    
    350 351
                                 // is activity was already treated ?
    
    351 352
                                 boolean newActivity = usedActivityIds.add(activity.getTopiaId());
    
    352
    -                            doExecuteActivityInCatchStratum(catchStratum,
    
    353
    +                            doExecuteActivityInCatchStratumWithoutSampleStratum(catchStratum,
    
    353 354
                                         activity,
    
    354 355
                                         activityIndex++,
    
    355 356
                                         nbActivities,
    
    ... ... @@ -408,35 +409,104 @@ public class Level2Action extends T3Action<Level2Configuration> {
    408 409
         private Collection<ZoneStratumAware> getZones(SchoolType schoolType) {
    
    409 410
             return oceanContext.values().stream().flatMap(o -> o.getZones(schoolType).stream()).distinct().collect(Collectors.toList());
    
    410 411
         }
    
    412
    +//
    
    413
    +//    private L2CatchStratum newCatchStratum(StratumConfiguration<Level2Configuration> stratumConfiguration,
    
    414
    +//                                           List<WeightCategoryTreatment> weightCategories) throws Exception {
    
    415
    +//        L2CatchStratum catchStratum = new L2CatchStratum(stratumConfiguration, species);
    
    416
    +//        catchStratum.init(serviceContext, weightCategories, this);
    
    417
    +//        // get the total weight of the catch stratum
    
    418
    +//        float catchStratumWeight = catchStratum.getTotalCatchWeightForSpeciesToFix();
    
    419
    +//        if (catchStratumWeight == 0) {
    
    420
    +//            // no catch in this stratum, skip it
    
    421
    +//            String message = l(locale, "t3.level2.message.noCatch.in.stratum");
    
    422
    +//            log.info(message);
    
    423
    +//            addInfoMessage(message);
    
    424
    +//            // let's nullify the catch stratum (make it no more available)
    
    425
    +//            catchStratum = null;
    
    426
    +//        } else {
    
    427
    +//            // log it
    
    428
    +//            String message = catchStratum.logCatchStratum(getDecoratorService());
    
    429
    +//            log.info(message);
    
    430
    +//            addInfoMessage(message);
    
    431
    +//        }
    
    432
    +//        return catchStratum;
    
    433
    +//    }
    
    434
    +
    
    435
    +//    private L2SampleStratum newSampleStratum(StratumConfiguration<Level2Configuration> stratumConfiguration,
    
    436
    +//                                             List<WeightCategoryTreatment> weightCategories,
    
    437
    +//                                             float totalCatchWeight) throws Exception {
    
    438
    +//        L2SampleStratum sampleStratum = new L2SampleStratum(stratumConfiguration, species, totalCatchWeight);
    
    439
    +//        sampleStratum.init(serviceContext, weightCategories, this);
    
    440
    +//        return sampleStratum;
    
    441
    +//    }
    
    442
    +
    
    443
    +    private void doExecuteActivityInCatchStratumWithoutSampleStratum(L2CatchStratum catchStratum,
    
    444
    +                                                                     Activity activity,
    
    445
    +                                                                     int activityIndex,
    
    446
    +                                                                     int nbActivities,
    
    447
    +                                                                     boolean deleteOldData) {
    
    411 448
     
    
    412
    -    private L2CatchStratum newCatchStratum(StratumConfiguration<Level2Configuration> stratumConfiguration,
    
    413
    -                                           List<WeightCategoryTreatment> weightCategories) throws Exception {
    
    414
    -        L2CatchStratum catchStratum = new L2CatchStratum(stratumConfiguration, species);
    
    415
    -        catchStratum.init(serviceContext, weightCategories, this);
    
    416
    -        // get the total weight of the catch stratum
    
    417
    -        float catchStratumWeight = catchStratum.getTotalCatchWeightForSpeciesToFix();
    
    418
    -        if (catchStratumWeight == 0) {
    
    419
    -            // no catch in this stratum, skip it
    
    420
    -            String message = l(locale, "t3.level2.message.noCatch.in.stratum");
    
    421
    -            log.info(message);
    
    422
    -            addInfoMessage(message);
    
    423
    -            // let's nullify the catch stratum (make it no more available)
    
    424
    -            catchStratum = null;
    
    425
    -        } else {
    
    426
    -            // log it
    
    427
    -            String message = catchStratum.logCatchStratum(getDecoratorService());
    
    428
    -            log.info(message);
    
    429
    -            addInfoMessage(message);
    
    449
    +        String activityStr = String.format("%s (%s)", decorate(activity), decorate(activity.getTrip(), DecoratorService.WITH_ID));
    
    450
    +        String message = l(locale, "t3.level2.message.start.activity", activityIndex, nbActivities, activityStr, 1);
    
    451
    +        log.info(message);
    
    452
    +        addInfoMessage(message);
    
    453
    +        if (deleteOldData) {
    
    454
    +            // delete old data for this activity
    
    455
    +            log.info(String.format("Delete previous level2 data of %s", activityStr));
    
    456
    +            activity.deleteComputedDataLevel2();
    
    457
    +        }
    
    458
    +        // build a model for getting total of each weight category
    
    459
    +        try (WeightCompositionAggregateModel catchWeightModelForAllSpecies = new WeightCompositionAggregateModel()) {
    
    460
    +            //FIXME-263 si la categorie de poids est dans la strate alors on ne doit que traiter cette catégorie
    
    461
    +            ActivityTopiaDao.fillWeightsFromCatchesWeight(activity, catchWeightModelForAllSpecies, 1);
    
    462
    +            try (WeightCompositionAggregateModel catchWeightModelForSpeciesToFix = catchWeightModelForAllSpecies.extractForSpecies(species)) {
    
    463
    +                // log catches weight
    
    464
    +                message = logCatchWeight(getDecoratorService(), catchWeightModelForAllSpecies, catchWeightModelForSpeciesToFix);
    
    465
    +                log.info(message);
    
    466
    +                addInfoMessage(message);
    
    467
    +            }
    
    468
    +            try (WeightCompositionAggregateModel model = new WeightCompositionAggregateModel()) {
    
    469
    +                ActivityTopiaDao.fillWeightsFromSetSpeciesCatWeight(activity, null, model);
    
    470
    +                try (WeightCompositionAggregateModel compositionModel = model.extractForSpecies(species)) {
    
    471
    +                    String activityResume = logActivityCatchStratum(model, compositionModel, getDecoratorService());
    
    472
    +                    message = l(locale, "t3.level2.message.activity.with.sample.useOwn.composition", activityResume);
    
    473
    +                    log.info(message);
    
    474
    +                    addInfoMessage(message);
    
    475
    +                }
    
    476
    +            }
    
    477
    +            // apply composition model to activity catches
    
    478
    +            applySampleSpecificCompositionWithoutSampleStratum(catchStratum, activity);
    
    430 479
             }
    
    431
    -        return catchStratum;
    
    432 480
         }
    
    433 481
     
    
    434
    -    private L2SampleStratum newSampleStratum(StratumConfiguration<Level2Configuration> stratumConfiguration,
    
    435
    -                                             List<WeightCategoryTreatment> weightCategories,
    
    436
    -                                             float totalCatchWeight) throws Exception {
    
    437
    -        L2SampleStratum sampleStratum = new L2SampleStratum(stratumConfiguration, species, totalCatchWeight);
    
    438
    -        sampleStratum.init(serviceContext, weightCategories, this);
    
    439
    -        return sampleStratum;
    
    482
    +    private void applySampleSpecificCompositionWithoutSampleStratum(L2CatchStratum catchStratum, Activity activity) {
    
    483
    +        try (WeightCompositionAggregateModel correctedCatchWeightModel = new WeightCompositionAggregateModel()) {
    
    484
    +            // Get all corrected catch group by weight category
    
    485
    +            Multimap<WeightCategoryTreatment, CorrectedElementaryCatch> correctedElementaryCatches =
    
    486
    +                    ActivityTopiaDao.groupByWeightCategoryTreatment(activity.getCorrectedElementaryCatch());
    
    487
    +            //FIXME-263 si la categorie de poids est dans la strate alors on ne doit que traiter cette catégorie
    
    488
    +            for (WeightCategoryTreatment weightCategory : correctedElementaryCatches.keySet()) {
    
    489
    +                Map<Species, Float> weights = new HashMap<>();
    
    490
    +                // Apply on all existing corrected catch weight
    
    491
    +                for (CorrectedElementaryCatch aCatch : correctedElementaryCatches.get(weightCategory)) {
    
    492
    +                    Species speciesToUse = aCatch.getSpecies();
    
    493
    +                    // the corrected catch weight to add to the row
    
    494
    +                    float correctedCatchWeight = aCatch.getCatchWeight();
    
    495
    +                    // hold added value (for logs)
    
    496
    +                    weights.put(speciesToUse, correctedCatchWeight);
    
    497
    +                    aCatch.setCorrectedCatchWeight(correctedCatchWeight);
    
    498
    +                    aCatch.setCorrectedFlag(false);
    
    499
    +                }
    
    500
    +                // add corrected weights used for this category
    
    501
    +                correctedCatchWeightModel.addModel(weightCategory, weights);
    
    502
    +            }
    
    503
    +            // log corrected catches weight
    
    504
    +            String message = logCorrectedCatchWeight(correctedCatchWeightModel, getDecoratorService());
    
    505
    +            log.info(message);
    
    506
    +            addInfoMessage(message);
    
    507
    +            // add corrected catch weight done for this activity in stratum output model
    
    508
    +            catchStratum.addActivityOutputModel(correctedCatchWeightModel);
    
    509
    +        }
    
    440 510
         }
    
    441 511
     
    
    442 512
         private void doExecuteActivityInCatchStratum(L2CatchStratum catchStratum,
    
    ... ... @@ -457,14 +527,14 @@ public class Level2Action extends T3Action<Level2Configuration> {
    457 527
             }
    
    458 528
             // build a model for getting total of each weight category
    
    459 529
             WeightCompositionAggregateModel catchWeightModelForAllSpecies = new WeightCompositionAggregateModel();
    
    530
    +        //FIXME-263 si la categorie de poids est dans la strate alors on ne doit que traiter cette catégorie
    
    460 531
             ActivityTopiaDao.fillWeightsFromCatchesWeight(activity, catchWeightModelForAllSpecies, nbZones);
    
    461 532
             WeightCompositionAggregateModel catchWeightModelForSpeciesToFix = catchWeightModelForAllSpecies.extractForSpecies(species);
    
    462 533
             // log catches weight
    
    463 534
             message = logCatchWeight(getDecoratorService(), catchWeightModelForAllSpecies, catchWeightModelForSpeciesToFix);
    
    464 535
             log.info(message);
    
    465 536
             addInfoMessage(message);
    
    466
    -        // obtain the sample composition model to use for the activity (can come from catch if it has some samples,
    
    467
    -        // otherwise use the catch stratum one)
    
    537
    +        // obtain the sample composition model to use for the activity (can come from catch if it has some samples, otherwise use the catch stratum one)
    
    468 538
             boolean activityWithSample = catchStratum.isActivityWithSample(activity);
    
    469 539
             boolean useAllSamplesOfStratum = getConfiguration().isUseAllSamplesOfStratum();
    
    470 540
             WeightCompositionAggregateModel compositionModel;
    
    ... ... @@ -498,161 +568,98 @@ public class Level2Action extends T3Action<Level2Configuration> {
    498 568
             }
    
    499 569
         }
    
    500 570
     
    
    501
    -    private void doExecuteActivityInCatchStratum(L2CatchStratum catchStratum,
    
    502
    -                                                 Activity activity,
    
    503
    -                                                 int activityIndex,
    
    504
    -                                                 int nbActivities,
    
    505
    -                                                 boolean deleteOldData) {
    
    506
    -
    
    507
    -        String activityStr = String.format("%s (%s)", decorate(activity), decorate(activity.getTrip(), DecoratorService.WITH_ID));
    
    508
    -        String message = l(locale, "t3.level2.message.start.activity", activityIndex, nbActivities, activityStr, 1);
    
    509
    -        log.info(message);
    
    510
    -        addInfoMessage(message);
    
    511
    -        if (deleteOldData) {
    
    512
    -            // delete old data for this activity
    
    513
    -            log.info(String.format("Delete previous level2 data of %s", activityStr));
    
    514
    -            activity.deleteComputedDataLevel2();
    
    515
    -        }
    
    516
    -        // build a model for getting total of each weight category
    
    517
    -        WeightCompositionAggregateModel catchWeightModelForAllSpecies = new WeightCompositionAggregateModel();
    
    518
    -        ActivityTopiaDao.fillWeightsFromCatchesWeight(activity, catchWeightModelForAllSpecies, 1);
    
    519
    -        WeightCompositionAggregateModel catchWeightModelForSpeciesToFix = catchWeightModelForAllSpecies.extractForSpecies(species);
    
    520
    -        // log catches weight
    
    521
    -        message = logCatchWeight(getDecoratorService(), catchWeightModelForAllSpecies, catchWeightModelForSpeciesToFix);
    
    522
    -        log.info(message);
    
    523
    -        addInfoMessage(message);
    
    524
    -        WeightCompositionAggregateModel model = new WeightCompositionAggregateModel();
    
    525
    -        ActivityTopiaDao.fillWeightsFromSetSpeciesCatWeight(activity, null, model);
    
    526
    -        WeightCompositionAggregateModel compositionModel = model.extractForSpecies(species);
    
    527
    -        String activityResume = logActivityCatchStratum(model, compositionModel, getDecoratorService());
    
    528
    -        message = l(locale, "t3.level2.message.activity.with.sample.useOwn.composition", activityResume);
    
    529
    -        log.info(message);
    
    530
    -        addInfoMessage(message);
    
    531
    -        // apply composition model to activity catches
    
    532
    -        applySampleSpecificComposition(catchStratum, activity);
    
    533
    -        catchWeightModelForAllSpecies.close();
    
    534
    -        catchWeightModelForSpeciesToFix.close();
    
    535
    -        compositionModel.close();
    
    536
    -    }
    
    537
    -
    
    538
    -    private void applySampleSpecificComposition(L2CatchStratum catchStratum, Activity activity) {
    
    539
    -        WeightCompositionAggregateModel correctedCatchWeightModel = new WeightCompositionAggregateModel();
    
    540
    -        // Get all corrected catch group by weight category
    
    541
    -        Multimap<WeightCategoryTreatment, CorrectedElementaryCatch> correctedElementaryCatches =
    
    542
    -                ActivityTopiaDao.groupByWeightCategoryTreatment(activity.getCorrectedElementaryCatch());
    
    543
    -        for (WeightCategoryTreatment weightCategory : correctedElementaryCatches.keySet()) {
    
    544
    -            Map<Species, Float> weights = new HashMap<>();
    
    545
    -            // Apply on all existing corrected catch weight
    
    546
    -            for (CorrectedElementaryCatch aCatch : correctedElementaryCatches.get(weightCategory)) {
    
    547
    -                Species speciesToUse = aCatch.getSpecies();
    
    548
    -                // the corrected catch weight to add to the row
    
    549
    -                float correctedCatchWeight = aCatch.getCatchWeight();
    
    550
    -                // hold added value (for logs)
    
    551
    -                weights.put(speciesToUse, correctedCatchWeight);
    
    552
    -                aCatch.setCorrectedCatchWeight(correctedCatchWeight);
    
    553
    -                aCatch.setCorrectedFlag(false);
    
    554
    -            }
    
    555
    -            // add corrected weights used for this category
    
    556
    -            correctedCatchWeightModel.addModel(weightCategory, weights);
    
    557
    -        }
    
    558
    -        // log corrected catches weight
    
    559
    -        String message = logCorrectedCatchWeight(correctedCatchWeightModel, getDecoratorService());
    
    560
    -        log.info(message);
    
    561
    -        addInfoMessage(message);
    
    562
    -        // add corrected catch weight done for this activity in stratum output model
    
    563
    -        catchStratum.addActivityOutputModel(correctedCatchWeightModel);
    
    564
    -    }
    
    565
    -
    
    566 571
         private void applySampleSpecificComposition(L2CatchStratum catchStratum,
    
    567 572
                                                     Activity activity,
    
    568 573
                                                     int nbZones,
    
    569 574
                                                     WeightCompositionAggregateModel sampleCompositionModel,
    
    570 575
                                                     WeightCompositionAggregateModel correctedCatchesForSpeciesToFix) {
    
    571
    -        WeightCompositionAggregateModel correctedCatchWeightModel = new WeightCompositionAggregateModel();
    
    572
    -        // Get all corrected catch group by weight category
    
    573
    -        Multimap<WeightCategoryTreatment, CorrectedElementaryCatch> correctedElementaryCatches =
    
    574
    -                ActivityTopiaDao.groupByWeightCategoryTreatment(activity.getCorrectedElementaryCatch());
    
    575
    -        for (WeightCategoryTreatment weightCategory : correctedElementaryCatches.keySet()) {
    
    576
    -            Map<Species, Float> weights = new HashMap<>();
    
    577
    -            // get composition model to use
    
    578
    -            WeightCompositionModel model = sampleCompositionModel.getModel(weightCategory);
    
    579
    -            // set of species still to fix
    
    580
    -            Set<Species> speciesToFix;
    
    581
    -            // set of species still to fix
    
    582
    -            Set<Species> speciesStillToFix;
    
    583
    -            // get total weight for species to fix from correctedCatches
    
    584
    -            float totalWeight;
    
    585
    -            if (model == null) {
    
    586
    -                // this means there is no specific composition for this weight category to apply for species to fix
    
    587
    -                // says there is no species to fix (so all catches will be copied to correctedCatchWeight (with no fixedFlag)
    
    588
    -                speciesToFix = speciesStillToFix = Collections.emptySet();
    
    589
    -                totalWeight = 0f;
    
    590
    -            } else {
    
    591
    -                // found a specific composition to apply for this weight category
    
    592
    -                speciesToFix = model.getSpecies();
    
    593
    -                speciesStillToFix = new HashSet<>(speciesToFix);
    
    594
    -                totalWeight = correctedCatchesForSpeciesToFix.getModel(weightCategory).getTotalWeight();
    
    595
    -            }
    
    596
    -            // divide the total weight to used by the number of zones of this activity
    
    597
    -            totalWeight = totalWeight / nbZones;
    
    598
    -            // Apply on all existing corrected catch weight
    
    599
    -            for (CorrectedElementaryCatch aCatch : correctedElementaryCatches.get(weightCategory)) {
    
    600
    -                Species speciesToUse = Objects.requireNonNull(aCatch.getSpecies());
    
    601
    -                // flag (was fixed or not)
    
    602
    -                boolean toFix;
    
    603
    -                // the corrected catch weight to add to the row
    
    604
    -                float correctedCatchWeight;
    
    605
    -                if (model != null && speciesToFix.contains(speciesToUse)) {
    
    606
    -                    // species to fix
    
    607
    -                    toFix = true;
    
    608
    -                    float weightRate = model.getWeightRate(speciesToUse);
    
    609
    -                    // new corrected catch weight
    
    610
    -                    correctedCatchWeight = totalWeight * weightRate;
    
    611
    -                    // species no more to treat
    
    612
    -                    speciesStillToFix.remove(speciesToUse);
    
    576
    +        try (WeightCompositionAggregateModel correctedCatchWeightModel = new WeightCompositionAggregateModel()) {
    
    577
    +            //FIXME-263 si la categorie de poids est dans la strate alors on ne doit que traiter cette catégorie
    
    578
    +            // Get all corrected catch group by weight category
    
    579
    +            Multimap<WeightCategoryTreatment, CorrectedElementaryCatch> correctedElementaryCatches =
    
    580
    +                    ActivityTopiaDao.groupByWeightCategoryTreatment(activity.getCorrectedElementaryCatch());
    
    581
    +            for (WeightCategoryTreatment weightCategory : correctedElementaryCatches.keySet()) {
    
    582
    +                Map<Species, Float> weights = new HashMap<>();
    
    583
    +                // get composition model to use
    
    584
    +                WeightCompositionModel model = sampleCompositionModel.getModel(weightCategory);
    
    585
    +                // set of species still to fix
    
    586
    +                Set<Species> speciesToFix;
    
    587
    +                // set of species still to fix
    
    588
    +                Set<Species> speciesStillToFix;
    
    589
    +                // get total weight for species to fix from correctedCatches
    
    590
    +                float totalWeight;
    
    591
    +                if (model == null) {
    
    592
    +                    // this means there is no specific composition for this weight category to apply for species to fix
    
    593
    +                    // says there is no species to fix (so all catches will be copied to correctedCatchWeight (with no fixedFlag)
    
    594
    +                    speciesToFix = speciesStillToFix = Collections.emptySet();
    
    595
    +                    totalWeight = 0f;
    
    613 596
                     } else {
    
    614
    -                    // nothing to fix, just propagate old value
    
    615
    -                    toFix = false;
    
    616
    -                    correctedCatchWeight = aCatch.getCatchWeight();
    
    597
    +                    // found a specific composition to apply for this weight category
    
    598
    +                    speciesToFix = model.getSpecies();
    
    599
    +                    speciesStillToFix = new HashSet<>(speciesToFix);
    
    600
    +                    totalWeight = correctedCatchesForSpeciesToFix.getModel(weightCategory).getTotalWeight();
    
    617 601
                     }
    
    618
    -                // hold added value (for logs)
    
    619
    -                weights.put(speciesToUse, correctedCatchWeight);
    
    620
    -                // Add to old value (if any)
    
    621
    -                Float oldCorrectedCatchWeight = aCatch.getCorrectedCatchWeight();
    
    622
    -                if (oldCorrectedCatchWeight == null) {
    
    623
    -                    oldCorrectedCatchWeight = 0f;
    
    602
    +                // divide the total weight to used by the number of zones of this activity
    
    603
    +                totalWeight = totalWeight / nbZones;
    
    604
    +                // Apply on all existing corrected catch weight
    
    605
    +                for (CorrectedElementaryCatch aCatch : correctedElementaryCatches.get(weightCategory)) {
    
    606
    +                    Species speciesToUse = Objects.requireNonNull(aCatch.getSpecies());
    
    607
    +                    // flag (was fixed or not)
    
    608
    +                    boolean toFix;
    
    609
    +                    // the corrected catch weight to add to the row
    
    610
    +                    float correctedCatchWeight;
    
    611
    +                    if (model != null && speciesToFix.contains(speciesToUse)) {
    
    612
    +                        // species to fix
    
    613
    +                        toFix = true;
    
    614
    +                        float weightRate = model.getWeightRate(speciesToUse);
    
    615
    +                        // new corrected catch weight
    
    616
    +                        correctedCatchWeight = totalWeight * weightRate;
    
    617
    +                        // species no more to treat
    
    618
    +                        speciesStillToFix.remove(speciesToUse);
    
    619
    +                    } else {
    
    620
    +                        // nothing to fix, just propagate old value
    
    621
    +                        toFix = false;
    
    622
    +                        correctedCatchWeight = aCatch.getCatchWeight();
    
    623
    +                    }
    
    624
    +                    // hold added value (for logs)
    
    625
    +                    weights.put(speciesToUse, correctedCatchWeight);
    
    626
    +                    // Add to old value (if any)
    
    627
    +                    Float oldCorrectedCatchWeight = aCatch.getCorrectedCatchWeight();
    
    628
    +                    if (oldCorrectedCatchWeight == null) {
    
    629
    +                        oldCorrectedCatchWeight = 0f;
    
    630
    +                    }
    
    631
    +                    aCatch.setCorrectedCatchWeight(oldCorrectedCatchWeight + correctedCatchWeight);
    
    632
    +                    aCatch.setCorrectedFlag(toFix);
    
    624 633
                     }
    
    625
    -                aCatch.setCorrectedCatchWeight(oldCorrectedCatchWeight + correctedCatchWeight);
    
    626
    -                aCatch.setCorrectedFlag(toFix);
    
    627
    -            }
    
    628
    -            // Creates new corrected catch weight records for all species still to fix
    
    629
    -            // Means they are in samples but not in catches
    
    630
    -            for (Species speciesToUse : speciesStillToFix) {
    
    631
    -                // weight rate of the species
    
    632
    -                float weightRate = model == null ? 1f : model.getWeightRate(speciesToUse);
    
    633
    -                // corrected catch weight
    
    634
    -                float correctedCatchWeight = totalWeight * weightRate;
    
    635
    -                // create new record
    
    636
    -                CorrectedElementaryCatch aCatch = correctedElementaryCatchDAO.create();
    
    637
    -                aCatch.setSpecies(speciesToUse);
    
    638
    -                aCatch.setWeightCategoryTreatment(weightCategory);
    
    639
    -                aCatch.setCatchWeight(0f);
    
    640
    -                aCatch.setCorrectedFlag(true);
    
    641
    -                aCatch.setCorrectedCatchWeight(correctedCatchWeight);
    
    642
    -                // hold added value (for logs)
    
    643
    -                weights.put(speciesToUse, correctedCatchWeight);
    
    644
    -                // add it to activity
    
    645
    -                activity.addCorrectedElementaryCatch(aCatch);
    
    634
    +                // Creates new corrected catch weight records for all species still to fix
    
    635
    +                // Means they are in samples but not in catches
    
    636
    +                for (Species speciesToUse : speciesStillToFix) {
    
    637
    +                    // weight rate of the species
    
    638
    +                    float weightRate = model == null ? 1f : model.getWeightRate(speciesToUse);
    
    639
    +                    // corrected catch weight
    
    640
    +                    float correctedCatchWeight = totalWeight * weightRate;
    
    641
    +                    // create new record
    
    642
    +                    CorrectedElementaryCatch aCatch = correctedElementaryCatchDAO.create();
    
    643
    +                    aCatch.setSpecies(speciesToUse);
    
    644
    +                    aCatch.setWeightCategoryTreatment(weightCategory);
    
    645
    +                    aCatch.setCatchWeight(0f);
    
    646
    +                    aCatch.setCorrectedFlag(true);
    
    647
    +                    aCatch.setCorrectedCatchWeight(correctedCatchWeight);
    
    648
    +                    // hold added value (for logs)
    
    649
    +                    weights.put(speciesToUse, correctedCatchWeight);
    
    650
    +                    // add it to activity
    
    651
    +                    activity.addCorrectedElementaryCatch(aCatch);
    
    652
    +                }
    
    653
    +                // add corrected weights used for this category
    
    654
    +                correctedCatchWeightModel.addModel(weightCategory, weights);
    
    646 655
                 }
    
    647
    -            // add corrected weights used for this category
    
    648
    -            correctedCatchWeightModel.addModel(weightCategory, weights);
    
    656
    +            // log corrected catches weight
    
    657
    +            String message = logCorrectedCatchWeight(correctedCatchWeightModel, getDecoratorService());
    
    658
    +            log.info(message);
    
    659
    +            addInfoMessage(message);
    
    660
    +            // add corrected catch weight done for this activity in stratum output model
    
    661
    +            catchStratum.addActivityOutputModel(correctedCatchWeightModel);
    
    649 662
             }
    
    650
    -        // log corrected catches weight
    
    651
    -        String message = logCorrectedCatchWeight(correctedCatchWeightModel, getDecoratorService());
    
    652
    -        log.info(message);
    
    653
    -        addInfoMessage(message);
    
    654
    -        // add corrected catch weight done for this activity in stratum output model
    
    655
    -        catchStratum.addActivityOutputModel(correctedCatchWeightModel);
    
    656 663
         }
    
    657 664
     
    
    658 665
         // -------------------------------------------------------------------------
    
    ... ... @@ -681,13 +688,13 @@ public class Level2Action extends T3Action<Level2Configuration> {
    681 688
     
    
    682 689
         @SuppressWarnings("unused")
    
    683 690
         public int getNbStrataFixed() {
    
    684
    -        return stratumsResult.size();
    
    691
    +        return stratumResultSet.size();
    
    685 692
         }
    
    686 693
     
    
    687 694
         @SuppressWarnings({"unused", "WeakerAccess"})
    
    688 695
         public Integer[] getAllSubstitutionLevels() {
    
    689 696
             Set<Integer> levels = new HashSet<>();
    
    690
    -        for (L2StratumResult stratumResult : stratumsResult) {
    
    697
    +        for (L2StratumResult stratumResult : stratumResultSet) {
    
    691 698
                 levels.add(stratumResult.getSubstitutionLevel());
    
    692 699
             }
    
    693 700
             List<Integer> result = new ArrayList<>(levels);
    
    ... ... @@ -703,7 +710,7 @@ public class Level2Action extends T3Action<Level2Configuration> {
    703 710
         @SuppressWarnings("unused")
    
    704 711
         public Collection<L2StratumResult> getStratumResult(int level) {
    
    705 712
             Set<L2StratumResult> singleResult = new LinkedHashSet<>();
    
    706
    -        for (L2StratumResult stratumResult : stratumsResult) {
    
    713
    +        for (L2StratumResult stratumResult : stratumResultSet) {
    
    707 714
                 if (level == stratumResult.getSubstitutionLevel()) {
    
    708 715
                     singleResult.add(stratumResult);
    
    709 716
                 }
    
    ... ... @@ -717,7 +724,7 @@ public class Level2Action extends T3Action<Level2Configuration> {
    717 724
             Integer[] levels = getAllSubstitutionLevels();
    
    718 725
             for (Integer level : levels) {
    
    719 726
                 Set<L2StratumResult> singleResult = new LinkedHashSet<>();
    
    720
    -            for (L2StratumResult stratumResult : stratumsResult) {
    
    727
    +            for (L2StratumResult stratumResult : stratumResultSet) {
    
    721 728
                     if (level == stratumResult.getSubstitutionLevel()) {
    
    722 729
                         singleResult.add(stratumResult);
    
    723 730
                     }
    
    ... ... @@ -752,7 +759,7 @@ public class Level2Action extends T3Action<Level2Configuration> {
    752 759
         @SuppressWarnings("unused")
    
    753 760
         public int getMaximumSizeForStratum() {
    
    754 761
             int result = 0;
    
    755
    -        for (L2StratumResult stratumResult : stratumsResult) {
    
    762
    +        for (L2StratumResult stratumResult : stratumResultSet) {
    
    756 763
                 result = Math.max(result, stratumResult.getLibelle().length() + 1);
    
    757 764
             }
    
    758 765
             return result;
    
    ... ... @@ -796,8 +803,8 @@ public class Level2Action extends T3Action<Level2Configuration> {
    796 803
                     modelForSpeciestoFix);
    
    797 804
         }
    
    798 805
     
    
    799
    -    public void setStratumsResult(Set<L2StratumResult> stratumsResult) {
    
    800
    -        this.stratumsResult = stratumsResult;
    
    806
    +    public void setStratumResultSet(Set<L2StratumResult> stratumResultSet) {
    
    807
    +        this.stratumResultSet = stratumResultSet;
    
    801 808
         }
    
    802 809
     
    
    803 810
         public void setInputCatchModelForAllSpecies(WeightCompositionAggregateModel inputCatchModelForAllSpecies) {
    
    ... ... @@ -807,4 +814,8 @@ public class Level2Action extends T3Action<Level2Configuration> {
    807 814
         public void setOutputCatchModelForAllSpecies(WeightCompositionAggregateModel outputCatchModelForAllSpecies) {
    
    808 815
             this.outputCatchModelForAllSpecies = outputCatchModelForAllSpecies;
    
    809 816
         }
    
    817
    +
    
    818
    +    T3ServiceContext getServiceContext() {
    
    819
    +        return serviceContext;
    
    820
    +    }
    
    810 821
     }

  • t3-actions/src/main/java/fr/ird/t3/actions/data/level3/L3SampleStratum.java
    ... ... @@ -181,7 +181,7 @@ public class L3SampleStratum extends SampleStratum<Level3Configuration, Level3Ac
    181 181
                     speciesCount.put(species, oldCount + newCount);
    
    182 182
                 }
    
    183 183
             }
    
    184
    -        addMergedActivitesCount(activities.size());
    
    184
    +        addMergedActivitiesCount(activities.size());
    
    185 185
     
    
    186 186
             if (log.isInfoEnabled()) {
    
    187 187
                 log.info(String.format("sampleStratumTotalWeight = %s", getSampleStratumTotalWeight()));
    

  • t3-actions/src/test/java/fr/ird/t3/actions/ActionResumeTest.java
    ... ... @@ -746,7 +746,7 @@ public class ActionResumeTest<C extends T3ActionConfiguration, A extends T3Actio
    746 746
                                 stratumResult.setNbActivities(5);
    
    747 747
     
    
    748 748
                                 stratumsResult.add(stratumResult);
    
    749
    -                            action.setStratumsResult(stratumsResult);
    
    749
    +                            action.setStratumResultSet(stratumsResult);
    
    750 750
     
    
    751 751
                                 action.setInputCatchModelForAllSpecies(new WeightCompositionAggregateModel());
    
    752 752
                                 action.setOutputCatchModelForAllSpecies(new WeightCompositionAggregateModel());
    

  • t3-domain/src/main/java/fr/ird/t3/actions/stratum/SampleStratum.java
    ... ... @@ -27,7 +27,6 @@ import fr.ird.t3.entities.reference.WeightCategoryTreatment;
    27 27
     import fr.ird.t3.services.IOCService;
    
    28 28
     import fr.ird.t3.services.T3ServiceContext;
    
    29 29
     import fr.ird.t3.services.ioc.InjectDAO;
    
    30
    -import org.nuiton.topia.persistence.TopiaException;
    
    31 30
     
    
    32 31
     import java.util.Collection;
    
    33 32
     import java.util.List;
    
    ... ... @@ -60,10 +59,13 @@ public abstract class SampleStratum<C extends LevelConfigurationWithStratum, A e
    60 59
          */
    
    61 60
         private Integer substitutionLevel;
    
    62 61
     
    
    62
    +    protected SampleStratum(StratumConfiguration<C> configuration, Collection<Species> speciesToFix) {
    
    63
    +        super(configuration, speciesToFix);
    
    64
    +    }
    
    65
    +
    
    63 66
         protected abstract SampleStratumLoader<C, A, S> newLoader();
    
    64 67
     
    
    65
    -    protected abstract String logSampleStratumLevel(int substitutionLevel,
    
    66
    -                                                    A messager);
    
    68
    +    protected abstract String logSampleStratumLevel(int substitutionLevel, A messager);
    
    67 69
     
    
    68 70
         /**
    
    69 71
          * Merge the given {@code activities} sample data in the stratum result.
    
    ... ... @@ -81,24 +83,15 @@ public abstract class SampleStratum<C extends LevelConfigurationWithStratum, A e
    81 83
          *
    
    82 84
          * @param serviceContext service context
    
    83 85
          * @param activities     the activities to merge
    
    84
    -     * @throws TopiaException if any database problem while loading data
    
    85 86
          */
    
    86
    -    protected abstract void mergeNewActivities(T3ServiceContext serviceContext,
    
    87
    -                                               Set<Activity> activities) throws TopiaException;
    
    88
    -
    
    89
    -    protected SampleStratum(StratumConfiguration<C> configuration,
    
    90
    -                            Collection<Species> speciesToFix) {
    
    91
    -        super(configuration, speciesToFix);
    
    92
    -    }
    
    87
    +    protected abstract void mergeNewActivities(T3ServiceContext serviceContext, Set<Activity> activities);
    
    93 88
     
    
    94
    -    protected final void addMergedActivitesCount(int nb) {
    
    89
    +    protected final void addMergedActivitiesCount(int nb) {
    
    95 90
             nbMergedActivities += nb;
    
    96 91
         }
    
    97 92
     
    
    98 93
         @Override
    
    99
    -    public void init(T3ServiceContext serviceContext,
    
    100
    -                     List<WeightCategoryTreatment> weightCategories,
    
    101
    -                     A messager) throws Exception {
    
    94
    +    public void init(T3ServiceContext serviceContext, List<WeightCategoryTreatment> weightCategories, A messager) throws Exception {
    
    102 95
     
    
    103 96
             SampleStratumLoader<C, A, S> stratumLoader = newLoader();
    
    104 97
     
    

  • t3-domain/src/main/java/fr/ird/t3/models/WeightCompositionAggregateModel.java
    ... ... @@ -85,8 +85,7 @@ public class WeightCompositionAggregateModel implements Closeable {
    85 85
         }
    
    86 86
     
    
    87 87
         public void addModel(WeightCompositionAggregateModel modelToMerge) {
    
    88
    -        for (WeightCompositionModel compositionModel :
    
    89
    -                modelToMerge.getModel().values()) {
    
    88
    +        for (WeightCompositionModel compositionModel : modelToMerge.getModel().values()) {
    
    90 89
                 addModel(compositionModel);
    
    91 90
             }
    
    92 91
         }