Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
asutoshmaharana2326
Active Participant

Introduction


This Blog demonstrates a custom Google Drive adapter for SAP Integration Suite, designed to facilitate seamless integration between SAP systems and Google Drive. Go through the adapter source code to understand the logic and implementation. Standard Google Adapters will be delivered via Google Workspace adapter and planned for Q3 2024. This is just a fun project to understand the basics behind Google APIs and implementing the same through an adapter. Not recommended for productive use but if you are trying to create a adapter for your project then surely take a reference of the source code.

Github Repo: asutosh.drive

Features




  • Bi-Directional Integration: This adapter supports both inbound and outbound data transfer between SAP and Google Drive, allowing you to push data from SAP to Google Drive and pull data from Google Drive into SAP.




  • Secure Authentication: The adapter provides secure authentication mechanisms to ensure that your data remains protected during the integration process.




  • Customizable Configuration: You can easily configure the adapter to suit your specific integration needs, including specifying folders and document types within Google Drive.




  • Real-time and Batch Processing: The adapter supports real-time and batch processing, giving you flexibility in how you exchange data between SAP and Google Drive.




  • Sender and Receiver Adapter: This adapter support both Sender and Receiver type configuration.




  • Scheduler Support: Sender adapter can be configured to run as per the schedule.




  • Externalized Parameters: All the parameters of the adapter can be externalized.




  • Simple Camel Expression Support: Simple Camel expressions are supported as input variables.




  • Archive and Delete Support: Archiving with or without added timestamp supported.




  • Huge File Upload Support: A resumable upload method is used to upload huge data in chunks.




Table of Contents



  1. Creating Client ID and Secret for Google Drive API

  2. Deploying a Custom Google Drive Adapter in SAP Integration Suite

  3. Prerequisites

  4. Configure the Google Drive Sender Adapter

  5. Configure the Google Drive Receiver Adapter

  6. Deploy iFlow

  7. Test

  8. Conclusion


Creating Client ID and Secret for Google Drive API


In order to access Google Drive API v3, you need to create OAuth 2.0 credentials, which include a client ID and secret. Follow these steps to obtain your credentials:



1. Set Up a Project in Google Cloud Console



  1. Go to the Google Cloud Console.

  2. Click the project drop-down and select or create the project you want to use for the Google Drive API.




2. Enable the Google Drive API



  1. In the Google Cloud Console, navigate to "APIs & Services" > "Library."

  2. Search for "Google Drive API" and select it.

  3. Click the "Enable" button to enable the API for your project.




3. Create OAuth 2.0 Credentials



  1. In the Google Cloud Console, navigate to "APIs & Services" > "Credentials."

  2. Click the "Create Credentials" dropdown and select "OAuth client ID."





  1. Choose "Web application" as the application type.


4. Configure the OAuth Consent Screen



  1. Click "Configure consent screen."

  2. Fill in the required fields such as "App Name" and "User Support Email."

  3. Add the authorized domains for your application.





  1. Add the scope for your application.




