Metadata Extraction

Avatar

Avatar

rishabhkrishan

Avatar

rishabhkrishan

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.

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar

Arun_Patidar

MVP

Total Posts

2.9K

Likes

999

Correct Answer

829

Avatar

Arun_Patidar

MVP

Total Posts

2.9K

Likes

999

Correct Answer

829
Arun_Patidar
MVP

11-04-2019

Hi,

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

Screenshot 2019-04-11 at 10.27.07 PM.png

Answers (4)

Answers (4)

Avatar

Avatar

Arun_Patidar

MVP

Total Posts

2.9K

Likes

999

Correct Answer

829

Avatar

Arun_Patidar

MVP

Total Posts

2.9K

Likes

999

Correct Answer

829
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.

Avatar

Avatar

rishabhkrishan

Avatar

rishabhkrishan

rishabhkrishan

12-04-2019

Thanks man it works.

Can you tell me why checking Handler Advance is important ?

Avatar

Avatar

rishabhkrishan

Avatar

rishabhkrishan

rishabhkrishan

11-04-2019

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

Avatar

Avatar

Arun_Patidar

MVP

Total Posts

2.9K

Likes

999

Correct Answer

829

Avatar

Arun_Patidar

MVP

Total Posts

2.9K

Likes

999

Correct Answer

829
Arun_Patidar
MVP

10-04-2019

Hi,

Your code looks ok.

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