Skip to content

Counters

The platform6.counters service manage queries that can be run on documents and routing orders.

Read the user guide of the Counters service to discover its operating mode.

List the counters

This resource returns the list of the counters.

Parameters

Headers of the request

Header’s key Description Value
platform6.request.action The action to perform (required) list
platform6.request.user The email address of the user sending the message

Headers of the response

Header’s key Description
platform6.response.value The list of counters

Example

def cm = [ headers: [ 'platform6.request.action': 'list' ] ]

print 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",
      "dataCluster": "B2BOX",
      "query": "/MessageInfo[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",
      "dataCluster": "B2BOX",
      "query": "/MessageInfo[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",
      "dataCluster": "B2BOX",
      "query": "/routingOrder",
      "target": "FailedRoutingOrder"
   }
]

Get a counter

Return the counter by his identifier if it exists, otherwise, it returns null.

Parameters

Headers of the request

Header’s key Description Value
platform6.request.action The action to perform (required) get
id The identifier of the counter (required)
platform6.request.user The email address of the user sending the message

Headers of the response

Header’s key Description
platform6.response.value The counter

Example

def cm = [
    headers: [
        'platform6.request.action': 'get',
        'id': 'Count_FailedRoutingOrders'
    ]
]

print 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",
   "dataCluster": "B2BOX",
   "query": "/routingOrder",
   "target": "FailedRoutingOrder"
}

Synchronize a counter

Run the counter’s query and update the counter’s value and last synchronisation date.

Parameters

Headers of the request

Header’s key Description Value
platform6.request.action The action to perform (required) synchronize
id The identifier of the counter (required)
platform6.request.user The email address of the user sending the message

Headers of the response

Header’s key Description
platform6.response.value The counter’s new value

Example

def cm = [
    headers: [
        'platform6.request.action': 'synchronize',
        'id': 'Count_FailedRoutingOrders'
    ]
]

print 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" : [
    "com.amalto.b2box.core.api.B2boxException: Unexpected exception synchronizing a counter: the counter 'Count_FailedRoutingOrders' is not found!",
    "    at com.amalto.service.counters.CountersService.notifyRequestMessage(CountersService.java:104)",
    "    at com.amalto.b2box.core.impl.servicecomponent.AbstractServiceComponent.onCommonMessage(AbstractServiceComponent.java:700)",
    "    at com.amalto.b2box.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)"
  ]
}