Search in sources :

Example 1 with FilterDetails

use of eu.europa.ec.fisheries.ers.service.search.FilterDetails in project UVMS-ActivityModule-APP by UnionVMS.

the class SearchQueryBuilder method createWherePartForQueryForFilters.

public StringBuilder createWherePartForQueryForFilters(StringBuilder sql, FishingActivityQuery 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());
    }
    // Create Where part of SQL Query
    int i = 0;
    for (SearchFilter key : keySet) {
        if (!appendWhereQueryPart(sql, filterMappings, keySet, i, key)) {
            continue;
        }
        i++;
    }
    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)

Example 2 with FilterDetails

use of eu.europa.ec.fisheries.ers.service.search.FilterDetails 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

FilterDetails (eu.europa.ec.fisheries.ers.service.search.FilterDetails)2 SearchFilter (eu.europa.ec.fisheries.uvms.activity.model.schemas.SearchFilter)2 HashSet (java.util.HashSet)2