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

Creating a Mongo replicaset using docker: Mongo replicaset + Nodejs + Docker Compose

This is a Docker tutorial for creating a Mongo replica set using docker compose and also a couple more containers to experiment with the replica set, above is the vid and below you will find some of the steps followed.
StepsPre-reqsHave node.js installedAnd docker installed (make sure you have docker-compose as well)Create a container for defining configurations for a mongo instanceCreate a container for setting up the replica setCreate a simple node app using expressjs and mongoose (A modified version from the previous video)Create a docker-compose file with the mongo and setup containers and two additional containers for experimenting with the replica setBuild, Run and experiment with your new containers Create a dockerfile for the first mongo container (not really needed but you could configure more stuff if needed)Include container with mongo preinstalled: FROM mongoCreate default/working directory: WORKDIR /usr/src/configsCopy mongo's configurations file into the container
C…

Creating Docker containers for Adobe Experience Manager

This is a Docker tutorial for creating a docker image for the Galen framework, above is the vid and below you will find some of the steps followed. Adobe experience manager is a content management system which in a nutshell is an application that allows us to create web sites to be consumed by end users. You might be familiar with other such applications like wordpress or drupal which serves the same purpose A typical deployment would be comprised of two AEM instances, the author instance used for creating and modifying content, the publish instance which serves the content and finally we have a dispatcher which is a static web server used for caching, load balancing and some security purposes. We can configure an AEM instance to work as an author or publish instance by either changing the file name for the jar file java -jar cq-author-450…

Creating a Docker container for a NodeJs application: Express + Mongo + Docker Compose

This is a Docker tutorial for creating a NodeJs container using expressjs and mongoose, above is the vid and below you will find the steps followed.
StepsPre-reqsHave node.js installedAnd docker installed (make sure you have docker-compose as well)Create an simple node app using expressjs and mongooseModify your container and create a docker-compose fileBuild and Run your new container Create your simple node appInitialize the node appnpm initInstall the dependencies for our appnpm install --save express mongoose Create the database.jsCreate the index.js Create a dockerfileInclude container with node preinstalled: FROM nodeCreate default/working directory: WORKDIR /usr/src/appCopy package.json to workdir and install dependencies (which we will need in this case😊): COPY package.json .RUN npm install Copy the rest of the app (just the index.js file in this case)COPY . .Expose the port required for reaching our expressjs appEXPOSE 3000Add a command to run when this container is star…