Using Media Handlers in Workflows to perform tasks on Assets

Media handlers are services that are usually used in combination with workflows.

CQ5 has the following default workflows to process assets:

  • DAM Asset Sync and Metadata Extractor

  • DAM Delete Asset

  • DAM Delete Dam Asset under /content/dam

  • DAM Sub Asset Processor

  • DAM Update Asset

Existing workflows can be extended and new ones can be created to process assets according to specific requirements.

By default, when a PDF document is uploaded into the /var/dam/geometrixx/documents folder, the default DAM Asset Sync and Metadata Extractor process:

  • copies the document into the /content/dam/geometrixx/documents folder

  • asks the AssetStore for a handler that is able to process pdf

Then, the pdf handler:

  • extracts the metadata

  • generates a thumbnail

  • creates sub-assets: each page of the document becomes a sub-asset

The following example shows how to disable the sub-asset creation for PDF documents by extending the workflow: the Process Subassets step will be replaced by an OR-split that checks the asset filename:

  • if it ends with .pdf, the asset reaches the End step.

  • if it does not end with .pdf, the asset goes through a Process Subassets step that generates sub-assets.

The workflow will look as follows:

Proceed as follows:

  1. Create a service (for example com.day.cq5.myprocess.DoNothingProcess) that does not affect the asset and install it in CQ5. This service will be used to bypass the sub-asset creation step.

    [Tip]Tip

    You can refer to the section called “Example: create a specific Text Handler” to see how to create a service and install it in CQ5.

  2. In your browser, open the Workflow Console (for example: http://localhost:4502/libs/workflow/content/console.html).

  3. Select the Models tab and edit the DAM Asset Sync and Metadata Extractor workflow.

  4. Drag and drop an OR Split between the Thumbnail Creation step and the Process Subassets step.

  5. Click the configuration button of the left step of the OR Split and set the following properties in the right panel:

    • Type: select Process

    • Description: This process creates subassets if handler is able to extract subassets

    • Handler Advance: true

    • Implementation: select com.day.cq.dam.core.process.CreateSubAssetsProcess

    • Process Arguments: /etc/workflow/models/dam/sub_asset_processor

    • Timeout: Off

    • Timeout Handler:

    • Title: Process Subassets

  6. Click the configuration button of the right step of the OR Split and set the following properties in the right panel:

    • Type: select Process

    • Description: This process does not affect the asset and leads to the next step

    • Handler Advance: true

    • Implementation: type the name of the service here (the service created in step 1; for example: com.day.cq5.myprocess.DoNothingProcess)

    • Process Arguments:

    • Timeout: Off

    • Timeout Handler:

    • Title: Do Nothing

  7. Delete the Process Subassets step that comes after the end of the OR Split.

  8. Create an ecma-script function that is set to true if the filename ends with .pdf, to false otherwise:

    1. In CQDE, create a file under /etc/workflow/scripts and call it myPdfCheck.ecma.

    2. Copy-paste the following code into it:

      function check() {
          if (workflowData.getPayloadType() == "JCR_PATH") {
               var path = workflowData.getPayload().toString();
               var node = jcrSession.getItem(path);
               
               if (node.getPath().indexOf(".pdf") >= 0) {
                  return true;
               } else {
                  return false;
               }  
           } else {
              return false;
           }
      }
    3. Save the file.

  9. Create an ecma-script function that is set to true if the filename does not end with .pdf, to false otherwise:

    1. In CQDE, create a file under /etc/workflow/scripts and call it myNotPdfCheck.ecma.

    2. Copy-paste the following code into it:

      function check() {
          if (workflowData.getPayloadType() == "JCR_PATH") {
               var path = workflowData.getPayload().toString();
               var node = jcrSession.getItem(path);
               
               if (node.getPath().indexOf(".pdf") >= 0) {
                  return false;
               } else {
                  return true;
               }  
           } else {
              return true;
           }
      }
    3. Save the file.

  10. In your browser, set the rule of the Process Subassets step of the OR Split: type /etc/workflow/scripts/myPdfCheck.ecma as value of the Rule.

  11. Set the rule of the Do Nothing step of the OR Split: type /etc/workflow/scripts/myNotPdfCheck.ecma as value of the Rule.

  12. Save the workflow.

From now on, whenever a pdf file is uploaded into the /var/dam/geometrixx/documents folder, the file is copied into /content/dam/geometrixx/documents, its metadata are extracted and thumbnails are generated. Subassets are not created anymore.