use of org.hisp.dhis.webapi.controller.dataitem.Filter.Combination.DISPLAY_NAME_ILIKE in project dhis2-core by dhis2.
the class FilteringHelper method setFilteringParams.
/**
* Sets the filtering defined by filters list into the paramsMap.
*
* @param filters the source of filtering params
* @param paramsMap the map that will receive the filtering params
* @param currentUser the current user logged
*/
public static void setFilteringParams(final Set<String> filters, final WebOptions options, final MapSqlParameterSource paramsMap, final User currentUser) {
final Locale currentLocale = defaultIfNull(getUserSetting(DB_LOCALE), getUserSetting(UI_LOCALE));
if (currentLocale != null && isNotBlank(currentLocale.getLanguage())) {
paramsMap.addValue(LOCALE, trimToEmpty(currentLocale.getLanguage()));
}
final String ilikeName = extractValueFromFilter(filters, NAME_ILIKE);
if (StringUtils.isNotEmpty(ilikeName)) {
paramsMap.addValue(NAME, wrap(addIlikeReplacingCharacters(ilikeName), "%"));
}
final String ilikeDisplayName = extractValueFromFilter(filters, DISPLAY_NAME_ILIKE);
if (StringUtils.isNotEmpty(ilikeDisplayName)) {
paramsMap.addValue(DISPLAY_NAME, wrap(addIlikeReplacingCharacters(ilikeDisplayName), "%"));
}
final String ilikeShortName = extractValueFromFilter(filters, SHORT_NAME_ILIKE);
if (StringUtils.isNotEmpty(ilikeShortName)) {
paramsMap.addValue(SHORT_NAME, wrap(addIlikeReplacingCharacters(ilikeShortName), "%"));
}
final String ilikeDisplayShortName = extractValueFromFilter(filters, DISPLAY_SHORT_NAME_ILIKE);
if (StringUtils.isNotEmpty(ilikeDisplayShortName)) {
paramsMap.addValue(DISPLAY_SHORT_NAME, wrap(addIlikeReplacingCharacters(ilikeDisplayShortName), "%"));
}
final String equalId = extractValueFromFilter(filters, ID_EQUAL, true);
if (isNotBlank(equalId)) {
paramsMap.addValue(UID, equalId);
}
final String rootJunction = options.getRootJunction().name();
if (isNotBlank(rootJunction)) {
paramsMap.addValue(ROOT_JUNCTION, rootJunction);
}
final String identifiableToken = extractValueFromFilter(filters, IDENTIFIABLE_TOKEN);
if (identifiableToken != null) {
final List<String> wordsAsTokens = getTokens(identifiableToken);
if (CollectionUtils.isNotEmpty(wordsAsTokens)) {
paramsMap.addValue(IDENTIFIABLE_TOKEN_COMPARISON, StringUtils.join(wordsAsTokens, ","));
}
}
if (containsFilterWithAnyOfPrefixes(filters, VALUE_TYPE_EQUAL.getCombination(), VALUE_TYPE_IN.getCombination())) {
final Set<String> valueTypesFilter = extractAllValueTypesFromFilters(filters);
assertThatValueTypeFilterHasOnlyAggregatableTypes(valueTypesFilter, filters);
paramsMap.addValue(VALUE_TYPES, extractAllValueTypesFromFilters(filters));
} else {
// Includes all value types.
paramsMap.addValue(VALUE_TYPES, getAggregatables().stream().map(type -> type.name()).collect(toSet()));
}
final String programId = extractValueFromFilter(filters, PROGRAM_ID_EQUAL, true);
// Add program id filtering id, if present.
if (isNotBlank(programId)) {
paramsMap.addValue(PROGRAM_ID, programId);
}
// Add user group filtering, when present.
if (currentUser != null && CollectionUtils.isNotEmpty(currentUser.getGroups())) {
final Set<String> userGroupUids = currentUser.getGroups().stream().filter(group -> group != null).map(group -> trimToEmpty(group.getUid())).collect(toSet());
paramsMap.addValue(USER_GROUP_UIDS, "{" + join(",", userGroupUids) + "}");
}
}
Aggregations