Search in sources :

Example 16 with FaCatchEntity

use of eu.europa.ec.fisheries.ers.fa.entities.FaCatchEntity in project UVMS-ActivityModule-APP by UnionVMS.

the class FishingActivityMapper method getSpeciesCode.

protected List<String> getSpeciesCode(FishingActivityEntity entity) {
    if (entity == null || entity.getFaCatchs() == null) {
        return Collections.emptyList();
    }
    HashSet<String> speciesCode = new HashSet<>();
    Set<FaCatchEntity> faCatchList = entity.getFaCatchs();
    for (FaCatchEntity faCatch : faCatchList) {
        speciesCode.add(faCatch.getSpeciesCode());
        getSpeciesCodeFromAapProduct(faCatch, speciesCode);
    }
    speciesCode.remove(null);
    return new ArrayList<>(speciesCode);
}
Also used : FaCatchEntity(eu.europa.ec.fisheries.ers.fa.entities.FaCatchEntity) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Example 17 with FaCatchEntity

use of eu.europa.ec.fisheries.ers.fa.entities.FaCatchEntity in project UVMS-ActivityModule-APP by UnionVMS.

the class FishingActivityMapper method getFaCatchEntities.

protected Set<FaCatchEntity> getFaCatchEntities(List<FACatch> faCatches, FishingActivityEntity fishingActivityEntity) {
    if (faCatches == null || faCatches.isEmpty()) {
        return Collections.emptySet();
    }
    Set<FaCatchEntity> faCatchEntities = new HashSet<>();
    for (FACatch faCatch : faCatches) {
        FaCatchEntity faCatchEntity = FaCatchMapper.INSTANCE.mapToFaCatchEntity(faCatch);
        faCatchEntity.setFishingActivity(fishingActivityEntity);
        faCatchEntity.setGearTypeCode(extractFishingGearTypeCode(faCatchEntity.getFishingGears()));
        faCatchEntity.setPresentation(extractPresentation(faCatchEntity.getAapProcesses()));
        faCatchEntities.add(mapFluxLocationSchemeIds(faCatch, faCatchEntity));
    }
    return faCatchEntities;
}
Also used : FaCatchEntity(eu.europa.ec.fisheries.ers.fa.entities.FaCatchEntity) FACatch(un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._20.FACatch) HashSet(java.util.HashSet)

Example 18 with FaCatchEntity

use of eu.europa.ec.fisheries.ers.fa.entities.FaCatchEntity 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)

Example 19 with FaCatchEntity

use of eu.europa.ec.fisheries.ers.fa.entities.FaCatchEntity in project UVMS-ActivityModule-APP by UnionVMS.

the class FishingActivityMapper method getQuantity.

/**
 * This method will calculate sum of all the weights of FACatches
 * @param entity
 * @return
 */
protected Double getQuantity(FishingActivityEntity entity) {
    if (entity == null || entity.getFaCatchs() == null) {
        return new Double(0);
    }
    Double quantity = new Double(0);
    Set<FaCatchEntity> faCatchList = entity.getFaCatchs();
    for (FaCatchEntity faCatch : faCatchList) {
        if (faCatch.getCalculatedWeightMeasure() != null)
            quantity = quantity + faCatch.getCalculatedWeightMeasure();
        getQuantityFromAapProduct(faCatch, quantity);
    }
    return quantity;
}
Also used : FaCatchEntity(eu.europa.ec.fisheries.ers.fa.entities.FaCatchEntity)

Example 20 with FaCatchEntity

use of eu.europa.ec.fisheries.ers.fa.entities.FaCatchEntity in project UVMS-ActivityModule-APP by UnionVMS.

the class FaCatchesProcessorMapper method mapFaCatchListToCatchGroupDto.

/**
 * Maps a list of CatchEntities (rappresenting a froup) to a  FaCatchGroupDto;
 *
 * @param groupCatchList
 * @return
 */
private static FaCatchGroupDto mapFaCatchListToCatchGroupDto(List<FaCatchEntity> groupCatchList) {
    FaCatchGroupDto groupDto = new FaCatchGroupDto();
    FaCatchEntity catchEntity = groupCatchList.get(0);
    // Set primary properties on groupDto
    groupDto.setType(catchEntity.getTypeCode());
    groupDto.setSpecies(catchEntity.getSpeciesCode());
    // Fill the denomination location part of the GroupDto.
    groupDto.setLocations(FaCatchGroupMapper.INSTANCE.mapFaCatchEntityToDenominationLocation(catchEntity));
    // calculate Totals And Fill Soecified Locations and Gears Per each Subgroup (subgrupped on BMS/LSC)
    calculateTotalsAndFillSubgroups(groupCatchList, groupDto);
    return groupDto;
}
Also used : FaCatchGroupDto(eu.europa.ec.fisheries.ers.service.dto.facatch.FaCatchGroupDto) FaCatchEntity(eu.europa.ec.fisheries.ers.fa.entities.FaCatchEntity)

Aggregations

FaCatchEntity (eu.europa.ec.fisheries.ers.fa.entities.FaCatchEntity)28 FishingActivityEntity (eu.europa.ec.fisheries.ers.fa.entities.FishingActivityEntity)11 Test (org.junit.Test)11 CatchEvolutionProgressDTO (eu.europa.ec.fisheries.ers.service.dto.fishingtrip.CatchEvolutionProgressDTO)10 FaReportDocumentType (eu.europa.ec.fisheries.ers.fa.utils.FaReportDocumentType)7 FaCatchTypeEnum (eu.europa.ec.fisheries.uvms.activity.model.schemas.FaCatchTypeEnum)7 FaReportDocumentEntity (eu.europa.ec.fisheries.ers.fa.entities.FaReportDocumentEntity)5 ArrayList (java.util.ArrayList)4 HashSet (java.util.HashSet)4 SneakyThrows (lombok.SneakyThrows)4 AapProcessEntity (eu.europa.ec.fisheries.ers.fa.entities.AapProcessEntity)3 FishingTripEntity (eu.europa.ec.fisheries.ers.fa.entities.FishingTripEntity)3 FishingActivityViewDTO (eu.europa.ec.fisheries.ers.service.dto.view.parent.FishingActivityViewDTO)3 BaseActivityViewMapper (eu.europa.ec.fisheries.ers.service.mapper.view.base.BaseActivityViewMapper)3 FACatch (un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._20.FACatch)3 AapProductEntity (eu.europa.ec.fisheries.ers.fa.entities.AapProductEntity)2 FishingGearEntity (eu.europa.ec.fisheries.ers.fa.entities.FishingGearEntity)2 FluxCharacteristicEntity (eu.europa.ec.fisheries.ers.fa.entities.FluxCharacteristicEntity)2 FluxLocationEntity (eu.europa.ec.fisheries.ers.fa.entities.FluxLocationEntity)2 FluxReportDocumentEntity (eu.europa.ec.fisheries.ers.fa.entities.FluxReportDocumentEntity)2