Search in sources :

Example 1 with ExchangeListQuery

use of eu.europa.ec.fisheries.schema.exchange.v1.ExchangeListQuery in project UVMS-ExchangeModule-APP by UnionVMS.

the class ExchangeLogModelTest method testDataEnrichment.

@Test
@SneakyThrows
public void testDataEnrichment() {
    Mockito.when(logDao.getExchangeLogListSearchCount(Mockito.anyString(), Mockito.anyList())).thenReturn(100L);
    Mockito.when(logDao.getExchangeLogListPaginated(Mockito.any(Integer.class), Mockito.any(Integer.class), Mockito.anyString(), Mockito.anyList())).thenReturn(logs);
    Mockito.when(logDao.getExchangeLogByRangeOfRefGuids(Mockito.anyList())).thenReturn(refLogs);
    ExchangeListQuery query = new ExchangeListQuery();
    ExchangeListPagination pagin = new ExchangeListPagination();
    ExchangeListCriteria exchCrit = new ExchangeListCriteria();
    query.setPagination(pagin);
    pagin.setListSize(10);
    query.setExchangeSearchCriteria(exchCrit);
    ListResponseDto exchangeLogListByQuery = exchangeLogModel.getExchangeLogListByQuery(query);
    List<ExchangeLogType> exchangeLogList = exchangeLogListByQuery.getExchangeLogList();
    ExchangeLogType exchangeLogType1 = exchangeLogList.get(0);
    ExchangeLogType exchangeLogType2 = exchangeLogList.get(1);
    assertTrue(exchangeLogType1.getRelatedLogData().isEmpty());
    assertTrue(!exchangeLogType2.getRelatedLogData().isEmpty());
    System.out.println("Done");
}
Also used : ExchangeListCriteria(eu.europa.ec.fisheries.schema.exchange.v1.ExchangeListCriteria) ExchangeLogType(eu.europa.ec.fisheries.schema.exchange.v1.ExchangeLogType) ExchangeListQuery(eu.europa.ec.fisheries.schema.exchange.v1.ExchangeListQuery) ExchangeListPagination(eu.europa.ec.fisheries.schema.exchange.v1.ExchangeListPagination) ListResponseDto(eu.europa.ec.fisheries.uvms.exchange.model.dto.ListResponseDto) Test(org.junit.Test) SneakyThrows(lombok.SneakyThrows)

Example 2 with ExchangeListQuery

use of eu.europa.ec.fisheries.schema.exchange.v1.ExchangeListQuery in project UVMS-ExchangeModule-APP by UnionVMS.

the class ExchangeLogModelBean method getExchangeLogListByQuery.

@Override
public ListResponseDto getExchangeLogListByQuery(ExchangeListQuery query) throws ExchangeModelException {
    if (query == null) {
        throw new InputArgumentException("Exchange list query is null");
    }
    if (query.getPagination() == null) {
        throw new InputArgumentException("Pagination in Exchange query is null");
    }
    if (query.getExchangeSearchCriteria() == null) {
        throw new InputArgumentException("No search criterias in Exchange query");
    }
    try {
        ListResponseDto response = new ListResponseDto();
        List<ExchangeLogType> exchLogTypes = new ArrayList<>();
        Integer page = query.getPagination().getPage();
        Integer listSize = query.getPagination().getListSize();
        List<SearchValue> searchKeyValues = SearchFieldMapper.mapSearchField(query.getExchangeSearchCriteria().getCriterias());
        String sql = SearchFieldMapper.createSelectSearchSql(searchKeyValues, true, query.getSorting());
        LOG.info("sql:" + sql);
        String countSql = SearchFieldMapper.createCountSearchSql(searchKeyValues, true);
        LOG.info("countSql:" + countSql);
        Long numberMatches = logDao.getExchangeLogListSearchCount(countSql, searchKeyValues);
        List<ExchangeLog> exchangeLogEntityList = logDao.getExchangeLogListPaginated(page, listSize, sql, searchKeyValues);
        for (ExchangeLog entity : exchangeLogEntityList) {
            exchLogTypes.add(LogMapper.toModel(entity));
        }
        // Enriches the "first level logs" with info related to the related logs.
        enrichDtosWithRelatedLogsInfo(exchLogTypes);
        int numberOfPages = (int) (numberMatches / listSize);
        if (numberMatches % listSize != 0) {
            numberOfPages += 1;
        }
        response.setTotalNumberOfPages(numberOfPages);
        response.setCurrentPage(query.getPagination().getPage());
        response.setExchangeLogList(exchLogTypes);
        return response;
    } catch (ExchangeSearchMapperException | ExchangeDaoException | ParseException ex) {
        LOG.error("[ Error when getting ExchangeLogs by query {}] {} ", query, ex.getMessage());
        throw new ExchangeModelException(ex.getMessage());
    }
}
Also used : InputArgumentException(eu.europa.ec.fisheries.uvms.exchange.model.exception.InputArgumentException) ExchangeLogType(eu.europa.ec.fisheries.schema.exchange.v1.ExchangeLogType) ExchangeSearchMapperException(eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeSearchMapperException) ArrayList(java.util.ArrayList) ExchangeLog(eu.europa.ec.fisheries.uvms.exchange.entity.exchangelog.ExchangeLog) ExchangeDaoException(eu.europa.ec.fisheries.uvms.exchange.exception.ExchangeDaoException) SearchValue(eu.europa.ec.fisheries.uvms.exchange.search.SearchValue) ExchangeModelException(eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeModelException) ParseException(java.text.ParseException) ListResponseDto(eu.europa.ec.fisheries.uvms.exchange.model.dto.ListResponseDto)

