4 Replies Latest reply on Mar 13, 2013 10:06 PM by Shriram K M

    Creating a thumbnail within a workflow process

    Shriram K M


      Within my workflow process, I want to create thumbnail images of the files/documents that have been uploaded in a page through the out of the box 'Download' component. I want to store these thumbnails on the same page(within /content/mypage). As far as I know, the logic of thumbnail creation of an uploaded files is already available in the DAM. On further probing, I got to know that the thumbnail creation is done as part of a workflow and the workflow process is 'CreateThumbnailProcess'(com.day.cq.dam.core.process.CreateThumbnailProcess). So I tried creating an instance of the CreateThumbnailProcess and calling the execute() method of this process within my workflow process. Here's a glimpse of what I did.


      public void execute(WorkItem item, WorkflowSession session, MetaDataMap args) throws WorkflowException {
           CreateThumbnailProcess proc = new CreateThumbnailProcess();
           System.out.println("Test Workflow entered!!");
           proc.execute(item, session, args);
           System.out.println("Test Workflow executed. Thumbnail created!!");


      But when I start my workflow, I keep getting "Test Workflow entered!!" multiple number of times on my console. I am unable to understand what's happening. Please help me. If there are any simpler alternatives to create a thumbnail, please suggest them too.


      Thanks in advance

      Shriram K M

        • 1. Re: Creating a thumbnail within a workflow process
          rush_pawan Level 4

          Hi Shriram,


          execute() is a default function and gets called automatically. Now as you mentioned that you have extended CreateThumbnailProcess class and want to run execute() from parent then you should do super.execute() instead creating the instance because in that way it always calls the child implementation if available (basic java rule).


          Now i also want to suggest if you have not doing anything extra in execute() in you child class just calling the super.execute() then you need not require to override it in your child class again.


          I hope it clarifies your doubt.




          • 2. Re: Creating a thumbnail within a workflow process
            Shriram K M Level 1

            Hi Pawan,
            I'm not extending the CreateThumbnailProcess. The workflow process which I referred to as 'my workflow process' in my post is a general workflow process that is completely independent of the CreateThumbnailProcess.

            • 3. Re: Creating a thumbnail within a workflow process
              rush_pawan Level 4



              So couple of things which you can try out to check what's causing the issue.


              1. If you comment

                   //proc.execute(item, session, args);

                does it still causing the same issue. If yes, then problem would be somewhere in your workflow call or process execution which calling this process recurring (i can assume as not see the whole code) and, if not, then this call is only causing the issue which is pretty wierd (looking into possibility and will update you) if you do not have extended the same process as you mentioned above.

              2. Not sure calling another process like this is correct way to do it because CreateThumbnailProcess automatically gets called in cq when image object created in system to create default renditions.


              To answer you other question.

              creating extra thumbnail apart from default renditions you should have to create workflow process as you already did but extend AbstractAssetWorkflowProcess (dont call CreateThumbnailProcess.execute() because there is default workflow process already setup.) and below code in execute method


              Asset asset = getAssetFromPayload(workItem, workflowSession.getSession());

              oriIs = asset.getOriginal().adaptTo(Node.class)

                                          .getProperty(JcrConstants.JCR_CONTENT + "/" + JcrConstants.JCR_DATA).getBinary().getStream();

              asset.addRendition(rendition, oriIs, mimetype);  //mimetype and rendition you have to create it as an object based on your requirement.


              also check http://dev.day.com/docs/en/cq/current/javadoc/com/day/cq/dam/core/process/CreateThumbnailP rocess.html for more detail.


              Let me know for more information.




              1 person found this helpful
              • 4. Re: Creating a thumbnail within a workflow process
                Shriram K M Level 1


                Thanks a lot for following up the problem!

                1. If I comment out the line that you have mentioned, then there is no error which implies that the problem is with the execute() method of the CreateThumbnailProcess.


                2. Yes, even I'm quite skeptical about the approach of calling the execute() method of another workflow process directly from within a workflow process.


                I am yet to try out the code snippet that you have mentioned but I have two questions in my mind regarding the code snippet

                1. How to set a document/file that I have as the workflow payload asset? Is there something like a setAssetInPayload() method?


                2. If I'm creating the rendition as mentioned in your code snippet, where will it be located? I want the renditions to sit on my page. Is that possible?