Difference between revisions of "Data cache service"

From Catglobe Wiki
Jump to: navigation, search
(Page created)
 
 
(34 intermediate revisions by 3 users not shown)
Line 1: Line 1:
== Introduction ==
 
When working on solutions for clients it is not always enough to report on the collected data, in some cases the client also wants to get access to the raw data directly.
 
  
Normally this can be handled by exporting the data, but in some cases the client is looking for an automated approach, where they can develop a data consumer, thus we have created a service from which we provide access to data from data caches.
+
[[Category:Miscellaneous]]
  
The raw data has also shown to be useful when setting up dashboards, where access to the raw data from an RCS for instance allows us to make very advanced solutions such as our CRM solution.
+
== Introduction  ==
  
== Service APIs ==
+
When working on solutions for clients it is not always enough to report on the collected data, in some cases the client also wants to get access to the raw data directly.  
The data cache service consists of two APIs; an external API allowing external applications to retrieve data from a data cache through SOAP calls, and an internal API that gives access to data from a data cache through JavaScript, which can be used from dashboards for example.
 
  
Requests using the internal API happens in a stateful context contrary to the external API where requests happen in a stateless context. Thus the primary difference between the two APIs is that the external API requires username and password each time a request is made.
+
Normally this can be handled by exporting the data, but in some cases the client is looking for an automated approach, where they can develop a data consumer, thus we have created a service from which we provide access to data from data caches.  
  
The user requesting data from a data cache must have minimum observer access to the data cache specification, no matter if the external or internal API is used.
+
The raw data has also shown to be useful when setting up dashboards, where access to the raw data from an RCS for instance allows us to make very advanced solutions such as our CRM solution.
 +
 
 +
== Service APIs  ==
 +
 
 +
The data cache service consists of two APIs; an external API allowing external applications to retrieve data from a data cache through SOAP calls, and an internal API that gives access to data from a data cache through JavaScript, which can be used from dashboards for example.
 +
 
 +
Requests using the internal API happens in a stateful context contrary to the external API where requests happen in a stateless context. Thus the primary difference between the two APIs is that the external API requires username and password each time a request is made.
 +
 
 +
The user requesting data from a data cache must have minimum observer access to the data cache specification, no matter if the external or internal API is used.  
 +
 
 +
=== Data structures  ===
 +
 
 +
When data from a data cache is returned to the requester it is represented by a simple object structure.
 +
 
 +
[[Image:DataCacheDto.png]]
 +
 
 +
The '''DataCacheDto''' package the data returned from the data cache, with meta data to map column names to data.
 +
 
 +
*ColumnMap is an array of key-value pairs which contains one element for each column in the returned data table
 +
**Key refers to the column name
 +
**Value refers to the column index starting from 0
 +
*Rows is an array of '''DataCacheRowDto''' objects which contains one element for each row retrieved from the data cache
 +
**Data refers to the array of data, one element per column
 +
 
 +
=== Internal API  ===
  
=== External API ===
 
 
<source lang="csharp">
 
<source lang="csharp">
 +
// Gets the number of rows of a data cache.
 +
int GetRowCount
 +
(
 +
  int dcsResourceId
 +
)
 +
 +
// Gets all rows from a data cache, with data from a selection of columns.
 +
DataCacheDto GetData
 +
(
 +
  string[] columns,
 +
  int dcsResourceId
 +
)
 +
 +
// Gets all rows from a data cache, with data from a selection of columns.
 +
DataCacheDto GetDataSorted
 +
(
 +
  string[] columns,
 +
  int dcsResourceId,
 +
  string[] orderByColumns,
 +
  DataCacheSortOrderEnum sortOrder
 +
)
 +
 +
// Gets all rows from a data cache starting from a row index and returning
 +
// rows as requested.
 +
DataCacheDto GetDataRows
 +
(
 +
  string[] columns,
 +
  int dcsResourceId,
 +
  int rowIndex,
 +
  int rowCount
 +
)
 +
 +
// Gets all rows from a data cache starting from a row index and returning
 +
// rows as requested.
 +
DataCacheDto GetDataRowsSorted
 +
(
 +
  string[] columns,
 +
  int dcsResourceId,
 +
  string[] orderByColumns,
 +
  DataCacheSortOrderEnum sortOrder,
 +
  int rowIndex,
 +
  int rowCount
 +
)
 +
 +
