Search in sources :

Example 1 with FaCatchGroupDetailsDto

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);
}
Also used : FaCatchEntity(eu.europa.ec.fisheries.ers.fa.entities.FaCatchEntity) LinkedHashSet(java.util.LinkedHashSet) FaCatchGroupDetailsDto(eu.europa.ec.fisheries.ers.service.dto.facatch.FaCatchGroupDetailsDto) FluxLocationDto(eu.europa.ec.fisheries.ers.service.dto.view.FluxLocationDto)

Aggregations

FaCatchEntity (eu.europa.ec.fisheries.ers.fa.entities.FaCatchEntity)1 FaCatchGroupDetailsDto (eu.europa.ec.fisheries.ers.service.dto.facatch.FaCatchGroupDetailsDto)1 FluxLocationDto (eu.europa.ec.fisheries.ers.service.dto.view.FluxLocationDto)1 LinkedHashSet (java.util.LinkedHashSet)1