Difference between revisions of "Data cache service"

From Catglobe Wiki
Jump to: navigation, search
Line 183: Line 183:
 
|}
 
|}
  
==== Examples ====
+
==== Example ====
 +
 
 +
<source lang="php">
 +
<?php
 +
header('Content-Type: text/plain');
 +
$client = new SoapClient('http://cghead.catglobe.com/services/external/DataCacheService.svc?wsdl');
 +
$obj->username = 'DataCacheViewer';
 +
$obj->password = 'MegetHemmeligt';
 +
$obj->top = 5;
 +
$obj->columns = array
 +
(
 +
  'User_ResourceId',
 +
  'FirstName',
 +
  'LastName',
 +
  'EmailAddress'
 +
);
 +
$obj->dcsResourceId = XXX;
 +
$result = $client->GetDataTop($obj);
 +
print_r($result);
 +
?>
 +
</source>

Revision as of 10:12, 15 October 2009

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

DataCacheDto

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 to the column index starting from 0
  • Rows is an array which contains one element for

DataCacheRowDto

Internal API

Type Signature Description
int GetRowCount (int dcsResourceId) Gets the number of rows of a data cache.
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, with data from a selection of columns.
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 all rows from a data cache starting from a row index and returning rows as requested.
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 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 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 selection of users.
DataCacheDto GetDataForLoggedInUser (string[] columns, int dcsResourceId, Guid dataViewUser) Gets all rows from a data cache,with data from a selection of columns, belonging to a logged in user.

Examples

<DIV id=contents>&nbsp;</DIV>
<SCRIPT type=text/javascript>
var rootPath = window.location.protocol+'//'+window.location.host;
rootPath = 'http://localhost/supernova';
function renderTable(data)
{
   var t = $('<table border="1">');
   
   var tr = $('<tr>').appendTo(t);
   for (var c in data.ColumnMap)
   {
      $('<th>')
         .html(data.ColumnMap[c].Key)
         .appendTo(tr);
   }

   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 t;
}
$(document).ready(function()
{
   $.getScript(rootPath+'/Services/Internal/DataCacheService.svc/js',
   function()
   {
      var columns = ['Id', 'Name', 'Path', 'ProjectCode', 'PlannedStartDate', 'PlannedEndDate'];
      var dcsResourceId = 41673;
      
      var dataCacheService = new Catglobe.Web.Services.Internal.IDataCacheServiceInternal();
      dataCacheService.GetData(
         columns,
         dcsResourceId,
         function(data)
         {
            renderTable(data).appendTo($('#contents'));
         },
         function()
         {
            alert('An error occurred');
         });
   });
});
</SCRIPT>

External API

Type Signature Description
int GetRowCount (string username, string password, int dcsResourceId) Gets the number of rows of a data cache.
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, with data from a selection of columns.
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 all rows from a data cache starting from a row index and returning rows as requested.
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 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 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) Gets all rows from a data cache, with data from a selection of columns, belonging to a selection of users.

Example

<?php
header('Content-Type: text/plain');
$client = new SoapClient('http://cghead.catglobe.com/services/external/DataCacheService.svc?wsdl');
$obj->username = 'DataCacheViewer';
$obj->password = 'MegetHemmeligt';
$obj->top = 5;
$obj->columns = array
(
   'User_ResourceId',
   'FirstName',
   'LastName',
   'EmailAddress'
);
$obj->dcsResourceId = XXX;
$result = $client->GetDataTop($obj);
print_r($result);
?>