// Gets the top N rows from a data cache, with data from a selection of columns,
 +
// ordered by some column. Rows with no values will be excluded, meaning that
 +
// the data cache returned might contain fewer rows, than indicated by N.
 +
DataCacheDto GetDataTop
 +
(
 +
  int top,
 +
  string[] columns,
 +
  int dcsResourceId
 +
)
 +
 +
// Gets the top N rows from a data cache, with data from a selection of columns,
 +
// ordered by some column. Rows with no values will be excluded, meaning that
 +
// the data cache returned might contain fewer rows, than indicated by N.
 +
DataCacheDto GetDataTopSorted
 +
(
 +
  int top,
 +
  string[] columns,
 +
  int dcsResourceId,
 +
  string[] orderByColumns,
 +
  DataCacheSortOrderEnum sortOrder
 +
)
  
 +
// Gets all rows from a data cache, with data from a selection of columns,
 +
// belonging to a selection of users.
 +
DataCacheDto GetDataForUsers
 +
(
 +
  string[] columns,
 +
  int dcsResourceId,
 +
  int[] users
 +
)
 +
 +
// Gets all rows from a data cache, with data from a selection of columns,
 +
// belonging to a selection of users.
 +
DataCacheDto GetDataForUsersSorted
 +
(
 +
  string[] columns,
 +
  int dcsResourceId,
 +
  int[] users,
 +
  string[] orderByColumns,
 +
  DataCacheSortOrderEnum sortOrder
 +
)
 +
 +
// Gets all rows from a data cache,with data from a selection of columns,
 +
// belonging to a logged in user.
 +
DataCacheDto GetDataForLoggedInUser
 +
(
 +
  string[] columns,
 +
  int dcsResourceId,
 +
  Guid dataViewUser
 +
)
 +
</source>
 +
 +
=== External API <br> ===
 +
 +
<source lang="csharp">
 +
// Gets the number of rows of a data cache.
 +
int GetRowCount
 +
(
 +
  string username,
 +
  string password,
 +
  int dcsResourceId
 +
)
 +
 +
// Gets all rows from a data cache, with data from a selection of columns.
 +
DataCacheDto GetData
 +
(
 +
  string username,
 +
  string password,
 +
  string[] columns,
 +
  int dcsResourceId
 +
)
 +
 +
// Gets all rows from a data cache, with data from a selection of columns.
 +
DataCacheDto GetDataSorted
 +
(
 +
  string username,
 +
  string password,
 +
  string[] columns,
 +
  int dcsResourceId,
 +
  string[] orderByColumns,
 +
  DataCacheSortOrderEnum sortOrder
 +
)
 +
 +
// Gets all rows from a data cache starting from a row index and returning rows as requested.
 +
DataCacheDto GetDataRows
 +
(
 +
  string username,
 +
  string password,
 +
  string[] columns,
 +
  int dcsResourceId,
 +
  int rowIndex,
 +
  int rowCount
 +
)
 +
 +
// Gets all rows from a data cache starting from a row index and returning rows as requested.
 +
DataCacheDto GetDataRowsSorted
 +
(
 +
  string username,
 +
  string password,
 +
  string[] columns,
 +
  int dcsResourceId,
 +
  string[] orderByColumns,
 +
  DataCacheSortOrderEnum sortOrder,
 +
  int rowIndex,
 +
  int rowCount
 +
)
 +
 +
// Gets the top N rows from a data cache, with data from a selection of columns, ordered by some column. Rows with no values will be excluded, meaning that the data cache returned might contain fewer rows, than indicated by N.
 +
DataCacheDto GetDataTop
 +
(
 +
  string username,
 +
  string password,
 +
  int top,
 +
  string[] columns,
 +
  int dcsResourceId
 +
)
 +
 +
// Gets the top N rows from a data cache, with data from a selection of columns, ordered by some column. Rows with no values will be excluded, meaning that the data cache returned might contain fewer rows, than indicated by N.
 +
DataCacheDto GetDataTopSorted
 +
(
 +
  string username,
 +
  string password,
 +
  int top,
 +
  string[] columns,
 +
  int dcsResourceId,
 +
  string[] orderByColumns,
 +
  DataCacheSortOrderEnum sortOrder
 +
)
 +
 +
