Search in sources :

Example 6 with PaginationDto

use of eu.europa.ec.fisheries.uvms.commons.rest.dto.PaginationDto in project UVMS-ActivityModule-APP by UnionVMS.

the class FishingTripDao method getFishingTripsForMatchingFilterCriteria.

/**
 * Get all the Fishing Trip entities for matching Filters
 *
 * @param query FishingActivityQuery
 * @return
 * @throws ServiceException
 */
public List<FishingTripEntity> getFishingTripsForMatchingFilterCriteria(FishingActivityQuery query) throws ServiceException {
    Query listQuery = getQueryForFilterFishingTrips(query);
    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 : 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)

Example 7 with PaginationDto

use of eu.europa.ec.fisheries.uvms.commons.rest.dto.PaginationDto 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 8 with PaginationDto

use of eu.europa.ec.fisheries.uvms.commons.rest.dto.PaginationDto in project UVMS-ActivityModule-APP by UnionVMS.

the class ActivityServiceBeanTest method getFishingActivityListByQuery.

@Test
@SneakyThrows
public void getFishingActivityListByQuery() throws ServiceException {
    FishingActivityQuery query = new FishingActivityQuery();
    Map<SearchFilter, String> searchCriteriaMap = new HashMap<>();
    searchCriteriaMap.put(SearchFilter.OWNER, "OWNER1");
    List<AreaIdentifierType> areaIdentifierTypes = new ArrayList<>();
    Map<SearchFilter, List<String>> searchCriteriaMapMultipleValue = new HashMap<>();
    List<String> purposeCodeList = new ArrayList<>();
    purposeCodeList.add("9");
    searchCriteriaMapMultipleValue.put(SearchFilter.PURPOSE, purposeCodeList);
    PaginationDto pagination = new PaginationDto();
    pagination.setPageSize(4);
    pagination.setOffset(1);
    query.setPagination(pagination);
    query.setSearchCriteriaMap(searchCriteriaMap);
    query.setSearchCriteriaMapMultipleValues(searchCriteriaMapMultipleValue);
    when(spatialModule.getFilteredAreaGeom(areaIdentifierTypes)).thenReturn("('MULTIPOINT (10 40, 40 30, 20 20, 30 10)')");
    when(fishingActivityDao.getFishingActivityListByQuery(query)).thenReturn(MapperUtil.getFishingActivityEntityList());
    // Trigger
    FilterFishingActivityReportResultDTO filterFishingActivityReportResultDTO = activityService.getFishingActivityListByQuery(query, null);
    Mockito.verify(fishingActivityDao, Mockito.times(1)).getFishingActivityListByQuery(Mockito.any(FishingActivityQuery.class));
    // Verify
    assertNotNull(filterFishingActivityReportResultDTO);
    assertNotNull(filterFishingActivityReportResultDTO.getResultList());
}
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) FilterFishingActivityReportResultDTO(eu.europa.ec.fisheries.ers.service.dto.FilterFishingActivityReportResultDTO) FishingActivityQuery(eu.europa.ec.fisheries.ers.service.search.FishingActivityQuery) ArrayList(java.util.ArrayList) List(java.util.List) AreaIdentifierType(eu.europa.ec.fisheries.uvms.spatial.model.schemas.AreaIdentifierType) Test(org.junit.Test) SneakyThrows(lombok.SneakyThrows)

Example 9 with PaginationDto

use of eu.europa.ec.fisheries.uvms.commons.rest.dto.PaginationDto in project UVMS-ActivityModule-APP by UnionVMS.

the class ActivityServiceBeanTest method getFishingActivityListByQuery_emptyResultSet.

