Metadata Extraction | Community
Skip to main content
Level 2
Apr 10, 2019 10:30 AM UTC
Solved

Metadata Extraction

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.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
arunpatidar
arunpatidarAccepted solution
New Participant
Apr 11, 2019 8:28 PM UTC

Hi,

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

Arun Patidar

5 replies

arunpatidar
New Participant
Apr 12, 2019 11:23 AM UTC

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.

Translate
Arun Patidar
RishabhKrAuthor
Level 2
Apr 12, 2019 10:36 AM UTC

Thanks man it works.

Can you tell me why checking Handler Advance is important ?

Translate
arunpatidar
arunpatidarAccepted solution
New Participant
Apr 11, 2019 8:28 PM UTC

Hi,

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

Translate
Arun Patidar
RishabhKrAuthor
Level 2
Apr 11, 2019 10:06 AM UTC

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

Translate
arunpatidar
New Participant
Apr 10, 2019 9:59 PM UTC

Hi,

Your code looks ok.

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

Translate
Arun Patidar