Search in sources :

Example 1 with SortKey

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

the class FishingTripServiceBeanTest method testBuildFishingTripSearchRespose.

@Test
@SneakyThrows
public void testBuildFishingTripSearchRespose() throws ServiceException, JsonProcessingException {
    FishingActivityQuery query = new FishingActivityQuery();
    Map<SearchFilter, String> searchCriteriaMap = new EnumMap<>(SearchFilter.class);
    searchCriteriaMap.put(SearchFilter.TRIP_ID, "NOR-TRP-20160517234053706");
    searchCriteriaMap.put(SearchFilter.FISHING_TRIP_SCHEME_ID, "EU_TRIP_ID");
    query.setSearchCriteriaMap(searchCriteriaMap);
    SortKey sortKey = new SortKey();
    sortKey.setSortBy(SearchFilter.PERIOD_START);
    sortKey.setReversed(false);
    query.setSorting(sortKey);
    when(fishingActivityDao.getFishingActivityListByQuery(any(FishingActivityQuery.class))).thenReturn(MapperUtil.getFishingActivityEntityList());
    // Trigger
    FishingTripResponse response = fishingTripService.buildFishingTripSearchRespose(MapperUtil.getFishingTripIdSet(), false);
    assertNotNull(response);
}
Also used : FishingActivityQuery(eu.europa.ec.fisheries.ers.service.search.FishingActivityQuery) FishingTripResponse(eu.europa.ec.fisheries.uvms.activity.model.schemas.FishingTripResponse) SearchFilter(eu.europa.ec.fisheries.uvms.activity.model.schemas.SearchFilter) SortKey(eu.europa.ec.fisheries.ers.service.search.SortKey) EnumMap(java.util.EnumMap) Test(org.junit.Test) SneakyThrows(lombok.SneakyThrows)

Example 2 with SortKey

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

the class FishingActivityDaoTest method testGetFishingActivityListByQuery.

@Test
@SneakyThrows
public void testGetFishingActivityListByQuery() 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);
    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.PORT, "GBR");
    searchCriteriaMap.put(SearchFilter.QUANTITY_MIN, "0");
    searchCriteriaMap.put(SearchFilter.QUANTITY_MAX, "25");
    query.setSearchCriteriaMap(searchCriteriaMap);
    PaginationDto pagination = new PaginationDto();
    pagination.setPageSize(2);
    pagination.setOffset(1);
    query.setPagination(pagination);
    SortKey sortingDto = new SortKey();
    sortingDto.setSortBy(SearchFilter.OCCURRENCE);
    sortingDto.setReversed(false);
    query.setSorting(sortingDto);
    List<FishingActivityEntity> finishingActivityList = dao.getFishingActivityListByQuery(query);
    System.out.println("done:" + finishingActivityList.size());
    assertNotNull(finishingActivityList);
}
Also used : 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) SortKey(eu.europa.ec.fisheries.ers.service.search.SortKey) FishingActivityQuery(eu.europa.ec.fisheries.ers.service.search.FishingActivityQuery) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test) SneakyThrows(lombok.SneakyThrows)

Example 3 with SortKey

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

the class FishingActivityDaoTest method testGetFishingActivityListByQuery_GetByFaReportID.

@Test
@SneakyThrows
public void testGetFishingActivityListByQuery_GetByFaReportID() 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.PORT, "GBR");
    searchCriteriaMap.put(SearchFilter.QUANTITY_MIN, "0");
    searchCriteriaMap.put(SearchFilter.QUANTITY_MAX, "25");
    searchCriteriaMap.put(SearchFilter.FA_REPORT_ID, "1");
    query.setSearchCriteriaMap(searchCriteriaMap);
    PaginationDto pagination = new PaginationDto();
    pagination.setPageSize(2);
    pagination.setOffset(1);
    query.setPagination(pagination);
    SortKey sortingDto = new SortKey();
    sortingDto.setSortBy(SearchFilter.OCCURRENCE);
    sortingDto.setReversed(false);
    query.setSorting(sortingDto);
    List<FishingActivityEntity> finishingActivityList = dao.getFishingActivityListByQuery(query);
    assertNotNull(finishingActivityList);
}
Also used : 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) SortKey(eu.europa.ec.fisheries.ers.service.search.SortKey) FishingActivityQuery(eu.europa.ec.fisheries.ers.service.search.FishingActivityQuery) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test) SneakyThrows(lombok.SneakyThrows)

