Search in sources :

Example 26 with FishingActivityEntity

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

the class FishingTripServiceBean method getFishingActivitySummaryList.

/**
 * This method creates FishingActivitySummary object from FishingActivityEntity object retrieved from database.
 *
 * @param uniqueActivityIdList      This method helps parent function to collect FishingActivities for all the fishingTrips. In order to avoid duplicate fishing Activities, we need to maintain uniqueActivityIdList
 * @param fishingActivityEntityList
 * @return
 */
public List<FishingActivitySummary> getFishingActivitySummaryList(List<FishingActivityEntity> fishingActivityEntityList, List<Integer> uniqueActivityIdList) {
    List<FishingActivitySummary> fishingActivitySummaryList = new ArrayList<>();
    if (CollectionUtils.isEmpty(uniqueActivityIdList)) {
        uniqueActivityIdList = new ArrayList<>();
    }
    for (FishingActivityEntity fishingActivityEntity : fishingActivityEntityList) {
        if (fishingActivityEntity != null && uniqueActivityIdList.add(fishingActivityEntity.getId())) {
            FishingActivitySummary fishingActivitySummary = FishingActivityMapper.INSTANCE.mapToFishingActivitySummary(fishingActivityEntity);
            ContactPartyEntity contactParty = getContactParty(fishingActivityEntity);
            if (contactParty != null) {
                VesselContactPartyType vesselContactParty = FishingActivityMapper.INSTANCE.mapToVesselContactParty(contactParty);
                fishingActivitySummary.setVesselContactParty(vesselContactParty);
            }
            if (fishingActivitySummary != null) {
                fishingActivitySummaryList.add(fishingActivitySummary);
            }
        }
    }
    return fishingActivitySummaryList;
}
Also used : FishingActivitySummary(eu.europa.ec.fisheries.uvms.activity.model.schemas.FishingActivitySummary) ArrayList(java.util.ArrayList) VesselContactPartyType(eu.europa.ec.fisheries.uvms.activity.model.schemas.VesselContactPartyType) ContactPartyEntity(eu.europa.ec.fisheries.ers.fa.entities.ContactPartyEntity) FishingActivityEntity(eu.europa.ec.fisheries.ers.fa.entities.FishingActivityEntity)

Example 27 with FishingActivityEntity

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

the class FishingTripServiceBean method populateFishingActivityReportListAndFishingTripSummary.

/**
 * @param fishingTripId     - Fishing trip summary will be collected for this tripID
 * @param reportDTOList     - This DTO will have details about Fishing Activities.Method will process and populate data into this list     *
 * @param multipolygon      - Activities only in this area would be selected
 * @param isOnlyTripSummary - This method you could reuse to only get Fishing trip summary as well
 * @throws ServiceException
 */
@Override
public Map<String, FishingActivityTypeDTO> populateFishingActivityReportListAndFishingTripSummary(String fishingTripId, List<ReportDTO> reportDTOList, Geometry multipolygon, boolean isOnlyTripSummary) throws ServiceException {
    List<FishingActivityEntity> fishingActivityList = fishingActivityDao.getFishingActivityListForFishingTrip(fishingTripId, multipolygon);
    if (CollectionUtils.isEmpty(fishingActivityList)) {
        return Collections.emptyMap();
    }
    Map<String, FishingActivityTypeDTO> tripSummary = new HashMap<>();
    for (FishingActivityEntity activityEntity : fishingActivityList) {
        if (!isOnlyTripSummary) {
            ReportDTO reportDTO = FishingActivityMapper.INSTANCE.mapToReportDTO(activityEntity);
            reportDTOList.add(reportDTO);
        }
        if (activityEntity != null && activityEntity.getFaReportDocument() != null && ActivityConstants.DECLARATION.equalsIgnoreCase(activityEntity.getFaReportDocument().getTypeCode())) {
            // FA Report should be of type Declaration. And Fishing Activity type should be Either Departure,Arrival or Landing
            populateFishingTripSummary(activityEntity, tripSummary);
        }
    }
    return tripSummary;
}
Also used : FishingActivityTypeDTO(eu.europa.ec.fisheries.ers.service.dto.fishingtrip.FishingActivityTypeDTO) HashMap(java.util.HashMap) ReportDTO(eu.europa.ec.fisheries.ers.service.dto.fishingtrip.ReportDTO) FishingActivityEntity(eu.europa.ec.fisheries.ers.fa.entities.FishingActivityEntity)

