Metadata Extraction | Community
Skip to main content
Level 2
April 10, 2019
Solved

Metadata Extraction

  • April 10, 2019
  • 5 replies
  • 2938 views

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.
Best answer by arunpatidar

Hi,

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

5 replies

arunpatidar
Community Advisor
Community Advisor
April 10, 2019

Hi,

Your code looks ok.

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

Arun Patidar
RishabhKrAuthor
Level 2
April 11, 2019

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

arunpatidar
Community Advisor
arunpatidarCommunity AdvisorAccepted solution
Community Advisor
April 11, 2019

Hi,

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

Arun Patidar
RishabhKrAuthor
Level 2
April 12, 2019

Thanks man it works.

Can you tell me why checking Handler Advance is important ?

arunpatidar
Community Advisor
Community Advisor
April 12, 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.

Arun Patidar