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;
}
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;
}
}
}
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);
}
}
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;
}
Aggregations