[MGNLREST-349] Creating asset via rest is not possible anymore Created: 04/Feb/22  Updated: 23/Oct/23  Resolved: 01/Mar/22

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

Type: Bug Priority: Critical
Reporter: Tobias Kerschbaum Assignee: Milan Divilek
Resolution: Fixed Votes: 2
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Problem/Incident
is caused by MGNLREST-343 Empty node name when using illegal ch... Closed
causality
is causing MGNLREST-347 DOC: What is a valid node name Closed
relation
is related to MGNLREST-359 Cannot put nodes with colons in the name Closed
is related to DOCU-2430 How to add an asset with REST tutoria... Closed
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
Date of First Response:
Epic Link: Headless Phase 2
Sprint: DevX 4
Story Points: 5
Team: DeveloperX

 Description   

Steps to reproduce

  1. Use any magnolia instance (for example jumpstart)
  2. Try adding an Asset via rest, like described in the documentation
    https://docs.magnolia-cms.com/product-docs/6.2/Developing/How-to-add-an-asset-with-REST.html

Expected results

It should be possible to add Assets via rest

Actual results

The Asset is not added properly because the jcr:content node of the asset is saved as jcr-content.

Workaround

Development notes

I think the problem could maybe come with this commit from the latest version:

https://git.magnolia-cms.com/projects/MODULES/repos/rest/commits/f9cd00ffd4349e62cb9e8ede62bf01bc1648381c#magnolia-rest-services/src/main/java/info/magnolia/rest/service/node/v1/NodeEndpoint.java

Because the colon is now an invalid character, jcr:content is saved as jcr-content.
I exported the file, renamed it back to jcr:content. After the reimport, the file was shown fine.

PM (Topher) Input

Do a little research why we escape : even though it's allowed character in JCR.

Valid (and actually required) node names are now being renamed to values that cause the system to work incorrectly. The reporter mentions the problem with the "jcr:content" name for assets. (It must be named "jcr:content"). I am not sure if this is the only case for Node names. I can see in linked docu page that there are also some required property names which have a colon, for example "jcr:data" or "jcr:mimeType".

It's challenging to decide on the proper behaviour because on one hand there are node names that require a colon, whereas when users use the UI colons are converted to dashes for the node name.

I propose the following:

Research what other requiired node names include a colon.

Checking if the node name in the REST request includes one of the known "required" names (such as 'jcr:content') and if so dont rename it. A more perissive but probably more future-proof approach would be to check if the node name inclues "jcr:" or "mgnl:" and if so, dont rename it.

The endpoint should return a message if a node has been renamed, and what its new name is. (otherwise the data on the client can get out of sync if it expects a certain name. Imagine the client has a system with 20 products and wants to import those items in Magnoila and maintiain "links" to them based on their names.)

The documentation should be updated to inform what are valid node names and what type of message is returned when invalid ones are supplied.

 

 



 Comments   
Comment by Milan Divilek [ 18/Feb/22 ]

Colons is invalid character in JCR Local Names.

InvalidChar ::= '/' | ':' | '[' | ']' | '|' | '*'

JCR name is composed of JCR namespace and JCR local name and colon is used as delimiter.

For example: "jcr:content"
Namespace: jcr
Local Name: content

see https://developer.adobe.com/experience-manager/reference-materials/spec/jcr/2.0/3_Repository_Model.html

Solution:
Correct solution in my opinion is adjust NodeNameHelper to work correctly when name contains also the jcr namespace.

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