[MGNLREST-265] Support resolve links in richTextField via NodeWriter Created: 10/Aug/20  Updated: 09/Jan/24

Status: Open
Project: Magnolia REST Framework
Component/s: delivery
Affects Version/s: 2.2.1
Fix Version/s: None

Type: Improvement Priority: Neutral
Reporter: Viet Nguyen Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: 622
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

mgnl-6.2.2


Attachments: PNG File Bildschirmfoto 2020-08-10 um 11.20.44.png    
Issue Links:
causality
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)
Testcase included:
Yes
Release notes required:
Yes
Documentation update required:
Yes
Team: DeveloperX

 Description   

reproduce steps

1. create a text component

form:
  properties:
    text:
      label: Text
      $type: richTextField

2.
add the component to a page and maintain a link

3.
Do a request against the delivery API:  http://localhost:8080/author/.rest/delivery/pages/v1/demo-content

The response is:

	"main": {
		"@name": "main",
		"@path": "/demo-content/main",
		"@id": "ceecf6c7-8a5c-48e1-a5d8-2dda9e5a0dfe",
		"@nodeType": "mgnl:area",
		"0": {
			"@name": "0",
			"@path": "/demo-content/main/0",
			"@id": "86c4e0a6-159d-4911-b589-4f6e2888e15c",
			"@nodeType": "mgnl:component",
			"text": "<p><a href=\"${link:{uuid:{943d6ee7-f6a5-4be0-9fb9-415b59b95523},repository:{website},path:{/demo-content/inhlatsseite}}}\">test</a></p>\n",
			"mgnl:template": "test:components/text",
			"@nodes": []
		},
		"@nodes": ["0"]
	}

expected result

I would expect a real page link. 

actual result

described above

implementation notes

The functionality I added is from the ContentMap. For freemarker, the links ware resolved there.
Would be better if we can have a flag in the endpoint definition for this function, true by default. Things like resolve references taking a number of depth.

Customer notes

Possible Solution:

private String getValueString(Value value) throws RepositoryException {
        switch (value.getType()) {
        case PropertyType.BINARY:
            return getBinaryString(value);
        case PropertyType.DECIMAL:
            return String.valueOf(value.getDecimal());
        case PropertyType.NAME:
        case PropertyType.URI:
        case PropertyType.DATE:
            return value.getString();
        default:
            return getStringValue(value);
        }
    }

    public String getStringValue(final Value value) {
        String result = PropertyUtil.getValueString(value);
        if (LinkUtil.UUID_PATTERN.matcher(result).find()) {
            try {
                result = info.magnolia.link.LinkUtil.convertLinksFromUUIDPattern(result);
            } catch (LinkException e) {
                LOGGER.warn("Failed to parse links with from {}", result, e);
            }
        }

        return result;
    }

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