Search in sources :

Example 1 with TripWidgetDto

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

the class FishingTripServiceBean method getTripWidgetDto.

@Override
public /**
 *  Returns TripWidgetDto based on the tripId and activityId
 */
TripWidgetDto getTripWidgetDto(FishingActivityEntity activityEntity, String tripId) {
    if (activityEntity == null && tripId == null) {
        return null;
    }
    TripWidgetDto tripWidgetDto = new TripWidgetDto();
    try {
        if (tripId != null) {
            log.debug("Trip Id found for Fishing Activity. Get TripWidget information for tripID :" + tripId);
            TripOverviewDto tripOverviewDto = getTripOverviewDto(activityEntity, tripId);
            List<TripOverviewDto> tripOverviewDtoList = new ArrayList<>();
            tripOverviewDtoList.add(tripOverviewDto);
            tripWidgetDto.setTrips(tripOverviewDtoList);
            if (activityEntity != null && activityEntity.getFaReportDocument() != null && CollectionUtils.isNotEmpty(activityEntity.getFaReportDocument().getVesselTransportMeans())) {
                Set<VesselTransportMeansEntity> vesselTransportMeansEntities = activityEntity.getFaReportDocument().getVesselTransportMeans();
                for (VesselTransportMeansEntity vesselTransportMeansEntity : vesselTransportMeansEntities) {
                    if (vesselTransportMeansEntity.getFishingActivity() == null) {
                        tripWidgetDto.setVesselDetails(getVesselDetailsDTO(vesselTransportMeansEntity, activityEntity));
                        break;
                    }
                }
            }
            // VesselDetailsDTO detailsDTO = getVesselDetailsForFishingTrip(tripId);
            // tripWidgetDto.setVesselDetails(detailsDTO);
            log.debug("tripWidgetDto set for tripID :" + tripId);
        } else {
            log.debug("TripId is not received for the screen. Try to get TripSummary information for all the tripIds specified for FishingActivity:" + activityEntity.getId());
            return createTripWidgetDtoWithFishingActivity(activityEntity);
        }
    } catch (ServiceException e) {
        log.error("Error while creating TripWidgetDto.", e);
    }
    return tripWidgetDto;
}
Also used : VesselTransportMeansEntity(eu.europa.ec.fisheries.ers.fa.entities.VesselTransportMeansEntity) ServiceException(eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException) ArrayList(java.util.ArrayList) TripWidgetDto(eu.europa.ec.fisheries.ers.service.dto.view.TripWidgetDto) TripOverviewDto(eu.europa.ec.fisheries.ers.service.dto.view.TripOverviewDto)

Example 2 with TripWidgetDto

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

the class FishingTripServiceBean method createTripWidgetDtoWithFishingActivity.

public TripWidgetDto createTripWidgetDtoWithFishingActivity(FishingActivityEntity activityEntity) throws ServiceException {
    TripWidgetDto tripWidgetDto = new TripWidgetDto();
    Set<FishingTripEntity> fishingTripEntities = activityEntity.getFishingTrips();
    if (CollectionUtils.isEmpty(fishingTripEntities)) {
        throw new ServiceException(" Could not find fishingTrips associated with FishingActivity id :" + activityEntity.getId());
    }
    List<TripOverviewDto> tripOverviewDtoList = new ArrayList<>();
    // try to find unique tripIds for the fishing Activity
    Set<String> tripIdSet = new HashSet<>();
    for (FishingTripEntity fishingTripEntity : fishingTripEntities) {
        Set<FishingTripIdentifierEntity> identifierEntities = fishingTripEntity.getFishingTripIdentifiers();
        for (FishingTripIdentifierEntity tripIdentifierEntity : identifierEntities) {
            if (!tripIdSet.contains(tripIdentifierEntity.getTripId())) {
                log.debug("Get Trip summary information for tripID :" + tripIdentifierEntity.getTripId());
                tripOverviewDtoList.add(getTripOverviewDto(activityEntity, tripIdentifierEntity.getTripId()));
                tripIdSet.add(tripIdentifierEntity.getTripId());
            }
        }
    }
    tripWidgetDto.setTrips(tripOverviewDtoList);
    // As per new requirement, vessel should always be the one associated with fishing Activity in the trip widget
    if (activityEntity != null && activityEntity.getFaReportDocument() != null && CollectionUtils.isNotEmpty(activityEntity.getFaReportDocument().getVesselTransportMeans())) {
        Set<VesselTransportMeansEntity> vesselTransportMeansEntities = activityEntity.getFaReportDocument().getVesselTransportMeans();
        for (VesselTransportMeansEntity vesselTransportMeansEntity : vesselTransportMeansEntities) {
            if (vesselTransportMeansEntity.getFishingActivity() == null) {
                tripWidgetDto.setVesselDetails(getVesselDetailsDTO(vesselTransportMeansEntity, activityEntity));
                break;
            }
        }
    }
    return tripWidgetDto;
}
Also used : FishingTripEntity(eu.europa.ec.fisheries.ers.fa.entities.FishingTripEntity) VesselTransportMeansEntity(eu.europa.ec.fisheries.ers.fa.entities.VesselTransportMeansEntity) ArrayList(java.util.ArrayList) TripWidgetDto(eu.europa.ec.fisheries.ers.service.dto.view.TripWidgetDto) FishingTripIdentifierEntity(eu.europa.ec.fisheries.ers.fa.entities.FishingTripIdentifierEntity) ServiceException(eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException) TripOverviewDto(eu.europa.ec.fisheries.ers.service.dto.view.TripOverviewDto) LinkedHashSet(java.util.LinkedHashSet) HashSet(java.util.HashSet)

Aggregations

VesselTransportMeansEntity (eu.europa.ec.fisheries.ers.fa.entities.VesselTransportMeansEntity)2 TripOverviewDto (eu.europa.ec.fisheries.ers.service.dto.view.TripOverviewDto)2 TripWidgetDto (eu.europa.ec.fisheries.ers.service.dto.view.TripWidgetDto)2 ServiceException (eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException)2 ArrayList (java.util.ArrayList)2 FishingTripEntity (eu.europa.ec.fisheries.ers.fa.entities.FishingTripEntity)1 FishingTripIdentifierEntity (eu.europa.ec.fisheries.ers.fa.entities.FishingTripIdentifierEntity)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1