Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

content node property updates

Avatar

Level 1

Hi,

 

I have a Content Fragment Model and content fragments created with content fragment model.

Now the team wants to move Content Fragment Model from "/conf/projectA/CustomModels/settings/CF-model" to "/conf/projectA/settings/CF-model".

 

Use case: Existing content fragments referencing "/conf/projectA/CustomModels/settings/CF-model" at /content/dam/cf1/data/@cq:model, /content/dam/cf1/idexedData/master/@string@model properties.

 

What is the best way to update above property values to point to new Content Fragment Model Path "/conf/projectA/settings/CF-model".

 

I appreciate all the help.

AEM 6.5.17 is version.

 

Thanks,

Sri

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @SreenivasuluPu 

1. Create a backup: Before making any changes, it's always a good practice to create a backup of your content in case anything goes wrong during the update process.

2. Update the Content Fragment Model path: Move the Content Fragment Model from "/conf/projectA/CustomModels/settings/CF-model" to "/conf/projectA/settings/CF-model". You can do this by using the AEM Web Console or the CRXDE Lite.

3. Update the property values: To update the property values of the existing content fragments, you can use the AEM Query Builder or a custom script. Here's an example of how you can use the AEM Query Builder to update the property values:

- Open the AEM Query Builder console (`/libs/cq/search/content/querydebug.html`).
- Enter the following query in the "Query" field:
path:/content/dam/cf1
Replace `/content/dam/cf1` with the actual path of your content fragments.
- Click on the "Execute Query" button to execute the query.
- Select the content fragments that need to be updated.
- Click on the "Edit Properties" button.
- Update the property values to point to the new Content Fragment Model path ("/conf/projectA/settings/CF-model").
- Save the changes.

4. Verify the updates: After updating the property values, verify that the content fragments now reference the new Content Fragment Model path ("/conf/projectA/settings/CF-model").
https://experienceleague.adobe.com/en/docs/experience-manager-guides/using/user-guide/output-gen/pub... 
https://experienceleague.adobe.com/en/docs/experience-manager-65/content/assets/content-fragments/co... 

 



View solution in original post

2 Replies

Avatar

Correct answer by
Community Advisor

Hi @SreenivasuluPu 

1. Create a backup: Before making any changes, it's always a good practice to create a backup of your content in case anything goes wrong during the update process.

2. Update the Content Fragment Model path: Move the Content Fragment Model from "/conf/projectA/CustomModels/settings/CF-model" to "/conf/projectA/settings/CF-model". You can do this by using the AEM Web Console or the CRXDE Lite.

3. Update the property values: To update the property values of the existing content fragments, you can use the AEM Query Builder or a custom script. Here's an example of how you can use the AEM Query Builder to update the property values:

- Open the AEM Query Builder console (`/libs/cq/search/content/querydebug.html`).
- Enter the following query in the "Query" field:
path:/content/dam/cf1
Replace `/content/dam/cf1` with the actual path of your content fragments.
- Click on the "Execute Query" button to execute the query.
- Select the content fragments that need to be updated.
- Click on the "Edit Properties" button.
- Update the property values to point to the new Content Fragment Model path ("/conf/projectA/settings/CF-model").
- Save the changes.

4. Verify the updates: After updating the property values, verify that the content fragments now reference the new Content Fragment Model path ("/conf/projectA/settings/CF-model").
https://experienceleague.adobe.com/en/docs/experience-manager-guides/using/user-guide/output-gen/pub... 
https://experienceleague.adobe.com/en/docs/experience-manager-65/content/assets/content-fragments/co... 

 



Avatar

Community Advisor

Hi @SreenivasuluPu ,

To update the property values referencing the old Content Fragment Model path to the new path in Adobe Experience Manager (AEM) 6.5.17 using Java code, you can follow these steps:

  1. Backup Content: Before making any changes, it's essential to create a backup of your content to avoid accidental data loss.

  2. Iterate Over Content Fragments: Write a Java code to iterate over the content fragments and update the properties referencing the old Content Fragment Model path to the new path.

  3. Update Properties: For each content fragment, check if the properties cq:model and model exist and if they contain the old path. If so, update them with the new path.

  4. Save Changes: After updating the properties, save the changes to the JCR repository.

Here's a sample Java code snippet to achieve this:

 

import javax.jcr.Node;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.NodeIterator;

import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceResolverFactory;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;

@Component(service = YourService.class)
public class YourService {

    @Reference
    private ResourceResolverFactory resolverFactory;

    public void updateContentFragmentModels() {
        // Define the old and new paths
        String oldModelPath = "/conf/projectA/CustomModels/settings/CF-model";
        String newModelPath = "/conf/projectA/settings/CF-model";

        try (ResourceResolver resolver = resolverFactory.getServiceResourceResolver(null)) {
            Session session = resolver.adaptTo(Session.class);
            if (session != null) {
                // Start the traversal from the root node where content fragments are stored
                Node rootNode = session.getNode("/content/dam");

                // Traverse content fragments
                traverseAndUpdate(rootNode, oldModelPath, newModelPath);

                // Save the changes
                session.save();
            }
        } catch (RepositoryException e) {
            // Handle exception
        }
    }

    private void traverseAndUpdate(Node node, String oldModelPath, String newModelPath) throws RepositoryException {
        if (node.hasProperty("cq:model")) {
            String modelPath = node.getProperty("cq:model").getString();
            if (modelPath.equals(oldModelPath)) {
                // Update the property value
                node.setProperty("cq:model", newModelPath);
            }
        }

        if (node.hasProperty("model")) {
            String modelPath = node.getProperty("model").getString();
            if (modelPath.equals(oldModelPath)) {
                // Update the property value
                node.setProperty("model", newModelPath);
            }
        }

        // Recursively process child nodes
        NodeIterator iterator = node.getNodes();
        while (iterator.hasNext()) {
            Node childNode = iterator.nextNode();
            traverseAndUpdate(childNode, oldModelPath, newModelPath);
        }
    }
}

 

This code assumes you have an OSGi service to execute the updates. Adjust the paths and error handling as needed for your specific requirements and environment.

 

Reference:

https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/how-to-update-a-lot-of-nod...

https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/how-to-add-update-properti...