Search in sources :

Example 11 with SearchFilter

use of eu.europa.ec.fisheries.uvms.activity.model.schemas.SearchFilter 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 12 with SearchFilter

use of eu.europa.ec.fisheries.uvms.activity.model.schemas.SearchFilter in project UVMS-ActivityModule-APP by UnionVMS.

the class SearchQueryBuilder method createWherePartForQueryForFilters.

public StringBuilder createWherePartForQueryForFilters(StringBuilder sql, FishingActivityQuery query) {
    Map<SearchFilter, FilterDetails> filterMappings = filterMap.getFilterMappings();
    Set<SearchFilter> keySet = new HashSet<>();
    if (MapUtils.isNotEmpty(query.getSearchCriteriaMap())) {
        keySet.addAll(query.getSearchCriteriaMap().keySet());
    }
    if (MapUtils.isNotEmpty(query.getSearchCriteriaMapMultipleValues())) {
        keySet.addAll(query.getSearchCriteriaMapMultipleValues().keySet());
    }
    // Create Where part of SQL Query
    int i = 0;
    for (SearchFilter key : keySet) {
        if (!appendWhereQueryPart(sql, filterMappings, keySet, i, key)) {
            continue;
        }
        i++;
    }
    return sql;
}
Also used : FilterDetails(eu.europa.ec.fisheries.ers.service.search.FilterDetails) SearchFilter(eu.europa.ec.fisheries.uvms.activity.model.schemas.SearchFilter) HashSet(java.util.HashSet)

Example 13 with SearchFilter

use of eu.europa.ec.fisheries.uvms.activity.model.schemas.SearchFilter 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)

Example 14 with SearchFilter

use of eu.europa.ec.fisheries.uvms.activity.model.schemas.SearchFilter in project UVMS-ActivityModule-APP by UnionVMS.

the class FishingActivityRequestMapper method extractFiltersAsMapWithMultipleValues.

/**
 * This method sorts incoming list and separates Filters with multiple values and put it into Map.
 * @param filterTypes List of searchFilters
 * @return Map<SearchFilter,List<String>> Map of SearchFilter and list of values for the filter
 * @throws ServiceException
 */
private static Map<SearchFilter, List<String>> extractFiltersAsMapWithMultipleValues(List<ListValueTypeFilter> filterTypes) throws ServiceException {
    Set<SearchFilter> filtersWithMultipleValues = FilterMap.getFiltersWhichSupportMultipleValues();
    Map<SearchFilter, List<String>> searchMap = new EnumMap<>(SearchFilter.class);
    for (ListValueTypeFilter filterType : filterTypes) {
        SearchFilter filter = filterType.getKey();
        if (!filtersWithMultipleValues.contains(filter)) {
            throw new ServiceException("Filter provided with multiple Values do not support Multiple Values. Filter name is:" + filter);
        }
        searchMap.put(filterType.getKey(), filterType.getValues());
    }
    return searchMap;
}
Also used : ServiceException(eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException) SearchFilter(eu.europa.ec.fisheries.uvms.activity.model.schemas.SearchFilter) List(java.util.List) EnumMap(java.util.EnumMap) ListValueTypeFilter(eu.europa.ec.fisheries.uvms.activity.model.schemas.ListValueTypeFilter)

Example 15 with SearchFilter

use of eu.europa.ec.fisheries.uvms.activity.model.schemas.SearchFilter in project UVMS-ActivityModule-APP by UnionVMS.

the class FaCatchReportServiceBean method getCatchDetailsScreenTable.

/**
 * This method gets you table structure for Catch details summary on TRIP SUMMARY VIEW
 * @param tripId data will be returned for this tripId
 * @param isLanding If landing then summary structure will include PRESENTATION information otherwise only species information will be included
 * @return
 * @throws ServiceException
 */
public FACatchSummaryDTO getCatchDetailsScreenTable(String tripId, boolean isLanding) throws ServiceException {
    FishingActivityQuery query = new FishingActivityQuery();
    List<GroupCriteria> groupByFields = getGroupByFields(isLanding);
    query.setGroupByFields(groupByFields);
    Map<SearchFilter, String> searchCriteriaMap = new EnumMap<>(SearchFilter.class);
    searchCriteriaMap.put(SearchFilter.TRIP_ID, tripId);
    query.setSearchCriteriaMap(searchCriteriaMap);
    return getCatchSummaryReport(query, isLanding);
}
Also used : FishingActivityQuery(eu.europa.ec.fisheries.ers.service.search.FishingActivityQuery) SearchFilter(eu.europa.ec.fisheries.uvms.activity.model.schemas.SearchFilter) EnumMap(java.util.EnumMap) GroupCriteria(eu.europa.ec.fisheries.uvms.activity.model.schemas.GroupCriteria)

Aggregations

SearchFilter (eu.europa.ec.fisheries.uvms.activity.model.schemas.SearchFilter)29 FishingActivityQuery (eu.europa.ec.fisheries.ers.service.search.FishingActivityQuery)19 ArrayList (java.util.ArrayList)18 List (java.util.List)17 Test (org.junit.Test)17 SneakyThrows (lombok.SneakyThrows)16 HashMap (java.util.HashMap)14 EnumMap (java.util.EnumMap)9 SortKey (eu.europa.ec.fisheries.ers.service.search.SortKey)8 PaginationDto (eu.europa.ec.fisheries.uvms.commons.rest.dto.PaginationDto)7 ServiceException (eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException)7 FilterMap (eu.europa.ec.fisheries.ers.service.search.FilterMap)4 FishingTripId (eu.europa.ec.fisheries.ers.service.search.FishingTripId)4 GroupCriteria (eu.europa.ec.fisheries.uvms.activity.model.schemas.GroupCriteria)4 Map (java.util.Map)4 FishingTripResponse (eu.europa.ec.fisheries.uvms.activity.model.schemas.FishingTripResponse)3 FaCatchSummaryCustomProxy (eu.europa.ec.fisheries.ers.fa.dao.proxy.FaCatchSummaryCustomProxy)2 FishingActivityEntity (eu.europa.ec.fisheries.ers.fa.entities.FishingActivityEntity)2 FilterFishingActivityReportResultDTO (eu.europa.ec.fisheries.ers.service.dto.FilterFishingActivityReportResultDTO)2 FilterDetails (eu.europa.ec.fisheries.ers.service.search.FilterDetails)2