Search in sources :

Example 1 with ExchangeSearchMapperException

use of eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeSearchMapperException in project UVMS-ExchangeModule-APP by UnionVMS.

the class SearchFieldMapper method getSortingString.

private static void getSortingString(Sorting sorting, StringBuilder selectBuffer) throws ExchangeSearchMapperException {
    if (sorting != null && sorting.getSortBy() != null) {
        SortField sortField = sorting.getSortBy();
        SortFieldMapper sortFieldMapper = null;
        if (sortField != null) {
            try {
                sortFieldMapper = mapSortField(sortField);
            } catch (ExchangeSearchMapperException e) {
                LOG.error("Error while mapping criteria", e);
                throw e;
            }
        }
        String fieldName = sortFieldMapper.getFieldName();
        String sortingDirection = "ASC";
        if (sorting.isReversed()) {
            sortingDirection = "DESC";
        }
        selectBuffer.append(" order by " + SearchTable.LOG.getTableAlias() + ".").append(fieldName).append(" ").append(sortingDirection);
    } else {
        selectBuffer.append(" order by " + SearchTable.LOG.getTableAlias() + ".updateTime desc ");
    }
}
Also used : ExchangeSearchMapperException(eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeSearchMapperException) SortField(eu.europa.ec.fisheries.schema.exchange.v1.SortField)

Example 2 with ExchangeSearchMapperException

use of eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeSearchMapperException 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 ExchangeSearchMapperException

use of eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeSearchMapperException 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

ExchangeSearchMapperException (eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeSearchMapperException)3 ArrayList (java.util.ArrayList)2 ExchangeListCriteriaPair (eu.europa.ec.fisheries.schema.exchange.v1.ExchangeListCriteriaPair)1 ExchangeLogType (eu.europa.ec.fisheries.schema.exchange.v1.ExchangeLogType)1 SortField (eu.europa.ec.fisheries.schema.exchange.v1.SortField)1 ExchangeLog (eu.europa.ec.fisheries.uvms.exchange.entity.exchangelog.ExchangeLog)1 ExchangeDaoException (eu.europa.ec.fisheries.uvms.exchange.exception.ExchangeDaoException)1 ListResponseDto (eu.europa.ec.fisheries.uvms.exchange.model.dto.ListResponseDto)1 ExchangeModelException (eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeModelException)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