Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Workflows in AEM 04 - MetaDataMap | AEM Community Blog Seeding

Avatar

Administrator

BlogImage.jpg

Workflows in AEM 04 - MetaDataMap by

Abstract

Sometimes we are faced with a situation where we need to pass data from one workflow step to the another. AEM's workflow API provides an easy way to achieve this using MetaDataMap.

Please note that only primitive data types like Integer, String etc. can be passed from one step to the another. If you have a requirement to pass non-primitive data then use the byte[] array.

Caution: If the data to be passed is too large, refrain passing InputStream. Instead, a better approach is to save the data in a JCR node in the step and retrieve it from the JCR node in a later step.

A MetaDataMap is the data structure which acts as a value map and allows users to set and get data among the steps.
Code example
Let's see a code example to demonstrate this concept. Here we will be using two process steps. In the first, we will be passing data and in the second, we will be retrieving it.
FirstProcessStep.java
package org.redquark.demo.core.workflows;

import org.osgi.service.component.annotations.Component;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.adobe.granite.workflow.WorkflowException;
import com.adobe.granite.workflow.WorkflowSession;
import com.adobe.granite.workflow.exec.WorkItem;
import com.adobe.granite.workflow.exec.WorkflowProcess;
import com.adobe.granite.workflow.metadata.MetaDataMap;

/**
* @author Anirudh Sharma
*/
@Component(service = WorkflowProcess.class, property = { "process.label=" + "First Process Step" })
public class FirstProcessStep implements WorkflowProcess {

private final Logger log = LoggerFactory.getLogger(this.getClass());

@Override
public void execute(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap metaDataMap)
throws WorkflowException {

log.info("Executing first workflow process step");

// Getting the metadata map
MetaDataMap map = workItem.getWorkflow().getWorkflowData().getMetaDataMap();

// Putting some values in the map
map.put("Data", "Data from the first step");
}

}

Read Full Blog

Workflows in AEM 04 - MetaDataMap

Q&A

Please use this thread to ask the related questions.

0 Replies