Search in sources :

Example 1 with FishingActivitySearchBuilder

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

the class SearchQueryBuilderTest method testCreateSQL.

@Test
@SneakyThrows
public void testCreateSQL() throws ServiceException {
    FishingActivityQuery query = new FishingActivityQuery();
    Map<SearchFilter, String> searchCriteriaMap = new HashMap<>();
    searchCriteriaMap.put(SearchFilter.ACTIVITY_TYPE, "DEPARTURE");
    query.setSearchCriteriaMap(searchCriteriaMap);
    PaginationDto pagination = new PaginationDto();
    pagination.setPageSize(2);
    pagination.setOffset(1);
    query.setPagination(pagination);
    SearchQueryBuilder search = new FishingActivitySearchBuilder();
    StringBuilder sql = search.createSQL(query);
    System.out.println("done:" + sql);
    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) Test(org.junit.Test) SneakyThrows(lombok.SneakyThrows)

Example 2 with FishingActivitySearchBuilder

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

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

the class FishingActivityDao method getFishingActivityListByQuery.

/*
     Get all the Fishing Activities which match Filter criterias mentioned in the Input. Also, provide the sorted data based on what user has requested.
     Provide paginated data if user has asked for it
     */
public List<FishingActivityEntity> getFishingActivityListByQuery(FishingActivityQuery query) throws ServiceException {
    LOG.info("Get Fishing Activity Report list by Query.");
    FishingActivitySearchBuilder search = new FishingActivitySearchBuilder();
    // Create Query dynamically based on filter and Sort criteria
    StringBuilder sqlToGetActivityList = search.createSQL(query);
    // Apply real values to Query built
    Query listQuery = getTypedQueryForFishingActivityFilter(sqlToGetActivityList, query, search);
    // Agreed with frontend.
    // Page size : Number of record to be retrieved in one page
    // offSet : The position from where the result should be picked. Starts with 0
    PaginationDto pagination = query.getPagination();
    if (pagination != null) {
        LOG.debug("Pagination information getting applied to Query is: Offset :" + pagination.getOffset() + " PageSize:" + pagination.getPageSize());
        listQuery.setFirstResult(pagination.getOffset());
        listQuery.setMaxResults(pagination.getPageSize());
    }
    return listQuery.getResultList();
}
Also used : FishingActivitySearchBuilder(eu.europa.ec.fisheries.ers.service.search.builder.FishingActivitySearchBuilder) Query(javax.persistence.Query) FishingActivityQuery(eu.europa.ec.fisheries.ers.service.search.FishingActivityQuery) PaginationDto(eu.europa.ec.fisheries.uvms.commons.rest.dto.PaginationDto)

Example 4 with FishingActivitySearchBuilder

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

the class FishingActivityDao method getCountForFishingActivityListByQuery.

public Integer getCountForFishingActivityListByQuery(FishingActivityQuery query) throws ServiceException {
    FishingActivitySearchBuilder search = new FishingActivitySearchBuilder();
    LOG.info("Get Total Count for Fishing Activities When filter criteria is present");
    StringBuilder sqlToGetActivityListCount = search.createSQL(query);
    Query countQuery = getTypedQueryForFishingActivityFilter(sqlToGetActivityListCount, query, search);
    return countQuery.getResultList().size();
}
Also used : FishingActivitySearchBuilder(eu.europa.ec.fisheries.ers.service.search.builder.FishingActivitySearchBuilder) Query(javax.persistence.Query) FishingActivityQuery(eu.europa.ec.fisheries.ers.service.search.FishingActivityQuery)

Aggregations

FishingActivityQuery (eu.europa.ec.fisheries.ers.service.search.FishingActivityQuery)4 FishingActivitySearchBuilder (eu.europa.ec.fisheries.ers.service.search.builder.FishingActivitySearchBuilder)4 PaginationDto (eu.europa.ec.fisheries.uvms.commons.rest.dto.PaginationDto)3 SearchQueryBuilder (eu.europa.ec.fisheries.ers.service.search.builder.SearchQueryBuilder)2 SearchFilter (eu.europa.ec.fisheries.uvms.activity.model.schemas.SearchFilter)2 HashMap (java.util.HashMap)2 Query (javax.persistence.Query)2 SneakyThrows (lombok.SneakyThrows)2 Test (org.junit.Test)2 SortKey (eu.europa.ec.fisheries.ers.service.search.SortKey)1