I am trying to retrieve the data from node and update as well.
This is the code that I am trying to run
try {
//Create a connection to the CQ repository running on local host
Repository repository = JcrUtils.getRepository("http://localhost:4502/crx/de/index.jsp#/content/launches/2021/09/16/Tool");
//Create a Session
javax.jcr.Session session = repository.login( new SimpleCredentials("admin", "admin".toCharArray()));
//Create a node that represents the root node
Node root = session.getRootNode();
// Retrieve content
Node node = root.getNode("jcr:content/sources/source_0");
LOG.info(node.getProperty("sourceRootResource").getString()+"This is sourceRootPath");
node.setProperty("sourceRootResource", "/content//websites/en_us/pyramid");
LOG.info("Property SET");
// Save the session changes and log out
session.save();
session.logout();
}
catch(Exception e){
LOG.error("Cant update node", e);
}
This is popping error.
The following RepositoryFactory classes were consulted:
Perhaps the repository you are trying to access is not available at the moment.
Solved! Go to Solution.
Views
Replies
Total Likes
@Ronnie09 - Use Service Resource resolver to get access to the AEM internal resources, and then update the node properties.
You can create a system user with appropriate permissions to the /content/launches/* path and use this to configure service for fetching the service resource resolver.
Some useful links for fetching service resource resolver -
https://aem4beginner.blogspot.com/how-to-get-resourceresolver-from
http://www.aemcq5tutorials.com/tutorials/resourceresolver-from-resourceresolverfactory/
Once you have the resource resolver object, you can refer to the following sample code:
// Fetch the node
Resource resource = resourceResolver.getResource("/content/launches/2021/09/16/Tool/jcr:content/sources/source_0");
Node node = resource.adaptTo(Node.class);
// Update the node
node.setProperty("sourceRootResource", "/content//websites/en_us/pyramid");
// Save the session
Session session = resourceResolver.adaptTo(Session.class);
session.save();
Thanks,
Fani
@Ronnie09 - Use Service Resource resolver to get access to the AEM internal resources, and then update the node properties.
You can create a system user with appropriate permissions to the /content/launches/* path and use this to configure service for fetching the service resource resolver.
Some useful links for fetching service resource resolver -
https://aem4beginner.blogspot.com/how-to-get-resourceresolver-from
http://www.aemcq5tutorials.com/tutorials/resourceresolver-from-resourceresolverfactory/
Once you have the resource resolver object, you can refer to the following sample code:
// Fetch the node
Resource resource = resourceResolver.getResource("/content/launches/2021/09/16/Tool/jcr:content/sources/source_0");
Node node = resource.adaptTo(Node.class);
// Update the node
node.setProperty("sourceRootResource", "/content//websites/en_us/pyramid");
// Save the session
Session session = resourceResolver.adaptTo(Session.class);
session.save();
Thanks,
Fani
Views
Likes
Replies