AEM Workflow | Community
Skip to main content
April 23, 2022
Solved

AEM Workflow

  • April 23, 2022
  • 1 reply
  • 1121 views

I want to write a model for Dynamic Participant Steps in which I want to approved modified content by different region head.

For Example ; Their are three region India, UK and US (for Global Website). They have their individual Region Head.

If any changes made in site by UK region then it will be approved by UK region head.

How can I write Model for three different region?

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 DEBAL_DAS

We can achieve this using Context Aware configuration and ParticipantStepChooser interface.

 

As we need to read site specific regional head in that case Context Aware configuration is the ideal choice to define Regional Head.

 

Below is my Context Aware Configuration associated with Regional Head.

Let's assume say user id:debal[default value] is the head for Global site as shown below -

 

/**
 * 
 */
package com.aem.demo.core.configurations;

import org.apache.sling.caconfig.annotation.Configuration;
import org.apache.sling.caconfig.annotation.Property;

/**
 * @author debal
 *
 */
@Configuration(label = "Regional Head Configuration", description = "Regional Head Configuration")
public @interface RegionalHeadConfiguration {

	@Property(label = "Regional Head", description = "Regional Head")
	String reginalHead() default "debal";

}

Context aware configuration associated with Regional Head of Global site -

Context aware configuration associated with Regional Head of Canada site -

Context aware configuration associated with Regional Head of German site -

 

Here debal, debalcanada and debalgerman are three different AEM users, they are part of same user group as shown below -

 

Below you could see I have mapped the site specific context aware configuration with relevant site specific content path -

 

For global site -

 

For German -

 

 

For Canada -

 

Here is my sample Dynamic Participant Step -

package com.aem.demo.core.workflows;

import java.util.Objects;

import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.caconfig.ConfigurationBuilder;
import org.osgi.service.component.annotations.Component;

import com.adobe.granite.workflow.WorkflowException;
import com.adobe.granite.workflow.WorkflowSession;
import com.adobe.granite.workflow.exec.ParticipantStepChooser;
import com.adobe.granite.workflow.exec.WorkItem;
import com.adobe.granite.workflow.metadata.MetaDataMap;
import com.aem.demo.core.configurations.RegionalHeadConfiguration;

@Component(service = ParticipantStepChooser.class, immediate = true, property = {
		"chooser.label=" + "Regional Head Reviewer Step Selection" })
public class RegionalHeadDynamicParticipantStep implements ParticipantStepChooser {

	@Override
	public String getParticipant(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap metaDataMap)
			throws WorkflowException {
		String participant = "";
		String payloadPath = workItem.getWorkflowData().getPayload().toString();
		ResourceResolver resourceResolver = workflowSession.adaptTo(ResourceResolver.class);

		Resource resource = resourceResolver.getResource(payloadPath);
		if (Objects.nonNull(resource)) {

			ConfigurationBuilder configurationBuilder = resource.adaptTo(ConfigurationBuilder.class);
			if (Objects.nonNull(configurationBuilder)) {
				RegionalHeadConfiguration regionalHeadConfiguration = configurationBuilder
						.as(RegionalHeadConfiguration.class);
				String reginalHead = regionalHeadConfiguration.reginalHead();
				if (!reginalHead.isEmpty()) {

					participant = reginalHead;
				} else {
					participant = "admin";
				}

			}

		}
		return participant;
	}

}

I have focused only Dynamic Participant Step and this is my workflow model -

 

I have started the above workflow on UK , Canada and German pages respectively with admin access.

 

Now you could see only relevant regional head received workflow notification in their inbox -

 

 

 

Hope this will help you.

1 reply

DEBAL_DAS
DEBAL_DASAccepted solution
April 23, 2022

We can achieve this using Context Aware configuration and ParticipantStepChooser interface.

 

As we need to read site specific regional head in that case Context Aware configuration is the ideal choice to define Regional Head.

 

Below is my Context Aware Configuration associated with Regional Head.

Let's assume say user id:debal[default value] is the head for Global site as shown below -

 

/**
 * 
 */
package com.aem.demo.core.configurations;

import org.apache.sling.caconfig.annotation.Configuration;
import org.apache.sling.caconfig.annotation.Property;

/**
 * @author debal
 *
 */
@Configuration(label = "Regional Head Configuration", description = "Regional Head Configuration")
public @interface RegionalHeadConfiguration {

	@Property(label = "Regional Head", description = "Regional Head")
	String reginalHead() default "debal";

}

Context aware configuration associated with Regional Head of Global site -

Context aware configuration associated with Regional Head of Canada site -

Context aware configuration associated with Regional Head of German site -

 

Here debal, debalcanada and debalgerman are three different AEM users, they are part of same user group as shown below -

 

Below you could see I have mapped the site specific context aware configuration with relevant site specific content path -

 

For global site -

 

For German -

 

 

For Canada -

 

Here is my sample Dynamic Participant Step -

package com.aem.demo.core.workflows;

import java.util.Objects;

import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.caconfig.ConfigurationBuilder;
import org.osgi.service.component.annotations.Component;

import com.adobe.granite.workflow.WorkflowException;
import com.adobe.granite.workflow.WorkflowSession;
import com.adobe.granite.workflow.exec.ParticipantStepChooser;
import com.adobe.granite.workflow.exec.WorkItem;
import com.adobe.granite.workflow.metadata.MetaDataMap;
import com.aem.demo.core.configurations.RegionalHeadConfiguration;

@Component(service = ParticipantStepChooser.class, immediate = true, property = {
		"chooser.label=" + "Regional Head Reviewer Step Selection" })
public class RegionalHeadDynamicParticipantStep implements ParticipantStepChooser {

	@Override
	public String getParticipant(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap metaDataMap)
			throws WorkflowException {
		String participant = "";
		String payloadPath = workItem.getWorkflowData().getPayload().toString();
		ResourceResolver resourceResolver = workflowSession.adaptTo(ResourceResolver.class);

		Resource resource = resourceResolver.getResource(payloadPath);
		if (Objects.nonNull(resource)) {

			ConfigurationBuilder configurationBuilder = resource.adaptTo(ConfigurationBuilder.class);
			if (Objects.nonNull(configurationBuilder)) {
				RegionalHeadConfiguration regionalHeadConfiguration = configurationBuilder
						.as(RegionalHeadConfiguration.class);
				String reginalHead = regionalHeadConfiguration.reginalHead();
				if (!reginalHead.isEmpty()) {

					participant = reginalHead;
				} else {
					participant = "admin";
				}

			}

		}
		return participant;
	}

}

I have focused only Dynamic Participant Step and this is my workflow model -

 

I have started the above workflow on UK , Canada and German pages respectively with admin access.

 

Now you could see only relevant regional head received workflow notification in their inbox -

 

 

 

Hope this will help you.