// Gets all rows from a data cache, with data from a selection of columns, belonging to a selection of users.
 +
DataCacheDto GetDataForUsers
 +
(
 +
  string username,
 +
  string password,
 +
  string[] columns,
 +
  int dcsResourceId,
 +
  int[] users
 +
)
 +
 +
// Gets all rows from a data cache, with data from a selection of columns, belonging to a selection of users.
 +
DataCacheDto GetDataForUsersSorted
 +
(
 +
  string username,
 +
  string password,
 +
  string[] columns,
 +
  int dcsResourceId,
 +
  int[] users,
 +
  string[] orderByColumns,
 +
  DataCacheSortOrderEnum sortOrder
 +
)
 
</source>
 
</source>
  
=== Internal API ===
+
== Examples  ==
<source lang="csharp">
+
 
      /// <summary>
+
=== Accessing a project resource data cache ===
      /// Gets the number of rows of a data cache
+
 
      /// </summary>
+
We have created a search on the standard project resource list which we want to utilize from a dashboard.
      /// <param name="dcsResourceId">The resource id for the data cache specification which contains the data</param>
+
 
      /// <returns>Returns the number of rows in the data cache</returns>
+
[[Image:DataCacheService ProjectResourceList.png]]
      int GetRowCount(int resourceId);
+
 
 +
In order to do so we must first create a data cache.
  
      /// <summary>
+
[[Image:DataCacheService DataCacheResourceCrd.png]]  
      /// Gets all rows from a data cache, with data from a selection of columns
 
      /// </summary>
 
      /// <param name="columns">The columns for which data is requested</param>
 
      /// <param name="dcsResourceId">The resource id for the data cache specification which contains the data</param>
 
      /// <returns>Returns the data cache containing all rows of data for the selected columns</returns>
 
      DataCacheDto GetData(string[] columns, int dcsResourceId);
 
  
      /// <summary>
+
Note down the resource id of the newly created RCS, we will need that for the dashboard.
      /// Gets all rows from a data cache, with data from a selection of columns
 
      /// </summary>
 
      /// <param name="columns">The columns for which data is requested</param>
 
      /// <param name="dcsResourceId">The resource id for the data cache specification which contains the data</param>
 
      /// <param name="orderByColumns">Order the result by these columns</param>
 
      /// <param name="sortOrder">Order the rows ascending or descending</param>
 
      /// <returns>Returns the data cache containing all rows of data for the selected columns</returns>
 
      DataCacheDto GetDataSorted(string[] columns, int dcsResourceId, string[] orderByColumns, DataCacheSortOrderEnum sortOrder);
 
  
      /// <summary>
+
[[Image:DataCacheService DataCacheResourceList.png]]  
      /// Gets all rows from a data cache starting from a row index and returning rows as requested
 
      /// </summary>
 
      /// <param name="columns">The columns for which data is requested</param>
 
      /// <param name="dcsResourceId">The resource id for the data cache specification which contains the data</param>
 
      /// <param name="rowIndex"></param>
 
      /// <param name="rowCount"></param>
 
      DataCacheDto GetDataRows(string[] columns, int dcsResourceId, int rowIndex, int rowCount);
 
  
      /// <summary>
+
Create a new dashboard, save it, and go to the Layout tab, change the view to HTML and paste in the script below:
      /// Gets all rows from a data cache starting from a row index and returning rows as requested
 
      /// </summary>
 
      /// <param name="columns">The columns for which data is requested</param>
 
      /// <param name="dcsResourceId">The resource id for the data cache specification which contains the data</param>
 
      /// <param name="orderByColumns"></param>
 
      /// <param name="sortOrder"></param>
 
      /// <param name="orderByColumns">Order the result by these columns</param>
 
      /// <param name="sortOrder">Order the rows ascending or descending</param>
 
      /// <param name="rowIndex"></param>
 
      /// <param name="rowCount"></param>
 
      DataCacheDto GetDataRowsSorted(string[] columns, int dcsResourceId, string[] orderByColumns, DataCacheSortOrderEnum sortOrder, int rowIndex, int rowCount);
 
  
      /// <summary>
+
<source lang="javascript">
      /// Gets the top N rows from a data cache, with data from a selection of columns, ordered by some column.
