Expand my Community achievements bar.

SOLVED

Adapt WorkflowSession to a ResourceResolver

Avatar

Level 4

Hi guys !

How can I adapt my WorkflowSession to a ResourceResolver ?
I found this searching on google:

@Reference

ResourceResolverFactory resourceResolverFactory;

public void execute (WorkItem workItem, WorkflowSession workflowSession, MetaDataMap metaDataMap) throws WorkflowException {

Resource resolver = null;

     try{

               resolver =resourceResolverFactory.getResourceResolver(Collections.singletonMap("user.jcr.session",

                            (Object) session.getSession()));

} catch (final Exception e) {

            throw new WorkflowException("could not get resource resolver", e);

        }

But then I want to pass it as a parameter and call method getResourceResolver over it and I can't.

Hmm, what is wrong here ?

I'm using AEM 6.2, thanks.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Dear Demd,

workflowSession.adaptTo(ResourceResolver.class);

Regards,

Peter

View solution in original post

10 Replies

Avatar

Correct answer by
Community Advisor

Dear Demd,

workflowSession.adaptTo(ResourceResolver.class);

Regards,

Peter

Avatar

Level 4

Hi,

Thanks for you answer but it doesn’t seem to work that way. I get:

cannot resolve method ‘adaptTo(java.lang.Class<org.apache.sling.api.resource.ResourceResolver

when I'm using this:

ResourceResolver resourceResolver = workflowSession.adaptTo(ResourceResolver.class);

@demd43642519 @

 

I have faced the similar issue cannot resolve to adaptTo when  I am trying to adapt workflowsession to resourceResolver. 

 

Later I realised that I have imported wrong packages.

I have imported 

import com.day.cq.workflow.WorkflowException;
import com.day.cq.workflow.WorkflowSession;
import com.day.cq.workflow.exec.WorkItem;
import com.day.cq.workflow.exec.WorkflowProcess;
import com.day.cq.workflow.metadata.MetaDataMap;

 

This issue has been fixed after importing the following packages.

 

import com.adobe.granite.workflow.WorkflowException;
import com.adobe.granite.workflow.WorkflowSession;
import com.adobe.granite.workflow.exec.WorkItem;
import com.adobe.granite.workflow.exec.WorkflowProcess;
import com.adobe.granite.workflow.metadata.MetaDataMap; 

 

Hope this will resolve your issue.

Avatar

Community Advisor

Should work... in AEM Docs for 6.2 WorkflowSession interface implements adaptable interface[1]

[1] WorkflowSession ("The Adobe AEM Quickstart and Web Application.")

Check your imports(e.g. make sure you actually imported this interface correctly) and make sure you adapt from WorkflowSession.

Regards,

Peter

Avatar

Level 4

So I guess my problem has to do with the packages I'm using.

For this project I'm using com.day.cq.workflow while for the adaptTo method I need the com.adobe.granite.workflow.

There is any way to workaround this ?

Avatar

Level 4

I mean, there are any other ways to adapt the WorkflowSession to ResourceResolver ?

Avatar

Level 10

You should be using latest Workflow APIS and UBER 6.2 when building the bundle,

Avatar

Level 10

Yes Scott is right.

Make sure to use latest workflow API's with UBER 6.2 Jar if you use AEM 6.2. Use latest workflow API i.e., com.adobe.granite.workflow then com.day.cq.workflow.

Hope this helps!

Thanks,

Ratna Kumar.

Avatar

Level 4

Hi again !

I can't seem to figure it out. I'm want an workflow that send an email using a custom template.

My only problem is that I can't seem to figure it out how to pass my SlingHttpServletRequest request to my custom Workflow Step.

For that i thought i have to adapt the WorkflowSession to a ResourceResolver. Is that right ?
Thanks. 

Avatar

Community Advisor

Dear Dem,

Have a look at acs webpage that discusses how to send email's and provides utility methods[1] also have a look at implementation code for your reference[2], also find following information on how to configure email system in AEM[3].

[1] Email API

[2] acs-aem-commons/EmailServiceImpl.java at master · Adobe-Consulting-Services/acs-aem-commons · GitHub  

[3] Configuring Email

Regards,

Peter