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;
}
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;
}
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);
}
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;
}
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());
}
Aggregations