[MGNLREST-345] JcrReferenceResolverDefinition wrongly generating links for cross site and self Created: 03/Feb/22  Updated: 01/Jun/23  Resolved: 01/Jun/23

Status: Closed
Project: Magnolia REST Framework
Component/s: None
Affects Version/s: 2.2.16
Fix Version/s: None

Type: Bug Priority: Neutral
Reporter: Bartosz Staryga Assignee: Dai Ha
Resolution: Not an issue Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: PNG File Screenshot 2022-02-03 at 16.16.08.png    
Issue Links:
causality
is causing MGNLREST-720 DOC: Position of referenceRepeat in e... Closed
Template:
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)
Bug DoR:
[ ]* Steps to reproduce, expected, and actual results filled
[ ]* Affected version filled
Release notes required:
Yes
Documentation update required:
Yes
Date of First Response:
Epic Link: Support
Team: DeveloperX
Work Started:

 Description   

Steps to reproduce

  1. we have a rest endpoint that resolves links to other pages with reference resolver:
      - name: linkReference
        propertyName: link
        referenceResolver: 
          class: info.magnolia.rest.reference.jcr.JcrReferenceResolverDefinition
          targetWorkspace: website
          expand: false
          generateLink: true
    
  1. we have a component that allows linking
  2. link to page itself
  3. link to page in other site (multisite)

Expected results

All links resolved correctly

Actual results

Link to self is not resolved
Link to cross-site is resolved in the wrong way

Normal link

{
"@name": "cta",
"@path": "/home/bartosz/hero/00/cta",
"@id": "ad764a41-167e-4acc-a145-71420082391d",
"@nodeType": "mgnl:contentNode",
"link": "http://ecommerce-headless-author.magnolia-cms-demo.com/home/TobiasDemo.html",
"text": "normal",
"mgnl:createdBy": "jl3r2p5kplieoo3t",
"mgnl:lastModified": "2022-02-03T15:14:10.069Z",
"mgnl:lastModifiedBy": "jl3r2p5kplieoo3t",
"@nodes": []
}

Link to self

{
"@name": "cta",
"@path": "/home/bartosz/hero/0/cta",
"@id": "c4d14527-fe8c-421c-90b6-b4fd5a835165",
"@nodeType": "mgnl:contentNode",
"text": "link to self",
"link": "45cbec50-608c-4cf5-bd13-33668a9f2173",
"mgnl:createdBy": "jl3r2p5kplieoo3t",
"mgnl:lastModified": "2022-02-03T15:12:54.893Z",
"mgnl:lastModifiedBy": "jl3r2p5kplieoo3t",
"@nodes": []
}

Link to cross site

{
"@name": "cta",
"@path": "/home/bartosz/hero/01/cta",
"@id": "2a8fa5ac-7062-421c-9d5a-dd95cebb1922",
"@nodeType": "mgnl:contentNode",
"text": "other page",
"link": "http://127.0.0.1:8080/home_ch/en/bathroom.html",
"mgnl:createdBy": "jl3r2p5kplieoo3t",
"mgnl:lastModified": "2022-02-03T15:14:31.348Z",
"mgnl:lastModifiedBy": "jl3r2p5kplieoo3t",
"@nodes": []
}


 Comments   
Comment by Viet Nguyen [ 14/Feb/23 ]

Set property referenceRepeat to "true" in your JcrDeliveryEndpointDefinition for link to self generating.
I would recommend that we change the property name from "referenceRepeat" to "resolveRootReference" or "selfReferenceResolve" for better UX. Also we should update our documentation for this and also our release note in case we change the property name so that customers who're using that property can know to update.
Regarding cross-site link resolver, we may need to create a new class which extends the current one for that. The mechanism may similar to AssetReferenceResolver.

Comment by Dai Ha [ 22/May/23 ]

Hi a viet.nguyen , bstaryga , I am trying to reproduce this issue. Locally, I am using travel and sportation sites for cross-site references. I make a travel page with link property to sportation page. This is what I got from the query:

 

{
   "@name":"test3",
   "@path":"/travel/test3",
   "@id":"92fe1f13-1c76-4586-bc29-b976e6c0c28e",
   "@nodeType":"mgnl:page",
   "link":"http://sportstation.magnolia-cms.com/about.html",
   "newHeader":true,
   "@nodes":[
      
   ]
}

The link is resolved correctly with ootb usage - do you happen to have the setup with issue that I can take a look? maybe the referenced site does not have domain mapping so it fallback to localhost?

 

Comment by Dai Ha [ 24/May/23 ]

Here is one sample for the usage of referenceRepeat property:

 

{
   "@name":"test4",
   "@path":"/travel/test4",
   "@id":"6c1d35d0-32b7-4aed-a31d-567b2cf61810",
   "@nodeType":"mgnl:page",
   "link":"http://travel-demo.magnolia-cms.com/test4.html",
   "newHeader":false,
   "@nodes":[
      
   ]
}

As discussed with a viet.nguyen yesterday, we will not change the property name because of the deep history of its usage - it will either required customer to adjust all of their config or increase the complexity in the implementation (also, so far no complaint on its name). In additional, we will not change default value referenceRepeat=true also, because it will trigger more processing by default which is not always required by client's system.

 

Comment by Dai Ha [ 24/May/23 ]

Hi tobias.kerschbaum, bstaryga and I have agreed on the solutions as below:

  • set domain mappings on all sites as this is used to build cross site links
  • set referenceRepeat to whatever for resolving self links correctly and why it needs to be set

I will have someone in devX to verify (qa) the discovery result again. We will need to improve the docs on the usage of referenceRepeat, maybe by adding an example, mdrapela?

Comment by Robert Šiška [ 30/May/23 ]

Can confirm, that the reference-resolving mechanism works correctly as designed.

I would agree that the documentation of reference resolvers isn't very clear about the referenceRepeat tip. Maye it could be more clear about where is it supposed to be defined (on endpoint definition level, not reference resolver definition level)

Not having site mappings for a certain site should (and in my case does) correctly resolve with fallback site as "http://localhost:8080/magnoliaAuthor/fallback/basic.html"

Generated at Mon Feb 12 06:59:00 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.