+
<div id=contents>&nbsp;</div>
      /// Rows with no values will be excluded, meaning that the data cache returned might contain fewer rows,
 
      /// than indicated by N
 
      /// </summary>
 
      /// <param name="top">The top N rows to return</param>
 
      /// <param name="columns">The columns for which data is requested</param>
 
      /// <param name="dcsResourceId">The resource id for the data cache specification which contains the data</param>
 
      /// <returns>Returns the data cache containing N rows of data for the selected columns</returns>
 
      DataCacheDto GetDataTop(int top, string[] columns, int dcsResourceId);
 
  
      /// <summary>
+
<script type=text/javascript>
      /// Gets the top N rows from a data cache, with data from a selection of columns, ordered by some column.
+
// Creating a variable for the web-site's root path like below
      /// Rows with no values will be excluded, meaning that the data cache returned might contain fewer rows,
+
// makes it easier to move the script between different sites
      /// than indicated by N
+
var rootPath = window.location.protocol+'//'+window.location.host;
      /// </summary>
 
      /// <param name="top">The top N rows to return</param>
 
      /// <param name="columns">The columns for which data is requested</param>
 
      /// <param name="dcsResourceId">The resource id for the data cache specification which contains the data</param>
 
      /// <param name="orderByColumns">Order the result by these columns</param>
 
      /// <param name="sortOrder">Order the rows ascending or descending</param>
 
      /// <returns>Returns the data cache containing N rows of data for the selected columns</returns>
 
      DataCacheDto GetDataTopSorted(int top, string[] columns, int dcsResourceId, string[] orderByColumns, DataCacheSortOrderEnum sortOrder);
 
  
      /// <summary>
+
// A simple table renderer implemented using jQuery
      /// Gets all rows from a data cache, with data from a selection of columns, belonging to a selection of users
+
function renderTable(data)
      /// </summary>
+
{
      /// <param name="columns">The columns for which data is requested</param>
+
  // Create table and header row
      /// <param name="dcsResourceId">The resource id for the data cache specification which contains the data</param>
+
  var t = $('<table border="1">'); 
      /// <param name="users">The user ids for which data is requested</param>
+
  var tr = $('<tr>').appendTo(t);
       /// <returns>Returns the data cache containing only data for the logged in user</returns>
+
  for (var c in data.ColumnMap)
      DataCacheDto GetDataForUsers(string[] columns, int dcsResourceId, int[] users);
+
  {
 +
       $('<th>')
 +
        .html(data.ColumnMap[c].Key)
 +
        .appendTo(tr);
 +
  }
  
      /// <summary>
+
  // Add data rows
      /// Gets all rows from a data cache, with data from a selection of columns, belonging to a selection of users
+
  for (var r = 0; r < data.Rows.length; r++)
      /// </summary>
+
  {
       /// <param name="columns">The columns for which data is requested</param>
+
       var tr = $('<tr>').appendTo(t);
       /// <param name="dcsResourceId">The resource id for the data cache specification which contains the data</param>
+
       var row = data.Rows[r];
       /// <param name="users">The user ids for which data is requested</param>
+
       for (var c = 0; c < row.Data.length; c++)
      /// <param name="orderByColumns">Order the result by these columns</param>
+
       {
       /// <param name="sortOrder">Order the rows ascending or descending</param>
+
        $('<td>')
      /// <returns>Returns the data cache containing only data for the logged in user</returns>
+
            .html((row.Data[c] == null) ? '&nbsp;' : row.Data[c])
      DataCacheDto GetDataForUsersSorted(string[] columns, int dcsResourceId, int[] users, string[] orderByColumns, DataCacheSortOrderEnum sortOrder);
+
            .appendTo(tr);
 +
      }
 +
  }
 +
 
 +
  // Return the jQuery table object
 +
  return t;
 +
}
  
      /// <summary>