5. Create OAuth Client ID



  1. After configuring the consent screen, you will be redirected to the OAuth client creation form.

  2. Enter a name for your OAuth client.

  3. Under "Authorized redirect URIs," add the redirect URLs where users will be redirected after granting permission (e.g., https://client.com/callback and https://<cf-domain>.integrationsuite.cfapps.jp10.hana.ondemand.com/itspaces/odata/api/v1/OAuthTokenF...).

  4. Click "Create" to create your OAuth client.

  5. Your client ID and secret will be displayed. Save them securely.




6. Download Credentials JSON



  1. Click the download icon next to your OAuth client ID to download the credentials JSON file.

  2. Keep this file secure, as it contains sensitive information.


7. Create Security Material



  1. Navigate to Security material tiles in the Monitoring Overview page.

  2. Create an Oauth2 Authorization Code artifact.





  1. Enter a name and description for your artifact.

  2. Choose Provider as Generic.

  3. Under Authorization URL and Token Service URL add https://accounts.google.com/o/oauth2/auth?access_type=offline&approval_prompt=force and https://oauth2.googleapis.com/token respectively.

  4. Copy client ID and secret from the JSON downloaded in section 6.

  5. Select Send As Body Parameter radio button.

  6. Add https://www.googleapis.com/auth/drive in the Scope input box.

  7. Click on Deploy button.




8. Authorize Security Material



  1. Click on Authorize button.





  1. New tab will open with Google sign in page. Login with the user added in section 4.





  1. If your consent app is still in testing then you might get the below screen. Click on continue to proceed.






  1. You will be redirected to this page. Please note you should receive below response otherwise the security material is not setup correctly. <response>Authorization was successful: Refresh Token was added to the OAuth2 Authorization Code Credential 'GoogleAPI'.</response>



Now you have successfully created OAuth 2.0 credentials (client ID and secret) for the Google Drive. You can use this security material in your iFlow to authenticate and access Google Drive resources.


Make sure to handle your credentials securely and never expose them in publicly accessible code or repositories.



Deploying a Custom Google Drive Adapter in SAP Integration Suite


In this guide, we will explore two methods for deploying a Custom Google Drive Adapter in SAP Integration Suite:




  1. Direct Upload using Web UI

  2. Upload using API


Method 1: Direct Upload using Web UI


Note: This method may take long time to upload.



Step 1: Log in to SAP Integration Suite



  1. Navigate to the SAP Integration Suite Web UI.

  2. Log in to your SAP Integration Suite account.


Step 2: Access the Integration Package



  1. In the SAP Integration Suite Web UI, go to the "Design" section.

  2. Locate and select the integration package where you want to deploy the Custom Google Drive Adapter.


Step 3: Download the Adapter File



  1. Download the asutosh.drive.esa file from the build path.

  2. Save it locally.


Step 4: Upload the Custom Adapter



  1. Inside the integration package, click "Edit," then navigate to the "Artifacts" tab.

  2. Click the "Add" button and select "Integration Adapter" to create a new custom integration adapter.

  3. Click the "Browse" button to select the asutosh.drive.esa file for the adapter.

  4. Click "Ok."


Step 5: Deploy the Integration Flow



  1. Navigate to the "Action" button and select the "Deploy" option.

  2. Monitor the deployment to ensure it's successful.


Method 2: Upload using API


Step 1: Obtain Service Keys



  1. Navigate to the BTP Cockpit.

  2. Go to your respective Sub-account and click on "Instances and Subscriptions" to check for the service instance.

  3. Check for the Service Process Integration Runtime and Plan api. If not found, quickly navigate to Service Marketplace and search for Process Integration Runtime service.

  4. Create a new instance and choose Plan as api.

  5. Provide an appropriate Instance Name and click on the next button. Select AuthGroup_IntegrationDeveloper and WorkspacePackagesEdit roles. Then click on the "Create" button.

  6. Now navigate to the instance and create a Service Key for the instance by providing an appropriate Service Key Name.

  7. Copy the JSON file to a secure location.


Step 2: Postman Setup



  1. Navigate to the SAP Business Accelerator Hub.

  2. Download the API Specification as JSON.

  3. Go to the Postman application and click on the import button. Drag and drop the JSON specification and click on the import button to create the collection.

  4. Navigate to the Integration Content collection.

  5. Go to the Authorization tab. Select OAuth 2.0 as the Type and Client Credentials as the Grant Type.

  6. Add the Access Token URLClient ID, and Client Secret as per the Service Key JSON file created in Step 1.

  7. Now navigate to the Variables tab and give your Cloud Integration API URL (e.g., https://<cf name>.it-<cf id>.cfapps.jp10.hana.ondemand.com/api/v1. You can get the same URL from the Service Key JSON url field + /api/v1).

  8. Now navigate to the Integration Content/IntegrationPackages/Get all integration packages. request and Add the header x-csrf-token with the value fetch. Click on the Send button and copy the x-csrf-token header value and package Id from the response.


Step 3: Import the Adapter



  1. Clone GitHub repo to your local PC either using git clone https://github.com/Asutosh-Integration/asutosh.drive.git command (if you have git installed) or else you can directly Download ZIP from GitHub.

  2. Now Open the Project in any IDE of your choice and run src/main/java/asutosh/google/FileToBase64AndSaveToFile.java file.

  3. Now navigate to target/build/asutosh.drive-Base64.txt path and copy the file content (Base64 encoded string of asutosh.drive.esa file).

  4. Navigate to the Postman tool and Integration Content/IntegrationAdapterDesigntimeArtifacts/Import integration adapter artifact request.

  5. Go to the body and add below JSON (After replacing Base64Content and packageID with the copied file content and Integration package ID).

    {
    "PackageId": "packageID",
    "ArtifactContent": "Base64Content"
    }



  6. Add the header X-CSRF-Token with the value received in the previous request.

  7. Use the Send button to import the custom adapter into the SAP Integration Suite tenant.


Step 4: Deployment



  1. Navigate to the SAP Integration Suite Web UI and deploy the adapter.

  2. Ensure that the Custom Google Drive Adapter is successfully deployed.


Congratulations! You have successfully deployed a Custom Google Drive Adapter in SAP Integration Suite using either of the above two different methods. Please refer the Documentation for step-by-step guide on adapter configuration in the iFlow.


Note: For more detailed instructions and troubleshooting tips, refer to SAP Integration Suite documentation or consult your SAP support resources.



Prerequisites


Before proceeding, ensure you have the following prerequisites in place:




  • Security Material for Google OAuth 2.0 Authorization Code created.

  • Custom Google Drive adapter deployed in the tenant.

  • Download and import sample iFlow to your SAP Integration Suite tenant.


Configure Custom Google Drive Sender Adapter


Once you have created a sender channel and selected the Google Drive sender adapter, you can configure the following attributes.


General
















Parameter Description
Name Enter the name of the Google Drive channel.

Settings








































Parameter Description
Choose Operation Only Download operation is supported in Sender Channel.
File Path Name of the file to Download. Use of Simple Camel expression is also supported.
⚠️Caution:
Multiple filenames are not supported.
Please always mention absolute path from the root (/).
While using both Simple Expression and constant, Please always mention extension of the file separated by ..
ℹ️Note:
Example of supported file paths are below.
/<rootFolder>/<subFolder>/<filename>.<ext>/<filename>.<ext>${header.filepathwithext}/<rootFolder>/${property.filenamewithext}
Example of file paths not supported are below.
<rootFolder>/<filename>.<ext> (should start with / or ${<expression>}), /<rootFolder>/<filename> (extension should be there in the filename)
Credential Name Name of the Oauth2 Authorization Code artifact.
Archive (Optional) Allow you to specify if you want to Archive the file. Choosing only archive (without Delete) will not delete the original file (only make a copy of file in the archive path).
Delete (Optional) Allow you to specify if you want to Delete the file. Choosing only Delete (without Archive) will move the file to trash.
Archive File Path (Mandatory if Archive selected) Specifies the target directory where to move the file.
⚠️Caution:
Target folder creation is not supported as of now so always mention the folders which are present in the drive.
Add Timestamp (Optional) Allow you to specify if you want to add timestamp to the archive file name.
e.g. archiveFilename2023-09-14 17:15:20.217.pdf

Scheduler





















































Scheduler Option Field Description
Run Once Specify if you want to run only once.
Schedule on Day On Date Specify the date on which you want the operation to be executed.
On Time Specify the time at which you want the operation to be executed.
Every Specify a time period (e.g., every hour) in a dedicated time window.
Time Zone Select the time zone that you want the scheduler to use as a reference for the date and time.
Schedule to Recur Daily Select the time or interval and time zone for the schedule to recur.
Weekly Select the checkboxes to indicate the days of the week on which the operation has to be executed. Also, specify the time or interval for the schedule to recur.
Monthly Select the day of the month on which the operation has to be executed. Also, indicate the time or the interval for the schedule to recur.

Configure Custom Google Drive Receiver Adapter


Once you have created a sender channel and selected the Google Drive receiver adapter, you can configure the following attributes.


General
















Parameter Description
Name Enter the name of the Google Drive channel.

Settings








































Parameter Description
Choose Operation Select the type of operation you want to perform.
1. Download: Export the file from the Google Drive.
2. Upload: Import the file to the Google Drive.
File Path Name of the filepath to Download/Upload. Use of Simple Camel expression is also supported.
⚠️Caution:
Multiple filenames are not supported.
Please always mention absolute path from the root (/).
While using both Simple Expression and constant, Please always mention extension of the file separated by ..
ℹ️Note:
Example of supported file paths are below.
/<rootFolder>/<subFolder>/<filename>.<ext>/<filename>.<ext>${header.filepathwithext}/<rootFolder>/${property.filenamewithext}
Example of file paths not supported are below.
<rootFolder>/<filename>.<ext> (should start with / or ${<expression>}), /<rootFolder>/<filename> (extension should be there in the filename)
Credential Name Name of the Oauth2 Authorization Code artifact.
Archive (Optional) Allow you to specify if you want to Archive the file. Choosing only archive (without Delete) will not delete the original file (only make a copy of file in the archive path).
Delete (Optional) Allow you to specify if you want to Delete the file. Choosing only Delete (without Archive) will move the file to trash.
Archive File Path (Mandatory if Archive selected) Specifies the target directory where to move the file.
⚠️Caution:
Target folder creation is not supported as of now so always mention the folders which are present in the drive.
Add Timestamp (Optional) Allow you to specify if you want to add timestamp to the archive file name.
e.g. archiveFilename2023-09-14 17:15:20.217.pdf

Deploy iFlow



  1. Save your iFlow configuration.

  2. Deploy the iFlow to your SAP Integration Suite tenant.

  3. Monitor the iFlow for any issues or errors during execution.


Test


Test Configuration:


Sender Adapter


The sender adapter is configured to download the file and scheduled to run once. The Archive, Delete and Add Timestamp is also added.




Content Modifier


A content modifier is added to define the file name as a property and assign a string "x" as the body to be uploaded by the receiver adapter.





Receiver Adapter


The receiver adapter is configured to upload the file to google drive with simple camel expression in the file path.




Result


Expected Result


The iFlow run will Download the TestFile.pdf file from TestFolder and archive the same with added timestamp in TestFolder. This will also upload a file named as TestFile1.pdf in TestFolder as per the file path configuration /TestFolder/${property.x}.



Before Deployment


There is only one file named TestFile.pdf in TestFolder.




Result


There are 2 files in the TestFolder.



TestFile1.pdf contain "x" which was configured in the content modifier body.




Conclusion


You have successfully configured and deployed a SAP Integration Suite iFlow with a custom Google Drive adapter, enabling scheduled runs, file downloads, archiving, timestamping, and handling large files. Make sure to test the adapter thoroughly in your tenant to ensure it meets your integration requirements.


If not then you can always clone the repo and change the code as per the requirement and then use maven mvn clean install command to build the adapter again.

5 Comments
Labels in this area