[MGNLCAT-197] getContentByCategoryIdentifier templating function returns invalid results Created: 23/Mar/21  Updated: 09/Sep/22  Resolved: 08/Sep/22

Status: Closed
Project: Magnolia Categorization Module
Component/s: None
Affects Version/s: 2.7.1
Fix Version/s: 2.9.1

Type: Bug Priority: Neutral
Reporter: Jonathan Ayala Assignee: Lam Nguyen Bao
Resolution: Fixed Votes: 0
Labels: None
Σ Remaining Estimate: Not Specified Remaining Estimate: Not Specified
Σ Time Spent: 1d 1h 10m Time Spent: 1d 1h 10m
Σ Original Estimate: Not Specified Original Estimate: Not Specified

Issue Links:
causality
Sub-Tasks:
Key
Summary
Type
Status
Assignee
MGNLCAT-206 QA Sub-task Completed Thuy To  
Template:
Acceptance criteria:
Empty
Task DoD:
[X]* Doc/release notes changes? Comment present?
[X]* Downstream builds green?
[X]* Solution information and context easily available?
[X]* Tests
[X]* FixVersion filled and not yet released
[ ]  Architecture Decision Record (ADR)
Bug DoR:
[ ]* Steps to reproduce, expected, and actual results filled
[ ]* Affected version filled
Epic Link: AuthorX Support
Sprint: AuthX 17
Story Points: 1
Team: AuthorX

 Description   

Steps to reproduce

  1.  Create a page that contains a link to another page
  2.  Call getContentByCategoryIdentifier(String, String) in CategorizationTemplatingFunctions to get all the content that is related to category whose uuid is the uuid of the page linked in previous step, i.e. what is passed as parameter is not the UUID of a category but another UUID (of a page). You can make use of the following script:
    catfn = info.magnolia.objectfactory.Components.getComponent(info.magnolia.module.categorization.functions.CategorizationTemplatingFunctions.class)
    println(catfn.getContentByCategoryIdentifier("PATH", "UUID"))
    

Expected results

Since passed UUID is not a category, no results are returned

Actual results

Page with link is returned

Workaround

Create an alternative function just like the existing one but using JCR-SQL2 instead of the deprecated XPATH expression

Development notes

According to the query that is generated, it should look for UUIDs within categories property:

...[jcr:contains(.categories, ''{1}'')]"

This is the only function making use of XPATH query, which is deprecated. Translating the existing query to the following would work as expected:

select * from [mgnl:content] as t WHERE CONTAINS(t.categories,'UUID') AND ISDESCENDANTNODE('PATH')

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