+
$(document).ready(function()
       /// Gets all rows from a data cache,with data from a selection of columns, belonging to a logged in user.
+
{
       ///
+
  // Load the JavaScript API for the internal data cache service
       /// This method can only be used from client-side where the user is already authenticated.
+
  $.getScript(rootPath+'/Services/Internal/DataCacheService.svc/js',
       /// </summary>
+
  function()
       /// <param name="dcsResourceId">The resource id for the data cache specification which contains the data</param>
+
  {
      /// <param name="columns">The columns for which data is requested</param>
+
       // Columns to retrieve from the data cache
      /// <param name="dataViewUser">The GUID for a user which have minimum observer access to the data cache specification</param>
+
      var columns =
      DataCacheDto GetDataForLoggedInUser(string[] columns, int dcsResourceId, Guid dataViewUser);
+
      [
 +
        'Id',
 +
        'Name',
 +
        'Path',
 +
        'ProjectCode',
 +
        'PlannedStartDate',
 +
        'PlannedEndDate'
 +
      ];
 +
     
 +
      // Data cache to retrieve the data from
 +
      var dcsResourceId = 34807128;
 +
     
 +
       // Start retrieving data from row 0
 +
      var rowIndex = 0;
 +
     
 +
       // Get 25 rows from the data cache
 +
      var rowCount = 25;
 +
     
 +
       // Create an instance of the internal data cache service API
 +
      var dataCacheService = new Catglobe.Web.Services.Internal.IDataCacheServiceInternal();
 +
     
 +
       // Get data from the data cache
 +
      dataCacheService.GetDataRows(
 +
        columns,
 +
        dcsResourceId,
 +
        rowIndex,
 +
        rowCount,
 +
        // When call to the service returns successfully
 +
        function(data)
 +
        {
 +
            // We receive data as a DataCacheDto object
 +
            // which we pass on to the table renderer
 +
            renderTable(data).appendTo($('#contents'));
 +
        },
 +
        // When call to the service returns failure
 +
        function(error)
 +
        {
 +
            // We announce the error received from the service
 +
            alert(error.get_message());
 +
        });
 +
  });
 +
});
 +
</script>
 
</source>
 
</source>
  
== Data structures ==
+
To access the same data cache from another site or web application written in PHP for example, we must use the external API for the service to provide user credentials, an example from PHP is shown below:
  
 +
<source lang="php">
 +
<?php
 +
// Set the header to return plain text
 +
header('Content-Type: text/plain');
  
== Error handling ==
+
// Create an instance of the soap client, with reference to the external API
 +
$client = new SoapClient('http://supernova.catglobe.com/services/external/DataCacheService.svc?wsdl');
  
 +
// Configure an anonymous object to pass necessary parameters to the service
 +
$obj->username = 'XXX';
 +
$obj->password = 'XXX';
  
== Examples ==
+
// Only select the top 5
 +
$obj->top = 5;
 +
 
 +
// Columns to retrieve from the data cache
 +
$obj->columns = array
 +
(
 +
  'Id',
 +
  'Name',
 +
  'Path',
 +
  'ProjectCode',
 +
  'PlannedStartDate',
 +
  'PlannedEndDate'
 +
);
 +
 
 +
// Data cache to retrieve the data from
 +
$obj->dcsResourceId = 34807128;
 +
 
 +
// Get the top 5 from the data cache
 +
$result = $client->GetDataTop($obj);
 +
 
 +
// Output the result
 +
print_r($result);
 +
?>
 +
</source>

Latest revision as of 12:20, 10 April 2015


Introduction

When working on solutions for clients it is not always enough to report on the collected data, in some cases the client also wants to get access to the raw data directly.

Normally this can be handled by exporting the data, but in some cases the client is looking for an automated approach, where they can develop a data consumer, thus we have created a service from which we provide access to data from data caches.

The raw data has also shown to be useful when setting up dashboards, where access to the raw data from an RCS for instance allows us to make very advanced solutions such as our CRM solution.

Service APIs

The data cache service consists of two APIs; an external API allowing external applications to retrieve data from a data cache through SOAP calls, and an internal API that gives access to data from a data cache through JavaScript, which can be used from dashboards for example.

Requests using the internal API happens in a stateful context contrary to the external API where requests happen in a stateless context. Thus the primary difference between the two APIs is that the external API requires username and password each time a request is made.

The user requesting data from a data cache must have minimum observer access to the data cache specification, no matter if the external or internal API is used.

Data structures

When data from a data cache is returned to the requester it is represented by a simple object structure.

DataCacheDto.png