Example 3 with ExchangeListQuery

use of eu.europa.ec.fisheries.schema.exchange.v1.ExchangeListQuery in project UVMS-Docker by UnionVMS.

the class ExchangeLogRestIT method getLogListByCriteriaTest.

/**
 * Gets the log list by criteria test.
 *
 * @return the log list by criteria test
 * @throws Exception the exception
 */
@Test
public void getLogListByCriteriaTest() throws Exception {
    ExchangeListQuery exchangeListQuery = new ExchangeListQuery();
    ExchangeListCriteria exchangeListCriteria = new ExchangeListCriteria();
    exchangeListCriteria.setIsDynamic(true);
    ExchangeListCriteriaPair exchangeListCriteriaPair = new ExchangeListCriteriaPair();
    exchangeListCriteriaPair.setKey(SearchField.STATUS);
    exchangeListCriteriaPair.setValue("SUCCESSFUL");
    exchangeListCriteria.getCriterias().add(exchangeListCriteriaPair);
    exchangeListQuery.setExchangeSearchCriteria(exchangeListCriteria);
    ExchangeListPagination exchangeListPagination = new ExchangeListPagination();
    exchangeListPagination.setPage(1);
    exchangeListPagination.setListSize(100);
    exchangeListQuery.setPagination(exchangeListPagination);
    final HttpResponse response = Request.Post(getBaseUrl() + "exchange/rest/exchange/list").bodyByteArray(writeValueAsString(exchangeListQuery).getBytes()).setHeader("Content-Type", "application/json").setHeader("Authorization", getValidJwtToken()).execute().returnResponse();
    Map<String, Object> dataMap = checkSuccessResponseReturnMap(response);
    List<List> logList = (List) dataMap.get("logList");
    assertFalse(logList.isEmpty());
}
Also used : ExchangeListCriteria(eu.europa.ec.fisheries.schema.exchange.v1.ExchangeListCriteria) HttpResponse(org.apache.http.HttpResponse) ExchangeListCriteriaPair(eu.europa.ec.fisheries.schema.exchange.v1.ExchangeListCriteriaPair) ArrayList(java.util.ArrayList) List(java.util.List) ExchangeListQuery(eu.europa.ec.fisheries.schema.exchange.v1.ExchangeListQuery) ExchangeListPagination(eu.europa.ec.fisheries.schema.exchange.v1.ExchangeListPagination) Test(org.junit.Test) AbstractRestServiceTest(eu.europa.ec.fisheries.uvms.docker.validation.common.AbstractRestServiceTest)

Aggregations

ExchangeListCriteria (eu.europa.ec.fisheries.schema.exchange.v1.ExchangeListCriteria)2 ExchangeListPagination (eu.europa.ec.fisheries.schema.exchange.v1.ExchangeListPagination)2 ExchangeListQuery (eu.europa.ec.fisheries.schema.exchange.v1.ExchangeListQuery)2 ExchangeLogType (eu.europa.ec.fisheries.schema.exchange.v1.ExchangeLogType)2 ListResponseDto (eu.europa.ec.fisheries.uvms.exchange.model.dto.ListResponseDto)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 ExchangeListCriteriaPair (eu.europa.ec.fisheries.schema.exchange.v1.ExchangeListCriteriaPair)1 AbstractRestServiceTest (eu.europa.ec.fisheries.uvms.docker.validation.common.AbstractRestServiceTest)1 ExchangeLog (eu.europa.ec.fisheries.uvms.exchange.entity.exchangelog.ExchangeLog)1 ExchangeDaoException (eu.europa.ec.fisheries.uvms.exchange.exception.ExchangeDaoException)1 ExchangeModelException (eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeModelException)1 ExchangeSearchMapperException (eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeSearchMapperException)1 InputArgumentException (eu.europa.ec.fisheries.uvms.exchange.model.exception.InputArgumentException)1 SearchValue (eu.europa.ec.fisheries.uvms.exchange.search.SearchValue)1 ParseException (java.text.ParseException)1 List (java.util.List)1 SneakyThrows (lombok.SneakyThrows)1 HttpResponse (org.apache.http.HttpResponse)1