use of eu.europa.ec.fisheries.uvms.activity.model.schemas.FishingTripResponse 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);
}
use of eu.europa.ec.fisheries.uvms.activity.model.schemas.FishingTripResponse in project UVMS-ActivityModule-APP by UnionVMS.
the class ActivityEventServiceBean method getFishingTripList.
@Override
public void getFishingTripList(@Observes @GetFishingTripListEvent EventMessage message) {
log.info(GOT_JMS_INSIDE_ACTIVITY_TO_GET + "FishingTripIds:");
try {
log.debug("JMS Incoming text message: {}", message.getJmsMessage().getText());
FishingTripRequest baseRequest = JAXBMarshaller.unmarshallTextMessage(message.getJmsMessage(), FishingTripRequest.class);
log.debug("FishingTriId Request Unmarshalled");
FishingTripResponse baseResponse = fishingTripService.filterFishingTripsForReporting(FishingActivityRequestMapper.buildFishingActivityQueryFromRequest(baseRequest));
log.debug("FishingTripResponse ::: " + FACatchSummaryHelper.printJsonstructure(baseResponse));
String response = JAXBMarshaller.marshallJaxBObjectToString(baseResponse);
log.debug("FishingTriId response marshalled");
producer.sendResponseMessageToSender(message.getJmsMessage(), response);
log.debug("Response sent back.");
} catch (ActivityModelMarshallException | JMSException | ServiceException | MessageException e) {
sendError(message, e);
}
}
use of eu.europa.ec.fisheries.uvms.activity.model.schemas.FishingTripResponse in project UVMS-ActivityModule-APP by UnionVMS.
the class FishingActivityResource method listFishingTripsByQuery.
@POST
@Path("/listTrips")
@Consumes(value = { MediaType.APPLICATION_JSON })
@Produces(MediaType.APPLICATION_JSON)
@Interceptors(ActivityExceptionInterceptor.class)
@IUserRoleInterceptor(requiredUserRole = { ActivityFeaturesEnum.LIST_ACTIVITY_REPORTS })
public Response listFishingTripsByQuery(@Context HttpServletRequest request, @HeaderParam("scopeName") String scopeName, @HeaderParam("roleName") String roleName, FishingActivityQuery fishingActivityQuery) throws ServiceException {
log.info("Query Received to search Fishing Activity Reports. " + fishingActivityQuery);
if (fishingActivityQuery == null) {
return createErrorResponse("Query to find list is null.");
}
String username = request.getRemoteUser();
List<Dataset> datasets = usmService.getDatasetsPerCategory(USMSpatial.USM_DATASET_CATEGORY, username, USMSpatial.APPLICATION_NAME, roleName, scopeName);
log.info("Successful retrieved");
FishingTripResponse fishingTripIdsForFilter = fishingTripService.filterFishingTrips(fishingActivityQuery);
return createSuccessResponse(fishingTripIdsForFilter);
}
use of eu.europa.ec.fisheries.uvms.activity.model.schemas.FishingTripResponse 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.uvms.activity.model.schemas.FishingTripResponse 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;
}
Aggregations