The DataCacheDto package the data returned from the data cache, with meta data to map column names to data.

  • ColumnMap is an array of key-value pairs which contains one element for each column in the returned data table
    • Key refers to the column name
    • Value refers to the column index starting from 0
  • Rows is an array of DataCacheRowDto objects which contains one element for each row retrieved from the data cache
    • Data refers to the array of data, one element per column

Internal API

// Gets the number of rows of a data cache.
int GetRowCount
(
   int dcsResourceId
)

// Gets all rows from a data cache, with data from a selection of columns.
DataCacheDto GetData
(
   string[] columns,
   int dcsResourceId
)

// Gets all rows from a data cache, with data from a selection of columns.
DataCacheDto GetDataSorted
(
   string[] columns,
   int dcsResourceId,
   string[] orderByColumns,
   DataCacheSortOrderEnum sortOrder
)

// Gets all rows from a data cache starting from a row index and returning
// rows as requested.
DataCacheDto GetDataRows
(
   string[] columns,
   int dcsResourceId,
   int rowIndex,
   int rowCount
)

// Gets all rows from a data cache starting from a row index and returning
// rows as requested.
DataCacheDto GetDataRowsSorted
(
   string[] columns,
   int dcsResourceId,
   string[] orderByColumns,
   DataCacheSortOrderEnum sortOrder,
   int rowIndex,
   int rowCount
)

// Gets the top N rows from a data cache, with data from a selection of columns,
// ordered by some column. Rows with no values will be excluded, meaning that 
// the data cache returned might contain fewer rows, than indicated by N.
DataCacheDto GetDataTop
(
   int top,
   string[] columns,
   int dcsResourceId
)

// Gets the top N rows from a data cache, with data from a selection of columns,
// ordered by some column. Rows with no values will be excluded, meaning that
// the data cache returned might contain fewer rows, than indicated by N.
DataCacheDto GetDataTopSorted
(
   int top,
   string[] columns,
   int dcsResourceId,
   string[] orderByColumns,
   DataCacheSortOrderEnum sortOrder
)

// Gets all rows from a data cache, with data from a selection of columns,
// belonging to a selection of users.
DataCacheDto GetDataForUsers
(
   string[] columns,
   int dcsResourceId,
   int[] users
)

// Gets all rows from a data cache, with data from a selection of columns,
// belonging to a selection of users.
DataCacheDto GetDataForUsersSorted
(
   string[] columns,
   int dcsResourceId,
   int[] users,
   string[] orderByColumns,
   DataCacheSortOrderEnum sortOrder
)

// Gets all rows from a data cache,with data from a selection of columns,
// belonging to a logged in user.
DataCacheDto GetDataForLoggedInUser
(
   string[] columns,
   int dcsResourceId,
   Guid dataViewUser
)

External API

// Gets the number of rows of a data cache.
int GetRowCount
(
   string username,
   string password,
   int dcsResourceId
)

// Gets all rows from a data cache, with data from a selection of columns.
DataCacheDto GetData
(
   string username,
   string password,
   string[] columns,
   int dcsResourceId
)

// Gets all rows from a data cache, with data from a selection of columns.
DataCacheDto GetDataSorted
(
   string username,
   string password,
   string[] columns,
   int dcsResourceId,
   string[] orderByColumns,
   DataCacheSortOrderEnum sortOrder
)

// Gets all rows from a data cache starting from a row index and returning rows as requested.
DataCacheDto GetDataRows
(
   string username,
   string password,
   string[] columns,
   int dcsResourceId,
   int rowIndex,
   int rowCount
)

// Gets all rows from a data cache starting from a row index and returning rows as requested.
DataCacheDto GetDataRowsSorted
(
   string username,
   string password,
   string[] columns,
   int dcsResourceId,
   string[] orderByColumns,
   DataCacheSortOrderEnum sortOrder,
   int rowIndex,
   int rowCount
)

// Gets the top N rows from a data cache, with data from a selection of columns, ordered by some column. Rows with no values will be excluded, meaning that the data cache returned might contain fewer rows, than indicated by N.
DataCacheDto GetDataTop
(
   string username,
   string password,
   int top,
   string[] columns,
   int dcsResourceId
)

// Gets the top N rows from a data cache, with data from a selection of columns, ordered by some column. Rows with no values will be excluded, meaning that the data cache returned might contain fewer rows, than indicated by N.
DataCacheDto GetDataTopSorted
(
   string username,
   string password,
   int top,
   string[] columns,
   int dcsResourceId,
   string[] orderByColumns,
   DataCacheSortOrderEnum sortOrder
)

