Search in sources :

Example 1 with FluxLocationDto

use of eu.europa.ec.fisheries.ers.service.dto.view.FluxLocationDto 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 2 with FluxLocationDto

use of eu.europa.ec.fisheries.ers.service.dto.view.FluxLocationDto in project UVMS-ActivityModule-APP by UnionVMS.

the class FaCatchesProcessorMapper method fillSpecifiedAndDestinationLocationsInGroupDetails.

/**
 * Fills the locations on FaCatchGroupDetailsDto DTO.
 *
 * @param fluxLocations
 * @param groupDetailsDto
 */
private static void fillSpecifiedAndDestinationLocationsInGroupDetails(Set<FluxLocationEntity> fluxLocations, FaCatchGroupDetailsDto groupDetailsDto) {
    if (CollectionUtils.isEmpty(fluxLocations)) {
        return;
    }
    List<DestinationLocationDto> destLocDtoList = groupDetailsDto.getDestinationLocation();
    List<FluxLocationDto> specifiedFluxLocDto = groupDetailsDto.getSpecifiedFluxLocations();
    for (FluxLocationEntity actLoc : fluxLocations) {
        String fluxLocationType = actLoc.getFluxLocationType();
        if (StringUtils.equals(fluxLocationType, FluxLocationCatchTypeEnum.FA_CATCH_DESTINATION.getType())) {
            destLocDtoList.add(new DestinationLocationDto(actLoc.getFluxLocationIdentifier(), actLoc.getCountryId(), actLoc.getName()));
        } else if (StringUtils.equals(fluxLocationType, FluxLocationCatchTypeEnum.FA_CATCH_SPECIFIED.getType())) {
            specifiedFluxLocDto.add(FluxLocationMapper.INSTANCE.mapEntityToFluxLocationDto(actLoc));
        }
    }
    groupDetailsDto.setDestinationLocation(destLocDtoList);
    groupDetailsDto.setSpecifiedFluxLocations(specifiedFluxLocDto);
}
Also used : DestinationLocationDto(eu.europa.ec.fisheries.ers.service.dto.facatch.DestinationLocationDto) FluxLocationDto(eu.europa.ec.fisheries.ers.service.dto.view.FluxLocationDto) FluxLocationEntity(eu.europa.ec.fisheries.ers.fa.entities.FluxLocationEntity)

Example 3 with FluxLocationDto

use of eu.europa.ec.fisheries.ers.service.dto.view.FluxLocationDto in project UVMS-ActivityModule-APP by UnionVMS.

the class FishingOperationViewMapper method mapFaEntityToFaDto.

@Override
public FishingActivityViewDTO mapFaEntityToFaDto(FishingActivityEntity faEntity) {
    FishingActivityViewDTO viewDTO = new FishingActivityViewDTO();
    ActivityDetailsDto detailsDto = mapActivityDetails(faEntity);
    detailsDto.setOccurrence(faEntity.getOccurence());
    detailsDto.setVesselActivity(faEntity.getVesselActivityCode());
    if (faEntity.getOperationsQuantity() != null && faEntity.getOperationsQuantity().getValue() != null) {
        detailsDto.setNrOfOperation(faEntity.getOperationsQuantity().getValue().intValue());
    }
    detailsDto.setFisheryType(faEntity.getFisheryTypeCode());
    detailsDto.setSpeciesTarget(faEntity.getSpeciesTargetCode());
    Set<FishingActivityIdentifierEntity> fishingActivityIdentifiers = faEntity.getFishingActivityIdentifiers();
    detailsDto.setIdentifiers(FishingActivityIdentifierMapper.INSTANCE.mapToIdentifierDTOSet(fishingActivityIdentifiers));
    detailsDto.setFishingTime(this.calculateFishingTime(faEntity.getDelimitedPeriods()));
    viewDTO.setActivityDetails(detailsDto);
    viewDTO.setGears(this.getGearsFromEntity(faEntity.getFishingGears()));
    viewDTO.setReportDetails(this.getReportDocsFromEntity(faEntity.getFaReportDocument()));
    viewDTO.setCatches(this.mapCatchesToGroupDto(faEntity));
    viewDTO.setProcessingProducts(this.getProcessingProductsByFaCatches(faEntity.getFaCatchs()));
    viewDTO.setGearProblems(GearShotRetrievalTileMapper.INSTANCE.mapGearProblemsToGearsDto(faEntity.getGearProblems()));
    viewDTO.setGearShotRetrievalList(GearShotRetrievalTileMapperImpl.INSTANCE.mapFromRelatedFishingActivities(faEntity));
    Set<FluxLocationDto> fluxLocationDtos = mapFromFluxLocation(faEntity.getFluxLocations());
    viewDTO.setLocations(fluxLocationDtos);
    viewDTO.setVesselDetails(getVesselDetailsDTO(faEntity));
    return viewDTO;
}
Also used : ActivityDetailsDto(eu.europa.ec.fisheries.ers.service.dto.view.ActivityDetailsDto) FishingActivityViewDTO(eu.europa.ec.fisheries.ers.service.dto.view.parent.FishingActivityViewDTO) FishingActivityIdentifierEntity(eu.europa.ec.fisheries.ers.fa.entities.FishingActivityIdentifierEntity) FluxLocationDto(eu.europa.ec.fisheries.ers.service.dto.view.FluxLocationDto)

