9 Replies Latest reply on Mar 16, 2012 8:35 AM by justin_at_adobe

    Is there a way to process multiple payloads in a CQ5 Workflow?

    jzeren

      I've only recently started working with CQ5 and in particular the Workflow system and from what I've seen so far I'm impressed.  I may not have fully grasped how the Workflow mechanism should be used but I was wondering if there was a way to process more than one "payload" in a workflow.  To provide context here is what I am trying to do.

       

      In CQ5 I have a direct link to the users of the system and a page about the user.  This is something like a meet the team page where every user of the system has access to at least their own page.  Ultimately I would like to create a workflow that kicks off a task to every user in a particular group that they need to make sure their page is up to date.  When the user views their page they see the workflow step in the side kick, they can make changes or not, but if they proceed they the workflow will move to notifying the manager (assigned in the workflow).  The manager can then review the persons page, and send it back to them if it is not sufficient, or upon approval, the page will automatically be published to the publish instance.

       

      The way I understand the workflow mechanism in CQ is that I would need to create a separate workflow for each person that has a page.  So if I had 20 employees set to edit their own pages, I would have to kick off 20 different workflows.  I'm not seeing any way around this because it looks like each workflow has a particular payload.

       

      Any help / ideas here would be appreciated.

        • 1. Re: Is there a way to process multiple payloads in a CQ5 Workflow?
          hypnotec Adobe Employee

          i think you're looking for the workflow package feature:

           

          Workflow Packages

          Developing Workflows

          • 2. Re: Is there a way to process multiple payloads in a CQ5 Workflow?
            jzeren Level 1

            This looks closer to what I need, but is there a way to assign a specific user to each resource in teh Workflow Package?  The workflow package looks like the whole thing is driven and initiated by one user who is updating multple content.  From what I could tell I could create a workflow package to include all of the pages (resources) that need to be editied (from my example, each employee's detail page) but there would be no way to enforce that only a specific logged in user could move the workflow along for their respective page. 

             

            The scenario I"m looking to creat is something like this:

             

            User's of the system:
            Administrator1 - Admin of the System

            Approver1 - Approver of content

            User1 - Responsible for updating Page1

            User2 - Responsible for updating Page2

             

            1.  Administrator Kicks off a workflow that notifies User1 and User2 to make updates to Page1 and Page2 respectfully

            2.  User1 makes updates to Page1 and User2 makes updates to Page2, both mark their stage of the workflow "complete" moving it to the next node.

            3. Approver1 is notified that User1 and User2 have edited Page1 and Page2 respectfully (I would see this as two seperate tasks in Approver1's inbox)

            4. Approver1 either accepts the updates moving each one to an "Activate Page/Asset" node pushing changes to the publish site, or steps one or both back with comments so that User1 and/or User2 can make necessary edits.

             

            Tlhe biggest problem I have with this scenario is the first step.  I can't seem to find a centralized way to handle what seems like it would be multiple workflows.  I can accomplish steps 2,3,4 easily using something like the "Publish Example" workflow, by modifying it to have a step where the "Approver1" type person could send the Workflow back to the initiator until the content is acceptable.  However, this leaves it up to User1 and User2 to initiate the workflow whenever they see fit.  I really want someone (like Administrator1 in the above example) to be able to initiate a set of tasks (to each user) from a single workflow.

             

            Maybe I'm bending the limitations of how the Workflow mechanism is supposed to work.  If so, I'll need to think up a new way to handle managing multiple updates at one time.

            • 3. Re: Is there a way to process multiple payloads in a CQ5 Workflow?
              hypnotec Adobe Employee

              IIUYC you're only having trouble with the amount of work ar lack of usability for the admin to kick off workflows for each page. after the inital kick-off it is quite all right to have 20 different workflows i think, as they present as "tasks" each personal to a user and reviewer.

               

              in order to facilitate launching a multitude of workflows with one step, you could customize the workflow with e.g an own WorkflowProcess implementation [0], that you can then hook into your workflow model.

               

              as an example:

              - admin puts pages in wf package

              - admin submits package into workflow X

              - the first step in the model of workflow X is your implementation

              - the implementation looks at the package contents and starts a new workflow for every entry

               

              the process step in your model is configurable via the dialog, delivering process arguments to your implementation. so you're quite flexible.

               

              [0] http://dev.day.com/docs/en/cq/current/developing/developing_workflows.html#Defining%20a%20 Process%20Step:%20with%20a%20Java%20Class

              • 4. Re: Is there a way to process multiple payloads in a CQ5 Workflow?
                jzeren Level 1

                Ok, I think this looks like what I need.  I should be able one or more process steps to kick off multiple workflows and manage them.

                 

                However, I was trying to implement the steps in the documentation you sent and I can not get my sample workflow process to show up in the Process Step List.

                 

                Here is my workflow process class:

                 

                package com.day.cq5.icubed_resource_profile;

                 

                import com.day.cq.workflow.WorkflowException;

                import com.day.cq.workflow.WorkflowSession;

                import com.day.cq.workflow.exec.WorkItem;

                import com.day.cq.workflow.exec.WorkflowData;

                import com.day.cq.workflow.exec.WorkflowProcess;

                import com.day.cq.workflow.metadata.MetaDataMap;

                import org.apache.felix.scr.annotations.Component;

                import org.apache.felix.scr.annotations.Properties;

                import org.apache.felix.scr.annotations.Property;

                import org.apache.felix.scr.annotations.Service;

                import org.osgi.framework.Constants;

                 

                import javax.jcr.Node;

                import javax.jcr.RepositoryException;

                 

                /**

                * Sample workflow process that sets an <code>approve</code> property to the payload based on the process argument value.

                */

                @Component

                @Service

                @Properties({

                        @Property(name = Constants.SERVICE_DESCRIPTION, value = "A sample workflow process implementation."),

                        @Property(name = Constants.SERVICE_VENDOR, value = "Adobe"),

                        @Property(name = "process.label", value = "JZ Sample Workflow Process")})

                public class JAZProcess implements WorkflowProcess

                {

                 

                    private static final String TYPE_JCR_PATH = "JCR_PATH";

                 

                    public void execute(WorkItem item, WorkflowSession session, MetaDataMap args) throws WorkflowException

                    {

                        WorkflowData workflowData = item.getWorkflowData();

                        if (workflowData.getPayloadType().equals(TYPE_JCR_PATH))

                        {

                            String path = workflowData.getPayload().toString() + "/jcr:content";

                            try

                            {

                                Node node = (Node) session.getSession().getItem(path);

                                if (node != null)

                                {

                                    node.setProperty("approved", readArgument(args));

                                    session.getSession().save();

                                }

                            }

                            catch (RepositoryException e)

                            {

                                throw new WorkflowException(e.getMessage(), e);

                            }

                        }

                    }

                 

                    private boolean readArgument(MetaDataMap args) {

                        String argument = args.get("PROCESS_ARGS", "false");

                        return argument.equalsIgnoreCase("true");

                    }

                   

                }

                 

                And below is my Maven Project's pom.xml:

                 

                <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

                  <modelVersion>4.0.0</modelVersion>

                  <groupId>com.day.cq5.icubed_resource_profile</groupId>

                  <artifactId>core</artifactId>

                  <version>0.0.1-SNAPSHOT</version>

                  <name>I-Cubed Resource Profile Core</name>

                  <description>This is the Core module</description>

                 

                  <packaging>bundle</packaging>

                <build>

                     <plugins>

                          <plugin>

                               <groupId>org.apache.maven.plugins</groupId>

                               <artifactId>maven-compiler-plugin</artifactId>

                               <configuration>

                                         <source>1.5</source>

                                         <target>1.5</target>

                               </configuration>

                          </plugin>

                          <plugin>

                               <groupId>org.apache.felix</groupId>

                               <artifactId>maven-bundle-plugin</artifactId>

                               <version>1.4.3</version>

                               <extensions>true</extensions>

                               <configuration>

                                    <instructions>

                                         <Private-Package>com.day.cq5.icubed_resource_profile</Private-Package>

                                    </instructions>

                               </configuration>

                          </plugin>

                     </plugins>

                </build>

                <dependencies>

                     <dependency>

                          <groupId>com.day.cq.wcm</groupId>

                           <artifactId>cq-wcm-api</artifactId>

                          <version>5.4.0</version>

                     </dependency>

                     <dependency>

                          <groupId>com.day.cq</groupId>

                          <artifactId>cq-commons</artifactId>

                          <version>5.4.6</version>

                     </dependency>

                     <dependency>

                          <groupId>org.apache.sling</groupId>

                          <artifactId>org.apache.sling.api</artifactId>

                          <version>2.2.4</version>

                     </dependency>

                </dependencies>

                </project>

                 

                From Eclipse I can perform "Run as -> Maven Install" and build the OSGi bundle ok.  (I know this because I have another class in the bundle that writes out to specific CQ Pages).  However, when I go to the details of a workflow and Add a "Process Step" then go to the "Process" tab and try to find my new process in the list I do not see it.  From what I put in the "process.label" property in the class it is my understanding that I should see "JZ Sample Workflow Process" in the list to choose from?

                 

                Any thoughts on what I may have missed?  I feel I can work with this to accomplish my goal if I can just figure this last peice out.

                • 5. Re: Is there a way to process multiple payloads in a CQ5 Workflow?
                  hypnotec Adobe Employee

                  you're missing the maven-scr-plugin that generates OSGi descriptors for your bundle, which in turn are picked up by the OSGi framework and make your component available.

                   

                  so add the plugin to your build section:

                   

                              <plugin>

                                  <groupId>org.apache.felix</groupId>

                                  <artifactId>maven-scr-plugin</artifactId>

                              </plugin>

                  • 6. Re: Is there a way to process multiple payloads in a CQ5 Workflow?
                    jzeren Level 1

                    I now have the following in my pom.xml but I still do not see my process in the list:

                     

                    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

                      <modelVersion>4.0.0</modelVersion>

                      <groupId>com.day.cq5.icubed_resource_profile</groupId>

                      <artifactId>core</artifactId>

                      <version>0.0.1-SNAPSHOT</version>

                      <name>I-Cubed Resource Profile Core</name>

                      <description>This is the Core module</description>

                     

                      <packaging>bundle</packaging>

                    <build>

                         <plugins>

                             <plugin>

                                <groupId>org.apache.felix</groupId>

                                <artifactId>maven-scr-plugin</artifactId>

                            </plugin>

                              <plugin>

                                   <groupId>org.apache.maven.plugins</groupId>

                                   <artifactId>maven-compiler-plugin</artifactId>

                                   <configuration>

                                             <source>1.5</source>

                                             <target>1.5</target>

                                   </configuration>

                              </plugin>

                              <plugin>

                                   <groupId>org.apache.felix</groupId>

                                   <artifactId>maven-bundle-plugin</artifactId>

                                   <version>1.4.3</version>

                                   <extensions>true</extensions>

                                   <configuration>

                                        <instructions>

                                             <Private-Package>com.day.cq5.icubed_resource_profile</Private-Package>

                                        </instructions>

                                   </configuration>

                              </plugin>

                         </plugins>

                    </build>

                    <dependencies>

                         <dependency>

                              <groupId>com.day.cq.wcm</groupId>

                               <artifactId>cq-wcm-api</artifactId>

                              <version>5.4.0</version>

                         </dependency>

                         <dependency>

                              <groupId>com.day.cq</groupId>

                              <artifactId>cq-commons</artifactId>

                              <version>5.4.6</version>

                         </dependency>

                         <dependency>

                              <groupId>org.apache.sling</groupId>

                              <artifactId>org.apache.sling.api</artifactId>

                              <version>2.2.4</version>

                         </dependency>

                    </dependencies>

                    </project>

                     

                    Am I missing something else? 

                    • 7. Re: Is there a way to process multiple payloads in a CQ5 Workflow?
                      jzeren Level 1

                      So I did a little digging, still did not get it working, but I think I'm getting closer.  From what I can tell the maven-scr-plugin needed some content, so I added the plugin as follows:

                       

                      <plugin>

                        <groupId>org.apache.felix</groupId>

                        <artifactId>maven-scr-plugin</artifactId>

                        <executions>

                            <execution>

                             <id>generate-scr-scrdescriptor</id>

                             <goals>

                               <goal>scr</goal>

                             </goals>

                          </execution>

                        </executions>

                      </plugin>

                       

                      After adding the above to the pom.xml I was getting the following error when building the bundle:

                       

                      [ERROR] Failed to execute goal org.apache.felix:maven-scr-plugin:1.7.4:scr (generate-scr-scrdescriptor) on project core: Execution generate-scr-scrdescriptor of goal org.apache.felix:maven-scr-plugin:1.7.4:scr failed: A required class was missing while executing org.apache.felix:maven-scr-plugin:1.7.4:scr: com/day/cq/workflow/exec/WorkflowProcess

                       

                      I added a dependancy in the pom.xml for the

                      <dependency>

                          <groupId>com.day.cq.workflow</groupId>

                          <artifactId>cq-workflow-api</artifactId>

                          <version>5.4.2</version>

                      </dependency>

                       

                      Adding the dependancy resolved the build error, but I am still getting an error in Eclipse (not sure how to fix it):

                       

                      Plugin execution not covered by lifecycle configuration: org.apache.felix:maven-scr-plugin:1.7.4:scr (execution: generate-scr-scrdescriptor, phase: process-classes)

                       

                      This error is showing up in Eclipse on the line that starts the Execution tag:

                       

                      <execution>

                          <id>generate-scr-scrdescriptor</id>

                          <goals>

                              <goal>scr</goal>

                          </goals>

                      </execution>

                       

                      I think what I have is closer to right, but again, still no success in getting my new Process to show up in the Process Step list.

                       

                      Are there any permissions that need to be set?  Just can't figure out what I'm missing.

                      • 8. Re: Is there a way to process multiple payloads in a CQ5 Workflow?
                        hypnotec Adobe Employee

                        i don't use eclipse, so i can't help you there - i build bundles from the command line (unix shell) using only maven. what is the maven output if you execute mvn clean install on the command line? and how do you install the bundle on CQ? using the maven-sling-plugin (mvn sling:install) or manually via web console, or via webDAV?

                        • 9. Re: Is there a way to process multiple payloads in a CQ5 Workflow?
                          justin_at_adobe Adobe Employee

                          I believe that message about the Plugin executions not covered means that you need to run Maven from the command line. Recent versions of m2eclipse have been very strict about which plugins they will execute.

                           

                          Also, when you run Maven, take a look at the target/scr-plugin-generated folder. That will indicate whether or not the scr plugin executed as expected.

                          1 person found this helpful