Ir al contenido principal

Create a custom AEM workflow process step with a dialog

In this tutorial I talk about how to create a custom workflow step process with an additional dialog for configuring it, above is the vid and below you will find some useful notes.
  1. 1.

    Pre-reqs

  2. 2.

    What is an AEM Workflow and workflow model

    • Workflows allow you to automate different tasks inside AEM by defining a sequence of steps to be executed and the actions to be performed at each step.
    • A workflow model represents the definition of a workflow using nodes for the steps or actions to be executed and transitions to define how the steps are organized and what is going to be the execution sequence
  3. 3.

    Creating the base app with the custom workflow step

    • Create the app using adobe's archetype
      mvn org.apache.maven.plugins:maven-archetype-plugin:2.4:generate "-DarchetypeGroupId=com.adobe.granite.archetypes" "-DarchetypeArtifactId=aem-project-archetype" "-DarchetypeVersion=20" "-DarchetypeCatalog=https://repo.adobe.com/nexus/content/groups/public/" "-DgroupId=co.dlighthouse.aem.workflowstepdialog" "-DartifactId=aem-workflow-step-dialog" "-Dversion=0.1.0-SNAPSHOT" "-Dpackage=co.dlighthouse.aem.workflowstepdialog" "-DappsFolderName=workflow-step-dialog" "-DconfFolderName=workflow-step-dialog" "-DartifactName=Workflow Step Dialog" "-DcomponentGroupName=Workflow Step Dialog" "-DcontentFolderName=workflow-step-dialog" "-DcssId=workflow-step-dialog" "-DpackageGroup=workflow-step-dialog" "-DsiteName=Workflow Step Dialog" “-DoptionIncludeExamples=n” “-DoptionIncludeFrontendModule=n” “-DoptionAemVersion=6.5.0”
      
    • Use the yeoman generator and create the custom workflow step, you can also check the code on github or do it by hand.
      npm install -g yo
      npm install -g generator-aem-application
      cd aem-workflow-step-dialog
      yo aem-application:workflow workflowName="Sample Application - Sample Workflow Process Step" componentParentPath=workflow-step-dialog/components/workflow componentNodeName=workflow-process javaRootPackageName=co.dlighthouse.aem.workflowstepdialog.core javaWorkflowClassName=SampleWorkflowProcess
      
    • For the dialog for the custom workflow step component we need the following:
      Component node (.content.xml)
      <?xml version="1.0" encoding="UTF-8"?>
      <jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
          jcr:primaryType="cq:Component"
          jcr:title="Sample Application - Sample Workflow Process Step"
          sling:resourceSuperType="cq/workflow/components/model/process"
          allowedParents="[*/parsys]"
          componentGroup="Workflow"/>
      
      cq:EditConfig node (_cq_editConfig.xml)
      <?xml version="1.0" encoding="UTF-8"?>
      <jcr:root xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
          cq:dialogMode="floating"
          cq:inherit="{Boolean}true"
          jcr:primaryType="cq:EditConfig">
          <cq:formParameters
              jcr:primaryType="nt:unstructured"
              jcr:title="Sample Application - Sample Workflow Process Step"
              PROCESS="co.dlighthouse.aem.workflowstepdialog.core.workflows.SampleWorkflowProcess"
              PROCESS_AUTO_ADVANCE="true"/>
      </jcr:root>
      
      Touch UI dialog cq:dialog node (_cq_dialog/.content.xml)
      <?xml version="1.0" encoding="UTF-8"?>
      <jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
          jcr:primaryType="nt:unstructured"
          jcr:title="Sample Application - Sample Workflow Process Step Properties"
          sling:resourceType="cq/gui/components/authoring/dialog">
          <content
              jcr:primaryType="nt:unstructured"
              sling:resourceType="granite/ui/components/coral/foundation/fixedcolumns">
              <items jcr:primaryType="nt:unstructured">
                  <common
                      jcr:primaryType="nt:unstructured"
                      cq:hideOnEdit="true"/>
                  <process
                      jcr:primaryType="nt:unstructured"
                      cq:hideOnEdit="true"/>
                  <column
                      jcr:primaryType="nt:unstructured"
                      sling:resourceType="granite/ui/components/coral/foundation/container">
                      <items jcr:primaryType="nt:unstructured">
                          <text
                              jcr:primaryType="nt:unstructured"
                              sling:resourceType="granite/ui/components/coral/foundation/form/textfield"
                              fieldLabel="Something Important"
                              name="./metaData/somethingImportant"/>
                      </items>
                  </column>
              </items>
          </content>
      </jcr:root>
      
    • We need the class that implements WorkflowProcess and overrides the execute method.
      package co.dlighthouse.aem.workflowstepdialog.core.workflows;
      
      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.WorkflowData;
      import com.adobe.granite.workflow.exec.WorkflowProcess;
      import com.adobe.granite.workflow.metadata.MetaDataMap;
      import org.apache.commons.lang3.StringUtils;
      import org.osgi.service.component.annotations.Component;
      import org.slf4j.Logger;
      import org.slf4j.LoggerFactory;
      
      @Component(
          service=WorkflowProcess.class,
          property = {"process.label=Sample Application - Sample Workflow Process Step"}
      )
      public class SampleWorkflowProcess implements WorkflowProcess {
          private static final Logger log = LoggerFactory.getLogger(SampleWorkflowProcess.class);
      
          @Override
          public void execute(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap args) throws WorkflowException {
      
              final WorkflowData workflowData = workItem.getWorkflowData();
              final String type = workflowData.getPayloadType();
      
              // Check if the payload is a path in the JCR; The other (less common) type is JCR_UUID
              if (!StringUtils.equals(type, "JCR_PATH")) {
                  return;
              }
              // Get the path to the JCR resource from the payload
              final String path = workflowData.getPayload().toString();
      
              String somethingImportant = args.get("somethingImportant", "not set");
      
              log.info("Sample Application - Sample Workflow Process Step - somethingImportant: {} - payload: {}", somethingImportant, path);
          }
      }
      
    • Finally build and deploy your new app into AEM
      mvn clean install -PautoInstallPackage -Padobe-public
      
  4. 4.

Comentarios

Entradas populares de este blog

Exposing Reactjs component methods to Javascript or non-reactjs applications

blog-static-generator-new If you want to integrate your javascript or non-reactjs application with a reactjs app and be able to access reactjs components and call their methods to execute actions or get information out of them, in this quick tips episode, you will learn how. Above is the vid and below you will find some useful notes. 1. Pre-reqs Have node.js installed 2. Exposing React JS to Javascript or non-reactjs applications ...

How to copy files from and to a running Docker container

Sometimes you want to copy files to or from a container that doesn’t have a volume previously created, in this quick tips episode, you will learn how. Above is the vid and below you will find some useful notes. 1. Pre-reqs Have Docker installed 2. Start a Docker container For this video I will be using a Jenkins image as an example, so let’s first download it by using docker pull docker pull jenkins/jenkins:lts ...

Brighten Up Your AEM Assets: How to Configure Default Backgrounds and Transparent Modes in Adobe Dynamic Media

Introduction The Importance of a Good Background Defining Your Default Background in AEM Defining Your Default Background in Dynamic Media Classic Transparent Images with fmt=png-alpha Explicit Background Colors with ?bgc Final Thoughts Introduction Welcome to our deep dive into the wonderful world of image backgrounds! In this post, we're going to explore how to configure Dynamic Media Classic in Adobe Experience Manager (AEM) to not only define a default background image but also how to get your images to pop with ...