Skip to content

Commit

Permalink
#28896 Feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
freddyDOTCMS committed Jun 26, 2024
1 parent 90a3627 commit 3ceb562
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -839,21 +839,24 @@ protected String suggestVelocityVarName(final String categoryVelVarName) throws
* Default Implementation for {@link CategoryFactory#findAll(String)}
* @param filter Value used to filter the Category by, returning only Categories that contain this value in their key, name, or variable name
*
* @return
* @return A Collection of {@link Category} filtered by 'filter', if filter is null then it return the that
* {@link CategoryFactoryImpl#findAll()}
*/
public List<Category> findAll(final String filter) throws DotDataException {

if ( !UtilMethods.isSet(filter) ) {
return findAll();
}

final DotConnect dc = new DotConnect()
.setSQL("SELECT * FROM category " +
"WHERE LOWER(category.category_name) LIKE ? OR " +
"LOWER(category.category_key) LIKE ? OR " +
"LOWER(category.category_velocity_var_name) LIKE ?");

if ( UtilMethods.isSet(filter) ) {
dc.addObject("%" + filter.toLowerCase() + "%");
dc.addObject("%" + filter.toLowerCase() + "%");
dc.addObject("%" + filter.toLowerCase() + "%");
}
dc.addObject("%" + filter.toLowerCase() + "%");
dc.addObject("%" + filter.toLowerCase() + "%");
dc.addObject("%" + filter.toLowerCase() + "%");

List<Category> categories = convertForCategories(dc.loadObjectResults());
updateCache(categories);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.dotmarketing.exception.DotSecurityException;
import com.dotmarketing.portlets.categories.model.Category;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

import com.liferay.util.StringUtil;
Expand Down Expand Up @@ -374,4 +375,13 @@ public void getAllCategoriesFiltered() throws DotDataException {
assertTrue(categories_2.containsAll(categoriesExpected));
}

@Test
public void getAllCategoriesWithNullFilter() throws DotDataException {
new CategoryDataGen().nextPersisted();

final List<Category> categoriesWithFilter = FactoryLocator.getCategoryFactory().findAll(null);
final List<Category> categoriesWithoutFilter = FactoryLocator.getCategoryFactory().findAll();
assertTrue(Objects.deepEquals(categoriesWithoutFilter, categoriesWithFilter));
}

}

0 comments on commit 3ceb562

Please sign in to comment.