Metadata Extraction

rishabhkrishan

10-04-2019

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.

Answers (4)

Answers (4)

Arun_Patidar

MVP

12-04-2019

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.