Search in sources :

Example 1 with SearchFilter

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

the class FaCatchReportServiceBeanTest method testGetCatchesTableForCatchDetailsScreen.

@Test
@SneakyThrows
public void testGetCatchesTableForCatchDetailsScreen() throws ServiceException {
    FishingActivityQuery query = new FishingActivityQuery();
    List<GroupCriteria> groupByFields = new ArrayList<>();
    groupByFields.add(GroupCriteria.DATE_DAY);
    groupByFields.add(GroupCriteria.FAO_AREA);
    groupByFields.add(GroupCriteria.TERRITORY);
    groupByFields.add(GroupCriteria.EFFORT_ZONE);
    groupByFields.add(GroupCriteria.GFCM_GSA);
    groupByFields.add(GroupCriteria.GFCM_STAT_RECTANGLE);
    groupByFields.add(GroupCriteria.ICES_STAT_RECTANGLE);
    groupByFields.add(GroupCriteria.RFMO);
    groupByFields.add(GroupCriteria.SPECIES);
    query.setGroupByFields(groupByFields);
    Map<SearchFilter, String> searchCriteriaMap = new EnumMap<SearchFilter, String>(SearchFilter.class);
    searchCriteriaMap.put(SearchFilter.TRIP_ID, "NOR-TRP-20160517234053706");
    query.setSearchCriteriaMap(searchCriteriaMap);
    when(faCatchDao.getGroupedFaCatchData(query, Boolean.FALSE)).thenReturn(MapperUtil.getGroupedFaCatchSummaryCustomEntityData());
    when(faCatchDao.getGroupedFaCatchData(query, Boolean.TRUE)).thenReturn(MapperUtil.getGroupedFaCatchSummaryCustomEntityData());
    // when(vesselIdentifiersDao.getLatestVesselIdByTrip("NOR-TRP-20160517234053706")).thenReturn(MapperUtil.getVesselIdentifiersList());
    // Trigger
    FACatchDetailsDTO faCatchDetailsDTO = faCatchReportService.getCatchDetailsScreen("NOR-TRP-20160517234053706");
    Mockito.verify(faCatchDao, Mockito.times(2)).getGroupedFaCatchData(Mockito.any(FishingActivityQuery.class), Mockito.any(Boolean.class));
    // Verify
    assertNotNull(faCatchDetailsDTO);
}
Also used : FishingActivityQuery(eu.europa.ec.fisheries.ers.service.search.FishingActivityQuery) ArrayList(java.util.ArrayList) SearchFilter(eu.europa.ec.fisheries.uvms.activity.model.schemas.SearchFilter) FACatchDetailsDTO(eu.europa.ec.fisheries.ers.service.dto.fareport.summary.FACatchDetailsDTO) EnumMap(java.util.EnumMap) GroupCriteria(eu.europa.ec.fisheries.uvms.activity.model.schemas.GroupCriteria) Test(org.junit.Test) SneakyThrows(lombok.SneakyThrows)

Example 2 with SearchFilter

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

the class FaCatchReportServiceBeanTest method testGetCatchSummaryReport.

@Test
@SneakyThrows
public void testGetCatchSummaryReport() throws ServiceException {
    FishingActivityQuery query = new FishingActivityQuery();
    List<GroupCriteria> groupByFields = new ArrayList<>();
    groupByFields.add(GroupCriteria.DATE_DAY);
    groupByFields.add(GroupCriteria.FAO_AREA);
    groupByFields.add(GroupCriteria.TERRITORY);
    groupByFields.add(GroupCriteria.EFFORT_ZONE);
    groupByFields.add(GroupCriteria.GFCM_GSA);
    groupByFields.add(GroupCriteria.GFCM_STAT_RECTANGLE);
    groupByFields.add(GroupCriteria.ICES_STAT_RECTANGLE);
    groupByFields.add(GroupCriteria.RFMO);
    groupByFields.add(GroupCriteria.SPECIES);
    query.setGroupByFields(groupByFields);
    Map<SearchFilter, String> searchCriteriaMap = new EnumMap<SearchFilter, String>(SearchFilter.class);
    searchCriteriaMap.put(SearchFilter.TRIP_ID, "NOR-TRP-20160517234053706");
    query.setSearchCriteriaMap(searchCriteriaMap);
    Map<FaCatchSummaryCustomProxy, List<FaCatchSummaryCustomProxy>> groupedData = MapperUtil.getGroupedFaCatchSummaryCustomEntityData();
    when((faCatchDao).getGroupedFaCatchData(any(FishingActivityQuery.class), any(Boolean.class))).thenReturn(groupedData);
    // when(faCatchDao.getGroupedFaCatchData(query,true)).thenReturn(MapperUtil.getGroupedFaCatchSummaryCustomEntityData());
    // when(vesselIdentifiersDao.getLatestVesselIdByTrip("NOR-TRP-20160517234053706")).thenReturn(MapperUtil.getVesselIdentifiersList());
    // Trigger
    FACatchSummaryDTO fACatchSummaryDTO = faCatchReportService.getCatchSummaryReport(query, false);
    Mockito.verify(faCatchDao, Mockito.times(1)).getGroupedFaCatchData(Mockito.any(FishingActivityQuery.class), Mockito.any(Boolean.class));
    // Verify
    assertNotNull(fACatchSummaryDTO);
}
Also used : ArrayList(java.util.ArrayList) SearchFilter(eu.europa.ec.fisheries.uvms.activity.model.schemas.SearchFilter) GroupCriteria(eu.europa.ec.fisheries.uvms.activity.model.schemas.GroupCriteria) FishingActivityQuery(eu.europa.ec.fisheries.ers.service.search.FishingActivityQuery) FaCatchSummaryCustomProxy(eu.europa.ec.fisheries.ers.fa.dao.proxy.FaCatchSummaryCustomProxy) FACatchSummaryDTO(eu.europa.ec.fisheries.ers.service.dto.fareport.summary.FACatchSummaryDTO) ArrayList(java.util.ArrayList) List(java.util.List) EnumMap(java.util.EnumMap) Test(org.junit.Test) SneakyThrows(lombok.SneakyThrows)

