Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

Adapt WorkflowSession to a ResourceResolver

demd43642519
Level 4
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
Peter_Puzanovs
Correct answer by
Community Advisor
Community Advisor

Dear Demd,

workflowSession.adaptTo(ResourceResolver.class);

Regards,

Peter

View solution in original post

0 Replies
Peter_Puzanovs
Correct answer by
Community Advisor
Community Advisor

Dear Demd,

workflowSession.adaptTo(ResourceResolver.class);

Regards,

Peter

View solution in original post

demd43642519
Level 4
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);

Peter_Puzanovs
Community Advisor
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

demd43642519
Level 4
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 ?

demd43642519
Level 4
Level 4

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

smacdonald2008
Level 10
Level 10

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

Ratna_Kumar
Community Advisor
Community Advisor

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.

demd43642519
Level 4
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. 

Peter_Puzanovs
Community Advisor
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