Search in sources :

Example 26 with SearchFilter

use of eu.europa.ec.fisheries.uvms.activity.model.schemas.SearchFilter in project UVMS-ActivityModule-APP by UnionVMS.

the class SearchQueryBuilder method getJoinPartForSortingOptions.

/**
 * This method makes sure that Table join is present for the Filter for which sorting has been requested.
 *
 * @param sql
 * @param query
 * @return
 */
private StringBuilder getJoinPartForSortingOptions(StringBuilder sql, FishingActivityQuery query) {
    SortKey sort = query.getSorting();
    // IF sorting has been requested and
    if (sort == null) {
        return sql;
    }
    SearchFilter field = sort.getSortBy();
    if (field == null) {
        return sql;
    }
    // Make sure that the field which we want to sort, table Join is present for it.
    switch(getFiledCase(sql, field)) {
        case 1:
            appendLeftJoinFetch(sql, filterMap.DELIMITED_PERIOD_TABLE_ALIAS);
            break;
        case 2:
            appendLeftJoinFetch(sql, FilterMap.FLUX_REPORT_DOC_TABLE_ALIAS);
            break;
        case 3:
            checkAndAppendIfNeededFluxReportDocTable(sql);
            break;
        default:
            break;
    }
    return sql;
}
Also used : SortKey(eu.europa.ec.fisheries.ers.service.search.SortKey) SearchFilter(eu.europa.ec.fisheries.uvms.activity.model.schemas.SearchFilter)

Example 27 with SearchFilter

use of eu.europa.ec.fisheries.uvms.activity.model.schemas.SearchFilter in project UVMS-ActivityModule-APP by UnionVMS.

the class SearchQueryBuilder method applyListValuesToQuery.

/**
 * Applies the values stored in the searchCriteriaMapMultipleValues map to the typedQuery
 *
 * @param searchCriteriaMap
 * @param typedQuery
 * @return
 * @throws ServiceException
 */
private void applyListValuesToQuery(Map<SearchFilter, List<String>> searchCriteriaMap, Query typedQuery) throws ServiceException {
    // Assign values to created SQL Query
    for (Map.Entry<SearchFilter, List<String>> entry : searchCriteriaMap.entrySet()) {
        SearchFilter key = entry.getKey();
        List<String> valueList = entry.getValue();
        // For WeightMeasure there is no mapping present, In that case
        if (queryParameterMappings.get(key) == null) {
            continue;
        }
        if (valueList == null || valueList.isEmpty()) {
            throw new ServiceException("valueList for filter " + key + " is null or empty");
        }
        switch(key) {
            case MASTER:
                List<String> uppperCaseValList = new ArrayList<>();
                for (String val : valueList) {
                    uppperCaseValList.add(val.toUpperCase());
                }
                typedQuery.setParameter(queryParameterMappings.get(key), uppperCaseValList);
                break;
            default:
                typedQuery.setParameter(queryParameterMappings.get(key), valueList);
                break;
        }
    }
}
Also used : ServiceException(eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException) ArrayList(java.util.ArrayList) SearchFilter(eu.europa.ec.fisheries.uvms.activity.model.schemas.SearchFilter) ArrayList(java.util.ArrayList) List(java.util.List) FilterMap(eu.europa.ec.fisheries.ers.service.search.FilterMap) Map(java.util.Map)

Example 28 with SearchFilter

use of eu.europa.ec.fisheries.uvms.activity.model.schemas.SearchFilter in project UVMS-ActivityModule-APP by UnionVMS.

the class SearchQueryBuilder method applySingleValuesToQuery.

