Namespace: DocumentService

sap. DocumentService

This plugin provides Document Service integration and synchronization functionality.


Adding and Removing the Document Service Plugin
The Document Service plugin is added and removed using the Cordova CLI.

To add the Document Service plugin to your project, use the following command:
cordova plugin add kapsel-plugin-document-service

To remove the Document Service plugin from your project, use the following command:
cordova plugin rm kapsel-plugin-document-service

Members

(constant) FILE_DECRYPTION_FAIL

This error code indicates that file decryption has failed using stored password.

(constant) FILE_TRANSFER_FAIL

This error code indicates an error occurred when using the Cordova File Transfer Plugin. More description can be found on https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-file-transfer/#filetransfererror (eg: failure in download/upload)

(constant) FILE_TYPE_INCORRECT

This error code indicates that a file with unexpected file type has been detected.

(constant) LOCAL_FILE_SYSTEM_ERR

This error code indicates an error occurred from local file system operations. (eg: fail to read/create/delete local file/directory, fail to get file metadata)

(constant) OBJECT_CANNOT_BE_PARSED

This error code indicates that the object body from response cannot be parsed.

(constant) REMOTE_FILE_SYSTEM_ERR

This error code indicates an error occurred from server side file system operations. (eg: fail to read/create/delete remote file/directory)

(constant) RESUMABLE_HANDLING_ERR

This error code indicates that an error has occurred when handling resumable download.

(constant) STORAGE_PERMISSION_NOT_ON

This error code indicates that an error occurred when device permission on storage operations is not turned on.

Methods

(static) createFolder(folderName, folderPath, successCallback, errorCallback)

Create a new folder in the specified path

Creates a new folder in the remote repository of the connected session.
Parameters:
Name Type Description
folderName String Name of the new folder
folderPath String Path where the new folder is located
successCallback function Success callback function
errorCallback function Error callback function
Example
sap.DocumentService.createFolder("New Folder", "/", successCallback, errorCallback);

(static) createLocalFolder(folderPath, successCallback, errorCallback)

Create a new local folder in the specified path

Creates a new folder in the local repository of the connected session.
Parameters:
Name Type Description
folderPath String Path where the new folder is located including the folder name
successCallback function Success callback function
errorCallback function Error callback function
Example
sap.DocumentService.createLocalFolder("/New Folder", successCallback, errorCallback);

(static) createSession(serverURL, successCallback, errorCallback)

Create a new session to the CMIS document repository

Creates a session that connects to the SAP server and prepares your application to utilize online features of the plugin.
Parameters:
Name Type Description
serverURL String URL to CPMs application
successCallback function Success callback function
errorCallback function Error callback function
Example
sap.DocumentService.createSession("https://hcpms-ixxxxxxtrial.hanatrial.ondemand.com/mobileservices/persistence/v1/json/com.example.app/", successCallback, errorCallback);

(static) deleteLocal(filePath, successCallback, errorCallback)

Delete a File/Folder from local device

Deletes a file on the local device. File is located at the provided file path and the path is relative to the root folder of the repository.
Parameters:
Name Type Description
filePath String Path where the file/folder is located
successCallback function Success callback function
errorCallback function Error callback function
Example
sap.DocumentService.deleteLocal("/", successCallback, errorCallback);

(static) deleteRemote(filePath, successCallback, errorCallback)

Delete a File/Folder from remote server

Deletes a file on the remote server. File is located at the provided file path and the path is relative to the root folder of the repository. Calls the error callback if remote folder is not empty.
Parameters:
Name Type Description
filePath String Path where the file/folder is located
successCallback function Success callback function
errorCallback function Error callback function
Example
sap.DocumentService.deleteRemote("/", successCallback, errorCallback);

(static) download(filePath, overwrite, successCallback, errorCallback, progressCallback)

Download specified file/folder from the server to the device

Download the specified file path, which should be given relative to the remote repository root, to the equivalent local folder. It creates intermediate folders if necessary. If the overwrite flag is set, existing local files/folders will be replaced with the remote copy. If not, it calls the error callback with an error object showing the details of the conflicting files.
Parameters:
Name Type Description
filePath String Path of file/folder on the server, defaults to root
overwrite boolean Overwrite existing local files
successCallback function Success callback function
errorCallback function Error callback function
progressCallback function Progress callback function
Example
sap.DocumentService.download('/', successCallback, errorCallback, progressCallback);

(static) exit()

Delete all decrypted files on plugin exit This function should be called when the application is being closed/loses focus. It deletes all files in the decrypted directory to prevent unauthorized access outside of the application.

