This tutorial shows how to access files and folders in an iHub volume and get details about these items. The resources for this task require an authId as an input parameter. The previous tutorial showed how to get an authId value.
Task 1: Get the available folders
Request the list of folders in the root directory in an iHub volume using the GET folders resource. For jQuery, form this request using a getJSON object. Parse the response object for the TotalCount field, which is the number of folders in the root directory. Then, create an HTML formatted string to display the number of folders in the output div.
3 After the definition of uriLogin, create a new variable for the path to the folders resource:
var uriFolders = 'http://mymachine:5000/ihub/v1/folders';
4 After the code that processes the login button click, add code to process the getfolders button click. Add the following functions to run the GET folders resource request and display the output:
2 Copy this file into a web application deployed to a web server. Then, type the URL of the page into a web browser. Alternatively, double-click the file in Windows Explorer. In username, type:
Administrator
3 Choose Login. Choose Get folder list. The list of files appears as shown in Figure 15‑9.
Figure 15‑9 Listing folders in the root folder using the REST API
Task 2: Get details of an individual folder
Create a selection list of the folders. Get the contents of the folder. Then, get its access control list.
1 Create the selection list of folders:
1 Add a label and a selection list after the definition of the getfolders button in the logintab div element, as shown in the following code:
<optionvalue="-1"selected="selected">Use Get folder list </option>
</select>
2 Create a variable to hold the list of folders. Populate the selection list in the code that processes the getfolders button click, as shown in the following code:
3 After the code that processes the selection from the list, add the following code to process the getfolderdetails button click:
// Process get folder details button
$( '#getfolderdetails' ).click( function(){
getFolderItems();
});
4 After the function that builds the folder list, add the following functions to run the GET folders/{folderId}/items resource and display an ordered list of the folder contents:
5 Save and run the file, as in the previous task. The list of files appears as shown in Figure 15‑11.
Figure 15‑11 Displaying folder contents using the REST API
3 Retrieve and display the access control list of the folder:
1 After the existing div element, add the following code to create a new div to display the list of privileges for the folder:
<divid="details">
<p></p>
<ul></ul>
</div>
2 After the function that builds the folder list, add the following functions to run the GET folders/{folderId}/privileges resource and display an unordered list of the folder contents:
$.getJSON( request, function( data ) { buildFolderPrivs( data )});
}
function buildFolderPrivs( data ) {
$( 'ul' ).empty( );
$('p').html( "The folder " + data.File.Name + " was last modified on " + data.File.TimeStamp + "<br />" + data.File.Name + " has the following privileges: <br />" );
if( JSON.stringify( data.ACL ) === '{}' ){
$( 'p' ).append(
"Access Control List is empty! Administrator access only.<br />" );
}else{
$.each( data.ACL.Permission, function( i, item ) {
3 In the buildFolderItemsList( ) function, run a files command to find the size of an item that is not a directory. After the code you added in the previous step, add the following else clause:
Figure 15‑13 Displaying file details on iHub using the REST API
A complete set of code for this example is provided in Listing 15‑2. Copy and paste this code into a text editor to create the complete example. To run the example, change mymachine to the fully qualified domain name of your REST API server.
Listing 15‑2 An Actuate REST API sample folder access page using JQuery
$.getJSON( request, function( data ) { buildFolderPrivs( data )});
}
function buildFolderPrivs( data ) {
$( 'ul' ).empty( );
$('p').html( "The folder " + data.File.Name + " was last modified on " + data.File.TimeStamp + "<br />" + data.File.Name + " has the following privileges: <br />" );
if( JSON.stringify( data.ACL ) === '{}' ){
$( 'p' ).append(
"Access Control List is empty! Administrator access only.<br />" );
}else{
$.each( data.ACL.Permission, function( i, item ) {