use of eu.europa.ec.fisheries.ers.service.search.FishingTripId in project UVMS-ActivityModule-APP by UnionVMS.
the class FishingTripDaoTest method testGetFishingTripIdsForMatchingFilterCriteria_allCommonFilters.
@Test
@SneakyThrows
public void testGetFishingTripIdsForMatchingFilterCriteria_allCommonFilters() throws Exception {
dbSetupTracker.skipNextLaunch();
Map<SearchFilter, String> searchCriteriaMap = new HashMap<>();
searchCriteriaMap.put(SearchFilter.ACTIVITY_TYPE, "DEPARTURE");
searchCriteriaMap.put(SearchFilter.SOURCE, "FLUX");
searchCriteriaMap.put(SearchFilter.OWNER, "OWNER1");
searchCriteriaMap.put(SearchFilter.FROM, "OWNER1");
searchCriteriaMap.put(SearchFilter.PERIOD_START, "2012-05-27T07:47:31");
searchCriteriaMap.put(SearchFilter.PERIOD_END, "2018-05-27T07:47:31");
searchCriteriaMap.put(SearchFilter.REPORT_TYPE, "DECLARATION");
searchCriteriaMap.put(SearchFilter.AREAS, "J");
searchCriteriaMap.put(SearchFilter.GEAR, "GEAR_TYPE");
searchCriteriaMap.put(SearchFilter.SPECIES, "BFT");
searchCriteriaMap.put(SearchFilter.QUANTITY_MIN, "0");
searchCriteriaMap.put(SearchFilter.QUANTITY_MAX, "50");
searchCriteriaMap.put(SearchFilter.MASTER, "MARK");
Map<SearchFilter, List<String>> searchCriteriaMapMultiVal = new HashMap<>();
List<String> purposeCodeValues = new ArrayList<>();
purposeCodeValues.add("9");
purposeCodeValues.add("1");
purposeCodeValues.add("5");
purposeCodeValues.add("3");
FishingActivityQuery query = new FishingActivityQuery();
query.setSearchCriteriaMap(searchCriteriaMap);
query.setSearchCriteriaMapMultipleValues(searchCriteriaMapMultiVal);
searchCriteriaMapMultiVal.put(SearchFilter.PURPOSE, purposeCodeValues);
Set<FishingTripId> fishingTripIdSet = dao.getFishingTripIdsForMatchingFilterCriteria(query);
FishingTripId fishingTripId = new FishingTripId("NOR-TRP-20160517234053706", "EU_TRIP_ID");
assertEquals(true, fishingTripIdSet.contains(fishingTripId));
assertNotNull(fishingTripIdSet);
}
use of eu.europa.ec.fisheries.ers.service.search.FishingTripId 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;
}
use of eu.europa.ec.fisheries.ers.service.search.FishingTripId in project UVMS-ActivityModule-APP by UnionVMS.
the class FishingTripServiceBean method filterFishingTrips.
/**
* This method filters fishing Trips for Activity tab
*/
@Override
public FishingTripResponse filterFishingTrips(FishingActivityQuery query) throws ServiceException {
log.info("getFishingTripResponse For Filter");
if ((MapUtils.isEmpty(query.getSearchCriteriaMap()) && MapUtils.isEmpty(query.getSearchCriteriaMapMultipleValues())) || activityServiceBean.checkAndEnrichIfVesselFiltersArePresent(query)) {
return new FishingTripResponse();
}
Set<FishingTripId> fishingTripIds = fishingTripDao.getFishingTripIdsForMatchingFilterCriteria(query);
log.debug("Fishing trips received from db:" + fishingTripIds.size());
Integer totalCountOfRecords = fishingTripDao.getCountOfFishingTripsForMatchingFilterCriteria(query);
log.debug("Total count of records: {} ", totalCountOfRecords);
FishingTripResponse fishingTripResponse = buildFishingTripSearchRespose(fishingTripIds, false);
fishingTripResponse.setTotalCountOfRecords(BigInteger.valueOf(totalCountOfRecords));
return fishingTripResponse;
}
use of eu.europa.ec.fisheries.ers.service.search.FishingTripId 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;
}
use of eu.europa.ec.fisheries.ers.service.search.FishingTripId in project UVMS-ActivityModule-APP by UnionVMS.
the class MapperUtil method getFishingTripIdSet.
public static Set<FishingTripId> getFishingTripIdSet() {
Set<FishingTripId> fishingTripIdSet = new HashSet<>();
fishingTripIdSet.add(new FishingTripId("NOR-TRP-20160517234053706", "EU_TRIP_ID"));
fishingTripIdSet.add(new FishingTripId("NOR-ABC-20160517234053706", "EU_TRIP_ID"));
return fishingTripIdSet;
}
Aggregations