Search in sources :

Example 1 with FishingTripId

use of eu.europa.ec.fisheries.ers.service.search.FishingTripId in project UVMS-ActivityModule-APP by UnionVMS.

the class FishingTripDaoTest method testGetFishingTripIdsForMatchingFilterCriteria_allCommonFilters.

@Test
@SneakyThrows
public void testGetFishingTripIdsForMatchingFilterCriteria_allCommonFilters() throws Exception {
    dbSetupTracker.skipNextLaunch();
    Map<SearchFilter, String> searchCriteriaMap = new HashMap<>();
    searchCriteriaMap.put(SearchFilter.ACTIVITY_TYPE, "DEPARTURE");
    searchCriteriaMap.put(SearchFilter.SOURCE, "FLUX");
    searchCriteriaMap.put(SearchFilter.OWNER, "OWNER1");
    searchCriteriaMap.put(SearchFilter.FROM, "OWNER1");
    searchCriteriaMap.put(SearchFilter.PERIOD_START, "2012-05-27T07:47:31");
    searchCriteriaMap.put(SearchFilter.PERIOD_END, "2018-05-27T07:47:31");
    searchCriteriaMap.put(SearchFilter.REPORT_TYPE, "DECLARATION");
    searchCriteriaMap.put(SearchFilter.AREAS, "J");
    searchCriteriaMap.put(SearchFilter.GEAR, "GEAR_TYPE");
    searchCriteriaMap.put(SearchFilter.SPECIES, "BFT");
    searchCriteriaMap.put(SearchFilter.QUANTITY_MIN, "0");
    searchCriteriaMap.put(SearchFilter.QUANTITY_MAX, "50");
    searchCriteriaMap.put(SearchFilter.MASTER, "MARK");
    Map<SearchFilter, List<String>> searchCriteriaMapMultiVal = new HashMap<>();
    List<String> purposeCodeValues = new ArrayList<>();
    purposeCodeValues.add("9");
    purposeCodeValues.add("1");
    purposeCodeValues.add("5");
    purposeCodeValues.add("3");
    FishingActivityQuery query = new FishingActivityQuery();
    query.setSearchCriteriaMap(searchCriteriaMap);
    query.setSearchCriteriaMapMultipleValues(searchCriteriaMapMultiVal);
    searchCriteriaMapMultiVal.put(SearchFilter.PURPOSE, purposeCodeValues);
    Set<FishingTripId> fishingTripIdSet = dao.getFishingTripIdsForMatchingFilterCriteria(query);
    FishingTripId fishingTripId = new FishingTripId("NOR-TRP-20160517234053706", "EU_TRIP_ID");
    assertEquals(true, fishingTripIdSet.contains(fishingTripId));
    assertNotNull(fishingTripIdSet);
}
Also used : FishingActivityQuery(eu.europa.ec.fisheries.ers.service.search.FishingActivityQuery) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SearchFilter(eu.europa.ec.fisheries.uvms.activity.model.schemas.SearchFilter) ArrayList(java.util.ArrayList) List(java.util.List) FishingTripId(eu.europa.ec.fisheries.ers.service.search.FishingTripId) Test(org.junit.Test) SneakyThrows(lombok.SneakyThrows)

Example 2 with FishingTripId

use of eu.europa.ec.fisheries.ers.service.search.FishingTripId in project UVMS-ActivityModule-APP by UnionVMS.

the class FishingTripServiceBean method buildFishingTripSearchRespose.

/**
 * This method builds FishingTripSerachReponse objectc for FishingTripIds passed to the method
 * collectFishingActivities : If the value is TRUE, all fishing Activities for every fishing Trip would be sent in the response.
 * If the value is FALSE, No fishing activities would be sent in the response.
 */