@Test
@SneakyThrows
public void getFishingActivityListByQuery_emptyResultSet() throws ServiceException {
    FishingActivityQuery query = new FishingActivityQuery();
    Map<SearchFilter, String> searchCriteriaMap = new HashMap<>();
    List<AreaIdentifierType> areaIdentifierTypes = new ArrayList<>();
    searchCriteriaMap.put(SearchFilter.OWNER, "OWNER1");
    Map<SearchFilter, List<String>> searchCriteriaMapMultipleValue = new HashMap<>();
    List<String> purposeCodeList = new ArrayList<>();
    purposeCodeList.add("9");
    searchCriteriaMapMultipleValue.put(SearchFilter.PURPOSE, purposeCodeList);
    PaginationDto pagination = new PaginationDto();
    pagination.setPageSize(4);
    pagination.setOffset(1);
    query.setPagination(pagination);
    query.setSearchCriteriaMap(searchCriteriaMap);
    query.setSearchCriteriaMapMultipleValues(searchCriteriaMapMultipleValue);
    when(spatialModule.getFilteredAreaGeom(areaIdentifierTypes)).thenReturn("('MULTIPOINT (10 40, 40 30, 20 20, 30 10)')");
    when(fishingActivityDao.getFishingActivityListByQuery(query)).thenReturn(new ArrayList<FishingActivityEntity>());
    // Trigger
    FilterFishingActivityReportResultDTO filterFishingActivityReportResultDTO = activityService.getFishingActivityListByQuery(query, new ArrayList<Dataset>());
    Mockito.verify(fishingActivityDao, Mockito.times(1)).getFishingActivityListByQuery(Mockito.any(FishingActivityQuery.class));
    // Verify
    assertNotNull(filterFishingActivityReportResultDTO);
}
Also used : HashMap(java.util.HashMap) Dataset(eu.europa.ec.fisheries.wsdl.user.types.Dataset) ArrayList(java.util.ArrayList) PaginationDto(eu.europa.ec.fisheries.uvms.commons.rest.dto.PaginationDto) SearchFilter(eu.europa.ec.fisheries.uvms.activity.model.schemas.SearchFilter) FilterFishingActivityReportResultDTO(eu.europa.ec.fisheries.ers.service.dto.FilterFishingActivityReportResultDTO) FishingActivityEntity(eu.europa.ec.fisheries.ers.fa.entities.FishingActivityEntity) FishingActivityQuery(eu.europa.ec.fisheries.ers.service.search.FishingActivityQuery) ArrayList(java.util.ArrayList) List(java.util.List) AreaIdentifierType(eu.europa.ec.fisheries.uvms.spatial.model.schemas.AreaIdentifierType) Test(org.junit.Test) SneakyThrows(lombok.SneakyThrows)

Example 10 with PaginationDto

use of eu.europa.ec.fisheries.uvms.commons.rest.dto.PaginationDto 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)

Aggregations

FishingActivityQuery (eu.europa.ec.fisheries.ers.service.search.FishingActivityQuery)10 PaginationDto (eu.europa.ec.fisheries.uvms.commons.rest.dto.PaginationDto)10 SearchFilter (eu.europa.ec.fisheries.uvms.activity.model.schemas.SearchFilter)7 HashMap (java.util.HashMap)7 SneakyThrows (lombok.SneakyThrows)7 Test (org.junit.Test)7 ArrayList (java.util.ArrayList)5 List (java.util.List)5 SortKey (eu.europa.ec.fisheries.ers.service.search.SortKey)4 FishingActivitySearchBuilder (eu.europa.ec.fisheries.ers.service.search.builder.FishingActivitySearchBuilder)3 Query (javax.persistence.Query)3 FilterFishingActivityReportResultDTO (eu.europa.ec.fisheries.ers.service.dto.FilterFishingActivityReportResultDTO)2 SearchQueryBuilder (eu.europa.ec.fisheries.ers.service.search.builder.SearchQueryBuilder)2 AreaIdentifierType (eu.europa.ec.fisheries.uvms.spatial.model.schemas.AreaIdentifierType)2 TypedQuery (javax.persistence.TypedQuery)2 FishingActivityEntity (eu.europa.ec.fisheries.ers.fa.entities.FishingActivityEntity)1 FishingTripId (eu.europa.ec.fisheries.ers.service.search.FishingTripId)1 ServiceException (eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException)1 Dataset (eu.europa.ec.fisheries.wsdl.user.types.Dataset)1 HashSet (java.util.HashSet)1