private void applySingleValuesToQuery(Map<SearchFilter, String> searchCriteriaMap, Query typedQuery) throws ServiceException {
    // Assign values to created SQL Query
    for (Map.Entry<SearchFilter, String> entry : searchCriteriaMap.entrySet()) {
        SearchFilter key = entry.getKey();
        String value = entry.getValue();
        // For WeightMeasure there is no mapping present, In that case
        if (queryParameterMappings.get(key) == null) {
            continue;
        }
        if (StringUtils.isEmpty(value)) {
            throw new ServiceException("Value for filter " + key + " is null or empty");
        }
        applyValueDependingOnKey(searchCriteriaMap, typedQuery, key, value);
    }
}
Also used : ServiceException(eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException) SearchFilter(eu.europa.ec.fisheries.uvms.activity.model.schemas.SearchFilter) FilterMap(eu.europa.ec.fisheries.ers.service.search.FilterMap) Map(java.util.Map)

Example 29 with SearchFilter

use of eu.europa.ec.fisheries.uvms.activity.model.schemas.SearchFilter in project UVMS-ActivityModule-APP by UnionVMS.

the class SearchQueryBuilder method createJoinTablesPartForQuery.

/**
 * Create Table Joins based on Filters provided by user. Avoid joining unnecessary tables
 *
 * @param sql
 * @param query
 * @return
 */
public StringBuilder createJoinTablesPartForQuery(StringBuilder sql, FishingActivityQuery query) {
    LOG.debug("Create Join Tables part of Query");
    Map<SearchFilter, FilterDetails> filterMappings = filterMap.getFilterMappings();
    Set<SearchFilter> keySet = new HashSet<>();
    if (MapUtils.isNotEmpty(query.getSearchCriteriaMap())) {
        keySet.addAll(query.getSearchCriteriaMap().keySet());
    }
    if (MapUtils.isNotEmpty(query.getSearchCriteriaMapMultipleValues())) {
        keySet.addAll(query.getSearchCriteriaMapMultipleValues().keySet());
    }
    for (SearchFilter key : keySet) {
        FilterDetails details = filterMappings.get(key);
        String joinString = null;
        if (details != null) {
            joinString = details.getJoinString();
        }
        if (joinString == null || sql.indexOf(joinString) != -1) {
            // If the Table join for the Filter is already present in SQL, do not join the table again
            continue;
        }
        completeQueryDependingOnKey(sql, key, joinString);
    }
    getJoinPartForSortingOptions(sql, query);
    // LOG.debug("Generated SQL for JOIN Part :" + sql);
    return sql;
}
Also used : FilterDetails(eu.europa.ec.fisheries.ers.service.search.FilterDetails) SearchFilter(eu.europa.ec.fisheries.uvms.activity.model.schemas.SearchFilter) HashSet(java.util.HashSet)

Aggregations

SearchFilter (eu.europa.ec.fisheries.uvms.activity.model.schemas.SearchFilter)29 FishingActivityQuery (eu.europa.ec.fisheries.ers.service.search.FishingActivityQuery)19 ArrayList (java.util.ArrayList)18 List (java.util.List)17 Test (org.junit.Test)17 SneakyThrows (lombok.SneakyThrows)16 HashMap (java.util.HashMap)14 EnumMap (java.util.EnumMap)9 SortKey (eu.europa.ec.fisheries.ers.service.search.SortKey)8 PaginationDto (eu.europa.ec.fisheries.uvms.commons.rest.dto.PaginationDto)7 ServiceException (eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException)7 FilterMap (eu.europa.ec.fisheries.ers.service.search.FilterMap)4 FishingTripId (eu.europa.ec.fisheries.ers.service.search.FishingTripId)4 GroupCriteria (eu.europa.ec.fisheries.uvms.activity.model.schemas.GroupCriteria)4 Map (java.util.Map)4 FishingTripResponse (eu.europa.ec.fisheries.uvms.activity.model.schemas.FishingTripResponse)3 FaCatchSummaryCustomProxy (eu.europa.ec.fisheries.ers.fa.dao.proxy.FaCatchSummaryCustomProxy)2 FishingActivityEntity (eu.europa.ec.fisheries.ers.fa.entities.FishingActivityEntity)2 FilterFishingActivityReportResultDTO (eu.europa.ec.fisheries.ers.service.dto.FilterFishingActivityReportResultDTO)2 FilterDetails (eu.europa.ec.fisheries.ers.service.search.FilterDetails)2