public FishingTripResponse buildFishingTripSearchRespose(Set<FishingTripId> fishingTripIds, boolean collectFishingActivities) throws ServiceException {
    if (fishingTripIds == null || fishingTripIds.isEmpty()) {
        return new FishingTripResponse();
    }
    List<Integer> uniqueActivityIdList = new ArrayList<>();
    List<FishingActivitySummary> fishingActivitySummaries = new ArrayList<>();
    List<FishingTripIdWithGeometry> fishingTripIdLists = new ArrayList<>();
    for (FishingTripId fishingTripId : fishingTripIds) {
        // FIXME find a way to remove execution of queries inside loop
        FishingActivityQuery query = new FishingActivityQuery();
        Map<SearchFilter, String> searchCriteriaMap = new EnumMap<>(SearchFilter.class);
        searchCriteriaMap.put(SearchFilter.TRIP_ID, fishingTripId.getTripId());
        searchCriteriaMap.put(SearchFilter.FISHING_TRIP_SCHEME_ID, fishingTripId.getSchemeID());
        query.setSearchCriteriaMap(searchCriteriaMap);
        SortKey sortKey = new SortKey();
        // this is important to find out first and last fishing activity for the Fishing Trip
        sortKey.setSortBy(SearchFilter.PERIOD_START);
        sortKey.setReversed(false);
        query.setSorting(sortKey);
        List<FishingActivityEntity> fishingActivityEntityList = fishingActivityDao.getFishingActivityListByQuery(query);
        if (collectFishingActivities) {
            fishingActivitySummaries.addAll(getFishingActivitySummaryList(fishingActivityEntityList, uniqueActivityIdList));
        }
        FishingTripIdWithGeometry fishingTripIdWithGeometry = new FishingTripIdWithGeometryMapper().mapToFishingTripIdWithDetails(fishingTripId, fishingActivityEntityList);
        fishingTripIdLists.add(fishingTripIdWithGeometry);
    }
    // populate response object
    FishingTripResponse response = new FishingTripResponse();
    response.setFishingActivityLists(fishingActivitySummaries);
    response.setFishingTripIdLists(fishingTripIdLists);
    return response;
}
Also used : FishingActivitySummary(eu.europa.ec.fisheries.uvms.activity.model.schemas.FishingActivitySummary) FishingTripIdWithGeometryMapper(eu.europa.ec.fisheries.ers.service.mapper.FishingTripIdWithGeometryMapper) ArrayList(java.util.ArrayList) SearchFilter(eu.europa.ec.fisheries.uvms.activity.model.schemas.SearchFilter) SortKey(eu.europa.ec.fisheries.ers.service.search.SortKey) FishingTripIdWithGeometry(eu.europa.ec.fisheries.uvms.activity.model.schemas.FishingTripIdWithGeometry) FishingTripId(eu.europa.ec.fisheries.ers.service.search.FishingTripId) FishingActivityEntity(eu.europa.ec.fisheries.ers.fa.entities.FishingActivityEntity) BigInteger(java.math.BigInteger) FishingActivityQuery(eu.europa.ec.fisheries.ers.service.search.FishingActivityQuery) FishingTripResponse(eu.europa.ec.fisheries.uvms.activity.model.schemas.FishingTripResponse) EnumMap(java.util.EnumMap)

Example 3 with FishingTripId

use of eu.europa.ec.fisheries.ers.service.search.FishingTripId in project UVMS-ActivityModule-APP by UnionVMS.

the class FishingTripServiceBean method filterFishingTrips.

/**
 * This method filters fishing Trips for Activity tab
 */
@Override
public FishingTripResponse filterFishingTrips(FishingActivityQuery query) throws ServiceException {
    log.info("getFishingTripResponse For Filter");
    if ((MapUtils.isEmpty(query.getSearchCriteriaMap()) && MapUtils.isEmpty(query.getSearchCriteriaMapMultipleValues())) || activityServiceBean.checkAndEnrichIfVesselFiltersArePresent(query)) {
        return new FishingTripResponse();
    }
    Set<FishingTripId> fishingTripIds = fishingTripDao.getFishingTripIdsForMatchingFilterCriteria(query);
    log.debug("Fishing trips received from db:" + fishingTripIds.size());
    Integer totalCountOfRecords = fishingTripDao.getCountOfFishingTripsForMatchingFilterCriteria(query);
    log.debug("Total count of records: {} ", totalCountOfRecords);
    FishingTripResponse fishingTripResponse = buildFishingTripSearchRespose(fishingTripIds, false);
    fishingTripResponse.setTotalCountOfRecords(BigInteger.valueOf(totalCountOfRecords));
    return fishingTripResponse;
}
Also used : BigInteger(java.math.BigInteger) FishingTripResponse(eu.europa.ec.fisheries.uvms.activity.model.schemas.FishingTripResponse) FishingTripId(eu.europa.ec.fisheries.ers.service.search.FishingTripId)

