Making Dropbox Documents Available in AEM

04 / Feb / 2016 by Jatin Gupta 5 comments

Use Case

Consider a scenario where a company uploads thousands of document related to its policies or some other stuff in AEM. It would be an overhead for AEM to manage those documents resulting in the degradation of performance since AEM is already managing a lot of tasks.

Solution

One way of managing documents and avoid overhead in AEM is to use document management systems like Dropbox and Google Drive. On the AEM side, we would have some way to make those documents available for view/download purpose.

Following customization needs to be done:

  • Customization  of Touch UI content Finder:  Adding one more option in Asset category and to showcase dropbox documents in the content finder on the selection of this option.
  • Integration with Dropbox: Fetching the metadata of the documents using Importer
  • Creation of droppable component: Enabling user to drop asset from asset category onto the page.
  • Metadata management of Dropbox documents

Steps to Integrate Dropbox with AEM:

Pre-requisites:

  • Java 1.8 (Only in case if you install the source code attached below as the source contains some Java 8 specific code snippet.)
  • You also need to install Jackson-core bundle as dropbox-SDK has dependency on it

Step1:

Sign up in dropbox and create a developer app in dropbox using the following link:

https://www.dropbox.com/developers/apps/create

For our integration Dropbox with AEM, we would be requiring the Access Token ( You need Click on “Generate Token” button to get the Access token. The reason we are generating the token from the dropbox portal only so that we can skip the manual flow of OAuth2. For OAuth2 flow you can access OAuth2.0 )

Step2:

Create the cloud services config page for Dropbox that has authoring dialog for parameters like Access Token, Target URL, Client-Identifier, Interval (The last three parameters we would be needing for creating the custom importer)

For creating the custom cloud service, please refer Create Custom Cloud service

Dropbox Configuration

Step3: Adding dependencies related to dropbox. I have used the maven build tool.  Add the following dependency to the project’s pom.xml


<dependency>
<groupId>com.dropbox.core</groupId>
<artifactId>dropbox-core-sdk</artifactId>
<version>1.7.7</version>
</dependency>

Also, Embed transitive dependencies used by dropbox SDK using the following code:


<Embed-Dependency>dropbox-core-sdk;scope=compile|runtime</Embed-Dependency>

Step4:

Create the dropbox config page using the template that was created in Step2. You can go to “http://<domain>:<port-no>/miscadmin#/etc/cloudservices” and create the page. The page would be created under the directory in CRXDE:

/etc/cloudservices/

Add configure the page accordingly. Please see the below snapshot for reference.

Configurations

Step 5:

Till now we are done with basic setup required for integration.It’s time to code NOW.

Create a custom importer that will poll the dropbox and fetch the metadata of the documents. The importer will also create a node (of type dam: Asset) under the path specified in the cloud config dialog of Dropbox Cloud Configuration Page created in Step4.

For reference, you can download DropboxImporter.java

Step6: Once the importer will be created, the only part left is to display the imported content in DAM’s content finder.

Note: The solution provided for displaying the content would only work in TOUCH UI because of the overlaying structure of the component.

(a) To add the option in dropdown for category under Asset tab in Content finder, we need do the following:

  • Overlay the following structure:  /libs/cq/gui/components/authoring/clientlibs/assetfinder/js in apps. Delete all the child folders under js.
  • Create a folder “dropboxdocument” and place the .js file under it. You can copy the .js file from /libs/cq/gui/components/authoring/clientlibs/assetfinder/js/document/documentController.js. Rename the file as per your wish and save.
  • Now open the above js file and then change the “name” property to “Dropbox Docs” and “itemResourceType” to the path “cq/gui/components/authoring/assetfinder/dropbox
  • Create js.txt in same hierarchy and add the path to the file created in above step and save all the above changes. Now open any page in TOUCH UI mode, you will find an extra option being added in dropdown.

Content finder

Key Properties:

  • name: The label that will be shown in the dropdown
  • itemResourceType: is the component that will be rendered in content finder for each asset
  • imageServlet: the service that will list of assets that match the mime types given in param and in response it will give the HTML code

(b) Now we need to customize the code the component mentioned in itemResourceType property so that it can show the desired properties of the asset in content finder. Copy dropbox.jsp to the path “/apps/cq/gui/components/authoring/assetfinder/dropbox/

Note: It can be any path. But according you need to change the itemResourceType property.

(c) We need to create the component in which dropbox documents can be dropped. So you can create a copy of OTB download component and modify the script accordingly.

That’s it……….

final

This is how the directory structure will look like:

folder hierarchy

Download Source Code: dropbox-integration

FOUND THIS USEFUL? SHARE IT

comments (5)

  1. Arpit Bora

    Superb article Jatin.
    I have one question “Instead of loading metadata information can we directly download the files under our dam” ?

    Reply
    1. Jatin Gupta Post author

      Hi Arpit,

      Is there any specific reason to save the file in DAM ? It will be an overhead to keep the files in DAM and also degrade the performance when the number of files increases. That’s the reason I thought of storing only the metadata and provide the download link to the asset/file once being dragged and dropped.

      And in case, if you want to store the file in DAM, you need to read the file content from Dropbox and then create the file in DAM and write the corresponding content.

      Please let me know in case if you need any help.

      Reply
    1. Jatin Gupta Post author

      Hi Vaibhav,

      Currently, I only implemented for Dropbox. Similar approach can be adopted for Google Drive also. The only changes that will be required are authentication for Google Drive and its API usage.

      Please let me know in case if you face any issues during integration.

      Reply

Leave a comment -