Tutorial: 9. Usage of Orion FileClient

9. Usage of Orion FileClient

This Wiki describes the usage of Orion FileClient library in the framework of HANA. Orion FileClient is a client-side library to be used in a browser in order to simplify the interaction with Orion server-side API. The libary allows one to work conveniently with files, packages, workspaces and projects.

The detailed description of Orion FileClient can be found at https://orion.eclipse.org/jsdoc/symbols/orion.fileClient.FileClient.html#createFile.

The client code is places in HANA at /sap/hana/xs/dt/base/client.

SapBackPack

This page describes how to use an additional parameter (SapBackPack) in order to extend the original functionality in the context of HANA. The obtained Orion compliant components can be used to in order to allow implementation of SAP HANA capabilities, not specified in the orion standard (by keeping 100% compliant to this standard). The approach called "Liquid Sigantures" uses JavaScript capabilities as script language: weak typing and weak inteface checks at compile and runtime. Each function specified in Orion is implemented with full signature fTest( a,b,c ) { }. Each extended function implements also one additional (complex) parameter carying sap specific attributes and values for this function in order to use SAP HANA additional functionality: for example, sapBackPack.aTest = 42.

  • Standard consumption causing standard behaviour is var result = fTest( a,b,c ) ;
  • Enhanced consumption causing usage of SAP HANA specifics is var result = fTest( a,b,c,sapBackPack ) ;

Orion client can be used this way for handling HANA capabilities by staying compliant to the standard and by being open for externally developed components.

Code Example:

var sapBackPack = new SapBackPack();

sapBackPack.Activate = true;
createFile(parentLocation, fileName, sapBackPack);

X-CSRF-Token

In order to prevent XSRF based attacks on the REST API an X-CSRF-Token must be generated. For saving the generated tocken there exists a global variable X_CSRF_Token. Below is an example of how to generate and use a X-CSRF-Token.

$.ajax({

url: "/sap/hana/xs/dt/base/server/csrf.xsjs",
type: 'HEAD',
headers: { "X-CSRF-Token": "Fetch" },

success: function(data, textStatus, jqXHR) {
if(jqXHR.getResponseHeader("x-sap-login-page")){
return;
}
var securityToken = jqXHR.getResponseHeader("X-CSRF-Token");
X_CSRF_Token = securityToken;
}
});

createFile(parentLocation, fileName); // current X_CSRF_Token is used

FileClient

createFile(parentLocation, fileName)

Create a new file in a specified location. Returns a deferred that will provide The new file object when ready. An additional parameter describes if the file should be activated. By default the file is activated.

Usage of additional parameter:

var sapBackPack = new SapBackPack();

sapBackPack.Activate = true;

read(location, isMetadata)

Returns the contents or metadata of the file at the given location. An additional parameter describes which version of the file should be provided. By default it is the active version of the file. The version is defined by an ETag.

Usage of additional parameter:

var sapBackPack = new SapBackPack();

sapBackPack.Version = 8; // ETag==8

write(location, contents, args)

Writes the contents or metadata of the file at the given location. An additional parameter describes if the file should be activated. By default the file is activated.

Usage of additional parameter:

var sapBackPack = new SapBackPack();

sapBackPack.Activate = true;

createWorkspace(name)

to be described

createProject(url, projectName, serverPath, create)

to be described