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 d821386218dd..bdeb50c43d10 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 @@ -46,6 +46,7 @@ public class CategoryFactoryImpl extends CategoryFactory { public static final String INODE = "inode"; + public static final String CATEGORY_NAME = "category_name"; CategoryCache catCache; final CategorySQL categorySQL; @@ -989,6 +990,8 @@ public List findHierarchy(final Collection inode final String queryTemplate = "WITH RECURSIVE CategoryHierarchy AS ( SELECT " + "c.inode," + "c.inode AS root_inode," + + "c.category_name," + + "c.category_name AS root_category_name," + "1 AS level," + "json_build_object('inode', c.inode, 'categoryName', c.category_name, 'key', c.category_key)::varchar AS path " + "FROM Category c " + @@ -997,13 +1000,15 @@ public List findHierarchy(final Collection inode "SELECT " + "c.inode, " + "ch.root_inode AS root_inode, " + + "c.category_name, " + + "ch.root_category_name AS root_category_name, " + "ch.level + 1 AS level, " + "CONCAT(json_build_object('inode', c.inode, 'categoryName', c.category_name, 'key', c.category_key)::varchar, ',', ch.path) AS path " + "FROM Category c JOIN tree t ON c.inode = t.parent JOIN CategoryHierarchy ch ON t.child = ch.inode " + ")," + "MaxLevels AS (SELECT root_inode, MAX(level) AS max_level FROM CategoryHierarchy GROUP BY root_inode) " + "SELECT " + - "ch.root_inode as inode, " + + "ch.root_inode as inode, ch.root_category_name as category_name, " + "CONCAT('[', path, ']')::jsonb as path " + "FROM CategoryHierarchy ch JOIN MaxLevels ml ON ch.root_inode = ml.root_inode AND ch.level = ml.max_level;"; @@ -1016,7 +1021,8 @@ public List findHierarchy(final Collection inode return dc.loadObjectResults().stream().map(row -> { final List parentList = getShortCategories(row.get("path").toString()); - return new HierarchyShortCategory(row.get(INODE).toString(), parentList.subList(0, parentList.size() - 1)); + return new HierarchyShortCategory(row.get(INODE).toString(), row.get(CATEGORY_NAME).toString(), + parentList.subList(0, parentList.size() - 1)); }).collect(Collectors.toList()); } diff --git a/dotCMS/src/main/java/com/dotmarketing/portlets/categories/model/HierarchyShortCategory.java b/dotCMS/src/main/java/com/dotmarketing/portlets/categories/model/HierarchyShortCategory.java index f2c5db0869b3..045db8e09cf3 100644 --- a/dotCMS/src/main/java/com/dotmarketing/portlets/categories/model/HierarchyShortCategory.java +++ b/dotCMS/src/main/java/com/dotmarketing/portlets/categories/model/HierarchyShortCategory.java @@ -8,11 +8,13 @@ */ public class HierarchyShortCategory implements Serializable { private final String inode; + private final String categoryName; private final List parentList; - public HierarchyShortCategory(final String inode, final List parentList) { + public HierarchyShortCategory(final String inode, final String categoryName, final List parentList) { this.inode = inode; this.parentList = parentList; + this.categoryName = categoryName; } public String getInode() { @@ -22,4 +24,8 @@ public String getInode() { public List getParentList() { return parentList; } + + public String getCategoryName() { + return categoryName; + } } diff --git a/dotcms-postman/src/main/resources/postman/Category.postman_collection.json b/dotcms-postman/src/main/resources/postman/Category.postman_collection.json index 5b9d409ca5ab..0610e191c68d 100644 --- a/dotcms-postman/src/main/resources/postman/Category.postman_collection.json +++ b/dotcms-postman/src/main/resources/postman/Category.postman_collection.json @@ -1,6 +1,6 @@ { "info": { - "_postman_id": "12554162-5748-4f0b-a315-85639e82d87b", + "_postman_id": "4aaa5f5d-78ea-498e-a1a4-3b367004de5e", "name": "Category", "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json", "_exporter_id": "30436704" @@ -3524,11 +3524,13 @@ " { ", "", " if (jsonData.entity[i]['inode'] === child2CategoryInodeHierarchy) {", + " pm.expect('Hierarchy Child 2').to.have.equals(jsonData.entity[i].categoryName);", " pm.expect(1).to.have.equals(jsonData.entity[i].parentList.length);", " pm.expect('Hierarchy Top level Category').to.have.equals(jsonData.entity[i].parentList[0].categoryName);", " pm.expect(pm.collectionVariables.get(\"topCategoryInodeHierarchy\")).to.have.equals(jsonData.entity[i].parentList[0].inode);", " pm.expect('Hierarchy_TOP_LEVEL').to.have.equals(jsonData.entity[i].parentList[0].key);", " } else if (jsonData.entity[i]['inode'] === grantChildCategoryInodeHierarchy) {", + " pm.expect('Hierarchy Grandchild 1').to.have.equals(jsonData.entity[i].categoryName);", " pm.expect(2).to.have.equals(jsonData.entity[i].parentList.length);", "", " pm.expect('Hierarchy Top level Category').to.have.equals(jsonData.entity[i].parentList[0].categoryName);",