new Pageable(options, payloadopt, limitopt, nullable, clientopt)
iotcs.enterprise.EnterpriseClient#getApplications
or
iotcs.enterprise.EnterpriseClient#getDevices
.
In the usage of the Pageable object the application has to take into account the state of the
object. The state of the object can be changed by using the
iotcs.enterprise.Pageable#page
method.
The object can have 3 states:
a. In the first state the Pageable object is created and this can be
done generally indirectly by using the iotcs.enterprise.EnterpriseClient
methods as stated above.
b. From the first state the Pageable object can enter only the second state and
only by calling the page with the following parameters:
- page('first');
- page('first', x);
- page(0);
- page(0, x);
Where x is the actual size of the page requested or if none is given
a default size is defined.
c. From the second state the Pageable object can enter only the third state
by calling page with any parameters defined for the method. Then the object
will stay only in the third state.
Each transition to a state will return a Promise object that can be used
for handling the response/error received for the page request.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
options |
object | The options that are given to the XMLHttpRequest object for making the initial request without the paging parameters (without offset or limit). | |
payload |
string |
<optional> |
The payload used in the initial and subsequent requests made for generating the pages. |
limit |
number |
<optional> <nullable> |
The initial limit used for generating the pages requested; optional as if none is given the default is 50. |
client |
iotcs.enterprise.EnterpriseClient |
<optional> |
The enterprise client used by this Pageable object for requests. This is optional and is used only in context of endpoint authentication. |
Example
// Create the enterprise client.
iotcs.enterprise.EnterpriseClient.newClient(entClient => {
// Create the Pageable object.
let pageable = entClient.getActiveDevices('urn:com:oracle:iot:device:humidity_sensor');
let recursivePrevious;
let recursiveNext;
// Function that iterates previous page until start.
recursivePrevious = function () {
pageable.page('prev').then( function (response) {
if (Array.isArray(response.items)) {
// Handle items.
}
if (pageable.prev) {
// If there is a prev link present...
recursivePrevious();
} else {
// Handle stop.
entClient.close();
}
}
}
// Function that iterates next page until end.
recursiveNext = function () {
pageable.page('next').then( function (response) {
if (Array.isArray(response.items)) {
// Handle items.
}
if (response.hasMore) {
// If there are more items then go next page...
recursiveNext();
} else if (pageable.prev) {
// If there are no more items and there is a prev link present, then we have
// reached the end and can go backwards.
recursivePrevious();
} else {
// Handle stop.
entClient.close();
}
}
}
// Retrieve first page.
pageable.page('first').then( function (response) {
if (Array.isArray(response.items)) {
// Handle items.
}
if (response.hasMore) {
// If there are more items, then there are more pages.
recursiveNext();
} else {
// Handle stop.
entClient.close();
}
}
});
Methods
(static) page(offset, limitopt) → {Promise}
A standard page response would have the following useful properties:
- items: The array of items representing content of the page.
- hasMore: A boolean value that would tell if a 'next' call can be made.
- count: The count of all the items that satisfy the request query.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
offset |
number | string | This parameter will set where the initial element of the page to be set; if the parameter is a number then the exact number is the position of the first element of the page, if the parameter is string then the values can be: 'first', 'last', 'next' and 'prev' and the page requested will be according to link associated to each setting: 'first page', 'next page' etc. | |
limit |
number |
<optional> |
If the offset is a number, then this parameter will be used to set a new limit for pages. If the parameter is not set, the limit used in the constructor will be used. |
Returns:
- Type
- Promise