Example 28 with FishingActivityEntity

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

the class FishingTripServiceBean method createMessageCounter.

/**
 * Populates the MessageCounter adding to the right counter 1 unit depending on the type of report (typeCode, purposeCode, size()).
 *
 * @param faReportDocumentList
 */
public MessageCountDTO createMessageCounter(List<FaReportDocumentEntity> faReportDocumentList) {
    MessageCountDTO messagesCounter = new MessageCountDTO();
    if (CollectionUtils.isEmpty(faReportDocumentList)) {
        return messagesCounter;
    }
    // Reports total
    messagesCounter.setNoOfReports(faReportDocumentList.size());
    for (FaReportDocumentEntity faReport : faReportDocumentList) {
        String faDocumentType = faReport.getTypeCode();
        String purposeCode = faReport.getFluxReportDocument().getPurpose();
        // Declarations / Notifications
        if (ActivityConstants.DECLARATION.equalsIgnoreCase(faDocumentType)) {
            messagesCounter.setNoOfDeclarations(messagesCounter.getNoOfDeclarations() + 1);
        } else if (ActivityConstants.NOTIFICATION.equalsIgnoreCase(faDocumentType)) {
            messagesCounter.setNoOfNotifications(messagesCounter.getNoOfNotifications() + 1);
        }
        // Fishing operations
        Set<FishingActivityEntity> faEntitiyList = faReport.getFishingActivities();
        if (isNotEmpty(faEntitiyList)) {
            for (FishingActivityEntity faEntity : faEntitiyList) {
                if (FishingActivityTypeEnum.FISHING_OPERATION.toString().equalsIgnoreCase(faEntity.getTypeCode())) {
                    messagesCounter.setNoOfFishingOperations(messagesCounter.getNoOfFishingOperations() + 1);
                }
            }
        }
        // PurposeCode : Deletions / Cancellations / Corrections
        if (ActivityConstants.DELETE.equalsIgnoreCase(purposeCode)) {
            messagesCounter.setNoOfDeletions(messagesCounter.getNoOfDeletions() + 1);
        } else if (ActivityConstants.CANCELLATION.equalsIgnoreCase(purposeCode)) {
            messagesCounter.setNoOfCancellations(messagesCounter.getNoOfCancellations() + 1);
        } else if (ActivityConstants.CORRECTION.equalsIgnoreCase(purposeCode)) {
            messagesCounter.setNoOfCorrections(messagesCounter.getNoOfCorrections() + 1);
        }
    }
    return messagesCounter;
}
Also used : FaReportDocumentEntity(eu.europa.ec.fisheries.ers.fa.entities.FaReportDocumentEntity) MessageCountDTO(eu.europa.ec.fisheries.ers.service.dto.fishingtrip.MessageCountDTO) FishingActivityEntity(eu.europa.ec.fisheries.ers.fa.entities.FishingActivityEntity)

Example 29 with FishingActivityEntity

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

the class FishingTripServiceBean method getVesselDetailsForFishingTrip.

@Override
public VesselDetailsDTO getVesselDetailsForFishingTrip(final String fishingTripId) throws ServiceException {
    if (fishingTripId == null) {
        throw new IllegalArgumentException("PARAMETER CANNOT BE NULL");
    }
    VesselDetailsDTO detailsDTO = null;
    try {
        VesselTransportMeansEntity latestVesselByTripId = vesselTransportMeansDao.findLatestVesselByTripId(fishingTripId);
        if (latestVesselByTripId != null) {
            FishingActivityEntity parent = latestVesselByTripId.getFishingActivity();
            detailsDTO = getVesselDetailsDTO(latestVesselByTripId, parent);
        }
    } catch (ServiceException e) {
        throw new ServiceException(e.getMessage(), e);
    }
    return detailsDTO;
}
Also used : VesselTransportMeansEntity(eu.europa.ec.fisheries.ers.fa.entities.VesselTransportMeansEntity) ServiceException(eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException) VesselDetailsDTO(eu.europa.ec.fisheries.ers.service.dto.fareport.details.VesselDetailsDTO) FishingActivityEntity(eu.europa.ec.fisheries.ers.fa.entities.FishingActivityEntity)