Example 4 with SortKey

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

the class SearchQueryBuilderTest method testCreateSQL_DateSorting.

@Test
@SneakyThrows
public void testCreateSQL_DateSorting() throws ServiceException {
    FishingActivityQuery query = new FishingActivityQuery();
    Map<SearchFilter, String> searchCriteriaMap = new HashMap<>();
    searchCriteriaMap.put(SearchFilter.OWNER, "OWNER1");
    searchCriteriaMap.put(SearchFilter.PERIOD_START, "2012-05-27 07:47:31");
    searchCriteriaMap.put(SearchFilter.PERIOD_END, "2015-05-27 07:47:31");
    searchCriteriaMap.put(SearchFilter.VESSEL_NAME, "vessel1");
    searchCriteriaMap.put(SearchFilter.VESSEL_IDENTIFIRE, "CFR123");
    searchCriteriaMap.put(SearchFilter.PURPOSE, "9");
    searchCriteriaMap.put(SearchFilter.REPORT_TYPE, "DECLARATION");
    searchCriteriaMap.put(SearchFilter.GEAR, "GEAR_TYPE");
    // searchCriteriaMap.put(SearchFilter.ACTIVITY_TYPE, "DEPARTURE");
    searchCriteriaMap.put(SearchFilter.SPECIES, "PLE");
    searchCriteriaMap.put(SearchFilter.MASTER, "MARK");
    searchCriteriaMap.put(SearchFilter.AREAS, "27.4.b");
    searchCriteriaMap.put(SearchFilter.PORT, "GBR");
    searchCriteriaMap.put(SearchFilter.QUANTITY_MIN, "0");
    searchCriteriaMap.put(SearchFilter.QUANTITY_MAX, "25");
    searchCriteriaMap.put(SearchFilter.WEIGHT_MEASURE, "TNE");
    searchCriteriaMap.put(SearchFilter.SOURCE, "FLUX");
    SortKey sortingDto = new SortKey();
    sortingDto.setSortBy(SearchFilter.PERIOD_START);
    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.setReversed(false);
    query.setSorting(sortingDto);
    query.setSorting(sortingDto2);
    SearchQueryBuilder search = new FishingActivitySearchBuilder();
    StringBuilder sql = search.createSQL(query);
    assertNotNull(sql);
}
Also used : FishingActivitySearchBuilder(eu.europa.ec.fisheries.ers.service.search.builder.FishingActivitySearchBuilder) FishingActivityQuery(eu.europa.ec.fisheries.ers.service.search.FishingActivityQuery) HashMap(java.util.HashMap) PaginationDto(eu.europa.ec.fisheries.uvms.commons.rest.dto.PaginationDto) SearchQueryBuilder(eu.europa.ec.fisheries.ers.service.search.builder.SearchQueryBuilder) SearchFilter(eu.europa.ec.fisheries.uvms.activity.model.schemas.SearchFilter) SortKey(eu.europa.ec.fisheries.ers.service.search.SortKey) Test(org.junit.Test) SneakyThrows(lombok.SneakyThrows)

Example 5 with SortKey

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

the class SearchQueryBuilder method createSortPartForQuery.

/**
 * Create sorting part for the Query
 * @param sql
 * @param query
 * @return
 * @throws ServiceException
 */
public StringBuilder createSortPartForQuery(StringBuilder sql, FishingActivityQuery query) throws ServiceException {
    LOG.debug("Create Sorting part of Query");
    SortKey sort = query.getSorting();
    if (sort != null && sort.getSortBy() != null) {
        SearchFilter field = sort.getSortBy();
        // if (SearchFilter.PERIOD_START.equals(field) || SearchFilter.PERIOD_END.equals(field)) {
        if (SearchFilter.PERIOD_END.equals(field)) {
            getSqlForStartAndEndDateSorting(sql, field, query);
        }
        String orderby = " ASC ";
        if (sort.isReversed()) {
            orderby = " DESC ";
        }
        String sortFieldMapping = FilterMap.getFilterSortMappings().get(field);
        if (sortFieldMapping == null) {
            throw new ServiceException("Information about which database field to be used for sorting is unavailable");
        }
        sql.append(" order by ").append(sortFieldMapping).append(orderby);
    } else {
        sql.append(" order by fa.acceptedDatetime ASC ");
    }
    // LOG.debug("Generated Query After Sort :" + sql);
    return sql;
}
Also used : ServiceException(eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException) 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