Search in sources :

Example 16 with FishingActivityQuery

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

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

the class FishingTripDao method getCountOfFishingTripsForMatchingFilterCriteria.

/**
 * Get total number of records for matching criteria without considering pagination
 *
 * @param query
 * @return
 * @throws ServiceException
 */
public Integer getCountOfFishingTripsForMatchingFilterCriteria(FishingActivityQuery query) throws ServiceException {
    Query listQuery = getQueryForFilterFishingTripIds(query);
    List resultList = listQuery.getResultList();
    Integer resultCount = new Integer(0);
    if (CollectionUtils.isNotEmpty(resultList)) {
        resultCount = resultList.size();
    }
    return resultCount;
}
Also used : TypedQuery(javax.persistence.TypedQuery) Query(javax.persistence.Query) FishingActivityQuery(eu.europa.ec.fisheries.ers.service.search.FishingActivityQuery) List(java.util.List)

Example 18 with FishingActivityQuery

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

the class FishingTripDao method getQueryForFilterFishingTrips.

private Query getQueryForFilterFishingTrips(FishingActivityQuery query) throws ServiceException {
    FishingTripSearchBuilder search = new FishingTripSearchBuilder();
    StringBuilder sqlToGetActivityList = search.createSQL(query);
    log.debug("SQL:" + sqlToGetActivityList);
    Query typedQuery = em.createQuery(sqlToGetActivityList.toString());
    return search.fillInValuesForTypedQuery(query, typedQuery);
}
Also used : FishingTripSearchBuilder(eu.europa.ec.fisheries.ers.service.search.builder.FishingTripSearchBuilder) TypedQuery(javax.persistence.TypedQuery) Query(javax.persistence.Query) FishingActivityQuery(eu.europa.ec.fisheries.ers.service.search.FishingActivityQuery)

Example 19 with FishingActivityQuery

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

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

Aggregations

FishingActivityQuery (eu.europa.ec.fisheries.ers.service.search.FishingActivityQuery)28 SearchFilter (eu.europa.ec.fisheries.uvms.activity.model.schemas.SearchFilter)19 Test (org.junit.Test)17 SneakyThrows (lombok.SneakyThrows)16 ArrayList (java.util.ArrayList)15 HashMap (java.util.HashMap)14 List (java.util.List)14 PaginationDto (eu.europa.ec.fisheries.uvms.commons.rest.dto.PaginationDto)10 Query (javax.persistence.Query)7 SortKey (eu.europa.ec.fisheries.ers.service.search.SortKey)6 FishingTripId (eu.europa.ec.fisheries.ers.service.search.FishingTripId)5 EnumMap (java.util.EnumMap)5 FishingActivitySearchBuilder (eu.europa.ec.fisheries.ers.service.search.builder.FishingActivitySearchBuilder)4 GroupCriteria (eu.europa.ec.fisheries.uvms.activity.model.schemas.GroupCriteria)4 TypedQuery (javax.persistence.TypedQuery)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 SearchQueryBuilder (eu.europa.ec.fisheries.ers.service.search.builder.SearchQueryBuilder)2