Search in sources :

Example 16 with SearchFilter

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

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

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

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

the class FishingTripServiceBeanTest method testFilterFishingTrips.

@Test
@SneakyThrows
public void testFilterFishingTrips() throws ServiceException, JsonProcessingException {
    Map<SearchFilter, String> searchMap = new HashMap<>();
    searchMap.put(SearchFilter.REPORT_TYPE, "NOTIFICATION");
    searchMap.put(SearchFilter.PERIOD_START, "2012-05-27T07:47:31");
    searchMap.put(SearchFilter.PERIOD_END, "2017-05-27T07:47:31");
    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);
    FishingActivityQuery query = new FishingActivityQuery();
    query.setSearchCriteriaMap(searchMap);
    query.setSearchCriteriaMapMultipleValues(searchCriteriaMapMultiVal);
    when(fishingTripDao.getFishingTripIdsForMatchingFilterCriteria(any(FishingActivityQuery.class))).thenReturn(MapperUtil.getFishingTripIdSet());
    when(fishingTripDao.getCountOfFishingTripsForMatchingFilterCriteria(any(FishingActivityQuery.class))).thenReturn(new Integer(2));
    when(fishingActivityDao.getFishingActivityListByQuery(any(FishingActivityQuery.class))).thenReturn(MapperUtil.getFishingActivityEntityList());
    // Trigger
    FishingTripResponse response = fishingTripService.filterFishingTrips(query);
    assertNotNull(response);
}
Also used : FishingActivityQuery(eu.europa.ec.fisheries.ers.service.search.FishingActivityQuery) FishingTripResponse(eu.europa.ec.fisheries.uvms.activity.model.schemas.FishingTripResponse) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SearchFilter(eu.europa.ec.fisheries.uvms.activity.model.schemas.SearchFilter) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test) SneakyThrows(lombok.SneakyThrows)

Example 20 with SearchFilter

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

the class FaCatchDaoTest method testGetFACatchSummaryReportString.

@Test
public void testGetFACatchSummaryReportString() throws Exception {
    dbSetupTracker.skipNextLaunch();
    FishingActivityQuery query = new FishingActivityQuery();
    Map<SearchFilter, String> searchCriteriaMap = new HashMap<>();
    List<GroupCriteria> groupByFields = new ArrayList<>();
    groupByFields.add(GroupCriteria.DATE_MONTH);
    groupByFields.add(GroupCriteria.SPECIES);
    query.setGroupByFields(groupByFields);
    searchCriteriaMap.put(SearchFilter.SOURCE, "FLUX");
    query.setSearchCriteriaMap(searchCriteriaMap);
    // FACatchSummaryHelper faCatchSummaryHelper = FACatchSummaryHelper.createFACatchSummaryHelper();
    // System.out.println( faCatchSummaryHelper.printJsonstructure(query));
    Map<FaCatchSummaryCustomProxy, List<FaCatchSummaryCustomProxy>> faCatchSummaryCustomEntityListMap = dao.getGroupedFaCatchData(query, false);
    assertNotNull(faCatchSummaryCustomEntityListMap);
}
Also used : FishingActivityQuery(eu.europa.ec.fisheries.ers.service.search.FishingActivityQuery) HashMap(java.util.HashMap) FaCatchSummaryCustomProxy(eu.europa.ec.fisheries.ers.fa.dao.proxy.FaCatchSummaryCustomProxy) ArrayList(java.util.ArrayList) SearchFilter(eu.europa.ec.fisheries.uvms.activity.model.schemas.SearchFilter) ArrayList(java.util.ArrayList) List(java.util.List) GroupCriteria(eu.europa.ec.fisheries.uvms.activity.model.schemas.GroupCriteria) Test(org.junit.Test)

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