Example 30 with FishingActivityEntity

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

the class FluxMessageServiceBean method setTripStartAndEndDateForFishingTrip.

private void setTripStartAndEndDateForFishingTrip(FishingTripEntity fishingTripEntity) {
    Set<FishingTripIdentifierEntity> identifierEntities = fishingTripEntity.getFishingTripIdentifiers();
    if (CollectionUtils.isEmpty(identifierEntities))
        return;
    for (FishingTripIdentifierEntity tripIdentifierEntity : identifierEntities) {
        try {
            List<FishingActivityEntity> fishingActivityEntityList = fishingTripService.getAllFishingActivitiesForTrip(tripIdentifierEntity.getTripId());
            if (CollectionUtils.isNotEmpty(fishingActivityEntityList)) {
                // Calculate trip start date
                FishingActivityEntity firstFishingActivity = fishingActivityEntityList.get(0);
                tripIdentifierEntity.setCalculatedTripStartDate(firstFishingActivity.getCalculatedStartTime());
                // calculate trip end date
                Date calculatedTripEndDate;
                int totalActivities = fishingActivityEntityList.size();
                if (totalActivities > 1) {
                    calculatedTripEndDate = fishingActivityEntityList.get(totalActivities - 1).getCalculatedStartTime();
                } else {
                    calculatedTripEndDate = firstFishingActivity.getCalculatedStartTime();
                }
                tripIdentifierEntity.setCalculatedTripEndDate(calculatedTripEndDate);
            }
        } catch (Exception e) {
            log.error("Error while trying to calculate FishingTrip start and end Date", e);
        }
    }
}
Also used : FishingTripIdentifierEntity(eu.europa.ec.fisheries.ers.fa.entities.FishingTripIdentifierEntity) Date(java.util.Date) ParseException(com.vividsolutions.jts.io.ParseException) ServiceException(eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException) FishingActivityEntity(eu.europa.ec.fisheries.ers.fa.entities.FishingActivityEntity)

Aggregations

FishingActivityEntity (eu.europa.ec.fisheries.ers.fa.entities.FishingActivityEntity)45 Test (org.junit.Test)17 ArrayList (java.util.ArrayList)14 FaCatchEntity (eu.europa.ec.fisheries.ers.fa.entities.FaCatchEntity)11 FaReportDocumentEntity (eu.europa.ec.fisheries.ers.fa.entities.FaReportDocumentEntity)9 VesselTransportMeansEntity (eu.europa.ec.fisheries.ers.fa.entities.VesselTransportMeansEntity)8 CatchEvolutionProgressDTO (eu.europa.ec.fisheries.ers.service.dto.fishingtrip.CatchEvolutionProgressDTO)5 FishingActivityViewDTO (eu.europa.ec.fisheries.ers.service.dto.view.parent.FishingActivityViewDTO)5 SneakyThrows (lombok.SneakyThrows)5 FishingActivity (un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._20.FishingActivity)5 FishingTripEntity (eu.europa.ec.fisheries.ers.fa.entities.FishingTripEntity)4 HashMap (java.util.HashMap)4 Geometry (com.vividsolutions.jts.geom.Geometry)3 FishingTripIdentifierEntity (eu.europa.ec.fisheries.ers.fa.entities.FishingTripIdentifierEntity)3 FluxLocationEntity (eu.europa.ec.fisheries.ers.fa.entities.FluxLocationEntity)3 FluxReportDocumentEntity (eu.europa.ec.fisheries.ers.fa.entities.FluxReportDocumentEntity)3 BaseActivityViewMapper (eu.europa.ec.fisheries.ers.service.mapper.view.base.BaseActivityViewMapper)3 FishingActivityQuery (eu.europa.ec.fisheries.ers.service.search.FishingActivityQuery)3 FishingActivitySummary (eu.europa.ec.fisheries.uvms.activity.model.schemas.FishingActivitySummary)3 ServiceException (eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException)3