Search in sources :

Example 1 with ExchangeListCriteriaPair

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

the class SearchFieldMapper method getSearchValueForMessageDirection.

private static SearchValue getSearchValueForMessageDirection(ExchangeListCriteriaPair criteria) {
    if (!SearchField.MESSAGE_DIRECTION.equals(criteria.getKey()) || criteria.getValue() == null) {
        return null;
    }
    MessageDirection messageDirection = MessageDirection.valueOf(criteria.getValue());
    SearchValue searchValue = null;
    switch(messageDirection) {
        case ALL:
            searchValue = null;
            break;
        case INCOMING:
            searchValue = new SearchValue(ExchangeSearchField.TRANSFER_INCOMING, "true");
            break;
        case OUTGOING:
            searchValue = new SearchValue(ExchangeSearchField.TRANSFER_INCOMING, "false");
            break;
        default:
            searchValue = null;
    }
    return searchValue;
}
Also used : MessageDirection(eu.europa.ec.fisheries.schema.exchange.v1.MessageDirection)

Example 2 with ExchangeListCriteriaPair

use of eu.europa.ec.fisheries.schema.exchange.v1.ExchangeListCriteriaPair 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)

Example 3 with ExchangeListCriteriaPair

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

the class SearchFieldMapper method mapSearchField.

/**
 * Converts List<ListCriteria> to List<SearchValue> so that a JPQL query can
 * be built based on the criterias
 *
 * @param listCriterias
 * @return
 * @throws ExchangeSearchMapperException
 */
public static List<SearchValue> mapSearchField(List<ExchangeListCriteriaPair> listCriterias) throws ExchangeSearchMapperException {
    if (CollectionUtils.isEmpty(listCriterias)) {
        LOG.debug(" Non valid search criteria when mapping ListCriterias to SearchValue, List is null or empty");
        return new ArrayList<>();
    }
    List<SearchValue> searchFields = new ArrayList<>();
    for (ExchangeListCriteriaPair criteria : listCriterias) {
        try {
            if (SearchField.MESSAGE_DIRECTION.equals(criteria.getKey())) {
                SearchValue searchValue = getSearchValueForMessageDirection(criteria);
                if (searchValue == null) {
                    continue;
                }
                searchFields.add(searchValue);
            } else {
                ExchangeSearchField field = mapCriteria(criteria.getKey());
                searchFields.add(new SearchValue(field, criteria.getValue()));
            }
        } catch (ExchangeSearchMapperException ex) {
            LOG.debug("[ Error when mapping to search field.. continuing with other criterias ]");
        }
    }
    return searchFields;
}
Also used : ExchangeSearchMapperException(eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeSearchMapperException) ArrayList(java.util.ArrayList) ExchangeListCriteriaPair(eu.europa.ec.fisheries.schema.exchange.v1.ExchangeListCriteriaPair)

Aggregations

ExchangeListCriteriaPair (eu.europa.ec.fisheries.schema.exchange.v1.ExchangeListCriteriaPair)2 ArrayList (java.util.ArrayList)2 ExchangeListCriteria (eu.europa.ec.fisheries.schema.exchange.v1.ExchangeListCriteria)1 ExchangeListPagination (eu.europa.ec.fisheries.schema.exchange.v1.ExchangeListPagination)1 ExchangeListQuery (eu.europa.ec.fisheries.schema.exchange.v1.ExchangeListQuery)1 MessageDirection (eu.europa.ec.fisheries.schema.exchange.v1.MessageDirection)1 AbstractRestServiceTest (eu.europa.ec.fisheries.uvms.docker.validation.common.AbstractRestServiceTest)1 ExchangeSearchMapperException (eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeSearchMapperException)1 List (java.util.List)1 HttpResponse (org.apache.http.HttpResponse)1 Test (org.junit.Test)1