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

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

How to create an AEM component using Reactjs

In this tutorial, I will show how to use use Adobe's archetype to create an AEM application with React.js support and also how to add a new React.js component so that it can be added into a page, above is the vid and below you will find some useful notes. In the second part we will see how to configure the Sling Model for the AEM React component. 1. Pre-reqs Have access to an Adobe Experience Manager instance. You will need aem 6.4 Service Pack 2 or newer. Have Maven installed, understand how it works and also understand how to use Adobe's archetype, you can watch my video about maven here: Creating an AEM application using Maven and Adobe's archetype 2.

House price prediction 3/4: What is One Hot Encoding

A series about creating a model using Python and Tensorflow and then importing the model and making predictions using Javascript in a Vue.js application, above is the vid and below you will find some useful notes. Here, in part 3 of this series, I will show what is and how does one hot encoding works. In the first post, called House price prediction 1/4: Using Keras/Tensorflow and python , I talked about how to create a model in python, pre-process a dataset I've already created, train a model, post-process, predict, and finally about creating different files for sharing some information about the data for use on the second part. Then in part 2, called House price prediction 2/4: Using Tensorflow.js, Vue.js and Javascript , I took the model, the data for pre and post processing and after loading everything we were finally able to predict