Adapt WorkflowSession to a ResourceResolver | Community
Skip to main content
New Participant
May 31, 2018
Solved

Adapt WorkflowSession to a ResourceResolver

  • May 31, 2018
  • 9 replies
  • 7325 views

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.

Best answer by Peter_Puzanovs

Dear Demd,

workflowSession.adaptTo(ResourceResolver.class);

Regards,

Peter

9 replies

Peter_Puzanovs
New Participant
June 4, 2018

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

New Participant
June 4, 2018

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. 

Ratna_Kumar
New Participant
May 31, 2018

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.

smacdonald2008
New Participant
May 31, 2018

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

New Participant
May 31, 2018

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

New Participant
May 31, 2018

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 ?

Peter_Puzanovs
New Participant
May 31, 2018

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

New Participant
May 31, 2018

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);

New Participant
February 8, 2024

@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.

Peter_Puzanovs
Peter_PuzanovsAccepted solution
New Participant
May 31, 2018

Dear Demd,

workflowSession.adaptTo(ResourceResolver.class);

Regards,

Peter