[ECOMMERCE-523] invalid (old) data in jcr breaks app in combination with ecommerceProductLinkField Created: 06/May/22  Updated: 16/Aug/22  Resolved: 28/Jun/22

Status: Closed
Project: E-commerce
Component/s: ui
Affects Version/s: 1.3.3
Fix Version/s: 1.3.4

Type: Bug Priority: Critical
Reporter: Tobias Kerschbaum Assignee: Thuy To
Resolution: Fixed Votes: 3
Labels: VN-Analysis, VN-Implementation, VN-Testing
Remaining Estimate: 0d
Time Spent: 7d 3h 50m
Original Estimate: Not Specified

Attachments: PNG File Screen Shot 2022-05-18 at 14.01.09.png     Text File ecommerceError.log     PNG File image-2022-05-17-10-06-57-099.png     PNG File image-2022-05-25-16-41-45-703.png    
Issue Links:
relation
is related to ECOMMERCE-477 Display the json in text field of eco... 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: AuthorX Support
Sprint: AuthX 12
Story Points: 3
Team: AuthorX

 Description   

Steps to reproduce:

  1. Define a simple content app with a product field.
  2. Create 2 entries in the app
  3. Use the JCR app to simulate one entry with the old structure and one with the new product structure like this:

OLD: commercetools/magnolia-services-media-demo/bd43e83b-f0ca-46fd-9ebc-f5deae14b646

NEW: {"definitionName":"commercetools","connectionName":"magnolia-services-media-demo","categoryId":"4d7a73d2-f3bd-475b-9dbe-74888a265d69","productId":"87a4d184-3635-4edc-8ba5-022e7b197b5a"}

       4. Try to open both entries

Expected result:

It should be possible to open both nodes. If there is an old structure in JCR, I need to have the chance as an author to change the old data in the new structure.

Actual result:

The App is breaking completely with the attached error and the author is not able to change the old data or use this node at all.

 



 Comments   
Comment by Thuy To [ 17/May/22 ]

Hi tobias.kerschbaum ,

I think this is not a bug because you are using type ecommerceProductLinkField and try to put a value that its format is incorrect in JCR.

From ecommerce version 1.3, we have stored the value in JCR formatted by json like {"definitionName":"commercetools","connectionName":"magnolia-services-media-demo","categoryId":"4d7a73d2-f3bd-475b-9dbe-74888a265d69","productId":"87a4d184-3635-4edc-8ba5-022e7b197b5a"}

If you want to store a value in jCR like commercetools/magnolia-services-media-demo/bd43e83b-f0ca-46fd-9ebc-f5deae14b646. then you can use  $type: categoryChooserField which was introduced in v1.2.

 

Comment by Christopher Zimmermann [ 20/May/22 ]

Our existing customers and partners want to migrate to the new ecommerceProductLinkField for all of the improvements that it brings. And we want them to migrate to it as well.

When we change the product to use a new data format, then we should also provide a migration of the content to be compatible with the new UI.

 

Comment by Thuy To [ 25/May/22 ]

Workaround:

1/ Modify the dialog with ecommerceProductLinkField type which is introduced in v1.3

2/Modify both yaml and ftl in templates components

+ In the yaml file: Adding a model class like this

modelClass: info.magnolia.ecommerce.app.field.ecommercechooser.EcommerceChooserBeanModel

+ In the ftl file:

Replace:  

[#assign product = ecomfn.getProductById(content.product)]

To:

[#assign ecommerceChooserBean = model.getEcommerceChooserBean("productDetail")!]
[#if ecommerceChooserBean?has_content]
    [#assign product = ecomfn.getProductById(ecommerceChooserBean.definitionName, ecommerceChooserBean.connectionName, ecommerceChooserBean.productId)!]
    [#if product?has_content]
     .........
    [/#if]
[/#if]

3/ Using another key different from the old one stored in JCR to avoid throwing exception on browser.

Development notes:  We can handle to read the old structures in JCR for new product picker types to make sure the content is compatible with the new UI. In another case, maybe providing the scripts for data migration.

 

Comment by Dominik Maslanka [ 01/Jun/22 ]

Hi,  I received this migration script from tobias.kerschbaum 

import info.magnolia.context.MgnlContext
import javax.jcr.Session;
import javax.jcr.Node;
import javax.jcr.NodeIterator

// Variables
productsChanged = 0
workspaceToCheck = "inspirations"
propertyToCheck = "product"
productToSet = '{"definitionName":"commercetools","connectionName":"magnolia-services-media-demo","categoryId":"5cb82653-0d1f-4fe9-808b-09f3b537ece2","productId":"c90b4a16-4b4a-4c42-a775-1ca4a753db6c"}'

Session session = MgnlContext.getJCRSession(workspaceToCheck);
Node rootNode = session.getNode("/");

processNode(rootNode);

println "Save session"
session.save();
println "Processing completed " + productsChanged + " Products changed"

// Processing a node
def processNode(node) {

//Process the current node
if (node.hasProperty(propertyToCheck))

{ node.setProperty(propertyToCheck, productToSet) productsChanged++ }

//Check whether it has sub nodes
if (node.hasNodes()) {
NodeIterator nodes = node.getNodes()
while (nodes.hasNext())

{ def subnode = nodes.nextNode() processNode(subnode) }

}
}

"Old structure only has the product id and not the category id but the new structure needs both. So (to migrate) the only possibility was to hardcode set one product. So we still have to go through all inspirations but at least we are able to do it in the UI and not in JCR" 
 

Comment by Christopher Zimmermann [ 28/Jun/22 ]

thuy.to could you please describe the solution? Is it a migration... or is it some extended compatibility... or something else? ie.. what has been implemented in the scope of this ticket?

Comment by Thuy To [ 28/Jun/22 ]

Hi czimmermann  

We have handled in code to read the old structures in JCR for new product picker types to make sure the content is compatible with the new UI. So we don't need to use the scripts for migration.

Comment by Christopher Zimmermann [ 28/Jun/22 ]

Thank you.

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