Hi,
I have a process step in a workflow that launches when a content fragment is created. It calls a custom process with the following code:
public void execute(WorkItem item, WorkflowSession session, MetaDataMap args) throws WorkflowException {
try {
Map<String, Object> serviceParams = new HashMap<String, Object>();
serviceParams.put(ResourceResolverFactory.SUBSERVICE, "test");
ResourceResolver resourceResolver;
resourceResolver = resolverFactory.getServiceResourceResolver(serviceParams);
Node node = resourceResolver.getResource(item.getContentPath()).adaptTo(Node.class);
Node tempNode = node.getNode("/jcr:content");
tempNode.setProperty("activated", "false");
but the setProperty is not adding the property to the jcr:content as expected. Is there something I am missing or doing wrong?
Solved! Go to Solution.
Hi,
First of all, why do you create a new session to perform this operation? Is there anything special, that you need to execute this as a special user?
You could use something like
Session mySession = workflowSession.getSession();
to get the session the workflow is using itself. Then you don't need to take care of the livecycle of the resourceResolver/JCR session at all. In you example you'll have a session leak, which will eventually lead to an OutOfMemory situation.
Then it's not enough just to set the property, you need to save the session as well.
session.save();
Jörg
Looks like you are using a system user for this task.
When you created a system users - make sure you did the following:
1. Provide permissions so this user can access the applicable location in the JCR.
2. You have correctly Mapped the System user using Felix console.
See this article as a reference -- Scott's Digital Community: Querying Adobe Experience Manager 6 data using the Sling getServiceResour...
There is a video too you can watch that shows you all steps.
.
Views
Replies
Total Likes
Hi,
First of all, why do you create a new session to perform this operation? Is there anything special, that you need to execute this as a special user?
You could use something like
Session mySession = workflowSession.getSession();
to get the session the workflow is using itself. Then you don't need to take care of the livecycle of the resourceResolver/JCR session at all. In you example you'll have a session leak, which will eventually lead to an OutOfMemory situation.
Then it's not enough just to set the property, you need to save the session as well.
session.save();
Jörg
Joerg makes a great point. When working with AEM JCR sessions - always close them:
// Save the session changes and log out
session.save();
session.logout();
Views
Replies
Total Likes
Jörg,
Thank you, changed my code to the following:
Session session = workflowSession.adaptTo(Session.class);
Node node = session.getNode(item.getContentPath()+"/jcr:content");
node.setProperty("activated", "false");
session.save();
session.logout();
Views
Replies
Total Likes
Remove the "session.logout();" statement, as it will cause problems in the workflow.
Here you violate the 1st rule of session handling: "You open the session, you close the session! If you don't open the session, don't close the session".
Jörg
Views
Replies
Total Likes
Thanks @joerg
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies