Expand my Community achievements bar.

SOLVED

AEM Workflow

Avatar

Level 1

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?

1 Accepted Solution

Avatar

Correct answer by
Employee Advisor

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 -

DEBAL_DAS_0-1650717451410.png

Context aware configuration associated with Regional Head of Canada site -

DEBAL_DAS_1-1650717539558.png

Context aware configuration associated with Regional Head of German site -

DEBAL_DAS_2-1650717635202.png

 

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

DEBAL_DAS_3-1650717694152.png

DEBAL_DAS_11-1650718517018.png

 

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

 

For global site -

DEBAL_DAS_4-1650717870802.png

 

For German -

DEBAL_DAS_6-1650718025141.png

 

 

For Canada -

DEBAL_DAS_5-1650717955756.png

 

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 -

DEBAL_DAS_7-1650718151626.png

 

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 -

DEBAL_DAS_8-1650718293200.png

 

DEBAL_DAS_9-1650718320487.png

 

DEBAL_DAS_10-1650718350102.png

 

Hope this will help you.

View solution in original post

1 Reply

Avatar

Correct answer by
Employee Advisor

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 -

DEBAL_DAS_0-1650717451410.png

Context aware configuration associated with Regional Head of Canada site -

DEBAL_DAS_1-1650717539558.png

Context aware configuration associated with Regional Head of German site -

DEBAL_DAS_2-1650717635202.png

 

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

DEBAL_DAS_3-1650717694152.png

DEBAL_DAS_11-1650718517018.png

 

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

 

For global site -

DEBAL_DAS_4-1650717870802.png

 

For German -

DEBAL_DAS_6-1650718025141.png

 

 

For Canada -

DEBAL_DAS_5-1650717955756.png

 

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 -

DEBAL_DAS_7-1650718151626.png

 

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 -

DEBAL_DAS_8-1650718293200.png

 

DEBAL_DAS_9-1650718320487.png

 

DEBAL_DAS_10-1650718350102.png

 

Hope this will help you.