From 3ceb562f350148eaaee58f07420427dc57ab3686 Mon Sep 17 00:00:00 2001 From: freddyDOTCMS Date: Wed, 26 Jun 2024 15:57:03 -0600 Subject: [PATCH] #28896 Feedback --- .../categories/business/CategoryFactoryImpl.java | 15 +++++++++------ .../categories/business/CategoryFactoryTest.java | 10 ++++++++++ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/dotCMS/src/main/java/com/dotmarketing/portlets/categories/business/CategoryFactoryImpl.java b/dotCMS/src/main/java/com/dotmarketing/portlets/categories/business/CategoryFactoryImpl.java index 5623fa47e807..b64c6fac8870 100644 --- a/dotCMS/src/main/java/com/dotmarketing/portlets/categories/business/CategoryFactoryImpl.java +++ b/dotCMS/src/main/java/com/dotmarketing/portlets/categories/business/CategoryFactoryImpl.java @@ -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 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 categories = convertForCategories(dc.loadObjectResults()); updateCache(categories); diff --git a/dotcms-integration/src/test/java/com/dotmarketing/portlets/categories/business/CategoryFactoryTest.java b/dotcms-integration/src/test/java/com/dotmarketing/portlets/categories/business/CategoryFactoryTest.java index 8705cfb2ccad..4abad3532ee5 100644 --- a/dotcms-integration/src/test/java/com/dotmarketing/portlets/categories/business/CategoryFactoryTest.java +++ b/dotcms-integration/src/test/java/com/dotmarketing/portlets/categories/business/CategoryFactoryTest.java @@ -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; @@ -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 categoriesWithFilter = FactoryLocator.getCategoryFactory().findAll(null); + final List categoriesWithoutFilter = FactoryLocator.getCategoryFactory().findAll(); + assertTrue(Objects.deepEquals(categoriesWithoutFilter, categoriesWithFilter)); + } + }