Search in sources :

Example 1 with FishingTripResponse

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);
}
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 2 with FishingTripResponse

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);
    }
}
Also used : FishingTripRequest(eu.europa.ec.fisheries.uvms.activity.model.schemas.FishingTripRequest) FishingTripResponse(eu.europa.ec.fisheries.uvms.activity.model.schemas.FishingTripResponse) ActivityModelMarshallException(eu.europa.ec.fisheries.uvms.activity.model.exception.ActivityModelMarshallException) ServiceException(eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException) MessageException(eu.europa.ec.fisheries.uvms.commons.message.api.MessageException) JMSException(javax.jms.JMSException)

Example 3 with FishingTripResponse

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);
}
Also used : FishingTripResponse(eu.europa.ec.fisheries.uvms.activity.model.schemas.FishingTripResponse) Dataset(eu.europa.ec.fisheries.wsdl.user.types.Dataset) Path(javax.ws.rs.Path) Interceptors(javax.interceptor.Interceptors) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) IUserRoleInterceptor(eu.europa.ec.fisheries.uvms.activity.rest.IUserRoleInterceptor)

Example 4 with FishingTripResponse

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;
}
Also used : FishingActivitySummary(eu.europa.ec.fisheries.uvms.activity.model.schemas.FishingActivitySummary) FishingTripIdWithGeometryMapper(eu.europa.ec.fisheries.ers.service.mapper.FishingTripIdWithGeometryMapper) ArrayList(java.util.ArrayList) SearchFilter(eu.europa.ec.fisheries.uvms.activity.model.schemas.SearchFilter) SortKey(eu.europa.ec.fisheries.ers.service.search.SortKey) FishingTripIdWithGeometry(eu.europa.ec.fisheries.uvms.activity.model.schemas.FishingTripIdWithGeometry) FishingTripId(eu.europa.ec.fisheries.ers.service.search.FishingTripId) FishingActivityEntity(eu.europa.ec.fisheries.ers.fa.entities.FishingActivityEntity) BigInteger(java.math.BigInteger) FishingActivityQuery(eu.europa.ec.fisheries.ers.service.search.FishingActivityQuery) FishingTripResponse(eu.europa.ec.fisheries.uvms.activity.model.schemas.FishingTripResponse) EnumMap(java.util.EnumMap)

Example 5 with FishingTripResponse

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;
}
Also used : BigInteger(java.math.BigInteger) FishingTripResponse(eu.europa.ec.fisheries.uvms.activity.model.schemas.FishingTripResponse) FishingTripId(eu.europa.ec.fisheries.ers.service.search.FishingTripId)

Aggregations

FishingTripResponse (eu.europa.ec.fisheries.uvms.activity.model.schemas.FishingTripResponse)6 FishingActivityQuery (eu.europa.ec.fisheries.ers.service.search.FishingActivityQuery)3 SearchFilter (eu.europa.ec.fisheries.uvms.activity.model.schemas.SearchFilter)3 FishingTripId (eu.europa.ec.fisheries.ers.service.search.FishingTripId)2 SortKey (eu.europa.ec.fisheries.ers.service.search.SortKey)2 BigInteger (java.math.BigInteger)2 ArrayList (java.util.ArrayList)2 EnumMap (java.util.EnumMap)2 SneakyThrows (lombok.SneakyThrows)2 Test (org.junit.Test)2 FishingActivityEntity (eu.europa.ec.fisheries.ers.fa.entities.FishingActivityEntity)1 FishingTripIdWithGeometryMapper (eu.europa.ec.fisheries.ers.service.mapper.FishingTripIdWithGeometryMapper)1 ActivityModelMarshallException (eu.europa.ec.fisheries.uvms.activity.model.exception.ActivityModelMarshallException)1 FishingActivitySummary (eu.europa.ec.fisheries.uvms.activity.model.schemas.FishingActivitySummary)1 FishingTripIdWithGeometry (eu.europa.ec.fisheries.uvms.activity.model.schemas.FishingTripIdWithGeometry)1 FishingTripRequest (eu.europa.ec.fisheries.uvms.activity.model.schemas.FishingTripRequest)1 IUserRoleInterceptor (eu.europa.ec.fisheries.uvms.activity.rest.IUserRoleInterceptor)1 MessageException (eu.europa.ec.fisheries.uvms.commons.message.api.MessageException)1 ServiceException (eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException)1 Dataset (eu.europa.ec.fisheries.wsdl.user.types.Dataset)1