Example 4 with FishingTripId

use of eu.europa.ec.fisheries.ers.service.search.FishingTripId in project UVMS-ActivityModule-APP by UnionVMS.

the class FishingTripDao method getFishingTripIdsForMatchingFilterCriteria.

/**
 * Get all the Fishing Trip entities for matching Filters
 *
 * @param query FishingActivityQuery
 * @return
 * @throws ServiceException
 */
public Set<FishingTripId> getFishingTripIdsForMatchingFilterCriteria(FishingActivityQuery query) throws ServiceException {
    Query listQuery = getQueryForFilterFishingTripIds(query);
    PaginationDto pagination = query.getPagination();
    if (pagination != null && pagination.getOffset() != null) {
        listQuery.setFirstResult(pagination.getOffset());
        listQuery.setMaxResults(pagination.getPageSize());
    }
    List<Object[]> resultList = listQuery.getResultList();
    if (CollectionUtils.isEmpty(resultList))
        return Collections.emptySet();
    Set<FishingTripId> fishingTripIds = new HashSet<>();
    for (Object[] objArr : resultList) {
        try {
            if (objArr != null && objArr.length == 2) {
                fishingTripIds.add(new FishingTripId((String) objArr[0], (String) objArr[1]));
            }
        } catch (Exception e) {
            log.error("Could not map sql selection to FishingTripId object", e);
        }
    }
    return fishingTripIds;
}
Also used : TypedQuery(javax.persistence.TypedQuery) Query(javax.persistence.Query) FishingActivityQuery(eu.europa.ec.fisheries.ers.service.search.FishingActivityQuery) PaginationDto(eu.europa.ec.fisheries.uvms.commons.rest.dto.PaginationDto) FishingTripId(eu.europa.ec.fisheries.ers.service.search.FishingTripId) ServiceException(eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException) HashSet(java.util.HashSet)

Example 5 with FishingTripId

use of eu.europa.ec.fisheries.ers.service.search.FishingTripId in project UVMS-ActivityModule-APP by UnionVMS.

the class MapperUtil method getFishingTripIdSet.

public static Set<FishingTripId> getFishingTripIdSet() {
    Set<FishingTripId> fishingTripIdSet = new HashSet<>();
    fishingTripIdSet.add(new FishingTripId("NOR-TRP-20160517234053706", "EU_TRIP_ID"));
    fishingTripIdSet.add(new FishingTripId("NOR-ABC-20160517234053706", "EU_TRIP_ID"));
    return fishingTripIdSet;
}
Also used : FishingTripId(eu.europa.ec.fisheries.ers.service.search.FishingTripId) HashSet(java.util.HashSet)

Aggregations

FishingTripId (eu.europa.ec.fisheries.ers.service.search.FishingTripId)7 FishingActivityQuery (eu.europa.ec.fisheries.ers.service.search.FishingActivityQuery)5 SearchFilter (eu.europa.ec.fisheries.uvms.activity.model.schemas.SearchFilter)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)3 List (java.util.List)3 SneakyThrows (lombok.SneakyThrows)3 Test (org.junit.Test)3 FishingTripResponse (eu.europa.ec.fisheries.uvms.activity.model.schemas.FishingTripResponse)2 BigInteger (java.math.BigInteger)2 HashSet (java.util.HashSet)2 FishingActivityEntity (eu.europa.ec.fisheries.ers.fa.entities.FishingActivityEntity)1 FishingTripIdWithGeometryMapper (eu.europa.ec.fisheries.ers.service.mapper.FishingTripIdWithGeometryMapper)1 SortKey (eu.europa.ec.fisheries.ers.service.search.SortKey)1 FishingActivitySummary (eu.europa.ec.fisheries.uvms.activity.model.schemas.FishingActivitySummary)1 FishingTripIdWithGeometry (eu.europa.ec.fisheries.uvms.activity.model.schemas.FishingTripIdWithGeometry)1 PaginationDto (eu.europa.ec.fisheries.uvms.commons.rest.dto.PaginationDto)1 ServiceException (eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException)1 EnumMap (java.util.EnumMap)1 Query (javax.persistence.Query)1