use of eu.europa.ec.fisheries.ers.service.dto.facatch.FaCatchGroupDetailsDto in project UVMS-ActivityModule-APP by UnionVMS.
the class FaCatchesProcessorMapper method calculateTotalsAndFillSubgroups.
/**
* Subgroups by BMS and LSC and :
* Calculates the total and fills all the details related to each subgroup.
*
* @param groupCatchList
* @param groupDto
*/
private static void calculateTotalsAndFillSubgroups(List<FaCatchEntity> groupCatchList, FaCatchGroupDto groupDto) {
Map<String, FaCatchGroupDetailsDto> groupingDetailsMap = groupDto.getGroupingDetails();
FaCatchGroupDetailsDto lscGroupDetailsDto = new FaCatchGroupDetailsDto();
FaCatchGroupDetailsDto bmsGroupDetailsDto = new FaCatchGroupDetailsDto();
// Weight and units totals
Double lscGroupTotalWeight = null;
Double lscGroupTotalUnits = null;
Double bmsGroupTotalWeight = null;
Double bmsGroupTotalUnits = null;
for (FaCatchEntity entity : groupCatchList) {
Double calculatedWeightMeasure = entity.getCalculatedWeightMeasure();
if (calculatedWeightMeasure == null) {
calculatedWeightMeasure = extractLiveWeight(entity.getAapProcesses());
}
Double unitQuantity = entity.getUnitQuantity();
String fishClassCode = entity.getFishClassCode() != null ? entity.getFishClassCode() : StringUtils.EMPTY;
switch(fishClassCode) {
case LSC:
// Weight and Units calculation
lscGroupTotalWeight = Utils.addDoubles(calculatedWeightMeasure, lscGroupTotalWeight);
lscGroupTotalUnits = Utils.addDoubles(unitQuantity, lscGroupTotalUnits);
fillDetailsForSubGroup(lscGroupDetailsDto, entity);
break;
case BMS:
// Weight and Units calculation
bmsGroupTotalWeight = Utils.addDoubles(calculatedWeightMeasure, bmsGroupTotalWeight);
bmsGroupTotalUnits = Utils.addDoubles(unitQuantity, bmsGroupTotalUnits);
fillDetailsForSubGroup(bmsGroupDetailsDto, entity);
break;
default:
log.error("While constructing Fa Catch Section of the view the FaCatchEntity with id : " + entity.getId() + " is neither LSC or BMS!");
}
}
setWeightsForSubGroup(groupDto, lscGroupDetailsDto, bmsGroupDetailsDto, lscGroupTotalWeight, lscGroupTotalUnits, bmsGroupTotalWeight, bmsGroupTotalUnits);
// Put the 2 subgroup properties in the groupingDetailsMap (property of FaCatchGroupDto).
List<FluxLocationDto> lscGroupDetailsDtoSpecifiedFluxLocations = lscGroupDetailsDto.getSpecifiedFluxLocations();
// remove duplicates
lscGroupDetailsDto.setSpecifiedFluxLocations(new ArrayList<>(new LinkedHashSet<>(lscGroupDetailsDtoSpecifiedFluxLocations)));
List<FluxLocationDto> bmsGroupDetailsDtoSpecifiedFluxLocations = bmsGroupDetailsDto.getSpecifiedFluxLocations();
// remove duplicates
bmsGroupDetailsDto.setSpecifiedFluxLocations(new ArrayList<>(new LinkedHashSet<>(bmsGroupDetailsDtoSpecifiedFluxLocations)));
groupingDetailsMap.put(BMS, bmsGroupDetailsDto);
groupingDetailsMap.put(LSC, lscGroupDetailsDto);
}
Aggregations