// Gets all rows from a data cache, with data from a selection of columns, belonging to a selection of users.
DataCacheDto GetDataForUsers
(
   string username,
   string password,
   string[] columns,
   int dcsResourceId,
   int[] users
)

// Gets all rows from a data cache, with data from a selection of columns, belonging to a selection of users.
DataCacheDto GetDataForUsersSorted
(
   string username,
   string password,
   string[] columns,
   int dcsResourceId,
   int[] users,
   string[] orderByColumns,
   DataCacheSortOrderEnum sortOrder
)

Examples

Accessing a project resource data cache

We have created a search on the standard project resource list which we want to utilize from a dashboard.

DataCacheService ProjectResourceList.png

In order to do so we must first create a data cache.

DataCacheService DataCacheResourceCrd.png

Note down the resource id of the newly created RCS, we will need that for the dashboard.

DataCacheService DataCacheResourceList.png

Create a new dashboard, save it, and go to the Layout tab, change the view to HTML and paste in the script below:

<div id=contents>&nbsp;</div>

<script type=text/javascript>
// Creating a variable for the web-site's root path like below
// makes it easier to move the script between different sites
var rootPath = window.location.protocol+'//'+window.location.host;

// A simple table renderer implemented using jQuery
function renderTable(data)
{
   // Create table and header row
   var t = $('<table border="1">');  
   var tr = $('<tr>').appendTo(t);
   for (var c in data.ColumnMap)
   {
      $('<th>')
         .html(data.ColumnMap[c].Key)
         .appendTo(tr);
   }

   // Add data rows
   for (var r = 0; r < data.Rows.length; r++)
   {
      var tr = $('<tr>').appendTo(t);
      var row = data.Rows[r];
      for (var c = 0; c < row.Data.length; c++)
      {
         $('<td>')
            .html((row.Data[c] == null) ? '&nbsp;' : row.Data[c])
            .appendTo(tr);
      }
   }
   
   // Return the jQuery table object
   return t;
}

$(document).ready(function()
{
   // Load the JavaScript API for the internal data cache service
   $.getScript(rootPath+'/Services/Internal/DataCacheService.svc/js',
   function()
   {
      // Columns to retrieve from the data cache
      var columns =
      [
         'Id',
         'Name',
         'Path',
         'ProjectCode',
         'PlannedStartDate',
         'PlannedEndDate'
      ];
      
      // Data cache to retrieve the data from
      var dcsResourceId = 34807128;
      
      // Start retrieving data from row 0
      var rowIndex = 0;
      
      // Get 25 rows from the data cache
      var rowCount = 25;
      
      // Create an instance of the internal data cache service API
      var dataCacheService = new Catglobe.Web.Services.Internal.IDataCacheServiceInternal();
      
      // Get data from the data cache
      dataCacheService.GetDataRows(
         columns,
         dcsResourceId,
         rowIndex,
         rowCount,
         // When call to the service returns successfully
         function(data)
         {
            // We receive data as a DataCacheDto object
            // which we pass on to the table renderer
            renderTable(data).appendTo($('#contents'));
         },
         // When call to the service returns failure
         function(error)
         {
            // We announce the error received from the service
            alert(error.get_message());
         });
   });
});
</script>

To access the same data cache from another site or web application written in PHP for example, we must use the external API for the service to provide user credentials, an example from PHP is shown below:

<?php
// Set the header to return plain text
header('Content-Type: text/plain');

// Create an instance of the soap client, with reference to the external API
$client = new SoapClient('http://supernova.catglobe.com/services/external/DataCacheService.svc?wsdl');

// Configure an anonymous object to pass necessary parameters to the service
$obj->username = 'XXX';
$obj->password = 'XXX';

// Only select the top 5
$obj->top = 5;

// Columns to retrieve from the data cache
$obj->columns = array
(
   'Id',
   'Name',
   'Path',
   'ProjectCode',
   'PlannedStartDate',
   'PlannedEndDate'
);

// Data cache to retrieve the data from
$obj->dcsResourceId = 34807128;

// Get the top 5 from the data cache
$result = $client->GetDataTop($obj);

// Output the result
print_r($result);
?>