Example 3 with SearchFilter

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

the class FishingTripServiceBeanTest method testBuildFishingTripSearchRespose.

@Test
@SneakyThrows
public void testBuildFishingTripSearchRespose() throws ServiceException, JsonProcessingException {
    FishingActivityQuery query = new FishingActivityQuery();
    Map<SearchFilter, String> searchCriteriaMap = new EnumMap<>(SearchFilter.class);
    searchCriteriaMap.put(SearchFilter.TRIP_ID, "NOR-TRP-20160517234053706");
    searchCriteriaMap.put(SearchFilter.FISHING_TRIP_SCHEME_ID, "EU_TRIP_ID");
    query.setSearchCriteriaMap(searchCriteriaMap);
    SortKey sortKey = new SortKey();
    sortKey.setSortBy(SearchFilter.PERIOD_START);
    sortKey.setReversed(false);
    query.setSorting(sortKey);
    when(fishingActivityDao.getFishingActivityListByQuery(any(FishingActivityQuery.class))).thenReturn(MapperUtil.getFishingActivityEntityList());
    // Trigger
    FishingTripResponse response = fishingTripService.buildFishingTripSearchRespose(MapperUtil.getFishingTripIdSet(), false);
    assertNotNull(response);
}
Also used : FishingActivityQuery(eu.europa.ec.fisheries.ers.service.search.FishingActivityQuery) FishingTripResponse(eu.europa.ec.fisheries.uvms.activity.model.schemas.FishingTripResponse) SearchFilter(eu.europa.ec.fisheries.uvms.activity.model.schemas.SearchFilter) SortKey(eu.europa.ec.fisheries.ers.service.search.SortKey) EnumMap(java.util.EnumMap) Test(org.junit.Test) SneakyThrows(lombok.SneakyThrows)

Example 4 with SearchFilter

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

the class ActivityServiceBean method separateSingleVsMultipleFilters.

// Improve this part later on
private void separateSingleVsMultipleFilters(FishingActivityQuery query) throws ServiceException {
    Map<SearchFilter, List<String>> searchMapWithMultipleValues = query.getSearchCriteriaMapMultipleValues();
    if (searchMapWithMultipleValues == null || searchMapWithMultipleValues.size() == 0 || searchMapWithMultipleValues.get(SearchFilter.PURPOSE) == null)
        throw new ServiceException("No purpose code provided for the Fishing activity filters! At least one needed!");
    Map<SearchFilter, String> searchMap = query.getSearchCriteriaMap();
    if (searchMap == null)
        return;
    validateInputFilters(searchMapWithMultipleValues);
    Set<SearchFilter> filtersWhichSupportMultipleValues = FilterMap.getFiltersWhichSupportMultipleValues();
    Iterator<Map.Entry<SearchFilter, String>> searchMapIterator = searchMap.entrySet().iterator();
    while (searchMapIterator.hasNext()) {
        Map.Entry<SearchFilter, String> e = searchMapIterator.next();
        SearchFilter key = e.getKey();
        String value = e.getValue();
        if (value == null)
            throw new ServiceException("Null value present for the key:" + key + " Please provide correct input.");
        if (filtersWhichSupportMultipleValues.contains(key)) {
            List<String> values = new ArrayList<>();
            values.add(value);
            searchMapWithMultipleValues.put(key, values);
            searchMapIterator.remove();
        }
    }
    query.setSearchCriteriaMapMultipleValues(searchMapWithMultipleValues);
    query.setSearchCriteriaMap(searchMap);
}
Also used : ArrayList(java.util.ArrayList) SearchFilter(eu.europa.ec.fisheries.uvms.activity.model.schemas.SearchFilter) ServiceException(eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) EnumMap(java.util.EnumMap) FaIdsListWithTripIdMap(eu.europa.ec.fisheries.uvms.activity.model.schemas.FaIdsListWithTripIdMap) FilterMap(eu.europa.ec.fisheries.ers.service.search.FilterMap)

Example 5 with SearchFilter

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

the class ActivityServiceBean method validateInputFilters.

private void validateInputFilters(Map<SearchFilter, List<String>> searchMapWithMultipleValues) throws ServiceException {
    if (MapUtils.isNotEmpty(searchMapWithMultipleValues)) {
        Iterator<Map.Entry<SearchFilter, List<String>>> searchMapIterator = searchMapWithMultipleValues.entrySet().iterator();
        while (searchMapIterator.hasNext()) {
            Map.Entry<SearchFilter, List<String>> e = searchMapIterator.next();
            SearchFilter key = e.getKey();
            List<String> values = e.getValue();
            if (values.contains(null) || values.contains("")) {
                throw new ServiceException("Null value present for the key:" + key + " Please provide correct input.");
            }
        }
    }
}
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) ArrayList(java.util.ArrayList) Map(java.util.Map) EnumMap(java.util.EnumMap) FaIdsListWithTripIdMap(eu.europa.ec.fisheries.uvms.activity.model.schemas.FaIdsListWithTripIdMap) FilterMap(eu.europa.ec.fisheries.ers.service.search.FilterMap)

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