(static) init(successCallback, errorCallback)

Initialize the Document Service Plugin. Must be called before any other functions. This function first calls the android file system to request file permissions to write to storage. It then creates directories for both encrypted (if encryption is enabled ) and unencrypted files using config parameters where they are available
Parameters:
Name Type Description
successCallback function Success callback function
errorCallback function Error callback function

(static) isFileDownloaded(filePath, successCallback, errorCallback)

Checks whether a file exists locally

Checks if a file exists locally and calls the success callback with the string concatenation of the filename, a colon (:) and a boolean.
Parameters:
Name Type Description
filePath String Path where the downloaded file is located
successCallback function Success callback function
errorCallback function Error callback function
Example
sap.DocumentService.isFileDownloaded("/Mario/koopa.png", successCallback, errorCallback);

(static) listLocal(targetFolderPath, successCallback, errorCallback)

List local files in specified path in JSON format

Calls the local system to obtain a list of all files in the specified path relative to the root folder. Returns an array containing objects representing a file or folder. The array also contains a boolean value that shows if the folder being listed is the root of the connected repository.

Return Structure:

  • {
  • isRootFolder: true
  • Object[0]:{name:"Folder1Name", type:"Local Folder"},
  • Object[1]:{name:"File1Name", type:"Local File"}
  • }
Parameters:
Name Type Description
targetFolderPath String Local path to list all the files/folders
successCallback function Success callback function
errorCallback function Error callback function
Example
sap.DocumentService.listLocalFiles("/",successCallback, errorCallback);

(static) listRemote(targetFolderPath, successCallback, errorCallback)

List remote files in specified path in JSON format

Calls the remote server to obtain a list of all files in the specified path relative to the root folder. Returns an array containing objects representing a file or folder. The array also contains a boolean value that shows if the folder being listed is the root of the connected repository.

Return Structure:

  • {
  • isRootFolder: true
  • Object[0]:{name:"Folder1Name", type:"CMIS Folder"},
  • Object[1]:{name:"File1Name", type:"CMIS File"}
  • }
Parameters:
Name Type Description
targetFolderPath String Path where the target folder is located
successCallback function Success callback function
errorCallback function Error callback function
Example
sap.DocumentService.listRemote("/", successCallback, errorCallback);

(static) openFile(filePath, successCallback, errorCallback)

Opens a local file

Use the attachment viewer plugin to open the target file. If the encryption option is on, decrypt the file before opening.
Parameters:
Name Type Description
filePath String Path of the file to open
successCallback function Success callback function
errorCallback function Error callback function
Example
sap.DocumentService.openFile("/Mario/koopa.png", successCallback, errorCallback);

(static) synchronization(filePath, successCallback, errorCallback, progressCallback)

Sync updates of the specified files between the server and the device.

Syncs files by first performing a download and then an upload. Path must be provided relative to the root folder.
Parameters:
Name Type Description
filePath String Path of file/folder on the device/remote server to sync, defaults to root
successCallback function Success callback function
errorCallback function Error callback function
progressCallback function Progress callback function
Example
sap.DocumentService.synchronization('/', successCallback, errorCallback);

(static) upload(filePath, overwrite, successCallback, progressCallback)

Upload specified file/folder from the device to the server

Upload the specified file path, which should be given relative to the local repository root, to the equivalent remote folder. If the remote destination folder does not exist, an error is thrown. If the overwrite flag is set, existing remote files/folders will be replaced with the local copy. If not, it calls the error callback with an error object showing the details of the conflicting files. This function does not exist if encryption is on because files in the local repository are not modifiable.
Parameters:
Name Type Description
filePath String Path of file/folder on the device, defaults to root
overwrite boolean Overwrite existing remote files
successCallback function Success callback function
progressCallback function Progress callback function
Example
sap.DocumentService.upload('/', successCallback, errorCallback);

(static) uploadWithFilePicker(destFolderPath, file, successCallback, errorCallback, progressCallback)

Upload a file using the webview file chooser to to the specified path

Used to upload files that are returned when an html input element is used to select the file from the device to be uploaded to the specified destination folder. The folder path must be given relative to the remote root folder.
Parameters:
Name Type Description
destFolderPath String Path where the destination folder is located
file File File object being uploaded
successCallback function Success callback function
errorCallback function Error callback function
progressCallback function Progress callback function
Example
sap.DocumentService.uploadWithFilePicker("/", successCallback, errorCallback);