[MGNLCAT-15] When using hierarchical categories, related categories paragraph should display parent and siblings of category selected in category overview page Created: 15/Feb/10  Updated: 04/Oct/13  Resolved: 19/Mar/10

Status: Closed
Project: Magnolia Categorization Module
Component/s: None
Affects Version/s: 1.1
Fix Version/s: 1.1.3

Type: Improvement Priority: Major
Reporter: Teresa Miyar Assignee: Philipp Bärfuss
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: Text File catutil.patch    
Template:
Patch included:
Yes
Acceptance criteria:
Empty
Task DoD:
[ ]* Doc/release notes changes? Comment present?
[ ]* Downstream builds green?
[ ]* Solution information and context easily available?
[ ]* Tests
[ ]* FixVersion filled and not yet released
[ ]  Architecture Decision Record (ADR)

 Description   
Index: src/main/java/info/magnolia/module/categorization/util/CategoryUtil.java
===================================================================
--- src/main/java/info/magnolia/module/categorization/util/CategoryUtil.java	(revision 31605)
+++ src/main/java/info/magnolia/module/categorization/util/CategoryUtil.java	(working copy)
@@ -96,7 +96,7 @@
     public static Collection getRelatedCategories(String name) {
         List relatedNodes = new ArrayList();
         try {
-            Content categoryNode = getCategoryNodeByName(name);
+            final Content categoryNode = getCategoryNodeByName(name);
             if(categoryNode.hasContent("relatedUUID")) {
                 Collection uuids = categoryNode.getChildByName("relatedUUID").getChildren();
                 Iterator uuidsIt = uuids.iterator();
@@ -110,6 +110,23 @@
                     }
                 }
             }
+            //Check if has sub categories
+            if (categoryNode.hasChildren()) {
+                relatedNodes.addAll(categoryNode.getChildren());
+            }
+            // check if has siblings
+            if(categoryNode.getLevel() > 2) {
+                Content parent = categoryNode.getParent();
+                relatedNodes.add(parent);
+                Iterator childrenIt = parent.getChildren().iterator();
+
+                while(childrenIt.hasNext()) {
+                    Content item = (Content)childrenIt.next();
+                    if(!categoryNode.getUUID().equals(item.getUUID())) {
+                        relatedNodes.add(item);
+                    }
+                }
+            }
         } catch (RepositoryException e) {
             log.warn("cant get category " + name, e);
         }

Generated at Mon Feb 12 04:42:17 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.