Counters
Service Id: platform6.charts
1. Get JSON List of Counter Service Items¶
Header key | Description | Value |
---|---|---|
platform6.request.action |
The action to perform (required) | list |
A valid response will be:
Header key | Description |
---|---|
platform6.response.status |
OK |
platform6.response.value |
JSON List |
Example¶
def cm = [ headers: [ 'platform6.request.action': 'list' ] ]
print p6.service.request('platform6.counters', cm).headers['platform6.response.value']
The response will be:
[
{
"name": "Count_Messages_Invoices_All",
"appKey": "",
"description": {
"EN": "Total # of Invoices",
"FR": "# total de factures traitées"
},
"enabled": true,
"contentMode": "NONE",
"lastModifiedBy": "admin@amalto.com",
"lastModifiedDate": 1533895680307,
"revisionId": "fe5328994068d160708cf79cd284987f",
"lastSyncDate": 1533895680307,
"value": 14,
"type": "COUNT",
"dataPartition": "TRANSACTION",
"query": "/TransactionInfo[BusinessDocName= \"Invoice\"]",
"target": "Item"
},
{
"name": "Count_MIs-with-Sent-status",
"appKey": "",
"description": { "EN": "Number of Invoices with \"Sent\" status" },
"enabled": true,
"contentMode": "NONE",
"lastModifiedBy": "admin@amalto.com",
"lastModifiedDate": 1533895560112,
"revisionId": "26febe961a1a3e3b2d24475ca85284f1",
"lastSyncDate": 1533895560112,
"value": 0,
"type": "COUNT",
"dataPartition": "TRANSACTION",
"query": "/TransactionInfo[BusinessDocName= \"Invoice\" and LastStatusCode = \"Sent\" ][concat(substring(CreationDate,1,8),substring(CreationDate,10,2),substring(CreationDate,13,2)) < concat(substring(\"${DATE-90m}\",1,8),substring(\"${DATE-90m}\",10,2),substring(\"${DATE-90m}\",13,2))][concat(substring(CreationDate,1,8),substring(CreationDate,10,2),substring(CreationDate,13,2)) > concat(substring(\"${DATE-90d}\",1,8),substring(\"${DATE-90d}\",10,2),substring(\"${DATE-90d}\",13,2))]",
"target": "Item"
},
{
"name": "Count_FailedRoutingOrders",
"appKey": "",
"description": { "EN": "Number Of Failed Routing Orders" },
"enabled": true,
"contentMode": "NONE",
"lastModifiedBy": "admin@amalto.com",
"lastModifiedDate": 1533897900205,
"revisionId": "c0ba7158d9e04ffa3621a74037dae387",
"lastSyncDate": 1533897900205,
"value": 24,
"type": "COUNT",
"dataPartition": "TRANSACTION",
"query": "/routingOrder",
"target": "FailedRoutingOrder"
}
]
2. Get JSON Counter Service Item Given Its Id¶
Header key | Description | Value |
---|---|---|
platform6.request.action |
The action to perform (required) | get |
id |
The identifier of the counter (required) |
A valid response will be:
Header key | Description |
---|---|
platform6.response.status |
OK |
platform6.response.value |
JSON CounterItem |
Example¶
def cm = [
headers: [
'platform6.request.action': 'get',
'id': 'Count_FailedRoutingOrders'
]
]
print p6.service.request('platform6.counters', cm).headers['platform6.response.value']
If it exists it returns the item (see below), otherwise, it returns null
.
{
"name": "Count_FailedRoutingOrders",
"appKey": "",
"description": { "EN": "Number Of Failed Routing Orders" },
"enabled": true,
"contentMode": "NONE",
"lastModifiedBy": "admin@amalto.com",
"lastModifiedDate": 1533898800109,
"revisionId": "f779d58bd18ead1b9b14b13f074269fb",
"lastSyncDate": 1533898800109,
"value": 24,
"type": "COUNT",
"dataPartition": "TRANSACTION",
"query": "/routingOrder",
"target": "FailedRoutingOrder"
}
2. Synchronize a Counter Service Item Given Its Id¶
Header’s key | Description | Value |
---|---|---|
platform6.request.action |
The action to perform (required) | synchronize |
id |
The identifier of the counter (required) |
A valid response will be:
Header key | Description |
---|---|
platform6.response.status |
OK |
platform6.response.value |
The counter’s new value |
Example¶
def cm = [
headers: [
'platform6.request.action': 'synchronize',
'id': 'Count_FailedRoutingOrders'
]
]
print p6.service.request('platform6.counters', cm).headers['platform6.response.value']
The output will be the new value of the counter:
24
If the counter does not exist, it will return an error:
{
"message" : "Unexpected exception synchronizing a counter: the counter 'Count_FailedRoutingOrders' is not found!",
"stackTrace" : [
"io.platform6.common.util.P6Exception: Unexpected exception synchronizing a counter: the counter 'Count_FailedRoutingOrders' is not found!",
" at io.platform6.core.service.counters.CountersService.notifyRequestMessage(CountersService.java:104)",
" at io.platform6.core.impl.servicecomponent.AbstractServiceComponent.onCommonMessage(AbstractServiceComponent.java:700)",
" at io.platform6.core.impl.platform.messagebus.BusQueueController$ServiceQueueRunner.run(BusQueueController.java:183)",
" at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)",
" at java.util.concurrent.FutureTask.run(FutureTask.java:266)",
" at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)",
" at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)",
" at java.lang.Thread.run(Thread.java:748)"
]
}