use of eu.europa.ec.fisheries.ers.service.search.SortKey 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.SortKey in project UVMS-ActivityModule-APP by UnionVMS.
the class FishingActivityDaoTest method testGetCountForFishingActivityListByQuery.
@Test
@SneakyThrows
public void testGetCountForFishingActivityListByQuery() throws Exception {
dbSetupTracker.skipNextLaunch();
FishingActivityQuery query = new FishingActivityQuery();
Map<SearchFilter, String> searchCriteriaMap = new HashMap<>();
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);
List<String> purposeCodeValues = new ArrayList<>();
purposeCodeValues.add("5");
purposeCodeValues.add("9");
searchCriteriaMapMultiVal.put(SearchFilter.PURPOSE, purposeCodeValues);
query.setSearchCriteriaMapMultipleValues(searchCriteriaMapMultiVal);
searchCriteriaMap.put(SearchFilter.OWNER, "OWNER1");
searchCriteriaMap.put(SearchFilter.PERIOD_START, "2012-05-27T07:47:31");
searchCriteriaMap.put(SearchFilter.PERIOD_END, "2015-05-27T07:47:31");
searchCriteriaMap.put(SearchFilter.VESSEL_NAME, "vessel1");
searchCriteriaMap.put(SearchFilter.VESSEL_IDENTIFIRE, "CFR123");
searchCriteriaMap.put(SearchFilter.REPORT_TYPE, "DECLARATION");
searchCriteriaMap.put(SearchFilter.GEAR, "GEAR_TYPE");
searchCriteriaMap.put(SearchFilter.SPECIES, "PLE");
searchCriteriaMap.put(SearchFilter.MASTER, "MARK");
searchCriteriaMap.put(SearchFilter.AREAS, "27.4.b");
searchCriteriaMap.put(SearchFilter.QUANTITY_MIN, "0");
searchCriteriaMap.put(SearchFilter.QUANTITY_MAX, "25");
searchCriteriaMap.put(SearchFilter.SOURCE, "FLUX");
SortKey sortingDto = new SortKey();
sortingDto.setSortBy(SearchFilter.PURPOSE);
sortingDto.setReversed(false);
query.setSorting(sortingDto);
query.setSearchCriteriaMap(searchCriteriaMap);
PaginationDto pagination = new PaginationDto();
pagination.setPageSize(2);
pagination.setOffset(1);
query.setPagination(pagination);
SortKey sortingDto2 = new SortKey();
sortingDto2.setSortBy(SearchFilter.OCCURRENCE);
sortingDto2.setReversed(false);
query.setSorting(sortingDto2);
int size = dao.getCountForFishingActivityListByQuery(query);
System.out.println("done:" + size);
// assertNotEquals(0, size);
}
use of eu.europa.ec.fisheries.ers.service.search.SortKey in project UVMS-ActivityModule-APP by UnionVMS.
the class SearchQueryBuilder method getJoinPartForSortingOptions.
/**
* This method makes sure that Table join is present for the Filter for which sorting has been requested.
*
* @param sql
* @param query
* @return
*/
private StringBuilder getJoinPartForSortingOptions(StringBuilder sql, FishingActivityQuery query) {
SortKey sort = query.getSorting();
// IF sorting has been requested and
if (sort == null) {
return sql;
}
SearchFilter field = sort.getSortBy();
if (field == null) {
return sql;
}
// Make sure that the field which we want to sort, table Join is present for it.
switch(getFiledCase(sql, field)) {
case 1:
appendLeftJoinFetch(sql, filterMap.DELIMITED_PERIOD_TABLE_ALIAS);
break;
case 2:
appendLeftJoinFetch(sql, FilterMap.FLUX_REPORT_DOC_TABLE_ALIAS);
break;
case 3:
checkAndAppendIfNeededFluxReportDocTable(sql);
break;
default:
break;
}
return sql;
}
Aggregations