Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Metadata Extraction

Avatar

Level 2

Hi All,

I wanted to set property of a metadata node in /content/dam/emailWorkflow64/asset.jpg/jcr:content/metadata (for example) using workflow. I have made a custom workflow process step and executed it manually inside a workflow model. Its not working please help.

I have given payload for workflow model : /content/dam/emailWorkflow64/asset.jpg/jcr:content/metadata

Here is code snippet :

import javax.jcr.Node;

import javax.jcr.PathNotFoundException;

import javax.jcr.RepositoryException;

import javax.jcr.Session;

import org.apache.sling.api.resource.ResourceResolverFactory;

import org.osgi.service.component.annotations.Component;

import org.osgi.service.component.annotations.Reference;

import org.slf4j.Logger;

import org.slf4j.LoggerFactory;

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.WorkflowData;

import com.day.cq.workflow.exec.WorkflowProcess;

import com.day.cq.workflow.metadata.MetaDataMap;

@Component(name="Metadata Extraction", service=WorkflowProcess.class,immediate=true,

  property= {

  "process.label=Metadata Extraction",

  "Constants.SERVICE_DESCRIPTION=Service for extracting metadata",

  "Constants.SERVICE_VENDORS=Rishabh_Inc"

  })

public class MetadataExtraction implements WorkflowProcess

{

  private  static final Logger log=LoggerFactory.getLogger(MetadataExtraction.class );

  @Reference

  private ResourceResolverFactory resourceResolverFactory;

  @Override

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

  {

       log.info("inside execute method");

       Node metadata=null;

       Session session=null;

       String filepath="";

       String payloadPath="";

       try {

            session=workFlowSession.getSession();

            WorkflowData workflowData=workItem.getWorkflowData();

            if(session!=null)

                 {

                 payloadPath=workflowData.getPayload().toString();

                 log.info("payload is:"+payloadPath);

                 metadata=session.getNode(payloadPath);

                 metadata.setProperty("name", "Upload1");

                 session.save();

                 }

            }

       catch (PathNotFoundException e)

          {

            log.info("caught path not found exception");

            e.printStackTrace();

           }

       catch (RepositoryException e)

          {

            log.info("caught in repository exception");

            e.printStackTrace();

            }

  }

}

I am using AEM v6.3.

Thanks in advance.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi,

did you checked the 'handler advance' option in the process step?

Screenshot 2019-04-11 at 10.27.07 PM.png



Arun Patidar

View solution in original post

5 Replies

Avatar

Community Advisor

Hi,

Your code looks ok.

What error are you getting? could you please share logs.



Arun Patidar

Avatar

Level 2

Workflow is not terminating and even I have setup a customised log file, there is nothing getting logged.

Avatar

Correct answer by
Community Advisor

Hi,

did you checked the 'handler advance' option in the process step?

Screenshot 2019-04-11 at 10.27.07 PM.png



Arun Patidar

Avatar

Level 2

Thanks man it works.

Can you tell me why checking Handler Advance is important ?

Avatar

Community Advisor

The handler advance option when true (checked), will advance the workflow to the next step after the current process is done with its execution.

In case the handler advance option is false (unchecked), the process script has to take care of advancing the workflow to the next step. In case the script doesn't handle this, the workflow would remain in the running state without proceeding further from the current step.



Arun Patidar