Search in sources :

Example 6 with SortKey

use of eu.europa.ec.fisheries.ers.service.search.SortKey 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 7 with SortKey

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

the class FishingActivityDaoTest method testGetCountForFishingActivityListByQuery.

@Test
@SneakyThrows
public void testGetCountForFishingActivityListByQuery() throws Exception {
    dbSetupTracker.skipNextLaunch();
    FishingActivityQuery query = new FishingActivityQuery();
    Map<SearchFilter, String> searchCriteriaMap = new HashMap<>();
    Map<SearchFilter, List<String>> searchCriteriaMapMultiVal = new HashMap<>();
    List<String> activityTypeValues = new ArrayList<>();
    activityTypeValues.add("FISHING_OPERATION");
    activityTypeValues.add("DEPARTURE");
    searchCriteriaMapMultiVal.put(SearchFilter.ACTIVITY_TYPE, activityTypeValues);
    List<String> purposeCodeValues = new ArrayList<>();
    purposeCodeValues.add("5");
    purposeCodeValues.add("9");
    searchCriteriaMapMultiVal.put(SearchFilter.PURPOSE, purposeCodeValues);
    query.setSearchCriteriaMapMultipleValues(searchCriteriaMapMultiVal);
    searchCriteriaMap.put(SearchFilter.OWNER, "OWNER1");
    searchCriteriaMap.put(SearchFilter.PERIOD_START, "2012-05-27T07:47:31");
    searchCriteriaMap.put(SearchFilter.PERIOD_END, "2015-05-27T07:47:31");
    searchCriteriaMap.put(SearchFilter.VESSEL_NAME, "vessel1");
    searchCriteriaMap.put(SearchFilter.VESSEL_IDENTIFIRE, "CFR123");
    searchCriteriaMap.put(SearchFilter.REPORT_TYPE, "DECLARATION");
    searchCriteriaMap.put(SearchFilter.GEAR, "GEAR_TYPE");
    searchCriteriaMap.put(SearchFilter.SPECIES, "PLE");
    searchCriteriaMap.put(SearchFilter.MASTER, "MARK");
    searchCriteriaMap.put(SearchFilter.AREAS, "27.4.b");
    searchCriteriaMap.put(SearchFilter.QUANTITY_MIN, "0");
    searchCriteriaMap.put(SearchFilter.QUANTITY_MAX, "25");
    searchCriteriaMap.put(SearchFilter.SOURCE, "FLUX");
    SortKey sortingDto = new SortKey();
    sortingDto.setSortBy(SearchFilter.PURPOSE);
    sortingDto.setReversed(false);
    query.setSorting(sortingDto);
    query.setSearchCriteriaMap(searchCriteriaMap);
    PaginationDto pagination = new PaginationDto();
    pagination.setPageSize(2);
    pagination.setOffset(1);
    query.setPagination(pagination);
    SortKey sortingDto2 = new SortKey();
    sortingDto2.setSortBy(SearchFilter.OCCURRENCE);
    sortingDto2.setReversed(false);
    query.setSorting(sortingDto2);
    int size = dao.getCountForFishingActivityListByQuery(query);
    System.out.println("done:" + size);
// assertNotEquals(0, size);
}
Also used : FishingActivityQuery(eu.europa.ec.fisheries.ers.service.search.FishingActivityQuery) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PaginationDto(eu.europa.ec.fisheries.uvms.commons.rest.dto.PaginationDto) SearchFilter(eu.europa.ec.fisheries.uvms.activity.model.schemas.SearchFilter) ArrayList(java.util.ArrayList) List(java.util.List) SortKey(eu.europa.ec.fisheries.ers.service.search.SortKey) Test(org.junit.Test) SneakyThrows(lombok.SneakyThrows)

Example 8 with SortKey

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

the class SearchQueryBuilder method getJoinPartForSortingOptions.

/**
 * This method makes sure that Table join is present for the Filter for which sorting has been requested.
 *
 * @param sql
 * @param query
 * @return
 */
private StringBuilder getJoinPartForSortingOptions(StringBuilder sql, FishingActivityQuery query) {
    SortKey sort = query.getSorting();
    // IF sorting has been requested and
    if (sort == null) {
        return sql;
    }
    SearchFilter field = sort.getSortBy();
    if (field == null) {
        return sql;
    }
    // Make sure that the field which we want to sort, table Join is present for it.
    switch(getFiledCase(sql, field)) {
        case 1:
            appendLeftJoinFetch(sql, filterMap.DELIMITED_PERIOD_TABLE_ALIAS);
            break;
        case 2:
            appendLeftJoinFetch(sql, FilterMap.FLUX_REPORT_DOC_TABLE_ALIAS);
            break;
        case 3:
            checkAndAppendIfNeededFluxReportDocTable(sql);
            break;
        default:
            break;
    }
    return sql;
}
Also used : SortKey(eu.europa.ec.fisheries.ers.service.search.SortKey) SearchFilter(eu.europa.ec.fisheries.uvms.activity.model.schemas.SearchFilter)

Aggregations

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