Example 4 with FluxLocationDto

use of eu.europa.ec.fisheries.ers.service.dto.view.FluxLocationDto in project UVMS-ActivityModule-APP by UnionVMS.

the class BaseActivityViewMapper method getSortedAreas.

public AreaDto getSortedAreas(FishingActivityEntity faEntity, Comparator<FluxLocationDto> comparator) {
    AreaDto areaDto = getAreas(faEntity);
    final List<FluxLocationDto> fluxLocationDtos = new ArrayList<>(areaDto.getFluxLocations());
    TreeSet<FluxLocationDto> fluxLocationDtoTreeSet = new TreeSet<FluxLocationDto>(comparator);
    fluxLocationDtoTreeSet.addAll(fluxLocationDtos);
    areaDto.setFluxLocations(fluxLocationDtoTreeSet);
    return areaDto;
}
Also used : TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) AreaDto(eu.europa.ec.fisheries.ers.service.dto.view.AreaDto) FluxLocationDto(eu.europa.ec.fisheries.ers.service.dto.view.FluxLocationDto)

Example 5 with FluxLocationDto

use of eu.europa.ec.fisheries.ers.service.dto.view.FluxLocationDto in project UVMS-ActivityModule-APP by UnionVMS.

the class ActivityServiceBean method addPortDescriptions.

private void addPortDescriptions(FishingActivityViewDTO fishingActivityViewDTO, String fluxLocationIdSchemeId) {
    if (fishingActivityViewDTO == null || StringUtils.isBlank(fluxLocationIdSchemeId)) {
        return;
    }
    final String ACRONYM = "LOCATION";
    String filter = null;
    final List<String> columnsList = new ArrayList<String>(Arrays.asList("code"));
    Integer nrOfResults = 1;
    if (CollectionUtils.isNotEmpty(fishingActivityViewDTO.getLocations())) {
        for (FluxLocationDto fluxLocationDto : fishingActivityViewDTO.getLocations()) {
            if (fluxLocationIdSchemeId.equals(fluxLocationDto.getFluxLocationIdentifierSchemeId())) {
                try {
                    filter = fluxLocationDto.getFluxLocationIdentifier();
                    List<String> codeDescriptions = mdrModuleService.getAcronymFromMdr(ACRONYM, filter, columnsList, nrOfResults, "description").get("description");
                    String codeDescription = codeDescriptions.get(0);
                    fluxLocationDto.setPortDescription(codeDescription);
                } catch (ServiceException e) {
                    log.error("Error while trying to set port description on FluxLocationDto.", e);
                } catch (IndexOutOfBoundsException iobe) {
                    log.error("Error while trying to set port description on FluxLocationDto! Description for code: " + fluxLocationDto.getTypeCode() + " doesn't exist", iobe);
                }
            }
        }
    }
}
Also used : ServiceException(eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException) ArrayList(java.util.ArrayList) FluxLocationDto(eu.europa.ec.fisheries.ers.service.dto.view.FluxLocationDto)

Aggregations

FluxLocationDto (eu.europa.ec.fisheries.ers.service.dto.view.FluxLocationDto)8 FluxLocationEntity (eu.europa.ec.fisheries.ers.fa.entities.FluxLocationEntity)4 Test (org.junit.Test)3 BaseUnitilsTest (eu.europa.ec.fisheries.uvms.BaseUnitilsTest)2 ArrayList (java.util.ArrayList)2 FaCatchEntity (eu.europa.ec.fisheries.ers.fa.entities.FaCatchEntity)1 FishingActivityIdentifierEntity (eu.europa.ec.fisheries.ers.fa.entities.FishingActivityIdentifierEntity)1 DestinationLocationDto (eu.europa.ec.fisheries.ers.service.dto.facatch.DestinationLocationDto)1 FaCatchGroupDetailsDto (eu.europa.ec.fisheries.ers.service.dto.facatch.FaCatchGroupDetailsDto)1 ActivityDetailsDto (eu.europa.ec.fisheries.ers.service.dto.view.ActivityDetailsDto)1 AreaDto (eu.europa.ec.fisheries.ers.service.dto.view.AreaDto)1 FishingActivityViewDTO (eu.europa.ec.fisheries.ers.service.dto.view.parent.FishingActivityViewDTO)1 ServiceException (eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException)1 LinkedHashSet (java.util.LinkedHashSet)1 TreeSet (java.util.TreeSet)1 SneakyThrows (lombok.SneakyThrows)1